ain-soph / trojanzoo

TrojanZoo provides a universal pytorch platform to conduct security researches (especially backdoor attacks/defenses) of image classification in deep learning.
https://ain-soph.github.io/trojanzoo
GNU General Public License v3.0
274 stars 62 forks source link

Unable to Access Triggered Dataset in BadNet Attack #200

Closed pheobyy closed 10 months ago

pheobyy commented 10 months ago

I would like to be able to access and inspect the dataset containing the added trigger after running the BadNet attack.

I ran the attack using the following command: python examples/backdoor_attack.py --color --verbose 1 --pretrained --validate_interval 1 --epochs 10 --lr 0.01 --mark_random_init --attack badnet --save After running the attack, I expected to be able to access the dataset containing the trigger, but I'm facing some difficulties in doing so. Here are the issues I encountered:

ain-soph commented 10 months ago
image
ain-soph commented 10 months ago

Btw, just a trick, using torchvision.utils.save_image(backdoored_img, "trigger_img.jpg") is easier than plt.imsave("trigger_img.jpg", backdoored_img.cpu().numpy())

https://pytorch.org/vision/stable/generated/torchvision.utils.save_image.html?highlight=save_#torchvision.utils.save_image

pheobyy commented 10 months ago

Thank you for your quick response! :)

I tried it again with train_mode == 'dataset' and it worked

For train_mode == 'batch' : I tried using torchvision.utils.save_image(backdoored_img, "trigger_img.jpg") instead of plt.imsave and everything worked fine! The "trigger_img" contained the images with the trigger attached. So the issue seems to be only related to plt.imsave. This is how "trigger_img" looks like if I use plt.imsave : trigger_img

ain-soph commented 10 months ago

This doesn't seem to be a trigger either. I think plt.imsave requires HWC rather than CHW order (not sure, never use it). So you might only output 3-pixel width somehow.

ain-soph commented 10 months ago

I guess your problem has been solved in previous discussion. I'll close this issue. Feel free to re-open if there is still any problem related to this issue.