Tensorflow.js tf.layers apply() Method

Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.
The tf.layers apply() method is used to execute the Layers computation and return Tensor(s) when we call it with the tf.Tensor(s). If we call it with the tf.SymbolicTensor(s) then, will prepare the layer for future execution.
Syntax:
apply (inputs, kwargs)
Parameters:
- inputs: This parameter holds the array as an input.
- kwargs[Optional]: It is an optional parameter that holds an additional keyword argument to be passed to call().
Return Value: It returns the tensor or the symbolicTensor of the same data type.
The below example illustrates the Tensorflow.js tf.layers apply() method:
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs" const denseLayer = tf.layers.dense({ units: 1, kernelInitializer: 'ones', useBias: false}); const input = tf.ones([2, 2]); const output = denseLayer.apply(input); // Print the output print(output) |
Output:
Tensor [[2], [2]]
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs" const denseLayer = tf.layers.dense({ units: 1, kernelInitializer: 'zeros', useBias: false}); const input = tf.ones([2, 2]); const output = denseLayer.apply(input); // Print the output print(output) |
Output:
Tensor [[0], [0]]
Reference: https://js.tensorflow.org/api/latest/#tf.layers.Layer.apply
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!



