Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone explain each output size calculation for this generator? class Generator ( nn . Module ) : def _ _ init _ _ (

Can someone explain each output size calculation for this generator?
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, stride=2, padding=0, final_layer=True),
)
def make_gen_block(self, input_channels, output_channels, kernel_size=3, stride=2, padding=0,final_layer=False):
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)
def unsqueeze_noise(self, noise):
return noise.view(len(noise), self.z_dim, 1,1)
def forward(self, noise):
x = self.unsqueeze_noise(noise)
return self.gen(x)
def get_noise(n_samples, z_dim, device='cpu'):
return torch.randn(n_samples, z_dim, device=device)

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

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions

Question

3 What are the aims of appraisal?

Answered: 1 week ago

Question

7 Compare and contrast evaluative and developmental appraisal.

Answered: 1 week ago