Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backward compat properties to CIFAR100 dataset classes #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add backward compat properties to CIFAR100 dataset classes #14

wants to merge 1 commit into from

Conversation

ml-illustrated
Copy link

Hello, fan of your great work. In trying to reproduce your CIFAR100 results via README example commands, they would end up in an error, e.g.,

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
Files already downloaded and verified
Traceback (most recent call last):
  File "train_student.py", line 345, in <module>
    main()
  File "train_student.py", line 157, in main
    mode=opt.mode)
  File "...RepDistiller/dataset/cifar100.py", line 211, in get_cifar100_dataloaders_sample
    percent=percent)
  File "...RepDistiller/dataset/cifar100.py", line 124, in __init__
    num_samples = len(self.train_data)
AttributeError: 'CIFAR100InstanceSample' object has no attribute 'train_data'

A simple change is to add four properties to a new class CIFAR100BackCompat to minimize the code changes, as submitted in this pull request.

For additional background, here's the Torchvision's MNIST source for reference: https://pytorch.org/docs/stable/_modules/torchvision/datasets/mnist.html#MNIST

relevant section:

    @property
    def train_labels(self):
        warnings.warn("train_labels has been renamed targets")
        return self.targets

    @property
    def test_labels(self):
        warnings.warn("test_labels has been renamed targets")
        return self.targets

    @property
    def train_data(self):
        warnings.warn("train_data has been renamed data")
        return self.data

    @property
    def test_data(self):
        warnings.warn("test_data has been renamed data")
        return self.data

Tested the changes with:

torch==1.3.1
torchvision==0.4.2

@HobbitLong
Copy link
Owner

HobbitLong commented Jan 3, 2020

@ml-illustrated , Thank you for your nice input, I like your modification a lot!

Just wonder would it be possible to make it compatible with both torchvision 0.4.2 and previous torchvision which still uses train_data stuff, e.g. torchvision 0.2.1?

@ml-illustrated
Copy link
Author

ml-illustrated commented Jan 4, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants