码迷,mamicode.com
首页 > 数据库 > 详细

caffe使用python创建lmdb

时间:2015-11-23 23:38:31      阅读:1350      评论:0      收藏:0      [点我收藏+]

标签:

 1 import numpy as np
 2 import sys
 3 from PIL import Image
 4 import lmdb
 5 import random
 6 import os
 7 
 8 sys.path.append(../caffe/python/)
 9 
10 import caffe
11 
12 if __name__ == __main__ :
13     train_list_file = ./trainlist.txt
14     train_images_root = ./train/images/
15 
16     f = open(train_list_file, r)
17     trainlist = f.readlines()
18     f.close()
19 
20     random.shuffle(trainlist)
21 
22     # creating images lmdb
23     in_db = lmdb.open(my-train-data-lmdb, map_size=int(1e12))
24     with in_db.begin(write=True) as in_txn :
25         for in_idx, in_ in enumerate(trainlist) :
26             fid = in_.strip()
27             fn = os.path.join(train_images_root, fid)
28             im = np.array(Image.open(fn))
29             im = im[:,:,::-1]
30             im = im.transpose((2, 0, 1))
31             im_dat = caffe.io.array_to_datum(im)
32             in_txn.put({:0>10d}.format(in_idx), im_dat.SerializeToString())
33     in_db.close()

 

caffe使用python创建lmdb

标签:

原文地址:http://www.cnblogs.com/leemo-o/p/4990021.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!