![]() |
A Keras layer for applying a tf.Transform output to input layers.
tft.TransformFeaturesLayer(
tft_output: tft.TFTransformOutput
,
exported_as_v1: Optional[bool] = None
)
Attributes | |
---|---|
activity_regularizer
|
Optional regularizer function for the output of this layer. |
distribute_strategy
|
The tf.distribute.Strategy this model was created under.
|
dtype
|
Dtype used by the weights of the layer, set in the constructor. |
dynamic
|
Whether the layer is dynamic (eager-only); set in the constructor. |
input
|
Retrieves the input tensor(s) of a layer.
Only applicable if the layer has exactly one input, i.e. if it is connected to one incoming layer. |
input_spec
|
InputSpec instance(s) describing the input format for this layer.
When you create a layer subclass, you can set
Now, if you try to call the layer on an input that isn't rank 4
(for instance, an input of shape
Input checks that can be specified via
For more information, see |
layers
|
|
losses
|
List of losses added using the add_loss() API.
Variable regularization tensors are created when this property is accessed,
so it is eager safe: accessing
|
metrics
|
Returns the model's metrics added using compile , add_metric APIs.
|
metrics_names
|
Returns the model's display labels for all outputs.
|
name
|
Name of the layer (string), set in the constructor. |
name_scope
|
Returns a tf.name_scope instance for this class.
|
non_trainable_weights
|
List of all non-trainable weights tracked by this layer.
Non-trainable weights are not updated during training. They are expected
to be updated manually in |
output
|
Retrieves the output tensor(s) of a layer.
Only applicable if the layer has exactly one output, i.e. if it is connected to one incoming layer. |
run_eagerly
|
Settable attribute indicating whether the model should run eagerly.
Running eagerly means that your model will be run step by step, like Python code. Your model might run slower, but it should become easier for you to debug it by stepping into individual layer calls. By default, we will attempt to compile your model to a static graph to deliver the best execution performance. |
submodules
|
Sequence of all sub-modules.
Submodules are modules which are properties of this module, or found as properties of modules which are properties of this module (and so on).
|
supports_masking
|
Whether this layer supports computing a mask using compute_mask .
|
trainable
|
|
trainable_weights
|
List of all trainable weights tracked by this layer.
Trainable weights are updated via gradient descent during training. |
weights
|
Returns the list of all layer variables/weights. |
Methods
add_loss
add_loss(
losses, **kwargs
)
Add loss tensor(s), potentially dependent on layer inputs.
Some losses (for instance, activity regularization losses) may be dependent
on the inputs passed when calling a layer. Hence, when reusing the same
layer on different inputs a
and b
, some entries in layer.losses
may
be dependent on a
and some on b
. This method automatically keeps track
of dependencies.
This method can be used inside a subclassed layer or model's call
function, in which case losses
should be a Tensor or list of Tensors.
Example:
class MyLayer(tf.keras.layers.Layer):
def call(self, inputs):
self.add_loss(tf.abs(tf.reduce_mean(inputs)))
return inputs
This method can also be called directly on a Functional Model during
construction. In this case, any loss Tensors passed to this Model must
be symbolic and be able to be traced back to the model's Input
s. These
losses become part of the model's topology and are tracked in get_config
.
Example:
inputs = tf.keras.Input(shape=(10,))
x = tf.keras.layers.Dense(10)(inputs)
outputs = tf.keras.layers.Dense(1)(x)
model = tf.keras.Model(inputs, outputs)
# Activity regularization.
model.add_loss(tf.abs(tf.reduce_mean(x)))
If this is not the case for your loss (if, for example, your loss references
a Variable
of one of the model's layers), you can wrap your loss in a
zero-argument lambda. These losses are not tracked as part of the model's
topology since they can't be serialized.
Example:
inputs = tf.keras.Input(shape=(10,))
d = tf.keras.layers.Dense(10)
x = d(inputs)
outputs = tf.keras.layers.Dense(1)(x)
model = tf.keras.Model(inputs, outputs)
# Weight regularization.
model.add_loss(lambda: tf.reduce_mean(d.kernel))
Arguments | |
---|---|
losses
|
Loss tensor, or list/tuple of tensors. Rather than tensors, losses may also be zero-argument callables which create a loss tensor. |
**kwargs
|
Additional keyword arguments for backward compatibility. Accepted values: inputs - Deprecated, will be automatically inferred. |
build
build(
input_shape
)
Builds the model based on input shapes received.
This is to be used for subclassed models, which do not know at instantiation time what their inputs look like.
This method only exists for users who want to call model.build()
in a
standalone way (as a substitute for calling the model on real data to
build it). It will never be called by the framework (and thus it will
never throw unexpected errors in an unrelated workflow).
Args | |
---|---|
input_shape
|
Single tuple, TensorShape, or list of shapes, where shapes are tuples, integers, or TensorShapes. |
Raises | |
---|---|
ValueError
|
In each of these cases, the user should build their model by calling it on real tensor data. |
compute_mask
compute_mask(
inputs, mask=None
)
Computes an output mask tensor.
Arguments | |
---|---|
inputs
|
Tensor or list of tensors. |
mask
|
Tensor or list of tensors. |
Returns | |
---|---|
None or a tensor (or list of tensors, one per output tensor of the layer). |
__call__
__call__(
*args, **kwargs
)
Wraps call
, applying pre- and post-processing steps.
Arguments | |
---|---|
*args
|
Positional arguments to be passed to self.call .
|
**kwargs
|
Keyword arguments to be passed to self.call .
|
Returns | |
---|---|
Output tensor(s). |
Note:
- The following optional keyword arguments are reserved for specific uses:
training
: Boolean scalar tensor of Python boolean indicating whether thecall
is meant for training or inference.mask
: Boolean input mask.
- If the layer's
call
method takes amask
argument (as some Keras layers do), its default value will be set to the mask generated forinputs
by the previous layer (ifinput
did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support.
Raises | |
---|---|
ValueError
|
if the layer's call method returns None (an invalid value).
|
RuntimeError
|
if super().__init__() was not called in the constructor.
|