|TensorFlow 1 version||View source on GitHub|
This is the class from which all layers inherit.
Compat aliases for migration
See Migration guide for more details.
tf.keras.layers.Layer( trainable=True, name=None, dtype=None, dynamic=False, **kwargs )
Used in the notebooks
|Used in the guide||Used in the tutorials|
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
call() method, and a state (weight variables), defined
either in the constructor
__init__() or in the
Users will just instantiate a layer and then treat it as a callable.
||Boolean, whether the layer's variables should be trainable.|
||String name of the layer.|
The dtype of the layer's computations and weights. Can also be a
Set this to
We recommend that descendants of
Layer implement the following methods:
__init__(): Defines custom layer attributes, and creates layer state variables that do not depend on input shapes, using
build(self, input_shape): This method can be used to create weights that depend on the shape(s) of the input(s), using
__call__()will automatically build the layer (if it has not been built yet) by calling
call(self, inputs, *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
training(boolean, whether the call is in inference mode or training mode). See more details in the layer/model subclassing guide
mask(boolean tensor encoding masked timesteps in the input, used in RNN layers). See more details in the layer/model subclassing guide A typical signature for this method is