From 5975f83179e484d1dae107d9d835a3712702b87e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Sw=C3=A4rd=20=F0=9F=87=B8=F0=9F=87=AA?= <35733515+NickSwardh@users.noreply.github.com> Date: Fri, 1 Nov 2024 22:58:36 +0100 Subject: [PATCH 1/2] Update README.md --- README.md | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 12fb7ac..589d8ab 100644 --- a/README.md +++ b/README.md @@ -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; @@ -102,7 +102,41 @@ 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 +// 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 @@ -337,4 +371,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 | \ No newline at end of file +| SegmentationYolov11Gpu | 28.97 ms | 0.293 ms | 0.274 ms | 406.2500 | 375.0000 | 125.0000 | 6.72 MB | yolov11s-seg | From c5826efb9848f5d924b9564319ea0c278e610a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Sw=C3=A4rd=20=F0=9F=87=B8=F0=9F=87=AA?= <35733515+NickSwardh@users.noreply.github.com> Date: Fri, 1 Nov 2024 23:00:47 +0100 Subject: [PATCH 2/2] Update README.md --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 589d8ab..93308a4 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,15 @@ resultImage.Save(@"save\as\new_image.jpg", SKEncodedImageFormat.Jpeg, 80); # 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() {