0

There is a very big question which always come up to my mind whenever I do preprocessing data before feeding it into CNN. When I resize the images to the correct size, I always ended up squeezing them in some way.

I have seen many people do the same thing, and I have looked everywhere for answers, but none of them really satisfy me, so my question is: Is this good for training? And how bad it would affect the network when testing it in real life?

Tien Dinh
  • 351
  • 1
  • 12

2 Answers2

2

You need a fixed size input dimension to your model. The alternative to resizing the images is either padding the data or training multiple models. For padding there are various methods which can create new problems. Multiple models for different sizes are too expensive because for each model you need a matching dataset.

The problems arising from resizing depend on your problem and the stretching factor. Convolutional NN are only to a small degree scale invariant, so stretching the images should work in many cases up to a certain degree.

To find an answer for your problem you can train two models and compare the performance: one with padding and one with scaling.

Benedikt S. Vogler
  • 554
  • 1
  • 5
  • 19
0

My best suggestion would be to not change the original ratio of the image. in this case, what you'd need to do is resize the image (keeping the same ratio) such that both dimensions are smaller or equal than the requested input size, and then pad it. for example. let's say your input to the network is 160x120, and you have a 500x500 image. in this case, resize the image to 120x120 and then pad it to 160x120.

Matan Hugi
  • 1,110
  • 8
  • 16
  • This is a great solution, however I think the network will be bias with padded images, and it would not be able to recognize a real life image with no padding – Tien Dinh Feb 20 '18 at 22:30
  • 1
    @LukeDinh - Unfortunately I don't have any empiric data to support my case at the moment, but for me this approach provided the best results among all other possibilities. – Matan Hugi Feb 20 '18 at 22:35