Closed qqwantu closed 3 months ago
手动更新预测库是只需要更新jar包和v7 v8的.so文件么? 如果需要手动更新模型和预测库,则可将 gradle 脚本中的 download* 接口注释即可, 将新的预测库替换至相应目录下 是哪段代码呢? import java.security.MessageDigest
download*
apply plugin: 'com.android.application'
android { compileSdkVersion 28 defaultConfig { applicationId "com.baidu.paddle.lite.demo.image_classification" minSdkVersion 15 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } }
dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:design:28.0.0' 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' implementation files('libs/PaddlePredictor.jar') }
def paddleLiteLibs = 'https://paddlelite-demo.bj.bcebos.com/libs/android/paddle_lite_libs_v2_10_gpu.tar.gz' task downloadAndExtractPaddleLiteLibs(type: DefaultTask) { doFirst { println "Downloading and extracting Paddle Lite libs" } doLast { // Prepare cache folder for libs if (!file("cache").exists()) { mkdir "cache" } // Generate cache name for libs MessageDigest messageDigest = MessageDigest.getInstance('MD5') messageDigest.update(paddleLiteLibs.bytes) String cacheName = new BigInteger(1, messageDigest.digest()).toString(32) // Download libs if (!file("cache/${cacheName}.tar.gz").exists()) { ant.get(src: paddleLiteLibs, dest: file("cache/${cacheName}.tar.gz")) } // Unpack libs if (!file("cache/${cacheName}").exists()) { copy { from tarTree("cache/${cacheName}.tar.gz") into "cache/${cacheName}" } } // Copy PaddlePredictor.jar if (!file("libs/PaddlePredictor.jar").exists()) { copy { from "cache/${cacheName}/java/PaddlePredictor.jar" into "libs" } } // Copy libpaddle_lite_jni.so for armeabi-v7a and arm64-v8a if (!file("src/main/jniLibs/armeabi-v7a/libpaddle_lite_jni.so").exists()) { copy { from "cache/${cacheName}/java/libs/armeabi-v7a/" into "src/main/jniLibs/armeabi-v7a" } } if (!file("src/main/jniLibs/arm64-v8a/libpaddle_lite_jni.so").exists()) { copy { from "cache/${cacheName}/java/libs/arm64-v8a/" into "src/main/jniLibs/arm64-v8a" } } } } preBuild.dependsOn downloadAndExtractPaddleLiteLibs
def paddleLiteModels = [ [ 'src' : 'https://paddlelite-demo.bj.bcebos.com/demo/image_classification/models/mobilenet_v1_for_cpu_v2_10.tar.gz', 'dest' : 'src/main/assets/models' ], [ 'src' : 'https://paddlelite-demo.bj.bcebos.com/demo/image_classification/models/mobilenet_v1_for_gpu.tar.gz', 'dest' : 'src/main/assets/models' ] ] task downloadAndExtractPaddleLiteModels(type: DefaultTask) { doFirst { println "Downloading and extracting Paddle Lite models" } doLast { // Prepare cache folder for models String cachePath = "cache" if (!file("${cachePath}").exists()) { mkdir "${cachePath}" } paddleLiteModels.eachWithIndex { model, index -> MessageDigest messageDigest = MessageDigest.getInstance('MD5') messageDigest.update(model.src.bytes) String cacheName = new BigInteger(1, messageDigest.digest()).toString(32) // Download the target model if not exists boolean copyFiles = !file("${model.dest}").exists() if (!file("${cachePath}/${cacheName}.tar.gz").exists()) { ant.get(src: model.src, dest: file("${cachePath}/${cacheName}.tar.gz")) copyFiles = true; // force to copy files from the latest archive files } // Copy model file if (copyFiles) { copy { from tarTree("${cachePath}/${cacheName}.tar.gz") into "${model.dest}" } } } } } preBuild.dependsOn downloadAndExtractPaddleLiteModels
You can comment out 81:preBuild.dependsOn downloadAndExtractPaddleLiteLibs and 123:preBuild.dependsOn downloadAndExtractPaddleLiteModels. Then you need to update model and the dependency libraries.
手动更新预测库是只需要更新jar包和v7 v8的.so文件么? 如果需要手动更新模型和预测库,则可将 gradle 脚本中的
download*
接口注释即可, 将新的预测库替换至相应目录下 是哪段代码呢? import java.security.MessageDigestapply plugin: 'com.android.application'
android { compileSdkVersion 28 defaultConfig { applicationId "com.baidu.paddle.lite.demo.image_classification" minSdkVersion 15 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } }
dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:design:28.0.0' 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' implementation files('libs/PaddlePredictor.jar') }
def paddleLiteLibs = 'https://paddlelite-demo.bj.bcebos.com/libs/android/paddle_lite_libs_v2_10_gpu.tar.gz' task downloadAndExtractPaddleLiteLibs(type: DefaultTask) { doFirst { println "Downloading and extracting Paddle Lite libs" } doLast { // Prepare cache folder for libs if (!file("cache").exists()) { mkdir "cache" } // Generate cache name for libs MessageDigest messageDigest = MessageDigest.getInstance('MD5') messageDigest.update(paddleLiteLibs.bytes) String cacheName = new BigInteger(1, messageDigest.digest()).toString(32) // Download libs if (!file("cache/${cacheName}.tar.gz").exists()) { ant.get(src: paddleLiteLibs, dest: file("cache/${cacheName}.tar.gz")) } // Unpack libs if (!file("cache/${cacheName}").exists()) { copy { from tarTree("cache/${cacheName}.tar.gz") into "cache/${cacheName}" } } // Copy PaddlePredictor.jar if (!file("libs/PaddlePredictor.jar").exists()) { copy { from "cache/${cacheName}/java/PaddlePredictor.jar" into "libs" } } // Copy libpaddle_lite_jni.so for armeabi-v7a and arm64-v8a if (!file("src/main/jniLibs/armeabi-v7a/libpaddle_lite_jni.so").exists()) { copy { from "cache/${cacheName}/java/libs/armeabi-v7a/" into "src/main/jniLibs/armeabi-v7a" } } if (!file("src/main/jniLibs/arm64-v8a/libpaddle_lite_jni.so").exists()) { copy { from "cache/${cacheName}/java/libs/arm64-v8a/" into "src/main/jniLibs/arm64-v8a" } } } } preBuild.dependsOn downloadAndExtractPaddleLiteLibs
def paddleLiteModels = [ [ 'src' : 'https://paddlelite-demo.bj.bcebos.com/demo/image_classification/models/mobilenet_v1_for_cpu_v2_10.tar.gz', 'dest' : 'src/main/assets/models' ], [ 'src' : 'https://paddlelite-demo.bj.bcebos.com/demo/image_classification/models/mobilenet_v1_for_gpu.tar.gz', 'dest' : 'src/main/assets/models' ] ] task downloadAndExtractPaddleLiteModels(type: DefaultTask) { doFirst { println "Downloading and extracting Paddle Lite models" } doLast { // Prepare cache folder for models String cachePath = "cache" if (!file("${cachePath}").exists()) { mkdir "${cachePath}" } paddleLiteModels.eachWithIndex { model, index -> MessageDigest messageDigest = MessageDigest.getInstance('MD5') messageDigest.update(model.src.bytes) String cacheName = new BigInteger(1, messageDigest.digest()).toString(32) // Download the target model if not exists boolean copyFiles = !file("${model.dest}").exists() if (!file("${cachePath}/${cacheName}.tar.gz").exists()) { ant.get(src: model.src, dest: file("${cachePath}/${cacheName}.tar.gz")) copyFiles = true; // force to copy files from the latest archive files } // Copy model file if (copyFiles) { copy { from tarTree("${cachePath}/${cacheName}.tar.gz") into "${model.dest}" } } } } } preBuild.dependsOn downloadAndExtractPaddleLiteModels