If you are still shipping 4โ€“8 GB container images just to run an object detection model on a CPU server, you are burning cycles and money. Developer Kenan Tabak recently detailed how to strip away the bloat of PyTorch, Ultralytics, and Hugging Face dependencies in production, relying instead on a lean stack of onnxruntime, numpy, and Pillow totaling roughly 150 MB. This approach, documented in a new DEV.to post, demonstrates that you can unify six different object detection architectures into a single inference engine without compromising accuracy.

The Unified Detector Architecture

Tabak's solution, the UnifiedONNXDetector class, initializes a single ort.InferenceSession to handle a diverse mix of models: YOLO26, YOLO11, YOLOv9c, RT-DETR-L, D-FINE-M, and RF-DETR-Base. By bypassing the training frameworks entirely, the code avoids the notorious version conflicts between CUDA and PyTorch that plague many deployment pipelines. The benchmark results on a Colab High-RAM CPU show that D-FINE-M achieves a median latency of 336.6 ms, nearly matching the 337.4 ms of YOLO26m, but with the added benefit of skipping Non-Maximum Suppression (NMS) entirely due to its query-based architecture.

Silent Failures: The Tensor Traps

The most valuable part of this write-up is the analysis of silent errors that do not throw exceptions but destroy model accuracy. One critical trap involves RF-DETR-Base, which requires ImageNet normalization (mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) unlike the standard [0, 1] scaling used by YOLO models. Failing to apply this specific normalization results in a threefold drop in recall and produces ghost boxes, yet the code runs without a single warning. Similarly, RF-DETR outputs a background channel (C+1) that must be sliced out before thresholding, or else the model will hallucinate fake classes.

Performance and Preprocessing Nuances

The article highlights distinct preprocessing requirements that often get hidden by high-level libraries. For YOLO families, the letterbox resizing technique is mandatory, but developers frequently forget the inverse scaling (x = (x - pad_x) / scale) when mapping predictions back to the original image coordinates, leading to misaligned bounding boxes on vertical or wide images. Conversely, RT-DETR-L requires direct resizing without letterboxing. Tabak also notes a subtle double-sigmoid error when using RT-DETR-L via Ultralytics ONNX exports, where the graph already applies sigmoid activation, causing background scores to spike if applied again in post-processing.

Key Takeaways

  • Dependency Weight: Switching to onnxruntime + numpy + Pillow reduces the inference stack from gigabytes to ~150 MB.
  • Normalization Matters: RF-DETR-Base fails silently with ~3x recall drop if ImageNet mean/std normalization is not explicitly applied.
  • Background Channels: DETR-family models like RF-DETR output C+1 channels; failing to slice the background channel causes IndexError or false positives.
  • Global Top-K: Official DETR evaluations use global top-k selection from the 300x C score pool, not per-query argmax, for precise mAP matching.

The Bottom Line

This is a masterclass in production discipline. If you cannot explain your tensor shapes and normalization pipelines in pure NumPy, you do not understand your deployment. The source provides open weights for all six architectures on Hugging Face, allowing builders to replicate the UnifiedONNXDetector results immediately.