Model.predict() behavior
See original GitHub issueTensorFlow.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:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
+nsthorat for fromPixels expertise