用训练好的模型识别自己手写的图片时报错
def load_preprosess_image(path):
img_raw = tf.io.read_file(path)
img_tensor = tf.cast(tf.image.decode_jpeg(img_raw, channels=1), tf.float32)
img_tensor = tf.image.resize(img_tensor, [28, 28])
img = img_tensor / 255.0
return img
if name == 'main':
app = Painter('./img/')
app.run()
ID = []
for count in range(app.count):
img = load_preprosess_image('./img/' + str(count) + '.jpg')
np.expand_dims(img, axis=-1)
model = tf.keras.models.load_model('./model.h5')
prediction = model.predict(img.numpy().reshape(1, 28, 28, 1))
result = np.argmax(prediction)
ID.append(result)
print('识别的数字为:', end='')
for item in ID:
print(item, end='')
环境Python3.6,tensorflow1.15,看到网上说是numpy版本的问题,我卸载分别重新装了1.17,1.18,1.19版本,还是报错,