tensorflow 之常见模块conv,bn...实现
使用tensorflow时,会发现tf.nn,tf.layers, tf.contrib模块有很多功能是重复的,尤其是卷积操作,在使用的时候,我们可以根据需要现在不同的模块。但有些时候可以一起混用。
下面是对三个模块的简述:
(1)tf.nn :提供神经网络相关操作的支持,包括卷积操作(conv)、池化操作(pooling)、归一化、loss、分类操作、embedding、RNN、Evaluation。
(2)tf.layers:主要提供的高层的神经网络,主要和卷积相关的,个人感觉是对tf.nn的进一步封装,tf.nn会更底层一些。
(3)tf.contrib:tf.contrib.layers提供够将计算图中的 网络层、正则化、摘要操作、是构建计算图的高级操作,但是tf.contrib包含不稳定和实验代码,有可能以后API会改变。
Batch normalization(BN):
tensorflow中提供了三种BN方法:https://blog.csdn.net/Leo_Xu06/article/details/79054326
tf.nn.batch_normalizationtf.layers.batch_normalizationtf.contrib.layers.batch_norm
以tf.layers.batch_normalization为例介绍里面所包含的主要参数:
tf.layers.batch_normalization(inputs, decay=0.999, center=True, scale=True, is_training=True, epsilon=0.001)
一般使用只要定义以下的参数即可:
inputs: 输入张量[N, H, W, C]
decay: 滑动平均的衰减系数,一般取接近1的值,这样能在验证和测试集上获得较好结果
center: 中心偏移量,上述的ββ ,为True,则自动添加,否则忽略
scale: 缩放系数,上述的γγ,为True,则自动添加,否则忽略
epsilon: 为防止除0而加的一个很小的数
- is_training: 是否是训练过程,为True则代表是训练过程,那么将根据decay用指数滑动平均求得moments,并累加保存到
moving_mean和moving_variance中。否则是测试过程,函数直接取这两个参数来用。
如果是True,则需在训练的session中添加将BN参数更新操作加入训练的代码:
# execute update_ops to update batch_norm weights update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
with tf.control_dependencies(update_ops):
optimizer = tf.train.AdamOptimizer(decayed_learning_rate)
train_op = optimizer.minimize(loss, global_step = global_step)
附官网链接:
https://www.tensorflow.org/api_docs/python/tf/nn/batch_normalization
tf.contrib.layers.batch_norm | TensorFlow
tf.layers.batch_normalization | TensorFlow
How is BatchNormalization layer in keras implemented in test phase?
- https://stackoverflow.com/questions/33949786/how-could-i-use-batch-normalization-in-tensorflow
tensorflow 之常见模块conv,bn...实现的更多相关文章
- tensorflow中slim模块api介绍
tensorflow中slim模块api介绍 翻译 2017年08月29日 20:13:35 http://blog.csdn.net/guvcolie/article/details/77686 ...
- 类装饰器,元类,垃圾回收GC,内建属性、内建方法,集合,functools模块,常见模块
'''''''''类装饰器'''class Test(): def __init__(self,func): print('---初始化---') print('func name is %s'%fu ...
- Ansible常见模块介绍
本节内容: ansible命令基础 常见模块举例 一.ansible命令基础 语法: ansible <host-pattern> [-f forks] [-m module_name] ...
- ansible入门二(Ansible常见模块介绍)
本节内容: ansible命令基础 常见模块举例 一.ansible命令基础 语法: ansible <host-pattern> [-f forks] [-m module_name] ...
- Ansible 常见模块介绍
目录 Ansible 常见模块介绍 ping 模块 command 模块 cron 模块 user 模块 group 模块 copy 模块 file 模块 service 模块 shell 模块 sc ...
- 第十八节,TensorFlow中使用批量归一化(BN)
在深度学习章节里,已经介绍了批量归一化的概念,详情请点击这里:第九节,改善深层神经网络:超参数调试.正则化以优化(下) 神经网络在进行训练时,主要是用来学习数据的分布规律,如果数据的训练部分和测试部分 ...
- Tensorflow.nn 核心模块详解
看过前面的例子,会发现实现深度神经网络需要使用 tensorflow.nn 这个核心模块.我们通过源码来一探究竟. # Copyright 2015 Google Inc. All Rights Re ...
- [tensorflow]图像处理相关模块的安装(python3中PIL)
直接上过程图(平台为Anaconda): 默认已经配置完了tensorflow的3.5的环境 我这里已经安装完成 接下来,就可以在python文件中引入模块了 from PIL import Imag ...
- Tensorflow 的saved_model模块学习
saved_model模块主要用于TensorFlow Serving.TF Serving是一个将训练好的模型部署至生产环境的系统,主要的优点在于可以保持Server端与API不变的情况下,部署新的 ...
随机推荐
- CI框架中site_url()和base_url()的区别
背景:在使用CI框架的使用经常碰到跳转和路径方面的问题,site_url()和base_url()很容易混淆,下面来说说他们的区别! 假如你config文件里面的base_url和index_page ...
- JAVA 获取分行符
public static final String CR_LF = System.getProperty("os.name").startsWith("Windows& ...
- NetCore+Dapper WebApi架构搭建(一):基本框架
初衷是想用dapper搭建一个高性能的架构,因为dapper操作数据库的效率很高 1.VS创建一个NetCore WebApi的框架,然后解决方案添加一个NetStandard的类库 整个解决方案如图 ...
- python通过swig调用静态库
swig - Simplified Wrapper and Interface Generator swig可以支持python,go,php,lua,ruby,c#等多种语言的包裹 本文主要记录如何 ...
- android view的 绘制流程
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 首先是 从 视图根 这个类的 进行遍历 performTraversals 方法 开 ...
- luoguP4036 [JSOI2008]火星人 平衡树+hash
这个操作十分的复杂 但是可以拿平衡树维护 直接二分答案然后用$hash$值判断即可 复杂度$O(10000 * log^2 n + n \log n)$ #include <cstdio> ...
- bzoj 1590: [Usaco2008 Dec]Secret Message 秘密信息
1590: [Usaco2008 Dec]Secret Message 秘密信息 Description 贝茜正在领导奶牛们逃跑.为了联络,奶牛们互相发送秘密信息. 信息是二进制的,共 ...
- hdu 4531 bfs(略难)
题目链接:点我 第一次不太清楚怎么判重,现在懂了,等下次再做 /* *HDU 4531 *BFS *注意判重 */ #include <stdio.h> #include <stri ...
- 小程序navigator点击有时候会闪一下
<navigator hover-class="none">
- How to exit the entire application from a Python thread?
If all your threads except the main ones are daemons, the best approach is generally thread.interrup ...