Trigger Based Leukemia Classifier on Azure Cloud — Prediction and Reporting
Deploying a Industry ready prediction and reporting model to Azure.This work helps in faster prediction and diagnosis of blood cancer, bridging the gap between the testing and diagnosis time by hematologist (Doctors specialized in Blood).
A very short story on how this started, just completed AZ-900 certification and started looking for a way to work on things whatever I have learned for the certification. Found out DevStories for doing just, that special thanks to Azure Developer Stories and Microsoft Azure for this great initiative on sharing knowledge with the dev community (especially building things on Azure).
For those people who say “Just show me what you have built”, here you go -> 🕵️♂️✨
Watch the Live Demo on YouTube 👇👇👇
For those people who say “Talk is cheap just show me the code”, here you go -> 👨💻✌
Building a serverless leukemia classifier using Azure Functions and Logic Apps.
Medical Background 👩⚕️👨⚕️
Personally I have seen lot of people posting on LinkedIn about their fight with cancer and some are alive to share their stories and for some they are not fortunate enough to do so.
Why still it’s the case with so much advancements in medicine science and technology??
One of the primary cause is that the time delay between the report from the lab and the review from Hematologist. It also costs you a lot to do tests every time, pretty expensive. So enough of medicine, let’s try addressing this.
As always Automation is the way forward, when the blood sample is captured in the laboratory it’s uploaded into our system and when that is done our machine learning image classifier detects the type of Leukemia in the initial screening phase. Then an email is triggered with the results of the model to hematologists and then the final decision is made and he will give feedback to our developer team to enhance and retrain our model to fine tune it.
Azure Services Used
- Azure Functions
- Azure Logic Apps
- Azure Cosmos DB
- Azure Blob Storage
- Azure Devops
Finally Mailjet for sending out emails (you can use any other similar mailing services of your choice)
A very simple flow diagram which describes the entire process
Let’s look at that in detail,🔍🔍🔍
I have used Python extensively in this one, feel free to replicate the same in your favorite language. 🐱👤🐱👤
Enough of talk!! Let’s see things in action, shall we???🤹♀️🤹♂️🤸♀️🤸♂️
Flow Started 💨💨
All the manual work, from uploading the image to updating the database can we hooked up to an UI, for simplicity purpose things are done manually.
Azure Cosmos DB 💫
The place where we store all our details of patient, prediction and hematologists. This is the initial view of the Container. The fields will be updated by the time we complete the entire flow.
0️⃣A sample item from the database, before the image is upload to Cosmos DB. Watch out for the change in predicted_type.
Azure Blob Storage
The lap technician will upload the microscopic blood sample images to our blob storage.
1️⃣As of now we have two patients images and you can add many more to trigger our flow.
Azure Logic Apps
2️⃣This is the complete design of our logic app. Let’s see how things work in each of the block in the upcoming parts.
This is where our first trigger will come into play. (Initial prediction of Leukemia)
3️⃣In this block we have the blob storage trigger, it will act when we upload a new image to Blob storage.
4️⃣Then we have the Azure function which predicts the type of leukemia and saves it to Cosmos DB.
Following are the list of functions used,
- leukemia-predict -> triggered from logic app when a change in blob storage is detected
- StaticPage -> present the portal page of our application
- SendMailTrigger -> Triggered when there is a change in Cosmos DB
- getcosmosdb-data -> will return all the items in the cosmos DB
- triggerleukemiamail -> will tirgger the SendMailTrigger function (🤔🤔🤨)
One of the best practice is to name your cosmos db without a “-” in between, let me explain it a little further, this is really important to understand. Ran into the same issue and was unable to detect it for 8 hours.
In the above image you can see a Azure function running with .NET runtime
Here is the same config of a Azure function with Python runtime which uses the same Cosmos DB.
This time it gives me an error that “-” are not allowed in the database name. You can see that in the right top corner highlighted text and on the left bottom corner we see another highlighted text which is the accepted configuration(name).
Due to this the Cosmos DB trigger in the Python runtime didn’t work.
So this is just one example that i came across which some or nobody knew about.
5️⃣You can see from the logs that it has predicted and updated the item in our Cosmos DB. These updates are done with the help of the Read-Write key.
6️⃣Finally, we have the send email block which will notify the hematologist about the new case that has been registered in our application.
7️⃣This is the updated container item after the image is uploaded and you can see the predicted_type is updated to ALL(Acute Lymphocytic Leukemia). This shows that our model ran successfully and updated the results.
8️⃣ Azure DevOps
Here is where we gather the mis-classified(false positive) images to retrain the model for continuous improvement and enhancements. This is achieved through the DevOps API with the PAT (Personal Access Token).
I know it’s a very long blog but hey, just hold on to me…. 🙋♂️🙋♀️
I have used Mailjet to send out mails, you can use your preferred mailing service or just Gmail if you want to.
Finally we have a simple dashboard which is updated every second (Planned to implement SignalR)
Running live here -> https://santhoshleukemiaclassifer.azurewebsites.net/api/StaticPage?name=index.html
💢Will keep it running only this month(April 2021),if you are reading this after that sorry, you won’t be able to view it.
Peek at the resource group which has all the services,
Example Code: Created my own Cosmos DB Client for updating and retrieval of items from containers. Done the same for DevOps (for creating a new work item)
Complete working code is in my GitHub Repo (With ML Model), just create the necessary resources and services.Then you are good to go.
Building a serverless leukemia classifer using Azure Functions and Logic Apps. …
- Upload the image through React UI Application
- Updating the container items also via React UI Application
- Direct decision making from Email (Reporting)
- Create a feedback loop to retrain the model further
Feel free to reach out if you need any further clarification on the implementation. I would be more than happy to answer those. 🤝
Looking forward to hear from you and improvements via Comment or PR (Pull Request in GitHub) are most welcomed.🙏🙏
Congratulations!! 🎉🎉you have successfully completed reading this huge blog.🤩🤩
Thanks a lot for reading out till the end.👓
Let’s connect if you want to collaborate on the further work or a quick catch up.🤝🤝