Skip to content
Microsoft Cognitive Services - TensorFlow CLI
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
CustomVision-TensorFlow.sln TensorFlow using C# Feb 7, 2018
CustomVision.cs TensorFlow using C# Feb 7, 2018
Program.cs TensorFlow using C# Feb 7, 2018 TensorFlow CLI - Offline image classification using C#

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

To learn more about Microsoft Cognitive Custom Vision Service, please see here:

Mean Values (RGB)

Depending on the 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


  • 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 is for mushroom classification

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


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

I tensorflow/core/platform/] 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


You can’t perform that action at this time.