Exemplo n.º 1
0
def segment_script(patch_size_x, patch_size_y, patch_size_z, hidden_layers_sizes, corruption_levels, prefix):
    
    root = '../../varghese/10_1_brain_mean/'
    
    #patch_size_x = 9
    #patch_size_y = 9
    #patch_size_z = 9
    recon_flag = False
    batch_size = 100
    
    if recon_flag == True:
        n_ins = patch_size_x * patch_size_y * patch_size_z * 5
    else:
        n_ins = patch_size_x * patch_size_y * patch_size_z * 4
    n_outs = 5
    noise_type = 1
    noise_dict = {1:'Gaussian Noise',0:'Masking Noise'}
    #hidden_layers_sizes = [1000,1000,1000]
    #corruption_levels = [0.01,0.01,0.01]
    
    test_path = root + 'testing'
    
    #prefix = 'xxx'
    
    print 'Extracting  Balanaced training patches...'
    B_Patch_Preprocess_recon_3D(patch_size_x,patch_size_y,patch_size_z,prefix,root+'training',
                                      root+'BRATS_training_patches/',False)
    print 'Training patches extracted!'                                      
    
    print 'Extracting  Balanced validation patches...'
    B_Patch_Preprocess_recon_3D(patch_size_x,patch_size_y,patch_size_z,prefix,root+'validation',                                     
                                      root+'BRATS_validation_patches/',False)
    print 'Validation patches extracted!' 

    print 'Extracting UnBalanced training patches...'
    U_Patch_Preprocess_recon_3D(patch_size_x,patch_size_y,patch_size_z,prefix,root+'training',
                                      root+'BRATS_training_patches/',False)
    print 'Training patches extracted!'                                      
    
    print 'Extracting Unbalanced validation patches...'
    U_Patch_Preprocess_recon_3D(patch_size_x,patch_size_y,patch_size_z,prefix,root+'validation',                                     
                                      root+'BRATS_validation_patches/',False)                                                
                                      
    path = '../results/'
    for subdir, dirs, files in os.walk(path):
        test_num = len(dirs)+1
        break

        
    os.mkdir('../results/test_'+str(test_num)+'_'+prefix)
    test_root = '../results/test_'+str(test_num)+'_'+prefix+'/'
    print 'Calling test_SdA...'
    
    
    finetune_lr = 0.1
    pretraining_epochs = 50
    pretrain_lr = 0.001
    training_epochs = 100

   
    f = open(test_root+prefix+'_params_info.txt', 'w')
    f.write( "Current date & time " + time.strftime("%c"))
    f.write('\nPrefix : '+prefix)
    f.write('\n3D Patches. Patch_size : '+str(patch_size_x)+', '+str(patch_size_y)+', '+str(patch_size_z))
    f.write('\nHidden Layer Sizes : ['+', '.join(map(str,hidden_layers_sizes))+' ]')
    f.write('\nNoise Type : '+noise_dict[noise_type])
    f.write('\nCorruption Levels : ['+', '.join(map(str,corruption_levels))+' ]')
    f.write('\nNo. of pre-training epochs : '+str(pretraining_epochs))
    f.write('\nNo. of Fine-tuning epochs : '+str(training_epochs))
    f.write('\nPretraining Learning rate : '+str(pretrain_lr))
    f.write('\nFine-tuning learning rate : '+str(finetune_lr))
    f.close()
    
    test_SdA(finetune_lr, pretraining_epochs,
             pretrain_lr, training_epochs,              
                root+'BRATS_training_patches/b_trainpatch_3D_'+prefix+'_.npy',
                root+'BRATS_training_patches/b_trainlabel_3D_'+prefix+'_.npy',
                root+'BRATS_validation_patches/b_validpatch_3D_'+prefix+'_.npy',
                root+'BRATS_validation_patches/b_validlabel_3D_'+prefix+'_.npy',
                root+'BRATS_training_patches/u_trainpatch_3D_'+prefix+'_.npy',
                root+'BRATS_training_patches/u_trainlabel_3D_'+prefix+'_.npy',
                root+'BRATS_validation_patches/u_validpatch_3D_'+prefix+'_.npy',
                root+'BRATS_validation_patches/u_validlabel_3D_'+prefix+'_.npy',batch_size, n_ins, n_outs, hidden_layers_sizes, test_root + prefix, corruption_levels)                
    print 'Network Trained and Saved!'                 
                
    test_network(test_root , prefix, test_path, patch_size_x, patch_size_y, patch_size_z, recon_flag)
    
    convert_mha(root+'testing', prefix)
    
    print '####################################################################'
    print
    print 'Completed one network with prefix : ', prefix
    print
    print '####################################################################'
