MLearning.ai
Published in

MLearning.ai

Building a Web Application to detect Breast Cancer in Ultrasound images

A friendly guide to easily do Object Detection on medical images

Photo by Priscilla Du Preez on Unsplash

Table of Contents:

  • Part 1: Training Model on ultrasound images
  • Part 2: Build Web Application with Streamlit

Requirements:

Create a New Project on Datature’s platform. GIF by Author.
Source

Part 1: Training Model on ultrasound images

  1. Upload and Annotate images
  2. Create Workflow
  3. Visualize Model Performance
  4. Download Tensorflow Artifact
  5. Run the predict script.py

1. Upload and Annotate images

1.1 Upload Images. Illustration by Author.
filename,xmin,ymin,width,height,label
benign (1).png,288,134,51,26,benign
benign (10).png,24,67,209,197,benign
benign (11).png,367,132,72,38,benign
benign (12).png,343,178,78,44,benign
benign (13).png,182,107,355,198,benign
benign (14).png,511,149,111,54,benign
1.2 Upload Annotations. Illustration by Author.
Visualize annotated images and Manually Annotation. GIF by Author.

2. Create Workflow

Create Workflow. Illustration by Author.
  • Right-click Datasets →Project dataset to split the dataset into training and validation sets.
  • Right-click Augmentations and select the techniques you prefer to apply transformations to images. There is also the possibility to have a preview of the resulted augmentations by clicking the button “Preview Augmentations” at the right bottom.
  • Right-click Models → RetinaNet models → Retina MobileNet V2 640x640. If you press the created window’s model, you can also set up the batch size and the number of iterations. In this case, we just change the default batch size to 4.
Run Training. Illustration by Author.

3. Visualize Model Performance

Model metrics and Advanced Evaluation. GIF by Author.
Example of Advanced Evaluation. Illustration by Author.

4. Download Tensorflow Artifact

Export Artifact. GIF by Author.

Run the predict script.py

  • Unzip the exported artifact.
  • Download requirements.txt and predict.py files from the the Datature’s GitHub Repository.
  • Set up a Python environment with a Python version between 3.6–3.8.
Screenshot on Github Repository.
Project Structure. Illustration by Author.
cd model_architecture
python predict.py --input "../input" --output "../output" --width 640 --height 640 --threshold 0.7 --model "../saved_model" --label "../label_map.pbtxt"
Model loaded, took 6.812467813491821 seconds...
Predicting for ../input/malignant (90).png...
Predicting for ../input/benign (53).png...
Saving predicted images to ../output/benign (53).png...
Predicting for ../input/benign (51).png...
Saving predicted images to ../output/benign (51).png...
Predicting for ../input/malignant (71).png...
Predicting for ../input/benign (52).png...
Predicting for ../input/malignant (111).png...
Saving predicted images to ../output/malignant (111).png...
Example of Benign prediction. Illustration by Author.
Example of Malignant Prediction. Illustration by Author.

Part 2: Build Web Application with Streamlit

Web Application. GIF by Author.
  • Use argparse library to define default arguments, such as the path of the model and the path of the label map.
  • Load the trained model.
  • Create the title of the app.
  • Upload an image, which can be in jpg or png format.
  • Create a button “Detect Breast Cancer”. After it’s pressed, we visualize the prediction on the right half of the web app.

Final thoughts:

--

--

Data Scientists must think like an artist when finding a solution when creating a piece of code. ⚪️ Artists enjoy working on interesting problems, even if there is no obvious answer ⚪️ linktr.ee/mlearning 🔵 Follow to join our 28K+ Unique DAILY Readers 🟠

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
Eugenia Anello

Research fellow in Interpretable Anomaly Detection | Top 1500 Writer on Medium | Love to share Data Science articles| https://www.linkedin.com/in/eugenia-anello