diff options
author | Jonathan L Long <jonlong@cs.berkeley.edu> | 2014-04-25 14:50:36 -0700 |
---|---|---|
committer | Jonathan L Long <jonlong@cs.berkeley.edu> | 2014-04-25 15:49:06 -0700 |
commit | f5c285813ccc32f60c975f254fe99860f8a50a26 (patch) | |
tree | 037e42bb41f2d9309f1900e2a5035e9db38a0a80 /python | |
parent | c6f1011bb4fe49383b12bca1fa5753c6421ad2ef (diff) | |
download | caffe-f5c285813ccc32f60c975f254fe99860f8a50a26.tar.gz caffe-f5c285813ccc32f60c975f254fe99860f8a50a26.tar.bz2 caffe-f5c285813ccc32f60c975f254fe99860f8a50a26.zip |
pycaffe: add unary CaffeNet constructor for uninitialized nets
Note that parameters are uninitialized, not zero-filled.
Diffstat (limited to 'python')
-rw-r--r-- | python/caffe/_caffe.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/python/caffe/_caffe.cpp b/python/caffe/_caffe.cpp index 0e6bac26..a443f897 100644 --- a/python/caffe/_caffe.cpp +++ b/python/caffe/_caffe.cpp @@ -134,17 +134,28 @@ class CaffeLayer { // A simple wrapper over CaffeNet that runs the forward process. struct CaffeNet { + // For cases where parameters will be determined later by the Python user, + // create a Net with unallocated parameters (which will not be zero-filled + // when accessed). + explicit CaffeNet(string param_file) { + Init(param_file); + } + CaffeNet(string param_file, string pretrained_param_file) { - CheckFile(param_file); + Init(param_file); CheckFile(pretrained_param_file); - - net_.reset(new Net<float>(param_file)); net_->CopyTrainedLayersFrom(pretrained_param_file); } explicit CaffeNet(shared_ptr<Net<float> > net) : net_(net) {} + void Init(string param_file) { + CheckFile(param_file); + net_.reset(new Net<float>(param_file)); + } + + virtual ~CaffeNet() {} inline void check_array_against_blob( @@ -308,6 +319,7 @@ class CaffeSGDSolver { BOOST_PYTHON_MODULE(_caffe) { boost::python::class_<CaffeNet>( "Net", boost::python::init<string, string>()) + .def(boost::python::init<string>()) .def("Forward", &CaffeNet::Forward) .def("ForwardPrefilled", &CaffeNet::ForwardPrefilled) .def("Backward", &CaffeNet::Backward) |