In Chapter 2, Introduction to Generative Models, we described GANs as a two-player min-max game, in which the Discriminator and Generator take turns. Informally speaking, the Discriminator learns to identify whether a sample is real or fake while the Generator tries to produce samples that the Discriminator believes to be real.
The implementation of this procedure is, indeed, similar to the informal description. Although, in our first implementation, each model will take one turn at a time, it is possible, and sometimes desirable, to have one model taking more turns than the other.
Our training procedure starts with sampling fake data produced by the Generator and real data. Note that, at this stage, we are not updating the Generator and no gradient is flowing through. Let's start with our method header:
def train(ndf=64, ngf=64, z_dim=100, lr_d=2e-4, lr_g...