import torchvision.transforms as transforms
from ms_segmentation.general.training_helper import EarlyStopping, exp_lr_scheduler, dice_loss_2d, create_training_validation_sets
from sklearn.metrics import jaccard_score as jsc
from ms_segmentation.evaluation.metrics import compute_dices, compute_hausdorf

path_data = r'D:\dev\ms_data\Challenges\ISBI2015\ISBI_CS'
#path_data = r'D:\dev\INS1'
path_train = jp(path_data, "train")
path_test = jp(path_data, "test")
#path_test = r'D:\dev\ISBI_CS\test'
#path_test = r'D:\dev\INS_Test\test'
debug = True
if (debug):
    experiment_name = "dummy_experiment_2DUNetConvGRU"
else:
    experiment_name, curr_date, curr_time = get_experiment_name(
        the_prefix="unet2dconvGRU")
#experiment_name = 'unet3d_2020-03-24_16_08_04[ISBI1-17]'
path_results = jp(path_data, experiment_name)
create_folder(path_results)
path_models = jp(path_results, "models")
create_folder(path_models)
path_segmentations = jp(path_results, "results")
create_folder(path_segmentations)

# Visualize one subject
#img, img_header = load(jp(path_train, '00001', 'FLAIR_masked.nii.gz'))
#mask, mask_header = load(jp(path_train, '00001', 'mask_FLAIR.nii.gz'))
#shim_overlay_slice(img, mask, 25, alpha=0.4)
#shim(img, 16)

# Define options for training
Esempio n. 2
0
options['num_timepoints'] = 3
options[
    'patch_sampling'] = 'mask'  # (mask, balanced or balanced+roi or non-uniform)
options['loss'] = 'dice'  # (dice, cross-entropy)
options['resample_each_epoch'] = False

path_base = r'D:\dev\ms_data\Challenges\ISBI2015\ISBI_L'
path_data = jp(path_base, 'longitudinal_normalized_images')  #ACHTUUUUNG
options['path_data'] = path_data
path_res = jp(path_base, "cross_validation")
all_patients = list_folders(path_data)

if (debug):
    experiment_name = "dummy_UNetLongit"
else:
    experiment_name, curr_date, curr_time = get_experiment_name(
        the_prefix="CROSS_VALIDATION_UNetLongit")

validation_images = ['03', '03', '04', '05', '02'
                     ]  # so that all experiments use the same validation image

#experiment_name = 'CROSS_VALIDATION_UNetLongit_2020-05-26_11_12_15'
fold = 0
for curr_test_patient in all_patients:
    fold += 1
    #For cross-validation it is necessary to remove fields so that they do not cause errors in function create_training_validation_sets
    if "training_path" in options:
        del options['training_path']
    if "test_path" in options:
        del options['test_path']

    curr_train_patients = all_patients.copy()
options['optimizer'] = 'adam'
options[
    'patch_sampling'] = 'mask'  # (mask, balanced or balanced+roi or non-uniform)
options['loss'] = 'dice'  # (dice, cross-entropy)
options['resample_each_epoch'] = False

path_base = r'D:\dev\ms_data\Challenges\ISBI2015\ISBI_L'
path_data = jp(path_base, 'isbi_train')
options['path_data'] = path_data
path_res = jp(path_base, "cross_validation")
all_patients = list_folders(path_data)

if (debug):
    experiment_name = "dummy_experiment_CROSS_VALIDATION_UNet_2D"
else:
    experiment_name, curr_date, curr_time = get_experiment_name(
        the_prefix="CROSS_VALIDATION_unet2d")

fold = 0

#experiment_name = 'CROSS_VALIDATION_unet2d_2020-04-16_12_01_25'
for curr_test_patient in all_patients:
    fold += 1
    curr_train_patients = all_patients.copy()
    curr_train_patients.remove(curr_test_patient)

    options['training_samples'] = curr_train_patients
    options['test_samples'] = [curr_test_patient]

    experiment_folder = jp(path_res, experiment_name)
    create_folder(experiment_folder)
Esempio n. 4
0
from sklearn.metrics import jaccard_score as jsc
from sklearn.metrics import accuracy_score as acc
from ms_segmentation.evaluation.metrics import compute_dices, compute_hausdorf

path_data = r'D:\dev\ms_data\Challenges\ISBI2015\ISBI_L'
#path_data = r'D:\dev\INS1'
path_train = jp(path_data, "train")
path_test = jp(path_data, "test")
#path_test = r'D:\dev\ISBI_CS\test'
#path_test = r'D:\dev\INS_Test\test'
debug = True

if (debug):
    experiment_name = "dummy_UNetConvGRU"
else:
    experiment_name, curr_date, curr_time = get_experiment_name(
        the_prefix="UNetConvGRU3D")
#experiment_name = 'UNetConvGRU_2020-04-01_14_47_12'
path_results = jp(path_data, experiment_name)
create_folder(path_results)
path_models = jp(path_results, "models")
create_folder(path_models)
path_segmentations = jp(path_results, "results")
create_folder(path_segmentations)

# Visualize one subject
#img, img_header = load(jp(path_train, '00001', 'FLAIR_masked.nii.gz'))
#mask, mask_header = load(jp(path_train, '00001', 'mask_FLAIR.nii.gz'))
#shim_overlay_slice(img, mask, 25, alpha=0.4)
#shim(img, 16)

