Skip to content

Conversation

@narshi
Copy link

@narshi narshi commented Sep 28, 2025

Description :

feat: Add on-demand MNN image classification from gallery

Integrate MNN-based image classification using a pre-copied MobileNet-v1 model, allowing users to analyze images picked from the device gallery.

Functional Changes

  • MNN Integration: Implemented runClassifier() to handle model loading, image preprocessing (resize/normalize to NCHW [1, 3, 224, 224]), and calling the native MNNClassifier.run() wrapper.
  • UI Trigger: Added the 'Pick Image' button (btnPickImage) to activity_main.xml and hooked it up in MainActivity to launch the image picker via startActivityForResult.
  • Pipeline: Handled the result in onActivityResult to trigger the runClassifier method.
  • Result Display: Displays the predicted class index using a Toast message upon successful inference.

Technical Details

  • Ensured necessary model copying logic from assets to the filesystem during the initial classifier button setup.
  • Implemented bitmapToNCHWFloatArray helper for required input preprocessing.
  • Used lifecycleScope and Dispatchers.IO for running the inference task off the main thread.

Description :

feat: Add on-demand MNN image classification from gallery

Integrate MNN-based image classification using a pre-copied MobileNet-v1 model, allowing users to analyze images picked from the device gallery.

### Functional Changes
* **MNN Integration:** Implemented `runClassifier()` to handle model loading, image preprocessing (resize/normalize to NCHW [1, 3, 224, 224]), and calling the native `MNNClassifier.run()` wrapper.
* **UI Trigger:** Added the 'Pick Image' button (`btnPickImage`) to `activity_main.xml` and hooked it up in `MainActivity` to launch the image picker via `startActivityForResult`.
* **Pipeline:** Handled the result in `onActivityResult` to trigger the `runClassifier` method.
* **Result Display:** Displays the predicted class index using a `Toast` message upon successful inference.

### Technical Details
* Ensured necessary model copying logic from assets to the filesystem during the initial classifier button setup.
* Implemented `bitmapToNCHWFloatArray` helper for required input preprocessing.
* Used `lifecycleScope` and `Dispatchers.IO` for running the inference task off the main thread.
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Narayanks seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants