TensorFlow实现的激活函数可视化
书上的代码:
# coding: utf-8 # In[1]: import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from pylab import * # In[19]: def show_activation(activation,y_lim=5):
x=np.arange(-10., 10., 0.01)
ts_x = tf.Variable(x)
ts_y =activation(ts_x )
with tf.Session() as sess:
init = tf.global_variables_initializer()
sess.run(init)
y=sess.run(ts_y)
ax = gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.spines['bottom'].set_position(('data',0))
ax.spines['left'].set_position(('data',0))
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
lines=plt.plot(x,y)
plt.setp(lines, color='b', linewidth=3.0)
plt.ylim(y_lim*-1-0.1,y_lim+0.1)
plt.xlim(-10,10) plt.show() # In[20]: show_activation(tf.nn.sigmoid,y_lim=1) # In[4]: show_activation(tf.nn.softsign,y_lim=1) # In[5]: show_activation(tf.nn.tanh,y_lim=1) # In[6]: show_activation(tf.nn.relu,y_lim=10) # In[7]: show_activation(tf.nn.softplus,y_lim=10) # In[8]: show_activation(tf.nn.elu,y_lim=10) # In[14]: a = tf.constant([[1.0,2.0],[1.0,2.0],[1.0,2.0]])
sess = tf.Session()
print(sess.run(tf.sigmoid(a))) # In[ ]:
sigmoid激活函数:
S(x)=1/(1+e-x)

优点在于输出映射在0-1内,单调连续,适合做输出层,求导容易。
缺点在于软饱和性,即当x趋于无穷大时,一阶导数趋于0,容易产生梯度消失,神经网络的改善缓慢或消失。
softsign激活函数:

tanh激活函数:
tanh(x)=(1-e-2x)/(1+e-2x)

也具有软饱和性,收敛速度比sigmoid快,但是仍无法解决梯度消失的问题。
relu激活函数:
f(x)=max(x,0)

缺点:当relu在x<0时硬饱和,即在负半轴,激活函数的一阶导数等于0。
优点:由于x>0时导数为1,所以relu能在正半轴保持梯度的不衰减,缓解梯度消失的问题。
但是随着训练的进行,部分落入硬饱和区,权重无法更新。
softplus激活函数:
relu的平滑版本f(x)=log(1+exp(x))

此外还有的激活函数如下数张图:


等等..............................................................................................
......................................................................................................
输入数据特征相差明显时,tanh效果较好,不明显时,sigmoid较好。二者在使用时需要对输入进行规范化,减少进入平坦区的可能。
relu是比较流行的激活函数,不需要输入量的规范化等...
TensorFlow实现的激活函数可视化的更多相关文章
- Tensorboard教程:Tensorflow命名空间与计算图可视化
Tensorflow命名空间与计算图可视化 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 强烈推荐Tensorflow实战Google深度学习框架 实验平台: Tensorflow ...
- 吴裕雄 python 神经网络——TensorFlow 训练过程的可视化 TensorBoard的应用
#训练过程的可视化 ,TensorBoard的应用 #导入模块并下载数据集 import tensorflow as tf from tensorflow.examples.tutorials.mni ...
- tensorflow(3)可视化,日志,调试
可视化 添加变量 tf.summary.histogram( "weights1", weights1) # 可视化观看变量 还有添加图像和音频. 常量 tf.summary.sc ...
- Tensorflow 之模型内容可视化
TensorFlow模型保存和提取方法 1. tensorflow实现 卷积神经网络CNN:Tensorflow实现(以及对卷积特征的可视化) # 卷积网络的训练数据为MNIST(28*28灰度单色图 ...
- 【tensorflow基础】ubuntu-tensorflow可视化工具tensorboard-No dashboards are active for the current data set.
前言 今天基于tensorflow训练一个检测模型,本应看到训练曲线的,却只见到一个文件events.out.tfevents.1570520647.hostname,后来发现这个文件可以查看训练曲线 ...
- TensorFlow(八):tensorboard可视化
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data from tensorflow.c ...
- Deep Learning基础--26种神经网络激活函数可视化
在神经网络中,激活函数决定来自给定输入集的节点的输出,其中非线性激活函数允许网络复制复杂的非线性行为.正如绝大多数神经网络借助某种形式的梯度下降进行优化,激活函数需要是可微分(或者至少是几乎完全可微分 ...
- tensorflow中常用激活函数和损失函数
激活函数 各激活函数曲线对比 常用激活函数: tf.sigmoid() tf.tanh() tf.nn.relu() tf.nn.softplus() tf.nn.softmax() tf.nn.dr ...
- Tensorflow机器学习入门——网络可视化TensorBoard
一.在代码中标记要显示的各种量 tensorboard各函数的作用和用法请参考:https://www.cnblogs.com/lyc-seu/p/8647792.html import tensor ...
随机推荐
- idea使用maven打包jar包
1.在pom.xml中加入以下内容: <?xml version="1.0" encoding="UTF-8"?> <project xmln ...
- centos7.2 增加3T的XFS模式分区
parted -l 查看分区情况与要分区的设备 # parted /dev/sda #选定要操作的硬盘 此时命令提示符会变成(parted) (par ...
- 关于 No buffer space available (maximum connections reached?): connect 的处理
一.问题: hudson一个应用打包部署一直不成功,检查报错 检查项目的JOB配置,开始以为是SVN的问题,但是重启SVN后问题一直存在 二.分析: TCP协议中,关闭TCP连接的是Server端(当 ...
- C++中的构造函数
C++中的构造函数可以分为4类: (1)默认构造函数.以Student类为例,默认构造函数的原型为 Student()://没有参数 (2)初始化构造函数 Student(int num,int ag ...
- 微信小程序开发——设置默认图片、错误加载图片
小程序不支持h5中的onerrorimg,只开放了binderror属性,当错误发生时,会发布到 AppService,事件对象event.detail = {errMsg: 'something w ...
- “东信杯”广西大学第一届程序设计竞赛(同步赛)H
链接:https://ac.nowcoder.com/acm/contest/283/H来源:牛客网 题目描述 由于临近广西大学建校90周年校庆,西大开始了喜闻乐见的校园修缮工程! 然后问题出现了,西 ...
- 水晶报表一页变两页,server2008添加XPS虚拟打印机
水晶报表,程序开发的时候是一页,部署到服务器上后变为两页. 经过这几天研究是服务器上水晶报表的打印机设置不对 本地水晶报表的打印机设置的是 Microsoft XPS Document Writer ...
- linux查看本服务端口开放情况
在Linux使用过程中,需要了解当前系统开放了哪些端口,并且要查看开放这些端口的具体进程和用户,可以通过netstat命令进行简单查询. 1.netstat命令各个参数说明如下: -t : 指明显示T ...
- composer ip2city配置
//根据ip获取地址信息composer require "mylukin/ip2city: dev-master" // vendor/mylukin/ip2city/src/I ...
- 读取properties文件的信息
1.properties配置文件的信息 fcsimage_path=C://FCSImage 2.Java代码 public final class Config { private static f ...