RF-DETR P&ID Symbol Detector
A fine-tuned RF-DETR model for detecting Process & Instrumentation Diagram (P&ID) symbols.
The model was developed as part of the paper:
Towards Automated P&ID Digitization: Graph-Based OCR Consolidation and Global Symbol–Tag Association
Accepted at ACM Symposium on Document Engineering (DocEng 2026) .
The detector recognizes the graphical symbols appearing in industrial P&IDs and is intended as the first stage of a complete P&ID digitization pipeline.
Training
The model was fine-tuned for 10 epochs on a custom P&ID symbol dataset containing 32 symbol classes. During training, both the base model and its Exponential Moving Average (EMA) weights were monitored. The EMA model was selected as the final checkpoint because it consistently achieved higher detection performance.
Detected Classes
The model detects the following classes:
ID Class 0 Not_used 1 Gate_Valve 2 Ball_Valve 3 Globe_valve_NO 4 Gate_valve_NO 5 Globe_valve_NO 6 Butterfly_valve 7 Plug_valve 8 Check_valve 9 Diaphragm_valve 10 Needle_valve 11 Half_Filled_Gate_Valve 12 Gate_Valve_NC 13 Globle_valve_NC 14 Control_Valve 15 Rotary_Valve 16 Ball_valve_NC 17 Paddle_blind 18 Spectacle_blind_Closed 19 Spectacle_blind_Open 20 Reducer 21 Flange_or_Nozzle 22 Rupture_disk 23 Pipe_Insulation_or_Tracing 24 Flow_Arrow 25 Sight_glass 26 Instrument_Field 27 Instrument_Field 28 Instrument_Panel 29 Instrument_Aux_Panel 30 Box 31 Instrument_Panel 32 Box
Installation
pip install rfdetr supervision
For tiled inference:
Load the model
1 from rfdetr import RFDETRBase
2
3 model = RFDETRBase (
4 pretrain_weights = "checkpoint_best_total.pth"
5 )
Inference (without SAHI)
1 import cv2
2 import supervision as sv
3
4 image = cv2 . imread ( "image.png" )
5
6 detections = model . predict (
7 image ,
8 threshold = 0.5
9 )
10
11 labels = [
12 f" { CLASS_NAMES [ c ] } { conf : .2f } "
13 for c , conf in zip (
14 detections . class_id ,
15 detections . confidence
16 )
17 ]
18
19 annotated = image . copy ( )
20
21 annotated = sv . BoxAnnotator ( ) . annotate (
22 annotated ,
23 detections
24 )
25
26 annotated = sv . LabelAnnotator ( ) . annotate (
27 annotated ,
28 detections ,
29 labels
30 )
31
32 sv . plot_image ( annotated )
Inference using SAHI
For very large engineering drawings (typically PDF pages rendered at high resolution), tiled inference significantly improves recall.
Recommended parameters:
Slice size: 1280 × 1280
Overlap: 20%
1 from sahi import AutoDetectionModel
2 from sahi . predict import get_sliced_prediction
3
4 detection_model = AutoDetectionModel . from_pretrained (
5 model_type = "roboflow" ,
6 model = model ,
7 confidence_threshold = 0.5 ,
8 category_mapping = CLASS_NAMES ,
9 device = "cuda" ,
10 )
11
12 result = get_sliced_prediction (
13 image ,
14 detection_model = detection_model ,
15 slice_height = 1280 ,
16 slice_width = 1280 ,
17 overlap_height_ratio = 0.2 ,
18 overlap_width_ratio = 0.2 ,
19 )
The resulting detections are available in
result.object_prediction_list
or can be converted into Supervision detections for visualization.
Example
Without SAHI:
Large drawings may miss small symbols.
With SAHI:
Large drawings are processed tile-by-tile, improving the detection of small symbols and densely packed regions.
📊 Test Performance
Overall Performance
Metric Score mAP@0.50:0.95 97.89% mAP@0.50 99.96% Precision 99.97% Recall 99.00%
Per-Class Performance
Class mAP@50:95 mAP@50 Precision Recall Gate_Valve 0.9906 1.0000 1.0000 0.99 Ball_Valve 0.9908 0.9999 1.0000 0.99 Globe_valve_NO 0.9904 1.0000 1.0000 0.99 Gate_valve_NO 0.9896 1.0000 1.0000 0.99 Butterfly_valve 0.9751 1.0000 1.0000 0.99 Plug valve 0.9775 1.0000 1.0000 0.99 Check_valve 0.9805 1.0000 1.0000 0.99 Diaphragm_valve 0.9812 1.0000 1.0000 0.99 Needle_valve 0.9950 1.0000 1.0000 0.99 Half_Filled_Gate_Valve 0.9915 1.0000 1.0000 0.99 Gate_Valve_NC 0.9881 1.0000 1.0000 0.99 Globle_valve_NC 0.9913 1.0000 1.0000 0.99 Control_Valve 1.0000 1.0000 1.0000 0.99 Rotary_Valve 0.9519 1.0000 1.0000 0.99 Ball_valve_NC 0.9608 1.0000 1.0000 0.99 Paddle_blind 0.9606 1.0000 1.0000 0.99 Spectacle_blind_Closed 0.9627 1.0000 1.0000 0.99 Spectacle_blind_Open 0.9651 0.9999 1.0000 0.99 Reducer 0.9864 1.0000 1.0000 0.99 Flange_or_Nozzle 0.9445 0.9901 1.0000 0.99 Rupture_disk 0.9843 0.9997 1.0000 0.99 Pipe_Insulation_or_Tracing 0.9864 1.0000 1.0000 0.99 Flow_Arrow 0.9447 1.0000 1.0000 0.99 sight_glass 0.9901 1.0000 1.0000 0.99 Instrument_Field 0.9881 0.9998 0.9982 0.99 Instrument_Panel 0.9890 0.9999 0.9947 0.99 Instrument_Aux_Panel 0.9875 0.9999 0.9982 0.99 Box 0.9482 1.0000 0.9981 0.99
🚀 Highlights
33 P&ID symbol classes
mAP@50: 99.96%
mAP@50:95: 97.89%
Precision: 99.97%
Recall: 99.00%
Control Valve achieved perfect detection performance (100% mAP).
More than 85% of the classes achieved a mAP@50:95 greater than 98%.
The EMA model consistently outperformed the base model during training and was selected as the final released checkpoint.
Optimized for high-resolution P&ID drawings and compatible with SAHI for sliced inference on large engineering diagrams.
Citation
If you use this model in your research, please cite:
1 @inproceedings{XXXX,
2 title={Towards Automated P\&ID Digitization: Graph-Based OCR Consolidation and Global Symbol--Tag Association},
3 author={...},
4 booktitle={Proceedings of the ACM Symposium on Document Engineering (DocEng)},
5 year={2026}
6 }
Acknowledgements
This model is built upon the excellent RF-DETR object detector and supports tiled inference through SAHI .
License
Please refer to the license accompanying this repository.