【发布时间】:2018-01-20 14:30:41
【问题描述】:
我正在使用 keras 为我的 CNN 加载我的 model.h5(权重文件)。 我正在使用 VGG-16 架构。我的训练数据由大小为 numpy 的数组组成(2590、3(对于 RGB)、875(宽度像素)、375(高度像素))。我已经完成了数据的训练,现在我正在使用 model.h5(带权重)进行预测。 我遇到了以下错误。
expected zero_padding2d_1_input to have shape (None, 3, 875, 375) but got array with shape (1, 375, 875, 3)
这是我的 VGG-16 CNN 的顶部 sn-p
def VGG_16(weights_path=None):
model = Sequential()
model.add(ZeroPadding2D((1,1),input_shape=(3,875,375)))
model.add(Convolution2D(64, 3, 3, activation='relu'))
model.add(ZeroPadding2D((1,1)))
model.add(Convolution2D(64, 3, 3, activation='relu'))
model.add(MaxPooling2D((2,2), strides=(2,2)))
.......... Continued ..........
这是我尝试过的 第一:我看了这些帖子:Error when checking target: expected dense_20 to have shape (None, 3) but got array with shape (1200, 1)
我正在尝试的代码:
model = VGG_16('/path/to/weights/file....../model.h5')
print("Created model")
img = np.array([np.array(Image.open(path_to_image_i_want_to_convert))])
img.reshape(1, 3, 875,375)
try:
prediction = model.predict(img)
print(prediction)
print("I finished your prediction")
except Exception as e:
print(str(e))
但是,这总是会引发错误。
预期 zero_padding2d_1_input 的形状为 (None, 3, 875, 375) 但得到的数组的形状为 (1, 375, 875, 3)
一个 numpy 数组怎么可能有一个无维度? 我究竟做错了什么?如何修改我的代码以便仅使用单个图像进行预测。
任何帮助将不胜感激谢谢!
【问题讨论】:
标签: python numpy tensorflow keras