Skip to content

Instantly share code, notes, and snippets.

@elbruno
Created October 28, 2020 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbruno/82c1ea2f843cb42a64276b7c4f30239a to your computer and use it in GitHub Desktop.
Save elbruno/82c1ea2f843cb42a64276b7c4f30239a to your computer and use it in GitHub Desktop.
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