Esempio n. 1
0
                    configer.update(["max_batch_size"], old_max_bs - 1)
                else:
                    raise RuntimeError(e)

    from segmentor.trainer import Trainer

    Log.info("self.configer.get('network','interp') {}".format(
        configer.get("network", "interp")))

    model_id = configer.get("network", "model_name")
    bestTrial = getBestTrial("cityscapes", model_id + "_")
    configer.add(["trial_nb"], bestTrial)
    bestWeights = "checkpoints/cityscapes/{}__trial{}_max_performance.pth".format(
        model_id, bestTrial - 1)
    dic = torch.load(bestWeights)

    configer.add(["teacher_interp"], 0)
    model = Trainer(configer)
    model.configer.resume(dic['config_dict'])
    model.seg_net.load_state_dict(dic["state_dict"])

    Log.info("loading {}".format(bestWeights))

    model.configer.add(["teacher_interp"], 0)
    model.configer.add(["network", "interp"], False)
    model.val(model.data_loader.get_valloader(dataset='val'),
              retSimMap=True,
              printallIoU=True,
              endEval=True,
              gradcam=configer.get("test", "gradcam"))
Esempio n. 2
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)
Esempio n. 3
0
            log_file, time.strftime("%Y-%m-%d_%X", time.localtime()))
        configer.update(['logging', 'log_file'], new_log_file)
    else:
        configer.update(['logging', 'logfile_level'], None)

    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()