Hi there,
Inspired from the YOLOv8n example provided on HuggingFace, I have the following code for a task I am trying to achieve:
// Get the indices
var scores = Functional.ReduceMax(allScores, 0) - 0.7f;
var classIDs = Functional.ArgMax(allScores, 0);
var indices = Functional.NMS(boxCoords, scores, 0.3f);
// Get the mask
var selectProtos = Functional.Select(Protos, 1, indices); // indices -> no. of dets after NMS, protos -> (32,8400)
How do we handle the case when the indices
variable has 0 detections? This would result in the shape [0]
and when used in the Functional.Select()
function, throws the following error for real-time inference:
IndexOutOfRangeException: Index was outside the bounds of the array.
Unity.Sentis.Layers.Select.Execute (Unity.Sentis.ExecutionContext ctx) (at ./Library/PackageCache/com.unity.sentis@1.5.0-pre.3/Runtime/Core/Layers/Layer.Transformation.cs:977)
Unity.Sentis.GenericWorker.Execute () (at ./Library/PackageCache/com.unity.sentis@1.5.0-pre.3/Runtime/Core/Backends/GenericWorker.cs:133)
Unity.Sentis.GenericWorker.Execute (Unity.Sentis.Tensor input) (at ./Library/PackageCache/com.unity.sentis@1.5.0-pre.3/Runtime/Core/Backends/GenericWorker.cs:105)
It is possible that the YOLOv8n does not detect anything in the scene, and since we can’t use an If operator to check the shape of the FunctionalTensor within Functional implementations, how should one go about fixing this?
Also please recommend what is the best way to approach such problems, where you need to select the best detection index based on some operations within the method, for example max bounding box height?
Cheers