diff --git a/OAT.xml b/OAT.xml index 928ee17f29576d91971fc29b891be2fecbed05af..4c2b93a4b086b18b163186213e373598b9263d93 100755 --- a/OAT.xml +++ b/OAT.xml @@ -66,6 +66,9 @@ Note:If the text contains special characters, please escape them according to th + + + diff --git a/ai/BUILD.gn b/ai/BUILD.gn old mode 100644 new mode 100755 index 4cd6f8677e412dcc67c9533ed4ebbdbbe374c2c2..2d5f62cb75e5e3bba5822d3a964d8d4be5038b29 --- a/ai/BUILD.gn +++ b/ai/BUILD.gn @@ -18,6 +18,9 @@ group("ai") { "neural_network_runtime/v2_0:neural_network_runtime", ] if (is_standard_system) { - deps += [ "mindspore:ActsMindSporeTest" ] + deps += [ + "mindspore/mindsporectest:ActsMindSporeTest", + "mindspore/mindsporejstest:ActsMindsporeJSTest", + ] } } diff --git a/ai/mindspore/BUILD.gn b/ai/mindspore/mindsporectest/BUILD.gn similarity index 100% rename from ai/mindspore/BUILD.gn rename to ai/mindspore/mindsporectest/BUILD.gn diff --git a/ai/mindspore/Test.json b/ai/mindspore/mindsporectest/Test.json similarity index 92% rename from ai/mindspore/Test.json rename to ai/mindspore/mindsporectest/Test.json index 54cfe834385afe35167ca73596dc2354af401b34..7732b5e601988d784264aecbd123b08a516bff21 100644 --- a/ai/mindspore/Test.json +++ b/ai/mindspore/mindsporectest/Test.json @@ -33,11 +33,11 @@ "resource/ai/mindspore/ml_Hand_deploy/ml_Hand_deploy_0.input -> /data/test", "resource/ai/mindspore/ml_Hand_deploy/ml_Hand_deploy0.output -> /data/test", "resource/ai/mindspore/ml_ocr_cn/ml_ocr_cn.ms -> /data/test", - "resource/ai/mindspore/ml_ocr_cn/ml_headpose_pb2tflite_offline_model.ms -> /data/test", + "resource/ai/mindspore/ml_ocr_cn/ml_ocr_cn_offline_model.ms -> /data/test", "resource/ai/mindspore/ml_ocr_cn/ml_ocr_cn_0.input -> /data/test", "resource/ai/mindspore/ml_ocr_cn/ml_ocr_cn0.output -> /data/test", "resource/ai/mindspore/ml_headpose_pb2tflite/ml_headpose_pb2tflite.ms -> /data/test", - "resource/ai/mindspore/ml_headpose_pb2tflite/ml_ocr_cn_offline_model.ms -> /data/test", + "resource/ai/mindspore/ml_headpose_pb2tflite/ml_headpose_pb2tflite_offline_model.ms -> /data/test", "resource/ai/mindspore/ml_headpose_pb2tflite/ml_headpose_pb2tflite_0.input -> /data/test", "resource/ai/mindspore/ml_headpose_pb2tflite/ml_headpose_pb2tflite_1.input -> /data/test", "resource/ai/mindspore/ml_headpose_pb2tflite/ml_headpose_pb2tflite_2.input -> /data/test", diff --git a/ai/mindspore/src/ohos_c_api_test_mslite.cpp b/ai/mindspore/mindsporectest/src/ohos_c_api_test_mslite.cpp similarity index 100% rename from ai/mindspore/src/ohos_c_api_test_mslite.cpp rename to ai/mindspore/mindsporectest/src/ohos_c_api_test_mslite.cpp diff --git a/ai/mindspore/src/ohos_common.cpp b/ai/mindspore/mindsporectest/src/ohos_common.cpp similarity index 100% rename from ai/mindspore/src/ohos_common.cpp rename to ai/mindspore/mindsporectest/src/ohos_common.cpp diff --git a/ai/mindspore/src/ohos_common.h b/ai/mindspore/mindsporectest/src/ohos_common.h similarity index 100% rename from ai/mindspore/src/ohos_common.h rename to ai/mindspore/mindsporectest/src/ohos_common.h diff --git a/ai/mindspore/mindsporejstest/AppScope/app.json b/ai/mindspore/mindsporejstest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..0f46e559a7b3a3ae96c4d0d13722ff177c405b52 --- /dev/null +++ b/ai/mindspore/mindsporejstest/AppScope/app.json @@ -0,0 +1,18 @@ +{ + "app": { + "bundleName": "com.example.mindsporejstest", + "bundleType": "atomicService", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true, + "minAPIVersion": 10, + "targetAPIVersion": 10, + "car": { + "apiCompatibleVersion": 10, + "singleUser": false + } + } +} diff --git a/ai/mindspore/mindsporejstest/AppScope/resources/base/element/string.json b/ai/mindspore/mindsporejstest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6181c9c565b36d9d1288f7d117274617dc9d6716 --- /dev/null +++ b/ai/mindspore/mindsporejstest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ActsMindsporeJSTest" + } + ] +} diff --git a/ai/mindspore/mindsporejstest/AppScope/resources/base/media/app_icon.png b/ai/mindspore/mindsporejstest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ai/mindspore/mindsporejstest/AppScope/resources/base/media/app_icon.png differ diff --git a/ai/mindspore/mindsporejstest/BUILD.gn b/ai/mindspore/mindsporejstest/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..ce339975221bcc8b150f6c95b2c00fe591a3cd67 --- /dev/null +++ b/ai/mindspore/mindsporejstest/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2021-2022 Huawei Device 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. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsMindsporeJSTest") { + hap_profile = "./src/main/module.json" + deps = [ + ":mindspore_js_assets", + ":mindspore_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsMindsporeJSTest" +} +ohos_app_scope("mindspore_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} +ohos_js_assets("mindspore_js_assets") { + source_dir = "./src/main/ets" +} +ohos_resources("mindspore_resources") { + sources = [ "./src/main/resources" ] + deps = [ ":mindspore_app_profile" ] + hap_profile = "./src/main/module.json" +} diff --git a/ai/mindspore/mindsporejstest/Test.json b/ai/mindspore/mindsporejstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..df3c23fe054c70d6b073d558f085fd1a6b41f110 --- /dev/null +++ b/ai/mindspore/mindsporejstest/Test.json @@ -0,0 +1,20 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "600000", + "shell-timeout": "800000", + "bundle-name": "com.example.mindsporejstest", + "module-name": "entry", + "testcase-timeout": 40000 + }, + "kits": [ + { + "test-file-name": [ + "ActsMindsporeJSTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/ai/mindspore/mindsporejstest/signature/openharmony_sx.p7b b/ai/mindspore/mindsporejstest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..74b21bfd2a174aab0aa42d24e20288b4a398bd90 Binary files /dev/null and b/ai/mindspore/mindsporejstest/signature/openharmony_sx.p7b differ diff --git a/ai/mindspore/mindsporejstest/src/main/ets/TestAbility/TestAbility.ets b/ai/mindspore/mindsporejstest/src/main/ets/TestAbility/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..8047717a863b54bd84516aca0b16024e744081fa --- /dev/null +++ b/ai/mindspore/mindsporejstest/src/main/ets/TestAbility/TestAbility.ets @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2023 Huawei Device 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. + */ +import UIAbility from '@ohos.app.ability.UIAbility'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import hilog from '@ohos.hilog'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; +import window from '@ohos.window'; +import Want from '@ohos.app.ability.Want'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; + +export default class TestAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + globalThis.context = this.context; + globalThis.abilityContext = this.context + hilog.info(0x0000, 'testTag', '%{public}s', 'fileDir:' + JSON.stringify(this.context.filesDir) ?? ''); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); + windowStage.loadContent('TestAbility/pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} diff --git a/ai/mindspore/mindsporejstest/src/main/ets/TestAbility/pages/Index.ets b/ai/mindspore/mindsporejstest/src/main/ets/TestAbility/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..07c41d5dcbd98b4fb2c504857d996cbaa81e7ed7 --- /dev/null +++ b/ai/mindspore/mindsporejstest/src/main/ets/TestAbility/pages/Index.ets @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2023 Huawei Device 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. + */ +import hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } diff --git a/ai/mindspore/mindsporejstest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/ai/mindspore/mindsporejstest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..92a16d84e8870da219c51d9f1342c79203c1f42d --- /dev/null +++ b/ai/mindspore/mindsporejstest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,49 @@ +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/ai/mindspore/mindsporejstest/src/main/ets/test/Ability.test.ets b/ai/mindspore/mindsporejstest/src/main/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..99c5e42a19b8eccc03e8c03f4ef364cef250bb15 --- /dev/null +++ b/ai/mindspore/mindsporejstest/src/main/ets/test/Ability.test.ets @@ -0,0 +1,2044 @@ +/* + * Copyright (C) 2023 Huawei Device 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. + */ +import hilog from '@ohos.hilog'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import mindSporeLite from '@ohos.ai.mindSporeLite'; +import fs from '@ohos.file.fs'; + +export default function abilityTest() { + describe('ActsAbilityTest', function () { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(function () { + let dir = globalThis.abilityContext.filesDir + "/"; + try { + let mnet_caffemodel_model_file = dir + "mnet.caffemodel.ms"; + globalThis.context.resourceManager.getRawFileContent("mnet.caffemodel.ms", (error, model_buffer) => { + if (error != null) { + //getRawFileDescriptor运行失败 + console.log( + "[rawfile_copy_to_sandbox] mnet.caffemodel.ms is copy " + + "failed:${error.code}, message: ${error.message}."); + } else { + //getRawFileDescriptor运行成功 + let file = fs.openSync(mnet_caffemodel_model_file, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + fs.writeSync(file.fd, model_buffer.buffer); + fs.closeSync(file); + console.log("[rawfile_copy_to_sandbox] mnet.caffemodel.ms is copy success"); + } + }); + + let mnet_caffemodel_bin_file = dir + "mnet_caffemodel_nhwc.bin"; + globalThis.context.resourceManager.getRawFileContent("mnet_caffemodel_nhwc.bin", (error, model_buffer) => { + if (error != null) { + //getRawFileDescriptor运行失败 + console.log( + "[rawfile_copy_to_sandbox] mnet_caffemodel_nhwc.bin is copy " + + "failed:${error.code}, message: ${error.message}."); + } else { + //getRawFileDescriptor运行成功 + let file = fs.openSync(mnet_caffemodel_bin_file, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + fs.writeSync(file.fd, model_buffer.buffer); + fs.closeSync(file); + console.log("[rawfile_copy_to_sandbox] mnet_caffemodel_nhwc.bin is copy success"); + } + }); + + let ml_ocr_model_file = dir + "ml_ocr_cn.ms"; + globalThis.context.resourceManager.getRawFileContent("ml_ocr_cn.ms", (error, model_buffer) => { + if (error != null) { + //getRawFileDescriptor运行失败 + console.log( + "[rawfile_copy_to_sandbox] ml_ocr_cn.ms is copy " + + "failed:${error.code}, message: ${error.message}."); + } else { + //getRawFileDescriptor运行成功 + let file = fs.openSync(ml_ocr_model_file, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + fs.writeSync(file.fd, model_buffer.buffer); + fs.closeSync(file); + console.log("[rawfile_copy_to_sandbox] ml_ocr_cn.ms is copy success"); + } + }); + + let ml_face_model_file = dir + "ml_face_isface.ms"; + globalThis.context.resourceManager.getRawFileContent("ml_face_isface.ms", (error, model_buffer) => { + if (error != null) { + //getRawFileDescriptor运行失败 + console.log( + "[rawfile_copy_to_sandbox] ml_face_isface.ms is copy " + + "failed:${error.code}, message: ${error.message}."); + } else { + //getRawFileDescriptor运行成功 + let file = fs.openSync(ml_face_model_file, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + fs.writeSync(file.fd, model_buffer.buffer); + fs.closeSync(file); + console.log("[rawfile_copy_to_sandbox] ml_face_isface.ms is copy success"); + } + }); + + } catch (error) { + console.info("[rawfile_copy_to_sandbox] getRawFileDescriptor api run failed" + error); + } + + console.info("[rawfile_copy_to_sandbox] sandbox path:" + dir); + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(function () { + let dir = globalThis.abilityContext.filesDir + "/"; + let mnet_caffemodel_model_file = dir + "mnet.caffemodel.ms"; + fs.access(mnet_caffemodel_model_file).then((res) => { + if (res) { + console.info("mnet.caffemodel.ms file exists"); + } + }).catch((err) => { + console.info("mnet.caffemodel.ms file does not exists! access failed with error message: " + err.message + ", error code: " + err.code); + }); + + let mnet_caffemodel_bin_file = dir + "mnet_caffemodel_nhwc.bin"; + fs.access(mnet_caffemodel_bin_file).then((res) => { + if (res) { + console.info("mnet_caffemodel_nhwc.bin file exists"); + } + }).catch((err) => { + console.info("mnet_caffemodel_nhwc.bin file does not exist! access failed with error message: " + + err.message + ", error code: " + err.code); + }); + + let ml_ocr_model = dir + "ml_ocr_cn.ms"; + fs.access(ml_ocr_model).then((res) => { + if (res) { + console.info("ml_ocr_cn.ms file exists"); + } + }).catch((err) => { + console.info("ml_ocr_cn.ms file does not exists! access failed with error message: " + + err.message + ", error code: " + err.code); + }); + + let ml_face_model = dir + "ml_face_isface.ms"; + fs.access(ml_face_model).then((res) => { + if (res) { + console.info("ml_face_isface.ms file exists"); + } + }).catch((err) => { + console.info("ml_face_isface.ms file does not exists! access failed with error message: " + + err.message + ", error code: " + err.code); + }); + + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(function () { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(function () { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + // 正常场景:ModelBuild,调用buffer方法,正常推理 + it('Test_load_model_param_model_buffer',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_buffer"); + let modelName = 'mnet.caffemodel.ms'; + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + syscontext.resourceManager.getRawFileContent(modelName).then((model_buffer) => { + let modelBuffer = model_buffer + let context: mindSporeLite.Context = {}; + context.target = ["cpu"]; + context.cpu = { + "threadNum": 1, + } + context.cpu.threadAffinityMode = 1; + context.cpu.precisionMode = "preferred_fp16"; + context.cpu.threadAffinityCoreList = [0, 1, 2, 3]; + mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, context).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].name); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + console.log(modelInputs[0].dataSize.toString()); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + }) + + + + // 正常场景:ModelBuild,调用fd方法,正常推理 + it('Test_load_model_param_model_fd', 0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_fd"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + console.log('=========MSLITE loadModel start====='); + let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY); + mindSporeLite.loadModelFromFd(file.fd).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].name); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + console.log(modelInputs[0].dataSize.toString()); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + // 正常场景:ModelBuild,调用loadModelFromFile方法,正常推理 + it('Test_load_model_param_model_path',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + let context:mindSporeLite.Context={}; + context.target = ["cpu"]; + context.cpu = { + "threadNum": 1, + } + context.cpu.threadAffinityMode = 1; + context.cpu.precisionMode = "preferred_fp16"; + context.cpu.threadAffinityCoreList = [0, 1, 2, 3]; + console.log('=========MSLITE loadModel start====='); + mindSporeLite.loadModelFromFile(model_file, context).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].name); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + console.log(modelInputs[0].dataSize.toString()); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + //正常场景:Context设置CPU,4线程 + it('Test_load_model_param_model_path_settings_threads_001',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_threads_001"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + let context:mindSporeLite.Context={}; + context.target = ["cpu"]; + context.cpu = { + "threadNum": 4, + } + mindSporeLite.loadModelFromFile(model_file, context).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].name); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + console.log(modelInputs[0].dataSize.toString()); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + //正常场景:Context设置CPU,2线程 + it('Test_load_model_param_model_path_settings_threads_002',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_threads_002"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + let context:mindSporeLite.Context={}; + context.target = ["cpu"]; + context.cpu = { + "threadNum": 2, + } + mindSporeLite.loadModelFromFile(model_file, context).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].name); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + console.log(modelInputs[0].dataSize.toString()); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + //正常场景:Context设置CPU,1线程 + it('Test_load_model_param_model_path_settings_threads_003',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_threads_003"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + let context:mindSporeLite.Context={}; + context.target = ["cpu"]; + context.cpu = { + "threadNum": 1, + } + mindSporeLite.loadModelFromFile(model_file, context).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].name); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + console.log(modelInputs[0].dataSize.toString()); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + //正常场景:Context设置CPU,0线程 + it('Test_load_model_param_model_path_settings_threads_004',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_threads_004"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + let context:mindSporeLite.Context={}; + context.target = ["cpu"]; + context.cpu = { + "threadNum": 0, + } + mindSporeLite.loadModelFromFile(model_file, context).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].name); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + console.log(modelInputs[0].dataSize.toString()); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + //异常场景:Context设置CPU,绑核设置为3,绑核失败 + it('Test_load_model_param_model_path_settings_affinity_001',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_affinity_001"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + let context:mindSporeLite.Context={}; + context.target = ["cpu"]; + context.cpu={}; + context.cpu.threadAffinityMode = 3; + console.log("MSLITE api test: set threadAffinityMode=3."); + mindSporeLite.loadModelFromFile(model_file, context).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].name); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + console.log(modelInputs[0].dataSize.toString()); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + ///异常场景:Context设置CPU,绑核设置为2,绑大核 + it('Test_load_model_param_model_path_settings_affinity_002',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_affinity_002"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + let context:mindSporeLite.Context={}; + context.target = ["cpu"]; + context.cpu={}; + context.cpu.threadAffinityMode = 2; + console.log("MSLITE api test: set threadAffinityMode=2."); + mindSporeLite.loadModelFromFile(model_file, context).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].name); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + console.log(modelInputs[0].dataSize.toString()); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + //异常场景:Context设置CPU,绑核设置为1,绑小核 + it('Test_load_model_param_model_path_settings_affinity_003',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_affinity_003"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + let context:mindSporeLite.Context={}; + context.target = ["cpu"]; + context.cpu={}; + context.cpu.threadAffinityMode = 1; + console.log("MSLITE api test: set threadAffinityMode=1."); + mindSporeLite.loadModelFromFile(model_file, context).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].name); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + console.log(modelInputs[0].dataSize.toString()); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + //正常场景:Context设置CPU,绑核设置为0,不绑核 + it('Test_load_model_param_model_path_settings_affinity_004',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_affinity_004"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + let context:mindSporeLite.Context={}; + context.target = ["cpu"]; + context.cpu={}; + context.cpu.threadAffinityMode = 0; + console.log("MSLITE api test: set threadAffinityMode=0."); + mindSporeLite.loadModelFromFile(model_file, context).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].name); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + console.log(modelInputs[0].dataSize.toString()); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + + //正常场景:Context设置CPU,绑核列表[0,1,2,3] + it('Test_load_model_param_model_path_settings_affinity_list_001',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_affinity_list_001"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + let context:mindSporeLite.Context={}; + context.target = ["cpu"]; + context.cpu={}; + context.cpu.threadAffinityCoreList = [0, 1, 2, 3]; + console.log("MSLITE api test: set threadAffinityCoreList=[0, 1, 2, 3]."); + mindSporeLite.loadModelFromFile(model_file, context).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].name); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + console.log(modelInputs[0].dataSize.toString()); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + //异常场景:ModelBuild,调用model path方法,path为空 + it('Test_load_model_param_model_path_is_None_001',0, async function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_is_None_001"); + let model_file = ""; + let context:mindSporeLite.Context={}; + context.target = ["cpu"]; + let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context) + console.log('=========MSLITE loadModel end====='); + expect(msliteModel).assertUndefined() + done() + }) + + + //异常场景:ModelBuild,调用buffer方法,modelBuffer为None + it('Test_load_model_param_model_buffer_is_None_001',0, async function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_buffer_is_None_001"); + let context:mindSporeLite.Context={}; + context.target = ["cpu"]; + let msliteModel = await mindSporeLite.loadModelFromBuffer(null, context) + console.log('=========MSLITE loadModel end====='); + expect(msliteModel).assertUndefined() + done() + }) + + + //异常场景:ModelBuild,context为null + it('Test_load_model_param_model_path_context_is_None_001',0, async function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_context_is_None_001"); + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + let context:mindSporeLite.Context=null; + let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context) + expect(msliteModel).assertUndefined() + console.log('=========MSLITE loadModel end====='); + done(); + }) + + // 正常场景:ModelResize,shape与之前一致 + it('Test_load_model_param_model_path_resize_001',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_resize_001"); + let inputName = 'ml_ocr_cn_0.input'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_ocr_cn.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + mindSporeLite.loadModelFromFile(model_file).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + console.log(modelInputs[0].name); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].shape.toString()).assertEqual("1,32,512,1"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("16384"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].dataSize.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("65536"); + console.log('=========MSLITE resize start=====') + let new_dim = new Array([1, 32, 512, 1]); + let resize_result = msliteModel.resize(modelInputs, new_dim); + expect(resize_result).assertTrue() + console.log('=========MSLITE resize success=====') + const modelInputs2 = msliteModel.getInputs(); + console.log(modelInputs2[0].name); + expect(modelInputs2[0].name.toString()).assertEqual("data"); + console.log(modelInputs2[0].shape.toString()); + expect(modelInputs2[0].shape.toString()).assertEqual("1,32,512,1"); + console.log(modelInputs2[0].elementNum.toString()); + expect(modelInputs2[0].elementNum.toString()).assertEqual("16384"); + console.log(modelInputs2[0].dtype.toString()); + expect(modelInputs2[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs2[0].format.toString()); + expect(modelInputs2[0].format.toString()).assertEqual("1"); + console.log(modelInputs2[0].dataSize.toString()); + expect(modelInputs2[0].dataSize.toString()).assertEqual("65536"); + modelInputs2[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs2).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + // 正常场景:ModelResize,shape与之前不一致 + it('Test_load_model_param_model_path_resize_002',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_resize_002"); + let inputName = 'ml_ocr_cn_0.input'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_ocr_cn.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + mindSporeLite.loadModelFromFile(model_file).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + console.log(modelInputs[0].name); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].shape.toString()).assertEqual("1,32,512,1"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("16384"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].dataSize.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("65536"); + console.log('=========MSLITE resize start=====') + let new_dim = new Array([1,64,256,1]); + let resize_result = msliteModel.resize(modelInputs, new_dim); + expect(resize_result).assertTrue() + console.log('=========MSLITE resize success=====') + const modelInputs2 = msliteModel.getInputs(); + console.log(modelInputs2[0].name); + expect(modelInputs2[0].name.toString()).assertEqual("data"); + console.log(modelInputs2[0].shape.toString()); + expect(modelInputs2[0].shape.toString()).assertEqual("1,64,256,1"); + console.log(modelInputs2[0].elementNum.toString()); + expect(modelInputs2[0].elementNum.toString()).assertEqual("16384"); + console.log(modelInputs2[0].dtype.toString()); + expect(modelInputs2[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs2[0].format.toString()); + expect(modelInputs2[0].format.toString()).assertEqual("1"); + console.log(modelInputs2[0].dataSize.toString()); + expect(modelInputs2[0].dataSize.toString()).assertEqual("65536"); + modelInputs2[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs2).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + // 异常场景:ModelResize,shape为三维 + it('Test_load_model_param_model_path_resize_003',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_resize_003"); + let inputName = 'ml_ocr_cn_0.input'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_ocr_cn.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + mindSporeLite.loadModelFromFile(model_file).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + console.log(modelInputs[0].name); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].shape.toString()).assertEqual("1,32,512,1"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("16384"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].dataSize.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("65536"); + console.log('=========MSLITE resize start=====') + let new_dim = new Array([1,32,1]); + let resize_result = msliteModel.resize(modelInputs, new_dim); + expect(resize_result).assertFalse; + console.log('=========MSLITE resize failed====='); + done(); + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + + // 异常场景:ModelResize,不支持resize的模型 + it('Test_load_model_param_model_path_resize_004',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_resize_004"); + let inputName = 'ml_face_isface_0.input'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + mindSporeLite.loadModelFromFile(model_file).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + console.log(modelInputs[0].name); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].shape.toString()).assertEqual("1,48,48,3"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6912"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].dataSize.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("27648"); + console.log('=========MSLITE resize start=====') + let new_dim = new Array([1,96,96,1]); + let resize_result = msliteModel.resize(modelInputs, new_dim); + expect(resize_result).assertFalse() + console.log('=========MSLITE resize failed=====') + const modelInputs2 = msliteModel.getInputs(); + console.log(modelInputs2[0].name); + expect(modelInputs2[0].name.toString()).assertEqual("data"); + console.log(modelInputs2[0].shape.toString()); + expect(modelInputs2[0].shape.toString()).assertEqual("1,48,48,3"); + console.log(modelInputs2[0].elementNum.toString()); + expect(modelInputs2[0].elementNum.toString()).assertEqual("6912"); + console.log(modelInputs2[0].dtype.toString()); + expect(modelInputs2[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs2[0].format.toString()); + expect(modelInputs2[0].format.toString()).assertEqual("1"); + console.log(modelInputs2[0].dataSize.toString()); + expect(modelInputs2[0].dataSize.toString()).assertEqual("27648"); + modelInputs2[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs2).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + // 异常场景:ModelResize,shape值有负数 + it('Test_load_model_param_model_path_resize_005',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_resize_005"); + let inputName = 'ml_ocr_cn_0.input'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_ocr_cn.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + mindSporeLite.loadModelFromFile(model_file).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + console.log(modelInputs[0].name); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].shape.toString()).assertEqual("1,32,512,1"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("16384"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].dataSize.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("65536"); + console.log('=========MSLITE resize start=====') + let new_dim = new Array([1,-32,32,1]); + let resize_result = msliteModel.resize(modelInputs, new_dim); + expect(resize_result).assertFalse() + console.log('=========MSLITE resize success=====') + const modelInputs2 = msliteModel.getInputs(); + console.log(modelInputs2[0].name); + expect(modelInputs2[0].name.toString()).assertEqual("data"); + console.log(modelInputs2[0].shape.toString()); + expect(modelInputs2[0].shape.toString()).assertEqual("1,32,512,1"); + console.log(modelInputs2[0].elementNum.toString()); + expect(modelInputs2[0].elementNum.toString()).assertEqual("16384"); + console.log(modelInputs2[0].dtype.toString()); + expect(modelInputs2[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs2[0].format.toString()); + expect(modelInputs2[0].format.toString()).assertEqual("1"); + console.log(modelInputs2[0].dataSize.toString()); + expect(modelInputs2[0].dataSize.toString()).assertEqual("65536"); + modelInputs2[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs2).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + // 正常场景:Build一次,Predict多次 + it('Test_load_model_param_model_path_much_predict_001',0, async function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_much_predict_001"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + let buffer = await syscontext.resourceManager.getRawFileContent(inputName) + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + let msliteModel = await mindSporeLite.loadModelFromFile(model_file) + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].name); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + console.log(modelInputs[0].dataSize.toString()); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + let num = 0; + for (var i = 0; i < 10; i++) { + console.log(i.toString()); + let modelOutputs = await msliteModel.predict(modelInputs); + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + console.log(output0.length.toString()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var z = 0; z < 2; z++) { + console.log(output0[z].toString()); + expect(output0[z].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + console.log('=========i.toString()====='); + console.log(i.toString()); + ++num; + console.log('=========num.toString()====='); + console.log(num.toString()); + if (num==10) { + done(); + } + } + }) + + // 异常场景:Build多次 + it('Test_load_model_param_model_path_much_build_001',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_much_build_001"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + for (var i = 0; i < 10; i++) { + mindSporeLite.loadModelFromFile(model_file) + } + mindSporeLite.loadModelFromFile(model_file).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].name); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + console.log(modelInputs[0].dataSize.toString()); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + // 正常场景:单输入模型 + it('Test_load_model_param_model_path_model_001',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_model_001"); + let modelName = 'ml_face_isface.ms'; + let inputName = 'ml_face_isface_0.input'; + let syscontext = globalThis.context + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + syscontext.resourceManager.getRawFileContent(modelName).then((model_buffer) => { + let modelBuffer = model_buffer + mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + console.log(modelInputs[0].name); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].shape.toString()).assertEqual("1,48,48,3"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6912"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].dataSize.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("27648"); + modelInputs[0].setData(inputBuffer.buffer); + let Inputs2 = new Float32Array(modelInputs[0].getData()); + for (var i = 0; i < 5; i++) { + console.log(Inputs2[i].toString()); + + } + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + }) + + + // 正常场景:多输入模型 + it('Test_load_model_param_model_path_model_002',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_model_002"); + let modelName = 'ml_video_edit_face_cutout_portraitSeg_deconv.ms'; + let inputName01 = 'ml_video_edit_face_cutout_portraitSeg_deconv_0.input'; + let inputName02 = 'ml_video_edit_face_cutout_portraitSeg_deconv_1.input'; + let syscontext = globalThis.context + syscontext.resourceManager.getRawFileContent(inputName01).then((buffer) => { + let inputBuffer01 = buffer; + syscontext.resourceManager.getRawFileContent(inputName02).then((buffer) => { + let inputBuffer02 = buffer; + console.log('=========MSLITE success, input01 bin bytelength: ' + inputBuffer01.byteLength) + console.log('=========MSLITE success, input02 bin bytelength: ' + inputBuffer02.byteLength) + syscontext.resourceManager.getRawFileContent(modelName).then((model_buffer) => { + let modelBuffer = model_buffer + mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + console.log(modelInputs[0].name); + expect(modelInputs[0].name.toString()).assertEqual("a"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].shape.toString()).assertEqual("1,512,512,3"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("786432"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].dataSize.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("3145728"); + + console.log(modelInputs[1].name); + expect(modelInputs[1].name.toString()).assertEqual("b"); + console.log(modelInputs[1].shape.toString()); + expect(modelInputs[1].shape.toString()).assertEqual("1,512,512,1"); + console.log(modelInputs[1].elementNum.toString()); + expect(modelInputs[1].elementNum.toString()).assertEqual("262144"); + console.log(modelInputs[1].dtype.toString()); + expect(modelInputs[1].dtype.toString()).assertEqual("43"); + console.log(modelInputs[1].format.toString()); + expect(modelInputs[1].format.toString()).assertEqual("1"); + console.log(modelInputs[1].dataSize.toString()); + expect(modelInputs[1].dataSize.toString()).assertEqual("1048576"); + modelInputs[0].setData(inputBuffer01.buffer); + modelInputs[1].setData(inputBuffer02.buffer); + let Inputs2 = new Float32Array(modelInputs[0].getData()); + for (var i = 0; i < 5; i++) { + console.log(Inputs2[i].toString()); + } + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + }) + + + + // 正常场景:输入为uint8模型 + it('Test_load_model_param_model_path_model_003',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_model_003"); + let modelName = 'aiy_vision_classifier_plants_V1_3.ms'; + let inputName = 'aiy_vision_classifier_plants_V1_3_0.input'; + let syscontext = globalThis.context + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + syscontext.resourceManager.getRawFileContent(modelName).then((model_buffer) => { + let modelBuffer = model_buffer + mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + console.log(modelInputs[0].name); + expect(modelInputs[0].name.toString()).assertEqual("module/hub_input/images_uint8"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].shape.toString()).assertEqual("1,224,224,3"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("150528"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("37"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].dataSize.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("150528"); + modelInputs[0].setData(inputBuffer.buffer); + let Inputs2 = new Float32Array(modelInputs[0].getData()); + for (var i = 0; i < 5; i++) { + console.log(Inputs2[i].toString()); + } + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + }) + + + // 正常场景:多输入单输出 + it('Test_load_model_param_model_path_model_004',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_model_004"); + let modelName = 'ml_headpose_pb2tflite.ms'; + let inputName01 = 'ml_headpose_pb2tflite_0.input'; + let inputName02 = 'ml_headpose_pb2tflite_1.input'; + let inputName03 = 'ml_headpose_pb2tflite_2.input'; + let syscontext = globalThis.context + syscontext.resourceManager.getRawFileContent(inputName01).then((buffer) => { + let inputBuffer01 = buffer; + syscontext.resourceManager.getRawFileContent(inputName02).then((buffer) => { + let inputBuffer02 = buffer; + syscontext.resourceManager.getRawFileContent(inputName03).then((buffer) => { + let inputBuffer03 = buffer; + console.log('=========MSLITE success, input01 bin bytelength: ' + inputBuffer01.byteLength) + console.log('=========MSLITE success, input02 bin bytelength: ' + inputBuffer02.byteLength) + console.log('=========MSLITE success, input03 bin bytelength: ' + inputBuffer03.byteLength) + syscontext.resourceManager.getRawFileContent(modelName).then((model_buffer) => { + let modelBuffer = model_buffer + mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then((msliteModel) => { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + console.log(modelInputs[0].name); + expect(modelInputs[0].name.toString()).assertEqual("input_1"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].shape.toString()).assertEqual("1,64,64,3"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("12288"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].dataSize.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("49152"); + + console.log(modelInputs[1].name); + expect(modelInputs[1].name.toString()).assertEqual("batch_normalization_8/batchnorm/add"); + console.log(modelInputs[1].shape.toString()); + expect(modelInputs[1].shape.toString()).assertEqual("16"); + console.log(modelInputs[1].elementNum.toString()); + expect(modelInputs[1].elementNum.toString()).assertEqual("16"); + console.log(modelInputs[1].dtype.toString()); + expect(modelInputs[1].dtype.toString()).assertEqual("43"); + console.log(modelInputs[1].format.toString()); + expect(modelInputs[1].format.toString()).assertEqual("1"); + console.log(modelInputs[1].dataSize.toString()); + expect(modelInputs[1].dataSize.toString()).assertEqual("64"); + + console.log(modelInputs[2].name); + expect(modelInputs[2].name.toString()).assertEqual("batch_normalization_1/batchnorm/add"); + console.log(modelInputs[2].shape.toString()); + expect(modelInputs[2].shape.toString()).assertEqual("16"); + console.log(modelInputs[2].elementNum.toString()); + expect(modelInputs[2].elementNum.toString()).assertEqual("16"); + console.log(modelInputs[2].dtype.toString()); + expect(modelInputs[2].dtype.toString()).assertEqual("43"); + console.log(modelInputs[2].format.toString()); + expect(modelInputs[2].format.toString()).assertEqual("1"); + console.log(modelInputs[2].dataSize.toString()); + expect(modelInputs[2].dataSize.toString()).assertEqual("64"); + modelInputs[0].setData(inputBuffer01.buffer); + modelInputs[1].setData(inputBuffer02.buffer); + modelInputs[2].setData(inputBuffer03.buffer); + let Inputs2 = new Float32Array(modelInputs[0].getData()); + for (var i = 0; i < 5; i++) { + console.log(Inputs2[i].toString()); + } + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs).then((modelOutputs) => { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + }).catch(err => { + console.log("predict catch: ", err); + done(); + }) + }).catch(err => { + console.log("loadModel catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + }) + + + // 正常场景:调用loadModelFromFile callback接口设置context + it('Test_load_model_param_model_path_callback',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_callback"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + let context:mindSporeLite.Context={}; + context.target = ["cpu"]; + context.cpu = { + "threadNum": 4, + } + context.cpu.threadAffinityMode = 1; + context.cpu.precisionMode = "preferred_fp16"; + context.cpu.threadAffinityCoreList = [0, 1, 2, 3]; + console.log('=========MSLITE loadModel start====='); + + mindSporeLite.loadModelFromFile(model_file, context, (msliteModel) => { + try { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + console.log(modelInputs[0].name); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].dataSize.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs, (modelOutputs) => { + try { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + } catch (error) { + console.info("predict catch: " + error); + done(); + } + }) + } catch (error) { + console.info("loadModel catch: " + error); + done(); + } + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + // 正常场景:调用loadModelFromBuffer callback接口设置context + it('Test_load_model_param_model_buffer_callback',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_buffer_callback"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let modelName = 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + syscontext.resourceManager.getRawFileContent(modelName).then((model_buffer) => { + let modelBuffer = model_buffer + let context:mindSporeLite.Context={}; + context.target = ["cpu"]; + context.cpu = { + "threadNum": 4, + } + context.cpu.threadAffinityMode = 1; + context.cpu.precisionMode = "preferred_fp16"; + context.cpu.threadAffinityCoreList = [0, 1, 2, 3]; + console.log('=========MSLITE loadModel start====='); + + mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, context, (msliteModel) => { + try { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + console.log(modelInputs[0].name); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].dataSize.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs, (modelOutputs) => { + try { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + } catch (error) { + console.info("predict catch: " + error); + done(); + } + }) + } catch (error) { + console.info("loadModel catch: " + error); + done(); + } + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + // 正常场景:调用loadModelFromFd callback接口设置context + it('Test_load_model_param_model_fd_callback',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_fd_callback"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY); + let context:mindSporeLite.Context={}; + context.target = ["cpu"]; + context.cpu = { + "threadNum": 4, + } + context.cpu.threadAffinityMode = 1; + context.cpu.precisionMode = "preferred_fp16"; + context.cpu.threadAffinityCoreList = [0, 1, 2, 3]; + console.log('=========MSLITE loadModel start====='); + + mindSporeLite.loadModelFromFd(file.fd, context, (msliteModel) => { + try { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + console.log(modelInputs[0].name); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].dataSize.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs, (modelOutputs) => { + try { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + } catch (error) { + console.info("predict catch: " + error); + done(); + } + }) + } catch (error) { + console.info("loadModel catch: " + error); + done(); + } + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + // 正常场景:调用loadModelFromFile callback接口未设置context + it('Test_load_model_param_model_path_callback_no_context',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_callback_no_context"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + console.log('=========MSLITE loadModel start====='); + + mindSporeLite.loadModelFromFile(model_file, (msliteModel) => { + try { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + console.log(modelInputs[0].name); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].dataSize.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs, (modelOutputs) => { + try { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + } catch (error) { + console.info("predict catch: " + error); + done(); + } + }) + } catch (error) { + console.info("loadModel catch: " + error); + done(); + } + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + // 正常场景:调用loadModelFromBuffer callback接口未设置context + it('Test_load_model_param_model_buffer_callback_no_context',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_buffer_callback_no_context"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let modelName = 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + syscontext.resourceManager.getRawFileContent(modelName).then((model_buffer) => { + let modelBuffer = model_buffer + console.log('=========MSLITE loadModel start====='); + mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, (msliteModel) => { + try { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + console.log(modelInputs[0].name); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].dataSize.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs, (modelOutputs) => { + try { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + } catch (error) { + console.info("predict catch: " + error); + done(); + } + }) + } catch (error) { + console.info("loadModel catch: " + error); + done(); + } + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + + + // 正常场景:调用loadModelFromFd callback接口未设置context + it('Test_load_model_param_model_fd_callback_no_context',0, function (done) { + console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_fd_callback_no_context"); + let inputName = 'mnet_caffemodel_nhwc.bin'; + let syscontext = globalThis.context + let model_file = globalThis.abilityContext.filesDir + '/' + 'mnet.caffemodel.ms'; + syscontext.resourceManager.getRawFileContent(inputName).then((buffer) => { + let inputBuffer = buffer; + console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength) + let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY); + console.log('=========MSLITE loadModel start====='); + mindSporeLite.loadModelFromFd(file.fd, (msliteModel) => { + try { + expect(msliteModel !== null).assertTrue(); + console.log('=========MSLITE loadModel end====='); + const modelInputs = msliteModel.getInputs(); + console.log(modelInputs[0].name); + expect(modelInputs[0].name.toString()).assertEqual("data"); + console.log(modelInputs[0].shape.toString()); + expect(modelInputs[0].shape.toString()).assertEqual("1,1024,1980,3"); + console.log(modelInputs[0].elementNum.toString()); + expect(modelInputs[0].elementNum.toString()).assertEqual("6082560"); + console.log(modelInputs[0].dtype.toString()); + expect(modelInputs[0].dtype.toString()).assertEqual("43"); + console.log(modelInputs[0].format.toString()); + expect(modelInputs[0].format.toString()).assertEqual("1"); + console.log(modelInputs[0].dataSize.toString()); + expect(modelInputs[0].dataSize.toString()).assertEqual("24330240"); + modelInputs[0].setData(inputBuffer.buffer); + console.log('=========MSLITE predict start====='); + msliteModel.predict(modelInputs, (modelOutputs) => { + try { + expect(modelOutputs !== null).assertTrue(); + console.log('=========MSLITE new Float32Array start====='); + let output0 = new Float32Array(modelOutputs[0].getData()); + expect(output0.length).assertLarger(0); + console.log('output0.length:' + output0.length); + for (var i = 0; i < 2; i++) { + console.log(output0[i].toString()); + expect(output0[i].toString() !== null).assertTrue(); + } + console.log('=========MSLITE new Float32Array end====='); + done(); + } catch (error) { + console.info("predict catch: " + error); + done(); + } + }) + } catch (error) { + console.info("loadModel catch: " + error); + done(); + } + }) + }).catch(err => { + console.log("getRawFileContent catch: ", err); + done(); + }) + }) + }) +} diff --git a/ai/mindspore/mindsporejstest/src/main/ets/test/List.test.ets b/ai/mindspore/mindsporejstest/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..529ac5901b5d822aed8c94fb69a9af817f23136e --- /dev/null +++ b/ai/mindspore/mindsporejstest/src/main/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2023 Huawei Device 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. + */ +import abilityTest from './Ability.test' + +export default function testsuite() { + abilityTest() +} diff --git a/ai/mindspore/mindsporejstest/src/main/module.json b/ai/mindspore/mindsporejstest/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..9a87b3ea20ff1b353dabe948f62dbd5b8b166f7c --- /dev/null +++ b/ai/mindspore/mindsporejstest/src/main/module.json @@ -0,0 +1,37 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": true, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/TestAbility/TestAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/ai/mindspore/mindsporejstest/src/main/resources/base/element/color.json b/ai/mindspore/mindsporejstest/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..afc173f8d5dcad83cc9d106e56fae9b79f74a29e --- /dev/null +++ b/ai/mindspore/mindsporejstest/src/main/resources/base/element/color.json @@ -0,0 +1,12 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "text_font_color", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ai/mindspore/mindsporejstest/src/main/resources/base/element/float.json b/ai/mindspore/mindsporejstest/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..100b7eef36cf0796e1fe69b7261b58d5cb415d10 --- /dev/null +++ b/ai/mindspore/mindsporejstest/src/main/resources/base/element/float.json @@ -0,0 +1,24 @@ +{ + "float": [ + { + "name": "title_immersive_font_size", + "value": "19fp" + }, + { + "name": "detail_immersive_font_size", + "value": "16fp" + }, + { + "name": "detail_immersive_margin_top", + "value": "6vp" + }, + { + "name": "detail_immersive_opacity", + "value": "0.66" + }, + { + "name": "column_padding", + "value": "12vp" + } + ] +} \ No newline at end of file diff --git a/ai/mindspore/mindsporejstest/src/main/resources/base/element/string.json b/ai/mindspore/mindsporejstest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e1cef378668a9a73e081f960f687ccf5b0f2e86d --- /dev/null +++ b/ai/mindspore/mindsporejstest/src/main/resources/base/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "EntryFormAbility_desc", + "value": "form_description" + }, + { + "name": "EntryFormAbility_label", + "value": "form_label" + }, + { + "name": "title_immersive", + "value": "Today's delicious food" + }, + { + "name": "detail_immersive", + "value": "A bowl of fragrant fried noodles, back to childhood memories" + } + ] +} \ No newline at end of file diff --git a/ai/mindspore/mindsporejstest/src/main/resources/base/media/ic_widget.png b/ai/mindspore/mindsporejstest/src/main/resources/base/media/ic_widget.png new file mode 100644 index 0000000000000000000000000000000000000000..c13bb4d340435b2e8d8fd90660ffc9916e1f6d68 Binary files /dev/null and b/ai/mindspore/mindsporejstest/src/main/resources/base/media/ic_widget.png differ diff --git a/ai/mindspore/mindsporejstest/src/main/resources/base/media/icon.png b/ai/mindspore/mindsporejstest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ai/mindspore/mindsporejstest/src/main/resources/base/media/icon.png differ diff --git a/ai/mindspore/mindsporejstest/src/main/resources/base/profile/form_config.json b/ai/mindspore/mindsporejstest/src/main/resources/base/profile/form_config.json new file mode 100644 index 0000000000000000000000000000000000000000..3752f88eef81460d104096f4e924207b4de38c14 --- /dev/null +++ b/ai/mindspore/mindsporejstest/src/main/resources/base/profile/form_config.json @@ -0,0 +1,23 @@ +{ + "forms": [ + { + "name": "widget", + "description": "This is a service widget.", + "src": "./ets/widget/pages/WidgetCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": true, + "updateEnabled": false, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + } + ] +} \ No newline at end of file diff --git a/ai/mindspore/mindsporejstest/src/main/resources/base/profile/main_pages.json b/ai/mindspore/mindsporejstest/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..77e90731b5a38d861663029b483df3d3ac9ec74b --- /dev/null +++ b/ai/mindspore/mindsporejstest/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "TestAbility/pages/Index" + ] +} diff --git a/ai/mindspore/mindsporejstest/src/main/resources/en_US/element/string.json b/ai/mindspore/mindsporejstest/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e1cef378668a9a73e081f960f687ccf5b0f2e86d --- /dev/null +++ b/ai/mindspore/mindsporejstest/src/main/resources/en_US/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "EntryFormAbility_desc", + "value": "form_description" + }, + { + "name": "EntryFormAbility_label", + "value": "form_label" + }, + { + "name": "title_immersive", + "value": "Today's delicious food" + }, + { + "name": "detail_immersive", + "value": "A bowl of fragrant fried noodles, back to childhood memories" + } + ] +} \ No newline at end of file diff --git a/ai/mindspore/mindsporejstest/src/main/resources/rawfile/aiy_vision_classifier_plants_V1_3.ms b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/aiy_vision_classifier_plants_V1_3.ms new file mode 100644 index 0000000000000000000000000000000000000000..a9942da07c2bc85dc39dd3d39c3f63c6c900b026 Binary files /dev/null and b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/aiy_vision_classifier_plants_V1_3.ms differ diff --git a/ai/mindspore/mindsporejstest/src/main/resources/rawfile/aiy_vision_classifier_plants_V1_3_0.input b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/aiy_vision_classifier_plants_V1_3_0.input new file mode 100644 index 0000000000000000000000000000000000000000..0d1a14831d740674712d2b4fecec491539391fd6 Binary files /dev/null and b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/aiy_vision_classifier_plants_V1_3_0.input differ diff --git a/ai/mindspore/mindsporejstest/src/main/resources/rawfile/cat.jpg b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/cat.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c8ce2c0e0be97ce20f1fd0f616e453e4a23fe57a Binary files /dev/null and b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/cat.jpg differ diff --git a/ai/mindspore/mindsporejstest/src/main/resources/rawfile/lenet_tod_infer.ms b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/lenet_tod_infer.ms new file mode 100644 index 0000000000000000000000000000000000000000..5fa71c3a7a44eb96f03f37bd55a613bc22cd1448 Binary files /dev/null and b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/lenet_tod_infer.ms differ diff --git a/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_face_isface.ms b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_face_isface.ms new file mode 100644 index 0000000000000000000000000000000000000000..10d1604774c8cd7ede6ea4c2ecf850de544563a0 Binary files /dev/null and b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_face_isface.ms differ diff --git a/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_face_isface_0.input b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_face_isface_0.input new file mode 100644 index 0000000000000000000000000000000000000000..2fd5bc3c13d662689d39f69559ce897875123572 Binary files /dev/null and b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_face_isface_0.input differ diff --git a/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_headpose_pb2tflite.ms b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_headpose_pb2tflite.ms new file mode 100644 index 0000000000000000000000000000000000000000..59e88aa5f27f6d3d649ba2b8ff7293f7c230d296 Binary files /dev/null and b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_headpose_pb2tflite.ms differ diff --git a/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_headpose_pb2tflite_0.input b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_headpose_pb2tflite_0.input new file mode 100644 index 0000000000000000000000000000000000000000..7901c1e7324237b186d81a5303ac2c46a07235b5 Binary files /dev/null and b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_headpose_pb2tflite_0.input differ diff --git a/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_headpose_pb2tflite_1.input b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_headpose_pb2tflite_1.input new file mode 100644 index 0000000000000000000000000000000000000000..48e4eb07b6ce348f662fd36f2644d15880cc9606 --- /dev/null +++ b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_headpose_pb2tflite_1.input @@ -0,0 +1,2 @@ +a->\l?&=hOO?M?>ҞE>ӥ>}=e +?0<ܔ<r?r=>= \ No newline at end of file diff --git a/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_headpose_pb2tflite_2.input b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_headpose_pb2tflite_2.input new file mode 100644 index 0000000000000000000000000000000000000000..264c3f579f81a0f67877f180c35f5afc3b8b04b2 Binary files /dev/null and b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_headpose_pb2tflite_2.input differ diff --git a/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_ocr_cn.ms b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_ocr_cn.ms new file mode 100644 index 0000000000000000000000000000000000000000..9922c5d03aacc6b02234d8ebdac41eb3a26fa069 Binary files /dev/null and b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_ocr_cn.ms differ diff --git a/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_ocr_cn_0.input b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_ocr_cn_0.input new file mode 100644 index 0000000000000000000000000000000000000000..f6e3b35ff5daefb541e46bb9ee88db0e224bc529 Binary files /dev/null and b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_ocr_cn_0.input differ diff --git a/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_video_edit_face_cutout_portraitSeg_deconv.ms b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_video_edit_face_cutout_portraitSeg_deconv.ms new file mode 100644 index 0000000000000000000000000000000000000000..1b23cfd68940dc030302e9ce59abb33c0da9aca8 Binary files /dev/null and b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_video_edit_face_cutout_portraitSeg_deconv.ms differ diff --git a/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_video_edit_face_cutout_portraitSeg_deconv_0.input b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_video_edit_face_cutout_portraitSeg_deconv_0.input new file mode 100644 index 0000000000000000000000000000000000000000..58867a8bc6140fc47044c083c30859b7fdcea365 Binary files /dev/null and b/ai/mindspore/mindsporejstest/src/main/resources/rawfile/ml_video_edit_face_cutout_portraitSeg_deconv_0.input differ