# asus4/tf-lite-unity-sample: TensorFlow Lite and MediaPipe samples for Unity

> A Unity sample project that ports the official TensorFlow Lite examples and several MediaPipe models to C#, shipping prebuilt native libraries for iOS, Android, macOS, Windows and Linux. The useful part is the UPM package; the caveat is that the samples and the runtime packages are versioned together and the last push was on 2026-05-28.

**asus4/tf-lite-unity-sample** — TensorFlow Lite Samples on Unity

- Repository: https://github.com/asus4/tf-lite-unity-sample
- Stars: 962 · Forks: 263
- Language: C#
- License: not declared
- Published: 2026-09-10 · Updated: 2026-09-10 · Language: en
- Canonical page: https://hysenlabs.com/projects/asus4-tf-lite-unity-sample

## What the tf-lite-unity-sample repository actually contains

Unity has no first-party TensorFlow Lite binding. The official TensorFlow Lite examples target Android, iOS, Python and the web, and MediaPipe ships its own graph-based pipelines. If you want MoveNet pose estimation or EfficientDet object detection inside a Unity scene, you write the interop layer yourself: P/Invoke into the native library, marshal tensors, manage the texture upload path, and handle a different delegate on every platform. This repository exists to remove that work. It is a port of the TensorFlow Lite examples to C#, plus utilities, and it is aimed at Unity developers who already know their way around a scene but do not want to spend a month on native bindings.

The sample list is broad rather than deep. Under TensorFlow there are MNIST, EfficientDet Object Detection, DeepLab, MoveNet, Style Transfer, Text Classification, Bert Question and Answer, Super Resolution and Audio Classification. Under MediaPipe there are Hand Tracking, Blaze Face, Face Mesh, Blaze Pose (full body) and Selfie Segmentation. The README states the project has been tested on iOS, Android, macOS, Windows and Linux with Unity 6000.3.11f1 and TensorFlow 2.21.0. Those are the versions the maintainer tested against, not a compatibility guarantee for your project.

The distinction that matters for adoption is between the sample scenes and the runtime packages. The scenes under Assets/Samples are demonstrations. The reusable part is the UPM package com.github.asus4.tflite and its companions, which carry the prebuilt native libraries. You can take the packages without taking the scenes.

## How the native libraries and delegates are split across platforms

The architecture is a thin C# layer over prebuilt native TensorFlow Lite binaries, with the delegate as the variable. The README's support table is the clearest statement of what you get. Core CPU is available on all five platforms. Metal Delegate is iOS and macOS. GPU Delegate is Android and Ubuntu, and the README marks Ubuntu as Experimental. NNAPI Delegate is Android only. Windows receives Core CPU and nothing else.

That table is the single most important thing to read before starting. A developer who prototypes on Windows with CPU inference and then expects GPU acceleration on Android will find that the delegate is a different code path with different constraints, not a flag. On Linux, the README points out that the GPU Delegate needs OpenGL ES and OpenCL installed, and links to the MediaPipe GPU support page for the setup steps. That is an environment prerequisite outside the Unity project.

There is also a build path for the native side. Prebuilt libraries ship inside the UPM package, and the README notes that TFLite libraries from version 2.14.0 onward are also available from DeNA's tflite-runtime-builder releases. If you need something newer than what ships, the repository includes build_tflite.py and the README gives the invocation. This is where the project stops being a drop-in package and becomes a build pipeline you own.

## Installing tf-lite-unity-sample through UPM

The README leads with an important warning: Git-LFS is required. The model files are large binaries, so a plain clone without Git-LFS leaves you with pointer files and scenes that fail at load. Install Git-LFS first, then clone the repository if you want the full set of examples.

```bash
git lfs install
git clone https://github.com/asus4/tf-lite-unity-sample.git
```

If you only need the runtime libraries rather than the sample scenes, the README gives a UPM route instead. You open Packages/manifest.json in your own project and add registries and dependencies. The npm registry entry is scoped to com.github.asus4, and the OpenUPM entry is scoped to com.cysharp.unitask, which is the optional async dependency.

