WARNING:tensorflow:`add_update` `inputs` kwarg has been deprecated.

这篇博客介绍了在TensorFlow 2.x中,由于`add_update`方法的`inputs`参数已弃用,导致自定义BN层出现警告的问题。在TF1.x中,该参数用于指定更新操作依赖的输入,但在TF2.x中,它将自动推断。解决警告的方法是将`self.add_update([...], inputs)`改为`self.add_update([...])`,以消除警告。
摘要由CSDN通过智能技术生成

    使用tensorflow 1x定义的层在tf2中使用提示警告:

WARNING:tensorflow:`add_update` `inputs` kwarg has been deprecated.

    检查是自定义BN层中采用self.add_update([...], inputs)的写法,而在tf2x版本中使用autoGraph,inputs参数已经被淘汰了,当然写了也会兼容,但是会被警告。修改为:self.add_update([...])则可以免除警告的骚扰。

https://github.com/tensorflow/tensorflow/blob/r2.1/tensorflow/python/keras/engine/base_layer.py

  @deprecation.deprecated_args(None, '`inputs` is now automatically inferred',
                               'inputs')
  @doc_controls.for_subclass_implementers
  def add_update(self, updates, inputs=None):
    """Add update op(s), potentially dependent on layer inputs.
    Weight updates (for instance, the updates of the moving mean and variance
    in a BatchNormalization layer) may be dependent on the inputs passed
    when calling a layer. Hence, when reusing the same layer on
    different inputs `a` and `b`, some entries in `layer.updates` may be
    dependent on `a` and some on `b`. This method automatically keeps track
    of dependencies.
    The `get_updates_for` method allows to retrieve the updates relevant to a
    specific set of inputs.
    This call is ignored when eager execution is enabled (in that case, variable
    updates are run on the fly and thus do not need to be tracked for later
    execution).
    Arguments:
      updates: Update op, or list/tuple of update ops, or zero-arg callable
        that returns an update op. A zero-arg callable should be passed in
        order to disable running the updates by setting `trainable=False`
        on this Layer, when executing in Eager mode.
      inputs: Deprecated, will be automatically inferred.
    """

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值