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


Python Model._test_loop方法代碼示例

本文整理匯總了Python中torchbearer.Model._test_loop方法的典型用法代碼示例。如果您正苦於以下問題:Python Model._test_loop方法的具體用法?Python Model._test_loop怎麽用?Python Model._test_loop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在torchbearer.Model的用法示例。


在下文中一共展示了Model._test_loop方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_test_loop_stop_training

# 需要導入模塊: from torchbearer import Model [as 別名]
# 或者: from torchbearer.Model import _test_loop [as 別名]
    def test_test_loop_stop_training(self):
        metric = Metric('test')
        metric_list = MetricList([metric])

        data = [(torch.Tensor([1]), torch.Tensor([1])), (torch.Tensor([2]), torch.Tensor([2])),
                (torch.Tensor([3]), torch.Tensor([3]))]
        validation_generator = DataLoader(data)
        validation_steps = len(data)

        callback = MagicMock()
        callback_List = torchbearer.CallbackList([callback])

        torchmodel = Mock(return_value=1)
        optimizer = MagicMock()

        criterion = Mock(return_value=2)

        torchbearermodel = Model(torchmodel, optimizer, criterion, [metric])

        state = torchbearermodel.main_state.copy()
        state.update({torchbearer.METRIC_LIST: metric_list, torchbearer.VALIDATION_GENERATOR: validation_generator,
                      torchbearer.CallbackList: callback_List, torchbearer.VALIDATION_STEPS: validation_steps,
                      torchbearer.CRITERION: criterion, torchbearer.STOP_TRAINING: True, torchbearer.METRICS: {}})

        torchbearerstate = torchbearermodel._test_loop(state, callback_List, False, Model._load_batch_standard, num_steps=None)

        self.assertTrue(torchbearerstate[torchbearer.MODEL].call_count == 1)
開發者ID:little1tow,項目名稱:torchbearer,代碼行數:29,代碼來源:test_torchbearer.py

示例2: test_test_loop_metrics

# 需要導入模塊: from torchbearer import Model [as 別名]
# 或者: from torchbearer.Model import _test_loop [as 別名]
    def test_test_loop_metrics(self):
        metric = Metric('test')
        metric.process = Mock(return_value={'test': 0})
        metric.process_final = Mock(return_value={'test': 0})
        metric.reset = Mock(return_value=None)
        metric_list = MetricList([metric])

        data = [(torch.Tensor([1]), torch.Tensor([1])), (torch.Tensor([2]), torch.Tensor([2])), (torch.Tensor([3]), torch.Tensor([3]))]
        validation_generator = DataLoader(data)
        validation_steps = len(data)

        callback = MagicMock()
        callback_List = torchbearer.CallbackList([callback])

        torchmodel = MagicMock()
        torchmodel.forward = Mock(return_value=1)
        optimizer = MagicMock()

        criterion = Mock(return_value=2)

        torchbearermodel = Model(torchmodel, optimizer, criterion, [metric])

        state = torchbearermodel.main_state.copy()
        state.update({torchbearer.METRIC_LIST: metric_list, torchbearer.VALIDATION_GENERATOR: validation_generator,
                 torchbearer.CallbackList: callback_List, torchbearer.MODEL: torchmodel, torchbearer.VALIDATION_STEPS: validation_steps,
                 torchbearer.CRITERION: criterion, torchbearer.STOP_TRAINING: False, torchbearer.METRICS: {}})

        torchbearerstate = torchbearermodel._test_loop(state, callback_List, False, Model._load_batch_standard, num_steps=None)

        torchbearerstate[torchbearer.METRIC_LIST].metric_list[0].reset.assert_called_once()
        self.assertTrue(torchbearerstate[torchbearer.METRIC_LIST].metric_list[0].process.call_count == len(data))
        torchbearerstate[torchbearer.METRIC_LIST].metric_list[0].process_final.assert_called_once()
        self.assertTrue(torchbearerstate[torchbearer.METRICS]['test'] == 0)
開發者ID:little1tow,項目名稱:torchbearer,代碼行數:35,代碼來源:test_torchbearer.py

示例3: test_main_loop_validation_setup

# 需要導入模塊: from torchbearer import Model [as 別名]
# 或者: from torchbearer.Model import _test_loop [as 別名]
    def test_main_loop_validation_setup(self):
        metric = Metric('test')

        data = [(torch.Tensor([1]), torch.Tensor([1])), (torch.Tensor([2]), torch.Tensor([2])), (torch.Tensor([3]), torch.Tensor([3]))]
        generator = DataLoader(data)
        valgenerator = DataLoader(data)
        train_steps = 2

        epochs = 1

        callback = MagicMock()

        torchmodel = MagicMock()
        torchmodel.forward = Mock(return_value=1)
        optimizer = MagicMock()

        loss = torch.tensor([2], requires_grad=True)
        criterion = Mock(return_value=loss)

        torchbearermodel = Model(torchmodel, optimizer, criterion, [metric])
        torchbearermodel._test_loop = Mock()
        torchbearerstate = torchbearermodel.fit_generator(generator, train_steps, epochs, 0, [callback],
                                                          validation_generator=valgenerator, initial_epoch=0,
                                                          pass_state=False)

        self.assertTrue(torchbearerstate[torchbearer.VALIDATION_STEPS] == len(valgenerator))
        self.assertTrue(torchbearerstate[torchbearer.VALIDATION_GENERATOR] == valgenerator)
開發者ID:little1tow,項目名稱:torchbearer,代碼行數:29,代碼來源:test_torchbearer.py

示例4: test_predict_generator_pass_state

# 需要導入模塊: from torchbearer import Model [as 別名]
# 或者: from torchbearer.Model import _test_loop [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)
開發者ID:little1tow,項目名稱:torchbearer,代碼行數:16,代碼來源:test_torchbearer.py

示例5: test_evaluate_generator_steps

# 需要導入模塊: from torchbearer import Model [as 別名]
# 或者: from torchbearer.Model import _test_loop [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)
開發者ID:little1tow,項目名稱:torchbearer,代碼行數:16,代碼來源:test_torchbearer.py

示例6: test_evaluate_generator_verbose

# 需要導入模塊: from torchbearer import Model [as 別名]
# 或者: from torchbearer.Model import _test_loop [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)
開發者ID:little1tow,項目名稱:torchbearer,代碼行數:18,代碼來源:test_torchbearer.py

示例7: test_predict_generator_verbose

# 需要導入模塊: from torchbearer import Model [as 別名]
# 或者: from torchbearer.Model import _test_loop [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)
開發者ID:little1tow,項目名稱:torchbearer,代碼行數:20,代碼來源:test_torchbearer.py


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