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.

Model.predict() behavior

See original GitHub issue

TensorFlow.js version: 0.12.3 Browser version: Chrome 67.0.3396.99

Hello, I’ll try to be brief, if this is a non-known behavior I’ll provide all the information needed to reproduce it. But if it’s known, I would suggest to document it.

In my application main loop I call model.predict(…). If later I call the resulting_tensor.data(), then model.predict takes around 10 miliseconds and tensor.data() around 300 miliseconds. So far so good. However, if I don’t call tensor.data(), and just dispose it, next time model.predict() is called, takes 300 miliseconds instead of 10 ms.

Is this expected? If so, any chance it can be documented?

// test 1
let model = ...
let loop = () => {
    let input = tf.fromPixels(...)
    let t = model.predict(input) // 10ms
    t.data().then((data) => { // 300ms
        input.dispose()
        t.dispose()
        requestAnimationFrame(loop)
    })
}
loop()

// test 2
let model = ...
let loop = () => {
    let input = tf.fromPixels(...)
    let t = model.predict(input) // 300ms
    // use t
    input.dispose()
    t.dispose()
    requestAnimationFrame(loop)
}
loop()

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
nsthoratcommented, Jul 25, 2018

@justadudewhohacks is correct. The time of actually calling “predict” or for that matter any ops is non-blocking. They simply enqueue programs to be run on the GPU. When you call .data(), that is when you introduce a sync between the CPU and the GPU, which means the timing you get after that call will be the “real” timing that it takes to execute that op.

Hope that helps.

0reactions
bileschicommented, Jul 25, 2018

+nsthorat for fromPixels expertise

Read more comments on GitHub >

github_iconTop Results From Across the Web

Predictive Behavior Modeling - Meaning & Advantages
Predictive behavior modeling helps predict the future behavior of customers allowing customer marketers to maximize the effectiveness of their efforts.
Read more >
Chapter 2 Predicting Behavior with Classification Models
The function knn_classifier() predicts the class for each test set instance and returns a list with their predictions and their ground truth classes....
Read more >
Propensity Modeling: Using Data (and Expertise) to Predict ...
Propensity modeling is an approach that attempts to predict the likelihood that visitors, leads, and customers will perform certain actions.
Read more >
Keras model predictions with strange behavior: High acc while ...
I still think it has something to do with the BatchNormalization() layer, although it has never happened with my other models before.
Read more >
What is Keras model predict? |How to use? - eduCBA
Using Keras model predict Compilation. We will have to compile the Keras model by using the method of Keras called compile() which takes...
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