Giter Site home page Giter Site logo

customvision-tensorflow-csharp's Introduction

CustomVision.ai TensorFlow CLI - Offline image classification using C#

Cross platform CLI to run a pre-trained model exported from CustomVision.ai in the Tensorflow format for image classification using the TensorFlowSharp library.

To learn more about Microsoft Cognitive Custom Vision Service, please see here: https://azure.microsoft.com/en-gb/services/cognitive-services/custom-vision-service/

Mean Values (RGB)

Depending on the CustomVision.ai model's Domain, you'll need to set the appropriate values within the code:

Project's Domain Mean Values (RGB)
General (Compact) (123, 117, 104)
Landmark (Compact) (123, 117, 104)
Retail (Compact) (0, 0, 0)

These are set in BGR eg:

// General (Compact) 
// Landmark (Compact)
var bgrValues = new TFTensor(new float[] { 104.0f, 117.0f, 123.0f });
// Retail (Compact)
var bgrValues = new TFTensor(0f);

CLI Arguments

Argument name shortcut example
TensorFlowModelFilePath -m Assets\model.pb
TensorFlowLabelsFilePath -l Assets\labels.txt
TestImageFilePath -t Assets\test.jpg

Usage

  • Open the solution
  • Restore Nuget Packages
  • Run & enjoy

In case you see the following error:

Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'libtensorflow': The specified module could not be found.

Copy the libtensorflow.dll file from the relevant %userprofile%.nuget\packages\tensorflowsharp runtimes folder of your OS into the same folder as the compiled executable.

Image classification

The sample TensorFlow model (exported from CustomVision.ai) is for mushroom classification

CustomVision-TensorFlow.exe -m Assets\model.pb -l Assets\labels.txt -t Assets\test.jpg

Output

Running the above from the command line will display the following:

I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
C:\Github\CustomVision-TensorFlow-CSharp\Assets\test.jpg = Agaricus bisporus (92.7477061748505%)
Total time: 00:00:00.4987094

Resources

customvision-tensorflow-csharp's People

Contributors

daltskin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

customvision-tensorflow-csharp's Issues

Object detection

This is not an issue, just an idea. How I should handle the object detection from the customvision.ai model? I define this input :
runner.AddInput(graph["Placeholder"][0], tensor).Fetch(graph["model_outputs"][0]);
but I have no idea on how to handle it.

Not working anymore

Have you tried with a new model exported lately?
When using a model exported last year, it works just fine. I tried today with a new model and it doesn't work anymore.
Any ideas?

I'm getting an exception:

Exception thrown: 'TensorFlow.TFException' in TensorFlowSharp.dll
An exception of type 'TensorFlow.TFException' occurred in TensorFlowSharp.dll but was not handled in user code
Input to reshape is a tensor with 97556 values, but the requested shape requires a multiple of 90944
	 [[Node: block0_0_reshape0 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](block0_0_concat, block0_0_reshape0/shape)]]

Great work

Hello :),

I found your great project, one the way of also loading a Python model for a University project
Maybe you are so kind that you could send it to me
Because at the moment I don't understand why you use the 'loss'
in the CustomVision.cs line 50

Thank you very much for your help in advance

Best Regards
Chris

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.