Using the mindspore1.0 Library and add lite test model

This commit is contained in:
gongdaguo 2020-09-17 17:09:41 +08:00
parent defd74e261
commit 1c3cf9f3f7
10 changed files with 30 additions and 21 deletions

View File

@ -22,6 +22,8 @@ inception_v1_224_quant.tflite
inception_v3_quant.tflite
inception_v4_299_quant.tflite
graph_8bit_1021_combine.tflite
lite-model_aiy_vision_classifier_insects_V1_3.tflite
lite-model_aiy_vision_classifier_plants_V1_3.tflite
lite-model_object_detection_mobile_object_labeler_v1_1.tflite
detect.tflite
ssd_mobilenet_v1_1_default_1.tflite

View File

@ -2,7 +2,7 @@
build/
mindspore/lib
app/src/main/assets/model/
app/src/main/cpp/mindspore-lite-0.7.0-minddata-arm64-cpu
app/src/main/cpp/mindspore-lite-*
output
*.ir
mindspore/ccsrc/schema/inner/*

View File

@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI})
set(MINDSPORELITE_VERSION mindspore-lite-0.7.0-minddata-arm64-cpu)
set(MINDSPORELITE_VERSION mindspore-lite-1.0.0-minddata-arm64-cpu)
# ============== Set MindSpore Dependencies. =============
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp)

View File

@ -4,7 +4,7 @@
* The libraries can be downloaded manually.
*/
def targetMindSporeInclude = "src/main/cpp/"
def mindsporeLite_Version = "mindspore-lite-0.7.0-minddata-arm64-cpu"
def mindsporeLite_Version = "mindspore-lite-1.0.0-minddata-arm64-cpu"
def targetModelFile = "src/main/assets/model/mobilenetv2.ms"
def mindSporeLibrary_arm64 = "src/main/cpp/${mindsporeLite_Version}.tar.gz"

View File

@ -243,9 +243,9 @@ bool PreProcessImageData(const LiteMat &lite_mat_bgr, LiteMat *lite_norm_mat_ptr
MS_PRINT("Crop error");
return false;
}
float means[3] = {0.485, 0.456, 0.406};
float vars[3] = {1.0 / 0.229, 1.0 / 0.224, 1.0 / 0.225};
SubStractMeanNormalize(lite_mat_cut, lite_norm_mat_cut, means, vars);
std::vector<float> means = {0.485, 0.456, 0.406};
std::vector<float> stds = {0.229, 0.224, 0.225};
SubStractMeanNormalize(lite_mat_cut, lite_norm_mat_cut, means, stds);
return true;
}

View File

