我想用我训练过的keras模型预测输入图像。但是,模型的输入形状与样本形状不同。我将package main
func Main() {
// do your main
}
func main() {
for {
Main()
}
}
用作channels_first
作为模型。我的图片image_data_format
以下是我从keras读取路径图像和预测错误的代码。
(img_width, img_height) = (150, 150)
您可以看到模型的输入形状为from scipy import misc
img_width, img_height = 150, 150
def get_img(img_path):
"""read image file from path
"""
img = misc.imread(img_path)
img_size = (img_width, img_height)
return misc.imresize(img, img_size)
>>> model.input.shape
TensorShape([Dimension(None), Dimension(150), Dimension(150), Dimension(3)])
>>> sample = get_img('mysample.png')
>>> sample.shape
150, 150, 3
,其中包含(None, 150, 150, 3)
。因此,我试图用None
重塑我的样本,但它不起作用。
None
示例的sample.reshape(img_height, img_width, 3, None)
TypeError: 'NoneType' object cannot be interpreted as an integer
也不起作用:
shape (img_height, img_width, 3, 1)
在这种情况下,如何重塑输入图像以适合模型输入形状?