convert_to_example_simple这个函数就是TFRecord格式的数据的制作过程。
import cv2
import numpy as np
import tensorflow as tf
def convert_to_example_simple(image_example, image_buffer):
"""
covert to tfrecord file
:param image_example: dict, an image example
:param image_buffer: string, JPEG encoding of RGB image
:param colorspace:
:param channels:
:param image_format:
:return:
Example proto
"""
# filename = str(image_example['filename'])
# class label for the whole image
class_label = image_example['label'] # 传入label值(1、0、-1、-2)
bbox = image_example['bbox'] # 传入bbox
roi = [bbox['xmin'], bbox['ymin'], bbox['xmax'], bbox['ymax']] # 传入坐标的4个值
landmark = [bbox['xlefteye'], bbox['ylefteye'], bbox['xrighteye'], bbox['yrighteye'], bbox['xnose'], bbox['ynose'],
bbox['xleftmouth'], bbox['yleftmouth'], bbox['xrightmouth'], bbox['yrightmouth']]
# 传入landmark的10个值
# example
example = tf.train.Example(features=tf.train.Features(feature={
'image/encoded': _bytes_feature(image_buffer), # 图片矩阵的字符串形式
'image/label': _int64_feature(class_label), # label
'image/roi': _float_feature(roi), # 人脸框4个坐标
'image/landmark': _float_feature(landmark) # landmark的10个坐标
}))
return example
img = cv2.imread('5.jpg')
cv2.imshow("img",img)
cv2.waitKey()
暂时没看懂,回头在看。