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. php实现根据字符串生成对应数组的方法

    先看看如下示例: <?php $config = array( 'project|page|index' => 'content', 'project|page|nav' => ar ...

  2. Codechef July Challenge 2018 : Subway Ride

    传送门 首先(想了很久之后)注意到一个性质:同一条边有多种颜色的话保留3种就可以了,这是因为假如最优解要求当前位置与相邻两条边都不相同,那么只要有3条边,就肯定可以满足这一点. 完事就做一个nlogn ...

  3. CSS3_盒阴影_倒影_盒子大小可调

    1. 盒阴影 会产生一个或者多个阴影 使用:    (多个阴影,以逗号隔开) /* (不能为负值) (可以负值) */ /* 水平方向偏移量 垂直反向偏移量 模糊程度 扩散程度 颜色 是否是内阴影; ...

  4. [LeetCode] Max Increase to Keep City Skyline 保持城市天际线的最大增高

    In a 2 dimensional array grid, each value grid[i][j] represents the height of a building located the ...

  5. AJAX-快速上手(四个步骤)

    ## 1, ajax ajax是使用js进行在不重新加载页面的情况下,使得页面局部刷新.而传统的页面加载即需要,重新加载整个页面.它的加载是异步进行的,即在加载的同时,页面的其他部分可以正常使用,不会 ...

  6. Tomcat报错invalid LOC header

    原因: 可能是jar包有问题. 解决方法: 1.找到加载不了的类对应的jar包. 2.在tomcat中webapps/INF/lib中找到对应的jar包,然后删除. 3.重新下载其它版本的jar包. ...

  7. 如何查询注册表的值及 Powershell 应用

    利用 c:\windows\system32\reg.exe 的 query 参数即可. reg.exe 的参数如下: C:\windows\system32> reg.exe /?REG Op ...

  8. TCP/IP详解--拥塞控制 & 慢开始、拥塞避免、快重传和快恢复。

    https://www.cnblogs.com/losbyday/p/5847041.html 膜拜大佬,看完了就会

  9. WPF DataGrid分页功能实现代码

    在Silverlight中DataGrid分页可以结合DataPager控件很容易实现,但是在WPF中没有类似的,需要手动实现这样一个控件: 1.创建一个UserControl,DP.xaml,代码如 ...

  10. Node.js 开发

    Node.js不必介绍,已经太火爆了.简单说是用Javascript开发Web服务端,基于Google V8引擎,单线程.不多说从零开始Windows平台下的Node.js的开发之旅. 环境工具为先 ...