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读图的更多相关文章

  1. matlab读图函数

    最基本的读图函数:imread imread函数的语法并不难,I=imread('D:\fyc-00_1-005.png');其中括号内写图片所在的完整路径(注意路径要用单引号括起来).I代表这个图片 ...

  2. LM_ReadImgMode.js PC单页轮播读图模式组件,零依赖!

    LM_ReadImgMode.js PC单页轮播读图模式组件,零依赖! github:http://dtdxrk.github.io/LM-ReadImgMode/ TXT 1.全新的2.0版本,脱离 ...

  3. Windows下利用MKL加速caffe,与openblas比较

    一.介绍:先简单Mark一下网上的介绍资料,弄清楚MKL是个啥,已经与openblas等的关系. 矩阵运算库blas, cblas, openblas, atlas, lapack, mkl之间有什么 ...

  4. [Caffe] ubuntu14.04下使用OpenBLAS加速Caffe

    一.apt安装 sudo apt-get install libopenblas-dev 二.手动从source安装 1. 下载OpenBLAS并编译 git clone https://github ...

  5. kibana限制用户只具备读图的权限

    假设需求 因为业务需要将日志系统收集到的信息进行图表化展示并交付到用户进行业务交流. 解决方案 这个需求看着似乎蛮简单的,如何解决? 1.对需要的数据进行过滤制作图表 2.对用户的权限限制为只读级别, ...

  6. C++ opencv高速样例学习——读图显示

    1.关键函数 1. 读入图片 imread(图片或位置,显示格式)默觉得:IMREAD_COLOR 显示格式: IMREAD_UNCHANGED =-1    // 8bit, color or no ...

  7. 用python Image读图

    https://www.cnblogs.com/kongzhagen/p/6295925.html import os name = [] with open('/media/hdc/xing/Dee ...

  8. TensorRT加速 ——NVIDIA终端AI芯片加速用,可以直接利用caffe或TensorFlow生成的模型来predict(inference)

    官网:https://developer.nvidia.com/tensorrt 作用:NVIDIA TensorRT™ is a high-performance deep learning inf ...

  9. Caffe学习系列(21):caffe图形化操作工具digits的安装与运行

    经过前面一系列的学习,我们基本上学会了如何在linux下运行caffe程序,也学会了如何用python接口进行数据及参数的可视化. 如果还没有学会的,请自行细细阅读: caffe学习系列:http:/ ...

随机推荐

  1. 2017-2018 Northwestern European Regional Contest (NWERC 2017)

    A. Ascending Photo 贪心增广. #include<bits/stdc++.h> using namespace std; const int MAXN = 1000000 ...

  2. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第5章编程练习7

    #include <iostream>#include <cstring>const MAXSIZE=100;using namespace std;int main (){  ...

  3. Buffer --缓冲器

    一. 启动Buffer缓冲器 node 输入 buffer 创建一个新的buffer var buf = new buffer(''hello word) 查看buf的长度 buf.length 运行 ...

  4. bootstrap_栅格系统_响应式工具_源码分析

    -----------------------------------------------------------------------------margin 为负 ​使盒子重叠 ​等高 等高 ...

  5. Lecture3.随机变量及其概率分布

    1.随机变量的定义 2.随机变量的类型: 若随机变量X的可能取值是有限个或可列个, 则称X为离散型随机变量. 反之,则称X为非离散型随机变量. 若随机变量X的可能取值“连续”(“不间断”),则称X 为 ...

  6. HBuilder

    什么是HBuilder? HBbuilder是DCloud(数字天堂)推出的一款支持HTML5的WEB开发IDE,主体是由java编写的,它将HTML/JS代码块进行代码封装,达到简单数据形成代码的特 ...

  7. dynamic 类型不能访问属性

    x //解决方案ProjectTest.项目A里面public object r(){ ,name = "zf"}; } //解决方案ProjectTest.项目B里面 publi ...

  8. ETL数据采集方法

    1.触发器方式 触发器方式是普遍采取的一种增量抽取机制.该方式是根据抽取要求,在要被抽取的源表上建立插入.修改.删除3个触发器,每当源表中的数据发生变化,就被相应的触发器将变化的数据写入一个增量日志表 ...

  9. awk命令使用经验

    1.为什么要使用awk 举一个简单的例子,作为一个java开发人员,在查看日志服务器(即时保存所有线上环境的日志)上的日志的时候,由于部署了服务的服务器不止一台,当想要查找某一个特定信息的时候,由于不 ...

  10. python练习题-day26

    #bim(property) class People: def __init__(self,name,weight,height): self.name=name self.weight=weigh ...