假设我有一个张量:
x = tf.reshape(tf.constant(tf.range(1, 21, dtype=tf.float32)), (5,4))
<tf.Tensor: id=1080557, shape=(5, 4), dtype=float32, numpy=
array([[ 1., 2., 3., 4.],
[ 5., 6., 7., 8.],
[ 9., 10., 11., 12.],
[13., 14., 15., 16.],
[17., 18., 19., 20.]], dtype=float32)>
我对其应用辍学:
dropout = tf.keras.layers.Dropout(0.1)
dropout(x, training=True)
<tf.Tensor: id=1080704, shape=(5, 4), dtype=float32, numpy=
array([[ 1.1111112, 2.2222223, 3.3333335, 0. ],
[ 5.555556 , 6.666667 , 7.777778 , 8.888889 ],
[10. , 11.111112 , 12.222223 , 0. ],
[14.444445 , 15.555556 , 16.666668 , 17.777779 ],
[18.88889 , 0. , 21.111113 , 22.222223 ]], dtype=float32)>
每次我运行它时,我都有 1 到 3 个不完全归零的值rate=0.1
。它实际适用的费率范围是多少?为什么非归零值会发生变化?
可视化 Celius Stingher 的答案:
l = 10000; r = range(l)
f = np.zeros((5,4))
for i in r:
d = dropout(x, training=True)
f += d
f = f/l
f
<tf.Tensor: id=1234967, shape=(5, 4), dtype=float32, numpy=
array([[ 1.0006623, 1.999991 , 2.988533 , 4.017763 ],
[ 5.000613 , 6.0477467, 7.0076656, 8.0248575],
[ 9.048 , 10.06455 , 10.980609 , 12.010143 ],
[12.918334 , 14.100925 , 15.039784 , 16.014153 ],
[17.0579 , 18.112 , 19.064175 , 20.024672 ]], dtype=float32)>