vturrisi / solo-learn

solo-learn: a library of self-supervised methods for visual representation learning powered by Pytorch Lightning
MIT License
1.39k stars 181 forks source link

How to perform down-stream task for image classification? #338

Closed saifhassan closed 1 year ago

saifhassan commented 1 year ago

Hei @turian @Froskekongen @Froskekongen @Borda @ojss,

It's really a nice repo on using self-supervised learning, like ALL-in-1.

I am new to SSL, however I have implemented your repo and developed model using main_pretrain.py code on Image classification dataset. Now I have pretrained model say byol-resnet-custom.ckpt, so how do I have to use this as down-stream task on my dataset? Please guide, I gone through main_linear.py but causing following errors:

usage: main_linear.py [--help] [--hydra-help] [--version] [--cfg {job,hydra,all}] [--resolve] [--package PACKAGE]
                      [--run] [--multirun] [--shell-completion] [--config-path CONFIG_PATH]
                      [--config-name CONFIG_NAME] [--config-dir CONFIG_DIR] [--experimental-rerun EXPERIMENTAL_RERUN]
                      [--info [{all,config,defaults,defaults-tree,plugins,searchpath}]]
                      [overrides [overrides ...]]
main_linear.py: error: unrecognized arguments: --dataset --backbone resnet18 --data_dir ./ --max_epochs 100 --gpus 0 --sync_batchnorm --precision 16 --optimizer sgd --scheduler step --lr 0.1 --lr_decay_steps 60 80 --weight_decay 0 --batch_size 128 --num_workers 4 --name general-linear-eval --pretrained_feature_extractor cifar10/byol-cifar10.ckpt --project self-supervised --wandb

Please guide regarding down-stream task, steps.

Thanks in advance.

vturrisi commented 1 year ago

Hey @saifhassan. I think you tagged the wrong people :). Anyways, from what I understood, you just wanna run the offline linear eval on a custom dataset. Can you share your full script?From the error, it looks like you are missing the --dataset parameter.

saifhassan commented 1 year ago

Hey @saifhassan. I think you tagged the wrong people :). Anyways, from what I understood, you just wanna run the offline linear eval on a custom dataset. Can you share your full script?From the error, it looks like you are missing the --dataset parameter.

being tagged wrong, you replied very fast. Thank you for that.

however that error is solved, Can you just guide me regarding the down-stream task, Like I have pretrained model using BYOL, Barlows, and others with ResNet18 and now want to apply on down-stream task (Image Classification)?

saifhassan commented 1 year ago

Hey @saifhassan. I think you tagged the wrong people :). Anyways, from what I understood, you just wanna run the offline linear eval on a custom dataset. Can you share your full script?From the error, it looks like you are missing the --dataset parameter.

I assumed that main_linear.py in repo means performing down-stream task, am I correct? if not, can you please guide me regarding how to perform down-stream task on pre-trained model which I have achieved using main_pretrain.py.

saifhassan commented 1 year ago

Thanks @vturrisi in advance

DonkeyShot21 commented 1 year ago

Yes, the main_linear.py file is used for downstream tasks. You just need to pass the downstream dataset and the pre-trained model in the config file. See an example here https://github.com/vturrisi/solo-learn/blob/main/scripts/linear/imagenet-100/barlow.yaml.

saifhassan commented 1 year ago

Yes, the main_linear.py file is used for downstream tasks. You just need to pass the downstream dataset and the pre-trained model in the config file. See an example here https://github.com/vturrisi/solo-learn/blob/main/scripts/linear/imagenet-100/barlow.yaml.

Thank you @DonkeyShot21. I have applied, worked! Thanks again.

saifhassan commented 1 year ago

Yes, the main_linear.py file is used for downstream tasks. You just need to pass the downstream dataset and the pre-trained model in the config file. See an example here https://github.com/vturrisi/solo-learn/blob/main/scripts/linear/imagenet-100/barlow.yaml.

and what about finetune folder? what's the actual work of it? and how can we use model for predicting/testing on test dataset and generate confusion matrix using the model trained using main_linear.py ? Please guide.

Thanks

vturrisi commented 1 year ago

@saifhassan you can also use main_linear.py to fine-tune the whole model instead of just training a linear classifier on top of the frozen backbone. For that, just follow the examples inside finetune. We don't support generating a confusion matrix, but you can easily implement it with lightning bolts or something like this.

saifhassan commented 1 year ago

@saifhassan you can also use main_linear.py to fine-tune the whole model instead of just training a linear classifier on top of the frozen backbone. For that, just follow the examples inside finetune. We don't support generating a confusion matrix, but you can easily implement it with lightning bolts or something like this.

Can you explain more regarding finetune. Actually that folder contains same .yaml file, How it can be used for finetuning?

or can you please guide, how can I finetune model generated by main_linear.py? some code snippet?

vturrisi commented 1 year ago

The files there have a flag --finetune. For example here: https://github.com/vturrisi/solo-learn/blob/6a891ee9af6e28ae071313b596f8e553b7227b64/scripts/finetune/imagenet/mae.yaml#L44