2017-05-05 161 views
0

batch_norm層我能還原權,偏見和batch_norm層從檢查點文件的模型和提取參數。 但是,對於多個檢查點文件(初始模型等),我無法找到BN層的縮放/伽瑪因子。恢復Tensorflow模型:找不到伽馬/規模在檢查點文件

例如,在公共inceptionV3檢查站,我可以找到: InceptionV3/Mixed_5d/Branch_2/Conv2d_0a_1x1/BatchNorm/moving_mean (DT_FLOAT) [64] InceptionV3/Mixed_5d/Branch_2/Conv2d_0a_1x1/BatchNorm/moving_variance (DT_FLOAT) [64] InceptionV3/Mixed_5d/Branch_2/Conv2d_0a_1x1/BatchNorm/beta (DT_FLOAT) [64]

然而,沒有什麼如InceptionV3/Mixed_5d/Branch_2/Conv2d_0a_1x1/BatchNorm/gamma

我怎樣才能得到gamma值或它在默認情況下重新調整爲1?

非常感謝!

回答

1

我與纖薄庫的預訓練inceptionV2同樣的問題。

首先,我用這個arg_scope,我得到了這個問題:

def _batch_norm_arg_scope(list_ops, 
          use_batch_norm=True, 
          batch_norm_decay=0.9997, 
          batch_norm_epsilon=0.001, 
          batch_norm_scale=False, 
          train_batch_norm=False): 
    """Slim arg scope for InceptionV2 batch norm.""" 
    if use_batch_norm: 
     batch_norm_params = { 
      'is_training': train_batch_norm, 
      'scale': batch_norm_scale, 
      'decay': batch_norm_decay, 
      'epsilon': batch_norm_epsilon 
     } 
     normalizer_fn = slim.batch_norm 
    else: 
     normalizer_fn = None 
     batch_norm_params = None 

    return slim.arg_scope(list_ops, 
          normalizer_fn=normalizer_fn, 
          normalizer_params=batch_norm_params) 

我使用arg_scope在纖薄庫解決。

with slim.arg_scope(inception_v2.inception_v2_arg_scope()): 

,僅僅是:

def inception_arg_scope(weight_decay=0.00004, 
         use_batch_norm=True, 
         batch_norm_decay=0.9997, 
         batch_norm_epsilon=0.001, 
         activation_fn=tf.nn.relu): 
    """Defines the default arg scope for inception models. 

    Args: 
    weight_decay: The weight decay to use for regularizing the model. 
    use_batch_norm: "If `True`, batch_norm is applied after each convolution. 
    batch_norm_decay: Decay for batch norm moving average. 
    batch_norm_epsilon: Small float added to variance to avoid dividing by zero 
     in batch norm. 
    activation_fn: Activation function for conv2d. 

    Returns: 
    An `arg_scope` to use for the inception models. 
    """ 
    batch_norm_params = { 
     # Decay for the moving averages. 
     'decay': batch_norm_decay, 
     # epsilon to prevent 0s in variance. 
     'epsilon': batch_norm_epsilon, 
     # collection containing update_ops. 
     'updates_collections': tf.GraphKeys.UPDATE_OPS, 
     # use fused batch norm if possible. 
     'fused': None, 
    } 
    if use_batch_norm: 
    normalizer_fn = slim.batch_norm 
    normalizer_params = batch_norm_params 
    else: 
    normalizer_fn = None 
    normalizer_params = {} 
    # Set weight_decay for weights in Conv and FC layers. 
    with slim.arg_scope([slim.conv2d, slim.fully_connected], 
         weights_regularizer=slim.l2_regularizer(weight_decay)): 
    with slim.arg_scope(
     [slim.conv2d], 
     weights_initializer=slim.variance_scaling_initializer(), 
     activation_fn=activation_fn, 
     normalizer_fn=normalizer_fn, 
     normalizer_params=normalizer_params) as sc: 
     return sc 
相關問題