(MOOC)TensorFlow入门实操课程model.predict([[test_images[0]/255]])报错解决

运行时报错:
WARNING:tensorflow:Model was constructed with shape (None, 28, 28) for input Tensor(“flatten_1_input:0”, shape=(None, 28, 28), dtype=float32), but it was called on an input with incompatible shape (None, 28).

修改
model.predict([[test_images[0]/255]])

model.predict((test_images[0]/255).reshape(1,28,28,1))

答案来自自老师答疑区

详细代码:

import numpy as np
#model.predict([[test_images[0]/255]])
print(np.argmax(model.predict((test_images[0]/255).reshape(1,28,28,1))))
print(test_labels[0])
import matplotlib.pyplot as plt
plt.imshow(train_images[0])

你可能感兴趣的:(tensorflow,tensorflow,python)