Example #1
0
ran_params = get_n_params(model.random_init_params())
spp_params = get_n_params(model.backbone.spp.parameters())
assert total_params == (ft_params + ran_params)
print(
    f'Num params: {total_params:,} = {ran_params:,}(random init) + {ft_params:,}(fine tune)'
)
print(f'SPP params: {spp_params:,}')

if evaluating:
    eval_loaders = [(loader_val, 'val')]  # , (loader_train, 'train')]
    store_dir = f'{dir_path}/out/'
    for d in ['', 'val', 'train', 'training']:
        os.makedirs(store_dir + d, exist_ok=True)
    to_color = ColorizeLabels(color_info)
    to_image = Compose([DenormalizeTh(scale, mean, std), Numpy(), to_color])
    eval_observers = [StorePreds(store_dir, to_image, to_color)]


def reset_optimizer(model, lr=4e-4):
    optim_params = [
        {
            'params': model.random_init_params(),
            'lr': lr,
            'weight_decay': weight_decay
        },
        {
            'params': model.fine_tune_params(),
            'lr': lr / fine_tune_factor,
            'weight_decay': weight_decay / fine_tune_factor
        },
    ]
Example #2
0
                        batch_size=1,
                        collate_fn=custom_collate,
                        num_workers=8)
loader_train = DataLoader(dataset_train,
                          batch_size=bs,
                          collate_fn=custom_collate)

total_params = get_n_params(model.parameters())
ft_params = get_n_params(model.fine_tune_params())
ran_params = get_n_params(model.random_init_params())
assert total_params == (ft_params + ran_params)
print(
    f'Num params: {total_params:,} = {ran_params:,}(random init) + {ft_params:,}(fine tune)'
)

eval_loaders = [(loader_val, 'val')]
eval_observers = []
store_preds = True
if store_preds:
    store_dir = f'{dir_path}/out/'
    store_dir_color = f'{dir_path}/outc/'
    for d in ['', 'val']:
        os.makedirs(store_dir + d, exist_ok=True)
        os.makedirs(store_dir_color + d, exist_ok=True)
    to_color = ColorizeLabels(Cityscapes.color_info)
    to_image = Compose([DenormalizeTh(scale, mean, std), Numpy(), to_color])
    # sp = StoreSubmissionPreds(store_dir, lambda x: x, to_color, store_dir_color)
    # eval_observers += [sp]
    preds = StorePreds(store_dir, to_image, to_color)
    eval_observers += [preds]