Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: [email protected]
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

Publication

AI in Medicine
Latest

AI in Medicine

Last Updated on January 8, 2023 by Editorial Team

Last Updated on January 16, 2022 by Editorial Team

Author(s): Dhruv Gangwani

Originally published on Towards AI the World’s Leading AI and Technology News and Media Company. If you are building an AI-related product or service, we invite you to consider becoming an AI sponsor. At Towards AI, we help scale AI and technology startups. Let us help you unleash your technology to the masses.

Artificial Intelligence

Automating medical tests using Artificial Intelligence

Photo by Irwan iwe onΒ Unsplash

Artificial Intelligence, in recent years, has automated several processes in almost every domain all over the globe. Specifically, AI has embraced Medical science in recent times when the world was struck with the COVID pandemic. From predicting the virus’s spread to examing the chest and lung’s X-ray, AI helped the human race in every possibleΒ manner.

But, Medical Science is still considered the most sensitive domain when it comes to relying on AI and Data Science. The reasons are pretty much straightforward: a small mistake by AI can cost aΒ life.

Two major scenarios canΒ occur:

  1. The patient is diagnosed with the disease and he/she is not affected.
  2. The patient is not diagnosed with the disease and he/she is affected.

Both scenarios will result in big disasters. One solution to the issue is that AI models must be fed with large volumes of quality data that covers all the unique test scenarios and exceptions as well. Secondly, we should let AI come to play but not at the risk of cutting down human involvement. This is to monitor and observe the nature of AI functioning and tune it accordingly. Once, AI models reach a stage where they are considered fully reliable then they should be tested on real patients. Mostly, industry-level practitioners don’t believe in relying on the accuracy of AI models in such sensitive scenarios. Rather, they trust metrics such as recall, precision, and F1Β score.

This blog will depict the end-to-end process of building a web app that accepts skin images as input and detects skin disease followed by sending medical reports to patients and doctors through WhatsApp messenger.

Table ofΒ Content:

  1. Data Source
  2. Exploratory DataΒ Analysis
  3. Model Training
  4. Whatsapp Configuration
  5. Creating WebΒ App
  6. Conclusion

Data Source

The dataset used for the training model is Skin Cancer MNIST: HAM10000. It comprises 10015 images over 7 classes of cancer. More than 50% of lesions are confirmed through histopathology and the ground truth for the rest of the cases is either follow-up examination (followup), expert consensus (consensus), or confirmation by in-vivo confocal microscopy (confocal). One issue with the dataset is that it does not have a class β€œNo disease” which is necessary for our application. I have opted for another way to deal with such a scenario which you’ll find in the next sections.

Exploratory DataΒ Analysis

  1. Frequency ofΒ Classes

It is very evident that the dataset is highly imbalanced where the frequency of melanocytic nevi (nv) is roughly seventy times the class with minimum frequency (melanoma). This brings the need of balancing the dataset by oversampling the ones except for the class with maximum frequency.

Source: Image byΒ Owner

2. Distribution of Skin disease overΒ Gender

The pie chart depicts that the probability of disease is gender-neutral. There are some specific kinds of cancer that are more likely to happen to a specific gender but not in this case. Further analysis might include gender distribution for an individual classes ofΒ cancer.

Distribution of disease overΒ gender

3. Histogram of the age ofΒ patients

Using the seaborn’s histplot to plot the histogram of patient’s age. This will disclose the group of age which is most affected. It is clear from the plot that people aged 40 to 60 are most affected byΒ cancer.

Histogram of patient’s age

4. Location of disease overΒ Gender

This plot will depict the body parts which are most frequently affected by these types of cancer for all genders. It is clear that β€œback” is the most affected for males and β€œlower extremity” forΒ females.

location (body parts) affected the most byΒ cancer

Model Training

Before the model is trained, we need to fix imbalanced data. I have used oversampling technique which creates duplicates of the data points who belong to the minority class (except for the class with the highest frequency).

Also, make sure to oversample the dataset (training dataset) after splitting the dataset into train and test. During splitting the dataset, training is allocated 90% of data while the rest is kept for testing the model once it is trained on the training dataset. Oversampling is performed only on the trainingΒ dataset.

The model architecture can be developed using two techniques: Custom architecture and Finetuning the pre-trained model. Some of the famous pre-trained models are VGG-16, Resnet50 and InceptionV3. While using the pre-trained model, the few last layers are altered to make it adaptable according to the current dataset. In this project, I have created a custom architecture that comprises several stacks of convolutional layer, max-pooling layer, and dense layer. Each layer performs a specific role in extracting features fromΒ images.

Convolutional Layer: It applies a kernel over an image to extract features such as vertical lines, horizontal lines, etc. The kernel can be imagined as a window of size K x K where K is usually an odd integer. It moves over an image with stride S and padding P can be laid at the boundary of the image to extract important features at the boundaries of the image. The output of the convolutional layer on Image I can be computed asΒ :

Output size = (I-K+2P)/S+1

Max Pooling Layer: It moves a kernel over an image to extract the feature with the max value. For example, the kernel of size 3*3 will cover nine pixels. It pixel with maximum value will be considered.

Dense Layer: Dense Layer is a simple layer of neurons in which each neuron receives input from all the neurons of the previous layer. It is the same as one used in Artificial neural networks. This layer is used for classification.

Though I have created a custom architecture, I believe that in most cases pre-trained models outperform the custom architectures. Additional details of model performance are provided in the Github repository mentioned at the end of thisΒ article.

Whatsapp Configuration

Whatsapp message is configured to send medical reports to the patient and doctor. Twilio is a platform that provides a set of APIs to send programmable SMS through multiple mediums. It provides a basic balance of $15 for every newΒ user.

Steps to configure WhatsApp messenger:

a. Login to Twilio and go to β€˜Programmable SMS’

b. Go to β€˜Setup Whatsapp’

c. Follow the set of steps mentioned on the platform.

Note: Copy and save the token and account ID mentioned on the homeΒ page.

Twilio library is used to send medical reports through Whatsapp. Token and account ID is stored in a separate file named credentials.py

Configuration of Whatsapp messenger

Creating WebΒ App

To create a web app, I have used Streamlit’s open-source framework. For the ones who are unaware of streamlit, It turns python scripts into the web app in minutes. It is especially for the ones like me, who have less or no experience with frontend technology. Install itΒ using,

pip install streamlit

I have created a basic web app that has a form and that has to be filled in to see the results. It asks the user for details such as skin photo, patient’s name, and contact number, doctor’s name, and contact number. As mentioned in the β€œdataset” section, this dataset does not have a class named β€œNo disease” which is very necessary. So if the confidence of the model drops below 80%, then it is considered as β€œNo diseaseΒ class”.

streamlit webΒ app

The web app would return the status of the process whether β€œSuccess” or β€œFailed” on the screen. Plus, it would send the report to the contact number of the patient and doctor through WhatsApp messenger. A snapshot of the message can be seen in the below attachedΒ image.

Whatsapp messenger

Conclusion

In this article, you must have learned that how deep learning has embraced medical science by automating the medical skin test. This is a basic prototype of such an application, whereas there is a lot to consider. For data science enthusiasts, Streamlit is a very easy and flexible open-source enabling us to develop a web app without explicit knowledge of front-end technologies.

You can find the demo video and all the resources here.

GitHub – DhruvGangwani/Streamlit-web-app: Skin disease detection using image classification. Streamlit to develop web app.


AI in Medicine was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.

Join thousands of data leaders on the AI newsletter. It’s free, we don’t spam, and we never share your email address. Keep up to date with the latest work in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming aΒ sponsor.

Published via Towards AI

Feedback ↓