예제 #1
0
def process_single_scan_battery_keras(model_folder,
                                      source_scan_battery_dirname):
    # Make sure model_folder and source_scan_battery_dirname exist.
    if not os_path_isdir(model_folder):
        raise OSError('{}: model folder {} does not exist'.format(
            SCRIPT_FNAME, model_folder))
    if not os_path_isdir(source_scan_battery_dirname):
        raise OSError(
            '{}: source scan battery folder {} does not exist'.format(
                SCRIPT_FNAME, source_scan_battery_dirname))

    # model/scan_batteries folders.
    model_scan_batteries_dirname = os_path_join(model_folder,
                                                SCAN_BATTERIES_DIRNAME)
    model_scan_battery_dirname = os_path_join(
        model_scan_batteries_dirname,
        os_path_basename(source_scan_battery_dirname))

    # Copy source scan_batteries folder into model scan_batteries folder
    # TODO: Could also just copy the entire scan_batteries folder (all 3 types) into model_folder
    # logging_info('{}: copying {} to {}'.format(SCRIPT_FNAME, source_scan_battery_dirname, model_scan_battery_dirname))
    # copy_anything(source_scan_battery_dirname, model_scan_battery_dirname)
    # model_scan_battery_process_scripts_dirname = os_path_abspath(os_path_join(model_scan_battery_dirname, PROCESS_SCRIPTS_DIRNAME))

    # Grab all targets with glob
    mode_scan_battery_target_prefix = os_path_join(model_scan_battery_dirname,
                                                   TARGET_PREFIX + '*')
    target_dirnames = glob_glob(mode_scan_battery_target_prefix)
    if not target_dirnames:
        raise ValueError('{}: no targets found with prefix {}'.format(
            SCRIPT_FNAME, mode_scan_battery_target_prefix))

    for target_dirname in target_dirnames:
        process_single_target(target_dirname)

    # for target_dirname in target_dirnames:
    #     # print('{}: processing target directory {}'.format(SCRIPT_FNAME, target_dirname))
    #     process_single_target(target_dirname)

    # Remove scan battery-level folders
    for folder in SCAN_BATTERY_FOLDERS_TO_REMOVE:
        folder_path = os_path_join(model_scan_battery_dirname, folder)
        if os_path_isdir(folder_path):
            # print('{}: Trying to remove {}'.format(SCRIPT_FNAME, folder_path))
            try:
                shutil.rmtree(folder_path)
            except:
                raise OSError(
                    'Error: unable to remove file {}'.format(folder_path))

    # Remove scan battery-level files
    for file in SCAN_BATTERY_FILES_TO_REMOVE:
        file_path = os_path_join(model_scan_battery_dirname, file)
        if os_path_isfile(file_path):
            # print('{}: Trying to remove {}'.format(SCRIPT_FNAME, file_path))
            try:
                os_remove(file_path)
            except:
                raise OSError(
                    'Error: unable to remove file {}'.format(file_path))
 def standard_xml_list_to_dataframe(self, directory: str) -> DataFrame:
     """
         xml_to_dataframe --> DataFrame
         path: path for the XML file that contains the dataset --> proper structure of XML is that of "LabelImg"
     """
     xml_list = []
     for xml_file in glob_glob(directory + '/*.xml'):
         tree = ET.parse(xml_file)
         root = tree.getroot()
         for member in root.findall('object'):
             bndbox = member.find('bndbox')
             value = (root.find('folder').text, root.find('filename').text,
                      int(root.find('size')[0].text),
                      int(root.find('size')[1].text),
                      member.find('name').text,
                      int(bndbox.find('xmin').text),
                      int(bndbox.find('ymin').text),
                      int(bndbox.find('xmax').text),
                      int(bndbox.find('ymax').text))
             xml_list.append(value)
     column_name = [
         'folder', 'filename', 'width', 'height', 'class-name', 'xmin',
         'ymin', 'xmax', 'ymax'
     ]
     xml_df = DataFrame(xml_list, columns=column_name)
     return xml_df
예제 #3
0
def findfiles(find_path, expression):
    #
    # Initial section for instantizing variables expected by remaining routine
    returned = list()
    #
    # Normalize the input parameters for simplifying the downstream procedures
    find_path_glob = os_path.join(find_path, "**")
    #
    # Recursively find matching files and directories using regular expression
    excepted = "failed to execute glob and listsearch functions for matchings"
    try:
        x = listsearch(glob_glob(find_path_glob, recursive=True), expression)
    except Exception as reason:
        raise Exception(excepted) from reason
    else:
        returned.extend(x)
    #
    # Returns matching list for files using glob patterns and match expression
    return [os_path.relpath(x, find_path) for x in returned]
예제 #4
0
def evaluate_one_model_keras(model_dirpath):
    # rename _trained as _evaluating
    new_folder_name = model_dirpath.replace('_trained', '_evaluating')
    shutil_move(model_dirpath, new_folder_name)
    model_name = os_path_basename(new_folder_name)
    copied_scan_battery_dirname = os_path_join(
        new_folder_name, os_path_basename(SCAN_BATTERIES_DIRNAME))
    copy_anything(SCAN_BATTERIES_DIRNAME, copied_scan_battery_dirname)

    time_start = time_time()

    # with Pool() as pool:
    #     list(pool.imap_unordered(process_single_target, target_dirnames))
    for scan_battery_dirname in glob_glob(
            os_path_join(SCAN_BATTERIES_DIRNAME, '*')):
        process_single_scan_battery_keras(new_folder_name,
                                          scan_battery_dirname)
    print('{}: it took {:.2f} to evaluate model {} for all scan batteries'.
          format(SCRIPT_FNAME,
                 time_time() - time_start, model_name))
    shutil_move(new_folder_name,
                new_folder_name.replace('_evaluating', '_evaluated'))
예제 #5
0
                        action='store_true')
    args = parser.parse_args()

    identifier = args.identifier
    max_to_evaluate = args.max_to_evaluate
    verbose = args.verbose

    logger = logging_getLogger('evaluate_keras')
    if verbose:
        logger.setLevel(logging_DEBUG)
    else:
        logger.setLevel(logging_INFO)

    model_search_path = os_path_join(MODELS_DIRNAME,
                                     str(identifier) + '_trained')
    models = glob_glob(model_search_path)
    num_models = len(models)

    if num_models == 0:
        raise ValueError('evaluate_models: given identifier ' +
                         str(identifier) + ' , expanded to ' +
                         str(model_search_path) + ' matched no model.')

    if max_to_evaluate > -1:
        count = 0

    # Process each model
    for model_index, model_folder in enumerate(models):
        if max_to_evaluate > -1 and count >= max_to_evaluate:
            break
 def get_xml_path_list(self, directory):
     return [x for x in glob_glob(directory + '/*.xml')]