如何在分类模型中对单个图像进行预测?
How to make predictions for a single image in a classification model?
我关注了一些协作,能够训练模型并评估其准确性。但是,它没有显示如何对单个输入进行预测。我只是想测试模型以预测一个新示例而不是一批示例。
当我使用 model.predict(image)
时,图像是图像的 NumPy 数组,我收到此错误
Error when checking input: expected keras_layer_input to have 4 dimensions, but got array with shape (2, 1)
我如何预测单个图像并找到它 class?
Link 我的合作伙伴:https://colab.research.google.com/drive/1dBwo43ULo99FsUQoxYRsaATIpCANPtkh
您可以通过扩展第一个维度来构建大小为 1 的批次:
image = np.expand_dims(image, 0)
话虽这么说,您的图片应该是 (height, width, channels)
或 (channels, height, width)
的形状,但从您收到的错误消息来看情况并非如此。
该错误表明您尝试发送给模型的图像不是它期望的格式
您可能需要进行相同的预处理(重塑、
缩放等)对于您的输入数据,对于用于训练的数据
如果您分享训练代码,我们可以详细说明具体需要做什么
我关注了一些协作,能够训练模型并评估其准确性。但是,它没有显示如何对单个输入进行预测。我只是想测试模型以预测一个新示例而不是一批示例。
当我使用 model.predict(image)
时,图像是图像的 NumPy 数组,我收到此错误
Error when checking input: expected keras_layer_input to have 4 dimensions, but got array with shape (2, 1)
我如何预测单个图像并找到它 class?
Link 我的合作伙伴:https://colab.research.google.com/drive/1dBwo43ULo99FsUQoxYRsaATIpCANPtkh
您可以通过扩展第一个维度来构建大小为 1 的批次:
image = np.expand_dims(image, 0)
话虽这么说,您的图片应该是 (height, width, channels)
或 (channels, height, width)
的形状,但从您收到的错误消息来看情况并非如此。
该错误表明您尝试发送给模型的图像不是它期望的格式
您可能需要进行相同的预处理(重塑、 缩放等)对于您的输入数据,对于用于训练的数据
如果您分享训练代码,我们可以详细说明具体需要做什么