The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

pietz (4) [Avatar] Offline
Thanks for the book. I'm enjoying it so far. I liked that you took multiple turns/analogies/examples to explain the main concepts in chapter 1. Sometimes you need to hear things more than once to fully understand them. I have a few comments and questions about the code in chapter 3. All of this based on V5 that was released today.

1) You have a style of defining models in Keras that I've never seen before:

model = Sequential()
# multiple model.add()
img = Input(shape=img_shape)
prediction = model(img)
return Model(img, prediction)

I had to run these to see that this actually works. I'm more used to doing it this way:
model = Sequential()
# multiple model.add()
return model

In this case the first layer would have an input_shape parameter. I want to argue that my example is shorter, more common and less confusing. Or am I missing something? It's the same when connecting the two networks. Shouldn't you be able to simple throw both of them in a Sequential model one after the other?

2) I don't understand the use of the line

gen_imgs = generator.predict(z)

in the section of training the generator

3) When setting the discriminator to not trainable you're doing it on the variable that we also use for training the discriminator. The training loop doesn't contain any lines for setting it back to trainable. I know it works because I ran the code but I don't understand why it works. Shouldn't the discriminator be untrainable because the weights are fixed?

4) You're essentially training the discriminator on 2 batches and the generator only on 1. Is that a hint that a the discriminator needs twice the training steps?

5) Is there a reason for creating a new noise vector for the generator training? Why not use the one we already created?

6) Why do we use the "real" labels for training the generator batch and not the "fake" labels? The generator produces the fakes after all. I can confirm that it needs to be this way to work but shouldn't there be some explanation about this? Did I miss it?

Vladimir Bok (10) [Avatar] Offline
Hi Paul,

Glad you are enjoying our book. Please see below for responses to your questions:

1) In our implementation, the input layers are defined as part of the Model that gets returned from the function; however, we understand how that can be confusing. Thanks to feedback from readers like you, we plan to refactor the implementation before the book goes to print.

This produces a batch of fake images that the Generator uses to fool the Discriminator.

3) Note that the combined model, in which the Discriminator is set to untrainable, is used to train the Generator only. The Discriminator is trained as a standalone, and independently compiled, model.

4) The Discriminator has to learn to identify real examples as real and fake examples as fake. As a result, it needs to be trained using both real and fake images.

5) Both implementations would work. We chose to produce new random noise vector each time for better readability.

6) Recall that the goal of the Generator is to fool the Discriminator into classifying fake examples as real. In other words, the Generator wants the Discriminator to assign the “real” label to the fake examples it produces.

I hope this helps clarify things. Please don’t hesitate to reach out with any other questions.

Thank you,
Vladimir //