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:/ ...
随机推荐
- JS对象1
1 String对象 字符串创建 (1) 直接创建 var s="hello"; console.log(s); console.log(typeof s) >> he ...
- 转 Using Async for File Access
原文:https://msdn.microsoft.com/en-us/library/jj155757.aspx using System; using System.Collections.Gen ...
- CSS3_元素拖曳原理_设置全局点击捕获_九宫格碰撞检测_自定义滚动条
拖曳原理: 元素的初始位置 + 鼠标距离差 = 元素最终位置 使元素可以拖动 function dragElement(obj){ obj.onmousedown = function(e){ e = ...
- 关于*.ashx 处理程序调试时 未能创建类型 错误
出现改问题的根本原因是因为,我更改过改类型的名字,而IDE并没有更改 ***.ashx. 注册类型名字. 所更改的类的名字应该是 "项目名字.文件名字“ 例如下图 应该更改类为 ”Wx_ ...
- Solve Error: MissingSchemaError: Schema hasn't been registered for model "YourModel".
使用MongoDB的时候,如果遇到下面这个错误: /home/ec2-user/YourProject/node_modules/mongoose/lib/index.js: throw new mo ...
- 安装Percona版本的MySQL主从复制
准备两台虚拟机,按顺序执行1.1节的公共部分 1.1 首先安装 cmake # yum –y install cmake //也需要安装gcc-c++,openssl openssl-deve ...
- Docker ElK安装部署使用教程
一.简介 1.核心组成 ELK由Elasticsearch.Logstash和Kibana三部分组件组成: Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引 ...
- Linux_相关命令(学习,备忘)
1.Linux 查看实时cpu使用率: top 说明:top命令即时显示process的动态 2.查看cpu处理器使用率: cat /proc/stat 3.平均cpu使用率 4.赋予文件夹下所有文件 ...
- F#周报2019年第14期
新闻 发布F# 4.6 SAFE Stack v1.0 发布fable编译器2.2,Fable.Core 3及其它 发布ML.NET 1.0 RC Saturn:增加路由诊断页面 Visual Stu ...
- 邮局 100分代码(dfs+多重剪枝)
蓝桥杯真题-邮局 #include<iostream> #include<algorithm> #include<set> #include<string&g ...