“padding=same” means input and output will be same but if my p is different number not using formula, p=(f-1)/2, what happens? for example, filter is 5X5 and p=1 and padding=same, then what happen? computer will still make same output with input?
Please see the details of padding in this link. When in doubt, create a model following your question and observe layer output shapes via print(model.summary())
The formula for the output size of a normal convolution layer is:
n_{out} = \displaystyle \lfloor \frac {n_{in} + 2p - f}{s} \rfloor + 1
Where f is the filter size, p is the padding and s is the stride value. If you want “same” padding, then you set n_{out} = n_{in} and solve for the p value given the other values.
One tricky and potentially confusing thing to realize is that TensorFlow/Keras implement “same” padding in a way that you could consider slightly surprising: they compute the p value for “same” assuming s = 1. So if your s value is > 1, then the output size is not actually the same.
Update: it turns out there is a good reason why “same” padding is only calculated with stride = 1. If you actually solve for the amount of padding required to get the same sized output when stride is 2 or greater, the numbers are crazy. Here’s a more recent thread that shows some examples of what would be required.