【发布时间】:2016-08-27 07:04:57
【问题描述】:
为了使调试过程更容易,我决定声明一个全局变量,它是一个指向类对象的指针,并使用全局指针来访问任何低级类变量。该类是使用模板定义的。在构造类对象的某个时刻,我可以分配全局指针并在其他地方使用它。
就我而言,我尝试添加一个变量类型 Net(这是用于 py-faster-rcnn 代码)。
namespace caffe {
...
int glb_layer_id;
template <typename Dtype>
shared_ptr<Net<Dtype>> glb_Net;
template <typename Dtype>
void Net<Dtype>::Init(const NetParameter& in_param) {
...
}
添加int glb_layer_id 没问题,我可以在其他地方使用该变量。但是当我添加一个变量glb_Net时,下面出现了编译错误。
ckim@stph45:~/Neuro/py-faster-rcnn.org] !make
make -C caffe-fast-rcnn/
make: 进入目录/home/ckim/Neuro/py-faster-rcnn.org/caffe-fast-rcnn'
CXX src/caffe/net.cpp
src/caffe/net.cpp:41: error: template declaration of 'caffe::Net<Dtype>* caffe::glb_Net'
src/caffe/net.cpp: In member function 'void caffe::Net<Dtype>::Init(const caffe::NetParameter&)':
src/caffe/net.cpp:75: error: 'glb_Net' was not declared in this scope
make: *** [.build_debug/src/caffe/net.o] Error 1
make: Leaving directory/home/ckim/Neuro/py-faster-rcnn.org/caffe-fast-rcnn'
Net 类最初是使用模板定义的,因此我必须对 Net 变量使用相同的模板。但是可以看到,有一个错误。问题是什么?任何帮助表示赞赏。 (顺便说一下,在 Caffe 中,我也想知道如何从 Net 内部的层访问 Net 变量。
【问题讨论】: