Exemplo n.º 1
0
def load_model_simclr(cfg):

    # encoder = get_resnet("resnet50", cfg.dataset.name, False, False)
    # projector = Projector(2048, 64)
    # block = ClBlock(encoder,projector,cfg.device,cfg.N,cfg.batch_size)
    # block = block.to(cfg.device)
    # return block

    proc_group = None
    rank = 0
    cfg.simcl.load = True
    cfg.simcl.rank = rank
    cfg.simcl.device = cfg.device
    cfg.simcl.denoising_prep = True
    simcl = simcl_load_model(cfg.simcl, rank, proc_group)
    return simcl
Exemplo n.º 2
0
def load_model_simclr(cfg):

    # encoder = get_resnet("resnet50", cfg.dataset.name, False, False)
    # projector = Projector(2048, 64)
    # block = ClBlock(encoder,projector,cfg.device,cfg.N,cfg.batch_size)
    # block = block.to(cfg.device)
    # return block

    proc_group = None
    rank = cfg.gpuid
    cfg.simcl.load = True
    cfg.simcl.rank = rank
    cfg.simcl.device = cfg.device
    cfg.simcl.denoising_prep = True
    simcl = simcl_load_model(cfg.simcl, rank, proc_group)
    for name, param in simcl.named_parameters():
        param = param.requires_grad_(False)
    simcl_enc = ClBlockEnc(simcl, cfg.dynamic.frame_size, cfg.d_model_attn)
    return simcl_enc
Exemplo n.º 3
0
def load_models(cfg, rank, proc_group):
    models = edict()

    # HACK: just get the models loaded but parameters are
    # saved together in block
    load = cfg.load
    cfg.load = False
    if cfg.simcl.load:
        cfg.simcl.rank = rank
        cfg.simcl.device = cfg.device
        cfg.simcl.denoising_prep = True
        simcl = simcl_load_model(cfg.simcl, rank, proc_group)
        encoder = simcl.encoder
        projector = simcl.projector
        # encoder.eval()
        # projector.eval()
        for param in encoder.parameters():
            param.requires_grad = False
        for param in projector.parameters():
            param.requires_grad = False
    else:
        encoder = load_encoder(cfg, rank)
        projector = load_projector(cfg, rank)
    decoder = load_decoder(cfg, rank)
    cfg.load = load
    model = DenoisingBlock(encoder, decoder, projector, rank, cfg.N,
                           cfg.batch_size, cfg.agg_enc_fxn, cfg.agg_enc_type)
    # if cfg.load:
    #     load_model_field(cfg,rank,model,"")
    if cfg.use_ddp:
        if cfg.sync_batchnorm:
            fxn = SyncBatchNorm.convert_sync_batchnorm
            model = fxn(model, proc_group)
        if cfg.use_apex:
            model = apex_DDP(model)
        else:
            model = th_DDP(model,
                           device_ids=[rank],
                           find_unused_parameters=True)
    return model