Example #1
0
def _demodata_toy_harn():
    # This will train a toy model with toy data using netharn
    import netharn as nh
    hyper = nh.HyperParams(
        **{
            'workdir': ub.ensure_app_cache_dir('torch_liberator/tests/deploy'),
            'name': 'demo_liberator_static',
            'xpu': nh.XPU.coerce('cpu'),
            'datasets': {
                'train': nh.data.ToyData2d(size=3, rng=0)
            },
            'loaders': {
                'batch_size': 64
            },
            'model': (nh.models.ToyNet2d, {}),
            'optimizer': (nh.optimizers.SGD, {
                'lr': 0.0001
            }),
            'criterion': (nh.criterions.FocalLoss, {}),
            'initializer': (nh.initializers.KaimingNormal, {}),
            'monitor': (nh.Monitor, {
                'max_epoch': 1
            }),
        })
    harn = nh.FitHarn(hyper)
    harn.preferences['use_tensorboard'] = False
    harn.preferences['log_gradients'] = False
    harn.preferences['timeout'] = 1
    return harn
Example #2
0
def _demodata_trained_dpath():
    # This will train a toy model with toy data using netharn
    import netharn as nh
    hyper = nh.HyperParams(
        **{
            'workdir': ub.ensure_app_cache_dir('netharn/tests/deploy'),
            'nice': 'deploy_demo_static',
            'xpu': nh.XPU.cast('cpu'),
            'datasets': {
                'train': nh.data.ToyData2d(size=3, rng=0)
            },
            'loaders': {
                'batch_size': 64
            },
            'model': (nh.models.ToyNet2d, {}),
            'optimizer': (nh.optimizers.SGD, {
                'lr': 0.0001
            }),
            'criterion': (nh.criterions.FocalLoss, {}),
            'initializer': (nh.initializers.KaimingNormal, {}),
            'monitor': (nh.Monitor, {
                'max_epoch': 1
            }),
        })
    harn = nh.FitHarn(hyper)
    harn.run()  # TODO: make this run faster if we don't need to rerun
    if len(list(glob.glob(join(harn.train_dpath, '*.py')))) > 1:
        # If multiple models are deployed some hash changed. Need to reset
        harn.initialize(reset='delete')
        harn.run()  # don't relearn if we already finished this one
    return harn.train_dpath
Example #3
0
 def _demodata_toy_sesssion(workdir, name='demo_session', lr=1e-4):
     """
     workdir = ub.ensure_app_cache_dir('netharn/tests/sessions')
     workdir
     """
     # This will train a toy model with toy data using netharn
     import netharn as nh
     hyper = nh.HyperParams(
         **{
             'workdir': ub.ensure_app_cache_dir('netharn/tests/sessions'),
             'name': name,
             'xpu': nh.XPU.coerce('cpu'),
             'datasets': {
                 'train': nh.data.ToyData2d(size=3, rng=0),
                 'vali': nh.data.ToyData2d(size=3, rng=0)
             },
             'loaders': {
                 'batch_size': 64
             },
             'model': (nh.models.ToyNet2d, {}),
             'optimizer': (nh.optimizers.SGD, {
                 'lr': lr
             }),
             'criterion': (nh.criterions.FocalLoss, {}),
             'initializer': (nh.initializers.KaimingNormal, {}),
             'monitor': (nh.Monitor, {
                 'max_epoch': 1
             }),
         })
     harn = nh.FitHarn(hyper)
     harn.preferences['use_tensorboard'] = False
     harn.preferences['timeout'] = 1
     harn.run()  # TODO: make this run faster if we don't need to rerun