Ejemplo n.º 1
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
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
Ejemplo n.º 4
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