pickel加速caffe读图
64*64*3小图(12KB),batchSize=128,训练样本100万,
全部load进来内存受不了,load一次需要大半天
训练时读入一个batch,ali云服务器上每个batch读入时间1.9~3.2s不等,迭代一次2s多
由于有多个label不能用caffe自带的lmdb转了,输入是自己写的python层,试着用pickel
import os, sys
import cv2
import numpy as np
import numpy.random as npr
import cPickle as pickle
wk_dir = "/Users/xxx/wkspace/caffe_space/detection/caffe/data/1103reg64/"
InputSize = int(sys.argv[1])
BatchSize = int(sys.argv[2])
trainfile = "train.txt"
testfile = "test.txt"
print "gen imdb with for net input:", InputSize, "batchSize:", BatchSize with open(wk_dir+trainfile, 'r') as f:
trainlines = f.readlines()
with open(wk_dir+testfile, 'r') as f:
testlines = f.readlines()
#######################################
# we seperate train data by batchsize #
#######################################
to_dir = wk_dir + "/trainIMDB/"
if not os.path.isdir(to_dir):
os.makedirs(to_dir) train_list = []
cur_ = 0
sum_ = len(trainlines)
for line in trainlines:
cur_ += 1
words = line.split()
image_file_name = words[0]
im = cv2.imread(wk_dir + image_file_name)
h,w,ch = im.shape
if h!=InputSize or w!=InputSize:
im = cv2.resize(im,(InputSize,InputSize))
roi = [float(words[2]),float(words[3]),float(words[4]),float(words[5])]
train_list.append([im, roi])
if (cur_ % BatchSize == 0):
print "write batch:" , cur_/BatchSize
fid = open(to_dir +'train'+ str(BatchSize) + '_'+str(cur_/BatchSize),'w')
pickle.dump(train_list, fid)
fid.close()
train_list[:] = [] print len(train_list), "train data generated\n" ###########################
# tests #
###########################
to_dir = wk_dir + "/testIMDB/"
if not os.path.isdir(to_dir):
os.makedirs(to_dir)
test_list = []
cur_ = 0
sum_ = len(testlines)
for line in testlines:
cur_ += 1
words = line.split()
image_file_name = words[0]
im = cv2.imread(wk_dir + image_file_name)
h,w,ch = im.shape
if h!=InputSize or w!=InputSize:
im = cv2.resize(im,(InputSize,InputSize))
roi = [float(words[2]),float(words[3]),float(words[4]),float(words[5])]
test_list.append([im, roi]) if (cur_ % BatchSize == 0):
print "write batch:", cur_ / BatchSize
fid = open(to_dir +'test'+ str(BatchSize) + '_'+str(cur_/BatchSize), 'w')
pickle.dump(test_list, fid)
fid.close()
test_list[:] = []
print len(test_list), "test data generated\n"
每个batch生成4.8MB的块(约比128张原图占3倍磁盘空间):

