我正在使用slim.batch_norm
分层并试图理解我的用例中的代码流。在我看来,如果输入等级为 2,则决定是否使用_fused_batch_norm()
或基类仅_fused_batch_norm()
在我的情况下使用的逻辑。如果等级为 4 并且函数本身(_fused_batch_norm),代码描述听起来也应该使用()) 支持 4 级,但逻辑似乎阻止调用它。以下是显示我所指内容的代码片段:
# 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
呢?