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

Can you guide me for creating self-supervised .ckpt file for custom dataset? #19

Open
saifhassan-phd opened this issue Sep 7, 2023 · 11 comments

Comments

@saifhassan-phd
Copy link

Thank you @XzwHan @JegZheng for this wonderful contribution, I have implemented this and want to use this model for my research project. So can you guide me for creating self-supervised .ckpt file for custom dataset (Any image classification dataset)?

I have gone through paper and code but unable to understand how you have developed .ckpt file for self-supervised model.

Thank you in advance.

@JegZheng
Copy link
Collaborator

JegZheng commented Sep 7, 2023

Thank you @XzwHan @JegZheng for this wonderful contribution, I have implemented this and want to use this model for my research project. So can you guide me for creating self-supervised .ckpt file for custom dataset (Any image classification dataset)?

I have gone through paper and code but unable to understand how you have developed .ckpt file for self-supervised model.

Thank you in advance.

Hi @saifhassan-phd ,

Our self-supervised model is adapted from our self-supervised learning work CACR. Please feel free to check this repo, where you can find how to use CACR to learn the self-supervised model on your dataset: https://github.com/JegZheng/CACR-SSL

@saifhassan-phd
Copy link
Author

Thank you @XzwHan @JegZheng for this wonderful contribution, I have implemented this and want to use this model for my research project. So can you guide me for creating self-supervised .ckpt file for custom dataset (Any image classification dataset)?
I have gone through paper and code but unable to understand how you have developed .ckpt file for self-supervised model.
Thank you in advance.

Hi @saifhassan-phd ,

Our self-supervised model is adapted from our self-supervised learning work CACR. Please feel free to check this repo, where you can find how to use CACR to learn the self-supervised model on your dataset: https://github.com/JegZheng/CACR-SSL

ok, Thanks for your quick response.

@saifhassan-phd
Copy link
Author

saifhassan-phd commented Sep 13, 2023

Thank you @XzwHan @JegZheng for this wonderful contribution, I have implemented this and want to use this model for my research project. So can you guide me for creating self-supervised .ckpt file for custom dataset (Any image classification dataset)?
I have gone through paper and code but unable to understand how you have developed .ckpt file for self-supervised model.
Thank you in advance.

Hi @saifhassan-phd ,

Our self-supervised model is adapted from our self-supervised learning work CACR. Please feel free to check this repo, where you can find how to use CACR to learn the self-supervised model on your dataset: https://github.com/JegZheng/CACR-SSL

@JegZheng @XzwHan , I have gone through https://github.com/JegZheng/CACR-SSL repo and completed cifar10 experiment and it generated encoder.pth file using main_ours.py file and also tested with linear.py file, now can you guide me regarding how can I use this encoder.pth with card model? Because in cifar10.yml config file, it mentions .ckpt file.

Thanks

@saifhassan-phd
Copy link
Author

Thank you @XzwHan @JegZheng for this wonderful contribution, I have implemented this and want to use this model for my research project. So can you guide me for creating self-supervised .ckpt file for custom dataset (Any image classification dataset)?
I have gone through paper and code but unable to understand how you have developed .ckpt file for self-supervised model.
Thank you in advance.

Hi @saifhassan-phd ,
Our self-supervised model is adapted from our self-supervised learning work CACR. Please feel free to check this repo, where you can find how to use CACR to learn the self-supervised model on your dataset: https://github.com/JegZheng/CACR-SSL

@JegZheng @XzwHan , I have gone through https://github.com/JegZheng/CACR-SSL repo and completed cifar10 experiment and it generated encoder.pth file using main_ours.py file and also tested with linear.py file, now can you guide me regarding how can I use this encoder.pth with card model? Because in cifar10.yml config file, it mentions .ckpt file.

Thanks

Specifically, can you guide, how you generate snapshot_supervised.ckpt and snapshot_self_supervised.ckpt files, I tried using https://github.com/JegZheng/CACR-SSL, but it produced .pth file?

@JegZheng
Copy link
Collaborator

Thank you @XzwHan @JegZheng for this wonderful contribution, I have implemented this and want to use this model for my research project. So can you guide me for creating self-supervised .ckpt file for custom dataset (Any image classification dataset)?
I have gone through paper and code but unable to understand how you have developed .ckpt file for self-supervised model.
Thank you in advance.

Hi @saifhassan-phd ,
Our self-supervised model is adapted from our self-supervised learning work CACR. Please feel free to check this repo, where you can find how to use CACR to learn the self-supervised model on your dataset: https://github.com/JegZheng/CACR-SSL

@JegZheng @XzwHan , I have gone through https://github.com/JegZheng/CACR-SSL repo and completed cifar10 experiment and it generated encoder.pth file using main_ours.py file and also tested with linear.py file, now can you guide me regarding how can I use this encoder.pth with card model? Because in cifar10.yml config file, it mentions .ckpt file.
Thanks

Specifically, can you guide, how you generate snapshot_supervised.ckpt and snapshot_self_supervised.ckpt files, I tried using https://github.com/JegZheng/CACR-SSL, but it produced .pth file?

We have provided the proxy function to load .pth file. Please check our code here (CARD/classification/card_classification.py, L208): https://github.com/XzwHan/CARD/blob/ebe2f2ae95dc7a7a95e6a71c0c8e1cabf8451087/classification/card_classification.py#L208C4-L208C5

Just put the .pth file in the corresponding folder and rename it as aux_ckpt.pth and it shall be ready.
Alternatively, you may create a loading function with the following step:

  1. Call torch.load() to load the .pth file (the .pth file from CACR repo is already a state_dict class)
  2. Call model.load_state_dict() to paste the weight to the model.

@saifhassan-phd
Copy link
Author

