本文整理匯總了Python中torchbearer.Model.fit方法的典型用法代碼示例。如果您正苦於以下問題:Python Model.fit方法的具體用法?Python Model.fit怎麽用?Python Model.fit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torchbearer.Model
的用法示例。
在下文中一共展示了Model.fit方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_fit_valid_sets_args
# 需要導入模塊: from torchbearer import Model [as 別名]
# 或者: from torchbearer.Model import fit [as 別名]
def test_fit_valid_sets_args(self, gtvs):
x = torch.rand(1,5)
y = torch.rand(1,5)
val_data = (1,2)
val_split = 0.2
shuffle = False
torchmodel = MagicMock()
torchmodel.forward = Mock(return_value=1)
optimizer = MagicMock()
metric = Metric('test')
loss = torch.tensor([2], requires_grad=True)
criterion = Mock(return_value=loss)
gtvs.return_value = (1, 2)
torchbearermodel = Model(torchmodel, optimizer, criterion, [metric])
torchbearermodel.fit_generator = Mock()
torchbearermodel.fit(x, y, 1, validation_data=val_data, validation_split=val_split, shuffle=shuffle)
gtvs.assert_called_once()
self.assertTrue(list(gtvs.call_args[0][0].numpy()[0]) == list(x.numpy()[0]))
self.assertTrue(list(gtvs.call_args[0][1].numpy()[0]) == list(y.numpy()[0]))
self.assertTrue(gtvs.call_args[0][2] == val_data)
self.assertTrue(gtvs.call_args[0][3] == val_split)
self.assertTrue(gtvs.call_args[1]['shuffle'] == shuffle)
示例2: test_fit_no_valid
# 需要導入模塊: from torchbearer import Model [as 別名]
# 或者: from torchbearer.Model import fit [as 別名]
def test_fit_no_valid(self):
x = torch.rand(1, 5)
y = torch.rand(1, 5)
torchmodel = MagicMock()
torchmodel.forward = Mock(return_value=1)
optimizer = MagicMock()
metric = Metric('test')
loss = torch.tensor([2], requires_grad=True)
criterion = Mock(return_value=loss)
torchbearermodel = Model(torchmodel, optimizer, criterion, [metric])
torchbearermodel.fit_generator = Mock()
fit = torchbearermodel.fit_generator
torchbearermodel.fit(x, y, 1, validation_split=None)
self.assertTrue(fit.call_args[1]['validation_generator'] is None)