Define the Dataset and Testset

1. The MRNet Dataset:

read_dir[source]

read_dir(naming, dir_files)

Read the directory and determine all files within typically include all files from naming Args: dir_files: filepath for the folders with the categories Return: filenames: dict of filenames with their corresponding category(axial...)

read_labels[source]

read_labels(datadir)

Read the csv files and store as a single tensor

class MRNetDataset[source]

MRNetDataset(args, transform=None, mode='train') :: Dataset

Magnetic Resonance Imaging Dataset of 1129 knee joints in training data and 119 for validation. The Dataset contains information about: root_dir: General file directory contains two dictionarys with the corresponding infos: dirs[{"train", "valid"}][{"abn", "acl", "men"}] -> abnormal, acl-rupture, meniscus

2. Transformations

class RandomCrop[source]

RandomCrop(args)

Randomly crop to only some slices of the image

class TriplePrep[source]

TriplePrep(args)

Randomly crop to only some slices of the image Further pad the picture to the 224 size!

class RandomRotate[source]

RandomRotate()

rotate all images with same random angle

class MiddleCrop[source]

MiddleCrop(args)

Crop to only some slices of the image from the middle

class Rescale[source]

Rescale(args, dtype='float32')

Rescale a whole MR set to a new size

class ToTensor[source]

ToTensor(type='FloatTensor')

Convert ndarrays in sample to Tensors.

class Normalize[source]

Normalize(usegpu=True)

Normalize the array

3. Loading the dataset and dataloader

load_mrnet_datasets[source]

load_mrnet_datasets(args)

Retruns the training and validation dataset with the corresponding loader

test_dataset[source]

test_dataset(args, valid_loader)

return the required model depending on the arguments:

load_test_batch[source]

load_test_batch(args)

This function creates a "pseudo" batch for simple testing

args.model_type = "vqvae"
args.dim = 3
args = compat_args(args)
batch = load_test_batch(args)
batch["img"].shape
torch.Size([1, 3, 16, 256, 256])
args.model_type = "vqvae"
args.dim = 2
args = compat_args(args)
batch = load_test_batch(args)
batch["img"].shape
torch.Size([1, 3, 256, 256])
args.model_type = "diagnosis"
args.dim = 3
args = compat_args(args)
batch = load_test_batch(args)
batch["img"]["axial"].shape
torch.Size([1, 49, 224, 224])

The KneeXray dataset

class GaussianBlur[source]

GaussianBlur(sigma=[0.1, 2.0])

Gaussian blur augmentation in SimCLR https://arxiv.org/abs/2002.05709

class TwoCropsTransform[source]

TwoCropsTransform(base_transform, adv_transform)

Take two random crops of one image as the query and key. from: https://arxiv.org/abs/1805.01978 https://github.com/facebookresearch/moco/blob/master/main_moco.py

load_kneexray_datasets[source]

load_kneexray_datasets(args)

Load the kneexray dataset

get_loader[source]

get_loader(args, root_dir)