训练时读入,ali云训练每个batch时间变为0.2s,可加速10倍
mac上是ssd硬盘,本来读图就很快,一个batch 0.05s, 改成pickel后反而变慢了,load一个batch需要0.2s。
pickel加速caffe读图的更多相关文章
- matlab读图函数
最基本的读图函数:imread imread函数的语法并不难,I=imread('D:\fyc-00_1-005.png');其中括号内写图片所在的完整路径(注意路径要用单引号括起来).I代表这个图片 ...
- LM_ReadImgMode.js PC单页轮播读图模式组件,零依赖!
LM_ReadImgMode.js PC单页轮播读图模式组件,零依赖! github:http://dtdxrk.github.io/LM-ReadImgMode/ TXT 1.全新的2.0版本,脱离 ...
- Windows下利用MKL加速caffe,与openblas比较
一.介绍:先简单Mark一下网上的介绍资料,弄清楚MKL是个啥,已经与openblas等的关系. 矩阵运算库blas, cblas, openblas, atlas, lapack, mkl之间有什么 ...
- [Caffe] ubuntu14.04下使用OpenBLAS加速Caffe
一.apt安装 sudo apt-get install libopenblas-dev 二.手动从source安装 1. 下载OpenBLAS并编译 git clone https://github ...
- kibana限制用户只具备读图的权限
假设需求 因为业务需要将日志系统收集到的信息进行图表化展示并交付到用户进行业务交流. 解决方案 这个需求看着似乎蛮简单的,如何解决? 1.对需要的数据进行过滤制作图表 2.对用户的权限限制为只读级别, ...
- C++ opencv高速样例学习——读图显示
1.关键函数 1. 读入图片 imread(图片或位置,显示格式)默觉得:IMREAD_COLOR 显示格式: IMREAD_UNCHANGED =-1 // 8bit, color or no ...
- 用python Image读图
https://www.cnblogs.com/kongzhagen/p/6295925.html import os name = [] with open('/media/hdc/xing/Dee ...
- TensorRT加速 ——NVIDIA终端AI芯片加速用,可以直接利用caffe或TensorFlow生成的模型来predict(inference)
官网:https://developer.nvidia.com/tensorrt 作用:NVIDIA TensorRT™ is a high-performance deep learning inf ...
- Caffe学习系列(21):caffe图形化操作工具digits的安装与运行
经过前面一系列的学习,我们基本上学会了如何在linux下运行caffe程序,也学会了如何用python接口进行数据及参数的可视化. 如果还没有学会的,请自行细细阅读: caffe学习系列:http:/ ...
随机推荐
- python-ironicclient使用
使用cli from ironicclient import client kwargs = {'os_username': 'ironic', 'os_password': 'IRONIC_PASS ...
- sqlite3使用总结(转并且修改)
此文来自http://blog.csdn.net/shengfang666/article/details/7937200,我在这儿重新发一下,备份参考. 前序:一. 版本二. ...
- laravel之模型操作
首先在App下创建模型,一个模型对应着一个表: 2.创建好模型之后,使用控制器来操作模型 先使用模型 创建方法来使用模型(记得要添加路由)
- 变量类型-List
教程:一:列表的创建 List(列表) 是 Python 中使用最频繁的数据类型.列表中元素的类型可以不相同,数字,字符串甚至可以包含列表(所谓嵌套) (1)List写在方括号之间,元素用逗号隔 ...
- Winform 关闭按钮
问题:我希望树形导航目录窗体在打开一条记录后自动隐藏,然后再次点击主页面打开按钮的时候在自动显示,这样就能保证树形目录仍旧显示隐藏前的展开状态.这里遇到一个问题,就是点击窗体右上角的关闭按钮时,默认情 ...
- linux安装zookeeper
安装环境:Linux:centos6.4Jdk:1.7以上版本 Zookeeper是java开发的可以运行在windows.linux环境.需要先安装jdk.安装步骤:第一步:安装jdk第二步:把zo ...
- pycharm 的 激活流程
激活流程 一.通过Activation code 方式激活 注册码获取地址为:http://idea.lanyus.com/ 在idea或者pycharm的Activation code中输入 注册码 ...
- 微信开发基于springboot
0.申请一个微信公众号,记住他的appId,secret,token,accesstoken 1.创建一个springboot项目.在pom文件里面导入微信开发工具类 <dependency&g ...
- IP,IP地址,mac地址
IP地址与IP是两个不同的概念.单独讲IP,是指IP协议 IP地址分为三类:单播地址(目的为单个主机):多播地址(目的端为同一组的所有主机):广播地址(目的端为网络上所有给定的主机) ip地址由网络和 ...
- No fallback instance of type class found for feign client user-service(转)
1.错误日志 在 feign 开启熔断,配置 fallback 类,实现当前接口的实现类时,报错信息如下: Error starting ApplicationContext. To display ...