Skip to content

Commit

Permalink
v0.6.0r1
Browse files Browse the repository at this point in the history
Add Image Segmentation App

Signed-off-by: QAIHM Team <[email protected]>
  • Loading branch information
qaihm-bot committed May 21, 2024
1 parent 49f7592 commit 4c5f865
Show file tree
Hide file tree
Showing 66 changed files with 3,456 additions and 341 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ Qualcomm® AI Hub Models is licensed under BSD-3. See the [LICENSE file](../LICE
| Model | README | Torch App | Device Export | CLI Demo
| -- | -- | -- | -- | --
| | | | |
| [TrOCR](https://aihub.qualcomm.com/models/trocr) | [qai_hub_models.models.trocr](qai_hub_models/models/trocr/README.md) | ✔️ | ✔️ | ✔️
| [OpenAI-Clip](https://aihub.qualcomm.com/models/openai_clip) | [qai_hub_models.models.openai_clip](qai_hub_models/models/openai_clip/README.md) | ✔️ | ✔️ | ✔️
| [TrOCR](https://aihub.qualcomm.com/models/trocr) | [qai_hub_models.models.trocr](qai_hub_models/models/trocr/README.md) | ✔️ | ✔️ | ✔️

### Generative Ai

Expand All @@ -405,9 +405,9 @@ Qualcomm® AI Hub Models is licensed under BSD-3. See the [LICENSE file](../LICE
| | | | |
| **Image Generation**
| [ControlNet](https://aihub.qualcomm.com/models/controlnet_quantized) | [qai_hub_models.models.controlnet_quantized](qai_hub_models/models/controlnet_quantized/README.md) | ✔️ | ✔️ | ✔️
| [Riffusion](qai_hub_models/models/riffusion_quantized/README.md) | [qai_hub_models.models.riffusion_quantized](qai_hub_models/models/riffusion_quantized/README.md) | ✔️ | ✔️ | ✔️
| [Riffusion](https://aihub.qualcomm.com/models/riffusion_quantized) | [qai_hub_models.models.riffusion_quantized](qai_hub_models/models/riffusion_quantized/README.md) | ✔️ | ✔️ | ✔️
| [Stable-Diffusion-v1.5](https://aihub.qualcomm.com/models/stable_diffusion_v1_5_quantized) | [qai_hub_models.models.stable_diffusion_v1_5_quantized](qai_hub_models/models/stable_diffusion_v1_5_quantized/README.md) | ✔️ | ✔️ | ✔️
| [Stable-Diffusion-v2.1](qai_hub_models/models/stable_diffusion_v2_1_quantized/README.md) | [qai_hub_models.models.stable_diffusion_v2_1_quantized](qai_hub_models/models/stable_diffusion_v2_1_quantized/README.md) | ✔️ | ✔️ | ✔️
| [Stable-Diffusion-v2.1](https://aihub.qualcomm.com/models/stable_diffusion_v2_1_quantized) | [qai_hub_models.models.stable_diffusion_v2_1_quantized](qai_hub_models/models/stable_diffusion_v2_1_quantized/README.md) | ✔️ | ✔️ | ✔️
| | | | |
| **Text Generation**
| [Baichuan-7B](https://aihub.qualcomm.com/models/baichuan_7b_quantized) | [qai_hub_models.models.baichuan_7b_quantized](qai_hub_models/models/baichuan_7b_quantized/README.md) | ✔️ | ✔️ | ✔️
Expand Down
7 changes: 7 additions & 0 deletions apps/android/SemanticSegmentation/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
opencv45/native/3rdparty/libs/**/*.a filter=lfs diff=lfs merge=lfs -text
opencv45/** filter=lfs diff=lfs merge=lfs -text
snpe-release/** filter=lfs diff=lfs merge=lfs -text
app/src/main/assets/* filter=lfs diff=lfs merge=lfs -text
sdk/** filter=lfs diff=lfs merge=lfs -text
app/src/main/jniLibs/** filter=lfs diff=lfs merge=lfs -text
AIMET_4W8A_hrnet_posnet.onnx filter=lfs diff=lfs merge=lfs -text
76 changes: 76 additions & 0 deletions apps/android/SemanticSegmentation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
### Requirements

1. Java, android-sdk and sdkmanager is already set at user's end
2. User should have Linux QNN SDK in local machine.
3. ANDROID_HOME is set to android-sdk path
4. AI-Hub is properly configured with user token.


## Info
Please execute build_apk.py. This script will compile and download a model from AI-Hub and paste it in your Android Project and Generate app-debug.apk
Here, we resize the input image based on model input and gives a segmented map as output which marks every pixek into its corresponding class.

## Preprocessing


```
Bitmap scaledBitmap = Bitmap.createScaledBitmap(modelInputBitmap,inpDims_w, inpDims_h,true);
float[][][][] floatInputArray = new float[1][inpDims_h][inpDims_w][3];
for (int x = 0; x < inpDims_h; x++) {
for (int y = 0; y < inpDims_w; y++) {
int pixel = scaledBitmap.getPixel(y, x);
floatInputArray[0][x][y][0] = (((float)Color.red(pixel))/225f);
floatInputArray[0][x][y][1] = ((float)Color.green(pixel)/255f);
floatInputArray[0][x][y][2] = ((float)Color.blue(pixel)/255f);
}
}
```


## PostProcessing


```
float[] temparr = new float[outDims_w];
for (int i = 0; i < outDims_h; i++) {
for (int j = 0; j < outDims_w; j++) { // Looping through the columns
float max_val=Float.NEGATIVE_INFINITY;
float maxIndex =-1; // Initializing the max value
for (int k = 0; k < noOfClasses; k++) { // Looping through the remaining elements in the first axis
if (output[0][i][j][k] > max_val) { // Comparing the current element with the max value
maxIndex=k;
max_val = output[0][i][j][k]; // Updating the max value if the current element is large
}
}
temparr[j]=maxIndex;
}
src.put(i,0,temparr);
}
Imgproc.resize(src, dst, dst.size(), 0, 0, Imgproc.INTER_AREA);
int z=0;
for (int x = 0; x <modelInputBitmap.getHeight(); x++) {
for (int y = 0; y <modelInputBitmap.getWidth(); y++){
segMap[z++] =(int)dst.get(x, y)[0];
}
}
```

### Build App:

You have to run build_apk.py for Image Classification. It will generate superresolution-debug.apk and install it in connected device.


build_apk.py [-h] -q QNNSDK [-m MODEL_NAME] [-path MODEL_PATH]

```
options:
-h, --help show this help message and exit
-q QNNSDK, --qnnsdk QNNSDK Give path of QNN SDK (REQUIRED)
-m MODEL_NAME, --model_name MODEL_NAME Model Name (Optional)
-path MODEL_PATH, --model_path MODEL_PATH Model Path (Optional)
```
8 changes: 8 additions & 0 deletions apps/android/SemanticSegmentation/app/local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Sat Jan 07 01:53:02 IST 2023
sdk.dir=C\:\\Users\\shubgoya\\AppData\\Local\\Android\\Sdk
21 changes: 21 additions & 0 deletions apps/android/SemanticSegmentation/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
41 changes: 41 additions & 0 deletions apps/android/SemanticSegmentation/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.qcom.aihub_segmentation">

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<application
android:configChanges="orientation|screenSize"
android:extractNativeLibs="true"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<uses-native-library
android:name="libcdsprpc.so"
android:required="true"/>

<uses-native-library
android:name="libOpenCL.so"
android:required="true"/>

<activity android:name="com.qcom.aihub_segmentation.HomeScreenActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name="com.qcom.aihub_segmentation.MainActivity"
android:screenOrientation="portrait">
</activity>
</application>

</manifest>
Git LFS file not shown
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4c5f865

Please sign in to comment.