Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am trying to understand a code, I am confused about the test cells. When i am printing the shape of the output it is

I am trying to understand a code, I am confused about the test cells. When i am printing the shape of the output it is hidden_output.shape =(num_test, 20,4,4), test_hidden_block_stride(hidden_output).shape)==(num_test, 20,10,10) and Gen_output.shape=(num_test, 1,28,28) for Mnist dataset. I am trying to understand how the sizes are being calculated here. Any help will be greatly appreciated! class Generator(nn.Module):
def __init__(self, z_dim=10, im_chan=1, hidden_dim=64):
super(Generator, self).__init__()
self.z_dim = z_dim
# Build the neural network
self.gen = nn.Sequential(
self.make_gen_block(z_dim, hidden_dim *4),
self.make_gen_block(hidden_dim *4, hidden_dim *2, kernel_size=4, stride=1),
self.make_gen_block(hidden_dim *2, hidden_dim),
self.make_gen_block(hidden_dim, im_chan, kernel_size=4, final_layer=True),
)
def make_gen_block(self, input_channels, output_channels, kernel_size=3, stride=2, padding=0,final_layer=False):
# Build the neural block
layers =[]
layers.append(nn.ConvTranspose2d(input_channels, output_channels, kernel_size, stride, padding, output_padding=padding))
if not final_layer:
layers.append(nn.BatchNorm2d(output_channels))
layers.append(nn.ReLU(True))
else:
layers.append(nn.Tanh())
return nn.Sequential(*layers)
# Testing
gen = Generator()
num_test =100
# Test the hidden block
test_hidden_noise = get_noise(num_test, gen.z_dim)
test_hidden_block = gen.make_gen_block(10,20, kernel_size=4, stride=1)
test_uns_noise = gen.unsqueeze_noise(test_hidden_noise)
hidden_output = test_hidden_block(test_uns_noise)
# Check that it works with other strides
test_hidden_block_stride = gen.make_gen_block(20,20, kernel_size=4, stride=2)
test_final_noise = get_noise(num_test, gen.z_dim)*20
test_final_block = gen.make_gen_block(10,20, final_layer=True)
test_final_uns_noise = gen.unsqueeze_noise(test_final_noise)
final_output = test_final_block(test_final_uns_noise)
# Test the whole thing:
test_gen_noise = get_noise(num_test, gen.z_dim)
test_uns_gen_noise = gen.unsqueeze_noise(test_gen_noise)
gen_output = gen(test_uns_gen_noise)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

=+ How about one you felt had acted in a hypocritical way?

Answered: 1 week ago