My goal is to classify products pictures into categories such as dress, sandals, etc.
I am using the MNIST fashion dataset, following this official tutorial word-per-word: https://www.tensorflow.org/tutorials/keras/basic_classification so my code is 100% identical to what can be read there:
# TensorFlow and tf.keras
import tensorflow as tf
from tensorflow import keras
# Helper libraries
import numpy as np
import matplotlib.pyplot as plt
print(tf.__version__)
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(128, activation=tf.nn.relu),
keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer=tf.train.AdamOptimizer(),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(train_images, train_labels, epochs=5)
test_loss, test_acc = model.evaluate(test_images, test_labels)
print('Test accuracy:', test_acc)
Problem: The resulting accuracy is always around 0.1, much lower than the tutorial's example output of 0.876.
I am obviously doing something wrong, but I can't figure out what. How to improve accuracy to something reasonable?
My output:
$ python classify-products.py
1.10.1
Epoch 1/5
2018-09-18 13:33:46.971437: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
60000/60000 [==============================] - 3s 47us/step - loss: 13.0161 - acc: 0.1924
Epoch 2/5
60000/60000 [==============================] - 3s 46us/step - loss: 12.8998 - acc: 0.1997
Epoch 3/5
60000/60000 [==============================] - 3s 46us/step - loss: 13.3386 - acc: 0.1724
Epoch 4/5
60000/60000 [==============================] - 3s 47us/step - loss: 12.9031 - acc: 0.1995
Epoch 5/5
60000/60000 [==============================] - 3s 47us/step - loss: 13.6666 - acc: 0.1521
10000/10000 [==============================] - 0s 26us/step
('Test accuracy:', 0.1005)
Switching to 20 epochs does not improve accuracy.