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笔 ...
随机推荐
- Android 之 tools:context和tools:ignore两个属性的作用
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...
- html+css基础知识
这是自己学习html时候做的一些记录,供大家参考 <!-- 块和内联 块元素:独占一行的元素 div p h ul div没有任何语义,就是一个纯粹的快元素 就是为了方便布局 span是内联元素 ...
- 合并流 SequenceInputStream
SequenceInputStream主要用来将2个流合并在一起,比如将两个txt中的内容合并为另外一个txt.下面给出一个实例: import java.io.File; import java.i ...
- NTFS的交换数据流ADS应用
NTFS的交换数据流ADS应用 NTFS是Windows常用的文件系统格式.该格式支持交换数据流(Alternate Data Streams,缩写ADS)特性.该特性可以让多个文件流使用同一个文 ...
- ubuntu14.06 Lts开启ssh服务
(1) apt-get install openssh-server (2)检查ssh服务开启状态 (3)通过以下命令启动ssh服务 service ssh stop service ssh star ...
- 安装android studio&flutter
参考:https://flutterchina.club/setup-windows/ 1.安装jdk 2.android studio下载地址 https://developer.android. ...
- 洛谷P2105 K皇后
To 洛谷.2105 K皇后 题目描述 小Z最近捡到了一个棋盘,他想在棋盘上摆放K个皇后.他想知道在他摆完这K个皇后之后,棋盘上还有多少了格子是不会被攻击到的. (Ps:一个皇后会攻击到这个皇后所在的 ...
- Python3练习题系列(01)
2018-06-13 题目: 根据用户回答做出相应的判断,完成一个“回答-判断”的小游戏 Python3知识点: if, else, elif 实例代码: print("You enter ...
- nodejs区分开发环境和生产环境
参考: https://www.cnblogs.com/suoking/p/5509060.html linux&mac 设置dev,producntion export NODE_ENV=p ...
- 当删除某一个jar包时tomcat中出现problem encountered while deleting resources问题
http://blog.csdn.net/u013226462/article/details/17715031