当某些层被冻结(不可训练)时,在迁移学习期间如何在 Keras mobilenet v3 imagenet 权重中实现丢失?
How dropout is implemented in Keras mobilenet v3 imagenet weights during transfer learning when some layers are frozen (made un-trainable)?
我正在处理图像分类问题,并在 ImageNet 上使用 90% 的预训练 Keras mobilenet v3,并在应用 0.2 的 dropout 时使剩余的 10% 层可训练。我想知道这是如何在后端处理的。
MobileNetV3Small(input_shape=(IMG_HEIGHT, IMG_WIDTH, DEPTH),
alpha=1.0,
minimalistic=False,
include_top=False,
weights='imagenet',
input_tensor=None,
pooling='max',
dropout_rate=0.2)
如果使用参数 training=False
调用图层,就像您预测时一样,什么也不会发生。让我们从一些输入开始:
import tensorflow as tf
rate = 0.4
dropout = tf.keras.layers.Dropout(rate)
x = tf.cast(tf.reshape(tf.range(1, 10), (3, 3)), tf.float32)
<tf.Tensor: shape=(3, 3), dtype=float32, numpy=
array([[1., 2., 3.],
[4., 5., 6.],
[7., 8., 9.]], dtype=float32)>
现在,让我们在训练时调用 dropout 模型:
dropout(x, training=True)
<tf.Tensor: shape=(3, 3), dtype=float32, numpy=
array([[ 0. , 3.3333333, 0. ],
[ 6.6666665, 8.333333 , 0. ],
[11.666666 , 13.333333 , 15. ]], dtype=float32)>
如您所见,所有剩余值都乘以 1/(1-p)
。现在让我们在 training=False
:
时调用网络
dropout(x, training=False)
<tf.Tensor: shape=(3, 3), dtype=float32, numpy=
array([[1., 2., 3.],
[4., 5., 6.],
[7., 8., 9.]], dtype=float32)>
没有任何反应。
我正在处理图像分类问题,并在 ImageNet 上使用 90% 的预训练 Keras mobilenet v3,并在应用 0.2 的 dropout 时使剩余的 10% 层可训练。我想知道这是如何在后端处理的。
MobileNetV3Small(input_shape=(IMG_HEIGHT, IMG_WIDTH, DEPTH),
alpha=1.0,
minimalistic=False,
include_top=False,
weights='imagenet',
input_tensor=None,
pooling='max',
dropout_rate=0.2)
如果使用参数 training=False
调用图层,就像您预测时一样,什么也不会发生。让我们从一些输入开始:
import tensorflow as tf
rate = 0.4
dropout = tf.keras.layers.Dropout(rate)
x = tf.cast(tf.reshape(tf.range(1, 10), (3, 3)), tf.float32)
<tf.Tensor: shape=(3, 3), dtype=float32, numpy=
array([[1., 2., 3.],
[4., 5., 6.],
[7., 8., 9.]], dtype=float32)>
现在,让我们在训练时调用 dropout 模型:
dropout(x, training=True)
<tf.Tensor: shape=(3, 3), dtype=float32, numpy=
array([[ 0. , 3.3333333, 0. ],
[ 6.6666665, 8.333333 , 0. ],
[11.666666 , 13.333333 , 15. ]], dtype=float32)>
如您所见,所有剩余值都乘以 1/(1-p)
。现在让我们在 training=False
:
dropout(x, training=False)
<tf.Tensor: shape=(3, 3), dtype=float32, numpy=
array([[1., 2., 3.],
[4., 5., 6.],
[7., 8., 9.]], dtype=float32)>
没有任何反应。