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

Getting pytorch weights from caffe model #3

Open
exploringNewThings opened this issue Aug 24, 2018 · 7 comments
Open

Getting pytorch weights from caffe model #3

exploringNewThings opened this issue Aug 24, 2018 · 7 comments

Comments

@exploringNewThings
Copy link

Hi @lijiaman ,

I was able to run your code without loading the caffe model weights in PyTorch model.
Now, I was trying to do this conversion, but I am facing some difficulty in that.

Till now what I have tried to do is take the caffe model and create dictionary (caffe_dict) out of it such that keys are the caffe layer names and value are the weights.
Now using the gen_mapping_layer_name function defined in modules/CASENet.py I have got the dictionary (layer_to_name_dict) that gives a mapping from pytorch layer name to caffe layer name.

So, basically now I take every layer form the pytorch model, get it's caffe layer name using layer_to_name_dict and then use this name as key in caffe_dict to get the corresponding weights.
But I am getting a key error when I am using one of the layer name that I got from layer_to_name_dict to get data using the caffe_dict which means that some of the layers have not been mapped by the gen_mapping_layer_name function.

Could you please suggest possible direction to look at to solve this problem or better would be if you could tell (in little detail) what you did to do this conversion?

Thanks.

@fkmajiji
Copy link

hello @exploringNewThings ,I download the source code of CASENet ,but I couldn't find the caffemodel,Could you tell me where did you get the model?Maybe,Would you mind send me your caffemodel of CASENet?

@mengxingkong
Copy link

hello @fkmajiji did you run this code successfully?

@fkmajiji
Copy link

hello @fkmajiji did you run this code successfully?

I'm sorry.I didn't run this code finally

@anirudh-chakravarthy
Copy link

anirudh-chakravarthy commented May 29, 2019

Hi,

I was able to run the code successfully for SBD.

For pretrained weights, you can check this repo out for download links.
For the Caffe prototxt file, use this.

For converting weights to numpy, use this repo. This repo will help you save each layer's weights as a .npy. I tried saving each npy file into a npz archive but it just wouldn't work. So, I used a small hack by not creating a .npz archive at all (which is default for the repo I shared). So correspondingly, modify the line 386 to point to the directory containing the npy files, not the npz archive. Be careful to use an absolute path, as I faced some errors with relative path. After this, run python modules/CASENet.py and it should work.

Then go ahead with the vis_features to visualize predictions.

For detailed instructions, you could refer to my repo. Hope this helps.

@fkmajiji
Copy link

fkmajiji commented May 29, 2019 via email

@fkmajiji
Copy link

fkmajiji commented May 29, 2019 via email

@anirudh-chakravarthy
Copy link

That's alright. Hope it else others then :)

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

4 participants