@创建于: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, usingadd_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), usingadd_weight().__call__()will automatically build the layer (if it has not been built yet) by callingbuild(). -
build(self, input_shape):此方法可用于创建依赖于输入形状的权重,使用add_weight()。__call__()将通过调用build()自动构建层(如果尚未构建)。 -
call(self, *args, **kwargs): Called in__call__after making surebuild()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

最低0.47元/天 解锁文章
9391

被折叠的 条评论
为什么被折叠?



