Skip to content

Commit

Permalink
Merge pull request BVLC#365 from longjon/pycaffe-empty-nets
Browse files Browse the repository at this point in the history
Add unary CaffeNet constructor for uninitialized nets
  • Loading branch information
shelhamer committed Apr 25, 2014
2 parents f6e0441 + 653271f commit 70b8023
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions python/caffe/_caffe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 70b8023

Please sign in to comment.