【发布时间】:2022-07-29 14:00:43
【问题描述】:
我在最后几天试图让 Yolo 在我的 GPU 上工作。我尝试使用https://github.yuuza.net/mentalstack/yolov5-net,我按照他们的指南使用 GPU,但它没有用。所有其他 C# Yolo 包装器都没有使用 Yolov5 版本,我想使用这个。所以我的问题是,我如何在我的 GPU 上使用 C# (.net 5.0) 中的 YoloV5。这是我与 yolov5-net 一起使用的代码:
using var image = Image.FromFile(path);
using var scorer = new YoloScorer<YoloCocoP5Model>("tinyyolov2-8.onnx");
List<YoloPrediction> predictions = scorer.Predict(image);
using var graphics = Graphics.FromImage(image);
foreach (var prediction in predictions)
{
double score = Math.Round(prediction.Score, 2);
graphics.DrawRectangles(new Pen(prediction.Label.Color, 8),
new[] { prediction.Rectangle });
var (x, y) = (prediction.Rectangle.X - 3, prediction.Rectangle.Y - 23);
graphics.DrawString($"{prediction.Label.Name} ({score})",
new Font("Arial", 40, GraphicsUnit.Pixel), new SolidBrush(prediction.Label.Color),
new PointF(x, y));
}
Console.WriteLine(outputPath);
image.Save(outputPath);
上面的代码有效,但是它吃掉了我的 CPU,显然不可能用它来快速处理很多图像。
【问题讨论】: