【问题标题】:Error while predicting classes of an trained DNN model预测训练有素的 DNN 模型的类别时出错
【发布时间】:2020-07-21 10:52:07
【问题描述】:

我使用以下程序来预测我的图像的类别。

from tensorflow.keras.preprocessing.image import load_img, img_to_array

x = load_img("8-SignLanguageMNIST/test1.jpg", target_size = (28, 28))

x = img_to_array(x)

x = np.expand_dims(x, axis = 0)

x = np.vstack([x])

classes = model.predict(x)
print(classes[0])

我用于训练的图像是形状 (28, 28, 1)。

我在这里上传了一个形状为 (28, 28, 3) 的 RGB 图像,我尝试将该图像转换为灰度然后进行预测,但一直出现以下错误。

ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 1 but received input with shape [None, 28, 28, 3]

谁能告诉我我做错了什么,并帮助我解决这个问题。

【问题讨论】:

标签: python tensorflow keras prediction


【解决方案1】:

您需要申请conversion to grayscale,如下所示:

load_img(path, color_mode='grayscale')

【讨论】:

    猜你喜欢
    • 2022-07-31
    • 2022-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 2020-01-15
    • 2020-09-14
    • 1970-01-01
    相关资源
    最近更新 更多