Skip to content

Commit

Permalink
[Android] add fastdeploy android sdk download task (PaddlePaddle#646)
Browse files Browse the repository at this point in the history
* [Bug Fix] fix android app detail page errors

* [Android] fix realtime camera mode and shutter

* [Bug Fix] fix AllocateSegmentationResultFromJava error

* [Bug Fix] fix camera preview size setting problem

* [Model] use uint8 buffer instead of fp32 in ppseg postprocess

* [Model] revert changes in ppseg

* [Model] revert postprocess changes in ppseg

* [Android] add fastdeploy android sdk download task
  • Loading branch information
DefTruth authored Nov 21, 2022
1 parent eeae48d commit 7ceb082
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 25 deletions.
77 changes: 61 additions & 16 deletions java/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,58 +25,103 @@ android {
}

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'
implementation 'com.android.support:design:28.0.0'
implementation 'org.jetbrains:annotations:15.0'
implementation project(path: ':fastdeploy')
//noinspection GradleDependency
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

def archives = [
def FD_MODEL = [
[
'src': 'https://bj.bcebos.com/paddlehub/fastdeploy/picodet_s_320_coco_lcnet.tgz',
'dest' : 'src/main/assets/models'
'src' : 'https://bj.bcebos.com/paddlehub/fastdeploy/picodet_s_320_coco_lcnet.tgz',
'dest': 'src/main/assets/models'
],
[
'src': 'https://bj.bcebos.com/paddlehub/fastdeploy/picodet_l_320_coco_lcnet.tgz',
'dest' : 'src/main/assets/models'
'src' : 'https://bj.bcebos.com/paddlehub/fastdeploy/picodet_l_320_coco_lcnet.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 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)
messageDigest.update(model.src.bytes)
String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
// Download the target archive if not exists
boolean copyFiles = !file("${archive.dest}").exists()
boolean copyFiles = !file("${model.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
println "Downloading ${model.src} -> ${cachePath}/${cacheName}.tgz"
ant.get(src: model.src, dest: file("${cachePath}/${cacheName}.tgz"))
copyFiles = true
// force to copy files from the latest archive files
}
// Extract the target archive if its dest path does not exists
if (copyFiles) {
println "Coping ${cachePath}/${cacheName}.aar -> ${model.dest}"
copy {
from tarTree("${cachePath}/${cacheName}.tgz")
into "${archive.dest}"
into "${model.dest}"
}
}
}
}
}

task downloadAndExtractSDKs(type: DefaultTask) {
doFirst {
println "Downloading and extracting fastdeploy android java sdk ..."
}
doLast {
// Prepare cache folder for archives
String cachePath = "cache"
if (!file("${cachePath}").exists()) {
mkdir "${cachePath}"
}
FD_JAVA_SDK.eachWithIndex { sdk, index ->
String[] sdkPaths = sdk.src.split("/")
// e.g fastdeploy-android-sdk-latest-dev.aar
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
// force to copy files from the latest downloaded sdk
}
// Copy the target archive if its dest path does not exists
if (copyFiles) {
println "Coping ${cachePath}/${sdkName} -> ${sdk.dest}/${sdkName}"
copy {
from "${cachePath}/${sdkName}"
into "${sdk.dest}"
}
}
}
}
}
preBuild.dependsOn downloadAndExtractArchives

preBuild.dependsOn downloadAndExtractSDKs
preBuild.dependsOn downloadAndExtractModels
2 changes: 1 addition & 1 deletion java/android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<!-- facedet values ... -->
<string name="FACEDET_MODEL_DIR_DEFAULT">models/scrfd_500m_bnkps_shape320x320_pd</string>
<!-- segmentation values ... -->
<string name="SEGMENTATION_MODEL_DIR_DEFAULT">models/portrait_pp_humansegv2_lite_256x144_inference_model</string>
<string name="SEGMENTATION_MODEL_DIR_DEFAULT">models/human_pp_humansegv1_lite_192x192_inference_model</string>
<!-- Other resources values-->
<string name="action_bar_take_photo">拍照识别</string>
<string name="action_bar_realtime">实时识别</string>
Expand Down
18 changes: 10 additions & 8 deletions java/android/fastdeploy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

def archives = [
def FD_CXX_LIB = [
[
'src' : 'https://bj.bcebos.com/fastdeploy/test/fastdeploy-android-latest-shared-dev.tgz',
'dest': 'libs'
Expand All @@ -53,32 +53,34 @@ def archives = [

task downloadAndExtractLibs(type: DefaultTask) {
doFirst {
println "Downloading and extracting archives including libs ..."
println "Downloading and extracting fastdeploy android c++ lib ..."
}
doLast {
// Prepare cache folder for archives
String cachePath = "cache"
if (!file("${cachePath}").exists()) {
mkdir "${cachePath}"
}
archives.eachWithIndex { archive, index ->
FD_CXX_LIB.eachWithIndex { lib, index ->
MessageDigest messageDigest = MessageDigest.getInstance('MD5')
messageDigest.update(archive.src.bytes)
messageDigest.update(lib.src.bytes)
String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
// Download the target archive if not exists
boolean copyFiles = !file("${archive.dest}").exists()
boolean copyFiles = !file("${lib.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
ant.get(src: lib.src, dest: file("${cachePath}/${cacheName}.tgz"))
copyFiles = true
// force to copy files from the latest archive files
}
// Extract the target archive if its dest path does not exists
if (copyFiles) {
copy {
from tarTree("${cachePath}/${cacheName}.tgz")
into "${archive.dest}"
into "${lib.dest}"
}
}
}
}
}

preBuild.dependsOn downloadAndExtractLibs

0 comments on commit 7ceb082

Please sign in to comment.