From 52659f4822a457ca44e0cdbd7fba878d219c47b4 Mon Sep 17 00:00:00 2001 From: Bin Li Date: Tue, 10 Jul 2018 09:56:32 +0800 Subject: [PATCH] conform android demo to new converter and docs --- docs/user_guide/advanced_usage.rst | 5 +-- docs/user_guide/basic_usage.rst | 4 +- .../{demo_app_models.yml => demo_models.yml} | 0 ...models_caffe.yml => demo_models_caffe.yml} | 0 ...o_app_models_tf.yml => demo_models_tf.yml} | 0 mace/examples/android/build.sh | 9 ++-- .../android/macelibrary/CMakeLists.txt | 21 ++++------ mace/examples/android/mobilenet.yml | 41 +++++++++++++++++++ .../python/tools/mace_engine_factory.h.jinja2 | 14 ++++--- 9 files changed, 68 insertions(+), 26 deletions(-) rename docs/user_guide/models/{demo_app_models.yml => demo_models.yml} (100%) rename docs/user_guide/models/{demo_app_models_caffe.yml => demo_models_caffe.yml} (100%) rename docs/user_guide/models/{demo_app_models_tf.yml => demo_models_tf.yml} (100%) create mode 100644 mace/examples/android/mobilenet.yml diff --git a/docs/user_guide/advanced_usage.rst b/docs/user_guide/advanced_usage.rst index 0b50a36f..1f536bff 100644 --- a/docs/user_guide/advanced_usage.rst +++ b/docs/user_guide/advanced_usage.rst @@ -22,10 +22,9 @@ in one deployment file. * **Example** - Here is an example deployment file with two models used by - `MACE Android demo application `__. + Here is an example deployment file with two models. - .. literalinclude:: models/demo_app_models.yml + .. literalinclude:: models/demo_models.yml :language: yaml diff --git a/docs/user_guide/basic_usage.rst b/docs/user_guide/basic_usage.rst index b5f2a784..84df881f 100644 --- a/docs/user_guide/basic_usage.rst +++ b/docs/user_guide/basic_usage.rst @@ -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`. diff --git a/docs/user_guide/models/demo_app_models.yml b/docs/user_guide/models/demo_models.yml similarity index 100% rename from docs/user_guide/models/demo_app_models.yml rename to docs/user_guide/models/demo_models.yml diff --git a/docs/user_guide/models/demo_app_models_caffe.yml b/docs/user_guide/models/demo_models_caffe.yml similarity index 100% rename from docs/user_guide/models/demo_app_models_caffe.yml rename to docs/user_guide/models/demo_models_caffe.yml diff --git a/docs/user_guide/models/demo_app_models_tf.yml b/docs/user_guide/models/demo_models_tf.yml similarity index 100% rename from docs/user_guide/models/demo_app_models_tf.yml rename to docs/user_guide/models/demo_models_tf.yml diff --git a/mace/examples/android/build.sh b/mace/examples/android/build.sh index a2badca3..b7b08eed 100755 --- a/mace/examples/android/build.sh +++ b/mace/examples/android/build.sh @@ -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 diff --git a/mace/examples/android/macelibrary/CMakeLists.txt b/mace/examples/android/macelibrary/CMakeLists.txt index 9f482a20..76c5e30e 100644 --- a/mace/examples/android/macelibrary/CMakeLists.txt +++ b/mace/examples/android/macelibrary/CMakeLists.txt @@ -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 diff --git a/mace/examples/android/mobilenet.yml b/mace/examples/android/mobilenet.yml new file mode 100644 index 00000000..ac5ba778 --- /dev/null +++ b/mace/examples/android/mobilenet.yml @@ -0,0 +1,41 @@ +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 diff --git a/mace/python/tools/mace_engine_factory.h.jinja2 b/mace/python/tools/mace_engine_factory.h.jinja2 index 9262dc67..e1a81753 100644 --- a/mace/python/tools/mace_engine_factory.h.jinja2 +++ b/mace/python/tools/mace_engine_factory.h.jinja2 @@ -59,6 +59,10 @@ MaceStatus CreateMaceEngineFromCode( return MaceStatus::MACE_INVALID_ARGS; } std::shared_ptr 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 %} -- GitLab