Padding and Stride Padding and Stride In [1]: from mxnet import nd - - PowerPoint PPT Presentation

padding and stride padding and stride
SMART_READER_LITE
LIVE PREVIEW

Padding and Stride Padding and Stride In [1]: from mxnet import nd - - PowerPoint PPT Presentation

2/23/2019 padding-and-strides slides Padding and Stride Padding and Stride In [1]: from mxnet import nd from mxnet.gluon import nn # Takes convolution operation and applies it to X def comp_conv2d(conv2d, X): conv2d.initialize() # Add two extra


slide-1
SLIDE 1

2/23/2019 padding-and-strides slides http://127.0.0.1:8000/padding-and-strides.slides.html?print-pdf/#/ 1/3

Padding and Stride Padding and Stride

In [1]: from mxnet import nd from mxnet.gluon import nn # Takes convolution operation and applies it to X def comp_conv2d(conv2d, X): conv2d.initialize() # Add two extra empty dimensions to X X = X.reshape((1, 1) + X.shape) Y = conv2d(X) return Y.reshape(Y.shape[2:])

slide-2
SLIDE 2

2/23/2019 padding-and-strides slides http://127.0.0.1:8000/padding-and-strides.slides.html?print-pdf/#/ 2/3

Padding Padding

In [2]:

Strides Strides

In [3]: conv2d = nn.Conv2D(1, kernel_size=3, padding=1) X = nd.random.uniform(shape=(8, 8)) # Padding of 1 leaves shape unchanged for 3x3 convolution comp_conv2d(conv2d, X).shape conv2d = nn.Conv2D(1, kernel_size=3, padding=1, strides=2) comp_conv2d(conv2d, X).shape Out[2]: (8, 8) Out[3]: (4, 4)

slide-3
SLIDE 3

2/23/2019 padding-and-strides slides http://127.0.0.1:8000/padding-and-strides.slides.html?print-pdf/#/ 3/3

Asymmetric kernels, padding and strides Asymmetric kernels, padding and strides

We can use different strides, different kernel sizes and different padding for height and

  • width. This can be used, e.g. to adjust the size to a desired shape (4:3 to 1:1).

In [4]: # pad only vertically and use different strides on the 8x8 image conv2d = nn.Conv2D(1, kernel_size=(3, 5), padding=(0, 1), strides=(3, 4)) comp_conv2d(conv2d, X).shape Out[4]: (2, 2)