• Hardware Platform (Jetson / GPU) GPU
• DeepStream Version 6.4
• TensorRT Version 8.6.1.6-1+cuda12.0
• NVIDIA GPU Driver Version (valid for GPU only) 545.23.08
This is my python code
# python3 test4.py -i file:///opt/nvidia/deepstream/deepstream-6.4/sources/deepstream_python_apps/apps/deepstream-imagedata-multistream-redaction/face.mp4 file:///opt/nvidia/deepstream/deepstream-6.4/sources/deepstream_python_apps/apps/deepstream-imagedata-multistream-redaction/testface.mp4 -c H264
import argparse
import sys
sys.path.append('../')
import gi
import configparser
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import GLib, Gst, GstRtspServer
from ctypes import *
import time
import sys
import math
import platform
from common.is_aarch_64 import is_aarch64
from common.bus_call import bus_call
from common.FPS import PERF_DATA
import numpy as np
import pyds
import cv2
import os
import os.path
from os import path
#🅲🅻🅰🆂🆂 🅸🅳 🅳🅴🅵🅸🅽🅸🅽🅶
PGIE_CLASS_ID_PERSON = 0
PGIE_CLASS_ID_FACE = 1
PGIE_CLASS_ID_BAG = 2
pgie_classes_str = ["Person", "Bag", "Face"]
MAX_DISPLAY_LEN = 64
perf_data = None
MUXER_OUTPUT_WIDTH = 720
MUXER_OUTPUT_HEIGHT = 576
MUXER_BATCH_TIMEOUT_USEC = 33000
TILED_OUTPUT_WIDTH = 720
TILED_OUTPUT_HEIGHT = 576
GST_CAPS_FEATURES_NVMM = "memory:NVMM"
def tiler_sink_pad_buffer_probe(pad, info, u_data):
frame_number = 0
num_rects = 0
gst_buffer = info.get_buffer()
#🅶🆂🆃 🅱🆄🅵🅵🅴🆁 🅸🅽🅸🆃🅸🅰🅻🅸🆉🅰🆃🅸🅾🅽
if not gst_buffer:
print("Unable to get GstBuffer ")
return
#Intiallizing object counter with 0
obj_counter = {
PGIE_CLASS_ID_PERSON: 0,
PGIE_CLASS_ID_BAG: 0,
PGIE_CLASS_ID_FACE: 0
}
#🅱🅰🆃🅲🅷 🅼🅴🆃🅰
batch_meta = pyds.gst_buffer_get_nvds_batch_meta(hash(gst_buffer))
l_frame = batch_meta.frame_meta_list
while l_frame is not None:
try:
frame_meta = pyds.NvDsFrameMeta.cast(l_frame.data)
except StopIteration:
break
frame_number = frame_meta.frame_num
l_obj = frame_meta.obj_meta_list
num_rects = frame_meta.num_obj_meta
# 🅾🅱🅹🅴🅲🆃 🅼🅴🆃🅰
while l_obj is not None:
try:
obj_meta = pyds.NvDsObjectMeta.cast(l_obj.data)
except StopIteration:
break
obj_counter[obj_meta.class_id] += 1
if (obj_meta.class_id == PGIE_CLASS_ID_FACE):
obj_meta.rect_params.border_width = 0
obj_meta.rect_params.has_bg_color = 0
obj_meta.rect_params.bg_color.red = 1
obj_meta.rect_params.bg_color.green = 0.0
obj_meta.rect_params.bg_color.blue = 0.0
obj_meta.rect_params.bg_color.alpha = 1.0
elif (obj_meta.class_id == PGIE_CLASS_ID_PERSON ) :
obj_meta.rect_params.border_width = 0
obj_meta.rect_params.has_bg_color = 0
obj_meta.rect_params.bg_color.red = 0.0
obj_meta.rect_params.bg_color.green = 1
obj_meta.rect_params.bg_color.blue = 0.0
obj_meta.rect_params.bg_color.alpha = 0.5
# get embedding
#print("obj Meta :",dir(obj_meta))
#obj Meta : ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'base_meta', 'cast', 'class_id', 'classifier_meta_list', 'confidence', 'detector_bbox_info', 'mask_params', 'misc_obj_info', 'obj_label', 'obj_user_meta_list', 'object_id', 'parent', 'rect_params', 'reserved', 'text_params', 'tracker_bbox_info', 'tracker_confidence', 'unique_component_id']
# print("Tracker bbox info : " , obj_meta.tracker_bbox_info)
# print("Tracker Confidence : ", obj_meta.tracker_confidence)
# print("User Meta list : ", obj_meta.obj_user_meta_list)
# l_user = obj_meta.obj_user_meta_list
# print("L_user",l_user)
while l_user is not None:
try:
user_meta = pyds.NvDsUserMeta.cast(l_user.data)
except StopIteration:
break
if (user_meta.base_meta.meta_type == pyds.NvDsMetaType.NVDSINFER_TENSOR_OUTPUT_META):
tensor_meta = pyds.NvDsInferTensorMeta.cast(user_meta.user_meta_data)
embeddings = tensor_meta.out_buf_ptrs_host[0]
# embedding_dims = tensor_meta.output_layers_info[0].inferDims
print("emb: ", embeddings)
try:
l_user = l_user.next
except StopIteration:
break
try:
l_obj = l_obj.next
except StopIteration:
break
display_meta=pyds.nvds_acquire_display_meta_from_pool(batch_meta)
display_meta.num_labels = 1
py_nvosd_text_params = display_meta.text_params[0]
py_nvosd_text_params.display_text = "Frame Number={} Number of Objects={} Number of Persons={} Number of Face ={}, Number of Bags ={}".format(frame_number, num_rects, obj_counter[PGIE_CLASS_ID_PERSON], obj_counter[PGIE_CLASS_ID_FACE], obj_counter[PGIE_CLASS_ID_BAG])
# Now set the offsets where the string should appear
py_nvosd_text_params.x_offset = 10
py_nvosd_text_params.y_offset = 12
# Font , font-color and font-size
py_nvosd_text_params.font_params.font_name = "Serif"
py_nvosd_text_params.font_params.font_size = 10
# set(red, green, blue, alpha); set to White
py_nvosd_text_params.font_params.font_color.set(1.0, 1.0, 1.0, 1.0)
# Text background color
py_nvosd_text_params.set_bg_clr = 1
# set(red, green, blue, alpha); set to Black
py_nvosd_text_params.text_bg_clr.set(0.0, 0.0, 0.0, 1.0)
# Using pyds.get_string() to get display_text as string
print(pyds.get_string(py_nvosd_text_params.display_text))
pyds.nvds_add_display_meta_to_frame(frame_meta, display_meta)
print("Frame Number=", frame_number, "Number of Objects=", num_rects, "Face_count=",
obj_counter[PGIE_CLASS_ID_FACE], "Person_count=", obj_counter[PGIE_CLASS_ID_PERSON])
# Update frame rate through this probe
stream_index = "stream{0}".format(frame_meta.pad_index)
global perf_data
perf_data.update_fps(stream_index)
try:
l_frame = l_frame.next
except StopIteration:
break
return Gst.PadProbeReturn.OK
def cb_newpad(decodebin, decoder_src_pad, data):
print("In cb_newpad\n")
caps = decoder_src_pad.get_current_caps()
gststruct = caps.get_structure(0)
gstname = gststruct.get_name()
source_bin = data
features = caps.get_features(0)
if (gstname.find("video") != -1):
if features.contains("memory:NVMM"):
bin_ghost_pad = source_bin.get_static_pad("src")
if not bin_ghost_pad.set_target(decoder_src_pad):
sys.stderr.write("Failed to link decoder src pad to source bin ghost pad\n")
else:
sys.stderr.write(" Error: Decodebin did not pick nvidia decoder plugin.\n")
def decodebin_child_added(child_proxy, Object, name, user_data):
print("Decodebin child added:", name, "\n")
if name.find("decodebin") != -1:
Object.connect("child-added", decodebin_child_added, user_data)
if not is_aarch64() and name.find("nvv4l2decoder") != -1:
Object.set_property("cudadec-memtype", 2)
def create_source_bin(index, uri):
print("Creating source bin")
bin_name = "source-bin-%02d" % index
print(bin_name)
nbin = Gst.Bin.new(bin_name)
if not nbin:
sys.stderr.write(" Unable to create source bin \n")
uri_decode_bin = Gst.ElementFactory.make("uridecodebin", "uri-decode-bin")
if not uri_decode_bin:
sys.stderr.write(" Unable to create uri decode bin \n")
uri_decode_bin.set_property("uri", uri)
uri_decode_bin.connect("pad-added", cb_newpad, nbin)
uri_decode_bin.connect("child-added", decodebin_child_added, nbin)
Gst.Bin.add(nbin, uri_decode_bin)
bin_pad = nbin.add_pad(Gst.GhostPad.new_no_target("src", Gst.PadDirection.SRC))
if not bin_pad:
sys.stderr.write(" Failed to add ghost pad in source bin \n")
return None
return nbin
def main(uri_inputs,codec,bitrate ):
# Check input arguments
number_sources = len(uri_inputs)
global perf_data
perf_data = PERF_DATA(number_sources)
# Standard GStreamer initialization
Gst.init(None)
# Create gstreamer elements */
# Create Pipeline element that will form a connection of other elements
# 🅲🆁🅴🅰🆃🅸🅽🅶 🅿🅸🅿🅴🅻🅸🅽🅴
print("Creating Pipeline \n ")
pipeline = Gst.Pipeline()
is_live = False
if not pipeline:
sys.stderr.write(" Unable to create Pipeline \n")
print("Creating streamux \n ")
# 🅲🆁🅴🅰🆃🅸🅽🅶 🆂🆃🆁🅴🅰🅼🆄🆇
# Create nvstreammux instance to form batches from one or more sources.
streammux = Gst.ElementFactory.make("nvstreammux", "Stream-muxer")
if not streammux:
sys.stderr.write(" Unable to create NvStreamMux \n")
# Streammux pipeline is added here
pipeline.add(streammux)
for i in range(number_sources):
print("Creating source_bin ", i, " \n ")
uri_name = uri_inputs[i]
if uri_name.find("rtsp://") == 0:
is_live = True
source_bin = create_source_bin(i, uri_name)
if not source_bin:
sys.stderr.write("Unable to create source bin \n")
pipeline.add(source_bin)
padname = "sink_%u" % i
sinkpad = streammux.get_request_pad(padname)
if not sinkpad:
sys.stderr.write("Unable to create sink pad bin \n")
srcpad = source_bin.get_static_pad("src")
if not srcpad:
sys.stderr.write("Unable to create src pad bin \n")
srcpad.link(sinkpad)
# # 🅲🆁🅴🅰🆃🅸🅽🅶 🆀🆄🅴🆄🅴
# queue1=Gst.ElementFactory.make("queue","queue1")
# queue2=Gst.ElementFactory.make("queui didnt add any sgie in the python code
# queue3=Gst.ElementFactory.make("queue","queue3")
# queue4=Gst.ElementFactory.make("queue","queue4")
# queue5=Gst.ElementFactory.make("queue","queue5")
# queue6=Gst.ElementFactory.make("queue","queue6")
# queue7=Gst.ElementFactory.make("queue","queue7")
# # Adding pipeline
# pipeline.add(queue1)
# pipeline.add(queue2)
# pipeline.add(queue3)
# pipeline.add(queue4)
# pipeline.add(queue5)
# pipeline.add(queue6)
# pipeline.add(queue7)
# 🅲🆁🅴🅰🆃🅸🅽🅶 🅿🅶🅸🅴
print("Creating Pgie \n ")
pgie = Gst.ElementFactory.make("nvinfer", "primary-inference")
if not pgie:
sys.stderr.write(" Unable to create pgie \n")
# 🅲🆁🅴🅰🆃🅸🅽🅶 🆃🆁🅰🅲🅺🅴🆁
tracker = Gst.ElementFactory.make("nvtracker", "tracker")
if not tracker:
sys.stderr.write(" Unable to create tracker \n")
# 🅲🆁🅴🅰🆃🅸🅽🅶 🆂🅶🅸🅴 1
sgie1 = Gst.ElementFactory.make("nvinfer", "secondary1-nvinference-engine")
if not sgie1:
sys.stderr.write(" Unable to make sgie1 \n")
# 🅲🆁🅴🅰🆃🅸🅽🅶 🅽🆅🆅🅸🅳🅲🅾🅽🆅 1
print("Creating nvvidconv1 \n ")
nvvidconv1 = Gst.ElementFactory.make("nvvideoconvert", "convertor1")
if not nvvidconv1:
sys.stderr.write(" Unable to create nvvidconv1 \n")
# Creating filter 1
print("Creating filter1 \n ")
caps1 = Gst.Caps.from_string("video/x-raw(memory:NVMM), format=RGBA")
filter1 = Gst.ElementFactory.make("capsfilter", "filter1")
if not filter1:
sys.stderr.write(" Unable to get the caps filter1 \n")
filter1.set_property("caps", caps1)
#🅲🆁🅴🅰🆃🅸🅽🅶 🆃🅸🅻🅴🆁
print("Creating tiler \n ")
tiler = Gst.ElementFactory.make("nvmultistreamtiler", "nvtiler")
if not tiler:
sys.stderr.write(" Unable to create tiler \n")
# 🅲🆁🅴🅰🆃🅸🅽🅶 🅽🆅🆅🅸🅳🅲🅾🅽🆅
print("Creating nvvidconv \n ")
nvvidconv = Gst.ElementFactory.make("nvvideoconvert", "convertor")
if not nvvidconv:
sys.stderr.write(" Unable to create nvvidconv \n")
# 🅲🆁🅴🅰🆃🅸🅽🅶 🅽🆅🅾🆂🅳
print("Creating nvosd \n ")
nvosd = Gst.ElementFactory.make("nvdsosd", "onscreendisplay")
if not nvosd:
sys.stderr.write(" Unable to create nvosd \n")
nvvidconv_postosd = Gst.ElementFactory.make("nvvideoconvert", "convertor_postosd")
if not nvvidconv_postosd:
sys.stderr.write(" Unable to create nvvidconv_postosd \n")
# Create Caps Filter
# Create a caps filter
caps = Gst.ElementFactory.make("capsfilter", "filter")
caps.set_property("caps", Gst.Caps.from_string("video/x-raw(memory:NVMM), format=I420"))
# Create a Encoder
# Make the encoder
if codec == "H264":
encoder = Gst.ElementFactory.make("nvv4l2h264enc", "encoder")
print("Creating H264 Encoder")
elif codec == "H265":
encoder = Gst.ElementFactory.make("nvv4l2h265enc", "encoder")
print("Creating H265 Encoder")
if not encoder:
sys.stderr.write(" Unable to create encoder")
encoder.set_property('bitrate', bitrate)
if is_aarch64():
encoder.set_property('preset-level', 1)
encoder.set_property('insert-sps-pps', 1)
#encoder.set_property('bufapi-version', 1)
# Make the payload-encode video into RTP packets
if codec == "H264":
rtppay = Gst.ElementFactory.make("rtph264pay", "rtppay")
print("Creating H264 rtppay")
elif codec == "H265":
rtppay = Gst.ElementFactory.make("rtph265pay", "rtppay")
print("Creating H265 rtppay")
if not rtppay:
sys.stderr.write(" Unable to create rtppay")
# Make the UDP sink
updsink_port_num = 5400
sink = Gst.ElementFactory.make("udpsink", "udpsink")
if not sink:
sys.stderr.write(" Unable to create udpsink")
sink.set_property('host', '224.224.255.255')
sink.set_property('port', updsink_port_num)
sink.set_property('async', False)
sink.set_property('sync', 1)
print("Playing file {} ".format(uri_inputs))
streammux.set_property('width', 1920)
streammux.set_property('height', 1080)
streammux.set_property('batch-size', number_sources)
streammux.set_property('batched-push-timeout', MUXER_BATCH_TIMEOUT_USEC)\
# Creating PGIE Property
pgie.set_property('config-file-path', "config_infer_primary_gie.txt")
pgie_batch_size = pgie.get_property("batch-size")
if (pgie_batch_size != number_sources):
print("WARNING: Overriding infer-config batch-size", pgie_batch_size, " with number of sources ",
number_sources, " \n")
pgie.set_property("batch-size", number_sources)
# SGIE1 set property
sgie1.set_property('config-file-path', "sgie1_config.txt")
tiler_rows = int(math.sqrt(number_sources))
tiler_columns = int(math.ceil((1.0 * number_sources) / tiler_rows))
tiler.set_property("rows", tiler_rows)
tiler.set_property("columns", tiler_columns)
tiler.set_property("width", TILED_OUTPUT_WIDTH)
tiler.set_property("height", TILED_OUTPUT_HEIGHT)
if not is_aarch64():
# Use CUDA unified memory in the pipeline so frames
# can be easily accessed on CPU in Python.
mem_type = int(pyds.NVBUF_MEM_CUDA_UNIFIED)
streammux.set_property("nvbuf-memory-type", mem_type)
nvvidconv.set_property("nvbuf-memory-type", mem_type)
nvvidconv1.set_property("nvbuf-memory-type", mem_type)
tiler.set_property("nvbuf-memory-type", mem_type)
nvvidconv_postosd.set_property("nvbuf-memory-type", mem_type)
#Set properties of tracker
config = configparser.ConfigParser()
config.read('tracker_config.txt')
config.sections()
for key in config['tracker']:
if key == 'tracker-width' :
tracker_width = config.getint('tracker', key)
tracker.set_property('tracker-width', tracker_width)
if key == 'tracker-height' :
tracker_height = config.getint('tracker', key)
tracker.set_property('tracker-height', tracker_height)
if key == 'gpu-id' :
tracker_gpu_id = config.getint('tracker', key)
tracker.set_property('gpu_id', tracker_gpu_id)
if key == 'll-lib-file' :
tracker_ll_lib_file = config.get('tracker', key)
tracker.set_property('ll-lib-file', tracker_ll_lib_file)
if key == 'll-config-file' :
tracker_ll_config_file = config.get('tracker', key)
tracker.set_property('ll-config-file', tracker_ll_config_file)
print("Adding elements to Pipeline \n")
pipeline.add(pgie)
pipeline.add(tracker)
pipeline.add(sgie1)
pipeline.add(tiler)
pipeline.add(nvvidconv)
pipeline.add(filter1)
pipeline.add(nvvidconv1)
pipeline.add(nvosd)
pipeline.add(nvvidconv_postosd)
pipeline.add(caps)
pipeline.add(encoder)
pipeline.add(rtppay)
pipeline.add(sink)
print("Linking elements in the Pipeline \n")
streammux.link(pgie)
pgie.link(tracker)
tracker.link(sgie1)
sgie1.link(nvvidconv1)
nvvidconv1.link(filter1)
filter1.link(tiler)
tiler.link(nvvidconv)
nvvidconv.link(nvosd)
nvosd.link(nvvidconv_postosd)
nvvidconv_postosd.link(caps)
caps.link(encoder)
encoder.link(rtppay)
rtppay.link(sink)
# create an event loop and feed gstreamer bus mesages to it
loop = GLib.MainLoop()
bus = pipeline.get_bus()
bus.add_signal_watch()
bus.connect("message", bus_call, loop)
# Start streaming
rtsp_port_num = 8554
server = GstRtspServer.RTSPServer.new()
server.props.service = "%d" % rtsp_port_num
server.attach(None)
factory = GstRtspServer.RTSPMediaFactory.new()
factory.set_launch( "( udpsrc name=pay0 port=%d buffer-size=524288 caps=\"application/x-rtp, media=video, clock-rate=90000, encoding-name=(string)%s, payload=96 \" )" % (updsink_port_num, codec))
factory.set_shared(True)
server.get_mount_points().add_factory("/ds-test", factory)
print("\n *** DeepStream: Launched RTSP Streaming at rtsp://localhost:%d/ds-test ***\n\n" % rtsp_port_num)
tiler_sink_pad = tiler.get_static_pad("sink")
if not tiler_sink_pad:
sys.stderr.write(" Unable to get sink pad \n")
else:
tiler_sink_pad.add_probe(Gst.PadProbeType.BUFFER, tiler_sink_pad_buffer_probe, 0)
# perf callback function to print fps every 5 sec
GLib.timeout_add(5000, perf_data.perf_print_callback)
print("Starting pipeline \n")
# start play back and listed to events
pipeline.set_state(Gst.State.PLAYING)
try:
loop.run()
except:
pass
# cleanup
print("Exiting app\n")
pipeline.set_state(Gst.State.NULL)
def parse_args():
parser = argparse.ArgumentParser(description='RTSP Output Sample Application Help ')
parser.add_argument("-i","--uri_inputs", metavar='N', type=str, nargs='+',
help='Path to inputs URI e.g. rtsp:// ... or file:// seperated by space')
parser.add_argument("-c", "--codec", default="H264",
help="RTSP Streaming Codec H264/H265 , default=H264", choices=['H264','H265'])
parser.add_argument("-b", "--bitrate", default=4000000,
help="Set the encoding bitrate ", type=int)
# Check input arguments
if len(sys.argv)==1:
parser.print_help(sys.stderr)
sys.exit(1)
args = parser.parse_args()
print("URI Inputs: " + str(args.uri_inputs ))
return args.uri_inputs , args.codec, args.bitrate
if __name__ == '__main__':
uri_inputs , out_codec, out_bitrate = parse_args()
sys.exit(main(uri_inputs, out_codec, out_bitrate))
This is my sgie1
[property]
gpu-id=0
gie-unique-id=2
operate-on-gie-id=1
num-detected-classes=2
net-scale-factor=0.01735207357279195
offsets=123.675;116.28;103.53
model-color-format=0
onnx-file=/opt/nvidia/deepstream/deepstream-6.4/samples/configs/test_by_varun/model/resnet50_market1501_aicity156.onnx
model-engine-file=/opt/nvidia/deepstream/deepstream-6.4/samples/configs/test_by_varun/model/resnet50_market1501_aicity156.onnx_b16_gpu0_fp16.engine
infer-dims=3;256;128
batch-size=30
# 0=FP32, 1=INT8, 2=FP16 mode
network-mode=2
network-type=1
interval=1
# Infer Processing Mode 1=Primary Mode 2=Secondary Mode
process-mode=2
# ## Clustering algorithm=0=GroupRectangle 1=DBSCAN 2=NMS 3=Hybrid 4=NoClustering
# cluster-mode=3
classifier-threshold=0
output-tensor-meta=1
maintain-aspect-ratio=0
# Extract embedding on "people" class only
operate-on-class-ids=0
ERROR: …/nvdsinfer/nvdsinfer_model_builder.cpp:307 Cannot access ONNX file ‘/opt/nvidia/deepstream/deepstream-6.4/samples/configs/test_by_varun/model/resnet50_market1501_aicity156.onnx’
ERROR: …/nvdsinfer/nvdsinfer_model_builder.cpp:971 failed to build network since parsing model errors.
ERROR: …/nvdsinfer/nvdsinfer_model_builder.cpp:804 failed to build network.
0:00:11.386077495 3036 0x55bb79324150 ERROR nvinfer gstnvinfer.cpp:676:gst_nvinfer_logger: NvDsInferContext[UID 2]: Error in NvDsInferContextImpl::buildModel() <nvdsinfer_context_impl.cpp:2126> [UID = 2]: build engine file failed
0:00:11.620323457 3036 0x55bb79324150 ERROR nvinfer gstnvinfer.cpp:676:gst_nvinfer_logger: NvDsInferContext[UID 2]: Error in NvDsInferContextImpl::generateBackendContext() <nvdsinfer_context_impl.cpp:2212> [UID = 2]: build backend context failed
0:00:11.621803589 3036 0x55bb79324150 ERROR nvinfer gstnvinfer.cpp:676:gst_nvinfer_logger: NvDsInferContext[UID 2]: Error in NvDsInferContextImpl::initialize() <nvdsinfer_context_impl.cpp:1351> [UID = 2]: generate backend failed, check config file settings
Error: gst-resource-error-quark: Failed to create NvDsInferContext instance (1): gstnvinfer.cpp(898): gst_nvinfer_start (): /GstPipeline:pipeline0/GstNvInfer:secondary1-nvinference-engine:
Config file path: sgie1_config.txt, NvDsInfer Error: NVDSINFER_CONFIG_FAILED
Exiting app
This is my error please help me with this