In the Convolution2D docs of keras, I found there are no details on definition of padding
keras.layers.convolutional.Convolution2D(nb_filter,
nb_row,
nb_col,
init='glorot_uniform',
activation=None,
weights=None,
border_mode='valid',
subsample=(1, 1),
dim_ordering='default',
W_regularizer=None,
b_regularizer=None,
activity_regularizer=None,
W_constraint=None,
b_constraint=None,
bias=True)
the subsample
argument is
tuple of length 2. Factor by which to subsample output. Also called strides elsewhere.
and I think it is stride.
And the border_mode
argument is
'valid', 'same' or 'full'. ('full' requires the Theano backend.)
valid
and same
are also arguments in TensorFlow's conv2d function.
How to define the padding, how to set the value of it?
What you want is the ZeroPadding2D layer, just put it before a convolutional layer. This is more flexible than just putting this functionality inside Convolution2D.
The accepted answer above mentioned the ZeroPadding2D layer in Keras. However, if you want to use some other kinds of padding which are not provided by Keras, such as reflection padding, you should implement them by yourself.
As far as I know, there are two ways to custom padding layer in Keras: 1. Use Lambda layer in Keras, and call the padding function from Keras's backend(typically TensorFlow). 2. Define your own Layer class. See this question for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With