本文整理匯總了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)