Abstract List of InputSpec class instances.
Each entry describes one required input:
n input tensors must have an inputSpec of length n.Name for this layer. Must be unique within a model.
Abstract stateSize(s) of the states. For RNN cells with only a single state, this is a single integer.
Protected trainable_Whether the layer weights will be updated during training.
Retrieves the input tensor(s) of a layer.
Only applicable if the layer has exactly one inbound node, i.e. if it is connected to one incoming layer.
Input tensor or list of input tensors.
AttributeError if the layer is connected to more than one incoming layers.
Retrieves the output tensor(s) of a layer.
Only applicable if the layer has exactly one inbound node, i.e. if it is connected to one incoming layer.
Output tensor or list of output tensors.
AttributeError if the layer is connected to more than one incoming layers.
Retrieves the output shape(s) of a layer.
Only applicable if the layer has only one inbound node, or if all inbound nodes have the same output shape.
Output shape or shapes.
AttributeError: if the layer is connected to more than one incoming nodes.
The concatenation of the lists trainableWeights and nonTrainableWeights (in this order).
Protected addAdds a weight variable to the layer.
Name of the new weight variable.
The shape of the weight.
Optional dtype: keyof DataTypeMapThe dtype of the weight.
Optional initializer: InitializerAn initializer instance.
Optional regularizer: RegularizerA regularizer instance.
Optional trainable: booleanWhether the weight should be trained via backprop or not (assuming that the layer itself is also trainable).
Optional constraint: ConstraintAn optional trainable.
Optional getInitializerFunc: FunctionThe created weight variable.
Builds or executes a Layer's logic.
When called with tf.Tensor(s), execute the Layer's computation and
return Tensor(s). For example:
const denseLayer = tf.layers.dense({
units: 1,
kernelInitializer: 'zeros',
useBias: false
});
// Invoke the layer's apply() method with a `tf.Tensor` (with concrete
// numeric values).
const input = tf.ones([2, 2]);
const output = denseLayer.apply(input);
// The output's value is expected to be [[0], [0]], due to the fact that
// the dense layer has a kernel initialized to all-zeros and does not have
// a bias.
output.print();
When called with tf.SymbolicTensor(s), this will prepare the layer for
future execution. This entails internal book-keeping on shapes of
expected Tensors, wiring layers together, and initializing weights.
Calling apply with tf.SymbolicTensors are typically used during the
building of non-tf.Sequential models. For example:
const flattenLayer = tf.layers.flatten();
const denseLayer = tf.layers.dense({units: 1});
// Use tf.layers.input() to obtain a SymbolicTensor as input to apply().
const input = tf.input({shape: [2, 2]});
const output1 = flattenLayer.apply(input);
// output1.shape is [null, 4]. The first dimension is the undetermined
// batch size. The second dimension comes from flattening the [2, 2]
// shape.
console.log(JSON.stringify(output1.shape));
// The output SymbolicTensor of the flatten layer can be used to call
// the apply() of the dense layer:
const output2 = denseLayer.apply(output1);
// output2.shape is [null, 1]. The first dimension is the undetermined
// batch size. The second dimension matches the number of units of the
// dense layer.
console.log(JSON.stringify(output2.shape));
// The input and output can be used to construct a model that consists
// of the flatten and dense layers.
const model = tf.model({inputs: input, outputs: output2});
a tf.Tensor or tf.SymbolicTensor or an Array of them.
Optional kwargs: KwargsAdditional keyword arguments to be passed to call().
Output of the layer's call method.
ValueError error in case the layer is missing shape information
for its build call.
Protected assertChecks compatibility between the layer and provided inputs.
This checks that the tensor(s) input
verify the input assumptions of the layer
(if any). If not, exceptions are raised.
Input tensor or list of input tensors.
ValueError in case of mismatch between the provided inputs and the expectations of the layer.
Attempt to dispose layer's weights.
This method decreases the reference count of the Layer object by 1.
A Layer is reference-counted. Its reference count is incremented by 1
the first item its apply() method is called and when it becomes a part
of a new Node (through calling the apply() method on a
tf.SymbolicTensor).
If the reference count of a Layer becomes 0, all the weights will be disposed and the underlying memory (e.g., the textures allocated in WebGL) will be freed.
Note: If the reference count is greater than 0 after the decrement, the weights of the Layer will not be disposed.
After a Layer is disposed, it cannot be used in calls such as apply(),
getWeights() or setWeights() anymore.
A DisposeResult Object with the following fields:
dispose() call.tf.Variables (i.e., weights) disposed
during this dispose() call.If the layer is not built yet, or if the layer has already been disposed.
Protected disposeReturn the class name for this class to use in serialization contexts.
Generally speaking this will be the same thing that constructor.name would have returned. However, the class name needs to be robust against minification for serialization/deserialization to work properly.
There's also places such as initializers.VarianceScaling, where implementation details between different languages led to different class hierarchies and a non-leaf node is used for serialization purposes.
Returns the config of the layer.
A layer config is a TS dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by 'Container' (one layer of abstraction above).
Porting Note: The TS dictionary follows TS naming standards for keys, and uses tfjs-layers type-safe Enums. Serialization methods should use a helper function to convert to the pythonic storage standard. (see serialization_utils.convertTsToPythonic)
TS dictionary of configuration.
Retrieves the input tensor(s) of a layer at a given node.
Integer, index of the node from which to retrieve the
attribute. E.g. nodeIndex=0 will correspond to the first time the layer
was called.
A tensor (or list of tensors if the layer has multiple inputs).
Retrieves the output tensor(s) of a layer at a given node.
Integer, index of the node from which to retrieve the
attribute. E.g. nodeIndex=0 will correspond to the first time the layer
was called.
A tensor (or list of tensors if the layer has multiple outputs).
Set the fast-weight-initialization flag.
In cases where the initialized weight values will be immediately
overwritten by loaded weight values during model loading, setting
the flag to true saves unnecessary calls to potentially expensive
initializers and speeds up the loading process.
Target value of the flag.
Sets the weights of the layer, from Tensors.
a list of Tensors. The number of arrays and their shape
must match number of the dimensions of the weights of the layer (i.e.
it should match the output of getWeights).
ValueError If the provided weights list does not match the layer's specifications.
Protected warnCheck compatibility between input shape and this layer's batchInputShape.
Print warning if any incompatibility is found.
Input shape to be checked.
Static fromProtected Static nodeConverts a layer and its index to a unique (immutable type) name.
This function is used internally with this.containerNodes.
The layer.
The layer's position (e.g. via enumerate) in a list of nodes.
The unique name.
Generated using TypeDoc
An RNNCell layer.
Doc