def check_chainer_model_equal(self, act, exp):
self.assertEqual(act.__class__, exp.__class__)
self.assertEqual(len(act._params), len(exp._params))
# Check for parameters
for act_param, exp_param in zip(act._params, exp._params):
act_param = getattr(act, act_param)
exp_param = getattr(exp, exp_param)
numpy.testing.assert_array_equal(act_param.data, exp_param.data)
# Recursively checking for children
if isinstance(act, chainer.ChainList):
self.assertEqual(len(act), len(exp))
for act_link, exp_link in zip(act, exp):
self.check_chainer_model_equal(act_link, exp_link)
else:
if not hasattr(act, "_children"):
return
for act_child, exp_child in zip(act._children, exp._children):
act_child = getattr(act, act_child)
exp_child = getattr(exp, exp_child)
self.check_chainer_model_equal(act_child, exp_child)
评论列表
文章目录