本文整理汇总了Python中torchbearer.Model.state_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Model.state_dict方法的具体用法?Python Model.state_dict怎么用?Python Model.state_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torchbearer.Model
的用法示例。
在下文中一共展示了Model.state_dict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_state_dict_kwargs
# 需要导入模块: from torchbearer import Model [as 别名]
# 或者: from torchbearer.Model import state_dict [as 别名]
def test_state_dict_kwargs(self):
keywords = {'destination': None, 'prefix': '', 'keep_vars': False}
torchmodel = MagicMock()
optimizer = MagicMock()
torchbearermodel = Model(torchmodel, optimizer, torch.nn.L1Loss(), [])
torchbearermodel.state_dict(**keywords)
self.assertTrue(torchmodel.state_dict.call_args[1] == keywords)
self.assertTrue(optimizer.state_dict.call_args[1] == {})
示例2: test_state_dict
# 需要导入模块: from torchbearer import Model [as 别名]
# 或者: from torchbearer.Model import state_dict [as 别名]
def test_state_dict(self):
torchmodel = torch.nn.Sequential(torch.nn.Linear(1,1))
torchmodel_state = torchmodel.state_dict()
optimizer = torch.optim.SGD(torchmodel.parameters(), 0.1)
optimizer_state = optimizer.state_dict()
torchbearermodel = Model(torchmodel, optimizer, torch.nn.L1Loss(), [])
torchbearer_state = torchbearermodel.state_dict()
self.assertTrue(torchbearer_state[torchbearer.MODEL] == torchmodel_state)
self.assertTrue(torchbearer_state[torchbearer.OPTIMIZER] == optimizer_state)
示例3: test_load_state_dict
# 需要导入模块: from torchbearer import Model [as 别名]
# 或者: from torchbearer.Model import state_dict [as 别名]
def test_load_state_dict(self):
key_words = {'strict': True}
torchmodel = torch.nn.Sequential(torch.nn.Linear(1,1))
torchmodel.load_state_dict = Mock()
torch_state = torchmodel.state_dict()
optimizer = torch.optim.SGD(torchmodel.parameters(), 0.1)
optimizer.load_state_dict = Mock()
optimizer_state = optimizer.state_dict()
torchbearermodel = Model(torchmodel, optimizer, torch.nn.L1Loss(), [])
torchbearer_state = torchbearermodel.state_dict()
torchbearermodel.load_state_dict(torchbearer_state, **key_words)
self.assertTrue(torchmodel.load_state_dict.call_args[0][0] == torch_state)
self.assertTrue(optimizer.load_state_dict.call_args[0][0] == optimizer_state)
self.assertTrue(torchmodel.load_state_dict.call_args[1] == key_words)