Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6571 Discussions

Confidence score on custom classify model

hungtrieu07
Novice
4,198 Views

In the previous thread, I have successfully display the output of person attribute recognition model using DLStreamer pipeline. But when debug, I saw the confidence score of that model is only 1 value, but I need each value of each attribute, for more post-processing on gvapython element.

This is my current pipeline:

GST_DEBUG=4 gst-launch-1.0 filesrc location=../video_data/1740731094984.mp4 ! decodebin ! videoconvert ! \
gvadetect model=./ov_exported_model/person_vehicle/FP16.xml device=CPU ! queue ! \
gvaclassify model=./onnx_models/openvino_model/model.xml model-proc=./onnx_models/openvino_model/model-proc.json object-class="person" device=CPU ! queue ! \
gvapython module=./process_attributes.py ! queue ! \
gvawatermark ! videoconvert ! autovideosink sync=false

 
0 Kudos
25 Replies
hungtrieu07
Novice
541 Views

Hello Witold, I tried your solution and this is the result:

hungtrieu07_0-1745484122329.png

Now the output label is only from detection model, the person attribute output are gone. I'm doing on merge some attributes into a group, I have some groups named "head region", "upper body region", etc... I have total 9 groups, each group I will get the max confidence score, so no more case a person maybe have 2 colors on upper body region. This is a graph of model's output:

hungtrieu07_1-1745484475942.png

 

0 Kudos
Witold_Intel
Employee
525 Views

Hi Hung, thanks for pointing this out. Apparently, an additional script for attribute grouping will be needed. It can be called attribute_grouper.py and look like this:


import numpy as np


# Full attribute list in EXACT model output order (verify with benchmark_app)

ATTRIBUTES_LIST = [

  "accessoryHat",    # 0

  "hairLong",      # 1

  "hairShort",     # 2

  "upperBodyShortSleeve", # 3

  "upperBodyBlack",   # 4

  "upperBodyBlue",   # 5

  "upperBodyBrown",   # 6

  "upperBodyGreen",   # 7

  "upperBodyGrey",   # 8

  "upperBodyOrange",  # 9

  "upperBodyPink",   # 10

  "upperBodyPurple",  # 11

  "upperBodyRed",    # 12

  "upperBodyWhite",   # 13

  "upperBodyYellow",  # 14

  "upperBodyLongSleeve", # 15

  "lowerBodyShorts",  # 16

  "lowerBodyShortSkirt", # 17

  "lowerBodyBlack",   # 18

  "lowerBodyBlue",   # 19

  "lowerBodyBrown",   # 20

  "lowerBodyGreen",   # 21

  "lowerBodyGrey",   # 22

  "lowerBodyOrange",  # 23

  "lowerBodyPink",   # 24

  "lowerBodyPurple",  # 25

  "lowerBodyRed",    # 26

  "lowerBodyWhite",   # 27

  "lowerBodyYellow",  # 28

  "lowerBodyLongSkirt", # 29

  "footwearLeatherShoes", # 30

  "footwearSandals",  # 31

  "footwearShoes",   # 32

  "footwearSneaker",  # 33

  "carryingBackpack",  # 34

  "carryingMessengerBag", # 35

  "carryingLuggageCase", # 36

  "carryingSuitcase",  # 37

  "personalLess30",   # 38

  "personalLess45",   # 39

  "personalLess60",   # 40

  "personalLarger60",  # 41

  "personalLess15",   # 42

  "personalMale",    # 43

  "personalFemale"   # 44

]


# Configure your 9 attribute groups here

