YijinHuang / pytorch-classification

A general, feasible, and extensible framework for classification tasks.
MIT License
58 stars 18 forks source link

Still got "AttributeError" after copying the Python script containing the "ContrastiveModel" class to the same folder as "main.py". #11

Closed DerrickGuu closed 4 months ago

DerrickGuu commented 4 months ago

%%%

  1. The "AttributeError" is caused by the pickle mechanism, which means you need to copy the Python script containing the "ContrastiveModel" class to the same folder as "main.py".

%%%

Originally posted by @YijinHuang in https://github.com/YijinHuang/pytorch-classification/issues/10#issuecomment-2188984591

I still got the same attribute error after doing so. Are there any further detailed instructions about how can I train the classification model to evaluate the weights from Lesion-based-Contrastive-Learning? Or are there any other parts I have to modify in the script?

Thanks for the help!

圖片_2024-06-28_021402767

YijinHuang commented 4 months ago

Thank you for helping me find this bug. I have uploaded a script in the Lesion-based-Contrastive-Learning repository that can be used to process your pre-trained model so it can be directly loaded in pytorch-classification.

Please find the script tools/model2weights.py in the Lesion-based CL repository and run it with the following command:

python model2weights.py --pretrained-model [path/to/your/model] --output [path/to/new/file]

Then update the "checkpoint" item in ~/configs/eyepacs.yaml with [path/to/new/file]. Make sure to keep strict=False in load_state_dict.

Additionally, I have updated the method for saving pre-trained models in the Lesion-based CL repository. If you use the latest code, you won't need to run this script.

DerrickGuu commented 4 months ago

Thanks for solving this issue! It worked fine to me, and now the results from Lesion-based CL can be directly loaded!