MadryLab / constructed-datasets

Datasets for the paper "Adversarial Examples are not Bugs, They Are Features"
http://gradientscience.org/adv
185 stars 23 forks source link

Error loading dataset - NameError: name 'folder' is not defined #4

Closed expectopatronum closed 5 years ago

expectopatronum commented 5 years ago

Hi, thanks for the great paper, I really enjoy reading it! I wanted to have a look at the data using the snippet from the README page - but I got the error NameError: name 'folder' is not defined I already changed a few things in order to get that far: data_path = "d_robust_CIFAR" and import os

I can't figure out from where to import TensorDataset (what is folder?). When I use TensorDataset from torch.utils.data I get another error because it doesn't have transform.

Thanks and best regards Verena

AngusG commented 5 years ago

Hi,

I don't know what folder refers to either. After this line train_data = ch.cat(ch.load(os.path.join(data_path, f"CIFAR_ims"))) you have raw numpy data and can implement transforms there, see e.g. https://stackoverflow.com/questions/55588201/pytorch-transforms-on-tensordataset

You can then pass the train_set to torch.utils.data import DataLoader like.

trainloader = DataLoader(train_set, batch_size=10)

However, it looks like the recommended use case is to use their robustness library.

AngusG commented 5 years ago

Ah. You need to use TensorDataset from https://github.com/MadryLab/robustness/blob/master/robustness/tools/folder.py#L219, which supports transforms, not to be confused with torch.utils.data import TensorDataset

expectopatronum commented 5 years ago

Thanks, that solved it for me!

Additional remark if someone else stumbles over this: [...] in train_transform = transforms.Compose([...]) is just a placeholder and needs to be replaced by an actual transform (this confused me because I haven't used transforms before).

AngusG commented 5 years ago

Yep, and I believe these are the transforms you need to reproduce their 88 clean / 48 robust accuracy. Would be great if someone from Madry Lab can confirm. Apologies if I missed this in the paper.

transform_train = transforms.Compose([
    transforms.RandomCrop(32, padding=4),
    transforms.RandomHorizontalFlip(),
    transforms.ColorJitter(.25,.25,.25),
    transforms.RandomRotation(2),
    transforms.ToTensor(),
])
arkosg commented 3 years ago

You guys literally saved my life