Add DM-Count crowd counting sample (CompiledModel GPU)#218
Open
john-rocky wants to merge 4 commits into
Open
Conversation
DM-Count (cvlab-stonybrook/DM-Count, NeurIPS 2020, MIT) regresses a person density map whose sum is the crowd size, running fully on the LiteRT CompiledModel GPU (30/30 nodes, 1 partition on a Pixel 8a; corr 0.9998-1.0 and count within 0.4% of PyTorch on real crowd images, ~79 ms/frame). Pure CNN (VGG19 + conv regression head) with one exact rewrite: the mid-graph F.upsample_bilinear (align_corners=True RESIZE_BILINEAR, banned on the delegate) is a linear operator, re-authored as two constant-matrix multiplies with the constant on the RHS (FULLY_CONNECTED; the delegate rejects BATCH_MATMUL with a constant LHS). Desktop corr vs PyTorch 1.000000 with an identical count. New crowd_counting category: Kotlin sample app (bundled crowd photo -> density heatmap + count) + conversion/ scripts (litert-torch build + CompiledModel-API validation).
Wrap every line in the conversion scripts to the 80-column limit of the Google Python Style Guide and add Args/Returns sections to the module-level function docstrings. No behavior changes.
Match the canonical compiled_model_api sample shape (image_segmentation /
dis_kotlin_gpu): a thin ComponentActivity host, a MainViewModel that owns the
CrowdCounter and confines every model call to a single-threaded dispatcher, an
immutable UiState, and a view/ package for the Compose screen and theme.
- MainActivity: programmatic LinearLayout -> Compose, with a PickVisualMedia
gallery launcher replacing the bundled-asset-only demo.
- MainViewModel: replaces the raw single-thread Executor; loads dmcount.tflite
from filesDir and surfaces the 'model not found - run install_to_device.sh'
hint as inline UI state. The renderOverlay density-map colorization math moves
over verbatim; the person count is added to UiState and shown in the status
line via a strings.xml format string.
- res/values/{strings,themes,colors}.xml: no hardcoded UI strings; the manifest
now uses @string/app_name and @style/Theme.CrowdCount.
- gradle/libs.versions.toml: adopt the version catalog used by the sibling
samples. LiteRT stays pinned at 2.1.5.
CrowdCounter.kt (the inference helper) is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
New crowd_counting category: DM-Count (NeurIPS 2020, MIT) running fully on the LiteRT
CompiledModelGPU delegate — the first crowd-counting sample. The model regresses a person density map whose sum is the crowd size, so it counts hundreds of people where detector-based counting saturates.install_to_device.sh).conversion/:build_dmcount.py(litert-torch) +validate_dmcount.py(static flatbuffer op scan + CompiledModel Python API parity check) + README.GPU conversion
DM-Count is a pure CNN (VGG19 + conv regression head). One exact rewrite makes it fully GPU-compatible: the mid-graph
F.upsample_bilinear(align_corners=TrueRESIZE_BILINEAR, banned on the delegate) is a linear operator, re-authored as two constant-matrix multiplies with the constant on the RHS (lowers toFULLY_CONNECTED; the delegate rejectsBATCH_MATMULwith a constant LHS). Desktop corr vs PyTorch 1.000000 with an identical count.Verification
:app:assembleDebugbuilds;validate_dmcount.pyreports opcheck clean, corr 1.000000, identical count.[1,3,512,512]NCHW RGB ImageNet-norm → output[1,1,64,64]density map (UCF-QNRF weights).Bundled test photo: Pexels (free license).