Search code examples
caffepycaffelmdbmatcaffe

Do I have to transpose my gray scale image while creating LMDB database?


I am converting a set of images and a set of ground truth images to LMDB database. The purpose is pixel-wise prediction. Most of the codes for creating LMDB from RGB images has a line indicating transpose in CxHxW order, as follows:

im = im.transpose((2,0,1)) # convert to CxHxW

My image data (both train data and corresponding ground truth images) are grayscale (i.e., single channel). My question is, what is the purpose of this line and should I do this matrix transpose for my single channel images and ground truth or it is not necessary?

Your help is appreciated.


Solution

  • Caffe processes images in BGR format instead of RGB. Since most pre-trained models on ImageNet are trained in BGR format, this operation (transpose) is applied by default. If you are training on grey scale images this is not needed. Moreover, even if you are training from scratch on RGB images, it is not necessary.