outputsToNMSPredictionsYolov5 method

List<ResultObjectDetection> outputsToNMSPredictionsYolov5(
  1. List<double> outputs
)

Implementation

List<ResultObjectDetection> outputsToNMSPredictionsYolov5(
    List<double> outputs) {
  List<ResultObjectDetection> results = [];
  for (int i = 0; i < outputRow; i++) {
    if (outputs[i * outputColumn + 4] > scoreThreshold) {
      double x = outputs[i * outputColumn];
      double y = outputs[i * outputColumn + 1];
      double w = outputs[i * outputColumn + 2];
      double h = outputs[i * outputColumn + 3];

      double left = (x - w / 2);
      double top = (y - h / 2);
      double right = (x + w / 2);
      double bottom = (y + h / 2);

      double max = outputs[i * outputColumn + 5];
      int cls = 0;
      for (int j = 0; j < outputColumn - 5; j++) {
        if (outputs[i * outputColumn + 5 + j] > max) {
          max = outputs[i * outputColumn + 5 + j];
          cls = j;
        }
      }

      PyTorchRect rect = PyTorchRect(
        left: left / imageWidth,
        top: top / imageHeight,
        width: w / imageWidth,
        height: h / imageHeight,
        bottom: bottom / imageHeight,
        right: right / imageWidth,
      );
      ResultObjectDetection result = ResultObjectDetection(
        classIndex: cls,
        score: outputs[i * outputColumn + 4],
        rect: rect,
      );

      results.add(result);
    }
  }

  print("Result length before processing ${results.length}");
  return nonMaxSuppression(results);
}