本文整理匯總了Python中torchbearer.Model.predict_generator方法的典型用法代碼示例。如果您正苦於以下問題:Python Model.predict_generator方法的具體用法?Python Model.predict_generator怎麽用?Python Model.predict_generator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torchbearer.Model
的用法示例。
在下文中一共展示了Model.predict_generator方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_predict_generator_pass_state
# 需要導入模塊: from torchbearer import Model [as 別名]
# 或者: from torchbearer.Model import predict_generator [as 別名]
def test_predict_generator_pass_state(self):
torchmodel = MagicMock()
optimizer = MagicMock()
generator = MagicMock()
pass_state = False
steps = 100
torchbearermodel = Model(torchmodel, optimizer, torch.nn.L1Loss(), [])
torchbearermodel.main_state[torchbearer.FINAL_PREDICTIONS] = 1
torchbearermodel._test_loop = Mock()
torchbearermodel.predict_generator(generator, 0, steps, pass_state)
self.assertTrue(torchbearermodel._test_loop.call_args[0][2] == pass_state)
示例2: test_predict_generator_verbose
# 需要導入模塊: from torchbearer import Model [as 別名]
# 或者: from torchbearer.Model import predict_generator [as 別名]
def test_predict_generator_verbose(self):
from torchbearer.callbacks import Tqdm
torchmodel = MagicMock()
optimizer = MagicMock()
generator = MagicMock()
pass_state = False
steps = None
torchbearermodel = Model(torchmodel, optimizer, torch.nn.L1Loss(), [])
torchbearermodel.main_state[torchbearer.FINAL_PREDICTIONS] = 1
torchbearermodel._test_loop = Mock()
torchbearermodel.predict_generator(generator, 1, steps, pass_state)
self.assertIsInstance(torchbearermodel._test_loop.call_args[0][1].callback_list[1], Tqdm)
self.assertTrue(torchbearermodel._test_loop.call_args[0][2] == pass_state)
self.assertTrue(torchbearermodel._test_loop.call_args[0][4] == steps)
示例3: test_predict
# 需要導入模塊: from torchbearer import Model [as 別名]
# 或者: from torchbearer.Model import predict_generator [as 別名]
def test_predict(self):
x = torch.rand(1,5)
pass_state = False
verbose=0
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.predict_generator = Mock()
pred = torchbearermodel.predict_generator
torchbearermodel.predict(x, verbose=verbose, pass_state=pass_state)
pred.assert_called_once()
self.assertTrue(pred.call_args[0][1] == verbose)
self.assertTrue(pred.call_args[1]['pass_state'] == pass_state)