Tensorflow目标检测API 1通道图像

Tensorflow目标检测API 1通道图像,tensorflow,object-detection,depth,Tensorflow,Object Detection,Depth,在Tensorflow的对象检测API中,是否有任何方法可以使用针对RGB图像进行训练的预训练模型,用于单通道灰度图像(深度)?我尝试了以下方法,使用Tensorflow中的预训练模型(更快的rcnn\u resnet101\u coco\u 11\u 06\u 2017)对灰度(1通道图像)执行对象检测。它确实对我有用 该模型是在RGB图像上训练的,所以我只需要在Tensorflow Repo中修改某些代码 第一次更改: 请注意,ipynb中的现有代码是为3通道映像编写的,因此请将load_i

在Tensorflow的对象检测API中,是否有任何方法可以使用针对RGB图像进行训练的预训练模型,用于单通道灰度图像(深度)?

我尝试了以下方法,使用Tensorflow中的预训练模型(更快的rcnn\u resnet101\u coco\u 11\u 06\u 2017)对灰度(1通道图像)执行对象检测。它确实对我有用

该模型是在RGB图像上训练的,所以我只需要在Tensorflow Repo中修改某些代码

第一次更改: 请注意,ipynb中的现有代码是为3通道映像编写的,因此请将load_image_更改为_numpy数组函数,如图所示

第二次更改:灰度图像只有一个通道中的数据。要执行目标检测,我们需要3个通道(推理代码是为3个通道编写的)

这可以通过两种方式实现。 a) 将单通道数据复制到另外两个通道中 b) 用零填充其他两个通道。 这两种方法都可以,我使用了第一种方法

在ipynb中,转到读取图像并将其转换为numpy数组(ipynb末尾的forloop)的部分

将代码更改为:

for image_path in TEST_IMAGE_PATHS:
  image = Image.open(image_path)
  # the array based representation of the image will be used later in order to prepare the
  # result image with boxes and labels on it.
  image_np = load_image_into_numpy_array(image)
  # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
  image_np_expanded = np.expand_dims(image_np, axis=0)
为此:

for image_path in TEST_IMAGE_PATHS:
  image = Image.open(image_path)
  # the array based representation of the image will be used later in order to prepare the
  # result image with boxes and labels on it.
  image_np = load_image_into_numpy_array(image)
  if image_np.shape[2] != 3:  
      image_np = np.broadcast_to(image_np, (image_np.shape[0], image_np.shape[1], 3)).copy() # Duplicating the Content
      ## adding Zeros to other Channels
      ## This adds Red Color stuff in background -- not recommended 
      # z = np.zeros(image_np.shape[:-1] + (2,), dtype=image_np.dtype)
      # image_np = np.concatenate((image_np, z), axis=-1)
  # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
  image_np_expanded = np.expand_dims(image_np, axis=0)
就是这样,运行该文件,您应该会看到结果。 这是我的结果

for image_path in TEST_IMAGE_PATHS:
  image = Image.open(image_path)
  # the array based representation of the image will be used later in order to prepare the
  # result image with boxes and labels on it.
  image_np = load_image_into_numpy_array(image)
  # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
  image_np_expanded = np.expand_dims(image_np, axis=0)
for image_path in TEST_IMAGE_PATHS:
  image = Image.open(image_path)
  # the array based representation of the image will be used later in order to prepare the
  # result image with boxes and labels on it.
  image_np = load_image_into_numpy_array(image)
  if image_np.shape[2] != 3:  
      image_np = np.broadcast_to(image_np, (image_np.shape[0], image_np.shape[1], 3)).copy() # Duplicating the Content
      ## adding Zeros to other Channels
      ## This adds Red Color stuff in background -- not recommended 
      # z = np.zeros(image_np.shape[:-1] + (2,), dtype=image_np.dtype)
      # image_np = np.concatenate((image_np, z), axis=-1)
  # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
  image_np_expanded = np.expand_dims(image_np, axis=0)