BT San Technology

5 August 2026

Deploying YOLO on Jetson: measuring from image capture to result

24 min read · Machine vision

Illustration: machined parts on a conveyor under a camera, an AI box and a monitor drawing detection boxes around the parts
AI-generated illustration

The quote says the model runs at 400 images per second. Once the camera is connected, the machine responds several times slower, and on some frames the conveyor has already passed the sorting point. The 400 is not a lie. It only measures the time the model is running. Capturing the image, resizing it, decoding the output and sending the result to the machine are not in that number at all.

This article builds a tool that times each stage of an object-detection pipeline from image capture to sending the result. It calculates p50, p95 and p99 and compares the model-only number with the whole-pipeline number. It then explains the NVIDIA tools used to measure on a real Jetson: trtexec, nvpmodel, jetson_clocks and tegrastats, citing the documents that were actually read.

A clear statement up front: the sample code ran on an ordinary CPU machine, not a Jetson, and it did not use a GPU. The inference stage is a stand-in that multiplies numpy matrices, not YOLO. So the timings in this article say nothing about a Jetson, and they differ on every machine. What the example teaches is how to measure and how to read the results, not the speed of any board.

The real problem: the model's number is not the time the machine waits

Consider three hypothetical situations. They are not from any BT San customer project.

  • Suppose a metal-parts factory sees a model speed figure on a vendor's web page and sets its budget by it. After the camera and PLC are connected, the real response time is the total of all stages, which is longer, because preprocessing and post-processing take at least as much time as the model.
  • Suppose a team measures an average of 30 frames per second and decides that is enough. But 1 frame in 100 is several times slower than the average, so a conveyor that must decide within a time limit misses now and then. The average hides the tail of the distribution.
  • Suppose a test on the bench uses the maximum power mode, but the real installation is in a hot cabinet set to a power-saving mode. The real speed is lower than what was measured, and nobody knows why.

All three are fixed by the same measurement discipline: measure every stage, exclude warm-up, report percentiles, separate throughput from latency, and measure under the same conditions as real use.

What the NVIDIA documents say, and what they do not

ToolWhat the documentation saysEffect on how to measure
trtexecThe TensorRT README describes it as a tool for using TensorRT without writing your own application. It benchmarks network speed with random or user-supplied inputs and builds serialized engines. Flags include --onnx --saveEngine --loadEngine --fp16 --int8 --exportTimesYou get the engine time only, not image capture, resizing or output decoding. The README does not detail the output fields or the flags for warm-up. Check trtexec --help on the machine you actually use.
nvpmodelUse sudo /usr/sbin/nvpmodel -q to see the current mode and -m with a mode number to set it. The documentation says that once set, the module stays in that mode until changed, and it persists across reboots.Record the mode number every time you measure. Numbers that do not state the mode cannot be compared.
MAXN modeThe documentation describes it as no limit on cores and the highest frequencies. It suits experiments with clock tuning, but it is not always the mode with the highest performance, because the hardware slows down when total power exceeds the TDP budget. Running heavy workloads in this mode for a long time is not recommended.Do not use MAXN as the reference number by default. Measure in the mode you will install with.
jetson_clocksA script that sets fixed maximum frequencies for the CPU, GPU and EMC, where the maximum is determined by the nvpmodel mode. It has --show --store --restore. The documentation says that after running it you cannot change the nvpmodel mode without a reboot.Use it to keep clocks steady during measurement, and record whether it was on. Results with it on and off can differ.
tegrastatsReports memory, each CPU core, GR3D_FREQ (GPU load and frequency), EMC, temperatures and power on each rail. By default it prints every 1000 milliseconds. Change that with --interval and write to a file with --logfile.Run it alongside the measurement to see whether clocks dropped or temperature rose during the run.
Summary of the documents that were read, accessed on 2026-11-21. The nvpmodel and jetson_clocks pages come from the Jetson Linux Developer Guide release r36.4.3. Mode names and numbers differ by module, so check the documentation for the JetPack release you use.

The TensorRT best-practices documentation that was read says only that GPU clocks, power and thermal throttling are environmental factors to control so that numbers are stable and repeatable. The details of how to measure are in other chapters, which this article does not cite.

Overview of the example

The example is plain python3 with numpy. There is nothing to install, no network and no GPU. All data is generated from a fixed seed. The timings change with the machine and with each run.

