Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
