Skin Cancer Classification Using AI

Kenneth Ekene Odoh
4 min readFeb 28, 2023

--

Introduction

Skin cancer is the growth of abnormal cells in the outermost skin layer (epidermis), caused by unrepaired DNA damage that triggers mutations. This mutation leads the skin cells to multiply rapidly and form malignant tumors. Skin cancer is usually caused by the sun’s harmful rays.

Just like many other cancer types, skin cancer when detected early, can be cured through surgical interventions. However, early detection remains a challenge for the following reasons:

  1. Clinical examinations are expensive and require a high level of training, and effort to operate the equipment.
  2. There are 9 classes of skin cancer, and so, it is usually difficult for even experienced medical practitioners to accurately identify and classify them visually.

This project aims to apply Artificial Intelligence in the detection and classification of skin cancers.

Source Code:

Objectives

  1. To train a machine learning model which can detect and classify skin cancer types.
  2. To deploy our model as a web app that will enable doctors (and anyone else) to quickly diagnose skin cancer using their smartphones, instead of going to perform the experiments in the laboratory.

About the Dataset

The dataset consists of 2357 images of malignant and benign oncological diseases, which were formed by the International Skin Imaging Collaboration (ISIC). All images were sorted according to the classification taken with ISIC, and all subsets were divided into the same number of images, except for melanomas and moles, whose images are slightly dominant.

The data set contains the following diseases:

  1. Actinic keratosis
  2. Basal cell carcinoma
  3. Dermatofibroma
  4. Melanoma
  5. Nevus
  6. Pigmented benign keratosis
  7. Seborrheic keratosis
  8. Squamous cell carcinoma
  9. Vascular lesion

The dataset can be found here on Kaggle.

Model Summary

Because this is a multi-class classification problem, we used a Convolution Neural Network (CNN) consisting of 16 layers to train the model. We also used other Python libraries such as Tensorflow, Pandas, Matplotlib, etc., for image preprocessing, data visualizations, and other ancillary statistical analysis, and the resulting model takes about 45 minutes to train.

The Convolutional Neural Network (CNN) Workflow. Source

Creating Training, Validation, and Test Splits

The original dataset was grouped into two folders: the train set (2239 images) and the test set (118 images).

80% of the train set was used to train the model while the remaining 20% was used to validate it.

Compiling and Training

Fig: Model performance on the original dataset

As we can see above, The model did overfit since the validation loss is much greater than the training loss. Also, we can see a great difference in accuracy scores.

The next step would be to check for class imbalance!

Checking for Class imbalance in the dataset. Image by Author

As you can see above, there is a class imbalance. Some classes (pigmented benign keratosis and melanoma) have a proportionately higher number of samples than others, and this is negatively affecting our model.

Augmenting the Image Dataset

We used the Augmentor library to manipulate our original dataset to obtain modified versions of the images. We did rotate the images 15 degrees (right and left), and for each class, 2,000 modified images were created, resulting in an overall sample size of 18,000 images.

Creating Training and Validation Set (Augmented)

We retrained the model but this time around, we used the images created using the Augmentor library. This increased the validation accuracy to 90%!

Fig: Model Performance after Augmenting the dataset

Hyperparameter Tuning

RandomSearch was used on the model. Also, different layer depths were tested but not much Improvement was recorded.

Testing and Deployment

Even though we recorded very high validation accuracy, the model performed poorly on the test set with an evaluation accuracy score of 44%. The Augmentor library could not help us solve the overfitting challenge, and given the delicate nature of its intended purpose (health), we could see that the model is not yet suitable for production.

We could not deploy the web app since the model’s performance is very poor. However, we created a local version using Streamlit.

A demo of the skin cancer prediction using our model and the local Streamlit app.

Recommendation and Conclusion

We have built a model with 44% accuracy. The performance is not yet optimal, but the objectives of the project were not completely defeated.

From this project, we could see that data augmentation doesn’t compensate for insufficient data. We hope that the accuracy of the model can be improved further with more images from ISIC or any other reliable source. Also, more parameter tuning could turn out to improve the accuracy even further, and as such, we can build further from here as more resources become available.

Overall, we believe that incorporating AI in cancer prediction is a step in the right direction. Even though models like this cannot entirely replace traditional laboratory diagnostics, they will greatly facilitate early detection, and so, help reduce the number of deaths attributed to skin cancers.

Contributors

Volker Tachin

Omar Alqaysi

Kenneth Odoh

Promise Uzoagulu

Shreyansh Gupta

Emako Efatobor

Thandazi Mnisi

Mutholib Yusira

--

--

Kenneth Ekene Odoh

Hi, my name is Kenneth Odoh. I am a digital marketer, writer, data analyst and Engineer. Check me out — kennethodoh.digital