test_serializer.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:nmtrain 作者: philip30 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号