mnist训练和测试精度仅为0.49

时间:2018-11-26 18:04:44

标签: python tensorflow keras deep-learning mnist

我正在尝试在MNIST数据集上实现基本的ANN,并且我在tensorflow中使用了相同的代码:https://www.tensorflow.org/tutorials/,但是在训练和测试数据集时准确性很低。我看不出是什么原因造成的。下面是输出:

    2018-11-26 11:55:02.526281: I 
tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports 
instructions that this TensorFlow binary was not compiled to use: AVX2 
FMA
Epoch 1/10
   32/7000 [..............................] - ETA: 1:12 - loss: 1.4159 
- acc: 0.4062
 960/7000 [===>..........................] - ETA: 2s - loss: 1.1616 - 
acc: 0.4052  
1920/7000 [=======>......................] - ETA: 1s - loss: 1.0438 - 
acc: 0.4297
2816/7000 [===========>..................] - ETA: 0s - loss: 1.0004 - 
acc: 0.4592
3712/7000 [==============>...............] - ETA: 0s - loss: 0.9788 - 
acc: 0.4749
4448/7000 [==================>...........] - ETA: 0s - loss: 0.9691 - 
acc: 0.4795
5408/7000 [======================>.......] - ETA: 0s - loss: 0.9602 - 
acc: 0.4741
6368/7000 [==========================>...] - ETA: 0s - loss: 0.9567 - 
acc: 0.4763
7000/7000 [==============================] - 1s 105us/step - loss: 
0.9543
acc: 0.4773
.................(I omitted some of the outputs, because they are almost the same.)

Epoch 10/10
  32/7000 [..............................] - ETA: 0s - loss: 0.9383 - 
acc: 0.5000
 896/7000 [==>...........................] - ETA: 0s - loss: 0.9201 - 
acc: 0.5022
1696/7000 [======>.......................] - ETA: 0s - loss: 0.9120 - 
acc: 0.5083
1984/7000 [=======>......................] - ETA: 0s - loss: 0.9153 - 
acc: 0.5055
2560/7000 [=========>....................] - ETA: 0s - loss: 0.9210 - 
acc: 0.5043
3328/7000 [=============>................] - ETA: 0s - loss: 0.9208 - 
acc: 0.5072
4096/7000 [================>.............] - ETA: 0s - loss: 0.9199 - 
acc: 0.5054
4672/7000 [===================>..........] - ETA: 0s - loss: 0.9235 - 
acc: 0.4991
5344/7000 [=====================>........] - ETA: 0s - loss: 0.9219 - 
acc: 0.5011
6144/7000 [=========================>....] - ETA: 0s - loss: 0.9240 - 
acc: 0.4977
7000/7000 [==============================] - 1s 75us/step - loss: 
0.9235 
acc: 0.4946
32/3000 [..............................] - ETA: 8s
1920/3000 [==================>...........] - ETA: 0s
3000/3000 [==============================] - 0s 54us/step
Test accuracy: 0.49966666666666665

我只使用下面的代码,该代码来自该网站:https://www.tensorflow.org/tutorials/。数据集是MNIST。

import tensorflow as tf

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(),
    tf.keras.layers.Dense(512, activation=tf.nn.relu),
    tf.keras.layers.Dropout(0.2),
    tf.keras.layers.Dense(10, activation=tf.nn.softmax)
])

model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5)

model.evaluate(x_test, y_test)

实际上,我只是在google colab上尝试了该代码,结果是正常的:

Epoch 1/1
60000/60000 [==============================] - 16s 270us/step - loss: 0.2015 - acc: 0.9406
10000/10000 [==============================] - 1s 61us/step
[0.11236203697770834, 0.9653]

现在,我假设此问题是由我的计算机(2015年初的Macbook)引起的,并且操作系统是Mac OS X 10.14.1。

0 个答案:

没有答案
相关问题