Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mismatch between code and paper in the gradient penalty algorithm #84

Closed
bfonta opened this issue Feb 11, 2019 · 1 comment
Closed

Mismatch between code and paper in the gradient penalty algorithm #84

bfonta opened this issue Feb 11, 2019 · 1 comment

Comments

@bfonta
Copy link

bfonta commented Feb 11, 2019

After comparing your code and your WGAN-GP paper, there seems to be a mismatch. When you perform the gradient penalty, you do the following:

    differences = fake_data - real_data
    interpolates = real_data + (alpha*differences)
    gradients = tf.gradients(Discriminator(interpolates), [interpolates])[0]
    slopes = tf.sqrt(tf.reduce_sum(tf.square(gradients), reduction_indices=[1]))
    gradient_penalty = tf.reduce_mean((slopes-1.)**2)
    disc_cost += LAMBDA*gradient_penalty

while in the paper it seems that you are describing the following (note the differences in the first two lines):

    differences = real_data - fake_data
    interpolates = fake_data + (alpha*differences)
    gradients = tf.gradients(Discriminator(interpolates), [interpolates])[0]
    slopes = tf.sqrt(tf.reduce_sum(tf.square(gradients), reduction_indices=[1]))
    gradient_penalty = tf.reduce_mean((slopes-1.)**2)
    disc_cost += LAMBDA*gradient_penalty

You are nevertheless still sampling from a line joining fake and real data, so it should not make much difference.

@bfonta bfonta changed the title Possible bug in the gradient penalty algorithm Mismatch between code and paper in the gradient penalty algorithm Feb 11, 2019
@a411919924
Copy link

The 1st case:
interpolates = real + alpha*(fake-real) = (1-alpha)real + alphafake
The 2nd case:
interpolates = fake + alpha*(real-fake) = alpha * real + (1-alpha)*fake

The two results are equal since the variable alpha is random float number between 0 and 1.

I wish this helps.

@bfonta bfonta closed this as completed Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants