Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for Model._make_predict_function #13116

Closed
wants to merge 1 commit into from
Closed

Add documentation for Model._make_predict_function #13116

wants to merge 1 commit into from

Conversation

samwaterbury
Copy link

Summary

This documents the keras.Model._make_predict_function method, which is necessary for keras.Model.predict to function correctly in threads.

Related Issues

Lots of people were looking for documentation on this function and could not find it. See this issue:

#6124

and this stack overflow thread:

https://stackoverflow.com/a/43393252

PR Overview

  • [n] This PR requires new unit tests [y/n] (make sure tests are included)
  • [y] This PR requires to update the documentation [y/n] (make sure the docs are up-to-date)
  • [y] This PR is backwards compatible [y/n]
  • [n] This PR changes the current API [y/n] (all API changes need to be approved by fchollet)

Note: the internal prediction function is not compiled until the first
call to `Model.predict`. If you are using `Model.predict` in a
multi-threaded environment, you should explicitly call
`Model._make_predict_function` first to avoid problems.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_make_predict_function is a private API. We should not recommend calling it.

Here, the user should simply call predict first.

Note that Keras models can't be guaranteed to be thread-safe. Consider having independent copies of the model in each thread for CPU inference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants