Commit 433f429e authored by Alessia Marcolini's avatar Alessia Marcolini
Browse files

Dataset augmentation script

parent 603710b7
%% Cell type:markdown id: tags:
## Augment dataset class-wise
%% Cell type:code id: tags:
``` python
%HN_env
```
%%%% Output: execute_result
<IPython.core.display.HTML object>
%% Cell type:code id: tags:
``` python
import os
PATH = os.path.join(os.path.abspath(os.path.curdir), '..')
import sys
import numpy as np
from dataset import NumpyCSVDataset, augment_3D_HN
import SimpleITK as sitk
```
%% Cell type:code id: tags:
``` python
#%%
DATASETDIR = '/thunderdisk/HN/processed/bbox_fixed2_64/'
AUGMENT_DIR = '/thunderdisk/HN/processed/bbox_64_augmented_LR'
os.makedirs(AUGMENT_DIR, exist_ok=False)
SIZE = 64
dataset = NumpyCSVDataset(DATASETDIR , f'{PATH}/data/clinical_data.csv', 'Locoregional', SIZE, mode='test')
labels = dataset.get_labels()
idx_positive = np.where(labels=='1')[0]
augment_K = 5
ratio_NP = int((len(labels) - len(idx_positive))/len(idx_positive))
```
%% Cell type:code id: tags:
``` python
len(labels), len(idx_positive)
```
%%%% Output: execute_result
(294, 42)
%% Cell type:code id: tags:
``` python
#%%
for i in range(len(dataset)):
sample = dataset[i]
SUB = sample['filename']
print(SUB)
image_orig = sample['data']
label = sample['target']
ratio = 1 if label=='0' else ratio_NP
# print(ratio)
id_image = 0
for j in range(ratio):
for k in range(augment_K):
image_aug = augment_3D_HN(image_orig, 'train', SIZE)
np.save(f'{AUGMENT_DIR}/{SUB}_{id_image}.npy', image_aug)
id_image += 1
```
%%%% Output: stream
HN-CHUM-001.npy
<class 'numpy.str_'>
HN-CHUM-002.npy
<class 'numpy.str_'>
HN-CHUM-003.npy
<class 'numpy.str_'>
HN-CHUM-004.npy
<class 'numpy.str_'>
HN-CHUM-005.npy
<class 'numpy.str_'>
HN-CHUM-006.npy
<class 'numpy.str_'>
HN-CHUM-007.npy
<class 'numpy.str_'>
HN-CHUM-008.npy
<class 'numpy.str_'>
HN-CHUM-009.npy
<class 'numpy.str_'>
HN-CHUM-010.npy
<class 'numpy.str_'>
HN-CHUM-011.npy
<class 'numpy.str_'>
HN-CHUM-012.npy
<class 'numpy.str_'>
HN-CHUM-013.npy
<class 'numpy.str_'>
HN-CHUM-014.npy
<class 'numpy.str_'>
HN-CHUM-015.npy
<class 'numpy.str_'>
HN-CHUM-016.npy
<class 'numpy.str_'>
HN-CHUM-017.npy
<class 'numpy.str_'>
HN-CHUM-018.npy
<class 'numpy.str_'>
HN-CHUM-019.npy
<class 'numpy.str_'>
HN-CHUM-021.npy
<class 'numpy.str_'>
HN-CHUM-022.npy
<class 'numpy.str_'>
HN-CHUM-023.npy
<class 'numpy.str_'>
HN-CHUM-024.npy
<class 'numpy.str_'>
HN-CHUM-025.npy
<class 'numpy.str_'>
HN-CHUM-026.npy
<class 'numpy.str_'>
HN-CHUM-027.npy
<class 'numpy.str_'>
HN-CHUM-028.npy
<class 'numpy.str_'>
HN-CHUM-029.npy
<class 'numpy.str_'>
HN-CHUM-030.npy
<class 'numpy.str_'>
HN-CHUM-031.npy
<class 'numpy.str_'>
HN-CHUM-032.npy
<class 'numpy.str_'>
HN-CHUM-033.npy
<class 'numpy.str_'>
HN-CHUM-034.npy
<class 'numpy.str_'>
HN-CHUM-035.npy
<class 'numpy.str_'>
HN-CHUM-036.npy
<class 'numpy.str_'>
HN-CHUM-037.npy
<class 'numpy.str_'>
HN-CHUM-038.npy
<class 'numpy.str_'>
HN-CHUM-039.npy
<class 'numpy.str_'>
HN-CHUM-040.npy
<class 'numpy.str_'>
HN-CHUM-041.npy
<class 'numpy.str_'>
HN-CHUM-042.npy
<class 'numpy.str_'>
HN-CHUM-043.npy
<class 'numpy.str_'>
HN-CHUM-044.npy
<class 'numpy.str_'>
HN-CHUM-045.npy
<class 'numpy.str_'>
HN-CHUM-046.npy
<class 'numpy.str_'>
HN-CHUM-047.npy
<class 'numpy.str_'>
HN-CHUM-048.npy
<class 'numpy.str_'>
HN-CHUM-049.npy
<class 'numpy.str_'>
HN-CHUM-050.npy
<class 'numpy.str_'>
HN-CHUM-051.npy
<class 'numpy.str_'>
HN-CHUM-052.npy
<class 'numpy.str_'>
HN-CHUM-053.npy
<class 'numpy.str_'>
HN-CHUM-054.npy
<class 'numpy.str_'>
HN-CHUM-055.npy
<class 'numpy.str_'>
HN-CHUM-056.npy
<class 'numpy.str_'>
HN-CHUM-057.npy
<class 'numpy.str_'>
HN-CHUM-058.npy
<class 'numpy.str_'>
HN-CHUM-059.npy
<class 'numpy.str_'>
HN-CHUM-060.npy
<class 'numpy.str_'>
HN-CHUM-061.npy
<class 'numpy.str_'>
HN-CHUM-062.npy
<class 'numpy.str_'>
HN-CHUM-063.npy
<class 'numpy.str_'>
HN-CHUM-064.npy
<class 'numpy.str_'>
HN-CHUM-065.npy
<class 'numpy.str_'>
HN-CHUS-001.npy
<class 'numpy.str_'>
HN-CHUS-002.npy
<class 'numpy.str_'>
HN-CHUS-003.npy
<class 'numpy.str_'>
HN-CHUS-004.npy
<class 'numpy.str_'>
HN-CHUS-005.npy
<class 'numpy.str_'>
HN-CHUS-006.npy
<class 'numpy.str_'>
HN-CHUS-007.npy
<class 'numpy.str_'>
HN-CHUS-008.npy
<class 'numpy.str_'>
HN-CHUS-009.npy
<class 'numpy.str_'>
HN-CHUS-010.npy
<class 'numpy.str_'>
HN-CHUS-011.npy
<class 'numpy.str_'>
HN-CHUS-012.npy
<class 'numpy.str_'>
HN-CHUS-013.npy
<class 'numpy.str_'>
HN-CHUS-014.npy
<class 'numpy.str_'>
HN-CHUS-015.npy
<class 'numpy.str_'>
HN-CHUS-016.npy
<class 'numpy.str_'>
HN-CHUS-017.npy
<class 'numpy.str_'>
HN-CHUS-018.npy
<class 'numpy.str_'>
HN-CHUS-019.npy
<class 'numpy.str_'>
HN-CHUS-020.npy
<class 'numpy.str_'>
HN-CHUS-021.npy
<class 'numpy.str_'>
HN-CHUS-022.npy
<class 'numpy.str_'>
HN-CHUS-023.npy
<class 'numpy.str_'>
HN-CHUS-024.npy
<class 'numpy.str_'>
HN-CHUS-025.npy
<class 'numpy.str_'>
HN-CHUS-026.npy
<class 'numpy.str_'>
HN-CHUS-027.npy
<class 'numpy.str_'>
HN-CHUS-028.npy
<class 'numpy.str_'>
HN-CHUS-029.npy
<class 'numpy.str_'>
HN-CHUS-030.npy
<class 'numpy.str_'>
HN-CHUS-031.npy
<class 'numpy.str_'>
HN-CHUS-032.npy
<class 'numpy.str_'>
HN-CHUS-033.npy
<class 'numpy.str_'>
HN-CHUS-034.npy
<class 'numpy.str_'>
HN-CHUS-035.npy
<class 'numpy.str_'>
HN-CHUS-036.npy
<class 'numpy.str_'>
HN-CHUS-037.npy
<class 'numpy.str_'>
HN-CHUS-038.npy
<class 'numpy.str_'>
HN-CHUS-039.npy
<class 'numpy.str_'>
HN-CHUS-040.npy
<class 'numpy.str_'>
HN-CHUS-041.npy
<class 'numpy.str_'>
HN-CHUS-042.npy
<class 'numpy.str_'>
HN-CHUS-043.npy
<class 'numpy.str_'>
HN-CHUS-044.npy
<class 'numpy.str_'>
HN-CHUS-045.npy
<class 'numpy.str_'>
HN-CHUS-046.npy
<class 'numpy.str_'>
HN-CHUS-047.npy
<class 'numpy.str_'>
HN-CHUS-048.npy
<class 'numpy.str_'>
HN-CHUS-049.npy
<class 'numpy.str_'>
HN-CHUS-050.npy
<class 'numpy.str_'>
HN-CHUS-051.npy
<class 'numpy.str_'>
HN-CHUS-052.npy
<class 'numpy.str_'>
HN-CHUS-053.npy
<class 'numpy.str_'>
HN-CHUS-054.npy
<class 'numpy.str_'>
HN-CHUS-055.npy
<class 'numpy.str_'>
HN-CHUS-056.npy
<class 'numpy.str_'>
HN-CHUS-057.npy
<class 'numpy.str_'>
HN-CHUS-058.npy
<class 'numpy.str_'>
HN-CHUS-059.npy
<class 'numpy.str_'>
HN-CHUS-060.npy
<class 'numpy.str_'>
HN-CHUS-061.npy
<class 'numpy.str_'>
HN-CHUS-062.npy
<class 'numpy.str_'>
HN-CHUS-063.npy
<class 'numpy.str_'>
HN-CHUS-064.npy
<class 'numpy.str_'>
HN-CHUS-065.npy
<class 'numpy.str_'>
HN-CHUS-066.npy
<class 'numpy.str_'>
HN-CHUS-067.npy
<class 'numpy.str_'>
HN-CHUS-068.npy
<class 'numpy.str_'>
HN-CHUS-069.npy
<class 'numpy.str_'>
HN-CHUS-070.npy
<class 'numpy.str_'>
HN-CHUS-071.npy
<class 'numpy.str_'>
HN-CHUS-072.npy
<class 'numpy.str_'>
HN-CHUS-073.npy
<class 'numpy.str_'>
HN-CHUS-074.npy
<class 'numpy.str_'>
HN-CHUS-075.npy
<class 'numpy.str_'>
HN-CHUS-076.npy
<class 'numpy.str_'>
HN-CHUS-077.npy
<class 'numpy.str_'>
HN-CHUS-078.npy
<class 'numpy.str_'>
HN-CHUS-080.npy
<class 'numpy.str_'>
HN-CHUS-081.npy
<class 'numpy.str_'>
HN-CHUS-082.npy
<class 'numpy.str_'>
HN-CHUS-083.npy
<class 'numpy.str_'>
HN-CHUS-084.npy
<class 'numpy.str_'>
HN-CHUS-085.npy
<class 'numpy.str_'>
HN-CHUS-086.npy
<class 'numpy.str_'>
HN-CHUS-087.npy
<class 'numpy.str_'>
HN-CHUS-088.npy
<class 'numpy.str_'>
HN-CHUS-089.npy
<class 'numpy.str_'>
HN-CHUS-090.npy
<class 'numpy.str_'>
HN-CHUS-091.npy
<class 'numpy.str_'>
HN-CHUS-092.npy
<class 'numpy.str_'>
HN-CHUS-094.npy
<class 'numpy.str_'>
HN-CHUS-095.npy
<class 'numpy.str_'>
HN-CHUS-096.npy
<class 'numpy.str_'>
HN-CHUS-097.npy
<class 'numpy.str_'>
HN-CHUS-098.npy
<class 'numpy.str_'>
HN-CHUS-099.npy
<class 'numpy.str_'>
HN-CHUS-100.npy
<class 'numpy.str_'>
HN-CHUS-101.npy
<class 'numpy.str_'>
HN-CHUS-102.npy
<class 'numpy.str_'>
HN-HGJ-001.npy
<class 'numpy.str_'>
HN-HGJ-002.npy
<class 'numpy.str_'>
HN-HGJ-003.npy
<class 'numpy.str_'>
HN-HGJ-004.npy
<class 'numpy.str_'>
HN-HGJ-005.npy
<class 'numpy.str_'>
HN-HGJ-006.npy
<class 'numpy.str_'>
HN-HGJ-007.npy
<class 'numpy.str_'>
HN-HGJ-008.npy
<class 'numpy.str_'>
HN-HGJ-009.npy
<class 'numpy.str_'>
HN-HGJ-010.npy
<class 'numpy.str_'>
HN-HGJ-011.npy
<class 'numpy.str_'>
HN-HGJ-012.npy
<class 'numpy.str_'>
HN-HGJ-013.npy
<class 'numpy.str_'>
HN-HGJ-014.npy
<class 'numpy.str_'>
HN-HGJ-015.npy
<class 'numpy.str_'>
HN-HGJ-016.npy
<class 'numpy.str_'>
HN-HGJ-017.npy
<class 'numpy.str_'>
HN-HGJ-018.npy
<class 'numpy.str_'>
HN-HGJ-019.npy
<class 'numpy.str_'>
HN-HGJ-020.npy
<class 'numpy.str_'>
HN-HGJ-021.npy
<class 'numpy.str_'>
HN-HGJ-022.npy
<class 'numpy.str_'>
HN-HGJ-023.npy
<class 'numpy.str_'>
HN-HGJ-024.npy
<class 'numpy.str_'>
HN-HGJ-025.npy
<class 'numpy.str_'>
HN-HGJ-026.npy
<class 'numpy.str_'>
HN-HGJ-027.npy
<class 'numpy.str_'>
HN-HGJ-028.npy
<class 'numpy.str_'>
HN-HGJ-029.npy
<class 'numpy.str_'>
HN-HGJ-030.npy
<class 'numpy.str_'>
HN-HGJ-031.npy
<class 'numpy.str_'>
HN-HGJ-032.npy
<class 'numpy.str_'>
HN-HGJ-033.npy
<class 'numpy.str_'>
HN-HGJ-034.npy
<class 'numpy.str_'>
HN-HGJ-035.npy
<class 'numpy.str_'>
HN-HGJ-036.npy
<class 'numpy.str_'>
HN-HGJ-037.npy
<class 'numpy.str_'>
HN-HGJ-038.npy
<class 'numpy.str_'>
HN-HGJ-039.npy
<class 'numpy.str_'>
HN-HGJ-040.npy
<class 'numpy.str_'>
HN-HGJ-041.npy
<class 'numpy.str_'>
HN-HGJ-042.npy
<class 'numpy.str_'>
HN-HGJ-043.npy
<class 'numpy.str_'>
HN-HGJ-044.npy
<class 'numpy.str_'>
HN-HGJ-045.npy
<class 'numpy.str_'>
HN-HGJ-046.npy
<class 'numpy.str_'>
HN-HGJ-047.npy
<class 'numpy.str_'>
HN-HGJ-048.npy
<class 'numpy.str_'>
HN-HGJ-049.npy
<class 'numpy.str_'>
HN-HGJ-050.npy
<class 'numpy.str_'>
HN-HGJ-051.npy
<class 'numpy.str_'>
HN-HGJ-052.npy
<class 'numpy.str_'>
HN-HGJ-053.npy
<class 'numpy.str_'>
HN-HGJ-054.npy
<class 'numpy.str_'>
HN-HGJ-055.npy
<class 'numpy.str_'>
HN-HGJ-056.npy
<class 'numpy.str_'>
HN-HGJ-057.npy
<class 'numpy.str_'>
HN-HGJ-058.npy
<class 'numpy.str_'>
HN-HGJ-059.npy
<class 'numpy.str_'>
HN-HGJ-060.npy
<class 'numpy.str_'>
HN-HGJ-061.npy
<class 'numpy.str_'>
HN-HGJ-062.npy
<class 'numpy.str_'>
HN-HGJ-063.npy
<class 'numpy.str_'>
HN-HGJ-064.npy
<class 'numpy.str_'>
HN-HGJ-065.npy
<class 'numpy.str_'>
HN-HGJ-066.npy
<class 'numpy.str_'>
HN-HGJ-067.npy
<class 'numpy.str_'>
HN-HGJ-069.npy
<class 'numpy.str_'>
HN-HGJ-070.npy
<class 'numpy.str_'>
HN-HGJ-071.npy
<class 'numpy.str_'>
HN-HGJ-072.npy
<class 'numpy.str_'>
HN-HGJ-073.npy
<class 'numpy.str_'>
HN-HGJ-074.npy
<class 'numpy.str_'>
HN-HGJ-075.npy
<class 'numpy.str_'>
HN-HGJ-076.npy
<class 'numpy.str_'>
HN-HGJ-077.npy
<class 'numpy.str_'>
HN-HGJ-078.npy
<class 'numpy.str_'>
HN-HGJ-079.npy
<class 'numpy.str_'>
HN-HGJ-080.npy
<class 'numpy.str_'>
HN-HGJ-081.npy
<class 'numpy.str_'>
HN-HGJ-082.npy
<class 'numpy.str_'>
HN-HGJ-083.npy
<class 'numpy.str_'>
HN-HGJ-084.npy
<class 'numpy.str_'>
HN-HGJ-085.npy
<class 'numpy.str_'>
HN-HGJ-086.npy
<class 'numpy.str_'>
HN-HGJ-087.npy
<class 'numpy.str_'>
HN-HGJ-088.npy
<class 'numpy.str_'>
HN-HGJ-089.npy
<class 'numpy.str_'>
HN-HGJ-090.npy
<class 'numpy.str_'>
HN-HGJ-091.npy
<class 'numpy.str_'>
HN-HGJ-092.npy
<class 'numpy.str_'>
HN-HMR-001.npy
<class 'numpy.str_'>
HN-HMR-002.npy
<class 'numpy.str_'>
HN-HMR-003.npy
<class 'numpy.str_'>
HN-HMR-004.npy
<class 'numpy.str_'>
HN-HMR-005.npy
<class 'numpy.str_'>
HN-HMR-006.npy
<class 'numpy.str_'>
HN-HMR-008.npy
<class 'numpy.str_'>
HN-HMR-009.npy
<class 'numpy.str_'>
HN-HMR-010.npy
<class 'numpy.str_'>
HN-HMR-011.npy
<class 'numpy.str_'>
HN-HMR-012.npy
<class 'numpy.str_'>
HN-HMR-013.npy
<class 'numpy.str_'>
HN-HMR-014.npy
<class 'numpy.str_'>
HN-HMR-015.npy
<class 'numpy.str_'>
HN-HMR-016.npy
<class 'numpy.str_'>
HN-HMR-018.npy
<class 'numpy.str_'>
HN-HMR-019.npy
<class 'numpy.str_'>
HN-HMR-020.npy
<class 'numpy.str_'>
HN-HMR-021.npy
<class 'numpy.str_'>
HN-HMR-022.npy
<class 'numpy.str_'>
HN-HMR-023.npy
<class 'numpy.str_'>
HN-HMR-024.npy
<class 'numpy.str_'>