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笔 ...
随机推荐
- Python4 - 文件操作
对文件操作流程 打开文件,得到文件句柄并赋值给一个变量 文件的内存对象-包含 文件名.字符集.大小.在硬盘上的起止位置... 通过句柄对文件进行操作 关闭文件 open 方法 open()函数打开一个 ...
- JavaScript开发区块链只需200行代码
用JavaScript开发实现一个简单区块链.通过这一开发过程,你将理解区块链技术是什么:区块链就是一个分布式数据库,存储结构是一个不断增长的链表,链表中包含着许多有序的记录. 然而,在通常情况下,当 ...
- (转)细说JDK动态代理的实现原理
原文:http://blog.csdn.net/mhmyqn/article/details/48474815 关于JDK的动态代理,最为人熟知的可能要数Spring AOP的实现,默认情况下,Spr ...
- Android应用开发-数据存储和界面展现(二)
SQLite数据库 // 自定义类MyOpenHelper继承自SQLiteOpenHelper MyOpenHelper oh = new MyOpenHelper(getContext(), &q ...
- OSINT系列:网站信任评估WOT
OSINT系列:网站信任评估WOT Web of Trust(WOT)是芬兰的一家网站信任评估服务公司.它通过收集用户对网站的评价,来评估网站的可信任度.在该公司网站www.mywot.com,用户 ...
- {}+[]与console.log({}+[])结果不同?从JavaScript的大括号谈起
看到这样一个问题:为什么直接在控制台运行{} + []和用console.log({} + [])输出,两者结果不一样? 于是乎打开chrome的控制台运行了一下: 为什么结果会这样呢?不得已学习一下 ...
- python 分类
python分类.机器学习连接 http://blog.csdn.net/eastmount/article/details/50473675 python机器学习列表 http://blog.csd ...
- Springzz中使用监听器,用于容器一启动就加载准备数据(application范围内的数据,用于减轻服务器压力,不用每次都去查数据)
java代码: public class InitListener implements ServletContextListener { public void contextInitialized ...
- [模板][P3796]AC自动机(加强版)
Description: 输出有哪些模式串在文本串中出现次数最多,这个次数是多少 Hint: 多组数据,$ len_{文本串}<=10^6,\sum len_{模式串} <= 70*150 ...
- git 删除分支 远程 && 本地
//查看远程分支 git branch -a //删除远程分支 git branch -r -d origin/branch-name git push origin :branch-name// 或 ...