c++neural-networkdeep-learningcaffebias-neuron

How can I know if there is no Bias exists in a layer using caffe framwork with c++ program


I'm trying to read weight and bias in a caffe framework with c++. Here is my code

shared_ptr<Blob<float> >& weight = current_layer->blobs()[0];//for weights
shared_ptr<Blob<float> >& bias = current_layer->blobs()[1];//for bias

But if for some model the bias is not present or defined it throughs a segmentation fault error.

So which function returns a boolean value which indicates the presens of bias and how to call the function in c++?


Solution

  • The blobs returned from current_layer->blobs() are stored in a std::vector, you can use its size property:

    if (current_layer->blobs().size() > 1) {
        shared_ptr<Blob<float> >& bias = current_layer->blobs()[1];//for bias
    }
    

    See this similar answer for python interface for more details.