HobbitLong/RepDistiller

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

Jiawen-huang opened this issue · 3 comments

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'

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)

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

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