And*_*rew 6 python ipython caffe
从文档中我认为有一个构造函数采用NetParameter参数,
explicit Net(const NetParameter¶m);
但是当我尝试使用它时:
import caffe
from caffe import layers as L
from google.protobuf import text_format
def logreg(hdf5, batch_size):
# logistic regression: data, matrix multiplication, and 2-class softmax loss
n = caffe.NetSpec()
n.data, n.label = L.HDF5Data(batch_size=batch_size, source=hdf5, ntop=2)
n.ip1 = L.InnerProduct(n.data, num_output=2, weight_filler=dict(type='xavier'))
n.accuracy = L.Accuracy(n.ip1, n.label)
n.loss = L.SoftmaxWithLoss(n.ip1, n.label)
return n.to_proto()
logreg_str = str(logreg('examples/hdf5_classification/data/test.txt', 10))
net_param = caffe.proto.caffe_pb2.NetParameter()
_ = text_format.Merge(logreg_str, net_param)
print type(net_param);
caffe.Net(net_param, caffe.TEST)
Run Code Online (Sandbox Code Playgroud)
ipython中出现以下错误
<class 'caffe.proto.caffe_pb2.NetParameter'>
---------------------------------------------------------------------------
ArgumentError Traceback (most recent call last)
<ipython-input-20-edce76ff13a1> in <module>()
14
15 print type(net_param);
---> 16 caffe.Net(net_param, caffe.TEST)
ArgumentError: Python argument types in
Net.__init__(Net, NetParameter, int) did not match C++ signature:
__init__(boost::python::api::object, std::string, std::string, int)
__init__(boost::python::api::object, std::string, int)
Run Code Online (Sandbox Code Playgroud)
那么我在这里做错了什么?我该如何使用这个构造函数?
注意:我知道如何使用"从磁盘构造函数中读取文件",我想使用NetParameter /或理解它为什么不起作用.
Shai评论后编辑:
我在2015年7月26日使用此命令获得了caffe:git clone https://github.com/BVLC/caffe.git
这是我磁盘上的文件:
~/caffe/src/caffe$ grep NetParameter net.cpp | head -1
Net<Dtype>::Net(const NetParameter& param) {
~/caffe/src/caffe$ ~/caffe/build/tools/caffe -version
caffe
Run Code Online (Sandbox Code Playgroud)
-version开关似乎什么都不做.我浏览了源代码,无法找到版本号.
你的代码没有任何问题。事实上,C++ 中有一个 Net 类的重载构造函数,但目前 Python 接口尚未公开它。python 接口仅限于带有文件参数的构造函数。
我不确定简单地将其暴露在 python/caffe/_caffe.cpp 中是否是阻止我们使用 NetParameter 构造 python Net 对象的唯一原因,或者是否需要更精细的更改。
| 归档时间: |
|
| 查看次数: |
2078 次 |
| 最近记录: |