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.