liveBook · Manning

Tensor shape

As explained in Inside Deep Learning: Math, Algorithms, Models

The dimensions of a tensor, used to describe its layout and reshaping operations.

A tensor shape records the dimensions of data and determines how a network output is laid out. In a GAN, out_shape specifies the generator output and discriminator input shape. section 9.1.3

The shape (-1, 28, 28) keeps the batch dimension flexible while arranging each generated MNIST example as a 28-by-28 image. The final linear layer produces abs(np.prod(out_shape)) values, then View(out_shape) reshapes them. section 9.1.3

Reshaping a GAN output

Set out_shape = (-1, 28, 28), pass it to simpleGAN, and obtain G(z) in image-shaped batches rather than flat vectors.

How Inside Deep Learning: Math, Algorithms, Models covers it

How deep it goes
Defines shape notation and implements reshaping through output-size multiplication and View, without developing convolutional layouts.
Examples
Uses (-1, 28, 28) to reshape generated flat values into batches of black-and-white MNIST images.
What you can do after
Apply tensor shapes via PyTorch by configuring out_shape and reshaping network outputs with View.
How it connects
Links tensor shape to reshaping, batch dimensions, generator networks, discriminator networks, and MNIST images.

Also explained in

Compare how 5 books explain tensor shape →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Inside Deep Learning: Math, Algorithms, Models. The section links point to the parts of the book it draws on.