GithubHelp home page GithubHelp logo

lobe.net's Introduction

.NET libraries for Lobe

A .NET library to run inference on exported Lobe models.

How to get started

Export the model from Lobe app

  • Export your model as ONNX format

Use the model in your own .NET application

Install the follwing packages

  • lobe.Onnx to import the Onnx based implementation of the image classifier.
  • lobe.ImageSharp to get image manipulation utilities
  • Microsoft.ML.OnnxRuntime to get he native onnx runtimes

This code creates a simple command line app that loads a model and classifies an image file

using System;
using System.IO;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using lobe.ImageSharp;

namespace lobe.TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var signatureFilePath = args[0];
            var imageToClassify = args[1];

            ImageClassifier.Register("onnx", () => new OnnxImageClassifier());
            using var classifier = ImageClassifier.CreateFromSignatureFile(
                new FileInfo(signatureFilePath));

            var results = classifier.Classify(Image
                .Load(imageToClassify).CloneAs<Rgb24>());
            Console.WriteLine(results.Classification.Label);
        }
    }
}

The code

ImageClassifier.Register("onnx", () => new OnnxImageClassifier());

Registers the OnnxImageClassifier against the format onnx

Then a classifier can be built from a signature file

using var classifier = ImageClassifier.CreateFromSignatureFile(new FileInfo(signatureFilePath));

Use the lobe app directly

For rapid iterations you can test your model by taking advantage of the http endpoint that the lobe app exposes. First, open the app and then the model you would like to use. Next, go to the export menu and select the api option, get the url from there (it should look like http://localhost:38100/predict/bdff75cc-ee54-46cf-a290-f9095ef78516").

In your .NET App make sure you have installed the following nuget packages

  • lobe.Http
  • lobe.ImageSharp

Then import the namespaces

using System.IO;
using SixLabors.ImageSharp;

using lobe.Http;

And finally create the client, connect to the endpoint and now use it classify the image

var client = new LobeClient();
client.UseUri(new Uri("http://localhost:38100/predict/bdff75cc-ee54-46cf-a290-f9095ef78516"));

var result = client.Classify(picture.CloneAs<Rgb24>());

lobe.net's People

Contributors

colombod avatar dmilkie avatar mbeissinger avatar tymtam2 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.