【问题标题】:How to prepare my images and annotation for retinanet training?如何为视网膜网络训练准备我的图像和注释?
【发布时间】:2019-07-28 01:16:17
【问题描述】:

我按照tutorial 在 coco 数据集上训练对象检测模型。本教程包含下载和使用coco dataset 及其注释并将其转换为TFRecord 的步骤。

我需要使用自己的自定义数据进行训练,我使用labelimg 工具进行了注释,该工具生成了包含 (w,h,xmin,ymin,xmax,ymax) 的图像的 xml 文件。

coco 数据集具有 JSON 格式,带有用于创建 TFRecord 的图像分割字段。

训练 resnet、retinanet 是否必须进行分段?

那么,谁能指导我从没有分段值的 XML 注释创建 JSON 注释的过程?

xml:

<annotation>
    <folder>frames</folder>
    <filename>83.jpg</filename>
    <path>/home/tdadmin/Downloads/large/f/frames/83.jpg</path>
    <source>
        <database>Unknown</database>
    </source>
    <size>
        <width>640</width>
        <height>480</height>
        <depth>3</depth>
    </size>
    <segmented>0</segmented>
    <object>
        <name>person</name>
        <pose>Unspecified</pose>
        <truncated>0</truncated>
        <difficult>0</difficult>
        <bndbox>
            <xmin>246</xmin>
            <ymin>48</ymin>
            <xmax>350</xmax>
            <ymax>165</ymax>
        </bndbox>
    </object>
</annotation>

【问题讨论】:

    标签: image-processing artificial-intelligence object-detection object-detection-api retinanet


    【解决方案1】:

    你现在做的有点像我之前做过的一个项目。所以我有一些建议给你。

    当我训练我的 Mask RCNN 模型时,我使用了 VGG Image Annotator (you can easily find that on Google)。通过使用该工具,可以轻松创建 json 注释文件。然后将其插入您的训练中。

    希望对您有所帮助。如果您仍有疑问,请随时对此发表评论。

    罗文

    【讨论】:

      【解决方案2】:

      注解格式其实并不重要。我之前自己从 txt 文件创建了 tfrecord。要创建自定义 tfrecord,您必须编写自己的 create_custom_tf_record.py,就像 this folder 中显示的其他内容一样。

      但是由于你使用的是 coco 类似的注解,你可以使用文件create_coco_tf_record.py。您需要自己实现的重要内容是annotations_listannotations_list 只是一个字典,因此您的目标是将您的 xml 文件解析为包含键值对的字典,然后将正确的值传递给 feature_dict,然后从 feature_dict 构造 tf.train.Example。有了tf.train.Example created,就可以轻松创建tfrecord了。

      因此,对于您的确切示例,首先解析 xml 文件。

      import xml.etree.ElementTree as ET
      tree = ET.parse('annotations.xml')
      

      然后像这样从tree 构造annotaions_list

      annotations_list = {}
      it = tree.iter()
      for key in it:
          annotations_list[str(key.tag)] = key.text
      

      然后你可以从annotations_list创建feature_dict

      feature_dict = {
        'image/height':
            dataset_util.int64_feature(annotatios_list['height']),
        'image/width':
            dataset_util.int64_feature(...),
        'image/filename':
            dataset_util.bytes_feature(...),
        'image/source_id':
            dataset_util.bytes_feature(...),
        'image/key/sha256':
            dataset_util.bytes_feature(...),
        'image/encoded':
            dataset_util.bytes_feature(...),
        'image/format':
            dataset_util.bytes_feature(...),
        'image/object/bbox/xmin':
            dataset_util.float_list_feature(...),
        'image/object/bbox/xmax':
            dataset_util.float_list_feature(...),
        'image/object/bbox/ymin':
            dataset_util.float_list_feature(...),
        'image/object/bbox/ymax':
            dataset_util.float_list_feature(...),
        'image/object/class/text':
            dataset_util.bytes_list_feature(....),
        'image/object/is_crowd':
            dataset_util.int64_list_feature(...),
        'image/object/area':
            dataset_util.float_list_feature(...),
        }
      

      只需确保feature_dict 字段对应于annotations_listlabel_map 中的正确字段。

      您可能想知道为什么feature_dict中的这些字段是必需的,根据官方文档using your own dataset,以下字段是必需的,其他是可选的。

      'image/height': dataset_util.int64_feature(height),
        'image/width': dataset_util.int64_feature(width),
        'image/filename': dataset_util.bytes_feature(filename),
        'image/source_id': dataset_util.bytes_feature(filename),
        'image/encoded': dataset_util.bytes_feature(encoded_image_data),
        'image/format': dataset_util.bytes_feature(image_format),
        'image/object/bbox/xmin': dataset_util.float_list_feature(xmins),
        'image/object/bbox/xmax': dataset_util.float_list_feature(xmaxs),
        'image/object/bbox/ymin': dataset_util.float_list_feature(ymins),
        'image/object/bbox/ymax': dataset_util.float_list_feature(ymaxs),
        'image/object/class/text': dataset_util.bytes_list_feature(classes_text),
        'image/object/class/label': dataset_util.int64_list_feature(classes),
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-04-27
        • 1970-01-01
        • 1970-01-01
        • 2017-05-28
        • 2011-10-30
        • 1970-01-01
        • 2012-10-24
        • 1970-01-01
        相关资源
        最近更新 更多