Harry24k / adversarial-attacks-pytorch

PyTorch implementation of adversarial attacks [torchattacks].
https://adversarial-attacks-pytorch.readthedocs.io/en/latest/index.html
MIT License
1.79k stars 338 forks source link

[bug] _target_map_function cannot be None #84

Closed Freed-Wu closed 1 year ago

Freed-Wu commented 1 year ago
$ pyright
...
~/.local/lib/python3.10/site-packages/torchattacks/attack.py:245:29 - error: Object of type "None" cannot be called (reportOptionalCall)

By default, self._target_map_function is None, so this is a bug:

            target_labels = self._target_map_function(images, labels)

Can be fixed by:

            if self._target_map_function is None:
                target_labels = labels
            else
                target_labels = self._target_map_function(images, labels)
Harry24k commented 1 year ago

Thank you.

It seems that the following default value of target_map_function is the problem: https://github.com/Harry24k/adversarial-attacks-pytorch/blob/2810a4088f661cc2af3ada0775d35f271c4e04f8/torchattacks/attack.py#L60

The default value is deleted.