caffe Python API 之卷积层(Convolution)
1、Convolution层:
就是卷积层,是卷积神经网络(CNN)的核心层。
层类型:Convolution
lr_mult: 学习率的系数,最终的学习率是这个数乘以solver.prototxt配置文件中的base_lr。如果有两个lr_mult, 则第一个表示权值的学习率,第二个表示偏置项的学习率。一般偏置项的学习率是权值学习率的两倍。
在后面的convolution_param中,我们可以设定卷积层的特有参数。
必须设置的参数:
num_output: 卷积核(filter)的个数
kernel_size: 卷积核的大小。如果卷积核的长和宽不等,需要用kernel_h和kernel_w分别设定
其它参数:
stride: 卷积核的步长,默认为1。也可以用stride_h和stride_w来设置。
pad: 扩充边缘,默认为0,不扩充。 扩充的时候是左右、上下对称的,比如卷积核的大小为5*5,那么pad设置为2,则四个边缘都扩充2个像素,即宽度和高度都扩充了4个像素,这样卷积运算之后的特征图就不会变小。也可以通过pad_h和pad_w来分别设定。
net.conv1 = caffe.layers.Convolution(
net.data,
param=[{"lr_mult": 1, "decay_mult": 1}, {"lr_mult": 2, "decay_mult": 1}], #lr_mult: 学习率的系数,最终的学习率是这个数乘以solver.prototxt配置文件中的base_lr。
#如果有两个lr_mult, 则第一个表示权值的学习率,第二个表示偏置项的学习率。一般偏置项的学习率是权值学习率的两倍。
name="Conv1",
kernel_size=3,
stride=1,
pad=1,
num_output=20,
group=2,
weight_filler=dict(type='xavier'),
bias_filler=dict(type='constant',value=0)) 输出:
layer {
name: "Conv1"
type: "Convolution"
bottom: "data"
top: "conv1"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 1
}
convolution_param {
num_output: 20
pad: 1
kernel_size: 3
group: 2
stride: 1
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
}
}
形式二:
net.conv2 = caffe.layers.Convolution(
net.data,
param=[{"lr_mult": 1, "decay_mult": 1}, {"lr_mult": 2, "decay_mult": 1}],
name="Conv2",
convolution_param=dict(
kernel_size=3,
stride=1,
pad=1,
num_output=20,
group=2,
weight_filler=dict(type='xavier'),
bias_filler=dict(type='constant',value=0))
) 输出相同:
layer {
name: "Conv2"
type: "Convolution"
bottom: "data"
top: "conv2"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 1
}
convolution_param {
num_output: 20
pad: 1
kernel_size: 3
group: 2
stride: 1
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
value: 0
}
}
}
caffe Python API 之卷积层(Convolution)的更多相关文章
- caffe Python API 之上卷积层(Deconvolution)
对于convolution: output = (input + 2 * p - k) / s + 1; 对于deconvolution: output = (input - 1) * s + k ...
- caffe Python API 之可视化
一.显示各层 # params显示:layer名,w,b for layer_name, param in net.params.items(): print layer_name + '\t' + ...
- caffe Python API 之 数据输入层(Data,ImageData,HDF5Data)
import sys sys.path.append('/projects/caffe-ssd/python') import caffe4 net = caffe.NetSpec() 一.Image ...
- caffe Python API 之激活函数ReLU
import sys import os sys.path.append("/projects/caffe-ssd/python") import caffe net = caff ...
- caffe Python API 之图片预处理
# 设定图片的shape格式为网络data层格式 transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape}) ...
- caffe Python API 之中值转换
# 编写一个函数,将二进制的均值转换为python的均值 def convert_mean(binMean,npyMean): blob = caffe.proto.caffe_pb2.BlobPro ...
- caffe Python API 之BatchNormal
net.bn = caffe.layers.BatchNorm( net.conv1, batch_norm_param=dict( moving_average_fraction=0.90, #滑动 ...
- caffe Python API 之Inference
#以SSD的检测测试为例 def detetion(image_dir,weight,deploy,resolution=300): caffe.set_mode_gpu() net = caffe. ...
- caffe Python API 之Model训练
# 训练设置 # 使用GPU caffe.set_device(gpu_id) # 若不设置,默认为0 caffe.set_mode_gpu() # 使用CPU caffe.set_mode_cpu( ...
随机推荐
- java.util.Stack类简介(栈)
Stack是一个后进先出(last in first out,LIFO)的堆栈,在Vector类的基础上扩展5个方法而来 Deque(双端队列)比起stack具有更好的完整性和一致性,应该被优先使用 ...
- jq的$.each遍历数组
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- JavaScript中的函数与栈
Javascript中会经常用到setTimeout来推迟一个函数的执行,如: setTimeout(function(){ alert("Hello World"); },100 ...
- Codeforces Round #342 (Div. 2) A
A. Guest From the Past time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Leetcode 94. 二叉树的中序遍历
1.问题描述 给定一个二叉树,返回它的中序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? 2.解法一 ...
- POJ 2976 二分
Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12515 Accepted: 4387 D ...
- 线程池 ------ linux C实现
大多数的网络服务器,包括Web服务器都具有一个特点,就是单位时间内必须处理数目巨大的连接请求,但是处理时间却是比较短的.在传统的多线程服务器模型中是这样实现的:一旦有个请求到达,就创建一个新的线程,由 ...
- File file:/data1/hadoop/yarn/local/usercache/hp/appcache/application_* does not exi
AM Container for appattempt_1453292851883_0381_000002 exited with exitCode: -1000For more detailed o ...
- 使用tcpdump监控网络消息发送
tcpdump是一个用于截取网络分组,并输出分组内容的工具,简单说就是数据包抓包工具.tcpdump凭借强大的功能和灵活的截取策略,使其成为Linux系统下用于网络分析和问题排查的首选工具. tcpd ...
- linux环境下,接着lnmp,安装redis
linux环境下,安装redis 操作记录: 回到家目录 cd ~查看 ls进入 lump cd lnmp1.3-fullls??? sudo ./addons.sh //---进入后选 ...