parameter_dict = configFile.CONFIG_DICT[config_file_str] parameter_dict[ 'RESULTS_DIR'] = parameter_dict['RESULTS_DIR'] + '_' + model_type use_gpu = torch.cuda.is_available() and parameter_dict['USE_GPU'] device = torch.device("cuda:0" if use_gpu else "cpu") kwargs_testing = {} kwargs_generator = { 'num_workers': 1, 'pin_memory': use_gpu, 'worker_init_fn': worker_init_fn } create_results_dir(parameter_dict['RESULTS_DIR']) attach = True if parameter_dict['STARTING_EPOCH'] > 0 else False experimentWriter = ExperimentWriter(join(parameter_dict['RESULTS_DIR'], 'experiment.txt'), attach=attach) ################################### ########### DATA LOADER ########### ################################### data_loader = DataLoader(parameter_dict) sbj = data_loader.subject_list[0] nslices = len(sbj.slice_list) idx = np.random.choice(nslices) data_loader.subject_list = sbj.slice_list[idx:idx + number_of_subjects] data_loader.rid_list = [s.id for s in sbj.slice_list]
parser.add_argument("-p", help="Params", default=None, type=str) arg = parser.parse_args(sys.argv[1:]) print('Getting parameters to train the model...') params_string = arg.p params = p.PARAMS_DICT[params_string].get_params() filename = params[p.MODEL_NAME] dir_path = join(params[p.OUTPUT_PATH], 'LR_' + str(params[p.LR]) + '_full_DA_shortcutTrue_allDB') logs_filepath = join(dir_path, 'logs', filename + '.txt') weights_filepath = join(dir_path, 'model_weights', filename + '.h5') """ REDIRECT STDOUT TO FILE """ print('Output redirected to file... ') print('Suggestion: Use tail command to see the output') io.create_results_dir(dir_path=dir_path) io.redirect_stdout_to_file(filepath=logs_filepath) print('PARAMETERS') print(params) print('Learning rate exponential decay') print('One subepoch') print('double l1, l2') """ ARCHITECTURE DEFINITION """ num_modalities = 2 model, output_shape = iSeg_models.get_model( num_modalities=num_modalities, segment_dimensions=tuple(params[p.INPUT_DIM]), num_classes=params[p.N_CLASSES], model_name=params[p.MODEL_NAME], shortcut_input=params[p.SHORTCUT_INPUT],
from os.path import join from os import listdir import pdb import shutil from database import read_slice_info from setup import DATA_DIR from src.utils.io import create_results_dir data_dir = join(DATA_DIR, 'dataset') create_results_dir(data_dir, subdirs=['ihc','mri','nissl']) shutil.copy('slice_info_ihc.csv', join(data_dir, 'ihc', 'slice_separation.csv')) shutil.copy('slice_info_nissl.csv', join(data_dir, 'nissl', 'slice_separation.csv')) slice_dict = read_slice_info(key='slice_number') for stain in ['NISSL', 'IHC']: files = listdir(join(DATA_DIR, stain.lower(), 'images_orig')) for f in files: slice_num = str(int(f.split('_')[1].split('.')[0])) pdb.set_trace() outf = slice_dict[stain][slice_num]['filename'] shutil.move(join(DATA_DIR, stain.lower(), 'images_orig', f),join(DATA_DIR, stain.lower(), 'images', outf)) shutil.move(join(DATA_DIR, stain.lower(), 'masks_orig', f),join(DATA_DIR, stain.lower(), 'masks', outf)) shutil.rmtree(join(DATA_DIR, stain.lower(), 'images_orig')) shutil.rmtree(join(DATA_DIR, stain.lower(), 'masks_orig'))
INIT_BASE_DIR = join(DATA_DIR, 'downloads') INIT_BASE_DIR_MRI = join(INIT_BASE_DIR, 'mri') INIT_BASE_DIR_IHC = join(INIT_BASE_DIR, 'ihc') INIT_BASE_DIR_NISSL = join(INIT_BASE_DIR, 'nissl') INIT_BASE_DIR_LINEAL = join(INIT_BASE_DIR, 'linear') MRI_ORIG = join(INIT_BASE_DIR_LINEAL, 'mri.orig.nii.gz') MRI_LIN = join(INIT_BASE_DIR_LINEAL, 'mri.nii.gz') HISTO_LIN = join(INIT_BASE_DIR_LINEAL, 'stack_nissl.lin.tree.nii.gz') BASE_DIR = join(DATA_DIR, 'dataset') BASE_DIR_MRI = join(BASE_DIR, 'mri') BASE_DIR_IHC = join(BASE_DIR, 'ihc') BASE_DIR_NISSL = join(BASE_DIR, 'nissl') create_results_dir(BASE_DIR_MRI, subdirs=['images', 'masks']) create_results_dir( BASE_DIR_IHC, subdirs=['images_resize', 'masks_resize', 'images', 'masks', 'affine']) create_results_dir( BASE_DIR_NISSL, subdirs=['images_resize', 'masks_resize', 'images', 'masks', 'affine']) ####################### ###### Parameters ##### ####################### MRI_RES = 0.5 HISTO_RES = 0.032 HISTO_THICKNESS = 0.05 OUTPUT_RES = 0.25