DL Prac03IT
DL Prac03IT
[24]: ''' Deep Learning : Practical No 3 Name:Devika Sawant Roll Number: 54 Year:
↪BE IT'''
[24]: ' Deep Learning : Practical No 3 Name:Devika Sawant Roll Number: 54 Year:BE
IT'
[2]: '''Build the Image classification model by dividing the model into following 4␣
↪stages:
[2]: "Build the Image classification model by dividing the model into following 4
stages:\n1.Loading and preprocessing the image data\n2.Defining the model's
architecture\n3.Training the model\n4.Estimating the model's performance"
X = images
y = labels
1
[5]: # Loading and preprocessing the image data
(X_train, y_train),(X_test, y_test) = mnist.load_data()
[6]: print(X_train.shape)
[7]: X_train[0].min(),X_train[0].max()
2
[10]: X_tarin = X_train.reshape((X_train.shape+ (1,)))
X_test = X_test.reshape((X_test.shape+(1,)))
[11]: y_train[0:20]
model = Sequential([
Conv2D(32,(3,3), activation="relu",input_shape=(28,28,1)),
MaxPooling2D((2,2)),
Flatten(),
Dense(100,activation="relu"),
Dense(10,activation="softmax")
])
3
)
[14]: model.summary()
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d (Conv2D) (None, 26, 26, 32) 320
=================================================================
Total params: 542,230
Trainable params: 542,230
Non-trainable params: 0
_________________________________________________________________
[15]: # Assuming you have X and y loaded, which represent the features and labels␣
↪respectively
# Split the data into training and validation sets (e.g., 80% train, 20%␣
↪validation)
Epoch 1/10
3200/3200 [==============================] - 108s 15ms/step - loss: 3.1938 -
accuracy: 0.1095 - val_loss: 2.3031 - val_accuracy: 0.1016
Epoch 2/10
3200/3200 [==============================] - 47s 15ms/step - loss: 2.3027 -
4
accuracy: 0.1089 - val_loss: 2.3041 - val_accuracy: 0.0978
Epoch 3/10
3200/3200 [==============================] - 47s 15ms/step - loss: 2.3026 -
accuracy: 0.1108 - val_loss: 2.3037 - val_accuracy: 0.0995
Epoch 4/10
3200/3200 [==============================] - 46s 14ms/step - loss: 2.3029 -
accuracy: 0.1094 - val_loss: 2.3031 - val_accuracy: 0.1082
Epoch 5/10
3200/3200 [==============================] - 49s 15ms/step - loss: 2.3027 -
accuracy: 0.1081 - val_loss: 2.3035 - val_accuracy: 0.1102
Epoch 6/10
3200/3200 [==============================] - 49s 15ms/step - loss: 2.3027 -
accuracy: 0.1117 - val_loss: 2.3022 - val_accuracy: 0.1102
Epoch 7/10
3200/3200 [==============================] - 45s 14ms/step - loss: 2.3029 -
accuracy: 0.1086 - val_loss: 2.3033 - val_accuracy: 0.1102
Epoch 8/10
3200/3200 [==============================] - 47s 15ms/step - loss: 2.3028 -
accuracy: 0.1087 - val_loss: 2.3024 - val_accuracy: 0.1102
Epoch 9/10
3200/3200 [==============================] - 45s 14ms/step - loss: 2.3029 -
accuracy: 0.1099 - val_loss: 2.3034 - val_accuracy: 0.0981
Epoch 10/10
3200/3200 [==============================] - 49s 15ms/step - loss: 2.3027 -
accuracy: 0.1106 - val_loss: 2.3036 - val_accuracy: 0.1102
5
1/1 [==============================] - 0s 20ms/step
1/1 [==============================] - 0s 21ms/step
1/1 [==============================] - 0s 21ms/step
1/1 [==============================] - 0s 36ms/step
1/1 [==============================] - 0s 20ms/step
[17]: 0.1135
[18]: n = random.randint(0,9999)
plt.imshow(X_test[n])
plt.show()
6
[19]: predicted_value = model.predict(X_test)
print("Handwritten number in the image is = %d" %np.argmax(predicted_value[n]))
[ ]: