【问题标题】:Which tensorflow batch norm code is used when input rank is 4?输入秩为 4 时使用哪个 tensorflow 批处理规范代码?
【发布时间】:2017-06-28 17:44:29
【问题描述】:

我正在使用来自layersslim.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


    【解决方案1】:

    你是对的,这是一个错误。当rank=4fused=None(或True)时,可以并且应该使用优化的_fused_batch_norm。这与tf.nn.fused_batch_norm 一致。

    看起来他们混淆了逻辑表达式,如果possible_to_fuse=True 应该触发,不管其他是什么。此外,如果feature_supported=True and not fused=False_fused_batch_norm 也符合条件。

    你应该报告给tensorflow issue tracker

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-11
      相关资源
      最近更新 更多