Tensorflow Lite commonly known as TFLite is used to generate and infer machine learning models on mobile and IoT(Edge) devices. TFLite made the on-device(offline) inference easier for multiple device architectures, such as Android, iOS, Raspberry pi and even backend servers. With TFLite you can build a lightweight server based inference application using any programming language with lightweight models, rather than using heavy Tensorflow models.

As developers, we can simply use existing optimized research models or convert existing Tensorflow models to TFLite. There are multiple ways of using TFLite in your mobile, IoT or server applications.

  • Implement the inference for different architecture(Android, iOS etc…) using the standard libraries, SDKs provided by TFLite.
  • Use the TFLite C API for inference along with platform independent programming language like Golang. And cross-compile for platforms like Android, iOS etc…

In this post I’m going to show case the implementation of TFLite inference application using platform independent language Golang and **cross-compiling **to a shared library. Which then can be consumed by Android, iOS etc…

First thanks to mattn who created the TFLite Go bindings and you can find the repo here. We will start the implementation of a simple Golang application for TFLite inference(You can find the example here). Here I’m using a simple text classifier which will classify to ‘Positive’ or ‘Negative’.

Here is the classifier.go, which has Go functions and are exported for use by C code.

#tensorflow #tflite #ios #golang #go

Tensorflow Lite (TFLite) with Golang (Go)
20.10 GEEK