Hi,
I’m running on, tensorflow = 2.0 with python = 3.7.0.
As it is on the subject,
When I evaluate my CNN model, it shows so many progress bars(“=”) and two different loss values.
I’m ok with the progress bars but the different loss values make me confused.
Do you have a key to solve the problem?
My situation as blow:
print(model.evaluate(x_test, y_test))
1200/1 [=========…omit…=============================================================================================] - 8s 7ms/sample - loss: 0.0320 - accuracy: 0.9817
[0.056471010148525236, 0.9816667]
This issue was fixed. Please try with the latest tensorflow version 2.9.1
Please refer to the sample working code
import numpy as np
import tensorflow as tf
print(tf.__version__)
from matplotlib import pyplot as plt
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10)
])
loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
model.compile(optimizer='adam',
loss=loss_fn,
metrics=['accuracy'])
history = model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test, verbose=2)
Output:
2.9.1
Epoch 1/5 1875/1875 [==============================] - 11s 5ms/step - loss: 0.2953 - accuracy: 0.9136
Epoch 2/5 1875/1875 [==============================] - 6s 3ms/step - loss: 0.1440 - accuracy: 0.9571
Epoch 3/5 1875/1875 [==============================] - 6s 3ms/step - loss: 0.1060 - accuracy: 0.9676
Epoch 4/5 1875/1875 [==============================] - 6s 3ms/step - loss: 0.0874 - accuracy: 0.9727
Epoch 5/5 1875/1875 [==============================] - 6s 3ms/step - loss: 0.0752 - accuracy: 0.9762
313/313 - 1s - loss: 0.0805 - accuracy: 0.9752 - 629ms/epoch - 2ms/step
[0.08049937337636948, 0.9751999974250793]