Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/techwingslab/yolov5-net
YOLOv5 object detection with C#, ML.NET, ONNX
https://github.com/techwingslab/yolov5-net
c-sharp dotnet dotnet-core machine-learning ml-net object-detection onnx yolo yolov5
Last synced: 1 day ago
JSON representation
YOLOv5 object detection with C#, ML.NET, ONNX
- Host: GitHub
- URL: https://github.com/techwingslab/yolov5-net
- Owner: techwingslab
- License: mit
- Created: 2021-03-20T09:56:12.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-10T18:23:12.000Z (over 1 year ago)
- Last Synced: 2025-01-22T22:47:07.743Z (2 days ago)
- Topics: c-sharp, dotnet, dotnet-core, machine-learning, ml-net, object-detection, onnx, yolo, yolov5
- Language: C#
- Homepage:
- Size: 149 MB
- Stars: 362
- Watchers: 13
- Forks: 105
- Open Issues: 34
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-yolo-object-detection - techwingslab/yolov5-net - net?style=social"/> : YOLOv5 object detection with C#, ML.NET, ONNX. (Other Versions of YOLO)
- awesome-yolo-object-detection - techwingslab/yolov5-net - net?style=social"/> : YOLOv5 object detection with C#, ML.NET, ONNX. (Other Versions of YOLO)
README
# Yolov5Net
YOLOv5 object detection with ML.NET, ONNX![example](https://raw.githubusercontent.com/techwingslab/yolov5-net/master/img/result.jpg)
## Installation
Run this line from Package Manager Console:
```
Install-Package Yolov5Net -Version 1.1.0
```For CPU usage run this line from Package Manager Console:
```
Install-Package Microsoft.ML.OnnxRuntime -Version 1.14.1
```For GPU usage run this line from Package Manager Console:
```
Install-Package Microsoft.ML.OnnxRuntime.Gpu -Version 1.14.1
```CPU and GPU packages can't be installed together.
## Usage
Yolov5Net contains two COCO pre-defined models: YoloCocoP5Model, YoloCocoP6Model.
If you have custom trained model, then inherit from YoloModel and override all the required properties and methods. See YoloCocoP5Model or YoloCocoP6Model implementation to get know how to wrap your own model.
```cs
using var image = await Image.LoadAsync("Assets/test.jpg");
{
using var scorer = new YoloScorer("Assets/Weights/yolov5n.onnx");
{
var predictions = scorer.Predict(image);var font = new Font(new FontCollection().Add("C:/Windows/Fonts/consola.ttf"), 16);
foreach (var prediction in predictions) // draw predictions
{
var score = Math.Round(prediction.Score, 2);var (x, y) = (prediction.Rectangle.Left - 3, prediction.Rectangle.Top - 23);
image.Mutate(a => a.DrawPolygon(new Pen(prediction.Label.Color, 1),
new PointF(prediction.Rectangle.Left, prediction.Rectangle.Top),
new PointF(prediction.Rectangle.Right, prediction.Rectangle.Top),
new PointF(prediction.Rectangle.Right, prediction.Rectangle.Bottom),
new PointF(prediction.Rectangle.Left, prediction.Rectangle.Bottom)
));image.Mutate(a => a.DrawText($"{prediction.Label.Name} ({score})",
font, prediction.Label.Color, new PointF(x, y)));
}await image.SaveAsync("Assets/result.jpg");
}
}
```