【发布时间】:2018-04-25 08:15:47
【问题描述】:
我有一个灰度图像数据集,我想使用 sdd-mobilenet 检查点来训练我的对象检测。 将灰度图像转换为 RGB 的正确方法是什么,我可以将我的数据集转换为 tfrecord? 这是我使用的代码(注意注释部分对我不起作用)
with tf.gfile.GFile(os.path.join(path, '{}'.format(group.filename)), 'rb') as fid:
encoded_jpg = fid.read()
# rgb_image = tf.image.grayscale_to_rgb(
# tf.image.encode_jpeg(encoded_jpg),
# name=None
# )
encoded_jpg_io = io.BytesIO(encoded_jpg)
encoded_jpg_io = tf.stack([encoded_jpg_io, encoded_jpg_io, encoded_jpg_io], axis=-1)
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/channels': dataset_util.int64_feature(),
'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
【问题讨论】:
标签: python tensorflow object-detection tfrecord