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 )


    model = model_dict[params.model]()
    
    model = model.cuda()
    tmp = torch.load(modelfile)
    state = tmp['state']

    state_keys = list(state.keys())
    for i, key in enumerate(state_keys):
        if "feature." in key:
            newkey = key.replace("feature.","")  # an architecture model has attribute 'feature', load architecture feature to backbone by casting name from 'feature.trunk.xx' to 'trunk.xx'  
            state[newkey] = state.pop(key)
        else:
Exemple #2
0
                                                   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,
                                                       n_query=15,
                                                       **few_shot_params)
        novel_loader = datamgr.get_data_loader(num_aug=params.gen_examples)

    elif params.test_dataset == "ChestX":
        print("Loading ChestX")
        datamgr = Chest_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)  ### what if aug is true???

    ## uncomment code below to see if code is same across loaders

    #########################################################################

    acc_all = []
    start_epoch = params.start_epoch
    stop_epoch = params.stop_epoch
    print(freeze_backbone)

    # replace finetine() with your own method
    iter_num = 600
            1, int(16 * params.test_n_way / params.train_n_way)
        )  #if test_n_way is smaller than train_n_way, reduce n_query to keep batch size small
        train_few_shot_params = dict(n_way=params.train_n_way,
                                     n_support=params.n_shot)
        test_few_shot_params = dict(n_way=params.test_n_way,
                                    n_support=params.n_shot)

        #if params.dataset == "miniImageNet":
        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')