TensorFlow Lite using Go API in 7 steps
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:
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.
- Model creation
- Set Interpreter options
- Create Interpreter
- Allocate Tensors
- Input Tensor/s
- Interpreter Invoke
- 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
I invite you to try this idea:
go get github.com/nbortolotti/tflitego
All the information included into: