caffe/conversion_utils.py
def save_lmdb(lmdb_file, output_dir, labels_file):
    """
    Saves the images in the lmdb file to output_dir. This method requires caffe to be installed.

    Parameters
    ----------
    lmdb_file: string
        Path to the input lmdb file
        
    output_dir: string
        Output directory for images (local filesystem)
    
    labels_file: string
        Output file (local filesystem) which saves the file names and associated labels. Format: 'output_file_path label'
    """
    lmdb_cursor = lmdb.open(lmdb_file, readonly=True).begin().cursor()
    datum = caffe.proto.caffe_pb2.Datum()
    i = 1
    with open(labels_file, 'w') as file:
        for _, value in lmdb_cursor:
            datum.ParseFromString(value)
            label = datum.label
            data = caffe.io.datum_to_array(datum)
            #data = np.transpose(data, (1,2,0))
            #data = np.rollaxis(data, 0,3)
            #s = StringIO()
            #s.write(datum.data)
            #s.seek(0)
            #PIL.Image.open(s).save(output_file_path, 'JPEG')
            #PIL.Image.open(PIL.Image.io.BytesIO(datum.data)).save(output_file_path, 'JPEG')
            output_file_path = os.path.join(output_dir, 'file_' + str(i) + '.jpg')
            file.write(output_file_path + ' ' + str(datum.label) + '\n')
            image = np.transpose(data, (1,2,0)) # CxHxW to HxWxC in cv2
            cv2.imwrite(output_file_path, image)
            i = i + 1

    Saves the images in the lmdb file to output_dir. This method requires caffe to be installed.

    Parameters
    ----------
    lmdb_file: string
        Path to the input lmdb file
        
    output_dir: string
        Output directory for images (local filesystem)
    
    labels_file: string
        Output file (local filesystem) which saves the file names and associated labels. Format: 'output_file_path label'
    
Saves the images in the lmdb file to output_dir. This method requires caffe to be installed.
Parameters

string
Path to the input lmdb file

string
Output directory for images (local filesystem)

string
Output file (local filesystem) which saves the file names and associated labels.
Saves the images in the lmdb file to output_dir . This method requires caffe to be installed . Parameters string Path to the input lmdb file string Output directory for images ( local filesystem ) string Output file ( local filesystem ) which saves the file names and associated labels .
def save_lmdb(lmdb_file, output_dir, labels_file):
    lmdb_cursor = lmdb.open(lmdb_file, readonly=True).begin().cursor()
    datum = caffe.proto.caffe_pb2.Datum()
    i = 1
    with open(labels_file, 'w') as file:
        for _, value in lmdb_cursor:
            datum.ParseFromString(value)
            label = datum.label
            data = caffe.io.datum_to_array(datum)
            output_file_path = os.path.join(output_dir, 'file_' + str(i) + '.jpg')
            file.write(output_file_path + ' ' + str(datum.label) + '\n')
            image = np.transpose(data, (1,2,0)) 
            cv2.imwrite(output_file_path, image)
            i = i + 1
def save_lmdb ( lmdb_file , output_dir , labels_file ) : lmdb_cursor = lmdb . open ( lmdb_file , readonly = True ) . begin ( ) . cursor ( ) datum = caffe . proto . caffe_pb2 . Datum ( ) i = 1 with open ( labels_file , 'w' ) as file : for _ , value in lmdb_cursor : datum . ParseFromString ( value ) label = datum . label data = caffe . io . datum_to_array ( datum ) output_file_path = os . path . join ( output_dir , 'file_' + str ( i ) + '.jpg' ) file . write ( output_file_path + ' ' + str ( datum . label ) + '\n' ) image = np . transpose ( data , ( 1 , 2 , 0 ) ) cv2 . imwrite ( output_file_path , image ) i = i + 1
Saves the images in the lmdb file to output_dir.
Saves the images in the lmdb file to output_dir .
"""
    Saves the images in the lmdb file to output_dir. This method requires caffe to be installed.

    Parameters
    ----------
    lmdb_file: string
        Path to the input lmdb file
        
    output_dir: string
        Output directory for images (local filesystem)
    
    labels_file: string
        Output file (local filesystem) which saves the file names and associated labels. Format: 'output_file_path label'
    """ #data = np.transpose(data, (1,2,0)) #data = np.rollaxis(data, 0,3) #s = StringIO() #s.write(datum.data) #s.seek(0) #PIL.Image.open(s).save(output_file_path, 'JPEG') #PIL.Image.open(PIL.Image.io.BytesIO(datum.data)).save(output_file_path, 'JPEG') # CxHxW to HxWxC in cv2
lmdb_file
output_dir
labels_file