当前位置: 首页>>代码示例>>Python>>正文


Python Model.fit方法代码示例

本文整理汇总了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)
开发者ID:little1tow,项目名称:torchbearer,代码行数:29,代码来源:test_torchbearer.py

示例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)
开发者ID:little1tow,项目名称:torchbearer,代码行数:20,代码来源:test_torchbearer.py


注:本文中的torchbearer.Model.fit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。