Video Classification
LiteRT
LiteRT
android
on-device
gpu
video-action-recognition
kinetics-600
movinet
streaming
Instructions to use litert-community/MoViNet-A0-Stream-LiteRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/MoViNet-A0-Stream-LiteRT with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
library_name: litert
|
| 4 |
+
pipeline_tag: video-classification
|
| 5 |
+
tags:
|
| 6 |
+
- litert
|
| 7 |
+
- tflite
|
| 8 |
+
- android
|
| 9 |
+
- on-device
|
| 10 |
+
- gpu
|
| 11 |
+
- video-action-recognition
|
| 12 |
+
- kinetics-600
|
| 13 |
+
- movinet
|
| 14 |
+
- streaming
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# MoViNet-A0 Stream — LiteRT (on-device video action recognition, GPU)
|
| 18 |
+
|
| 19 |
+
On-device **streaming video action recognition**: recognises human actions across a
|
| 20 |
+
stream of camera frames — one frame at a time, constant memory, real-time — running
|
| 21 |
+
**fully on the LiteRT `CompiledModel` GPU delegate** (no CPU fallback).
|
| 22 |
+
|
| 23 |
+
- **Architecture:** [MoViNet-A0](https://arxiv.org/abs/2103.11511) streaming variant
|
| 24 |
+
(Google Research) — a causal 2+1D CNN.
|
| 25 |
+
- **Task:** [Kinetics-600](https://github.com/cvdfoundation/kinetics-dataset) — 600 action classes.
|
| 26 |
+
- **Weights:** ported PyTorch checkpoint from [Atze00/MoViNet-pytorch](https://github.com/Atze00/MoViNet-pytorch).
|
| 27 |
+
- **Size:** 15 MB · ~3.75 M params · input frame `172×172`.
|
| 28 |
+
|
| 29 |
+

|
| 30 |
+
|
| 31 |
+
## How the streaming graph works
|
| 32 |
+
|
| 33 |
+
MoViNet's temporal convolutions and global-average-pools each keep a small buffer of
|
| 34 |
+
the recent past, so the network can be fed **one frame at a time** and its prediction
|
| 35 |
+
sharpens as more frames of the same action arrive. The stock streaming graph carries
|
| 36 |
+
that history in **5D** state tensors `[1, T, H, W, C]`, which a GPU delegate cannot
|
| 37 |
+
compile (all tensors must be ≤ 4D). This model is re-authored as a **single-frame,
|
| 38 |
+
4D-only functional forward** (**47 inputs / 28 outputs**) with the recurrent state
|
| 39 |
+
threaded explicitly through the graph I/O:
|
| 40 |
+
|
| 41 |
+
| I/O slot | count | shape | meaning |
|
| 42 |
+
|-----------------|-------|-----------------|-------------------------------------------|
|
| 43 |
+
| `input[0]` | 1 | `[1,3,172,172]` | current RGB frame (NCHW, 0..1) |
|
| 44 |
+
| `input[1..28]` | 28 | `[1,C,H,W]` | temporal-conv stream buffers (11 convs) |
|
| 45 |
+
| `input[29..44]` | 16 | `[1,C,1,1]` | streaming avg-pool running sums (15 SE + head) |
|
| 46 |
+
| `input[45]` | 1 | `[1,1,1,1]` | `inv_count` = 1 / current frame number |
|
| 47 |
+
| `input[46]` | 1 | `[1,1,1,1]` | constant `1.0` (Mali output decoupler) |
|
| 48 |
+
| `output[0]` | 1 | `[1,600]` | Kinetics-600 logits |
|
| 49 |
+
| `output[1..11]` | 11 | `[1,C,H,W]` | current per-temporal-conv frame |
|
| 50 |
+
| `output[12..27]`| 16 | `[1,C,1,1]` | fresh per-frame spatial means |
|
| 51 |
+
|
| 52 |
+
The **stream-buffer shift register and pool running-sum accumulation are done
|
| 53 |
+
host-side**: each frame you run once, shift each stream buffer (drop oldest, append
|
| 54 |
+
the emitted current frame), accumulate `running_sum += emitted_mean`, and feed both
|
| 55 |
+
back as inputs. The converted graph is **all float32, 0 tensors of rank > 4, 0
|
| 56 |
+
GPU-incompatible ops** and matches the original PyTorch model bit-for-bit
|
| 57 |
+
(correlation 0.99999999999, top-5 identical; device GPU on a Pixel 8a locks onto
|
| 58 |
+
"jumping jacks" within a few frames). Keeping the state in-graph tripped three silent
|
| 59 |
+
Mali `CompiledModel` bugs, which is why the state plumbing is host-side.
|
| 60 |
+
|
| 61 |
+
## Minimal usage
|
| 62 |
+
|
| 63 |
+
### Python (LiteRT / ai-edge-litert, frame-by-frame)
|
| 64 |
+
|
| 65 |
+
```python
|
| 66 |
+
from ai_edge_litert.interpreter import Interpreter
|
| 67 |
+
import numpy as np
|
| 68 |
+
|
| 69 |
+
it = Interpreter(model_path="movinet_a0_stream.tflite"); it.allocate_tensors()
|
| 70 |
+
inp, out = it.get_input_details(), it.get_output_details()
|
| 71 |
+
|
| 72 |
+
DIMS = [2, 2, 2, 4, 2, 2, 4, 2, 2, 2, 4] # temporal-conv buffer depths
|
| 73 |
+
offs, o = [], 0
|
| 74 |
+
for d in DIMS: offs.append(o); o += d
|
| 75 |
+
hist = [[np.zeros(inp[1 + offs[c] + i]["shape"], np.float32) for i in range(DIMS[c])]
|
| 76 |
+
for c in range(11)] # host-side shift registers
|
| 77 |
+
psum = [np.zeros(inp[29 + i]["shape"], np.float32) for i in range(16)] # running sums
|
| 78 |
+
|
| 79 |
+
for n, frame in enumerate(video_frames, start=1): # frame: [1,3,172,172], RGB, 0..1
|
| 80 |
+
it.set_tensor(inp[0]["index"], frame.astype(np.float32))
|
| 81 |
+
for c in range(11):
|
| 82 |
+
for i in range(DIMS[c]): it.set_tensor(inp[1 + offs[c] + i]["index"], hist[c][i])
|
| 83 |
+
for i in range(16): it.set_tensor(inp[29 + i]["index"], psum[i])
|
| 84 |
+
it.set_tensor(inp[45]["index"], np.full((1, 1, 1, 1), 1.0 / n, np.float32)) # inv_count
|
| 85 |
+
it.set_tensor(inp[46]["index"], np.ones((1, 1, 1, 1), np.float32)) # decoupler
|
| 86 |
+
it.invoke()
|
| 87 |
+
logits = it.get_tensor(out[0]["index"])[0] # [600]
|
| 88 |
+
for c in range(11): # shift: drop oldest, append current
|
| 89 |
+
hist[c] = hist[c][1:] + [it.get_tensor(out[1 + c]["index"]).copy()]
|
| 90 |
+
for i in range(16): # accumulate running sum
|
| 91 |
+
psum[i] = psum[i] + it.get_tensor(out[12 + i]["index"])
|
| 92 |
+
|
| 93 |
+
print("top-1:", int(logits.argmax()))
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
A full Kotlin implementation (camera → per-frame → top-5) is in the sample app's
|
| 97 |
+
`ActionRecognizer.kt`.
|
| 98 |
+
|
| 99 |
+
## Conversion
|
| 100 |
+
|
| 101 |
+
Re-authored and converted with **litert-torch**. See the sample app and build script:
|
| 102 |
+
`build_movinet.py` + `stream_model.py`.
|
| 103 |
+
|
| 104 |
+
## License
|
| 105 |
+
|
| 106 |
+
Apache-2.0 (MoViNet / Atze00/MoViNet-pytorch). Kinetics-600 label taxonomy from the
|
| 107 |
+
DeepMind Kinetics dataset.
|