So I have h5 Keras Tensorflow Deep Learning model which accepts a NumPy array as an input and gives the desired numerical result in a form of a NumPy array (Python)
Now I want to do the same in tensorflow.js so I converted the model and imported it and used the model.predict function (JavaScript)
const x = tf.tensor2d([company_name])
const output = model.predict(x)
console.log(output)
And I get this as the output
Tensor {
kept: false,
isDisposedInternal: false,
shape: [ 1, 1 ],
dtype: 'float32',
size: 1,
strides: [ 1 ],
dataId: { id: 35 },
id: 52,
rankType: '2',
scopeId: 0
}
I would like to get the actual value of the tensor2d like 38.340986 that I got in the NumPy array. I tried using
model.predict(x.get(0,0));
But it returns a type error
Help is appreciated.
CodePudding user response:
You will need to download the tensors when using Tensorflow.js
const output = model.predict(x).dataSync()
CodePudding user response:
Tensors are the core datastructure of TensorFlow.js They are a generalization of vectors and matrices to potentially higher dimensions.
model.predict(np.array([value1], [value2])))