Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wait for #2286] [SWAP] Implement inference mode #2300

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Tue Feb 14 16:37:06 KST 2023
gradle.version=7.5
Binary file not shown.
Empty file.
6 changes: 6 additions & 0 deletions Applications/Android/PicoGPTJNI/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Applications/Android/PicoGPTJNI/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Applications/Android/PicoGPTJNI/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Applications/Android/PicoGPTJNI/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

147 changes: 147 additions & 0 deletions Applications/Android/PicoGPTJNI/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 94 additions & 0 deletions Applications/Android/PicoGPTJNI/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
title: Android NNtrainer Applicaiton Sample
...

# Adnroid NNtrainer Application Sample
This is a pratical demonstration of Android NNTrainer Resnet Application with [cifar100](https://www.cs.toronto.edu/~kriz/cifar.html) data.

## How to run
Build nntrainer with `${NNTRAINER_HOME}/tools/package_android.sh` as in [Document](https://github.com/nnstreamer/nntrainer/blob/main/docs/how-to-run-example-android.md)

```bash
$ ls
api CONTRIBUTING.md index.md MAINTAINERS.md nnstreamer nntrainer.pc.in RELEASE.md
Applications debian jni meson.build nntrainer packaging test
CODE_OF_CONDUCT.md docs LICENSE meson_options.txt nntrainer.ini.in README.md tools
$
$ ./tools/package_android.sh
$ ls builddir/android_build_result
Android.mk conf examples include lib
$ ls builddir/android_build_result/libs/arm64-v8a
libcapi-nntrainer.so libccapi-nntrainer.so libc++_shared.so libnnstreamer-native.so libnntrainer.so
```

Build the jni with `{$APP_HOME}/app/src/main/jni/prepare_android_deps.sh`
```bash
$cd {$APP_HOME}/app/src/main/jni

./prepare_android_deps.sh
{$APP_HOME}/ResnetJNI/app/src/main/jni/nntrainer
[arm64-v8a] Prebuilt : libccapi-nntrainer.so <= jni/nntrainer/lib/arm64-v8a/
[arm64-v8a] Install : libccapi-nntrainer.so => libs/arm64-v8a/libccapi-nntrainer.so
[arm64-v8a] Prebuilt : libnntrainer.so <= jni/nntrainer/lib/arm64-v8a/
[arm64-v8a] Install : libnntrainer.so => libs/arm64-v8a/libnntrainer.so
[arm64-v8a] Compile++ : resnet_jni <= resnet.cpp
[arm64-v8a] Compile++ : resnet_jni <= resnet_jni.cpp
[arm64-v8a] Compile++ : resnet_jni <= dataloader.cpp
[arm64-v8a] Compile++ : resnet_jni <= image.cpp
[arm64-v8a] Prebuilt : libc++_shared.so <= <NDK>/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/
[arm64-v8a] SharedLibrary : libresnet_jni.so
[arm64-v8a] Install : libresnet_jni.so => libs/arm64-v8a/libresnet_jni.so
[arm64-v8a] Install : libc++_shared.so => libs/arm64-v8a/libc++_shared.so
```

Prepare the training data set. you can download the cifar100 and place it into asset directory.

```bash
$cd {$APP_HOME}/app/src/main/asset
$ls
test train
$ cd train/
$ ls
apple bridge cockroach hamster motorcycle plain seal table willow_tree
aquarium_fish bus couch house mountain plate shark tank wolf
baby butterfly crab kangaroo mouse poppy shrew telephone woman
bear camel crocodile keyboard mushroom porcupine skunk television worm
beaver can cup lamp oak_tree possum skyscraper tiger
bed castle dinosaur lawn_mower orange rabbit snail tractor
bee caterpillar dolphin leopard orchid raccoon snake train
beetle cattle elephant lion otter ray spider trout
bicycle chair flatfish lizard palm_tree road squirrel tulip
bottle chimpanzee forest lobster pear rocket streetcar turtle
bowl clock fox man pickup_truck rose sunflower wardrobe
boy cloud girl maple_tree pine_tree sea sweet_pepper whale

```


Build Application with gradlew.

``` bash
$cd {$APP_HOME}
$./gradlew build

> Configure project :app

> Task :app:stripDebugDebugSymbols
Unable to strip the following libraries, packaging them as they are: libc++_shared.so, libccapi-nntrainer.so, libnntrainer.so, libresnet_jni.so.

...

BUILD SUCCESSFUL in 10s
83 actionable tasks: 81 executed, 2 up-to-date

```

Install the application and run

``` bash
$adb install {$APP_HOME}/app/build/outputs/apk/debug/app-debug.apk

```

After run the application, you can run the applicaiton.
![Application](/docs/images/app_resnet.jpg?raw=true)
39 changes: 39 additions & 0 deletions Applications/Android/PicoGPTJNI/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
plugins {
id 'com.android.application'
}

android {
compileSdk 31

defaultConfig {
applicationId "com.applications.picogptjni"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
namespace 'com.applications.picogptjni'
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
21 changes: 21 additions & 0 deletions Applications/Android/PicoGPTJNI/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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.PicoGPTJNI">
<!-- android:requestLegacyExternalStorage="true" -->
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>
Loading