Graffiti on train wagons may seem like a cosmetic issue at first glance, but for Deutsche Bahn it represents a serious operational and financial challenge. Each year, graffiti-related damage exceeds €12 million: costs driven not only by cleaning efforts but also by disrupted operations, additional coordination work, and reduced availability of affected wagons.
To address this issue more effectively, Deutsche Bahn is pursuing an ambitious goal: automating the detection and documentation of graffiti across its rolling stock. A foundational element of this initiative is the automatic recognition of UIC wagon numbers, the unique identifiers assigned to each rail vehicle in Europe. These numbers are crucial for fleet management, maintenance planning, asset tracking, and linking graffiti occurrences to specific wagons.
This case study demonstrates how a modern Computer Vision solution was developed to automatically detect and recognize UIC numbers (‘Union Internationale des Chemins de fer’ or ‘International Union of Railways’) under real-world conditions. The resulting system achieved approximately 98% recognition accuracy, creating a scalable foundation for future graffiti detection and significantly improving the efficiency of wagon identification processes.
The Challenge: Reliable Identification in Complex Visual Environments
At first glance, recognizing wagon numbers may appear trivial. Cameras capture passing trains, a system reads the number, and the job is done. In reality, the task is far more complex.
UIC numbers appear in images captured in uncontrolled outdoor environments where lighting, weather, and image quality vary significantly. Trains may be photographed during daylight, at night, in rain, snow, fog, or under strong shadows. In many cases, the UIC label is partially obscured by dirt, wear, reflections, or even graffiti itself.
To add to the complexity, UIC numbers are formatted differently depending on the wagon type. The typography, spacing, and exact placement differ across models, requiring the system to generalize across a wide range of appearances.
A further challenge comes from the image size. Large‑scale images—sometimes reaching 12,000 pixels in width—capture entire wagons or even entire trains. Within these massive images, UIC numbers appear as small, often noisy regions that require precise localization before text can be extracted.
Developing a system capable of dealing with this variability demands a solution that is robust, adaptive, and deeply integrated into a multi‑stage Computer Vision pipeline.
The Solution: A Multi‑Stage Deep Learning Workflow
To meet these challenges, the team developed a modular pipeline combining object detection, image enhancement, and optical character recognition (OCR). Each component processes the input to prepare it for the next stage, resulting in a highly reliable end-to-end system.
1. Detecting the UIC Region with RetinaNet
The first step was locating the UIC label within the image. A RetinaNet object detection model trained with MMDetection identifies the exact area containing the wagon number.
To achieve production-ready robustness, the training dataset was significantly expanded. The project started with only 223 annotated images, primarily containing ICE trains. Through additional data collection and annotation efforts, the dataset grew to 745 images containing more than 1,100 manually created labels. Special attention was paid to difficult edge cases such as poor lighting, motion blur, graffiti, and different wagon types.
The resulting detector achieved a mean Average Precision (mAP@0.5) of 94.8%, enabling highly reliable localization of UIC labels even under challenging conditions.
2. Extracting and Processing the Region of Interest
Once detected, the UIC region is extracted as an individual image crop. This isolates the number from the rest of the scene and prevents extraneous background elements from introducing noise into the OCR process. It also significantly reduces the computational load of subsequent processing steps.
3. Enhancing Readability via Auto‑Contrast
Because the quality of these image crops can vary widely, an automatic contrast enhancement step is applied. The auto‑contrast function elevates subtle brightness differences, improves the visibility of characters, and compensates for poor lighting, shadows, or surface contamination.
This preprocessing step ensures that the OCR model receives the cleanest possible representation of the UIC number.
4. Extracting the Number with PaddleOCR
The enhanced images are then processed with PaddleOCR, a fast and accurate OCR engine known for its robustness when handling low-resolution images, distorted characters, varying lighting conditions, and multilingual text. PaddleOCR extracts the sequence of digits and converts them into machine-readable text.
Even when characters are partially obstructed or slightly distorted, the model demonstrates strong performance in extracting the correct UIC number.
5. Rule‑Based Postprocessing for Verification
UIC numbers follow strict structural rules (a standardized 12-digit wagon identification code including an internal checksum digit) defined by international railway standards. This domain knowledge is used to validate and correct OCR outputs. Potential misread characters are adjusted, implausible patterns are filtered out, and the final result is checked against UIC formatting guidelines.
Only after this validation step is the number accepted as accurate.
Benefits for Deutsche Bahn
The automated extraction of UIC numbers marks an important milestone for Deutsche Bahn’s digital transformation efforts. It unlocks several operational advantages:
Accelerated Graffiti Detection
With wagons identified automatically, graffiti occurrences can be linked to specific assets without manual verification. This creates a reliable foundation for further automation in recognition and documentation.
More Efficient Maintenance and Cleaning Scheduling
Knowing which wagon is affected allows cleaning teams to be dispatched with precision. This reduces delays, minimizes downtime, and improves the planning of maintenance windows. Over time, Computer Vision can also help anticipate cleaning needs, as we’ve shown when forecasting dirt and pollution levels on vehicles.
Better Use of Operational Resources
Precise wagon identification leads to more efficient resource allocation across the network. Workshops, staff, and cleaning infrastructure can be coordinated more effectively, particularly in a system as large and dynamic as Deutsche Bahn’s.
Implementation and Technology Stack
The solution was developed within two months by a Computer Vision specialist experienced in deep learning, data annotation, and OCR technologies. Close collaboration with Deutsche Bahn ensured that the system was continuously validated against real operational needs and real‑world imagery.
To accelerate model development and experimentation, the training pipeline was optimized for GPU execution in an AWS-based environment. This reduced training times from approximately 12 hours to just 30 minutes, representing a 24x performance improvement. Faster training cycles enabled rapid iteration on model architectures, hyperparameters, and dataset enhancements while maintaining a production-ready deployment setup.
The project leverages a modern, extensible technology stack:
- Python as the primary development language
- MMDetection for training the RetinaNet detector
- CVAT for high‑quality data annotation
- PaddleOCR for text extraction
Together, these tools form a scalable and production-ready foundation for future enhancements.
The automated UIC recognition project demonstrates how Computer Vision can address real-world operational challenges in large industrial environments. Through a combination of deep learning, OCR technology, railway-specific validation rules, and a carefully engineered training dataset, the solution achieved 98% recognition accuracy while remaining robust against graffiti, varying lighting conditions, and different wagon types.
Beyond the technical metrics, the project provides Deutsche Bahn with a critical building block for future automated graffiti detection and more efficient fleet operations. It is a strong example of how AI can convert unstructured visual data into actionable business information, creating measurable value for asset-intensive organizations.








