如何解决Tensorflow 对象检测 API - API 是否支持所有 PASCAL VOC 标签
我想将我的 PASCALVOC-XML-Files 解析为 TF-Records。目前我使用以下代码:
def create_tf_example(group,path):
with tf.gfile.GFile(os.path.join(path,'{}'.format(group.filename)),'rb') as fid:
encoded_jpg = fid.read()
encoded_jpg_io = io.BytesIO(encoded_jpg)
image = Image.open(encoded_jpg_io)
width,height = image.size
filename = group.filename.encode('utf8')
image_format = b'jpg'
xmins = []
xmaxs = []
ymins = []
ymaxs = []
classes_text = []
classes = []
for index,row in group.object.iterrows():
xmins.append(row['xmin'] / width)
xmaxs.append(row['xmax'] / width)
ymins.append(row['ymin'] / height)
ymaxs.append(row['ymax'] / height)
classes_text.append(row['class'].encode('utf8'))
classes.append(class_text_to_int(row['class']))
tf_example = tf.train.Example(features=tf.train.Features(feature={
'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_jpg),'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),}))
return tf_example
如果我将 XML-Tags truncated
、occluded
或 difficult
的内容添加到 tfrecord 中,会有什么影响吗?
这是一个 XML 文件的示例:
<annotation>
<folder>folder_name</folder>
<filename>image.jpg</filename>
<path>C:\path\to\image.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>5000</width>
<height>5000</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>airplane</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<occluded>0</occluded>
<bndbox>
<xmin>1807</xmin>
<ymin>3081</ymin>
<xmax>2010</xmax>
<ymax>3254</ymax>
</bndbox>
</object>
…
</annotation>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。