FilePurpose
bench.pyA harness that times five stages, excludes warm-up, prints a percentile report, and compares the sequential version with the two-thread version
vision.pyLetterbox, normalise, IoU, box decoding and NMS with numpy
stats.pyPercentile with linear interpolation, and summarize
test_bench.pyTests for IoU, NMS, letterbox and percentile, with no timing tests
output.txtThe actual stdout of python3 bench.py
README.mdRun commands and things to know
Files in the jetson-yolo-end-to-end-benchmark folder

Step 1: time each stage with one clock

Use time.perf_counter. The Python documentation describes it as the clock with the highest resolution for measuring short durations, and its reference point is undefined, so only the difference between two calls is meaningful. The function run_frame wraps each stage with one clock read. The capture stage creates a synthetic 640x480 image. The inference stage calls the matrix-multiplication stand-in. The handoff stage in the example is just appending to an in-memory list. The real one is a write to a PLC or MQTT, which may be the slowest stage.

bench.py · lines 41–57
def run_frame(i, rng_img, raws, net, sink):
    """One frame through all stages. Returns per-stage ms and end-to-end ms."""
    t = [time.perf_counter()]
    frame = rng_img.integers(0, 256, size=(H, W, 3), dtype=np.uint8)  # capture
    t.append(time.perf_counter())
    img, lb = letterbox(frame, SIZE)
    x = normalise(img)
    t.append(time.perf_counter())
    net(x)
    t.append(time.perf_counter())
    boxes, scores = decode(raws[i % len(raws)], 0.5, lb)
    keep = nms(boxes, scores, 0.45)
    t.append(time.perf_counter())
    sink.append((i, len(keep)))  # simplified: in-memory list; production = PLC/MQTT/DB write
    t.append(time.perf_counter())
    ms = [(t[k + 1] - t[k]) * 1000 for k in range(5)]
    return ms, (t[-1] - t[0]) * 1000
bench.py: the run_frame function times each stage

The inference stage seen in the same file is the class StandIn, which multiplies fixed-size matrices in three layers. It exists only so that this stage takes a few milliseconds on a CPU. It has nothing to do with YOLO and does not detect anything. To measure on a real board, replace it with a call to your engine. The rest of the harness can be reused as is.

Step 2: warm-up must run but must not be counted

The first few runs are slower than normal because of caches, memory allocation and libraries loading themselves. On a device with a GPU, the context and engine are also initialised. The example runs the first 30 frames and discards them, so only the remaining 300 frames are counted. The right number of warm-up frames depends on the data: look at the round where the time becomes stable. The 30 in the example is a value we chose ourselves.

bench.py · lines 60–77
def run_sequential(frames, warmup, seed=7):
    rng = np.random.default_rng(seed)
    net = StandIn(rng)
    raws = [make_raw(rng) for _ in range(16)]
    img_rng = np.random.default_rng(seed + 1)
    sink = []
    for i in range(warmup):  # warm-up: executed, never recorded
        run_frame(i, img_rng, raws, net, sink)
    per = {s: [] for s in STAGES}
    e2e = []
    t0 = time.perf_counter()
    for i in range(frames):
        ms, total = run_frame(i, img_rng, raws, net, sink)
        for s, v in zip(STAGES, ms):
            per[s].append(v)
        e2e.append(total)
    wall = time.perf_counter() - t0
    return per, e2e, frames / wall
bench.py: run_sequential runs warm-up first, then collects times

Step 3: percentiles: p50 shows normal, p99 shows the bad day

p50 is the median. p95 is the value that 95 percent of frames are faster than. p99 is the value that 99 percent of frames are faster than. A conveyor that must decide before the part passes the sorting point needs to look at p99 or the maximum, not the average. The example writes its own percentile with linear interpolation, the same as the default of numpy.percentile (the numpy documentation says the default method is linear), and has a test against numpy to make sure they match.

stats.py · lines 5–16
def percentile(values, q):
    """Linear interpolation between closest ranks (same rule as numpy's default).
    q is 0..100. Raises ValueError on empty input or q out of range."""
    if not values:
        raise ValueError("empty sample")
    if not 0 <= q <= 100:
        raise ValueError("q must be within 0..100")
    xs = sorted(values)
    h = (len(xs) - 1) * q / 100.0
    lo = math.floor(h)
    hi = min(lo + 1, len(xs) - 1)
    return xs[lo] + (h - lo) * (xs[hi] - xs[lo])
