Skip to content

Commit 542d42a

Browse files
authored
[Android] Add PaddleClasModel android jni demo (#406)
* [Android] Add PaddleClasModel android jni demo * [Android] Add PaddleClasModel android jni demo
1 parent ea1f3e6 commit 542d42a

File tree

103 files changed

+5381
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+5381
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.DS_Store
2+
.idea
3+
.gradle
4+
.cxx
5+
cache
6+
build
7+
app/cache
8+
app/libs/fastdeploy*
9+
app/.cxx
10+
app/build
11+
app/src/main/assets/models/*
12+
app/.gradle
13+
app/.idea
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 图像分类 Android Demo 使用文档
2+
3+
- TODO
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import java.security.MessageDigest
2+
3+
apply plugin: 'com.android.application'
4+
5+
android {
6+
compileSdk 28
7+
8+
defaultConfig {
9+
applicationId "com.baidu.paddle.fastdeploy"
10+
minSdkVersion 15
11+
//noinspection ExpiredTargetSdkVersion
12+
targetSdkVersion 28
13+
versionCode 1
14+
versionName "1.0"
15+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16+
17+
externalNativeBuild {
18+
cmake {
19+
arguments '-DANDROID_PLATFORM=android-21', '-DANDROID_STL=c++_shared', "-DANDROID_TOOLCHAIN=clang"
20+
abiFilters 'armeabi-v7a', 'arm64-v8a'
21+
cppFlags "-std=c++11"
22+
}
23+
}
24+
}
25+
26+
buildTypes {
27+
release {
28+
minifyEnabled false
29+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
30+
}
31+
}
32+
33+
externalNativeBuild {
34+
cmake {
35+
path file('src/main/cpp/CMakeLists.txt')
36+
version '3.10.2'
37+
}
38+
}
39+
ndkVersion '20.1.5948944'
40+
}
41+
42+
dependencies {
43+
implementation fileTree(include: ['*.jar'], dir: 'libs')
44+
implementation 'com.android.support:appcompat-v7:28.0.0'
45+
//noinspection GradleDependency
46+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
47+
implementation 'com.android.support:design:28.0.0'
48+
implementation 'org.jetbrains:annotations:15.0'
49+
//noinspection GradleDependency
50+
testImplementation 'junit:junit:4.12'
51+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
52+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
53+
}
54+
55+
def archives = [
56+
[
57+
'src' : 'https://bj.bcebos.com/fastdeploy/release/android/fastdeploy-android-0.4.0-shared.tgz',
58+
'dest': 'libs'
59+
],
60+
[
61+
'src': 'https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV1_x0_25_infer.tgz',
62+
'dest' : 'src/main/assets/models'
63+
]
64+
]
65+
66+
task downloadAndExtractArchives(type: DefaultTask) {
67+
doFirst {
68+
println "Downloading and extracting archives including libs and models"
69+
}
70+
doLast {
71+
// Prepare cache folder for archives
72+
String cachePath = "cache"
73+
if (!file("${cachePath}").exists()) {
74+
mkdir "${cachePath}"
75+
}
76+
archives.eachWithIndex { archive, index ->
77+
MessageDigest messageDigest = MessageDigest.getInstance('MD5')
78+
messageDigest.update(archive.src.bytes)
79+
String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
80+
// Download the target archive if not exists
81+
boolean copyFiles = !file("${archive.dest}").exists()
82+
if (!file("${cachePath}/${cacheName}.tgz").exists()) {
83+
ant.get(src: archive.src, dest: file("${cachePath}/${cacheName}.tgz"))
84+
copyFiles = true // force to copy files from the latest archive files
85+
}
86+
// Extract the target archive if its dest path does not exists
87+
if (copyFiles) {
88+
copy {
89+
from tarTree("${cachePath}/${cacheName}.tgz")
90+
into "${archive.dest}"
91+
}
92+
}
93+
}
94+
}
95+
}
96+
preBuild.dependsOn downloadAndExtractArchives
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fastdeploy-*
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.baidu.paddle.fastdeploy;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.baidu.paddle.fastdeploy", appContext.getPackageName());
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.baidu.paddle.fastdeploy.examples">
4+
5+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
6+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
7+
<uses-permission android:name="android.permission.CAMERA"/>
8+
<uses-feature android:name="android.hardware.camera" />
9+
<uses-feature android:name="android.hardware.camera.autofocus" />
10+
11+
<application
12+
android:allowBackup="true"
13+
android:icon="@mipmap/ic_launcher"
14+
android:label="@string/app_name"
15+
android:roundIcon="@mipmap/ic_launcher_round"
16+
android:supportsRtl="true"
17+
android:theme="@style/AppTheme">
18+
<activity android:name="com.baidu.paddle.fastdeploy.examples.MainActivity">
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN"/>
21+
<category android:name="android.intent.category.LAUNCHER"/>
22+
</intent-filter>
23+
</activity>
24+
<activity
25+
android:name="com.baidu.paddle.fastdeploy.examples.SettingsActivity"
26+
android:label="Settings">
27+
</activity>
28+
</application>
29+
30+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
person
2+
bicycle
3+
car
4+
motorcycle
5+
airplane
6+
bus
7+
train
8+
truck
9+
boat
10+
traffic light
11+
fire hydrant
12+
stop sign
13+
parking meter
14+
bench
15+
bird
16+
cat
17+
dog
18+
horse
19+
sheep
20+
cow
21+
elephant
22+
bear
23+
zebra
24+
giraffe
25+
backpack
26+
umbrella
27+
handbag
28+
tie
29+
suitcase
30+
frisbee
31+
skis
32+
snowboard
33+
sports ball
34+
kite
35+
baseball bat
36+
baseball glove
37+
skateboard
38+
surfboard
39+
tennis racket
40+
bottle
41+
wine glass
42+
cup
43+
fork
44+
knife
45+
spoon
46+
bowl
47+
banana
48+
apple
49+
sandwich
50+
orange
51+
broccoli
52+
carrot
53+
hot dog
54+
pizza
55+
donut
56+
cake
57+
chair
58+
couch
59+
potted plant
60+
bed
61+
dining table
62+
toilet
63+
tv
64+
laptop
65+
mouse
66+
remote
67+
keyboard
68+
cell phone
69+
microwave
70+
oven
71+
toaster
72+
sink
73+
refrigerator
74+
book
75+
clock
76+
vase
77+
scissors
78+
teddy bear
79+
hair drier
80+
toothbrush

0 commit comments

Comments
 (0)