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

trojanvision.datasets.ImageFolder #183

Closed avdvg closed 1 year ago

avdvg commented 1 year ago

Dear developers: The way to load the dataset in the example is trojanvision.datasets.create(**kwargs).

I'm trying to load a dataset in ImageFolder format: The format of the dataset to be loaded is '_{self.folder_path}/{self.name}/{mode}/{class_name}/{imgidx}.png'. image image image

So I adjusted the code to: dataset = trojanvision.datasets.ImageFolder(**kwargs)

And I set in parameter configuration --color --verbose 1 --validate_interval 1 --dataset mnist --attack badnet --data_dir /home/ubuntu/xx/datasets - --mark_random_init --epochs 50 --lr 0.01

My program has the following error: Traceback (most recent call last): File "/home/ubuntu/lrchang/trojanzoo/examples/backdoor_attack.py", line 25, in dataset = trojanvision.datasets.ImageFolder(kwargs) File "/home/ubuntu/lrchang/trojanzoo/trojanvision/datasets/imagefolder.py", line 79, in init super().init(kwargs) File "/home/ubuntu/lrchang/trojanzoo/trojanvision/datasets/imageset.py", line 146, in init super().init(**kwargs) File "/home/ubuntu/lrchang/trojanzoo/trojanzoo/datasets.py", line 154, in init self.loader['train'] = self.get_dataloader(mode='train') File "/home/ubuntu/lrchang/trojanzoo/trojanzoo/datasets.py", line 414, in get_dataloader batch_size = self.batch_size File "/home/ubuntu/anaconda3/envs/py310/lib/python3.10/functools.py", line 981, in get val = self.func(instance) File "/home/ubuntu/lrchang/trojanzoo/trojanzoo/datasets.py", line 175, in batch_size return self.__batch_size if self.__batch_size >= 0 else \ TypeError: '>=' not supported between instances of 'NoneType' and 'int' P{'default': None, 'device': device(type='cuda'), 'seed': 1228, 'data_seed': 1228, 'verbose': 1, 'color': True, 'tqdm': False, 'cudnn_benchmark': False, 'num_gpus': 1, 'world_size': 1} Dataset Folder Path: None

Process finished with exit code 1

How should I adjust the code to load the expected dataset? Looking forward to your reply~

ain-soph commented 1 year ago

batch_size issue should be already fixed in the most recent commit. Please pull the most up-to-date codes and see if that works.

https://github.com/ain-soph/trojanzoo/commit/1f417cc0da0c4ad0483a6f050f18930d0813f9e3