YoloDotNet 2.2.0

dotnet add package YoloDotNet --version 2.2.0                
NuGet\Install-Package YoloDotNet -Version 2.2.0                
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="YoloDotNet" Version="2.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add YoloDotNet --version 2.2.0                
#r "nuget: YoloDotNet, 2.2.0"                
#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.
// Install YoloDotNet as a Cake Addin
#addin nuget:?package=YoloDotNet&version=2.2.0

// Install YoloDotNet as a Cake Tool
#tool nuget:?package=YoloDotNet&version=2.2.0                

YoloDotNet v2.2

YoloDotNet is a blazing-fast C# .NET 8 implementation of Yolo and Yolo-World models for real-time object detection in images and videos. Powered by ONNX Runtime, and supercharged with GPU acceleration using CUDA, this app is all about detecting objects at lightning speed!

Supported Versions:

Yolov8 Yolov9 Yolov10 Yolov11 Yolo-World

Supported Tasks:

  ✓   Classification   Categorize an image
  ✓   Object Detection   Detect multiple objects in a single image
  ✓   OBB Detection   OBB (Oriented Bounding Box)
  ✓   Segmentation   Separate detected objects using pixel masks
  ✓   Pose Estimation   Identifying location of specific keypoints in an image

Batteries not included.

What's new in YoloDotNet v2.2?

Things are moving fast, YoloDotNet 2.2 is already here packed with exciting new features! Ever wanted to experiment with Yolo-World models in .NET? Now's your chance. With Open-Vocabulary detection and real-time, zero-shot object detection, the model can now find objects it hasn't even been trained on. It's a whole new level of object detection fun!

Yolo-World Support: Yep, you read that right – Open-Vocabulary detection is now in the mix! Real-time, zero-shot object detection is here, so the model can spot stuff it’s never been trained on. Mind-blowing, right? More about Yolo-World here.
Pixel Confidence for Segmentation: Need more control? An optional pixel confidence parameter has been added for segmentation. Now it's possible to fine-tune those segmentation masks like a pro 😉

Nuget

> dotnet add package YoloDotNet

Install CUDA (optional)

YoloDotNet with GPU-acceleration requires CUDA Toolkit 12.x and cuDNN 9.x.

ONNX runtime's current compatibility with specific versions.

  1. Open File Explorer and navigate to the folder where the cuDNN-dll's are installed. The typical path looks like:
    C:\Program Files\NVIDIA\CUDNN\v9.x\bin\v12.x (where x is your version)

  2. Once you are in this specific folder (which contains .dll files), copy the folder path from the address bar at the top of the window.

  3. Add the cuDNN-Path to your System Variables:

    • Type env in windows search
    • Click on Edit the system environment variables
    • Click on Environment Variables
    • Under System Variables select the Path-variable and click Edit
    • Click on New and paste in your cuDNN dll-folder path
    • Click Ok a million times to save the changes
  4. Super-duper-important! In order for Windows to pick up the changes in your Environment Variables, make sure to close all open programs before you continue with whatever you were doing 😉

Export Yolo models to ONNX

All models must be exported to ONNX format. How to export to ONNX format.
The ONNX-models included in this repo are from Ultralytics s-series (small). https://docs.ultralytics.com/models.

Verify your model

using YoloDotNet;

// Instantiate a new Yolo object with your ONNX-model
using var yolo = new Yolo(@"path\to\model.onnx");

Console.WriteLine(yolo.OnnxModel.ModelType); // Output modeltype...

Example - Image inference

using YoloDotNet;
using YoloDotNet.Enums;
using YoloDotNet.Models;
using YoloDotNet.Extensions;
using SkiaSharp;

// Instantiate a new Yolo object
using var yolo = new Yolo(new YoloOptions
{
    OnnxModel = @"path\to\model.onnx",      // Your Yolo model in onnx format
    ModelType = ModelType.ObjectDetection,  // Set your model type
    Cuda = false,                           // Use CPU or CUDA for GPU accelerated inference. Default = true
    GpuId = 0                               // Select Gpu by id. Default = 0
    PrimeGpu = false,                       // Pre-allocate GPU before first inference. Default = false
});

// Load image
using var image = SKImage.FromEncodedData(@"path\to\image.jpg");

// Run inference and get the results
var results = yolo.RunObjectDetection(image, confidence: 0.25, iou: 0.7);

// Draw results
using var resultImage = image.Draw(results);

// Save to file
resultImage.Save(@"save\as\new_image.jpg", SKEncodedImageFormat.Jpeg, 80);

Example - Video inference

[!IMPORTANT] Processing video requires FFmpeg and FFProbe

  • Download FFMPEG
  • Add FFmpeg and ffprobe to the Path-variable in your Environment Variables
using YoloDotNet;
using YoloDotNet.Enums;
using YoloDotNet.Models;

// Instantiate a new Yolo object
using var yolo = new Yolo(new YoloOptions
{
    OnnxModel = @"path\to\model.onnx",      // Your Yolov8 or Yolov10 model in onnx format
    ModelType = ModelType.ObjectDetection,  // Set your model type
    Cuda = false,                           // Use CPU or CUDA for GPU accelerated inference. Default = true
    GpuId = 0                               // Select Gpu by id. Default = 0
    PrimeGpu = false,                       // Pre-allocate GPU before first. Default = false
});

