0

I am trying to plot layer out of caffe as follow.

    int ncols = (int)(sqrt (blob.channels()));
    int nrows;
    if(blob.channels()%ncols!=0){
        nrows = ncols+1;
    }

    int Rows = nrows*blob.height();
    int Cols = ncols*blob.width();
    cv::Mat image = cv::Mat::zeros(Rows+nrows, Cols+ncols, CV_32FC1);
    ///////Plotting output of individual layer
    if(blob.height()>1 && blob.width()>1){
            cv::Size ss(blob.width(), blob.height());
            Dtype* data = blob.mutable_cpu_data();
            int r=0; int c=0;
            for(int k=0; k < blob.channels(); k++)
            {
              cv::Mat channel(ss, CV_32FC1, data);

              channel.copyTo(image(cv::Rect(c*blob.width()+1, r*blob.height()+1,  blob.width(), blob.height())));
              c++;
              if(c>0 &&c%ncols==0){
                  r++;
                  c=0;
              }

              channel.release();
              data += ss.area();
            }
    }

For that I have error as

CXX src/caffe/net.cpp
src/caffe/net.cpp: In instantiation of ‘void caffe::Net<Dtype>::ForwardDebugInfo(int) [with Dtype = float]’:
src/caffe/net.cpp:1040:1:   required from here
src/caffe/net.cpp:632:49: error: passing ‘const caffe::Blob<float>’ as ‘this’ argument discards qualifiers [-fpermissive]
             Dtype* data = blob.mutable_cpu_data();
                                                 ^
In file included from ./include/caffe/layer.hpp:8:0,
                 from src/caffe/net.cpp:11:
./include/caffe/blob.hpp:225:10: note:   in call to ‘Dtype* caffe::Blob<Dtype>::mutable_cpu_data() [with Dtype = float]’
   Dtype* mutable_cpu_data();
          ^
src/caffe/net.cpp: In instantiation of ‘void caffe::Net<Dtype>::ForwardDebugInfo(int) [with Dtype = double]’:
src/caffe/net.cpp:1040:1:   required from here
src/caffe/net.cpp:632:49: error: passing ‘const caffe::Blob<double>’ as ‘this’ argument discards qualifiers [-fpermissive]
             Dtype* data = blob.mutable_cpu_data();
                                                 ^
In file included from ./include/caffe/layer.hpp:8:0,
                 from src/caffe/net.cpp:11:
./include/caffe/blob.hpp:225:10: note:   in call to ‘Dtype* caffe::Blob<Dtype>::mutable_cpu_data() [with Dtype = double]’
   Dtype* mutable_cpu_data();
          ^
Makefile:575: recipe for target '.build_debug/src/caffe/net.o' failed
make: *** [.build_debug/src/caffe/net.o] Error 1

What does that error means? Earlier version of caffe, it was fine. I did it before. Now what could be the error?

1 Answer 1

2

That error translates as "You pass a const object as this argument to a non-const method mutable_cpu_data"

const Dtype* cpu_data() const;
Dtype* mutable_cpu_data();

"Passing an object as this argument" suggests use of operators . or -> to access object's method and use of operator().

If you do that, you potentially can change const object, so it's an error, unless permissive mode engaged.

Sign up to request clarification or add additional context in comments.

2 Comments

So the error happened at this line Dtype* data = blob.mutable_cpu_data(); how can I fix it?
Thanks I removed const from this line (Blob<Dtype>& blob = *top_vecs_[layer_id][top_id];) and it is ok.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.