Skip to content

How To Deploy ML Models With Google Cloud Run

Learn how to deploy Machine Learning models with Google Cloud Run.


Learn how to deploy Machine Learning / Deep Learning models with Google Cloud Run. We build a simple app with TensorFlow and Flask, containerize it with Docker, and deploy it to Google Cloud Run.

You can find the code on GitHub: https://github.com/patrickloeber/ml-deployment.

1. Write App (Flask, TensorFlow)

  • The code to build, train, and save the model is in the test folder.
  • Implement the app in main.py

2. Setup Google Cloud

  • Create new project
  • Activate Cloud Run API and Cloud Build API

3. Install and init Google Cloud SDK

4. Dockerfile, requirements.txt, .dockerignore

5. Cloud build & deploy

gcloud builds submit --tag gcr.io/<project_id>/<function_name>
gcloud run deploy --image gcr.io/<project_id>/<function_name> --platform managed

Test

  • Test the code with test/test.py

FREE VS Code / PyCharm Extensions I Use

✅ Write cleaner code with Sourcery, instant refactoring suggestions: Link*


Python Problem-Solving Bootcamp

🚀 Solve 42 programming puzzles over the course of 21 days: Link*

* These are affiliate link. By clicking on it you will not have any additional costs. Instead, you will support my project. Thank you! 🙏