激活函数(relu,prelu,elu,+BN)对比on cifar10

Lrelu实现:
def lrelu(x, leak=0.2, name="lrelu"):
return tf.maximum(x, leak * x) Prelu实现:
def parametric_relu(_x):
alphas = tf.get_variable('alpha', _x.get_shape()[-1],
initializer=tf.constant_initializer(0.25),
dtype = tf.float32
)
pos = tf.nn.relu(_x)
neg = alphas * (_x - abs(_x)) * 0.5
print(alphas)
return pos + neg BN实现:
def batch_norm(x, n_out,scope='bn'):
"""
Batch normalization on convolutional maps.
Args:
x: Tensor, 4D BHWD input maps
n_out: integer, depth of input maps
phase_train: boolean tf.Variable, true indicates training phase
scope: string, variable scope Return:
normed: batch-normalized maps
"""
with tf.variable_scope(scope):
beta = tf.Variable(tf.constant(0.0, shape=[n_out]),
name='beta', trainable=True)
gamma = tf.Variable(tf.constant(1.0, shape=[n_out]),
name='gamma', trainable=True)
tf.add_to_collection('biases', beta)
tf.add_to_collection('weights', gamma) batch_mean, batch_var = tf.nn.moments(x, [0,1,2], name='moments')
ema = tf.train.ExponentialMovingAverage(decay=0.99) def mean_var_with_update():
ema_apply_op = ema.apply([batch_mean, batch_var])
with tf.control_dependencies([ema_apply_op]):
return tf.identity(batch_mean), tf.identity(batch_var)
#mean, var = control_flow_ops.cond(phase_train,
# mean, var = control_flow_ops.cond(phase_train,
# mean_var_with_update,
# lambda: (ema.average(batch_mean), ema.average(batch_var)))
mean, var = mean_var_with_update()
normed = tf.nn.batch_normalization(x, mean, var,
beta, gamma, 1e-3)
return normed




解压:tar -zxvf xxx.tar.gz
cifar-100-python/
cifar-100-python/file.txt~
cifar-100-python/train
cifar-100-python/test
cifar-100-python/meta
def unpickle(file):
import cPickle
fo = open(file, ‘rb’)
dict = cPickle.load(fo)
fo.close()
return dict
label_bytes =2 # 2 for CIFAR-100
#取第二个标签100维
result.label = tf.cast(
tf.strided_slice(record_bytes, [1], [label_bytes]), tf.int32)
https://towardsdatascience.com/activation-functions-neural-networks-1cbd9f8d91d6
激活函数(relu,prelu,elu,+BN)对比on cifar10的更多相关文章
- 激活函数ReLU、Leaky ReLU、PReLU和RReLU
“激活函数”能分成两类——“饱和激活函数”和“非饱和激活函数”. sigmoid和tanh是“饱和激活函数”,而ReLU及其变体则是“非饱和激活函数”.使用“非饱和激活函数”的优势在于两点: 1 ...
- [转]激活函数ReLU、Leaky ReLU、PReLU和RReLU
“激活函数”能分成两类——“饱和激活函数”和“非饱和激活函数”. sigmoid和tanh是“饱和激活函数”,而ReLU及其变体则是“非饱和激活函数”.使用“非饱和激活函数”的优势在于两点: 1 ...
- 激活函数(ReLU, Swish, Maxout)
神经网络中使用激活函数来加入非线性因素,提高模型的表达能力. ReLU(Rectified Linear Unit,修正线性单元) 形式如下: \[ \begin{equation} f(x)= \b ...
- 【机器学习】激活函数(ReLU, Swish, Maxout)
https://blog.csdn.net/ChenVast/article/details/81382939 神经网络中使用激活函数来加入非线性因素,提高模型的表达能力. ReLU(Rectifie ...
- ReLU 和sigmoid 函数对比
详细对比请查看:http://www.zhihu.com/question/29021768/answer/43517930 . 激活函数的作用: 是为了增加神经网络模型的非线性.否则你想想,没有激活 ...
- ReLU 和sigmoid 函数对比以及droupout
参考知乎的讨论:https://www.zhihu.com/question/29021768 1.计算简单,反向传播时涉及除法,sigmod求导要比Relu复杂: 2.对于深层网络,sigmod反向 ...
- caffe Python API 之激活函数ReLU
import sys import os sys.path.append("/projects/caffe-ssd/python") import caffe net = caff ...
- Difference between ReLU、LReLU、PReLU、CReLU、ELU、SELU
激活函数 ReLU.LReLU.PReLU.CReLU.ELU.SELU 的定义和区别 ReLU tensorflow中:tf.nn.relu(features, name=None) LReLU ...
- 神经网络中的激活函数具体是什么?为什么ReLu要好过于tanh和sigmoid function?(转)
为什么引入激活函数? 如果不用激励函数(其实相当于激励函数是f(x) = x),在这种情况下你每一层输出都是上层输入的线性函数,很容易验证,无论你神经网络有多少层,输出都是输入的线性组合,与没有隐藏层 ...
随机推荐
- php语法分析
php的语法分析的主要作用是验证词法分析的基础上将token组成的序列,在php这门语言中是否是一个有效的句子,也可以理解为这些token序列是否匹配设计php这门语言时的语法模型,在匹配的情况下构建 ...
- 【xsy1611】 数位dp 数位dp
这题是显然的数位$dp$,然而我居然写了一个下午!!! 我们不难想到差分,令$solve(x,y)$表示从第一个数字在区间$[0,x]$,第二个数字在区间$[0,y]$的答案. 不难发现题目中给了你一 ...
- 关于防止表单form重复提交的方式
表单重复提交: 1.第一种:添加以后刷新页面(刷新的是Servlet) 2.第二种:重复点击提交按钮. * 使用令牌机制:(防止表单重复提交) * 在表单页面中 生成一个令牌 * 将这个令牌保存在se ...
- 分析org.rpgpoet.Music.wizards.length
例子如下: package bazola; public class Gabriel { static int n = org.rpgpoet.Music.wizards.length; } pack ...
- SearchView去掉下划线
SearchView calSearchView = (SearchView) findViewById(R.id.sv_search_text); if (calSearchView != null ...
- linux下清空c++ cin无效流的方式
cin.clear(); cin.ignore(10000,'\n');//这里面的参数很重要
- MySQL decimal unsigned 更新负数不报错却为0
今天在验证接口的并发问题时,把之前通过 redis 解决的并发压力转移到 mysql 上(redis 在 set 保存数据和数据过期需要去向数据库获取时存在时延,会存在空挡造成大并发多插入数据的风险: ...
- Linux-(ps,grep)
grep命令 1.命令格式: grep [option] pattern file 2.命令功能: 用于过滤/搜索的特定字符.可使用正则表达式能多种命令配合使用,使用上十分灵活. Linux系统中gr ...
- linux 查找删除找定文件
find . -name "*.lastUpdated" -exec rm -rf {} \; 这个命令是find的基本用法,可以分两部分,find ~/ -name " ...
- nginx 学习笔记(1) nginx安装
1.nginx安装 根据操作系统的不同,nginx的安装方式也不相同. 1.1 对linux系统来说,nginx.org提供了nginx安装包.http://nginx.org/en/linux_pa ...