{"id":15663860,"url":"https://github.com/nbortolotti/tflitego","last_synced_at":"2025-05-06T18:46:59.716Z","repository":{"id":51090636,"uuid":"319110143","full_name":"nbortolotti/tflitego","owner":"nbortolotti","description":"tflitego provide a simple and clear solution to use TensorFlow lite in Go. Our objective is provide a cohesive  API, simplicity related to  TensorFlow Lite C API connection and maintainability.","archived":false,"fork":false,"pushed_at":"2021-05-24T12:28:34.000Z","size":3285,"stargazers_count":17,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-31T01:51:15.064Z","etag":null,"topics":["edge-computing","go","golang","interpreter","tensorflow","tensorflow-lite","tflite"],"latest_commit_sha":null,"homepage":"https://tflitego.nicolasbortolotti.com/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nbortolotti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-06T19:08:08.000Z","updated_at":"2024-02-02T00:50:44.000Z","dependencies_parsed_at":"2022-08-03T02:45:58.042Z","dependency_job_id":null,"html_url":"https://github.com/nbortolotti/tflitego","commit_stats":null,"previous_names":["nbortolotti/gotflite"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbortolotti%2Ftflitego","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbortolotti%2Ftflitego/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbortolotti%2Ftflitego/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbortolotti%2Ftflitego/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nbortolotti","download_url":"https://codeload.github.com/nbortolotti/tflitego/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252748552,"owners_count":21798340,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["edge-computing","go","golang","interpreter","tensorflow","tensorflow-lite","tflite"],"created_at":"2024-10-03T13:40:12.452Z","updated_at":"2025-05-06T18:46:59.694Z","avatar_url":"https://github.com/nbortolotti.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Go](https://github.com/nbortolotti/gotflite/workflows/Go/badge.svg?branch=main)\n[![Coverage Status](https://coveralls.io/repos/github/nbortolotti/tflitego/badge.svg?branch=main)](https://coveralls.io/github/nbortolotti/tflitego?branch=main)\n[![GoDoc](https://godoc.org/github.com/nbortolotti/tflitego?status.svg)](https://godoc.org/github.com/nbortolotti/tflitego)\n[![Gitter](https://badges.gitter.im/tflitego/community.svg)](https://gitter.im/tflitego/community?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n![Subreddit subscribers](https://img.shields.io/reddit/subreddit-subscribers/tflitego?style=social)\n\n\n# tflitego: TensorFlow Lite for Go\ntflitego provide a simple and clear solution to use TensorFlow lite in Go. Our objective is provide a cohesive API, simplicity related to TensorFlow Lite C API connection and maintainability.\n\n## Requeriments\nTensorFlow Lite C API. A native shared library target that contains the C API for inference has been provided. Assuming a working bazel configuration, this can be built as follows:\n\n```shell script\nbazel build -c opt //tensorflow/lite/c:tensorflowlite_c\n```\nmore details [here](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/c)\n\nAlternativally, if your prefer a simplification to use TensorFlow Lite C API, I prepared a a package here:\n* [linux/X86_64, 2.4.0](https://storage.googleapis.com/clitelibrary/ctflitelib_2.4.0.tar.gz). Tested ubuntu 18.04\n\n```shell script\nwget https://storage.googleapis.com/clitelibrary/ctflitelib_[version].tar.gz\nsudo tar -C /usr/local -xzf ctflitelib_[version].tar.gz\nsudo ldconfig\n```\nReplaces version for the available package. Example:\n\n```shell script\nwget https://storage.googleapis.com/clitelibrary/ctflitelib_2.4.0.tar.gz\n```\n* [raspberrypi_linux/ARMv7, 2.4.0](https://storage.googleapis.com/clitelibrary/ctflitelib_2.4.0_ARMv7.tar.gz)\n\n\n```shell script\nwget https://storage.googleapis.com/clitelibrary/ctflitelib_2.4.0_ARMv7.tar.gz\nsudo tar -C /usr/local -xzf ctflitelib_2.4.0_ARMv7.tar.gz\n```\n\n## Installation\n\n```shell script\ngo get github.com/nbortolotti/tflitego\n```\n\n## How to use\n\n1. Create the model, here using the method from file.\n\n```go\nmodel, err := tflite.NewTFLiteModelFromFile(\"iris_lite.tflite\")\ndefer model.Delete()\nif err != nil {\n    log.Fatal(\"cannot load model\", err)\n}\n```\n\n2. Set Interpreter options\n\n```go\noptions, err := tflite.NewInterpreterOptions()\ndefer options.Delete()\nif err != nil {\n    log.Fatal(\"cannot initialize interpreter options\", err)\n}\noptions.SetNumThread(4)\n```\n\n3. Create Interpreter\n\n```go\ninterpreter, err := tflite.NewInterpreter(model, options)\ndefer interpreter.Delete()\nif err != nil {\n    log.Fatal(\"cannot create interpreter\", err)\n}\n```\n\n4. Allocate Tensors\n\n```go\nstatus := interpreter.AllocateTensors()\nif status != tflite.TfLiteOk {\n    log.Println(\"allocate Tensors failed\")\n}\n```\n\n5. Input Tensor/s\n\n```go\nnewspecie := []float32{7.9, 3.8, 6.4, 2.0}\ninput, err := interpreter.GetInputTensor(0)\nif err != nil {\n\tlog.Println(\"cannot get input tensor\", err)\n}\ninput.SetFloat32(newspecie)\n```\n\n6. Interpreter Invoke \n\n```go\nstatus = interpreter.Invoke()\nif status != tflite.StatusOk {\n    log.Println(\"invoke interpreter failed\")\n}\n```\n\n7. Outputs/Results\n\n```go\noutput, err := interpreter.GetOutputTensor(0)\nif err != nil {\n\tlog.Println(\"cannot get output tensor\", err)\n}\nout := output.OperateFloat32()\nfmt.Println(topSpecie(out))\n```\n\n\u003cimg src=\"https://storage.googleapis.com/tflitego/iris3.gif?raw=true\" width=\"600px\"\u003e\n\nAlso here is possible view examples about tflitego in action:\n* [tflite examples](https://github.com/nbortolotti/tflitego_examples)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnbortolotti%2Ftflitego","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnbortolotti%2Ftflitego","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnbortolotti%2Ftflitego/lists"}