个人实践代码如下:

 #!/usr/bin/env sh
# Compute the mean image from the imagenet training lmdb
# N.B. this is available in data/ilsvrc12 EXAMPLE=/home/wp/CAFFE/caffe-master/myself/00b
DATA=/home/wp/CAFFE/caffe-master/myself/00b
TOOLS=build/tools $TOOLS/compute_image_mean $EXAMPLE/00b_train_lmdb \
$DATA/00bmean.binaryproto echo "Done." # cd CAFFE/caffe-master
# sh ./myself/00b/make_00b_mean.sh

参考一:
图片减去均值再训练,会提高训练速度和精度。因此,一般都会有这个操作。

caffe程序提供了一个计算均值的文件compute_image_mean.cpp,我们直接使用就可以了

# sudo build/tools/compute_image_mean examples/myfile/img_train_lmdb examples/myfile/mean.binaryproto
compute_image_mean带两个参数,第一个参数是lmdb训练数据位置,第二个参数设定均值文件的名字及保存路径。 
运行成功后,会在 examples/myfile/ 下面生成一个mean.binaryproto的均值文件。 参考二:

接着,计算均值,打开make_imagenet_mean.sh,修改:

#!/usr/bin/env sh
# Compute the mean image from the imagenet training lmdb
# N.B. this is available in data/ilsvrc12 EXAMPLE=examples/imagenet
DATA=examples/imagenet
TOOLS=build/tools $TOOLS/compute_image_mean $EXAMPLE/mydata_train_lmdb \ #改成你的lmdb
$DATA/mydata_mean.binaryproto #生成的均值文件名,可修改 echo "Done."

这样,均值文件就计算好了。

参考三:

关于均值文件

(1) 在Caffe中作classification时经常需要使用均值文件,但是caffe自己提供的脚本只能将图像数据转换为 binaryproto类似的形式 (2) 我们在使用python接口时需要将npy形式的均值文件导入进来,而非binaryproto这样的均值文件

均值文件形式之间的转换

google类以下发现可以使用如下的代码进行转换: 代码是我自己实际使用的,有注释

import PIL
import Image
import sys
import time
import os
import numpy as np
from matplotlib import pyplot as plt start = time.time() # Make sure that caffe is on the python path
caffe_root = '/home/gavinzhou/caffe-master/'
sys.path.insert(0, caffe_root + 'python') import caffe
# "source" is the binary file converted by the command shell
# "des" is the binary file with python format converted from "source"
source = caffe_root + 'gavinzhou_LAB/alexnet/GF18_mean.binaryproto'
des = caffe_root + 'gavinzhou_LAB/alexnet/GF18_mean.npy' # BlobProto object
blob = caffe.proto.caffe_pb2.BlobProto()
data = open( source , 'rb' ).read()
# parsing source data
blob.ParseFromString(data)
# convert to npy format
arr = np.array( caffe.io.blobproto_to_array(blob) )
out = arr[0]
# save the converted result
np.save( des , out )

实际测试时,验证数据集使用binaryproto形式的均值文件和测试数据集使用npy形式的均值文件时,

正确率基本一样(差异很小但是还是验证集合稍高)

