tensorflow.keras.layers.Layer官网介绍、样例代码

@创建于:20210629
@修改于:20210629

1、Layer官网介绍

| A layer is a callable object that takes as input one or more tensors and that outputs one or more tensors. It involves computation, defined in the call() method, and a state (weight variables), defined either in the constructor __init__() or in the build() method.

层是一个可调用对象,它以一个或多个张量作为输入并输出一个或多个张量。 它涉及在call() 方法中定义的计算,以及在构造函数__init__()build() 方法中定义的state(权重变量)。

We recommend that descendants of Layer implement the following methods:
我们建议 Layer 的后代实现以下方法:

  • __init__(): Defines custom layer attributes, and creates layer state variables that do not depend on input shapes, using add_weight().

  • __init__():定义自定义层属性,并使用 add_weight() 创建不依赖于输入形状的层状态变量。

  • build(self, input_shape): This method can be used to create weights that depend on the shape(s) of the input(s), using add_weight(). __call__() will automatically build the layer (if it has not been built yet) by calling build().

  • build(self, input_shape):此方法可用于创建依赖于输入形状的权重,使用 add_weight()__call__() 将通过调用 build() 自动构建层(如果尚未构建)。

  • call(self, *args, **kwargs): Called in __call__ after making sure build() has been called. call() performs the logic of applying the layer to the input tensors (which should be passed in as argument).

  • Two reserved keyword arguments you can optionally use in call() are:

    • training (boolean, whether the call is in inference mode or training mode)
    • mask (boolean tensor encoding masked timesteps in the input, used in RNN layers)
  • call(self, *args, **kwargs):在确保调用了 build() 之后在 __call__ 中调用。 call() 执行将层应用到输入张量(应该作为参数传入)的逻辑。
    您可以选择在 call() 中使用的两个保留关键字参数是:

    • training(布尔值,无论调用是在推理模式还是训练模式)
    • mask(布尔张量编码输入中的屏蔽时间步长,用于 RNN 层)
  • get_config(self): Returns a dictionary containing the configuration used to

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值