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

时间:2018-03-29 06:48:05

标签: 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

1 个答案:

答案 0 :(得分:1)

尝试添加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
  }
}