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++?
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.