TensorFlow2.0:张量限幅
**
一 tf.clip_by_value( )函数
**
tf.maximum(a,b)返回a和b之间的最大值
tf.minimum(a,b)返回a和b之间的最小值
tf.clip_by_value(t, clip_value_min, clip_value_max, name=None)限制tensor t中张量的最小值为clip_value_min,张量的最大值为clip_value_max
In [25]: a = tf.range(9) In [26]: a
Out[26]: <tf.Tensor: id=53, shape=(9,), dtype=int32, numpy=array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=int32)>In [27]: tf.maximum(a,2)#返回a和2之间的最大值,本质是限制a的最小值为2
Out[27]: <tf.Tensor: id=56, shape=(9,), dtype=int32, numpy=array([2, 2, 2, 3, 4, 5, 6, 7, 8], dtype=int32)>In [28]: tf.minimum(a,8)#返回a和8之间的最小值,本质时限制a的最大值为8
Out[28]: <tf.Tensor: id=59, shape=(9,), dtype=int32, numpy=array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=int32)>In [29]: tf.clip_by_value(a,2,8) #限制tensor a中张量的最最小值为2,最大值为8
Out[29]: <tf.Tensor: id=64, shape=(9,), dtype=int32, numpy=array([2, 2, 2, 3, 4, 5, 6, 7, 8], dtype=int32)>
**
二 tf.nn.relu( )函数
**
In [41]: a = tf.range(9) In [42]: a = a-5 In [43]: a
Out[43]: <tf.Tensor: id=87, shape=(9,), dtype=int32, numpy=array([-5, -4, -3, -2, -1, 0, 1, 2, 3], dtype=int32)>In [44]: tf.nn.relu(a)
Out[44]: <tf.Tensor: id=89, shape=(9,), dtype=int32, numpy=array([0, 0, 0, 0, 0, 0, 1, 2, 3], dtype=int32)>In [45]: tf.maximum(a,0)
Out[45]: <tf.Tensor: id=92, shape=(9,), dtype=int32, numpy=array([0, 0, 0, 0, 0, 0, 1, 2, 3], dtype=int32)>
**
三 tf.clip_by_norm( )根据范数裁剪
**
In [54]: a = tf.random.normal([2,2],mean=100) In [55]: a
Out[55]:
<tf.Tensor: id=157, shape=(2, 2), dtype=float32, numpy=
array([[99.52346 , 98.461006],[98.95429 , 99.52083 ]], dtype=float32)>In [56]: tf.norm(a)
Out[56]: <tf.Tensor: id=163, shape=(), dtype=float32, numpy=198.23177>In [57]: aa = tf.clip_by_norm(a,10) In [58]: aa
Out[58]:
<tf.Tensor: id=180, shape=(2, 2), dtype=float32, numpy=
array([[5.0205607, 4.9669642],[4.9918485, 5.0204277]], dtype=float32)>In [59]: tf.norm(aa)
Out[59]: <tf.Tensor: id=186, shape=(), dtype=float32, numpy=10.0>
**
四 tf.clip_by_global_norm( )函数
**
gradient clipping梯度裁剪:
tf.clip_by_global_norm(t_list, clip_norm, use_norm=None, name=None)
对整体的梯度数据按照范数进行裁剪,防止梯度爆炸(gradient exploding)和梯度消失(gradient vanishing)
TensorFlow2.0:张量限幅相关推荐
- TensorFlow2.0:张量排序
** 一 sort argsort排序 ** tf.sort( )按照升序或者降序对张量进行排序 tf.argsort( )按照升序或者降序对张量进行排序,但返回的是索引 In [4]: a = tf ...
- TensorFlow2.0:张量的合并与分割
** 一 tf.concat( ) 函数–合并 ** In [2]: a = tf.ones([4,35,8]) In [3]: b = tf.ones([2,35,8]) In [4]: c = t ...
- TensorFlow2.0:张量的数学运算
(1)+ - * / (2)** pow square (3) sqrt (4) // % (5) exp log (6)@ matmul (7) linear layer element-wise: ...
- 【TensorFlow2.0】(7) 张量排序、填充、复制、限幅、坐标选择
各位同学好,今天和大家分享一下TensorFlow2.0中的一些操作.内容有: (1)排序 tf.sort().tf.argsort().top_k():(2)填充 tf.pad():(3)复制 tf ...
- 【TensorFlow2.0】(6) 数据统计,范数、最值、求和、均值、最值位置、唯一值、张量比较
各位同学好,今天和大家分享一下TensorFlow2.0中的数据分析操作.内容有: (1)范数 tf.norm():(2)最值 tf.reduce_min(), tf.reduce_max()(3)求 ...
- 深度学习(16)TensorFlow高阶操作五: 张量限幅
深度学习(16)TensorFlow高阶操作五: 张量限幅 1. clip_by_value 2. relu 3. clip_by_norm 4. Gradient clipping 5. 梯度爆炸实 ...
- TensorFlow2.0系列教程集合版(附PDF下载)
文章来源于机器学习算法与Python实战,作者奥辰 TensorFlow2.0(1):基本数据结构--张量 TensorFlow2.0(2):数学运算 TensorFlow2.0(3):张量排序.最大 ...
- 【TensorFlow2.0】(5) 数学计算、合并、分割
各位同学好,今天和大家分享一下TensorFlow2.0中的数学运算方法.合并与分割.内容有: (1)基本运算:(2)矩阵相乘:(3)合并 tf.concat().tf.stack():(4)分割 t ...
- 【TensorFlow2.0】(4) 维度变换、广播
各位同学好,今天我和大家分享一下TensorFlow2.0中有关数学计算的相关操作,主要内容有: (1) 改变维度:reshape():(2) 维度转置:transpose():(3) 增加维度:ex ...
最新文章
- Sql语法---DDL
- python用哪个版本比较好 2020_2020年最常见的Python面试题答案
- python四十八:多态
- 云游戏打破硬件限制,传输体验或成发展掣肘!
- 获取指定某一天的00:00—23:59
- MySQL官方备份_Mysqlbackup 备份详解(mysql官方备份工具)
- Windows2003下DHCP服务器备份、还原、迁移、绑定
- 初学者python笔记(filter()函数完全详解)
- 基于Go语言构建区块链:part5
- 人工智能目标检测模型总结(三)——yolov1模型(2)
- Matlab字符串转换及数值格式转换
- 面向对象设计 腾讯代码案例 学习人家的模式和格式
- Linux设置每分钟、每小时、每天、每周、每月、每年定时执行
- 没有十年网龄都不知道的事儿
- Spring Boot 2.1.6.RELEASE embed tomcat启动过程
- html怎么定义403页面,自定义 403 错误页面(示例代码)
- vue中的this.$router.replace()和.push()和.go()的区别解析
- 如何选择适合你的兴趣爱好(一),拉丁舞
- kali Linux命令大全
- 监控视频压缩1—INSTANCE SEGMENTATION BASED BACKGROUND REFERENCE FRAME GENERATIONFOR SURVEILLANCE VIDEO CODI
热门文章
- JAVA前三章预习总结
- gcc 编译流程分析
- 制作透明的图标ICO
- OneNote中到底能放多少种东西?
- ASP.NET AJAX,WCF,ADO.NET Entity 开发实例
- 【LeetCode 剑指offer刷题】字符串题12:Valid Palindrome(回文词系列)
- 数据库mysql:MySQL软件安装
- ios swift 实现饼状图进度条,swift环形进度条
- kmalloc、vmalloc、__get_free_pages()的区别
- OpenGL之路(六)贴图