Tukanoid
Tukanoid

Reputation: 81

Tensorflow model from very 1st tutorial doesnt work like expected

Trying to start learning tensorflow by tutorials. Started with 1st one (of course) and for some reason when I try to learn model it shows loss number between 10 and 12 and accuracy number is 0.2 and 0.3 but in tutorial numbers are very different. Before I had some troubles installing tensorflow, as I tried to make gpu work with it, but I only got errors, so I reinstalled it with cpu support only (python-tensorflow package archlinux). But also I get 2019-02-22 19:18:02.042566: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA error. I don't know if that's the case.

My code is:

import tensorflow as tf
from tensorflow import keras

import numpy as np
import matplotlib.pyplot as plt


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='adam',
              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)

Thanks in advance!

Upvotes: 0

Views: 42

Answers (1)

Sharky
Sharky

Reputation: 4543

Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA This is just a warning, stating that you can compile from source and be able to use it.

As for your model, it's ok, but if you normalize inputs, you'll get 70% accuracy

train_images = train_images.astype('float32') / 255
test_images = test_images.astype('float32') / 255

You can find more on that here https://stats.stackexchange.com/questions/211436/why-normalize-images-by-subtracting-datasets-image-mean-instead-of-the-current

Upvotes: 1

Related Questions