add unit test for clear_param_diffs
authorValentin Tolmer <valentin.tolmer@gmail.com>
Wed, 22 Jun 2016 00:42:31 +0000 (17:42 -0700)
committerValentin Tolmer <valentin.tolmer@gmail.com>
Wed, 22 Jun 2016 00:42:31 +0000 (17:42 -0700)
python/caffe/test/test_net.py

index 4cacfcd..7fb9f47 100644 (file)
@@ -63,6 +63,17 @@ class TestNet(unittest.TestCase):
         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'])