【发布时间】:2017-06-28 17:44:29
【问题描述】:
我正在使用来自layers 的slim.batch_norm 并试图理解我的用例中的代码流。在我看来,如果输入等级为 2,则决定是否使用 _fused_batch_norm() 或基类将仅使用 _fused_batch_norm() 的逻辑。如果等级为 4,代码描述听起来也应该使用并且函数本身 (_fused_batch_norm()) 支持 4 级,但逻辑似乎阻止调用它。以下是代码的 sn-p,显示了我所指的内容:
# Only use _fused_batch_norm (1) if fused is set True or if it is
# possible to use (currently it doesn't support batch weights,
# renorm, and the case when rank is neither 2 nor 4),
# and (2) if used with zero_debias_moving_mean, or an input shape of rank 2,
# or non-default updates_collections (not implemented in
# normalization_layers.BatchNormalization yet); otherwise use the fused
# implementation in normalization_layers.BatchNormalization.
inputs = ops.convert_to_tensor(inputs)
rank = inputs.get_shape().ndims
feature_supported = batch_weights is None and not renorm and rank in [2, 4]
possible_to_fuse = fused is None and feature_supported
if (fused or possible_to_fuse) and (
zero_debias_moving_mean or rank == 2 or
updates_collections is not ops.GraphKeys.UPDATE_OPS):
return _fused_batch_norm(...)
对于我的用例,我在默认设置下都有以下参数:
batch_weights=None
fused=False
renorm=False
zero_debias_moving_mean=False
updates_collections=ops.GraphKeys.UPDATE_OPS
如果我的输入是 4 级,看起来代码将使用 normalization_layers.BatchNormalization 中的融合实现我对逻辑的理解是否正确?
这是预期的正确行为吗?我想知道条件rank==2 是否实际上应该是rank in [2,4]?如果后者是正确的,那么这将是一个潜在的错误。如果原件是正确的,那为什么还要rank in [2,4]来判断feature_supported呢?
【问题讨论】:
标签: python tensorflow batch-normalization