IVilson.AI.Yolov7net 1.0.10

dotnet add package IVilson.AI.Yolov7net --version 1.0.10
                    
NuGet\Install-Package IVilson.AI.Yolov7net -Version 1.0.10
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IVilson.AI.Yolov7net" Version="1.0.10" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IVilson.AI.Yolov7net" Version="1.0.10" />
                    
Directory.Packages.props
<PackageReference Include="IVilson.AI.Yolov7net" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IVilson.AI.Yolov7net --version 1.0.10
                    
#r "nuget: IVilson.AI.Yolov7net, 1.0.10"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=IVilson.AI.Yolov7net&version=1.0.10
                    
Install IVilson.AI.Yolov7net as a Cake Addin
#tool nuget:?package=IVilson.AI.Yolov7net&version=1.0.10
                    
Install IVilson.AI.Yolov7net as a Cake Tool

2024.6.21

Fixed the bug where YOLOv10 inference results only contained one prediction. 修正了 yolov10 推理结果只有一个的bug.

2024.6.12

修正了了使用 skiasharp 预测框不准的问题。

移除system.drawing 的支持

主分支已使用 skiasharp.

具体使用方法参考 demo 工程的 Program.cs

最新的性能测试 Performance

work on i13900k + 64Gb Ram + RTX4090

alternate text is missing from this package README image

2024.6.9

  1. add yolov10 support. Yolov10
// init Yolov8 with onnx (include nms results)file path
using var yolo = new Yolov10("./assets/yolov10n.onnx", true);
// setup labels of onnx model 
yolo.SetupYoloDefaultLabels();   // use custom trained model should use your labels like: yolo.SetupLabels(string[] labels)
using var image = SKBitmap.Decode("Assets/" + fileName);
var predictions = yolo.Predict(image);  // now you can use numsharp to parse output data like this : var ret = yolo.Predict(image,useNumpy:true);
// draw box
using var canvas = new SKCanvas(image);
var paintRect = new SKPaint
{
    Style = SKPaintStyle.Stroke,
    StrokeWidth = 1,
    IsAntialias = true
};

var paintText = new SKPaint
{
    TextSize = 16,
    IsAntialias = true,
    Typeface = SKTypeface.FromFamilyName("Consolas")
};

foreach (var prediction in predictions) // 迭代预测结果并绘制
{
    double score = Math.Round(prediction.Score, 2);
    paintRect.Color = prediction.Label.Color;
    paintText.Color = prediction.Label.Color;

    // 绘制矩形
    canvas.DrawRect(prediction.Rectangle, paintRect);

    // 绘制文本
    var x = prediction.Rectangle.X - 3;
    var y = prediction.Rectangle.Y - 23;
    canvas.DrawText($"{prediction.Label.Name} ({score})", x, y, paintText);
}

yolov10 和 yolov7 保持兼容,包含了NMS 操作,感觉性能上比不上yolov9

2024.5.3 new branch released.

  1. Considering cross-platform compatibility, such as supporting mobile development, I have removed numpy support in this new branch to reduce the size of the program package.
  2. Remove System.Drawing and replace it with SkiaSharp.

HISTORY

2024.4.7 this project upgrade to net8.0

Repository Update Notice As part of our ongoing efforts to improve our project structure and workflow, we have made the following changes to the branches of this repository:

The master branch has been renamed to net6.0. This change reflects our progression and the versioning aligned with the new features and improvements. The net8.0 branch has been renamed to master. This is now the main branch where the latest stable releases and active developments will happen.

Yolov7net Now support yolov9,yolov8,yolov7,yolov5.

.net 6 yolov5, yolov7, yolov8 onnx runtime interface, work for:

  1. yolov9 https://github.com/WongKinYiu/yolov9
  2. yolov8 https://github.com/ultralytics/ultralytics
  3. yolov7 https://github.com/WongKinYiu/yolov7
  4. yolov5 https://github.com/ultralytics/yolov5

Usage:

install-package IVilson.AI.Yolov7net

alternate text is missing from this package README image

yolov9 和 yolov8 的 onnx 输出参数相同,都是 (1,84,8400)

如果有问题请前往 issus 进行提问,我会尽量解答

Yolov9

// init Yolov8 with onnx (include nms results)file path
using var yolo = new Yolov8("./assets/yolov9-c.onnx", true);
// setup labels of onnx model 
yolo.SetupYoloDefaultLabels();   // use custom trained model should use your labels like: yolo.SetupLabels(string[] labels)
using var image = Image.FromFile("Assets/demo.jpg");
var predictions = yolo.Predict(image);  // now you can use numsharp to parse output data like this : var ret = yolo.Predict(image,useNumpy:true);
// draw box
using var graphics = Graphics.FromImage(image);
foreach (var prediction in predictions) // iterate predictions to draw results
{
    double score = Math.Round(prediction.Score, 2);
    graphics.DrawRectangles(new Pen(prediction.Label.Color, 1),new[] { prediction.Rectangle });
    var (x, y) = (prediction.Rectangle.X - 3, prediction.Rectangle.Y - 23);
    graphics.DrawString($"{prediction.Label.Name} ({score})",
                    new Font("Consolas", 16, GraphicsUnit.Pixel), new SolidBrush(prediction.Label.Color),
                    new PointF(x, y));
}

