Can Keras deal with input images with different size?

后端 未结 2 1563
無奈伤痛
無奈伤痛 2020-12-01 01:21

Can the Keras deal with input images with different size? For example, in the fully convolutional neural network, the input images can have any size. However, we need to spe

2条回答
  •  甜味超标
    2020-12-01 02:03

    Yes. Just change your input shape to shape=(n_channels, None, None). Where n_channels is the number of channels in your input image.

    I'm using Theano backend though, so if you are using tensorflow you might have to change it to (None,None,n_channels)

    You should use:

    input_shape=(1, None, None)

    None in a shape denotes a variable dimension. Note that not all layers will work with such variable dimensions, since some layers require shape information (such as Flatten). https://github.com/fchollet/keras/issues/1920

    For example, using keras's functional API your input layer would be:

    For a RGB dataset

    inp = Input(shape=(3,None,None))
    

    For a Gray dataset

    inp = Input(shape=(1,None,None))
    

提交回复
热议问题