Exemplo n.º 1
0
            model_3 = model_3.get_all_feat(all_feats.cuda()).cuda()
        del all_feats  ##clear memory
        del data_loader2
        del datamgr2
        del x
        del x_var
        ds = True

    freeze_backbone = params.freeze_backbone
    ##################################################################
    pretrained_dataset = "miniImageNet"

    if params.test_dataset == "ISIC":
        print("Loading ISIC")
        datamgr = ISIC_few_shot.SetDataManager2(image_size,
                                                n_eposide=iter_num,
                                                n_query=15,
                                                **few_shot_params)
        novel_loader = datamgr.get_data_loader(num_aug=params.gen_examples)

    elif params.test_dataset == "EuroSAT":
        print("Loading EuroSAT")
        datamgr = EuroSAT_few_shot.SetDataManager2(image_size,
                                                   n_eposide=iter_num,
                                                   n_query=15,
                                                   **few_shot_params)
        novel_loader = datamgr.get_data_loader(num_aug=params.gen_examples)

    elif params.test_dataset == "CropDisease":
        print("Loading CropDisease")
        datamgr = CropDisease_few_shot.SetDataManager2(image_size,
                                                       n_eposide=iter_num,
Exemplo n.º 2
0
        base_datamgr = miniImageNet_few_shot.SetDataManager(
            image_size, n_query=n_query, **train_few_shot_params)
        base_loader = base_datamgr.get_data_loader(aug=params.train_aug)

        # use unlabeled data from these novel domains for adversarial domain adaptation
        # TODO: since the data is unlabeled, we need to modify data manager / data loader
        if params.dataset == "ChestX":
            target_datamgr = Chest_few_shot.SetDataManager(
                image_size, n_query=n_query, **train_few_shot_params)

        elif params.dataset == "EuroSAT":
            target_datamgr = EuroSAT_few_shot.SetDataManager(
                image_size, n_query=n_query, **train_few_shot_params)

        elif params.dataset == "ISIC2018":
            target_datamgr = ISIC_few_shot.SetDataManager(
                image_size, n_query=n_query, **train_few_shot_params)

        elif params.dataset == "CropDiseases":
            target_datamgr = CropDisease_few_show.SetDataManager(
                image_size, n_query=n_query, **train_few_shot_params)

        else:
            raise ValueError('Unknown dataset')

        target_loader = target_datamgr.get_data_loader(novel_file,
                                                       aug=params.train_aug)

        if params.adversarial or params.adaptFinetune:
            # TODO: check argv
            target_datamgr = SetDataManager(image_size,
                                            n_query=n_query,
Exemplo n.º 3
0
    #params.save_iter = 399
    if params.save_iter != -1:
        modelfile   = get_assigned_file(checkpoint_dir, params.save_iter)
    elif params.method in ['baseline'] :
        modelfile   = get_resume_file(checkpoint_dir)
    else:
        modelfile   = get_best_file(checkpoint_dir)

    if params.save_iter != -1:
        outfile = os.path.join( checkpoint_dir.replace("checkpoints","features"), params.dataset + "_" + str(params.save_iter)+ ".hdf5") 
    else:
        outfile = os.path.join( checkpoint_dir.replace("checkpoints","features"), params.dataset + ".hdf5") 


    if params.dataset in ["ISIC"]:
        datamgr         = ISIC_few_shot.SimpleDataManager(image_size, batch_size = 64)
        data_loader     = datamgr.get_data_loader(aug = False )

    elif params.dataset in ["EuroSAT"]:

        datamgr         = EuroSAT_few_shot.SimpleDataManager(image_size, batch_size = 64)
        data_loader     = datamgr.get_data_loader(aug = False )

    elif params.dataset in ["CropDisease"]:
        datamgr         = CropDisease_few_shot.SimpleDataManager(image_size, batch_size = 64)
        data_loader     = datamgr.get_data_loader(aug = False )

    elif params.dataset in ["ChestX"]:
        datamgr         = Chest_few_shot.SimpleDataManager(image_size, batch_size = 64)
        data_loader     = datamgr.get_data_loader(aug = False )
Exemplo n.º 4
0
                                                       n_query=n_query,
                                                       mode="train",
                                                       **train_few_shot_params)
        base_loader = datamgr.get_data_loader(aug=params.train_aug)
        #the above line waste a lot of time
        val_datamgr = miniImageNet_few_shot.SetDataManager(
            image_size, n_query=n_query, mode="val", **test_few_shot_params)
        val_loader = val_datamgr.get_data_loader(aug=False)

        #=========== ISIC or EuroSAT ========
        few_shot_params = dict(n_way=params.test_n_way,
                               n_support=params.n_shot)
        if params.method == 'mytpnadaptisic':
            print("init mytpnadaptisic")
            datamgr = ISIC_few_shot.SetDataManager(image_size,
                                                   n_eposide=600,
                                                   n_query=n_query,
                                                   **few_shot_params)
        elif params.method == 'mytpnadapteurosat':
            print("init mytpnadapteurosat")
            datamgr = EuroSAT_few_shot.SetDataManager(image_size,
                                                      n_eposide=600,
                                                      n_query=n_query,
                                                      **few_shot_params)
        else:
            raise ValueError('Unknown method')
        novel_loader = datamgr.get_data_loader(aug=False)
        #=====================================

        #======= load pretrained model and ckpt =======
        model = MyTPN_Adapt(model_dict[params.model], **train_few_shot_params)