8.caffe:make_mean.sh( 数据平均化 )
个人实践代码如下:
#!/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( 数据平均化 )的更多相关文章
- 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/ ...
- caffe添加python数据层
caffe添加python数据层(ImageData) 在caffe中添加自定义层时,必须要实现这四个函数,在C++中是(LayerSetUp,Reshape,Forward_cpu,Backward ...
- 5.caffe:train.sh 和 test.sh (训练与测试 )
一,train.sh #!/usr/bin/env sh ./build/tools/caffe train --solver=myself/00b/solver.prototxt # cd CAFF ...
- caffe中关于数据进行预处理的方式
caffe的数据层layer中再载入数据时,会先要对数据进行预处理.一般处理的方式有两种: 1. 使用均值处理 transform_param { mirror: true crop_size: me ...
- 总结一下用caffe跑图片数据的研究流程
近期在用caffe玩一些数据集,这些数据集是从淘宝爬下来的图片.主要是想研究一下对女性衣服的分类. 以下是一些详细的操作流程,这里总结一下. 1 爬取数据.写爬虫从淘宝爬取自己须要的数据. 2 数据预 ...
- caffe 中 python 数据层
caffe中大多数层用C++写成. 但是对于自己数据的输入要写对应的输入层,比如你要去图像中的一部分,不能用LMDB,或者你的label 需要特殊的标记. 这时候就需要用python 写一个输入层. ...
- 使用caffe的HDF5数据完毕回归任务
一直在研究怎样用caffe做行人检測问题.然而參考那些经典结构比方faster-rcnn等,都是自己定义的caffe层来完毕的检測任务. 这些都要求对caffe框架有一定程度的了解.近期看到了怎样用c ...
- caffe parse_log.sh
画loss曲线需要用到此shell脚本 #!/bin/bash # Usage parse_log.sh caffe.log # It creates the following two text f ...
- 【撸码caffe 五】数据层搭建
caffe.cpp中的train函数内声明了一个类型为Solver类的智能指针solver: // Train / Finetune a model. int train() { -- shared_ ...
随机推荐
- text matching(文本匹配) 相关资料总结
最近工作上需要做句子语义去重相关的工作,本质上这是属于NLP中text matching(文本匹配)相关的内容.因此我花了一些时间整理了一些关于这个方向的资料,整理如下(也许会持续更新): BiMPM ...
- Python学习笔记——GUI
1. 相关文档 EasyGui 官网:http://easygui.sourceforge.net 官方的教学文档:easygui-docs-0.96\tutorial\index.html 小甲鱼翻 ...
- springboot datajpa 简明说明
findById返回Optional的使用 查询 public Object lookupDevice(Integer id) { return deviceJpa.findById(id).orEl ...
- mysql的密码规则问题
今天在设置mysql某用户的密码时,出现了此报错: ERROR 1819 (HY000) Your password does not satisfy the current policy req ...
- yum源 epel源 替换及安装
#!/bin/sh # 备份yum源 zip -r /etc/yum.repos.d/yum_resource_back_up.zip /etc/yum.repos.d/* # 替换yum源 wget ...
- 自定义的C4P数据库连接池
要想自己写一个数据库连接池 需要实现DataSoure这个类,然后重写getConnection 这个方法 public class C4p0 implements DataSource{ priva ...
- IDEA插件之JProfiler
1.是什么?来用干嘛的? 一个商业授权的Java剖析工具. 用来剖析程序内存.CPU使用情况,找到性能瓶颈,快速定位问题所在. 2.IDEA安装JProfiler插件 (1)File -> Se ...
- 【洛谷】P4202 [NOI2008]奥运物流
[洛谷]P4202 [NOI2008]奥运物流 感觉有点降智 首先设环长为\(len\),很容易推导出 \[ R(1) = \frac{\sum_{i = 1}^{N} C_{i} k^{dep[i] ...
- 创建安全的 Netty 程序
1.使用 SSL/TLS 创建安全的 Netty 程序 SSL 和 TLS 是众所周知的标准和分层的协议,它们可以确保数据时私有的 Netty提供了SSLHandler对网络数据进行加密 使用Http ...
- NOIP(CSP)答题技巧&小细节
1.主函数类型 通常使用int main(),然而可以使用完全等价的signed main() 解锁 #define int long long 的操作 2.long long 的使用 数列长度/边 ...