How to use the fastai.layer_optimizer.LayerOptimizer function in fastai

To help you get started, we’ve selected a few fastai examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fastai / fastai / tests / test_layer_optimizer.py View on Github external
def test_set_wds_with_single_value():
    lo = LayerOptimizer(FakeOpt, params_('A', 'B', 'C'), 1e-2, 1e-4)
    lo.set_wds(1e-5)
    check_optimizer_(lo.opt, [(nm, 1e-2, 1e-5) for nm in 'ABC'])
github fastai / fastai / tests / test_layer_optimizer.py View on Github external
def test_set_lrs_with_too_few_values():
    lo = LayerOptimizer(FakeOpt, params_('A', 'B', 'C'), 1e-2, 1e-4)
    with pytest.raises(AssertionError):
        lo.set_lrs([2e-2, 3e-2])
    # Also make sure the optimizer didn't change.
    check_optimizer_(lo.opt, [(nm, 1e-2, 1e-4) for nm in 'ABC'])
github fastai / fastai / tests / test_layer_optimizer.py View on Github external
def test_construction_with_singleton_lr_and_wd():
    lo = LayerOptimizer(FakeOpt, params_('A', 'B', 'C'), 1e-2, 1e-4)
    check_optimizer_(lo.opt, [(nm, 1e-2, 1e-4) for nm in 'ABC'])
github fastai / fastai / tests / test_layer_optimizer.py View on Github external
def test_construction_with_lists_of_lrs_and_wds():
    lo = LayerOptimizer(
        FakeOpt,
        params_('A', 'B', 'C'),
        (1e-2, 2e-2, 3e-2),
        (9e-3, 8e-3, 7e-3),
    )
    check_optimizer_(
        lo.opt,
        [('A', 1e-2, 9e-3), ('B', 2e-2, 8e-3), ('C', 3e-2, 7e-3)],
    )
github fastai / fastai / tests / test_layer_optimizer.py View on Github external
def test_construction_with_too_few_wds():
    with pytest.raises(AssertionError):
        LayerOptimizer(FakeOpt, params_('A', 'B', 'C'), 1e-2, (9e-3, 8e-3))
github fastai / fastai / tests / test_layer_optimizer.py View on Github external
def test_set_wds_with_list_of_values():
    lo = LayerOptimizer(FakeOpt, params_('A', 'B', 'C'), 1e-2, 1e-4)
    lo.set_wds([9e-3, 8e-3, 7e-3])
    check_optimizer_(
        lo.opt,
        [('A', 1e-2, 9e-3), ('B', 1e-2, 8e-3), ('C', 1e-2, 7e-3)],
    )
github fastai / fastai / tests / test_layer_optimizer.py View on Github external
def test_construction_with_too_few_lrs():
    with pytest.raises(AssertionError):
        LayerOptimizer(FakeOpt, params_('A', 'B', 'C'), (1e-2, 2e-2), 1e-4)
github jantic / DeOldify / fasterai / training.py View on Github external
def _generate_clr_sched(self, model:nn.Module, use_clr_beta:(int), lrs:[float], cycle_len:int):
        wds = 1e-7
        opt_fn = partial(optim.Adam, betas=(0.0,0.9))
        layer_opt = LayerOptimizer(opt_fn, self._get_inner_module(model).get_layer_groups(), lrs, wds)
        div,pct = use_clr_beta[:2]
        moms = use_clr_beta[2:] if len(use_clr_beta) > 3 else None
        cycle_end =  None
        return CircularLR_beta(layer_opt, len(self.md.trn_dl)*cycle_len, on_cycle_end=cycle_end, div=div, pct=pct, momentums=moms)