```json
{
  "scopedRegistries": [
    {
      "name": "npm",
      "url": "https://registry.npmjs.com",
      "scopes": ["com.github.asus4"]
    },
    {
      "name": "package.openupm.com",
      "url": "https://package.openupm.com",
      "scopes": ["com.cysharp.unitask"]
    }
  ],
  "dependencies": {
    "com.github.asus4.tflite": "2.21.0-rc1",
    "com.github.asus4.tflite.common": "2.21.0-rc1",
    "com.github.asus4.mediapipe": "2.21.0-rc1",
    "com.cysharp.unitask": "2.5.11"
  }
}
```

The three com.github.asus4 packages are the core runtime, the TFLite utilities and the MediaPipe utilities. UniTask is optional, and the README states that async methods are available only when it is installed. After saving the file, Unity resolves the packages and you should see them in the Package Manager. Then open one of the sample scenes and press Play; the README's showcase GIFs (MNIST, SSD, DeepLab, Style Transfer, Hand Tracking, BERT) show the expected behaviour for each.

## Building the TFLite native libraries yourself

The prebuilt path covers the five listed platforms at whatever version the package pins. When you need a newer TensorFlow Lite, the repository expects you to build it. The README's steps are: clone the TensorFlow repository, run ./configure inside it, then run build_tflite.py with platform flags.

```sh
# Update iOS, Android and macOS
./build_tflite.py --tfpath ../tensorflow -ios -android -macos

# Build with XNNPACK
./build_tflite.py --tfpath ../tensorflow -macos -xnnpack
```

The --tfpath flag points at your TensorFlow checkout, and the platform flags select targets. The second example adds XNNPACK, which is the CPU acceleration library. Note the asymmetry: the first invocation updates three platforms, the second builds one platform with an extra option. The README does not describe how to combine XNNPACK with the multi-platform invocation, so treat the two lines as separate recipes rather than composable flags. It also does not document what happens to the previously built libraries, so keep your own record of which binaries are in which package version.

## Where tf-lite-unity-sample is the wrong choice

The release history is the first limitation. The most recent releases are v2.21.0-rc1 and v2.21.0-rc0, both from late May 2026, and the last push to the repository was on 2026-05-28. The release before those, v2.19.0-p3, dates from 2025-09-08. The version numbers you install from UPM are release candidates. That is a deliberate signal about stability expectations, and it means you are tracking a moving target if you pin to the newest tag.

Second, the platform table is a hard boundary. If you target a console, the web, or visionOS, the prebuilt libraries do not cover you. Windows gets CPU only, so a Windows desktop build with GPU inference is not supported by the shipped binaries. Ubuntu GPU is marked Experimental by the README itself.

