0
$\begingroup$

As far as I know, different image size is not a problem for convolutional layers, but what bothers me is the fully connected layer we have,after flattening last convolutional layer. Because, If I am not mistaken, the size of the fully connected layer is determined by the size of the last convolutional layer such that each nodes in it will have corresponding node in the fully connected layer. Using image with different image size will have different number of features at its last convolutional layer. So can we feed different sized images to the CNN

(This is not a question like "Should I train CNN with different image sizes?", I just want to know if it is possible)

$\endgroup$

1 Answer 1

2
$\begingroup$

Because, If I am not mistaken, the size of the fully connected layer is determined by the size of the last convolutional layer such that each nodes in it will have corresponding node in the fully connected layer.

If you use adaptive or global pooling layers, the problem does not appear, since you guarantee, at some point in your forward pass, the activations will conform to the size you set in the pooling layer.

See Keras GlobalPooling2D, for an example on global pooling.

Alternatively, PyTorch AdaptiveAvgPool2d implements adaptive pooling.

$\endgroup$
1
  • $\begingroup$ Thank you for your answer.Yes it could work for general cases but I realized that I fotget to mention I want to know what hapens in transfer learning case. I see Jeremy Howard at fastai course fine tune the network with input of 128x128 image size and later with 256 x 256 image size. What hapens the pre-trained model's weight at the fully connected layer when we feed different image size?Additionally, what you say can work if we design the NN that way but at fastai course he uses ResNet34 and he can feed different image size despite the fact that not all convolutional layer uses global pooling $\endgroup$
    – ikadorus
    Nov 19, 2019 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.