Can we use caffe for other image formats like .pgm?

1,056 views
Skip to first unread message

Sateesh Babu G

unread,
May 11, 2015, 4:37:24 AM5/11/15
to caffe...@googlegroups.com
Can we use caffe for other image formats like .pgm?

Ashwani Rai

unread,
May 12, 2015, 5:10:54 AM5/12/15
to caffe...@googlegroups.com
Yes. I've used it with .ppm

Sateesh Babu G

unread,
May 12, 2015, 5:35:06 AM5/12/15
to caffe...@googlegroups.com
@ Ashwani Rai Could you please describe the procedure to use caffe for .ppm images for classification ?

Ashwani Rai

unread,
May 12, 2015, 5:39:10 AM5/12/15
to caffe...@googlegroups.com
Nothing special, same as jpeg example.

Sateesh Babu G

unread,
May 12, 2015, 7:11:10 AM5/12/15
to caffe...@googlegroups.com
@ Ashwani Rai, How to use caffe for gray scale images like .pgm format?

Michael Wilber

unread,
May 12, 2015, 8:42:46 AM5/12/15
to caffe...@googlegroups.com
Caffe's convert_imageset tool uses OpenCV to read images, and the list of supported image formats is documented here: http://docs.opencv.org/3.0-beta/modules/imgcodecs/doc/reading_and_writing_images.html#Mat imread(const String& filename, int flags) 


  • Windows bitmaps - *.bmp, *.dib (always supported)
  • JPEG files - *.jpeg, *.jpg, *.jpe (see the Notes section)
  • JPEG 2000 files - *.jp2 (see the Notes section)
  • Portable Network Graphics - *.png (see the Notes section)
  • WebP - *.webp (see the Notes section)
  • Portable image format - *.pbm, *.pgm, *.ppm (always supported)
  • Sun rasters - *.sr, *.ras (always supported)
  • TIFF files - *.tiff, *.tif (see the Notes section)

If it doesn't work, you can also use the special "ImageMagick" preprocessing layer :) Run "convert imagename.ppm imagename.png" with ImageMagick installed before feeding them through converge_imageset.

Sateesh Babu G

unread,
May 12, 2015, 10:38:03 PM5/12/15
to caffe...@googlegroups.com
@ Michael Wilber, Thanks for your confirmation. I am new to Caffe, Could you please list procedure to train and classify gray scale images using Caffe.

Ashwani Rai

unread,
May 12, 2015, 10:39:59 PM5/12/15
to caffe...@googlegroups.com
@Sateesh Just follow the example provided on classification on the caffe page. It is the same procedure for gray scale as well.  

Sateesh Babu G

unread,
May 12, 2015, 11:27:20 PM5/12/15
to caffe...@googlegroups.com
@Ashwani Rai, Thanks for your response. I have followed the procedure described by dennis-chen in the post https://github.com/BVLC/caffe/issues/550

In create_imagenet.sh, I have passed --gray into convert_imageset as follow:

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

In deploy.prototext, I have used input dimensions as follow:

name: "CaffeNet"
input: "data"
input_dim: 10
input_dim: 1
input_dim: 227
input_dim: 227


Finally in the python classifier wrapper, I am creating network as follow:

net = caffe.Classifier(MODEL_FILE, PRETRAINED, 
              mean = np.load('out.npy').mean(1).mean(1),
      raw_scale=255,
      image_dims=(256,256))

But still it is not working, all images are classified into one class.

Sateesh Babu G

unread,
May 13, 2015, 10:42:18 PM5/13/15
to caffe...@googlegroups.com
Please can anyone explain me the procedure for gray scale images classification using Caffe. I have followed the below procedure but no success.

 I have followed the procedure described by dennis-chen in the post https://github.com/BVLC/caffe/issues/550

In create_imagenet.sh, I have passed --gray into convert_imageset as follow:

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

In deploy.prototext, I have used input dimensions as follow:

name: "CaffeNet"
input: "data"
input_dim: 10
input_dim: 1
input_dim: 227
input_dim: 227


Finally in the python classifier wrapper, I am creating network as follow:

net = caffe.Classifier(MODEL_FILE, PRETRAINED, 
               mean = np.load('out.npy').mean(1).mean(1),
       raw_scale=255,
       image_dims=(256,256))

But still it is not working, all images are classified into one class.

Thanks in advance!!!!!!!
Reply all
Reply to author
Forward
0 new messages