lijiaman / CASENet

30 stars 2 forks source link

Getting pytorch weights from caffe model #3

Open exploringNewThings opened 6 years ago

exploringNewThings commented 6 years ago

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 commented 5 years ago

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 commented 5 years ago

hello @fkmajiji did you run this code successfully?

fkmajiji commented 5 years ago

hello @fkmajiji did you run this code successfully?

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

anirudh-chakravarthy commented 5 years ago

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 commented 5 years ago

Thank you very much for your reply and guidance. Your reply is very detailed which Will help me a lot. You are very enthusiastic!

发自我的移动手机

在 2019年5月29日,下午2:44,Anirudh S Chakravarthy notifications@github.com 写道:

Hi,

I was able to run the code successfully for SBD. For converting weights to numpy, use this repo. This repo will help you save each layer's weights as a .npy

For pretrained weights, you can check out this repo. For the prototxt file, use this.

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. Hope this helps.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

fkmajiji commented 5 years ago

I’m sorry. For some reason, I didn’t continue run this code

发自我的移动手机

在 2019年4月13日,上午10:42,琉璃梦 notifications@github.com 写道:

hello @fkmajiji did you run this code successfully?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

anirudh-chakravarthy commented 5 years ago

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