# Keeping the Secondary Classifier's best predicition

**URL:** <https://forums.developer.nvidia.com/t/keeping-the-secondary-classifiers-best-predicition/178524>\
**Category:** DeepStream SDK\
**Created:** [May 20, 2021, 11:24am UTC](https://forums.developer.nvidia.com/t/keeping-the-secondary-classifiers-best-predicition/178524 "2021-05-20T11:24:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wassim\_mohsni](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@wassim\_mohsni](https://forums.developer.nvidia.com/u/wassim_mohsni)\
**Post date:** [May 20, 2021, 11:24am UTC](https://forums.developer.nvidia.com/t/keeping-the-secondary-classifiers-best-predicition/178524/1 "2021-05-20T11:24:36Z")

</div>

Hello!

I’m creating an ALPR deepstream application on my Jetson Nano, and this is the inference part of the pipleline:  
Pgie (Plate Detector) → Tracker → OCR (Classifier)  
I am stuck with a couple of things:

1. For every tracked plate ID, I want to keep using (interval=0) the secondary classifier for inference until I get a classification confidece that’s higher than a certain threshold, and if I don’t, I want to simply keep the classification with the highest confidence.  
How do I do this?

2. I made 2 versions of my deepstream app, a C app and a deepstream\_app\_config.txt. I want to Crop the frame with nvvideoConvert before sending it to the Plate Detector. Is it possible to do it in the deepstream\_app\_config.txt without diving into C code? If yes then is there an example?

3. After cropping the frame and passing it to the detector, How do I display the inference results on the original full frame?

Thank you!

**• Hardware Platform: Jetson Nano 4GB**  
**• DeepStream 5.1**  
**• JetPack Version 4.5.1**  
**• TensorRT Version 7.1.3**  
**• Issue Type: questions**

---

<div class="post-metadata">

**Author:** ![bcao](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/bcao/32/14043_2.png) [@bcao](https://forums.developer.nvidia.com/u/bcao)\
**Post date:** [May 24, 2021, 1:42pm UTC](https://forums.developer.nvidia.com/t/keeping-the-secondary-classifiers-best-predicition/178524/3 "2021-05-24T13:42:44Z")

</div>

> [@wassim\_mohsni](#):
>
> For every tracked plate ID, I want to keep using (interval=0) the secondary classifier for inference until I get a classification confidece that’s higher than a certain threshold, and if I don’t, I want to simply keep the classification with the highest confidence.  
> How do I do this?

We already have some policy to decide if sgie should do inference when tracker enabled, you can check

> [@wassim\_mohsni](#):
>
> I made 2 versions of my deepstream app, a C app and a deepstream\_app\_config.txt. I want to Crop the frame with nvvideoConvert before sending it to the Plate Detector. Is it possible to do it in the deepstream\_app\_config.txt without diving into C code? If yes then is there an example?

Why you need to do that, sgie just do the same thing before do inference, you can check gstnvinfer.cpp → should\_infer\_object

> [@wassim\_mohsni](#):
>
> After cropping the frame and passing it to the detector, How do I display the inference results on the original full frame?

You can check gstnvinfer\_meta\_utils.cpp

---

<div class="post-metadata">

**Author:** ![wassim\_mohsni](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@wassim\_mohsni](https://forums.developer.nvidia.com/u/wassim_mohsni)\
**Post date:** [May 27, 2021, 10:52am UTC](https://forums.developer.nvidia.com/t/keeping-the-secondary-classifiers-best-predicition/178524/4 "2021-05-27T10:52:54Z")

</div>

> We already have some policy to decide if sgie should do inference when tracker enabled, you can check

> Why you need to do that, sgie just do the same thing before do inference, you can check gstnvinfer.cpp → should\_infer\_object

Yes I’m aware of the policy of reinfering if the object size gets 20% bigger, but I want to change it, I want the classifier to keep reinfering until the probability reaches a certain threshold.

So I dug into gstnvinfer.cpp → should\_infer\_object, and to implement my custom policy I need to access the classifier metadata in order to get the classification probabilty.

NvDsClassifierMetaList → NvDsClassifierMeta → NvDsLabelInfoList → \_NvDsLabelInfo → result\_prob

Problem is if you look at that for loop, the “classifier\_meta” variable is always null, am I doing something wrong? Is that not the right way to access Classifier metdata?

```
static inline gboolean
should_infer_object (GstNvInfer * nvinfer, GstBuffer * inbuf,
    NvDsObjectMeta * obj_meta, gulong frame_num,
    GstNvInferObjectHistory * history)
{
  NvDsClassifierMeta* classifier_meta;
  NvDsClassifierMetaList* classifier_meta_list;
  ...
  /* History is irrevelavant for detectors. */
  if (history && IS_CLASSIFIER_INSTANCE (nvinfer)) {
    gboolean should_reinfer = FALSE;
    ...
    for (classifier_meta_list = obj_meta->classifier_meta_list; classifier_meta_list; classifier_meta_list = classifier_meta_list->next) {
       
       classifier_meta = (NvDsClassifierMeta *) classifier_meta_list->data;
       if (classifier_meta == NULL) {
          // Ignore Null classifier meta.
          continue;
       }
    }
    return should_reinfer;
  }

  return TRUE;
}

```

---

<div class="post-metadata">

**Author:** ![bcao](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/bcao/32/14043_2.png) [@bcao](https://forums.developer.nvidia.com/u/bcao)\
**Post date:** [June 8, 2021, 7:41am UTC](https://forums.developer.nvidia.com/t/keeping-the-secondary-classifiers-best-predicition/178524/5 "2021-06-08T07:41:20Z")

</div>

> [@wassim\_mohsni](#):
>
> Problem is if you look at that for loop, the “classifier\_meta” variable is always null, am I doing something wrong? Is that not the right way to access Classifier metdata?

It should be expected since the classifier\_meta is attached after the inference, you can check gstnvinfer\_meta\_utils.cpp

---

<div class="post-metadata">

**Author:** ![TomNVIDIA](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/tomnvidia/32/14181_2.png) [@TomNVIDIA](https://forums.developer.nvidia.com/u/TomNVIDIA)\
**Post date:** [October 12, 2021, 4:13pm UTC](https://forums.developer.nvidia.com/t/keeping-the-secondary-classifiers-best-predicition/178524/7 "2021-10-12T16:13:54Z")

</div>


