예제 #1
0
def dnbc(experimental_settings):
    train_dataset, test_dataset = datasets.get_dataset(experimental_settings)

    def _imp(hp_dict, cuda_id, save_path):
        model = models.DenseNetBC(**hp_dict, n_cls=experimental_settings.n_cls)
        train_data, test_data = datasets.get_data(train_dataset,
                                                  test_dataset,
                                                  batch_size=model.batch_size)
        return evaluating_model(model, hp_dict, train_data, test_data, cuda_id,
                                save_path)

    return _imp
예제 #2
0
def mlp(experimental_settings):
    train_dataset, test_dataset = datasets.get_dataset(experimental_settings)
    image_size = experimental_settings.image_size

    def _imp(hp_dict, cuda_id, save_path):
        model = models.MultiLayerPerceptron(**hp_dict,
                                            n_cls=experimental_settings.n_cls,
                                            image_size=image_size)
        train_data, test_data = datasets.get_data(train_dataset,
                                                  test_dataset,
                                                  batch_size=model.batch_size)
        return evaluating_model(model, hp_dict, train_data, test_data, cuda_id,
                                save_path)

    return _imp
예제 #3
0
def cnn(experimental_settings):
    train_dataset, test_dataset = datasets.get_dataset(
        dataset_name=experimental_settings["dataset_name"],
        n_cls=experimental_settings["n_cls"],
        image_size=experimental_settings["image_size"],
        data_frac=experimental_settings["data_frac"],
        biased_cls=experimental_settings["biased_cls"])

    def _imp(hp_dict, cuda_id, save_path):
        model = models.CNN(**hp_dict, n_cls=experimental_settings["n_cls"])
        train_data, test_data = datasets.get_data(train_dataset,
                                                  test_dataset,
                                                  batch_size=model.batch_size)
        return train(model, hp_dict, train_data, test_data, cuda_id, save_path)

    return _imp
예제 #4
0
def transfer(experimental_settings):
    train_dataset, test_dataset, train_idx, valid_idx = datasets.get_dataset(
        experimental_settings)

    def _imp(hp_dict, cuda_id, save_path):
        args = models.Transfer(**hp_dict, \
            n_cls=experimental_settings.n_cls, \
            epochs=experimental_settings.epochs, \
            opt=experimental_settings.opt, \
            mtra=experimental_settings.mtransfer, \
            gcam=experimental_settings.gcam
            )
        train_data, test_data = datasets.get_data(train_dataset,
                                                  test_dataset,
                                                  batch_size=args.batch_size)
        if experimental_settings.mtransfer.upper() == "RESNET50":
            model = m.resnet50(pretrained=True)
            num_ftrs = model.fc.in_features
        elif experimental_settings.mtransfer.upper() == "RESNET152":
            model = m.resnet50(pretrained=True)
            num_ftrs = model.fc.in_features
        elif experimental_settings.mtransfer.upper() == "EFF7":
            model = EfficientNet.from_pretrained('efficientnet-b7')
            num_ftrs = model._fc.in_features
        elif experimental_settings.mtransfer.upper() == "EFF0":
            model = EfficientNet.from_pretrained('efficientnet-b0')
            num_ftrs = model._fc.in_features
        elif experimental_settings.mtransfer.upper() == "WRN50_2":
            model = torch.hub.load('pytorch/vision:v0.6.0',
                                   'wide_resnet50_2',
                                   pretrained=True)
            num_ftrs = model.fc.in_features
        elif experimental_settings.mtransfer.upper() == "WRN101_2":
            model = torch.hub.load('pytorch/vision:v0.6.0',
                                   'wide_resnet50_2',
                                   pretrained=True)
            num_ftrs = model.fc.in_features
        model.fc = nn.Linear(num_ftrs, experimental_settings.n_cls)
        return evaluating_model_t(model, hp_dict, train_data, test_data,
                                  cuda_id, save_path, args, train_idx,
                                  valid_idx)

    return _imp