Add DewarpNet document dewarping sample (CompiledModel GPU)#208
Open
john-rocky wants to merge 4 commits into
Open
Add DewarpNet document dewarping sample (CompiledModel GPU)#208john-rocky wants to merge 4 commits into
john-rocky wants to merge 4 commits into
Conversation
DewarpNet (cvlab-stonybrook/DewarpNet, ICCV 2019, MIT) flattens a photographed curved/folded document — the core of a document scanner — running fully on the LiteRT CompiledModel GPU at ~24 ms/frame on a Pixel 8a. First document-processing sample. Two CNNs (WCNet UNet + BMNet DenseNet) predict a backward-mapping grid on the GPU (371/371 nodes, 1 partition; device corr 0.999866) and a tiny host-side grid_sample flattens the page. Two exact conversion patches: ConvTranspose2d -> ZeroStuffConvT2d (Mali rejects TRANSPOSE_CONV) and Hardtanh(0,1) -> relu(x)-relu(x-1) (Mali rejects RELU_0_TO_1). CPU-exact vs PyTorch (corr 0.9999999999). Sample at compiled_model_api/document_dewarping/dewarpnet_kotlin_gpu (android app + conversion scripts), with a deterministic bundled-image before/after demo.
john-rocky
force-pushed
the
dewarpnet-document-dewarping-sample
branch
from
July 6, 2026 23:52
cde4eaa to
f7ce4a2
Compare
… conversion script, copyright 2026
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.
Rehost the DewarpNet sample on Jetpack Compose + MVVM to match the canonical compiled_model_api sample shape. - MainActivity is now a thin ComponentActivity that observes MainViewModel and adds a gallery picker (PickVisualMedia); the old programmatic View layout is gone. - New MainViewModel owns the DocumentDewarper, confines every model call to a single-parallelism Dispatchers.Default worker, loads dewarp.tflite from filesDir with an inline install_to_device.sh message when it is missing, and closes the helper in onCleared(). - New UiState, ImageUtils (asset + EXIF decode), DewarpScreen, Theme and Color, plus res/values strings/themes/colors; every UI string is externalized. - The DocumentDewarper inference helper (model I/O and the host-side grid_sample unwarp) is left byte-identical. - Adopt the Gradle version catalog (AGP 8.9.1 / Kotlin 2.2.21 / compileSdk 36); LiteRT stays pinned at 2.1.5. - Fix dead ormbg references in install_to_device.sh (build_dewarp.py and the final app name).
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.
DewarpNet (ICCV 2019, MIT) flattens a photographed, curved/folded document — the core of a document scanner — running fully on the LiteRT
CompiledModelGPU at ~24 ms/frame on a Pixel 8a. The first document-processing sample.Two CNNs (WCNet UNet + BMNet DenseNet) predict a backward-mapping grid on the GPU (371/371 nodes on the delegate, 1 partition; device corr 0.999866, ~24 ms), and a tiny host-side
grid_sampleflattens the page. Two exact conversion patches:ConvTranspose2d→ ZeroStuffConvT2d (Mali rejectsTRANSPOSE_CONV) andHardtanh(0,1)→relu(x)-relu(x-1)(Mali rejectsRELU_0_TO_1). CPU-exact vs PyTorch (corr 0.9999999999). Input[1,3,256,256]BGR /255, output[1,2,128,128]backward map.Model: litert-community/DewarpNet-LiteRT.
Sample at
compiled_model_api/document_dewarping/dewarpnet_kotlin_gpu(android app + conversion scripts), with a deterministic bundled-image before/after demo.