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. 马昕璐201771010118《面向对象程序设计(java)》第七周学习总结

    第一部分:理论知识学习部分 Java用于控制可见性的4个访问权限修饰符: 1.private(只有该类可以访问) 2.protected(该类及其子类的成员可以访问,同一个包中的类也可访问) 3.pu ...

  2. priority_queue和sort应用

    #include"iostream" #include"String" #include"stdio.h" #include "s ...

  3. linux 中数据库的常用操作

    1-连接数据库: mysql -h localhost -u jiangbiao -p xxxxx@xxx:~$ mysql -h localhost -u jiangbiao -p Enter pa ...

  4. Centos 7 上使用nginx为Node.js配置反向代理时错误:(13: Permission denied) while connecting to upstream

    错误来源:Centos 7 上使用nginx为Node.js配置反向代理时产生(13: Permission denied) while connecting to upstream的错误 nginx ...

  5. Python基础之列表深浅复制和列表推导式

    一.列表深浅复制: 浅拷贝内存图如下: 深拷贝内存图如下: 二.列表推导式: 实例: """ 列表推导式 练习:exercise01 """ ...

  6. (转载)CentOS6 Linux系统添加永久静态路由的方法

    https://blog.csdn.net/magerguo/article/details/49636231

  7. 【Python基础】lpthw - Exercise 40 模块、类和对象

    一. 模块(module) 模块中包含一些函数和变量,在其他程序中使用该模块的内容时,需要先将模块import进去,再使用.操作符获取函数或变量,如 # This goes in mystuff.py ...

  8. 使用 Canal 实现数据异构

    小结: 1. https://mp.weixin.qq.com/s/z-5aoGVuk7JzIGrJJWgeJw 使用 Canal 实现数据异构 原创: 杜亦舒 性能与架构 3月4日

  9. tableview Footerview有多余的间距

    调整footerView的高度 UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(, , Main_Screen_Width, )] ...

  10. SVN百度云服务器安装使用。

    安装SVN客户端 此时,必须重启,否则经常出现用不了. 重启后,还是用不了的话,那么就重新安装系统. 网站地址: http://xiaomosheng.bceapp.com/ SVN代码服务器的地址: ...