Skip to content

Add U2-Net Portrait photo-to-pencil-sketch sample (CompiledModel GPU)#217

Open
john-rocky wants to merge 5 commits into
google-ai-edge:mainfrom
john-rocky:u2net-portrait-sketch-sample
Open

Add U2-Net Portrait photo-to-pencil-sketch sample (CompiledModel GPU)#217
john-rocky wants to merge 5 commits into
google-ai-edge:mainfrom
john-rocky:u2net-portrait-sketch-sample

Conversation

@john-rocky

Copy link
Copy Markdown
Contributor

The U²-Net portrait model (Apache-2.0) turns a face photo into a hand-drawn pencil line portrait — a fun creative / AR filter — running fully on the LiteRT CompiledModel GPU at ~12 ms/frame on a Pixel 8a. The first portrait-sketch sample.

Pure CNN (U²-Net RSU blocks) → fully GPU-compatible (893/893 nodes on the delegate, 1 partition; device corr 0.998683) with one defensive patch: align_corners=False. CPU-exact vs PyTorch (corr 1.0). Input [1,3,512,512] RGB ImageNet-norm, output [1,1,512,512] (min-max normalize, invert for dark strokes on white).

Model: litert-community/U2Net-Portrait-Sketch-LiteRT.

Sample at compiled_model_api/portrait_sketch/u2net_portrait_kotlin_gpu (android app + conversion scripts), with a deterministic bundled-image photo-to-sketch demo.

The U2-Net portrait model (xuebinqin/U-2-Net, Apache-2.0) turns a face photo into a hand-drawn pencil line portrait — a fun creative / AR filter — running fully on the LiteRT CompiledModel GPU at ~12 ms/frame on a Pixel 8a. First portrait-sketch sample.

Pure CNN (U2-Net RSU blocks) → fully GPU-compatible (893/893 nodes, 1 partition; device corr 0.998683) with one defensive patch: align_corners=False. CPU-exact vs PyTorch (corr 1.0). Input [1,3,512,512] RGB ImageNet-norm, output [1,1,512,512] (min-max normalize, invert for dark strokes on white).

Sample at compiled_model_api/portrait_sketch/u2net_portrait_kotlin_gpu (android app + conversion scripts), with a deterministic bundled-image photo-to-sketch demo.
… conversion script, drop personal path default, 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.
Restructure the app to the image_segmentation reference: a thin
ComponentActivity host over a MainViewModel + immutable UiState, UI strings
moved to res/values, a Gradle version catalog, and status-bar inset padding.
Inference/model code is unchanged.
@john-rocky
john-rocky force-pushed the u2net-portrait-sketch-sample branch from 817f888 to 1254017 Compare July 9, 2026 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant