Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/NickSwardh/YoloDotNet
Browse files Browse the repository at this point in the history
  • Loading branch information
NickSwardh committed Dec 7, 2024
2 parents 82b2770 + c5826ef commit 6b2e93c
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ using var yolo = new Yolo(@"path\to\model.onnx");
Console.WriteLine(yolo.OnnxModel.ModelType); // Output modeltype...
```

# Example - Image inference
# Example 1 - Image inference

```csharp
using YoloDotNet;
Expand Down Expand Up @@ -102,7 +102,50 @@ using var resultImage = image.Draw(results);
resultImage.Save(@"save\as\new_image.jpg", SKEncodedImageFormat.Jpeg, 80);
```

# Example - Video inference
# Example 2 - Inference on a batch of images
```csharp
using System;
using System.IO;
using SkiaSharp;
using YoloDotNet;
using YoloDotNet.Enums;
using YoloDotNet.Models;
using YoloDotNet.Extensions;
using System.Threading.Tasks;

// Instantiate a new yolo-object
using var yolo = new Yolo(new YoloOptions()
{
OnnxModel = @"path\to\model.onnx",
Cuda = true,
PrimeGpu = true,
ModelType = ModelType.ObjectDetection
});

// Collect images
var images = Directory.GetFiles(@"path\to\image\folder");

// Process images using parallelism for faster processing
Parallel.ForEach(images, image =>
{
// Load image
using var img = SKImage.FromEncodedData(image);

// Run inference
var results = yolo.RunObjectDetection(img, 0.25, 0.5);

// Draw results
using var resultImg = img.Draw(results);

// Save results
resultImg.Save(Path.Combine(@"path\to\save\folder", Path.GetFileName(image)));

// Do further processing if needed...
});
```

# Example 3 - Video inference

> [!IMPORTANT]
> Processing video requires FFmpeg and FFProbe
Expand Down Expand Up @@ -337,4 +380,4 @@ DefaultJob : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
| SegmentationYolov8Cpu | 56.79 ms | 1.121 ms | 1.246 ms | 444.4444 | 333.3333 | 111.1111 | 7.31 MB | yolov8s-seg |
| SegmentationYolov8Gpu | 31.50 ms | 0.630 ms | 1.198 ms | 468.7500 | 437.5000 | 156.2500 | 7.28 MB | yolov8s-seg |
| SegmentationYolov11Cpu | 96.84 ms | 1.848 ms | 2.270 ms | 333.3333 | 166.6667 | - | 6.8 MB | yolov11s-seg |
| SegmentationYolov11Gpu | 28.97 ms | 0.293 ms | 0.274 ms | 406.2500 | 375.0000 | 125.0000 | 6.72 MB | yolov11s-seg |
| SegmentationYolov11Gpu | 28.97 ms | 0.293 ms | 0.274 ms | 406.2500 | 375.0000 | 125.0000 | 6.72 MB | yolov11s-seg |

0 comments on commit 6b2e93c

Please sign in to comment.