Skip to content

Use MobileSAM on Android, enable NNAPI and unload unused AI models fast, fix inpainting#1090

Open
waxm134 wants to merge 4 commits intoCyberTimon:mainfrom
waxm134:android_ai_fix
Open

Use MobileSAM on Android, enable NNAPI and unload unused AI models fast, fix inpainting#1090
waxm134 wants to merge 4 commits intoCyberTimon:mainfrom
waxm134:android_ai_fix

Conversation

@waxm134
Copy link
Copy Markdown
Contributor

@waxm134 waxm134 commented Apr 25, 2026

Description

  • AI model performance tweaks and bug fixes for Android

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Performance improvement
  • Code refactoring
  • Documentation update
  • UI/UX improvement
  • Build/CI or Dependency update

Changes Made

  • SAM2 model is heavy for android devices, switch to MobileSAM on Android to increase subject mask speed and lower RAM usage
  • Enable NNAPI to leverage any NPU provided by the SoC
  • unload unused AI models quickly to avoid OOM fails due to excessive RAM usage
  • fixed inpainting on Android

Screenshots/Videos

Testing

  • I have tested these changes locally and confirmed that they work as expected without issues

Test Configuration:

  • OS: Ubuntu 24.04, Android 16
  • Hardware: Intel i5, Pixel 9 Pro, Xiaomi Pad 7

Checklist

  • My code follows the project's code style
  • I haven't added unnecessary AI-generated code comments
  • My changes generate no new warnings or errors

Additional Notes

AI Disclaimer:

Please state the involvement of AI in this PR:

  • This PR is entirely AI-generated
  • This PR is AI-generated but guided by a human
  • This PR was handwritten with AI assistance (spell check, logic suggestions, error resolving)
  • This PR contains only blood, sweat, and coffee (AI-free)

@CyberTimon
Copy link
Copy Markdown
Owner

Are you sure NNAPI gets utilized and it doesn't just silently fallback to CPU because the compiled onnxruntime library wasn't compiled with NNAPI in it?

@waxm134
Copy link
Copy Markdown
Contributor Author

waxm134 commented Apr 26, 2026

That's interesting. At least for the LAMA_Dilated I explicitly removed loading it via NNAPI because it failed with NNAPI enabled. I can try to debug this further, but in general I think it's worth to enable NPU usage on Android.

@Duecki1
Copy link
Copy Markdown
Contributor

Duecki1 commented Apr 27, 2026

I've just tested this pr on my Pixel 7 Pro, which is not very powerful. AI Masking works and inpainting does too, without the app crashing.

@Duecki1
Copy link
Copy Markdown
Contributor

Duecki1 commented Apr 30, 2026

@waxm134 do you think you could maybe look into that weird mask bug? I cannot find any solution to it. To replicate it, work with masks on an image for some time, at some random point you wont be able to click on mask components anymore. You can't select them anymore, only the main masks.

Screen_Recording_20260430_230508_RapidRAW.mp4

@waxm134
Copy link
Copy Markdown
Contributor Author

waxm134 commented May 1, 2026

@waxm134 do you think you could maybe look into that weird mask bug? I cannot find any solution to it. To replicate it, work with masks on an image for some time, at some random point you wont be able to click on mask components anymore. You can't select them anymore, only the main masks.

I can try to replicate the issue on my side and try to debug.

@Duecki1
Copy link
Copy Markdown
Contributor

Duecki1 commented May 1, 2026

@waxm134 do you think you could maybe look into that weird mask bug? I cannot find any solution to it. To replicate it, work with masks on an image for some time, at some random point you wont be able to click on mask components anymore. You can't select them anymore, only the main masks.

I can try to replicate the issue on my side and try to debug.

Thank you, only if its okay for you tho. It happens often when im editing masks, but I can't find why.

@waxm134
Copy link
Copy Markdown
Contributor Author

waxm134 commented May 2, 2026

@waxm134 do you think you could maybe look into that weird mask bug? I cannot find any solution to it. To replicate it, work with masks on an image for some time, at some random point you wont be able to click on mask components anymore. You can't select them anymore, only the main masks.

I can try to replicate the issue on my side and try to debug.

Thank you, only if its okay for you tho. It happens often when im editing masks, but I can't find why.

I tried to reproduce on my Pixel 9 and cannot reproduce it. But on the Xiaomi Pad 7 I reproduced it once and then immediately after the buttons froze the app crashed so I guess it has to do with RAM pressure and OOM. I try to implement some simple fixes to reduce overall RAM usage at the moment, maybe afterwards it's gone.

@Duecki1
Copy link
Copy Markdown
Contributor

Duecki1 commented May 2, 2026

@waxm134 do you think you could maybe look into that weird mask bug? I cannot find any solution to it. To replicate it, work with masks on an image for some time, at some random point you wont be able to click on mask components anymore. You can't select them anymore, only the main masks.

I can try to replicate the issue on my side and try to debug.

Thank you, only if its okay for you tho. It happens often when im editing masks, but I can't find why.

I tried to reproduce on my Pixel 9 and cannot reproduce it. But on the Xiaomi Pad 7 I reproduced it once and then immediately after the buttons froze the app crashed so I guess it has to do with RAM pressure and OOM. I try to implement some simple fixes to reduce overall RAM usage at the moment, maybe afterwards it's gone.

Really weird behavior :/. Thanks for testing tho <3. Hopefully we will be able to fix it :D

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.

3 participants