# Define options for training
Esempio n. 5
0
from ms_segmentation.general.training_helper import EarlyStopping, exp_lr_scheduler, dice_loss, create_training_validation_sets, get_dictionary_with_paths_cs
from sklearn.metrics import jaccard_score as jsc
from sklearn.metrics import accuracy_score as acc
from ms_segmentation.evaluation.metrics import compute_metrics
from torch.optim import Adadelta, Adam

path_data = r'D:\dev\ms_data\Challenges\ISBI2015\ISBI_CS'
path_train = jp(path_data, "train")
path_test = jp(path_data, "test")

debug = False

if(debug):
    experiment_name = "dummy_experiment_3DUNet"
else:
    experiment_name, curr_date, curr_time = get_experiment_name(the_prefix = "UNet3D_alt_images")

experiment_name = 'UNet3D_alt_images_2020-05-03_14_09_14'    
path_results = jp(path_data, experiment_name)
create_folder(path_results)
path_models = jp(path_results, "models")
create_folder(path_models)
path_segmentations = jp(path_results, "results")
create_folder(path_segmentations)


options = {}
options['training_path'] = path_train
options['test_path'] = path_test
options['val_split']  = 0.2
#options['input_data'] = ['flair.nii.gz', 'mprage.nii.gz', 'pd.nii.gz']
Esempio n. 6
0
options['loss'] = 'dice' # (dice, cross-entropy)
options['resample_each_epoch'] = False


path_base = r'D:\dev\ms_data\Challenges\ISBI2015\ISBI_L'
path_data = jp(path_base, 'isbi_train')          # ACHTUUUNG
options['path_data'] = path_data
path_res = jp(path_base, "cross_validation")
all_patients = list_folders(path_data)



if(debug):
    experiment_name = "dummy_UNet_ConvLSTM3D"
else:
    experiment_name, curr_date, curr_time = get_experiment_name(the_prefix = "CROSS_VALIDATION_UNetConvLSTM3D")

validation_images = ['03', '03', '04', '05', '02'] # so that all experiments use the same validation image

#experiment_name = 'CROSS_VALIDATION_UNetConvLSTM3D_2020-07-25_06_46_44'
fold = 0
for curr_test_patient in all_patients:
    fold += 1

    #For cross-validation it is necessary to remove fields so that they do not cause errors in function create_training_validation_sets
    if "training_path" in options:
        del options['training_path']
    if "test_path" in options:
        del options['test_path']

    curr_train_patients = all_patients.copy()
Esempio n. 7
0
from ms_segmentation.general.training_helper import EarlyStopping, exp_lr_scheduler, dice_loss, create_training_validation_sets, get_dictionary_with_paths_cs
from sklearn.metrics import jaccard_score as jsc
from sklearn.metrics import accuracy_score as acc
from ms_segmentation.evaluation.metrics import compute_metrics
from torch.optim import Adadelta, Adam

path_data = r'D:\dev\ms_data\Challenges\ISBI2015\ISBI_CS'
path_train = jp(path_data, "train")
path_test = jp(path_data, "test")

debug = False

if (debug):
    experiment_name = "dummy_experiment_3DUNet_center"
else:
    experiment_name, curr_date, curr_time = get_experiment_name(
        the_prefix="UNet3D_center")
path_results = jp(path_data, experiment_name)
create_folder(path_results)
path_models = jp(path_results, "models")
create_folder(path_models)
path_segmentations = jp(path_results, "results")
create_folder(path_segmentations)

options = {}
options['training_path'] = path_train
options['test_path'] = path_test
options['val_split'] = 0.2
options['input_data'] = ['flair.nii.gz', 'mprage.nii.gz', 'pd.nii.gz']
options['gt'] = 'mask1.nii.gz'
options['brain_mask'] = 'brain_mask.nii.gz'
options['num_classes'] = 2
from torch.utils.data import DataLoader
import torch.nn.functional as F
from torch.optim import Adadelta, Adam
import torchvision.transforms as transforms
from ms_segmentation.general.training_helper import EarlyStopping, exp_lr_scheduler, dice_loss, create_training_validation_sets
from sklearn.metrics import jaccard_score as jsc
from ms_segmentation.evaluation.metrics import compute_dices, compute_hausdorf

path_data = r'D:\dev\ms_data\Challenges\ISBI2015\ISBI_CS'
#path_data = r'D:\dev\INS1'
path_train = jp(path_data, "train")
path_test = jp(path_data, "test")
#path_test = r'D:\dev\ISBI_CS\test'
#path_test = r'D:\dev\INS_Test\test'

experiment_name, curr_date, curr_time = get_experiment_name(
    the_prefix="unet3d")
#experiment_name = 'unet3d_2020-03-24_16_08_04[ISBI1-17]'
path_results = jp(path_data, experiment_name)
create_folder(path_results)
path_models = jp(path_results, "models")
create_folder(path_models)
path_segmentations = jp(path_results, "results")
create_folder(path_segmentations)

# Visualize one subject
#img, img_header = load(jp(path_train, '00001', 'FLAIR_masked.nii.gz'))
#mask, mask_header = load(jp(path_train, '00001', 'mask_FLAIR.nii.gz'))
#shim_overlay_slice(img, mask, 25, alpha=0.4)
#shim(img, 16)

# Define options for training