Exemplo n.º 2
0
    f.write('\nHidden Layer Sizes : ['+', '.join(map(str,hidden_layers_sizes))+' ]')
    f.write('\nNoise Type : '+noise_dict[noise_type])
    f.write('\nCorruption Levels : ['+', '.join(map(str,corruption_levels))+' ]')
    f.write('\nNo. of pre-training epochs : '+str(pretraining_epochs))
    f.write('\nNo. of Fine-tuning epochs : '+str(training_epochs))
    f.write('\nPretraining Learning rate : '+str(pretrain_lr))
    f.write('\nFine-tuning learning rate : '+str(finetune_lr))
    f.close()
    
    test_SdA(finetune_lr, pretraining_epochs,
             pretrain_lr, training_epochs,              
                root+'BRATS_training_patches/b_trainpatch_3D_'+prefix+'_.npy',
                root+'BRATS_training_patches/b_trainlabel_3D_'+prefix+'_.npy',
                root+'BRATS_validation_patches/b_validpatch_3D_'+prefix+'_.npy',
                root+'BRATS_validation_patches/b_validlabel_3D_'+prefix+'_.npy',
                root+'BRATS_training_patches/u_trainpatch_3D_'+prefix+'_.npy',
                root+'BRATS_training_patches/u_trainlabel_3D_'+prefix+'_.npy',
                root+'BRATS_validation_patches/u_validpatch_3D_'+prefix+'_.npy',
                root+'BRATS_validation_patches/u_validlabel_3D_'+prefix+'_.npy',batch_size, n_ins, n_outs, hidden_layers_sizes, test_root + prefix, corruption_levels)
                
    print 'Network Trained and Saved!'                
                
    test_network(test_root , prefix, test_path, patch_size_x, patch_size_y, patch_size_z, recon_flag)
    
#    convert_mha(root+'testing', prefix)
    
    
                

                
Exemplo n.º 3
0
    f.write("\nNo. of Fine-tuning epochs : " + str(training_epochs))
    f.write("\nPretraining Learning rate : " + str(pretrain_lr))
    f.write("\nFine-tuning learning rate : " + str(finetune_lr))
    f.close()

    test_SdA(
        finetune_lr,
        pretraining_epochs,
        pretrain_lr,
        training_epochs,
        root + "BRATS_training_patches/b_10_trainpatch_2D_" + prefix + "_.npy",
        root + "BRATS_training_patches/b_10_trainlabel_2D_" + prefix + "_.npy",
        root + "BRATS_validation_patches/b_10_validpatch_2D_" + prefix + "_.npy",
        root + "BRATS_validation_patches/b_10_validlabel_2D_" + prefix + "_.npy",
        root + "BRATS_training_patches/u_10_trainpatch_2D_" + prefix + "_.npy",
        root + "BRATS_training_patches/u_10_trainlabel_2D_" + prefix + "_.npy",
        root + "BRATS_validation_patches/u_10_validpatch_2D_" + prefix + "_.npy",
        root + "BRATS_validation_patches/u_10_validlabel_2D_" + prefix + "_.npy",
        batch_size,
        n_ins,
        n_outs,
        hidden_layers_sizes,
        test_root + prefix,
        corruption_levels,
    )
    print "Network Trained and Saved!"

    test_network(test_root, prefix, test_path, patch_size, patch_size, patch_size, recon_flag, 2)

#    convert_mha(root+'testing', prefix, 2)
Exemplo n.º 4
0
    # for i in xrange(len(dropout_rates)):
    #     if i == 1:
    #         break
	   #  runMLP2(finetune_lr,
	   #      150,
	   #      batch_size,
	   #      layer_sizes,
	   #      dropout_rates[i],
	   #      test_root + prefix + 'pre_training.pkl',
	   #      root+'BRATS_training_patches/u_trainpatch_3D_'+prefix+'_.npy',
	   #      root+'BRATS_training_patches/u_trainlabel_3D_'+prefix+'_.npy',
	   #      root+'BRATS_validation_patches/u_validpatch_3D_'+prefix+'_.npy',
	   #      root+'BRATS_validation_patches/u_validlabel_3D_'+prefix+'_.npy',
	   #      test_root + prefix + '_' + str(i))
#########################################################################################
    test_network(test_root,new_prefix,test_path,11,11,3,False,3)

    # ### START OF POST-PROCESSING PIPELINE ###

    LesionMasker(test_path + '/' , new_prefix)
    print 'binarizing...'
    binarize(root, new_prefix + 'Masked_RawOutput.nii')
    print new_prefix + 'Masked_RawOutput.nii'
    print 'binarized'

    callString = 'python analysis.py > ' + new_prefix + '.txt'
    print callString
    subprocess.call(callString, shell = True)

    calculateDice(new_prefix + '.txt', testingImages)
    
