当前位置: 首页>>代码示例>>Python>>正文


Python dataset_util.recursive_parse_xml_to_dict方法代码示例

本文整理汇总了Python中object_detection.utils.dataset_util.recursive_parse_xml_to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python dataset_util.recursive_parse_xml_to_dict方法的具体用法?Python dataset_util.recursive_parse_xml_to_dict怎么用?Python dataset_util.recursive_parse_xml_to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在object_detection.utils.dataset_util的用法示例。


在下文中一共展示了dataset_util.recursive_parse_xml_to_dict方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from object_detection.utils import dataset_util [as 别名]
# 或者: from object_detection.utils.dataset_util import recursive_parse_xml_to_dict [as 别名]
def main(_):
  if FLAGS.set not in SETS:
    raise ValueError('set must be in : {}'.format(SETS))
  if FLAGS.year not in YEARS:
    raise ValueError('year must be in : {}'.format(YEARS))

  data_dir = FLAGS.data_dir
  years = ['VOC2007', 'VOC2012']
  if FLAGS.year != 'merged':
    years = [FLAGS.year]

  writer = tf.python_io.TFRecordWriter(FLAGS.output_path)

  label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path)

  for year in years:
    logging.info('Reading from PASCAL %s dataset.', year)
    examples_path = os.path.join(data_dir, year, 'ImageSets', 'Main',
                                 'aeroplane_' + FLAGS.set + '.txt')
    annotations_dir = os.path.join(data_dir, year, FLAGS.annotations_dir)
    examples_list = dataset_util.read_examples_list(examples_path)
    for idx, example in enumerate(examples_list):
      if idx % 100 == 0:
        logging.info('On image %d of %d', idx, len(examples_list))
      path = os.path.join(annotations_dir, example + '.xml')
      with tf.gfile.GFile(path, 'r') as fid:
        xml_str = fid.read()
      xml = etree.fromstring(xml_str)
      data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation']

      tf_example = dict_to_tf_example(data, FLAGS.data_dir, label_map_dict,
                                      FLAGS.ignore_difficult_instances)
      writer.write(tf_example.SerializeToString())

  writer.close() 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:37,代码来源:create_pascal_tf_record.py

示例2: create_tf_record

# 需要导入模块: from object_detection.utils import dataset_util [as 别名]
# 或者: from object_detection.utils.dataset_util import recursive_parse_xml_to_dict [as 别名]
def create_tf_record(output_filename,
                     label_map_dict,
                     annotations_dir,
                     image_dir,
                     examples):
  """Creates a TFRecord file from examples.

  Args:
    output_filename: Path to where output file is saved.
    label_map_dict: The label map dictionary.
    annotations_dir: Directory where annotation files are stored.
    image_dir: Directory where image files are stored.
    examples: Examples to parse and save to tf record.
  """
  writer = tf.python_io.TFRecordWriter(output_filename)
  for idx, example in enumerate(examples):
    if idx % 100 == 0:
      logging.info('On image %d of %d', idx, len(examples))
    path = os.path.join(annotations_dir, 'xmls', example + '.xml')

    if not os.path.exists(path):
      logging.warning('Could not find %s, ignoring example.', path)
      continue
    with tf.gfile.GFile(path, 'r') as fid:
      xml_str = fid.read()
    xml = etree.fromstring(xml_str)
    data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation']

    tf_example = dict_to_tf_example(data, label_map_dict, image_dir)
    writer.write(tf_example.SerializeToString())

  writer.close()


# TODO: Add test for pet/PASCAL main files. 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:37,代码来源:create_pet_tf_record.py

示例3: create_tf_record

# 需要导入模块: from object_detection.utils import dataset_util [as 别名]
# 或者: from object_detection.utils.dataset_util import recursive_parse_xml_to_dict [as 别名]
def create_tf_record(output_filename,
                     label_map_dict,
                     annotations_dir,
                     image_dir,
                     examples):
  """Creates a TFRecord file from examples.

  Args:
    output_filename: Path to where output file is saved.
    label_map_dict: The label map dictionary.
    annotations_dir: Directory where annotation files are stored.
    image_dir: Directory where image files are stored.
    examples: Examples to parse and save to tf record.
  """
  writer = tf.python_io.TFRecordWriter(output_filename)
  for idx, example in enumerate(examples):
    if idx % 100 == 0:
      logging.info('On image %d of %d', idx, len(examples))
    path = os.path.join(annotations_dir, 'xmls', example + '.xml')

    if not os.path.exists(path):
      logging.warning('Could not find %s, ignoring example.', path)
      continue
    with tf.gfile.GFile(path, 'r') as fid:
      xml_str = fid.read()
    xml = etree.fromstring(xml_str)
    data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation']

    tf_example = dict_to_tf_example(data, label_map_dict, image_dir)
    writer.write(tf_example.SerializeToString())

  writer.close() 
开发者ID:maartensukel,项目名称:garbage-object-detection-tensorflow,代码行数:34,代码来源:create_tf_record.py

示例4: main

