You are on page 1of 15

Mid-term Preparation

Capsule
28
Input shape: (1, 28, 28)
Apply a CNN with the following parameters 28

● Input channel = 1
● Output channel = 256
● Kernel size = 9
● Stride = 2
● Padding = 0

conv = Conv2d(1, 256, kernel_size=9, stride=1, padding=0)


x = conv(input)
print(x.shape)

The shape of the output x is:


28
Input shape: (1, 28, 28)
Apply a CNN with the following parameters 28

● Input channel = 1
● Output channel = 256
● Kernel size = 9
● Stride = 2
● Padding = 0

conv = Conv2d(1, 256, kernel_size=9, stride=1, padding=0)


x = conv(input)
print(x.shape)

The shape of the output x is: 256 20 20


Input is the output from previous step
Input shape: (256, 20, 20)
Define a set of 8 CNNs with the following parameters for each CNN
● Input channel = 256 conv_list = nn.ModuleList([nn.Conv2d(
in_channels=256,
● Output channel = 32
out_channels=32,
● Kernel size = 9 kernel_size=9,
● Stride = 2 stride=2,
● Padding = 0 padding=0) for _ in range(8)])

u1 = conv_list[0](input)
print(u1.shape)
Apply the 1st CNN in the set to the input
The shape of the output (u1) is:
Input is the output from previous step
Input shape: (256, 20, 20)
Define a set of 8 CNNs with the following parameters for each CNN
● Input channel = 256 conv_list = nn.ModuleList([nn.Conv2d(
in_channels=256,
● Output channel = 32
out_channels=32,
● Kernel size = 9 kernel_size=9,
● Stride = 2 stride=2,
● Padding = 0 padding=0) for _ in range(8)])

u1 = conv_list[0](input)
print(u1.shape)
Apply the 1st CNN in the set to the input
The shape of the output (u1) is: 32 6 6
Apply the all 8 CNNs from the set to the input and stack the output together.

The stacking will create a new dimension, this will be the 1st dimension.

conv_list = nn.ModuleList([nn.Conv2d(
in_channels=256,
out_channels=32,
kernel_size=9,
stride=2,
padding=0) for _ in range(8)])

u = stack([conv(x) for conv in conv_list])


print(u.shape)

The shape of the output (u) is:


Apply the all 8 CNNs from the set to the input and stack the output together.

The stacking will create a new dimension, this will be the 1st dimension.

conv_list = nn.ModuleList([nn.Conv2d(
in_channels=256,
out_channels=32,
kernel_size=9,
stride=2,
padding=0) for _ in range(8)])

u = stack([conv(x) for conv in conv_list])


print(u.shape)

The shape of the output (u) is: 8 32 6 6


Reshape the output u into a 2D vector where the 2nd dimension is 8.

u = u.view((-1, 8))
print(u.shape)

The new shape of the output (u) is: 8


Reshape the output u so that it become a

u = u.view((-1, 8))
print(u.shape)

The new shape of the output (u) is: 1152 8


Routing
Assume that we use the following decoder structure to reconstruct a digit.

The last FC layer output a 1-dimension vector. What is the shape of this vector in order to
reconstruct the original digit image?
Assume that we use the following decoder structure to reconstruct a digit.

The last FC layer output a 1-dimension vector. What is the shape of this vector in order to
reconstruct the original digit image?
Answer: 784 (28x28)
Thank you

You might also like