how to use predict in tensorflow js

546 Views Asked by At

I made a model in python and exported it to tensorflow js. The model is classifying facial images to emotions, and there should be 7 categories.

I made a tensor from the image and used predict like so:

const prediction = model.predict(imageTensor);

my prediction is :

Tensor {
  "dataId": Object {},
  "dtype": "float32",
  "id": 415,
  "isDisposedInternal": false,
  "kept": false,
  "rankType": "2",
  "scopeId": 197,
  "shape": Array [
    1,
    7,
  ],
  "size": 7,
  "strides": Array [
    7,
  ],
}

how do I extract the result from here?

2

There are 2 best solutions below

0
On BEST ANSWER

found the answer, I was using typescript and it was needed: const prediction = (model.predict( imageTensor ) as tf.Tensor).dataSync();

1
On

Prediction is a tensor. If you want to access the data, you need to use prediction.dataSync()