TensorFlow Lite using Go API in 7 steps

Nicolas Bortolotti
2 min readJan 4, 2021

--

TensorFlow Lite is an open source deep learning framework for on-device inference. Current API supports officially python, java and C++.

The main question here is, what happen if we would like to use Go & TensorFlow Lite?

The objective of this article is provide the opportunity to use Go into the powerful world of on-device inference and also provide an smooth utilization experience.

There are some initiatives working on that but without a clear core design, maintenance environment and dependencies.

For the initial proposal I decided to use TensorFlow Lite C library and for the binding I’m using cgo (cgo enables the creation of Go packages that call C code) to implement the solution.

I created the initial version of the library tflitego. *always welcome contributors, go experts & on-device inference experts, etc.

Here the initial version design:

generic abstraction of design

I also created an initial examples project with the proposal, the objective here is to use Iris TensorFlow lite model and see tflitego in action. Basically we need 7 steps to execute a simple inference.

animation with tflitego in action
  1. Model creation
  2. Set Interpreter options
  3. Create Interpreter
  4. Allocate Tensors
  5. Input Tensor/s
  6. Interpreter Invoke
  7. Outputs/Results

Regarding the deployment environment, I created a representation in GitHub actions to test the simplicity of use tflitego. (linux/X86_64, 2.4.0, Ubuntu 18.04 ). *TensorFlow 2.4.0. The key is a package to deploy correctly TensorFlow C Library. example here

I also represented a simple deployment method to use in raspberry pi, for now tested in v3. Raspberrypi_linux/ARMv7, 2.4.0 *TensorFlow 2.4.0

wget https://storage.googleapis.com/clitelibrary/ctflitelib_2.4.0_ARMv7.tar.gz
sudo tar -C /usr/local -xzf ctflitelib_2.4.0_ARMv7.tar.gz
pretty straightforward methodology

I invite you to try this idea:

go get github.com/nbortolotti/tflitego

All the information included into:

--

--

Nicolas Bortolotti
Nicolas Bortolotti

Written by Nicolas Bortolotti

Technical Program Manager at Google and Engineering Researcher

No responses yet