stats.py: percentile

The limit of percentiles is sample size. A p99 from 300 frames depends on only three slow frames. To report a p99 you can trust, measure thousands of frames or more, and repeat the measurement several times.

Step 4: preprocess: letterbox must be correct in both directions

Most detectors take a square image, so the image is resized while keeping its aspect ratio and then padded. This is called letterbox. A 640x480 image is resized with scale 1.0 and padded 80 pixels on the top and on the bottom. A 480x960 image is resized with scale 0.667 and padded 160 pixels on the left and on the right. The scale and the padding must be kept, because the post-process stage needs them to map box coordinates back to the original image. If you forget this step, the boxes will be offset from the real part.

vision.py · lines 5–13
def letterbox_params(w, h, size):
    """Scale to fit a size x size square, keep aspect ratio, centre with padding.
    Returns (scale, new_w, new_h, pad_x, pad_y); pad is the left/top offset."""
    if w <= 0 or h <= 0 or size <= 0:
        raise ValueError("w, h and size must be positive")
    scale = min(size / w, size / h)
    new_w = max(1, round(w * scale))
    new_h = max(1, round(h * scale))
    return scale, new_w, new_h, (size - new_w) // 2, (size - new_h) // 2
vision.py: letterbox_params calculates the scale and padding
vision.py · lines 16–26
def letterbox(img, size, fill=114):
    """img: HxWx3 uint8. Nearest-neighbour resize (simplified: production uses
    bilinear or a GPU kernel). Returns (size x size x 3 uint8, params)."""
    h, w = img.shape[:2]
    scale, nw, nh, px, py = letterbox_params(w, h, size)
    ys = np.minimum((np.arange(nh) / scale).astype(np.int64), h - 1)
    xs = np.minimum((np.arange(nw) / scale).astype(np.int64), w - 1)
    out = np.full((size, size, 3), fill, dtype=np.uint8)
    out[py:py + nh, px:px + nw] = img[ys][:, xs]
    return out, (scale, px, py)
vision.py: letterbox resizes with nearest neighbour, then pads

The example uses nearest neighbour to keep it short. Real work uses bilinear or a GPU kernel, which gives slightly different images and very different times.

Step 5: post-process: IoU and NMS

A detector gives several overlapping boxes around a single part. NMS keeps the box with the highest score and removes boxes that overlap it by more than a set IoU. IoU is the overlapping area divided by the combined area. The example creates 1,500 synthetic boxes in six groups from a fixed seed. The decode stage drops low-score boxes and converts the rest to corner format. The NMS stage is vectorized with numpy.

vision.py · lines 42–59
def nms(boxes, scores, thr):
    """Greedy NMS. Returns kept indices, highest score first.
    Ties keep the lower index (stable sort)."""
    order = np.argsort(-scores, kind="stable")
    x1, y1, x2, y2 = boxes[:, 0], boxes[:, 1], boxes[:, 2], boxes[:, 3]
    area = np.maximum(0, x2 - x1) * np.maximum(0, y2 - y1)
    keep = []
    while order.size:
        i = order[0]
        keep.append(int(i))
        rest = order[1:]
        iw = np.maximum(0, np.minimum(x2[i], x2[rest]) - np.maximum(x1[i], x1[rest]))
        ih = np.maximum(0, np.minimum(y2[i], y2[rest]) - np.maximum(y1[i], y1[rest]))
        inter = iw * ih
        union = area[i] + area[rest] - inter
        ov = np.where(union > 0, inter / np.where(union > 0, union, 1), 0.0)
        order = rest[ov <= thr]
    return keep
vision.py: greedy nms with numpy

The time of this stage depends on how many boxes pass the score threshold. A scene with tightly packed parts, or a low score threshold, will be slower. So measure with the heaviest image you expect to see, not the easiest.

A real run: how the model alone fools us

The results below come from running python3 bench.py on our CPU machine, not a Jetson. Running it again will give different numbers. When writing the article we ran it several times and found that the preprocess time at p50 swung from about 3 to 7 milliseconds between runs, which is why you need to measure several times.

output.txt
host: CPU only, python 3.14.4, numpy 2.3.5
frames measured: 300, warm-up frames excluded: 30
stand-in inference = numpy matmuls, NOT YOLO. Timings are from THIS host, not a Jetson.

