print("Execution time with earlier stopping: %s minutes" % ((end_time[3] - start_time[3])/60))
Execution time with earlier stopping: 6.480882187684377 minutes
nn_plot(hist[3], 13, loss=True)
nn_plot(hist[3], 13, acc=True)
# Evaluate the model on the test data using 'evaluate'
print("Evaluate on test data")
results.append(model[-1].evaluate(x_test, y_test_label, batch_size=64))
print("test loss, test acc:", results[1])
Evaluate on test data 157/157 [==============================] - 3s 19ms/step - loss: 0.0609 - categorical_accuracy: 0.9861 test loss, test acc: [0.06089204549789429, 0.9861000180244446]
The accuracy achieved over the test set now is 98.61%. It was close to our model with 50 epochs but slitghly worse. These variations may be explained by the randomness over the samples and parameters initialization and is completely expected.
We will add activation functions to each filter, increasing the model's capability to extract useful information from the data.
model.append(tf.keras.models.Sequential([
tf.keras.layers.Conv2D(16, (3, 3), activation='relu', input_shape=(28, 28, 1)),
tf.keras.layers.MaxPooling2D(pool_size=(2, 2)),
tf.keras.layers.Conv2D(32, (3, 3), activation='relu'),
tf.keras.layers.MaxPooling2D(pool_size=(2, 2)),
tf.keras.layers.Conv2D(32, (3, 3), activation='relu'),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(32, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
]))
nn_compile(model[-1], params[-1])