Closed Freed-Wu closed 2 years ago
In bim.py:
bim.py
a = torch.clamp(ori_images - self.eps, min=0) b = (adv_images >= a).float()*adv_images \ + (adv_images < a).float()*a c = (b > ori_images+self.eps).float()*(ori_images+self.eps) \ + (b <= ori_images + self.eps).float()*b images = torch.clamp(c, max=1).detach()
In rfgsm.py:
rfgsm.py
delta = torch.clamp(adv_images - images, min=-self.eps, max=self.eps) adv_images = torch.clamp(images + delta, min=0, max=1).detach()
Seem that there are same function:
$\mathrm{advimage} \leftarrow \max(\mathrm{advimage}, (\mathrm{oriimage} - \epsilon))$ $\mathrm{advimage} \leftarrow \min(\mathrm{advimage}, (\mathrm{oriimage} + \epsilon))$ $\mathrm{advimage} \leftarrow \max(\mathrm{advimage}, 0)$ $\mathrm{advimage} \leftarrow \min(\mathrm{advimage}, 1)$
Why use different code to realize?
Definitely, they are identical. However, the codes are built on the proposed algorithm in the original paper. I hope the answer helps you!
In
bim.py
:In
rfgsm.py
:Seem that there are same function:
$\mathrm{advimage} \leftarrow \max(\mathrm{advimage}, (\mathrm{oriimage} - \epsilon))$ $\mathrm{advimage} \leftarrow \min(\mathrm{advimage}, (\mathrm{oriimage} + \epsilon))$ $\mathrm{advimage} \leftarrow \max(\mathrm{advimage}, 0)$ $\mathrm{advimage} \leftarrow \min(\mathrm{advimage}, 1)$
Why use different code to realize?