🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Computer Vision System Design

AI System DesignComputer Vision SystemsđŸŸĸ Free Lesson

Computer Vision System Design

Module 11 - Building Production-Grade Vision Pipelines

What You'll Learn

  • 1Derive an end-to-end p99 latency budget from a camera frame interval and check a design against it
  • 2Compute fleet size and GPU count from camera count, frame rate, and measured batch throughput
  • 3Choose between classification, detection, and segmentation heads for a stated accuracy and latency target
  • 4Quantize and compile a model with INT8 and TensorRT and estimate the cost per million frames

Why This Matters

Computer vision powers autonomous vehicles, medical imaging, manufacturing quality control, and augmented reality. Designing a CV system means solving challenges in real-time inference, accuracy across diverse conditions, and deploying models at scale on heterogeneous hardware - from cloud GPUs to edge devices.

The numbers make the constraint concrete: a 30 FPS camera emits one frame every 33.3 ms, a 4K frame is 8.3 million pixels, and a fleet of 64 cameras generates 1,920 frames per second. If the serving path cannot absorb that rate the queue grows without bound and the system silently converts from real-time to batch. This lesson builds the latency, throughput, and cost arithmetic that turns a model benchmark into a deployment plan.


System Architecture Overview

Computer Vision System ArchitectureImage/Video InputCameras, Uploads, StreamsPreprocessingResize, Normalize, AugmentModel RouterTask-specific dispatchPost-ProcessingNMS, ThresholdingImage Classification- ResNet, EfficientNet- Vision Transformer (ViT)- ConvNeXt- Use case: Scene recognition, product categorization- Latency: 5-50ms (GPU), 100-500ms (CPU)- Top-1 Accuracy: 88-91% (ImageNet)Object Detection- YOLOv8, YOLO-NAS- DETR, RT-DETR- Faster R-CNN family- Use case: Autonomous driving, surveillance- Latency: 10-80ms (YOLO), 100ms+ (2-stage)- [email protected]: 50-75% (COCO)Segmentation- Mask R-CNN, SAM- U-Net, DeepLabV3+- SegFormer, Mask2Former- Use case: Medical imaging, satellite- Latency: 50-200ms (real-time)- mIoU: 45-60% (COCO panoptic)Cloud GPUA100, H100 clustersBatch processingHigh throughputEdge DevicesJetson, Coral, NPULow latencyQuantized modelsMobileCore ML, TFLiteONNX RuntimeNPU accelerationStreaming PipelineKafka + Flink/SparkReal-time frame processingBackpressure handlingMonitoring & ObservabilityLatency P50/P95/P99 - Throughput - Accuracy Metrics - Data Drift Detection - GPU Utilization - Error Rates

Image Classification Pipeline

Core Architecture

An image classification pipeline loads a pretrained CNN (e.g., EfficientNet-V2) and replaces the final classifier head with a linear layer matching the number of target classes. Input images go through a preprocessing stage - resize to 256px, center-crop to 224px, normalize with ImageNet statistics - before being passed through the model. Inference runs under torch.inference_mode() for optimized performance.

Batch Inference with Dynamic Batching

Dynamic batching collects incoming inference requests into batches up to a configurable max size (e.g., 32) within a time window (e.g., 10ms). This amortizes GPU overhead across multiple requests. Requests are prioritized, and results are dispatched back to callers asynchronously using asyncio.


Object Detection: YOLO Integration

YOLO-based detection services load a pretrained model (e.g., YOLOv8x), fuse convolution and batch norm layers for faster inference, and run detection with configurable confidence thresholds. Key parameters include IoU threshold (0.45), image size (644), and FP16 half-precision mode for speed. For video streams, YOLO supports built-in tracking (ByteTrack) with real-time callbacks per frame.

Detection Metrics and IoU

A predicted box counts as a true positive only when its overlap with a ground truth box clears a matching threshold. That overlap is intersection over union:

At IoU = 0.50 a detector is graded on coarse localization, which is generous for autonomous driving but fine for image tagging. At IoU = 0.95 the same weights often lose 20 to 30 mAP points, so the threshold has to travel with the number you quote. COCO reports mAP averaged over ten thresholds from 0.50 to 0.95:

A model that scores 52 percent [email protected] and 35 percent mAP@[0.50:0.95] is telling you it finds the objects but boxes them loosely, and the fix is usually a longer training schedule or a finer anchor assignment, not a bigger backbone.


Vision Transformer (ViT) Architecture

ViT works by splitting an image into fixed-size patches (e.g., 16x16), projecting each patch into an embedding dimension via a convolutional layer, prepending a learnable CLS token, and adding positional embeddings. The sequence of patch embeddings is then processed by transformer encoder blocks, each containing multi-head self-attention and an MLP with GELU activation, connected via residual connections and layer normalization.


Edge Deployment Optimization

Edge deployment uses ONNX Runtime for cross-platform inference with provider fallback (CUDA -> CPU). Models are optimized through graph optimization and INT8 dynamic quantization. For NVIDIA hardware, TensorRT compiles ONNX models with FP16 support, custom workspace allocation, and layer fusion for maximum throughput. The build process parses the ONNX graph, configures builder flags, and serializes the optimized engine.


Multi-Task Vision Pipeline

A multi-task vision pipeline routes frames through task-specific models (classifier, detector, segmentor) based on requested tasks. For video streams, it reads frames from a video source, processes each frame through the requested models concurrently, and dispatches results via callbacks. Models can be loaded on demand to save memory.


Capacity Planning: Frames to GPUs

