Custom Vision with TensorFlow exported model using C# .NET Core and TensorFlowSharp
In a previous post, I built an image classification model for mushrooms using CustomVision.ai. In this post I want to take that a stage further and create a TensorFlow model that I can use on different operating systems and crucially, offline with no internet connection and using my favourite language, C#.
There are already some mobile CustomVision.ai samples on Github:
So what about other platforms?
Well, it turns out that our very own Elon Musk, Miguel de Icaza has been busy working on a TensorFlowSharp library which are NET bindings to the TensorFlow library published here: https://github.com/tensorflow/tensorflow
This library makes it easy to use an exported TensorFlow model from CustomVision.ai in your own cross platform .NET applications. So, I've built a sample .NET Core CLI that takes a TensorFlow exported model and uses TensorFlowSharp to perform offline image classification. To get started, head over to the CustomVision.ai portal. Make sure you have one of the Compact Domains selected, as these are the only ones that you can export. If you change your Domain, you'll need to retrain the model. Once you've done this, the option to Export the model in the TensorFlow format will become available. Download the zip file containing both the model.pb and model.txt file.
If you need help on this, follow the docs: /en-us/azure/cognitive-services/custom-vision-service/export-your-model
In the .NET Core CLI application sample, simply replace your model.pb and model.txt file within the \Assets folder and change the image to your own. Depending on your Domain you may need to change the RGB values as described in the Readme.md
Full code with mushroom classification exported TensorFlow model here: https://github.com/daltskin/CustomVision-TensorFlow-CSharp