【问题标题】:How dropout is implemented in Keras mobilenet v3 imagenet weights during transfer learning when some layers are frozen (made un-trainable)?当某些层被冻结(不可训练)时,在迁移学习期间如何在 Keras mobilenet v3 imagenet 权重中实现 dropout?
【发布时间】:2021-04-24 17:00:57
【问题描述】:

我正在研究一个图像分类问题,在 ImageNet 上使用了 90% 的预训练 Keras mobilenet v3,其余 10% 的层在应用 0.2 的 dropout 时可训练。我想知道这是如何在后端处理的。

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)

【问题讨论】:

    标签: python-3.x keras deep-learning imagenet


    【解决方案1】:

    如果使用参数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)>
    

    什么都没有发生。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-23
      • 2021-08-25
      • 1970-01-01
      • 2019-10-06
      • 2020-03-20
      • 1970-01-01
      • 1970-01-01
      • 2018-07-13
      相关资源
      最近更新 更多