# Python add user meta data to batch\_meta

**URL:** <https://forums.developer.nvidia.com/t/python-add-user-meta-data-to-batch-meta/197632>\
**Category:** DeepStream SDK\
**Tags:** python, gstreamer, deepstream\
**Created:** [December 9, 2021, 4:00pm UTC](https://forums.developer.nvidia.com/t/python-add-user-meta-data-to-batch-meta/197632 "2021-12-09T16:00:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahsaanraazaa](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/ahsaanraazaa/32/278647_2.png) [@ahsaanraazaa](https://forums.developer.nvidia.com/u/ahsaanraazaa)\
**Post date:** [December 9, 2021, 4:00pm UTC](https://forums.developer.nvidia.com/t/python-add-user-meta-data-to-batch-meta/197632/1 "2021-12-09T16:00:28Z")

</div>

Please provide complete information as applicable to your setup.

**• Hardware Platform (GPU)**  
**• DeepStream Version 5.1**  
**• TensorRT 7.2**  
**• NVIDIA GPU Driver Version 4.55.23.0.5**  
**• Issue Type(bugs)**  
\*\*• How to reproduce the issue ? \*\*

we are trying to add user\_meta\_data to batch\_meta data to transfer data between plugins  
we looked into deepstream-user-metadata-test.c app to for reference to write code for our  
python plugin.

**1:** For start we used pyds.nvds\_get\_user\_meta\_type(“NVDS\_USER\_META\_OUR\_CASE”) as mentioned  
in your python documentation to create custom type but when ever we run this

```
        CustomMetadata.Type = pyds.nvds_get_user_meta_type("NVDS_USER_META_OUR_CASE")
        print(CustomMetadata.Type)

         we get this in the output.

         **NvDsMetaType.???**

```

**2:** user\_meta: pyds.NvDsUserMeta = pyds.nvds\_acquire\_user\_meta\_from\_pool(batch\_meta)  
pyds.user\_copyfunc(user\_meta, metadata.copy)  
pyds.user\_releasefunc(user\_meta, metadata.release)  
the function metadata.copy and metadata.release never ran and these lines produce no errors

\*\*3:\*\*we used Cython to generate capsule instance to attach it to user\_meta\_data  
custom\_obj = metadata.CustomMetadata()  
user\_meta: pyds.NvDsUserMeta = pyds.nvds\_acquire\_user\_meta\_from\_pool(batch\_meta)  
pyds.user\_copyfunc(user\_meta, metadata.copy)  
pyds.user\_releasefunc(user\_meta, metadata.release)

```
        test = Test()
        Test.peek(test.vars)
        user_meta.user_meta_data = test.vars
        print("user_meta.", user_meta.user_meta_data)
        user_meta.base_meta.meta_type = metadata.CustomMetadata.Type
        pyds.nvds_add_user_meta_to_batch(batch_meta, user_meta)

        **below code is to convert python data to capsule instance**

```

> Blockquote\> #cython: language\_level=3

from cpython.pycapsule cimport PyCapsule\_New, PyCapsule\_IsValid, PyCapsule\_GetPointer

class Test:  
def **init** (self):  
cdef int test = 10  
cdef const char \*name = “test”  
self.vars = PyCapsule\_New(\<void \*\>&test, name, NULL)

```
@staticmethod
def peek(self):
    cdef const char *name = "test"
    if not PyCapsule_IsValid(self, name):
        raise ValueError("invalid pointer to parameters")
    cdef int test = <int >PyCapsule_GetPointer(self, name)
    print(test[0])

    # Print pointer address
    print("{0:x}".format(<unsigned long long>test))
    
def get_caps(self):
    cdef int test = 10
    cdef const char *name = "test"
    return PyCapsule_New(<void *>&test, name, NULL)
    
    # Print pointer address
    #print("{0:x}".format(<unsigned long long>test))

```

there are no errors on assaigning the capsule instance but when we received data on the other plugin we  
get **\<capsule object NULL at 0x7f18db86a5a0\>**

---

<div class="post-metadata">

**Author:** ![Fiona.Chen](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/fiona.chen/32/15508_2.png) [@Fiona.Chen](https://forums.developer.nvidia.com/u/Fiona.Chen)\
**Post date:** [December 14, 2021, 5:08am UTC](https://forums.developer.nvidia.com/t/python-add-user-meta-data-to-batch-meta/197632/3 "2021-12-14T05:08:13Z")

</div>

> [@ahsaanraazaa](#):
>
> **1:** For start we used pyds.nvds\_get\_user\_meta\_type(“NVDS\_USER\_META\_OUR\_CASE”) as mentioned  
> in your python documentation to create custom type but when ever we run this

The meta\_type is not string type. [NVIDIA DeepStream SDK API Reference: Metadata Structures | NVIDIA Docs](https://docs.nvidia.com/metropolis/deepstream/sdk-api/group __metadata__ structures.html#gafe355a3b337b0ac13e25394dddf6a63f)

> [@ahsaanraazaa](#):
>
> **2:** user\_meta: pyds.NvDsUserMeta = pyds.nvds\_acquire\_user\_meta\_from\_pool(batch\_meta)  
> pyds.user\_copyfunc(user\_meta, metadata.copy)  
> pyds.user\_releasefunc(user\_meta, metadata.release)  
> the function metadata.copy and metadata.release never ran and these lines produce no errors

Please debug your code

> [@ahsaanraazaa](#):
>
> \*\*3:\*\*we used Cython to generate capsule instance to attach it to user\_meta\_data  
> custom\_obj = metadata.CustomMetadata()  
> user\_meta: pyds.NvDsUserMeta = pyds.nvds\_acquire\_user\_meta\_from\_pool(batch\_meta)  
> pyds.user\_copyfunc(user\_meta, metadata.copy)  
> pyds.user\_releasefunc(user\_meta, metadata.release)

> <https://github.com/NVIDIA-AI-IOT/deepstream_python_apps/blob/master/HOWTO.md#metadata-access>

---

<div class="post-metadata">

**Author:** ![ahsaanraazaa](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/ahsaanraazaa/32/278647_2.png) [@ahsaanraazaa](https://forums.developer.nvidia.com/u/ahsaanraazaa)\
**Post date:** [December 15, 2021, 7:55am UTC](https://forums.developer.nvidia.com/t/python-add-user-meta-data-to-batch-meta/197632/4 "2021-12-15T07:55:59Z")

</div>

The meta\_type is not string type. [NVIDIA DeepStream SDK API Reference: Metadata Structures](https://docs.nvidia.com/metropolis/deepstream/sdk-api/group __metadata__ structures.html#gafe355a3b337b0ac13e25394dddf6a63f)

Here in your documentation it is taking string as an argument:  
[https://docs.nvidia.com/metropolis/deepstream/python-api/PYTHON\_API/Methods/methodsdoc.html#nvds-get-user-meta-type](https://docs.nvidia.com/metropolis/deepstream/python-api/PYTHON_API/Methods/methodsdoc.html#nvds-get-user-meta-type)

 ![send_nvidia](https://global.discourse-cdn.com/nvidia/original/3X/9/a/9a955df6a94eb81ab1c5cf96afdaad93e79093e3.png)

In your documentation

[https://docs.nvidia.com/metropolis/deepstream/sdk-api/group\_\_metadata\_\_structures.html#ggafe355a3b337b0ac13e25394dddf6a63fa406287ab4e6a314d51cf3bc0788afc2b](https://docs.nvidia.com/metropolis/deepstream/sdk-api/group __metadata__ structures.html#ggafe355a3b337b0ac13e25394dddf6a63fa406287ab4e6a314d51cf3bc0788afc2b)  
it is mentioned that we can add **“user specific meta types”** at the end of **enum NvDsMetaType**.  
In python we can not add value to the enum at runtime, can you please explain how we can add our custom type to enum NvDsMetaType.

2 .  
we can access meta data generated by nv\_infer down the pipeline  
but we are not able to add our custom data to the buffer.  
The aim is to attach meta data from a plugin and access that meta data from different plugin down the pipeline.

---

<div class="post-metadata">

**Author:** ![NNDam](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@NNDam](https://forums.developer.nvidia.com/u/NNDam)\
**Post date:** [February 17, 2022, 8:00am UTC](https://forums.developer.nvidia.com/t/python-add-user-meta-data-to-batch-meta/197632/5 "2022-02-17T08:00:52Z")

</div>

Hi @ahsaanraazaa ,  
I tried both  
**user\_meta.user\_meta\_data = test.vars**  
**user\_meta.user\_meta\_data = pyds.NvDsUserMeta.cast(test.vars)**  
and still have same problems **\<capsule object NULL at 0x7f18db86a5a0\>**  
Did you solve your problems ?

---

<div class="post-metadata">

**Author:** ![ahsaanraazaa](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/ahsaanraazaa/32/278647_2.png) [@ahsaanraazaa](https://forums.developer.nvidia.com/u/ahsaanraazaa)\
**Post date:** [October 11, 2022, 10:35am UTC](https://forums.developer.nvidia.com/t/python-add-user-meta-data-to-batch-meta/197632/6 "2022-10-11T10:35:32Z")

</div>

Nope

---

<div class="post-metadata">

**Author:** ![Fiona.Chen](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/fiona.chen/32/15508_2.png) [@Fiona.Chen](https://forums.developer.nvidia.com/u/Fiona.Chen)\
**Post date:** [November 8, 2022, 10:17am UTC](https://forums.developer.nvidia.com/t/python-add-user-meta-data-to-batch-meta/197632/8 "2022-11-08T10:17:52Z")

</div>

**There is no update from you for a period, assuming this is not an issue anymore. Hence we are closing this topic. If need further support, please open a new one.  
Thanks**  
There is sample of the usage for pyds.nvds\_add\_user\_meta\_to\_frame in [deepstream\_python\_apps/deepstream\_test\_4.py at master · NVIDIA-AI-IOT/deepstream\_python\_apps (github.com)](https://github.com/NVIDIA-AI-IOT/deepstream_python_apps/blob/master/apps/deepstream-test4/deepstream_test_4.py#L308), it is the similar case.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [December 6, 2022, 6:19am UTC](https://forums.developer.nvidia.com/t/python-add-user-meta-data-to-batch-meta/197632/10 "2022-12-06T06:19:56Z")

</div>

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