dotnet / dotnet/machinelearning

[Image Classification] Very long time to warm-up when doing the first prediction

Open
#4,428 10 comments 0 reactions 0 assignees View on GitHub
area-Vision enhancement Priority:2 tenet-performance
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

I'd like to know if we can do anything to improve the first prediction's needed time when using the new Image Classification model based on DNN (TensorFlow).

This behavior/times happen when using the default DNN architecture which is **ResnetV250**.

When using the CPU, the first prediction takes something in between 7 to 12 seconds depending on the model and environment.
Then, upcoming predictions using the same PredictionEngine only need around 200 mlSecs if using CPU.

![image](https://user-images.githubusercontent.com/1712635/68045426-b09ec580-fc96-11e9-9a38-506089a32cc7.png)

When using a GPU the difference is even larger. Around 15 secs for the first prediction, then a lot less for the next predictions (in this case, something in between 40 mlsecs and 100 mlSecs)

![image](https://user-images.githubusercontent.com/1712635/68045597-1e4af180-fc97-11e9-859e-66ef707f59fc.png)

Basically, after the first prediction, it behaves good, with CPU and even better with GPU, but the first prediction needs a huge amount of time to probably initialize internally?

Could that initialization be improved or happen before calling .Predict()?
I'd like to know if we can do anything to improve the behavior/perf of the first prediction like initializing in advanced when creating the prediction engine instead of when predicting the first time?

@codemzs - Thoughts?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.