CoolFace
Modelpublic

litert-community/DM-Count-Crowd-LiteRT

sourceHugging Facemitupdated 14d agoView on Hugging Face
3likes150downloads
Model Card

Measured on device (edge-compat): Raspberry Pi 5 · LiteRT 2.2.0.dev20260804 · CPU/XNNPACK, 4 threads · 1924 ms p50 (2026-08-31); browser · Chromium 151 on M4 Max · LiteRT.js 2.5.3 · WebGPU · 14.8 ms p50 · output matches CPU (2026-08-11). Record: https://github.com/john-rocky/edge-compat/blob/main/cards/dm-count-crowd/CARD.md

DM-Count — Crowd counting (LiteRT GPU)

On-device crowd counting running fully on the LiteRT `CompiledModel` GPU delegate (no CPU fallback). DM-Count (NeurIPS 2020) regresses a person density map whose sum is the crowd size — it counts hundreds of people where detector-based counting saturates.

  • Architecture: VGG19 backbone + conv regression head — pure CNN.
  • Weights: cvlab-stonybrook/DM-Count (UCF-QNRF) · MIT.
  • Size: 86 MB.

[image]

Input (left) → density heatmap + count (right). Photo: Pexels (free license).

I/O

  • Input: [1, 3, 512, 512] NCHW, RGB, ImageNet-normalized (mean [0.485,0.456,0.406], std [0.229,0.224,0.225]).
  • Output: [1, 1, 64, 64] non-negative density map — sum(map) = estimated person count; normalize per frame for a heatmap overlay.

GPU conversion

DM-Count is a pure CNN (VGG19 + conv head). It converts fully GPU-compatible (30/30 nodes on the delegate, 1 partition; Pixel 8a corr 0.9998–1.0 and count within 0.4% of PyTorch on real crowd images, ~79 ms/frame) with one exact rewrite: the mid-graph F.upsample_bilinear (aligncorners=True `RESIZEBILINEAR, banned on the delegate) is a linear operator, re-authored as two constant-matrix multiplies — with the constant on the **RHS** (lowers to FULLYCONNECTED`; the delegate rejects `BATCHMATMUL` with a constant LHS). Desktop corr vs PyTorch is 1.000000 with an identical count.

Minimal usage

Kotlin (Android, LiteRT CompiledModel GPU)

kotlin
val options = CompiledModel.Options(Accelerator.GPU)
val model = CompiledModel.create(context.assets, "dmcount.tflite", options, null)
val inBufs = model.createInputBuffers()
val outBufs = model.createOutputBuffers()

inBufs[0].writeFloat(inputNCHW)          // [1,3,512,512] RGB, ImageNet-norm
model.run(inBufs, outBufs)
val density = outBufs[0].readFloat()     // [64*64] density map
val count = density.sum()                // estimated number of people

Python (LiteRT CompiledModel API)

python
import numpy as np
from ai_edge_litert.compiled_model import CompiledModel

model = CompiledModel.from_file("dmcount.tflite")
inputs = model.create_input_buffers(0)
outputs = model.create_output_buffers(0)
inputs[0].write(np.ascontiguousarray(x, np.float32))  # [1,3,512,512] RGB, ImageNet-norm
model.run_by_index(0, inputs, outputs)
n = model.get_output_buffer_requirements(0, 0)["buffer_size"] // 4
density = outputs[0].read(n, np.float32).reshape(64, 64)
count = float(density.sum())

Conversion

Converted with litert-torch (build_dmcount.py): loads the MIT DM-Count (UCF-QNRF) weights and exports the raw density map. The UCF-QNRF checkpoint generalizes best across scenes; the upstream repo also bundles an NWPU-Crowd variant.

Performance

Measured on a Pixel 8a (Tensor G3, Android 16) with the standard TFLite `benchmark_model` tool — 10 warm-up runs then 50 timed runs, reported as the tool's mean.

RuntimeBackendGraph on GPULatency
LiteRT CompiledModel (LITERT_CL)GPU30 / 30~79 ms
TFLite benchmark_model (TfLiteGpuDelegateV2)GPU (OpenCL)30 / 3098.2 ms
TFLite benchmark_modelCPU (XNNPACK, 4 threads)3185.7 ms

The two GPU rows are different runtimes, not a contradiction. The LITERT_CL figure is the one recorded when this model shipped, taken through LiteRT's own CompiledModel accelerator — the path the Kotlin sample app and the LiteRT API use. The TfLiteGpuDelegateV2 figure is the classic TFLite OpenCL delegate, measured with a tool anyone can download and re-run. They agree on how much of the graph the GPU takes; they disagree on speed, and the classic delegate is the slower of the two here. Read the TfLiteGpuDelegateV2 row as a reproducible floor, not as this model's speed on LiteRT.

Snapdragon NPU (Hexagon)

The NPU is 2.90x faster than the GPU (9.54 ms against 27.64 ms) and loads 6.79x faster (139 ms against 943 ms).

backendinference (median / min)load
NPU (Hexagon v81)9.54 ms / 9.16 ms139 ms
GPU (Adreno)27.64 ms / 27.38 ms943 ms

Measured on a Samsung Galaxy S26 (Snapdragon 8 Elite Gen 5 / SM8850, Hexagon v81, Android 16), LiteRT CompiledModel 2.2.0, one accelerator per process, 5 warm-up runs then N=50 timed runs, median reported. Every run held thermal status NONE throughout. Headroom 0.70-0.71, where 1.0 is the throttling threshold.

The NPU rows here ran artifacts compiled ahead of time for SM8850 with QAIRT 2.47.0; the GPU rows ran the published files as they are. LiteRT can also compile for the NPU on the device at first load, which is what lets you ship the published file unchanged — that path and the ten runtime libraries it needs are in the NPU recipe, and we did not measure it here. GPU wiring is in the GPU recipe.

Raspberry Pi 5 (CPU)

Measured on a Raspberry Pi 5 Model B Rev 1.1 (8 GB, Raspberry Pi OS 64-bit) with the LiteRT `benchmark_model` tool from litert-cli-nightly 0.2.0.dev20260805: CPU inference (XNNPACK, 4 threads), 3 invocations per file of 10 warm-up plus 50 timed runs (the tool caps a phase at 150 s, so very slow graphs run fewer — the Runs column is the actual timed total). The latency is the median across invocations; the spread is the min–max over all timed runs. No thermal throttling occurred during these runs (vcgencmd get_throttled stayed 0x0).

FileInference (median)Spread (min–max)RunsPeak memory
dmcount.tflite1,923.8 ms1,858.0–2,054.7 ms150367 MB

License

MIT (DM-Count / cvlab-stonybrook). Trained on UCF-QNRF.