當前位置: 首頁>>代碼示例>>Python>>正文


Python Model.state_dict方法代碼示例

本文整理匯總了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] == {})
開發者ID:little1tow,項目名稱:torchbearer,代碼行數:12,代碼來源:test_torchbearer.py

示例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)
開發者ID:little1tow,項目名稱:torchbearer,代碼行數:14,代碼來源:test_torchbearer.py

示例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)
開發者ID:little1tow,項目名稱:torchbearer,代碼行數:21,代碼來源:test_torchbearer.py


注:本文中的torchbearer.Model.state_dict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。