def get_initial_model(): backbone = resnet18(pretrained=True, pyramid_levels=num_levels, k_upsample=3, scale=scale, mean=mean, std=std, k_bneck=1, output_stride=ostride, efficient=False) model_tmp = SemsegModel(backbone, num_classes, k=1, bias=True) model_tmp.load_state_dict(torch.load('weights/rn18_pyramid/model_best.pt'), strict=False) model_tmp.criterion = BoundaryAwareFocalLoss(gamma=.5, num_classes=num_classes, ignore_id=ignore_id) return model_tmp
dataset_train = Vistas(root, transforms=trans_train, subset='training', epoch=epoch) dataset_val = Vistas(root, transforms=trans_val, subset='validation', epoch=epoch) backbone = resnet18(pretrained=True, k_up=3, scale=scale, mean=mean, std=std, output_stride=output_stride, efficient=False) model = SemsegModel(backbone, num_classes, k=1, bias=True) if evaluating: model.load_state_dict(torch.load(f'{dir_path}/stored/model_best.pt'), strict=False) else: model.criterion = BoundaryAwareFocalLoss(gamma=.5, num_classes=num_classes, ignore_id=ignore_id) bn_count = 0 for m in model.modules(): if isinstance(m, nn.BatchNorm2d): bn_count += 1 print(f'Num BN layers: {bn_count}') if not evaluating: lr = 8e-4 lr_min = 1e-6 fine_tune_factor = 4 weight_decay = 1e-4 optim_params = [ {'params': model.random_init_params(), 'lr': lr, 'weight_decay': weight_decay},
def get_initial_model(): tmp_resnet = resnet34(pretrained=True, k_up=3, scale=scale, mean=mean, std=std, output_stride=8, efficient=False) tmp_model = SemsegModel(tmp_resnet, num_classes, k=1, bias=True) tmp_model.load_state_dict(torch.load('weights/76-66_resnet34x8/stored/model_best.pt'), strict=False) model.criterion = BoundaryAwareFocalLoss(gamma=.5, num_classes=num_classes, ignore_id=ignore_id) return tmp_model