// Set video options
var options = new VideoOptions
{
    VideoFile = @"path\to\video.mp4",
    OutputDir = @"path\to\output\dir",
    //GenerateVideo = true,
    //DrawLabels = true,
    //FPS = 30,
    //Width = 640,  // Resize video...
    //Height = -2,  // -2 automatically calculate dimensions to keep proportions
    //Quality = 28,
    //DrawConfidence = true,
    //KeepAudio = true,
    //KeepFrames = false,
    //DrawSegment = DrawSegment.Default,
    //PoseOptions = MyPoseMarkerConfiguration // Your own pose marker configuration...
};

// Run inference on video
var results = yolo.RunObjectDetection(options, 0.25, 0.7);

// Do further processing with 'results'...

Custom KeyPoint configuration for Pose Estimation

Example on how to configure Keypoints for a Pose Estimation model

// Pass in a KeyPoint options parameter to the Draw() extension method. Ex:
image.Draw(poseEstimationResults, poseOptions);

Access ONNX metadata and labels

The internal ONNX metadata such as input & output parameters, version, author, description, date along with the labels can be accessed via the yolo.OnnxModel property.

Example:

using var yolo = new Yolo(@"path\to\model.onnx");

// ONNX metadata and labels resides inside yolo.OnnxModel
Console.WriteLine(yolo.OnnxModel);

Example:

// Instantiate a new object
using var yolo = new Yolo(@"path\to\model.onnx");

// Display metadata
foreach (var property in yolo.OnnxModel.GetType().GetProperties())
{
    var value = property.GetValue(yolo.OnnxModel);
    Console.WriteLine($"{property.Name,-20}{value!}");

    if (property.Name == nameof(yolo.OnnxModel.CustomMetaData))
        foreach (var data in (Dictionary<string, string>)value!)
            Console.WriteLine($"{"",-20}{data.Key,-20}{data.Value}");
}

// Get ONNX labels
var labels = yolo.OnnxModel.Labels;

Console.WriteLine();
Console.WriteLine($"Labels ({labels.Length}):");
Console.WriteLine(new string('-', 58));

// Display
for (var i = 0; i < labels.Length; i++)
    Console.WriteLine($"index: {i,-8} label: {labels[i].Name,20} color: {labels[i].Color}");

// Output:

// ModelType           ObjectDetection
// InputName           images
// OutputName          output0
// CustomMetaData      System.Collections.Generic.Dictionary`2[System.String,System.String]
//                     date                2023-11-07T13:33:33.565196
//                     description         Ultralytics YOLOv8n model trained on coco.yaml
//                     author              Ultralytics
//                     task                detect
//                     license             AGPL-3.0 https://ultralytics.com/license
//                     version             8.0.202
//                     stride              32
//                     batch               1
//                     imgsz               [640, 640]
//                     names               {0: 'person', 1: 'bicycle', 2: 'car' ... }
// ImageSize           Size [ Width=640, Height=640 ]
// Input               Input { BatchSize = 1, Channels = 3, Width = 640, Height = 640 }
// Output              ObjectDetectionShape { BatchSize = 1, Elements = 84, Channels = 8400 }
// Labels              YoloDotNet.Models.LabelModel[]
//
// Labels (80):
// ---------------------------------------------------------
// index: 0        label: person              color: #5d8aa8
// index: 1        label: bicycle             color: #f0f8ff
// index: 2        label: car                 color: #e32636
// index: 3        label: motorcycle          color: #efdecd
// ...

https://paypal.me/nickswardh

References & Acknowledgements

https://github.com/ultralytics/ultralytics

https://github.com/sstainba/Yolov8.Net

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

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. 
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 YoloDotNet:

Package Downloads
VL.YoloDotNet

YoloDotNet for VL

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.0 3,078 10/13/2024
2.1.0 679 10/6/2024
2.0.0 1,764 7/12/2024
1.7.0 873 5/2/2024
1.6.0 471 4/4/2024
1.5.0 252 3/14/2024
1.4.0 602 3/6/2024
1.3.0 442 2/25/2024
1.2.0 215 2/5/2024
1.1.0 204 1/17/2024
1.0.0 302 12/8/2023

Things are moving fast, YoloDotNet 2.2 is already here packed with exciting new features! Ever wanted to experiment with Yolo-World models in .NET? Now's your chance. With Open-Vocabulary detection and real-time, zero-shot object detection, the model can now find objects it hasn't even been trained on. It's a whole new level of object detection fun!

In v2.2:

Yolo-World Support:
Yep, you read that right – Open-Vocabulary detection is now in the mix! Real-time, zero-shot object detection is here, so the model can spot  stuff it’s never been trained on. Mind-blowing, right?

Pixel Confidence for Segmentation:
Need more control? An optional pixel confidence parameter has been added for segmentation. Now it's possible to fine-tune those segmentation masks like a pro ;)