tensorflow 笔记11:tf.nn.dropout() 的使用
tf.nn.dropout:函数
官网说明:
tf.nn.dropout(
x,
keep_prob,
noise_shape=None,
seed=None,
name=None
)
Defined in tensorflow/python/ops/nn_ops.py. See the guides: Layers (contrib) > Higher level ops for building neural network layers, Neural Network > Activation Functions Computes dropout. With probability keep_prob, outputs the input element scaled up by 1 / keep_prob, otherwise outputs 0. The scaling is so that the expected sum is unchanged. By default, each element is kept or dropped independently. If noise_shape is specified,
it must be broadcastable to the shape of x, and only dimensions with noise_shape[i] == shape(x)[i] will make independent decisions. For example, if shape(x) = [k, l, m, n] and noise_shape = [k, 1, 1, n], each batch and channel component will be kept independently and each row and column will be kept or not kept together. Args:
x: A floating point tensor.
keep_prob: A scalar Tensor with the same type as x. The probability that each element is kept.
noise_shape: A 1-D Tensor of type int32, representing the shape for randomly generated keep/drop flags.
seed: A Python integer. Used to create random seeds. See tf.set_random_seed for behavior.
name: A name for this operation (optional).
Returns:
A Tensor of the same shape of x. Raises:
ValueError: If keep_prob is not in (0, 1] or if x is not a floating point tensor.
使用说明:
参数 keep_prob: 表示的是保留的比例,假设为0.8 则 20% 的数据变为0,然后其他的数据乘以 1/keep_prob;keep_prob 越大,保留的越多;
参数 noise_shape:干扰形状。 此字段默认是None,表示第一个元素的操作都是独立,但是也不一定。比例:数据的形状是shape(x)=[k, l, m, n],而noise_shape=[k, 1, 1, n],则第1和4列是独立保留或删除,第2和3列是要么全部保留,要么全部删除。
代码举例:
import os
import numpy as np
import tensorflow as tf x = tf.Variable(tf.ones([10, 10])) inputs = tf.nn.dropout(x, 0.8) init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
print (x.eval())
print (inputs.eval())
输出结果:
[[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]]
[[1.25 1.25 0. 1.25 1.25 1.25 1.25 1.25 1.25 0. ]
[0. 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25]
[1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25]
[1.25 1.25 1.25 1.25 1.25 0. 1.25 1.25 1.25 1.25]
[1.25 1.25 1.25 1.25 1.25 0. 1.25 1.25 0. 1.25]
[1.25 1.25 1.25 1.25 1.25 0. 0. 1.25 1.25 1.25]
[0. 1.25 1.25 0. 1.25 1.25 1.25 0. 1.25 0. ]
[1.25 0. 0. 1.25 1.25 1.25 1.25 1.25 1.25 1.25]
[1.25 1.25 1.25 0. 1.25 1.25 1.25 0. 0. 0. ]
[1.25 1.25 0. 0. 0. 0. 1.25 1.25 1.25 1.25]]
加入 noise:
import os
import numpy as np
import tensorflow as tf x = tf.Variable(tf.ones([3,3,3])) inputs = tf.nn.dropout(x, 0.5,[3,1,3]) init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
print (x.eval())
print (inputs.eval())
输出:
[[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]] [[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]] [[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]]
[[[0. 2. 2.]
[0. 2. 2.]
[0. 2. 2.]] [[2. 2. 2.]
[2. 2. 2.]
[2. 2. 2.]] [[0. 2. 2.]
[0. 2. 2.]
[0. 2. 2.]]]
tensorflow 笔记11:tf.nn.dropout() 的使用的更多相关文章
- Tensorflow学习笔记(2):tf.nn.dropout 与 tf.layers.dropout
A quick glance through tensorflow/python/layers/core.py and tensorflow/python/ops/nn_ops.pyreveals t ...
- TensorFlow学习笔记 速记1——tf.nn.dropout
tf.nn.dropout(x, keep_prob, noise_shape=None, seed=None,name=None) 上面方法中常用的是前两个参数: 第一个参数 x:指输入: 第二个 ...
- TensorFlow之tf.nn.dropout():防止模型训练过程中的过拟合问题
一:适用范围: tf.nn.dropout是TensorFlow里面为了防止或减轻过拟合而使用的函数,它一般用在全连接层 二:原理: dropout就是在不同的训练过程中随机扔掉一部分神经元.也就是让 ...
- TensorFlow函数教程:tf.nn.dropout
tf.nn.dropout函数 tf.nn.dropout( x, keep_prob, noise_shape=None, seed=None, name=None ) 定义在:tensorflow ...
- TensorFlow学习---tf.nn.dropout防止过拟合
一. Dropout原理简述: tf.nn.dropout是TensorFlow里面为了防止或减轻过拟合而使用的函数,它一般用在全连接层. Dropout就是在不同的训练过程中随机扔掉一部分神经元.也 ...
- 深度学习原理与框架-Tensorflow卷积神经网络-卷积神经网络mnist分类 1.tf.nn.conv2d(卷积操作) 2.tf.nn.max_pool(最大池化操作) 3.tf.nn.dropout(执行dropout操作) 4.tf.nn.softmax_cross_entropy_with_logits(交叉熵损失) 5.tf.truncated_normal(两个标准差内的正态分布)
1. tf.nn.conv2d(x, w, strides=[1, 1, 1, 1], padding='SAME') # 对数据进行卷积操作 参数说明:x表示输入数据,w表示卷积核, stride ...
- tf.nn.dropout
tf.nn.dropout(x, keep_prob, noise_shape=None, seed=None, name=None) 此函数是为了防止在训练中过拟合的操作,将训练输出按一定规则进行变 ...
- tf.nn.dropout 激活函数
tf.nn.dropout(x,keep_prob,noise_shape=None,seed=None,name=None) 参数: x:一个浮点型Tensor. keep_prob:一个标量Ten ...
- tensorflow笔记:使用tf来实现word2vec
(一) tensorflow笔记:流程,概念和简单代码注释 (二) tensorflow笔记:多层CNN代码分析 (三) tensorflow笔记:多层LSTM代码分析 (四) tensorflow笔 ...
随机推荐
- PopupWindow下拉列表
效果图 步骤: 1.画出编辑框的布局.popupWindow的布局.popupWindow中listview每行的布局 2.new一个PopupWindow对象,设置其属性 3.定义一个BaseAda ...
- RefreshListView下拉刷新
布局: <com.example.administrator.d30_myrefreshlistview.RefreshListView android:id="@+id/refres ...
- 暴力破解工具hydra与Medusa
---恢复内容开始--- 暴力破解工具hydra与Medusa 内容 (一)hadry (二)Medusa (一)hydra 选项 -l LOGIN 指定破解的用户名称,对特定用户破解. -L FIL ...
- 使用perf工具导致系统hang死的原因
[perf工具导致系统hang住的原因是触发了低版本kernel的bug] 今天在测试服务器做压测,运行perf record做性能分析时,系统再次hang住了,这次在系统日志中记录了一些有用的信息, ...
- Web大前端面试题-Day8
1. 说说你对作用域链的理解? 作用域链的作用是保证执行环境里 有权访问的变量和函数是有序的, 作用域链的变量只能向上访问, 变量访问到window对象即被终止, 作用域链向下访问变量是不被允许的; ...
- internet连接共享
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_shai nternet连接共享 允许其他网络用户通过此计算机的internet连接来连接
- C#获得窗口控件句柄
/*整个Windows编程的基础.一个句柄是指使用的一个唯一的整数值,即一个4字节(64位程序中为8字节)长的数值,来标识应用程序中的不同对象和同类中的不同的实例,诸如,一个窗口,按钮,图标,滚动条, ...
- Python获取系统音量
1,如果是windows下 试试这个python 模块winsoundhttp://docs.python.org/2/library/winsound.html这个也可以winmm调整windows ...
- 潭州课堂25班:Ph201805201 WEB 之 页面编写 第三课 (课堂笔记)
index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- BZOJ5384 有趣的字符串题 回文树
神奇的结论: 一个字符串的所有回文后缀的长度,可以形成$k$个等差数列,$k$是$log$级的 考虑前$R$个字符组成的字符串,对于一个等差数列,假设组成这个等差数列的回文串,最短的叫$a$,最长的叫 ...