An end to end project which shows how to deploy a Tensorflow model on Google Cloud
View Demo »
This project demonstrates how to train a ML model with TensorFlow and deploy the model to Google Cloud Run with the help of Cloud Build and Docker.
Set up the project locally.
- Python
- Pip
- Google Cloud SDK
-
Clone the repo
git clone https://github.com/pratikkalein/deploy-tf-cloud-run.git
-
Create and activate virtual environment
python3 -m venv venv source venv/bin/activate
-
Install requirements.txt
pip install -r requirements.txt
-
Open and run the 01-train.py file
python3 01-train.py
You can try playing with the batch size and epochs. Once the training is done a
.keras
file will be saved into the root directory. -
Run the 02-load.py file to load and test the output of the model.
python3 02-load.py
-
Change your current working directory to
deploy
cd deploy
-
Make sure you are authenticated with gcloud CLI
gcloud auth login
Your default browser will open once you run this command. Choose your Google account.
-
Observe the 03-main.py file to understand how the flask API is working. Start the build using gcloud CLI.
gcloud builds submit --tag gcr.io/<project_id>/<function_name>
It usually takes 3-4 mins to build.
-
Once the build is done deploy to cloud run.
gcloud run deploy --image gcr.io/<project_id>/<function_name> --platform managed
It usually takes 3-4 mins to deploy.
-
Go to Google Cloud Console and open Cloud run. You can find the URL endpoint.
- Open the 04-st-app.py and add the URL you got from Cloud run and paste it at the location mentioned in the file.
- Run the file.
streamlit run 04-st-app.py
- Upload the image and test the prediction output.
Distributed under the MIT License. See LICENSE.txt
for more information.
Pratik Kale
Twitter - @pratikkalein LinkedIn- /in/pratikkalein
Project Link: https://github.com/pratikkalein/deploy-tf-cloud-run Demo Link : http://pratik.tech/tf-run-demo