facebookresearch / pytorch_GAN_zoo

A mix of GAN implementations including progressive growing
BSD 3-Clause "New" or "Revised" License
1.62k stars 271 forks source link

Bug in miniBatchStdDev #69

Closed PgLoLo closed 5 years ago

PgLoLo commented 5 years ago

As far, as I understand, the miniBatchStdDev layer has a bug in this line

There the group and batch dimensions swap so after that std outputs tiled incorrectly.

We can try this on this code sample:

a = torch.tensor([0, 0, 0, 0, 1, 2, 3, 4, 100, 200, 300, 400], dtype=torch.float32)
a = a.reshape(-1, 1, 1, 1)
miniBatchStdDev(a, 4)[:, -1, 0, 0]

The output would be

tensor([ 99.5100,  99.5100,  99.5100,  99.5100, 149.1763, 149.1763, 149.1763,
        149.1763, 188.8589, 188.8589, 188.8589, 188.8589])

wich is obviously incorrect and should be

tensor([99.5100,  149.1763, 188.8589, 99.5100,  149.1763, 188.8589, 99.5100,  
        149.1763, 188.8589, 99.5100,  149.1763, 188.8589])

Am I right?

Molugan commented 5 years ago

Indeed it seems that you're right. I'll correct it right away.

I'll need to test it but there should be a PR within a week.

Molugan commented 5 years ago

Thanks for pointing the bug, it was well hidden.

Molugan commented 5 years ago

https://github.com/facebookresearch/pytorch_GAN_zoo/pull/70