Every stage of a vision request spends from one deadline. A frame is queued, preprocessed, run through the model, and post-processed, so the tail latency is the sum of the four stages:

A 30 FPS camera produces a frame every 33.3 ms, and transport plus scheduling absorbs about 10 ms of that, leaving 23 ms for the pipeline. A measured split on an A100 running YOLOv8s at 640 x 640 in FP16 is 2 ms queue, 1 ms preprocessing, 16 ms inference, and 2 ms of non-maximum suppression: 21 ms of the 23 ms available. Inference is 76 percent of the budget, so model choice, not infrastructure tuning, sets the ceiling.

Throughput comes from the same measurements. Serving batches of size that take seconds gives a per-GPU rate of:

A batch of 32 frames in 45 ms yields 711 images per second, about 7x the single-request rate. Fleet size for cameras at frames per second with utilization headroom is:

Designing for 100 percent utilization instead gives 2.7 GPUs, which fails on the evening traffic peak. That is why capacity plans carry 30 percent headroom rather than trusting an average.

Cost per Prediction

Capacity is half the decision; unit economics is the other half. With a GPU priced at USD per hour:

At p = USD 3.50 per hour, R = 711 images per second, and u = 0.70, one million frames costs USD 1.95. The same arithmetic on cheaper hardware changes the ranking, so price the whole table rather than only the fastest row.

TargetHardwareModel and inputPrecisionp50 latencyThroughputUSD per 1M frames
Cloud batchA100 40GBYOLOv8s at 640 x 640FP1616 ms711 img/s1.95
Cloud realtimeL4YOLOv8n at 640 x 640FP169 ms210 img/s1.51
Edge gatewayJetson Orin NXYOLOv8n at 640 x 640INT811 ms90 img/s-
MobileApple A17 NPUMobileNetV3 SSD at 320 x 320INT88 ms120 img/s-

Common Mistakes

Sizing the fleet from mean latency

Fix: Budget with p99: at 30 FPS the whole pipeline must finish inside 33.3 ms or the queue grows without bound.

Quantizing without a calibration set

Fix: Run INT8 calibration on 200 to 500 representative images, otherwise mAP can drop 3 to 8 points.

Accepting on aggregate mAP alone

Fix: Add a per-class recall gate, since rare classes disappear inside a healthy average mAP.

Best Practices

  • Pin resize, crop, and normalize in the same artifact as the weights so training and serving preprocessing cannot drift apart
  • Batch dynamically with a 5 to 10 ms window to trade a little latency for 2x to 4x GPU throughput
  • Profile p50 and p99 on the target device before committing to a model size, since datacenter numbers hide edge memory limits

Key Takeaways

  • End-to-end p99 is the sum of queue, preprocessing, inference, and post-processing, and a 30 FPS stream caps the whole budget at 33.3 ms
  • 64 cameras at 30 FPS is 1,920 frames per second; at 711 img/s per A100 and 70 percent utilization the fleet is 4 GPUs
  • Cost per frame is p / (3600 x R x u), so an A100 at USD 3.50 per hour serves 1M frames for USD 1.95
  • COCO mAP averages IoU thresholds from 0.50 to 0.95, so always quote the threshold with the number

Frequently Asked Questions

How many GPUs do I need for 64 cameras at 30 FPS?

Start from the aggregate rate: 64 cameras x 30 FPS = 1,920 frames per second. A batched service measured at 711 images per second per A100, derated to 70 percent sustained utilization, covers 498 frames per second, and 1,920 / 498 = 3.86, which rounds up to 4 GPUs. If you skip the derating you buy 2.7 GPUs worth of hardware and the sixth camera shard queues during peak hours.

Why does non-maximum suppression run after the model?

The detector emits many overlapping boxes per object because each anchor or query can fire independently. NMS sorts detections by confidence, keeps the highest, and suppresses every box with IoU above the threshold (0.45 in the pipeline above), which typically removes 85 to 95 percent of raw boxes. It costs about 2 ms, so it belongs in the latency budget rather than being treated as free post-processing.

When should you pick a Vision Transformer over a CNN?

ViT models with 16 x 16 patches capture long-range dependencies in one attention layer instead of many pooling layers, and they match or beat CNNs on ImageNet once training data passes roughly 10 to 20 million images. Below that, a ConvNeXt or EfficientNet trained with strong augmentation reaches the same accuracy with 30 to 50 percent less inference cost. Choose ViT when you have the data and the budget, and a modern CNN when you do not.

Interview Questions

Q1: How do you handle class imbalance in image classification?

Combine augmentation (random crops, flips, CutMix, MixUp) with class-weighted or focal loss and oversampling of minority classes. Focal loss down-weights easy negatives, so gradient flow concentrates on the misclassified tail where the imbalance actually hurts.

Q2: Compare YOLO and Faster R-CNN for real-time detection.

YOLO runs 30 to 100 FPS with [email protected] in the 50 to 60 range on COCO; Faster R-CNN gains 3 to 6 mAP but drops to 5 to 15 FPS. For edge targets YOLOv8-nano compiled with TensorRT is the usual pick, RT-DETR when transformer detection quality matters more than raw FPS.

Q3: How do you optimize a vision model for edge deployment?

Quantize to INT8 with a 200 to 500 image calibration set, then prune or distill into MobileNet or EfficientNet-Lite, then compile with TensorRT, ONNX Runtime, or Core ML. Profile on the target device, because a laptop benchmark hides the memory-bandwidth ceiling that dominates on a Jetson or an NPU.

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-07

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert AI System Design Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement