当输入秩为4时,使用哪个tensorflow批次规范代码?

2024-06-25 06:29:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用来自layersslim.batch_norm,并试图理解我的用例中的代码流。在我看来,如果输入秩为2,那么决定是使用_fused_batch_norm()还是基类只使用_fused_batch_norm()的逻辑。如果rank为4并且函数本身(_fused_batch_norm())支持rank为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(...)

对于我的用例,以下参数都是默认设置:

^{pr2}$

如果我的输入是秩4,那么看起来代码将使用normalization_layers.BatchNormalization中的融合实现,我对逻辑的理解正确吗?在

这是预期的正确行为吗?我想知道条件rank==2是否应该是rank in [2,4]?如果后者是正确的,那么这将是一个潜在的bug。如果原稿是正确的,那么为什么要用rank in [2,4]来确定{}?在


Tags: orandto代码innormifis
1条回答
网友
1楼 · 发布于 2024-06-25 06:29:16

你说得对,这是个虫子。当rank=4和{}(或True)时,可以而且应该使用优化的_fused_batch_norm。这与^{}一致。在

看起来他们混淆了逻辑表达式,不管其他东西是什么,都应该触发if possible_to_fuse=True。此外,如果feature_supported=True and not fused=False_fused_batch_norm也是合格的。在

你应该报告给tensorflow issue tracker。在

相关问题 更多 >