Skip to content

Commit

Permalink
Update PaddleDetector.cs
Browse files Browse the repository at this point in the history
防止当识别到的ClassID大于模型中预设的种类时,导致Config.LabelList 索引溢出的问题
  • Loading branch information
LuGuangguang authored Apr 29, 2024
1 parent 46328a7 commit b1ac945
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Sdcb.PaddleDetection/PaddleDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ public DetectionResult[] Run(Mat src)
if (isRbox)
{
int classId = (int)MathUtil.Round(outputData[0 + j * 10]);
if (classId > Config.LabelList.Length - 1)
{
continue;
}
float score = outputData[1 + j * 10];
int x1 = (int)(outputData[2 + j * 10] * r.Width);
int y1 = (int)(outputData[3 + j * 10] * r.Height);
Expand All @@ -186,6 +190,10 @@ public DetectionResult[] Run(Mat src)
else
{
int classId = (int)MathUtil.Round(outputData[0 + j * 6]);
if (classId > Config.LabelList.Length - 1)
{
continue;
}
float score = outputData[1 + j * 6];
int xmin = (int)(outputData[2 + j * 6] * r.Width);
int ymin = (int)(outputData[3 + j * 6] * r.Height);
Expand All @@ -194,6 +202,7 @@ public DetectionResult[] Run(Mat src)
result[j] = new DetectionResult(new[] { xmin, ymin, xmax, ymax }, classId, Config.LabelList[classId], score);
}
}
result = result.Where(r => r != null).ToArray();
return result;
}
}
Expand Down Expand Up @@ -406,4 +415,4 @@ static IEnumerable<Scalar> GenerateColorMapToScalar()
}
}
}
}
}

0 comments on commit b1ac945

Please sign in to comment.