【问题标题】:How to add slim.batch_norm after custom ops/layer in tensorflow?如何在 tensorflow 中的自定义操作/层之后添加 slim.batch_norm?
【发布时间】:2018-06-29 15:21:24
【问题描述】:

我有一个旨在构建架构的函数

Input(x) -> o=My_ops(x,128) -> o=slim.batch_norm(o)

所以,我的功能是

def _build_block(self, x, name, is_training=True):
  with tf.variable_scope(name) as scope:
    o = my_ops(x, 256)
    batch_norm_params = {
      'decay': 0.9997,
      'epsilon': 1e-5,
      'scale': True,
      'updates_collections': tf.GraphKeys.UPDATE_OPS,
      'fused': None,  # Use fused batch norm if possible.
      'is_training': is_training
    }
    with slim.arg_scope([slim.batch_norm], **batch_norm_params) as bn:
      return slim.batch_norm(o)

我说的对吗?我可以在上面的函数中设置is_training 吗?如果没有,你能帮我解决吗?

【问题讨论】:

  • 你真的需要arg_scope 来获得一个batch_norm吗?
  • 因为我必须使用像is_training=True这样的客户设置,衰减0.9997,所以我用它来传递bn参数。你有其他方法吗?谢谢

标签: tensorflow deep-learning tf-slim batch-normalization tensorflow-slim


【解决方案1】:

你的功能没问题。是的,您可以像这样将is_training 设置为slim.batch_norm

但您的代码在我看来过于复杂。这是一个等效版本:

def _build_block(self, x, name, is_training=True):
  with tf.variable_scope(name):
    o = my_ops(x, 256)
    return slim.batch_norm(o, decay=0.9997, epsilon=1e-5, scale=True, is_training=is_training)

请注意,我删除了arg_scope(因为它的主要用例是重复 多个层的相同参数,你只有一个),省略了@987654325 @ 和 fused=None(因为这些是默认值),删除了 as scope(因为它没有被使用)。

【讨论】:

    猜你喜欢
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多