Answered step by step
Verified Expert Solution
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 hiddenoutput.shape numtest, testhiddenblockstridehiddenoutputshapenumtest, and Genoutput.shapenumtest, for Mnist dataset. I am trying to understand how the sizes are being calculated here. Any help will be greatly appreciated! class GeneratornnModule:
def initself zdim imchan hiddendim:
superGenerator selfinit
self.zdim zdim
# Build the neural network
self.gen nnSequential
self.makegenblockzdim, hiddendim
self.makegenblockhiddendim hiddendim kernelsize stride
self.makegenblockhiddendim hiddendim
self.makegenblockhiddendim, imchan, kernelsize finallayerTrue
def makegenblockself inputchannels, outputchannels, kernelsize stride paddingfinallayerFalse:
# Build the neural block
layers
layers.appendnnConvTransposedinputchannels, outputchannels, kernelsize, stride, padding, outputpaddingpadding
if not finallayer:
layers.appendnnBatchNormdoutputchannels
layers.appendnnReLUTrue
else:
layers.appendnnTanh
return nnSequentiallayers
# Testing
gen Generator
numtest
# Test the hidden block
testhiddennoise getnoisenumtest, gen.zdim
testhiddenblock gen.makegenblock kernelsize stride
testunsnoise gen.unsqueezenoisetesthiddennoise
hiddenoutput testhiddenblocktestunsnoise
# Check that it works with other strides
testhiddenblockstride gen.makegenblock kernelsize stride
testfinalnoise getnoisenumtest, gen.zdim
testfinalblock gen.makegenblock finallayerTrue
testfinalunsnoise gen.unsqueezenoisetestfinalnoise
finaloutput testfinalblocktestfinalunsnoise
# Test the whole thing:
testgennoise getnoisenumtest, gen.zdim
testunsgennoise gen.unsqueezenoisetestgennoise
genoutput gentestunsgennoise
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started