Beispiel #1
0
stats_dataset = corda.CORDA(
    encoder_df,
    corda_base_path=corda_basepath,
    rsna_base_path=rsna_basepath,
    chest_base_path=chestxray_basepath,
    transform=stats_transforms
)

stats_dataloader = torch.utils.data.DataLoader(
    stats_dataset, batch_size=10,
    shuffle=False, num_workers=10,
    worker_init_fn=lambda id: utils.set_seed(seed),
    pin_memory=True
)

mean, std = utils.get_mean_and_std(stats_dataloader)
print(f'Mean & std for corda+{args.pretrain}:', mean, std)



# CORDA ONLY (balance majority class)
train_df = corda_train_df
val_df = corda_val_df
test_df = corda_test_df

if args.train == 'corda':
    train_df = pd.concat((
        corda_train_df[corda_train_df.covid == 0].sample(n=84, random_state=42),
        corda_train_df[corda_train_df.covid == 1].sample(n=84, random_state=42)
    ))
])

train_dataset = corda.CORDAChestXRay(stats_train_df,
                                     chest_base_path=dataset_path,
                                     corda_base_path=corda_basepath,
                                     transform=transforms)

train_dataloader = torch.utils.data.DataLoader(
    train_dataset,
    batch_size=10,
    shuffle=False,
    num_workers=10,
    worker_init_fn=lambda id: utils.set_seed(seed),
    pin_memory=True)

mean, std = utils.get_mean_and_std(train_dataloader)
print(f'Mean & std for corda+chestxray (unprocessed):', mean, std)

# %%
train_transforms = torchvision.transforms.Compose([
    torchvision.transforms.Resize(256),
    torchvision.transforms.RandomAffine(0, translate=(0, 0.1),
                                        scale=(1, 1.10)),
    torchvision.transforms.CenterCrop(224),
    torchvision.transforms.ToTensor(),
    torchvision.transforms.Normalize(mean, std)
])

transforms = torchvision.transforms.Compose([
    torchvision.transforms.Resize(256),
    torchvision.transforms.CenterCrop(224),