Image classification:

I am having a data set of image collection more than 10k but even though all are the same image but taken in different sizes (pixels into pixels) some are in square and some are in a rectangle. When I am trying to make them similar, I have planned to zoom to the image exactly where my learning is concentrated but I don't know how to do this.

Note these are color images.

I don't whether this is the good approach or any approach is appreciable.


2 Answers 2


You don't need to change their size. You can zero pad the images when you feed them into the Network. Zero padding creates a "frame of zeros" around each image, so that they all take equal shape.

conv layers in Keras / TensorFlow 2.0 come with already built-in zero padding arguments.


One obvious way is resizing images to a fixed size either by padding zeros for smaller ones or cropping for larger ones.

But a better one is just pass the image as it is to the convolution layers. Convolution layers works irrespective of image size variation.

The problem comes with fully connected layers, because they need exact input size. For this you can use max pooling layer before fully connected layer to convert variable size input to fixed size.

In this way we don't loose information neither add noise, which happens with resizing.

  • $\begingroup$ Thanks ashukid, all images containing different resolution. Some images got already zoomed in and some images are squared resolution. Example Atos blind datasets in kaggle.. that's what a actually I am doing $\endgroup$ Commented Jul 7, 2019 at 16:31
  • $\begingroup$ This is not totally correct! although convolution layers work with any image size, if the subsequent layers contain fully connected ones, you have to fix your resolution from the beginning. $\endgroup$
    – Moher
    Commented Oct 28, 2020 at 15:41

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.