Deploying Computer Vision Models for Health Diagnostics Imaging.

martinbald81

martinbald81

Posted on June 28, 2023

Deploying Computer Vision Models for Health Diagnostics Imaging.

The capabilities of Computer Vision (CV) models are progressing by leaps and bounds fostering more and more adoption across a number of industries. One of these industries is the healthcare sector where computer vision is being used as a powerful diagnostic imaging tool to provide potential life saving results for patients. These CV models can help diagnose diseases, monitor treatments, and improve outcomes for patients. Analyzing images from various sources, such as X-rays, MRI scans, ultrasound, or optical cameras, they can detect anomalies, measure features, segment regions, and classify conditions.

In this post, we will demonstrate putting a computer vision model into production that detects mitochondria from high resolution images.

For this example we will be using a high resolution 1536 x 2048 image that is broken down into “patches” of 256x256 images that can be quickly analyzed.

Mitochondria are known as the “powerhouse” of the cell, and having a healthy amount of mitochondria indicates that a patient has enough energy to live a healthy life, or may have underlying issues that a doctor can check for.

Scanning high resolution images of patient cells can be used to count how many mitochondria a patient has, but the process is laborious. The following ML Model is trained to examine an image of cells, then detect which structures are mitochondria. This is used to speed up the process of testing patients and determining next steps.

Before moving on, you can step through this computer vision deployment exercise by downloading the Wallaroo Community Edition and the Health Diagnostic Imaging Tutorial.

After loading the necessary dependencies and libraries the next step is to establish a connection to the Wallaroo Client. The Python library is included in the Wallaroo install and available through the Jupyter Hub interface provided with your Wallaroo environment.

We will create a workspace to manage our pipeline and models. The following variables will set the name of our sample workspace then set it as the current workspace.

Python code for Workspace, Pipeline creation, and Model file name

Python code for setting to the current workspace and pipeline

Python code for setting to the current workspace and pipeline

In the next step we will:

  1. Upload our model.
  2. Apply it as a step in our pipeline.
  3. Create a pipeline deployment with enough memory to perform the inferences.
  4. Deploy the pipeline

Deploying the ML model to production

It’s important to point out that our model is deployed in less than 45 seconds which can take days and weeks normally with other ML tools.

The next step is to process the image into a numpy array that the model is trained to detect from.

We start by retrieving all the patch images from a recorded time series tiff recorded on one of our microscopes.

Python code for retrieving all the patch images

Randomly we will retrieve a 256x256 patch image and use it to do our semantic segmentation prediction.

We’ll then convert it into a numpy array and insert into a DataFrame for a single inference.

The following helper function loadImageAndConvertTiff is used to convert the image into a numpy, then insert that into the DataFrame. This allows a later command to take the randomly grabbed image and perform the process on other images.

Python code for helper function  raw `loadImageAndConvertTiff` endraw  used to convert the image into a numpy and insertion into the DataFrame

Python commands to take the randomly grabbed image and perform the process on other images

We will now perform our inferences and display the results. This results in a predicted mask showing us where the mitochondria cells are located.

  1. The first image is the input image.
  2. The 2nd image is the ground truth. The mask was created by a human who identified the mitochondria cells in the input image
  3. The 3rd image is the predicted mask after running inference on the Wallaroo pipeline.

We’ll perform this 10 times to show how quickly the inferences can be submitted.

Python code for running the inferences ten times

ML model Mitochondria image output

ML model Mitochondria image output

Finally we will undeploy our pipeline and give the resources back to the instance.

Python code for undeploying the ML pipeline

This is just one example of how to use Machine Learning to overcome difficulties to deploy and serve CV models without complex technical infrastructure bottlenecks or requiring data engineering expertise to imaging the data, and to use computer vision models for advanced object detection, object classification for health diagnostic imaging in areas of radiology, pathology, cell-imaging.

As mentioned above you can try this yourself by downloading the Wallaroo Community Edition and the Health Diagnostic Imaging Tutorial.

💖 💪 🙅 🚩
martinbald81
martinbald81

Posted on June 28, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related