Convert images to LMDB | Implementing FCN for semantic segmentation.

1,019 views
Skip to first unread message

Abhilash Panigrahi

unread,
Nov 17, 2015, 6:27:12 AM11/17/15
to Caffe Users
I'm trying to create a LMDB database for using with FCN-8 with my own custom data The following two codes are for Images and Labels respectively. Can someone please verify, if it is correct? I am not getting the right result using this data.

train1.txt and trainLabel1.txt are text files with location of all images.

Convert Images of 3x512x640

import caffe
import lmdb
from PIL import Image
import numpy as np
np.set_printoptions(threshold=np.nan)

with open('data/images/train1.txt') as T:
        lines = T.readlines()

in_db = lmdb.open('train1lmdb', map_size=int(1e12))
with in_db.begin(write=True) as in_txn:
        for in_idx, in_ in enumerate(lines):
                im = np.array(Image.open(in_[:-1])) # or load whatever ndarray you need
                im = im[:,:,::-1]
                im = im.transpose((2,0,1))
                print im.shape
                im_dat = caffe.io.array_to_datum(im)
                in_txn.put('{:0>10d}'.format(in_idx), im_dat.SerializeToString())
in_db.close()

For labels of 1x512x640

import caffe
import lmdb
from PIL import Image
import numpy as np
np.set_printoptions(threshold=np.nan)

with open('data/labeled/trainLabel1.txt') as T:
        lines = T.readlines()

in_db = lmdb.open('label1lmdb', map_size=int(1e12))
with in_db.begin(write=True) as in_txn:
        for in_idx, in_ in enumerate(lines):
                im = np.array(Image.open(in_[:-1])) # or load whatever ndarray you need
                #im = im[:,:,::-1]
                #im = im.transpose((2,0,1))
                im = np.expand_dims(im, axis=0)
                print im.shape
                im_dat = caffe.io.array_to_datum(im)
                in_txn.put('{:0>10d}'.format(in_idx), im_dat.SerializeToString())
#print im
in_db.close()


Somehow, the output after training the net is wrong. I feel the mistake is in this operation.

Sameer Khan

unread,
May 26, 2016, 6:15:26 AM5/26/16
to Caffe Users

Hi Abhilash will you please let me know how i can train fcn own my own data, As of now i have two classes with label names skull and skull stripped how can i make the lmdb of labels.

Mina Rezaei

unread,
Oct 7, 2016, 6:29:47 AM10/7/16
to Caffe Users
Dear Abhilash

I have same problem for my data preparation, I am not sure about lmdb format, how did you arrange instance and classes?

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