Exemplo n.º 1
0
def do_registration_eval(args, registration_pair_list, pair_name_list=None):
    """
    set running env and run the task

    registration_pair_list includes source_path_list, target_path_list, l_source_path_list, l_target_path_list
    source_path_list: the source image list, each item refers to the abstract path of the image
    target_path_list: the target image list,  each item refers to the abstract path of the image
    l_source_path_list: optional, the label of source image list, each item refers to the abstract path of the image
    l_target_path_list:optional, the label of target image list, each item refers to the abstract path of the image

    :param args: the parsed arguments
    :param registration_pair_list:  list of registration pairs, [source_list, target_list, lsource_list, ltarget_list]
    :return: None
    """
    task_output_path = args.task_output_path
    os.makedirs(task_output_path, exist_ok=True)

    setting_folder_path = args.setting_folder_path
    dm, tsm = init_test_env(setting_folder_path, task_output_path,
                            registration_pair_list, pair_name_list)
    tsm.task_par['tsk_set']['gpu_ids'] = args.gpu_id
    model_path = args.model_path
    if model_path is not None:
        assert os.path.isfile(model_path), "the model {} not exist".format_map(
            model_path)
        tsm.task_par['tsk_set'][
            'model_path'] = model_path  #if not tsm.task_par['tsk_set']['train']:
    force_test_setting(dm, tsm, task_output_path)

    dm_json_path = os.path.join(
        task_output_path, 'cur_data_setting.json') if dm is not None else None
    tsm_json_path = os.path.join(task_output_path, 'cur_task_setting.json')
    run_one_task(tsm_json_path, dm_json_path)
Exemplo n.º 2
0
def do_segmentation_eval(args, segmentation_file_list):
    """
    set running env and run the task

    :param args: the parsed arguments
    :param segmentation_file_list:  list of segmentation file list, [image_list, label_list]
    :return: None
    """
    task_output_path = args.task_output_path
    os.makedirs(task_output_path, exist_ok=True)
    setting_folder_path = args.setting_folder_path
    file_txt_path = args.file_txt_path
    fname_txt_path = file_txt_path.replace("file_path_list.txt",
                                           "file_name_list.txt")
    fname_list = read_txt_into_list(fname_txt_path) if os.path.isfile(
        fname_txt_path) else None
    dm, tsm = init_test_env(setting_folder_path, task_output_path,
                            segmentation_file_list, fname_list)
    tsm.task_par['tsk_set']['gpu_ids'] = args.gpu_id
    model_path = args.model_path
    if model_path is not None:
        assert os.path.isfile(model_path), "the model {} not exist".format_map(
            model_path)
        tsm.task_par['tsk_set']['model_path'] = model_path
    force_test_setting(dm, tsm, task_output_path)

    dm_json_path = os.path.join(
        task_output_path, 'cur_data_setting.json') if dm is not None else None
    tsm_json_path = os.path.join(task_output_path, 'cur_task_setting.json')
    run_one_task(tsm_json_path, dm_json_path)
Exemplo n.º 3
0
def __do_segmentation_train(args, pipeline=None):
    """
        set running env and run the task

        :param args: the parsed arguments
        :param pipeline:a Pipeline object
        :return: a Pipeline object
    """

    output_root_path = args.output_root_path
    task_name = args.task_name
    data_task_name = args.data_task_name
    setting_folder_path = args.setting_folder_path
    data_task_path = os.path.join(output_root_path, data_task_name)
    task_output_path = os.path.join(data_task_path, task_name)
    os.makedirs(task_output_path, exist_ok=True)
    dm, tsm = init_train_env(setting_folder_path, output_root_path, task_name,
                             data_task_name)
    tsm.task_par['tsk_set']['gpu_ids'] = args.gpu_id
    dm_json_path = os.path.join(
        task_output_path, 'cur_data_setting.json') if dm is not None else None
    tsm_json_path = os.path.join(task_output_path, 'cur_task_setting.json')
    tsm.save(tsm_json_path)
    if dm is not None:
        dm.save(dm_json_path)
    data_loaders = pipeline.data_loaders if pipeline is not None else None
    pipeline = run_one_task(tsm_json_path, dm_json_path, data_loaders)
    return pipeline
