Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the value of an item in a tensor in Tensorflow.js

How do I get the value out of a tensor in Tensorflow.js after specifying the index?

like image 648
Pranay Aryal Avatar asked Apr 17 '18 03:04

Pranay Aryal


People also ask

What is the role of TF tidy () in TensorFlow JS?

The . tidy() function is used to execute the given function i.e. fn and once its terminated it clears up all the equidistant tensors that are allotted by the stated function fn excluding the ones that are returned by fn.

What is the value of a tensor?

A tensor is a vector or matrix of n-dimensions that represents all types of data. All values in a tensor hold identical data type with a known (or partially known) shape. The shape of the data is the dimensionality of the matrix or array. A tensor can be originated from the input data or the result of a computation.


1 Answers

You can use datasync for this.

const newTensor = tf.tensor2d([[2,4],[5,6]]);
const tensorData = newTensor.dataSync();
console.log("data[0] is " + tensorData[0]);
console.log("data[3] is " + tensorData[3]);

https://codepen.io/anon/pen/NMKgeO?editors=1011

like image 180
BlessedKey Avatar answered Oct 01 '22 11:10

BlessedKey