gpt4 book ai didi

python - 当输入等级为 4 时,使用哪种 tensorflow 批标准化代码?

转载 作者:太空宇宙 更新时间:2023-11-03 15:04:08 25 4
gpt4 key购买 nike

我正在使用slim.batch_norm来自layers并尝试理解我的用例中的代码流程。在我看来,这就像决定是否使用_fused_batch_norm()的逻辑或者基类将仅使用_fused_batch_norm()在我的例子中,如果输入等级为 2。代码描述听起来好像如果等级为 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

最佳答案

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

看起来他们混淆了逻辑表达式,如果possible_to_fuse=True应该触发,无论其他一切是什么。此外,如果 feature_supported=True 并且 not fused=False,则 _fused_batch_norm 也符合条件。

您应该将其报告给tensorflow issue tracker .

关于python - 当输入等级为 4 时,使用哪种 tensorflow 批标准化代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44809342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com