【发布时间】:2018-07-15 01:05:59
【问题描述】:
我的问题到最后了。
一个example CNN 使用 mini-batch GD 训练,并使用最后一个全连接层(第 60 行)中的 dropout 作为
fc1 = tf.layers.dropout(fc1, rate=dropout, training=is_training)
起初我认为tf.layers.dropout 或tf.nn.dropout 在列中随机将神经元设置为零。但我最近发现情况并非如此。下面的代码打印了dropout 的作用。我使用fc0 作为 4 x 10 特征矩阵,fc 作为 drop out 版本。
import tensorflow as tf
import numpy as np
fc0 = tf.random_normal([4, 10])
fc = tf.nn.dropout(fc0, 0.5)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
a, b = sess.run([fc0, fc])
np.savetxt("oo.txt", np.vstack((a, b)), fmt="%.2f", delimiter=",")
在输出oo.txt(原始矩阵:第1-4行,丢弃矩阵:第5-8行):
0.10,1.69,0.36,-0.53,0.89,0.71,-0.84,0.24,-0.72,-0.44
0.88,0.32,0.58,-0.18,1.57,0.04,0.58,-0.56,-0.66,0.59
-1.65,-1.68,-0.26,-0.09,-1.35,-0.21,1.78,-1.69,-0.47,1.26
-1.52,0.52,-0.99,0.35,0.90,1.17,-0.92,-0.68,-0.27,0.68
0.20,0.00,0.71,-0.00,0.00,0.00,-0.00,0.47,-0.00,-0.87
0.00,0.00,0.00,-0.00,3.15,0.07,1.16,-0.00,-1.32,0.00
-0.00,-3.36,-0.00,-0.17,-0.00,-0.42,3.57,-3.37,-0.00,2.53
-0.00,1.05,-1.99,0.00,1.80,0.00,-0.00,-0.00,-0.55,1.35
我对 正确的? dropout 的理解是,在 mini-batch 或 中为每个样本剔除 p% same 单位>batch梯度下降阶段,反向传播更新“细化网络”的权重和偏差。然而,在example的实现中,一个批次中每个样本的神经元被随机丢弃,如oo.txt第5到8行所示,对于每个样本,“细化网络”是不同。
作为比较,在随机梯度下降的情况下,样本被一个一个地输入神经网络,并且在每次迭代中,每个 tf.layers.dropout 引入的“细化网络”的权重都会更新。
我的问题是,在 mini-batch 或 batch 训练中,不应该实现为一批中的所有样本敲除相同的神经元吗?也许通过在每次迭代中对所有输入批次样本应用一个掩码? 比如:
# ones: a 1xN all 1s tensor
# mask: a 1xN 0-1 tensor, multiply fc1 by mask with broadcasting along the axis of samples
mask = tf.layers.dropout(ones, rate=dropout, training=is_training)
fc1 = tf.multiply(fc1, mask)
现在我在想example 中的 dropout 策略可能是更新某个神经元权重的加权方式,如果一个神经元保持在 10 个样本中的 1 个中mini-batch,它的权重将更新alpha * 1/10 * (y_k_hat-y_k) * x_k,与alpha * 1/10 * sum[(y_k_hat-y_k) * x_k]相比,在所有10个样本中保存另一个神经元的权重?
来自here的截图
【问题讨论】:
标签: tensorflow machine-learning neural-network gradient-descent mini-batch