GantMan / nsfw_model

Keras model of NSFW detector
Other
1.8k stars 279 forks source link

First prediction is too slow #110

Closed chrystalla closed 1 year ago

chrystalla commented 2 years ago

May someone knows why the first time I run the inference is too slow and then for the next predictions is ok? It needs like 20s to predict the first picture and the second around ~0.5 s

akmalkadi commented 2 years ago

I think because you load the model into your memory. Try to load it when your app runs as a general object/

OttomanZ commented 2 years ago

@chrystalla you may want to go ahead and create a flask rest API where you go ahead and serve NSFW detection requests, this way you can go ahead and save time to load the model in your memory.

Because every time you go ahead and start your script it's gonna go ahead and load the model into your memory not to mention TensorFlow and other packages take a bit of time to load on their own, therefore the above approach is going to be the best one in your use case.

colindean commented 1 year ago

Please reopen if you can provide the version of nsfw_detector that you are using, what Python version, what platform, and a code example. @OttomanZ's advice is accurate.