Skip to content

Commit

Permalink
Merge pull request BVLC#4348 from nitnelave/python/clear_params
Browse files Browse the repository at this point in the history
Add clear_param_diffs to the python net interface
  • Loading branch information
shelhamer authored Jul 11, 2016
2 parents 4af9062 + 892c78d commit a1a9d30
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/caffe/_caffe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ BOOST_PYTHON_MODULE(_caffe) {
.def("_forward", &Net<Dtype>::ForwardFromTo)
.def("_backward", &Net<Dtype>::BackwardFromTo)
.def("reshape", &Net<Dtype>::Reshape)
.def("clear_param_diffs", &Net<Dtype>::ClearParamDiffs)
// The cast is to select a particular overload.
.def("copy_from", static_cast<void (Net<Dtype>::*)(const string)>(
&Net<Dtype>::CopyTrainedLayersFrom))
Expand Down
11 changes: 11 additions & 0 deletions python/caffe/test/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ def test_forward_backward(self):
self.net.forward()
self.net.backward()

def test_clear_param_diffs(self):
# Run a forward/backward step to have non-zero diffs
self.net.forward()
self.net.backward()
diff = self.net.params["conv"][0].diff
# Check that we have non-zero diffs
self.assertTrue(diff.max() > 0)
self.net.clear_param_diffs()
# Check that the diffs are now 0
self.assertTrue((diff == 0).all())

def test_inputs_outputs(self):
self.assertEqual(self.net.inputs, [])
self.assertEqual(self.net.outputs, ['loss'])
Expand Down

0 comments on commit a1a9d30

Please sign in to comment.