Hi @clay1 - currently there isn’t an API in the imageNet class for this - I will add it to my todo list.
What you could do to test it though, is add a quick little function to jetson-inference/c/imageNet.h
(inside the imageNet class, around line 183 or so would work)
// add this inside public imageNet functions
inline float GetConfidence( uint32_t index ) const { return mOutputs[0].CPU[index]; }
Then, you would need to write the Python binding for this in jetson-inference/python/bindings/PyImageNet.cpp
PyObject* PyImageNet_GetConfidence( PyImageNet_Object* self, PyObject* args )
{
if( !self || !self->net )
{
PyErr_SetString(PyExc_Exception, LOG_PY_INFERENCE "imageNet invalid object instance");
return NULL;
}
int classIdx = 0;
if( !PyArg_ParseTuple(args, "i", &classIdx) )
{
PyErr_SetString(PyExc_Exception, LOG_PY_INFERENCE "imageNet failed to parse arguments");
return NULL;
}
if( classIdx < 0 || classIdx >= self->net->GetNumClasses() )
{
PyErr_SetString(PyExc_Exception, LOG_PY_INFERENCE "imageNet requested class index is out of bounds");
return NULL;
}
return PyFloat_FromDouble(self->net->GetConfidence(classIdx));
}
Finally, add the binding to pyImageNet_Methods[]
list to register it with Python:
static PyMethodDef pyImageNet_Methods[] =
{
/* add this GetConfidence line below */
{ "GetConfidence", (PyCFunction)PyImageNet_GetConfidence, METH_VARARGS, "Get class confidence"},
{ "Classify", (PyCFunction)PyImageNet_Classify, METH_VARARGS|METH_KEYWORDS, DOC_CLASSIFY},
{ "GetNetworkName", (PyCFunction)PyImageNet_GetNetworkName, METH_NOARGS, DOC_GET_NETWORK_NAME},
{ "GetNumClasses", (PyCFunction)PyImageNet_GetNumClasses, METH_NOARGS, DOC_GET_NUM_CLASSES},
{ "GetClassDesc", (PyCFunction)PyImageNet_GetClassDesc, METH_VARARGS, DOC_GET_CLASS_DESC},
{ "GetClassSynset", (PyCFunction)PyImageNet_GetClassSynset, METH_VARARGS, DOC_GET_CLASS_SYNSET},
{ "Usage", (PyCFunction)PyImageNet_Usage, METH_NOARGS|METH_STATIC, DOC_USAGE_STRING},
{NULL} /* Sentinel */
};
Then you should be able to use it in a loop from Python, like net.GetConfidence(n)
Remember to re-run make
and sudo make install
after making the changes.