[英]How to use Padding in conv2d layer of specific size
My input size image is : 256 * 256
我的输入尺寸图像是:
256 * 256
Conv2d Kernal Size : 4*4
and strides at 2*2
. Conv2d 内核大小:
4*4
和2*2
步幅。
The output will be 127*127
.输出将是
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.我想传递给 Max Pool 为此我想应用填充以使其
128*128
以便池工作良好并且池输出将用于其他层。
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. tf.layers.conv2d
有一个padding
参数,您可以使用它来执行此操作。 The default is "valid"
which means no padding is done, so each convolution will slightly shrink the input.默认值为
"valid"
,这意味着不进行填充,因此每个卷积都会略微缩小输入。 You can pass padding="same"
instead.您可以改为传递
padding="same"
。 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.这是在步幅之前,因此使用 2 的步幅仍将下采样 2 倍。在您的示例中,使用
padding="same"
应该导致卷积输出的大小为 128x128。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.