Original code by David Soto - email@example.com
Original repo can be found here
This is a forked version by Freddie Poser - https://vogonjeltz.com
The data from this project comes from the ISIC Archive which contains a huge number of images of melanomas which have been used here to train models to classify the risk of a mole turning malignant.
The download feature of the ISIC archive website, whilst powerful, faills frequently resulting in corrupt downloads. Depending on the licencing terms I may upload the selected images used here to a webserver so that people can have easier access to them.
The data used in this project comes from four of the datasets on the ISIC website:
- UDA-1: 60 images
[B: 23, M:37]
- UDA-2: 557 images
[B: 398, M: 159]
- MSK-1: 1100 images
[B: 787, M: 301]
- MSK-2: 352 images
[B: 0, M: 352]
- Benign images here excluded as per original project
Data Processing and Ingest
To set the data up for the project to use methods can be found in the
Set up the following directory structure:
\-skincancer \-data \-benign | \- All benign images as JPG... |-malignant \- All malignant images as JPG... \data_scaled \-benign |-malgnant \data_scaled_validation \-benign |-malignant
Run the methods in
data_scaled directory will now contain the scaled data for use in training and
data_scaled_validation contains images to be used for validation (by default 10% of the provided images).
Once the issue in keras (described below) was avoided I managed to start getting the CNN used in the original project to train on the data set. This resuslted (after 95 epochs) and the ROC curve below.
My next problem was to get GPU training working on my machine. This was more of a hassle than it should have been but in the end I got it working with the following versions:
- Python 3.6
- Latest version of drivers for my card (960M)
This was done in an Anaconda3 environment. Installed using the following commands (once CUDA/cuDNN installed):
conda install numpy
pip install tensorflow-gpu
pip install keras
This installation sped up training by ~8x.
The code for all of this can be found in
Included in the original project was a jupyter notebook that was used to visualise the output of a network. I updated this file to work better with multiple images.
VGG16 and Data Augmentation
As in the original project I have attempted to use transfer learning and apply the VGG16 model (pre-trained on the ImageNet dataset) to the problem. The code can be found in the two files
src/sandbox/v3_vgg_DA.py as well as the file containing the model definition
The structure I used was to take the VGG model (without the last three layers) and feed it into a fully connected layer with 128 neurons. This then has one output - for binary classification. i freeze the whole of the VGG16 network so that the weights don't change during training. This leaves just the final two layers that learn to interpret the result of the VGG output.
As well as learning better than the standalone CNN it also learns a lot faster, skipping out the stage I observed where the network would not train at all for up to 30 epochs before changing. This network reached ~0.73 accuracy in just three epochs.
I also used data-augmentation (rotation and flipping) techniques as well as dropout to prevent overfitting.
I trained this structure for 90 epochs which gave the following results:
|avg / total||0.84||0.82||0.82||204|
I had the idea to try and combine the VGG16 model with a small standard CNN (3 layers) to try and achieve better results. I am still experimenting with this setup but my initial test trained for over 300 epochs achieved an AUC of 92 and test results as follows:
|avg / total||0.87||0.86||0.846||204|
Problems with keras
On my installation (and it seems others) the use of the keras method
model.fit_generator leads to a
TypeError that occurs when trying to pickle an object. For now I have stopped using this and replaced it with a standard
model.fit call. This persists when using
When trying to implement DA using the inbuilt keras tools I found that the key was to set the option
False. This allows me to use the full features of
fit_generator without the breaking bug.
This tool has been designed only for educational purposes to demonstrate the use of Machine Learning tools in the medical field. This tool does not replace advice or evaluation by a medical professional. Nothing on this site should be construed as an attempt to offer a medical opinion or practice medicine.