Resources

Benchmark Timing Function.

Warmup iterations followed by timed inference, reporting median, P95 latency, and FPS.

model = YOLO(str(engine_path), task='detect')
img = np.random.randint(0, 255, (IMGSZ, IMGSZ, 3), dtype=np.uint8)

# Warmup
for _ in range(WARMUP):
    model(img, conf=CONF, iou=IOU, verbose=False)

# Timed inference
latencies = []
for _ in range(ITERS):
    t0 = time.perf_counter()
    model(img, conf=CONF, iou=IOU, verbose=False)
    latencies.append((time.perf_counter() - t0) * 1000)

lat_med = round(statistics.median(latencies), 2)
lat_p95 = round(np.percentile(latencies, 95), 2)
fps_med = round(1000 / lat_med, 1) if lat_med > 0 else 0.0

Uses a single random image at a fixed size rather than real data — this measures pure model + postprocessing latency, isolated from I/O and preprocessing cost.

← Return to ArticleBrowse All Resources →