Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
9b7678a4
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
9b7678a4
编写于
7月 21, 2023
作者:
O
openharmony_ci
提交者:
Gitee
7月 21, 2023
浏览文件
操作
浏览文件
下载
差异文件
!9407 fixing bugs
Merge pull request !9407 from nierong/master
上级
7e8ec6ab
0c1985c8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
559 addition
and
650 deletion
+559
-650
ai/mindspore/mindsporejstest/src/main/ets/test/Ability.test.ets
...dspore/mindsporejstest/src/main/ets/test/Ability.test.ets
+559
-647
ai/mindspore/mindsporejstest/src/main/resources/rawfile/mnet.caffemodel.ms
...sporejstest/src/main/resources/rawfile/mnet.caffemodel.ms
+0
-0
ai/mindspore/mindsporejstest/src/main/resources/rawfile/mnet_caffemodel_480_720.ms
...est/src/main/resources/rawfile/mnet_caffemodel_480_720.ms
+0
-0
ai/mindspore/mindsporejstest/src/main/resources/rawfile/mnet_caffemodel_nhwc.bin
...stest/src/main/resources/rawfile/mnet_caffemodel_nhwc.bin
+0
-3
未找到文件。
ai/mindspore/mindsporejstest/src/main/ets/test/Ability.test.ets
浏览文件 @
9b7678a4
...
...
@@ -23,35 +23,34 @@ export default function abilityTest() {
beforeAll(function () {
let dir = globalThis.abilityContext.filesDir + "/";
try {
let m
net_caffemodel_model_file = dir + "mnet.caffemodel
.ms";
globalThis.context.resourceManager.getRawFileContent("m
net.caffemodel
.ms", (error, model_buffer) => {
let m
l_face_model_file = dir + "ml_face_isface
.ms";
globalThis.context.resourceManager.getRawFileContent("m
l_face_isface
.ms", (error, model_buffer) => {
if (error != null) {
//getRawFileDescriptor运行失败
console.log(
"[rawfile_copy_to_sandbox] m
net.caffemodel
.ms is copy " +
"[rawfile_copy_to_sandbox] m
l_face_isface
.ms is copy " +
"failed:${error.code}, message: ${error.message}.");
} else {
//getRawFileDescriptor运行成功
let file = fs.openSync(m
net_caffemodel
_model_file, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
let file = fs.openSync(m
l_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] m
net.caffemodel
.ms is copy success");
console.log("[rawfile_copy_to_sandbox] m
l_face_isface
.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) => {
let mnet_caffemodel_bin_file = dir + "ml_face_isface_0.input";
globalThis.context.resourceManager.getRawFileContent("ml_face_isface_0.input", (error, model_buffer) => {
if (error != null) {
//getRawFileDescriptor运行失败
console.log(
"[rawfile_copy_to_sandbox] m
net_caffemodel_nhwc.bin
is copy " +
"[rawfile_copy_to_sandbox] m
l_face_isface_0.input
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] m
net_caffemodel_nhwc.bin
is copy success");
console.log("[rawfile_copy_to_sandbox] m
l_face_isface_0.input
is copy success");
}
});
...
...
@@ -70,23 +69,7 @@ export default function abilityTest() {
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);
}
...
...
@@ -95,29 +78,31 @@ export default function abilityTest() {
// 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 () {
beforeEach(
async
function () {
let dir = globalThis.abilityContext.filesDir + "/";
let mnet_caffemodel_model_file = dir + "mnet.caffemodel.ms";
fs.access(mnet_caffemodel_model_file).then((res) => {
let ml_face_model = dir + "ml_face_isface.ms";
await fs.access(ml_face_model).then(async (res) => {
if (res) {
console.info("m
net.caffemodel
.ms file exists");
console.info("m
l_face_isface
.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);
console.info("ml_face_isface.ms file does not exists! access failed with error message: " +
err.message + ", error code: " + err.code);
});
let mnet_caffemodel_bin_file = dir + "m
net_caffemodel_nhwc.bin
";
fs.access(mnet_caffemodel_bin_file).then(
(res) => {
let mnet_caffemodel_bin_file = dir + "m
l_face_isface_0.input
";
await fs.access(mnet_caffemodel_bin_file).then(async
(res) => {
if (res) {
console.info("m
net_caffemodel_nhwc.bin
file exists");
console.info("m
l_face_isface_0.input
file exists");
}
}).catch((err) => {
console.info("m
net_caffemodel_nhwc.bin
file does not exist! access failed with error message: " +
console.info("m
l_face_isface_0.input
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) => {
await fs.access(ml_ocr_model).then(async
(res) => {
if (res) {
console.info("ml_ocr_cn.ms file exists");
}
...
...
@@ -126,15 +111,7 @@ export default function abilityTest() {
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**.
...
...
@@ -150,49 +127,49 @@ export default function abilityTest() {
// This API supports only one parameter: clear action function.
})
// 正常场景:ModelBuild,调用buffer方法,正常推理
it('Test_load_model_param_model_buffer',
0, function (done
) {
it('Test_load_model_param_model_buffer',
0, async function (
) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_buffer");
let modelName = 'm
net.caffemodel
.ms';
let inputName = 'm
net_caffemodel_nhwc.bin
';
let modelName = 'm
l_face_isface
.ms';
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(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 success, input bin bytelength: ' + inputBuffer.byteLength)
;
await syscontext.resourceManager.getRawFileContent(modelName).then(async
(model_buffer) => {
let modelBuffer = model_buffer
;
let context: mindSporeLite.Context = {};
context.target = ["cpu", "nnrt"];
context.nnrt = {};
context.cpu = {};
context.cpu.threadNum = 1
context.cpu.threadNum = 1
;
context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.BIG_CORES_FIRST;
context.cpu.precisionMode = "preferred_fp16";
context.cpu.threadAffinityCoreList = [0, 1, 2, 3];
mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, context).then(
(msliteModel) => {
await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, context).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48,3")
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -202,18 +179,14 @@ export default function abilityTest() {
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();
})
})
})
...
...
@@ -221,41 +194,41 @@ export default function abilityTest() {
// 正常场景:ModelBuild,调用fd方法,正常推理
it('Test_load_model_param_model_fd', 0,
function (done
) {
it('Test_load_model_param_model_fd', 0,
async function (
) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_fd");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
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) => {
await mindSporeLite.loadModelFromFd(file.fd).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48,3")
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -265,65 +238,61 @@ export default function abilityTest() {
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
) {
it('Test_load_model_param_model_path',
0, async function (
) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
;
let context:mindSporeLite.Context={};
context.target = ["cpu", "nnrt"];
context.nnrt = {};
context.cpu = {};
context.cpu.threadNum = 1
context.cpu.threadNum = 1
;
context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.BIG_CORES_FIRST;
context.cpu.precisionMode = "preferred_fp16";
context.cpu.threadAffinityCoreList = [0, 1, 2, 3];
console.log('=========MSLITE loadModel start=====');
mindSporeLite.loadModelFromFile(model_file, context).then(
(msliteModel) => {
await mindSporeLite.loadModelFromFile(model_file, context).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48,3")
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -334,61 +303,57 @@ export default function abilityTest() {
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
) {
it('Test_load_model_param_model_path_settings_threads_001',
0, async function (
) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_threads_001");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
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) => {
await mindSporeLite.loadModelFromFile(model_file, context).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48,3")
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -399,61 +364,57 @@ export default function abilityTest() {
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
) {
it('Test_load_model_param_model_path_settings_threads_002',
0, async function (
) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_threads_002");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
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) => {
await mindSporeLite.loadModelFromFile(model_file, context).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48,3")
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -464,28 +425,24 @@ export default function abilityTest() {
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
) {
it('Test_load_model_param_model_path_settings_threads_003',
0, async function (
) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_threads_003");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
let context:mindSporeLite.Context={};
...
...
@@ -493,31 +450,31 @@ export default function abilityTest() {
context.cpu = {
"threadNum": 1,
}
mindSporeLite.loadModelFromFile(model_file, context).then(
(msliteModel) => {
await mindSporeLite.loadModelFromFile(model_file, context).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980
,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48
,3");
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -528,61 +485,57 @@ export default function abilityTest() {
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
) {
it('Test_load_model_param_model_path_settings_threads_004',
0, async function (
) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_threads_004");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
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) => {
await mindSporeLite.loadModelFromFile(model_file, context).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48,3")
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -593,61 +546,57 @@ export default function abilityTest() {
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
) {
it('Test_load_model_param_model_path_settings_affinity_001',
0, async function (
) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_affinity_001");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
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) => {
await mindSporeLite.loadModelFromFile(model_file, context).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980,3");
;
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48,3")
;
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -658,61 +607,57 @@ export default function abilityTest() {
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
) {
it('Test_load_model_param_model_path_settings_affinity_002',
0, async function (
) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_affinity_002");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
;
let context:mindSporeLite.Context={};
context.target = ["cpu"];
context.cpu={};
context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.LITTLE_CORES_FIRST;
console.log("MSLITE api test: set threadAffinityMode=2.");
mindSporeLite.loadModelFromFile(model_file, context).then(
(msliteModel) => {
await mindSporeLite.loadModelFromFile(model_file, context).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980
,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48
,3");
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -723,29 +668,25 @@ export default function abilityTest() {
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
) {
it('Test_load_model_param_model_path_settings_affinity_003',
0, async function (
) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_affinity_003");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
let context:mindSporeLite.Context={};
...
...
@@ -753,31 +694,31 @@ export default function abilityTest() {
context.cpu={};
context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.BIG_CORES_FIRST;
console.log("MSLITE api test: set threadAffinityMode=1.");
mindSporeLite.loadModelFromFile(model_file, context).then(
(msliteModel) => {
await mindSporeLite.loadModelFromFile(model_file, context).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48,3")
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -788,60 +729,56 @@ export default function abilityTest() {
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
) {
it('Test_load_model_param_model_path_settings_affinity_004',
0, async function (
) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_affinity_004");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
;
let context:mindSporeLite.Context={};
context.target = ["cpu"];
context.cpu={};
context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.NO_AFFINITIES;
console.log("MSLITE api test: set threadAffinityMode=0.");
mindSporeLite.loadModelFromFile(model_file, context).then(
(msliteModel) => {
await mindSporeLite.loadModelFromFile(model_file, context).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48,3")
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -852,62 +789,58 @@ export default function abilityTest() {
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
) {
it('Test_load_model_param_model_path_settings_affinity_list_001',
0, async function (
) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_settings_affinity_list_001");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
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) => {
await mindSporeLite.loadModelFromFile(model_file, context).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48,3")
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -918,18 +851,14 @@ export default function abilityTest() {
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();
})
})
...
...
@@ -939,10 +868,10 @@ export default function abilityTest() {
let model_file = "";
let context:mindSporeLite.Context={};
context.target = ["cpu"];
let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context)
let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context)
;
console.log('=========MSLITE loadModel end=====');
expect(msliteModel).assertUndefined()
done()
expect(msliteModel).assertUndefined()
;
done()
;
})
...
...
@@ -951,82 +880,82 @@ export default function abilityTest() {
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)
let msliteModel = await mindSporeLite.loadModelFromBuffer(null, context)
;
console.log('=========MSLITE loadModel end=====');
expect(msliteModel).assertUndefined()
done()
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 + '/' + 'm
net.caffemodel
.ms';
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
let context:mindSporeLite.Context=null;
let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context)
expect(msliteModel).assertUndefined()
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
) {
it('Test_load_model_param_model_path_resize_001',
0, async function (
) {
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 syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_ocr_cn.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
mindSporeLite.loadModelFromFile(model_file).then(
(msliteModel) => {
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
;
await mindSporeLite.loadModelFromFile(model_file).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,32,512,1");
let input_elementNum = modelInputs[0].elementNum
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("16384");
let input_dtype = modelInputs[0].dtype
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("65536");
console.log('=========MSLITE resize start=====')
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=====')
expect(resize_result).assertTrue()
;
console.log('=========MSLITE resize success=====')
;
const modelInputs2 = msliteModel.getInputs();
let input_name2 = modelInputs2[0].name
let input_name2 = modelInputs2[0].name
;
console.log(input_name2.toString());
expect(input_name2.toString()).assertEqual("data");
let input_shape2 = modelInputs2[0].shape
let input_shape2 = modelInputs2[0].shape
;
console.log(input_shape2.toString());
expect(input_shape2.toString()).assertEqual("1,32,512,1");
let input_elementNum2 = modelInputs2[0].elementNum
let input_elementNum2 = modelInputs2[0].elementNum
;
console.log(input_elementNum2.toString());
expect(input_elementNum2.toString()).assertEqual("16384");
let input_dtype2 = modelInputs2[0].dtype
let input_dtype2 = modelInputs2[0].dtype
;
console.log(input_dtype2.toString());
expect(input_dtype2).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format2 = modelInputs2[0].format
let input_format2 = modelInputs2[0].format
;
console.log(input_format2.toString());
expect(input_format2).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize2 = modelInputs2[0].dataSize
let input_dataSize2 = modelInputs2[0].dataSize
;
console.log(input_dataSize2.toString());
expect(input_dataSize2.toString()).assertEqual("65536");
modelInputs2[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs2).then((modelOutputs) => {
await
msliteModel.predict(modelInputs2).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -1037,80 +966,76 @@ export default function abilityTest() {
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
) {
it('Test_load_model_param_model_path_resize_002',
0, async function (
) {
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 syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_ocr_cn.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
mindSporeLite.loadModelFromFile(model_file).then(
(msliteModel) => {
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
;
await mindSporeLite.loadModelFromFile(model_file).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,32,512,1");
let input_elementNum = modelInputs[0].elementNum
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("16384");
let input_dtype = modelInputs[0].dtype
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("65536");
console.log('=========MSLITE resize start=====')
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=====')
expect(resize_result).assertTrue()
;
console.log('=========MSLITE resize success=====')
;
const modelInputs2 = msliteModel.getInputs();
let input_name2 = modelInputs2[0].name
let input_name2 = modelInputs2[0].name
;
console.log(input_name2.toString());
expect(input_name2.toString()).assertEqual("data");
let input_shape2 = modelInputs2[0].shape
let input_shape2 = modelInputs2[0].shape
;
console.log(input_shape2.toString());
expect(input_shape2.toString()).assertEqual("1,64,256,1");
let input_elementNum2 = modelInputs2[0].elementNum
let input_elementNum2 = modelInputs2[0].elementNum
;
console.log(input_elementNum2.toString());
expect(input_elementNum2.toString()).assertEqual("16384");
let input_dtype2 = modelInputs2[0].dtype
let input_dtype2 = modelInputs2[0].dtype
;
console.log(input_dtype2.toString());
expect(input_dtype2).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format2 = modelInputs2[0].format
let input_format2 = modelInputs2[0].format
;
console.log(input_format2.toString());
expect(input_format2).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize2 = modelInputs2[0].dataSize
let input_dataSize2 = modelInputs2[0].dataSize
;
console.log(input_dataSize2.toString());
expect(input_dataSize2.toString()).assertEqual("65536");
modelInputs2[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs2).then((modelOutputs) => {
await
msliteModel.predict(modelInputs2).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -1121,261 +1046,253 @@ export default function abilityTest() {
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
) {
it('Test_load_model_param_model_path_resize_003',
0, async function (
) {
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 syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_ocr_cn.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
mindSporeLite.loadModelFromFile(model_file).then(
(msliteModel) => {
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
;
await mindSporeLite.loadModelFromFile(model_file).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,32,512,1");
let input_elementNum = modelInputs[0].elementNum
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("16384");
let input_dtype = modelInputs[0].dtype
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("65536");
console.log('=========MSLITE resize start=====')
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
) {
it('Test_load_model_param_model_path_resize_004',
0, async function (
) {
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 syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
mindSporeLite.loadModelFromFile(model_file).then(
(msliteModel) => {
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
;
await mindSporeLite.loadModelFromFile(model_file).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_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");
let input_dtype = modelInputs[0].dtype
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("27648");
console.log('=========MSLITE resize start=====')
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=====')
done();
expect(resize_result).assertFalse();
console.log('=========MSLITE resize failed=====');
}).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
) {
it('Test_load_model_param_model_path_resize_005',
0, async function (
) {
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 syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_ocr_cn.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
mindSporeLite.loadModelFromFile(model_file).then(
(msliteModel) => {
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
;
await mindSporeLite.loadModelFromFile(model_file).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,32,512,1");
let input_elementNum = modelInputs[0].elementNum
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("16384");
let input_dtype = modelInputs[0].dtype
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("65536");
console.log('=========MSLITE resize start=====')
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 failed=====')
done();
expect(resize_result).assertFalse();
console.log('=========MSLITE resize failed=====');
}).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
) {
it('Test_load_model_param_model_path_much_predict_001',0, async function () {
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();
let input_name = modelInputs[0].name
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,1024,1980,3");
let input_elementNum = modelInputs[0].elementNum
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6082560");
let input_dtype = modelInputs[0].dtype
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("24330240");
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();
}
}
let inputName = 'ml_face_isface_0.input';
let syscontext = globalThis.context;
let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
await mindSporeLite.loadModelFromFile(model_file).then(async (msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,48,48,3");
let input_elementNum = modelInputs[0].elementNum;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6912");
let input_dtype = modelInputs[0].dtype;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("27648");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
let num = 0;
for (var i = 0; i < 10; i++) {
await 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=====');
}).catch(err => {
console.log("predict catch: ", err);
})
console.log('=========MSLITE new Float32Array end=====');
console.log('=========i.toString()=====');
console.log(i.toString());
++num;
console.log('=========num.toString()=====');
console.log(num.toString());
}
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
})
// 异常场景:Build多次
it('Test_load_model_param_model_path_much_build_001',
0, function (done
) {
it('Test_load_model_param_model_path_much_build_001',
0, async function (
) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_much_build_001");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
;
for (var i = 0; i < 10; i++) {
mindSporeLite.loadModelFromFile(model_file)
mindSporeLite.loadModelFromFile(model_file)
;
}
mindSporeLite.loadModelFromFile(model_file).then(
(msliteModel) => {
await mindSporeLite.loadModelFromFile(model_file).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980
,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48
,3");
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -1386,51 +1303,47 @@ export default function abilityTest() {
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
) {
it('Test_load_model_param_model_path_model_001',
0, async function (
) {
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 syscontext = globalThis.context
;
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(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) => {
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
;
await syscontext.resourceManager.getRawFileContent(modelName).then(async
(model_buffer) => {
let modelBuffer = model_buffer
;
await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_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");
let input_dtype = modelInputs[0].dtype
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("27648");
modelInputs[0].setData(inputBuffer.buffer);
...
...
@@ -1440,7 +1353,7 @@ export default function abilityTest() {
}
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -1450,39 +1363,35 @@ export default function abilityTest() {
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
) {
it('Test_load_model_param_model_path_model_002',
0, async function (
) {
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 syscontext = globalThis.context
;
await syscontext.resourceManager.getRawFileContent(inputName01).then(async
(buffer) => {
let inputBuffer01 = buffer;
syscontext.resourceManager.getRawFileContent(inputName02).then(
(buffer) => {
await syscontext.resourceManager.getRawFileContent(inputName02).then(async
(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) => {
console.log('=========MSLITE success, input01 bin bytelength: ' + inputBuffer01.byteLength)
;
console.log('=========MSLITE success, input02 bin bytelength: ' + inputBuffer02.byteLength)
;
await syscontext.resourceManager.getRawFileContent(modelName).then(async
(model_buffer) => {
let modelBuffer = model_buffer
;
await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
...
...
@@ -1492,13 +1401,13 @@ export default function abilityTest() {
expect(modelInputs[0].shape.toString()).assertEqual("1,512,512,3");
console.log(modelInputs[0].elementNum.toString());
expect(modelInputs[0].elementNum.toString()).assertEqual("786432");
let input_dtype = modelInputs[0].dtype
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("3145728");
...
...
@@ -1521,7 +1430,7 @@ export default function abilityTest() {
console.log(Inputs2[i].toString());
}
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -1531,22 +1440,17 @@ export default function abilityTest() {
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();
})
})
})
...
...
@@ -1554,17 +1458,17 @@ export default function abilityTest() {
// 正常场景:输入为uint8模型
it('Test_load_model_param_model_path_model_003',
0, function (done
) {
it('Test_load_model_param_model_path_model_003',
0, async function (
) {
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 syscontext = globalThis.context
;
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(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) => {
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
;
await syscontext.resourceManager.getRawFileContent(modelName).then(async
(model_buffer) => {
let modelBuffer = model_buffer
;
await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
...
...
@@ -1581,58 +1485,54 @@ export default function abilityTest() {
console.log(modelInputs[0].dataSize.toString());
expect(modelInputs[0].dataSize.toString()).assertEqual("150528");
modelInputs[0].setData(inputBuffer.buffer);
let Inputs2 = new
Float32
Array(modelInputs[0].getData());
let Inputs2 = new
Uint8
Array(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) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new
Float32
Array(modelOutputs[0].getData());
let output0 = new
Uint8
Array(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
) {
it('Test_load_model_param_model_path_model_004',
0, async function (
) {
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) => {
await syscontext.resourceManager.getRawFileContent(inputName01).then(async
(buffer) => {
let inputBuffer01 = buffer;
syscontext.resourceManager.getRawFileContent(inputName02).then(
(buffer) => {
await syscontext.resourceManager.getRawFileContent(inputName02).then(async
(buffer) => {
let inputBuffer02 = buffer;
syscontext.resourceManager.getRawFileContent(inputName03).then(
(buffer) => {
await syscontext.resourceManager.getRawFileContent(inputName03).then(async
(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) => {
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)
;
await syscontext.resourceManager.getRawFileContent(modelName).then(async
(model_buffer) => {
let modelBuffer = model_buffer
;
await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then(async
(msliteModel) => {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
...
...
@@ -1642,13 +1542,13 @@ export default function abilityTest() {
expect(modelInputs[0].shape.toString()).assertEqual("1,64,64,3");
console.log(modelInputs[0].elementNum.toString());
expect(modelInputs[0].elementNum.toString()).assertEqual("12288");
let input_dtype = modelInputs[0].dtype
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("49152");
...
...
@@ -1685,7 +1585,7 @@ export default function abilityTest() {
console.log(Inputs2[i].toString());
}
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs).then((modelOutputs) => {
await
msliteModel.predict(modelInputs).then((modelOutputs) => {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
...
...
@@ -1695,40 +1595,34 @@ export default function abilityTest() {
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) {
it('Test_load_model_param_model_path_callback',
0, async
function (done) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_callback");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
;
let context:mindSporeLite.Context={};
context.target = ["cpu"];
context.cpu = {
...
...
@@ -1744,24 +1638,24 @@ export default function abilityTest() {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980
,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48
,3");
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs, (modelOutputs) => {
...
...
@@ -1782,6 +1676,9 @@ export default function abilityTest() {
done();
}
})
for (var j = 0; j < 10000; j++){
console.log("wait predict end:" + j.toString());
}
} catch (error) {
console.info("loadModel catch: " + error);
done();
...
...
@@ -1795,16 +1692,16 @@ export default function abilityTest() {
// 正常场景:调用loadModelFromBuffer callback接口设置context
it('Test_load_model_param_model_buffer_callback',
0,
function (done) {
it('Test_load_model_param_model_buffer_callback',
0, async
function (done) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_buffer_callback");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let modelName = 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let modelName = 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(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 success, input bin bytelength: ' + inputBuffer.byteLength)
;
await syscontext.resourceManager.getRawFileContent(modelName).then(async
(model_buffer) => {
let modelBuffer = model_buffer
;
let context:mindSporeLite.Context={};
context.target = ["cpu"];
context.cpu = {
...
...
@@ -1820,24 +1717,24 @@ export default function abilityTest() {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48,3")
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs, (modelOutputs) => {
...
...
@@ -1858,6 +1755,9 @@ export default function abilityTest() {
done();
}
})
for (var j = 0; j < 10000; j++){
console.log("wait predict end:" + j.toString());
}
} catch (error) {
console.info("loadModel catch: " + error);
done();
...
...
@@ -1875,14 +1775,14 @@ export default function abilityTest() {
// 正常场景:调用loadModelFromFd callback接口设置context
it('Test_load_model_param_model_fd_callback',
0,
function (done) {
it('Test_load_model_param_model_fd_callback',
0, async
function (done) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_fd_callback");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
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"];
...
...
@@ -1899,24 +1799,24 @@ export default function abilityTest() {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48,3")
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs, (modelOutputs) => {
...
...
@@ -1937,6 +1837,9 @@ export default function abilityTest() {
done();
}
})
for (var j = 0; j < 10000; j++){
console.log("wait predict end:" + j.toString());
}
} catch (error) {
console.info("loadModel catch: " + error);
done();
...
...
@@ -1950,14 +1853,14 @@ export default function abilityTest() {
// 正常场景:调用loadModelFromFile callback接口未设置context
it('Test_load_model_param_model_path_callback_no_context',
0,
function (done) {
it('Test_load_model_param_model_path_callback_no_context',
0, async
function (done) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_callback_no_context");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
;
console.log('=========MSLITE loadModel start=====');
mindSporeLite.loadModelFromFile(model_file, (msliteModel) => {
...
...
@@ -1965,24 +1868,24 @@ export default function abilityTest() {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48,3")
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs, (modelOutputs) => {
...
...
@@ -2003,6 +1906,9 @@ export default function abilityTest() {
done();
}
})
for (var j = 0; j < 10000; j++){
console.log("wait predict end:" + j.toString());
}
} catch (error) {
console.info("loadModel catch: " + error);
done();
...
...
@@ -2016,40 +1922,40 @@ export default function abilityTest() {
// 正常场景:调用loadModelFromBuffer callback接口未设置context
it('Test_load_model_param_model_buffer_callback_no_context',
0,
function (done) {
it('Test_load_model_param_model_buffer_callback_no_context',
0, async
function (done) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_buffer_callback_no_context");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let modelName = 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let modelName = 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(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 success, input bin bytelength: ' + inputBuffer.byteLength)
;
await syscontext.resourceManager.getRawFileContent(modelName).then(async
(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();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48,3")
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs, (modelOutputs) => {
...
...
@@ -2070,6 +1976,9 @@ export default function abilityTest() {
done();
}
})
for (var j = 0; j < 10000; j++){
console.log("wait predict end:" + j.toString());
}
} catch (error) {
console.info("loadModel catch: " + error);
done();
...
...
@@ -2087,14 +1996,14 @@ export default function abilityTest() {
// 正常场景:调用loadModelFromFd callback接口未设置context
it('Test_load_model_param_model_fd_callback_no_context',
0,
function (done) {
it('Test_load_model_param_model_fd_callback_no_context',
0, async
function (done) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_fd_callback_no_context");
let inputName = 'm
net_caffemodel_nhwc.bin
';
let syscontext = globalThis.context
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
net.caffemodel
.ms';
syscontext.resourceManager.getRawFileContent(inputName).then(
(buffer) => {
let inputName = 'm
l_face_isface_0.input
';
let syscontext = globalThis.context
;
let model_file = globalThis.abilityContext.filesDir + '/' + 'm
l_face_isface
.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async
(buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength)
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) => {
...
...
@@ -2102,24 +2011,24 @@ export default function abilityTest() {
expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs();
let input_name = modelInputs[0].name
let input_name = modelInputs[0].name
;
console.log(input_name.toString());
expect(input_name.toString()).assertEqual("data");
let input_shape = modelInputs[0].shape
let input_shape = modelInputs[0].shape
;
console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,
1024,1980
,3");
let input_elementNum = modelInputs[0].elementNum
expect(input_shape.toString()).assertEqual("1,
48,48
,3");
let input_elementNum = modelInputs[0].elementNum
;
console.log(input_elementNum.toString());
expect(input_elementNum.toString()).assertEqual("6
082560
");
let input_dtype = modelInputs[0].dtype
expect(input_elementNum.toString()).assertEqual("6
912
");
let input_dtype = modelInputs[0].dtype
;
console.log(input_dtype.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_format = modelInputs[0].format
let input_format = modelInputs[0].format
;
console.log(input_format.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize
let input_dataSize = modelInputs[0].dataSize
;
console.log(input_dataSize.toString());
expect(input_dataSize.toString()).assertEqual("2
4330240
");
expect(input_dataSize.toString()).assertEqual("2
7648
");
modelInputs[0].setData(inputBuffer.buffer);
console.log('=========MSLITE predict start=====');
msliteModel.predict(modelInputs, (modelOutputs) => {
...
...
@@ -2140,6 +2049,9 @@ export default function abilityTest() {
done();
}
})
for (var j = 0; j < 10000; j++){
console.log("wait predict end:" + j.toString());
}
} catch (error) {
console.info("loadModel catch: " + error);
done();
...
...
@@ -2152,7 +2064,7 @@ export default function abilityTest() {
})
// 正常场景:头文件枚举值测试
it('Test_enumerated_value',
0,
function (done) {
it('Test_enumerated_value',
0, async
function (done) {
try{
expect(mindSporeLite.Format.NCHW).assertEqual(0);
expect(mindSporeLite.Format.NHWC).assertEqual(1);
...
...
ai/mindspore/mindsporejstest/src/main/resources/rawfile/mnet.caffemodel.ms
已删除
100644 → 0
浏览文件 @
7e8ec6ab
文件已删除
ai/mindspore/mindsporejstest/src/main/resources/rawfile/mnet_caffemodel_480_720.ms
已删除
100644 → 0
浏览文件 @
7e8ec6ab
文件已删除
ai/mindspore/mindsporejstest/src/main/resources/rawfile/mnet_caffemodel_nhwc.bin
已删除
100644 → 0
LFS
浏览文件 @
7e8ec6ab
文件已删除
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录