【Caffe篇】--Caffe从入门到初始及各层介绍
一、前述
Caffe,全称Convolutional Architecture for Fast Feature Embedding。是一种常用的深度学习框架,主要应用在视频、图像处理方面的应用上。caffe是一个清晰,可读性高,快速的深度学习框架。作者是贾扬清,加州大学伯克利的ph.D,现就职于Facebook。caffe的官网是http://caffe.berkeleyvision.org/。
二、具体
1、输入层
layer {
name: "cifar"
type: "Data"
top: "data" #一般用bottom表示输入,top表示输出,多个top代表有多个输出
top: "label"
include {
phase: TRAIN #训练网络分为训练阶段和自测试阶段,如果没写include则表示该层即在测试中,又在训练中
}
transform_param {
mean_file: "examples/cifar10/mean.binaryproto" #用一个配置文件来进行均值的操作
transform_param {
scale: 0.00390625
mirror: 1 # 1表示开启镜像,0表示关闭,也可用ture和false来表示
# 剪裁一个 227*227的图块,在训练阶段随机剪裁,在测试阶段从中间裁剪
crop_size: 227
}
}
data_param {
source: "examples/cifar10/cifar10_train_lmdb" #数据库来源
batch_size: 64 #每次批处理的个数
backend: LMDB #选用数据的名称
}
} ### 使用LMDB源
layer {
name: "mnist"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
scale: 0.00390625
}
data_param {
source: "examples/mnist/mnist_train_lmdb"
batch_size: 64
backend: LMDB
}
} ###使用HDF5数据源
layer {
name: "data"
type: "HDF5Data"
top: "data"
top: "label"
hdf5_data_param {
source: "examples/hdf5_classification/data/train.txt"
batch_size: 10
}
} ###数据直接来源与图片
#/path/to/images/img3423.jpg 2
#/path/to/images/img3424.jpg 13
#/path/to/images/img3425.jpg 8 layer {
name: "data"
type: "ImageData" #类型
top: "data"
top: "label"
transform_param {
mirror: false
crop_size: 227
mean_file: "data/ilsvrc12/imagenet_mean.binaryproto"
}
image_data_param {
source: "examples/_temp/file_list.txt"
batch_size: 50
new_height: 256 #如果设置就对图片进行resize操作
new_width: 256
}
}
2、卷积层
layer {
name: "conv1" #定义一个名字 必须指定的
type: "Convolution"
bottom: "data"#前面连接的层 data层
top: "conv1"#输出是卷积层
param {
lr_mult: 1 #lr_mult: #当前层的学习率 学习率的系数,最终的学习率是这个数乘以solver.prototxt配置文件中的base_lr。如果有两个lr_mult, 则第一个表示权值的学习率,第二个表示偏置项的学习率。一般偏置项的学习率是权值学习率的两倍。
}
param {
lr_mult: 2
}
convolution_param {
num_output: 20 #卷积核(filter)的个数等于特征图的个数
kernel_size: 5 #卷积核的大小 5*5*d 中的d是上一层的深度
stride: 1 #卷积核的步长,默认为1
pad: 0 #扩充边缘,默认为0,不扩充
weight_filler {
type: "xavier" #权值初始化。 默认为“constant",值全为0,很多时候我们用"xavier"算法来进行初始化,也可以设置为”gaussian"
}
bias_filler {
type: "constant" #偏置项的初始化。一般设置为"constant",值全为0
}
}
} 输入:n*c0*w0*h0
输出:n*c1*w1*h1
其中,c1就是参数中的num_output,生成的特征图个数
w1=(w0+2*pad-kernel_size)/stride+1;
h1=(h0+2*pad-kernel_size)/stride+1; 结论: 假设输入时h*w k是kernel_size p 是padding s是stride则
特征图 的输出的h是多大的 (h-k+2p)/s+1
w是(w-k+2p)/s+1
3、池化层
layer {
name: "pool1"
type: "Pooling"
bottom: "conv1"
top: "pool1"
pooling_param {
pool: MAX #池化方法,默认为MAX。目前可用的方法有MAX, AVE
kernel_size: 3 #池化的核大小
stride: 2 #池化的步长,默认为1。一般我们设置为2,即不重叠。
}
} #pooling层的运算方法基本是和卷积层是一样的。
4、激活函数层
#在激活层中,对输入数据进行激活操作,是逐元素进行运算的,在运算过程中,没有改变数据的大小,即输入和输出的数据大小是相等的。 ###Sigmoid layer {
name: "test"
bottom: "conv"
top: "test"
type: "Sigmoid"
} #ReLU是目前使用最多的激活函数,主要因为其收敛更快,并且能保持同样效果。标准的ReLU函数为max(x, 0),当x>0时,输出x; 当x<=0时,输出0
f(x)=max(x,0) layer {
name: "relu1"
type: "ReLU"
bottom: "pool1"
top: "pool1"
}
5、全连接层
#全连接层,输出的是一个简单向量 参数跟卷积层一样
layer {
name: "ip1"
type: "InnerProduct"
bottom: "pool2"
top: "ip1"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 500
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
#测试的时候输入准确率
layer {
name: "accuracy"
type: "Accuracy"
bottom: "ip2"#两个输入一个输入是分类结果
bottom: "label"#另一个输入是label
top: "accuracy"
include {
phase: TEST
}
}
6、softmax_layer
#softmax-loss layer:输出loss值 对于softmax 得到损失函数 -logp p为正确的分类的概率
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip1"
bottom: "label"
top: "loss"
} #softmax layer: 输出似然值 得到每一个类别的概率值
layers {
bottom: "cls3_fc"
top: "prob"
name: "prob"
type: “Softmax"
}
7、reshape层
#在不改变数据的情况下,改变输入的维度 layer {
name: "reshape"
type: "Reshape"
bottom: "input"
top: "output"
reshape_param {
shape {
dim: 0 # copy the dimension from below
dim: 2
dim: 3
dim: -1 # infer it from the other dimensions
}
}
} 有一个可选的参数组shape, 用于指定blob数据的各维的值(blob是一个四维的数据:n*c*w*h)。 dim:0 表示维度不变,即输入和输出是相同的维度。 dim:2 或 dim:3 将原来的维度变成2或3 dim:-1 表示由系统自动计算维度。数据的总量不变,系统会根据blob数据的其它三维来自动计算当前维的维度值 。 假设原数据为:32*3*28*28, 表示32张3通道的28*28的彩色图片
shape {
dim: 0 #表示不变
dim: 0
dim: 14
dim: -1 #表示自动推断
}
输出数据为:32*3*14*56 #Dropout是一个防止过拟合的层
#只需要设置一个dropout_ratio就可以了。
layer {
name: "drop7"
type: "Dropout"
bottom: "fc7-conv"
top: "fc7-conv"
dropout_param {
dropout_ratio: 0.5
}
}
【Caffe篇】--Caffe从入门到初始及各层介绍的更多相关文章
- 推荐csdn里的几篇activiti基础入门及提高的博客
昨天有个网友加qq询问我有没有非maven搭建的activiti项目的demo,因为我博客中写了一个用maven,我当时没有,于是晚上回家尝试了一下,结果比较容易就实现了. 之后和那个网友聊了一下,他 ...
- RabbitMQ学习总结 第二篇:快速入门HelloWorld
目录 RabbitMQ学习总结 第一篇:理论篇 RabbitMQ学习总结 第二篇:快速入门HelloWorld RabbitMQ学习总结 第三篇:工作队列Work Queue RabbitMQ学习总结 ...
- caffe编译环境的错误:..build_release/src/caffe/proto/caffe.pb.h:23:35: fatal error: google/protobuf/arena.h: 没有那个文件
在搭建caffe的环境时出现错误: .build_release/src/caffe/proto/caffe.pb.h:23:35: fatal error: google/protobuf/aren ...
- Python之路,第一篇:Python入门与基础
第一篇:Python入门与基础 1,什么是python? Python 是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. 2,python的特征: (1)易于学习,易于利用: (2)开 ...
- caffe/blob.hpp:9:34: fatal error: caffe/proto/caffe.pb.h: 没有那个文件或目录
You need to generate caffe.pb.h manually using protoc as follows. # In the directory you installed C ...
- caffe/proto/caffe.pb.h: No such file or director
caffe编译过程中遇到的为问题: fatal error: caffe/proto/caffe.pb.h: No such file or directory 解决方法: 用protoc从caffe ...
- 【caffe】Caffe的Python接口-官方教程-01-learning-Lenet-详细说明(含代码)
01-learning-Lenet, 主要讲的是 如何用python写一个Lenet,以及用来对手写体数据进行分类(Mnist).从此教程可以知道如何用python写prototxt,知道如何单步训练 ...
- 【caffe】Caffe的Python接口-官方教程-00-classification-详细说明(含代码)
00-classification 主要讲的是如何利用caffenet(与Alex-net稍稍不同的模型)对一张图片进行分类(基于imagenet的1000个类别) 先说说教程到底在哪(反正我是找了半 ...
- caffe.bin caffe的框架
最近打算看一看caffe实现的源码,因为发现好多工作都是基于改动网络来实现自己的的目的.比如变更目标函数以及网络结构,以实现图片风格转化或者达到更好的效果. 深度学习框架 https://mp.wei ...
随机推荐
- RabbitMQ (四) 路由选择 (Routing)
上一篇博客我们建立了一个简单的日志系统,我们能够广播日志消息给所有你的接收者,如果你不了解,请查看:RabbitMQ (三) 发布/订阅.本篇博客我们准备给日志系统添加新的特性,让日志接收者能够订阅部 ...
- 跟我学ASP.NET MVC之六:SportsStrore添加产品目录导航
摘要: 上一篇文章,我建立了SportsStore应用程序的核心架构.现在我将使用这个架构向这个应用程序添加功能,你将开始看到这个基础架构的作用.我将添加重要的面向客户的简单功能,在这个过程中,你将看 ...
- System.out.println()
System是java.lang中的类,out为System中的一个静态数据成员,out是java.io.PrintStream类的对象,而println()是java.io.PrintStream类 ...
- timeCache.go
package blog4go import ( "sync" "time" ) const ( // PrefixTimeFormat 时间格式前缀 Pre ...
- BZOJ_2142_礼物_扩展lucas+组合数取模+CRT
BZOJ_2142_礼物_扩展lucas+组合数取模 Description 一年一度的圣诞节快要来到了.每年的圣诞节小E都会收到许多礼物,当然他也会送出许多礼物.不同的人物在小E 心目中的重要性不同 ...
- BZOJ_1833_[ZJOI2010]count 数字计数_数位DP
BZOJ_1833_[ZJOI2010]count 数字计数_数位DP 题意: 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. 分析: 数位DP f[i][ ...
- 常用 Linux 命令的基本使用
常用 Linux 命令的基本使用 操作系统 作用:管理好硬件设备,让软件可以和硬件发生交互类型 桌面操作系统 Windows macos linux 服务器操作系统 linux Windows ser ...
- set的便捷操作
认识集合 由一个或多个确定的元素所构成的整体叫做集合. 集合中的元素有三个特征: 1.确定性(集合中的元素必须是确定的) 2.互异性(集合中的元素互不相同.例如:集合A={1,a},则a不能等于1) ...
- Flask导入静态文件问题
然而如果使用flask开发web,并且需要在本地导入已经写好的css js 文件或者image一系列,这些文件是静态文件,需要另外建一个文件夹static;并且在html文件修改导入方法,exampl ...
- 在.NET Core中使用Exceptionless分布式日志收集框架
一.Exceptionless简介 Exceptionless 是一个开源的实时的日志收集框架,它可以应用在基于 ASP.NET,ASP.NET Core,Web Api,Web Forms,WPF, ...