Mean-image computation looks random

793 views
Skip to first unread message

Alykhan Tejani

unread,
Dec 22, 2014, 6:22:38 AM12/22/14
to caffe...@googlegroups.com
Hi guys,

I'm very new to Caffe and am trying to train a network on my own data, just to work from the ground up I wanted to view the mean image computed by the compute_image binary that is shipped with Caffe. I am displaying it with the following python:

import caffe
import numpy as np
import sys
import png
from PIL import Image

if len(sys.argv) != 3:
  print "Usage: python convert_protomean.py proto.mean out.png"
  sys.exit()

blob = caffe.proto.caffe_pb2.BlobProto()
data = open( sys.argv[1] , 'rb' ).read()
blob.ParseFromString(data)
arr = np.array( caffe.io.blobproto_to_array(blob) )
out = arr[0]
print(out.shape)
img = Image.fromarray(out.T, 'RGB')

img.save(sys.argv[2])

However, the image looked like fairly random noise (which could be the case as the dataset is large).

So, just to test I decided to create the mean image from a single image (it should be that same image, correct?)

So I created a directory 'tmp_test' and put one image in there 'apple-0.jpg'.

I created a lmdb dataset using the following command (with the convert_imageset script)

GLOG_logtostderr=1 $TOOLS/convert_imageset \
    --resize_height=256 \
    --resize_width=256 \
    --shuffle \
    --backend=lmdb \
    $TRAIN_DATA_ROOT \
    $DATA/train.txt \
    $EXAMPLE/tmp_train_lmdb

which appeared to correctly create the database of 1 image.

I then computed the image mean with the following:

./build/tools/compute_image_mean tmp_test/tmp_train_lmdb \
 tmp_test/tmp_mean.binaryproto

I then viewed the file and have attached the input image ('apple-0.jpg') and the mean images




Am I doing something wrong?

Thanks,
Aly

Alykhan Tejani

unread,
Dec 22, 2014, 9:26:50 AM12/22/14
to caffe...@googlegroups.com
Fixed this (almost)

The problem was in the display script I have added lines in bold for anyone else who is stuck on this

import caffe
import numpy as np
import sys
import png
from PIL import Image

if len(sys.argv) != 3:
  print "Usage: python convert_protomean.py proto.mean out.png"
  sys.exit()

blob = caffe.proto.caffe_pb2.BlobProto()
data = open( sys.argv[1] , 'rb' ).read()
blob.ParseFromString(data)
arr = np.array( caffe.io.blobproto_to_array(blob) )
out = arr[0]
out = np.ascontiguousarray(out.transpose(1,2,0))
out = out.astype(np.uint8)
img = Image.fromarray(out, 'RGB')

img.save(sys.argv[2])

Alykhan Tejani

unread,
Dec 22, 2014, 9:27:37 AM12/22/14
to caffe...@googlegroups.com
The only issue now is the red and blue channels are flipped, but this is not such a big deal
Reply all
Reply to author
Forward
0 new messages