Skip to content

Commit cc1c8fb

Browse files
mitarshelhamer
authored andcommitted
[pycaffe] expose solver update to do manual solving
a sketch of `solver.step()` done out manually: 1. `solver.net.forward()` 2. `solver.net.backward()` 3. `solver.net.apply_update()` 4. `solver.net.clear_param_diffs()`
1 parent a357693 commit cc1c8fb

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

include/caffe/sgd_solvers.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ class SGDSolver : public Solver<Dtype> {
2323

2424
const vector<shared_ptr<Blob<Dtype> > >& history() { return history_; }
2525

26+
virtual void ApplyUpdate();
27+
2628
protected:
2729
void PreSolve();
2830
Dtype GetLearningRate();
29-
virtual void ApplyUpdate();
3031
virtual void Normalize(int param_id);
3132
virtual void Regularize(int param_id);
3233
virtual void ComputeUpdateValue(int param_id, Dtype rate);

include/caffe/solver.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ class Solver {
9494
*/
9595
virtual inline const char* type() const { return ""; }
9696

97-
protected:
9897
// Make and apply the update value for the current iteration.
9998
virtual void ApplyUpdate() = 0;
99+
100+
protected:
100101
string SnapshotFilename(const string extension);
101102
string SnapshotToBinaryProto();
102103
string SnapshotToHDF5();

python/caffe/_caffe.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ BOOST_PYTHON_MODULE(_caffe) {
507507
.def("restore", &Solver<Dtype>::Restore)
508508
.def("snapshot", &Solver<Dtype>::Snapshot)
509509
.def("share_weights", &share_weights)
510+
.def("apply_update", &Solver<Dtype>::ApplyUpdate)
510511
.add_property("param", bp::make_function(&Solver<Dtype>::param,
511512
bp::return_value_policy<bp::copy_const_reference>()));
512513
BP_REGISTER_SHARED_PTR_TO_PYTHON(Solver<Dtype>);

0 commit comments

Comments
 (0)