question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Property 'print' does not exist on type 'Tensor<Rank>[]'.

See original GitHub issue

If you would like to get help from the community, our Google group might be a better fit.

TensorFlow.js version

0.6.1

Browser version

Describe the problem or feature request

I use Typescript environment (Angular 5)

I trying to run this code from thehttps://js.tensorflow.org/#getting-started

 import * as tf from '@tensorflow/tfjs';

  // Define a model for linear regression.
  const model = tf.sequential();
  model.add(tf.layers.dense({units: 1, inputShape: [1]}));

  // Prepare the model for training: Specify the loss and the optimizer.
  model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});

  // Generate some synthetic data for training.
  const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
  const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);

  // Train the model using the data.
  model.fit(xs, ys).then(() => {
    // Use the model to do inference on a data point the model hasn't seen before:
    model.predict(tf.tensor2d([5], [1, 1])).print();
  });

3

ERROR in src/app/app.component.ts(29,47): error TS2339: Property 'print' does not exist on type 'Tensor<Rank> | Tensor<Rank>[]'.
  Property 'print' does not exist on type 'Tensor<Rank>[]'.

I think is the model.d.ts file please add the print method inside this file

Code to reproduce the bug / link to feature request

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

41reactions
dsmilkovcommented, Apr 1, 2018

Hi @George35mk

We wrote that example for es6 javascript. For typescript, since predict() can return either a Tensor, or Tensor[], depending on how many outputs your model has, you have to notify the compiler which one it is:

(model.predict(...) as tf.Tensor).print()

Hope this helps!

2reactions
grinsteindavidcommented, Oct 3, 2021

const result = model.predict(tf.tensor2d(input, [1, 1])) as tf.Tensor; // this is a tensor

const data = await result.data(); // will return a promise with the Y value ( result )

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tensorflow.js print() and dataSync methods on model.predict ...
Property 'dataSync' does not exist on type 'Tensor<Rank> | Tensor<Rank>[]'. or proptery 'print' ... – Happy Machine. Oct 1, 2018 at 14:24. Is...
Read more >
Introduction to Tensors | TensorFlow Core
Tensor 's data type use the Tensor.dtype property. When creating a tf.Tensor from a Python object you may optionally specify the datatype. If...
Read more >
Source code for hottbox.algorithms.decomposition.cpd
Computed via alternating least squares (ALS) Parameters ---------- init : str Type of factor matrix initialisation. Available options are `svd` and `random` ...
Read more >
Tensor Decompositions and Applications
There are many other tensor decompositions, including INDSCAL, ... This type of result does not hold true for higher-order tensors. For instance,.
Read more >
The Complexity of Tensor Rank
the tensor rank problem remains NP-hard over R and C; this is not immediate, since, ... There are many computational problems related to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found