outputsToNMSPredictionsYoloV8 method
Implementation
List<ResultObjectDetection> outputsToNMSPredictionsYoloV8(
List<double> outputs) {
List<ResultObjectDetection> results = [];
for (int i = 0; i < outputRow; i++) {
double x = outputs[i];
double y = outputs[outputRow + i];
double w = outputs[2 * outputRow + i];
double h = outputs[3 * outputRow + i];
double left = (x - w / 2);
double top = (y - h / 2);
double right = (x + w / 2);
double bottom = (y + h / 2);
double max = outputs[4 * outputRow + i];
int cls = 0;
for (int j = 4; j < outputColumn; j++) {
if (outputs[j * outputRow + i] > max) {
max = outputs[j * outputRow + i];
cls = j - 4;
}
}
if (max > scoreThreshold) {
PyTorchRect rect = PyTorchRect(
left: left / imageWidth,
top: top / imageHeight,
right: right / imageWidth,
bottom: bottom / imageHeight,
width: w / imageWidth,
height: h / imageHeight,
);
ResultObjectDetection result =
ResultObjectDetection(classIndex: cls, score: max, rect: rect);
results.add(result);
}
}
print("Result length before processing ${results.length}");
return nonMaxSuppression(results); // Please implement this method
}