Search code examples
image-processingcomputer-visioncaffe

Convert image as gray scale in IMAGE_DATA layer in caffe


I have IMAGE_DATA layer (old format), following layer reads image of depth 3. I need to keep the depth of the image as 1 (use as gray scale image).

Is there any parameter in IMAGE_DATA layer (old format) using which I can do the same ?

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
  }
}

Logs:

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)

All the input images are in gray scale:

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

Solution

  • Try adding 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
      }
    }