Caffe: Reading LMDB from Python

前端 未结 2 1010
自闭症患者
自闭症患者 2020-12-13 15:23

I\'ve extracted features using caffe, which generates a .mdb file. Then I\'m trying to read it using Python and display it as a readable number.

import lmdb
         


        
2条回答
  •  一整个雨季
    2020-12-13 15:38

    Here's the working code I figured out

    import caffe
    import lmdb
    
    lmdb_env = lmdb.open('directory_containing_mdb')
    lmdb_txn = lmdb_env.begin()
    lmdb_cursor = lmdb_txn.cursor()
    datum = caffe.proto.caffe_pb2.Datum()
    
    for key, value in lmdb_cursor:
        datum.ParseFromString(value)
        label = datum.label
        data = caffe.io.datum_to_array(datum)
        for l, d in zip(label, data):
                print l, d
    

提交回复
热议问题