在Keras中,辍学对象的体重是多少? [英] In Keras, on which weight is the dropout applied?

查看:95
本文介绍了在Keras中,辍学对象的体重是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正试图找到一种方法来检索给定层的权重"被忽略(特别是当我在测试阶段使用训练"标志来使用辍学时). 有没有找到它的简单方法,还是我有义务创建一个自定义的辍学图层?

I am currently trying to find a way to retrieve which weights are "ignored" for a given layer (especially when I use the "training" flag to use dropout during the test phase). Is there an easy way to find it or am I obligated to create a custom dropout layer ?

推荐答案

没有简单的方法. Keras的tensorflow后端简单地调用tf.nn.dropout,它通过生成其输入大小的随机矩阵来工作,并且如果随机矩阵中的对应值小于阈值,则将输入中的值设置为零.

There is no easy way. Keras' tensorflow backend simply calls tf.nn.dropout which works by generating a random matrix of the size of its input and sets values in the input to zero if the corresponding value in the random matrix is less than the threshold.

这是关键步骤,位于 https中://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/nn_ops.py :

# Sample a uniform distribution on [0.0, 1.0) and select values larger than
# rate.
random_tensor = random_ops.random_uniform(
    noise_shape, seed=seed, dtype=x.dtype)
keep_prob = 1 - rate
ret = (1 / keep_prob) * math_ops.cast(keep_prob >= random_tensor,
                                      x.dtype) * x

您不能直接通过keras检索这些结果,因为随机乘法会立即应用并且不会保存.但是,您可以尝试修改源代码以打印或保存math_ops.cast(keep_prob >= random_tensor,x.dtype)的结果,该结果包含在使用dropout时使用了哪些权重.

You can't retrieve these results directly through keras since the random multiplication is applied immediately and not saved. However you can try to modify the source code to print or save the result of math_ops.cast(keep_prob >= random_tensor,x.dtype) which contains which weights were used in that use of dropout.

这篇关于在Keras中,辍学对象的体重是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