Repository navigation
Description
Describe the bug
With the stock config_tracker_NvSORT.yml, nvtracker outputs no objects on any frame when the nvinfer in front of it skips frames (interval 1 or more). The detector still finds objects on the frames it runs on. With interval=0 the same pipeline works.
The tracker comparison table in the Gst-nvtracker documentation lists NvSORT (and IOU) under "Best Use Cases" with: "Detector is expected to run every frame or very frequently (ex. every alternate frame)". So interval=1 should work with this config.
The stock config_tracker_IOU.yml has the same earlyTerminationAge: 1 and works at interval=1. config_tracker_NvDCF_perf.yml works too. If earlyTerminationAge in a copy of the NvSORT file is raised from 1 to interval + 1, NvSORT outputs objects again. Our guess from the documented early termination rule: a new target gets no detection on the next frame, so it is ended while still tentative, before it is ever output.
Steps/Code to reproduce bug
Save the script below as repro_nvsort_interval.py and run it in the stock image. It uses only stock files: samples/streams/sample_720p.h264, config_infer_primary.txt (unchanged; interval, batch-size=1 and model-engine-file are set as element properties) and the stock tracker configs. Probes on the nvinfer and nvtracker src pads count objects per frame for the first 300 frames.
docker run --rm --gpus all -v "$PWD":/repro \
-v nvsort-engine:/opt/nvidia/deepstream/deepstream-9.2/samples/models/Primary_Detector \
--entrypoint bash ghcr.io/nvidia/deepstream:9.2-triton-multiarch \
-c "pip install -q --break-system-packages pyyaml && python3 /repro/repro_nvsort_interval.py NvSORT 1"The first run builds the TensorRT engine (about 30 s here). The named volume keeps it, so later runs take about 5 s. Arguments: a stock tracker config name (NvSORT, IOU, NvDCF_perf) and the interval. --early-termination-age N runs a copy of the stock file with only that value changed.
Results, 300 frames, 2 runs per row. Both runs gave the same counts, except the NvDCF_perf object total (5225 and 5226):
| Tracker config | interval | Frames with detector objects | Frames with tracker objects | Objects behind the tracker |
|---|---|---|---|---|
| NvSORT (stock) | 0 | 300 | 295 | 4761 |
| NvSORT (stock) | 1 | 150 | 0 | 0 |
| NvSORT (stock) | 2 | 100 | 0 | 0 |
| NvSORT (stock) | 4 | 60 | 0 | 0 |
| NvSORT, earlyTerminationAge: 2 | 1 | 150 | 147 | 2319 |
| NvSORT, earlyTerminationAge: 3 | 2 | 100 | 98 | 1528 |
| IOU (stock) | 1 | 150 | 296 | 5856 |
| NvDCF_perf (stock) | 1 | 150 | 298 | 5225 |
Output with NvSORT at interval 1:
RESULT tracker=NvSORT interval=1 frames=300 frames_with_detector_objects=150 frames_with_tracker_objects=0 tracker_objects=0 tracker_ids=0
With the raised earlyTerminationAge, NvSORT outputs objects only on the frames the detector ran on (147 of 150), while IOU and NvDCF also output objects on the skipped frames.
repro_nvsort_interval.py
r"""nvtracker with the stock config_tracker_NvSORT.yml outputs no objects when nvinfer skips frames (interval > 0).
The pipeline is the image's sample stream through its stock primary detector and a stock tracker config:
filesrc sample_720p.h264 -> h264parse -> nvv4l2decoder -> nvstreammux -> nvinfer -> nvtracker -> fakesink
nvinfer uses samples/configs/deepstream-app/config_infer_primary.txt unchanged. Only `interval`, `batch-size` and
`model-engine-file` are set through element properties. A probe on the nvinfer src pad counts the detector's
objects per frame, and a probe on the nvtracker src pad counts the objects behind the tracker. The run stops after
MAX_FRAMES frames.
repro_nvsort_interval.py <tracker> <interval> [--early-termination-age N]
<tracker> is a stock file name in samples/configs/deepstream-app without the prefix and suffix: NvSORT, IOU,
NvDCF_perf, ... With --early-termination-age the script runs a copy of the stock file with only that value changed.
Run in the stock image (pyyaml first, because `import pyservicemaker` needs it). nvinfer builds the TensorRT engine
for batch size 1 when it does not find it (about 30 s on an RTX A4000 Laptop GPU) and writes it next to the model.
The named volume keeps the model directory, so only the first run builds it and later runs take a few seconds:
docker run --rm --gpus all -v "$PWD":/repro \
-v nvsort-engine:/opt/nvidia/deepstream/deepstream-9.2/samples/models/Primary_Detector \
--entrypoint bash ghcr.io/nvidia/deepstream:9.2-triton-multiarch \
-c "pip install -q --break-system-packages pyyaml && python3 /repro/repro_nvsort_interval.py NvSORT 1"
Expected: the tracker reports objects on most frames, as it does at interval 0 and with the stock IOU and NvDCF
configs at interval 1.
Actual with NvSORT at interval 1, 2 or 4: the detector finds objects on the frames it runs on, and the tracker
reports 0 objects on every frame:
RESULT tracker=NvSORT interval=1 frames=300 frames_with_detector_objects=150 frames_with_tracker_objects=0
tracker_objects=0 tracker_ids=0
With --early-termination-age set to interval + 1 the tracker reports objects again, on the frames the detector
runs on:
RESULT tracker=NvSORT earlyTerminationAge=2 interval=1 frames=300 frames_with_detector_objects=150
frames_with_tracker_objects=147 tracker_objects=2319 tracker_ids=92
"""
import argparse
import re
import sys
import threading
from pathlib import Path
from pyservicemaker import BatchMetadataOperator, Pipeline, Probe
DS = Path("/opt/nvidia/deepstream/deepstream")
STREAM = DS / "samples/streams/sample_720p.h264"
CONFIGS = DS / "samples/configs/deepstream-app"
PGIE_CONFIG = CONFIGS / "config_infer_primary.txt"
TRACKER_LIB = DS / "lib/libnvds_nvmultiobjecttracker.so"
ENGINE = DS / "samples/models/Primary_Detector/resnet18_trafficcamnet_pruned.onnx_b1_gpu0_fp16.engine"
MAX_FRAMES = 300
class Count(BatchMetadataOperator):
"""Counts frames, frames with objects, objects and object ids on one pad."""
def __init__(self, done: threading.Event | None = None) -> None:
super().__init__()
self.frames = 0
self.frames_with_objects = 0
self.objects = 0
self.ids: set[int] = set()
self.done = done
def handle_metadata(self, batch_meta) -> None:
for frame_meta in batch_meta.frame_items:
if self.frames >= MAX_FRAMES:
continue
n = 0
for obj in frame_meta.object_items:
n += 1
self.ids.add(int(obj.object_id))
self.frames += 1
self.objects += n
self.frames_with_objects += n > 0
if self.done is not None and self.frames == MAX_FRAMES:
self.done.set()
def tracker_config(name: str, early_termination_age: int | None) -> str:
stock = CONFIGS / f"config_tracker_{name}.yml"
if early_termination_age is None:
return str(stock)
text, n = re.subn(r"(earlyTerminationAge:\s*)\d+", rf"\g<1>{early_termination_age}", stock.read_text(), count=1)
if n != 1:
sys.exit(f"no earlyTerminationAge in {stock}")
copy = Path(f"/tmp/config_tracker_{name}_eta{early_termination_age}.yml")
copy.write_text(text)
return str(copy)
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("tracker")
parser.add_argument("interval", type=int)
parser.add_argument("--early-termination-age", type=int)
args = parser.parse_args()
done = threading.Event()
detector = Count()
tracker = Count(done)
pipeline = Pipeline("nvsort-interval")
pipeline.add("filesrc", "src", {"location": str(STREAM)})
pipeline.add("h264parse", "parser")
pipeline.add("nvv4l2decoder", "decoder")
pipeline.add("nvstreammux", "mux", {"batch-size": 1, "width": 1280, "height": 720})
pipeline.add(
"nvinfer",
"pgie",
{
"config-file-path": str(PGIE_CONFIG),
"batch-size": 1,
"interval": args.interval,
"model-engine-file": str(ENGINE),
},
)
pipeline.add(
"nvtracker",
"tracker",
{
"ll-lib-file": str(TRACKER_LIB),
"ll-config-file": tracker_config(args.tracker, args.early_termination_age),
"tracker-width": 960,
"tracker-height": 544,
},
)
pipeline.add("fakesink", "sink", {"sync": False})
pipeline.link("src", "parser", "decoder")
pipeline.link(("decoder", "mux"), ("", "sink_%u"))
pipeline.link("mux", "pgie", "tracker", "sink")
pipeline.attach("pgie", Probe("detector", detector))
pipeline.attach("tracker", Probe("tracked", tracker))
waiter = threading.Thread(target=pipeline.wait)
pipeline.start()
waiter.start()
done.wait(timeout=600)
pipeline.stop()
waiter.join()
eta = "" if args.early_termination_age is None else f" earlyTerminationAge={args.early_termination_age}"
print(
f"RESULT tracker={args.tracker}{eta} interval={args.interval} frames={tracker.frames} "
f"frames_with_detector_objects={detector.frames_with_objects} "
f"frames_with_tracker_objects={tracker.frames_with_objects} "
f"tracker_objects={tracker.objects} tracker_ids={len(tracker.ids)}",
flush=True,
)
if __name__ == "__main__":
main()Expected behavior
With the stock config_tracker_NvSORT.yml and interval=1, nvtracker outputs the tracked objects, as it does with interval=0 and as the stock IOU and NvDCF configs do. If NvSORT needs other values when the detector skips frames, a stock config for that case, or a note in the documentation with the values to use (for example earlyTerminationAge relative to interval), would solve it for users.
Environment details
- Docker on bare metal (Ubuntu host, RTX A4000 Laptop GPU, driver 615.71.09)
ghcr.io/nvidia/deepstream:9.2-triton-multiarch(digestsha256:94a49674eb475f0416ce49742430cfbd644258b4e6512b09c76ddd90164c6dc7)
Additional context
The failure is silent. The tracker logs no warning or error, and the pipeline runs to the end with empty frames behind the tracker. The log of a failing run has the same lines as a working one (a GLib-CRITICAL ... Source ID 2 was not found line at stop appears in every run, the working ones too).
Activity
kevinsongbing commentedon Nov 23, 2026
Thanks for the detailed report and repro script. Your observation is right. We suggest to use NvDCF for use cases where nvinfer needs to set inference interval.