caffe的lmdb資料讀取
阿新 • • 發佈:2018-12-31
import lmdb
import caffe
if __name__ == '__main__':
lmdb_path=r'./DeepID2_train_lmdb'
#open lmdb
lmdb_env = lmdb.open(lmdb_path)
#begin transaction
lmdb_txn = lmdb_env.begin()
#get cursor
lmdb_cursor = lmdb_txn.cursor()
#get data object
datum = caffe.proto.caffe_pb2.Datum()
idx = 0
min_val = 1000000
max_val = -1
label_dict = {}
for key, value in lmdb_cursor:
#parse back to datum
datum.ParseFromString(value)
#get y value
label = datum.label
label_dict[label] =1
if int(label) > max_val:
max_val = int(label)
if int(label) < min_val:
min_val = int(label)
if label != 0:
continue
print('key = '+key+' label = ' + str(label))
idx += 1
#if idx >30:
# break
print('max_val:'+str(max_val))
print('min_val:'+str(min_val))
print(len(label_dict))
for i in range(max_val):
if i not in label_dict:
print(i)
lmdb_env.close()