WomanLife: Deep Learning for the detection and classification of breast cancer
WomanLife explores breast ultrasound-image classification with TensorFlow and Keras: an educational project with three image classes and explicit clinical limits.
A learning project shared by the community. The article documents its team, methods and results; it does not establish that the prototype is ready for real-world use.

Editorial note: this article documents an educational project and its results on the data used. It does not establish clinical validation or authorisation to diagnose or treat patients. Proposed healthcare applications are retained as the team’s goals, not demonstrated capabilities.
La Paz. Deep Learning. 2021
Deep learning makes it possible to explore automated medical-image classification. WomanLife investigates this with breast ultrasound images as an educational prototype, with the longer-term aim of studying tools that could support healthcare professionals.
Breast cancer is a major health concern, and timely detection and treatment can improve outcomes. Unequal access to examinations and specialists motivated us to explore supporting tools, without replacing clinical assessment.
Description of the problem
The project classifies ultrasound images from a dataset collected from women aged 25–75. The model estimates one of three image categories; it does not segment lesions or independently establish a person’s diagnosis.
Objective
Explore an ultrasound-image classifier that, after appropriate clinical validation, could be studied as a support tool for healthcare professionals. The prototype is not intended for self-diagnosis and does not demonstrate reduced costs or mortality.
Model selection
We work with three ultrasound-image labels: benign, malignant and normal, using a convolutional network built with TensorFlow Keras.
Datasets
The dataset comes from Baheya Hospital in Cairo, Egypt, and contains 780 breast ultrasound images, collected from women aged 25–75: 133 normal, 437 benign and 210 malignant images. Their average size is 500 × 500 pixels. Some examples appear below.

Fig. 1. Samples of images
The dataset includes segmentation masks. Since our model performs classification, we excluded those masks from its inputs using shell commands; they remain useful for other tasks.
Implemented techniques
We must emphasize that until now there is a shortage of public data sets of breast cancer ultrasound images and it prevents the good performance of the algorithms. Because of this, the authors who made public the dataset we used, recommend augmenting data using GANs.
We trained one GAN per class to generate additional images, using 150 epochs for each training run.
The GANs did not produce usable images, so we did not use their outputs in this version. Further work could explore longer training and different architectures, while checking the quality and usefulness of generated images.

Fig. 2. MALIGNANT

Source: Compiled by authors using Matplotlib

Fig. 3. BENIGN

Source: Compiled by authors using Matplotlib

Fig.4. NORMAL

Source: Compiled by authors using Matplotlib
Network definition
Within the possible design patterns in Keras, subclassing has been implemented to use the low-level APIs of Keras. You can consult more information about this in the following article:
https://towardsdatascience.com/3-keras-design-patterns-every-ml-engineer-should-know-cae87618c7e3
The structure of the network consists of:
- Preprocessing layer: Resizing, Rescaling and Normalization
- Conv2D: 32 filters, stride 4, “same” padding and ReLU activation
- MaxPooling2D: pool_size (3, 3), “same” padding and stride 2
- Flatten
- Dense: 512 neurons and ReLU activation
- Dropout (0.4)
- Dense: 3 neurons and SoftMax activation
We started from AlexNet and adjusted the neuron counts, fully connected layers and dropout rates.
We use the Adam optimiser with learning rate of 0.0001, the Sparse Categorical Crossentropy loss function and Sparse Categorical Accuracy metric.

Fig. 5. Model summary — Source: Compiled by authors
Training
TensorBoard was used to observe the real-time behavior of the accuracy and loss values, which provides useful graphs to analyze results and many controls for their manipulation.

Fig. 6. Dashboard TensorBoard — Source: Compiled by authors
Early stopping
We use EarlyStopping as a form of regularization to avoid overfitting when training the model. For example, if the loss value stops decreasing, the training will stop even though all iterations have not been completed.
Conclusions and future works
WomanLife explores a possible tool to support ultrasound-image analysis.
The ambition is to support specialists, but further testing is needed to determine whether the model has clinical value. The educational application does not replace medical consultation.
From now on we intend to optimize the model using a GAN network to obtain greater precision and use techniques that find the correct parameters for training the model (Hyperparameter tuning).
We also built an application that accepts an image from the camera or gallery and returns model scores for the dataset’s three classes. Those scores are neither a diagnosis nor validated clinical probabilities of having cancer.
The model was developed in pure TensorFlow, converted, saved and exported to TensorFlow Lite.

Fig. 7. Sample of the operation of the application prototype — Source: Own elaboration

Fig. 8. Conversion from TensorFlow to TensorFlow Lite architecture — Source: Own elaboration
Sources
The notebook and mobile application are available in these GitHub repositories:
My repositories also contain other data science and machine learning projects. Comments and suggestions are welcome.
About the authors
Erick Calderín Morales
Systems engineer with experience in software development, master’s student in systems engineering and master’s degree in data science with an affinity for artificial intelligence.
Linkedin: https://www.linkedin.com/in/erick-calderin-5bb6963b/
Sharon Maygua Mendiola
Mechatronics engineering student with a degree in physics.
Linkedin: https://www.linkedin.com/in/sharon-sarai-maygua-mendiola-22288019a/
References
- Al-Dhabyani, W., Gomaa, M., Khaled, H., & Aly, F. (2019). Deep learning approaches for data augmentation and classification of breast masses using ultrasound images. Int. J. Adv. Comput. Sci. Appl, 10(5), 1–11.
- Al-Dhabyani, W., Gomaa, M., Khaled, H., & Fahmy, A. (2020). Dataset of breast ultrasound images. Data in Brief, 28, 104863.
- TensorFlow. 2021. Deep Convolutional Generative Adversarial Network | TensorFlow Core. [online] Available at: <https://www.tensorflow.org/tutorials/generative/dcgan>.
- Gowda. R., 2019. DCGAN Implementation in Keras explained. [online] Medium. Available at: <https://medium.com/@ramyahrgowda/dcgan-implementation-in-keras-explained-e1918fc930ea>.
- Poulopoulos. D, 2021. 3 Keras Design Patterns Every ML Engineer Should Know. [online] Medium. Available at: <https://towardsdatascience.com/3-keras-design-patterns-every-ml-engineer-should-know-cae87618c7e3>.
Project presentation: DemoDay
Repository
In the following repository you will find the code used to develop this application:
Written by
Erick Calderin
Systems Engineer passionate about deep learning and artificial intelligence
More artificial intelligence!
Saturdays.AI supports collaborative AI learning through courses and projects with social impact (#ai4good).
A story from the Saturdays.AI community. Originally published on Dec 31, 2021.
← More community stories



