我想使用Tensorflow对象检测API来处理多通道图像(例如,4通道RGB +红外线)。有一个教程如何更改API以添加其他通道。然而,本教程是在一年前编写的,自那以后API就有了发展,现在看来API可以接受多通道映像了。
例如,在tensorflow-models/research/object-detection/data_decoders/tf_example_decoder.py中,除了fields.InputDataFields.image之外,现在还有fields.InputDataFields.image_additional_channels.它是否可以用于输入图像中输入图像中输入到fields.InputDataFields.image的标准3通道之外的其他通道?我不知道这个image_additional_channels的用途以及如何使用它。
更普遍的是,我的问题是如何使用Tensorflow对象检测API来处理多通道(>3)图像。它们是否被默认接受,即被考虑在内?我可以让他们训练一个模型,但是在object_detection_tutorial笔记本电脑中,它不能接受超过3个通道,这让我怀疑它在训练中是否忽略了第四个通道。
我使用的是对象检测API的最新提交(7a75bfc) Tensorflow 1.12.0。image_additional_channels于2018年6月6日添加到提交的9fce9c6中。
发布于 2018-12-11 14:00:23
我也在做同样的事。在培训期间,它似乎接受了额外的通道(您需要在创建TfExample文件时添加它们)。还需要将管道配置文件的num_additional_channels
部分中的train_input_reader
设置为所添加的通道数。
但是,导出模型以进行推理的脚本似乎不支持以允许它接受其他通道的方式导出模型。
如您所见:探测/出口商
输入张量只是一个标准的图像张量,而tensor_dict[fields.InputDataFields.image_additional_channels]
不包含在输入中。
我将为我的项目修复这个问题,所以我将尝试打开一个拉请求并让他们将其合并到其中。
发布于 2019-07-19 15:11:20
对于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),
}))
但是,导出模型以进行推理的脚本似乎不支持以允许它接受其他通道的方式导出模型。 如您所见:探测/出口商 输入张量只是一个标准的图像张量,而tensor_dictfields.InputDataFields.image_additional_channels不包含在输入中。 我将为我的项目修复这个问题,所以我将尝试打开一个拉请求并让他们将其合并到其中。
我也想知道!我设法训练没有问题,但我不能使用训练的模型,因为额外的通道不能加载.你修好了吗?
https://stackoverflow.com/questions/53392807
复制相似问题