caffe icon indicating copy to clipboard operation
caffe copied to clipboard

Define a specific filter to be used in convs

Open Engin007 opened this issue 11 years ago • 4 comments

Hello BVLC community,

I would like to know how to modify the "learned" filters by the net. I tried to search through the cpp files to find the appropriate one but did not find any. I have my problem analyzed and have an idea to apply certain filters to hopefully improve the results of my net. I found that convoluting according to certain filter might obtain a better feature to describe my problem. Could you help me in locating were that code might be? I am a bit lost trying to search for the appropriate cpp.. I have wrote my own filter and would like to apply it to my data.

Thank you

Engin007 avatar Dec 13 '14 18:12 Engin007

Hi Engin007, caffe::Net exposes layers() and layer_names() methods that you can use to find and get the layer you are looking for. All Layer classes expose a public blobs() method (see Layer.hpp) which returns a ref to a vector of shared pointers to Blob. If you look at conv_layer.cpp, you can see ConvolutionLayer uses blobs_[0] for the filter weights, and blobs_[1] for the biases. Once you've got the blob pointer, I think you can stuff your filters in by accessing individual filter values with something like:

*(blob->mutable_cpu_data() + blob->offset(0,c,h,w)) = some float, where c is the channel, h is height, w is width.

I haven't tried most of this myself so no guarantees, but it should give you somewhere to start.

jyegerlehner avatar Dec 14 '14 02:12 jyegerlehner

Thank you for your reply! I will give it a shot, I have overlooked the blob structure (which actually should be my starting point) . Thank you for pointing that out

Engin007 avatar Dec 14 '14 23:12 Engin007

Check out the editing model parameters example on the home page that shows how to assign parameters through Python and save the resulting model. In this way you can transplant your custom filters into a model.

Note that you should ask usage questions like this on the caffe-users mailing list.

shelhamer avatar Dec 15 '14 02:12 shelhamer

I did not know where to post these issues, now I do :) thanks for the help

Engin007 avatar Dec 15 '14 10:12 Engin007