CVDL7 61
CVDL7 61
ipynb - Colab
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
import numpy as np
import matplotlib.pyplot as plt
import cv2
def LeNet():
model = keras.Sequential([
layers.Conv2D(6, kernel_size=5, activation='tanh', padding='same', input_shape=(28, 28, 1)),
layers.AvgPool2D(pool_size=2, strides=2),
layers.Conv2D(16, kernel_size=5, activation='tanh'),
layers.AvgPool2D(pool_size=2, strides=2),
layers.Flatten(),
layers.Dense(120, activation='tanh'),
layers.Dense(84, activation='tanh'),
layers.Dense(10, activation='softmax')
])
return model
https://colab.research.google.com/drive/1z4qsPvWNq_KgUB_5q5N0OFY80VOZUeg4#scrollTo=29cSEMWxx-Vn&printMode=true 1/3
3/12/25, 8:15 PM cvdl 7.ipynb - Colab
1875/1875 ━━━━━━━━━━━━━━━━━━━━ 81s 23ms/step - accuracy: 0.9935 - loss: 0.0207 - val_accuracy: 0.9870 - val_loss: 0.0449
Epoch 9/10
1875/1875 ━━━━━━━━━━━━━━━━━━━━ 79s 21ms/step - accuracy: 0.9944 - loss: 0.0169 - val_accuracy: 0.9869 - val_loss: 0.0419
Epoch 10/10
1875/1875 ━━━━━━━━━━━━━━━━━━━━ 43s 23ms/step - accuracy: 0.9952 - loss: 0.0148 - val_accuracy: 0.9846 - val_loss: 0.0544
313/313 ━━━━━━━━━━━━━━━━━━━━ 3s 9ms/step - accuracy: 0.9815 - loss: 0.0629
WARNING:absl:You are saving your model as an HDF5 file via `model.save()` or `keras.saving.save_model(model)`. This file format is c
Test Accuracy: 0.9846
predict("/content/download.png")
WARNING:absl:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until y
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 156ms/step
predict("/content/33.jpg")
https://colab.research.google.com/drive/1z4qsPvWNq_KgUB_5q5N0OFY80VOZUeg4#scrollTo=29cSEMWxx-Vn&printMode=true 2/3
3/12/25, 8:15 PM cvdl 7.ipynb - Colab
WARNING:absl:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until y
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 120ms/step
predict("/content/download 4.jpg")
WARNING:absl:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until y
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 127ms/step
https://colab.research.google.com/drive/1z4qsPvWNq_KgUB_5q5N0OFY80VOZUeg4#scrollTo=29cSEMWxx-Vn&printMode=true 3/3