PKU-ML / AdvNotRealFeatures

Official Code for reproductivity of the NeurIPS 2023 paper: Adversarial Examples Are Not Real Features
13 stars 2 forks source link

ValueError When Setting Dataset Attribute in DataLoader in train_dm.py #6

Open CUMT-CSXSH opened 2 months ago

CUMT-CSXSH commented 2 months ago

The code attempts to set the dataset attribute of an already initialized DataLoader, which raises a ValueError. This error occurs because modifying the dataset attribute after initialization is not allowed.

Error Message: ValueError: dataset attribute should not be set after DataLoader is initialized

Code Snippet:

  1. line 97: if 'robust' in args.dataset: trainloader.dataset = Crafted_CIFAR10_Training_Set(trainloader.dataset.transform, args.dataset)
  2. line 173: if 'robust' in args.dataset: train_set = Crafted_CIFAR10_Training_Set(transform_train, args.dataset)

Solution:

  1. if 'robust' in args.dataset: train_dataset = Crafted_CIFAR10_Training_Set(trainloader.dataset.transform, args.dataset) trainloader = DataLoader(train_dataset, batch_size=train_configs.batch_size, shuffle=True, num_workers=num_workers)
  2. if 'robust' in args.dataset: train_set = Crafted_CIFAR10_Training_Set(transform_train, args.dataset) else: train_set = torchvision.datasets.CIFAR10('../data', train=True, transform=transform_train, download=True)

After I modify the code, it can run normally

Charles20021201 commented 2 months ago

Hi, sorry for the late reply.

We have fixed the bug as you suggested.

Again we thank you for pointing out the bug and correcting it. If there are any unresolved questions or ideas, please share them with us!

Best, Charles