Created
October 28, 2020 20:33
-
-
Save elbruno/82c1ea2f843cb42a64276b7c4f30239a to your computer and use it in GitHub Desktop.
lobeonnxcsharpsample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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