tf.nn.dropout

tf.nn.dropout(x, keep_prob, noise_shape=None, seed=None, name=None)

Type: function

Docstring: 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 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].

example:

import tensorflow as tf
import numpy as np
# 神经元输入值
neuros = np.array([1, 1, 1, 1],dtype=np.float32)
# 接入dropout层
neuros_drop = tf.nn.dropout(neuros, keep_prob=0.5)
with tf.Session() as sess:
    neuros_drop_res = sess.run(neuros_drop)
    print(neuros_drop_res)
[ 0.  2.  2.  2.]
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • tf.nn.dropout(x, keep_prob, noise_shape=None, seed=None, ...
    HabileBadger阅读 7,363评论 0 0
  • 执念 是一种信仰 【 遇见·Beauty】第三季回顾 做内外兼修·魅力女子,必须要有自己的时间和空间,必须要学...
    Lisa_su阅读 5,737评论 0 1
  • 已经步入夏天了。 向来都是不爱夏天,那样的闷热,烦躁,让人没办法喘息。 我坐在窗边的位置上,又开始望着窗外发呆了。...
    的树阅读 975评论 0 0
  • 在读幼师期间,我有一个朋友,她非常的漂亮!她很爱美、也喜欢别人关注她,但每每有人评论她这个不好、那个不好时,她...
    小小怪有个帅啊坝阅读 2,761评论 9 8
  • 《生来彷徨》 我们都一样生来便彷徨 《花开浪漫》 爱情花开浪漫初恋终究成渣 《梦想》 愿明天有太阳焦灼我即将腐朽的...
    何鲸洛阅读 3,828评论 3 1