Code Cell UNQ_C1: Unexpected error (IndexError

My guess is you are doing the selection in an “elementwise” way, instead of the intended “row-wise” manner. Test your code with some sample vectors like the ones I showed in my examples above and see if you get outputs that have a mix of values in each entry instead of each “sample” being consistently real or fake.

Here’s a test:

# Play cell to test combine_sample
my_real = torch.ones(7,5) * 0.5
my_fake = torch.ones(7,5) * -0.75
my_output = combine_sample(my_real, my_fake, 0.4)
print(f"my_output = {my_output}")

When I run that, here’s what I get with code that passes the tests in the notebook:

real.shape torch.Size([7, 5])
fake.shape torch.Size([7, 5])
fake_mask.shape before torch.Size([7])
target_images.shape torch.Size([7, 5])
my_output = tensor([[ 0.5000,  0.5000,  0.5000,  0.5000,  0.5000],
        [-0.7500, -0.7500, -0.7500, -0.7500, -0.7500],
        [ 0.5000,  0.5000,  0.5000,  0.5000,  0.5000],
        [-0.7500, -0.7500, -0.7500, -0.7500, -0.7500],
        [-0.7500, -0.7500, -0.7500, -0.7500, -0.7500],
        [ 0.5000,  0.5000,  0.5000,  0.5000,  0.5000],
        [ 0.5000,  0.5000,  0.5000,  0.5000,  0.5000]])

Notice that every row is either all real or all fake. What do you see when you run that test with your code?