问题描述:
由于不同的backend(theno或tensorflow)对输入inpu_img维度要求的次序不一样,所以如果弄混就会出现上述错误.
解决方法:
方法一:
假设输入为:
model.add(ZeroPadding2D((1, 1), batch_input_shape=(1, 3, img_width, img_height)))
将其改为
:
model.add(ZeroPadding2D((1, 1), batch_input_shape=(1, img_width, img_height, 3)))
方法二:
在网络层明确指明:image_dim_ordering,
即输入图像的维度次序
;
例如加上如下语句
:
from keras import backend as K
if K.image_dim_ordering() == 'th':
model.add(ZeroPadding2D((1, 1), batch_input_shape=(1,3,img_width, img_height)))
else:
model.add(ZeroPadding2D((1, 1), batch_input_shape=(1,img_width, img_height,3)))
方法三
:
修改文件’
~/.keras/keras.json’
中的’
tf
’
为’
th
’.
Reference:
http://stackoverflow.com/questions/39848466/tensorflow-keras-convolution2d-valueerror-filter-must-not-be-larger-than-t