问题描述
我已经在 40 个类上训练了模型,并且通过移除顶层来训练它,但是它抛出了一个错误。现在在 colab 的下一个块中,如果我加载模型进行预测,它不会给出结果
from keras.applications.inception_resnet_v2 import preprocess_input
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications import imagenet_utils
def prepare_image(file):
img_path = '/content/drive/MyDrive/test imgs/'
img = image.load_img(img_path + file,target_size=(224,224))
img_array = image.img_to_array(img)
img_array_expanded_dims = np.expand_dims(img_array,axis=0)
return tf.keras.applications.inception_resnet_v2.preprocess_input(img_array_expanded_dims)
model = tf.keras.models.load_model("CNN resnet.h5")
preprocessed_image = prepare_image('mcd.jpg')
predictions = model.predict(preprocessed_image)
print("Predictions are",predictions)
results = imagenet_utils.decode_predictions(predictions)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)