model.fit()
prints
60000/60000 [==============================] - 10s 175us/sample - loss: 0.4940 - accuracy: 0.8262
Which is normal. But
model.evaluate()
prints
10000/1 [======.....10000times......=====] - 1s 117us/sample - loss: 0.2859 - accuracy: 0.8578
Why?!
This issue is resolved in the Tensorflow Version
of 2.1-rc0
.
Please find the below code, which resolves the issue:
!pip install tensorflow==2.1-rc0
import tensorflow as tf
from tensorflow import keras
print('Version of TensorFlow:', tf.__version__)
print('Version of tf.keras:', tf.keras.__version__)
# Import dataset
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
# Build and Compile the model
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy']
)
# Train the model
print('Training')
model.fit(train_images, train_labels, epochs=5)
# Evaluate the model
print('Evaluating')
test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=1)
print('\nTest accuracy:', test_acc)
Shown below is the screenshot of the Execution Log:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.