Yolov8

// init Yolov8 with onnx (include nms results)file path
using var yolo = new Yolov8("./assets/yolov8n.onnx", true);
// setup labels of onnx model 
yolo.SetupYoloDefaultLabels();   // use custom trained model should use your labels like: yolo.SetupLabels(string[] labels)
using var image = Image.FromFile("Assets/demo.jpg");
var predictions = yolo.Predict(image);  // now you can use numsharp to parse output data like this : var ret = yolo.Predict(image,useNumpy:true);
// draw box
using var graphics = Graphics.FromImage(image);
foreach (var prediction in predictions) // iterate predictions to draw results
{
    double score = Math.Round(prediction.Score, 2);
    graphics.DrawRectangles(new Pen(prediction.Label.Color, 1),new[] { prediction.Rectangle });
    var (x, y) = (prediction.Rectangle.X - 3, prediction.Rectangle.Y - 23);
    graphics.DrawString($"{prediction.Label.Name} ({score})",
                    new Font("Consolas", 16, GraphicsUnit.Pixel), new SolidBrush(prediction.Label.Color),
                    new PointF(x, y));
}

yolov7 可以直接导出包含nms操作结果的onnx, 使用方法略有不同,需要使用 Yolov7 这个类

// init Yolov7 with onnx (include nms results)file path
using var yolo = new Yolov7("./assets/yolov7-tiny_640x640.onnx", true);
// setup labels of onnx model 
yolo.SetupYoloDefaultLabels();   // use custom trained model should use your labels like: yolo.SetupLabels(string[] labels)
using var image = Image.FromFile("Assets/demo.jpg");
var predictions = yolo.Predict(image);

// draw box
using var graphics = Graphics.FromImage(image);
foreach (var prediction in predictions) // iterate predictions to draw results
{
    double score = Math.Round(prediction.Score, 2);
    graphics.DrawRectangles(new Pen(prediction.Label.Color, 1),new[] { prediction.Rectangle });
    var (x, y) = (prediction.Rectangle.X - 3, prediction.Rectangle.Y - 23);
    graphics.DrawString($"{prediction.Label.Name} ({score})",
                    new Font("Consolas", 16, GraphicsUnit.Pixel), new SolidBrush(prediction.Label.Color),
                    new PointF(x, y));
}

对于未包括nms 结果的模型,需要用到 yolov5 这个类

// init Yolov5 with onnx file path
using var yolo = new Yolov5("./assets/yolov7-tiny_640x640.onnx", true);
// setup labels of onnx model 
yolo.SetupYoloDefaultLabels();   // use custom trained model should use your labels like: yolo.SetupLabels(string[] labels)
using var image = Image.FromFile("Assets/demo.jpg");
var predictions = yolo.Predict(image);

// draw box
using var graphics = Graphics.FromImage(image);
foreach (var prediction in predictions) // iterate predictions to draw results
{
    double score = Math.Round(prediction.Score, 2);
    graphics.DrawRectangles(new Pen(prediction.Label.Color, 1),new[] { prediction.Rectangle });
    var (x, y) = (prediction.Rectangle.X - 3, prediction.Rectangle.Y - 23);
    graphics.DrawString($"{prediction.Label.Name} ({score})",
                    new Font("Consolas", 16, GraphicsUnit.Pixel), new SolidBrush(prediction.Label.Color),
                    new PointF(x, y));
}


alternate text is missing from this package README image

References & Acknowledgements

https://github.com/THU-MIG/yolov10

https://github.com/WongKinYiu/yolov9

https://github.com/ultralytics/ultralytics

https://github.com/WongKinYiu/yolov7

https://github.com/ultralytics/yolov5

https://github.com/mentalstack/yolov5-net

https://github.com/ibaiGorordo/ONNX-YOLOv7-Object-Detection

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on IVilson.AI.Yolov7net:

Package Downloads
IVilson.Gis.Utils

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.10 499 6/20/2024
1.0.8 155 6/12/2024 1.0.8 is deprecated because it has critical bugs.
1.0.4 220 4/12/2024 1.0.4 is deprecated because it is no longer maintained.
1.0.3 767 2/8/2023
1.0.2 980 8/1/2022
1.0.1 324 8/1/2022