Add DehazeFormer-MCT image dehazing sample (CompiledModel GPU)#219
Open
john-rocky wants to merge 3 commits into
Open
Add DehazeFormer-MCT image dehazing sample (CompiledModel GPU)#219john-rocky wants to merge 3 commits into
john-rocky wants to merge 3 commits into
Conversation
DehazeFormer-MCT (IDKiro/DehazeFormer, TIP 2023, MIT; mixed-dataset curve-mapping variant from the author's HF Space) removes real-world fog/haze/smoke, with the Swin-windowed-attention basenet running fully on the LiteRT CompiledModel GPU (Pixel 8a: 2042/2042 nodes, 1 partition; device corr 0.999998, end-to-end vs the official pipeline corr 0.999997, ~255 ms/frame). The 256x256 basenet emits 72 per-pixel curve parameters; the sample applies the curves to the full-resolution photo host-side (the exact official grid_sample mapping, replica corr 1.0). Exact re-authors: reflect pads -> slice+concat (litert-torch lowers reflection_pad2d to banned GATHER_ND, including padding=0 reflect convs), Swin window partition/reverse <=4D + qkv slices + baked relative-position bias, SKFusion 5D->4D pairwise softmax, Conv+PixelShuffle -> zero-stuff ConvTranspose, and RLN global norm / SKFusion global pool -> hierarchical means (a single MEAN over 1.5M elements overflows the Mali fp16 accumulator -> NaN). Desktop corr vs PyTorch 1.0000000. New image_dehazing category: Kotlin sample app (bundled hazy photo -> dehazed full-res result) + 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
Dehazer 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; surfaces the
'model not found - run install_to_device.sh' hint as inline UI state.
- res/values/{strings,themes,colors}.xml: no hardcoded UI strings; the
manifest now uses @string/app_name and @style/Theme.Dehaze.
- gradle/libs.versions.toml: adopt the version catalog used by the sibling
samples. LiteRT stays pinned at 2.1.5.
Dehazer.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 image_dehazing category: DehazeFormer (TIP 2023, MIT; the author's MCT curve-mapping variant trained on a mixed dataset for real-world haze) running fully on the LiteRT
CompiledModelGPU delegate — the first dehazing sample. Removes fog / haze / smoke and restores contrast and color.install_to_device.sh).conversion/:build_dehaze.py(litert-torch; fetches the author's code + MIT checkpoint from their HF Space) +validate_dehaze.py(static flatbuffer op scan + CompiledModel Python API parity) + README.GPU conversion (all re-authors exact — desktop corr vs PyTorch 1.0000000)
reflection_pad2dtoGATHER_ND(rejected by the delegate) — includingpadding_mode='reflect'convs with padding=0, which still route throughF.pad.MEANover C·H·W (1.5M elements) overflows the Mali fp16 accumulator → NaN output; equal-windowavg_poolstages + small MEANs are mathematically identical and fp16-safe.Verification
:app:assembleDebugbuilds;validate_dehaze.pyreports opcheck clean, corr 1.0000000.[1,3,256,256]NCHW RGB in [-1,1] → output[1,72,256,256]curve parameters.Bundled test photo: Pexels (free license).