在Mac上的MNIST手写数字识别任务,但不输出手写数字的照片

时间:2019-05-18 23:05:30

标签: python keras tensor mnist digits

我正在Mac上执行MNIST手指识别任务,但它没有显示图像的预测值,而只是进行了准确的检查。

我在Mac上使用Spyder。它似乎在Windows上可以正常工作,但在我的Mac上却不能。顺便说一句,我正在使用python(spyder)3.7。

import tensorflow as tf
import numpy as np
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(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=1)
model.evaluate(x_test, y_test)

x_pred_value = np.argmax(model.predict(x_test),axis=1)

for i in range(7):
    print("\nThe following digit is a ",x_pred_value[i]) 
    plt.imshow(x_test[i])
plt.show()

我希望代码能给我输出照片并使用以下行给出预测:“以下输出为...”

此外,这些是我收到的警告消息:

WARNING:tensorflow:From /anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
WARNING:tensorflow:From /anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/layers/core.py:143: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.
Instructions for updating:
Please use `rate` instead of `keep_prob`. Ra
2019-05-19 08:46:38.036080: 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
2019-05-19 08:46:38.036685: I tensorflow/core/common_runtime/process_util.cc:71] Creating new thread pool with default inter op setting: 4. Tune using inter_op_parallelism_threads for best performance.

0 个答案:

没有答案