How to Rewrite deepstream_user_metadata_app in Python

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU) Jetson AGX Xavier
• DeepStream Version 5.1
• JetPack Version (valid for Jetson only) 4.6

• Issue Type( questions, new requirements, bugs): I want to Rewrite deepstream_user_metadata_app in Python But the we got the Error:

The C original code:

       /* Acquire NvDsUserMeta user meta from pool */
        user_meta = nvds_acquire_user_meta_from_pool(batch_meta);

        /* Set NvDsUserMeta below */
        user_meta->user_meta_data = (void *)set_metadata_ptr();
        user_meta->base_meta.meta_type = user_meta_type;
        user_meta->base_meta.copy_func = (NvDsMetaCopyFunc)copy_user_meta;
        user_meta->base_meta.release_func = (NvDsMetaReleaseFunc)release_user_meta;

I rewrite to This:

        user_meta = pyds.nvds_acquire_user_meta_from_pool(batch_meta);
        user_meta = pyds.NvDsUserMeta.cast(user_meta)
        # /* Set NvDsUserMeta below */
        user_meta.user_meta_data = set_metadata_ptr()
        user_meta.base_meta.meta_type = user_meta_type
        pyds.user_copyfunc(user_meta, copy_user_meta)
        pyds.user_releasefunc(user_meta, release_user_meta)

The set_metadata_ptr function in Python

def set_metadata_ptr():
    user_metadata = [i for i in range(USER_ARRAY_SIZE)]
    return np.array(user_metadata)

The copy_user_meta and release_user_meta in Python:

def copy_user_meta(data, user_data):
    # Cast data to pyds.NvDsUserMeta
    user_meta = pyds.NvDsUserMeta.cast(data)
    src_meta_data = user_meta.user_meta_data
    dst_user_metadata = src_meta_data.copy()
    return dst_user_metadata

def release_user_meta(data, user_data):
    # Cast data to pyds.NvDsUserMeta
    user_meta = pyds.NvDsUserMeta.cast(data)

When I run the Python code, the Error appeared:

Invoked with: <pyds.NvDsUserMeta object at 0x7f58688e30>, array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15])
Traceback (most recent call last):
  File "", line 185, in nvinfer_src_pad_buffer_probe
    user_meta.user_meta_data = set_metadata_ptr()
TypeError: (): incompatible function arguments. The following argument types are supported:
    1. (self: pyds.NvDsUserMeta, arg0: capsule) -> None

Thank you !

Can you refer below samples?

deepstream_python_apps/ at master · NVIDIA-AI-IOT/deepstream_python_apps · GitHub

Sir, It doesn’t work. I want to write the deepstream_user_metadata in Python. The deepstream test 1 not relevant to deepstream_user_metadata. You just make sure that my function above is correct or not ? And if not, what should I change?

Thank you

1 Like

@Fiona.Chen , can you share the sample for the topic?

1 Like

Please refer to deepstream_python_apps/ at master · NVIDIA-AI-IOT/deepstream_python_apps (

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.