Tensorflow + Keras + Convolution2d: ValueError: Filter must not be larger than the input: Filter: (5, 5) Input: (3, 350)

假如想象 提交于 2019-11-28 13:50:00

The problem is that the order of input_shape() changes depending the backend you are using (tensorflow or theano).

The best solution I found was defining this order in the file ~/.keras/keras.json.

Try to use the theano order with tensorflow backend, or theano order with theano backend.

Create the keras directory in your home and create the keras json: mkdir ~/.keras && touch ~/.keras/keras.json

{
    "image_dim_ordering": "th", 
    "epsilon": 1e-07, 
    "floatx": "float32", 
    "backend": "tensorflow"
}

Just encountered the same problem myself, when I was following a tutorial. As pointed out by @Yao Zhang, the error is caused by the order in the input_shape. There are multiple ways to solve the problem.

  • Option 1: Change the order in input_shape

The line of your code

model.add(Convolution2D(32, 5, 5, border_mode='valid', input_shape=(3, IMG_WIDTH, IMG_HEIGHT)))

should be changed to

model.add(Convolution2D(32, 5, 5, border_mode='valid', input_shape=(IMG_WIDTH, IMG_HEIGHT, 3)))

which should be fine then.

  • Option 2: Specify image_dim_ordering in your layers

  • Option 3: Modify the keras configuration file by changing 'tf' to 'th' in your ~/.keras/keras.json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!