.apply 对 keras 层有什么作用?有没有办法省略它或任何其他替代方法来获得相同的输出而不使用 .apply?

What does .apply do for a keras layer? Is there a way to omit it or any other alternative way to get the same output without using .apply?

有人可以解释一下 .apply(input_feature) 的实际作用吗?

VFE_1_layer = tf.keras.layers.Dense(16, tf.nn.relu)
vfe_1_out = VFE_1_layer.apply(feature)

Layer.apply 已弃用。推荐的替代方法是使用 Layer.__call__ 代替(这可以通过简单地 调用 来完成):

dense = tf.keras.layers.Dense(16, activation='relu')
new_feature = dense(feature)

这被称为 函数式 API 风格。


您可以找到弃用通知here:

class Layer:
  ...

  @deprecation.deprecated(
      date=None, instructions='Please use `layer.__call__` method instead.')
  @doc_controls.do_not_doc_inheritable
  def apply(self, inputs, *args, **kwargs):
    """Deprecated, do NOT use!

    This is an alias of `self.__call__`.

    Arguments:
      inputs: Input tensor(s).
      *args: additional positional arguments to be passed to `self.call`.
      **kwargs: additional keyword arguments to be passed to `self.call`.

    Returns:
      Output tensor(s).
    """
    return self.__call__(inputs, *args, **kwargs)