tensorflow - 如何在 model.predict 解码预测中使用 38 个类而不是 1000 个类
问题描述
每次使用 resnet50 深度学习模型在 decode_predictions 中引发错误消息时,我都会发现植物病害检测错误
错误
需要一批预测(即形状的二维数组(样本,1000))。找到具有形状的数组:(1, 38)"
enter code here
model = ResNet50(weights='imagenet',include_top=False,classes=38)
try:
model = load_model('/content/drive/My
Drive/color/checkpoints/ResNet50_model_weights.h5')
print("model loaded")
except:
print("model not loaded")
img_path = '/content/drive/My Drive/color/test/0/appleblackrot188.jpg'
img = image.load_img(img_path, target_size=(300, 300))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = model.predict(x)
print('Predicted:', decode_predictions(preds,top=3)[0])
解决方案
您可以尝试使用预处理功能:
import tensorflow as tf
# Using the keras wrapper on tensorflow (it must be the same using just keras).
IMAGE = [] # From image source, i did it from the camera.
toPred = tf.keras.applications.resnet50.preprocess_input(np.expand_dims(tf.keras.preprocessing.image.img_to_array(IMAGE), axis=0))
也许这可以帮助:)
推荐阅读
- reactivesearch - AppBase / 反应式搜索:从 id 数组中过滤的策略
- python - 列出一组给定数字的组合及其总数
- java - 向从 Firebase 实时数据库检索的号码发送短信
- dart - 如何在 Flutter 中使用 bloc 模式在 UI 上显示函数回调和错误?
- haskell - 如何为具有不同构造函数 Haskell 的类型实例化 Eq(或任何类)
- javascript - 如何从对象数组中获取唯一的类别数据
- java - Java上字符串添加的奇怪行为
- c++ - c++ 中有没有办法使用点运算符而不是 -> 来表示 pSomePointer->pValue->nSubvalue
- go - 如何在 golang 中实例化函数类型?
- laravel - 无法使用带有 Laravel 5.4 的 sendgrid 发送电子邮件并发现错误