Melanoma Detection Using a CNN-Based Model: A Deep Learning Approach for Skin Cancer Diagnosis

Mallikarjuna Jana
4 min readJun 12, 2023

--

Introduction:

Melanoma, a type of skin cancer, is a serious health concern with potentially life-threatening consequences if not detected early. With the advancements in deep learning and computer vision, building a CNN-based model has become a promising approach for accurate melanoma detection. In this blog post, we will explore the steps involved in creating a CNN-based model that can effectively identify melanoma, providing a valuable tool for early diagnosis and treatment.

Melanoma Detection using Convolution Neural Network (CNNs)

Understanding Convolutional Neural Networks (CNNs):

Convolutional Neural Networks (CNNs) are a class of deep learning models specifically designed to excel in image processing tasks. CNNs consist of multiple layers, including convolutional, pooling, and fully connected layers, which allow them to learn complex patterns and features from images. Leveraging these properties, we can develop a CNN-based model for melanoma detection.

Lets Understand the Data Set:

Data Source : The dataset available in Kaggle , which consists of 2K+ images of malignant and benign oncological diseases, which were formed from the International Skin Imaging Collaboration (ISIC).

Construct Model

Importing Essential Libraries:

Create Data Set:

Use 80% of the images for training, and 20% for validation, the parameters for the loader

batch_size = 32
img_height = 180
img_width = 180

Create train and Validation set using keras.preprocessing

Create Model:

Below model is having 7 Layers sequential for organising layers in a linear stack, before creating model rescale images to normalize pixel values between (0,1) and with parameters

  • activation function =’relu’
  • filters (3,3) and (5,5)
  • Dropout 0.25 and
  • Dense layer with activation ‘softmax’

Above model will bring us the params as

Total params: 1,172,265
Trainable params: 1,172,265
Non-trainable params: 0

Compile the Model:

Compiling the model with recommended parameters

  • optimizer=’adam’ — Adam is a popular optimization algorithm that combines the benefits of both AdaGrad and RMSProp. It is known for its efficiency and effectiveness in training neural networks.
  • loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True) — Sparse categorical cross-entropy is commonly used for multi-class classification tasks, where the labels are integers representing the class indices .And the from_logits=True indicates that the model's output is not normalized by a softmax activation, allowing the loss
  • metrics=[‘accuracy’] — model’s accuracy will be calculated and reported during training and evaluation. Accuracy is a commonly used metric that measures the percentage of correctly predicted labels compared to the true labels.

Train the model :

When trining the model, train a model with many Trainable params will take huge time to process, recommend to not use local system, use Google’s colab instead and enable hardware accelerator as GPU Edit->NoteBook Settings

using epochs as 20

Visualize the results in graphs to have better understanding on model performance. some of way of graphs using matplotlib.pyplot for accuracy and loss

Analysis:

This is completion of model creation, compiling and train and validate the model.

If the finding are with good accuracy with train and validation set (80% above 70%) that is very good model in my perspective, it may vary based on the data and hyper parameters.

If your model is having overfitting because of class imbalnce please continue below

Data augmentation:

Use case :

Most of the times in real life datasets can have class imbalance, one class can have proportionately higher number of samples compared to the others. Class imbalance can have a detrimental effect on the final model quality. Hence as a sanity check it becomes important to check what is the distribution of classes in the data before proceeding. In such cases Data Agumentation techniques will help

Augmentation:

Commonly used in Convolutional Neural Networks (CNNs) to artificially increase the size of the training dataset by applying various transformations to the existing data. It helps improve the performance and generalization ability of CNN models by providing more diverse and varied training examples.

The idea behind data augmentation is to create new training samples by applying random transformations to the original images while preserving the class labels.

These transformations can include below and these can be combined and applied with random parameters to generate new training samples on-the-fly during the training process.

  • Flipping
  • Rotation
  • Translation
  • Scaling
  • Zooming
  • Shearing

Data augmentation is typically implemented using data augmentation libraries or frameworks, such as the ImageDataGenerator class in Keras or python package Augmentor (https://augmentor.readthedocs.io/en/master/)

Install using !pip install Augmentor in your colab then import

Below is the code which is generating 500 images using Agumentor in your train_dir, in each labelled directory by keeping extra folder output. Later we can combine both initial set of class images and generated images in output folder tougher to train your model to reduce the class imbalance .

With the the help Agumentor we are trying to resolve class imbalance which eventually reduces the model overfitting.

Complete Notebook: You can refer complete notebook in my git

Thanks for reading!

Happy Coding .. 👍🏻 😉

--

--