简体   繁体   中英

How to use Padding in conv2d layer of specific size

My input size image is : 256 * 256

Conv2d Kernal Size : 4*4 and strides at 2*2 .

The output will be 127*127 . I want to pass to Max Pool for this i want to apply padding to make it 128*128 so that pooling works well and pooling output will be used in other layers.

How i can apply padding for this conv.

conv1 = tf.layers.conv2d(x, 32, (4,4),strides=(2,2), activation=tf.nn.relu)

tf.layers.conv2d has a padding parameter that you can use to do this. The default is "valid" which means no padding is done, so each convolution will slightly shrink the input. You can pass padding="same" instead. This will apply padding such that the output of the convolution is equal in size to the input. This is before strides, so using a stride of 2 will still downsample by a factor 2. In your example, using padding="same" should result in the convolution output to have size 128x128.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM