Tensorflow.js tf.layers apply() Method
Last Updated :
22 Apr, 2022
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(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(output)
|
Output:
Tensor [[0], [0]]
Reference: https://js.tensorflow.org/api/latest/#tf.layers.Layer.apply
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...