Tensorflow.js tf.keep() Function
Last Updated :
01 Jun, 2021
Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.
The .keep() function is used to hold a tensor input that is formed within a tf.tidy() method from being spontaneously discarded.
Syntax:
tf.keep(result)
Parameters:
- result: It is the stated tensor input which is to be held from being discarded.
Return Value: It returns tf.Tensor object.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
let res1;
const res2 = tf.tidy(() => {
const result = tf.scalar(121);
res1 = tf.keep(result.sqrt());
});
res1.print();
|
Output:
Tensor
11
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
let res1;
const res2 = tf.tidy(() => {
res1 = tf.keep(tf.tensor1d(
[1.3, 0.5, 0, NaN, null , -.5]).cos());
});
res1.print();
|
Output:
Tensor
[0.2675007, 0.8775977, 1, NaN, 1, 0.8775977]
Reference: https://js.tensorflow.org/api/latest/#keep
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...