Keras PROGRAM
Keras PROGRAM
frameworks such as TensorFlow, Theano, and Microsoft Cognitive Toolkit (CNTK). It was developed
to make building and experimenting with deep learning models easier and faster. In fact, it's now
part of TensorFlow as its official high-level API.
SAMPLE PROGRAM:
import tensorflow as tf
train_labels = to_categorical(train_labels)
test_labels = to_categorical(test_labels)
model = models.Sequential()
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy'])
OUTPUT:
Epoch 1/5
938/938 ━━━━━━━━━━━━━━━━━━━━ 17s 16ms/step - accuracy: 0.8592 - loss:
0.4609
Epoch 2/5
938/938 ━━━━━━━━━━━━━━━━━━━━ 20s 16ms/step - accuracy: 0.9817 - loss:
0.0588
Epoch 3/5
938/938 ━━━━━━━━━━━━━━━━━━━━ 15s 16ms/step - accuracy: 0.9880 - loss:
0.0404
Epoch 4/5
938/938 ━━━━━━━━━━━━━━━━━━━━ 21s 16ms/step - accuracy: 0.9909 - loss:
0.0280
Epoch 5/5
938/938 ━━━━━━━━━━━━━━━━━━━━ 20s 16ms/step - accuracy: 0.9931 - loss:
0.0214
313/313 ━━━━━━━━━━━━━━━━━━━━ 1s 4ms/step - accuracy: 0.9893 - loss: 0.0347
Test accuracy: 0.991599977016449