Well so I have tried:

- [1] Moving everything to Windows, but same problem there - no frozen system, but bluescreen.
- [2] Tested under Pytorch 0.4.1 - Same Problem.
- [3] Set integrated GPU as display card and use NVIDIA Gpus only for PyTorch - Same Problem.

So I can pretty much rule out OS-problems. Also, I don’t think there is a hardware issue, since the PSU should be powerful enough.

So in a last hope, I’ve attached a functional version of the dataset. I hope there is some error in there :D.

In it, I accumulate every relevant path to my data files in a dictionary and, well, load it in `_getitem_()`

.

```
"""=================================="""
"""====== Load Basic Libraries ======"""
"""=================================="""
import numpy as np
import os, sys, time, csv, itertools, copy
from tqdm import tqdm, trange
import torch
import torch.nn as nn
from torch.utils.data import Dataset
sys.path.insert(0, '../Helper_Functions')
sys.path.insert(0, '../Network_Library')
import helper_functions as hf
import Network_Auxiliaries as aux
import scipy.ndimage.measurements as snm
import skimage.transform as st
import pandas as pd
""""""""""""""""""""""""""""""""""""
"""===== Dataset 4 Training ==="""
""""""""""""""""""""""""""""""""""""
class Dataset_Training(Dataset):
def __init__(self, base_path, train_val_split=0.8, perc_data=1., standardize=True, augment=False, crop=[224,224], seed=1):
self.rng = np.random.RandomState(seed)
### Read in CSVs containing paths to data slices (0.5MB numpy files .npy)
v = pd.read_csv(base_path+"Assign_2D_Volumes.csv",header=0)
l = pd.read_csv(base_path+"Assign_2D_LiverMasks.csv",header=0)
n = pd.read_csv(base_path+"Assign_2D_LesionMasks.csv",header=0)
wle = pd.read_csv(base_path+"Assign_2D_LesionWmaps.csv",header=0)
### Get unique data volumess
self.available_volumes = sorted(list(set(np.array(v["Volume"]))),key=lambda x: int(x.split('-')[-1]))
self.rng.shuffle(self.available_volumes)
self.available_volumes = self.available_volumes[:int(len(self.available_volumes)*perc_data)]
self.available_volumes = self.available_volumes[:int(len(self.available_volumes)*train_val_split)]
### Create path dictionary
roi_vicinity = 4
self.training_volumes = {key:{"LesWmap_Paths":[], "LesMask_Paths":[],"LivMask_Paths":[],"Has Lesion":[], "Vol_Paths":[],"LesSlices":[], "LivSlices":[]} for key in self.available_volumes}
iter_vals = tqdm(v["Volume"])
iter_vals.set_description('Reading and assigning training data paths')
for i,vol in enumerate(iter_vals):
if np.sum(l["Has Mask"][i:i+roi_vicinity]) and vol in self.available_volumes:
self.training_volumes[vol]["Vol_Paths"].append(v["Slice Path"][i])
self.training_volumes[vol]["LivMask_Paths"].append(l["Slice Path"][i])
self.training_volumes[vol]["LesMask_Paths"].append(n["Slice Path"][i])
self.training_volumes[vol]["Has Lesion"].append(n["Has Mask"][i])
self.training_volumes[vol]["LesWmap_Paths"].append(wle["Slice Path"][i])
for i,vol in enumerate(self.available_volumes):
if np.sum(self.training_volumes[vol]["Has Lesion"]):
self.training_volumes[vol]["LesSlices"] = list(np.where(self.training_volumes[vol]["Has Lesion"])[0])
self.training_volumes[vol]["LivSlices"] = list(set(np.arange(0,len(self.training_volumes[vol]["Has Lesion"])))-set(self.training_volumes[vol]["LesSlices"]))
else:
self.training_volumes[vol]["LesSlices"] = []
self.training_volumes[vol]["LivSlices"] = list(np.arange(0,len(self.training_volumes[vol]["Has Lesion"])))
self.n_files = np.sum([len(self.training_volumes[key]["Vol_Paths"]) for key in self.training_volumes.keys()])
### Other input arguments
self.standardize = standardize
self.augment = augment
self.crop_size = crop
self.n_crops = n_crops
self.channel_size = channel_size
def __getitem__(self, idx):
#>> Data Volume Array Of Interest
VOI = self.available_volumes[self.rng.randint(0,len(self.available_volumes))]
#>> There are two types of Slices - randomly pick one
chosen_slice_from_VOI = self.rng.randint(0,3)>0 and len(self.training_volumes[VOI]["LesSlices"])>0
#>> Pick a random slice from either category
if chosen_slice_from_VOI:
SOI = self.rng.choice(self.training_volumes[VOI]["LesSlices"])
else:
SOI = self.rng.choice(self.training_volumes[VOI]["LivSlices"])
#>> Load Slice of Interest
V2O = np.expand_dims(np.expand_dims(np.load(self.training_volumes[VOI]["Vol_Paths"][SOI]),0),0)
#>> Perform data standardization if required
V2O = hf.normalize(V2O, supply_mode="orig")
#>> Load The Respective Target Mask
Les2O = np.load(self.training_volumes[VOI]["LesMask_Paths"][SOI])
Les2O = np.expand_dims(np.expand_dims(Les2O,0),0)
#>> Load An Additional Crop Mask
Liv2O = np.expand_dims(np.expand_dims(np.load(self.training_volumes[VOI]["LivMask_Paths"][SOI]),0),0)
#>> And A Used Cost Map
Wmap2O = np.expand_dims(np.expand_dims(np.load(self.training_volumes[VOI]["LesWmap_Paths"][SOI]),0),0)
#>> Images Are Too Big So They Get Cropped.
files_to_crop = [V2O, Les2O, Wmap2O]
#>> But First, I Augment Them (rotation & zooming with scipy.ndimage.interpolation.rotate/zoom)
files_to_crop = list(hf.augment_2D(files_to_crop, copy_files=True, seed=self.rng.randint(0,1e8), is_mask = [0,1,0]))
#>> Crop Images - Function slices random subarray from input arrays in files_to_crop. Liv2O provides the regions in which to crop.
crops_for_picked_batch = hf.get_crops_per_batch(files_to_crop, Liv2O, crop_size=self.crop_size)
V2O = crops_for_picked_batch[0]
Les2O = crops_for_picked_batch[1]
Wmap2O = crops_for_picked_batch[2]
return_dict = {"vol":V2O[0,:], "lesmask":Les2O[0,:], "wmap": Wmap2O[0,:].astype('float')}
return return_dict
def __len__(self):
return int(self.n_files)
""""""""""""""""""""""""""""""""""""
"""===== Dataset 4 Validation ==="""
""""""""""""""""""""""""""""""""""""
class Dataset_Validation(Dataset):
def __init__(self, base_path, tv_split=0.85, standardize=True, seed=1, is_training=False, perc_data=1.):
self.tv_split = tv_split
self.standardize = standardize
self.rng = np.random.RandomState(seed)
### Read in CSVs to data files (npy-files, 0.5MB)
v = pd.read_csv(base_path+"Assign_2D_Volumes.csv",header=0)
l = pd.read_csv(base_path+"Assign_2D_LiverMasks.csv",header=0)
n = pd.read_csv(base_path+"Assign_2D_LesionMasks.csv",header=0)
### Get unique volumes
self.available_volumes = sorted(list(set(np.array(v["Volume"]))),key=lambda x: int(x.split('-')[-1]))
self.rng.shuffle(self.available_volumes)
self.available_volumes = self.available_volumes[:int(len(self.available_volumes)*perc_data)]
self.available_volumes = self.available_volumes[int(len(self.available_volumes)*tv_split):]
self.available_volumes.sort()
self.validation_volumes = {key:{"LesMask_Paths":[],"LivMask_Paths":[],"Vol_Paths":[]} for key in self.available_volumes}
iter_vals = tqdm(v["Volume"])
iter_vals.set_description('Reading and assigning validation data paths')
for i,vol in enumerate(iter_vals):
if vol in self.available_volumes:
if l['Has Mask'][i]:
self.validation_volumes[vol]["Vol_Paths"].append(v["Slice Path"][i])
self.validation_volumes[vol]["LivMask_Paths"].append(l["Slice Path"][i])
self.validation_volumes[vol]["LesMask_Paths"].append(n["Slice Path"][i])
self.volume_separators = [len(self.validation_volumes[vol]["Vol_Paths"]) for vol in self.validation_volumes.keys()]
self.validation_data = {"vol":[], "lesmask":[], "livmask":[]}
for vol in self.available_volumes:
for i in range(len(self.validation_volumes[vol]["Vol_Paths"])):
vol_slices = self.validation_volumes[vol]["Vol_Paths"][i]
liv_slices = self.validation_volumes[vol]["LivMask_Paths"][i]
les_slices = self.validation_volumes[vol]["LesMask_Paths"][i]
self.validation_data["vol"].append(vol_slices)
self.validation_data["livmask"].append(liv_slices)
self.validation_data["lesmask"].append(les_slices)
self.n_files = len(self.validation_data["vol"])
def __getitem__(self, idx):
#>> Slice of Interest
V2O = np.expand_dims(np.expand_dims(np.load(self.validation_data["vol"][idx]),0),0)
#>> Data Standardization
V2O = hf.normalize(V2O, supply_mode="orig")
Les2O = np.expand_dims(np.expand_dims(np.load(self.validation_data["lesmask"][idx]),0),0)
Liv2O = np.expand_dims(np.expand_dims(np.load(self.validation_data["livmask"][idx]),0),0)
return_dict = {"vol":V2O[0,:], "lesmask":Les2O[0,:], "livmask":Liv2O[0,:]}
return return_dict
def __len__(self):
return self.n_files
```