Training a CNN From Scratch For Melanoma Detection Using Keras

Image for post
Image for post

I will be sharing a script using Keras for training a Convolutional Neural Network (CNN) from scratch for melanoma detection. You can view the code from this GitHub repository.

Before proceeding however, make sure that you structure the data as follows (the numbers represent the number of images in each file):

Image for post
Image for post

You can download the data from, here. I used two classes as you can see from the figure above (nevus and melanoma). For training, I kept 374 images in each class to keep the data balanced.

The results will not be optimal, as the purpose is to show how one can train a CNN from scratch.

Image for post
Image for post

What variables to edit in the code?

You need to edit the following variables to point to your data:

train_directory (path to your training directory)

validation_directory (path to your training directory)

test_directory (path to your testing directory)

What should you expect (outputs)?

Training and validation accuracy

Image for post
Image for post

Training and validation loss

Image for post
Image for post

Test accuracy

This will be a value. In my case, the test accuracy was around 77.1%.

ROC curve

Image for post
Image for post

In addition to some other values (i.e. confusion matrix) that will be displayed on the console.

The next post shows how to train a CNN from scratch for melanoma detection, but with data augmentation. You can find the next post, here.

Leveraging machine/deep learning and image processing in medical image analysis. You can kindly find more information about me on my website: https://abder.me

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