Having problem on creating my custom filler

90 views
Skip to first unread message

jim D.

unread,
May 14, 2016, 4:10:38 PM5/14/16
to Caffe Users

hi guys,


I hope you can help me with the following.


I am trying to create a custom filler. Firstly, i add new class in file caffe/include/caffe/filler.hpp. Lets say I want to add a class named class GaborFiller. I used XavierFiller as template and I wrote some simple code, that actually doesn't do anything more than calling a function from a different file to initialize weight blob with gabor filters. I also modified the parser at the end of the same file.


The code for that class is just below:


template <typename Dtype>

class GaborFiller : public Filler<Dtype> {

public:

explicit GaborFiller(const FillerParameter& param)

: Filler<Dtype>(param) {}

virtual void Fill(Blob<Dtype>* blob) {

CHECK(blob->count());

caffe_random_gabor_kernels<Dtype>(blob->num(), blob->channels(), blob->height(), blob->width(), blob->mutable_cpu_data());

CHECK_EQ(this->filler_param_.sparse(), -1)

<< "Sparsity not supported by this Filler.";

}

};



The main initialization is done in caffe_random_gabor_kernels(). I add that function in file caffe/src/caffe/util/math_functions.cpp , where are located caffe_rng_uniform and caffe_rng_gaussian located, which are used in other fillers of fille.hpp.


I actually just placed that function, just under caffe_rng_gaussian(), in math_function.cpp. I also added a custom function for random numbers.


I declared that function based caffe_rng_gaussian(), like :


template <typename Dtype>

void caffe_random_gabor_kernels(const int N, const int K, const int H, const int W, Dtype* r) {

blah … blah … blah...

}


and its templates like:


template

void caffe_random_gabor_kernels<float>(const int N, const int K, const int H, const int W, float* r);

template

void caffe_random_gabor_kernels<double>(const int N, const int K, const int H, const int W, double* r);

------



The problem is when I try to re-compile caffe, using : make all -j4, it throws me errors like :


- ./include/caffe/filler.hpp: In member function ‘virtual void caffe::GaborFiller<Dtype>::Fill(caffe::Blob<Dtype>*)’:

./include/caffe/filler.hpp:276:2: error: ‘caffe_random_gabor_kernels’ was not declared in this scope

caffe_random_gabor_kernels<Dtype>(blob->num(), blob->channels(), blob->height(), blob->width(), blob->mutable_cpu_data());

^

./include/caffe/filler.hpp:276:34: error: expected primary-expression before ‘>’ token

caffe_random_gabor_kernels<Dtype>(blob->num(), blob->channels(), blob->height(), blob->width(), blob->mutable_cpu_data());



Its like it can't see my function in math_functions.cpp. As I said, I just place here right after caffe_rng_gaussian(). One more thing is, the first time I tried to re-compile caffe with those 2 modified files, I had a simple syntax error in the caffe_random_gabor_kernels, where instead of

using name r[index...] to refer to weights blob, I used blob[index...]. I changed it, so I only get the message above. That means that my function is not completely invisible. Then why it throws that error , I posted above ????

Reply all
Reply to author
Forward
0 new messages