8.caffe:make_mean.sh( 数据平均化 )的更多相关文章

  1. 6.caffe:create_txt.sh(数据预处理成txt文本文件)

    #!/usr/bin/env sh DATA=/home/wp/CAFFE/caffe-master/myself/00b MY=/home/wp/CAFFE/caffe-master/myself/ ...

  2. caffe添加python数据层

    caffe添加python数据层(ImageData) 在caffe中添加自定义层时,必须要实现这四个函数,在C++中是(LayerSetUp,Reshape,Forward_cpu,Backward ...

  3. 5.caffe:train.sh 和 test.sh (训练与测试 )

    一,train.sh #!/usr/bin/env sh ./build/tools/caffe train --solver=myself/00b/solver.prototxt # cd CAFF ...

  4. caffe中关于数据进行预处理的方式

    caffe的数据层layer中再载入数据时,会先要对数据进行预处理.一般处理的方式有两种: 1. 使用均值处理 transform_param { mirror: true crop_size: me ...

  5. 总结一下用caffe跑图片数据的研究流程

    近期在用caffe玩一些数据集,这些数据集是从淘宝爬下来的图片.主要是想研究一下对女性衣服的分类. 以下是一些详细的操作流程,这里总结一下. 1 爬取数据.写爬虫从淘宝爬取自己须要的数据. 2 数据预 ...

  6. caffe 中 python 数据层

    caffe中大多数层用C++写成. 但是对于自己数据的输入要写对应的输入层,比如你要去图像中的一部分,不能用LMDB,或者你的label 需要特殊的标记. 这时候就需要用python 写一个输入层. ...

  7. 使用caffe的HDF5数据完毕回归任务

    一直在研究怎样用caffe做行人检測问题.然而參考那些经典结构比方faster-rcnn等,都是自己定义的caffe层来完毕的检測任务. 这些都要求对caffe框架有一定程度的了解.近期看到了怎样用c ...

  8. caffe parse_log.sh

    画loss曲线需要用到此shell脚本 #!/bin/bash # Usage parse_log.sh caffe.log # It creates the following two text f ...

  9. 【撸码caffe 五】数据层搭建

    caffe.cpp中的train函数内声明了一个类型为Solver类的智能指针solver: // Train / Finetune a model. int train() { -- shared_ ...

随机推荐

  1. 关于antd form表单getFieldsError方法

    getFieldsError()方法其实只有required:true时,双向数据绑定. {getFieldDecorator('note', { rules: [{ required: true, ...

  2. 我是如何提高工作效率的-工具篇(一)-Clover

    痛点: 还在为资源管理器窗口切来切去烦恼吗? 效果图: 实现工具:Clover 放个链接 链接:https://pan.baidu.com/s/1UiUQZtE99fMNDe1f2gOnlg   提取 ...

  3. java 中 this 和 super 说明及在构造器中super()和this()相互调用执行顺序

    this this 表示当前对象 使用上细分的话,this有 this. 和this()的使用情况 ,下面我们开始细撸 this . 使用场景一: 在成员方法中,this.变量名 指带当前对象的变量, ...

  4. [Kevin英语情报局]那些年我们说过的中式英语

    一. blonde hair 金色头发 grey hair 白头发 baijiu 白酒 white wine 白葡萄酒 I don't think it's right 我认为不正确 I'm chin ...

  5. C#实现自动刷新网页

    需要的童鞋可以下载整个项目:http://pan.baidu.com/s/1geMADvP 运行效果图如下:

  6. .Net WebApi接口之Swagger集成详解

    本文详细的介绍了.net从一个新的项目中创建api后集成swagger调试接口的流程! 1.首先我们创建一个MVC项目(VS2012): 2.然后在项目中的Controllers文件夹中添加API接口 ...

  7. 第一次git到GitHub过程

    首先在GitHub上创建一个仓库

  8. 洛谷 题解 P2502 【[HAOI2006]旅行】

    由于此题边数比较小,所以可以先给边排个序,然后跑m遍最小生成树,每跑一次删除一条边,找最优解. 防TLE技巧 把边按从小到大的顺序排好,那么只要当前无法联通,那么后面也无法联通 最优解找法 doubl ...

  9. zotero入门简介

    文献管理工具必备的功能:word文档中插入文献引用,自动生成参考文献列表. 支持系统:windows, linux, macOS. 费用:免费提供300M以内文献库存储容量. 其他:支持笔记,条目附件 ...

  10. centos7yum的配置

    首先呢,本人的centos的版本是7.5 这里我主要介绍的是通过挂在系统镜像文件和指定网络epel镜像源. 首先指定本地的光盘当做yum的仓库 1.删除/etc/yum.repos.d的所有文件 2. ...