How to set data as gray image ( 8bit 256)?

2,045 views
Skip to first unread message

ZhongShan HU

unread,
Jun 15, 2015, 7:33:51 PM6/15/15
to caffe...@googlegroups.com
we create a image data to train the caffe net .  all the image are converted to gray jpeg format. In deploy stage , we find we should set channel =3 (inputdim :1 , 3, 100, 100) to get correct shape. 
It seems that  although we use gray jpg in training , the caffe net still treat the data as color image( channel =3) , is it possible to set the input data as gray image ? How?

Ilya Zhenin

unread,
Jun 16, 2015, 6:26:31 AM6/16/15
to caffe...@googlegroups.com
Making my own training process from 0 on MNIST data I found out that if we want train on gray images we should make LMDB set using tool convert_images with flag "--gray=True". Or make LMDB on your own but store them as 1 channel images I suppose.

вторник, 16 июня 2015 г., 2:33:51 UTC+3 пользователь ZhongShan HU написал:

ZhongShan HU

unread,
Jun 17, 2015, 7:23:20 PM6/17/15
to caffe...@googlegroups.com
Thanks llya, I will try this method.

Shehroz Khan

unread,
Jun 18, 2015, 2:13:58 PM6/18/15
to caffe...@googlegroups.com
Can we not just write this in the prototxt file like this
name: "LeNet"
input: "data"
input_dim: 64 // batch size
input_dim: 1 // number of channels (3 for RGB)
input_dim: 28 // height
input_dim: 28 // width

Floris Gaisser

unread,
Jun 18, 2015, 9:58:29 PM6/18/15
to caffe...@googlegroups.com
If you load images into the network with the image_data layer, you should set the is_color image_layer_param to false.
Example:
layer {
  name: "image_data"
  type: "ImageData"
  top: "data"
  top: "lable"
  include {
    phase: TRAIN
  }
  transform_param {
    scale: 0.00390625
  }
  image_data_param {
    source: "[file]"
    root_folder: ""
    batch_size: 100
    is_color: false
    shuffle: false
  }
}

In the case of MNIST is a different story, as the MNIST data is SIGNED. Thus has negative values, that are truncated when saved into images without scaling the data.

In the case where you convert images into a database (like leveldb or lmdb) setting an option to load it in grayscale is of great importance.
Reply all
Reply to author
Forward
0 new messages