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

我使用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

我已经使用 from keras.models import load_model 加载了模型,并且尝试预测手写图像。我尝试集成的模型是 low_loss.hdf5

def testmodel(image_path):      global model    # 加载预训练的Keras模型      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 

我希望预测手写图像数据。


回答:

您遇到错误是因为您在代码中没有导入TensorFlow,或者如果您已经导入了,您没有给它一个别名。

    import tensorflow as tf

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注