mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2026-04-24 01:29:57 +08:00
[Android] Add classification and ocr app examples (#676)
* Remove redundant code for segmentation. * Classification Documentation and example improvement. * Ocr Documentation and example improvement. Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com>
This commit is contained in:
@@ -6,21 +6,13 @@ android {
|
||||
compileSdk 28
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.baidu.paddle.fastdeploy"
|
||||
applicationId 'com.baidu.paddle.fastdeploy.app.examples'
|
||||
minSdkVersion 15
|
||||
//noinspection ExpiredTargetSdkVersion
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments '-DANDROID_PLATFORM=android-21', '-DANDROID_STL=c++_shared', "-DANDROID_TOOLCHAIN=clang"
|
||||
abiFilters 'armeabi-v7a', 'arm64-v8a'
|
||||
cppFlags "-std=c++11"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
@@ -30,17 +22,10 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path file('src/main/cpp/CMakeLists.txt')
|
||||
version '3.10.2'
|
||||
}
|
||||
}
|
||||
ndkVersion '20.1.5948944'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation fileTree(include: ['*.aar'], dir: 'libs')
|
||||
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||
//noinspection GradleDependency
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||
@@ -52,45 +37,81 @@ dependencies {
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
}
|
||||
|
||||
def archives = [
|
||||
def FD_MODEL = [
|
||||
[
|
||||
'src' : 'https://bj.bcebos.com/fastdeploy/release/android/fastdeploy-android-0.4.0-shared.tgz',
|
||||
'dest': 'libs'
|
||||
],
|
||||
[
|
||||
'src': 'https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV1_x0_25_infer.tgz',
|
||||
'dest' : 'src/main/assets/models'
|
||||
'src' : 'https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV1_x0_25_infer.tgz',
|
||||
'dest': 'src/main/assets/models'
|
||||
]
|
||||
]
|
||||
|
||||
task downloadAndExtractArchives(type: DefaultTask) {
|
||||
def FD_JAVA_SDK = [
|
||||
[
|
||||
'src' : 'https://bj.bcebos.com/fastdeploy/test/fastdeploy-android-sdk-latest-dev.aar',
|
||||
'dest': 'libs'
|
||||
]
|
||||
]
|
||||
|
||||
task downloadAndExtractModels(type: DefaultTask) {
|
||||
doFirst {
|
||||
println "Downloading and extracting archives including libs and models"
|
||||
println "Downloading and extracting fastdeploy models ..."
|
||||
}
|
||||
doLast {
|
||||
// Prepare cache folder for archives
|
||||
String cachePath = "cache"
|
||||
if (!file("${cachePath}").exists()) {
|
||||
mkdir "${cachePath}"
|
||||
}
|
||||
archives.eachWithIndex { archive, index ->
|
||||
FD_MODEL.eachWithIndex { model, index ->
|
||||
MessageDigest messageDigest = MessageDigest.getInstance('MD5')
|
||||
messageDigest.update(archive.src.bytes)
|
||||
String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
|
||||
// Download the target archive if not exists
|
||||
boolean copyFiles = !file("${archive.dest}").exists()
|
||||
if (!file("${cachePath}/${cacheName}.tgz").exists()) {
|
||||
ant.get(src: archive.src, dest: file("${cachePath}/${cacheName}.tgz"))
|
||||
copyFiles = true // force to copy files from the latest archive files
|
||||
messageDigest.update(model.src.bytes)
|
||||
String[] modelPaths = model.src.split("/")
|
||||
String modelName = modelPaths[modelPaths.length - 1]
|
||||
// Download the target model if not exists
|
||||
boolean copyFiles = !file("${model.dest}").exists()
|
||||
if (!file("${cachePath}/${modelName}").exists()) {
|
||||
println "Downloading ${model.src} -> ${cachePath}/${modelName}"
|
||||
ant.get(src: model.src, dest: file("${cachePath}/${modelName}"))
|
||||
copyFiles = true
|
||||
}
|
||||
// Extract the target archive if its dest path does not exists
|
||||
if (copyFiles) {
|
||||
println "Coping ${cachePath}/${modelName} -> ${model.dest}"
|
||||
copy {
|
||||
from tarTree("${cachePath}/${cacheName}.tgz")
|
||||
into "${archive.dest}"
|
||||
from tarTree("${cachePath}/${modelName}")
|
||||
into "${model.dest}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
preBuild.dependsOn downloadAndExtractArchives
|
||||
|
||||
task downloadAndExtractSDKs(type: DefaultTask) {
|
||||
doFirst {
|
||||
println "Downloading and extracting fastdeploy android java sdk ..."
|
||||
}
|
||||
doLast {
|
||||
String cachePath = "cache"
|
||||
if (!file("${cachePath}").exists()) {
|
||||
mkdir "${cachePath}"
|
||||
}
|
||||
FD_JAVA_SDK.eachWithIndex { sdk, index ->
|
||||
String[] sdkPaths = sdk.src.split("/")
|
||||
String sdkName = sdkPaths[sdkPaths.length - 1]
|
||||
// Download the target SDK if not exists
|
||||
boolean copyFiles = !file("${sdk.dest}/${sdkName}").exists()
|
||||
if (!file("${cachePath}/${sdkName}").exists()) {
|
||||
println "Downloading ${sdk.src} -> ${cachePath}/${sdkName}"
|
||||
ant.get(src: sdk.src, dest: file("${cachePath}/${sdkName}"))
|
||||
copyFiles = true
|
||||
}
|
||||
if (copyFiles) {
|
||||
println "Coping ${cachePath}/${sdkName} -> ${sdk.dest}/${sdkName}"
|
||||
copy {
|
||||
from "${cachePath}/${sdkName}"
|
||||
into "${sdk.dest}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
preBuild.dependsOn downloadAndExtractSDKs
|
||||
preBuild.dependsOn downloadAndExtractModels
|
||||
Reference in New Issue
Block a user