ATTRIBUTE_GROUPS = {

  # Group 1: Head Attributes

  "Head": {

    "attributes": ["accessoryHat", "hairLong", "hairShort"],

    "display_template": "Head: {attribute}",

    "threshold": 0.4 # Lower threshold for head items

  },

   

  # Group 2: Upper Body Color

  "UpperColor": {

    "attributes": ["upperBodyBlack", "upperBodyBlue", "upperBodyBrown",

           "upperBodyGreen", "upperBodyGrey", "upperBodyOrange",

           "upperBodyPink", "upperBodyPurple", "upperBodyRed",

           "upperBodyWhite", "upperBodyYellow"],

    "display_template": "Upper: {attribute}",

    "threshold": 0.5

  },

   

  # Group 3: Upper Body Style

  "UpperStyle": {

    "attributes": ["upperBodyShortSleeve", "upperBodyLongSleeve"],

    "display_template": "Sleeve: {attribute}",

    "threshold": 0.5,

    "mutually_exclusive": True # Only one can be true

  },

   

  # Group 4: Lower Body Color

  "LowerColor": {

    "attributes": ["lowerBodyBlack", "lowerBodyBlue", "lowerBodyBrown",

           "lowerBodyGreen", "lowerBodyGrey", "lowerBodyOrange",

           "lowerBodyPink", "lowerBodyPurple", "lowerBodyRed",

           "lowerBodyWhite", "lowerBodyYellow"],

    "display_template": "Lower: {attribute}",

    "threshold": 0.5

  },

   

  # Group 5: Lower Body Style

  "LowerStyle": {

    "attributes": ["lowerBodyShorts", "lowerBodyShortSkirt", "lowerBodyLongSkirt"],

    "display_template": "Bottom: {attribute}",

    "threshold": 0.5,

    "mutually_exclusive": True

  },

   

  # Group 6: Footwear

  "Footwear": {

    "attributes": ["footwearLeatherShoes", "footwearSandals", 

           "footwearShoes", "footwearSneaker"],

    "display_template": "Shoes: {attribute}",

    "threshold": 0.5

  },

   

  # Group 7: Carrying Items

  "Carrying": {

    "attributes": ["carryingBackpack", "carryingMessengerBag",

           "carryingLuggageCase", "carryingSuitcase"],

    "display_template": "Bag: {attribute}",

    "threshold": 0.4 # Lower threshold for rare items

  },

   

  # Group 8: Age Group

  "Age": {

    "attributes": ["personalLess15", "personalLess30", 

           "personalLess45", "personalLess60", "personalLarger60"],

    "display_template": "Age: {attribute}",

    "threshold": 0.5,

    "mutually_exclusive": True

  },

   

  # Group 9: Gender

  "Gender": {

    "attributes": ["personalMale", "personalFemale"],

    "display_template": "Gender: {attribute}",

    "threshold": 0.7, # Higher threshold for gender

    "mutually_exclusive": True

  }

}


def process_frame(frame):

  for roi in frame.regions():

    # 1. Extract raw predictions

    attr_predictions = {}

    for tensor in roi.tensors():

      if tensor.format() == "ANY":

        data = tensor.data()

        if len(data) == len(ATTRIBUTES_LIST):

          for i, confidence in enumerate(data):

            attr_predictions[ATTRIBUTES_LIST[i]] = float(confidence)

     

    # 2. Process each group

    results = []

    for group_name, config in ATTRIBUTE_GROUPS.items():

      best_attr = None

      max_conf = 0

       

      for attribute in config["attributes"]:

        conf = attr_predictions.get(attribute, 0)

         

        # Skip if mutually exclusive and we already have a high-confidence result

        if config.get("mutually_exclusive", False) and best_attr and max_conf > config["threshold"]:

          continue

           

        if conf > max_conf and conf > config["threshold"]:

          max_conf = conf

          best_attr = attribute

       

      if best_attr:

        display_text = config["display_template"].format(attribute=best_attr)

        results.append((display_text, max_conf))

     

    # 3. Update ROI labels (shows all groups with detected attributes)

    if results:

      # Combine all results into one label for cleaner display

      combined_label = " | ".join([text for text, _ in results])

      roi.set_label(combined_label, min([conf for _, conf in results]))

   

  return True


# For debugging (enable in development)

DEBUG_MODE = False

if DEBUG_MODE:

  def debug_print_predictions(predictions):

    print("\nRaw Predictions:")

    for attr, conf in predictions.items():

      if conf > 0.3: # Only show attributes with >30% confidence

        print(f"{attr}: {conf:.2f}")

   

  # Add this inside process_frame after getting attr_predictions

  debug_print_predictions(attr_predictions)


0 Kudos
Witold_Intel
Employee
491 Views

I can add that the updated pipeline should be set up like this if it helps you:


gst-launch-1.0 \

filesrc location=video.mp4 ! decodebin ! videoconvert ! \

gvadetect model=person_vehicle.xml device=CPU ! queue ! \

gvainference model=attribute_model.xml device=CPU inference-region=roi ! queue ! \

gvapython module=attribute_grouper.py ! \

gvawatermark ! videoconvert ! autovideosink sync=false


0 Kudos
Witold_Intel
Employee
462 Views

Hi Hung, please respond to the previous messages within 3 business days. Otherwise I will consider this issue resolved.


0 Kudos
Wan_Intel
Moderator
417 Views

Hi hungtrieu07,

Thank you for your question.


If you need additional information from Intel, please submit a new thread as this thread will no longer be monitored.



Regards,

Wan


0 Kudos
Reply