提交 3e20b7af 编写于 作者: B Bin Li

android demo build docs and script

上级 021e765a
# The name of library
library_name: library_name
target_abis: [armeabi-v7a, arm64-v8a]
# The soc serialno of specific device.
# Get by command `adb shell getprop | grep ro.board.platform | cut -d [ -f3 | cut -d ] -f1`.
target_socs: [msm8998]
library_name: mobilenet
target_abis: [arm64-v8a]
embed_model_data: 1
# The build mode for model(s).
# 'code' stand for transfer model(s) into cpp code, 'proto' for model(s) in protobuf file(s).
build_type: code
linkshared: 1
linkshared: 0
# One yaml config file can contain multi models' config message.
models:
model_name: # model tag, which will be used in model loading and must be specific.
mobilenet_v1: # model tag, which will be used in model loading and must be specific.
platform: tensorflow
model_file_path: path/to/model64.pb # also support http:// and https://
model_sha256_checksum: 7f7462333406e7dea87222737590ebb7d94490194d2f21a7d72bafa87e64e9f9
# support local path, http:// and https://
model_file_path: https://cnbj1.fds.api.xiaomi.com/mace/miai-models/mobilenet-v1/mobilenet-v1-1.0.pb
model_sha256_checksum: 71b10f540ece33c49a7b51f5d4095fc9bd78ce46ebf0300487b2ee23d71294e6
subgraphs:
- input_tensors: input_node
input_shapes: 1,64,64,3
output_tensors: output_node
output_shapes: 1,64,64,2
runtime: gpu
data_type: fp16_fp32
- input_tensors: input
input_shapes: 1,224,224,3
output_tensors: MobilenetV1/Predictions/Reshape_1
output_shapes: 1,1001
runtime: cpu+gpu
limit_opencl_kernel_time: 0
nnlib_graph_mode: 0
obfuscate: 1
obfuscate: 0
winograd: 0
input_files:
- path/to/input_files # support http://
second_net:
platform: caffe
model_file_path: path/to/model.prototxt
weight_file_path: path/to/weight.caffemodel
model_sha256_checksum: 05d92625809dc9edd6484882335c48c043397aed450a168d75eb8b538e86881a
weight_sha256_checksum: 05d92625809dc9edd6484882335c48c043397aed450a168d75eb8b538e86881a
mobilenet_v2:
platform: tensorflow
model_file_path: https://cnbj1.fds.api.xiaomi.com/mace/miai-models/mobilenet-v2/mobilenet-v2-1.0.pb
model_sha256_checksum: 369f9a5f38f3c15b4311c1c84c032ce868da9f371b5f78c13d3ea3c537389bb4
subgraphs:
- input_tensors:
- input_node0
- input_node1
input_shapes:
- 1,256,256,3
- 1,128,128,3
output_tensors:
- output_node0
- output_node1
output_shapes:
- 1,256,256,2
- 1,1,1,2
validation_inputs_data:
- path/to/input_files # support http://
runtime: cpu
limit_opencl_kernel_time: 1
- input_tensors: input
input_shapes: 1,224,224,3
output_tensors: MobilenetV2/Predictions/Reshape_1
output_shapes: 1,1001
runtime: cpu+gpu
limit_opencl_kernel_time: 0
nnlib_graph_mode: 0
obfuscate: 1
obfuscate: 0
winograd: 0
Android Demo
------------
------------
Try it by downloading the [APK](https://cnbj1.fds.api.xiaomi.com/mace/demo/mace_android_demo.apk).
How to build
---------------
* Build native library, please refer to [docs](docs) for more information.
```
# Execute following commands from the project's root directory
python tools/converter.py build --config=docs/getting_started/models/demo_app_models.yaml
cp -r build/mobilenet/include/ mace/examples/android/macelibrary/src/main/cpp/
cp -r build/mobilenet/lib/ mace/examples/android/macelibrary/src/main/cpp/
```
* Build APK
* Import the `mace/examples/android` directory as a new Android Studio project and select `install run`
* Or build it with gradle:
```
cd mace/exampls/android
./gradlew installAppRelease
```
* You can also build native library and APK with `mace/examples/android/build.sh`
```
cd mace/exampls/android
./build.sh
```
# mace demo使用方法
* 使用前需要生成静态库和头文件,具体参考[文档](docs)
* 把mace/public目录下的mace.h和mace_runtime.h拷贝到macelibrary/src/main/cpp/include下面
* 把生成的mace/codegen/engine/mace_engine_factory.h拷贝到macelibrary/src/main/cpp/include下面
* 静态库的路径是在mace/build/demo_app_models/lib/下
* 使用android studio 导入项目,然后运行install run
* 还可以使用gradle命令(需要安装gradle)生成apk 具体命令例如:./gradlew assemble(或者Release|Debug)
## 交流与反馈
* 欢迎通过Github Issues提交问题报告与建议
* QQ群: 756046893
## License
[Apache License 2.0](LICENSE).
package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0
# It is necessary to use this filegroup rather than globbing the files in this
# folder directly the examples/android:tensorflow_demo target due to the fact
# that assets_dir is necessarily set to "" there (to allow using other
# arbitrary targets as assets).
filegroup(
name = "asset_files",
srcs = glob(
["**/*"],
exclude = ["BUILD"],
),
)
......@@ -17,7 +17,7 @@ package com.xiaomi.mace.demo.result;
public class ResultData {
public String name;
public float probability;
public long costTime; //毫秒
public long costTime; // ms
public ResultData(String name, float probability) {
this.name = name;
......
#!/usr/bin/env bash
set -e -u -o pipefail
pushd ../../../
python tools/converter.py build --config=docs/getting_started/models/demo_app_models.yaml
cp -r build/mobilenet/include/ mace/examples/android/macelibrary/src/main/cpp/
cp -r build/mobilenet/lib/ mace/examples/android/macelibrary/src/main/cpp/
popd
./gradlew installAppRelease
......@@ -13,7 +13,8 @@ cmake_minimum_required(VERSION 3.4.1)
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../app/libs/${ANDROID_ABI})
include_directories(${CMAKE_SOURCE_DIR}/)
file(GLOB static_file ${CMAKE_SOURCE_DIR}/../../../build/demo_app_models/lib/arm64-v8a/*.a)
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/include)
file(GLOB static_file ${CMAKE_SOURCE_DIR}/src/main/cpp/lib/arm64-v8a/*.a)
MESSAGE(STATUS "FILE URL = ${CMAKE_SOURCE_DIR}")
MESSAGE(STATUS "FILE URL = ${static_file}")
......
......@@ -25,9 +25,9 @@
#include <vector>
#include <numeric>
#include "src/main/cpp/include/mace.h"
#include "src/main/cpp/include/mace_runtime.h"
#include "src/main/cpp/include/mace_engine_factory.h"
#include "src/main/cpp/include/mace/public/mace.h"
#include "src/main/cpp/include/mace/public/mace_runtime.h"
#include "src/main/cpp/include/mace/public/mace_engine_factory.h"
namespace {
......@@ -45,9 +45,9 @@ struct MaceContext {
mace::DeviceType device_type = mace::DeviceType::CPU;
std::map<std::string, ModelInfo> model_infos = {
{"mobilenet_v1", {"input", "MobilenetV1/Predictions/Reshape_1",
{1, 224, 224, 3}, {1, 1, 1, 1001}}},
{1, 224, 224, 3}, {1, 1001}}},
{"mobilenet_v2", {"input", "MobilenetV2/Predictions/Reshape_1",
{1, 224, 224, 3}, {1, 1, 1, 1001}}}
{1, 224, 224, 3}, {1, 1001}}}
};
};
......@@ -146,11 +146,11 @@ Java_com_xiaomi_mace_JniMaceUtils_maceMobilenetCreateEngine(
mace::MaceStatus create_engine_status =
CreateMaceEngineFromCode(mace_context.model_name,
std::string(),
input_names,
output_names,
mace_context.device_type,
&mace_context.engine);
std::string(),
input_names,
output_names,
mace_context.device_type,
&mace_context.engine);
__android_log_print(ANDROID_LOG_ERROR,
"image_classify attrs",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册