2025

Machine Learning Techniques for Anomaly Detection in Pharmaceutical Quality Control

Doctoral work on machine learning and computer vision for anomaly detection in pharmaceutical quality control.

Ph.D. thesisOpen access

Authors

Affiliations

Correspondence

niccolo.ferrari@unife.it

Abstract

The rapid advancements in Machine Learning (ML) and Computer Vision (CV) have revolutionized industrial quality control, especially in pharmaceutical manufacturing, where strict safety and regulatory standards demand exceptional product quality. Traditional quality control methods largely reliant on manual inspection are time-consuming, error-prone, and lack the scalability required for high-throughput production. This dissertation addresses these issues by developing ML-driven techniques for anomaly detection in pharmaceutical quality control, with a focus on high-speed industrial lines. A primary challenge is detecting Out-of-Distribution (OOD) anomalies, namely defects that deviate from the standard production distribution. Traditional Computer Vision methods based on blob-analysis struggle with such anomalies because of their rigid, parameter-dependent nature. In contrast, modern deep learning approaches, which learn from extensive datasets, offer enhanced flexibility and scalability. However, deploying these models in real-time environments introduces further challenges, including dataset imbalance, strict inference time limits, and hardware constraints. The chief contribution of this thesis is the development of the novel Generative-Reconstructive-Discriminative Network (GRD-Net), engineered to achieve both accurate anomaly detection and efficient real-time processing. GRD-Net exploits the capabilities of Generative Adversarial Networks (GANs) to reconstruct defect-free images while simultaneously generating heatmaps that highlight anomalous regions. This dual-stage process improves defect localization precision and overall system accuracy, marking a significant advancement over traditional methods particularly in detecting small and irregular defects. Benchmarking on both public and proprietary pharmaceutical datasets confirms its robustness and efficiency in real-world conditions. In parallel, the research introduces a derivative architecture, the Residual Generative Adversarial Network for Anomaly Detection (ResGANAD), specifically optimized for industrial deployment. Successfully integrated into high-speed Blow-Fill-Seal (BFS) vial inspection lines, ResGANAD detects OOD anomalies in real-time with minimal disruption to production throughput while maintaining high accuracy. Furthermore, this dissertation evaluates and adapts embedding similarity-based techniques such as PaDiM and PatchCore, which prove effective in scenarios with scarce labeled anomaly data. Although these methods traditionally rely on memory-intensive components like memory banks limiting their scalability, the thesis proposes adaptations that reduce dependence on pre-trained networks and enhance performance in large-scale industrial settings. Extensive experimental results demonstrate the efficacy of the proposed models across a diverse range of real-world defects, including subtle anomalies that conventional inspection algorithms often overlook. Moreover, the models are rigorously tested against the stringent regulatory and safety requirements of pharmaceutical manufacturing, ensuring both high detection accuracy and real-time operational capability. In summary, this dissertation advances the application of machine learning to anomaly detection in pharmaceutical quality control. The developed systems enhance the accuracy and speed of defect detection while offering scalable solutions suitable for high-throughput industrial environments. By integrating these advanced ML techniques, manufacturers can improve product quality, reduce reliance on manual inspection, and achieve higher operational efficiency. Future work will focus on further optimizing these models, adapting them to emerging industrial processes, and incorporating explainability mechanisms to strengthen trust and regulatory compliance.

Keywords

Machine learningComputer visionAnomaly detectionPharmaceutical quality controlIndustrial inspection