def dict_to_coco_example(img_data):
"""Convert python dictionary formath data of one image to tf.Example proto.
Args:
img_data: infomation of one image, inclue bounding box, labels of bounding box,\
height, width, encoded pixel data.
Returns:
example: The converted tf.Example
"""
bboxes = img_data['bboxes']
xmin, xmax, ymin, ymax = [], [], [], []
for bbox in bboxes:
xmin.append(bbox[0])
xmax.append(bbox[0] + bbox[2])
ymin.append(bbox[1])
ymax.append(bbox[1] + bbox[3])
example = tf.train.Example(features=tf.train.Features(feature={
'image/height': dataset_util.int64_feature(img_data['height']),
'image/width': dataset_util.int64_feature(img_data['width']),
'image/object/bbox/xmin': dataset_util.float_list_feature(xmin),
'image/object/bbox/xmax': dataset_util.float_list_feature(xmax),
'image/object/bbox/ymin': dataset_util.float_list_feature(ymin),
'image/object/bbox/ymax': dataset_util.float_list_feature(ymax),
'image/object/class/label': dataset_util.int64_list_feature(img_data['labels']),
'image/encoded': dataset_util.bytes_feature(img_data['pixel_data']),
'image/format': dataset_util.bytes_feature('jpeg'.encode('utf-8')),
}))
return example
create_coco_tf_record.py 文件源码
python
阅读 34
收藏 0
点赞 0
评论 0
评论列表
文章目录