# 需要导入模块: from object_detection.utils import dataset_util [as 别名]
# 或者: from object_detection.utils.dataset_util import recursive_parse_xml_to_dict [as 别名]
def main(_):
  if FLAGS.set not in SETS:
    raise ValueError('set must be in : {}'.format(SETS))
  if FLAGS.year not in YEARS:
    raise ValueError('year must be in : {}'.format(YEARS))

  data_dir = FLAGS.data_dir
  years = ['cont_train', 'VOC2012']
  if FLAGS.year != 'merged':
    years = [FLAGS.year]

  writer = tf.python_io.TFRecordWriter(FLAGS.output_path)

  label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path)

  for year in years:
    logging.info('Reading from PASCAL %s dataset.', year)
    examples_path = os.path.join(data_dir, year, 'ImageSets', 'Main',  FLAGS.set + '.txt')
    annotations_dir = os.path.join(data_dir, year, FLAGS.annotations_dir)
    examples_list = dataset_util.read_examples_list(examples_path)
    for idx, example in enumerate(examples_list):
      if idx % 100 == 0:
        logging.info('On image %d of %d', idx, len(examples_list))
      path = os.path.join(annotations_dir, example + '.xml')
      with tf.gfile.GFile(path, 'r') as fid:
        xml_str = fid.read()
      xml = etree.fromstring(xml_str)
      data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation']

      tf_example = dict_to_tf_example(data, FLAGS.data_dir, label_map_dict,
                                      FLAGS.ignore_difficult_instances)

      writer.write(tf_example.SerializeToString())

  writer.close() 
开发者ID:lonelygo,项目名称:container_detection,代码行数:37,代码来源:create_pascal_tf_record.py

示例5: create_tf_record

# 需要导入模块: from object_detection.utils import dataset_util [as 别名]
# 或者: from object_detection.utils.dataset_util import recursive_parse_xml_to_dict [as 别名]
def create_tf_record(output_record_file,
                     label_map_dict,
                     jpegfilenames):
    '''Creates a TFRecord file from examples.

    Args:
        output_record_file: Path to where output file is saved.
        label_map_dict: The label map dictionary.
        jpegfilenames: Examples to parse and save to tf record.
    '''
    writer = tf.python_io.TFRecordWriter(output_record_file)
    for idx, example in enumerate(jpegfilenames):
        if idx % 100 == 0:
            logging.info('On image %d of %d', idx, len(jpegfilenames))
        xmlfile = os.path.join(ANNOTATIONS_DIR, example + '.xml')

        if not os.path.exists(xmlfile):
            logging.warning('Could not find %s, ignoring example.', xmlfile)
            continue
        with tf.gfile.GFile(xmlfile, 'r') as fid:
            xml_str = fid.read()
        xml = etree.fromstring(xml_str)
        data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation']

        tf_example = dict_to_tf_example(data, label_map_dict)
        writer.write(tf_example.SerializeToString())

    writer.close() 
开发者ID:naisy,项目名称:train_ssd_mobilenet,代码行数:30,代码来源:build2_tf_record.py

示例6: main

# 需要导入模块: from object_detection.utils import dataset_util [as 别名]
# 或者: from object_detection.utils.dataset_util import recursive_parse_xml_to_dict [as 别名]
def main(_):
  if FLAGS.set not in SETS:
    raise ValueError('set must be in : {}'.format(SETS))
  print("Getting data for {} set".format(FLAGS.set))

  data_dir = FLAGS.data_dir

  writer = tf.python_io.TFRecordWriter(FLAGS.output_path)

  label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path)

  if FLAGS.set == 'trainval':
    examples_list_knot1 = get_examples_list(data_dir, 'knot_', 'train')
    examples_list_knot2 = get_examples_list(data_dir, 'knot_', 'val')
  #print(len(examples_list_knot1), len(examples_list_knot2), len(examples_list_defect1), len(examples_list_defect2))
    examples_list = examples_list_knot1 +  examples_list_knot2 # + examples_list_defect1 + examples_list_defect2
  else:
    examples_list = get_examples_list(data_dir, 'knot_', FLAGS.set)

  print("About to parse {}  examples".format(len(examples_list)))

  annotations_dir = os.path.join(data_dir, FLAGS.annotations_dir)
  for idx, example in enumerate(examples_list):
    if idx % 10 == 0:
      logging.info('On image %d of %d', idx, len(examples_list))
      print('On image {0} of {1}'.format(idx, len(examples_list)))
    path = os.path.join(annotations_dir, example + '.xml')
    with tf.gfile.GFile(path, 'r') as fid:
      xml_str = fid.read()
    xml = etree.fromstring(xml_str)
    data = dataset_util.recursive_parse_xml_to_dict(xml)['annotation']

    tf_example = dict_to_tf_example(data, FLAGS.data_dir, label_map_dict,
                                    FLAGS.ignore_difficult_instances)
    writer.write(tf_example.SerializeToString())

  writer.close() 
开发者ID:olgaliak,项目名称:active-learning-detect,代码行数:39,代码来源:create_knots_tf_record.py

示例7: xml_to_dict

# 需要导入模块: from object_detection.utils import dataset_util [as 别名]
# 或者: from object_detection.utils.dataset_util import recursive_parse_xml_to_dict [as 别名]
def xml_to_dict(path):
    with tf.gfile.GFile(path, 'r') as fid:
        xml_str = fid.read()
    xml = etree.fromstring(xml_str)
    return dataset_util.recursive_parse_xml_to_dict(xml)['annotation'] 
开发者ID:sshleifer,项目名称:object_detection_kitti,代码行数:7,代码来源:create_dataset.py


注:本文中的object_detection.utils.dataset_util.recursive_parse_xml_to_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。