@author: bmi
"""

from test_network import *

#prefix = ['11x11_1000-500-250-100_G1','11x11_2000-1000-1000-500_G1','13x13_1000-500-250_G1','13x13_2000-1000-500-100_G1','9x9_2000-1000-500-100_G1',
#            '9x9_1000-500-250-100_G1','9x9_1000-1000-1000_G1','9x9_1000-500-100_G1','7x7_1000-500-250_G1']

prefix = ['Tumor_NonTumor_9x9x9_5000-200-500G1','Tumor_NonTumor_11x11x11_5000-2000-500G15']

root = '../../varghese/10_1_brain_mean/'
#test_root = ['/home/bmi/BRATS/results/test2D9_11x11_1000-500-250-100_G1/',
#             '/home/bmi/BRATS/results/test2D10_11x11_2000-1000-1000-500_G1/',
#             '/home/bmi/BRATS/results/test2D11_13x13_1000-500-250_G1/',
#             '/home/bmi/BRATS/results/test2D12_13x13_2000-1000-500-100_G1/',
#             '/home/bmi/BRATS/results/test2D13_9x9_2000-1000-500-100_G1/',
#             '/home/bmi/BRATS/results/test2D14_9x9_1000-500-250-100_G1/',
#             '/home/bmi/BRATS/results/test2D15_9x9_1000-1000-1000_G1/',
#             '/home/bmi/BRATS/results/test2D16_9x9_1000-500-100_G1/',
#             '/home/bmi/BRATS/results/test2D17_7x7_1000-500-250_G1/']

test_root = ['/home/bmi/BRATS/results/test17_Tumor_NonTumor_9x9x9_5000-200-500G1/',
             '/home/bmi/BRATS/results/test18_Tumor_NonTumor_9x9x9_5000-2000-500G15/']
             
patch_z = [11,11,13,13,9,9,9,9,7]
             
test_path = root+'testing'

for i in xrange(len(prefix)):
    test_network(test_root[i],prefix[i],test_path,9,9,9,False,3)
    print i
Exemplo n.º 6
0
def segment_2D_script(patch_size, hidden_layers_sizes, corruption_levels, prefix):
    
    root = '../../varghese/10_1_brain_mean/'
    
#    patch_size = 11
    
    recon_flag = False
    batch_size = 100
    if recon_flag == True:
        n_ins = patch_size * patch_size * 5
    else:
        n_ins = patch_size * patch_size * 4
    n_outs = 5
#    hidden_layers_sizes = [1000,1000,1000]
#    corruption_levels = [0.01,0.01,0.01]
#    noise_type = 1 #1- Gaussian, 0 - masking
    
    test_path = root + 'testing'
#    prefix = 'yyy'
    
    print 'Extracting training patches...'
    Patch_Preprocess_recon_2D(patch_size,patch_size, prefix,root+'training',root+'BRATS_training_patches/',False)
    print 'Training patches extracted!'                                      
    
    print 'Extracting validation patches...'
    Patch_Preprocess_recon_2D(patch_size,patch_size,prefix,root+'validation',                                     
                                      root+'BRATS_validation_patches/',False)
    print 'Validation patches extracted!'                                              
                                      
    path = '../results/'
    for subdir, dirs, files in os.walk(path):
        test_num = len(dirs)+1
        break
#        print test_num
        ##########---------SET PREFIX--------##########
    os.mkdir('../results/test2D'+str(test_num)+'_'+prefix)
#    

    test_root = '../results/test2D'+str(test_num)+'_'+prefix+'/'
    

    
    print 'Calling test_SdA...'
    
    finetune_lr = 0.1
    pretraining_epochs = 1
    pretrain_lr = 0.001
    training_epochs = 1
    
    test_SdA(finetune_lr, pretraining_epochs,
             pretrain_lr, training_epochs,              
                root+'BRATS_training_patches/trainpatch_2D_'+prefix+'_.npy',
                root+'BRATS_training_patches/trainlabel_2D_'+prefix+'_.npy',
                root+'BRATS_validation_patches/validpatch_2D_'+prefix+'_.npy',
                root+'BRATS_validation_patches/validlabel_2D_'+prefix+'_.npy',batch_size, n_ins, n_outs, hidden_layers_sizes, test_root + prefix, corruption_levels)
                
    print 'Network Trained and Saved!'                
                
    test_network(test_root , prefix, test_path, patch_size, patch_size, patch_size, recon_flag, 2)
    
    convert_mha(root+'testing', prefix, 2) 
#    
#    
Exemplo n.º 7
0
from test_network import *
from lesion_masker import *

prefix = '2013new_9x9x9_5000-2000-500_M244'
root = '/media/varkey/mega_test/HGG_NORM/'
test_root = '/home/bmi/BRATS/results/test_147_2013new_9x9x9_5000-2000-500_M244/'
test_path = root

test_network(test_root,prefix,test_path,9,9,9,False,3)
#LesionMasker(prefix, test_path)