Skip to content

Instantly share code, notes, and snippets.

@ahmedbesbes
Created July 15, 2019 17:02
Show Gist options
  • Save ahmedbesbes/70b9b5bd78eb694fe333ba4de3bc2a75 to your computer and use it in GitHub Desktop.
Save ahmedbesbes/70b9b5bd78eb694fe333ba4de3bc2a75 to your computer and use it in GitHub Desktop.
train_path = '../data/train/'
def load_one_stack(case, data_path=train_path, plane='coronal'):
fpath = '{}/{}/{}.npy'.format(data_path, plane, case)
return np.load(fpath)
def load_stacks(case, data_path=train_path):
x = {}
planes = ['coronal', 'sagittal', 'axial']
for i, plane in enumerate(planes):
x[plane] = load_one_stack(case, plane=plane)
return x
def load_cases(train=True, n=None):
assert (type(n) == int) and (n < 1250)
if train:
case_list = pd.read_csv('../data/train-acl.csv', names=['case', 'label'], header=None,
dtype={'case': str, 'label': np.int64})['case'].tolist()
else:
case_list = pd.read_csv('../data/valid-acl.csv', names=['case', 'label'], header=None,
dtype={'case': str, 'label': np.int64})['case'].tolist()
cases = {}
if n is not None:
case_list = case_list[:n]
for case in tqdm_notebook(case_list, leave=False):
x = load_stacks(case)
cases[case] = x
return cases
cases = load_cases(n=100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment