diff --git a/official/lite/README_CN.md b/official/lite/README_CN.md new file mode 100644 index 0000000000000000000000000000000000000000..8701e8e6230a53b947a0316a786270d3326cadad --- /dev/null +++ b/official/lite/README_CN.md @@ -0,0 +1,3 @@ +# 娉ㄦ剰浜嬮」 + +## 涓轰簡璁╁紑鍙戣€呮洿濂藉湴浣撻獙MindSpore锛孉ndroid瀹㈡埛绔晶鐨勫浘鍍忓垎绫籟image_classification]鍜岀尗鐙楀垎绫籟pet_classification]鐨凙PP搴旂敤缁熶竴绾冲叆Vision APP搴旂敤涓娿€傜敤鎴峰彲鍓嶅線浣撻獙[Vision APP](https://gitee.com/mindspore/vision/tree/master/android) diff --git a/official/lite/image_classification/.gitignore b/official/lite/image_classification/.gitignore deleted file mode 100644 index 836b944df63a11110d1f58d0f6364fd662a4d1a5..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/.gitignore +++ /dev/null @@ -1,83 +0,0 @@ -# MindSpore -build/ -mindspore/lib -app/src/main/assets/model/ -app/src/main/cpp/mindspore-lite-* -output -*.ir -mindspore/ccsrc/schema/inner/* - -# Cmake files -CMakeFiles/ -cmake_install.cmake -CMakeCache.txt -Makefile -cmake-build-debug - -# Dynamic libraries -*.so -*.so.* -*.dylib - -# Static libraries -*.la -*.lai -*.a -*.lib - -# Protocol buffers -*_pb2.py -*.pb.h -*.pb.cc - -# Object files -*.o - -# Editor -.vscode -.idea/ - -# Cquery -.cquery_cached_index/ -compile_commands.json - -# Ctags and cscope -tags -TAGS -CTAGS -GTAGS -GRTAGS -GSYMS -GPATH -cscope.* - -# Python files -*__pycache__* -.pytest_cache - -# Mac files -*.DS_Store - -# Test results -test_temp_summary_event_file/ -*.dot -*.dat -*.svg -*.perf -*.info -*.ckpt -*.shp -*.pkl -.clangd -mindspore/version.py -mindspore/default_config.py -mindspore/.commit_id -onnx.proto -mindspore/ccsrc/onnx.proto - -# Android -local.properties -.gradle -sdk/build -sdk/.cxx -app/.cxx diff --git a/official/lite/image_classification/README.en.md b/official/lite/image_classification/README.en.md deleted file mode 100644 index 575c6d8633b52ded691f76f72675be5af653ed1d..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/README.en.md +++ /dev/null @@ -1,332 +0,0 @@ -# Demo of Image Classification - -The following describes how to use the MindSpore Lite C++ APIs (Android JNIs) and MindSpore Lite image classification models to perform on-device inference, classify the content captured by a device camera, and display the most possible classification result on the application's image preview screen. -> The purpose of this sample program is to demonstrate how to use mindspire Lite API to complete inference. The effect of image classification depends on the model and the data set used in model training, which is not the focus of this sample program. - -## Running Dependencies - -- Android Studio 3.2 or later (Android 4.0 or later is recommended.) - -## Building and Running - -1. Load the sample source code to Android Studio. - -  - - Start Android Studio, click `File > Settings > System Settings > Android SDK`, and select the corresponding `SDK Tools`. As shown in the following figure, select an SDK and click `OK`. Android Studio automatically installs the SDK. - -  - - > Android SDK Tools is the default installation. You can see this by unchecking the `Hide Obsolete Packages`box. - > - > If you have any Android Studio configuration problem when trying this demo, please refer to item 4 to resolve it. - -2. Connect to an Android device and runs this application. - - Connect to the Android device through a USB cable for debugging. Click `Run 'app'` to run the sample project on your device. - -  - - > Android Studio will automatically download MindSpore Lite, model files and other dependencies during the compilation process. Please be patient during this process. - > - > For details about how to connect the Android Studio to a device for debugging, see <https://developer.android.com/studio/run/device?hl=zh-cn>. - > - > The mobile phone needs to be turn on "USB debugging mode" before Android Studio can recognize the mobile phone. Huawei mobile phones generally turn on "USB debugging model" in Settings -> system and update -> developer Options -> USB debugging. - -3. Continue the installation on the Android device. After the installation is complete, you can view the content captured by a camera and the inference result. - -  - -4. The solutions of configuration problems: - - 4.1 Problems of NDK, CMake, JDK Tools: - - If the tools installed in Android Studio are not recognized, you can re-download and install them from the corresponding official website, and configure the path. - - - NDK >= 21.3 [NDK](https://developer.android.google.cn/ndk/downloads?hl=zh-cn) - - CMake >= 3.10.2 [CMake](https://cmake.org/download) - - Android SDK >= 26 [SDK](https://developer.microsoft.com/zh-cn/windows/downloads/windows-10-sdk/) - - JDK >= 1.8 [JDK](http://jdk.java.net) - -  - - 4.2 NDK version does not match: - - Open `Android SDK`, click `Show Package Details`, and select the appropriate NDK version according to the error message. -  - - 4.3 Problem of Android Studio version: - - Update the Android Studio version in `Toolbar - Help - Checkout for Updates`. - - 4.4 Gradle dependencies installed too slowly: - - As shown in the picture, open the Demo root directory `build. Gradle` file, then add huawei mirror source address: `maven {url 'https://developer.huawei.com/repo/'}`, modify the classpath to 4.0.0 and click ` sync ` . Once the download is complete, restore the classpath version and synchronize it again. - -## Detailed Description of the Sample Program - -This image classification sample program on the Android device includes a Java layer and a JNI layer. At the Java layer, the Android Camera 2 API is used to enable a camera to obtain image frames and process images. At the JNI layer, the model inference process is completed in [Runtime](https://www.mindspore.cn/lite/docs/en/master/use/runtime.html). - -### Sample Program Structure - -```text -app -鈹� -鈹溾攢鈹€ src/main -鈹� 鈹溾攢鈹€ assets # resource files -| | 鈹斺攢鈹€ mobilenetv2.ms # model file -鈹� | -鈹� 鈹溾攢鈹€ cpp # main logic encapsulation classes for model loading and prediction -| | | -| | 鈹溾攢鈹€ mindspore_lite_x.x.x-runtime-arm64-cpu #MindSpore Lite Version -| | 鈹溾攢鈹€ MindSporeNetnative.cpp # JNI methods related to MindSpore calling -鈹� | 鈹斺攢鈹€ MindSporeNetnative.h # header file -鈹� | -鈹� 鈹溾攢鈹€ java # application code at the Java layer -鈹� 鈹� 鈹斺攢鈹€ com.mindspore.classification -鈹� 鈹� 鈹溾攢鈹€ gallery.classify # implementation related to image processing and MindSpore JNI calling -鈹� 鈹� 鈹� 鈹斺攢鈹€ ... -鈹� 鈹� 鈹斺攢鈹€ widget # implementation related to camera enabling and drawing -鈹� 鈹� 鈹斺攢鈹€ ... -鈹� 鈹� -鈹� 鈹溾攢鈹€ res # resource files related to Android -鈹� 鈹斺攢鈹€ AndroidManifest.xml # Android configuration file -鈹� -鈹溾攢鈹€ CMakeList.txt # CMake compilation entry file -鈹� -鈹溾攢鈹€ build.gradle # Other Android configuration file -鈹溾攢鈹€ download.gradle # MindSpore version download -鈹斺攢鈹€ ... -``` - -### Configuring MindSpore Lite Dependencies - -When MindSpore C++ APIs are called at the Android JNI layer, related library files are required. You can use MindSpore Lite [source code compilation](https://www.mindspore.cn/lite/docs/en/master/use/build.html) to generate the MindSpore Lite version. In this case, you need to use the compile command of generate with image preprocessing module. - -In this example, the build process automatically downloads the `mindspore-lite-1.0.1-runtime-arm64-cpu` by the `app/download.gradle` file and saves in the `app/src/main/cpp` directory. - -Note: if the automatic download fails, please manually download the relevant library files and put them in the corresponding location. - -mindspore-lite-1.1.1-runtime-arm64-cpu.tar.gz [Download link](https://ms-release.obs.cn-north-4.myhuaweicloud.com/1.1.1/MindSpore/lite/release_0220/android/mindspore-lite-1.1.1-runtime-arm64-cpu.tar.gz) - -```text -android{ - defaultConfig{ - externalNativeBuild{ - cmake{ - arguments "-DANDROID_STL=c++_shared" - cppFlags "-std=c++17 -fexceptions -frtti" - } - } - - ndk{ - abiFilters'armeabi-v7a', 'arm64-v8a' - } - } -} -``` - -Create a link to the `.so` library file in the `app/CMakeLists.txt` file: - -```text -# ============== Set MindSpore Dependencies. ============= -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp) -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}) -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/include) - -add_library(mindspore-lite SHARED IMPORTED) -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}/minddata/lib/libminddata-lite.so) -# --------------- MindSpore Lite set End. -------------------- - -# Link target library. -target_link_libraries( - ... - # --- mindspore --- - minddata-lite - mindspore-lite - ... -) -``` - -### Downloading and Deploying a Model File - -In this example, the download.gradle File configuration auto download `mobilenetv2.ms`and placed in the 'app/libs/arm64-v8a' directory. - -Note: if the automatic download fails, please manually download the relevant library files and put them in the corresponding location. - -mobilenetv2.ms [mobilenetv2.ms]( https://download.mindspore.cn/model_zoo/official/lite/mobilenetv2_openimage_lite/mobilenetv2.ms) - -### Compiling On-Device Inference Code - -Call MindSpore Lite C++ APIs at the JNI layer to implement on-device inference. - -The inference code process is as follows. For details about the complete code, see `src/cpp/MindSporeNetnative.cpp`. - -1. Load the MindSpore Lite model file and build the context, session, and computational graph for inference. - - - Load a model file. Create and configure the context for model inference. - - ```cpp - // Buffer is the model data passed in by the Java layer - jlong bufferLen = env->GetDirectBufferCapacity(buffer); - char *modelBuffer = CreateLocalModelBuffer(env, buffer); - ``` - - - Create a session. - - ```cpp - void **labelEnv = new void *; - MSNetWork *labelNet = new MSNetWork; - *labelEnv = labelNet; - - // Create context. - mindspore::lite::Context *context = new mindspore::lite::Context; - context->thread_num_ = num_thread; - - // Create the mindspore session. - labelNet->CreateSessionMS(modelBuffer, bufferLen, "device label", context); - delete(context); - - ``` - - - Load the model file and build a computational graph for inference. - - ```cpp - void MSNetWork::CreateSessionMS(char* modelBuffer, size_t bufferLen, std::string name, mindspore::lite::Context* ctx) - { - CreateSession(modelBuffer, bufferLen, ctx); - session = mindspore::session::LiteSession::CreateSession(ctx); - auto model = mindspore::lite::Model::Import(modelBuffer, bufferLen); - int ret = session->CompileGraph(model); - } - ``` - -2. Convert the input image into the Tensor format of the MindSpore model. - - Convert the image data to be detected into the Tensor format of the MindSpore model. - - ```cpp - if (!BitmapToLiteMat(env, srcBitmap, &lite_mat_bgr)) { - MS_PRINT("BitmapToLiteMat error"); - return NULL; - } - if (!PreProcessImageData(lite_mat_bgr, &lite_norm_mat_cut)) { - MS_PRINT("PreProcessImageData error"); - return NULL; - } - - ImgDims inputDims; - inputDims.channel = lite_norm_mat_cut.channel_; - inputDims.width = lite_norm_mat_cut.width_; - inputDims.height = lite_norm_mat_cut.height_; - - // Get the mindsore inference environment which created in loadModel(). - void **labelEnv = reinterpret_cast<void **>(netEnv); - if (labelEnv == nullptr) { - MS_PRINT("MindSpore error, labelEnv is a nullptr."); - return NULL; - } - MSNetWork *labelNet = static_cast<MSNetWork *>(*labelEnv); - - auto mSession = labelNet->session(); - if (mSession == nullptr) { - MS_PRINT("MindSpore error, Session is a nullptr."); - return NULL; - } - MS_PRINT("MindSpore get session."); - - auto msInputs = mSession->GetInputs(); - if (msInputs.size() == 0) { - MS_PRINT("MindSpore error, msInputs.size() equals 0."); - return NULL; - } - auto inTensor = msInputs.front(); - - float *dataHWC = reinterpret_cast<float *>(lite_norm_mat_cut.data_ptr_); - // Copy dataHWC to the model input tensor. - memcpy(inTensor->MutableData(), dataHWC, - inputDims.channel * inputDims.width * inputDims.height * sizeof(float)); - ``` - -3. Perform inference on the input tensor based on the model, obtain the output tensor, and perform post-processing. - - - Perform graph execution and on-device inference. - - ```cpp - // After the model and image tensor data is loaded, run inference. - auto status = mSession->RunGraph(); - ``` - - - Obtain the output data. - - ```cpp - auto names = mSession->GetOutputTensorNames(); - std::unordered_map<std::string,mindspore::tensor::MSTensor *> msOutputs; - for (const auto &name : names) { - auto temp_dat =mSession->GetOutputByTensorName(name); - msOutputs.insert(std::pair<std::string, mindspore::tensor::MSTensor *> {name, temp_dat}); - } - std::string retStr = ProcessRunnetResult(msOutputs, ret); - ``` - - - Perform post-processing of the output data. - - ```cpp - std::string ProcessRunnetResult(const int RET_CATEGORY_SUM, const char *const labels_name_map[], - std::unordered_map<std::string, mindspore::tensor::MSTensor *> msOutputs) { - // Get the branch of the model output. - // Use iterators to get map elements. - std::unordered_map<std::string, mindspore::tensor::MSTensor *>::iterator iter; - iter = msOutputs.begin(); - - // The mobilenetv2.ms model output just one branch. - auto outputTensor = iter->second; - - int tensorNum = outputTensor->ElementsNum(); - MS_PRINT("Number of tensor elements:%d", tensorNum); - - // Get a pointer to the first score. - float *temp_scores = static_cast<float *>(outputTensor->MutableData()); - float scores[RET_CATEGORY_SUM]; - for (int i = 0; i < RET_CATEGORY_SUM; ++i) { - scores[i] = temp_scores[i]; - } - - float unifiedThre = 0.5; - float probMax = 1.0; - for (size_t i = 0; i < RET_CATEGORY_SUM; ++i) { - float threshold = g_thres_map[i]; - float tmpProb = scores[i]; - if (tmpProb < threshold) { - tmpProb = tmpProb / threshold * unifiedThre; - } else { - tmpProb = (tmpProb - threshold) / (probMax - threshold) * unifiedThre + unifiedThre; - } - scores[i] = tmpProb; - } - - for (int i = 0; i < RET_CATEGORY_SUM; ++i) { - if (scores[i] > 0.5) { - MS_PRINT("MindSpore scores[%d] : [%f]", i, scores[i]); - } - } - - // Score for each category. - // Converted to text information that needs to be displayed in the APP. - std::string categoryScore = ""; - for (int i = 0; i < RET_CATEGORY_SUM; ++i) { - categoryScore += labels_name_map[i]; - categoryScore += ":"; - std::string score_str = std::to_string(scores[i]); - categoryScore += score_str; - categoryScore += ";"; - } - return categoryScore; - } - - ``` diff --git a/official/lite/image_classification/README.md b/official/lite/image_classification/README.md deleted file mode 100644 index 665780a78056e35afed5290e9209273a886fc008..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/README.md +++ /dev/null @@ -1,346 +0,0 @@ -# MindSpore Lite 绔晶鍥惧儚鍒嗙被demo锛圓ndroid锛� - -鏈ず渚嬬▼搴忔紨绀轰簡濡備綍鍦ㄧ渚у埄鐢∕indSpore Lite C++ API锛圓ndroid JNI锛変互鍙奙indSpore Lite 鍥惧儚鍒嗙被妯″瀷瀹屾垚绔晶鎺ㄧ悊锛屽疄鐜板璁惧鎽勫儚澶存崟鑾风殑鍐呭杩涜鍒嗙被锛屽苟鍦ˋpp鍥惧儚棰勮鐣岄潰涓樉绀哄嚭鏈€鍙兘鐨勫垎绫荤粨鏋溿€� -> 鏈ず渚嬬▼搴忕洰鐨勬槸婕旂ず濡備綍浣跨敤MindSpore Lite API瀹屾垚鎺ㄧ悊锛屽浘鍍忓垎绫绘晥鏋滃彇鍐充簬妯″瀷浠ュ強妯″瀷璁粌浣跨敤鐨勬暟鎹泦锛屼笉鏄湰绀轰緥绋嬪簭鐨勯噸鐐广€� - -## 杩愯渚濊禆 - -- Android Studio >= 3.2 (鎺ㄨ崘4.0浠ヤ笂鐗堟湰) - -## 鏋勫缓涓庤繍琛� - -1. 鍦ˋndroid Studio涓姞杞芥湰绀轰緥婧愮爜銆� - -  - - 鍚姩Android Studio鍚庯紝鐐瑰嚮`File->Settings->System Settings->Android SDK`锛屽嬀閫夌浉搴旂殑`SDK Tools`銆傚涓嬪浘鎵€绀猴紝鍕鹃€夊悗锛岀偣鍑籤OK`锛孉ndroid Studio鍗冲彲鑷姩瀹夎SDK銆� - -  - - > Android SDK Tools涓洪粯璁ゅ畨瑁呴」锛屽彇娑坄Hide Obsolete Packages`閫夋涔嬪悗鍙湅鍒般€� - > - > 浣跨敤杩囩▼涓嫢鍑虹幇闂锛屽彲鍙傝€冪4椤硅В鍐炽€� - -2. 杩炴帴Android璁惧锛岃繍琛岃搴旂敤绋嬪簭銆� - - 閫氳繃USB杩炴帴Android鎵嬫満銆傚緟鎴愬姛璇嗗埆鍒拌澶囧悗锛岀偣鍑籤Run 'app'`鍗冲彲鍦ㄦ偍鐨勬墜鏈轰笂杩愯鏈ず渚嬮」鐩€� - - > 缂栬瘧杩囩▼涓瑼ndroid Studio浼氳嚜鍔ㄤ笅杞組indSpore Lite銆佹ā鍨嬫枃浠剁瓑鐩稿叧渚濊禆椤癸紝缂栬瘧杩囩▼闇€鍋氳€愬績绛夊緟銆� - > - > Android Studio杩炴帴璁惧璋冭瘯鎿嶄綔锛屽彲鍙傝€�<https://developer.android.com/studio/run/device?hl=zh-cn>銆� - > - > 鎵嬫満闇€寮€鍚€淯SB璋冭瘯妯″紡鈥濓紝Android Studio 鎵嶈兘璇嗗埆鍒版墜鏈恒€� 鍗庝负鎵嬫満涓€鑸湪璁剧疆->绯荤粺鍜屾洿鏂�->寮€鍙戜汉鍛橀€夐」->USB璋冭瘯涓紑濮嬧€淯SB璋冭瘯妯″瀷鈥濄€� - -  - -3. 鍦ˋndroid璁惧涓婏紝鐐瑰嚮鈥滅户缁畨瑁呪€濓紝瀹夎瀹屽嵆鍙煡鐪嬪埌璁惧鎽勫儚澶存崟鑾风殑鍐呭鍜屾帹鐞嗙粨鏋溿€� - -  - - 濡備笅鍥炬墍绀猴紝璇嗗埆鍑虹殑姒傜巼鏈€楂樼殑鐗╀綋鏄鐗┿€� - -  - -4. Demo閮ㄧ讲闂瑙e喅鏂规銆� - - 4.1 NDK銆丆Make銆丣DK绛夊伐鍏烽棶棰橈細 - - 濡傛灉Android Studio鍐呭畨瑁呯殑宸ュ叿鍑虹幇鏃犳硶璇嗗埆绛夐棶棰橈紝鍙噸鏂颁粠鐩稿簲瀹樼綉涓嬭浇鍜屽畨瑁咃紝骞堕厤缃矾寰勩€� - - - NDK >= 21.3 [NDK](https://developer.android.google.cn/ndk/downloads?hl=zh-cn) - - CMake >= 3.10.2 [CMake](https://cmake.org/download) - - Android SDK >= 26 [SDK](https://developer.microsoft.com/zh-cn/windows/downloads/windows-10-sdk/) - - JDK >= 1.8 [JDK](http://jdk.java.net) - -  - - 4.2 NDK鐗堟湰涓嶅尮閰嶉棶棰橈細 - - 鎵撳紑`Android SDK`锛岀偣鍑籤Show Package Details`锛屾牴鎹姤閿欎俊鎭€夋嫨瀹夎鍚堥€傜殑NDK鐗堟湰銆� -  - - 4.3 Android Studio鐗堟湰闂锛� - - 鍦╜宸ュ叿鏍�-help-Checkout for Updates`涓洿鏂癆ndroid Studio鐗堟湰銆� - - 4.4 Gradle涓嬩緷璧栭」瀹夎杩囨參闂锛� - - 濡傚浘鎵€绀猴紝 鎵撳紑Demo鏍圭洰褰曚笅`build.gradle`鏂囦欢锛屽姞鍏ュ崕涓洪暅鍍忔簮鍦板潃锛歚maven {url 'https://developer.huawei.com/repo/'}`锛屼慨鏀筩lasspath涓�4.0.0锛岀偣鍑籤sync`杩涜鍚屾銆備笅杞藉畬鎴愬悗锛屽皢classpath鐗堟湰澶嶅師锛屽啀娆¤繘琛屽悓姝ャ€� -  - -## 绀轰緥绋嬪簭璇︾粏璇存槑 - -鏈渚у浘鍍忓垎绫籄ndroid绀轰緥绋嬪簭鍒嗕负JAVA灞傚拰JNI灞傦紝鍏朵腑锛孞AVA灞備富瑕侀€氳繃Android Camera 2 API瀹炵幇鎽勫儚澶磋幏鍙栧浘鍍忓抚锛屼互鍙婄浉搴旂殑鍥惧儚澶勭悊绛夊姛鑳斤紱JNI灞傚畬鎴愭ā鍨嬫帹鐞嗙殑杩囩▼銆� - -> 姝ゅ璇︾粏璇存槑绀轰緥绋嬪簭鐨凧NI灞傚疄鐜帮紝JAVA灞傝繍鐢ˋndroid Camera 2 API瀹炵幇寮€鍚澶囨憚鍍忓ご浠ュ強鍥惧儚甯у鐞嗙瓑鍔熻兘锛岄渶璇昏€呭叿澶囦竴瀹氱殑Android寮€鍙戝熀纭€鐭ヨ瘑銆� - -### 绀轰緥绋嬪簭缁撴瀯 - -```text -app -鈹溾攢鈹€ src/main -鈹� 鈹溾攢鈹€ assets # 璧勬簮鏂囦欢 -| | 鈹斺攢鈹€ mobilenetv2.ms # 瀛樻斁妯″瀷鏂囦欢 -鈹� | -鈹� 鈹溾攢鈹€ cpp # 妯″瀷鍔犺浇鍜岄娴嬩富瑕侀€昏緫灏佽绫� -| | 鈹溾攢鈹€ .. -| | 鈹溾攢鈹€ mindspore_lite_x.x.x-runtime-arm64-cpu #MindSpore Lite鐗堟湰 -| | 鈹溾攢鈹€ MindSporeNetnative.cpp # MindSpore璋冪敤鐩稿叧鐨凧NI鏂规硶 -鈹� | 鈹斺攢鈹€ MindSporeNetnative.h # 澶存枃浠� -| | 鈹斺攢鈹€ MsNetWork.cpp # MindSpre鎺ュ彛灏佽 -鈹� | -鈹� 鈹溾攢鈹€ java # java灞傚簲鐢ㄤ唬鐮� -鈹� 鈹� 鈹斺攢鈹€ com.mindspore.classification -鈹� 鈹� 鈹溾攢鈹€ gallery.classify # 鍥惧儚澶勭悊鍙奙indSpore JNI璋冪敤鐩稿叧瀹炵幇 -鈹� 鈹� 鈹� 鈹斺攢鈹€ ... -鈹� 鈹� 鈹斺攢鈹€ widget # 寮€鍚憚鍍忓ご鍙婄粯鍒剁浉鍏冲疄鐜� -鈹� 鈹� 鈹斺攢鈹€ ... -鈹� 鈹� -鈹� 鈹溾攢鈹€ res # 瀛樻斁Android鐩稿叧鐨勮祫婧愭枃浠� -鈹� 鈹斺攢鈹€ AndroidManifest.xml # Android閰嶇疆鏂囦欢 -鈹� -鈹溾攢鈹€ CMakeList.txt # cmake缂栬瘧鍏ュ彛鏂囦欢 -鈹� -鈹溾攢鈹€ build.gradle # 鍏朵粬Android閰嶇疆鏂囦欢 -鈹溾攢鈹€ download.gradle # 宸ョ▼渚濊禆鏂囦欢涓嬭浇 -鈹斺攢鈹€ ... -``` - -### 閰嶇疆MindSpore Lite渚濊禆椤� - -Android JNI灞傝皟鐢∕indSpore C++ API鏃讹紝闇€瑕佺浉鍏冲簱鏂囦欢鏀寔銆傚彲閫氳繃MindSpore Lite[婧愮爜缂栬瘧](https://www.mindspore.cn/lite/docs/zh-CN/master/use/build.html)鐢熸垚`mindspore-lite-{version}-minddata-{os}-{device}.tar.gz`搴撴枃浠跺寘骞惰В鍘嬬缉锛堝寘鍚玚libmindspore-lite.so`搴撴枃浠跺拰鐩稿叧澶存枃浠讹級锛屽湪鏈緥涓渶浣跨敤鐢熸垚甯﹀浘鍍忛澶勭悊妯″潡鐨勭紪璇戝懡浠ゃ€� - -> version锛氳緭鍑轰欢鐗堟湰鍙凤紝涓庢墍缂栬瘧鐨勫垎鏀唬鐮佸搴旂殑鐗堟湰涓€鑷淬€� -> -> device锛氬綋鍓嶅垎涓篶pu锛堝唴缃瓹PU绠楀瓙锛夊拰gpu锛堝唴缃瓹PU鍜孏PU绠楀瓙锛夈€� -> -> os锛氳緭鍑轰欢搴旈儴缃茬殑鎿嶄綔绯荤粺銆� - -鏈ず渚嬩腑锛宐uild杩囩▼鐢眃ownload.gradle鏂囦欢鑷姩涓嬭浇MindSpore Lite 鐗堟湰鏂囦欢锛屽苟鏀剧疆鍦╜app/src/main/cpp/`鐩綍涓嬨€� - -> 鑻ヨ嚜鍔ㄤ笅杞藉け璐ワ紝璇锋墜鍔ㄤ笅杞界浉鍏冲簱鏂囦欢锛岃В鍘嬪苟鏀惧湪瀵瑰簲浣嶇疆锛� - - mindspore-lite-1.1.1-runtime-arm64-cpu.tar.gz [涓嬭浇閾炬帴](https://ms-release.obs.cn-north-4.myhuaweicloud.com/1.1.1/MindSpore/lite/release_0220/android/mindspore-lite-1.1.1-runtime-arm64-cpu.tar.gz) - -鍦╝pp鐨刞build.gradle`鏂囦欢涓厤缃瓹Make缂栬瘧鏀寔锛屼互鍙奰arm64-v8a`鐨勭紪璇戞敮鎸侊紝濡備笅鎵€绀猴細 - -```text -android{ - defaultConfig{ - externalNativeBuild{ - cmake{ - arguments "-DANDROID_STL=c++_shared" - cppFlags "-std=c++17 -fexceptions -frtti" - } - } - - ndk{ - abiFilters 'arm64-v8a' - } - } -} -``` - -鍦╜app/CMakeLists.txt`鏂囦欢涓缓绔媊.so`搴撴枃浠堕摼鎺ワ紝濡備笅鎵€绀恒€� - -```text -# ============== Set MindSpore Dependencies. ============= -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp) -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}) -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/include) - -add_library(mindspore-lite SHARED IMPORTED) -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}/minddata/lib/libminddata-lite.so) -# --------------- MindSpore Lite set End. -------------------- - -# Link target library. -target_link_libraries( - ... - # --- mindspore --- - minddata-lite - mindspore-lite - ... -) -``` - -### 涓嬭浇鍙婇儴缃叉ā鍨嬫枃浠� - -浠嶮indSpore Model Hub涓笅杞芥ā鍨嬫枃浠讹紝鏈ず渚嬬▼搴忎腑浣跨敤鐨勭粓绔浘鍍忓垎绫绘ā鍨嬫枃浠朵负`mobilenetv2.ms`锛屽悓鏍烽€氳繃download.gradle鑴氭湰鍦ˋPP鏋勫缓鏃惰嚜鍔ㄤ笅杞斤紝骞舵斁缃湪`app/src/main/assets`宸ョ▼鐩綍涓嬨€� - -> 鑻ヤ笅杞藉け璐ヨ鎵嬪姩涓嬭浇妯″瀷鏂囦欢锛宮obilenetv2.ms [涓嬭浇閾炬帴](https://download.mindspore.cn/model_zoo/official/lite/mobilenetv2_openimage_lite/mobilenetv2.ms)銆� - -### 缂栧啓绔晶鎺ㄧ悊浠g爜 - -鍦↗NI灞傝皟鐢∕indSpore Lite C++ API瀹炵幇绔祴鎺ㄧ悊銆� - -鎺ㄧ悊浠g爜娴佺▼濡備笅锛屽畬鏁翠唬鐮佽鍙傝`src/cpp/MindSporeNetnative.cpp`銆� - -1. 鍔犺浇MindSpore Lite妯″瀷鏂囦欢锛屾瀯寤轰笂涓嬫枃銆佷細璇濅互鍙婄敤浜庢帹鐞嗙殑璁$畻鍥俱€� - - - 鍔犺浇妯″瀷鏂囦欢锛氬垱寤哄苟閰嶇疆鐢ㄤ簬妯″瀷鎺ㄧ悊鐨勪笂涓嬫枃 - - ```cpp - // Buffer is the model data passed in by the Java layer - jlong bufferLen = env->GetDirectBufferCapacity(buffer); - char *modelBuffer = CreateLocalModelBuffer(env, buffer); - ``` - - - 鍒涘缓浼氳瘽 - - ```cpp - void **labelEnv = new void *; - MSNetWork *labelNet = new MSNetWork; - *labelEnv = labelNet; - - // Create context. - lite::Context *context = new lite::Context; - context->thread_num_ = numThread; //Specify the number of threads to run inference - - // Create the mindspore session. - labelNet->CreateSessionMS(modelBuffer, bufferLen, context); - delete(context); - - ``` - - - 鍔犺浇妯″瀷鏂囦欢骞舵瀯寤虹敤浜庢帹鐞嗙殑璁$畻鍥� - - ```cpp - void MSNetWork::CreateSessionMS(char* modelBuffer, size_t bufferLen, std::string name, mindspore::lite::Context* ctx) - { - CreateSession(modelBuffer, bufferLen, ctx); - session = mindspore::session::LiteSession::CreateSession(ctx); - auto model = mindspore::lite::Model::Import(modelBuffer, bufferLen); - int ret = session->CompileGraph(model); - } - ``` - -2. 灏嗚緭鍏ュ浘鐗囪浆鎹负浼犲叆MindSpore妯″瀷鐨凾ensor鏍煎紡銆� - - 灏嗗緟妫€娴嬪浘鐗囨暟鎹浆鎹负杈撳叆MindSpore妯″瀷鐨凾ensor銆� - - ```cpp - if (!BitmapToLiteMat(env, srcBitmap, &lite_mat_bgr)) { - MS_PRINT("BitmapToLiteMat error"); - return NULL; - } - if (!PreProcessImageData(lite_mat_bgr, &lite_norm_mat_cut)) { - MS_PRINT("PreProcessImageData error"); - return NULL; - } - - ImgDims inputDims; - inputDims.channel = lite_norm_mat_cut.channel_; - inputDims.width = lite_norm_mat_cut.width_; - inputDims.height = lite_norm_mat_cut.height_; - - // Get the mindsore inference environment which created in loadModel(). - void **labelEnv = reinterpret_cast<void **>(netEnv); - if (labelEnv == nullptr) { - MS_PRINT("MindSpore error, labelEnv is a nullptr."); - return NULL; - } - MSNetWork *labelNet = static_cast<MSNetWork *>(*labelEnv); - - auto mSession = labelNet->session(); - if (mSession == nullptr) { - MS_PRINT("MindSpore error, Session is a nullptr."); - return NULL; - } - MS_PRINT("MindSpore get session."); - - auto msInputs = mSession->GetInputs(); - if (msInputs.size() == 0) { - MS_PRINT("MindSpore error, msInputs.size() equals 0."); - return NULL; - } - auto inTensor = msInputs.front(); - - float *dataHWC = reinterpret_cast<float *>(lite_norm_mat_cut.data_ptr_); - // Copy dataHWC to the model input tensor. - memcpy(inTensor->MutableData(), dataHWC, - inputDims.channel * inputDims.width * inputDims.height * sizeof(float)); - ``` - -3. 瀵硅緭鍏ensor鎸夌収妯″瀷杩涜鎺ㄧ悊锛岃幏鍙栬緭鍑篢ensor锛屽苟杩涜鍚庡鐞嗐€� - - - 鍥炬墽琛岋紝绔祴鎺ㄧ悊銆� - - ```cpp - // After the model and image tensor data is loaded, run inference. - auto status = mSession->RunGraph(); - ``` - - - 鑾峰彇杈撳嚭鏁版嵁銆� - - ```cpp - auto names = mSession->GetOutputTensorNames(); - std::unordered_map<std::string,mindspore::tensor::MSTensor *> msOutputs; - for (const auto &name : names) { - auto temp_dat =mSession->GetOutputByTensorName(name); - msOutputs.insert(std::pair<std::string, mindspore::tensor::MSTensor *> {name, temp_dat}); - } - std::string resultStr = ProcessRunnetResult(::RET_CATEGORY_SUM, - ::labels_name_map, msOutputs); - ``` - - - 杈撳嚭鏁版嵁鐨勫悗缁鐞嗐€� - - ```cpp - std::string ProcessRunnetResult(const int RET_CATEGORY_SUM, const char *const labels_name_map[], - std::unordered_map<std::string, mindspore::tensor::MSTensor *> msOutputs) { - // Get the branch of the model output. - // Use iterators to get map elements. - std::unordered_map<std::string, mindspore::tensor::MSTensor *>::iterator iter; - iter = msOutputs.begin(); - - // The mobilenetv2.ms model output just one branch. - auto outputTensor = iter->second; - - int tensorNum = outputTensor->ElementsNum(); - MS_PRINT("Number of tensor elements:%d", tensorNum); - - // Get a pointer to the first score. - float *temp_scores = static_cast<float *>(outputTensor->MutableData()); - float scores[RET_CATEGORY_SUM]; - for (int i = 0; i < RET_CATEGORY_SUM; ++i) { - scores[i] = temp_scores[i]; - } - - float unifiedThre = 0.5; - float probMax = 1.0; - for (size_t i = 0; i < RET_CATEGORY_SUM; ++i) { - float threshold = g_thres_map[i]; - float tmpProb = scores[i]; - if (tmpProb < threshold) { - tmpProb = tmpProb / threshold * unifiedThre; - } else { - tmpProb = (tmpProb - threshold) / (probMax - threshold) * unifiedThre + unifiedThre; - } - scores[i] = tmpProb; - } - - for (int i = 0; i < RET_CATEGORY_SUM; ++i) { - if (scores[i] > 0.5) { - MS_PRINT("MindSpore scores[%d] : [%f]", i, scores[i]); - } - } - - // Score for each category. - // Converted to text information that needs to be displayed in the APP. - std::string categoryScore = ""; - for (int i = 0; i < RET_CATEGORY_SUM; ++i) { - categoryScore += labels_name_map[i]; - categoryScore += ":"; - std::string score_str = std::to_string(scores[i]); - categoryScore += score_str; - categoryScore += ";"; - } - return categoryScore; - } - - ``` diff --git a/official/lite/image_classification/app/.gitignore b/official/lite/image_classification/app/.gitignore deleted file mode 100644 index 796b96d1c402326528b4ba3c12ee9d92d0e212e9..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/official/lite/image_classification/app/CMakeLists.txt b/official/lite/image_classification/app/CMakeLists.txt deleted file mode 100644 index 5961ee99b4d0a26bbc6c4142dc637ae28a12f45f..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/CMakeLists.txt +++ /dev/null @@ -1,96 +0,0 @@ -# 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) - -set(CMAKE_VERBOSE_MAKEFILE on) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}) - -set(MINDSPORELITE_VERSION mindspore-lite-1.6.0-android-aarch64) - -# ============== Set MindSpore Dependencies. ============= -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}) -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/runtime) -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/runtime/include/api) -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/runtime/include/dataset) -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/runtime/include/dataset/lite_cv) -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/runtime/include/schema) -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/runtime/include/ir/dtype) -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/runtime/third_party) - -add_library(mindspore-lite SHARED IMPORTED) -add_library(minddata-lite SHARED IMPORTED) -add_library(libmindspore-lite-train SHARED IMPORTED) -add_library(libjpeg SHARED IMPORTED) -add_library(libturbojpeg SHARED IMPORTED) - -set_target_properties(mindspore-lite PROPERTIES IMPORTED_LOCATION - ${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/runtime/lib/libmindspore-lite.so) -set_target_properties(minddata-lite PROPERTIES IMPORTED_LOCATION - ${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/runtime/lib/libminddata-lite.so) -set_target_properties(libmindspore-lite-train PROPERTIES IMPORTED_LOCATION - ${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/runtime/lib/libmindspore-lite-train.so) -set_target_properties(libjpeg PROPERTIES IMPORTED_LOCATION - ${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/runtime/third_party/libjpeg-turbo/lib/libjpeg.so) -set_target_properties(libturbojpeg PROPERTIES IMPORTED_LOCATION - ${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/runtime/third_party/libjpeg-turbo/lib/libturbojpeg.so) - -# --------------- MindSpore Lite set End. -------------------- - - -# 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. - -file(GLOB_RECURSE cpp_src "src/main/cpp/*.cpp" "src/main/cpp/*.h") - -add_library( # Sets the name of the library. - mlkit-label-MS - - # Sets the library as a shared library. - SHARED - - # Provides a relative path to your source file(s). - ${cpp_src}) - - -# Searches for a specified prebuilt library and stores the path as a -# variable. Because CMake includes system libraries in the search path by -# default, you only need to specify the name of the public NDK library -# you want to add. CMake verifies that the library exists before -# completing its build. - -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) - - -find_library(jnigraphics-lib jnig路raphics) - -# 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. -add_definitions(-DMNN_USE_LOGCAT) -target_link_libraries( # Specifies the target library. - mlkit-label-MS - - # --- mindspore --- - minddata-lite - mindspore-lite - libmindspore-lite-train - libjpeg - libturbojpeg - - # --- other dependencies.--- - -ljnigraphics - android - - # Links the target library to the log library - ${log-lib} - ) \ No newline at end of file diff --git a/official/lite/image_classification/app/build.gradle b/official/lite/image_classification/app/build.gradle deleted file mode 100644 index db3f6d37af9cfa4faefe23390b4a081a6ff00868..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/build.gradle +++ /dev/null @@ -1,78 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 30 - buildToolsVersion "30.0.1" - - defaultConfig { - applicationId "com.mindspore.classification" - minSdkVersion 21 - targetSdkVersion 30 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - externalNativeBuild { - cmake { - arguments "-DANDROID_STL=c++_shared" - cppFlags "-std=c++17 -fexceptions -frtti" - } - } - ndk { - abiFilters 'arm64-v8a' - } - } - aaptOptions { - noCompress '.so', 'ms' - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - - customDebugType { - debuggable true - } - } - externalNativeBuild { - cmake { - path file('CMakeLists.txt') - } - } - ndkVersion '21.3.6528147' - - sourceSets{ - main { - jniLibs.srcDirs = ['libs'] - } - } - packagingOptions{ - pickFirst 'lib/arm64-v8a/libmlkit-label-MS.so' - } - -} - - - -// Before gradle build. -// To download some necessary libraries. -apply from:'download.gradle' - - - -dependencies { - implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' -// implementation project(path: ':sdk') - - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test.ext:junit:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - - implementation 'com.google.android.material:material:1.0.0' - androidTestImplementation 'com.android.support.test:rules:1.0.2' - androidTestImplementation 'com.google.truth:truth:1.0.1' -} diff --git a/official/lite/image_classification/app/download.gradle b/official/lite/image_classification/app/download.gradle deleted file mode 100644 index 715c04160ea29a2ca29920a8540122cc75663f79..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/download.gradle +++ /dev/null @@ -1,82 +0,0 @@ -/** - * To download necessary library from HuaWei server. - * Including mindspore-lite .so file, minddata-lite .so file and model file. - * The libraries can be downloaded manually. - */ -def targetMindSporeInclude = "src/main/cpp/" -def mindsporeLite_Version = "1.6.0" -def modle_Version = "1.6" -def mindsporeLite_android_Version = "mindspore-lite-1.6.0-android-aarch64" - -def targetModelFile = "src/main/assets/model/mobilenetv2.ms" -def mindSporeLibrary_arm64 = "src/main/cpp/${mindsporeLite_android_Version}.tar.gz" -def modelDownloadUrl = "https://download.mindspore.cn/model_zoo/official/lite/mobilenetv2_openimage_lite/${modle_Version}/mobilenetv2.ms" -def mindsporeLiteDownloadUrl = "https://ms-release.obs.cn-north-4.myhuaweicloud.com/${mindsporeLite_Version}/MindSpore/lite/android_aarch64/gpu/${mindsporeLite_android_Version}.tar.gz" -def cleantargetMindSporeInclude = "src/main/cpp" - -task cleanCmakeCache(type: Delete) { - delete '.cxx/cmake/debug' - delete '.cxx/cmake/release' -} - -task downloadModelFile(type: DownloadUrlTask) { - doFirst { - println "Downloading ${modelDownloadUrl}" - } - sourceUrl = "${modelDownloadUrl}" - target = file("${targetModelFile}") -} - -task downloadMindSporeLibrary(type: DownloadUrlTask) { - doFirst { - println "Downloading ${mindsporeLiteDownloadUrl}" - } - sourceUrl = "${mindsporeLiteDownloadUrl}" - target = file("${mindSporeLibrary_arm64}") -} - -task unzipMindSporeInclude(type: Copy, dependsOn: 'downloadMindSporeLibrary') { - doFirst { - println "Unzipping ${mindSporeLibrary_arm64}" - } - from tarTree(resources.gzip("${mindSporeLibrary_arm64}")) - into "${targetMindSporeInclude}" -} - -task cleanUnusedmindsporeFiles(type: Delete, dependsOn: ['unzipMindSporeInclude']) { - delete fileTree("${cleantargetMindSporeInclude}").matching { - include "*.tar.gz" - } -} -/* - * Using preBuild to download mindspore library and model file. - * Run before gradle build. - */ -if (file("src/main/cpp/${mindsporeLite_android_Version}/runtime/lib/libmindspore-lite.so").exists()){ - downloadMindSporeLibrary.enabled = false - unzipMindSporeInclude.enabled = false - cleanUnusedmindsporeFiles.enabled = false -} - -if (file("src/main/assets/model/mobilenetv2.ms").exists()){ - downloadModelFile.enabled = false -} - -preBuild.dependsOn cleanCmakeCache -preBuild.dependsOn downloadModelFile -preBuild.dependsOn downloadMindSporeLibrary -preBuild.dependsOn unzipMindSporeInclude -preBuild.dependsOn cleanUnusedmindsporeFiles - -class DownloadUrlTask extends DefaultTask { - @Input - String sourceUrl - - @OutputFile - File target - - @TaskAction - void download() { - ant.get(src: sourceUrl, dest: target) - } -} diff --git a/official/lite/image_classification/app/proguard-rules.pro b/official/lite/image_classification/app/proguard-rules.pro deleted file mode 100644 index 481bb434814107eb79d7a30b676d344b0df2f8ce..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/official/lite/image_classification/app/src/androidTest/java/com/mindspore/classification/ExampleInstrumentedTest.java b/official/lite/image_classification/app/src/androidTest/java/com/mindspore/classification/ExampleInstrumentedTest.java deleted file mode 100644 index 4418c07a673e120afb425c92ade5e6116909db24..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/androidTest/java/com/mindspore/classification/ExampleInstrumentedTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mindspore.classification; - -import android.content.Context; - -import androidx.test.platform.app.InstrumentationRegistry; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumented test, which will execute on an Android device. - * - * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - assertEquals("com.mindspore.classification", appContext.getPackageName()); - } -} diff --git a/official/lite/image_classification/app/src/main/AndroidManifest.xml b/official/lite/image_classification/app/src/main/AndroidManifest.xml deleted file mode 100644 index b48c6a6022b4ec3ba45913e554b810d852320e05..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.mindspore.classification" - android:versionCode="1" - android:versionName="1.0"> - - <uses-permission android:name="android.permission.CAMERA" /> - <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" /> - <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" /> - <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> - <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> - <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEM" /> - <uses-permission android:name="android.permission.READ_PHONE_STATE" /> - - <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="com.mindspore.classification.widget.CameraActivity" - android:screenOrientation="portrait"> - <intent-filter> - <action android:name="android.intent.action.MAIN" /> - <category android:name="android.intent.category.LAUNCHER" /> - </intent-filter> - </activity> - </application> - -</manifest> \ No newline at end of file diff --git a/official/lite/image_classification/app/src/main/cpp/MSNetWork.cpp b/official/lite/image_classification/app/src/main/cpp/MSNetWork.cpp deleted file mode 100644 index c321c6235b2d086516ab846520fba8a1434972a8..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/cpp/MSNetWork.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "MSNetWork.h" -#include <android/log.h> -#include <iostream> -#include <string> -#include "include/errorcode.h" - -#define MS_PRINT(format, ...) __android_log_print(ANDROID_LOG_INFO, "MSJNI", format, ##__VA_ARGS__) - -MSNetWork::MSNetWork(void) : model_(nullptr) {} - -MSNetWork::~MSNetWork(void) {} - -bool MSNetWork::BuildModel(char *modelBuffer, size_t bufferLen, - std::shared_ptr<mindspore::Context> ctx) { - model_ = std::make_shared<mindspore::Model>(); - if (model_ == nullptr) { - MS_PRINT("MindSpore build model failed!."); - return false; - } - auto ret = model_->Build(modelBuffer, bufferLen, mindspore::ModelType::kMindIR, ctx); - return ret.IsOk(); -} diff --git a/official/lite/image_classification/app/src/main/cpp/MSNetWork.h b/official/lite/image_classification/app/src/main/cpp/MSNetWork.h deleted file mode 100644 index e946c6a972e826d796533106e509dbf71e1efa7e..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/cpp/MSNetWork.h +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MSNETWORK_H -#define MSNETWORK_H - -#include <types.h> -#include <model.h> -#include <cstdio> -#include <algorithm> -#include <fstream> -#include <functional> -#include <sstream> -#include <vector> -#include <map> -#include <string> -#include <memory> -#include <utility> - -struct ImgDims { - int channel = 0; - int width = 0; - int height = 0; -}; - -class MSNetWork { - public: - MSNetWork(); - - ~MSNetWork(); - - bool BuildModel(char *modelBuffer, size_t bufferLen, std::shared_ptr<mindspore::Context> ctx); - - std::shared_ptr<mindspore::Model> model() const { return model_; } - - void ReleaseNets(void) {} - private: - std::shared_ptr<mindspore::Model> model_; -}; -#endif diff --git a/official/lite/image_classification/app/src/main/cpp/MindSporeNetnative.cpp b/official/lite/image_classification/app/src/main/cpp/MindSporeNetnative.cpp deleted file mode 100644 index 5f5c354df8b19d094baa47f191fed0b76b860326..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/cpp/MindSporeNetnative.cpp +++ /dev/null @@ -1,487 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include <jni.h> -#include <android/bitmap.h> -#include <android/asset_manager_jni.h> -#include <android/log.h> -#include <utility> -#include <cstring> -#include <vector> -#include <string> -#include <unordered_map> -#include <set> -#include "include/errorcode.h" -#include "include/ms_tensor.h" -#include "MindSporeNetnative.h" -#include "MSNetWork.h" -#include "lite_cv/lite_mat.h" -#include "lite_cv/image_process.h" - -using mindspore::dataset::LiteMat; -using mindspore::dataset::LPixelType; -using mindspore::dataset::LDataType; -#define MS_PRINT(format, ...) __android_log_print(ANDROID_LOG_INFO, "MSJNI", format, ##__VA_ARGS__) - - -static const int RET_CATEGORY_SUM = 410; -static const char *labels_name_map[RET_CATEGORY_SUM] = { - "Herd", "Safari", "Bangle", "Cushion", "Countertop", - "Prom", "Branch", "Sports", "Sky", "Community", - "Wheel", "Cola", "Tuxedo", "Flowerpot", "Team", - "Computer", "Unicycle", "Brig", "Aerospace engineering", "Scuba diving", - "Goggles", "Fruit", "Badminton", "Horse", "Sunglasses", - "Fun", "Prairie", "Poster", "Flag", "Speedboat", - "Eyelash", "Veil", "Mobile phone", "Wheelbarrow", "Saucer", - "Leather", "Drawer", "Paper", "Pier", "Waterfowl", - "Tights", "Rickshaw", "Vegetable", "Handrail", "Ice", - "Metal", "Flower", "Wing", "Silverware", "Event", - "Skyline", "Money", "Comics", "Handbag", "Porcelain", - "Rodeo", "Curtain", "Tile", "Human mouth", "Army", - "Menu", "Boat", "Snowboarding", "Cairn terrier", "Net", - "Pasteles", "Cup", "Rugby", "Pho", "Cap", - "Human hair", "Surfing", "Loveseat", "Museum", "Shipwreck", - "Trunk (Tree)", "Plush", "Monochrome", "Volcano", "Rock", - "Pillow", "Presentation", "Nebula", "Subwoofer", "Lake", - "Sledding", "Bangs", "Tablecloth", "Necklace", "Swimwear", - "Standing", "Jeans", "Carnival", "Softball", "Centrepiece", - "Skateboarder", "Cake", "Dragon", "Aurora", "Skiing", - "Bathroom", "Dog", "Needlework", "Umbrella", "Church", - "Fire", "Piano", "Denim", "Bridle", "Cabinetry", - "Lipstick", "Ring", "Television", "Roller", "Seal", - "Concert", "Product", "News", "Fast food", "Horn (Animal)", - "Tattoo", "Bird", "Bridegroom", "Love", "Helmet", - "Dinosaur", "Icing", "Miniature", "Tire", "Toy", - "Icicle", "Jacket", "Coffee", "Mosque", "Rowing", - "Wetsuit", "Camping", "Underwater", "Christmas", "Gelato", - "Whiteboard", "Field", "Ragdoll", "Construction", "Lampshade", - "Palace", "Meal", "Factory", "Cage", "Clipper (Boat)", - "Gymnastics", "Turtle", "Human foot", "Marriage", "Web page", - "Human beard", "Fog", "Wool", "Cappuccino", "Lighthouse", - "Lego", "Sparkler", "Sari", "Model", "Temple", - "Beanie", "Building", "Waterfall", "Penguin", "Cave", - "Stadium", "Smile", "Human hand", "Park", "Desk", - "Shetland sheepdog", "Bar", "Eating", "Neon", "Dalmatian", - "Crocodile", "Wakeboarding", "Longboard", "Road", "Race", - "Kitchen", "Odometer", "Cliff", "Fiction", "School", - "Interaction", "Bullfighting", "Boxer", "Gown", "Aquarium", - "Superhero", "Pie", "Asphalt", "Surfboard", "Cheeseburger", - "Screenshot", "Supper", "Laugh", "Lunch", "Party ", - "Glacier", "Bench", "Grandparent", "Sink", "Pomacentridae", - "Blazer", "Brick", "Space", "Backpacking", "Stuffed toy", - "Sushi", "Glitter", "Bonfire", "Castle", "Marathon", - "Pizza", "Beach", "Human ear", "Racing", "Sitting", - "Iceberg", "Shelf", "Vehicle", "Pop music", "Playground", - "Clown", "Car", "Rein", "Fur", "Musician", - "Casino", "Baby", "Alcohol", "Strap", "Reef", - "Balloon", "Outerwear", "Cathedral", "Competition", "Joker", - "Blackboard", "Bunk bed", "Bear", "Moon", "Archery", - "Polo", "River", "Fishing", "Ferris wheel", "Mortarboard", - "Bracelet", "Flesh", "Statue", "Farm", "Desert", - "Chain", "Aircraft", "Textile", "Hot dog", "Knitting", - "Singer", "Juice", "Circus", "Chair", "Musical instrument", - "Room", "Crochet", "Sailboat", "Newspaper", "Santa claus", - "Swamp", "Skyscraper", "Skin", "Rocket", "Aviation", - "Airliner", "Garden", "Ruins", "Storm", "Glasses", - "Balance", "Nail (Body part)", "Rainbow", "Soil ", "Vacation ", - "Moustache", "Doily", "Food", "Bride ", "Cattle", - "Pocket", "Infrastructure", "Train", "Gerbil", "Fireworks", - "Pet", "Dam", "Crew", "Couch", "Bathing", - "Quilting", "Motorcycle", "Butterfly", "Sled", "Watercolor paint", - "Rafting", "Monument", "Lightning", "Sunset", "Bumper", - "Shoe", "Waterskiing", "Sneakers", "Tower", "Insect", - "Pool", "Placemat", "Airplane", "Plant", "Jungle", - "Armrest", "Duck", "Dress", "Tableware", "Petal", - "Bus", "Hanukkah", "Forest", "Hat", "Barn", - "Tubing", "Snorkeling", "Cool", "Cookware and bakeware", "Cycling", - "Swing (Seat)", "Muscle", "Cat", "Skateboard", "Star", - "Toe", "Junk", "Bicycle", "Bedroom", "Person", - "Sand", "Canyon", "Tie", "Twig", "Sphynx", - "Supervillain", "Nightclub", "Ranch", "Pattern", "Shorts", - "Himalayan", "Wall", "Leggings", "Windsurfing", "Deejay", - "Dance", "Van", "Bento", "Sleep", "Wine", - "Picnic", "Leisure", "Dune", "Crowd", "Kayak", - "Ballroom", "Selfie", "Graduation", "Frigate", "Mountain", - "Dude", "Windshield", "Skiff", "Class", "Scarf", - "Bull", "Soccer", "Bag", "Basset hound", "Tractor", - "Swimming", "Running", "Track", "Helicopter", "Pitch", - "Clock", "Song", "Jersey", "Stairs", "Flap", - "Jewellery", "Bridge", "Cuisine", "Bread", "Caving", - "Shell", "Wreath", "Roof", "Cookie", "Canoe"}; - -static float g_thres_map[RET_CATEGORY_SUM] = { - 0.23, 0.03, 0.10, 0.13, 0.03, - 0.10, 0.06, 0.09, 0.09, 0.05, - 0.01, 0.04, 0.01, 0.27, 0.05, - 0.16, 0.01, 0.16, 0.04, 0.13, - 0.09, 0.18, 0.10, 0.65, 0.08, - 0.04, 0.08, 0.01, 0.05, 0.20, - 0.01, 0.16, 0.10, 0.10, 0.10, - 0.02, 0.24, 0.08, 0.10, 0.53, - 0.07, 0.05, 0.07, 0.27, 0.02, - 0.01, 0.71, 0.01, 0.06, 0.06, - 0.03, 0.96, 0.03, 0.94, 0.05, - 0.03, 0.14, 0.09, 0.03, 0.11, - 0.50, 0.16, 0.07, 0.07, 0.06, - 0.07, 0.08, 0.10, 0.29, 0.03, - 0.05, 0.11, 0.03, 0.03, 0.03, - 0.01, 0.11, 0.07, 0.03, 0.49, - 0.12, 0.30, 0.10, 0.15, 0.02, - 0.06, 0.17, 0.01, 0.04, 0.07, - 0.06, 0.02, 0.19, 0.20, 0.14, - 0.35, 0.15, 0.01, 0.10, 0.13, - 0.43, 0.11, 0.12, 0.32, 0.01, - 0.22, 0.51, 0.02, 0.04, 0.14, - 0.04, 0.35, 0.35, 0.01, 0.54, - 0.04, 0.02, 0.03, 0.02, 0.38, - 0.13, 0.19, 0.06, 0.01, 0.02, - 0.06, 0.03, 0.04, 0.01, 0.10, - 0.01, 0.07, 0.07, 0.07, 0.33, - 0.08, 0.04, 0.06, 0.07, 0.07, - 0.11, 0.02, 0.32, 0.48, 0.14, - 0.01, 0.01, 0.04, 0.05, 0.04, - 0.16, 0.50, 0.11, 0.03, 0.04, - 0.02, 0.55, 0.17, 0.13, 0.84, - 0.18, 0.03, 0.16, 0.02, 0.06, - 0.03, 0.11, 0.96, 0.36, 0.68, - 0.02, 0.08, 0.02, 0.01, 0.03, - 0.05, 0.14, 0.09, 0.06, 0.03, - 0.20, 0.15, 0.62, 0.03, 0.10, - 0.08, 0.02, 0.02, 0.06, 0.03, - 0.04, 0.01, 0.10, 0.05, 0.04, - 0.02, 0.07, 0.03, 0.32, 0.11, - 0.03, 0.02, 0.03, 0.01, 0.03, - 0.03, 0.25, 0.20, 0.19, 0.03, - 0.11, 0.03, 0.02, 0.03, 0.15, - 0.14, 0.06, 0.11, 0.03, 0.02, - 0.02, 0.52, 0.03, 0.02, 0.02, - 0.02, 0.09, 0.56, 0.01, 0.22, - 0.01, 0.48, 0.14, 0.10, 0.08, - 0.73, 0.39, 0.09, 0.10, 0.85, - 0.31, 0.03, 0.05, 0.01, 0.01, - 0.01, 0.10, 0.28, 0.02, 0.03, - 0.04, 0.03, 0.07, 0.14, 0.20, - 0.10, 0.01, 0.05, 0.37, 0.12, - 0.04, 0.44, 0.04, 0.26, 0.08, - 0.07, 0.27, 0.10, 0.03, 0.01, - 0.03, 0.16, 0.41, 0.16, 0.34, - 0.04, 0.30, 0.04, 0.05, 0.18, - 0.33, 0.03, 0.21, 0.03, 0.04, - 0.22, 0.01, 0.04, 0.02, 0.01, - 0.06, 0.02, 0.08, 0.87, 0.11, - 0.15, 0.05, 0.14, 0.09, 0.08, - 0.22, 0.09, 0.07, 0.06, 0.06, - 0.05, 0.43, 0.70, 0.03, 0.07, - 0.06, 0.07, 0.14, 0.04, 0.01, - 0.03, 0.05, 0.65, 0.06, 0.04, - 0.23, 0.06, 0.75, 0.10, 0.01, - 0.63, 0.41, 0.09, 0.01, 0.01, - 0.18, 0.10, 0.03, 0.01, 0.05, - 0.13, 0.18, 0.03, 0.23, 0.01, - 0.04, 0.03, 0.38, 0.90, 0.21, - 0.18, 0.10, 0.48, 0.08, 0.46, - 0.03, 0.01, 0.02, 0.03, 0.10, - 0.01, 0.09, 0.01, 0.01, 0.01, - 0.10, 0.41, 0.01, 0.06, 0.75, - 0.08, 0.01, 0.01, 0.08, 0.21, - 0.06, 0.02, 0.05, 0.02, 0.05, - 0.09, 0.12, 0.03, 0.06, 0.11, - 0.03, 0.01, 0.01, 0.06, 0.84, - 0.04, 0.81, 0.39, 0.02, 0.29, - 0.77, 0.07, 0.06, 0.22, 0.23, - 0.23, 0.01, 0.02, 0.13, 0.04, - 0.19, 0.04, 0.08, 0.27, 0.09, - 0.06, 0.01, 0.03, 0.21, 0.04, -}; - -char *CreateLocalModelBuffer(JNIEnv *env, jobject modelBuffer) { - jbyte *modelAddr = static_cast<jbyte *>(env->GetDirectBufferAddress(modelBuffer)); - int modelLen = static_cast<int>(env->GetDirectBufferCapacity(modelBuffer)); - char *buffer(new char[modelLen]); - memcpy(buffer, modelAddr, modelLen); - return buffer; -} - -/** - * To process the result of MindSpore inference. - * @param msOutputs - * @return - */ -std::string ProcessRunnetResult(const int RET_CATEGORY_SUM, const char *const labels_name_map[], - std::unordered_map<std::string, mindspore::MSTensor> msOutputs) { - // Get the branch of the model output. - // Use iterators to get map elements. - std::unordered_map<std::string, mindspore::MSTensor>::iterator iter; - iter = msOutputs.begin(); - - // The mobilenetv2.ms model output just one branch. - auto outputTensor = iter->second; - - int tensorNum = outputTensor.ElementNum(); - MS_PRINT("Number of tensor elements:%d", tensorNum); - - // Get a pointer to the first score. - float *temp_scores = static_cast<float *>(outputTensor.MutableData()); - float scores[RET_CATEGORY_SUM]; - for (int i = 0; i < RET_CATEGORY_SUM; ++i) { - scores[i] = temp_scores[i]; - } - - const float unifiedThre = 0.5; - const float probMax = 1.0; - for (size_t i = 0; i < RET_CATEGORY_SUM; ++i) { - float threshold = g_thres_map[i]; - float tmpProb = scores[i]; - if (tmpProb < threshold) { - tmpProb = tmpProb / threshold * unifiedThre; - } else { - tmpProb = (tmpProb - threshold) / (probMax - threshold) * unifiedThre + unifiedThre; - } - scores[i] = tmpProb; - } - - for (int i = 0; i < RET_CATEGORY_SUM; ++i) { - if (scores[i] > 0.5) { - MS_PRINT("MindSpore scores[%d] : [%f]", i, scores[i]); - } - } - - // Score for each category. - // Converted to text information that needs to be displayed in the APP. - std::string categoryScore = ""; - for (int i = 0; i < RET_CATEGORY_SUM; ++i) { - categoryScore += labels_name_map[i]; - categoryScore += ":"; - std::string score_str = std::to_string(scores[i]); - categoryScore += score_str; - categoryScore += ";"; - } - return categoryScore; -} - -bool BitmapToLiteMat(JNIEnv *env, const jobject &srcBitmap, LiteMat *lite_mat) { - bool ret = false; - AndroidBitmapInfo info; - void *pixels = nullptr; - LiteMat &lite_mat_bgr = *lite_mat; - AndroidBitmap_getInfo(env, srcBitmap, &info); - if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) { - MS_PRINT("Image Err, Request RGBA"); - return false; - } - AndroidBitmap_lockPixels(env, srcBitmap, &pixels); - if (info.stride == info.width * 4) { - ret = InitFromPixel(reinterpret_cast<const unsigned char *>(pixels), - LPixelType::RGBA2RGB, LDataType::UINT8, - info.width, info.height, lite_mat_bgr); - if (!ret) { - MS_PRINT("Init From RGBA error"); - } - } else { - unsigned char *pixels_ptr = new unsigned char[info.width * info.height * 4]; - unsigned char *ptr = pixels_ptr; - unsigned char *data = reinterpret_cast<unsigned char *>(pixels); - for (int i = 0; i < info.height; i++) { - memcpy(ptr, data, info.width * 4); - ptr += info.width * 4; - data += info.stride; - } - ret = InitFromPixel(reinterpret_cast<const unsigned char *>(pixels_ptr), - LPixelType::RGBA2RGB, LDataType::UINT8, - info.width, info.height, lite_mat_bgr); - if (!ret) { - MS_PRINT("Init From RGBA error"); - } - delete[] (pixels_ptr); - } - AndroidBitmap_unlockPixels(env, srcBitmap); - return ret; -} - -bool PreProcessImageData(const LiteMat &lite_mat_bgr, LiteMat *lite_norm_mat_ptr) { - bool ret = false; - LiteMat lite_mat_resize; - LiteMat &lite_norm_mat_cut = *lite_norm_mat_ptr; - ret = ResizeBilinear(lite_mat_bgr, lite_mat_resize, 256, 256); - if (!ret) { - MS_PRINT("ResizeBilinear error"); - return false; - } - LiteMat lite_mat_convert_float; - ret = ConvertTo(lite_mat_resize, lite_mat_convert_float, 1.0 / 255.0); - if (!ret) { - MS_PRINT("ConvertTo error"); - return false; - } - LiteMat lite_mat_cut; - ret = Crop(lite_mat_convert_float, lite_mat_cut, 16, 16, 224, 224); - if (!ret) { - MS_PRINT("Crop error"); - return false; - } - 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; -} - - -/** - * The Java layer reads the model into MappedByteBuffer or ByteBuffer to load the model. - */ -extern "C" -JNIEXPORT jlong JNICALL -Java_com_mindspore_classification_gallery_classify_TrackingMobile_loadModel(JNIEnv *env, - jobject thiz, - jobject model_buffer, - jint num_thread) { - if (nullptr == model_buffer) { - MS_PRINT("error, buffer is nullptr!"); - return (jlong) nullptr; - } - jlong bufferLen = env->GetDirectBufferCapacity(model_buffer); - if (0 == bufferLen) { - MS_PRINT("error, bufferLen is 0!"); - return (jlong) nullptr; - } - - char *modelBuffer = CreateLocalModelBuffer(env, model_buffer); - if (modelBuffer == nullptr) { - MS_PRINT("modelBuffer create failed!"); - return (jlong) nullptr; - } - - // To create a MindSpore network inference environment. - void **labelEnv = new void *; - MSNetWork *labelNet = new MSNetWork; - *labelEnv = labelNet; - - auto context = std::make_shared<mindspore::Context>(); - if (context == nullptr) { - MS_PRINT("context create failed!"); - delete labelNet; - delete labelEnv; - return (jlong) nullptr; - } - - context->SetThreadNum(num_thread); - context->SetThreadAffinity(0); - auto &device_list = context->MutableDeviceInfo(); - auto cpuDeviceInfo = std::make_shared<mindspore::CPUDeviceInfo>(); - cpuDeviceInfo->SetEnableFP16(false); - device_list.push_back(cpuDeviceInfo); - - if (!labelNet->BuildModel(modelBuffer, bufferLen, context)) { - MS_PRINT("MindSpore Build model failed!."); - delete labelNet; - delete labelEnv; - return (jlong) nullptr; - } - - return (jlong) labelEnv; -} - -/** - * After the inference environment is successfully created, - * sending a picture to the model and run inference. - */ -extern "C" JNIEXPORT jstring JNICALL -Java_com_mindspore_classification_gallery_classify_TrackingMobile_runNet(JNIEnv *env, jclass type, - jlong netEnv, - jobject srcBitmap) { - LiteMat lite_mat_bgr, lite_norm_mat_cut; - - if (!BitmapToLiteMat(env, srcBitmap, &lite_mat_bgr)) { - MS_PRINT("BitmapToLiteMat error"); - return NULL; - } - if (!PreProcessImageData(lite_mat_bgr, &lite_norm_mat_cut)) { - MS_PRINT("PreProcessImageData error"); - return NULL; - } - - ImgDims inputDims; - inputDims.channel = lite_norm_mat_cut.channel_; - inputDims.width = lite_norm_mat_cut.width_; - inputDims.height = lite_norm_mat_cut.height_; - - // Get the MindSpore inference environment which created in loadModel(). - void **labelEnv = reinterpret_cast<void **>(netEnv); - if (labelEnv == nullptr) { - MS_PRINT("MindSpore error, labelEnv is a nullptr."); - return NULL; - } - MSNetWork *labelNet = static_cast<MSNetWork *>(*labelEnv); - - auto mModel = labelNet->model(); - if (mModel == nullptr) { - MS_PRINT("MindSpore error, Session is a nullptr."); - return NULL; - } - MS_PRINT("MindSpore get session."); - - auto msInputs = mModel->GetInputs(); - if (msInputs.empty()) { - MS_PRINT("MindSpore error, msInputs.size() equals 0."); - return NULL; - } - auto inTensor = msInputs.front(); - - float *dataHWC = reinterpret_cast<float *>(lite_norm_mat_cut.data_ptr_); - // Copy dataHWC to the model input tensor. - memcpy(inTensor.MutableData(), dataHWC, - inputDims.channel * inputDims.width * inputDims.height * sizeof(float)); - std::vector<mindspore::MSTensor> outputs; - // After the model and image tensor data is loaded, run inference. - auto status = mModel->Predict(msInputs, &outputs); - - if (!status.IsOk()) { - MS_PRINT("MindSpore run net error."); - return NULL; - } - - /** - * Get the MindSpore inference results. - * Return the map of output node name and MindSpore Lite MSTensor. - */ - auto names = mModel->GetOutputTensorNames(); - std::unordered_map<std::string, mindspore::MSTensor> msOutputs; - for (const auto &name : names) { - auto temp_dat = mModel->GetOutputByTensorName(name); - msOutputs.insert(std::pair<std::string, mindspore::MSTensor>{name, temp_dat}); - } - - std::string resultStr = ProcessRunnetResult(::RET_CATEGORY_SUM, - ::labels_name_map, msOutputs); - - const char *resultCharData = resultStr.c_str(); - return (env)->NewStringUTF(resultCharData); -} - -extern "C" JNIEXPORT jboolean JNICALL -Java_com_mindspore_classification_gallery_classify_TrackingMobile_unloadModel(JNIEnv *env, - jclass type, - jlong netEnv) { - MS_PRINT("MindSpore release net."); - void **labelEnv = reinterpret_cast<void **>(netEnv); - if (labelEnv == nullptr) { - MS_PRINT("MindSpore error, labelEnv is a nullptr."); - } - MSNetWork *labelNet = static_cast<MSNetWork *>(*labelEnv); - - labelNet->ReleaseNets(); - - return (jboolean) true; -} diff --git a/official/lite/image_classification/app/src/main/cpp/MindSporeNetnative.h b/official/lite/image_classification/app/src/main/cpp/MindSporeNetnative.h deleted file mode 100644 index b28dc3723486ecaeedcb7c9c88c47644d02fe431..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/cpp/MindSporeNetnative.h +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MINDSPORE_JNI_HMS_DEBUG_MINDSPORENETNATIVE_H -#define MINDSPORE_JNI_HMS_DEBUG_MINDSPORENETNATIVE_H - - -#endif // MINDSPORE_JNI_HMS_DEBUG_MINDSPORENETNATIVE_H diff --git a/official/lite/image_classification/app/src/main/java/com/mindspore/classification/gallery/classify/CompareSizesByArea.java b/official/lite/image_classification/app/src/main/java/com/mindspore/classification/gallery/classify/CompareSizesByArea.java deleted file mode 100644 index f72628d185837cc6791411456a41836a1e687be6..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/java/com/mindspore/classification/gallery/classify/CompareSizesByArea.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mindspore.classification.gallery.classify; - -import android.util.Size; -import java.util.Comparator; - -/** - * Data comparator. - */ - -public class CompareSizesByArea implements Comparator<Size> { - - @Override - public int compare(Size lhs, Size rhs) { - // We cast here to ensure the multiplications won't overflow - return Long.signum((long) lhs.getWidth() * lhs.getHeight() - (long) rhs.getWidth() * rhs.getHeight()); - } - -} \ No newline at end of file diff --git a/official/lite/image_classification/app/src/main/java/com/mindspore/classification/gallery/classify/RecognitionObjectBean.java b/official/lite/image_classification/app/src/main/java/com/mindspore/classification/gallery/classify/RecognitionObjectBean.java deleted file mode 100644 index 23cd5b902bd1f668bc770bc351d919e3617ecef3..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/java/com/mindspore/classification/gallery/classify/RecognitionObjectBean.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mindspore.classification.gallery.classify; - -public class RecognitionObjectBean { - - private String name; - private float score; - - public RecognitionObjectBean(String name, float score) { - this.name = name; - this.score = score; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public float getScore() { - return score; - } - - public void setScore(float score) { - this.score = score; - } - - -} diff --git a/official/lite/image_classification/app/src/main/java/com/mindspore/classification/gallery/classify/TrackingMobile.java b/official/lite/image_classification/app/src/main/java/com/mindspore/classification/gallery/classify/TrackingMobile.java deleted file mode 100644 index 4c01c4fa339fa1f3e9a8772cf53d27425f3aa662..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/java/com/mindspore/classification/gallery/classify/TrackingMobile.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mindspore.classification.gallery.classify; - -import android.content.Context; -import android.graphics.Bitmap; -import android.util.Log; - -import java.io.InputStream; -import java.nio.ByteBuffer; - -/** - * Call the MindSpore interface API in the Java layer. - */ -public class TrackingMobile { - private final static String TAG = "TrackingMobile"; - - static { - try { - System.loadLibrary("mlkit-label-MS"); - Log.i(TAG, "load libiMindSpore.so successfully."); - } catch (UnsatisfiedLinkError e) { - Log.e(TAG, "UnsatisfiedLinkError " + e.getMessage()); - } - } - - // The address of the running inference environment. - private long netEnv = 0; - - private final Context mActivity; - - public TrackingMobile(Context activity) { - this.mActivity = activity; - } - - /** - * JNI load model and also create model inference environment. - * - * @param modelBuffer Model buffer. - * @param numThread The num of thread. - * @return MindSpore Inference environment address. - */ - public native long loadModel(ByteBuffer modelBuffer, int numThread); - - /** - * Running model. - * - * @param netEnv Inference environment address. - * @param img A picture to be inferred. - * @return Inference result - */ - public native String runNet(long netEnv, Bitmap img); - - /** - * Unbind model data. - * - * @param netEnv Inference environment address. - * @return Unbound state. - */ - public native boolean unloadModel(long netEnv); - - /** - * The C++ side is encapsulated into a method of the MSNetWorks class - * - * @param modelPath Model file location - * @return Load model file status - */ - public boolean loadModelFromBuf(String modelPath) { - ByteBuffer buffer = loadModelFile(modelPath); - netEnv = loadModel(buffer, 2); //numThread's default setting is 2. - if (netEnv == 0){ // Loading model failed. - return false; - } - - return true; - } - - /** - * Run MindSpore inference. - */ - public String MindSpore_runnet(Bitmap img) { - String ret_str = runNet(netEnv, img); - return ret_str; - } - - /** - * Unload model. - * @return true - */ - public boolean unloadModel() { - unloadModel(netEnv); - return true; - } - - /** - * Load model file stream. - * @param modelPath Model file path. - * @return Model ByteBuffer. - */ - public ByteBuffer loadModelFile(String modelPath) { - InputStream is = null; - try { - is = mActivity.getAssets().open(modelPath); - byte[] bytes = new byte[is.available()]; - is.read(bytes); - return ByteBuffer.allocateDirect(bytes.length).put(bytes); - } catch (Exception e) { - Log.d("loadModelFile", " Exception occur. "); - Log.e(TAG, Log.getStackTraceString(e)); - } - return null; - } -} diff --git a/official/lite/image_classification/app/src/main/java/com/mindspore/classification/widget/AutoFitTextureView.java b/official/lite/image_classification/app/src/main/java/com/mindspore/classification/widget/AutoFitTextureView.java deleted file mode 100644 index c1f41788ec74ba63521db83b34609b1232a882a9..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/java/com/mindspore/classification/widget/AutoFitTextureView.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mindspore.classification.widget; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.TextureView; - -public class AutoFitTextureView extends TextureView { - - private int mRatioWidth = 0; - private int mRatioHeight = 0; - - public AutoFitTextureView(Context context) { - this(context, null); - } - - public AutoFitTextureView(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public AutoFitTextureView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - /** - * Sets the aspect ratio for this view. The size of the view will be measured based on the ratio - * calculated from the parameters. Note that the actual sizes of parameters don't matter, that - * is, calling setAspectRatio(2, 3) and setAspectRatio(4, 6) make the same result. - * - * @param width Relative horizontal size - * @param height Relative vertical size - */ - public void setAspectRatio(int width, int height) { - if (width < 0 || height < 0) { - throw new IllegalArgumentException("Size cannot be negative."); - } - mRatioWidth = width; - mRatioHeight = height; - requestLayout(); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - int width = MeasureSpec.getSize(widthMeasureSpec); - int height = MeasureSpec.getSize(heightMeasureSpec); - - if (0 == mRatioWidth || 0 == mRatioHeight) { - setMeasuredDimension(width, height); - } else { - if (width > height * mRatioWidth / mRatioHeight) { - setMeasuredDimension(width, width * mRatioHeight / mRatioWidth); - } else { - setMeasuredDimension(height * mRatioWidth / mRatioHeight, height); - } - } - } - -} diff --git a/official/lite/image_classification/app/src/main/java/com/mindspore/classification/widget/CameraActivity.java b/official/lite/image_classification/app/src/main/java/com/mindspore/classification/widget/CameraActivity.java deleted file mode 100644 index cac0fded1623b6e519afc1afc904175f1c7059d2..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/java/com/mindspore/classification/widget/CameraActivity.java +++ /dev/null @@ -1,259 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mindspore.classification.widget; - -import android.Manifest; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.graphics.Color; -import android.net.Uri; -import android.os.Build; -import android.os.Bundle; -import android.provider.Settings; -import android.util.Log; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.view.WindowManager; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.UiThread; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; - -import com.mindspore.classification.R; -import com.mindspore.classification.gallery.classify.RecognitionObjectBean; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -/** - * The main interface of camera preview. - * Using Camera 2 API. - */ -public class CameraActivity extends AppCompatActivity{ - private static final String TAG = "CameraActivity"; - - private static final String[] PERMISSIONS = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, - Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}; - private static final int REQUEST_PERMISSION = 1; - private static final int REQUEST_PERMISSION_AGAIN = 2; - private boolean isAllGranted; - - private static final String BUNDLE_FRAGMENTS_KEY = "android:support:fragments"; - - private LinearLayout bottomLayout; - - private List<RecognitionObjectBean> recognitionObjectBeanList; - - - @Override - protected void onCreate(final Bundle savedInstanceState) { - Log.d(TAG, "onCreate"); - - if (savedInstanceState != null && this.clearFragmentsTag()) { - // Clear the state of the fragment when rebuilding. - savedInstanceState.remove(BUNDLE_FRAGMENTS_KEY); - } - super.onCreate(null); - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - - setContentView(R.layout.activity_camera); - bottomLayout = findViewById(R.id.layout_bottom_content); - requestPermissions(); - } - - private void requestPermissions() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - isAllGranted = checkPermissionAllGranted(PERMISSIONS); - if (!isAllGranted) { - ActivityCompat.requestPermissions(this, PERMISSIONS, REQUEST_PERMISSION); - } else { - addCameraFragment(); - } - } else { - isAllGranted = true; - addCameraFragment(); - } - } - - - private boolean checkPermissionAllGranted(String[] permissions) { - for (String permission : permissions) { - if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) { - return false; - } - } - return true; - } - - /** - * Authority application result callback - */ - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - if (REQUEST_PERMISSION == requestCode) { - isAllGranted = true; - - for (int grant : grantResults) { - if (grant != PackageManager.PERMISSION_GRANTED) { - isAllGranted = false; - break; - } - } - if (!isAllGranted) { - openAppDetails(); - } else { - addCameraFragment(); - } - } - } - - private void openAppDetails() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage("PoseNet 闇€瑕佽闂� 鈥滅浉鏈衡€� 鍜� 鈥滃閮ㄥ瓨鍌ㄥ櫒鈥濓紝璇峰埌 鈥滃簲鐢ㄤ俊鎭� -> 鏉冮檺鈥� 涓巿浜堬紒"); - builder.setPositiveButton("鍘绘墜鍔ㄦ巿鏉�", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Intent intent = new Intent(); - intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); - intent.addCategory(Intent.CATEGORY_DEFAULT); - intent.setData(Uri.parse("package:" + getPackageName())); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); - intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); - startActivityForResult(intent, REQUEST_PERMISSION_AGAIN); - } - }); - builder.setNegativeButton("鍙栨秷", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - finish(); - } - }); - builder.show(); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (REQUEST_PERMISSION_AGAIN == requestCode) { - requestPermissions(); - } - } - - - protected void addCameraFragment() { - CameraFragment cameraFragment = CameraFragment.newInstance(new CameraFragment.RecognitionDataCallBack() { - @Override - public void onRecognitionDataCallBack(String result, final String time) { - dealRecognitionData(result,time); - } - }); - - getSupportFragmentManager().beginTransaction() - .replace(R.id.container, cameraFragment) - .commitAllowingStateLoss(); - } - - private void dealRecognitionData(String result, final String time) { - if (recognitionObjectBeanList != null) { - recognitionObjectBeanList.clear(); - } else { - recognitionObjectBeanList = new ArrayList<>(); - } - - if (!result.equals("")) { - String[] resultArray = result.split(";"); - for (String singleRecognitionResult:resultArray) { - String[] singleResult = singleRecognitionResult.split(":"); - float score = Float.parseFloat(singleResult[1]); - if (score > 0.5) { - recognitionObjectBeanList.add(new RecognitionObjectBean(singleResult[0], score)); - } - } - Collections.sort(recognitionObjectBeanList, new Comparator<RecognitionObjectBean>() { - @Override - public int compare(RecognitionObjectBean t1, RecognitionObjectBean t2) { - return Float.compare(t2.getScore(), t1.getScore()); - } - }); - } - - runOnUiThread(new Runnable() { - @Override - public void run() { - showResultsInBottomSheet(recognitionObjectBeanList,time); - } - }); - } - - @UiThread - protected void showResultsInBottomSheet(List<RecognitionObjectBean> list,String time) { - bottomLayout.removeAllViews(); - if (list != null && list.size() > 0){ - int classNum = 0; - for (RecognitionObjectBean bean:list) { - classNum++; - HorTextView horTextView = new HorTextView(this); - horTextView.setLeftTitle(bean.getName()); - horTextView.setRightContent(String.format("%.2f", (100 * bean.getScore())) + "%"); - horTextView.setBottomLineVisible(View.VISIBLE); - bottomLayout.addView(horTextView); - if (classNum > 4){ // set maximum display is 5. - break; - } - } - HorTextView horTextView = new HorTextView(this); - horTextView.setLeftTitle("Inference Time锛�"); - horTextView.setRightContent(time); - horTextView.setBottomLineVisible(View.INVISIBLE); - bottomLayout.addView(horTextView); - }else{ - TextView textView = new TextView(this); - textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)); - textView.setText("Keep moving."); - textView.setGravity(Gravity.CENTER); - textView.setTextColor(Color.BLACK); - textView.setTextSize(30); - bottomLayout.addView(textView); - } - - - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - if (outState != null && this.clearFragmentsTag()) { - outState.remove(BUNDLE_FRAGMENTS_KEY); - } - } - - protected boolean clearFragmentsTag() { - return true; - } -} diff --git a/official/lite/image_classification/app/src/main/java/com/mindspore/classification/widget/CameraFragment.java b/official/lite/image_classification/app/src/main/java/com/mindspore/classification/widget/CameraFragment.java deleted file mode 100644 index 3118d1b20334b8d101f5e00f1b1098388d073cf0..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/java/com/mindspore/classification/widget/CameraFragment.java +++ /dev/null @@ -1,816 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mindspore.classification.widget; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.Context; -import android.content.res.Configuration; -import android.graphics.Bitmap; -import android.graphics.ImageFormat; -import android.graphics.Matrix; -import android.graphics.Point; -import android.graphics.RectF; -import android.graphics.SurfaceTexture; -import android.hardware.camera2.CameraAccessException; -import android.hardware.camera2.CameraCaptureSession; -import android.hardware.camera2.CameraCharacteristics; -import android.hardware.camera2.CameraDevice; -import android.hardware.camera2.CameraManager; -import android.hardware.camera2.CameraMetadata; -import android.hardware.camera2.CaptureRequest; -import android.hardware.camera2.CaptureResult; -import android.hardware.camera2.TotalCaptureResult; -import android.hardware.camera2.params.StreamConfigurationMap; -import android.media.Image; -import android.media.ImageReader; -import android.os.Bundle; -import android.os.Handler; -import android.os.HandlerThread; -import android.util.Log; -import android.util.Size; -import android.util.SparseIntArray; -import android.view.LayoutInflater; -import android.view.Surface; -import android.view.TextureView; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; - -import com.mindspore.classification.R; -import com.mindspore.classification.gallery.classify.CompareSizesByArea; -import com.mindspore.classification.gallery.classify.TrackingMobile; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; - -public class CameraFragment extends Fragment { - - private static final String TAG = "CameraFragment"; - - private static final SparseIntArray ORIENTATIONS = new SparseIntArray(); - - static { - ORIENTATIONS.append(Surface.ROTATION_0, 90); - ORIENTATIONS.append(Surface.ROTATION_90, 0); - ORIENTATIONS.append(Surface.ROTATION_180, 270); - ORIENTATIONS.append(Surface.ROTATION_270, 180); - } - - private static final int MAX_PREVIEW_WIDTH = 1920; - - private static final int MAX_PREVIEW_HEIGHT = 1280; - - private Semaphore mCameraOpenCloseLock = new Semaphore(1); - - private int mState = STATE_PREVIEW; - - private static final int STATE_PREVIEW = 0; - - private static final int STATE_WAITING_LOCK = 1; - - private static final int STATE_WAITING_PRECAPTURE = 2; - - private static final int STATE_WAITING_NON_PRECAPTURE = 3; - - private static final int STATE_PICTURE_TAKEN = 4; - - /** - * Data interface returned after identification. - */ - private RecognitionDataCallBack recognitionDataCallBack; - - - private AutoFitTextureView mTextureView; - - private TrackingMobile mTrackingMobile; - - private boolean mFlashSupported; - - private boolean isPreBackgroundThreadPause; - - - /** - * HandlerThread and Handler of camera and algorithm. - */ - private HandlerThread mCameraHandlerThread, mMindsporeHandlerThread; - - private Handler mCameraHandler, mMindsporeHandler; - - private CameraManager mCameraManager; - - private CameraCaptureSession mCaptureSession; - - private CameraDevice mCameraDevice; - - private String mCameraId; - - private ImageReader mImageReader; - - private CaptureRequest.Builder mPreviewRequestBuilder; - - private CaptureRequest mPreviewRequest; - - private File mFile; - - private Size mPreviewSize; - - private int mSensorOrientation; - - private CameraDevice.StateCallback mCameraDeviceStateCallback; - - - private CameraFragment(RecognitionDataCallBack recognitionDataCallBack) { - this.recognitionDataCallBack = recognitionDataCallBack; - } - - /** - * Singleton. - * - * @param recognitionDataCallBack Identify data return interface. - * @return Construction method. - */ - public static CameraFragment newInstance(RecognitionDataCallBack recognitionDataCallBack) { - return new CameraFragment(recognitionDataCallBack); - } - - /** - * Data interface returned after identification. - */ - public interface RecognitionDataCallBack { - /** - * Data interface returned after identification. - * - * @param result Recognition result - * @param time Response time - */ - void onRecognitionDataCallBack(String result, String time); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_camera, container, false); - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - mTextureView = (AutoFitTextureView) view.findViewById(R.id.texture); - } - - @Override - public void onActivityCreated(@Nullable Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - mTrackingMobile = new TrackingMobile(getActivity()); - - String modelPath = "model/mobilenetv2.ms"; - boolean ret = mTrackingMobile.loadModelFromBuf(modelPath); - Log.d(TAG, "Loading model return value: " + ret); - } - - - @Override - public void onResume() { - super.onResume(); - initChildThread(); - initCameraManager(); - initSelectCamera(); - initHandlerMatchingSize(); - initImageReader(); - initTextureViewListener(); - } - - @Override - public void onDetach() { - super.onDetach(); - if (mTrackingMobile != null) { - boolean ret = mTrackingMobile.unloadModel(); - Log.d(TAG, "Unload model return value: " + ret); - } - } - - @Override - public void onPause() { - closeCamera(); - stopBackgroundThread(); - super.onPause(); - } - - private void initChildThread() { - mCameraHandlerThread = new HandlerThread("CAMERA2"); - mCameraHandlerThread.start(); - mCameraHandler = new Handler(mCameraHandlerThread.getLooper()); - - mMindsporeHandlerThread = new HandlerThread("MINDSPORE"); - mMindsporeHandlerThread.start(); - mMindsporeHandler = new Handler(mMindsporeHandlerThread.getLooper()); - mMindsporeHandler.postDelayed(classifyRunnable, 500); - } - - - /** - * Detect time-consuming threads - */ - private Runnable classifyRunnable = new Runnable() { - public void run() { - synchronized (CameraFragment.this) { - Bitmap bitmap = mTextureView.getBitmap(); - if (bitmap != null) { - long startTime = System.currentTimeMillis(); - // The current bitmap performs the sending request identification operation - String ret = mTrackingMobile.MindSpore_runnet(bitmap); - long endTime = System.currentTimeMillis(); - if (recognitionDataCallBack != null) { - // Interface returns data銆� - recognitionDataCallBack.onRecognitionDataCallBack(ret, (endTime - startTime) + "ms "); - } - if (!bitmap.isRecycled()) { - bitmap.recycle(); - } - } - if (mMindsporeHandler != null && !isPreBackgroundThreadPause) { - mMindsporeHandler.postDelayed(classifyRunnable, 500); - } - } - } - }; - - private void initCameraManager() { - mCameraManager = (CameraManager) getActivity().getSystemService(Context.CAMERA_SERVICE); - } - - private void initSelectCamera() { - try { - String[] cameraIdArray = mCameraManager.getCameraIdList(); - for (String itemId : cameraIdArray) { - CameraCharacteristics itemCharacteristics = mCameraManager.getCameraCharacteristics(itemId); - Integer facing = itemCharacteristics.get(CameraCharacteristics.LENS_FACING); - if (facing == CameraCharacteristics.LENS_FACING_BACK) { - mCameraId = itemId; - break; - } - - } - } catch (CameraAccessException e) { - e.printStackTrace(); - } - if (mCameraId == null) { - Toast.makeText(getActivity(), getString(R.string.camera_error), Toast.LENGTH_SHORT).show(); - } - } - - private StreamConfigurationMap streamConfigurationMap; - private Size largest; - - /** - * Calculate the camera resolution suitable for the current screen resolution. - */ - private void initHandlerMatchingSize() { - try { - CameraCharacteristics cameraCharacteristics = mCameraManager.getCameraCharacteristics(mCameraId); - streamConfigurationMap = cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); - - Size[] sizes = streamConfigurationMap.getOutputSizes(ImageFormat.JPEG); - largest = Collections.max(Arrays.asList(sizes), new CompareSizesByArea()); - - Boolean available = cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); - mFlashSupported = available == null ? false : available; - } catch (CameraAccessException e) { - e.printStackTrace(); - } - } - - /** - * Initialize the picture. - */ - private void initImageReader() { - final int W = 640; - final int H = 480; - - mImageReader = ImageReader.newInstance(W, H, ImageFormat.JPEG, 30); - mImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() { - @Override - public void onImageAvailable(ImageReader reader) { - mFile = new File(getActivity().getExternalFilesDir(null), System.currentTimeMillis() + ".jpg"); - // Get the data frame and start the algorithm processing. - try { - // Get the next image from the ImageReader queue. - Image image = reader.acquireNextImage(); - image.close(); - } catch (Exception e) { - Log.e(TAG, "onImageAvailable: " + e.toString()); - } - } - }, mCameraHandler); - } - - /** - * TextureView.SurfaceTextureListener - */ - private void initTextureViewListener() { - if (mTextureView.isAvailable()) { - openCamera(mTextureView.getMeasuredWidth(), mTextureView.getMeasuredHeight()); - Log.d(TAG, "isAvailable: " + mTextureView.getWidth() + "--" + mTextureView.getHeight()); - } else { - mTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() { - @Override - public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) { - openCamera(width, height); - } - - @Override - public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) { - configureTransform(width, height); - } - - @Override - public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surfaceTexture) { - return true; - } - - @Override - public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surfaceTexture) { - - } - }); - } - } - - - @SuppressLint("MissingPermission") - private void openCamera(int width, int height) { - setPreviewSize(width, height, streamConfigurationMap, largest); - configureTransform(width, height); - - mCameraDeviceStateCallback = new CameraDevice.StateCallback() { - @Override - public void onOpened(@NonNull CameraDevice cameraDevice) { - if (cameraDevice != null) { - mCameraOpenCloseLock.release(); - mCameraDevice = cameraDevice; - createCameraPreviewSession(); - } - } - - @Override - public void onDisconnected(@NonNull CameraDevice cameraDevice) { - if (cameraDevice != null) { - mCameraOpenCloseLock.release(); - cameraDevice.close(); - mCameraDevice = null; - } - } - - @Override - public void onError(@NonNull CameraDevice cameraDevice, int i) { - if (cameraDevice != null) { - mCameraOpenCloseLock.release(); - cameraDevice.close(); - mCameraDevice = null; - if (null != getActivity()) { - getActivity().finish(); - } - } - } - }; - - - try { - if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { - throw new RuntimeException("Time out waiting to lock ic_launcher opening."); - } - mCameraManager.openCamera(mCameraId, mCameraDeviceStateCallback, mCameraHandler); - } catch (CameraAccessException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - throw new RuntimeException("Interrupted while trying to lock ic_launcher opening.", e); - } - - - } - - - /** - * Open camera preview. - */ - private void createCameraPreviewSession() { - try { - SurfaceTexture texture = mTextureView.getSurfaceTexture(); - // Set preview size. - texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); - // This is the output Surface we need to start preview. - Surface surface = new Surface(texture); - - mPreviewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW); - mPreviewRequestBuilder.addTarget(surface); - // Here, we create a CameraCaptureSession for ic_launcher preview. - mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()), - new CameraCaptureSession.StateCallback() { - - @Override - public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { - // The ic_launcher is already closed - if (null == mCameraDevice) { - return; - } - - // When the session is ready, we start displaying the preview. - mCaptureSession = cameraCaptureSession; - try { - // Auto focus should be continuous for ic_launcher preview. - mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, - CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE); - // Flash is automatically enabled when necessary. - setAutoFlash(mPreviewRequestBuilder); - // Finally, we start displaying the ic_launcher preview. - mPreviewRequest = mPreviewRequestBuilder.build(); - mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mCameraHandler); - } catch (CameraAccessException e) { - e.printStackTrace(); - } - } - - @Override - public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) { - Toast.makeText(getActivity(), "Failed", Toast.LENGTH_LONG).show(); - } - }, null); - } catch (CameraAccessException e) { - e.printStackTrace(); - } - } - - - private CameraCaptureSession.CaptureCallback mCaptureCallback = new CameraCaptureSession.CaptureCallback() { - - private void process(CaptureResult result) { - switch (mState) { - case STATE_PREVIEW: { - // We have nothing to do when the ic_launcher preview is working normally. - break; - } - case STATE_WAITING_LOCK: { - Integer afState = result.get(CaptureResult.CONTROL_AF_STATE); - if (afState == null) { - captureStillPicture(); - } else if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState - || CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) { - // CONTROL_AE_STATE can be null on some devices - Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); - if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) { - mState = STATE_PICTURE_TAKEN; - captureStillPicture(); - } else { - runPrecaptureSequence(); - } - } - break; - } - case STATE_WAITING_PRECAPTURE: { - // CONTROL_AE_STATE can be null on some devices - Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); - if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE - || aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) { - mState = STATE_WAITING_NON_PRECAPTURE; - } - break; - } - case STATE_WAITING_NON_PRECAPTURE: { - // CONTROL_AE_STATE can be null on some devices - Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); - if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) { - mState = STATE_PICTURE_TAKEN; - captureStillPicture(); - } - break; - } - } - } - - @Override - public void onCaptureProgressed(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, - @NonNull CaptureResult partialResult) { - process(partialResult); - } - - @Override - public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, - @NonNull TotalCaptureResult result) { - process(result); - } - }; - - - /** - * Run the precapture sequence for capturing a still image. This method should be called when - * we get a response in. - */ - private void runPrecaptureSequence() { - try { - // This is how to tell the ic_launcher to trigger. - mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, - CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START); - // Tell #mCaptureCallback to wait for the precapture sequence to be set. - mState = STATE_WAITING_PRECAPTURE; - mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mCameraHandler); - } catch (CameraAccessException e) { - e.printStackTrace(); - } - } - - /** - * Capture a still picture. This method should be called when we get a response in - * {@link #mCaptureCallback} from both - */ - private void captureStillPicture() { - try { - final Activity activity = getActivity(); - if (null == activity || null == mCameraDevice) { - return; - } - // This is the CaptureRequest.Builder that we use to take a picture. - final CaptureRequest.Builder captureBuilder = - mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); - captureBuilder.addTarget(mImageReader.getSurface()); - - // Use the same AE and AF modes as the preview. - captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE); - setAutoFlash(captureBuilder); - - // Orientation - int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); - captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation)); - - CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() { - - @Override - public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, - @NonNull TotalCaptureResult result) { - showToast("Saved: " + mFile); - Log.d(TAG, mFile.toString()); - unlockFocus(); - } - }; - - mCaptureSession.stopRepeating(); - mCaptureSession.abortCaptures(); - mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null); - } catch (CameraAccessException e) { - e.printStackTrace(); - } - } - - /** - * Retrieves the JPEG orientation from the specified screen rotation. - * - * @param rotation The screen rotation. - * @return The JPEG orientation (one of 0, 90, 270, and 360) - */ - private int getOrientation(int rotation) { - return (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360; - } - - /** - * Unlock the focus. This method should be called when still image capture sequence is - * finished. - */ - private void unlockFocus() { - try { - // Reset the auto-focus trigger - mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL); - setAutoFlash(mPreviewRequestBuilder); - mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mCameraHandler); - // After this, the ic_launcher will go back to the normal state of preview. - mState = STATE_PREVIEW; - mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mCameraHandler); - } catch (CameraAccessException e) { - e.printStackTrace(); - } - } - - private void setAutoFlash(CaptureRequest.Builder requestBuilder) { - if (mFlashSupported) { - requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH); - } - } - - protected void showToast(final String text) { - final Activity activity = getActivity(); - if (activity != null) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - Toast.makeText(activity, text, Toast.LENGTH_SHORT).show(); - } - }); - } - } - - /** - * Configures the necessary {@link Matrix} transformation to `mTextureView`. - * This method should be called after the ic_launcher preview size is determined in - * setUpCameraOutputs and also the size of `mTextureView` is fixed. - * - * @param viewWidth The width of `mTextureView` - * @param viewHeight The height of `mTextureView` - */ - protected void configureTransform(int viewWidth, int viewHeight) { - Activity activity = getActivity(); - if (null == mTextureView || null == mPreviewSize || null == activity) { - return; - } - int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); - Matrix matrix = new Matrix(); - RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); - RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth()); - float centerX = viewRect.centerX(); - float centerY = viewRect.centerY(); - if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { - bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); - matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); - float scale = - Math.max((float) viewHeight / mPreviewSize.getHeight(), (float) viewWidth / mPreviewSize.getWidth()); - matrix.postScale(scale, scale, centerX, centerY); - matrix.postRotate(90 * (rotation - 2), centerX, centerY); - } else if (Surface.ROTATION_180 == rotation) { - matrix.postRotate(180, centerX, centerY); - } - mTextureView.setTransform(matrix); - } - - - /** - * Set preview image size and positioning. - * - * @param width - * @param height - * @param map StreamConfigurationMap, the manager of all output formats and sizes supported by the camera. - * @param largest The max size - */ - private void setPreviewSize(int width, int height, StreamConfigurationMap map, Size largest) { - // Find out if we need to swap dimension to get the preview size relative to sensor coordinate. - int displayRotation = getActivity().getWindowManager().getDefaultDisplay().getRotation(); - Log.d(TAG, "displayRotation: " + displayRotation); - - boolean swappedDimensions = false; - if (Surface.ROTATION_0 == displayRotation || Surface.ROTATION_180 == displayRotation) { - if (mSensorOrientation == 90 || mSensorOrientation == 270) { - swappedDimensions = true; - } - } else if (Surface.ROTATION_90 == displayRotation || Surface.ROTATION_270 == displayRotation) { - if (mSensorOrientation == 0 || mSensorOrientation == 180) { - swappedDimensions = true; - } - } - - Point displaySize = new Point(); - getActivity().getWindowManager().getDefaultDisplay().getSize(displaySize); - int rotatedPreviewWidth = width; - int rotatedPreviewHeight = height; - int maxPreviewWidth = displaySize.x; - int maxPreviewHeight = displaySize.y; - - if (swappedDimensions) { - rotatedPreviewWidth = height; - rotatedPreviewHeight = width; - maxPreviewWidth = displaySize.y; - maxPreviewHeight = displaySize.x; - } - - if (maxPreviewWidth > MAX_PREVIEW_WIDTH) { - maxPreviewWidth = MAX_PREVIEW_WIDTH; - } - - if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) { - maxPreviewHeight = MAX_PREVIEW_HEIGHT; - } - - // Danger, W.R.! Attempting to use too large a preview size could exceed the ic_launcher - // bus' bandwidth limitation, resulting in gorgeous previews but the storage of - // garbage capture data. - mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth, - rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, largest); - - // We fit the aspect ratio of TextureView to the size of preview we picked. - int orientation = getResources().getConfiguration().orientation;// manifest涓柟鍚戝凡缁忓啓姝� - if (orientation == Configuration.ORIENTATION_LANDSCAPE) { - mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight()); - } else { - mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth()); - } - } - - /** - * Given {@code choices} of {@code Size}s supported by a ic_launcher, choose the smallest one that - * is at least as large as the respective texture view size, and that is at most as large as the - * respective max size, and whose aspect ratio matches with the specified value. If such size - * doesn't exist, choose the largest one that is at most as large as the respective max size, - * and whose aspect ratio matches with the specified value. - * - * @param choices The list of sizes that the ic_launcher supports for the intended output - * class - * @param textureViewWidth The width of the texture view relative to sensor coordinate - * @param textureViewHeight The height of the texture view relative to sensor coordinate - * @param maxWidth The maximum width that can be chosen - * @param maxHeight The maximum height that can be chosen - * @param aspectRatio The aspect ratio - * @return The optimal {@code Size}, or an arbitrary one if none were big enough - */ - protected Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight, int maxWidth, - int maxHeight, Size aspectRatio) { - - // Collect the supported resolutions that are at least as big as the preview Surface - List<Size> bigEnough = new ArrayList<>(); - // Collect the supported resolutions that are smaller than the preview Surface - List<Size> notBigEnough = new ArrayList<>(); - int w = aspectRatio.getWidth(); - int h = aspectRatio.getHeight(); - for (Size option : choices) { - if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight - && option.getHeight() == option.getWidth() * h / w) { - // if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight) { - if (option.getWidth() >= textureViewWidth && option.getHeight() >= textureViewHeight) { - bigEnough.add(option); - } else { - notBigEnough.add(option); - } - } - } - - if (bigEnough.size() > 0) { - return Collections.min(bigEnough, new CompareSizesByArea()); - } else if (notBigEnough.size() > 0) { - return Collections.max(notBigEnough, new CompareSizesByArea()); - } else { - Log.e(TAG, "Couldn't find any suitable preview size"); - return choices[0]; - } - } - - - /** - * Closes the current {@link CameraDevice}. - */ - private void closeCamera() { - try { - mCameraOpenCloseLock.acquire(); - if (null != mCaptureSession) { - mCaptureSession.close(); - mCaptureSession = null; - } - if (null != mCameraDevice) { - mCameraDevice.close(); - mCameraDevice = null; - } - if (null != mImageReader) { - mImageReader.close(); - mImageReader = null; - } - } catch (InterruptedException e) { - throw new RuntimeException("Interrupted while trying to lock ic_launcher closing.", e); - } finally { - mCameraOpenCloseLock.release(); - } - } - - private void stopBackgroundThread() { - isPreBackgroundThreadPause = true; - mCameraHandlerThread.quitSafely(); - mMindsporeHandlerThread.quitSafely(); - try { - mCameraHandlerThread.join(); - mCameraHandlerThread = null; - mCameraHandler.removeCallbacksAndMessages(null); - mCameraHandler = null; - - mMindsporeHandlerThread.join(); - mMindsporeHandlerThread = null; - mMindsporeHandler.removeCallbacksAndMessages(null); - mMindsporeHandler = null; - } catch (InterruptedException e) { - e.printStackTrace(); - } - } -} diff --git a/official/lite/image_classification/app/src/main/java/com/mindspore/classification/widget/HorTextView.java b/official/lite/image_classification/app/src/main/java/com/mindspore/classification/widget/HorTextView.java deleted file mode 100644 index e515b8bb93d169b3c7ae814d0e67caf7203cffda..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/java/com/mindspore/classification/widget/HorTextView.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mindspore.classification.widget; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.LinearLayout; -import android.widget.TextView; - -import androidx.annotation.Nullable; - -import com.mindspore.classification.R; - -public class HorTextView extends LinearLayout { - private TextView tvLeftTitle, tvRightContent; - private View viewBottomLine; - - public HorTextView(Context context) { - this(context, null); - } - - public HorTextView(Context context, @Nullable AttributeSet attrs) { - this(context, attrs, 0); - } - - public HorTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - LayoutInflater.from(context).inflate(R.layout.layout_hor_text_view, this); - tvLeftTitle = findViewById(R.id.tv_left_title); - tvRightContent = findViewById(R.id.tv_right_content); - viewBottomLine = findViewById(R.id.view_bottom_line); - } - - - public void setLeftTitle(String title) { - tvLeftTitle.setText(title); - } - - public void setRightContent(String content) { - tvRightContent.setText(content); - } - - public void setBottomLineVisible(int isVisible) { - viewBottomLine.setVisibility(isVisible); - } - -} diff --git a/official/lite/image_classification/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/official/lite/image_classification/app/src/main/res/drawable-v24/ic_launcher_foreground.xml deleted file mode 100644 index 2b068d11462a4b96669193de13a711a3a36220a0..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ /dev/null @@ -1,30 +0,0 @@ -<vector xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:aapt="http://schemas.android.com/aapt" - android:width="108dp" - android:height="108dp" - android:viewportWidth="108" - android:viewportHeight="108"> - <path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z"> - <aapt:attr name="android:fillColor"> - <gradient - android:endX="85.84757" - android:endY="92.4963" - android:startX="42.9492" - android:startY="49.59793" - android:type="linear"> - <item - android:color="#44000000" - android:offset="0.0" /> - <item - android:color="#00000000" - android:offset="1.0" /> - </gradient> - </aapt:attr> - </path> - <path - android:fillColor="#FFFFFF" - android:fillType="nonZero" - android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z" - android:strokeWidth="1" - android:strokeColor="#00000000" /> -</vector> \ No newline at end of file diff --git a/official/lite/image_classification/app/src/main/res/drawable/ic_launcher_background.xml b/official/lite/image_classification/app/src/main/res/drawable/ic_launcher_background.xml deleted file mode 100644 index d5fccc538c179838bfdce779c26eebb4fa0b5ce9..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/res/drawable/ic_launcher_background.xml +++ /dev/null @@ -1,170 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<vector xmlns:android="http://schemas.android.com/apk/res/android" - android:width="108dp" - android:height="108dp" - android:viewportHeight="108" - android:viewportWidth="108"> - <path - android:fillColor="#26A69A" - android:pathData="M0,0h108v108h-108z" /> - <path - android:fillColor="#00000000" - android:pathData="M9,0L9,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M19,0L19,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M29,0L29,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M39,0L39,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M49,0L49,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M59,0L59,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M69,0L69,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M79,0L79,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M89,0L89,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M99,0L99,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,9L108,9" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,19L108,19" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,29L108,29" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,39L108,39" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,49L108,49" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,59L108,59" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,69L108,69" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,79L108,79" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,89L108,89" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,99L108,99" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M19,29L89,29" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M19,39L89,39" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M19,49L89,49" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M19,59L89,59" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M19,69L89,69" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M19,79L89,79" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M29,19L29,89" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M39,19L39,89" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M49,19L49,89" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M59,19L59,89" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M69,19L69,89" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M79,19L79,89" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> -</vector> diff --git a/official/lite/image_classification/app/src/main/res/drawable/rectangle.xml b/official/lite/image_classification/app/src/main/res/drawable/rectangle.xml deleted file mode 100644 index b8f5d3559c4e83072d5d73a3241d240aa68daccf..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/res/drawable/rectangle.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<shape xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/listview_background_shape"> - <stroke - android:width="1dp" - android:color="@android:color/darker_gray" /> - <padding - android:bottom="2dp" - android:left="2dp" - android:right="2dp" - android:top="2dp" /> - <solid android:color="#ffffffff" /> -</shape> \ No newline at end of file diff --git a/official/lite/image_classification/app/src/main/res/drawable/switch_thumb.xml b/official/lite/image_classification/app/src/main/res/drawable/switch_thumb.xml deleted file mode 100644 index ef6cfd23398879085c2724d6442dc7c36c6a62a4..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/res/drawable/switch_thumb.xml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<shape xmlns:android="http://schemas.android.com/apk/res/android"> - <size - android:width="40dp" - android:height="40dp" /> - <corners android:radius="20dp" /> - <solid android:color="#82eae5e5" /> -</shape> \ No newline at end of file diff --git a/official/lite/image_classification/app/src/main/res/drawable/switch_track.xml b/official/lite/image_classification/app/src/main/res/drawable/switch_track.xml deleted file mode 100644 index 3088fe56f61eada53d7074baa948fd4cba249fec..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/res/drawable/switch_track.xml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<shape xmlns:android="http://schemas.android.com/apk/res/android"> - <size - android:width="100dp" - android:height="40dp"/> - <corners android:radius="20dp" /> - <solid android:color="#784b4b4b" /> -</shape> \ No newline at end of file diff --git a/official/lite/image_classification/app/src/main/res/layout/activity_camera.xml b/official/lite/image_classification/app/src/main/res/layout/activity_camera.xml deleted file mode 100644 index 8daee6efa18c57afa09440e07b1ff4cac92600bf..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/res/layout/activity_camera.xml +++ /dev/null @@ -1,55 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="#00000000"> - - <RelativeLayout - android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="#00000000" - android:orientation="vertical"> - - - <FrameLayout - android:id="@+id/container" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="@android:color/black" - tools:context="com.mindspore.classification.widget.CameraActivity" /> - - - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar" - android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - android:layout_alignParentTop="true" - android:background="@color/mindspore_semi_transparent"> - - <TextView - android:gravity="center_vertical" - android:textColor="#ffffff" - android:drawablePadding="5dp" - android:textSize="30sp" - android:drawableStart="@mipmap/logo" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:text="MindSpore"/> - </androidx.appcompat.widget.Toolbar> - - <LinearLayout - android:gravity="center" - android:background="#ffffff" - android:id="@+id/layout_bottom_content" - android:layout_alignParentBottom="true" - android:layout_width="match_parent" - android:layout_height="200dp" - android:orientation="vertical" /> - </RelativeLayout> - - -<!-- <include--> -<!-- android:id="@+id/bottom_sheet_layout"--> -<!-- layout="@layout/layout_bottom_sheet" />--> -</androidx.coordinatorlayout.widget.CoordinatorLayout> diff --git a/official/lite/image_classification/app/src/main/res/layout/fragment_camera.xml b/official/lite/image_classification/app/src/main/res/layout/fragment_camera.xml deleted file mode 100644 index b4e11ed708d8e25c79f912db60f7e1efa2b56139..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/res/layout/fragment_camera.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="@color/white" - android:orientation="vertical"> - - <com.mindspore.classification.widget.AutoFitTextureView - android:id="@+id/texture" - android:layout_width="match_parent" - android:layout_height="match_parent" /> - -</FrameLayout> diff --git a/official/lite/image_classification/app/src/main/res/layout/layout_hor_text_view.xml b/official/lite/image_classification/app/src/main/res/layout/layout_hor_text_view.xml deleted file mode 100644 index eb9bea42d187c9ea23b6b10875df8baa4846aef9..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/res/layout/layout_hor_text_view.xml +++ /dev/null @@ -1,40 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="vertical"> - - <TextView - android:id="@+id/tv_left_title" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginStart="@dimen/hor_text_view_text_margin_normal" - android:layout_marginTop="@dimen/hor_text_view_text_margin_small" - android:textSize="@dimen/hor_text_view_text_size" - tools:text="person" /> - - <TextView - android:gravity="end" - android:layout_toRightOf="@+id/tv_left_title" - android:textColor="@color/black" - android:layout_alignParentEnd="true" - android:id="@+id/tv_right_content" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginEnd="@dimen/hor_text_view_text_margin_normal" - android:layout_marginStart="@dimen/hor_text_view_text_margin_normal" - android:layout_marginTop="@dimen/hor_text_view_text_margin_small" - android:textSize="@dimen/hor_text_view_text_size" - tools:text="12.5" /> - - <View - android:id="@+id/view_bottom_line" - android:layout_marginTop="@dimen/hor_text_view_text_margin_small" - android:layout_alignStart="@+id/tv_left_title" - android:layout_alignEnd="@+id/tv_right_content" - android:background="@color/gray" - android:layout_below="@+id/tv_left_title" - android:layout_height="0.5dp" - android:layout_width="match_parent"/> -</RelativeLayout> \ No newline at end of file diff --git a/official/lite/image_classification/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/official/lite/image_classification/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml deleted file mode 100644 index 036d09bc5fd523323794379703c4a111d1e28a04..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +++ /dev/null @@ -1,5 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> - <background android:drawable="@color/ic_launcher_background"/> - <foreground android:drawable="@mipmap/ic_launcher_foreground"/> -</adaptive-icon> \ No newline at end of file diff --git a/official/lite/image_classification/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/official/lite/image_classification/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml deleted file mode 100644 index 036d09bc5fd523323794379703c4a111d1e28a04..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +++ /dev/null @@ -1,5 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> - <background android:drawable="@color/ic_launcher_background"/> - <foreground android:drawable="@mipmap/ic_launcher_foreground"/> -</adaptive-icon> \ No newline at end of file diff --git a/official/lite/image_classification/app/src/main/res/mipmap-hdpi/ic_launcher.png b/official/lite/image_classification/app/src/main/res/mipmap-hdpi/ic_launcher.png deleted file mode 100644 index ad551dcf1cbe832e9801f25e147679b728a79246..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png b/official/lite/image_classification/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png deleted file mode 100644 index cea70b6899274f284773af7238c7a0708cc61894..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/official/lite/image_classification/app/src/main/res/mipmap-hdpi/ic_launcher_round.png deleted file mode 100644 index 12602e9e7b70a988c28e122846fcf6881d6477ac..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-hdpi/ic_launcher_round.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/mipmap-mdpi/ic_launcher.png b/official/lite/image_classification/app/src/main/res/mipmap-mdpi/ic_launcher.png deleted file mode 100644 index 534bc3b190c0ed1b85b242743357fc1259410075..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png b/official/lite/image_classification/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png deleted file mode 100644 index 0cc30d70ba56155109f5a40d8ae1cfac7662e592..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/official/lite/image_classification/app/src/main/res/mipmap-mdpi/ic_launcher_round.png deleted file mode 100644 index 13d25d7dcb9b0be595242856b5feed76ccab935b..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-mdpi/ic_launcher_round.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/official/lite/image_classification/app/src/main/res/mipmap-xhdpi/ic_launcher.png deleted file mode 100644 index ce4d40a73968ac2ecd2c3bb242f5440b184b867f..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png b/official/lite/image_classification/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png deleted file mode 100644 index 4f8f320bf70950dbbd3c6589d4d5d91e154f5938..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/official/lite/image_classification/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png deleted file mode 100644 index 674ae88e4d54c6b6eab8eece581c4fb5c228e32b..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/official/lite/image_classification/app/src/main/res/mipmap-xxhdpi/ic_launcher.png deleted file mode 100644 index 7c87876ea0630a0ca13e0246defa735809249bc4..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png b/official/lite/image_classification/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png deleted file mode 100644 index d4b8095ea91305149c7fa1fd9950f40d99cd8ee4..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/official/lite/image_classification/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png deleted file mode 100644 index 2528822d4dffc4c9a0b414f533197a5eb0734a0f..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/mipmap-xxhdpi/logo.png b/official/lite/image_classification/app/src/main/res/mipmap-xxhdpi/logo.png deleted file mode 100644 index c90f1dda4399a42e4c0c504f144508afb99ec326..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-xxhdpi/logo.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/official/lite/image_classification/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png deleted file mode 100644 index cae0e3a3260f2b98a9831633ff4cceba9fc54e93..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png b/official/lite/image_classification/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png deleted file mode 100644 index c1229997eb0df6dc6e437fe38aa90840c6b4ee60..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/official/lite/image_classification/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png deleted file mode 100644 index 24849e26b4669ea0426232e3ec3ee0f3565ef28b..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/official/lite/image_classification/app/src/main/res/values/colors.xml b/official/lite/image_classification/app/src/main/res/values/colors.xml deleted file mode 100644 index 73bd50bbb28dcad795e6bb40eda9cd789b8c1a09..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/res/values/colors.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <color name="colorPrimary">#6200EE</color> - <color name="colorPrimaryDark">#3700B3</color> - <color name="colorAccent">#03DAC5</color> - - - <color name="mindspore_color_primary">#00D4EF</color> - <color name="mindspore_color_primary_dark">#03A9F4</color> - <color name="mindspore_color_accent">#769DDA</color> - - <color name="mindspore_semi_transparent">#66000000</color> - - <color name="white">#ffffff</color> - <color name="black">#000000</color> - <color name="gray">#A69D9D</color> - -</resources> \ No newline at end of file diff --git a/official/lite/image_classification/app/src/main/res/values/dimens.xml b/official/lite/image_classification/app/src/main/res/values/dimens.xml deleted file mode 100644 index a7b5dd0995ed7b6fe032fe40565e9b1ad2dae413..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/res/values/dimens.xml +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <dimen name="ms_bottom_sheet_corner_radius">15dp</dimen> - <dimen name="ms_bottom_sheet_top_padding">8dp</dimen> - - <dimen name="hor_text_view_text_margin_normal">15dp</dimen> - <dimen name="hor_text_view_text_margin_small">6dp</dimen> - <dimen name="hor_text_view_text_size">15sp</dimen> -</resources> \ No newline at end of file diff --git a/official/lite/image_classification/app/src/main/res/values/ic_launcher_background.xml b/official/lite/image_classification/app/src/main/res/values/ic_launcher_background.xml deleted file mode 100644 index c5d5899fdf0a1b144bf341b29e0c66ba50bbcedd..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/res/values/ic_launcher_background.xml +++ /dev/null @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <color name="ic_launcher_background">#FFFFFF</color> -</resources> \ No newline at end of file diff --git a/official/lite/image_classification/app/src/main/res/values/strings.xml b/official/lite/image_classification/app/src/main/res/values/strings.xml deleted file mode 100644 index 50f77970282909bba79f72f5f5ffdb7ea21372ab..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/res/values/strings.xml +++ /dev/null @@ -1,30 +0,0 @@ -<resources> - <string name="app_name">Classification</string> - <string name="action_settings">璁剧疆</string> - - <string name="request_permission">This sample needs camera permission.</string> - <string name="camera_error">This device doesn\'t support Camera2 API.</string> - <string name="intro_message">浣跨敤鐨刧oogle鐨刢amera2demo.</string> - <string name="appwidget_text">EXAMPLE</string> - <string name="add_widget">Add widget</string> - - - <string name="ms_ic_app_name" translation_description="Image Classification demo app [CHAR_LIMIT=40]">TFL Classify</string> - <string name="ms_ic_camera_error" translation_description="Error regarding camera support[CHAR_LIMIT=40]">This device doesn\'t support Camera2 API.</string> - <string name="ms_ic_gpu_quant_error" translation_description="Error regarding GPU support for Quant models[CHAR_LIMIT=60]">GPU does not yet supported quantized models.</string> - <string name="ms_ic_model" translatable="false">Model:</string> - <string-array name="ms_ic_models" translatable="false"> - <item>Quantized_EfficientNet</item> - <item>Float_EfficientNet</item> - <item>Quantized_MobileNet</item> - <item>Float_MobileNet</item> - </string-array> - - <string name="ms_ic_device" translatable="false">Device:</string> - <string-array name="ms_ic_devices" translatable="false"> - <item>CPU</item> - <item>GPU</item> - <item>NNAPI</item> - </string-array> - -</resources> \ No newline at end of file diff --git a/official/lite/image_classification/app/src/main/res/values/styles.xml b/official/lite/image_classification/app/src/main/res/values/styles.xml deleted file mode 100644 index 13f74a4612ae4ee788536d05d8d14d20e3238f7b..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/main/res/values/styles.xml +++ /dev/null @@ -1,10 +0,0 @@ -<resources> - <!-- Base application theme. --> - <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> - <!-- Customize your theme here. --> - <item name="colorPrimary">@color/colorPrimary</item> - <item name="colorPrimaryDark">@color/colorPrimaryDark</item> - <item name="colorAccent">@color/colorAccent</item> - </style> - -</resources> \ No newline at end of file diff --git a/official/lite/image_classification/app/src/test/java/com/mindspore/classification/ExampleUnitTest.java b/official/lite/image_classification/app/src/test/java/com/mindspore/classification/ExampleUnitTest.java deleted file mode 100644 index 15a015ba8c37643a15610adf232a8754fbf06099..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/app/src/test/java/com/mindspore/classification/ExampleUnitTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mindspore.classification; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() { - assertEquals(4, 2 + 2); - } -} diff --git a/official/lite/image_classification/build.gradle b/official/lite/image_classification/build.gradle deleted file mode 100644 index 6754c23d52caabf45925ba403600949593949972..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/build.gradle +++ /dev/null @@ -1,24 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. -buildscript { - repositories { - google() - jcenter() - } - dependencies { - classpath "com.android.tools.build:gradle:4.0.1" - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - google() - jcenter() - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} \ No newline at end of file diff --git a/official/lite/image_classification/gradle.properties b/official/lite/image_classification/gradle.properties deleted file mode 100644 index f5020a3b3734dd3278c76586966dd4cec65659f4..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/gradle.properties +++ /dev/null @@ -1,20 +0,0 @@ -# Project-wide Gradle settings. -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx2048m -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true -# AndroidX package structure to make it clearer which packages are bundled with the -# Android operating system, and which are packaged with your app"s APK -# https://developer.android.com/topic/libraries/support-library/androidx-rn -android.useAndroidX=true -# Automatically convert third-party libraries to use AndroidX -android.enableJetifier=true -android.injected.testOnly=false \ No newline at end of file diff --git a/official/lite/image_classification/gradle/wrapper/gradle-wrapper.jar b/official/lite/image_classification/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index f6b961fd5a86aa5fbfe90f707c3138408be7c718..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/official/lite/image_classification/gradle/wrapper/gradle-wrapper.properties b/official/lite/image_classification/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 1d8635ad736243bee4244822252bca9e39252d05..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Tue Jul 28 10:28:05 CST 2020 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip diff --git a/official/lite/image_classification/gradlew b/official/lite/image_classification/gradlew deleted file mode 100644 index cccdd3d517fc5249beaefa600691cf150f2fa3e6..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/gradlew +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/env sh - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - -exec "$JAVACMD" "$@" diff --git a/official/lite/image_classification/gradlew.bat b/official/lite/image_classification/gradlew.bat deleted file mode 100644 index f9553162f122c71b34635112e717c3e733b5b212..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/gradlew.bat +++ /dev/null @@ -1,84 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/official/lite/image_classification/images/NDK_version.jpg b/official/lite/image_classification/images/NDK_version.jpg deleted file mode 100644 index 50af23b0db95875ea5458f3106d99fe39cd74739..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/images/NDK_version.jpg and /dev/null differ diff --git a/official/lite/image_classification/images/app_result.jpg b/official/lite/image_classification/images/app_result.jpg deleted file mode 100644 index 9287aad111992c39145c70f6a473818e31402bc7..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/images/app_result.jpg and /dev/null differ diff --git a/official/lite/image_classification/images/home.png b/official/lite/image_classification/images/home.png deleted file mode 100644 index 29e954a425c3b42e61353b97394d774f646cada7..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/images/home.png and /dev/null differ diff --git a/official/lite/image_classification/images/install.jpg b/official/lite/image_classification/images/install.jpg deleted file mode 100644 index c98ee71dae722be180a8b88c1661eabf85c97dce..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/images/install.jpg and /dev/null differ diff --git a/official/lite/image_classification/images/maven.jpg b/official/lite/image_classification/images/maven.jpg deleted file mode 100644 index eee21bb1df4072216e540ba1e7dea49f03822d58..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/images/maven.jpg and /dev/null differ diff --git a/official/lite/image_classification/images/project_structure.png b/official/lite/image_classification/images/project_structure.png deleted file mode 100644 index 6f71294479c4cd91dd983136d7f13960227c3c57..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/images/project_structure.png and /dev/null differ diff --git a/official/lite/image_classification/images/run_app.PNG b/official/lite/image_classification/images/run_app.PNG deleted file mode 100644 index 2557b6293de5b3d7fefe7f6e58b57c03deabb55d..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/images/run_app.PNG and /dev/null differ diff --git a/official/lite/image_classification/images/sdk_management.jpg b/official/lite/image_classification/images/sdk_management.jpg deleted file mode 100644 index 4051b9bab33419b0fc554bbd08c1221e7d22a2b4..0000000000000000000000000000000000000000 Binary files a/official/lite/image_classification/images/sdk_management.jpg and /dev/null differ diff --git a/official/lite/image_classification/settings.gradle b/official/lite/image_classification/settings.gradle deleted file mode 100644 index 1003c3b16ed7273357b1db638f2948e886b21efe..0000000000000000000000000000000000000000 --- a/official/lite/image_classification/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -include ':app' -rootProject.name = "Classification" \ No newline at end of file diff --git a/official/lite/pet_classification/.gitignore b/official/lite/pet_classification/.gitignore deleted file mode 100644 index 836b944df63a11110d1f58d0f6364fd662a4d1a5..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/.gitignore +++ /dev/null @@ -1,83 +0,0 @@ -# MindSpore -build/ -mindspore/lib -app/src/main/assets/model/ -app/src/main/cpp/mindspore-lite-* -output -*.ir -mindspore/ccsrc/schema/inner/* - -# Cmake files -CMakeFiles/ -cmake_install.cmake -CMakeCache.txt -Makefile -cmake-build-debug - -# Dynamic libraries -*.so -*.so.* -*.dylib - -# Static libraries -*.la -*.lai -*.a -*.lib - -# Protocol buffers -*_pb2.py -*.pb.h -*.pb.cc - -# Object files -*.o - -# Editor -.vscode -.idea/ - -# Cquery -.cquery_cached_index/ -compile_commands.json - -# Ctags and cscope -tags -TAGS -CTAGS -GTAGS -GRTAGS -GSYMS -GPATH -cscope.* - -# Python files -*__pycache__* -.pytest_cache - -# Mac files -*.DS_Store - -# Test results -test_temp_summary_event_file/ -*.dot -*.dat -*.svg -*.perf -*.info -*.ckpt -*.shp -*.pkl -.clangd -mindspore/version.py -mindspore/default_config.py -mindspore/.commit_id -onnx.proto -mindspore/ccsrc/onnx.proto - -# Android -local.properties -.gradle -sdk/build -sdk/.cxx -app/.cxx diff --git a/official/lite/pet_classification/app/.gitignore b/official/lite/pet_classification/app/.gitignore deleted file mode 100644 index 793dd2960b574467d12485d19a3a1385d4985fc7..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/build -!/libs/ -!/src/main/assets/model/ -!/src/main/cpp/mindspore-lite-1.0.1-runtime-arm64-cpu/ - -/src/main/cpp/mindspore-lite-1.0.1-runtime-arm64-cpu/ \ No newline at end of file diff --git a/official/lite/pet_classification/app/CMakeLists.txt b/official/lite/pet_classification/app/CMakeLists.txt deleted file mode 100644 index 651f6af6a690c7af2269fabb2e41797accbff3ff..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/CMakeLists.txt +++ /dev/null @@ -1,78 +0,0 @@ -# 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) - -set(CMAKE_VERBOSE_MAKEFILE on) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}) - -set(MINDSPORELITE_VERSION mindspore-lite-1.1.1-runtime-arm64-cpu) - -# ============== Set MindSpore Dependencies. ============= -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp) -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}) -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/include) -include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/minddata/include) - -add_library(mindspore-lite SHARED IMPORTED) -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}/minddata/lib/libminddata-lite.so) -# --------------- MindSpore Lite set End. -------------------- - - -# 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. - -file(GLOB_RECURSE cpp_src "src/main/cpp/*.cpp" "src/main/cpp/*.h") - -add_library( # Sets the name of the library. - mlkit-label-MS - - # Sets the library as a shared library. - SHARED - - # Provides a relative path to your source file(s). - ${cpp_src}) - - -# Searches for a specified prebuilt library and stores the path as a -# variable. Because CMake includes system libraries in the search path by -# default, you only need to specify the name of the public NDK library -# you want to add. CMake verifies that the library exists before -# completing its build. - -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) - - -find_library(jnigraphics-lib jnig路raphics) - -# 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. -add_definitions(-DMNN_USE_LOGCAT) -target_link_libraries( # Specifies the target library. - mlkit-label-MS - - # --- mindspore --- - minddata-lite - mindspore-lite - - # --- other dependencies.--- - -ljnigraphics - android - - # Links the target library to the log library - ${log-lib} - ) \ No newline at end of file diff --git a/official/lite/pet_classification/app/build.gradle b/official/lite/pet_classification/app/build.gradle deleted file mode 100644 index eea533d92a279f2c73849013bbaf31474f1e8c57..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/build.gradle +++ /dev/null @@ -1,78 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 30 - buildToolsVersion "30.0.1" - - defaultConfig { - applicationId "com.mindspore.classificationforpet" - minSdkVersion 21 - targetSdkVersion 30 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - externalNativeBuild { - cmake { - arguments "-DANDROID_STL=c++_shared" - cppFlags "-std=c++17" - } - } - ndk { - abiFilters 'arm64-v8a' - } - } - aaptOptions { - noCompress '.so', 'ms' - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - externalNativeBuild { - cmake { - path file('CMakeLists.txt') - } - } - ndkVersion '21.3.6528147' - - sourceSets { - main { - jniLibs.srcDirs = ['libs'] - } - } - packagingOptions { - pickFirst 'lib/arm64-v8a/libmlkit-label-MS.so' - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - -} - - -// Before gradle build. -// To download some necessary libraries. -apply from: 'download.gradle' - - -dependencies { - implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation 'androidx.appcompat:appcompat:1.3.0-alpha02' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' -// implementation project(path: ':sdk') - - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test.ext:junit:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - - implementation 'com.google.android.material:material:1.0.0' - androidTestImplementation 'com.android.support.test:rules:1.0.2' - androidTestImplementation 'com.google.truth:truth:1.0.1' - implementation 'com.github.bumptech.glide:glide:4.11.0' - annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' -} diff --git a/official/lite/pet_classification/app/download.gradle b/official/lite/pet_classification/app/download.gradle deleted file mode 100644 index 9b32e9b61154d0d892dd630b872c8ffb163c1325..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/download.gradle +++ /dev/null @@ -1,82 +0,0 @@ -/** - * To download necessary library from HuaWei server. - * Including mindspore-lite .so file, minddata-lite .so file and model file. - * The libraries can be downloaded manually. - */ -def targetMindSporeInclude = "src/main/cpp/" -def mindsporeLite_Version = "mindspore-lite-1.1.1-runtime-arm64-cpu" - -def targetModelFile = "src/main/assets/model/mobilenetv2.ms" -def mindSporeLibrary_arm64 = "src/main/cpp/${mindsporeLite_Version}.tar.gz" - -def modelDownloadUrl = "https://download.mindspore.cn/model_zoo/official/lite/mobilenetv2_openimage_lite/mobilenetv2.ms" -def mindsporeLiteDownloadUrl = "https://ms-release.obs.cn-north-4.myhuaweicloud.com/1.1.1/MindSpore/lite/release_0220/android/${mindsporeLite_Version}.tar.gz" - -def cleantargetMindSporeInclude = "src/main/cpp" - -task cleanCmakeCache(type: Delete) { - delete '.cxx/cmake/debug' - delete '.cxx/cmake/release' -} - -task downloadModelFile(type: DownloadUrlTask) { - doFirst { - println "Downloading ${modelDownloadUrl}" - } - sourceUrl = "${modelDownloadUrl}" - target = file("${targetModelFile}") -} - -task downloadMindSporeLibrary(type: DownloadUrlTask) { - doFirst { - println "Downloading ${mindsporeLiteDownloadUrl}" - } - sourceUrl = "${mindsporeLiteDownloadUrl}" - target = file("${mindSporeLibrary_arm64}") -} - -task unzipMindSporeInclude(type: Copy, dependsOn: 'downloadMindSporeLibrary') { - doFirst { - println "Unzipping ${mindSporeLibrary_arm64}" - } - from tarTree(resources.gzip("${mindSporeLibrary_arm64}")) - into "${targetMindSporeInclude}" -} - -task cleanUnusedmindsporeFiles(type: Delete, dependsOn: ['unzipMindSporeInclude']) { - delete fileTree("${cleantargetMindSporeInclude}").matching { - include "*.tar.gz" - } -} -/* - * Using preBuild to download mindspore library and model file. - * Run before gradle build. - */ -if (file("src/main/cpp/${mindsporeLite_Version}/lib/libmindspore-lite.so").exists()){ - downloadMindSporeLibrary.enabled = false - unzipMindSporeInclude.enabled = false - cleanUnusedmindsporeFiles.enabled = false -} - -if (file("src/main/assets/model/mobilenetv2.ms").exists()){ - downloadModelFile.enabled = false -} - -preBuild.dependsOn cleanCmakeCache -preBuild.dependsOn downloadModelFile -preBuild.dependsOn downloadMindSporeLibrary -preBuild.dependsOn unzipMindSporeInclude -preBuild.dependsOn cleanUnusedmindsporeFiles - -class DownloadUrlTask extends DefaultTask { - @Input - String sourceUrl - - @OutputFile - File target - - @TaskAction - void download() { - ant.get(src: sourceUrl, dest: target) - } -} diff --git a/official/lite/pet_classification/app/proguard-rules.pro b/official/lite/pet_classification/app/proguard-rules.pro deleted file mode 100644 index 481bb434814107eb79d7a30b676d344b0df2f8ce..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/androidTest/java/com/mindspore/classificationforpet/ExampleInstrumentedTest.java b/official/lite/pet_classification/app/src/androidTest/java/com/mindspore/classificationforpet/ExampleInstrumentedTest.java deleted file mode 100644 index fba0e2c36cbed5ae8fbe6e3467013a68e1d928a2..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/androidTest/java/com/mindspore/classificationforpet/ExampleInstrumentedTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mindspore.classificationforpet; - -import android.content.Context; - -import androidx.test.platform.app.InstrumentationRegistry; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumented test, which will execute on an Android device. - * - * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - assertEquals("com.mindspore.classification", appContext.getPackageName()); - } -} diff --git a/official/lite/pet_classification/app/src/main/AndroidManifest.xml b/official/lite/pet_classification/app/src/main/AndroidManifest.xml deleted file mode 100644 index d1bf88980f69f6571ad3a81dc46bf202bab84d96..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,50 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - package="com.mindspore.classificationforpet" - android:versionCode="1" - android:versionName="1.0"> - - <uses-permission android:name="android.permission.CAMERA" /> - <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" /> - <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" /> - <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> - <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> - <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEM" /> - <uses-permission android:name="android.permission.READ_PHONE_STATE" /> - - <application - android:allowBackup="true" - android:icon="@mipmap/ic_launcher" - android:label="@string/app_name" - android:requestLegacyExternalStorage="true" - android:roundIcon="@mipmap/ic_launcher_round" - android:supportsRtl="true" - android:theme="@style/AppTheme"> - <activity android:name="com.mindspore.classificationforpet.widget.MainActivity" - android:screenOrientation="portrait" - > - <intent-filter> - <action android:name="android.intent.action.MAIN" /> - <category android:name="android.intent.category.LAUNCHER" /> - </intent-filter> - </activity> - <activity - android:name="com.mindspore.classificationforpet.widget.CameraActivity" - android:screenOrientation="portrait"> - </activity> - - <provider - android:name="androidx.core.content.FileProvider" - android:authorities="com.mindspore.classificationforpet.fileprovider" - android:exported="false" - tools:replace="android:authorities" - android:grantUriPermissions="true"> - <meta-data - tools:replace="android:resource" - android:name="android.support.FILE_PROVIDER_PATHS" - android:resource="@xml/file_paths" /> - </provider> - </application> - -</manifest> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/assets/model/car.ms b/official/lite/pet_classification/app/src/main/assets/model/car.ms deleted file mode 100644 index 6fb38984d78b7ba3c679bcdcc4199729b6899e09..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/assets/model/car.ms and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/assets/model/mobilenetv2.ms b/official/lite/pet_classification/app/src/main/assets/model/mobilenetv2.ms deleted file mode 100644 index a13432bf2f7118f6f0e332387e54998422561e20..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/assets/model/mobilenetv2.ms and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/cpp/ImageMindSporeNetnative.cpp b/official/lite/pet_classification/app/src/main/cpp/ImageMindSporeNetnative.cpp deleted file mode 100644 index 55d2364bcbf41a50a3a22041d1d026adcabb3a0f..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/cpp/ImageMindSporeNetnative.cpp +++ /dev/null @@ -1,397 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include <jni.h> -#include <android/bitmap.h> -#include <android/asset_manager_jni.h> -#include <android/log.h> -#include <utility> -#include <cstring> -#include <vector> -#include <string> -#include <unordered_map> -#include <set> -#include "include/errorcode.h" -#include "include/ms_tensor.h" -#include "ImageMindSporeNetnative.h" -#include "MSNetWork.h" -#include "lite_cv/lite_mat.h" -#include "lite_cv/image_process.h" - -using mindspore::dataset::LiteMat; -using mindspore::dataset::LPixelType; -using mindspore::dataset::LDataType; -#define MS_PRINT(format, ...) __android_log_print(ANDROID_LOG_INFO, "MSJNI", format, ##__VA_ARGS__) - - -static const int RET_CATEGORY_SUM = 410; - -static float g_thres_map[RET_CATEGORY_SUM] = { - 0.23, 0.03, 0.10, 0.13, 0.03, - 0.10, 0.06, 0.09, 0.09, 0.05, - 0.01, 0.04, 0.01, 0.27, 0.05, - 0.16, 0.01, 0.16, 0.04, 0.13, - 0.09, 0.18, 0.10, 0.65, 0.08, - 0.04, 0.08, 0.01, 0.05, 0.20, - 0.01, 0.16, 0.10, 0.10, 0.10, - 0.02, 0.24, 0.08, 0.10, 0.53, - 0.07, 0.05, 0.07, 0.27, 0.02, - 0.01, 0.71, 0.01, 0.06, 0.06, - 0.03, 0.96, 0.03, 0.94, 0.05, - 0.03, 0.14, 0.09, 0.03, 0.11, - 0.50, 0.16, 0.07, 0.07, 0.06, - 0.07, 0.08, 0.10, 0.29, 0.03, - 0.05, 0.11, 0.03, 0.03, 0.03, - 0.01, 0.11, 0.07, 0.03, 0.49, - 0.12, 0.30, 0.10, 0.15, 0.02, - 0.06, 0.17, 0.01, 0.04, 0.07, - 0.06, 0.02, 0.19, 0.20, 0.14, - 0.35, 0.15, 0.01, 0.10, 0.13, - 0.43, 0.11, 0.12, 0.32, 0.01, - 0.22, 0.51, 0.02, 0.04, 0.14, - 0.04, 0.35, 0.35, 0.01, 0.54, - 0.04, 0.02, 0.03, 0.02, 0.38, - 0.13, 0.19, 0.06, 0.01, 0.02, - 0.06, 0.03, 0.04, 0.01, 0.10, - 0.01, 0.07, 0.07, 0.07, 0.33, - 0.08, 0.04, 0.06, 0.07, 0.07, - 0.11, 0.02, 0.32, 0.48, 0.14, - 0.01, 0.01, 0.04, 0.05, 0.04, - 0.16, 0.50, 0.11, 0.03, 0.04, - 0.02, 0.55, 0.17, 0.13, 0.84, - 0.18, 0.03, 0.16, 0.02, 0.06, - 0.03, 0.11, 0.96, 0.36, 0.68, - 0.02, 0.08, 0.02, 0.01, 0.03, - 0.05, 0.14, 0.09, 0.06, 0.03, - 0.20, 0.15, 0.62, 0.03, 0.10, - 0.08, 0.02, 0.02, 0.06, 0.03, - 0.04, 0.01, 0.10, 0.05, 0.04, - 0.02, 0.07, 0.03, 0.32, 0.11, - 0.03, 0.02, 0.03, 0.01, 0.03, - 0.03, 0.25, 0.20, 0.19, 0.03, - 0.11, 0.03, 0.02, 0.03, 0.15, - 0.14, 0.06, 0.11, 0.03, 0.02, - 0.02, 0.52, 0.03, 0.02, 0.02, - 0.02, 0.09, 0.56, 0.01, 0.22, - 0.01, 0.48, 0.14, 0.10, 0.08, - 0.73, 0.39, 0.09, 0.10, 0.85, - 0.31, 0.03, 0.05, 0.01, 0.01, - 0.01, 0.10, 0.28, 0.02, 0.03, - 0.04, 0.03, 0.07, 0.14, 0.20, - 0.10, 0.01, 0.05, 0.37, 0.12, - 0.04, 0.44, 0.04, 0.26, 0.08, - 0.07, 0.27, 0.10, 0.03, 0.01, - 0.03, 0.16, 0.41, 0.16, 0.34, - 0.04, 0.30, 0.04, 0.05, 0.18, - 0.33, 0.03, 0.21, 0.03, 0.04, - 0.22, 0.01, 0.04, 0.02, 0.01, - 0.06, 0.02, 0.08, 0.87, 0.11, - 0.15, 0.05, 0.14, 0.09, 0.08, - 0.22, 0.09, 0.07, 0.06, 0.06, - 0.05, 0.43, 0.70, 0.03, 0.07, - 0.06, 0.07, 0.14, 0.04, 0.01, - 0.03, 0.05, 0.65, 0.06, 0.04, - 0.23, 0.06, 0.75, 0.10, 0.01, - 0.63, 0.41, 0.09, 0.01, 0.01, - 0.18, 0.10, 0.03, 0.01, 0.05, - 0.13, 0.18, 0.03, 0.23, 0.01, - 0.04, 0.03, 0.38, 0.90, 0.21, - 0.18, 0.10, 0.48, 0.08, 0.46, - 0.03, 0.01, 0.02, 0.03, 0.10, - 0.01, 0.09, 0.01, 0.01, 0.01, - 0.10, 0.41, 0.01, 0.06, 0.75, - 0.08, 0.01, 0.01, 0.08, 0.21, - 0.06, 0.02, 0.05, 0.02, 0.05, - 0.09, 0.12, 0.03, 0.06, 0.11, - 0.03, 0.01, 0.01, 0.06, 0.84, - 0.04, 0.81, 0.39, 0.02, 0.29, - 0.77, 0.07, 0.06, 0.22, 0.23, - 0.23, 0.01, 0.02, 0.13, 0.04, - 0.19, 0.04, 0.08, 0.27, 0.09, - 0.06, 0.01, 0.03, 0.21, 0.04, -}; - -char *ImageCreateLocalModelBuffer(JNIEnv *env, jobject modelBuffer) { - jbyte *modelAddr = static_cast<jbyte *>(env->GetDirectBufferAddress(modelBuffer)); - int modelLen = static_cast<int>(env->GetDirectBufferCapacity(modelBuffer)); - char *buffer(new char[modelLen]); - memcpy(buffer, modelAddr, modelLen); - return buffer; -} - -/** - * To process the result of mindspore inference. - * @param msOutputs - * @return - */ -std::string ImageProcessRunnetResult(const int RET_CATEGORY_SUM, - std::unordered_map<std::string, mindspore::tensor::MSTensor *> msOutputs) { - // Get the branch of the model output. - // Use iterators to get map elements. - std::unordered_map<std::string, mindspore::tensor::MSTensor *>::iterator iter; - iter = msOutputs.begin(); - - // The mobilenetv2.ms model output just one branch. - auto outputTensor = iter->second; - - int tensorNum = outputTensor->ElementsNum(); - MS_PRINT("Number of tensor elements:%d", tensorNum); - - // Get a pointer to the first score. - float *temp_scores = static_cast<float *>(outputTensor->MutableData()); - float scores[RET_CATEGORY_SUM]; - for (int i = 0; i < RET_CATEGORY_SUM; ++i) { - scores[i] = temp_scores[i]; - } - - const float unifiedThre = 0.5; - const float probMax = 1.0; - for (size_t i = 0; i < RET_CATEGORY_SUM; ++i) { - float threshold = g_thres_map[i]; - float tmpProb = scores[i]; - if (tmpProb < threshold) { - tmpProb = tmpProb / threshold * unifiedThre; - } else { - tmpProb = (tmpProb - threshold) / (probMax - threshold) * unifiedThre + unifiedThre; - } - scores[i] = tmpProb; - } - - // Score for each category. - // Converted to text information that needs to be displayed in the APP. - std::string categoryScore = ""; - for (int i = 0; i < RET_CATEGORY_SUM; ++i) { - categoryScore += std::to_string(i); - categoryScore += ":"; - std::string score_str = std::to_string(scores[i]); - categoryScore += score_str; - categoryScore += ";"; - } - MS_PRINT("categoryScore:%s", categoryScore.c_str()); - - return categoryScore; -} - -bool ImageBitmapToLiteMat(JNIEnv *env, const jobject &srcBitmap, LiteMat *lite_mat) { - bool ret = false; - AndroidBitmapInfo info; - void *pixels = nullptr; - LiteMat &lite_mat_bgr = *lite_mat; - AndroidBitmap_getInfo(env, srcBitmap, &info); - if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) { - MS_PRINT("Image Err, Request RGBA"); - return false; - } - AndroidBitmap_lockPixels(env, srcBitmap, &pixels); - if (info.stride == info.width * 4) { - ret = InitFromPixel(reinterpret_cast<const unsigned char *>(pixels), - LPixelType::RGBA2RGB, LDataType::UINT8, - info.width, info.height, lite_mat_bgr); - if (!ret) { - MS_PRINT("Init From RGBA error"); - } - } else { - unsigned char *pixels_ptr = new unsigned char[info.width * info.height * 4]; - unsigned char *ptr = pixels_ptr; - unsigned char *data = reinterpret_cast<unsigned char *>(pixels); - for (int i = 0; i < info.height; i++) { - memcpy(ptr, data, info.width * 4); - ptr += info.width * 4; - data += info.stride; - } - ret = InitFromPixel(reinterpret_cast<const unsigned char *>(pixels_ptr), - LPixelType::RGBA2RGB, LDataType::UINT8, - info.width, info.height, lite_mat_bgr); - if (!ret) { - MS_PRINT("Init From RGBA error"); - } - delete[] (pixels_ptr); - } - AndroidBitmap_unlockPixels(env, srcBitmap); - return ret; -} - -bool ImagePreProcessImageData(const LiteMat &lite_mat_bgr, LiteMat *lite_norm_mat_ptr) { - bool ret = false; - LiteMat lite_mat_resize; - LiteMat &lite_norm_mat_cut = *lite_norm_mat_ptr; - ret = ResizeBilinear(lite_mat_bgr, lite_mat_resize, 256, 256); - if (!ret) { - MS_PRINT("ResizeBilinear error"); - return false; - } - LiteMat lite_mat_convert_float; - ret = ConvertTo(lite_mat_resize, lite_mat_convert_float, 1.0 / 255.0); - if (!ret) { - MS_PRINT("ConvertTo error"); - return false; - } - LiteMat lite_mat_cut; - ret = Crop(lite_mat_convert_float, lite_mat_cut, 16, 16, 224, 224); - if (!ret) { - MS_PRINT("Crop error"); - return false; - } - 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; -} - - -/** - * The Java layer reads the model into MappedByteBuffer or ByteBuffer to load the model. - */ -extern "C" -JNIEXPORT jlong JNICALL -Java_com_mindspore_classificationforpet_gallery_classify_ImageTrackingMobile_loadModel(JNIEnv *env, - jobject thiz, - jobject model_buffer, - jint num_thread) { - if (nullptr == model_buffer) { - MS_PRINT("error, buffer is nullptr!"); - return (jlong) nullptr; - } - jlong bufferLen = env->GetDirectBufferCapacity(model_buffer); - if (0 == bufferLen) { - MS_PRINT("error, bufferLen is 0!"); - return (jlong) nullptr; - } - - char *modelBuffer = ImageCreateLocalModelBuffer(env, model_buffer); - if (modelBuffer == nullptr) { - MS_PRINT("modelBuffer create failed!"); - return (jlong) nullptr; - } - - // To create a mindspore network inference environment. - void **labelEnv = new void *; - MSNetWork *labelNet = new MSNetWork; - *labelEnv = labelNet; - - mindspore::lite::Context *context = new mindspore::lite::Context; - context->thread_num_ = num_thread; - - labelNet->CreateSessionMS(modelBuffer, bufferLen, context); - delete context; - - if (labelNet->session() == nullptr) { - MS_PRINT("MindSpore create session failed!."); - delete labelNet; - delete labelEnv; - return (jlong) nullptr; - } - - if (model_buffer != nullptr) { - env->DeleteLocalRef(model_buffer); - } - - return (jlong) labelEnv; -} - -/** - * After the inference environment is successfully created, - * sending a picture to the model and run inference. - */ -extern "C" JNIEXPORT jstring JNICALL -Java_com_mindspore_classificationforpet_gallery_classify_ImageTrackingMobile_runNet(JNIEnv *env, - jclass type, - jlong netEnv, - jobject srcBitmap) { - LiteMat lite_mat_bgr, lite_norm_mat_cut; - - if (!ImageBitmapToLiteMat(env, srcBitmap, &lite_mat_bgr)) { - MS_PRINT("ImageBitmapToLiteMat error"); - return NULL; - } - if (!ImagePreProcessImageData(lite_mat_bgr, &lite_norm_mat_cut)) { - MS_PRINT("ImagePreProcessImageData error"); - return NULL; - } - - ImgDims inputDims; - inputDims.channel = lite_norm_mat_cut.channel_; - inputDims.width = lite_norm_mat_cut.width_; - inputDims.height = lite_norm_mat_cut.height_; - - // Get the mindsore inference environment which created in loadModel(). - void **labelEnv = reinterpret_cast<void **>(netEnv); - if (labelEnv == nullptr) { - MS_PRINT("MindSpore error, labelEnv is a nullptr."); - return NULL; - } - MSNetWork *labelNet = static_cast<MSNetWork *>(*labelEnv); - - auto mSession = labelNet->session(); - if (mSession == nullptr) { - MS_PRINT("MindSpore error, Session is a nullptr."); - return NULL; - } - MS_PRINT("MindSpore get session."); - - auto msInputs = mSession->GetInputs(); - if (msInputs.size() == 0) { - MS_PRINT("MindSpore error, msInputs.size() equals 0."); - return NULL; - } - auto inTensor = msInputs.front(); - - float *dataHWC = reinterpret_cast<float *>(lite_norm_mat_cut.data_ptr_); - // Copy dataHWC to the model input tensor. - memcpy(inTensor->MutableData(), dataHWC, - inputDims.channel * inputDims.width * inputDims.height * sizeof(float)); - - // After the model and image tensor data is loaded, run inference. - auto status = mSession->RunGraph(); - - if (status != mindspore::lite::RET_OK) { - MS_PRINT("MindSpore run net error."); - return NULL; - } - - /** - * Get the mindspore inference results. - * Return the map of output node name and MindSpore Lite MSTensor. - */ - auto names = mSession->GetOutputTensorNames(); - std::unordered_map<std::string, mindspore::tensor::MSTensor *> msOutputs; - for (const auto &name : names) { - auto temp_dat = mSession->GetOutputByTensorName(name); - msOutputs.insert(std::pair<std::string, mindspore::tensor::MSTensor *>{name, temp_dat}); - } - - std::string resultStr = ImageProcessRunnetResult(::RET_CATEGORY_SUM, msOutputs); - MS_PRINT("resultStr:%s", resultStr.c_str()); - - const char *resultCharData = resultStr.c_str(); - - return (env)->NewStringUTF(resultCharData); -} - -extern "C" JNIEXPORT jboolean JNICALL -Java_com_mindspore_classificationforpet_gallery_classify_ImageTrackingMobile_unloadModel(JNIEnv *env, - jclass type, - jlong netEnv) { - MS_PRINT("MindSpore release net."); - void **labelEnv = reinterpret_cast<void **>(netEnv); - if (labelEnv == nullptr) { - MS_PRINT("MindSpore error, labelEnv is a nullptr."); - } - MSNetWork *labelNet = static_cast<MSNetWork *>(*labelEnv); - - labelNet->ReleaseNets(); - - return (jboolean) true; -} diff --git a/official/lite/pet_classification/app/src/main/cpp/ImageMindSporeNetnative.h b/official/lite/pet_classification/app/src/main/cpp/ImageMindSporeNetnative.h deleted file mode 100644 index 688409082cc073a0b59bebeb4031b9a81546eaed..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/cpp/ImageMindSporeNetnative.h +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef IMAGE_MINDSPORE_JNI_HMS_DEBUG_MINDSPORENETNATIVE_H -#define IMAGE_MINDSPORE_JNI_HMS_DEBUG_MINDSPORENETNATIVE_H - - -#endif // MINDSPORE_JNI_HMS_DEBUG_MINDSPORENETNATIVE_H diff --git a/official/lite/pet_classification/app/src/main/cpp/MSNetWork.cpp b/official/lite/pet_classification/app/src/main/cpp/MSNetWork.cpp deleted file mode 100644 index 1401303a39a99f584d6ddb001a521e93802df2a4..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/cpp/MSNetWork.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "MSNetWork.h" -#include <android/log.h> -#include <iostream> -#include <string> -#include "include/errorcode.h" - -#define MS_PRINT(format, ...) __android_log_print(ANDROID_LOG_INFO, "MSJNI", format, ##__VA_ARGS__) - -MSNetWork::MSNetWork(void) : session_(nullptr), model_(nullptr) {} - -MSNetWork::~MSNetWork(void) {} - -void MSNetWork::CreateSessionMS(char *modelBuffer, size_t bufferLen, mindspore::lite::Context *ctx) { - session_ = mindspore::session::LiteSession::CreateSession(ctx); - if (session_ == nullptr) { - MS_PRINT("Create Session failed."); - return; - } - - // Compile model. - model_ = mindspore::lite::Model::Import(modelBuffer, bufferLen); - if (model_ == nullptr) { - ReleaseNets(); - MS_PRINT("Import model failed."); - return; - } - - int ret = session_->CompileGraph(model_); - if (ret != mindspore::lite::RET_OK) { - ReleaseNets(); - MS_PRINT("CompileGraph failed."); - return; - } -} - -void MSNetWork::ReleaseNets(void) { - if (model_ != nullptr) { - model_->Free(); - delete model_; - model_ = nullptr; - } - if (session_ != nullptr) { - delete session_; - session_ = nullptr; - } -} diff --git a/official/lite/pet_classification/app/src/main/cpp/MSNetWork.h b/official/lite/pet_classification/app/src/main/cpp/MSNetWork.h deleted file mode 100644 index cbf9a89afbf37df60b776feedda4b11e381c6639..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/cpp/MSNetWork.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MSNETWORK_H -#define MSNETWORK_H - -#include <context.h> -#include <lite_session.h> -#include <model.h> -#include <errorcode.h> -#include <cstdio> -#include <algorithm> -#include <fstream> -#include <functional> -#include <sstream> -#include <vector> -#include <map> -#include <string> -#include <memory> -#include <utility> - -struct ImgDims { - int channel = 0; - int width = 0; - int height = 0; -}; - -/*struct SessIterm { - std::shared_ptr<mindspore::session::LiteSession> sess = nullptr; -};*/ - -class MSNetWork { - public: - MSNetWork(); - - ~MSNetWork(); - - void CreateSessionMS(char *modelBuffer, size_t bufferLen, mindspore::lite::Context *ctx); - - void ReleaseNets(void); - - mindspore::session::LiteSession *session() const { return session_; } - private: - mindspore::session::LiteSession *session_; - mindspore::lite::Model *model_; -}; -#endif diff --git a/official/lite/pet_classification/app/src/main/cpp/MindSporeNetnative.cpp b/official/lite/pet_classification/app/src/main/cpp/MindSporeNetnative.cpp deleted file mode 100644 index 611856ecc0b17ef10b243ebc3a7946fad4f5c5d4..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/cpp/MindSporeNetnative.cpp +++ /dev/null @@ -1,295 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include <jni.h> -#include <android/bitmap.h> -#include <android/asset_manager_jni.h> -#include <android/log.h> -#include <utility> -#include <cstring> -#include <vector> -#include <string> -#include <unordered_map> -#include <set> -#include "include/errorcode.h" -#include "include/ms_tensor.h" -#include "MindSporeNetnative.h" -#include "MSNetWork.h" -#include "lite_cv/lite_mat.h" -#include "lite_cv/image_process.h" - -using mindspore::dataset::LiteMat; -using mindspore::dataset::LPixelType; -using mindspore::dataset::LDataType; -#define MS_PRINT(format, ...) __android_log_print(ANDROID_LOG_INFO, "MSJNI", format, ##__VA_ARGS__) - - -static const int RET_PET_DETAILED_SUM = 2; -static const char *labels_name_pet_detailed_map[RET_PET_DETAILED_SUM] = { - {"鐚�"}, - {"鐙�"} -}; - - -char *CreateLocalModelBuffer(JNIEnv *env, jobject modelBuffer) { - jbyte *modelAddr = static_cast<jbyte *>(env->GetDirectBufferAddress(modelBuffer)); - int modelLen = static_cast<int>(env->GetDirectBufferCapacity(modelBuffer)); - char *buffer(new char[modelLen]); - memcpy(buffer, modelAddr, modelLen); - return buffer; -} - -/** - * To process the result of mindspore inference. - * @param msOutputs - * @return - */ -std::string ProcessRunnetResult(const int RET_CATEGORY_SUM, - std::unordered_map<std::string, mindspore::tensor::MSTensor *> msOutputs) { - // Get the branch of the model output. - // Use iterators to get map elements. - std::unordered_map<std::string, mindspore::tensor::MSTensor *>::iterator iter; - iter = msOutputs.begin(); - - // The mobilenetv2.ms model output just one branch. - auto outputTensor = iter->second; - - // Get a pointer to the first score. - float *temp_scores = static_cast<float *>(outputTensor->MutableData()); - float max = 0.0; - int maxIndex = 0; - for (int i = 0; i < RET_PET_DETAILED_SUM; ++i) { - if (temp_scores[i] > max) { - max = temp_scores[i]; - maxIndex = i; - } - } - - // Score for each category. - // Converted to text information that needs to be displayed in the APP. - std::string categoryScore = ""; - categoryScore += std::to_string(maxIndex); - return categoryScore; -} - -bool BitmapToLiteMat(JNIEnv *env, const jobject &srcBitmap, LiteMat *lite_mat) { - bool ret = false; - AndroidBitmapInfo info; - void *pixels = nullptr; - LiteMat &lite_mat_bgr = *lite_mat; - AndroidBitmap_getInfo(env, srcBitmap, &info); - if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) { - MS_PRINT("Image Err, Request RGBA"); - return false; - } - AndroidBitmap_lockPixels(env, srcBitmap, &pixels); - if (info.stride == info.width * 4) { - ret = InitFromPixel(reinterpret_cast<const unsigned char *>(pixels), - LPixelType::RGBA2RGB, LDataType::UINT8, - info.width, info.height, lite_mat_bgr); - if (!ret) { - MS_PRINT("Init From RGBA error"); - } - } else { - unsigned char *pixels_ptr = new unsigned char[info.width * info.height * 4]; - unsigned char *ptr = pixels_ptr; - unsigned char *data = reinterpret_cast<unsigned char *>(pixels); - for (int i = 0; i < info.height; i++) { - memcpy(ptr, data, info.width * 4); - ptr += info.width * 4; - data += info.stride; - } - ret = InitFromPixel(reinterpret_cast<const unsigned char *>(pixels_ptr), - LPixelType::RGBA2RGB, LDataType::UINT8, - info.width, info.height, lite_mat_bgr); - if (!ret) { - MS_PRINT("Init From RGBA error"); - } - delete[] (pixels_ptr); - } - AndroidBitmap_unlockPixels(env, srcBitmap); - return ret; -} - -bool PreProcessImageData(const LiteMat &lite_mat_bgr, LiteMat *lite_norm_mat_ptr) { - bool ret = false; - LiteMat lite_mat_resize; - LiteMat &lite_norm_mat_cut = *lite_norm_mat_ptr; - ret = ResizeBilinear(lite_mat_bgr, lite_mat_resize, 256, 256); - if (!ret) { - MS_PRINT("ResizeBilinear error"); - return false; - } - LiteMat lite_mat_convert_float; - ret = ConvertTo(lite_mat_resize, lite_mat_convert_float, 1.0 / 255.0); - if (!ret) { - MS_PRINT("ConvertTo error"); - return false; - } - LiteMat lite_mat_cut; - ret = Crop(lite_mat_convert_float, lite_mat_cut, 16, 16, 224, 224); - if (!ret) { - MS_PRINT("Crop error"); - return false; - } - 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; -} - - -/** - * The Java layer reads the model into MappedByteBuffer or ByteBuffer to load the model. - */ -extern "C" -JNIEXPORT jlong JNICALL -Java_com_mindspore_classificationforpet_gallery_classify_TrackingMobile_loadModel(JNIEnv *env, - jobject thiz, - jobject model_buffer, - jint num_thread) { - if (nullptr == model_buffer) { - MS_PRINT("error, buffer is nullptr!"); - return (jlong) nullptr; - } - jlong bufferLen = env->GetDirectBufferCapacity(model_buffer); - if (0 == bufferLen) { - MS_PRINT("error, bufferLen is 0!"); - return (jlong) nullptr; - } - - char *modelBuffer = CreateLocalModelBuffer(env, model_buffer); - if (modelBuffer == nullptr) { - MS_PRINT("modelBuffer create failed!"); - return (jlong) nullptr; - } - - // To create a mindspore network inference environment. - void **labelEnv = new void *; - MSNetWork *labelNet = new MSNetWork; - *labelEnv = labelNet; - - mindspore::lite::Context *context = new mindspore::lite::Context; - context->thread_num_ = num_thread; - - labelNet->CreateSessionMS(modelBuffer, bufferLen, context); - delete context; - - if (labelNet->session() == nullptr) { - MS_PRINT("MindSpore create session failed!."); - delete labelNet; - delete labelEnv; - return (jlong) nullptr; - } - - if (model_buffer != nullptr) { - env->DeleteLocalRef(model_buffer); - } - - return (jlong) labelEnv; -} - -/** - * After the inference environment is successfully created, - * sending a picture to the model and run inference. - */ -extern "C" JNIEXPORT jstring JNICALL -Java_com_mindspore_classificationforpet_gallery_classify_TrackingMobile_runNet(JNIEnv *env, jclass type, - jlong netEnv, - jobject srcBitmap) { - LiteMat lite_mat_bgr, lite_norm_mat_cut; - - if (!BitmapToLiteMat(env, srcBitmap, &lite_mat_bgr)) { - MS_PRINT("BitmapToLiteMat error"); - return NULL; - } - if (!PreProcessImageData(lite_mat_bgr, &lite_norm_mat_cut)) { - MS_PRINT("PreProcessImageData error"); - return NULL; - } - - ImgDims inputDims; - inputDims.channel = lite_norm_mat_cut.channel_; - inputDims.width = lite_norm_mat_cut.width_; - inputDims.height = lite_norm_mat_cut.height_; - - // Get the mindsore inference environment which created in loadModel(). - void **labelEnv = reinterpret_cast<void **>(netEnv); - if (labelEnv == nullptr) { - MS_PRINT("MindSpore error, labelEnv is a nullptr."); - return NULL; - } - MSNetWork *labelNet = static_cast<MSNetWork *>(*labelEnv); - - auto mSession = labelNet->session(); - if (mSession == nullptr) { - MS_PRINT("MindSpore error, Session is a nullptr."); - return NULL; - } - MS_PRINT("MindSpore get session."); - - auto msInputs = mSession->GetInputs(); - if (msInputs.size() == 0) { - MS_PRINT("MindSpore error, msInputs.size() equals 0."); - return NULL; - } - auto inTensor = msInputs.front(); - - float *dataHWC = reinterpret_cast<float *>(lite_norm_mat_cut.data_ptr_); - // Copy dataHWC to the model input tensor. - memcpy(inTensor->MutableData(), dataHWC, - inputDims.channel * inputDims.width * inputDims.height * sizeof(float)); - - // After the model and image tensor data is loaded, run inference. - auto status = mSession->RunGraph(); - - if (status != mindspore::lite::RET_OK) { - MS_PRINT("MindSpore run net error."); - return NULL; - } - - /** - * Get the mindspore inference results. - * Return the map of output node name and MindSpore Lite MSTensor. - */ - auto names = mSession->GetOutputTensorNames(); - - std::unordered_map<std::string, mindspore::tensor::MSTensor *> msOutputs; - for (const auto &name : names) { - auto temp_dat = mSession->GetOutputByTensorName(name); - msOutputs.insert(std::pair<std::string, mindspore::tensor::MSTensor *>{name, temp_dat}); - } - - std::string resultStr = ProcessRunnetResult(::RET_PET_DETAILED_SUM, msOutputs); - - const char *resultCharData = resultStr.c_str(); - return (env)->NewStringUTF(resultCharData); -} - -extern "C" JNIEXPORT jboolean JNICALL -Java_com_mindspore_classificationforpet_gallery_classify_TrackingMobile_unloadModel(JNIEnv *env, - jclass type, - jlong netEnv) { - MS_PRINT("MindSpore release net."); - void **labelEnv = reinterpret_cast<void **>(netEnv); - if (labelEnv == nullptr) { - MS_PRINT("MindSpore error, labelEnv is a nullptr."); - } - MSNetWork *labelNet = static_cast<MSNetWork *>(*labelEnv); - - labelNet->ReleaseNets(); - - return (jboolean) true; -} diff --git a/official/lite/pet_classification/app/src/main/cpp/MindSporeNetnative.h b/official/lite/pet_classification/app/src/main/cpp/MindSporeNetnative.h deleted file mode 100644 index 92707373fee67b2490953ea328655fa2cde9d09c..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/cpp/MindSporeNetnative.h +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MINDSPORE_JNI_HMS_DEBUG_MINDSPORENETNATIVE_H -#define MINDSPORE_JNI_HMS_DEBUG_MINDSPORENETNATIVE_H - - -#endif // MINDSPORE_JNI_HMS_DEBUG_MINDSPORENETNATIVE_H diff --git a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/gallery/classify/BitmapUtils.java b/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/gallery/classify/BitmapUtils.java deleted file mode 100644 index f4b677c5d4ccc25450ca67e7d7c0dbb68440f519..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/gallery/classify/BitmapUtils.java +++ /dev/null @@ -1,165 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * <p> - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mindspore.classificationforpet.gallery.classify; - -import android.app.Activity; -import android.content.ContentResolver; -import android.content.Context; -import android.database.Cursor; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Matrix; -import android.media.ExifInterface; -import android.net.Uri; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; - -public class BitmapUtils { - private static final String TAG = "BitmapUtils"; - - public static void recycleBitmap(Bitmap... bitmaps) { - for (Bitmap bitmap : bitmaps) { - if (bitmap != null && !bitmap.isRecycled()) { - bitmap.recycle(); - bitmap = null; - } - } - } - - public static Bitmap getBitmapFormUri(Activity ac, Uri uri) { - Bitmap bitmap = null; - try { - InputStream input = ac.getContentResolver().openInputStream(uri); - BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options(); - onlyBoundsOptions.inJustDecodeBounds = true; - onlyBoundsOptions.inDither = true;//optional - onlyBoundsOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;//optional - BitmapFactory.decodeStream(input, null, onlyBoundsOptions); - input.close(); - int originalWidth = onlyBoundsOptions.outWidth; - int originalHeight = onlyBoundsOptions.outHeight; - if ((originalWidth == -1) || (originalHeight == -1)) - return null; - float hh = 1920f; - float ww = 1080f; - int be = 1; - if (originalWidth > originalHeight && originalWidth > ww) { - be = (int) (originalWidth / ww); - } else if (originalWidth < originalHeight && originalHeight > hh) { - be = (int) (originalHeight / hh); - } - if (be <= 0) { - be = 1; - } - BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); - bitmapOptions.inSampleSize = be; - bitmapOptions.inDither = true;//optional - bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;//optional - input = ac.getContentResolver().openInputStream(uri); - bitmap = BitmapFactory.decodeStream(input, null, bitmapOptions); - input.close(); - - - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return compressImage(bitmap); - } - - - public static Bitmap compressImage(Bitmap image) { - if (image != null) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - image.compress(Bitmap.CompressFormat.JPEG, 100, baos); - int options = 100; - while (baos.toByteArray().length / 1024 > 100) { - baos.reset(); - image.compress(Bitmap.CompressFormat.JPEG, options, baos); - options -= 10; - } - ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray()); - Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null); - return bitmap; - }else { - return null; - } - } - - public static File getFileFromMediaUri(Context ac, Uri uri) { - if (uri.getScheme().toString().compareTo("content") == 0) { - ContentResolver cr = ac.getContentResolver(); - Cursor cursor = cr.query(uri, null, null, null, null); - if (cursor != null) { - cursor.moveToFirst(); - String filePath = cursor.getString(cursor.getColumnIndex("_data")); - cursor.close(); - if (filePath != null) { - return new File(filePath); - } - } - } else if (uri.getScheme().toString().compareTo("file") == 0) { - return new File(uri.toString().replace("file://", "")); - } - return null; - } - - public static int getBitmapDegree(String path) { - int degree = 0; - try { - ExifInterface exifInterface = new ExifInterface(path); - int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, - ExifInterface.ORIENTATION_NORMAL); - switch (orientation) { - case ExifInterface.ORIENTATION_ROTATE_90: - degree = 90; - break; - case ExifInterface.ORIENTATION_ROTATE_180: - degree = 180; - break; - case ExifInterface.ORIENTATION_ROTATE_270: - degree = 270; - break; - } - } catch (IOException e) { - e.printStackTrace(); - } - return degree; - } - - public static Bitmap rotateBitmapByDegree(Bitmap bm, int degree) { - Bitmap returnBm = null; - Matrix matrix = new Matrix(); - matrix.postRotate(degree); - try { - returnBm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); - } catch (OutOfMemoryError e) { - } - if (returnBm == null) { - returnBm = bm; - } - if (bm != returnBm) { - bm.recycle(); - } - return returnBm; - } -} diff --git a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/gallery/classify/CompareSizesByArea.java b/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/gallery/classify/CompareSizesByArea.java deleted file mode 100644 index 85511d9b488b591641fd2adce395ba7dde9ee2f4..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/gallery/classify/CompareSizesByArea.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mindspore.classificationforpet.gallery.classify; - -import android.util.Size; -import java.util.Comparator; - -/** - * Data comparator. - */ - -public class CompareSizesByArea implements Comparator<Size> { - - @Override - public int compare(Size lhs, Size rhs) { - // We cast here to ensure the multiplications won't overflow - return Long.signum((long) lhs.getWidth() * lhs.getHeight() - (long) rhs.getWidth() * rhs.getHeight()); - } - -} \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/gallery/classify/ImageTrackingMobile.java b/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/gallery/classify/ImageTrackingMobile.java deleted file mode 100644 index 6fa7a3660e1b9384ed5421e33e9e8e1124475ecb..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/gallery/classify/ImageTrackingMobile.java +++ /dev/null @@ -1,128 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * <p> - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mindspore.classificationforpet.gallery.classify; - -import android.content.Context; -import android.graphics.Bitmap; -import android.util.Log; - -import java.io.InputStream; -import java.nio.ByteBuffer; - -/** - * Call the MindSpore interface API in the Java layer. - */ -public class ImageTrackingMobile { - private final static String TAG = "ImageTrackingMobile"; - - static { - try { - System.loadLibrary("mlkit-label-MS"); - Log.i(TAG, "load libiMindSpore.so successfully."); - } catch (UnsatisfiedLinkError e) { - Log.e(TAG, "UnsatisfiedLinkError >>>>>>" + e.getMessage()); - } - } - - // The address of the running inference environment. - private long netEnv = 0; - - private final Context mActivity; - - public ImageTrackingMobile(Context activity) { - this.mActivity = activity; - } - - /** - * JNI load model and also create model inference environment. - * - * @param modelBuffer Model buffer. - * @param numThread The num of thread. - * @return MindSpore Inference environment address. - */ - public native long loadModel(ByteBuffer modelBuffer, int numThread); - - /** - * Running model. - * - * @param netEnv Inference environment address. - * @param img A picture to be inferred. - * @return Inference result - */ - public native String runNet(long netEnv, Bitmap img); - - /** - * Unbind model data. - * - * @param netEnv Inference environment address. - * @return Unbound state. - */ - public native boolean unloadModel(long netEnv); - - /** - * The C++ side is encapsulated into a method of the MSNetWorks class - * - * @param modelPath Model file location - * @return Load model file status - */ - public boolean loadModelFromBuf(String modelPath) { - ByteBuffer buffer = loadModelFile(modelPath); - netEnv = loadModel(buffer, 2); //numThread's default setting is 2. - if (netEnv == 0) { // Loading model failed. - return false; - } - - return true; - } - - /** - * Run MindSpore inference. - */ - public String MindSpore_runnet(Bitmap img) { - String ret_str = runNet(netEnv, img); - return ret_str; - } - - /** - * Unload model. - * - * @return true - */ - public boolean unloadModel() { - unloadModel(netEnv); - return true; - } - - /** - * Load model file stream. - * - * @param modelPath Model file path. - * @return Model ByteBuffer. - */ - public ByteBuffer loadModelFile(String modelPath) { - InputStream is = null; - try { - is = mActivity.getAssets().open(modelPath); - byte[] bytes = new byte[is.available()]; - is.read(bytes); - return ByteBuffer.allocateDirect(bytes.length).put(bytes); - } catch (Exception e) { - Log.d("loadModelFile", " Exception occur. "); - Log.e(TAG, Log.getStackTraceString(e)); - } - return null; - } -} diff --git a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/gallery/classify/RecognitionImageBean.java b/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/gallery/classify/RecognitionImageBean.java deleted file mode 100644 index 018088bf504b557200918cf98fc3a057c1acb0e5..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/gallery/classify/RecognitionImageBean.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * <p> - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mindspore.classificationforpet.gallery.classify; - -public class RecognitionImageBean { - - private String name; - private float score; - - public RecognitionImageBean(String name, float score) { - this.name = name; - this.score = score; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public float getScore() { - return score; - } - - public void setScore(float score) { - this.score = score; - } - - -} diff --git a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/gallery/classify/TrackingMobile.java b/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/gallery/classify/TrackingMobile.java deleted file mode 100644 index 81ff9b682bb50210da6ad9c7af60f03d8b1a5688..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/gallery/classify/TrackingMobile.java +++ /dev/null @@ -1,128 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mindspore.classificationforpet.gallery.classify; - -import android.content.Context; -import android.graphics.Bitmap; -import android.util.Log; - -import java.io.FileInputStream; -import java.io.InputStream; -import java.nio.ByteBuffer; - -/** - * Call the MindSpore interface API in the Java layer. - */ -public class TrackingMobile { - private final static String TAG = "TrackingMobile"; - - static { - try { - System.loadLibrary("mlkit-label-MS"); - Log.i(TAG, "load libiMindSpore.so successfully."); - } catch (UnsatisfiedLinkError e) { - Log.e(TAG, "UnsatisfiedLinkError " + e.getMessage()); - } - } - - // The address of the running inference environment. - private long netEnv = 0; - - private final Context mActivity; - - public TrackingMobile(Context activity) { - this.mActivity = activity; - } - - /** - * JNI load model and also create model inference environment. - * - * @param modelBuffer Model buffer. - * @param numThread The num of thread. - * @return MindSpore Inference environment address. - */ - public native long loadModel(ByteBuffer modelBuffer, int numThread); - - /** - * Running model. - * - * @param netEnv Inference environment address. - * @param img A picture to be inferred. - * @return Inference result - */ - public native String runNet(long netEnv, Bitmap img); - - /** - * Unbind model data. - * - * @param netEnv Inference environment address. - * @return Unbound state. - */ - public native boolean unloadModel(long netEnv); - - /** - * The C++ side is encapsulated into a method of the MSNetWorks class - * - * @param modelPath Model file location - * @return Load model file status - */ - public boolean loadModelFromBuf(String modelPath) { - ByteBuffer buffer = loadModelFile(modelPath); - netEnv = loadModel(buffer, 2); //numThread's default setting is 2. - if (netEnv == 0){ // Loading model failed. - return false; - } - - return true; - } - - /** - * Run MindSpore inference. - */ - public String MindSpore_runnet(Bitmap img) { - String ret_str = runNet(netEnv, img); - return ret_str; - } - - /** - * Unload model. - * @return true - */ - public boolean unloadModel() { - unloadModel(netEnv); - return true; - } - - /** - * Load model file stream. - * @param modelPath Model file path. - * @return Model ByteBuffer. - */ - public ByteBuffer loadModelFile(String modelPath) { - InputStream is = null; - try { - is = new FileInputStream(modelPath); - byte[] bytes = new byte[is.available()]; - is.read(bytes); - return ByteBuffer.allocateDirect(bytes.length).put(bytes); - } catch (Exception e) { - Log.d("loadModelFile", " Exception occur. "); - Log.e(TAG, Log.getStackTraceString(e)); - } - return null; - } -} diff --git a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/AutoFitTextureView.java b/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/AutoFitTextureView.java deleted file mode 100644 index 45d3f17992961c0e74d4bf97d321b8f255dfe8a0..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/AutoFitTextureView.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * <p> - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mindspore.classificationforpet.widget; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.TextureView; - -public class AutoFitTextureView extends TextureView { - - private int mRatioWidth = 0; - private int mRatioHeight = 0; - - public AutoFitTextureView(Context context) { - this(context, null); - } - - public AutoFitTextureView(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public AutoFitTextureView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - /** - * Sets the aspect ratio for this view. The size of the view will be measured based on the ratio - * calculated from the parameters. Note that the actual sizes of parameters don't matter, that - * is, calling setAspectRatio(2, 3) and setAspectRatio(4, 6) make the same result. - * - * @param width Relative horizontal size - * @param height Relative vertical size - */ - public void setAspectRatio(int width, int height) { - if (width < 0 || height < 0) { - throw new IllegalArgumentException("Size cannot be negative."); - } - mRatioWidth = width; - mRatioHeight = height; - requestLayout(); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - int width = MeasureSpec.getSize(widthMeasureSpec); - int height = MeasureSpec.getSize(heightMeasureSpec); - - if (0 == mRatioWidth || 0 == mRatioHeight) { - setMeasuredDimension(width, height); - } else { - if (width > height * mRatioWidth / mRatioHeight) { - setMeasuredDimension(width, width * mRatioHeight / mRatioWidth); - } else { - setMeasuredDimension(height * mRatioWidth / mRatioHeight, height); - } - } - } - -} diff --git a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/CameraActivity.java b/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/CameraActivity.java deleted file mode 100644 index 9cecf9f293627041835b9059b4b0f5dec56b1401..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/CameraActivity.java +++ /dev/null @@ -1,159 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * <p> - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mindspore.classificationforpet.widget; - -import android.graphics.Bitmap; -import android.os.Bundle; -import android.text.TextUtils; -import android.util.Log; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.Nullable; -import androidx.annotation.UiThread; -import androidx.appcompat.app.AppCompatActivity; - -import com.mindspore.classificationforpet.R; -import com.mindspore.classificationforpet.gallery.classify.ImageTrackingMobile; -import com.mindspore.classificationforpet.gallery.classify.RecognitionImageBean; -import com.mindspore.classificationforpet.gallery.classify.TrackingMobile; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * The main interface of camera preview. - * Using Camera 2 API. - */ -public class CameraActivity extends AppCompatActivity { - private static final String TAG = "CameraActivity"; - private static final String IMAGE_SCENE_MS = "model/mobilenetv2.ms"; - - private String filePath; - private boolean isPetModel; - private TrackingMobile trackingMobile; - private ImageTrackingMobile imageTrackingMobile; - - private TextView resultText; - private List<RecognitionImageBean> recognitionObjectBeanList; - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_camera); - - filePath = getIntent().getStringExtra("FILEPATH"); - isPetModel = getIntent().getBooleanExtra("ISHASPetMODELFILE", false); - resultText = findViewById(R.id.textResult); - - if (isPetModel) { - trackingMobile = new TrackingMobile(this); - boolean ret = trackingMobile.loadModelFromBuf(filePath); - if (!ret) { - Log.e(TAG, "Load model error."); - return; - } - } else { - imageTrackingMobile = new ImageTrackingMobile(this); - boolean ret = imageTrackingMobile.loadModelFromBuf(IMAGE_SCENE_MS); - if (!ret) { - Log.e(TAG, "Load model error."); - return; - } - } - addCameraFragment(); - } - - protected void addCameraFragment() { - CameraFragment cameraFragment = CameraFragment.newInstance(bitmap -> { - runOnUiThread(() -> initMindspore(bitmap)); - }); - - getSupportFragmentManager().beginTransaction() - .replace(R.id.container, cameraFragment) - .commitAllowingStateLoss(); - } - - - private void initMindspore(Bitmap bitmap) { - // run net. - if (isPetModel) { - long startTime = System.currentTimeMillis(); - String result = trackingMobile.MindSpore_runnet(bitmap); - long endTime = System.currentTimeMillis(); - String[] IMAGECONTENT = getResources().getStringArray(R.array.image_category_pet); - int nameIndex = Integer.parseInt(result); - resultText.setText(IMAGECONTENT[nameIndex]); - Log.d(TAG, "RUNNET CONSUMING锛�" + (endTime - startTime) + "ms"); - Log.d(TAG, "result锛�" + result); - } else { - if (recognitionObjectBeanList != null) { - recognitionObjectBeanList.clear(); - } else { - recognitionObjectBeanList = new ArrayList<>(); - } - - long startTime = System.currentTimeMillis(); - String result = imageTrackingMobile.MindSpore_runnet(bitmap); - long endTime = System.currentTimeMillis(); - Log.d(TAG, "RUNNET CONSUMING锛�" + (endTime - startTime) + "ms"); - Log.d(TAG, "result锛�" + result); - String[] IMAGECONTENT = getResources().getStringArray(R.array.image_category); - if (!TextUtils.isEmpty(result)) { - String[] resultArray = result.split(";"); - for (String singleRecognitionResult : resultArray) { - String[] singleResult = singleRecognitionResult.split(":"); - int nameIndex = Integer.parseInt(singleResult[0]); - float score = Float.parseFloat(singleResult[1]); - if (score > 0.5) { - recognitionObjectBeanList.add(new RecognitionImageBean(IMAGECONTENT[nameIndex], score)); - } - } - Collections.sort(recognitionObjectBeanList, (t1, t2) -> Float.compare(t2.getScore(), t1.getScore())); - showResultsInBottomSheet(recognitionObjectBeanList, (endTime - startTime) + "ms"); - } - } - } - - - @UiThread - protected void showResultsInBottomSheet(List<RecognitionImageBean> list, String time) { - if (list == null || list.size() < 1) { - return; - } - StringBuilder stringBuilder = new StringBuilder(); - for (int i = 0; i < list.size(); i++) { - RecognitionImageBean bean = list.get(i); - stringBuilder.append(bean.getName()).append("\r:\r").append(String.format("%.2f", (100 * bean.getScore())) + "%").append("\r\n"); - if (i > 3) { // set maximum display is 3. - break; - } - } - resultText.setText(stringBuilder); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (trackingMobile != null) { - trackingMobile.unloadModel(); - } - if (imageTrackingMobile != null) { - imageTrackingMobile.unloadModel(); - } - } -} diff --git a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/CameraFragment.java b/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/CameraFragment.java deleted file mode 100644 index 64da7e0902cf2f411c9f403c24d579aa42ab5935..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/CameraFragment.java +++ /dev/null @@ -1,781 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * <p> - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mindspore.classificationforpet.widget; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.Context; -import android.content.res.Configuration; -import android.graphics.Bitmap; -import android.graphics.ImageFormat; -import android.graphics.Matrix; -import android.graphics.Point; -import android.graphics.RectF; -import android.graphics.SurfaceTexture; -import android.hardware.camera2.CameraAccessException; -import android.hardware.camera2.CameraCaptureSession; -import android.hardware.camera2.CameraCharacteristics; -import android.hardware.camera2.CameraDevice; -import android.hardware.camera2.CameraManager; -import android.hardware.camera2.CameraMetadata; -import android.hardware.camera2.CaptureRequest; -import android.hardware.camera2.CaptureResult; -import android.hardware.camera2.TotalCaptureResult; -import android.hardware.camera2.params.StreamConfigurationMap; -import android.media.Image; -import android.media.ImageReader; -import android.os.Bundle; -import android.os.Environment; -import android.os.Handler; -import android.os.HandlerThread; -import android.util.Log; -import android.util.Size; -import android.util.SparseIntArray; -import android.view.LayoutInflater; -import android.view.Surface; -import android.view.TextureView; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; - -import com.mindspore.classificationforpet.R; -import com.mindspore.classificationforpet.gallery.classify.CompareSizesByArea; -import com.mindspore.classificationforpet.gallery.classify.TrackingMobile; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; - -public class CameraFragment extends Fragment { - - private static final String TAG = "CameraFragment"; - - private static final SparseIntArray ORIENTATIONS = new SparseIntArray(); - - static { - ORIENTATIONS.append(Surface.ROTATION_0, 90); - ORIENTATIONS.append(Surface.ROTATION_90, 0); - ORIENTATIONS.append(Surface.ROTATION_180, 270); - ORIENTATIONS.append(Surface.ROTATION_270, 180); - } - - private static final int MAX_PREVIEW_WIDTH = 1920; - - private static final int MAX_PREVIEW_HEIGHT = 1280; - - private Semaphore mCameraOpenCloseLock = new Semaphore(1); - - private int mState = STATE_PREVIEW; - - private static final int STATE_PREVIEW = 0; - - private static final int STATE_WAITING_LOCK = 1; - - private static final int STATE_WAITING_PRECAPTURE = 2; - - private static final int STATE_WAITING_NON_PRECAPTURE = 3; - - private static final int STATE_PICTURE_TAKEN = 4; - - /** - * Data interface returned after identification. - */ - private RecognitionDataCallBack recognitionDataCallBack; - - private AutoFitTextureView mTextureView; - - private boolean mFlashSupported; - - private boolean isPreBackgroundThreadPause; - - - /** - * HandlerThread and Handler of camera and algorithm. - */ - private HandlerThread mCameraHandlerThread, mMindsporeHandlerThread; - - private Handler mCameraHandler, mMindsporeHandler; - - private CameraManager mCameraManager; - - private CameraCaptureSession mCaptureSession; - - private CameraDevice mCameraDevice; - - private String mCameraId; - - private ImageReader mImageReader; - - private CaptureRequest.Builder mPreviewRequestBuilder; - - private CaptureRequest mPreviewRequest; - - private File mFile; - - private Size mPreviewSize; - - private int mSensorOrientation; - - private CameraDevice.StateCallback mCameraDeviceStateCallback; - - - private CameraFragment(RecognitionDataCallBack recognitionDataCallBack) { - this.recognitionDataCallBack = recognitionDataCallBack; - } - - /** - * Singleton. - * - * @param recognitionDataCallBack Identify data return interface. - * @return Construction method. - */ - public static CameraFragment newInstance(RecognitionDataCallBack recognitionDataCallBack) { - return new CameraFragment(recognitionDataCallBack); - } - - /** - * Data interface returned after identification. - */ - public interface RecognitionDataCallBack { - - void onRecognitionDataCallBack(Bitmap bitmap); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_camera, container, false); - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - mTextureView = (AutoFitTextureView) view.findViewById(R.id.texture); - } - - @Override - public void onResume() { - super.onResume(); - initChildThread(); - initCameraManager(); - initSelectCamera(); - initHandlerMatchingSize(); - initImageReader(); - initTextureViewListener(); - } - - @Override - public void onPause() { - closeCamera(); - stopBackgroundThread(); - super.onPause(); - } - - private void initChildThread() { - mCameraHandlerThread = new HandlerThread("CAMERA2"); - mCameraHandlerThread.start(); - mCameraHandler = new Handler(mCameraHandlerThread.getLooper()); - - mMindsporeHandlerThread = new HandlerThread("MINDSPORE"); - mMindsporeHandlerThread.start(); - mMindsporeHandler = new Handler(mMindsporeHandlerThread.getLooper()); - mMindsporeHandler.postDelayed(classifyRunnable, 500); - } - - - /** - * Detect time-consuming threads - */ - private Runnable classifyRunnable = new Runnable() { - public void run() { - synchronized (CameraFragment.this) { - Bitmap bitmap = mTextureView.getBitmap(); - if (bitmap != null) { - if (recognitionDataCallBack != null) { - // Interface returns data銆� - recognitionDataCallBack.onRecognitionDataCallBack(bitmap); - } - } - if (mMindsporeHandler != null && !isPreBackgroundThreadPause) { - mMindsporeHandler.postDelayed(classifyRunnable, 500); - } - } - } - }; - - private void initCameraManager() { - mCameraManager = (CameraManager) getActivity().getSystemService(Context.CAMERA_SERVICE); - } - - private void initSelectCamera() { - try { - String[] cameraIdArray = mCameraManager.getCameraIdList(); - for (String itemId : cameraIdArray) { - CameraCharacteristics itemCharacteristics = mCameraManager.getCameraCharacteristics(itemId); - Integer facing = itemCharacteristics.get(CameraCharacteristics.LENS_FACING); - if (facing == CameraCharacteristics.LENS_FACING_BACK) { - mCameraId = itemId; - break; - } - - } - } catch (CameraAccessException e) { - e.printStackTrace(); - } - if (mCameraId == null) { - Toast.makeText(getActivity(), getString(R.string.camera_error), Toast.LENGTH_SHORT).show(); - } - } - - private StreamConfigurationMap streamConfigurationMap; - private Size largest; - - /** - * Calculate the camera resolution suitable for the current screen resolution. - */ - private void initHandlerMatchingSize() { - try { - CameraCharacteristics cameraCharacteristics = mCameraManager.getCameraCharacteristics(mCameraId); - streamConfigurationMap = cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); - - Size[] sizes = streamConfigurationMap.getOutputSizes(ImageFormat.JPEG); - largest = Collections.max(Arrays.asList(sizes), new CompareSizesByArea()); - - Boolean available = cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); - mFlashSupported = available == null ? false : available; - } catch (CameraAccessException e) { - e.printStackTrace(); - } - } - - /** - * Initialize the picture. - */ - private void initImageReader() { - final int W = 640; - final int H = 480; - - mImageReader = ImageReader.newInstance(W, H, ImageFormat.JPEG, 30); - mImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() { - @Override - public void onImageAvailable(ImageReader reader) { - mFile = new File(getActivity().getExternalFilesDir(null), System.currentTimeMillis() + ".jpg"); - // Get the data frame and start the algorithm processing. - try { - // Get the next image from the ImageReader queue. - Image image = reader.acquireNextImage(); - image.close(); - } catch (Exception e) { - Log.e(TAG, "onImageAvailable: " + e.toString()); - } - } - }, mCameraHandler); - } - - /** - * TextureView.SurfaceTextureListener - */ - private void initTextureViewListener() { - if (mTextureView.isAvailable()) { - openCamera(mTextureView.getMeasuredWidth(), mTextureView.getMeasuredHeight()); - Log.d(TAG, "isAvailable: " + mTextureView.getWidth() + "--" + mTextureView.getHeight()); - } else { - mTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() { - @Override - public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) { - openCamera(width, height); - } - - @Override - public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) { - configureTransform(width, height); - } - - @Override - public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surfaceTexture) { - return true; - } - - @Override - public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surfaceTexture) { - - } - }); - } - } - - - @SuppressLint("MissingPermission") - private void openCamera(int width, int height) { - setPreviewSize(width, height, streamConfigurationMap, largest); - configureTransform(width, height); - - mCameraDeviceStateCallback = new CameraDevice.StateCallback() { - @Override - public void onOpened(@NonNull CameraDevice cameraDevice) { - if (cameraDevice != null) { - mCameraOpenCloseLock.release(); - mCameraDevice = cameraDevice; - createCameraPreviewSession(); - } - } - - @Override - public void onDisconnected(@NonNull CameraDevice cameraDevice) { - if (cameraDevice != null) { - mCameraOpenCloseLock.release(); - cameraDevice.close(); - mCameraDevice = null; - } - } - - @Override - public void onError(@NonNull CameraDevice cameraDevice, int i) { - if (cameraDevice != null) { - mCameraOpenCloseLock.release(); - cameraDevice.close(); - mCameraDevice = null; - if (null != getActivity()) { - getActivity().finish(); - } - } - } - }; - - - try { - if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { - throw new RuntimeException("Time out waiting to lock ic_launcher opening."); - } - mCameraManager.openCamera(mCameraId, mCameraDeviceStateCallback, mCameraHandler); - } catch (CameraAccessException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - throw new RuntimeException("Interrupted while trying to lock ic_launcher opening.", e); - } - - - } - - - /** - * Open camera preview. - */ - private void createCameraPreviewSession() { - try { - SurfaceTexture texture = mTextureView.getSurfaceTexture(); - // Set preview size. - texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); - // This is the output Surface we need to start preview. - Surface surface = new Surface(texture); - - mPreviewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW); - mPreviewRequestBuilder.addTarget(surface); - // Here, we create a CameraCaptureSession for ic_launcher preview. - mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()), - new CameraCaptureSession.StateCallback() { - - @Override - public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { - // The ic_launcher is already closed - if (null == mCameraDevice) { - return; - } - - // When the session is ready, we start displaying the preview. - mCaptureSession = cameraCaptureSession; - try { - // Auto focus should be continuous for ic_launcher preview. - mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, - CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE); - // Flash is automatically enabled when necessary. - setAutoFlash(mPreviewRequestBuilder); - // Finally, we start displaying the ic_launcher preview. - mPreviewRequest = mPreviewRequestBuilder.build(); - mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mCameraHandler); - } catch (CameraAccessException e) { - e.printStackTrace(); - } - } - - @Override - public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) { - Toast.makeText(getActivity(), "Failed", Toast.LENGTH_LONG).show(); - } - }, null); - } catch (CameraAccessException e) { - e.printStackTrace(); - } - } - - - private CameraCaptureSession.CaptureCallback mCaptureCallback = new CameraCaptureSession.CaptureCallback() { - - private void process(CaptureResult result) { - switch (mState) { - case STATE_PREVIEW: { - // We have nothing to do when the ic_launcher preview is working normally. - break; - } - case STATE_WAITING_LOCK: { - Integer afState = result.get(CaptureResult.CONTROL_AF_STATE); - if (afState == null) { - captureStillPicture(); - } else if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState - || CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) { - // CONTROL_AE_STATE can be null on some devices - Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); - if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) { - mState = STATE_PICTURE_TAKEN; - captureStillPicture(); - } else { - runPrecaptureSequence(); - } - } - break; - } - case STATE_WAITING_PRECAPTURE: { - // CONTROL_AE_STATE can be null on some devices - Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); - if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE - || aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) { - mState = STATE_WAITING_NON_PRECAPTURE; - } - break; - } - case STATE_WAITING_NON_PRECAPTURE: { - // CONTROL_AE_STATE can be null on some devices - Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); - if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) { - mState = STATE_PICTURE_TAKEN; - captureStillPicture(); - } - break; - } - } - } - - @Override - public void onCaptureProgressed(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, - @NonNull CaptureResult partialResult) { - process(partialResult); - } - - @Override - public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, - @NonNull TotalCaptureResult result) { - process(result); - } - }; - - - /** - * Run the precapture sequence for capturing a still image. This method should be called when - * we get a response in. - */ - private void runPrecaptureSequence() { - try { - // This is how to tell the ic_launcher to trigger. - mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, - CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START); - // Tell #mCaptureCallback to wait for the precapture sequence to be set. - mState = STATE_WAITING_PRECAPTURE; - mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mCameraHandler); - } catch (CameraAccessException e) { - e.printStackTrace(); - } - } - - /** - * Capture a still picture. This method should be called when we get a response in - * {@link #mCaptureCallback} from both - */ - private void captureStillPicture() { - try { - final Activity activity = getActivity(); - if (null == activity || null == mCameraDevice) { - return; - } - // This is the CaptureRequest.Builder that we use to take a picture. - final CaptureRequest.Builder captureBuilder = - mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); - captureBuilder.addTarget(mImageReader.getSurface()); - - // Use the same AE and AF modes as the preview. - captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE); - setAutoFlash(captureBuilder); - - // Orientation - int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); - captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation)); - - CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() { - - @Override - public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, - @NonNull TotalCaptureResult result) { - showToast("Saved: " + mFile); - Log.d(TAG, mFile.toString()); - unlockFocus(); - } - }; - - mCaptureSession.stopRepeating(); - mCaptureSession.abortCaptures(); - mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null); - } catch (CameraAccessException e) { - e.printStackTrace(); - } - } - - /** - * Retrieves the JPEG orientation from the specified screen rotation. - * - * @param rotation The screen rotation. - * @return The JPEG orientation (one of 0, 90, 270, and 360) - */ - private int getOrientation(int rotation) { - return (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360; - } - - /** - * Unlock the focus. This method should be called when still image capture sequence is - * finished. - */ - private void unlockFocus() { - try { - // Reset the auto-focus trigger - mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL); - setAutoFlash(mPreviewRequestBuilder); - mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mCameraHandler); - // After this, the ic_launcher will go back to the normal state of preview. - mState = STATE_PREVIEW; - mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mCameraHandler); - } catch (CameraAccessException e) { - e.printStackTrace(); - } - } - - private void setAutoFlash(CaptureRequest.Builder requestBuilder) { - if (mFlashSupported) { - requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH); - } - } - - protected void showToast(final String text) { - final Activity activity = getActivity(); - if (activity != null) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - Toast.makeText(activity, text, Toast.LENGTH_SHORT).show(); - } - }); - } - } - - /** - * Configures the necessary {@link Matrix} transformation to `mTextureView`. - * This method should be called after the ic_launcher preview size is determined in - * setUpCameraOutputs and also the size of `mTextureView` is fixed. - * - * @param viewWidth The width of `mTextureView` - * @param viewHeight The height of `mTextureView` - */ - protected void configureTransform(int viewWidth, int viewHeight) { - Activity activity = getActivity(); - if (null == mTextureView || null == mPreviewSize || null == activity) { - return; - } - int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); - Matrix matrix = new Matrix(); - RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); - RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth()); - float centerX = viewRect.centerX(); - float centerY = viewRect.centerY(); - if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { - bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); - matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); - float scale = - Math.max((float) viewHeight / mPreviewSize.getHeight(), (float) viewWidth / mPreviewSize.getWidth()); - matrix.postScale(scale, scale, centerX, centerY); - matrix.postRotate(90 * (rotation - 2), centerX, centerY); - } else if (Surface.ROTATION_180 == rotation) { - matrix.postRotate(180, centerX, centerY); - } - mTextureView.setTransform(matrix); - } - - - /** - * Set preview image size and positioning. - * - * @param width - * @param height - * @param map StreamConfigurationMap, the manager of all output formats and sizes supported by the camera. - * @param largest The max size - */ - private void setPreviewSize(int width, int height, StreamConfigurationMap map, Size largest) { - // Find out if we need to swap dimension to get the preview size relative to sensor coordinate. - int displayRotation = getActivity().getWindowManager().getDefaultDisplay().getRotation(); - Log.d(TAG, "displayRotation: " + displayRotation); - - boolean swappedDimensions = false; - if (Surface.ROTATION_0 == displayRotation || Surface.ROTATION_180 == displayRotation) { - if (mSensorOrientation == 90 || mSensorOrientation == 270) { - swappedDimensions = true; - } - } else if (Surface.ROTATION_90 == displayRotation || Surface.ROTATION_270 == displayRotation) { - if (mSensorOrientation == 0 || mSensorOrientation == 180) { - swappedDimensions = true; - } - } - - Point displaySize = new Point(); - getActivity().getWindowManager().getDefaultDisplay().getSize(displaySize); - int rotatedPreviewWidth = width; - int rotatedPreviewHeight = height; - int maxPreviewWidth = displaySize.x; - int maxPreviewHeight = displaySize.y; - - if (swappedDimensions) { - rotatedPreviewWidth = height; - rotatedPreviewHeight = width; - maxPreviewWidth = displaySize.y; - maxPreviewHeight = displaySize.x; - } - - if (maxPreviewWidth > MAX_PREVIEW_WIDTH) { - maxPreviewWidth = MAX_PREVIEW_WIDTH; - } - - if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) { - maxPreviewHeight = MAX_PREVIEW_HEIGHT; - } - - // Danger, W.R.! Attempting to use too large a preview size could exceed the ic_launcher - // bus' bandwidth limitation, resulting in gorgeous previews but the storage of - // garbage capture data. - mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth, - rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, largest); - - // We fit the aspect ratio of TextureView to the size of preview we picked. - int orientation = getResources().getConfiguration().orientation;// manifest涓柟鍚戝凡缁忓啓姝� - if (orientation == Configuration.ORIENTATION_LANDSCAPE) { - mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight()); - } else { - mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth()); - } - } - - /** - * Given {@code choices} of {@code Size}s supported by a ic_launcher, choose the smallest one that - * is at least as large as the respective texture view size, and that is at most as large as the - * respective max size, and whose aspect ratio matches with the specified value. If such size - * doesn't exist, choose the largest one that is at most as large as the respective max size, - * and whose aspect ratio matches with the specified value. - * - * @param choices The list of sizes that the ic_launcher supports for the intended output - * class - * @param textureViewWidth The width of the texture view relative to sensor coordinate - * @param textureViewHeight The height of the texture view relative to sensor coordinate - * @param maxWidth The maximum width that can be chosen - * @param maxHeight The maximum height that can be chosen - * @param aspectRatio The aspect ratio - * @return The optimal {@code Size}, or an arbitrary one if none were big enough - */ - protected Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight, int maxWidth, - int maxHeight, Size aspectRatio) { - - // Collect the supported resolutions that are at least as big as the preview Surface - List<Size> bigEnough = new ArrayList<>(); - // Collect the supported resolutions that are smaller than the preview Surface - List<Size> notBigEnough = new ArrayList<>(); - int w = aspectRatio.getWidth(); - int h = aspectRatio.getHeight(); - for (Size option : choices) { - if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight - && option.getHeight() == option.getWidth() * h / w) { - // if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight) { - if (option.getWidth() >= textureViewWidth && option.getHeight() >= textureViewHeight) { - bigEnough.add(option); - } else { - notBigEnough.add(option); - } - } - } - - if (bigEnough.size() > 0) { - return Collections.min(bigEnough, new CompareSizesByArea()); - } else if (notBigEnough.size() > 0) { - return Collections.max(notBigEnough, new CompareSizesByArea()); - } else { - Log.e(TAG, "Couldn't find any suitable preview size"); - return choices[0]; - } - } - - - /** - * Closes the current {@link CameraDevice}. - */ - private void closeCamera() { - try { - mCameraOpenCloseLock.acquire(); - if (null != mCaptureSession) { - mCaptureSession.close(); - mCaptureSession = null; - } - if (null != mCameraDevice) { - mCameraDevice.close(); - mCameraDevice = null; - } - if (null != mImageReader) { - mImageReader.close(); - mImageReader = null; - } - } catch (InterruptedException e) { - throw new RuntimeException("Interrupted while trying to lock ic_launcher closing.", e); - } finally { - mCameraOpenCloseLock.release(); - } - } - - private void stopBackgroundThread() { - isPreBackgroundThreadPause = true; - mCameraHandlerThread.quitSafely(); - mMindsporeHandlerThread.quitSafely(); - try { - mCameraHandlerThread.join(); - mCameraHandlerThread = null; - mCameraHandler.removeCallbacksAndMessages(null); - mCameraHandler = null; - - mMindsporeHandlerThread.join(); - mMindsporeHandlerThread = null; - mMindsporeHandler.removeCallbacksAndMessages(null); - mMindsporeHandler = null; - } catch (InterruptedException e) { - e.printStackTrace(); - } - } -} diff --git a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/MainActivity.java b/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/MainActivity.java deleted file mode 100644 index 968e3b104b0ac47ac0c70a695fc0b531b3d4a25b..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/MainActivity.java +++ /dev/null @@ -1,338 +0,0 @@ -package com.mindspore.classificationforpet.widget; - -import android.Manifest; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.net.Uri; -import android.os.Build; -import android.os.Bundle; -import android.os.Environment; -import android.provider.MediaStore; -import android.provider.Settings; -import android.text.TextUtils; -import android.util.Log; -import android.view.View; -import android.widget.ImageView; -import android.widget.ProgressBar; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.UiThread; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; -import androidx.core.content.FileProvider; -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.mindspore.classificationforpet.R; -import com.mindspore.classificationforpet.gallery.classify.BitmapUtils; -import com.mindspore.classificationforpet.gallery.classify.ImageTrackingMobile; -import com.mindspore.classificationforpet.gallery.classify.RecognitionImageBean; -import com.mindspore.classificationforpet.gallery.classify.TrackingMobile; - -import java.io.File; -import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class MainActivity extends AppCompatActivity implements OnBackgroundImageListener { - - private static final String TAG = "MainActivity"; - - private static final String[] PERMISSIONS = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, - Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}; - private static final int REQUEST_PERMISSION = 0; - - private static final int[] IMAGES = {R.drawable.style4, R.drawable.style8, R.drawable.style1, R.drawable.style6, R.drawable.style3, - R.drawable.style7, R.drawable.style5, R.drawable.style9, R.drawable.style0, R.drawable.style2}; - - private static final int RC_CHOOSE_PHOTO = 1; - private static final int RC_CHOOSE_CAMERA = 2; - private static final String IMAGE_SCENE_MS = "model/mobilenetv2.ms"; - - private boolean isAllGranted; - private static final String Pet_MS = "pet.ms"; - private File ROOT_FILE = new File(Environment.getExternalStorageDirectory().getAbsoluteFile(), "PetClassification"); - private File DIR_FILE = new File(ROOT_FILE, Pet_MS); - - private ImageView imgPreview; - private Uri imageUri; - private TextView textResult; - private ProgressBar progressBar; - private RecyclerView recyclerView; - private TrackingMobile trackingMobile; - private ImageTrackingMobile imageTrackingMobile; - private List<RecognitionImageBean> recognitionObjectBeanList; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - init(); - requestPermissions(); - } - - private void init() { - imgPreview = findViewById(R.id.img_origin); - textResult = findViewById(R.id.tv_image); - progressBar = findViewById(R.id.progress); - recyclerView = findViewById(R.id.recyclerview); - recyclerView.setLayoutManager(new GridLayoutManager(this, 3)); - recyclerView.setAdapter(new RecyclerViewAdapter(this, IMAGES, this)); - trackingMobile = new TrackingMobile(this); - imageTrackingMobile = new ImageTrackingMobile(this); - } - - private void requestPermissions() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - isAllGranted = checkPermissionAllGranted(PERMISSIONS); - if (!isAllGranted) { - ActivityCompat.requestPermissions(this, PERMISSIONS, REQUEST_PERMISSION); - } - } else { - isAllGranted = true; - } - } - - private boolean checkPermissionAllGranted(String[] permissions) { - for (String permission : permissions) { - if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) { - return false; - } - } - return true; - } - - /** - * Authority application result callback - */ - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - if (REQUEST_PERMISSION == requestCode) { - isAllGranted = true; - for (int grant : grantResults) { - if (grant != PackageManager.PERMISSION_GRANTED) { - isAllGranted = false; - break; - } - } - if (!isAllGranted) { - openAppDetails(); - } - } - } - - private void openAppDetails() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage(getString(R.string.app_choose_authority)); - builder.setPositiveButton(getString(R.string.app_choose_authority_manual), (dialog, which) -> { - Intent intent = new Intent(); - intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); - intent.addCategory(Intent.CATEGORY_DEFAULT); - intent.setData(Uri.parse("package:" + getPackageName())); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); - intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); - startActivity(intent); - }); - builder.setNegativeButton(getString(R.string.app_choose_cancle), null); - builder.show(); - } - - public boolean isHasPetModelFile() { - if (DIR_FILE.exists()) { - return true; - } else { - if (!ROOT_FILE.exists()) { - ROOT_FILE.mkdirs(); - } - return false; - } - } - - public void onClickPhoto(View view) { - if (isAllGranted) { - openGallay(); - } else { - requestPermissions(); - } - } - - public void onClickCamera(View view) { - if (isAllGranted) { - openCamera(); - } else { - requestPermissions(); - } - } - - public void onClickScene(View view) { - Intent intent = new Intent(MainActivity.this, CameraActivity.class); - intent.putExtra("FILEPATH", DIR_FILE.getPath()); - intent.putExtra("ISHASPetMODELFILE", isHasPetModelFile()); - startActivity(intent); - } - - @Override - public void onBackImageSelected(int position) { - imgPreview.setImageResource(IMAGES[position]); - initMindspore(BitmapFactory.decodeResource(getResources(), IMAGES[position])); - } - - private void openGallay() { - Intent intentToPickPic = new Intent(Intent.ACTION_PICK, null); - intentToPickPic.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*"); - startActivityForResult(intentToPickPic, RC_CHOOSE_PHOTO); - } - - private void openCamera() { - Intent intentToTakePhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - String mTempPhotoPath = Environment.getExternalStorageDirectory() + File.separator + "photo22.jpeg"; - imageUri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".fileprovider", new File(mTempPhotoPath)); - intentToTakePhoto.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); - startActivityForResult(intentToTakePhoto, RC_CHOOSE_CAMERA); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (resultCode == RESULT_OK) { - if (RC_CHOOSE_PHOTO == requestCode) { - if (null != data && null != data.getData()) { - this.imageUri = data.getData(); - showOriginImage(); - } else { - finish(); - } - } else if (RC_CHOOSE_CAMERA == requestCode) { - showOriginCamera(); - } - } - } - - private void showOriginImage() { - File file = BitmapUtils.getFileFromMediaUri(this, imageUri); - Bitmap photoBmp = BitmapUtils.getBitmapFormUri(this, Uri.fromFile(file)); - int degree = BitmapUtils.getBitmapDegree(file.getAbsolutePath()); - Bitmap originBitmap = BitmapUtils.rotateBitmapByDegree(photoBmp, degree); - if (originBitmap != null) { - imgPreview.setImageBitmap(originBitmap); - initMindspore(originBitmap.copy(Bitmap.Config.ARGB_8888, true)); - } else { - Toast.makeText(this, R.string.image_invalid, Toast.LENGTH_LONG).show(); - } - } - - private void showOriginCamera() { - try { - Bitmap originBitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri)); - if (originBitmap != null) { - imgPreview.setImageBitmap(originBitmap); - initMindspore(originBitmap.copy(Bitmap.Config.ARGB_8888, true)); - } else { - Toast.makeText(this, R.string.image_invalid, Toast.LENGTH_LONG).show(); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - } - - private void initMindspore(Bitmap bitmap) { - progressBar.setVisibility(View.VISIBLE); - - if (isHasPetModelFile()) { - boolean ret = trackingMobile.loadModelFromBuf(DIR_FILE.getPath()); - if (!ret) { - textResult.setText("Load model error."); - Log.e(TAG, "Load model error."); - return; - } - // run net. - long startTime = System.currentTimeMillis(); - String result = trackingMobile.MindSpore_runnet(bitmap); - long endTime = System.currentTimeMillis(); - String[] IMAGECONTENT = getResources().getStringArray(R.array.image_category_pet); - int nameIndex = Integer.parseInt(result); - progressBar.setVisibility(View.GONE); - textResult.setText(IMAGECONTENT[nameIndex]); - Log.d(TAG, "RUNNET CONSUMING锛�" + (endTime - startTime) + "ms"); - Log.d(TAG, "result锛�" + result); - } else { - if (recognitionObjectBeanList != null) { - recognitionObjectBeanList.clear(); - } else { - recognitionObjectBeanList = new ArrayList<>(); - } - - boolean ret = imageTrackingMobile.loadModelFromBuf(IMAGE_SCENE_MS); - if (!ret) { - textResult.setText("Load model error."); - Log.e(TAG, "Load model error."); - return; - } - // run net. - long startTime = System.currentTimeMillis(); - String result = imageTrackingMobile.MindSpore_runnet(bitmap); - long endTime = System.currentTimeMillis(); - progressBar.setVisibility(View.GONE); - Log.d(TAG, "RUNNET CONSUMING锛�" + (endTime - startTime) + "ms"); - Log.d(TAG, "result锛�" + result); - String[] IMAGECONTENT = getResources().getStringArray(R.array.image_category); - - if (!TextUtils.isEmpty(result)) { - String[] resultArray = result.split(";"); - for (String singleRecognitionResult : resultArray) { - String[] singleResult = singleRecognitionResult.split(":"); - int nameIndex = Integer.parseInt(singleResult[0]); - float score = Float.parseFloat(singleResult[1]); - if (score > 0.5) { - recognitionObjectBeanList.add(new RecognitionImageBean(IMAGECONTENT[nameIndex], score)); - } - } - Collections.sort(recognitionObjectBeanList, (t1, t2) -> Float.compare(t2.getScore(), t1.getScore())); - showResultsInBottomSheet(recognitionObjectBeanList, (endTime - startTime) + "ms"); - } - } - if (!bitmap.isRecycled()) { - bitmap.recycle(); - } - } - - @UiThread - protected void showResultsInBottomSheet(List<RecognitionImageBean> list, String time) { - if (list == null || list.size() < 1) { - return; - } - StringBuilder stringBuilder = new StringBuilder(); - for (int i = 0; i < list.size(); i++) { - RecognitionImageBean bean = list.get(i); - stringBuilder.append(bean.getName()).append("\r:\r").append(String.format("%.2f", (100 * bean.getScore())) + "%").append("\r\n"); - if (i > 3) { // set maximum display is 3. - break; - } - } - textResult.setText(stringBuilder); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (trackingMobile != null) { - trackingMobile.unloadModel(); - } - if (imageTrackingMobile != null) { - imageTrackingMobile.unloadModel(); - } - } - - -} \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/OnBackgroundImageListener.java b/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/OnBackgroundImageListener.java deleted file mode 100644 index 849ed2dd924bebb828304c8006ba89c082a97a26..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/OnBackgroundImageListener.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * <p> - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mindspore.classificationforpet.widget; - -public interface OnBackgroundImageListener { - void onBackImageSelected(int position); - -} diff --git a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/RecyclerViewAdapter.java b/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/RecyclerViewAdapter.java deleted file mode 100644 index d8fce78924e356462d1e073d9ab40d739fa9f945..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/java/com/mindspore/classificationforpet/widget/RecyclerViewAdapter.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * <p> - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mindspore.classificationforpet.widget; - -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.mindspore.classificationforpet.R; - -public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.StyleItemViewHolder> { - - private final int[] IMAGES; - private final Context context; - private final OnBackgroundImageListener mListener; - - public RecyclerViewAdapter(Context context, int[] IMAGES, OnBackgroundImageListener mListener) { - this.IMAGES = IMAGES; - this.context = context; - this.mListener = mListener; - } - - @NonNull - @Override - public StyleItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(context) - .inflate(R.layout.image_item, parent, false); - return new StyleItemViewHolder(view); - } - - @Override - public void onBindViewHolder(@NonNull StyleItemViewHolder holder, int position) { - Glide.with(context). - load(IMAGES[position]). - into(holder.getImageView()); - - View view = holder.getMView(); - view.setTag(IMAGES[position]); - view.setOnClickListener(view1 -> { - if (mListener != null) { - mListener.onBackImageSelected(position); - } - }); - } - - - @Override - public int getItemCount() { - return IMAGES == null ? 0 : IMAGES.length; - } - - - public class StyleItemViewHolder extends RecyclerView.ViewHolder { - private ImageView imageView; - private final View mView; - - public final ImageView getImageView() { - return this.imageView; - } - - public final void setImageView(ImageView imageView) { - this.imageView = imageView; - } - - public final View getMView() { - return this.mView; - } - - public StyleItemViewHolder(View mView) { - super(mView); - this.mView = mView; - this.imageView = mView.findViewById(R.id.image_view); - } - } -} diff --git a/official/lite/pet_classification/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/official/lite/pet_classification/app/src/main/res/drawable-v24/ic_launcher_foreground.xml deleted file mode 100644 index 2b068d11462a4b96669193de13a711a3a36220a0..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ /dev/null @@ -1,30 +0,0 @@ -<vector xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:aapt="http://schemas.android.com/aapt" - android:width="108dp" - android:height="108dp" - android:viewportWidth="108" - android:viewportHeight="108"> - <path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z"> - <aapt:attr name="android:fillColor"> - <gradient - android:endX="85.84757" - android:endY="92.4963" - android:startX="42.9492" - android:startY="49.59793" - android:type="linear"> - <item - android:color="#44000000" - android:offset="0.0" /> - <item - android:color="#00000000" - android:offset="1.0" /> - </gradient> - </aapt:attr> - </path> - <path - android:fillColor="#FFFFFF" - android:fillType="nonZero" - android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z" - android:strokeWidth="1" - android:strokeColor="#00000000" /> -</vector> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/logo.png b/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/logo.png deleted file mode 100644 index c90f1dda4399a42e4c0c504f144508afb99ec326..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/logo.png and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/logo2.png b/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/logo2.png deleted file mode 100644 index 589b9926f67875b8376c65e908e223894b5b90be..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/logo2.png and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style0.jpg b/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style0.jpg deleted file mode 100644 index 1b15ce8ab7ac22b0ccf0a7de47fe85a151dd15b1..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style0.jpg and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style1.jpg b/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style1.jpg deleted file mode 100644 index 4c8d57864c3b56ea8cec35be20a98d670ce6b434..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style1.jpg and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style2.jpg b/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style2.jpg deleted file mode 100644 index 8184f44bd19605ee2e88a0512c933909d9c65ecf..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style2.jpg and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style3.jpg b/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style3.jpg deleted file mode 100644 index 54d4a2a24ff4c0948c957daba0dbe45d381b537c..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style3.jpg and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style4.jpg b/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style4.jpg deleted file mode 100644 index 5408c8a8405b9b310ca100a06170d70a16d86b70..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style4.jpg and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style5.jpg b/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style5.jpg deleted file mode 100644 index 553efa6b4c8ff9ffb55398c42a9b2c628c07749d..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style5.jpg and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style6.jpg b/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style6.jpg deleted file mode 100644 index a6a878c1897723e9210bf0d4c69b8f551341f4b8..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style6.jpg and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style7.jpg b/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style7.jpg deleted file mode 100644 index 3aa16aa86f0f34786a992b9df97fc06cf0b22478..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style7.jpg and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style8.jpg b/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style8.jpg deleted file mode 100644 index 72877cc980f2401603cab2ef63727a1b5632c120..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style8.jpg and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style9.jpg b/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style9.jpg deleted file mode 100644 index 713a4fcd9669d02f863f53a84dbeec9b203f164f..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/drawable-xxhdpi/style9.jpg and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/drawable/ic_launcher_background.xml b/official/lite/pet_classification/app/src/main/res/drawable/ic_launcher_background.xml deleted file mode 100644 index d5fccc538c179838bfdce779c26eebb4fa0b5ce9..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/drawable/ic_launcher_background.xml +++ /dev/null @@ -1,170 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<vector xmlns:android="http://schemas.android.com/apk/res/android" - android:width="108dp" - android:height="108dp" - android:viewportHeight="108" - android:viewportWidth="108"> - <path - android:fillColor="#26A69A" - android:pathData="M0,0h108v108h-108z" /> - <path - android:fillColor="#00000000" - android:pathData="M9,0L9,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M19,0L19,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M29,0L29,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M39,0L39,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M49,0L49,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M59,0L59,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M69,0L69,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M79,0L79,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M89,0L89,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M99,0L99,108" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,9L108,9" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,19L108,19" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,29L108,29" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,39L108,39" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,49L108,49" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,59L108,59" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,69L108,69" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,79L108,79" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,89L108,89" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M0,99L108,99" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M19,29L89,29" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M19,39L89,39" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M19,49L89,49" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M19,59L89,59" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M19,69L89,69" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M19,79L89,79" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M29,19L29,89" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M39,19L39,89" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M49,19L49,89" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M59,19L59,89" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M69,19L69,89" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> - <path - android:fillColor="#00000000" - android:pathData="M79,19L79,89" - android:strokeColor="#33FFFFFF" - android:strokeWidth="0.8" /> -</vector> diff --git a/official/lite/pet_classification/app/src/main/res/drawable/progressbar.xml b/official/lite/pet_classification/app/src/main/res/drawable/progressbar.xml deleted file mode 100644 index d48a929d888727f64eb4c281c9ffb14da8b578c8..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/drawable/progressbar.xml +++ /dev/null @@ -1,20 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android" - android:fromDegrees="0" - android:pivotX="50%" - android:pivotY="50%" - android:toDegrees="360"> - <shape - android:innerRadiusRatio="3" - android:shape="ring" - android:thicknessRatio="8" - android:useLevel="false"> - <gradient - android:centerColor="#62AEEC" - android:centerY="0.50" - android:endColor="#1063A5" - android:startColor="#61C2EC" - android:type="sweep" - android:useLevel="false" /> - </shape> -</animated-rotate> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/res/drawable/rectangle.xml b/official/lite/pet_classification/app/src/main/res/drawable/rectangle.xml deleted file mode 100644 index b8f5d3559c4e83072d5d73a3241d240aa68daccf..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/drawable/rectangle.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<shape xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/listview_background_shape"> - <stroke - android:width="1dp" - android:color="@android:color/darker_gray" /> - <padding - android:bottom="2dp" - android:left="2dp" - android:right="2dp" - android:top="2dp" /> - <solid android:color="#ffffffff" /> -</shape> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/res/drawable/switch_thumb.xml b/official/lite/pet_classification/app/src/main/res/drawable/switch_thumb.xml deleted file mode 100644 index ef6cfd23398879085c2724d6442dc7c36c6a62a4..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/drawable/switch_thumb.xml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<shape xmlns:android="http://schemas.android.com/apk/res/android"> - <size - android:width="40dp" - android:height="40dp" /> - <corners android:radius="20dp" /> - <solid android:color="#82eae5e5" /> -</shape> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/res/drawable/switch_track.xml b/official/lite/pet_classification/app/src/main/res/drawable/switch_track.xml deleted file mode 100644 index 3088fe56f61eada53d7074baa948fd4cba249fec..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/drawable/switch_track.xml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<shape xmlns:android="http://schemas.android.com/apk/res/android"> - <size - android:width="100dp" - android:height="40dp"/> - <corners android:radius="20dp" /> - <solid android:color="#784b4b4b" /> -</shape> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/res/layout/activity_camera.xml b/official/lite/pet_classification/app/src/main/res/layout/activity_camera.xml deleted file mode 100644 index fc580307f633e3254b0ff104e4a85ae00724cabd..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/layout/activity_camera.xml +++ /dev/null @@ -1,53 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="#00000000"> - - <RelativeLayout - android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="#00000000" - android:orientation="vertical"> - - <FrameLayout - android:id="@+id/container" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="@android:color/black" - tools:context="com.mindspore.classificationforpet.widget.CameraActivity" /> - - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar" - android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - android:layout_alignParentTop="true" - android:background="#66000000"> - - <TextView - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:drawableStart="@drawable/logo" - android:drawablePadding="5dp" - android:gravity="center_vertical" - android:maxLines="1" - android:text="@string/app_name" - android:textColor="#ffffff" - android:textSize="20sp" /> - </androidx.appcompat.widget.Toolbar> - - <TextView - android:maxLines="3" - android:id="@+id/textResult" - android:layout_width="match_parent" - android:layout_height="150dp" - android:layout_alignParentBottom="true" - android:background="@color/white" - android:gravity="center" - android:orientation="vertical" - android:text="@string/app_result_identifying" - android:textColor="@color/black" - android:textSize="25sp" /> - </RelativeLayout> -</androidx.coordinatorlayout.widget.CoordinatorLayout> diff --git a/official/lite/pet_classification/app/src/main/res/layout/activity_main.xml b/official/lite/pet_classification/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index 7d71eb5a5938d02afdc908a224ee52c2e7eba75a..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,129 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="@color/colorPrimary" - android:orientation="vertical"> - - <androidx.appcompat.widget.Toolbar - android:id="@+id/toolbar" - android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - android:layout_alignParentTop="true" - android:background="#66000000"> - - <TextView - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:drawableStart="@drawable/logo" - android:drawablePadding="5dp" - android:gravity="center_vertical" - android:maxLines="1" - android:text="@string/app_name" - android:textColor="#ffffff" - android:textSize="20sp" /> - </androidx.appcompat.widget.Toolbar> - - <FrameLayout - android:layout_width="match_parent" - android:layout_height="300dp"> - - <ImageView - android:id="@+id/img_origin" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="center" - android:layout_margin="10dp" - android:scaleType="fitXY" - android:src="@drawable/logo2" /> - - <ProgressBar - android:id="@+id/progress" - android:layout_width="80dp" - android:layout_height="80dp" - android:layout_gravity="center" - android:indeterminateDrawable="@drawable/progressbar" - android:visibility="invisible" /> - </FrameLayout> - - <TextView - android:maxLines="3" - android:id="@+id/tv_image" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginLeft="20dp" - android:layout_marginTop="20dp" - android:text="@string/app_choose_an_image" - android:textAllCaps="false" - android:textColor="@color/white" - android:textSize="20sp" /> - - <LinearLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginTop="15dp" - android:orientation="horizontal"> - - <Button - android:layout_width="0dp" - android:layout_height="48dp" - android:layout_marginLeft="20dp" - android:layout_marginRight="5dp" - android:layout_weight="1" - android:background="@color/gray_btn" - android:gravity="center" - android:onClick="onClickPhoto" - android:text="@string/app_photo" - android:textAllCaps="false" - android:textColor="@color/white" - android:textSize="12sp" /> - - <Button - android:layout_width="0dp" - android:layout_height="48dp" - android:layout_marginLeft="5dp" - android:layout_marginRight="5dp" - android:layout_weight="1" - android:background="@color/gray_btn" - android:gravity="center" - android:onClick="onClickCamera" - android:text="@string/app_camera" - android:textAllCaps="false" - android:textColor="@color/white" - android:textSize="12sp" /> - - <Button - android:layout_width="0dp" - android:layout_height="48dp" - android:layout_marginLeft="5dp" - android:layout_marginRight="5dp" - android:layout_weight="1" - android:background="@color/gray_btn" - android:gravity="center" - android:onClick="onClickScene" - android:text="@string/app_scan" - android:textAllCaps="false" - android:textColor="@color/white" - android:textSize="12sp" /> - </LinearLayout> - - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginLeft="20dp" - android:layout_marginTop="20dp" - android:text="@string/app_choose_a_sample" - android:textColor="@color/white" - android:textSize="20sp" /> - - <androidx.recyclerview.widget.RecyclerView - android:id="@+id/recyclerview" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_margin="20dp" - android:fadeScrollbars="false" - android:scrollbarSize="6dp" - android:scrollbarStyle="outsideInset" - android:scrollbarThumbVertical="@color/gray" - android:scrollbars="vertical" /> -</LinearLayout> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/res/layout/fragment_camera.xml b/official/lite/pet_classification/app/src/main/res/layout/fragment_camera.xml deleted file mode 100644 index c569114bc74c9b2b23ef22e5033e9a108ca89b8b..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/layout/fragment_camera.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="@color/white" - android:orientation="vertical"> - - <com.mindspore.classificationforpet.widget.AutoFitTextureView - android:id="@+id/texture" - android:layout_width="match_parent" - android:layout_height="match_parent" /> - -</FrameLayout> diff --git a/official/lite/pet_classification/app/src/main/res/layout/image_item.xml b/official/lite/pet_classification/app/src/main/res/layout/image_item.xml deleted file mode 100644 index 7109ec85ca7d06cfcb331dbf8a0e9c519ed8b822..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/layout/image_item.xml +++ /dev/null @@ -1,14 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:orientation="vertical"> - - <ImageView - android:id="@+id/image_view" - android:layout_width="wrap_content" - android:layout_height="120dp" - android:scaleType="fitXY" - tools:srcCompat="@drawable/logo" /> -</LinearLayout> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/res/layout/layout_hor_text_view.xml b/official/lite/pet_classification/app/src/main/res/layout/layout_hor_text_view.xml deleted file mode 100644 index eb9bea42d187c9ea23b6b10875df8baa4846aef9..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/layout/layout_hor_text_view.xml +++ /dev/null @@ -1,40 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="vertical"> - - <TextView - android:id="@+id/tv_left_title" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginStart="@dimen/hor_text_view_text_margin_normal" - android:layout_marginTop="@dimen/hor_text_view_text_margin_small" - android:textSize="@dimen/hor_text_view_text_size" - tools:text="person" /> - - <TextView - android:gravity="end" - android:layout_toRightOf="@+id/tv_left_title" - android:textColor="@color/black" - android:layout_alignParentEnd="true" - android:id="@+id/tv_right_content" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginEnd="@dimen/hor_text_view_text_margin_normal" - android:layout_marginStart="@dimen/hor_text_view_text_margin_normal" - android:layout_marginTop="@dimen/hor_text_view_text_margin_small" - android:textSize="@dimen/hor_text_view_text_size" - tools:text="12.5" /> - - <View - android:id="@+id/view_bottom_line" - android:layout_marginTop="@dimen/hor_text_view_text_margin_small" - android:layout_alignStart="@+id/tv_left_title" - android:layout_alignEnd="@+id/tv_right_content" - android:background="@color/gray" - android:layout_below="@+id/tv_left_title" - android:layout_height="0.5dp" - android:layout_width="match_parent"/> -</RelativeLayout> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/res/mipmap-hdpi/ic_launcher.png b/official/lite/pet_classification/app/src/main/res/mipmap-hdpi/ic_launcher.png deleted file mode 100644 index a571e60098c92c2baca8a5df62f2929cbff01b52..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/official/lite/pet_classification/app/src/main/res/mipmap-hdpi/ic_launcher_round.png deleted file mode 100644 index 61da551c5594a1f9d26193983d2cd69189014603..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/mipmap-hdpi/ic_launcher_round.png and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/mipmap-mdpi/ic_launcher.png b/official/lite/pet_classification/app/src/main/res/mipmap-mdpi/ic_launcher.png deleted file mode 100644 index c41dd28531901b2c23927768c84bb6765ebcc1db..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/official/lite/pet_classification/app/src/main/res/mipmap-mdpi/ic_launcher_round.png deleted file mode 100644 index db5080a752731b34d38d7c634732b2cd999125d0..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/mipmap-mdpi/ic_launcher_round.png and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/official/lite/pet_classification/app/src/main/res/mipmap-xhdpi/ic_launcher.png deleted file mode 100644 index 6dba46dab19242bf475ddf2e0a10042de6a0be16..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/official/lite/pet_classification/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png deleted file mode 100644 index da31a871c8dc461a1ea114510bfac640307b0a90..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/official/lite/pet_classification/app/src/main/res/mipmap-xxhdpi/ic_launcher.png deleted file mode 100644 index 15ac681720f3df43c647bf0c081f0314ee34eae1..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/official/lite/pet_classification/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png deleted file mode 100644 index b216f2d313cc673d8b8c4da591c174ebed52795c..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/official/lite/pet_classification/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png deleted file mode 100644 index f25a419744727fb48b4b4137b6c6a3a8f2620d51..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/official/lite/pet_classification/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png deleted file mode 100644 index e96783ccce844001359f968f5cd9d85b341bd3fb..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/official/lite/pet_classification/app/src/main/res/values-en/strings.xml b/official/lite/pet_classification/app/src/main/res/values-en/strings.xml deleted file mode 100644 index 05aa77be9c0860d15a6e59c1ce9208f4c78763ff..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/values-en/strings.xml +++ /dev/null @@ -1,437 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <string name="app_name">PetClassification</string> - <string name="action_settings">Settings</string> - - <string name="camera_error">This device doesn\'t support Camera2 API.</string> - - <string name="image_invalid">The image path you selected is not valid. Please choose again</string> - <string name="train_invalid">Sorry, there is no object identified in this picture. Try another picture</string> - - <string name="app_result_identifying">Identifying鈥�</string> - <string name="app_choose_an_image">Choose an image</string> - <string name="app_photo">PHOTO</string> - <string name="app_camera">CAMERA</string> - <string name="app_scan">SCAN</string> - <string name="app_choose_a_sample">Choose a sample</string> - <string name="app_choose_authority">PetClassification needs to access 鈥淐amera鈥� and 鈥淓xternal Storage鈥�, please use "Application Information -> Permission" to grant authority. </string> - <string name="app_choose_authority_manual"> Manually authorize this APP. </string> - <string name="app_choose_cancle">Cancel</string> - <string-array name="image_category_pet"> - <item>Cat</item> - <item>Dog</item> - </string-array> - - <string-array name="image_category"> - <item>Herd</item> - <item>Safari</item> - <item>Bangle</item> - <item>Cushion</item> - <item>Countertop</item> - <item>Prom</item> - <item>Branch</item> - <item>Sports</item> - <item>Sky</item> - <item>Community</item> - <item>Wheel</item> - <item>Cola</item> - <item>Tuxedo</item> - <item>Flowerpot</item> - <item>Team</item> - <item>Computer</item> - <item>Unicycle</item> - <item>Brig</item> - <item>Aerospace engineering</item> - <item>Scuba diving</item> - <item>Goggles</item> - <item>Fruit</item> - <item>Badminton</item> - <item>Horse</item> - <item>Sunglasses</item> - <item>Fun</item> - <item>Prairie</item> - <item>Poster</item> - <item>Flag</item> - <item>Speedboat</item> - <item>Eyelash</item> - <item>Veil</item> - <item>Mobile phone</item> - <item>Wheelbarrow</item> - <item>Saucer</item> - <item>Leather</item> - <item>Drawer</item> - <item>Paper</item> - <item>Pier</item> - <item>Waterfowl</item> - <item>Tights</item> - <item>Rickshaw</item> - <item>Vegetable</item> - <item>Handrail</item> - <item>Ice</item> - <item>Metal</item> - <item>Flower</item> - <item>Wing</item> - <item>Silverware</item> - <item>Event</item> - <item>Skyline</item> - <item>Money</item> - <item>Comics</item> - <item>Handbag</item> - <item>Porcelain</item> - <item>Rodeo</item> - <item>Curtain</item> - <item>Tile</item> - <item>Human mouth</item> - <item>Army</item> - <item>Menu</item> - <item>Boat</item> - <item>Snowboarding</item> - <item>Cairn terrier</item> - <item>Net</item> - <item>Pasteles</item> - <item>Cup</item> - <item>Rugby</item> - <item>Pho</item> - <item>Cap</item> - <item>Human hair</item> - <item>Surfing</item> - <item>Loveseat</item> - <item>Museum</item> - <item>Shipwreck</item> - <item>Trunk (Tree)</item> - <item>Plush</item> - <item>Monochrome</item> - <item>Volcano</item> - <item>Rock</item> - <item>Pillow</item> - <item>Presentation</item> - <item>Nebula</item> - <item>Subwoofer</item> - <item>Lake</item> - <item>Sledding</item> - <item>Bangs</item> - <item>Tablecloth</item> - <item>Necklace</item> - <item>Swimwear</item> - <item>Standing</item> - <item>Jeans</item> - <item>Carnival</item> - <item>Softball</item> - <item>Centrepiece</item> - <item>Skateboarder</item> - <item>Cake</item> - <item>Dragon</item> - <item>Aurora</item> - <item>Skiing</item> - <item>Bathroom</item> - <item>Dog</item> - <item>Needlework</item> - <item>Umbrella</item> - <item>Church</item> - <item>Fire</item> - <item>Piano</item> - <item>Denim</item> - <item>Bridle</item> - <item>Cabinetry</item> - <item>Lipstick</item> - <item>Ring</item> - <item>Television</item> - <item>Roller</item> - <item>Seal</item> - <item>Concert</item> - <item>Product</item> - <item>News</item> - <item>Fast food</item> - <item>Horn (Animal)</item> - <item>Tattoo</item> - <item>Bird</item> - <item>Bridegroom</item> - <item>Love</item> - <item>Helmet</item> - <item>Dinosaur</item> - <item>Icing</item> - <item>Miniature</item> - <item>Tire</item> - <item>Toy</item> - <item>Icicle</item> - <item>Jacket</item> - <item>Coffee</item> - <item>Mosque</item> - <item>Rowing</item> - <item>Wetsuit</item> - <item>Camping</item> - <item>Underwater</item> - <item>Christmas</item> - <item>Gelato</item> - <item>Whiteboard</item> - <item>Field</item> - <item>Ragdoll</item> - <item>Construction</item> - <item>Lampshade</item> - <item>Palace</item> - <item>Meal</item> - <item>Factory</item> - <item>Cage</item> - <item>Clipper (Boat)</item> - <item>Gymnastics</item> - <item>Turtle</item> - <item>Human foot</item> - <item>Marriage</item> - <item>Web page</item> - <item>Human beard</item> - <item>Fog</item> - <item>Wool</item> - <item>Cappuccino</item> - <item>Lighthouse</item> - <item>Lego</item> - <item>Sparkler</item> - <item>Sari</item> - <item>Model</item> - <item>Temple</item> - <item>Beanie</item> - <item>Building</item> - <item>Waterfall</item> - <item>Penguin</item> - <item>Cave</item> - <item>Stadium</item> - <item>Smile</item> - <item>Human hand</item> - <item>Park</item> - <item>Desk</item> - <item>Shetland sheepdog</item> - <item>Bar</item> - <item>Eating</item> - <item>Neon</item> - <item>Dalmatian</item> - <item>Crocodile</item> - <item>Wakeboarding</item> - <item>Longboard</item> - <item>Road</item> - <item>Race</item> - <item>Kitchen</item> - <item>Odometer</item> - <item>Cliff</item> - <item>Fiction</item> - <item>School</item> - <item>Interaction</item> - <item>Bullfighting</item> - <item>Boxer</item> - <item>Gown</item> - <item>Aquarium</item> - <item>Superhero</item> - <item>Pie</item> - <item>Asphalt</item> - <item>Surfboard</item> - <item>Cheeseburger</item> - <item>Screenshot</item> - <item>Supper</item> - <item>Laugh</item> - <item>Lunch</item> - <item>Party </item> - <item>Glacier</item> - <item>Bench</item> - <item>Grandparent</item> - <item>Sink</item> - <item>Pomacentridae</item> - <item>Blazer</item> - <item>Brick</item> - <item>Space</item> - <item>Backpacking</item> - <item>Stuffed toy</item> - <item>Sushi</item> - <item>Glitter</item> - <item>Bonfire</item> - <item>Castle</item> - <item>Marathon</item> - <item>Pizza</item> - <item>Beach</item> - <item>Human ear</item> - <item>Racing</item> - <item>Sitting</item> - <item>Iceberg</item> - <item>Shelf</item> - <item>Vehicle</item> - <item>Pop music</item> - <item>Playground</item> - <item>Clown</item> - <item>Car</item> - <item>Rein</item> - <item>Fur</item> - <item>Musician</item> - <item>Casino</item> - <item>Baby</item> - <item>Alcohol</item> - <item>Strap</item> - <item>Reef</item> - <item>Balloon</item> - <item>Outerwear</item> - <item>Cathedral</item> - <item>Competition</item> - <item>Joker</item> - <item>Blackboard</item> - <item>Bunk bed</item> - <item>Bear</item> - <item>Moon</item> - <item>Archery</item> - <item>Polo</item> - <item>River</item> - <item>Fishing</item> - <item>Ferris wheel</item> - <item>Mortarboard</item> - <item>Bracelet</item> - <item>Flesh</item> - <item>Statue</item> - <item>Farm</item> - <item>Desert</item> - <item>Chain</item> - <item>Aircraft</item> - <item>Textile</item> - <item>Hot dog</item> - <item>Knitting</item> - <item>Singer</item> - <item>Juice</item> - <item>Circus</item> - <item>Chair</item> - <item>Musical instrument</item> - <item>Room</item> - <item>Crochet</item> - <item>Sailboat</item> - <item>Newspaper</item> - <item>Santa claus</item> - <item>Swamp</item> - <item>Skyscraper</item> - <item>Skin</item> - <item>Rocket</item> - <item>Aviation</item> - <item>Airliner</item> - <item>Garden</item> - <item>Ruins</item> - <item>Storm</item> - <item>Glasses</item> - <item>Balance</item> - <item>Nail (Body part)</item> - <item>Rainbow</item> - <item>Soil </item> - <item>Vacation </item> - <item>Moustache</item> - <item>Doily</item> - <item>Food</item> - <item>Bride </item> - <item>Cattle</item> - <item>Pocket</item> - <item>Infrastructure</item> - <item>Train</item> - <item>Gerbil</item> - <item>Fireworks</item> - <item>Pet</item> - <item>Dam</item> - <item>Crew</item> - <item>Couch</item> - <item>Bathing</item> - <item>Quilting</item> - <item>Motorcycle</item> - <item>Butterfly</item> - <item>Sled</item> - <item>Watercolor paint</item> - <item>Rafting</item> - <item>Monument</item> - <item>Lightning</item> - <item>Sunset</item> - <item>Bumper</item> - <item>Shoe</item> - <item>Waterskiing</item> - <item>Sneakers</item> - <item>Tower</item> - <item>Insect</item> - <item>Pool</item> - <item>Placemat</item> - <item>Airplane</item> - <item>Plant</item> - <item>Jungle</item> - <item>Armrest</item> - <item>Duck</item> - <item>Dress</item> - <item>Tableware</item> - <item>Petal</item> - <item>Bus</item> - <item>Hanukkah</item> - <item>Forest</item> - <item>Hat</item> - <item>Barn</item> - <item>Tubing</item> - <item>Snorkeling</item> - <item>Cool</item> - <item>Cookware and bakeware</item> - <item>Cycling</item> - <item>Swing (Seat)</item> - <item>Muscle</item> - <item>Cat</item> - <item>Skateboard</item> - <item>Star</item> - <item>Toe</item> - <item>Junk</item> - <item>Bicycle</item> - <item>Bedroom</item> - <item>Person</item> - <item>Sand</item> - <item>Canyon</item> - <item>Tie</item> - <item>Twig</item> - <item>Sphynx</item> - <item>Supervillain</item> - <item>Nightclub</item> - <item>Ranch</item> - <item>Pattern</item> - <item>Shorts</item> - <item>Himalayan</item> - <item>Wall</item> - <item>Leggings</item> - <item>Windsurfing</item> - <item>Deejay</item> - <item>Dance</item> - <item>Van</item> - <item>Bento</item> - <item>Sleep</item> - <item>Wine</item> - <item>Picnic</item> - <item>Leisure</item> - <item>Dune</item> - <item>Crowd</item> - <item>Kayak</item> - <item>Ballroom</item> - <item>Selfie</item> - <item>Graduation</item> - <item>Frigate</item> - <item>Mountain</item> - <item>Dude</item> - <item>Windshield</item> - <item>Skiff</item> - <item>Class</item> - <item>Scarf</item> - <item>Bull</item> - <item>Soccer</item> - <item>Bag</item> - <item>Basset hound</item> - <item>Tractor</item> - <item>Swimming</item> - <item>Running</item> - <item>Track</item> - <item>Helicopter</item> - <item>Pitch</item> - <item>Clock</item> - <item>Song</item> - <item>Jersey</item> - <item>Stairs</item> - <item>Flap</item> - <item>Jewellery</item> - <item>Bridge</item> - <item>Cuisine</item> - <item>Bread</item> - <item>Caving</item> - <item>Shell</item> - <item>Wreath</item> - <item>Roof</item> - <item>Cookie</item> - <item>Canoe</item> - </string-array> -</resources> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/res/values-zh/strings.xml b/official/lite/pet_classification/app/src/main/res/values-zh/strings.xml deleted file mode 100644 index 1fc47435c197f3229f8f20d0902f385f7ac7c589..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/values-zh/strings.xml +++ /dev/null @@ -1,441 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <string name="app_name">PetClassification</string> - - <string name="action_settings">璁剧疆</string> - - <string name="camera_error">姝よ澶囦笉鏀寔Camera2 API.</string> - - <string name="image_invalid">鍥剧墖璺緞鏃犳晥锛岃鎹竴寮犲浘鐗囥€�</string> - <string name="train_invalid">鎶辨瓑锛屽綋鍓嶅浘鐗囨病鏈夊彲璇嗗埆鐗╀綋锛岃鏇存崲鍏朵粬鍥剧墖璇曡瘯!</string> - - <string name="app_result_identifying">姝e湪璇嗗埆...</string> - <string name="app_choose_an_image">閫夋嫨涓€寮犲浘鐗�</string> - <string name="app_photo">鍥剧墖</string> - <string name="app_camera">鐩告満</string>鐩告満/string> - <string name="app_scan">棰勮</string> - <string name="app_choose_a_sample">閫夋嫨涓€涓渚�</string> - <string name="app_choose_authority">PetClassification闇€瑕佽闂� 鈥滅浉鏈衡€� 鍜� 鈥滃閮ㄥ瓨鍌ㄥ櫒鈥濓紝璇峰埌 鈥滃簲鐢ㄤ俊鎭� -> 鏉冮檺鈥� 涓巿浜堬紒</string> - <string name="app_choose_authority_manual">鍘绘墜鍔ㄦ巿鏉�</string> - <string name="app_choose_cancle">鍙栨秷</string> - - <string-array name="image_category_pet"> - <item>鐚�</item> - <item>鐙�</item> - </string-array> - - <string-array name="image_category"> - <item>鏀剧墽</item> - <item>鑻规灉娴忚鍣�</item> - <item>鎵嬮暞</item> - <item>鍧愬灚</item> - <item>鍙伴潰</item> - <item>鑸炰細</item> - <item>绉�</item> - <item>浣撹偛</item> - <item>澶╃┖</item> - <item>绀惧尯</item> - <item>杞�</item> - <item>鍙箰</item> - <item>鐢峰+绀兼湇</item> - <item>鑺辩泦</item> - <item>鐞冮槦</item> - <item>鐢佃剳</item> - <item>鐙疆杞�</item> - <item>鍙屾鑸�</item> - <item>鑸┖鑸ぉ宸ョ▼</item> - <item>姘磋偤娼滄按</item> - <item>椋庨暅</item> - <item>姘存灉</item> - <item>缇芥瘺鐞�</item> - <item>椹�</item> - <item>澧ㄩ暅</item> - <item>濂界帺</item> - <item>鑽夊師</item> - <item>娴锋姤</item> - <item>鏃�</item> - <item>蹇墖</item> - <item>鐫瘺</item> - <item>闈㈢罕</item> - <item>绉诲姩鐢佃瘽</item> - <item>鐙疆杞�</item> - <item>纰�</item> - <item>鐨潻</item> - <item>鎶藉眽</item> - <item>绾�</item> - <item>鐮佸ご</item> - <item>姘寸</item> - <item>绱ц韩琛�</item> - <item>浜哄姏杞�</item> - <item>钄彍</item> - <item>鎵舵墜</item> - <item>鍐�</item> - <item>閲戝睘</item> - <item>鑺�</item> - <item>缈呰唨</item> - <item>閾跺櫒</item> - <item>浜嬩欢</item> - <item>澶╅檯绾�</item> - <item>閽�</item> - <item>婕敾</item> - <item>鎵嬫彁鍖�</item> - <item>鐡�</item> - <item>绔炴妧鑰�</item> - <item>绐楀笜</item> - <item>鐡�</item> - <item>浜虹被鐨勫槾宸�</item> - <item>鍐涢槦</item> - <item>鑿滃崟</item> - <item>鑸�</item> - <item>鍗曟澘婊戦洩</item> - <item>鍑仼鐙�</item> - <item>缃�</item> - <item>绮樿创</item> - <item>鏉瓙</item> - <item>姗勬鐞�</item> - <item> 绮�</item> - <item>甯�</item> - <item>浜虹殑澶村彂</item> - <item>鍐叉氮</item> - <item>鍙屼汉娌欏彂</item> - <item>鍗氱墿棣�</item> - <item>娌夎埞</item> - <item>鏍�</item> - <item>闀挎瘺缁�</item> - <item>鍗曡壊</item> - <item>鐏北</item> - <item>宀╃煶</item> - <item>鏋曞ご</item> - <item>浠嬬粛</item> - <item>鏄熶簯</item> - <item>浣庨煶鐐�</item> - <item>婀�</item> - <item>闆﹪</item> - <item>鍒樻捣</item> - <item>妗屽竷</item> - <item>椤归摼</item> - <item>娓告吵琛�</item> - <item>绔欑珛</item> - <item>鐗涗粩瑁�</item> - <item>鐙傛</item> - <item>鍨掔悆</item> - <item>涓績</item> - <item>婊戞澘鎵�</item> - <item>铔嬬硶</item> - <item>榫�</item> - <item>鏋佸厜</item> - <item>婊戦洩</item> - <item>娴村</item> - <item>鐙�</item> - <item>閽堢嚎娲�</item> - <item>闆ㄤ紴</item> - <item>鏁欎細</item> - <item>鐏�</item> - <item>閽㈢惔</item> - <item>鐗涗粩甯�</item> - <item>杈�</item> - <item>鍐呴榿</item> - <item>鍙g孩</item> - <item>鐜�</item> - <item>鐢佃</item> - <item>婊氱瓛</item> - <item>瀵嗗皝</item> - <item>闊充箰浼�</item> - <item>浜у搧</item> - <item>鏂伴椈</item> - <item>蹇</item> - <item>瑙掞紙鍔ㄧ墿锛�</item> - <item>绾硅韩</item> - <item>楦�</item> - <item>鏂伴儙</item> - <item>鐖�</item> - <item>澶寸洈</item> - <item>鎭愰緳</item> - <item>鍒ㄥ啺</item> - <item>寰瀷</item> - <item>鑳�</item> - <item>鐜╁叿</item> - <item>鍐版煴</item> - <item>澶瑰厠</item> - <item>鍜栧暋</item> - <item>娓呯湡瀵�</item> - <item>鍒掕埞</item> - <item>娼滄按琛�</item> - <item>闇茶惀</item> - <item>姘翠笅</item> - <item>鍦h癁</item> - <item>鏍兼媺鎵�</item> - <item>鐧芥澘</item> - <item>棰嗗煙</item> - <item>甯冨伓鐚�</item> - <item>鏂藉伐</item> - <item>鐏僵</item> - <item>瀹�</item> - <item>鑶抽</item> - <item>鍘�</item> - <item>绗�</item> - <item>蹇埞锛堣埞锛�</item> - <item>浣撴搷</item> - <item>榫�</item> - <item>浜鸿剼</item> - <item>濠氬Щ</item> - <item>缃戦〉</item> - <item>浜鸿儭椤�</item> - <item>澶氶浘璺</item> - <item>缇婃瘺</item> - <item>鍗″竷濂囪鍜栧暋</item> - <item>鐏</item> - <item>涔愰珮</item> - <item>鐏姳</item> - <item>鑾庝附</item> - <item>妯″瀷</item> - <item>瀵哄簷</item> - <item>璞嗚眴</item> - <item>寤洪€�</item> - <item>鐎戝竷</item> - <item>浼侀箙</item> - <item>娲炵┐</item> - <item>浣撹偛鍦�</item> - <item>寰瑧</item> - <item>浜虹殑鎵�</item> - <item>鍏洯</item> - <item>鍙�</item> - <item>璁惧緱鍏扮兢宀涚墽缇婄姮</item> - <item>閰掑惂</item> - <item>鍚�</item> - <item>姘�</item> - <item>鏂戠偣鐙�</item> - <item>槌勯奔</item> - <item>婊戞按</item> - <item>闀挎澘</item> - <item>璺�</item> - <item>绉嶆棌</item> - <item>鍘ㄦ埧</item> - <item>閲岀▼琛�</item> - <item>鎮礀</item> - <item>灏忚</item> - <item>瀛︽牎</item> - <item>鐩镐簰浣滅敤</item> - <item>鏂楃墰</item> - <item>涔夊拰鍥�</item> - <item>琚�</item> - <item>姘存棌棣�</item> - <item>瓒呯骇鑻遍泟</item> - <item>棣呴ゼ</item> - <item>娌ラ潚</item> - <item>鍐叉氮鏉�</item> - <item>鑺濆+姹夊牎</item> - <item>灞忓箷鎴浘</item> - <item>鏅氶</item> - <item>绗�</item> - <item>鍗堥</item> - <item>娲惧 </item> - <item>鍐板窛</item> - <item>闀垮嚦</item> - <item>绁栫埗姣�</item> - <item>姘存Ы</item> - <item>闆€椴风</item> - <item>瑗胯澶栧</item> - <item>鐮�</item> - <item>绌洪棿</item> - <item>鑳屽寘</item> - <item>姣涚粧鐜╁叿</item> - <item>瀵垮徃</item> - <item>闂厜</item> - <item>绡濈伀</item> - <item>鍩庡牎</item> - <item>椹媺鏉�</item> - <item>姣旇惃</item> - <item>娴锋哗</item> - <item>浜鸿€�</item> - <item>璧涜溅</item> - <item>鍧愮潃</item> - <item>鍐板北</item> - <item>鏋�</item> - <item>杞﹁締</item> - <item>娴佽闊充箰</item> - <item>鎿嶅満</item> - <item>灏忎笐</item> - <item>姹借溅</item> - <item>鏀剁揣</item> - <item>姣涚毊</item> - <item>闊充箰瀹�</item> - <item>璧屽満</item> - <item>瀹濆疂</item> - <item>閱�</item> - <item>鑳屽甫</item> - <item>绀�</item> - <item>姘旂悆</item> - <item>澶栧</item> - <item>澶ф暀鍫�</item> - <item>绔炰簤</item> - <item>灏忎笐</item> - <item>榛戞澘</item> - <item>鍙屽眰搴�</item> - <item>鐔�</item> - <item>鏈堜寒</item> - <item>灏勭</item> - <item>椹悆</item> - <item>娌�</item> - <item>閽撻奔</item> - <item>鎽╁ぉ杞�</item> - <item>鐮傛祮鏉�</item> - <item>鎵嬮暞</item> - <item>鑲�</item> - <item>闆曞儚</item> - <item>鍐滃満</item> - <item>娌欐紶</item> - <item>閾�</item> - <item>椋炴満</item> - <item>绾虹粐鍝�</item> - <item>鐑嫍</item> - <item>閽堢粐</item> - <item>姝屾墜</item> - <item>鏋滄眮</item> - <item>椹垙鍥�</item> - <item>妞呭瓙</item> - <item>涔愬櫒</item> - <item>鎴块棿</item> - <item>閽╅拡</item> - <item>甯嗚埞</item> - <item>鎶ョ焊</item> - <item>鍦h癁鑰佷汉</item> - <item>娌兼辰</item> - <item>鎽╁ぉ澶фゼ</item> - <item>鐨偆</item> - <item>鐏</item> - <item>鑸┖</item> - <item>瀹㈡満</item> - <item>鑺卞洯</item> - <item>搴熷</item> - <item>椋庢毚</item> - <item>鐪奸暅</item> - <item>骞宠 </item> - <item>鎸囩敳锛堣韩浣撻儴浣嶏級</item> - <item>褰╄櫣</item> - <item>娉� </item> - <item>鍋囨湡</item> - <item>鑳″瓙</item> - <item>妗屽肪</item> - <item>椁愰ギ</item> - <item>鏂板</item> - <item>鐗�</item> - <item>鍙h</item> - <item>鍩虹璁炬柦</item> - <item>鍩瑰吇</item> - <item>娌欓紶</item> - <item>鐑熻姳</item> - <item>瀹犵墿</item> - <item>鍧�</item> - <item>鑸瑰憳</item> - <item>闀挎</item> - <item>娲楁尽</item> - <item>閫€鍑�</item> - <item>鎽╂墭杞�</item> - <item>铦磋澏</item> - <item>闆﹪</item> - <item>姘村僵棰滄枡</item> - <item>婕傛祦</item> - <item>绾康纰�</item> - <item>闂數</item> - <item>鏃ヨ惤</item> - <item>淇濋櫓鏉�</item> - <item>闉嬪瓙</item> - <item>婊戞按</item> - <item>鐞冮瀷</item> - <item>濉�</item> - <item>鏄嗚櫕</item> - <item>娓告吵姹�</item> - <item>椁愬灚</item> - <item>椋炴満</item> - <item>鍘�</item> - <item>涓涙灄</item> - <item>鎵舵墜</item> - <item>楦�</item> - <item>杩炶。瑁�</item> - <item>椁愬叿</item> - <item>鑺辩摚</item> - <item>鎬荤嚎</item> - <item>鍏夋槑鑺�</item> - <item>妫灄</item> - <item>甯藉瓙</item> - <item>璋蜂粨</item> - <item>绠¢亾</item> - <item>娴綔</item> - <item>鍑�</item> - <item>鐐婂叿鍜岀儰鐩�</item> - <item>寰幆</item> - <item>绉嬪崈锛堝骇浣嶏級</item> - <item>鑲岃倝</item> - <item>鐚�</item> - <item>婊戞澘</item> - <item>鏄�</item> - <item>鑴氳毒</item> - <item>鍨冨溇</item> - <item>鑷杞�</item> - <item>鍗у</item> - <item>浜�</item> - <item>鐮�</item> - <item>宄¤胺</item> - <item>棰嗗甫</item> - <item>鏋濇潯</item> - <item>鍔犳嬁澶ф棤姣涚尗</item> - <item>瓒呯骇鍙嶆淳</item> - <item>澶滃簵</item> - <item>鐗у満</item> - <item>妯″紡</item> - <item>鐭¥</item> - <item>鍠滈┈鎷夐泤灞�</item> - <item>澹�</item> - <item>缁戣吙</item> - <item>椋庡竼鍐叉氮</item> - <item>DJ</item> - <item>鑸炶箞</item> - <item>鍘㈠紡璐ц溅</item> - <item>渚垮綋</item> - <item>鐫¤</item> - <item>钁¤悇閰�</item> - <item>閲庨</item> - <item>浼戦棽</item> - <item>娌欎笜</item> - <item>浜虹兢</item> - <item>鐨墖</item> - <item>鑸炲巺</item> - <item>鑷媿</item> - <item>姣曚笟</item> - <item>鎶ゅ崼鑸�</item> - <item>灞�</item> - <item>鐢蜂汉</item> - <item>鎸¢鐜荤拑</item> - <item>灏忚墖</item> - <item>绫�</item> - <item>鍥村肪</item> - <item>鍏墰</item> - <item>瓒崇悆</item> - <item>琚�</item> - <item>宸村悏搴︾寧鐘�</item> - <item>鎷栨媺鏈�</item> - <item>娓告吵鐨�</item> - <item>姝e湪杩愯</item> - <item>璺熻釜</item> - <item>鐩村崌鏈�</item> - <item>娌ラ潚</item> - <item>鏃堕挓</item> - <item>姝屾洸</item> - <item>娉借タ宀�</item> - <item>妤兼</item> - <item>瑗熺考</item> - <item>棣栭グ</item> - <item>妗�</item> - <item>缇庨</item> - <item>闈㈠寘</item> - <item>鎺㈡礊</item> - <item>璐濆3</item> - <item>鑺卞湀</item> - <item>灞嬮《</item> - <item>鏇插楗�</item> - <item>鐙湪鑸�</item> - </string-array> - - -</resources> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/res/values/colors.xml b/official/lite/pet_classification/app/src/main/res/values/colors.xml deleted file mode 100644 index 7d780cf8088a04c1a89fa320ea41052d9db61b11..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/values/colors.xml +++ /dev/null @@ -1,17 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <color name="colorPrimary">#303030</color> - <color name="colorPrimaryDark">#3700B3</color> - <color name="colorAccent">#03DAC5</color> - - <color name="white">#ffffff</color> - <color name="black">#000000</color> - <color name="gray">#A69D9D</color> - <color name="gray_btn">#424242</color> - - <color name="text_blue">#6DA7FF</color> - <color name="text_yellow">#F8E71C</color> - <color name="text_orange">#FF844D</color> - <color name="text_green">#66B50A</color> - -</resources> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/res/values/dimens.xml b/official/lite/pet_classification/app/src/main/res/values/dimens.xml deleted file mode 100644 index a7b5dd0995ed7b6fe032fe40565e9b1ad2dae413..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/values/dimens.xml +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <dimen name="ms_bottom_sheet_corner_radius">15dp</dimen> - <dimen name="ms_bottom_sheet_top_padding">8dp</dimen> - - <dimen name="hor_text_view_text_margin_normal">15dp</dimen> - <dimen name="hor_text_view_text_margin_small">6dp</dimen> - <dimen name="hor_text_view_text_size">15sp</dimen> -</resources> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/res/values/ic_launcher_background.xml b/official/lite/pet_classification/app/src/main/res/values/ic_launcher_background.xml deleted file mode 100644 index c5d5899fdf0a1b144bf341b29e0c66ba50bbcedd..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/values/ic_launcher_background.xml +++ /dev/null @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <color name="ic_launcher_background">#FFFFFF</color> -</resources> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/res/values/strings.xml b/official/lite/pet_classification/app/src/main/res/values/strings.xml deleted file mode 100644 index 597396f48f709b11f69fd2d8fe1d7a195c93b6f2..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/values/strings.xml +++ /dev/null @@ -1,439 +0,0 @@ -<resources> - <string name="app_name">PetClassification</string> - <string name="action_settings">璁剧疆</string> - - <string name="camera_error">This device doesn\'t support Camera2 API.</string> - - <string name="image_invalid">The image path you selected is not valid. Please choose again</string> - <string name="train_invalid">Sorry, there is no object identified in this picture. Try another picture</string> - - <string name="app_result_identifying">姝e湪璇嗗埆...</string> - <string name="app_choose_an_image">Choose an image</string> - <string name="app_photo">PHOTO</string> - <string name="app_camera">CAMERA</string> - <string name="app_scan">SCAN</string> - <string name="app_choose_a_sample">Choose a sample</string> - <string name="app_choose_authority">PetClassification闇€瑕佽闂� 鈥滅浉鏈衡€� 鍜� 鈥滃閮ㄥ瓨鍌ㄥ櫒鈥濓紝璇峰埌 鈥滃簲鐢ㄤ俊鎭� -> 鏉冮檺鈥� 涓巿浜堬紒</string> - <string name="app_choose_authority_manual">鍘绘墜鍔ㄦ巿鏉�</string> - <string name="app_choose_cancle">鍙栨秷</string> - - <string-array name="image_category_pet"> - <item>Cat</item> - <item>Dog</item> - </string-array> - - <string-array name="image_category"> - <item>Herd</item> - <item>Safari</item> - <item>Bangle</item> - <item>Cushion</item> - <item>Countertop</item> - <item>Prom</item> - <item>Branch</item> - <item>Sports</item> - <item>Sky</item> - <item>Community</item> - <item>Wheel</item> - <item>Cola</item> - <item>Tuxedo</item> - <item>Flowerpot</item> - <item>Team</item> - <item>Computer</item> - <item>Unicycle</item> - <item>Brig</item> - <item>Aerospace engineering</item> - <item>Scuba diving</item> - <item>Goggles</item> - <item>Fruit</item> - <item>Badminton</item> - <item>Horse</item> - <item>Sunglasses</item> - <item>Fun</item> - <item>Prairie</item> - <item>Poster</item> - <item>Flag</item> - <item>Speedboat</item> - <item>Eyelash</item> - <item>Veil</item> - <item>Mobile phone</item> - <item>Wheelbarrow</item> - <item>Saucer</item> - <item>Leather</item> - <item>Drawer</item> - <item>Paper</item> - <item>Pier</item> - <item>Waterfowl</item> - <item>Tights</item> - <item>Rickshaw</item> - <item>Vegetable</item> - <item>Handrail</item> - <item>Ice</item> - <item>Metal</item> - <item>Flower</item> - <item>Wing</item> - <item>Silverware</item> - <item>Event</item> - <item>Skyline</item> - <item>Money</item> - <item>Comics</item> - <item>Handbag</item> - <item>Porcelain</item> - <item>Rodeo</item> - <item>Curtain</item> - <item>Tile</item> - <item>Human mouth</item> - <item>Army</item> - <item>Menu</item> - <item>Boat</item> - <item>Snowboarding</item> - <item>Cairn terrier</item> - <item>Net</item> - <item>Pasteles</item> - <item>Cup</item> - <item>Rugby</item> - <item>Pho</item> - <item>Cap</item> - <item>Human hair</item> - <item>Surfing</item> - <item>Loveseat</item> - <item>Museum</item> - <item>Shipwreck</item> - <item>Trunk (Tree)</item> - <item>Plush</item> - <item>Monochrome</item> - <item>Volcano</item> - <item>Rock</item> - <item>Pillow</item> - <item>Presentation</item> - <item>Nebula</item> - <item>Subwoofer</item> - <item>Lake</item> - <item>Sledding</item> - <item>Bangs</item> - <item>Tablecloth</item> - <item>Necklace</item> - <item>Swimwear</item> - <item>Standing</item> - <item>Jeans</item> - <item>Carnival</item> - <item>Softball</item> - <item>Centrepiece</item> - <item>Skateboarder</item> - <item>Cake</item> - <item>Dragon</item> - <item>Aurora</item> - <item>Skiing</item> - <item>Bathroom</item> - <item>Dog</item> - <item>Needlework</item> - <item>Umbrella</item> - <item>Church</item> - <item>Fire</item> - <item>Piano</item> - <item>Denim</item> - <item>Bridle</item> - <item>Cabinetry</item> - <item>Lipstick</item> - <item>Ring</item> - <item>Television</item> - <item>Roller</item> - <item>Seal</item> - <item>Concert</item> - <item>Product</item> - <item>News</item> - <item>Fast food</item> - <item>Horn (Animal)</item> - <item>Tattoo</item> - <item>Bird</item> - <item>Bridegroom</item> - <item>Love</item> - <item>Helmet</item> - <item>Dinosaur</item> - <item>Icing</item> - <item>Miniature</item> - <item>Tire</item> - <item>Toy</item> - <item>Icicle</item> - <item>Jacket</item> - <item>Coffee</item> - <item>Mosque</item> - <item>Rowing</item> - <item>Wetsuit</item> - <item>Camping</item> - <item>Underwater</item> - <item>Christmas</item> - <item>Gelato</item> - <item>Whiteboard</item> - <item>Field</item> - <item>Ragdoll</item> - <item>Construction</item> - <item>Lampshade</item> - <item>Palace</item> - <item>Meal</item> - <item>Factory</item> - <item>Cage</item> - <item>Clipper (Boat)</item> - <item>Gymnastics</item> - <item>Turtle</item> - <item>Human foot</item> - <item>Marriage</item> - <item>Web page</item> - <item>Human beard</item> - <item>Fog</item> - <item>Wool</item> - <item>Cappuccino</item> - <item>Lighthouse</item> - <item>Lego</item> - <item>Sparkler</item> - <item>Sari</item> - <item>Model</item> - <item>Temple</item> - <item>Beanie</item> - <item>Building</item> - <item>Waterfall</item> - <item>Penguin</item> - <item>Cave</item> - <item>Stadium</item> - <item>Smile</item> - <item>Human hand</item> - <item>Park</item> - <item>Desk</item> - <item>Shetland sheepdog</item> - <item>Bar</item> - <item>Eating</item> - <item>Neon</item> - <item>Dalmatian</item> - <item>Crocodile</item> - <item>Wakeboarding</item> - <item>Longboard</item> - <item>Road</item> - <item>Race</item> - <item>Kitchen</item> - <item>Odometer</item> - <item>Cliff</item> - <item>Fiction</item> - <item>School</item> - <item>Interaction</item> - <item>Bullfighting</item> - <item>Boxer</item> - <item>Gown</item> - <item>Aquarium</item> - <item>Superhero</item> - <item>Pie</item> - <item>Asphalt</item> - <item>Surfboard</item> - <item>Cheeseburger</item> - <item>Screenshot</item> - <item>Supper</item> - <item>Laugh</item> - <item>Lunch</item> - <item>Party </item> - <item>Glacier</item> - <item>Bench</item> - <item>Grandparent</item> - <item>Sink</item> - <item>Pomacentridae</item> - <item>Blazer</item> - <item>Brick</item> - <item>Space</item> - <item>Backpacking</item> - <item>Stuffed toy</item> - <item>Sushi</item> - <item>Glitter</item> - <item>Bonfire</item> - <item>Castle</item> - <item>Marathon</item> - <item>Pizza</item> - <item>Beach</item> - <item>Human ear</item> - <item>Racing</item> - <item>Sitting</item> - <item>Iceberg</item> - <item>Shelf</item> - <item>Vehicle</item> - <item>Pop music</item> - <item>Playground</item> - <item>Clown</item> - <item>Car</item> - <item>Rein</item> - <item>Fur</item> - <item>Musician</item> - <item>Casino</item> - <item>Baby</item> - <item>Alcohol</item> - <item>Strap</item> - <item>Reef</item> - <item>Balloon</item> - <item>Outerwear</item> - <item>Cathedral</item> - <item>Competition</item> - <item>Joker</item> - <item>Blackboard</item> - <item>Bunk bed</item> - <item>Bear</item> - <item>Moon</item> - <item>Archery</item> - <item>Polo</item> - <item>River</item> - <item>Fishing</item> - <item>Ferris wheel</item> - <item>Mortarboard</item> - <item>Bracelet</item> - <item>Flesh</item> - <item>Statue</item> - <item>Farm</item> - <item>Desert</item> - <item>Chain</item> - <item>Aircraft</item> - <item>Textile</item> - <item>Hot dog</item> - <item>Knitting</item> - <item>Singer</item> - <item>Juice</item> - <item>Circus</item> - <item>Chair</item> - <item>Musical instrument</item> - <item>Room</item> - <item>Crochet</item> - <item>Sailboat</item> - <item>Newspaper</item> - <item>Santa claus</item> - <item>Swamp</item> - <item>Skyscraper</item> - <item>Skin</item> - <item>Rocket</item> - <item>Aviation</item> - <item>Airliner</item> - <item>Garden</item> - <item>Ruins</item> - <item>Storm</item> - <item>Glasses</item> - <item>Balance</item> - <item>Nail (Body part)</item> - <item>Rainbow</item> - <item>Soil </item> - <item>Vacation </item> - <item>Moustache</item> - <item>Doily</item> - <item>Food</item> - <item>Bride </item> - <item>Cattle</item> - <item>Pocket</item> - <item>Infrastructure</item> - <item>Train</item> - <item>Gerbil</item> - <item>Fireworks</item> - <item>Pet</item> - <item>Dam</item> - <item>Crew</item> - <item>Couch</item> - <item>Bathing</item> - <item>Quilting</item> - <item>Motorcycle</item> - <item>Butterfly</item> - <item>Sled</item> - <item>Watercolor paint</item> - <item>Rafting</item> - <item>Monument</item> - <item>Lightning</item> - <item>Sunset</item> - <item>Bumper</item> - <item>Shoe</item> - <item>Waterskiing</item> - <item>Sneakers</item> - <item>Tower</item> - <item>Insect</item> - <item>Pool</item> - <item>Placemat</item> - <item>Airplane</item> - <item>Plant</item> - <item>Jungle</item> - <item>Armrest</item> - <item>Duck</item> - <item>Dress</item> - <item>Tableware</item> - <item>Petal</item> - <item>Bus</item> - <item>Hanukkah</item> - <item>Forest</item> - <item>Hat</item> - <item>Barn</item> - <item>Tubing</item> - <item>Snorkeling</item> - <item>Cool</item> - <item>Cookware and bakeware</item> - <item>Cycling</item> - <item>Swing (Seat)</item> - <item>Muscle</item> - <item>Cat</item> - <item>Skateboard</item> - <item>Star</item> - <item>Toe</item> - <item>Junk</item> - <item>Bicycle</item> - <item>Bedroom</item> - <item>Person</item> - <item>Sand</item> - <item>Canyon</item> - <item>Tie</item> - <item>Twig</item> - <item>Sphynx</item> - <item>Supervillain</item> - <item>Nightclub</item> - <item>Ranch</item> - <item>Pattern</item> - <item>Shorts</item> - <item>Himalayan</item> - <item>Wall</item> - <item>Leggings</item> - <item>Windsurfing</item> - <item>Deejay</item> - <item>Dance</item> - <item>Van</item> - <item>Bento</item> - <item>Sleep</item> - <item>Wine</item> - <item>Picnic</item> - <item>Leisure</item> - <item>Dune</item> - <item>Crowd</item> - <item>Kayak</item> - <item>Ballroom</item> - <item>Selfie</item> - <item>Graduation</item> - <item>Frigate</item> - <item>Mountain</item> - <item>Dude</item> - <item>Windshield</item> - <item>Skiff</item> - <item>Class</item> - <item>Scarf</item> - <item>Bull</item> - <item>Soccer</item> - <item>Bag</item> - <item>Basset hound</item> - <item>Tractor</item> - <item>Swimming</item> - <item>Running</item> - <item>Track</item> - <item>Helicopter</item> - <item>Pitch</item> - <item>Clock</item> - <item>Song</item> - <item>Jersey</item> - <item>Stairs</item> - <item>Flap</item> - <item>Jewellery</item> - <item>Bridge</item> - <item>Cuisine</item> - <item>Bread</item> - <item>Caving</item> - <item>Shell</item> - <item>Wreath</item> - <item>Roof</item> - <item>Cookie</item> - <item>Canoe</item> - </string-array> - - -</resources> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/res/values/styles.xml b/official/lite/pet_classification/app/src/main/res/values/styles.xml deleted file mode 100644 index 13f74a4612ae4ee788536d05d8d14d20e3238f7b..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/values/styles.xml +++ /dev/null @@ -1,10 +0,0 @@ -<resources> - <!-- Base application theme. --> - <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> - <!-- Customize your theme here. --> - <item name="colorPrimary">@color/colorPrimary</item> - <item name="colorPrimaryDark">@color/colorPrimaryDark</item> - <item name="colorAccent">@color/colorAccent</item> - </style> - -</resources> \ No newline at end of file diff --git a/official/lite/pet_classification/app/src/main/res/xml/file_paths.xml b/official/lite/pet_classification/app/src/main/res/xml/file_paths.xml deleted file mode 100644 index a075ef96b4bd20fc317ba9f03f1933c629fcab3b..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/main/res/xml/file_paths.xml +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<paths> - <external-path - name="external_files" - path="." /> -</paths> diff --git a/official/lite/pet_classification/app/src/test/java/com/mindspore/classificationforpet/ExampleUnitTest.java b/official/lite/pet_classification/app/src/test/java/com/mindspore/classificationforpet/ExampleUnitTest.java deleted file mode 100644 index 2e2b7efbe81d565ed8daaeb6669d45e0f708ab35..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/app/src/test/java/com/mindspore/classificationforpet/ExampleUnitTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2021 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mindspore.classificationforpet; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() { - assertEquals(4, 2 + 2); - } -} diff --git a/official/lite/pet_classification/build.gradle b/official/lite/pet_classification/build.gradle deleted file mode 100644 index 8205219fc669d5f47ddd44e0ba622ba9521c4421..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/build.gradle +++ /dev/null @@ -1,27 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. -buildscript { - repositories { - google() - jcenter() - } - dependencies { - classpath "com.android.tools.build:gradle:4.0.1" - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - maven { - url "https://mirrors.huaweicloud.com/repository/maven/" - } - google() - jcenter() - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} \ No newline at end of file diff --git a/official/lite/pet_classification/gradle.properties b/official/lite/pet_classification/gradle.properties deleted file mode 100644 index f5020a3b3734dd3278c76586966dd4cec65659f4..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/gradle.properties +++ /dev/null @@ -1,20 +0,0 @@ -# Project-wide Gradle settings. -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx2048m -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true -# AndroidX package structure to make it clearer which packages are bundled with the -# Android operating system, and which are packaged with your app"s APK -# https://developer.android.com/topic/libraries/support-library/androidx-rn -android.useAndroidX=true -# Automatically convert third-party libraries to use AndroidX -android.enableJetifier=true -android.injected.testOnly=false \ No newline at end of file diff --git a/official/lite/pet_classification/gradle/wrapper/gradle-wrapper.jar b/official/lite/pet_classification/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index f6b961fd5a86aa5fbfe90f707c3138408be7c718..0000000000000000000000000000000000000000 Binary files a/official/lite/pet_classification/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/official/lite/pet_classification/gradle/wrapper/gradle-wrapper.properties b/official/lite/pet_classification/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 1d8635ad736243bee4244822252bca9e39252d05..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Tue Jul 28 10:28:05 CST 2020 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip diff --git a/official/lite/pet_classification/gradlew b/official/lite/pet_classification/gradlew deleted file mode 100644 index cccdd3d517fc5249beaefa600691cf150f2fa3e6..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/gradlew +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/env sh - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - -exec "$JAVACMD" "$@" diff --git a/official/lite/pet_classification/gradlew.bat b/official/lite/pet_classification/gradlew.bat deleted file mode 100644 index f9553162f122c71b34635112e717c3e733b5b212..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/gradlew.bat +++ /dev/null @@ -1,84 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/official/lite/pet_classification/settings.gradle b/official/lite/pet_classification/settings.gradle deleted file mode 100644 index 2c8486e4f274ffb867b0268bd0d2cd42c860ff0a..0000000000000000000000000000000000000000 --- a/official/lite/pet_classification/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -include ':app' -rootProject.name = "PetClassification" \ No newline at end of file