Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy
Hardware Platform :** GPU RTX 3060, Intel i5 , 16GB Ram
balaji@balaji-B760M-H:~$ ls /usr/local | grep cuda
cuda
cuda-12
cuda-12.6
balaji@balaji-B760M-H:~$ deepstream-app --version
deepstream-app version 7.1.0
DeepStreamSDK 7.1.0
TensorRT version: 10.3.0
RTX3060
NVIDIA-SMI 580.95.05 Driver Version: 580.95.05 CUDA Version: 13.0
I try many solution but getting same wrong output error or wrong object detect.
please help me to fix this issue .
getting wrong output
please see video .
my code is
#!/usr/bin/env python3
import os
import sys
import subprocess
from shutil import which
# ================= USER CONFIG =================
BASE_PATH = “/home/balaji/Avinash/aiproject/deepstream”
# Make sure engine is built for TensorRT 10.3 / DeepStream 7.1
YOLO_ENGINE = “/home/balaji/Avinash/aiproject/yolov8n.engine”
#CUSTOM_LIB = “/home/balaji/Downloads/yolo_deepstream/deepstream_yolo/nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so”
CUSTOM_LIB = “/home/balaji/Avinash/aiproject/DeepStream-Yolo/nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so”
RTSP_URI = “rtsp://admin:admin%40123@192.168.0.195:554/cam/realmonitor?channel=2&subtype=0&protocols=tcp”
INPUT_WIDTH = 640
INPUT_HEIGHT = 640
NUM_CLASSES = 80
USE_DISPLAY = True # True: show output window; False: use headless fake sink
LOG_FILE = os.path.join(BASE_PATH, “deepstream_runner.log”)
# ==================== UTILS ====================
def log(msg):
print(msg)
with open(LOG_FILE, “a”) as f:
f.write(msg + “\n”)
def check_dependencies():
errors =
if not os.path.exists(YOLO_ENGINE):
errors.append(f"❌ YOLO engine not found: {YOLO_ENGINE}")
if not os.path.exists(CUSTOM_LIB):
errors.append(f"❌ Custom parser lib not found: {CUSTOM_LIB}")
if not which(“deepstream-app”):
errors.append(“❌ deepstream-app not found in PATH”)
return errors
# ==================== CONFIG GENERATORS ====================
def make_labels():
labels = [
“person”,“bicycle”,“car”,“motorcycle”,“airplane”,“bus”,“train”,“truck”,“boat”,
“traffic light”,“fire hydrant”,“stop sign”,“parking meter”,“bench”,“bird”,
“cat”,“dog”,“horse”,“sheep”,“cow”,“elephant”,“bear”,“zebra”,“giraffe”,
“backpack”,“umbrella”,“handbag”,“tie”,“suitcase”,“frisbee”,“skis”,“snowboard”,
“sports ball”,“kite”,“baseball bat”,“baseball glove”,“skateboard”,“surfboard”,
“tennis racket”,“bottle”,“wine glass”,“cup”,“fork”,“knife”,“spoon”,“bowl”,
“banana”,“apple”,“sandwich”,“orange”,“broccoli”,“carrot”,“hot dog”,“pizza”,
“donut”,“cake”,“chair”,“couch”,“potted plant”,“bed”,“dining table”,“toilet”,
“tv”,“laptop”,“mouse”,“remote”,“keyboard”,“cell phone”,“microwave”,“oven”,
“toaster”,“sink”,“refrigerator”,“book”,“clock”,“vase”,“scissors”,“teddy bear”,
“hair drier”,“toothbrush”
\]
os.makedirs(BASE_PATH, exist_ok=True)
path = os.path.join(BASE_PATH, “labels.txt”)
with open(path, “w”) as f:
f.write(“\n”.join(labels))
log(f"✓ Labels created: {path}")
return path
def make_infer_config(labels_path):
cfg = f"“”[property]
gpu-id=0
gie-unique-id=1
model-engine-file={YOLO_ENGINE}
labelfile-path={labels_path}
batch-size=1
network-type=0
num-detected-classes={NUM_CLASSES}
process-mode=1
interval=0
custom-lib-path={CUSTOM_LIB}
parse-bbox-func-name=NvDsInferParseYoloCuda
cluster-mode=4
maintain-aspect-ratio=1
symmetric-padding=1
network-mode=2
“”"
path = os.path.join(BASE_PATH, “config_infer_primary.txt”)
with open(path, “w”) as f:
f.write(cfg.strip())
log(f"✓ Inference config created: {path}")
return path
def make_app_config(infer_cfg):
sink_type = 2 if USE_DISPLAY else 5 # 2=overlay window, 5=fake sink
cfg = f"“”[application]
enable-perf-measurement=1
perf-measurement-interval-sec=5
[source0]
enable=1
type=4
uri={RTSP_URI}
latency=300
cudadec-memtype=0
[streammux]
gpu-id=0
batch-size=1
width={INPUT_WIDTH}
height={INPUT_HEIGHT}
live-source=1
batched-push-timeout=40000
nvbuf-memory-type=0
[primary-gie]
enable=1
gpu-id=0
config-file={infer_cfg}
[osd]
enable=1
gpu-id=0
border-width=2
text-size=18
display-text=1
text-bg-color=0;0;0;0.6
text-color=1;1;1;1
clock-text-size=16
process-mode=0
[sink0]
enable=1
type={sink_type}
sync=0
“”"
path = os.path.join(BASE_PATH, “deepstream_app_config.txt”)
with open(path, “w”) as f:
f.write(cfg.strip())
log(f"✓ App config created: {path}")
return path
# ==================== RUNNER ====================
def run_deepstream(app_cfg):
log(“\n🚀 Starting DeepStream…”)
cmd = [“deepstream-app”, “-c”, app_cfg]
log(f"Command: {’ '.join(cmd)}")
# Use subprocess to capture stdout/stderr
try:
with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) as p:
for line in p.stdout:
log(line.strip())
p.wait()
log(f"DeepStream exited with code {p.returncode}")
except Exception as e:
log(f"❌ Failed to run DeepStream: {e}")
# ==================== MAIN ====================
def main():
log(“\n🔹 DeepStream YOLO Runner 🔹\n”)
errors = check_dependencies()
if errors:
for e in errors:
log(e)
return 1
labels = make_labels()
infer_cfg = make_infer_config(labels)
app_cfg = make_app_config(infer_cfg)
run_deepstream(app_cfg)
return 0
if _name_ == “_main_”:
sys.exit(main())