提交 1855fe15 编写于 作者: 刘托

Merge branch 'android_demo' into 'master'

conform android demo to new converter and docs

See merge request !653
......@@ -22,10 +22,9 @@ in one deployment file.
* **Example**
Here is an example deployment file with two models used by
`MACE Android demo application <https://github.com/XiaoMi/mace/blob/master/mace/examples/android>`__.
Here is an example deployment file with two models.
.. literalinclude:: models/demo_app_models.yml
.. literalinclude:: models/demo_models.yml
:language: yaml
......
......@@ -144,12 +144,12 @@ Modify one of them and use it for your own case.
- TensorFlow
.. literalinclude:: models/demo_app_models_tf.yml
.. literalinclude:: models/demo_models_tf.yml
:language: yaml
- Caffe
.. literalinclude:: models/demo_app_models_caffe.yml
.. literalinclude:: models/demo_models_caffe.yml
:language: yaml
More details about model deployment file are in :doc:`advanced_usage`.
......
......@@ -3,10 +3,13 @@
set -e -u -o pipefail
pushd ../../../
python tools/converter.py build --config=docs/user_guide/models/demo_app_models.yml
cp -r builds/mobilenet/include mace/examples/android/macelibrary/src/main/cpp/
cp -r builds/mobilenet/lib mace/examples/android/macelibrary/src/main/cpp/
python tools/converter.py convert --config=mace/examples/android/mobilenet.yml
cp -rf builds/mobilenet/include mace/examples/android/macelibrary/src/main/cpp/
cp -rf builds/mobilenet/model mace/examples/android/macelibrary/src/main/cpp/
bash tools/build-standalone-lib.sh
cp -rf builds/lib mace/examples/android/macelibrary/src/main/cpp/
popd
......
......@@ -14,18 +14,12 @@ cmake_minimum_required(VERSION 3.4.1)
include_directories(${CMAKE_SOURCE_DIR}/)
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}")
foreach(fileStr ${static_file})
set(tmpstr ${fileStr})
MESSAGE(STATUS "FILE URL = ${tmpstr}")
endforeach()
add_library (mace_mobile_lib STATIC IMPORTED)
set_target_properties(mace_mobile_lib PROPERTIES IMPORTED_LOCATION ${tmpstr})
set(mace_file ${CMAKE_SOURCE_DIR}/src/main/cpp/lib/arm64-v8a/libmace.a)
set(mobilenet_file ${CMAKE_SOURCE_DIR}/src/main/cpp/model/mobilenet.a)
add_library (mace_lib STATIC IMPORTED)
set_target_properties(mace_lib PROPERTIES IMPORTED_LOCATION ${mace_file})
add_library (mobilenet_lib STATIC IMPORTED)
set_target_properties(mobilenet_lib PROPERTIES IMPORTED_LOCATION ${mobilenet_file})
add_library( # Sets the name of the library.
mace_mobile_jni
......@@ -55,7 +49,8 @@ find_library( # Sets the name of the path variable.
target_link_libraries( # Specifies the target library.
mace_mobile_jni
mace_mobile_lib
mace_lib
mobilenet_lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
\ No newline at end of file
library_name: mobilenet
target_abis: [arm64-v8a]
model_graph_format: code
model_data_format: code
models:
mobilenet_v1:
platform: tensorflow
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
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: 0
winograd: 0
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
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: 0
winograd: 0
......@@ -59,6 +59,10 @@ MaceStatus CreateMaceEngineFromCode(
return MaceStatus::MACE_INVALID_ARGS;
}
std::shared_ptr<NetDef> net_def;
{% if embed_model_data %}
(void)model_data_file;
const unsigned char * model_data;
{% endif %}
MaceStatus status = MaceStatus::MACE_SUCCESS;
switch (model_name_map[model_name]) {
{% for i in range(model_tags |length) %}
......@@ -66,12 +70,12 @@ MaceStatus CreateMaceEngineFromCode(
net_def = mace::{{model_tags[i]}}::CreateNet();
engine->reset(new mace::MaceEngine(device_type));
{% if embed_model_data %}
(void)model_data_file;
const unsigned char * model_data =
mace::{{model_tags[i]}}::LoadModelData();
status = (*engine)->Init(net_def.get(), input_nodes, output_nodes, model_data);
model_data = mace::{{model_tags[i]}}::LoadModelData();
status = (*engine)->Init(net_def.get(), input_nodes, output_nodes,
model_data);
{% else %}
status = (*engine)->Init(net_def.get(), input_nodes, output_nodes, model_data_file);
status = (*engine)->Init(net_def.get(), input_nodes, output_nodes,
model_data_file);
{% endif %}
break;
{% endfor %}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册