dusty-nv / jetson-inference

Hello AI World guide to deploying deep-learning inference networks and deep vision primitives with TensorRT and NVIDIA Jetson.
https://developer.nvidia.com/embedded/twodaystoademo
MIT License
7.78k stars 2.98k forks source link

Using 2 class onnx classifier with deepstream, labels are the same (probability=1.0, num_classes=0) #1106

Closed vi-jmak closed 1 year ago

vi-jmak commented 3 years ago

Hi, I have trained a 2-class classifier with jetson-inference package and exported to onnx file. I am trying to use this with Deepstream 5.1 as primary gie on Jetson Xavier NX. I seem to be able to run deepstream with the config and extracting meta data using pyds.so from the python bindings and through: NvDsFrameMeta->NvDsObjectMeta->NvDsClassifierMeta->NvDsLabelInfo. I have changed the labels file so that it is in the format label1;label2.

However, the results only show label1 with a probability of 1.0 and num_classes=0 from NvDsLabelInfo. Please could you advise, thanks!

Config file:

[property]
gpu-id=0
net-scale-factor=1
onnx-file=models/resnet18.onnx
labelfile-path=labels.txt
force-implicit-batch-dim=0
batch-size=1
# 0=FP32 and 1=INT8 mode 2=FP16
network-mode=2
#classifier
network-type=1

gie-unique-id=1
classifier-threshold=0.5
# process-mode: 2 - inferences on crops from primary detector, 1 - inferences on whole frame
process-mode=1
vi-jmak commented 3 years ago

I am now trying to write a custom parser using the files at /opt/nvidia/deepstream/deepstream/sources/libs/nvdsinfer_customparser. The README suggests that it should be suitable for Resnet18. Printing out, I get:

numAttributes = 1
numClasses = 2

which seem correct, but printing out probability from float probability = outputCoverageBuffer[c]; always seems to give either 1 or 0. I have tested the model with imagenet and get reasonable results (probability not equal to 1).

vi-jmak commented 3 years ago

Hi, after more experimenting, it seems that the net-scale-factor and offset seem to make the outputs more sensitive but still give poor results. I have read the docs and understand what the terms mean, but unsure how to calculate them?

Appreciate any pointers/advice!