Sorry for confusion. I have pillow in my package list. Imported as
from PIL import Image

I also tried with python 2.7 version to load lmdb as caffe uses python 2.7 but no affect.
I tried to load the data without lmdb just with image name and label as list by overriding getitem function. But it is horribly slow. Thats why I tried to load lmdb. Will raise issue of loading dataset as list in separate chain.
But I am still unable to figure out why
Image.open(buf). fails

I printed the
print('The buffer information :',len(imgbuf),index,self.keys[index])

It prints correctly the Key. Problem is with IO buffering. Tried to use OpenCV and the error goes away but it has problem further down the chain.
 with env.begin(write=False) as txn:
        imgbuf = txn.get(self.keys[index])
        print('The buffer information :',len(imgbuf),index,self.keys[index])
    import cv2
    import numpy
    img = cv2.imdecode(
    numpy.fromstring(imgbuf, dtype=numpy.uint8), 1)