In development

Technical note

From PyTorch to Jetson: our TensorRT optimisation pipeline

A model that scores well on a validation set is only half of an inspection system. The other half is getting a decision out of it fast enough, on a small device bolted next to a conveyor, for every part. This note describes how a model trained in our cloud becomes the engine that runs on a station, and the latency budget we design against.

The constraints

A typical station has one to four industrial cameras, each delivering frames of two to five megapixels, triggered by the PLC as a part arrives. The reject mechanism needs a decision before the part passes the diverter. We design every station against a target of under 50 ms per frame from capture to decision. That number is a design target, not a measured customer result; achievable latency depends on resolution, model size, camera count and the Jetson Orin module chosen.

Stage 1: export

Models are trained in PyTorch, or with NVIDIA TAO Toolkit, which itself exports deployable formats. For PyTorch models we export to ONNX with a fixed input resolution per station, because dynamic shapes cost performance on the device. Export is followed by an automatic parity check: the ONNX model and the PyTorch model are run on the same validation images and their outputs must agree within a small tolerance. Most export problems — unsupported operators, silent changes in interpolation or normalisation — are caught here rather than on the line.

Stage 2: building the TensorRT engine

TensorRT compiles the ONNX graph into an engine specific to the GPU architecture and TensorRT version on the target device. It fuses layers, selects kernels and plans memory. Because engines are not portable across device types, our build service produces one engine per supported Jetson module and JetPack version, and the edge agent downloads the one that matches its hardware.

Precision: FP32, FP16, INT8

  • FP16 is our default starting point. On Jetson Orin it typically gives a large speed-up over FP32 with negligible accuracy change for convolutional vision models.
  • INT8 can be faster again and reduces memory bandwidth, but quantising activations needs calibration. We use post-training calibration with a representative set of a few hundred images from the station itself — good parts and defects, under the lighting the station actually sees. Calibrating on generic images is a common cause of accuracy loss.
  • Layers that are sensitive to quantisation, such as the final layers of a segmentation head, can be kept in FP16 while the backbone runs in INT8.

The accuracy gate

No optimised engine is promoted on speed alone. Each candidate is evaluated on the station's held-out validation set and compared with the FP32 reference. For detection we compare per-class precision and recall at the operating threshold; for anomaly models we compare image AUROC and the false reject rate at the agreed catch rate. If the optimised engine falls outside the tolerance agreed for that station, the build falls back to the next higher precision. The chosen precision and the comparison are stored with the model version and visible in the audit log.

Stage 3: DeepStream integration

On the device, the engine runs inside a DeepStream pipeline. DeepStream lets us keep the whole path on the GPU: camera frames are ingested, decoded where necessary, resized and normalised, batched across cameras, passed to TensorRT and post-processed without round trips to CPU memory. Post-processing — non-maximum suppression for detection, heatmap computation and thresholding for anomaly models — produces the decision, which the agent sends to the PLC over digital I/O, with OPC UA and MQTT in development.

Two details matter more than they look. First, batching across cameras: when several cameras trigger together, one batched inference is cheaper than several single ones. Second, decoupling image upload from the decision path: saving images for review or retraining happens asynchronously so that a slow network can never delay a reject signal.

The latency budget

We allocate the 50 ms target across the pipeline and measure each stage separately during station sizing. All values below are targets for a single-camera station at around 5 MP on Jetson Orin, not measured customer results.

StageBudgetLabel
Frame acquisition and transfer from camera8 msTarget
Pre-processing (resize, normalise) on GPU5 msTarget
TensorRT inference25 msTarget
Post-processing and decision5 msTarget
PLC signal2 msTarget
Total45 ms (5 ms headroom)Target

If a station cannot meet its budget at the required resolution, the options are explicit: crop to a region of interest, use a smaller backbone, move to INT8 if the accuracy gate allows, or choose a larger Orin module. We make that call with the customer before deployment, not after.

Monitoring after deployment

The agent reports per-stage latency percentiles, throughput, GPU utilisation and device temperature. Sustained thermal throttling is one of the more common causes of latency creep on fanless enclosures, so we flag it early. The drift monitor runs alongside, comparing image statistics and model confidence with the training distribution.

Status

The export, build and accuracy-gate pipeline is in development and being exercised on sample data and public datasets. Benchmarks will be published here labelled as internal benchmarks on public datasets, with the device, JetPack version and model configuration they came from.


← All research notes