如何使用手写识别模型作为API?

2024-04-26 02:45:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经使用Tensorflow和Keras通过IAM数据集创建了一个机器学习模型。如何将此模型作为API加载以预测图像?当我试图整合时,它显示出错误

return self.function(inputs, **arguments)
  File "test2.py", line 136, in resize_image
    return tf.image.resize_images(image,[56,56])
    NameError: name 'tf' is not defined

我使用从keras.型号导入load\u model并尝试预测图像笔迹。low_loss.hdf5是我试图集成的模型。你知道吗


def testmodel(image_path):
      global model
    # load the pre-trained Keras model
      model = load_model('low_loss.hdf5')
      model.summary()
      img = Image.open(image_path).convert("L")
      img = np.resize(image_path, (28,28,1))
      im2arr = np.array(img)
      im2arr = im2arr.reshape(1,28,28,1)
      y_pred = model.predict_classes(im2arr)
      return y_pred 

我希望预测图像手写数据。你知道吗


Tags: 数据path模型图像imageimgmodelreturn
2条回答

出现错误的原因是您没有在代码中导入TensorFlow,或者如果导入了TensorFlow,则没有提供别名。你知道吗

    import tensorflow as tf

你的错误是关于tf的,它没有加载。你知道吗

尝试:

import tensorflow as tf

相关问题 更多 >