stage             p50      p95      p99      max  (ms)
capture         0.470    0.530    0.732    0.965
preprocess      3.135    6.242    7.545    8.037
inference       2.452    2.711    3.106    3.456
postprocess     0.327    0.382    0.420    0.568
handoff         0.000    0.000    0.001    0.004
end-to-end      6.399    9.745   10.937   12.236

model-only p50 2.45 ms -> 407.9 FPS if you quote only the model
end-to-end p50 6.40 ms -> 156.3 FPS sequential
the model is 38% of the p50 frame; 62% is everything else
sequential throughput measured by wall clock: 143.9 FPS

pipelined (2 threads): throughput 321.5 FPS, latency p50 6.74 / p95 7.85 / p99 9.31 ms
1000 / pipelined p50 latency = 148.4 FPS, but measured throughput is 321.5 FPS: two frames are in flight at once, so throughput is not 1 / latency
output.txt: the actual result of python3 bench.py. Timings depend on the machine and on the run.
  1. The top table shows each stage and the total. In this run, inference is about 38 percent of the p50 time for the whole frame. About two thirds of the rest is image capture, resizing and output decoding.
  2. If you divide 1000 by the model time alone, you get about 408 FPS. But the whole-pipeline p50 gives about 156 FPS, and the throughput measured with a real clock is about 144 FPS, lower still, because the average is pulled up by slow frames. Dividing 1000 by p50 is therefore always too optimistic.
  3. The p99 of the total time is about 1.7 times the p50 in this run. This shows that the tail of the distribution matters for designing the machine's response time.
  4. The last line is the two-thread version. The first thread does capture and preprocess, and the second does inference and post-process. The measured throughput is about 321 FPS, more than 1000 divided by the p50 latency of about 148 FPS, because two frames are in the pipeline at once. Throughput and latency are therefore different numbers. A system that must respond in time should look at latency. A system that must sweep through many images should look at throughput.

Do not conclude that two threads are always faster. This example works because numpy releases the GIL during matrix multiplication. On a real board where capture, resizing and the model compete for the same resources, the result may differ. You have to measure it yourself.

Why measure in the power mode you actually use

On a Jetson, the power mode sets the number of cores and the maximum frequencies of the CPU, GPU and EMC. The documentation says MAXN has no limits and does not guarantee the highest performance for every workload, because when total power exceeds the budget the hardware slows itself down, and it advises against running heavy workloads in this mode for a long time. Other modes have different power budgets. For example, the documentation gives the AGX Orin 64GB, which has 15W, 30W, 50W and MAXN modes. If the control cabinet has to limit power or heat, the numbers used for decisions must come from that mode.

  1. Record the mode with sudo nvpmodel -q, and choose the mode you will actually use with nvpmodel -m followed by the mode number.
  2. If you want steady clocks during measurement, use jetson_clocks and note that it was on. Remember that the documentation says changing the mode afterwards requires a reboot.
  3. Run tegrastats --interval 1000 --logfile with a file name alongside the harness, and watch GR3D_FREQ, temperature and power. If the frequency drops mid-measurement, the p99 number will rise even though the model did not change.
  4. Measure long enough for the machine to reach a stable thermal state, not only right after power-on.
  5. If you use trtexec, treat the result as an engine-only number. Compare it with the whole-pipeline harness to see which stage accounts for the difference.

How the tests work

The tests in the example folder cover four areas and assert no timing numbers at all, because timings change with the machine. If they asserted timings, the tests would fail at random.

  • percentile: a hand-calculated value matches the output (for example, p50 of 1 to 4 is 2.5), it matches numpy.percentile, it does not depend on the order of the data, and it raises an error when the data is empty or q is out of range
  • letterbox: a 640x480 image gets 80-pixel padding, a portrait image gets padding on the left and right, zero size is rejected, and a box in the center that is mapped back lands at the center of the original image
  • IoU: identical boxes give 1, boxes that do not overlap give 0, boxes overlapping by half give one third, and a zero-area box does not divide by zero
  • NMS: it removes overlapping boxes and keeps distant ones, the result changes with the threshold, and it accepts empty input
