def main(): system_param, input_data_param = user_parameters_parser.run() if util.has_bad_inputs(system_param): return -1 # print all parameters to txt file for future reference all_param = {} all_param.update(system_param) all_param.update(input_data_param) txt_file = 'settings_{}.txt'.format(system_param['SYSTEM'].action) model_folder = touch_folder(system_param['SYSTEM'].model_dir) txt_file = os.path.join(model_folder, txt_file) util.print_save_input_parameters(all_param, txt_file) # keep all commandline outputs log_file_name = os.path.join( model_folder, '{}_{}'.format(all_param['SYSTEM'].action, 'niftynet_log')) set_logger(file_name=log_file_name) # start application app_driver = ApplicationDriver() app_driver.initialise_application(system_param, input_data_param) app_driver.run_application() return 0
def main(): system_param, input_data_param = user_parameters_parser.run() if util.has_bad_inputs(system_param): return -1 # print all parameters to txt file for future reference all_param = {} all_param.update(system_param) all_param.update(input_data_param) # Set up path for niftynet model_root # (rewriting user input with an absolute path) system_param['SYSTEM'].model_dir = resolve_module_dir( system_param['SYSTEM'].model_dir, create_new=system_param['SYSTEM'].action == "train") # writing all params for future reference txt_file = 'settings_{}.txt'.format(system_param['SYSTEM'].action) txt_file = os.path.join(system_param['SYSTEM'].model_dir, txt_file) util.print_save_input_parameters(all_param, txt_file) # keep all commandline outputs to model_root log_file_name = os.path.join( system_param['SYSTEM'].model_dir, '{}_{}'.format(all_param['SYSTEM'].action, 'niftynet_log')) set_logger(file_name=log_file_name) # set up all model folder related parameters here # see https://cmiclab.cs.ucl.ac.uk/CMIC/NiftyNet/issues/168 # 1. resolve mapping file: try: if system_param['NETWORK'].histogram_ref_file: system_param['NETWORK'].histogram_ref_file = to_absolute_path( input_path=system_param['NETWORK'].histogram_ref_file, model_root=system_param['SYSTEM'].model_dir) except (AttributeError, KeyError): pass # 2. resolve output file: try: if system_param['INFERENCE'].save_seg_dir: system_param['INFERENCE'].save_seg_dir = to_absolute_path( input_path=system_param['INFERENCE'].save_seg_dir, model_root=system_param['SYSTEM'].model_dir) except (AttributeError, KeyError): pass # start application app_driver = ApplicationDriver() app_driver.initialise_application(system_param, input_data_param) app_driver.run_application() return 0
# with self.assertRaisesRegexp( # tf.errors.NotFoundError, 'Failed to find'): # ModelRestorer(**vars(test_driver)).restore_model(None) def test_from_file_initialisation(self): test_driver = get_initialised_driver(40, False) expected_init = np.array([[ -0.23192197, 0.60880029, -0.24921742, -0.00186354, -0.3345384, 0.16067748, -0.2210995, -0.19460233, -0.3035436, -0.42839912, -0.0489039, -0.90753943, -0.12664583, -0.23129687, 0.01584663, -0.43854219, 0.40412974, 0.0396539, -0.1590578, -0.53759819 ]], dtype=np.float32) graph = test_driver.create_graph(test_driver.app, 1, True) with self.test_session(graph=graph) as sess: test_tensor = tf.get_default_graph().get_tensor_by_name( "G/conv_bn_selu/conv_/w:0") with self.assertRaisesRegexp(tf.errors.FailedPreconditionError, 'uninitialized value'): _ = sess.run(test_tensor) ModelRestorer(**vars(test_driver)).restore_model(None) after_init = sess.run(test_tensor) self.assertAllClose(after_init[0], expected_init) _ = sess.run(tf.global_variables()) if __name__ == "__main__": set_logger() # _run_test_application() tf.test.main()
def main(): set_logger() system_param, input_data_param = user_parameters_parser.run() if util.has_bad_inputs(system_param): return -1 # print all parameters to txt file for future reference all_param = {} all_param.update(system_param) all_param.update(input_data_param) # Set up path for niftynet model_root # (rewriting user input with an absolute path) system_param['SYSTEM'].model_dir = resolve_module_dir( system_param['SYSTEM'].model_dir, create_new=system_param['SYSTEM'].action == "train") # writing all params for future reference txt_file = 'settings_{}.txt'.format(system_param['SYSTEM'].action) txt_file = os.path.join(system_param['SYSTEM'].model_dir, txt_file) try: util.print_save_input_parameters(all_param, txt_file) except IOError: tf.logging.fatal( 'Unable to write %s,\nplease check ' 'model_dir parameter, current value: %s', txt_file, system_param['SYSTEM'].model_dir) raise # keep all commandline outputs to model_root log_file_name = os.path.join( system_param['SYSTEM'].model_dir, '{}_{}'.format(all_param['SYSTEM'].action, 'niftynet_log')) set_logger(file_name=log_file_name) # set up all model folder related parameters here # see https://cmiclab.cs.ucl.ac.uk/CMIC/NiftyNet/issues/168 # 1. resolve mapping file: try: if system_param['NETWORK'].histogram_ref_file: system_param['NETWORK'].histogram_ref_file = to_absolute_path( input_path=system_param['NETWORK'].histogram_ref_file, model_root=system_param['SYSTEM'].model_dir) except (AttributeError, KeyError): pass # 2. resolve output file: try: if system_param['INFERENCE'].save_seg_dir: system_param['INFERENCE'].save_seg_dir = to_absolute_path( input_path=system_param['INFERENCE'].save_seg_dir, model_root=system_param['SYSTEM'].model_dir) except (AttributeError, KeyError): pass # 3. resolve dataset splitting file: try: if system_param['SYSTEM'].dataset_split_file: system_param['SYSTEM'].dataset_split_file = to_absolute_path( input_path=system_param['SYSTEM'].dataset_split_file, model_root=system_param['SYSTEM'].model_dir) except (AttributeError, KeyError): pass # start application app_driver = ApplicationDriver() app_driver.initialise_application(system_param, input_data_param) app_driver.run_application() return 0
def main(): set_logger() print("Hola como vai estoy en el init de niftynet ################") system_param, input_data_param = user_parameters_parser.run() if util.has_bad_inputs(system_param): return -1 # print all parameters to txt file for future reference all_param = {} all_param.update(system_param) all_param.update(input_data_param) # Set up path for niftynet model_root # (rewriting user input with an absolute path) system_param['SYSTEM'].model_dir = resolve_module_dir( system_param['SYSTEM'].model_dir, create_new=system_param['SYSTEM'].action == "train") # writing all params for future reference txt_file = 'settings_{}.txt'.format(system_param['SYSTEM'].action) txt_file = os.path.join(system_param['SYSTEM'].model_dir, txt_file) try: util.print_save_input_parameters(all_param, txt_file) except IOError: tf.logging.fatal( 'Unable to write %s,\nplease check ' 'model_dir parameter, current value: %s', txt_file, system_param['SYSTEM'].model_dir) raise # keep all commandline outputs to model_root log_file_name = os.path.join( system_param['SYSTEM'].model_dir, '{}_{}'.format(all_param['SYSTEM'].action, 'niftynet_log')) set_logger(file_name=log_file_name) # set up all model folder related parameters here # see https://cmiclab.cs.ucl.ac.uk/CMIC/NiftyNet/issues/168 # 1. resolve mapping file: try: if system_param['NETWORK'].histogram_ref_file: system_param['NETWORK'].histogram_ref_file = to_absolute_path( input_path=system_param['NETWORK'].histogram_ref_file, model_root=system_param['SYSTEM'].model_dir) except (AttributeError, KeyError): pass # 2. resolve output file: try: if system_param['INFERENCE'].save_seg_dir: system_param['INFERENCE'].save_seg_dir = to_absolute_path( input_path=system_param['INFERENCE'].save_seg_dir, model_root=system_param['SYSTEM'].model_dir) except (AttributeError, KeyError): pass # 3. resolve dataset splitting file: try: if system_param['SYSTEM'].dataset_split_file: system_param['SYSTEM'].dataset_split_file = to_absolute_path( input_path=system_param['SYSTEM'].dataset_split_file, model_root=system_param['SYSTEM'].model_dir) except (AttributeError, KeyError): pass # start application app_driver = ApplicationDriver() print("Initializing application$$$$$$$$$$$$$$$$$$$$$BEGIN") app_driver.initialise_application(system_param, input_data_param) print("Initializing application$$$$$$$$$$$$$$$$$$$$$END") print("Initializing RUN application$$$$$$$$$$$$$$$$$$$$$BEGIN") app_driver.run_application() print("Initializing RUN application$$$$$$$$$$$$$$$$$$$$$END") return 0
def main(): system_param, input_data_param = user_parameters_parser.run() if util.has_bad_inputs(system_param): return -1 # print all parameters to txt file for future reference all_param = {} all_param.update(system_param) all_param.update(input_data_param) # Set up path for niftynet model_root # (rewriting user input with an absolute path) system_param['SYSTEM'].model_dir = resolve_module_dir( system_param['SYSTEM'].model_dir, create_new=system_param['SYSTEM'].action == TRAIN) # writing all params for future reference txt_file = 'settings_{}.txt'.format(system_param['SYSTEM'].action) txt_file = os.path.join(system_param['SYSTEM'].model_dir, txt_file) try: util.print_save_input_parameters(all_param, txt_file) except IOError: tf.logging.fatal( 'Unable to write %s,\nplease check ' 'model_dir parameter, current value: %s', txt_file, system_param['SYSTEM'].model_dir) raise # keep all commandline outputs to model_root log_file_name = os.path.join( system_param['SYSTEM'].model_dir, '{}_{}'.format(all_param['SYSTEM'].action, 'niftynet_log')) set_logger(file_name=log_file_name) # set up all model folder related parameters here # see https://cmiclab.cs.ucl.ac.uk/CMIC/NiftyNet/issues/168 # 1. resolve mapping file: try: if system_param['NETWORK'].histogram_ref_file: system_param['NETWORK'].histogram_ref_file = to_absolute_path( input_path=system_param['NETWORK'].histogram_ref_file, model_root=system_param['SYSTEM'].model_dir) except (AttributeError, KeyError): pass # 2. resolve output file: try: if system_param['INFERENCE'].save_seg_dir: system_param['INFERENCE'].save_seg_dir = to_absolute_path( input_path=system_param['INFERENCE'].save_seg_dir, model_root=system_param['SYSTEM'].model_dir) except (AttributeError, KeyError): pass # 3. resolve dataset splitting file: try: if system_param['SYSTEM'].dataset_split_file: system_param['SYSTEM'].dataset_split_file = to_absolute_path( input_path=system_param['SYSTEM'].dataset_split_file, model_root=system_param['SYSTEM'].model_dir) except (AttributeError, KeyError): pass # 4. resolve evaluation dir: try: if system_param['EVALUATION'].save_csv_dir: system_param['EVALUATION'].save_csv_dir = to_absolute_path( input_path=system_param['EVALUATION'].save_csv_dir, model_root=system_param['SYSTEM'].model_dir) except (AttributeError, KeyError): pass # start application driver_table = { TRAIN: ApplicationDriver, INFER: ApplicationDriver, EVAL: EvaluationApplicationDriver, EXPORT: ApplicationDriver} app_driver = driver_table[system_param['SYSTEM'].action]() app_driver.initialise_application(system_param, input_data_param) app_driver.run(app_driver.app) if tf.get_default_session() is not None: tf.get_default_session().close() tf.reset_default_graph() close_logger() return 0
'output_prob':False}) eval_param=NS({'evaluations':'Dice'}) mask = np.reshape(np.abs(np.linspace(0.,2.,64)-1)>.8,[4,4,4,1,1]) data_dict = {'label':mask,'inferred':mask} interp_orders = {'label':0,'inferred':0} image_folder = '.' e = SegmentationEvaluator(None, segmentation_param, eval_param) def generator(): yield ('test',data_dict,interp_orders) result_dict = e.evaluate_from_generator(generator()) self.assertIn(('subject_id', 'label'), result_dict) self.assertIn(('subject_id', 'cc_id'), result_dict) self.assertEqual(tuple(result_dict[('subject_id', 'label')].index.names), ('subject_id', 'label')) self.assertEqual(tuple(result_dict[('subject_id', 'cc_id')].index.names), ('subject_id', 'cc_id')) print(result_dict[('subject_id', 'cc_id')].to_dict('index')) self.assertEqual(result_dict[('subject_id', 'label')].to_dict('index'), {('test', 1): {'dice': 1.}}) self.assertEqual(result_dict[('subject_id', 'cc_id')].to_dict('index'), {('test', 'r1_s1'): {'dice': 1.}, ('test', 'r2_s2'): {'dice': 1.}}) if __name__ == "__main__": set_logger() # _run_test_application() tf.test.main()