LTS4 / hold-me-tight

Source code of "Hold me tight! Influence of discriminative features on deep network boundaries"
https://arxiv.org/abs/2002.06349
Apache License 2.0
22 stars 1 forks source link

Some confusion about the code? #2

Closed LeavesLei closed 3 years ago

LeavesLei commented 3 years ago

https://github.com/LTS4/hold-me-tight/blob/b893e97f0b5fe8100472ac68d715d0cb99d0c7dc/utils.py#L166

Hi, the work "Hold me tight!" is excellent and I enjoy the reading. Here, I have a small question about the code:

for inputs, targets in dataloader:            
    inputs, targets = inputs.to(DEVICE), targets.to(DEVICE)            
    if proc_fun:                
        inputs = proc_fun(inputs)
    adv_perts = torch.zeros_like(inputs)            
    for n, im in enumerate(inputs):                
        adv_perts[n], _, _, _, _ = subspace_deepfool(im, model, trans, Sp=Sp)

You define adv_perts through adv_perts = torch.zeros_like(inputs), and then calculate the perturbations by adv_perts[n], _, _, _, _ = subspace_deepfool(im, model, trans, Sp=Sp). However, you re-define adv_perts in the next loop without dealing with the calculated adv_perts[n]. I am a little confused about this and look forward to your reply.

amodas commented 3 years ago

Hi @LeavesLei. Thanks for spotting this!

In fact, the sp_margin.append(adv_perts.cpu().view([-1, np.prod(inputs.shape[1:])]).norm(dim=[1])) should be indented once, in order to get inside the for inputs, targets in dataloader: loop.

I just pushed an updated version that fixes this issue. Let me know if you still think that something is problematic!

LeavesLei commented 3 years ago

Thanks for your quick reply😄.