cg563 / simple-blackbox-attack

Code for ICML 2019 paper "Simple Black-box Adversarial Attacks"
MIT License
191 stars 56 forks source link

about data_root #18

Closed CQJhealer closed 3 years ago

CQJhealer commented 3 years ago

I want to use cifar 10,but i don't konw how to set this . (py36) sugon@sugon-X795-G30:~/cqj/SimBA$ python run_simba.py --data_root cifar --num_iters 10000 --pixel_attack --freq_dims 224 /home/sugon/miniconda3/envs/py36/lib/python3.6/site-packages/torchvision/transforms/transforms.py:280: UserWarning: The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead. "please use transforms.Resize instead.") Traceback (most recent call last): File "run_simba.py", line 173, in testset = dset.ImageFolder(args.data_root + '/val', utils.IMAGENET_TRANSFORM) File "/home/sugon/miniconda3/envs/py36/lib/python3.6/site-packages/torchvision/datasets/folder.py", line 229, in init is_valid_file=is_valid_file) File "/home/sugon/miniconda3/envs/py36/lib/python3.6/site-packages/torchvision/datasets/folder.py", line 108, in init classes, class_to_idx = self._find_classes(self.root) File "/home/sugon/miniconda3/envs/py36/lib/python3.6/site-packages/torchvision/datasets/folder.py", line 137, in _find_classes classes = [d.name for d in os.scandir(dir) if d.is_dir()] FileNotFoundError: [Errno 2] No such file or directory: 'cifar/val'

CQJhealer commented 3 years ago

是cifar10的里面需要有val吗 我的cifar10里面是data_batch_1这些文件。抱歉了,我看了你的介绍像是一个中国人,就打中文了。

cg563 commented 3 years ago

为了回复有助于其他人我还是回英文吧。

The --data_root argument is meant for specifying the ImageNet folder. Some changes are needed to adapt the code for CIFAR-10, namely https://github.com/cg563/simple-blackbox-attack/blob/master/run_simba.py#L173 should be changed to dset.CIFAR10 and the normalize function in https://github.com/cg563/simple-blackbox-attack/blob/master/run_simba.py#L40 should be using CIFAR normalization constants.

Since running the code on CIFAR-10 seems to be in popular demand, I will update the repo with a CIFAR-10 version in the next few days if this helps.

CQJhealer commented 3 years ago

def normalize(x): return utils.apply_normalization(x, 'cifar') testset = dset.ImageFolder(args.data_root + '/val', utils.CIFAR_TRANSFORM) sugon@sugon-X795-G30:~/cqj/SimBA$ python run_simba.py --data_root dset.CIFAR10 --num_iters 10000 --pixel_attack --freq_dims 224 /home/sugon/miniconda3/envs/py36/lib/python3.6/site-packages/torchvision/transforms/transforms.py:280: UserWarning: The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead. "please use transforms.Resize instead.") Traceback (most recent call last): File "run_simba.py", line 173, in testset = dset.ImageFolder(args.data_root + '/val', utils.CIFAR_TRANSFORM) File "/home/sugon/miniconda3/envs/py36/lib/python3.6/site-packages/torchvision/datasets/folder.py", line 229, in init is_valid_file=is_valid_file) File "/home/sugon/miniconda3/envs/py36/lib/python3.6/site-packages/torchvision/datasets/folder.py", line 108, in init classes, class_to_idx = self._find_classes(self.root) File "/home/sugon/miniconda3/envs/py36/lib/python3.6/site-packages/torchvision/datasets/folder.py", line 137, in _find_classes classes = [d.name for d in os.scandir(dir) if d.is_dir()] FileNotFoundError: [Errno 2] No such file or directory: 'dset.CIFAR10/val' python run_simba.py --data_root dset.CIFAR10 normalize --num_iters 10000 --pixel_attack --freq_dims 224 /home/sugon/miniconda3/envs/py36/lib/python3.6/site-packages/torchvision/transforms/transforms.py:280: UserWarning: The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead. "please use transforms.Resize instead.") usage: run_simba.py [-h] --data_root DATA_ROOT [--result_dir RESULT_DIR] [--sampled_image_dir SAMPLED_IMAGE_DIR] [--model MODEL] [--num_runs NUM_RUNS] [--batch_size BATCH_SIZE] [--num_iters NUM_ITERS] [--log_every LOG_EVERY] [--epsilon EPSILON] [--linf_bound LINF_BOUND] [--freq_dims FREQ_DIMS] [--order ORDER] [--stride STRIDE] [--targeted] [--pixel_attack] [--save_suffix SAVE_SUFFIX] run_simba.py: error: unrecognized arguments: normalize

I change the code ,but failed

cg563 commented 3 years ago

I have added the CIFAR attack code to https://github.com/cg563/simple-blackbox-attack/blob/master/run_simba_cifar.py. Let me know if this resolves your issue.

CQJhealer commented 3 years ago

I don't know how to express my thanks. I can only wish you good health and smooth work