This class represents a generic parent class for mapping between keys and data samples.
The class represents a subclass/child class of data.Dataset, inheriting its functionality.
This class is composed of a __init__ constructor, a __getitem__(), supporting fetching a data sample for a given key, and __len__(), which returns the size of the dataset.
Args:
X (HDF5 datafile): hierarchically organized input data
y (HDF5 datafile): hierarchically organized output data
Returns:
input_data (torch.tensor): Tensor representation of the input data
label_data (torch.tensor): Tensor representation of the output data
int: lenght of the output
"""
def__init__(self,X,y):
self.X=X
self.y=y
def__getitem__(self,index):
input_data=torch.from_numpy(self.X[index])
label_data=torch.from_numpy(self.y[index])
returninput_data,label_data
def__len__(self):
returnlen(self.y)
defget_datasetsHDF5(data_parameters):
"""Data Loader Function.
THIS FUNCTION IS NOT DEPRECATED: Loader function rewritten.
This function loads the various data file and returns the relevand mapped datasets.
Args:
data_parameters (dict): Dictionary containing relevant information for the datafiles.
returnvolume# This is assumed to be the default orientation
eliforientation=="axial":
returnvolume.transpose((1,2,0))
eliforientation=="coronal":
returnvolume.transpose((2,0,1))
else:
raiseValueError(
"Orientation value is invalid. It must be either >>coronal<<, >>axial<< or >>sagital<< ")
returnvolume,header
defload_and_preprocess(file_paths,orientation):
"""Load & Preprocess
This function is composed of two other function calls: one that calls a function loading the data, and another which preprocesses the data to the required format.
# TODO: Need to check if any more proprocessing would be required besides summing the tracts!
Args:
file_paths (list): List containing the input data and target labelled output data
orientation (str): String detailing the current view (COR, SAG, AXL)
Returns:
volume (np.array): Array of training image data of data type dtype.
label_map (np.array): Array of labelled image data of data type dtype.
header (class): 'nibabel.nifti1.Nifti1Header' class object, containing image metadata