machine-learning - 如何在 TensorFlow 中正确实现卷积的 dropout

标签 machine-learning tensorflow neural-network conv-neural-network

根据关于 Dropout 的原始论文,正则化方法可以应用于卷积层,通常可以提高其性能。 TensorFlow 函数 tf.nn.dropout 通过使用 noise_shape 参数来支持这一点,允许用户选择将独立丢弃张量的哪些部分。然而,论文和文档都没有明确解释哪些维度应该独立保留,并且 TensorFlow 对 noise_shape 工作原理的解释也相当不清楚。

only dimensions with noise_shape[i] == shape(x)[i] will make independent decisions.

我假设对于形状为[batch_size, height, width,channels]的典型CNN层输出,我们不希望单独的行或列自行丢弃,而是整体丢弃 channel (相当于完全连接的神经网络中的节点)独立于示例(即,可以针对批处理中的不同示例删除不同的 channel )。我的这个假设正确吗?

如果是这样,如何使用 noise_shape 参数来实现具有如此特异性的 dropout?会不会是:

noise_shape=[batch_size, 1, 1, channels]

或者:

noise_shape=[1, height, width, 1]

最佳答案

来自here ,

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.

代码可能有助于解释这一点。

noise_shape = noise_shape if noise_shape is not None else array_ops.shape(x)
# uniform [keep_prob, 1.0 + keep_prob)
random_tensor = keep_prob
random_tensor += random_ops.random_uniform(noise_shape,
                                           seed=seed,
                                           dtype=x.dtype)
# 0. if [keep_prob, 1.0) and 1. if [1.0, 1.0 + keep_prob)
binary_tensor = math_ops.floor(random_tensor)
ret = math_ops.div(x, keep_prob) * binary_tensor
ret.set_shape(x.get_shape())
return ret

random_tensor +=支持broadcast 。当noise_shape[i]设置为1时,意味着该维度中的所有元素都会添加相同的0到1之间的随机值。因此,当noise_shape=[k, 1, 1, n] ,特征图中的每一行和每一列都会保留或不保留在一起。另一方面,每个示例(批处理)或每个 channel 接收不同的随机值,并且每个随机值将独立保存。

关于machine-learning - 如何在 TensorFlow 中正确实现卷积的 dropout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45189165/

相关文章:

machine-learning - 为什么强盗问题在强化学习中也被称为一步/状态 MDP?

python - 使用多层感知器的 XOR 分类对于所有输入输出 1

python - 朴素贝叶斯 : Imbalanced Test Dataset

python - 如何以数值稳定的方式计算梯度

artificial-intelligence - 关于聚类方法的问题

javascript - 如何提高前馈神经网络的准确性?

matrix - 深度学习模型中不同数量节点的直觉

python - 如何在使用 ImageDataGenerator 时使用 to_categorical

python - 在 tensorflow 中使用保存的估计器时出现 saving_model_cli 问题

python - 如何使用 Keras 创建多输入一输出 LSTM 模型?