ValueError: `decode_predictions` 需要一批预测即形状的二维数组样本,1000找到具有形状的数组:(1, 40)

问题描述

我已经在 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...