Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
lobeonnxcsharpsample.cs
using System;
using System.IO;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using lobe.ImageSharp;
using lobe;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var signatureFilePath = "signature.json";
ImageClassifier.Register("onnx", () => new OnnxImageClassifier());
using var classifier = ImageClassifier.CreateFromSignatureFile(
new FileInfo(signatureFilePath));
// Images
ShowResults("fishy.png", classifier);
ShowResults("human.png", classifier);
}
private static void ShowResults(string imagePath, ImageClassifier classifier)
{
var results = classifier.Classify(Image
.Load(imagePath).CloneAs<Rgb24>());
Console.WriteLine();
Console.WriteLine($"Image : {imagePath}");
Console.WriteLine($"Top Label: {results.Classification.Label}");
foreach (var res in results.Classifications)
{
Console.WriteLine($" - Label: {res.Label} - Confidence: {res.Confidence}");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment