cs231n / cs231n.github.io

Public facing notes page
MIT License
10.06k stars 4.06k forks source link

Assignment 3 GANs-TensorFlow.ipynb #206

Open sunskyhsh opened 5 years ago

sunskyhsh commented 5 years ago

I was doing Assignment 3 of 2018 version, but I ran into one error in the function run_a_gan:

---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
...
InvalidArgumentError: Incompatible shapes: [96,1] vs. [128,1]
     [[Node: gradients/add_grad/BroadcastGradientArgs = BroadcastGradientArgs[T=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](gradients/add_grad/Shape, gradients/add_grad/Shape_1)]]

Then I checked the size of each batch and found that the size of the last batch is 96 rather than the expected 128. I guess others may run into this error too, and then they can find the cause here.

djape24394 commented 4 years ago

I had the same issue, but it was actually the error with computing the discriminator loss. I called cross entropy for real and fake scores, than added those two and used tf.math.reduce_mean after addition, but if you look at the definition of discriminator loss, you need to sum the averaged cross entropy losses computed separately for real and fake images.