Tensorflow目标检测API图像的意义

Tensorflow目标检测API图像的意义,tensorflow,object-detection,object-detection-api,satellite-image,Tensorflow,Object Detection,Object Detection Api,Satellite Image,我想将Tensorflow对象检测API用于多通道图像(例如,4通道RGB+红外)。这里有一个如何更改API以添加其他通道的示例。然而,本教程是一年前编写的,API从那时起就不断发展,似乎API现在可以接受多通道图像 例如,在tensorflow models/research/object Detector/data_decoders/tf_example_decoder.py中,除了fields.InputDataFields.image之外,现在还有fields.InputDataFiel

我想将Tensorflow对象检测API用于多通道图像(例如,4通道RGB+红外)。这里有一个如何更改API以添加其他通道的示例。然而,本教程是一年前编写的,API从那时起就不断发展,似乎API现在可以接受多通道图像

例如,在tensorflow models/research/object Detector/data_decoders/tf_example_decoder.py中,除了fields.InputDataFields.image之外,现在还有fields.InputDataFields.image\u其他\u通道。除了输入到fields.InputDataFields.image的标准3个通道之外,它还可以用于输入图像中的任何其他通道吗?我不知道这个图像的目的是什么以及如何使用它

更一般地说,我的问题是如何对多通道(>3)图像使用Tensorflow对象检测API。默认情况下是否接受,即是否考虑?我可以输入它们来训练模型,但对于对象检测教程笔记本中的推理,它不能接受超过3个通道,这让我怀疑它在训练过程中是否忽略了第4个通道


我使用的是Tensorflow 1.12.0,对象检测API的最新提交(7a75bfc)。2018年6月6日,在commit 9fce9c6中添加了额外的图像频道

我正在尝试做同样的事情。它似乎在培训期间接受其他通道(您需要在创建TfExample文件期间添加它们)。您还需要将管道配置文件的
train\u input\u reader
部分中的
num\u additional\u channels
设置为已添加的通道数

但是,用于导出模型进行推理的脚本似乎不支持以允许其接受其他通道的方式导出模型

正如你在这里看到的:

输入张量只是一个标准的图像张量,
tensor\u dict[fields.InputDataFields.image\u additional\u channels]
不包括在输入中


我将为我的项目修复此问题,因此我将尝试打开一个请求并让他们将其合并。

对于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
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),
}))
其中,
dictionary[0]
包含rgb图像的路径,
dictionary[1]
包含深度图像的路径

然后,必须按如下方式创建TFRecord:

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
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_dict[fields.InputDataFields.image_additional_channels]不可用 包括在输入中

我将为我的项目解决这个问题,所以我将尝试打开一个窗口 请求并让他们将其合并


我也想知道!我设法训练没有问题,但我不能使用训练过的模型,因为附加通道无法加载。。。你修好了吗?

哦,太好了,有人也在做这个。若你们可以分享你们的修正来进行推理,那个就太好了(我猜pull请求可能需要一段时间才能被接受)。在培训方面,对于TFRecord generation,我遵循以下原则。默认情况下,它会读取其他通道吗?你有没有检查过,在训练过程中,它实际上考虑了任何其他通道?你好,你实现了多通道模型吗?我也在尝试使用相同的教程来实现这一点,但由于API发生了变化,所以它无法正常工作。