Kubernetes Tutorial: Part 2 — Streamlit based object detection application
“There’s no place like 127.0.0.1”
This is the second part of the five-part series — “ From Sandbox to K8S: Deploying a Streamlit based object detection application using Minikube.”
In the field of computer vision, object detection is a well defined and matured area; they are a family of algorithms that helps us in identifying and locating objects of interest in an image or a video. I don’t want to rant much about object detection here since there are loads of good quality materials available online to understand this technology. In this tutorial series, we will be deploying two object detection models, namely SSD (Single Shot Detector) and YOLO-v3 (You Only Look Once) build using Pytorch that can detect common objects of interest. Also, we will be leveraging the idea of using pre-trained models instead of training them from scratch, thus saving a lot of time and compute resource. The codes and the models for object detection pipeline that we use here are heavily inspired from here and here. Also, we will be only using the CPUs to run our model.
Putting them together
Since the primary goal of this tutorial is to understand how one can deploy a machine learning model using K8S, we will restrict ourselves to building a simple application which enables users to select the algorithm they want to run, SSD or YOLO, upload an image for which they want to run the inference and see the predictions of the chosen algorithm.
This is how the welcome page looks like:
And this is how it looks when a user runs inference on an image:
As of now, this is directly run on my machine, and that’s evident from the localhost:8501 appearing at the top of the web page. Also, when building such an application, we need to take care that the model weights are persisted in memory as soon as the web page loads; this is essential as it prevents the model from loading into memory every time the user uploads an image for inference, this greatly enhances the user experience. We achieve this using the Streamlit’s inbuilt caching mechanism, the @st.cache decorator.
Now we are all set to take this application that is running in a sandbox environment and deploy the same in Minikube after containerization.