Breast Cancer Detection

Manuel I. Gómez G.
2 min readMay 20, 2022

At the time this code was created I was having my first approach to CNN. Most of the code was inspired by a course that I had at that time, and also some extra features that were added to improve and keep practicing even further.

Beside creating all this model construction code, using this notebook on Google Colab and looking at the option of launching MLflow along with it, either locally or using Google Colab, however, this won’t be discussed on this post.

Code development

First thing needed it’s a dataset, the one used was provided by the Computer Science department (IC/UFF) work in Visual Lab. Dataset contains around 5000 images for two different classes, healthy and sick.

For data preprocess, two things were made: a data augmentation function which will randomly flips image horizontally and a random contrast between 5 to 25%; also we normalize each pictures, as the original ResNet101v2, so that way our model later on receives data in a better format.

Once the preprocessing function are ready, it’s time to create our model using ResNet101v2 model and adding a couple layers at the end to help decide, whether or not, if patient is healthy. Hyperparameters and a callback that were used are shown below.

Hyperparameters
Callback for EarlyStopping

Now it’s time to begin with training; five epochs were given for it, after doing it we get around 85%.

Metrics for first model approach.

The results obtained based on metrics are good, but they can get even better, so it’s time to perform a fine tuning, in order to do it, we would freeze 300 out of 377 layers in this pretrained model. By doing this transfer learning and having computer to retrain those last layers, model metrics should have a better performance, giving out around 95%.

Metrics comparison after fine tuning model.

--

--