Medical Image Classification using Azure Functions and Cognitive Services

Parag Ghorpade
Sep 4 · 10 min read
Image for post
Image for post




Section I: Training the model


Microsoft Custom Vision

Image for post
Image for post
Successfully deployed custom vision service
Image for post
Image for post
Image for post
Image for post

Section II: Azure Functions model serving

git clone
git clone
BASH:-cd startpython -m venv .venvsource .venv/bin/activateIf Python didn’t install the venv package on your Linux distribution, run the following command:sudo apt-get install python3-venvCMD:- cd startpy -3.6 -m venv .venv.venv\scripts\activate
func init — worker-runtime python
func new --name classify --template “HTTP trigger”

Testing App Locally

func start

Import and serve the Tensorflow Model

BASH:-cp ../resources/ classify
copy ..\resources\ classify
pip install --no-cache-dir -r requirements.txt

Configure Function to run predictions

import logging
import azure.functions as func
import json
# Import helper script
from .predict import predict_image_from_url
def main(req: func.HttpRequest) -> func.HttpResponse:
image_url = req.params.get('img')'Image URL received: ' + image_url)
results = predict_image_from_url(image_url) headers = {
"Content-type": "application/json",
"Access-Control-Allow-Origin": "*"
return func.HttpResponse(json.dumps(results), headers = headers)
func start
Sample Images:
RESULT (you should be able to see similar response in the browser):-
{"created": "2020-09-03T16:16:01.225972", "predictedTagName": "Pneumonia", "prediction": [{"tagName": "Pneumonia", "probability": 1.0}]}

Run basic front end locally
BASH:- python -m http.serverCMD:- py -m http.server
Image for post
Image for post


Image for post
Image for post

Hosting the function app

az login
az group create --name classify-image --location eastus
az storage account create --name <STORAGE_NAME> --location eastus --resource-group classify-image --sku Standard_LRS
az functionapp create --resource-group classify-image --os-type Linux --consumption-plan-location eastus --runtime python --runtime-version 3.6 --functions-version 2 --name <APP_NAME> --storage-account <STORAGE_NAME>
func azure functionapp publish <APP_NAME>
Image for post
Image for post


Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store