moboehle / B-cos

B-cos Networks: Alignment is All we Need for Interpretability
Other
103 stars 11 forks source link

Cannot train on TinyImagenet #6

Closed saa025 closed 1 year ago

saa025 commented 1 year ago

Hello,

I attempting to run one of the basic experiments with the TinyImagenet dataset. Below are the steps I've taken and the issues I am running into. I would very much appreciate any help.

I've downloaded the tiny-imagenet-200 dataset from the following locations: http://cs231n.stanford.edu/tiny-imagenet-200.zip

I unzipped to the ./data folder where I then resorted the data into the expected format for the train and val folders. The directory structure is as follows:

tiny-imagenet-200
    train/
        class1/
            sample1.jpg
            sample2.jpg
            ...
        class2/
            sample1.jpg
            sample2.jpg
            ...
    val/
        class1/
            sample1.jpg
            sample2.jpg
            ...
        class2/
            sample1.jpg
            sample2.jpg
            ...

I then tried to run the experiment for Imagenet on this dataset with the following command:

py experiments/Imagenet/bcos/model.py --single_epoch=true --experiment_name=resnet_34 --dataset_name=TinyImagenet --model_config=bcos

It seems like it loads up the data but errors out with the following:

image

I then assumed that there may be something wrong with the data loader so I then attempted to simply load the data and iterate through the Dataloader. This is the result:

image

Not sure if I am doing anything wrong. Any input would be appreciated.

Thanks

nps1ngh commented 1 year ago

Hi, this seems to be related to numpy deprecating np.int.

You could try changing https://github.com/moboehle/B-cos/blob/452ff6bf8d043783276ab40b1ccfcacebfbdb4f5/data/augmentations/rand_augment.py#L84

to

img_np = np.array(img).astype(int) 

The OneHot transform takes the number of classes to initialize, your second error seems to suggest that it has the wrong number of classes. For TinyImageNet you have 200 classes but the transform apparently got 10 as the number. You should try looking into changing that.


Also make sure you add the appropriate configs for TinyImagenet in https://github.com/moboehle/B-cos/tree/main/experiments As you can see it currently only has configs for Imagenet and CIFAR10, you will need to add your custom ones for TinyImagenet yourself.