Covid-19 Detection by analyzing Chest X-Ray Images-II.

A step-by-step guide to deploy a Deep Learning model as a web application on Google Cloud Platform’s App Engine service.

Shaunak Varudandi
Geek Culture

--

Photo by Jonathan Borba on Unsplash

Introduction

Coronavirus (COVID-19) is an infectious disease caused by related RNA viruses that affect mammals and birds. After the first case was reported in Wuhan, China in December 2019, Coronavirus became a global pandemic that has caused around 3.8 million deaths (as of 18th June) around the world. One of the techniques to diagnose if a patient is suffering from Covid-19 is to study their chest x-rays to look for evidence of probable infection and later, administer the requisite treatment to cure them of the disease.

I decided to automate this process of diagnosis by leveraging the power of pre-trained Deep Learning models. The deep learning model would analyze the image of a chest x-ray and help faster diagnose the covid-19 virus.

The following article can be considered as Part 2 of the Chest X-Ray Classifier project, and this article aims to elaborate on the steps needed to successfully deploy a Deep Learning model on Google Cloud Platform’s App Engine service. Readers of the following article who haven’t read Part 1 of the Chest X-Ray Classifier project can do so via the following link.

Problem Statement

To develop a web application that analyzes a chest x-ray and determines whether a patient is positive or negative for Covid-19.

Work Flow

In my first article on the chest x-ray classifier project, I enlisted the help of a pre-trained deep learning model which was ResNet50. I used it as my base model and built the rest of my model’s architecture on top of that. As soon as the model training was completed, I tested the model on various model performance tests such as accuracy, precision, recall, confusion matrix and ROC-AUC scores.

Once I was certain that my deep learning model passed the scrutiny of different performance tests, I decided to deploy the deep learning model as a backend to a web application. Unlike my previous project where I deployed the deep learning model on AWS’s EC2 instance, this time around, I deployed the deep learning model as a web application on Google Cloud Platform’s App Engine service.

Step 1: Creating the UI for the web application.

I used the StreamLit library to develop the front-end of the deployed web application. The UI included a sidebar that houses the functionality which allows a user to upload the image of their chest x-ray post which, the user gets the results with the preview of their uploaded image. A snapshot of the web application can be seen in the image below.

(Image by Author)

Step 2: Create the configuration files needed to host the web application on Google Cloud Platform.

Before I deploy the web application onto Google Cloud Platforms’ App Engine Service, a few configurations files are needed to ensure successful deployment.

The first file is the app.yaml file and it is used to specify the desired configurations for our application. This file helps specify the runtime, environment type, and resource settings needed by the web application to run smoothly.

The second file is the Dockerfile and it contains the instructions and steps needed for building and setting up the docker image and the docker container in which our web application will run.

Lastly, we need to create the requiremnts.txt file and specify the libraries needed for the web application to deliver results once it is hosted on the App Engine service.

With the required configuration files now created, I can move onto completing the deployment of my web application.

Step 3: Model Deployment

After the completion of Step 2, I have all the files needed to deploy the web application on Google Cloud’s App Engine service. Before I start the deployment process, it is important to download the Google Cloud SDK application as well as creating a Google account to access Google Cloud Platform’s App Engine service.

1- As soon as the above-mentioned steps are completed, search for Google Cloud Platform from your desired browser, scroll through the search results and click on “Cloud Console”. Once you gain access to your cloud console, navigate to the top left corner and click on “Select a Project”. In the pop-up that appears next, select the “New Project” option.

(Image by Author)

2 - Clicking on the new project option redirects the user to a new screen that requires him/her to enter a project name. Once the details are entered, click on “Create” and complete the final step for the creation of a new project.

(Image by Author)

3 - Once the new project is created, it is important to enable the Cloud Build API. To enable it, open a new tab in your browser and paste the following link. Once the site loads, click on the Blue button which says “Open the Cloud Build Settings page”. In the new tab that opens up, click on “View API” and then click on “Enable”. Once the API is successfully enabled, close the tab and return to the dashboard of the newly created project.

(Images by Author)

4 - It is now time to deploy the code onto the Google Cloud Platform. The deployment will be done via the local command prompt on our system and with the help of Google Cloud SDK which can be downloaded from the following link. Once the download is complete, install Google Cloud SDK and proceed to the next step.

5 - You can open the command prompt in the local machine and set the working directory to the location where the script file of the web application is present as well as the configuration files created in Step 2.

6 - Once the path is set, type the below-specified command in the command prompt which will start the deployment of your application.

gcloud init

7- After the above command is executed, the next step is to choose the configuration. Choose the option to “Create a new configuration” and give the configuration a name. Additionally, choose the Google account that was used to create the new project on Google Cloud Platform.

(Image by Author)

8- Upon receiving the message of a successful login, select the project that was created by you for deploying the X-Ray Classifier project and wait for the configuration to complete. As soon as it is done, move to the next step.

(Image by Author)

9- It is now time to deploy all the code into the project that was created on the Google Cloud Platform. To do so, type the below command in your command prompt.

gcloud deploy

Next, select the region where you want your App Engine application to be located, I chose option “4”. Lastly, enter “Y” to commence the deployment operation.

(Image by Author)

10- Once the deployment is complete, and provided that the deployment was successful, you will receive the URL to your web application which can be used to access it. Additionally, you can type the below-listed command in your command prompt and the web application will automatically open in your browser.

gcloud app browse

Warning: Once you are done testing/playing around with your deployed web application, it is always ideal to delete your Google Cloud project. This prevents the risk of incurring unnecessary service charges. To achieve this, go to the sidebar menu, select IAM & Admin and then Manage Resources. The page displays all the currently active projects, select the project that you created to host the X-Ray Classifier project and delete it.

(Images by Author)

Conclusion

Having previously deployed Machine Learning/Deep Learning models on Heroku and AWS, I decided to expand my portfolio of cloud deployments by deploying the X-Ray Classifier on Google Cloud Platform's App Engine Service. It gave me the opportunity to work with the Google Cloud interface, deploy the code using Google Cloud SDK and, understand the importance of a Dockerfile and the role it plays in application deployment on the cloud.

I was able to successfully deploy the web application using Google Cloud Platform’s App Engine Service and the deployed application worked perfectly and gave accurate results.

In my next project, the aim is to deploy a Machine Learning/Deep Learning enabled application on Microsoft’s cloud computing service, Azure.

All the requisite project files to complete this end-to-end project can be found on my Github profile. I hope you enjoyed reading my blog.

--

--

Shaunak Varudandi
Geek Culture

MBA (Co-op) student at the DeGroote School of Business || Aspiring Business Data Analyst.