Exemplo n.º 1
0
def run(configer, trial):

    if configer.get('phase') == 'train' and configer.get("network", "optuna"):
        configer.update(["train", "batch_size"],
                        trial.suggest_int("batch_size",
                                          2 * torch.cuda.device_count(),
                                          configer.get("max_batch_size"),
                                          step=1))

        configer.update(["lr", "base_lr"],
                        trial.suggest_float("base_lr",
                                            0.0001,
                                            0.0019,
                                            step=0.0003))
        configer.update(["lr", "lr_policy"],
                        trial.suggest_categorical("lr_policy",
                                                  ["step", "lambda_poly"]))

        configer.get("lr", "step")["gamma"] = trial.suggest_float("gamma",
                                                                  0.3,
                                                                  0.9,
                                                                  step=0.2)
        configer.get("lr",
                     "step")["step_size"] = trial.suggest_int("step_size",
                                                              50,
                                                              400,
                                                              step=50)

        configer.update(["optim", "optim_method"],
                        trial.suggest_categorical("optim_method",
                                                  ["sgd", "adam"]))
        configer.update(["lr", "nbb_mult"],
                        trial.suggest_float("nbb_mult", 0.25, 4, step=0.25))

        if configer.get("optim", "optim_method") == "sgd":
            configer.get("optim", "sgd")["weight_decay"] = trial.suggest_float(
                "weight_decay", 0.00001, 0.0002, step=0.00003)
            configer.get("optim",
                         "sgd")["nesterov"] = trial.suggest_categorical(
                             "nesterov", [False, True])

        else:
            configer.get("optim",
                         "adam")["weight_decay"] = trial.suggest_float(
                             "weight_decay", 0.0001, 0.0010, step=0.0002)

        configer.get("network",
                     "loss_weights")["aux_loss"] = trial.suggest_float(
                         "aux_loss", 0.2, 0.8, step=0.2)
        configer.get("network",
                     "loss_weights")["seg_loss"] = trial.suggest_float(
                         "seg_loss", .5, 2.0, step=0.5)

        if configer.get("network", "use_teach"):
            configer.update(["teacher_temp"],
                            trial.suggest_float("teacher_temp", 1, 21, step=5))
            configer.update(["teacher_interp"],
                            trial.suggest_float("teacher_interp",
                                                0.1,
                                                1,
                                                step=0.1))
        else:
            configer.update(["teacher_interp"], 0)

        lossType = trial.suggest_categorical(
            "loss_type", ["fs_auxce_loss", "fs_auxohemce_loss "])
        lossType = lossType.replace(" ", "")
        configer.update(["loss", "loss_type"], lossType)

    if not configer.exists("trial_nb"):
        configer.add(["trial_nb"], trial.number)
    else:
        configer.update(["trial_nb"], trial.number)

    model = None
    if configer.get('method') == 'fcn_segmentor':
        if configer.get('phase') == 'train':
            from segmentor.trainer import Trainer
            model = Trainer(configer)
        elif configer.get('phase') == 'test':
            from segmentor.tester import Tester
            model = Tester(configer)
        elif configer.get('phase') == 'test_offset':
            from segmentor.tester_offset import Tester
            model = Tester(configer)
    else:
        Log.error('Method: {} is not valid.'.format(configer.get('task')))
        exit(1)

    if configer.get('phase') == 'train':
        miou = model.train(trial)
        return miou

    elif configer.get('phase').startswith('test') and configer.get(
            'network', 'resume') is not None:
        model.test()
    else:
        Log.error('Phase: {} is not valid.'.format(configer.get('phase')))
        exit(1)
Exemplo n.º 2
0
    Log.init(logfile_level=configer.get('logging', 'logfile_level'),
             stdout_level=configer.get('logging', 'stdout_level'),
             log_file=configer.get('logging', 'log_file'),
             log_format=configer.get('logging', 'log_format'),
             rewrite=configer.get('logging', 'rewrite'))

    model = None
    if configer.get('method') == 'fcn_segmentor':
        if configer.get('phase') == 'train':
            from segmentor.trainer import Trainer
            model = Trainer(configer)
        elif configer.get('phase') == 'test':
            from segmentor.tester import Tester
            model = Tester(configer)
        elif configer.get('phase') == 'test_offset':
            from segmentor.tester_offset import Tester
            model = Tester(configer)
    else:
        Log.error('Method: {} is not valid.'.format(configer.get('task')))
        exit(1)

    if configer.get('phase') == 'train':
        model.train()
    elif configer.get('phase').startswith('test') and configer.get(
            'network', 'resume') is not None:
        model.test()
    else:
        Log.error('Phase: {} is not valid.'.format(configer.get('phase')))
        exit(1)