When training a CNN one option is either to zero pad an image to make it bigger or upsample it. When should I choose each one?
What criteria is leveraged for choosing a method?
Data Science Stack Exchange is a question and answer site for Data science professionals, Machine Learning specialists, and those interested in learning more about the field. It only takes a minute to sign up.Sign up to join this community
It depends on application.
For upsampling, Keras documentation says:
Repeats the rows and columns of the data by size and size respectively.
For zero padding, Keras documentation says:
This layer can add rows and columns of zeros at the top, bottom, left and right side of an image tensor.
So, imagine You have picture of sharp edge shapes, and You want to build model that could learn to distinguish them. In that case, I would likely go with UpSampling, because You would have extra data, and Your shape structure wouldn't be ruined. While, with smooth curved edges, smoothness could be ruined. In that case, I would go with ZeroPadding, because it won't touch inner data, it will only add zeros side the borders.
This is my intuition about those two functions, don't take it for granted. The best option You could do is to test both on Your sample and see the output.
Oh, well, let's say it depends on your task and model. For instance, in autoencoders, there are two main choices for upsampling. You can employ transposed convolution or rescaling. The better choice is the latter case due to the fact that the former can lead to checker-board artifacts. About zero padding, it is usually done in almost all CNNs if you use the same convolution which means the height and width of the output activation maps should be equal to the size of their input counterparts. Zero padding is usually done when you want to extract features from inputs with conv layers. The main reason we use zero padding is that the boundary locations in the inputs of the conv layers affect more entries in the output activation map.