Thank you @XzwHan @JegZheng for this wonderful contribution, I have implemented this and want to use this model for my research project. So can you guide me for creating self-supervised .ckpt file for custom dataset (Any image classification dataset)?
I have gone through paper and code but unable to understand how you have developed .ckpt file for self-supervised model.
Thank you in advance.

Hi @saifhassan-phd ,
Our self-supervised model is adapted from our self-supervised learning work CACR. Please feel free to check this repo, where you can find how to use CACR to learn the self-supervised model on your dataset: https://github.com/JegZheng/CACR-SSL

@JegZheng @XzwHan , I have gone through https://github.com/JegZheng/CACR-SSL repo and completed cifar10 experiment and it generated encoder.pth file using main_ours.py file and also tested with linear.py file, now can you guide me regarding how can I use this encoder.pth with card model? Because in cifar10.yml config file, it mentions .ckpt file.
Thanks

Specifically, can you guide, how you generate snapshot_supervised.ckpt and snapshot_self_supervised.ckpt files, I tried using https://github.com/JegZheng/CACR-SSL, but it produced .pth file?

We have provided the proxy function to load .pth file. Please check our code here (CARD/classification/card_classification.py, L208): https://github.com/XzwHan/CARD/blob/ebe2f2ae95dc7a7a95e6a71c0c8e1cabf8451087/classification/card_classification.py#L208C4-L208C5

Just put the .pth file in the corresponding folder and rename it as aux_ckpt.pth and it shall be ready. Alternatively, you may create a loading function with the following step:

  1. Call torch.load() to load the .pth file (the .pth file from CACR repo is already a state_dict class)
  2. Call model.load_state_dict() to paste the weight to the model.

I didn't understand, Let me rephrase, I want to know how you produced snapshot_self_supervised.ckpt file?

@saifhassan-phd
Copy link
Author

I mean how can I generate these .ckpt files for cifar-10 dataset

@saifhassan-phd
Copy link
Author

Thank you @XzwHan @JegZheng for this wonderful contribution, I have implemented this and want to use this model for my research project. So can you guide me for creating self-supervised .ckpt file for custom dataset (Any image classification dataset)?
I have gone through paper and code but unable to understand how you have developed .ckpt file for self-supervised model.
Thank you in advance.

Hi @saifhassan-phd ,
Our self-supervised model is adapted from our self-supervised learning work CACR. Please feel free to check this repo, where you can find how to use CACR to learn the self-supervised model on your dataset: https://github.com/JegZheng/CACR-SSL

@JegZheng @XzwHan , I have gone through https://github.com/JegZheng/CACR-SSL repo and completed cifar10 experiment and it generated encoder.pth file using main_ours.py file and also tested with linear.py file, now can you guide me regarding how can I use this encoder.pth with card model? Because in cifar10.yml config file, it mentions .ckpt file.
Thanks

Specifically, can you guide, how you generate snapshot_supervised.ckpt and snapshot_self_supervised.ckpt files, I tried using https://github.com/JegZheng/CACR-SSL, but it produced .pth file?

We have provided the proxy function to load .pth file. Please check our code here (CARD/classification/card_classification.py, L208): https://github.com/XzwHan/CARD/blob/ebe2f2ae95dc7a7a95e6a71c0c8e1cabf8451087/classification/card_classification.py#L208C4-L208C5

Just put the .pth file in the corresponding folder and rename it as aux_ckpt.pth and it shall be ready. Alternatively, you may create a loading function with the following step:

  1. Call torch.load() to load the .pth file (the .pth file from CACR repo is already a state_dict class)
  2. Call model.load_state_dict() to paste the weight to the model.

I have tried that proxy function, it causes keyerror on line 210, tried load_state_dict(aux_state[0]), load_state_dict(aux_state['state_dict']) and load_state_dict(aux_state), but again error.

@JegZheng
Copy link
Collaborator

The .pth file saved from CACR repo is directly the state_dict, and the .ckpt in CARD is a dictionary, where the state_dict is stored under the key 'state_dict'. This is why:

  • In CACR, we directly load the weight to the model as model.load_state_dict(torch.load(file_path))
  • In CARD, we load as model.load_state_dict(torch.load(file_path['state_dict'])

Let's do a simpler solution without changing the code. Could you please try:

  1. We load the .pth file produced by CACR code
  2. Resave this state_dict in a dictionary, and make the key named 'state_dict'.

For example,
model_weight = torch.load('encoder.pth')
weight_dict = {'state_dict': model_weight}
torch.save(weight_dict, 'snapshot_self_supervised.ckpt')

@saifhassan-phd
Copy link
Author

The .pth file saved from CACR repo is directly the state_dict, and the .ckpt in CARD is a dictionary, where the state_dict is stored under the key 'state_dict'. This is why:

  • In CACR, we directly load the weight to the model as model.load_state_dict(torch.load(file_path))
  • In CARD, we load as model.load_state_dict(torch.load(file_path['state_dict'])

Let's do a simpler solution without changing the code. Could you please try:

  1. We load the .pth file produced by CACR code
  2. Resave this state_dict in a dictionary, and make the key named 'state_dict'.

For example, model_weight = torch.load('encoder.pth') weight_dict = {'state_dict': model_weight} torch.save(weight_dict, 'snapshot_self_supervised.ckpt')

I got it, I was doing mistake by using different backbone while SSL and then in CARD, got it. Error Solved. Thanks for your quick response.

@saifhassan-phd
Copy link
Author

Hey @JegZheng @XzwHan

I have successfully implemented small_experiments/cifar10 but could not find code for cifar10 using moco (self-supervised).

How can we pre-train cifar10 using moco and then use it with CARD model?

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

No branches or pull requests

2 participants