FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #4348 from nitnelave/python/clear_params · hongwuya/Caffe-HRT@a1a9d30 · GitHub

Repository navigation

Commit a1a9d30

Browse files
authored
Merge pull request #4348 from nitnelave/python/clear_params
Add clear_param_diffs to the python net interface
2 parents 4af9062 + 892c78d commit a1a9d30

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎python/caffe/_caffe.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ BOOST_PYTHON_MODULE(_caffe) {
299299
.def("_forward", &Net<Dtype>::ForwardFromTo)
300300
.def("_backward", &Net<Dtype>::BackwardFromTo)
301301
.def("reshape", &Net<Dtype>::Reshape)
302+
.def("clear_param_diffs", &Net<Dtype>::ClearParamDiffs)
302303
// The cast is to select a particular overload.
303304
.def("copy_from", static_cast<void (Net<Dtype>::*)(const string)>(
304305
&Net<Dtype>::CopyTrainedLayersFrom))

‎python/caffe/test/test_net.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ def test_forward_backward(self):
6363
self.net.forward()
6464
self.net.backward()
6565

66+
def test_clear_param_diffs(self):
67+
# Run a forward/backward step to have non-zero diffs
68+
self.net.forward()
69+
self.net.backward()
70+
diff = self.net.params["conv"][0].diff
71+
# Check that we have non-zero diffs
72+
self.assertTrue(diff.max() > 0)
73+
self.net.clear_param_diffs()
74+
# Check that the diffs are now 0
75+
self.assertTrue((diff == 0).all())
76+
6677
def test_inputs_outputs(self):
6778
self.assertEqual(self.net.inputs, [])
6879
self.assertEqual(self.net.outputs, ['loss'])

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL