mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 00:57:33 +08:00
[Android] add fastdeploy android sdk download task (#646)
* [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
This commit is contained in:
@@ -25,20 +25,19 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.aar'], dir: 'libs')
|
||||||
implementation 'com.android.support:appcompat-v7:28.0.0'
|
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||||
//noinspection GradleDependency
|
//noinspection GradleDependency
|
||||||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||||
implementation 'com.android.support:design:28.0.0'
|
implementation 'com.android.support:design:28.0.0'
|
||||||
implementation 'org.jetbrains:annotations:15.0'
|
implementation 'org.jetbrains:annotations:15.0'
|
||||||
implementation project(path: ':fastdeploy')
|
|
||||||
//noinspection GradleDependency
|
//noinspection GradleDependency
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.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',
|
'src' : 'https://bj.bcebos.com/paddlehub/fastdeploy/picodet_s_320_coco_lcnet.tgz',
|
||||||
'dest': 'src/main/assets/models'
|
'dest': 'src/main/assets/models'
|
||||||
@@ -49,9 +48,16 @@ def archives = [
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
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 {
|
doFirst {
|
||||||
println "Downloading and extracting archives including models ..."
|
println "Downloading and extracting fastdeploy models ..."
|
||||||
}
|
}
|
||||||
doLast {
|
doLast {
|
||||||
// Prepare cache folder for archives
|
// Prepare cache folder for archives
|
||||||
@@ -59,24 +65,63 @@ task downloadAndExtractArchives(type: DefaultTask) {
|
|||||||
if (!file("${cachePath}").exists()) {
|
if (!file("${cachePath}").exists()) {
|
||||||
mkdir "${cachePath}"
|
mkdir "${cachePath}"
|
||||||
}
|
}
|
||||||
archives.eachWithIndex { archive, index ->
|
FD_MODEL.eachWithIndex { model, index ->
|
||||||
MessageDigest messageDigest = MessageDigest.getInstance('MD5')
|
MessageDigest messageDigest = MessageDigest.getInstance('MD5')
|
||||||
messageDigest.update(archive.src.bytes)
|
messageDigest.update(model.src.bytes)
|
||||||
String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
|
String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
|
||||||
// Download the target archive if not exists
|
// 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()) {
|
if (!file("${cachePath}/${cacheName}.tgz").exists()) {
|
||||||
ant.get(src: archive.src, dest: file("${cachePath}/${cacheName}.tgz"))
|
println "Downloading ${model.src} -> ${cachePath}/${cacheName}.tgz"
|
||||||
copyFiles = true // force to copy files from the latest archive files
|
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
|
// Extract the target archive if its dest path does not exists
|
||||||
if (copyFiles) {
|
if (copyFiles) {
|
||||||
|
println "Coping ${cachePath}/${cacheName}.aar -> ${model.dest}"
|
||||||
copy {
|
copy {
|
||||||
from tarTree("${cachePath}/${cacheName}.tgz")
|
from tarTree("${cachePath}/${cacheName}.tgz")
|
||||||
into "${archive.dest}"
|
into "${model.dest}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
preBuild.dependsOn downloadAndExtractArchives
|
|
||||||
|
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 downloadAndExtractSDKs
|
||||||
|
preBuild.dependsOn downloadAndExtractModels
|
@@ -35,7 +35,7 @@
|
|||||||
<!-- facedet values ... -->
|
<!-- facedet values ... -->
|
||||||
<string name="FACEDET_MODEL_DIR_DEFAULT">models/scrfd_500m_bnkps_shape320x320_pd</string>
|
<string name="FACEDET_MODEL_DIR_DEFAULT">models/scrfd_500m_bnkps_shape320x320_pd</string>
|
||||||
<!-- segmentation values ... -->
|
<!-- 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-->
|
<!-- Other resources values-->
|
||||||
<string name="action_bar_take_photo">拍照识别</string>
|
<string name="action_bar_take_photo">拍照识别</string>
|
||||||
<string name="action_bar_realtime">实时识别</string>
|
<string name="action_bar_realtime">实时识别</string>
|
||||||
|
@@ -44,7 +44,7 @@ dependencies {
|
|||||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
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',
|
'src' : 'https://bj.bcebos.com/fastdeploy/test/fastdeploy-android-latest-shared-dev.tgz',
|
||||||
'dest': 'libs'
|
'dest': 'libs'
|
||||||
@@ -53,7 +53,7 @@ def archives = [
|
|||||||
|
|
||||||
task downloadAndExtractLibs(type: DefaultTask) {
|
task downloadAndExtractLibs(type: DefaultTask) {
|
||||||
doFirst {
|
doFirst {
|
||||||
println "Downloading and extracting archives including libs ..."
|
println "Downloading and extracting fastdeploy android c++ lib ..."
|
||||||
}
|
}
|
||||||
doLast {
|
doLast {
|
||||||
// Prepare cache folder for archives
|
// Prepare cache folder for archives
|
||||||
@@ -61,24 +61,26 @@ task downloadAndExtractLibs(type: DefaultTask) {
|
|||||||
if (!file("${cachePath}").exists()) {
|
if (!file("${cachePath}").exists()) {
|
||||||
mkdir "${cachePath}"
|
mkdir "${cachePath}"
|
||||||
}
|
}
|
||||||
archives.eachWithIndex { archive, index ->
|
FD_CXX_LIB.eachWithIndex { lib, index ->
|
||||||
MessageDigest messageDigest = MessageDigest.getInstance('MD5')
|
MessageDigest messageDigest = MessageDigest.getInstance('MD5')
|
||||||
messageDigest.update(archive.src.bytes)
|
messageDigest.update(lib.src.bytes)
|
||||||
String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
|
String cacheName = new BigInteger(1, messageDigest.digest()).toString(32)
|
||||||
// Download the target archive if not exists
|
// 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()) {
|
if (!file("${cachePath}/${cacheName}.tgz").exists()) {
|
||||||
ant.get(src: archive.src, dest: file("${cachePath}/${cacheName}.tgz"))
|
ant.get(src: lib.src, dest: file("${cachePath}/${cacheName}.tgz"))
|
||||||
copyFiles = true // force to copy files from the latest archive files
|
copyFiles = true
|
||||||
|
// force to copy files from the latest archive files
|
||||||
}
|
}
|
||||||
// Extract the target archive if its dest path does not exists
|
// Extract the target archive if its dest path does not exists
|
||||||
if (copyFiles) {
|
if (copyFiles) {
|
||||||
copy {
|
copy {
|
||||||
from tarTree("${cachePath}/${cacheName}.tgz")
|
from tarTree("${cachePath}/${cacheName}.tgz")
|
||||||
into "${archive.dest}"
|
into "${lib.dest}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
preBuild.dependsOn downloadAndExtractLibs
|
preBuild.dependsOn downloadAndExtractLibs
|
Reference in New Issue
Block a user