I am new to CNNs, and I'm trying to follow along with a Pytorch DCGAN tutorial by reimplementing it in Keras. Clearly there are some differences in the frameworks, but in particular I am struggling to understand how the input noise vector is handled per the following image of the generator architecture:

Generator architecture

The code goes on to define the first layer of the network as:

# input is Z, going into a convolution
nn.ConvTranspose2d( nz, ngf * 8, 4, 1, 0, bias=False),
nn.BatchNorm2d(ngf * 8),
# state size. (ngf*8) x 4 x 4

Where nz = 100 (size of noise vector) and ngf = 64.

How does that work? Is the noise vector implicitly reshaped by that first convolutional layer to a (?, 4, 4) tensor, as suggested by the diagram? How would that even work? Is there an implicit dense connection between the noise vector and the convolutional layer? How does that first layer result in a tensor of shape (64*8, 4, 4) per the comment?


1 Answer 1


Turned out to be a dumb question in the end - the noise vector is simply treated as a 1x1 array with "depth" (i.e. number of channels/features) of 100, which can of course be processed by the ConvTranspose2d layer. This reshaping to 1x1x100 just has to be explicitly specified as the first layer in keras:

model.add(Reshape((1, 1, 100), input_shape=(100,)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.