Exemplo n.º 4
0
def __do_registration_train(args, pipeline=None):
    """
        set running env and run the task

        :param args: the parsed arguments
        :param pipeline:a Pipeline object, only used for two-stage training, the pipeline of the first stage (including dataloader) would be pass to the second stage
        :return: a Pipeline object
    """

    output_root_path = args.output_root_path
    task_name = args.task_name
    data_task_name = args.data_task_name
    setting_folder_path = args.setting_folder_path
    data_task_path = os.path.join(output_root_path, data_task_name)
    task_output_path = os.path.join(data_task_path, task_name)
    os.makedirs(task_output_path, exist_ok=True)
    dm, tsm = init_train_env(setting_folder_path, output_root_path, task_name,
                             data_task_name)
    dm, tsm = addition_settings_for_two_stage_training(dm, tsm)
    tsm.task_par['tsk_set']['gpu_ids'] = args.gpu_id
    dm_json_path = os.path.join(
        task_output_path, 'cur_data_setting.json') if dm is not None else None
    tsm_json_path = os.path.join(task_output_path, 'cur_task_setting.json')
    tsm.save(tsm_json_path)
    if dm is not None:
        dm.save(dm_json_path)
    data_loaders = pipeline.data_loaders if pipeline is not None else None
    pipeline = run_one_task(tsm_json_path, dm_json_path, data_loaders)
    return pipeline
Exemplo n.º 5
0
def do_registration_eval(args, registration_pair_list, pair_name_list=None):
    """
    set running env and run the task

    registration_pair_list includes source_path_list, target_path_list, l_source_path_list, l_target_path_list
    source_path_list: the source image list, each item refers to the abstract path of the image
    target_path_list: the target image list,  each item refers to the abstract path of the image
    l_source_path_list: optional, the label of source image list, each item refers to the abstract path of the image
    l_target_path_list:optional, the label of target image list, each item refers to the abstract path of the image

    :param args: the parsed arguments
    :param registration_pair_list:  list of registration pairs, [source_list, target_list, lsource_list, ltarget_list]
    :return: None
    """
    task_output_path = args.task_output_path
    os.makedirs(task_output_path, exist_ok=True)
    run_demo = args.run_demo
    if run_demo:
        demo_name = args.demo_name
        if demo_name not in ['ants', 'demons', 'nifty_reg']:
            setting_folder_path = os.path.join('./demo_settings/mermaid',
                                               demo_name)
        else:
            setting_folder_path = os.path.join('./demo_settings', demo_name)
        assert os.path.isdir(
            setting_folder_path
        ), "the {} is not in supported demo list, eval_network_rdmm/eval_network_vsvf/opt_vsvf/opt_rdmm/opt_rdmm_predefined/ants/demons/niftyreg"
        # task_output_path = os.path.join('./demo_output/mermaid',demo_name)
    else:
        setting_folder_path = args.setting_folder_path
    dm, tsm = init_test_env(setting_folder_path, task_output_path,
                            registration_pair_list, pair_name_list)
    tsm.task_par['tsk_set']['gpu_ids'] = args.gpu_id
    # if not tsm.task_par['tsk_set']['train']:
    force_test_setting(dm, tsm, task_output_path)

    dm_json_path = os.path.join(
        task_output_path, 'cur_data_setting.json') if dm is not None else None
    tsm_json_path = os.path.join(task_output_path, 'cur_task_setting.json')
    run_one_task(tsm_json_path, dm_json_path)
Exemplo n.º 6
0
    def __do_segmentation_train(self, pipeline=None):
    """
        set running env and run the task
        :param pipeline:a Pipeline object
        :return: a Pipeline object
    """
    self.pipeline = pipeline
    self.output_root_path = self.args.output_root_path
    self.task_name = self.args.task_name
    self.data_task_name = self.args.data_task_name
    self.setting_folder_path = self.args.setting_folder_path
    self.data_task_path = os.path.join(output_root_path,data_task_name)
    self.task_output_path = os.path.join(data_task_path,task_name)
    os.makedirs(task_output_path, exist_ok=True)

    dm, tsm = self.init_train_env()
    tsm.task_par['tsk_set']['gpu_ids'] = args.gpu_id
    self.dm_json_path = os.path.join(task_output_path, 'cur_data_setting.json') if dm is not None else None
    self.tsm_json_path = os.path.join(task_output_path, 'cur_task_setting.json')
    tsm.save(self.tsm_json_path)
    if dm is not None:
        dm.save(self.dm_json_path)
    data_loaders = pipeline.data_loaders if self.pipeline is not None else None
    self.pipeline = run_one_task(self.tsm_json_path, self.dm_json_path, data_loaders)