# Preprocessing and Postprocessing in deepstream python

**URL:** <https://forums.developer.nvidia.com/t/preprocessing-and-postprocessing-in-deepstream-python/334359>\
**Category:** DeepStream SDK\
**Tags:** python, deepstream\
**Created:** [May 26, 2025, 12:03pm UTC](https://forums.developer.nvidia.com/t/preprocessing-and-postprocessing-in-deepstream-python/334359 "2025-05-26T12:03:30Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishakraj](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@vishakraj](https://forums.developer.nvidia.com/u/vishakraj)\
**Post date:** [May 26, 2025, 12:03pm UTC](https://forums.developer.nvidia.com/t/preprocessing-and-postprocessing-in-deepstream-python/334359/1 "2025-05-26T12:03:30Z")

</div>

**• Hardware Platform (Jetson / GPU)** : Jetson  
**• DeepStream Version** : 7.1  
**• JetPack Version (valid for Jetson only)** : 6.2  
**• TensorRT Version** : 10.3.0.30

Hi,

I am working on Deepstream with Python - [GitHub - NVIDIA-AI-IOT/deepstream\_python\_apps: DeepStream SDK Python bindings and sample applications](https://github.com/NVIDIA-AI-IOT/deepstream_python_apps) using `nvcr.io/nvidia/deepstream:7.1-triton-multiarch` docker image

Where, I successfully created the app with yolo algorithm to detect persons, now, i am looking to create the secondary model sgie to predict the gender of that person.

The main challenge is in the pipeline, how to do the preprocessing of the objects detected from the pgie and then feed to sgie as input.

I am using a prob function to get the object bbox details of the pgie, but how to link the preprocessing instruction in the pipeline which is required for the sgie. Is the preprocessing instruction has to be linked like a prob function before sgie?

Another clarification, currently, i am using the prob to take the output of pgie, if i added sgie, then how to get that output along with the pgie outputs.

I need to know the hierarchy for this scenario, help me to understand this flow, thanks

---

<div class="post-metadata">

**Author:** ![yuweiw](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/yuweiw/32/101255_2.png) [@yuweiw](https://forums.developer.nvidia.com/u/yuweiw)\
**Post date:** [May 27, 2025, 1:59am UTC](https://forums.developer.nvidia.com/t/preprocessing-and-postprocessing-in-deepstream-python/334359/3 "2025-05-27T01:59:04Z")

</div>

Please refer to our source code sample `sources\apps\sample_apps\deepstream-test2` first. This sample demonstrates how to first detect a vehicle, and then classify the type of the vehicle.  
Pipeline:

```auto
source->nvstreammux->pgie->sgie->nvdsosd->sink

```

Please set the config files according to your sgie model.

---

<div class="post-metadata">

**Author:** ![vishakraj](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@vishakraj](https://forums.developer.nvidia.com/u/vishakraj)\
**Post date:** [May 27, 2025, 5:49am UTC](https://forums.developer.nvidia.com/t/preprocessing-and-postprocessing-in-deepstream-python/334359/4 "2025-05-27T05:49:04Z")

</div>

@yuweiw, thanks for writting back,

I go through the `test2` app, i understand the flow, but the sgie model needs little bit of custom preprocessing, I need to do that from the output prediction of pgie. for that, i need the flow how to achieve that.

How to link that preprocessing function, is there any components available to do?

---

<div class="post-metadata">

**Author:** ![yuweiw](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/yuweiw/32/101255_2.png) [@yuweiw](https://forums.developer.nvidia.com/u/yuweiw)\
**Post date:** [May 27, 2025, 8:06am UTC](https://forums.developer.nvidia.com/t/preprocessing-and-postprocessing-in-deepstream-python/334359/5 "2025-05-27T08:06:50Z")

</div>

> [@vishakraj](#):
>
> How to link that preprocessing function, is there any components available to do?

Yes. You can modify the pipeline like below.

```auto
source->nvstreammux->pgie->nvpreprocess->sgie->nvdsosd->sink

```

You can refer to our [deepstream-pose-classification](https://github.com/NVIDIA-AI-IOT/deepstream_tao_apps/tree/master/apps/tao_others/deepstream-pose-classification). The pipeline is similar to your scenario.

---

<div class="post-metadata">

**Author:** ![vishakraj](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@vishakraj](https://forums.developer.nvidia.com/u/vishakraj)\
**Post date:** [May 27, 2025, 9:10am UTC](https://forums.developer.nvidia.com/t/preprocessing-and-postprocessing-in-deepstream-python/334359/6 "2025-05-27T09:10:09Z")

</div>

> [@yuweiw](#):
>
> You can refer to our [deepstream-pose-classification](https://github.com/NVIDIA-AI-IOT/deepstream_tao_apps/tree/master/apps/tao_others/deepstream-pose-classification). The pipeline is similar to your scenario.

this is in cpp code, is there any example in python available for reference  
please let me know

---

<div class="post-metadata">

**Author:** ![vishakraj](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@vishakraj](https://forums.developer.nvidia.com/u/vishakraj)\
**Post date:** [May 27, 2025, 9:24am UTC](https://forums.developer.nvidia.com/t/preprocessing-and-postprocessing-in-deepstream-python/334359/7 "2025-05-27T09:24:50Z")

</div>

Need to clarify this →

Statement 1 - the pgie gives the coordinates of the objects for the input stream resolution

Statement 2 - the sgie needs the cropped object image with preprocessed using some instructions

these two statements are necessary,

is the deepstream, automatically cropped the image based on the pgie output and feeds as input to sgie, - is that the way it works? if so, how this is happening, what is the flow of it. In the apps, i seen, we are just link different components and it works fine, but where this flow of cropping the objects based on the pgie output is defined, I mean which parameter handling this input for the sgie, If known, i can check for adding prob to process that input.

And, how to create the labels.txt file if the models has multiple head, like one head for classification and other for regression value, how it will be handled in labels.txt file. And how to make the sgie config file for updating the other parameters, like num-detected-classes, etc

please help me understand this, thanks

---

<div class="post-metadata">

**Author:** ![yuweiw](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/yuweiw/32/101255_2.png) [@yuweiw](https://forums.developer.nvidia.com/u/yuweiw)\
**Post date:** [May 28, 2025, 5:45am UTC](https://forums.developer.nvidia.com/t/preprocessing-and-postprocessing-in-deepstream-python/334359/8 "2025-05-28T05:45:53Z")

</div>

> [@vishakraj](#):
>
> is the deepstream, automatically cropped the image based on the pgie output and feeds as input to sgie, - is that the way it works?

No. The pgie just sends the coordinates of the object, not crops the images. If you want to know the detailed process, please refer to the [nvinfer diagram](https://forums.developer.nvidia.com/t/deepstream-sdk-faq/80236) to read our open-source code `sources\gst-plugins\gst-nvinfer\gstnvinfer.cpp`.

> [@vishakraj](#):
>
> how to create the labels.txt file if the models has multiple head, like one head for classification and other for regression value, how it will be handled in labels.txt file.

This needs to be configured according to your own model.

---

<div class="post-metadata">

**Author:** ![vishakraj](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@vishakraj](https://forums.developer.nvidia.com/u/vishakraj)\
**Post date:** [May 28, 2025, 5:55am UTC](https://forums.developer.nvidia.com/t/preprocessing-and-postprocessing-in-deepstream-python/334359/9 "2025-05-28T05:55:20Z")

</div>

> [@yuweiw](#):
>
> This needs to be configured according to your own model.

Could you please share the document for this or any reference

`sources\gst-plugins\gst-nvinfer\gstnvinfer.cpp` - i will go through it, I am regaining the c/cpp syntaxs

thanks for sharing this

---

<div class="post-metadata">

**Author:** ![yuweiw](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/yuweiw/32/101255_2.png) [@yuweiw](https://forums.developer.nvidia.com/u/yuweiw)\
**Post date:** [May 28, 2025, 8:38am UTC](https://forums.developer.nvidia.com/t/preprocessing-and-postprocessing-in-deepstream-python/334359/10 "2025-05-28T08:38:45Z")

</div>

> [@vishakraj](#):
>
> Could you please share the document for this or any reference

This should be provided by the organization who trained the model. DeepStream is used for deploying the model. It won’t generate the label file.

---

<div class="post-metadata">

**Author:** ![vishakraj](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@vishakraj](https://forums.developer.nvidia.com/u/vishakraj)\
**Post date:** [May 28, 2025, 10:13am UTC](https://forums.developer.nvidia.com/t/preprocessing-and-postprocessing-in-deepstream-python/334359/11 "2025-05-28T10:13:44Z")

</div>

I am seeking the syntax for the labels.txt file

For eg., from the model there we are getting three values, the first two values is the probability values for the classification task, and the last value is for regression task. If a model arch. is like this, then in what format the labels.txt should be?

---

<div class="post-metadata">

**Author:** ![yuweiw](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/yuweiw/32/101255_2.png) [@yuweiw](https://forums.developer.nvidia.com/u/yuweiw)\
**Post date:** [June 4, 2025, 3:06am UTC](https://forums.developer.nvidia.com/t/preprocessing-and-postprocessing-in-deepstream-python/334359/13 "2025-06-04T03:06:32Z")

</div>

You can refer to our source code `samples\models\Secondary_VehicleMake\labels.txt`.

---

<div class="post-metadata">

**Author:** ![yingliu](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/yingliu/32/136703_2.png) [@yingliu](https://forums.developer.nvidia.com/u/yingliu)\
**Post date:** [July 1, 2025, 8:21am UTC](https://forums.developer.nvidia.com/t/preprocessing-and-postprocessing-in-deepstream-python/334359/14 "2025-07-01T08:21:33Z")

</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**

---

<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:** [July 15, 2025, 8:22am UTC](https://forums.developer.nvidia.com/t/preprocessing-and-postprocessing-in-deepstream-python/334359/15 "2025-07-15T08:22:09Z")

</div>

Closed on July 15, 2025, 8:22am UTC

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