Extract filters and bias
Hi all, I want to know how can i only extract filters and biases from my own caffemodel. I read the tutorial of " filter visualization example", but i dont know how to do when using my own caffemodel.(I dont know which part i should modify in that reference code) I want to extract filters and bisaes and then save into .mat file for MATLAB. can anyone help me? please and thanks.
I used matcaffe (the matlab wrapper) for the same issue
- open matlab
- make sure the path to your matcaffe (caffe_root/matlab/caffe) is in the defpath. If not, add it manually or write: addpath(your path); in matlab
- initialize your caffe Net by writing: caffe('init', 'your_net_definition.prototxt','your_model.caffemodel').
- do a forward pass by writing: caffe('forward', {});
- and then extract the weights: weights = caffe('get_weights'); "weights" will contain the weights and biases of all the layers. You will see it from its structure when you open it
- save "weights" into a mat file: save('path_to_folder/filename.mat', 'weights');
Thanks for your answer! I did it step by step, but still have error : Error using caffe Expected 3 arguments, got 2
Error in model (line 4) caffe('init','deploy.prototxt','super_resolution_iter_1000.caffemodel');
And the following is my code:
addpath('/home/jensen810814/code/caffe/matlab/caffe/'); addpath('/home/jensen810814/code/caffe/examples/super_resolution/'); addpath('/home/jensen810814/code/caffe/examples/super_resolution/Model/'); caffe('init','deploy.prototxt','super_resolution_iter_1000.caffemodel'); caffe('forward',{}); weights = caffe('get_weights'); save('/home/jensen810814/code/caffe/examples/super_resolution/filter_data.mat','weights');
Can you tell me how to deal with it? thanks a lot. (btw, did the 'your_net_definition.prototxt' mean deploy.prototxt or train_protptxt which i used to train my net?)
I meant the train.prototxt (or train_test.prototxt if you defined both train and test nets in one prototxt file). Does it work if you use this prototxt file?
I tried both files...but still have same problem QAQ.
I solve this question. Thanks again.
@jensen810814 how did you solve the question that defined both train and test nets in one prototxt file?