对于 TFRecord 创建,您必须在此处编辑示例:
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
这部分代码加载并打开一个图像文件路径;如果您有多个图像,则必须将它们加载到不同的变量中。例如,我使用这样的东西:
with tf.gfile.GFile(dictionary[0], 'rb') as fid:
encoded_jpg = fid.read()
if ndata > 1:
with tf.gfile.GFile(dictionary[1], 'rb') as fid:
encoded_depth = fid.read()
encoded_inputs = encoded_depth
其中dictionary[0]
包含 rgb 图像dictionary[1]
的路径,并包含深度图像的路径。
然后,必须像这样创建 TFRecord:
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/additional_channels/encoded': dataset_util.bytes_feature(encoded_inputs),
'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),
}))
但是,导出模型以进行推理的脚本似乎不支持以允许其接受其他通道的方式导出模型。
正如你在这里看到的:
https ://github.com/tensorflow/models/blob/master/research/object_detection/exporter.py#L129
输入张量只是标准图像张量,输入中不包含 tensor_dict[fields.InputDataFields.image_additional_channels]。
我即将为我的项目解决这个问题,所以我会尝试打开一个拉取请求并让他们将其合并。
我也想知道!我设法训练没有问题,但我不能使用训练后的模型,因为无法加载额外的通道......你解决了吗?