在 caffe 的 IMAGE_DATA 图层中将图像转换为灰度

Convert image as gray scale in IMAGE_DATA layer in caffe

我有 IMAGE_DATA 层(旧格式),下一层读取深度为 3 的图像。我需要将图像的深度保持为 1(用作灰度图像)。

IMAGE_DATA 图层(旧格式)中是否有我可以使用的任何参数?

layers {
  name: "data"
  type: IMAGE_DATA
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  image_data_param {
    source: "train.txt"
    batch_size: 100
    new_height: 28
    new_width: 28
  }
}

日志:

I0329 12:20:12.253433 17261 net.cpp:98] Setting up data
I0329 12:20:12.253439 17261 image_data_layer.cpp:34] Opening file train.txt
I0329 12:20:12.284766 17261 image_data_layer.cpp:49] A total of 60000 images.
I0329 12:20:12.287030 17261 image_data_layer.cpp:78] output data size: 100,3,28,28
I0329 12:20:12.287175 17261 net.cpp:105] Top shape: 100 3 28 28 (235200)
I0329 12:20:12.287185 17261 net.cpp:105] Top shape: 100 1 1 1 (100)

所有输入图像均为灰度:

$file 30751.png
30751.png: PNG image data, 28 x 28, 8-bit grayscale, non-interlaced

尝试添加 is_color: false:

layers {
  name: "data"
  type: IMAGE_DATA
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  image_data_param {
    source: "train.txt"
    batch_size: 100
    new_height: 28
    new_width: 28
    is_color: false  # force gray scale images
  }
}