本文整理汇总了Python中torchbearer.Model.evaluate_generator方法的典型用法代码示例。如果您正苦于以下问题:Python Model.evaluate_generator方法的具体用法?Python Model.evaluate_generator怎么用?Python Model.evaluate_generator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torchbearer.Model
的用法示例。
在下文中一共展示了Model.evaluate_generator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_evaluate_generator_steps
# 需要导入模块: from torchbearer import Model [as 别名]
# 或者: from torchbearer.Model import evaluate_generator [as 别名]
def test_evaluate_generator_steps(self):
torchmodel = MagicMock()
optimizer = MagicMock()
generator = MagicMock()
pass_state = False
steps = 100
torchbearermodel = Model(torchmodel, optimizer, torch.nn.L1Loss(), [])
torchbearermodel.main_state[torchbearer.METRICS] = 1
torchbearermodel._test_loop = Mock()
torchbearermodel.evaluate_generator(generator, 0, steps, pass_state)
self.assertTrue(torchbearermodel._test_loop.call_args[0][4] == steps)
示例2: test_evaluate_generator_verbose
# 需要导入模块: from torchbearer import Model [as 别名]
# 或者: from torchbearer.Model import evaluate_generator [as 别名]
def test_evaluate_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.METRICS] = 1
torchbearermodel._test_loop = Mock()
torchbearermodel.evaluate_generator(generator, 1, steps, pass_state)
self.assertIsInstance(torchbearermodel._test_loop.call_args[0][1].callback_list[0], Tqdm)
示例3: test_evaluate
# 需要导入模块: from torchbearer import Model [as 别名]
# 或者: from torchbearer.Model import evaluate_generator [as 别名]
def test_evaluate(self):
x = torch.rand(1,5)
y = 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.evaluate_generator = Mock()
ev = torchbearermodel.evaluate_generator
torchbearermodel.evaluate(x, y, verbose=verbose, pass_state=pass_state)
ev.assert_called_once()
self.assertTrue(ev.call_args[0][1] == verbose)
self.assertTrue(ev.call_args[1]['pass_state'] == pass_state)