我训练了这个模型(从网站上直接复制粘贴)并用model.save(). 我现在想用它来对我生成的图像进行分类,所以我保存它们并将它们重塑为 28x28 像素,然后尝试将它们提供给模型,如下所示:
from matplotlib import image
img = image.imread('img.png')[:,:,:1] #so that the shape ends up being (28,28,1)
print(self.model.predict(img))
但是当我运行它时,我得到了一堆错误:
警告:tensorflow:模型是用形状 (None, 28, 28, 1) 为输入 Tensor("input_1:0", shape=(None, 28, 28, 1), dtype=float32) 构建的,但它被调用形状不兼容的输入(无、28、1、1)。...
ValueError: Input 0 of layer dense_12 is incompatible with the layer: expected axis -1 of input shape to have value 784 but received input with shape [None, 28]`
我已经进行了一些挖掘,根据这一行,输入的形状似乎存在问题:WARNING:tensorflow:Model was constructed with shape (None, 28, 28, 1) for input Tensor("input_1:0", shape=(None, 28, 28, 1), dtype=float32), but it was called on an input with incompatible shape (None, 28, 1, 1)
如何将图像转换为正确的形状?
互换的青春
相关分类