2

I am trying to generate the mean image from training data in caffe. My data is 256x256 grayscale images. I created lmdb by using create_imagenet.sh by replecing --shuffle with --gray.

I edited create_imagenet.sh as follows:

GLOG_logtostderr=1 $TOOLS/convert_imageset \
    --resize_height=$RESIZE_HEIGHT \
    --resize_width=$RESIZE_WIDTH \
    --gray \
    $TRAIN_DATA_ROOT \
    $DATA/train.txt \
    $EXAMPLE/train_lmdb

echo "Creating val lmdb..."

GLOG_logtostderr=1 $TOOLS/convert_imageset \
    --resize_height=$RESIZE_HEIGHT \
    --resize_width=$RESIZE_WIDTH \
    --gray \
    $VAL_DATA_ROOT \
    $DATA/val.txt \
    $EXAMPLE/val_lmdb

echo "Done."

But I am still getting error while creating mean image.

 /home/user1/caffe-master/build/tools/compute_image_mean -backend=lmdb /home/user1/input/train_lmdb /home/user1/input/train_mean.binaryproto

Here is the error:

    F0105 14:50:52.470038  2191 compute_image_mean.cpp:77] Check failed: size_in_datum == data_size (64000 vs. 65536) Incorrect data field size 64000
*** Check failure stack trace: ***
    @     0x7faa4978d5cd  google::LogMessage::Fail()
    @     0x7faa4978f433  google::LogMessage::SendToLog()
    @     0x7faa4978d15b  google::LogMessage::Flush()
    @     0x7faa4978fe1e  google::LogMessageFatal::~LogMessageFatal()
    @           0x402be1  main
    @     0x7faa486da830  __libc_start_main
    @           0x403249  _start
    @              (nil)  (unknown)
Aborted (core dumped)

Does anyone have any suggestion to tackle this error?

Your help is really appreciated.

S.EB
  • 1,966
  • 4
  • 29
  • 54
  • After creating LMDB by using `create_imagnet.sh` , I am still getting the error. why? – S.EB Jan 05 '17 at 12:39

1 Answers1

1

Make sure your images are 256X256, you must convert all the images into a same size before runing the net.

adding --gray to your LMDB will create your images as single-channel.

layer {
  name: "data"
  type: "Data"
  [...]
  transform_param {
    scale: 0.1
    mean_file_size: mean.binaryproto
    # for images in particular horizontal mirroring and random cropping
    # can be done as simple data augmentations.
    mirror: 1  # 1 = on, 0 = off
    # crop a `crop_size` x `crop_size` patch:
    # - at random during training
    # - from the center during testing
    crop_size: 256 # cropping your images
  }
}
Z.Kal
  • 426
  • 4
  • 18
  • Thanks for your reply. Could you please let me know how can I add this `--gray` parameters to LMDB? I have already generated the LMDB by [this code] (https://github.com/yawaterss/caffe-pascalcontext-fcn32s/blob/master/lmdb_data.py). I am a beginner in caffe, I do not know exactly what do you mean. Thank again. I was not successful to generate `mean.binaryproto` yet. – S.EB Jan 05 '17 at 09:53
  • try this [link](http://example.com). its how lmdb file created in imagenet. if my answer was helpful please mark it as correct (V). – Z.Kal Jan 05 '17 at 09:59
  • Sorry I am not able to open the link. it needs permission. – S.EB Jan 05 '17 at 10:13
  • try this: https://github.com/BVLC/caffe/blob/master/examples/imagenet/create_imagenet.sh – Z.Kal Jan 05 '17 at 10:15
  • Thanks for your help. May I ask whether I am adding `--gray` in a right place or not? `GLOG_logtostderr=1 $TOOLS/convert_imageset \ --resize_height=$RESIZE_HEIGHT \ --resize_width=$RESIZE_WIDTH \ --gray \ $TRAIN_DATA_ROOT \ $DATA/train.txt \ $EXAMPLE/ilsvrc12_train_lmdb` . I replaced with `shuffle` since I do not want to do shuffling. – S.EB Jan 05 '17 at 10:30
  • try it. or you can convert images color via python: `from PIL import Image img = Image.open('image.png').convert('LA') img.save('greyscale.png')` – Z.Kal Jan 05 '17 at 11:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/132397/discussion-between-s-eb-and-z-kal). – S.EB Jan 05 '17 at 12:25