@ -43,8 +43,7 @@ This object detection sample program on the Android device includes a Java layer
### Configuring MindSpore Lite Dependencies
In Android Studio, place the compiled `libmindspore-lite.so` library file (which can contain multiple compatible architectures) in the `app/libs/ARM64-V8a` (Arm64) or `app/libs/armeabi-v7a` (Arm32) directory of the application project. In the `build.gradle` file of the application, configure the compilation support of CMake, `arm64-v8a`, and `armeabi-v7a`.  
In Android studio, the compiled mindpool-lite-x.x.x-mindata-armxx-cpu package (including ` libmindspot- lite.so `The library file and related header files, which can contain multiple compatible architectures), are unzipped and placed in the 'app / SRC / main / CPP' directory of the app project, and the` build.gradle `Cmake and 'arm64-v8a' and 'armeabi-v7a' are configured in the file as follows It is shown as follows:
```
android{
defaultConfig{
@ -65,10 +64,14 @@ Create a link to the `.so` library file in the `app/CMakeLists.txt` file:
```
# Set MindSpore Lite Dependencies.
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/include/MindSpore)
set(MINDSPORELITE_VERSION mindspore-lite-1.0.0-minddata-arm64-cpu)
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION})
add_library(mindspore-lite SHARED IMPORTED )
set_target_properties(mindspore-lite PROPERTIES
IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/libs/libmindspore-lite.so")
add_library(minddata-lite SHARED IMPORTED )
set_target_properties(mindspore-lite PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/lib/libmindspore-lite.so)
set_target_properties(minddata-lite PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/lib/libminddata-lite.so)
# Link target library.
target_link_libraries(

View File

@ -62,7 +62,7 @@ app
| | └── ssd.ms # 存放模型文件
│ |
│ ├── cpp # 模型加载和预测主要逻辑封装类
| | ├── mindspore-lite-...-cpu # minspore源码编译出的调用包,包含demo jni层依赖的库文件及相关的头文件
| | ├── mindspore-lite-x.x.x-mindata-arm64-cpu # minspore源码编译出的调用包,包含demo jni层依赖的库文件及相关的头文件
| | | └── ...
│ | |
| | ├── MindSporeNetnative.cpp # MindSpore调用相关的JNI方法
@ -87,7 +87,7 @@ app
Android JNI层调用MindSpore C++ API时需要相关库文件支持。可通过MindSpore Lite[源码编译](https://www.mindspore.cn/lite/docs/zh-CN/master/deploy.html)生成`libmindspore-lite.so`库文件。
在Android Studio中将编译完成的`libmindspore-lite.so`库文件可包含多个兼容架构分别放置在APP工程的`app/libs/arm64-v8a`ARM64或`app/libs/armeabi-v7a`ARM32目录下并在app的`build.gradle`文件中配置CMake编译支持以及`arm64-v8a`和`armeabi-v7a`的编译支持,如下所示:
在Android Studio中将编译完成的mindspore-lite-X.X.X-mindata-armXX-cpu压缩包包含`libmindspore-lite.so`库文件和相关头文件可包含多个兼容架构解压之后放置在APP工程的`app/src/main/cpp`目录下并在app的`build.gradle`文件中配置CMake编译支持以及`arm64-v8a`和`armeabi-v7a`的编译支持,如下所示:
```
android{
defaultConfig{
@ -108,10 +108,14 @@ android{
```
# Set MindSpore Lite Dependencies.
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/include/MindSpore)
set(MINDSPORELITE_VERSION mindspore-lite-1.0.0-minddata-arm64-cpu)
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION})
add_library(mindspore-lite SHARED IMPORTED )
set_target_properties(mindspore-lite PROPERTIES
IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/libs/libmindspore-lite.so")
add_library(minddata-lite SHARED IMPORTED )
set_target_properties(mindspore-lite PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/lib/libmindspore-lite.so)
set_target_properties(minddata-lite PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/lib/libminddata-lite.so)
# Link target library.
target_link_libraries(

View File

@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI})
set(MINDSPORELITE_VERSION mindspore-lite-0.7.0-minddata-arm64-cpu)
set(MINDSPORELITE_VERSION mindspore-lite-1.0.0-minddata-arm64-cpu)
# ============== Set MindSpore Dependencies. =============
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp)

View File

@ -4,7 +4,7 @@
* The libraries can be downloaded manually.
*/
def targetMindSporeInclude = "src/main/cpp/"
def mindsporeLite_Version = "mindspore-lite-0.7.0-minddata-arm64-cpu"
def mindsporeLite_Version = "mindspore-lite-1.0.0-minddata-arm64-cpu"
def targetModelFile = "src/main/assets/model/ssd.ms"
def mindSporeLibrary_arm64 = "src/main/cpp/${mindsporeLite_Version}.tar.gz"

View File

@ -89,9 +89,9 @@ bool PreProcessImageData(const LiteMat &lite_mat_bgr, LiteMat *lite_norm_mat_ptr
return false;
}
float means[3] = {0.485, 0.456, 0.406};
float vars[3] = {1.0 / 0.229, 1.0 / 0.224, 1.0 / 0.225};
SubStractMeanNormalize(lite_mat_convert_float, lite_norm_mat_cut, means, vars);
std::vector<float> means = {0.485, 0.456, 0.406};
std::vector<float> stds = {0.229, 0.224, 0.225};
SubStractMeanNormalize(lite_mat_convert_float, lite_norm_mat_cut, means, stds);
return true;
}