Third, the licence situation is genuinely awkward for commercial work. The README states that Assets/Samples/* is MIT, and it lists TensorFlow and MediaPipe as Apache 2.0. It then adds a separate note: each TensorFlow Lite model might have a different license, and you should check the license of the model you use. The Selfie Segmentation model is described as a modified model from PINTO_model_zoo with the custom post-process removed, which is a concrete example of a model whose provenance differs from the surrounding code. If your legal review assumes the whole repository is MIT because the samples are, that assumption is wrong.

Finally, the repository is a sample collection, not a product. There is no documented rollback procedure, no migration guide between the rc versions, and the README does not describe a support channel. You are adopting a reference implementation and its packages, with the maintenance cadence you can infer from the push dates.

## Alternatives: ONNX Runtime, Unity Sentis, and hand-rolled bindings

The closest alternative in the Unity ecosystem is ONNX Runtime, and the difference is the model format and the conversion step. TensorFlow Lite uses .tflite files produced by the TensorFlow Lite converter; ONNX Runtime consumes .onnx graphs and has its own Unity bindings. If your models already exist as ONNX exports from PyTorch, ONNX Runtime removes the conversion entirely. If they come from TensorFlow or from MediaPipe, this repository's samples are closer to working code, because the MediaPipe models here are already packaged with the post-processing the pipelines expect.

The second alternative is Unity's own inference package, which keeps you inside the Unity toolchain and Unity's release cycle. The trade-off is model coverage and operator support: a graph that runs under TensorFlow Lite may need conversion or may not convert cleanly. This repository's advantage is that each sample corresponds to a model the maintainer has already got running on the listed platforms.

The third option is writing the binding yourself, which is what this project did. That gives you complete control over the delegate selection and the tensor marshalling, and it is the right call if you need a platform or an operator set the prebuilt libraries do not cover. The cost is the interop layer, the per-platform native builds, and the ongoing work of tracking TensorFlow Lite releases. For a team whose product is the model rather than the runtime, that is usually the wrong place to spend engineering time.

## Maintenance cost and licence implications

The upgrade path is version-pinned in Packages/manifest.json. Because com.github.asus4.tflite, com.github.asus4.tflite.common and com.github.asus4.mediapipe are listed at the same version string, moving one means moving all three, and the current published version is 2.21.0-rc1. The native libraries inside those packages correspond to TensorFlow 2.21.0 per the README's tested-versions line. Upgrading the C# package without rebuilding the native libraries, or the reverse, is the failure mode to watch for.

On licensing, the split is explicit. The samples folder Assets/Samples/* is MIT, with the copyright notice naming Koki Ibukuro and the year 2024. TensorFlow is Apache License 2.0 and MediaPipe is Apache License 2.0, and the README notes that some MediaPipe C# code is based on terryky/tflite_gles_app. The models sit outside that umbrella: the README instructs you to check the license of each model you use, and lists the official TFLite models and the MediaPipe models separately. The top-level repository metadata does not declare a single license for the project as a whole. That is a documentation gap worth resolving with your own legal review before shipping, because the answer depends on which model files end up in your build, not on the repository's badge.

## Conclusion

Adopt it if you are building an on-device vision, audio or text feature in Unity and want working reference scenes rather than a blank integration. Do not adopt it if you need a supported commercial runtime with an SLA, or if your target is a platform outside the five the README lists, because the prebuilt libraries do not cover anything else. Before committing, verify three things: that Git-LFS is installed and the model files actually arrived, that the delegate you intend to use exists for your platform in the prebuilt table (GPU Delegate is Android and experimental Ubuntu only, NNAPI is Android only, Metal is iOS and macOS only), and that every model you plan to ship has its own license, since the README states each TensorFlow Lite model may carry a different one.

## FAQ

### What is a .TFLite file?

It is the model format TensorFlow Lite runs. This project consumes those files: the README lists the official TFLite models it ports, including EfficientDet, DeepLab, MoveNet, Bert and Style Transfer, and ships prebuilt native libraries to execute them on iOS, Android, macOS, Windows and Linux.

### What is TensorFlow Lite used for?

On-device inference. The examples in this repository cover object detection, semantic segmentation, pose estimation, style transfer, text classification, question answering, super resolution and audio classification, all running inside Unity scenes rather than on a server.

### Is TensorFlow Lite deprecated?

The README does not address deprecation. It states the project is tested with TensorFlow 2.21.0 and publishes packages at version 2.21.0-rc1, and it points to DeNA's tflite-runtime-builder releases for TFLite libraries from v2.14.0 onward, so the underlying runtime is still being built against current versions.

### How to convert PT model to TFLite?

The README does not cover PyTorch conversion; it points to the official TensorFlow Lite examples for the models it ports, and to DeNA's tflite-runtime-builder releases for the native TFLite libraries from v2.14.0 onward. Conversion itself happens outside this repository, before the .tflite file reaches Unity.

## Sources

- [asus4/tf-lite-unity-sample on GitHub](https://github.com/asus4/tf-lite-unity-sample)
- [Issues](https://github.com/asus4/tf-lite-unity-sample/issues)
- [README](https://github.com/asus4/tf-lite-unity-sample/blob/master/README.md)
- [Releases](https://github.com/asus4/tf-lite-unity-sample/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/asus4-tf-lite-unity-sample
