How to implement adversarial attacks (deterministically)?

Oh, I’m sorry, I thought it was for scale_factor=2:

a = torch.arange(9, dtype=torch.float).view(1,1,3,3)
b = torch.nn.functional.interpolate(a, scale_factor=2)
b2 = a[:, :, :, None, :, None].expand(-1, -1, -1, 2, -1, 2).reshape(a.size(0), a.size(1), a.size(2)*2, a.size(3)*2)
print((b-b2).abs().max().item())
1 Like