Principle:Tensorflow Tfjs Layer API Surface
| Knowledge Sources | |
|---|---|
| Domains | Deep_Learning, API_Design, Layers_API |
| Last Updated | 2026-02-10 06:00 GMT |
Overview
Public API surface that exposes layer construction, metric computation, weight initialization, and utility functions through factory functions registered on the tf.layers, tf.metrics, tf.initializers, tf.constraints, and tf.regularizers namespaces.
Description
TensorFlow.js Layers uses a factory function pattern to expose its API. Rather than requiring users to directly instantiate classes, the library provides top-level functions (e.g., tf.layers.dense(), tf.metrics.binaryAccuracy()) that create and return configured layer/metric instances. These factory functions are defined in exports_*.ts files:
- exports_layers.ts: All layer constructors (dense, conv2d, lstm, etc.)
- exports_metrics.ts: Metric functions (accuracy, precision, recall, etc.)
- exports_initializers.ts: Weight initializer factories (glorotUniform, heNormal, etc.)
- exports_constraints.ts: Weight constraint factories (maxNorm, nonNeg, etc.)
- exports_regularizers.ts: Weight regularizer factories (l1, l2, l1l2)
This pattern provides a consistent, discoverable API surface while keeping internal class hierarchies encapsulated.
Usage
Use the factory functions under the tf.layers, tf.metrics, tf.initializers, tf.constraints, and tf.regularizers namespaces when building models. These are the intended public entry points for constructing all TensorFlow.js Layers objects.
Theoretical Basis
Pseudo-code Logic:
// Factory pattern: user-facing function creates internal class instance
// tf.layers.dense({units: 10}) internally calls: new Dense({units: 10})
// tf.regularizers.l2({l2: 0.01}) internally calls: new L2({l2: 0.01})
// Registration pattern using @doc annotations:
function dense(args: DenseLayerArgs): Dense {
return new Dense(args);
}
Related Pages
- Implementation:Tensorflow_Tfjs_Exports_Layers
- Implementation:Tensorflow_Tfjs_Exports_Metrics
- Implementation:Tensorflow_Tfjs_Exports_Initializers
- Implementation:Tensorflow_Tfjs_Exports_Constraints
- Implementation:Tensorflow_Tfjs_Exports_Regularizers
- Implementation:Tensorflow_Tfjs_Generic_Utils
- Implementation:Tensorflow_Tfjs_Layer_Variables
- Implementation:Tensorflow_Tfjs_Layer_Utils
- Implementation:Tensorflow_Tfjs_Training_Utils
- Implementation:Tensorflow_Tfjs_Python_Inference