End-to-end breast cancer detection with Python — Part 1 | by Jordan Van Eetveldt | Towards Data Science

According to cancer.org, breast cancer is the most common cancer in American women. In the US, there is a 1 in 8 chance that a woman will develop breast cancer. In this series of articles we will show how deep learning and image processing can be applied to detect malignant breast masses. We will first focus on detecting breast masses (part1), then we will segment them (part2) and finally we will classify whether a mass is benign or malignant (part3).
There exists two types of mammography: Film-screen and more recently Full-Field Digital Mammography. In this article I used the INbreast dataset. It contains 115 cases with a total of 410 Full-Field Digital Mammography in DICOM format. There are four different types of breast diseases recorded in the database, including Mass, Calcification, Asymmetry, and Distortion. Only mass lesions were selected, resulting in 106 images. Each image is coupled with accurate contours made by specialists in XML format. For the detection part, as we don’t need to segment the mass, the contours were converted into bounding boxes. Below you can find the code that convert a mask of the lesions to YOLO format annotations:
Here are shown some samples from the dataset with corresponding generated bounding boxes:
As we can see a lot of pixels are background pixels which bring no information. To avoid the proportion of mass pixels from being underrepresented we can crop the ROI, that is the breast region. This can be done with OpenCV and Otsu’s thresholding technique:
Then I applied 3 preprocessing steps inspired by [1]. These 3 steps consist of:
Truncation normalization
Image enhancement
Image synthesizing
Even after cropping, the image is still composed of many black pixels. This may have negative effects on the detection if we normalize the image as it is (because the breast region will appear less intense). Here the goal is to normalize the intensity distribution of the pixels in the breast region. You can refer to the original article to see algorithm details [1]. Below I provide my implementation in python:
To enhance the contrast of the breast region and so the mass lesion, Contrast Limited Adaptive Histogram Equalization (CLAHE) algorithm is applied with clip limit 1 and 2:
After applying these 3 steps, the mass lesions appear much clearly. This will improve Yolov4 accuracy. In the final step, a 3-channel image is synthesized and composed of the truncated and normalized image, the contrast enhanced image with clip limit 1, and the contrast enhanced image with clip limit 2 [1].
YOLOv4 has been used to perform mass detection on the enhanced images. It is a one stage detector particularly efficient when context is needed compared to two stages detector. As explained in [1], when background is independent from foreground, two stages detectors are useful as the first stage extracts ROI. However Cao, H [1] mentioned that in breast mass detection, lesions are not independent from the breast region and therefore one stage detectors may be more efficient. To correctly evaluate the performance of the algorithm I split the data-set into 3 parts:
Train set is composed of 80% of the images
Validation set is composed of 10% of the images
Test set is composed of 10% of the images
As the resulting train set is small, data augmentation has been applied (only on the train set). Each image has been augmented 8 times with random rotation, flip and shift. YOLO takes care of other augmentations such as Mosaic data augmentation etc; see [2]. I performed a 2-fold cross validation using the same procedure explained above.
To evaluate the detector, I used the recall and the False Negative rate (FNR) metrics. Note that in cancer detection it is very important to have a very low FNR and a high recall (otherwise we miss a potential cancer). A detection is considered as a True Positive (TP) if the Intersection Over Union (IOU) between the predicted bounding box and the ground truth is greater than 0.25. Also a bounding box is considered only if its confidence is greater that 0.25. The results have been evaluated on the validation and test sets.
        Validation set evaluation+--------+----+----+----+--------+------+|        | TP | FP | FN | Recall | FNR  |+--------+----+----+----+--------+------+| Fold 1 | 10 |  3 |  1 |   0.91 | 0.07 || Fold 2 | 11 |  1 |  1 |   0.92 | 0.08 |+--------+----+----+----+--------+------+            Test set evaluation+--------+----+----+----+--------+------+|        | TP | FP | FN | Recall | FNR  |+--------+----+----+----+--------+------+| Fold 1 | 12 |  1 |  0 |      1 |    0 || Fold 2 | 11 |  4 |  2 |   0.85 | 0.13 |+--------+----+----+----+--------+------+
YOLOv4 appears to be highly efficient in breast mass detection. I achieve 92% mean recall on the validation and test sets which correspond to state-of-the-art results in the literature ([1] achieved 91.3% recall). The model seems to struggle a little bit on small mass lesions in the fold2 test set. I trained Yolov4 on a 8GB nvidia RTX 2080 GPU. This forces me to limit the image size to 512x512. Having more resources and data could allow us to train the algorithm on more powerful models such as the state-of-the-art YOLOv4-P7 and with higher resolution images. This should improve accuracy on small mass regions. Here are the results on the test set (unseen images) during both folds:
We have trained a highly accurate breast mass detector in python with YOLOv4. This has been possible partly thanks to an efficient image preprocessing step. Results are really promising and similar to those in the literature. In the next articles, we will see how to segment the mass. Having already a detector being able to crop the masses will be useful to train the segmentation model only on the mass regions. Then we will classify whether a mass is malignant. Stay tuned ;)
Note: I provide the script to create the dataset and my config file for training YOLO on my github :)
[1] Cao, H. (2020). Breast mass detection in digital mammography based on anchor-free architecture. ArXiv, abs/2009.00857.
[2] Bochkovskiy, A., Wang, C., & Liao, H. (2020). YOLOv4: Optimal Speed and Accuracy of Object Detection. ArXiv, abs/2004.10934.
[3] Al-Antari MA, Al-Masni MA, Choi MT, Han SM, Kim TS. A fully integrated computer-aided diagnosis system for digital X-ray mammograms via deep learning detection, segmentation, and classification. International Journal of Medical Informatics. 2018 Sep;117:44–54. DOI: 10.1016/j.ijmedinf.2018.06.003.