Inserting noise section

is there possibly an error for the noise insertion section of the style gan components assignment. I in one section of the grader all of the checks are greater than except one.

assert torch.abs((inject_noise(fake_images) - fake_images).std(0)).mean() > 1e-4
assert torch.abs((inject_noise(fake_images) - fake_images).std(1)).mean() < 1e-4
assert torch.abs((inject_noise(fake_images) - fake_images).std(2)).mean() > 1e-4
assert torch.abs((inject_noise(fake_images) - fake_images).std(3)).mean() > 1e-4

Check that the per-channel change is roughly normal

It’s been a while since I looked at this assignment, but I think the point is that not all 4 of the dimensions are handled the same way there. Look at how dimension 1 is treated in noise injection: the size of that dimension is 1, but the other dimensions are all non-trivial. What effect will that have in the resulting behavior? :nerd_face:

ok, thanks. At least know what direction to look in now. Thanks!

do you think randn is the right function to use to set the weights?

torch.randn([1, channels, 1, 1])

Yes, that’s the way I did it. Mind you, I worked this assignment > 2 years ago, so I don’t know if they’ve subsequently updated the assignment in any way.

I just got the latest version of the notebook and there is only one minor change since 2 years ago in the template code that they provide. So I think that weight initialization should still be correct.

ok, thanks again. There are only two coding blocks in this section so I have no clue what I could be missing. Using the image shape as the noise shape.

What error are you getting?

Note that the noise shape is not the same as the image shape, right? That was what I was referring to earlier about why the test for dimension 1 is different. Oh, ok, that was part of the code you need to write, so that is probably where your bug is. The shape of the noise is the same as the shape of the image in every dimension except dimension 1. Dimension 1 has only 1 element for noise.

3 Likes

That’s what I think I’m trying, but still failing at least one of the tests;

noise_shape = (1, image.shape[1], image.shape[2], image.shape[3])

But indexing in python is 0-based, so dimension 1 is the second dimension, right?

Or to put it another way, which dimension is the “channel” dimension? It is index 1, which is the second dimension.

oh wow, I tried every dimension being one but that one. I was sure that one had to be the channel number, but it makes sense now. Thank you !

1 Like