Classifying Skin Cancers with Convolutional Neural Networks

Source: Artificial Intelligence on Medium

Classifying Skin Cancers with Convolutional Neural Networks

The medical industry is without a doubt one to benefit from recent advances in machine learning technologies, especially in image recognition. In this tutorial we will go over how to create a neural network which classifies images of skin cancers into two categories: malignant and benign.

The first step is to download our dataset, which can be found here. The collection of images consists of 224 * 224 images in either of the two categories.

Two benign and two malignant skin cancers

Once we have the data downloaded and unpacked, we will gather a list of images for our generator:

We create a training set of 2300 images and a test set of 600 images so that we have equal numbers of both types of cancer. Next we shuffle our arrays:

With our training files gathered, we can create a generator which will load batches of images during training:

The __getitem__ class method fetches a batch of data from the set.

Finally we can define our model, which will use 2D convolutional layers to better interpret the image data:

Then, after creating our two generators, we can train our model:

The model reaches aroud 85–90% accuracy after between 5 and 10 epochs of training.