I am getting error with caffe.io.array_to_datum() for single channel images, how to solve?

42 views
Skip to first unread message

Sara Caffe

unread,
Jan 3, 2017, 4:35:56 AM1/3/17
to Caffe Users
I am trying to convert a set of grayscale images and ground truth images to LMDB for segmentation task. I have created 4 text files (train.txttrain_label.txtval.txtval_label.txt) indicating path to each image in each folder. For many days, it is taking my time and still I am not successful. I am a beginner in python and caffe I will be thankful if somebody helps me here. I tried the attached code. 
After commenting
  im = im.transpose((2,0,1)) # convert to CxHxW   
I am still getting error:
Creating Training Data LMDB File ..... 
0 /home/user2/caffe-pascalcontext-fcn32s/dataset/Train/PNG/image-001-001.png
(281, 389)
(1, 281, 389)
Traceback (most recent call last):
  File "lmdb_data.py", line 104, in <module>
    img_to_lmdb(train_img_paths, train_img_lmdb)
  File "lmdb_data.py", line 46, in img_to_lmdb
    im_dat = caffe.io.array_to_datum(im)
  File "/home/user2/caffe-master/python/caffe/io.py", line 78, in array_to_datum
    datum.float_data.extend(arr.flat)
  File "/home/user2/anaconda2/envs/caffeenv/lib/python2.7/site-packages/google/protobuf/internal/containers.py", line 275, in extend
    new_values = [self._type_checker.CheckValue(elem) for elem in elem_seq_iter]
  File "/home/user2/anaconda2/envs/caffeenv/lib/python2.7/site-packages/google/protobuf/internal/type_checkers.py", line 108, in CheckValue
    raise TypeError(message)
TypeError: 66 has type <type 'numpy.int32'>, but expected one of: ((<type 'float'>, <type 'int'>, <type 'long'>),)

  1. How can I fix this error?
  2. How can I convert these four image sets into LMDB?
  3. Is it possible I use convert_imageset (Caffe built-in converter) for this task? If yes, please let me know how can I do that?

Your help is really appreciated.


lmdb_data.py

Przemek D

unread,
Jan 3, 2017, 5:51:19 AM1/3/17
to Caffe Users
The error seems to mean that you load data as int32 while LMDB backend expects a different type. Try converting to int by astype function, for example change line 36 in your attached script to:
im = np.array(Image.open(in_)).astype(np.int)
Reply all
Reply to author
Forward
0 new messages