test_bench.py · lines 59–76
class IouNms(unittest.TestCase):
    def test_iou(self):
        self.assertEqual(iou([0, 0, 10, 10], [0, 0, 10, 10]), 1.0)
        self.assertEqual(iou([0, 0, 10, 10], [20, 20, 30, 30]), 0.0)
        self.assertAlmostEqual(iou([0, 0, 10, 10], [5, 0, 15, 10]), 50 / 150)
        self.assertEqual(iou([0, 0, 0, 0], [0, 0, 0, 0]), 0.0)

    def test_nms_suppresses_overlap_keeps_distant(self):
        boxes = np.array([[0, 0, 10, 10], [1, 1, 11, 11], [50, 50, 60, 60]], dtype=np.float32)
        scores = np.array([0.8, 0.9, 0.7], dtype=np.float32)
        self.assertEqual(nms(boxes, scores, 0.5), [1, 2])

    def test_nms_threshold_and_empty(self):
        boxes = np.array([[0, 0, 10, 10], [5, 0, 15, 10]], dtype=np.float32)
        s = np.array([0.9, 0.8], dtype=np.float32)
        self.assertEqual(nms(boxes, s, 0.2), [0])      # iou 0.333 > 0.2
        self.assertEqual(nms(boxes, s, 0.5), [0, 1])   # iou 0.333 <= 0.5
        self.assertEqual(nms(np.zeros((0, 4), np.float32), np.zeros(0, np.float32), 0.5), [])
test_bench.py: the IoU and NMS tests

Moving to a real board: what the example does not do

  • Replace StandIn with a call to the real engine, and measure with CUDA events or synchronize before reading the time, because a GPU call often returns before the work is finished. Without synchronization you only measure the time to issue the work.
  • Use a real camera or a real video file, because capture and decode times are very different from random images.
  • Use real images of the hardest case, because the number of boxes entering NMS changes the post-process time.
  • Measure the handoff stage against the real PLC or database, including the case of a slow network.
  • Keep the per-frame time log long enough, and count dropped frames or frames over the deadline separately from the percentiles.
  • Measure accuracy alongside, because lowering precision or image size to go faster can change the detection results.

Hypothetical examples: applying this to three jobs

  • Suppose a crack-inspection line must decide before the part reaches the sorting mechanism: set the time ceiling from the conveyor speed and the distance, then compare it with the p99 of the total time, not the average FPS.
  • Suppose a system counts boxes on a pallet and takes one image per pallet: response time is not critical, so look at throughput and accuracy more.
  • Suppose several cameras share one board: measure all of them at the same time, because contention for memory and EMC makes single-camera numbers too optimistic.

Common mistakes and a checklist

  • Quoting the model's speed as the system's speed
  • Not discarding warm-up, so the slow first runs enter the statistics
  • Reporting only the average or the average FPS, with no p95, p99 or maximum
  • Using 1000 divided by latency in place of throughput, or the reverse
  • Measuring in MAXN mode but installing in another mode, or not recording the mode and the jetson_clocks state
  • Measuring while the machine is still cold, so the effect of thermal throttling is not seen
  • Running once and drawing a conclusion, even though other runs can differ by a factor of two
  1. State the machine's response-time ceiling in milliseconds before measuring.
  2. Record the model, board, JetPack release, nvpmodel mode, jetson_clocks state and room temperature.
  3. Measure every stage, not only the model, and exclude warm-up.
  4. Report p50, p95, p99, the maximum, and the number of frames over the ceiling.
  5. Report latency and throughput separately.
  6. Run tegrastats alongside, and check whether clocks or temperature changed along the way.
  7. Repeat the measurement several times and report the range of results.
  8. Measure accuracy on real data of the job every time you change the model or precision.

Caution: all numbers in this article come from a CPU machine, not a Jetson. The example is not a benchmark of any board or of YOLO, and it is a learning set, not production code. NVIDIA's mode names and commands change with the JetPack release and the module, so check the documentation for the release you use before configuring a real machine.

References

  1. NVIDIA Jetson Linux Developer Guide r36.4.3: Jetson Orin power and performance (nvpmodel, power modes, jetson_clocks) (accessed 2026-11-21)
  2. NVIDIA Jetson Linux Developer Guide r36.4.3: Tegrastats Utility (accessed 2026-11-21)
  3. NVIDIA TensorRT: trtexec README (accessed 2026-11-21)
  4. NVIDIA TensorRT: performance best practices (chapter overview) (accessed 2026-11-21)
  5. NumPy: numpy.percentile (accessed 2026-11-21)
  6. Python: time.perf_counter (accessed 2026-11-21)

Add us on LINE

Scan with the LINE app on your phone

QR code to add LINE @Bankoos

LINE ID: @Bankoos

Open LINE on this computer