CPU vs GPU for Video Object Detection: A D-FINE Benchmark
On the test machine, moving D-FINE from the CPU to the GPU lowered the median detector time per frame by a ratio of 4.5 for the nano model and 13.2 for the large one. The timed parts of a short run did not shrink nearly as much: for the same 100 frames the ratio was between 1.6 and 4.6, because frame sampling and model loading take about as long either way.
The detector timed here is the one in the D-FINE pipeline of AI-Powered Video Analyzer 1.1.0, running through VisionServeX 3.23.0, measured on 27 November 2026. Only the detector path was benchmarked. Captioning, transcription, audio tagging, language-model summaries and report writing were not, so nothing below is the speed of a full video analysis.
What was measured
Machine and software
| Item | Value |
|---|---|
| CPU | Intel Core i7-14700F, 20 cores, 28 threads; PyTorch used 20 intra-op threads |
| CPU settings | intel_pstate with the powersave governor, power profile performance |
| RAM | 61 GiB |
| GPU | NVIDIA RTX 5080, 16 GB, driver 580.178.04, 360 W power limit |
| System | Ubuntu 26.04.1, Linux 7.0.0-44, Python 3.13.12, FFmpeg 8.0.1 |
| Libraries | PyTorch 2.15.0 (CUDA 13.2 build), torchvision 0.29.2, Transformers 5.24.1, VisionServeX 3.23.0 |
| Software under test | AI-Powered Video Analyzer 1.1.0, commit 313448a |
| Checkpoint revisions | nano 066438d, small 2b548d1, medium e828496, large c89de47 (ustc-community) |
Input and protocol
The input was a 9 second clip of three public-domain or CC0 photographs with a slow pan, repeated 12 times without re-encoding: 640 x 360, 30 fps, 3240 frames, 108.7 seconds. The sampler selected 100 frames, which is the command's cap, and stopped decoding at frame 2970.
- Batch size 1, 32-bit floating point, model input 640 x 640.
- Four presets on two devices, five repetitions each, interleaved, one process per run: 40 benchmark runs and 40 runs of a separate timing script.
- Weights already downloaded and the Hugging Face hub set to offline.
- For CPU runs the GPU was also hidden from the process (
CUDA_VISIBLE_DEVICESset to empty). - The GPU showed 0% utilisation before and after the whole series, with 1910 MiB already held by the desktop and other programs. This is a shared desktop; background CPU load was not controlled.
Two instruments were used. The package's own benchmark command samples frames, loads and warms the detector, times one pass over the frames and prints the mean milliseconds per frame. A script outside the package timed each predict call, synchronised the GPU around the timer and recorded peak memory.
Reproducing the runs
ffmpeg -stream_loop 11 -i clip.mp4 -c copy long.mp4
ai-video-analyzer benchmark long.mp4 --preset balanced --device cuda --max-frames 100
ai-video-analyzer benchmark long.mp4 --preset balanced --device cpu --max-frames 100
In the output, read the Detection runtime line, which also gives milliseconds per frame. Note that --device controls only the detector. If you ask for a device that is not available, version 1.1.0 falls back to the CPU without saying so, and the analysis report does not record which device ran. The benchmark command writes no file, and its --compare option leaves out quality+.
The timing core of the script, shortened:
import sys, time
import numpy as np
import torch
from ai_powered_video_analyzer.frames import FrameSampler
from ai_powered_video_analyzer.backends.visionservex_backend import VisionServeXBackend
device, preset = sys.argv[1], sys.argv[2]
cuda = device == "cuda"
def sync():
if cuda:
torch.cuda.synchronize()
def timed(fn):
sync(); t = time.perf_counter(); out = fn(); sync()
return out, time.perf_counter() - t
frames, t_sample = timed(lambda: FrameSampler(strategy="adaptive", target_fps=1.0, max_frames=100).sample("long.mp4"))
backend, t_construct = timed(lambda: VisionServeXBackend(preset=preset, device=device))
first, t_first = timed(lambda: backend.predict(frames[0].frame)) # lazy weight load + first inference
_, t_warm = timed(backend.warmup) # package warmup(): one 640x640 black frame
if cuda:
torch.cuda.reset_peak_memory_stats() # peak memory of the loop only
per_frame, n_det = [], 0
for r in frames:
dets, t = timed(lambda: backend.predict(r.frame))
per_frame.append(t * 1000); n_det += len(dets)
print(preset, device, np.median(per_frame), np.mean(per_frame), n_det)
if cuda:
print("peak allocated MiB", torch.cuda.max_memory_allocated() / 2**20)
The synchronisation matters: CUDA operations are queued and run asynchronously, so a timer stopped without torch.cuda.synchronize() can measure how long it took to launch work, not to finish it.
Detector time per frame
Each cell is the median of five runs, with the lowest and highest run in brackets. A run's value is its mean over 100 frames, or its 95th percentile in the last column.
| Preset (model) | Device | benchmark ms/frame |
Script ms/frame | Script p95 ms |
|---|---|---|---|---|
fast (dfine-n) |
GPU | 10.9 (10.8-11.4) | 10.2 (10.1-11.0) | 10.6 (10.4-19.1) |
| fast | CPU | 49.4 (44.0-77.5) | 53.0 (49.9-77.9) | 57.0 (53.8-57.5) |
balanced (dfine-s) |
GPU | 11.8 (11.5-12.2) | 11.0 (10.8-14.2) | 11.3 (11.1-18.6) |
| balanced | CPU | 106.7 (101.4-130.7) | 100.9 (96.8-113.2) | 110.6 (107.4-145.2) |
quality (dfine-m) |
GPU | 14.3 (14.0-17.5) | 13.5 (13.1-23.7) | 15.2 (13.5-34.5) |
| quality | CPU | 161.3 (145.2-164.0) | 162.5 (159.3-166.5) | 172.2 (167.9-201.7) |
quality+ (dfine-l) |
GPU | 17.9 (17.8-18.4) | 17.4 (17.1-18.6) | 18.2 (17.6-23.5) |
| quality+ | CPU | 235.8 (222.7-239.6) | 238.7 (231.7-248.3) | 253.3 (244.8-331.3) |
The two instruments agree within 6 ms on every row, which is a useful check that neither is badly wrong.
There were occasional stalls. One CPU run of fast contained a single 1997 ms frame, which lifted that run's mean to 77.9 ms while its 95th percentile stayed at 54.9 ms. One GPU run of quality had a per-frame median of 23.6 ms against 13.1 ms in the other four. The causes were not investigated. This is why a single pass is a poor basis for a comparison, and why medians and ranges are given.
What the presets cost
| Preset | Model | Parameters | Detections on the 100 frames | GPU ms | CPU ms | CPU / GPU |
|---|---|---|---|---|---|---|
| fast | dfine-n |
3,770,421 | 706 (GPU), 717 (CPU) | 10.9 | 49.4 | 4.5 |
| balanced | dfine-s |
10,309,605 | 377 | 11.8 | 106.7 | 9.0 |
| quality | dfine-m |
19,563,368 | 233 | 14.3 | 161.3 | 11.3 |
| quality+ | dfine-l |
31,244,152 | 277 | 17.9 | 235.8 | 13.2 |
On the GPU, eight times as many parameters cost only about 7 ms more per frame; on the CPU, the same step cost about 186 ms. A likely explanation is that at batch size 1 on a large GPU, costs that do not depend on model size, such as preparing the image on the CPU, copying data and launching kernels, make up much of each call. The breakdown inside a call was not measured, so treat that as a hypothesis.
The detection counts are not an accuracy ranking: there is no ground truth, the input is three pictures repeated, and the presets were trained on different data. The fast preset reported 11 more detections on the CPU than on the GPU for identical frames. Scores close to the threshold falling on different sides would explain it, but that was not checked. The other presets matched in count.
From latency to throughput
With frames processed one at a time, detector throughput is about 1000 / latency_in_ms frames per second: 56 to 92 on this GPU and 4.2 to 20 on this CPU. That is the throughput of the detector call only.
Compare it with how many frames the analyzer asks for. By default it aims at about one sampled frame per second of video and can go up to roughly 3.75 per second at 30 fps when there is sustained motion. Even the slowest case here, quality+ on the CPU at 235.8 ms, would spend about 0.24 s of detector time per video second at one frame per second, and about 0.88 s at 3.75. This is arithmetic from the measured latency and covers the detector alone.
Two techniques change the relation between latency and throughput, and neither is in use here. Batching processes several frames in one forward pass; it can raise throughput while each frame waits longer. The analyzer sends one frame per pass, although VisionServeX 3.23.0 offers batched D-FINE inference. Asynchronous or pipelined execution lets decoding and inference overlap, so total time approaches that of the slowest stage instead of the sum of the stages.
Loading and warm-up
The first call costs far more than the rest, because the weights are loaded on first use.
| Step (range of medians across presets) | GPU | CPU |
|---|---|---|
| Constructing the detector object | 0.25 s | 0.21 s |
First predict (loads weights, runs one frame) |
1.72-1.84 s | 1.42-1.67 s |
Package warmup() afterwards |
0.012-0.021 s | 0.042-0.209 s |
benchmark command's "load+warmup" |
2.65-2.77 s | 2.20-2.48 s |
Leave warm-up out when you report steady latency, and put it back when you estimate how long a job takes. On the GPU, loading and warm-up exceeded the whole detection loop over 100 frames for every preset.
In the analyzer's JSON report, the object_detection timing includes this lazy loading, so do not divide it by the frame count and call the result latency.
Why a faster detector shortens the run much less
The wall-clock time of a whole analysis is a sum of many terms:
T = T_start + T_load + T_sample + N * (t_pre + t_net + t_post)
+ N * t_other_frame_models + T_audio + T_summary + T_report
| Term | Meaning | Measured here? |
|---|---|---|
T_start |
Starting Python and importing libraries | No |
T_load |
Constructing models, loading weights, warm-up | Detector only |
T_sample |
Decoding the video and selecting frames | Yes |
N |
Number of sampled frames | 100 |
t_pre, t_net, t_post |
Resizing the frame, the network, turning outputs into records | Only their sum, as the detector latency |
t_other_frame_models |
Other per-frame models, such as captioning | No |
T_audio |
Audio extraction, transcription and audio tagging | No |
T_summary, T_report |
Language-model summary and writing the reports | No |
The benchmark command times three of these: sampling frames (decoding on the CPU, about 1.5 s here on either device; the timing script measured the same sampler at about 0.7 s in its GPU runs and 1.2 s in its CPU runs, so this is the least stable term), loading and warming the detector, and the detection loop. Their sum is not the duration of an analysis, which includes every other term above.
Amdahl's law states what accelerating one part can do for the total:
S = 1 / ( (1 - p) + p / s )
p is the fraction of the original time spent in the part you accelerate, s is how much faster that part becomes, and S is the overall speed-up. Here the original run is the CPU run, the accelerated part is the detection loop and s is the latency ratio.
# medians of five runs of the `benchmark` command, 100 sampled frames, on the test machine
# preset: (CPU ms/frame, GPU ms/frame, CPU load s, GPU load s, CPU sampling s, GPU sampling s)
runs = {
"fast": (49.4, 10.9, 2.20, 2.65, 1.51, 1.53),
"balanced": (106.7, 11.8, 2.33, 2.70, 1.49, 1.51),
"quality": (161.3, 14.3, 2.38, 2.74, 1.49, 1.51),
"quality+": (235.8, 17.9, 2.48, 2.77, 1.52, 1.49),
}
N = 100
print("preset fps CPU fps GPU s(det) CPU sum GPU sum ratio Amdahl")
for name, (c, g, load_c, load_g, samp_c, samp_g) in runs.items():
total_c = samp_c + load_c + N * c / 1000 # sum of the three timed parts
total_g = samp_g + load_g + N * g / 1000
s = c / g # speed-up of the detector loop
p = (N * c / 1000) / total_c # its share of the CPU run
amdahl = 1 / ((1 - p) + p / s)
print(f"{name:9s} {1000 / c:8.1f} {1000 / g:8.1f} {s:7.2f} {total_c:7.2f}s {total_g:7.2f}s "
f"{total_c / total_g:6.2f} {amdahl:7.2f}")
preset fps CPU fps GPU s(det) CPU sum GPU sum ratio Amdahl
fast 20.2 91.7 4.53 8.65s 5.27s 1.64 1.80
balanced 9.4 84.7 9.04 14.49s 5.39s 2.69 2.90
quality 6.2 69.9 11.28 20.00s 5.68s 3.52 3.77
quality+ 4.2 55.9 13.17 27.58s 6.05s 4.56 4.76
For the default preset, a detector that is faster by a ratio of 9.0 gives a ratio of only 2.7 on the three parts. The measured ratio is a little below Amdahl's value because the formula assumes everything else is unchanged, while loading and warm-up took 0.37 s longer on the GPU.
How the length of the job changes the answer
The next block is a model built from the measured parts, not a measurement. It assumes that loading is paid once and that sampling costs the same per selected frame as in this clip (about 15 ms, roughly 30 decoded frames of 640 x 360 per selected one).
# balanced preset; a model built from the measured parts, NOT a measurement
cpu_ms, gpu_ms, load_c, load_g, _, samp_g = runs["balanced"]
per_frame_sampling = samp_g / 100 # decoding this clip, per selected frame
extra_load, saved = load_g - load_c, (cpu_ms - gpu_ms) / 1000
print(f"GPU pays back its longer load after {extra_load / saved:.1f} frames")
for n in (10, 100, 1000, 10000):
cpu = load_c + n * (per_frame_sampling + cpu_ms / 1000)
gpu = load_g + n * (per_frame_sampling + gpu_ms / 1000)
print(f"{n:6d} frames: CPU {cpu:8.1f} s GPU {gpu:7.1f} s ratio {cpu / gpu:.2f}")
limit = (per_frame_sampling + cpu_ms / 1000) / (per_frame_sampling + gpu_ms / 1000)
print(f"limit for very long inputs: {limit:.2f} (detector alone: {cpu_ms / gpu_ms:.2f})")
GPU pays back its longer load after 3.9 frames
10 frames: CPU 3.5 s GPU 3.0 s ratio 1.20
100 frames: CPU 14.5 s GPU 5.4 s ratio 2.69
1000 frames: CPU 124.1 s GPU 29.6 s ratio 4.19
10000 frames: CPU 1220.3 s GPU 271.7 s ratio 4.49
limit for very long inputs: 4.53 (detector alone: 9.04)
With that sampling cost the model's ratio stops near 4.5 even for arbitrarily long inputs, because decoding stays on the CPU. The limit depends strongly on this one input: with the roughly 0.7 s that the timing script measured in its GPU runs instead of 1.5 s, the same formula gives about 6. (The analyzer also stops after 2000 sampled frames by default, so very long jobs need that setting raised.)
Every further stage dilutes or changes the picture. BLIP captioning, Whisper and PANNs were not measured here, ignore --device and use any GPU they can see; a language model for summaries runs in its own server.
Theoretical processing time from per frame latency and fixed parts
A calculator that multiplies the number of analysed frames by the time per frame, adds fixed costs for frame sampling and model loading, and reports total time, throughput and the share of each part.
| part | time |
|---|---|
| frames100 frames × 106.7 ms | 10.67 s |
| frame sampling | 1.49 s |
| model load and warmup | 2.33 s |
| total | 14.49 s |
- frame stage alone
- 9.37 frames per second
- end to end
- 6.90 frames per second
- total against video length
- ×0.13 the video's duration
Theoretical processing time: 14.49 s, of which frames 10.67 s.
GPU memory
For one frame at a time, the detector is small: at most 250 MiB of tensors and 726 MiB for the whole process, for the large model. Do not size a machine from these figures if you also enable captioning or transcription; their memory was not measured, and the analyzer does not unload models between stages.
What about resolution?
Only 640 x 360 input was measured. The network always receives 640 x 640, so its own arithmetic does not change with the source size. Decoding, the sampler's pixel-by-pixel frame comparison and the resize before the model do grow with the number of pixels. If your footage is 1080p or 4K, expect the sampling part to weigh more, and measure it.
Why published ms/frame numbers differ
Two latency figures are comparable only if these match:
- Hardware: GPU model, power limit, CPU and thread count.
- Runtime and precision: the D-FINE authors report latency with TensorRT in half precision on a T4; the analyzer runs PyTorch and Transformers in full precision.
- What is timed: the network alone, or
predictincluding image preparation and postprocessing. - Batch size and input size.
- Warm or cold: whether loading is inside the number.
- Statistic: one pass and a mean, or repeated runs with a median and spread.
- Input frames: their content and number.
The analyzer's repository records and the ranges quoted from them come from earlier single passes on clips that are not published, with GPU results only. They were taken under different conditions, so they are not comparable with the tables here. For the general habit of writing down such context, see recording benchmark context, and to find where time goes inside a PyTorch call, profiling with PyTorch tools. torch.utils.benchmark.Timer handles warm-up and synchronisation for microbenchmarks; note that it uses one thread unless told otherwise.
Choosing a device and preset
- A few short clips: loading and sampling dominate. A GPU helps, but far less than the latency ratio suggests.
- Many frames: the GPU's advantage grows towards the limit set by CPU decoding.
- Many files: each command-line call is a new process and pays loading again; a long-running program helps only if it reuses the loaded detector.
- CPU only: the preset matters a lot, from 49 to 236 ms per frame here. Check on your own footage whether the smaller model finds what you need.
- On a GPU: moving from
fasttoquality+cost about 7 ms per frame here, less per run than loading. Choose by measured accuracy on your data.
These apply to this processor and card. Run the three commands above on your own machine before deciding.
If you want to try a COCO detector on your own hardware without installing Python, Anastig Vision Lab, a separate platform that is not part of the analyzer, can run D-FINE-N in the browser using WebGPU or the CPU. None of the numbers in this article apply to it. Disclosure: the author of this article is also involved in building Anastig.
How D-FINE produces its boxes, and what the scores mean, is explained in D-FINE object detection on video frames.
How many frames reach the detector depends on the sampler; see adaptive frame sampling and scene change detection.
For browser, local worker and remote execution, compare running vision models with browser and GPU workers.
References
- Y. Peng, H. Li, P. Wu, Y. Zhang, X. Sun, F. Wu. D-FINE: Redefine Regression Task in DETRs as Fine-grained Distribution Refinement. arXiv:2410.13842
- G. M. Amdahl. Validity of the single processor approach to achieving large scale computing capabilities. AFIPS Spring Joint Computer Conference, 1967. doi:10.1145/1465482.1465560
- PyTorch documentation, CUDA semantics, asynchronous execution. docs.pytorch.org
- PyTorch documentation,
torch.utils.benchmark. docs.pytorch.org - A. Sajjadi. AI-Powered Video Analyzer, source repository, version 1.1.0. GitHub