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() 的使用的更多相关文章

  1. 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 ...

  2. TensorFlow学习笔记 速记1——tf.nn.dropout

    tf.nn.dropout(x, keep_prob, noise_shape=None, seed=None,name=None)  上面方法中常用的是前两个参数: 第一个参数 x:指输入: 第二个 ...

  3. TensorFlow之tf.nn.dropout():防止模型训练过程中的过拟合问题

    一:适用范围: tf.nn.dropout是TensorFlow里面为了防止或减轻过拟合而使用的函数,它一般用在全连接层 二:原理: dropout就是在不同的训练过程中随机扔掉一部分神经元.也就是让 ...

  4. TensorFlow函数教程:tf.nn.dropout

    tf.nn.dropout函数 tf.nn.dropout( x, keep_prob, noise_shape=None, seed=None, name=None ) 定义在:tensorflow ...

  5. TensorFlow学习---tf.nn.dropout防止过拟合

    一. Dropout原理简述: tf.nn.dropout是TensorFlow里面为了防止或减轻过拟合而使用的函数,它一般用在全连接层. Dropout就是在不同的训练过程中随机扔掉一部分神经元.也 ...

  6. 深度学习原理与框架-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 ...

  7. tf.nn.dropout

    tf.nn.dropout(x, keep_prob, noise_shape=None, seed=None, name=None) 此函数是为了防止在训练中过拟合的操作,将训练输出按一定规则进行变 ...

  8. tf.nn.dropout 激活函数

    tf.nn.dropout(x,keep_prob,noise_shape=None,seed=None,name=None) 参数: x:一个浮点型Tensor. keep_prob:一个标量Ten ...

  9. tensorflow笔记:使用tf来实现word2vec

    (一) tensorflow笔记:流程,概念和简单代码注释 (二) tensorflow笔记:多层CNN代码分析 (三) tensorflow笔记:多层LSTM代码分析 (四) tensorflow笔 ...

随机推荐

  1. Linux 内核编译问题

    linux0.12 编译过程 https://www.bbsmax.com/A/GBJrMb0Kz0/ http://www.cnblogs.com/strugglesometimes/p/42313 ...

  2. 《Gradle权威指南》--Java Gradle插件

    No1: dependencies{ compile group: 'com.squareup.okhttp3',name:'okhttp',version:'3.0.1' } //缩写 depend ...

  3. UVA 11624-Fire!【双BFS】

    <题目链接> 题目大意: 你的任务是帮助J走出一个大火蔓延的迷宫.J每分钟可以超上下左右四个方向移动,而所有着火的格子每一分钟都会往四个方向蔓延一格.迷宫中有一些障碍,J和火都无法进入.当 ...

  4. Python Django 学习 (一) 【Django 框架初探】

    1. 简介: Python下有许多款不同的 Web 框架.Django是重量级选手中最有代表性的一位.2008年9月发布第一个版本,目前的Django版本应该是2.1. 2. 本文的环境 OS : W ...

  5. mysql5.7一键安装脚本

    0. 概述 最近鼓捣出了一个mysql安装脚本,将该脚本,mysql的my.cnf文件,mysql的安装包这三个文件放在同一个目录下面,执行sh mysql-auto-install.sh就可以完成m ...

  6. Orleans逐步教程

    参考文档:https://dotnet.github.io/orleans/Tutorials/index.html 一.通过模板创建Orleans ①下载vs插件:https://marketpla ...

  7. 关于restful API url整理

    每个资源使用两个URL 资源集合用一个URL,具体某个资源用一个URL: /employees         #资源集合的URL /employees/56      #具体某个资源的URL 用名词 ...

  8. [ 转载 ] Handler详解

    带着问题学习 Android Handler 消息机制 Marker_Sky 关注  0.4 2018.02.06 18:04* 字数 3992 阅读 541评论 0喜欢 13   学习 Androi ...

  9. 树上统计treecnt(dsu on tree 并查集 正难则反)

    题目链接 dalao们怎么都写的线段树合并啊.. dsu跑的好慢. \(Description\) 给定一棵\(n(n\leq 10^5)\)个点的树. 定义\(Tree[L,R]\)表示为了使得\( ...

  10. BZOJ.3809.Gty的二逼妹子序列(分块 莫队)

    题目链接 /* 25832 kb 26964 ms 莫队+树状数组:增加/删除/查询 都是O(logn)的,总时间复杂度O(m*sqrt(n)*logn),卡不过 莫队+分块:这样查询虽然变成了sqr ...