【问题标题】:How to use Yolo V5 in C# with a GPU?如何在带有 GPU 的 C# 中使用 Yolo V5?
【发布时间】: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,显然不可能用它来快速处理很多图像。

【问题讨论】:

    标签: c# .net gpu yolo yolov5


    【解决方案1】:

    你可以试试这个: 使用 var image = Image.FromFile(path); var options = SessionOptions.MakeSessionOptionWithCudaProvider(0); 使用 var scorer = new YoloScorer("Assets/Weights/yolov5n.onnx", options); 确保您安装了 CUDA 工具包和 cudnn。 这段代码可能有效与否,我不确定,但你可以试试这个,这就是我能提供的全部帮助

    【讨论】:

      猜你喜欢
      • 2022-08-20
      • 1970-01-01
      • 2020-04-27
      • 2021-12-02
      • 2022-10-04
      • 2021-01-03
      • 1970-01-01
      • 2022-10-02
      • 1970-01-01
      相关资源
      最近更新 更多