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/
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);
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.
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
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
- Link to Custom Vision Service Documentation
- Link to Custom Vision with Android
- Link to TensorFlow documentation
- Link to TensorFlowSharp
- Link to TensorFlow example code using Python
- Link to TensorFlow example code using C++
- Link to TensorFlow example code using Java