HobbitLong / RepDistiller

[ICLR 2020] Contrastive Representation Distillation (CRD), and benchmark of recent knowledge distillation methods
BSD 2-Clause "Simplified" License
2.11k stars 389 forks source link

AttributeError: 'CIFAR100InstanceSample' object has no attribute 'train_data' #38

Open Jiawen-huang opened 3 years ago

Jiawen-huang commented 3 years ago

I run your code:python train_student.py --path_t ./save/models/resnet32x4_vanilla/ckpt_epoch_240.pth --distill crd --model_s resnet8x4 -a 0 -b 0.8 --trial 1 but Encounter an error:

....../RepDistiller/dataset/cifar100.py", line 124, in init num_samples = len(self.train_data)

AttributeError: 'CIFAR100InstanceSample' object has no attribute 'train_data'

siihwanpark commented 3 years ago

This issue is caused by the version of pyTorch. As version updated, the source code of torchvision.datasets.CIFAR100 also has been updated. This issue can be resolved simply replace datasets.CIFAR100 by source code from [here].(https://pytorch.org/docs/0.4.0/_modules/torchvision/datasets/cifar.html#CIFAR10)

NEUdeep commented 3 years ago

just like: img, target = self.data[index], self.targets[index] for 1.7.0

Harr7y commented 2 years ago

torch 1.7.0 It works.

  1. in dataset/cifar100.py replace all the "self.train_data" and "self.test_data" with "self. data" ; "self.train_labels" and "self.test_labels" -> "self.targets"
  2. helper/util.py line:55 replace "view(-1)" with "reshape(-1)"

More details in the definition of torchvision/datasets/cifar.py: class CIFAR10