-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PaddlePaddle Hackathon 2] task 62 PP-TinyPose Demo #250
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.gradle/ | ||
.idea/ | ||
.vscode/ | ||
app/.cxx/ | ||
app/OpenCV/ | ||
app/PaddleLite*/ | ||
app/build/ | ||
app/cache/ | ||
app/src/main/assets/ | ||
local.properties |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# PP-Tiny-Pose Demo 使用指南 | ||
在 Android 上实现实时的Pose关键点的检测功能 | ||
|
||
|
||
## 如何运行 Demo | ||
|
||
## 要求 | ||
* Android | ||
* 在本地环境安装好 Android Studio 工具,详细安装方法请见[Android Stuido 官网](https://developer.android.com/studio) | ||
* Android手机或开发版,NPU的功能暂时只在nova5、mate30和mate30 5G上进行了测试,用户可自行尝试其它搭载了麒麟810和990芯片的华为手机(如nova5i pro、mate30 pro、荣耀v30,mate40或p40,且需要将系统更新到最新版) | ||
* 打开 Android 手机的 USB 调试模式,开启方法: `手机设置 -> 查找开发者选项 -> 打开开发者选项和 USB 调试模式` | ||
|
||
**注意**:如果您的 Android Studio 尚未配置 NDK ,请根据 Android Studio 用户指南中的[安装及配置 NDK 和 CMake ](https://developer.android.com/studio/projects/install-ndk)内容,预先配置好 NDK 。您可以选择最新的 NDK 版本,或者使用 | ||
Paddle Lite 预测库版本一样的 NDK | ||
|
||
## 安装 | ||
|
||
* Android | ||
* 打开 Android Studio,在 "Welcome to Android Studio" 窗口点击 "Open an existing Android Studio project",在弹出的路径选择窗口中进入 "face_keypoints_detection_demo" 目录,然后点击右下角的 "Open" 按钮即可导入工程 | ||
* 通过 USB 连接 Android 手机或开发板; | ||
* 载入工程后,点击菜单栏的 Run->Run `App` 按钮,在弹出的 "Select Deployment Target" 窗口选择已经连接的 Android 设备,然后点击 "OK" 按钮; | ||
* 由于 Demo 所用到的库和模型均通过 `app/build.gradle` 脚本在线下载,因此,第一次编译耗时较长(取决于网络下载速度),请耐心等待; | ||
* 如果库和模型下载失败,建议手动下载并拷贝到相应目录下 | ||
|
||
<p align="center"> | ||
<img src="./images/run_app.jpg"/> | ||
</p> | ||
|
||
> **注意:** | ||
>> 如果您在导入项目、编译或者运行过程中遇到 NDK 配置错误的提示,请打开 ` File > Project Structure > SDK Location`,修改 `Andriod NDK location` 为您本机配置的 NDK 所在路径。 | ||
>> 如果您是通过 Andriod Studio 的 SDK Tools 下载的 NDK (见本章节"环境准备"),可以直接点击下拉框选择默认路径。 | ||
>> 还有一种 NDK 配置方法,你可以在 `face_keypoints_detection_demo/local.properties` 文件中手动完成 NDK 路径配置,如下图所示 | ||
>> 如果以上步骤仍旧无法解决 NDK 配置错误,请尝试根据 Andriod Studio 官方文档中的[更新 Android Gradle 插件](https://developer.android.com/studio/releases/gradle-plugin?hl=zh-cn#updating-plugin)章节,尝试更新Android Gradle plugin版本。 | ||
|
||
|
||
## 更新到PaddleLite-2.11-rc | ||
|
||
下载PaddleLite-2.11-rc.zip,并解压到项目目录。解压后目录应该如下所示。 | ||
|
||
``` | ||
├── app | ||
│ ├── build.gradle | ||
│ ├── PaddleLite-2.11-rc | ||
│ │ ├── include | ||
│ │ │ ├── paddle_api.h | ||
│ │ │ ├── paddle_image_preprocess.h | ||
│ │ │ ├── paddle_lite_factory_helper.h | ||
│ │ │ ├── paddle_place.h | ||
│ │ │ ├── paddle_use_kernels.h | ||
│ │ │ ├── paddle_use_ops.h | ||
│ │ │ └── paddle_use_passes.h | ||
│ │ └── lib | ||
│ │ └── libpaddle_light_api_shared.so | ||
│ └── src | ||
... | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import java.security.MessageDigest | ||
|
||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
defaultConfig { | ||
applicationId "com.baidu.paddle.lite.demo.face_keypoints_detection_demo" | ||
minSdkVersion 15 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
externalNativeBuild { | ||
cmake { | ||
arguments '-DANDROID_PLATFORM=android-23', '-DANDROID_STL=c++_shared', "-DANDROID_TOOLCHAIN=" | ||
abiFilters 'arm64-v8a' | ||
cppFlags "-std=c++11 -mfpu=neon" | ||
} | ||
} | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
externalNativeBuild { | ||
cmake { | ||
path "src/main/cpp/CMakeLists.txt" | ||
version "3.10.2" | ||
} | ||
} | ||
} | ||
|
||
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' | ||
} | ||
|
||
def archives = [ | ||
[ | ||
'src' : 'https://paddlelite-demo.bj.bcebos.com/libs/android/paddle_lite_libs_v2_10_rc.tar.gz', | ||
'dest': 'PaddleLite' | ||
], | ||
[ | ||
'src' : 'https://paddlelite-demo.bj.bcebos.com/libs/android/opencv-4.2.0-android-sdk.tar.gz', | ||
'dest': 'OpenCV' | ||
], | ||
[ | ||
'src' : 'https://paddlelite-demo.bj.bcebos.com/models/ultra_light_fast_generic_face_detector_1mb_640_for_cpu_v2_10_rc.tar.gz', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这些模型有使用吗?么有话,可以删除 |
||
'dest' : 'src/main/assets/models/face_detector_for_cpu' | ||
], | ||
[ | ||
'src' : 'https://paddlelite-demo.bj.bcebos.com/models/facekeypoints_detector_fp32_60_60_for_cpu_v2_10_rc.tar.gz', | ||
'dest' : 'src/main/assets/models/facekeypoints_detector_for_cpu' | ||
] | ||
] | ||
|
||
task downloadAndExtractArchives(type: DefaultTask) { | ||
doFirst { | ||
println "Downloading and extracting archives including libs and models" | ||
} | ||
doLast { | ||
// Prepare cache folder for archives | ||
String cachePath = "cache" | ||
if (!file("${cachePath}").exists()) { | ||
mkdir "${cachePath}" | ||
} | ||
archives.eachWithIndex { archive, 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}.tar.gz").exists()) { | ||
ant.get(src: archive.src, dest: file("${cachePath}/${cacheName}.tar.gz")) | ||
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}.tar.gz") | ||
into "${archive.dest}" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
preBuild.dependsOn downloadAndExtractArchives |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.baidu.paddle.lite.demo.face_keypoints_detection"> | ||
|
||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.CAMERA"/> | ||
<uses-feature android:name="android.hardware.camera" /> | ||
<uses-feature android:name="android.hardware.camera.autofocus" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".SettingsActivity" | ||
android:label="Settings"> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# For more information about using CMake with Android Studio, read the | ||
# documentation: https://d.android.com/studio/projects/add-native-code.html | ||
|
||
# Sets the minimum version of CMake required to build the native library. | ||
|
||
cmake_minimum_required(VERSION 3.4.1) | ||
|
||
# Creates and names a library, sets it as either STATIC or SHARED, and provides | ||
# the relative paths to its source code. You can define multiple libraries, and | ||
# CMake builds them for you. Gradle automatically packages shared libraries with | ||
# your APK. | ||
|
||
set(PaddleLite_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../PaddleLite-2.11-rc") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议目录名由PaddleLite-2.11-rc 改为PaddleLite |
||
include_directories(${PaddleLite_DIR}/include) | ||
|
||
set(OpenCV_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../OpenCV/sdk/native/jni") | ||
find_package(OpenCV REQUIRED) | ||
message(STATUS "OpenCV libraries: ${OpenCV_LIBS}") | ||
include_directories(${OpenCV_INCLUDE_DIRS}) | ||
|
||
set(CMAKE_CXX_FLAGS | ||
"${CMAKE_CXX_FLAGS} -ffast-math -Ofast -Os -DNDEBUG -fno-exceptions -fomit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables" | ||
) | ||
set(CMAKE_CXX_FLAGS | ||
"${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -fdata-sections -ffunction-sections" | ||
) | ||
set(CMAKE_SHARED_LINKER_FLAGS | ||
"${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,-z,nocopyreloc") | ||
|
||
add_library( | ||
# Sets the name of the library. | ||
Native | ||
# Sets the library as a shared library. | ||
SHARED | ||
# Provides a relative path to your source file(s). | ||
Native.cc postprocess.cc Detector.cc Detector_Kpts.cc Pipeline.cc Utils.cc) | ||
|
||
find_library( | ||
# Sets the name of the path variable. | ||
log-lib | ||
# Specifies the name of the NDK library that you want CMake to locate. | ||
log) | ||
|
||
add_library( | ||
# Sets the name of the library. | ||
paddle_light_api_shared | ||
# Sets the library as a shared library. | ||
SHARED | ||
# Provides a relative path to your source file(s). | ||
IMPORTED) | ||
|
||
set_target_properties( | ||
# Specifies the target library. | ||
paddle_light_api_shared | ||
# Specifies the parameter you want to define. | ||
PROPERTIES | ||
IMPORTED_LOCATION | ||
${PaddleLite_DIR}/lib/libpaddle_light_api_shared.so | ||
# Provides the path to the library you want to import. | ||
) | ||
|
||
# Specifies libraries CMake should link to your target library. You can link | ||
# multiple libraries, such as libraries you define in this build script, | ||
# prebuilt third-party libraries, or system libraries. | ||
|
||
target_link_libraries( | ||
# Specifies the target library. | ||
Native | ||
paddle_light_api_shared | ||
${OpenCV_LIBS} | ||
GLESv2 | ||
EGL | ||
${log-lib}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 加个空行 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块内容辛苦补充下,并展示运行效果示意图