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

Possible issue with the Loss_flow code for Spatially Transformed Adversarial Examples #4

Open
ahmadajal opened this issue Oct 20, 2020 · 0 comments

Comments

@ahmadajal
Copy link

ahmadajal commented Oct 20, 2020

Hello,

I think there is an issue with the way you implement flow loss in the code. In the main paper it says that the flow loss is the sum of spatial movement distance for any two adjacent pixels. In the code you are doing the following:
`
def forward(self, f):
# TODO: padding
'''
f - f.size() = [1, h, w, 2]
f[0, :, :, 0] - u channel
f[0, :, :, 1] - v channel
'''
f_u = f[:, :, :, 0].unsqueeze(1)
f_v = f[:, :, :, 1].unsqueeze(1)

    diff_u = F.conv2d(f_u, self.filters)[0][0] # don't use squeeze
    diff_u_sq = torch.mul(diff_u, diff_u)

    diff_v = F.conv2d(f_v, self.filters)[0][0] # don't use squeeze
    diff_v_sq = torch.mul(diff_v, diff_v)

    dist = torch.sqrt(torch.sum(diff_u_sq, dim=0) + torch.sum(diff_v_sq, dim=0))
    return torch.sum(dist)

The problem is that on the lines you are computingdiff_uanddiff_v, you only compute the sum for the neighboring pixel on the top left. I guess this is probably a small typo in the code. In fact, I think those two lines should be like this: diff_u = F.conv2d(f_u, self.filters)[0]`.
Please correct me if I am wrong. thanks in advance for your reply.

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

1 participant