在caffe中获取Blob数据
Getting Blob data in caffe
我正在尝试从 caffe 中绘制图层,如下所示。
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();
}
}
为此我有错误
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
这个错误是什么意思?
早期版本的caffe,没问题。我以前做过。
现在可能是什么错误?
该错误翻译为 "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" 建议使用运算符。或 -> 访问对象的方法和 operator() 的使用。
如果这样做,您可能会更改 const 对象,因此这是一个错误,除非启用了宽容模式。
我正在尝试从 caffe 中绘制图层,如下所示。
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();
}
}
为此我有错误
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
这个错误是什么意思? 早期版本的caffe,没问题。我以前做过。 现在可能是什么错误?
该错误翻译为 "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" 建议使用运算符。或 -> 访问对象的方法和 operator() 的使用。
如果这样做,您可能会更改 const 对象,因此这是一个错误,除非启用了宽容模式。