Type Lambda
Namespace tensorflow.keras.layers
Parent Layer
Interfaces ILambda
Wraps arbitrary expressions as a `Layer` object. The `Lambda` layer exists so that arbitrary TensorFlow functions
can be used when constructing `Sequential` and Functional API
models. `Lambda` layers are best suited for simple operations or
quick experimentation. For more advanced use cases, subclassing
`keras.layers.Layer` is preferred. One reason for this is that
when saving a Model, `Lambda` layers are saved by serializing the
Python bytecode, whereas subclassed Layers are saved via overriding
their `get_config` method and are thus more portable. Models that rely
on subclassed Layers are also often easier to visualize and reason
about. Examples: Variables can be created within a `Lambda` layer. Like with
other layers, these variables will be created only once and reused
if the `Lambda` layer is called on new inputs. If creating more
than one variable in a given `Lambda` instance, be sure to use
a different name for each variable. Note that calling sublayers
from within a `Lambda` is not supported. Example of variable creation:
Note that creating two instances of `Lambda` using the same function
will *not* share Variables between the two instances. Each instance of
`Lambda` will create and manage its own weights.
Show Example
# add a x -> x^2 layer model.add(Lambda(lambda x: x ** 2))
Methods
Properties
- activity_regularizer
- activity_regularizer_dyn
- arguments
- built
- dtype
- dtype_dyn
- dynamic
- dynamic_dyn
- function
- inbound_nodes
- inbound_nodes_dyn
- input
- input_dyn
- input_mask
- input_mask_dyn
- input_shape
- input_shape_dyn
- input_spec
- input_spec_dyn
- losses
- losses_dyn
- mask
- metrics
- metrics_dyn
- name
- name_dyn
- name_scope
- name_scope_dyn
- non_trainable_variables
- non_trainable_variables_dyn
- non_trainable_weights
- non_trainable_weights_dyn
- outbound_nodes
- outbound_nodes_dyn
- output
- output_dyn
- output_mask
- output_mask_dyn
- output_shape
- output_shape_dyn
- PythonObject
- stateful
- submodules
- submodules_dyn
- supports_masking
- trainable
- trainable_dyn
- trainable_variables
- trainable_variables_dyn
- trainable_weights
- trainable_weights_dyn
- updates
- updates_dyn
- variables
- variables_dyn
- weights
- weights_dyn