Recognition of Mastitis in Cow Mammary Ultrasound Images

This project is a collaboration between faculty members in the Department of Animal Science (Sheila Andrew), Biomedical Engineering (Patrick Kumavor), and the AI Lab (Cuong Do).


  • Mastitis is the most common disease in the dairy industry.
  • Inflammation of the mammary gland due to bacterial infection.
  • Typically caused by an immune response to bacteria having infiltrated the teats.

Figure 1: A scan featuring an uninfected mammary quarter demonstrating an even and uninterrupted distribution of gray to black and white areas

Figure 2: A scan featuring an infected mammary quarter demonstrating  a more severe difference in the range of gray to black and white areas


Severe Effect: Cows with an infection have reduced milk yield, increased body temperature, and reduced mobility.

Limitation: The dataset is small in size, including 34 examples of normal cases, and 23 examples of infected cases.

Approach: The size of the dataset is small, which isn’t suitable for a Deep Learning model which needs a significant amount of data. We take a Transfer Learning approach, which borrows network weights of currently available large networks, such as VGG16, VGG19, Xception, Inception, and DenseNet as the base model, and build the fully connected layers on the top.

The approach was adjusted later with using random crop and rotational augmentation to increase the data size.

DensetNet Architecture – Image from

Software: We use TensorFlow, together with other image processing and ulitilty packages such as Open CV and PIL.

Modeling: Data is split into Training/Validation/Test partitions. Hyperparameter optimization runs on a grid of learning rate, batch size, dropout rate, and epochs.

Result example: