dpthayer (3) [Avatar] Offline
#1
In the code listed in the e-book for chapter three where the author sets up the discriminator model and combines it with the generator I am getting a compile error when I try to run this in Jupyter Notebook . The error states that

ValueError: Layer model_1 was called with an input that isn't a symbolic tensor. Received type: <class 'tuple'>. Full input: [(28, 28, 1)]. All inputs to the layer should be tensors.

Then when you try to run the GAN in the code as follows

iterations = 1000
batch_size = 128
sample_interval = 200

# Run training for the specified number of iterations
train(iterations, batch_size)

you get the following error

C:\Users\DThayer\AppData\Local\conda\conda\envs\keras\lib\site-packages\keras\engine\training.py:478: UserWarning: Discrepancy between trainable weights and collected trainable weights, did you set `model.trainable` without calling `model.compile` after ?
'Discrepancy between trainable weights and collected trainable'
C:\Users\DThayer\AppData\Local\conda\conda\envs\keras\lib\site-packages\keras\engine\training.py:478: UserWarning: Discrepancy between trainable weights and collected trainable weights, did you set `model.trainable` without calling `model.compile` after ?
'Discrepancy between trainable weights and collected trainable'

and then the Notebook prints the following output.

0 [D loss: 1.654155, acc.: 82.03%] [G loss: 0.866902]


How well vetted is the code printed in the book.?
What should I do to fix this problem?

I feel you can talk about something till you're blue in the face but if the code doesn't compile and run it is an exercise in futility.

Thanks for taking the time to consider this problem

David Thayer
Vladimir B. (5) [Avatar] Offline
#2
Hi David,

Thank you for bringing this to our attention. You are completely right: it is unacceptable for readers to run into issues like these, even in an early pre-release version of a book. We are sincerely sorry.

Complete, revised implementation of the GAN in Chapter 3 can be found here:
https://github.com/GANs-in-Action/gans-in-action/blob/master/chapter-3/Chapter_3_GAN.ipynb

As for the first issue you experienced—”ValueError: Layer model_1 was called with an input that isn't a symbolic tensor”—I was unfortunately unable to reproduce it, even with the version of the code currently in MEAP. Perhaps it has to do with differing versions of Keras, TensorFlow, and/or Python? The code was run in a conda environment with the following versions: Keras==2.1.6; TensorFlow==1.8.0; Python==3.6.0. Which versions are you using? I can see if the error can be reproduced with the setup you used.

The second error/warning regarding the “Discrepancy between trainable weights and collected trainable weights” is actually by design. Recall that while training the Generator, we want to hold the Discriminator's trainable parameters constant, and vice versa. Accordingly, not all parameters will be trainable at any given time. After compiling the network, Keras warns us about this because (in pretty much every case except GAN) all trainable parameters should be, well, trainable. The updated implementation includes a line that suppresses the warning and provides an explanatory comment.

These issues will all be addressed in the upcoming update to MEAP and, ultimately, none of the errors will make it to the printed edition. Thank you for helping us make our book the best it can be.

Please do not hesitate to reach out with any other questions or feedback.

Thank you,
Vladimir
Vladimir B. (5) [Avatar] Offline
#3
Update: The revisions are now live in MEAP. The latest code is also available in our GitHub repository: https://github.com/GANs-in-Action/gans-in-action