提交 bc3b4444 编写于 作者: P principal87

更新模型、修改Promise和Callback调用方式、处理告警

Signed-off-by: Nprincipal87 <nierong3@huawei.com>
上级 0c1985c8
...@@ -165,11 +165,12 @@ bool allclose(float *a, float *b, uint64_t count, float rtol = 1e-05, ...@@ -165,11 +165,12 @@ bool allclose(float *a, float *b, uint64_t count, float rtol = 1e-05,
if (i == count - 1) { if (i == count - 1) {
printf(" ……\n"); printf(" ……\n");
printf("\n *** Total fail_count: %u\n", fail_count); printf("\n *** Total fail_count: %u\n", fail_count);
printf("\n fabs(a[i] - b[i])/(fabs(b[i])+1) : %f\n", if (fail_count != 0) {
tol / fail_count); printf("\n fabs(a[i] - b[i])/(fabs(b[i])+1) : %f\n",
printf("\n fabs(a[i] - b[i]) : %f\n", tol1 / fail_count); tol / fail_count);
printf("\n fabs(a[i] - b[i])/fabs(b[i]) : %f\n", tol2 / fail_count); printf("\n fabs(a[i] - b[i]) : %f\n", tol1 / fail_count);
printf("\n fabs(a[i] - b[i])/fabs(b[i]) : %f\n", tol2 / fail_count);
}
c = c + count; c = c + count;
printf("\n avg : %f\n", sum / count); printf("\n avg : %f\n", sum / count);
printf("\n min : %f\n", minimum); printf("\n min : %f\n", minimum);
...@@ -254,10 +255,12 @@ bool allclose_int8(uint8_t *a, uint8_t *b, uint64_t count, float rtol = 1e-05, ...@@ -254,10 +255,12 @@ bool allclose_int8(uint8_t *a, uint8_t *b, uint64_t count, float rtol = 1e-05,
if (i == count - 1) { if (i == count - 1) {
printf(" ……\n"); printf(" ……\n");
printf("\n *** Total fail_count: %u\n", fail_count); printf("\n *** Total fail_count: %u\n", fail_count);
printf("\n fabs(a[i] - b[i])/(fabs(b[i])+1) : %f\n", if (fail_count != 0) {
tol / fail_count); printf("\n fabs(a[i] - b[i])/(fabs(b[i])+1) : %f\n",
printf("\n fabs(a[i] - b[i]) : %f\n", tol1 / fail_count); tol / fail_count);
printf("\n fabs(a[i] - b[i])/fabs(b[i]) : %f\n", tol2 / fail_count); printf("\n fabs(a[i] - b[i]) : %f\n", tol1 / fail_count);
printf("\n fabs(a[i] - b[i])/fabs(b[i]) : %f\n", tol2 / fail_count);
}
c = c + count; c = c + count;
printf("\n avg : %f\n", sum / count); printf("\n avg : %f\n", sum / count);
......
...@@ -69,7 +69,7 @@ export default function abilityTest() { ...@@ -69,7 +69,7 @@ export default function abilityTest() {
console.log("[rawfile_copy_to_sandbox] ml_ocr_cn.ms is copy success"); console.log("[rawfile_copy_to_sandbox] ml_ocr_cn.ms is copy success");
} }
}); });
} catch (error) { } catch (error) {
console.info("[rawfile_copy_to_sandbox] getRawFileDescriptor api run failed" + error); console.info("[rawfile_copy_to_sandbox] getRawFileDescriptor api run failed" + error);
} }
...@@ -80,7 +80,7 @@ export default function abilityTest() { ...@@ -80,7 +80,7 @@ export default function abilityTest() {
}) })
beforeEach(async function () { beforeEach(async function () {
let dir = globalThis.abilityContext.filesDir + "/"; let dir = globalThis.abilityContext.filesDir + "/";
let ml_face_model = dir + "ml_face_isface.ms"; let ml_face_model = dir + "ml_face_isface.ms";
await fs.access(ml_face_model).then(async (res) => { await fs.access(ml_face_model).then(async (res) => {
if (res) { if (res) {
...@@ -90,7 +90,7 @@ export default function abilityTest() { ...@@ -90,7 +90,7 @@ export default function abilityTest() {
console.info("ml_face_isface.ms file does not exists! access failed with error message: " + console.info("ml_face_isface.ms file does not exists! access failed with error message: " +
err.message + ", error code: " + err.code); err.message + ", error code: " + err.code);
}); });
let mnet_caffemodel_bin_file = dir + "ml_face_isface_0.input"; let mnet_caffemodel_bin_file = dir + "ml_face_isface_0.input";
await fs.access(mnet_caffemodel_bin_file).then(async (res) => { await fs.access(mnet_caffemodel_bin_file).then(async (res) => {
if (res) { if (res) {
...@@ -132,63 +132,53 @@ export default function abilityTest() { ...@@ -132,63 +132,53 @@ export default function abilityTest() {
let modelName = 'ml_face_isface.ms'; let modelName = 'ml_face_isface.ms';
let inputName = 'ml_face_isface_0.input'; let inputName = 'ml_face_isface_0.input';
let syscontext = globalThis.context let syscontext = globalThis.context
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
let inputBuffer = buffer; console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); let modelBuffer = await syscontext.resourceManager.getRawFileContent(modelName);
await syscontext.resourceManager.getRawFileContent(modelName).then(async (model_buffer) => { let context: mindSporeLite.Context = {};
let modelBuffer = model_buffer; context.target = ["cpu", "nnrt"];
let context: mindSporeLite.Context = {}; context.nnrt = {};
context.target = ["cpu", "nnrt"]; context.cpu = {};
context.nnrt = {}; context.cpu.threadNum = 1;
context.cpu = {}; context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.BIG_CORES_FIRST;
context.cpu.threadNum = 1; context.cpu.precisionMode = "preferred_fp16";
context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.BIG_CORES_FIRST; context.cpu.threadAffinityCoreList = [0, 1, 2, 3];
context.cpu.precisionMode = "preferred_fp16"; let msliteModel = await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, context)
context.cpu.threadAffinityCoreList = [0, 1, 2, 3]; expect(msliteModel !== null).assertTrue();
await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, context).then(async (msliteModel) => { console.log('=========MSLITE loadModel end=====');
expect(msliteModel !== null).assertTrue(); const modelInputs = msliteModel.getInputs();
console.log('=========MSLITE loadModel end====='); let input_name = modelInputs[0].name;
const modelInputs = msliteModel.getInputs(); console.log(input_name.toString());
let input_name = modelInputs[0].name; expect(input_name.toString()).assertEqual("data");
console.log(input_name.toString()); let input_shape = modelInputs[0].shape;
expect(input_name.toString()).assertEqual("data"); console.log(input_shape.toString());
let input_shape = modelInputs[0].shape; expect(input_shape.toString()).assertEqual("1,48,48,3")
console.log(input_shape.toString()); let input_elementNum = modelInputs[0].elementNum;
expect(input_shape.toString()).assertEqual("1,48,48,3") console.log(input_elementNum.toString());
let input_elementNum = modelInputs[0].elementNum; expect(input_elementNum.toString()).assertEqual("6912");
console.log(input_elementNum.toString()); let input_dtype = modelInputs[0].dtype;
expect(input_elementNum.toString()).assertEqual("6912"); console.log(input_dtype.toString());
let input_dtype = modelInputs[0].dtype; expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
console.log(input_dtype.toString()); let input_format = modelInputs[0].format;
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32); console.log(input_format.toString());
let input_format = modelInputs[0].format; expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
console.log(input_format.toString()); let input_dataSize = modelInputs[0].dataSize;
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); console.log(input_dataSize.toString());
let input_dataSize = modelInputs[0].dataSize; expect(input_dataSize.toString()).assertEqual("27648");
console.log(input_dataSize.toString()); modelInputs[0].setData(inputBuffer.buffer);
expect(input_dataSize.toString()).assertEqual("27648"); console.log('=========MSLITE predict start=====');
modelInputs[0].setData(inputBuffer.buffer); let modelOutputs = await msliteModel.predict(modelInputs);
console.log('=========MSLITE predict start====='); expect(modelOutputs !== null).assertTrue();
await msliteModel.predict(modelInputs).then((modelOutputs) => { console.log('=========MSLITE new Float32Array start=====');
expect(modelOutputs !== null).assertTrue(); let output0 = new Float32Array(modelOutputs[0].getData());
console.log('=========MSLITE new Float32Array start====='); console.log('output0.length:' + output0.length);
let output0 = new Float32Array(modelOutputs[0].getData()); for (var i = 0; i < 2; i++) {
console.log('output0.length:' + output0.length); console.log(output0[i].toString());
for (var i = 0; i < 2; i++) { expect(output0[i].toString() !== null).assertTrue();
console.log(output0[i].toString()); }
expect(output0[i].toString() !== null).assertTrue(); const modelInputs0 = msliteModel.getInputs();
} console.log(modelInputs0[0].name.toString());
console.log('=========MSLITE new Float32Array end====='); console.log('=========MSLITE new Float32Array end=====');
}).catch(err => {
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
})
}) })
...@@ -199,55 +189,46 @@ export default function abilityTest() { ...@@ -199,55 +189,46 @@ export default function abilityTest() {
let inputName = 'ml_face_isface_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
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=====');
console.log('=========MSLITE loadModel start====='); let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY);
let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY); let msliteModel = await mindSporeLite.loadModelFromFd(file.fd);
await mindSporeLite.loadModelFromFd(file.fd).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,48,48,3");
expect(input_shape.toString()).assertEqual("1,48,48,3") let input_elementNum = modelInputs[0].elementNum;
let input_elementNum = modelInputs[0].elementNum; console.log(input_elementNum.toString());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("6912");
expect(input_elementNum.toString()).assertEqual("6912"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("27648");
expect(input_dataSize.toString()).assertEqual("27648"); modelInputs[0].setData(inputBuffer.buffer);
modelInputs[0].setData(inputBuffer.buffer); console.log('=========MSLITE predict start=====');
console.log('=========MSLITE predict start====='); let modelOutputs = await msliteModel.predict(modelInputs);
await msliteModel.predict(modelInputs).then((modelOutputs) => { expect(modelOutputs !== null).assertTrue();
expect(modelOutputs !== null).assertTrue(); console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE new Float32Array start====='); let output0 = new Float32Array(modelOutputs[0].getData());
let output0 = new Float32Array(modelOutputs[0].getData()); console.log('output0.length:' + output0.length);
console.log('output0.length:' + output0.length); for (var i = 0; i < 2; i++) {
for (var i = 0; i < 2; i++) { console.log(output0[i].toString());
console.log(output0[i].toString()); expect(output0[i].toString() !== null).assertTrue();
expect(output0[i].toString() !== null).assertTrue(); }
} const modelInputs0 = msliteModel.getInputs();
console.log('=========MSLITE new Float32Array end====='); console.log(modelInputs0[0].name.toString());
}).catch(err => { console.log('=========MSLITE new Float32Array end=====');
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
// 正常场景:ModelBuild,调用loadModelFromFile方法,正常推理 // 正常场景:ModelBuild,调用loadModelFromFile方法,正常推理
...@@ -256,62 +237,54 @@ export default function abilityTest() { ...@@ -256,62 +237,54 @@ export default function abilityTest() {
let inputName = 'ml_face_isface_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
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={};
let context:mindSporeLite.Context={}; context.target = ["cpu", "nnrt"];
context.target = ["cpu", "nnrt"]; context.nnrt = {};
context.nnrt = {}; context.cpu = {};
context.cpu = {}; context.cpu.threadNum = 1;
context.cpu.threadNum = 1; context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.BIG_CORES_FIRST;
context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.BIG_CORES_FIRST; context.cpu.precisionMode = "preferred_fp16";
context.cpu.precisionMode = "preferred_fp16"; context.cpu.threadAffinityCoreList = [0, 1, 2, 3];
context.cpu.threadAffinityCoreList = [0, 1, 2, 3]; console.log('=========MSLITE loadModel start=====');
console.log('=========MSLITE loadModel start====='); let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,48,48,3")
expect(input_shape.toString()).assertEqual("1,48,48,3") let input_elementNum = modelInputs[0].elementNum;
let input_elementNum = modelInputs[0].elementNum; console.log(input_elementNum.toString());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("6912");
expect(input_elementNum.toString()).assertEqual("6912"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("27648");
expect(input_dataSize.toString()).assertEqual("27648"); modelInputs[0].setData(inputBuffer.buffer);
modelInputs[0].setData(inputBuffer.buffer); console.log('=========MSLITE predict start=====');
console.log('=========MSLITE predict start====='); let modelOutputs = await msliteModel.predict(modelInputs);
await msliteModel.predict(modelInputs).then((modelOutputs) => { expect(modelOutputs !== null).assertTrue();
expect(modelOutputs !== null).assertTrue(); console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE new Float32Array start====='); let output0 = new Float32Array(modelOutputs[0].getData());
let output0 = new Float32Array(modelOutputs[0].getData()); expect(output0.length).assertLarger(0);
expect(output0.length).assertLarger(0); console.log('output0.length:' + output0.length);
console.log('output0.length:' + output0.length); for (var i = 0; i < 2; i++) {
for (var i = 0; i < 2; i++) { console.log(output0[i].toString());
console.log(output0[i].toString()); expect(output0[i].toString() !== null).assertTrue();
expect(output0[i].toString() !== null).assertTrue(); }
} const modelInputs0 = msliteModel.getInputs();
console.log('=========MSLITE new Float32Array end====='); console.log(modelInputs0[0].name.toString());
}).catch(err => { console.log('=========MSLITE new Float32Array end=====');
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
...@@ -321,58 +294,50 @@ export default function abilityTest() { ...@@ -321,58 +294,50 @@ export default function abilityTest() {
let inputName = 'ml_face_isface_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
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={};
let context:mindSporeLite.Context={}; context.target = ["cpu"];
context.target = ["cpu"]; context.cpu = {
context.cpu = { "threadNum": 4,
"threadNum": 4, }
} let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,48,48,3")
expect(input_shape.toString()).assertEqual("1,48,48,3") let input_elementNum = modelInputs[0].elementNum;
let input_elementNum = modelInputs[0].elementNum; console.log(input_elementNum.toString());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("6912");
expect(input_elementNum.toString()).assertEqual("6912"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("27648");
expect(input_dataSize.toString()).assertEqual("27648"); modelInputs[0].setData(inputBuffer.buffer);
modelInputs[0].setData(inputBuffer.buffer); console.log('=========MSLITE predict start=====');
console.log('=========MSLITE predict start====='); let modelOutputs = await msliteModel.predict(modelInputs);
await msliteModel.predict(modelInputs).then((modelOutputs) => { expect(modelOutputs !== null).assertTrue();
expect(modelOutputs !== null).assertTrue(); console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE new Float32Array start====='); let output0 = new Float32Array(modelOutputs[0].getData());
let output0 = new Float32Array(modelOutputs[0].getData()); expect(output0.length).assertLarger(0);
expect(output0.length).assertLarger(0); console.log('output0.length:' + output0.length);
console.log('output0.length:' + output0.length); for (var i = 0; i < 2; i++) {
for (var i = 0; i < 2; i++) { console.log(output0[i].toString());
console.log(output0[i].toString()); expect(output0[i].toString() !== null).assertTrue();
expect(output0[i].toString() !== null).assertTrue(); }
} const modelInputs0 = msliteModel.getInputs();
console.log('=========MSLITE new Float32Array end====='); console.log(modelInputs0[0].name.toString());
}).catch(err => { console.log('=========MSLITE new Float32Array end=====');
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
...@@ -382,58 +347,50 @@ export default function abilityTest() { ...@@ -382,58 +347,50 @@ export default function abilityTest() {
let inputName = 'ml_face_isface_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
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={};
let context:mindSporeLite.Context={}; context.target = ["cpu"];
context.target = ["cpu"]; context.cpu = {
context.cpu = { "threadNum": 2,
"threadNum": 2, }
} let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,48,48,3")
expect(input_shape.toString()).assertEqual("1,48,48,3") let input_elementNum = modelInputs[0].elementNum;
let input_elementNum = modelInputs[0].elementNum; console.log(input_elementNum.toString());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("6912");
expect(input_elementNum.toString()).assertEqual("6912"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("27648");
expect(input_dataSize.toString()).assertEqual("27648"); modelInputs[0].setData(inputBuffer.buffer);
modelInputs[0].setData(inputBuffer.buffer); console.log('=========MSLITE predict start=====');
console.log('=========MSLITE predict start====='); let modelOutputs = await msliteModel.predict(modelInputs);
await msliteModel.predict(modelInputs).then((modelOutputs) => { expect(modelOutputs !== null).assertTrue();
expect(modelOutputs !== null).assertTrue(); console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE new Float32Array start====='); let output0 = new Float32Array(modelOutputs[0].getData());
let output0 = new Float32Array(modelOutputs[0].getData()); expect(output0.length).assertLarger(0);
expect(output0.length).assertLarger(0); console.log('output0.length:' + output0.length);
console.log('output0.length:' + output0.length); for (var i = 0; i < 2; i++) {
for (var i = 0; i < 2; i++) { console.log(output0[i].toString());
console.log(output0[i].toString()); expect(output0[i].toString() !== null).assertTrue();
expect(output0[i].toString() !== null).assertTrue(); }
} const modelInputs0 = msliteModel.getInputs();
console.log('=========MSLITE new Float32Array end====='); console.log(modelInputs0[0].name.toString());
}).catch(err => { console.log('=========MSLITE new Float32Array end=====');
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
//正常场景:Context设置CPU,1线程 //正常场景:Context设置CPU,1线程
...@@ -442,58 +399,50 @@ export default function abilityTest() { ...@@ -442,58 +399,50 @@ export default function abilityTest() {
let inputName = 'ml_face_isface_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
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={};
let context:mindSporeLite.Context={}; context.target = ["cpu"];
context.target = ["cpu"]; context.cpu = {
context.cpu = { "threadNum": 1,
"threadNum": 1, }
} let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,48,48,3");
expect(input_shape.toString()).assertEqual("1,48,48,3"); let input_elementNum = modelInputs[0].elementNum;
let input_elementNum = modelInputs[0].elementNum; console.log(input_elementNum.toString());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("6912");
expect(input_elementNum.toString()).assertEqual("6912"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("27648");
expect(input_dataSize.toString()).assertEqual("27648"); modelInputs[0].setData(inputBuffer.buffer);
modelInputs[0].setData(inputBuffer.buffer); console.log('=========MSLITE predict start=====');
console.log('=========MSLITE predict start====='); let modelOutputs = await msliteModel.predict(modelInputs);
await msliteModel.predict(modelInputs).then((modelOutputs) => { expect(modelOutputs !== null).assertTrue();
expect(modelOutputs !== null).assertTrue(); console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE new Float32Array start====='); let output0 = new Float32Array(modelOutputs[0].getData());
let output0 = new Float32Array(modelOutputs[0].getData()); expect(output0.length).assertLarger(0);
expect(output0.length).assertLarger(0); console.log('output0.length:' + output0.length);
console.log('output0.length:' + output0.length); for (var i = 0; i < 2; i++) {
for (var i = 0; i < 2; i++) { console.log(output0[i].toString());
console.log(output0[i].toString()); expect(output0[i].toString() !== null).assertTrue();
expect(output0[i].toString() !== null).assertTrue(); }
} const modelInputs0 = msliteModel.getInputs();
console.log('=========MSLITE new Float32Array end====='); console.log(modelInputs0[0].name.toString());
}).catch(err => { console.log('=========MSLITE new Float32Array end=====');
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
...@@ -503,58 +452,50 @@ export default function abilityTest() { ...@@ -503,58 +452,50 @@ export default function abilityTest() {
let inputName = 'ml_face_isface_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
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={};
let context:mindSporeLite.Context={}; context.target = ["cpu"];
context.target = ["cpu"]; context.cpu = {
context.cpu = { "threadNum": 0,
"threadNum": 0, }
} let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,48,48,3")
expect(input_shape.toString()).assertEqual("1,48,48,3") let input_elementNum = modelInputs[0].elementNum;
let input_elementNum = modelInputs[0].elementNum; console.log(input_elementNum.toString());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("6912");
expect(input_elementNum.toString()).assertEqual("6912"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("27648");
expect(input_dataSize.toString()).assertEqual("27648"); modelInputs[0].setData(inputBuffer.buffer);
modelInputs[0].setData(inputBuffer.buffer); console.log('=========MSLITE predict start=====');
console.log('=========MSLITE predict start====='); let modelOutputs = await msliteModel.predict(modelInputs);
await msliteModel.predict(modelInputs).then((modelOutputs) => { expect(modelOutputs !== null).assertTrue();
expect(modelOutputs !== null).assertTrue(); console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE new Float32Array start====='); let output0 = new Float32Array(modelOutputs[0].getData());
let output0 = new Float32Array(modelOutputs[0].getData()); expect(output0.length).assertLarger(0);
expect(output0.length).assertLarger(0); console.log('output0.length:' + output0.length);
console.log('output0.length:' + output0.length); for (var i = 0; i < 2; i++) {
for (var i = 0; i < 2; i++) { console.log(output0[i].toString());
console.log(output0[i].toString()); expect(output0[i].toString() !== null).assertTrue();
expect(output0[i].toString() !== null).assertTrue(); }
} const modelInputs0 = msliteModel.getInputs();
console.log('=========MSLITE new Float32Array end====='); console.log(modelInputs0[0].name.toString());
}).catch(err => { console.log('=========MSLITE new Float32Array end=====');
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
...@@ -564,58 +505,50 @@ export default function abilityTest() { ...@@ -564,58 +505,50 @@ export default function abilityTest() {
let inputName = 'ml_face_isface_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
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={};
let context:mindSporeLite.Context={}; context.target = ["cpu"];
context.target = ["cpu"]; context.cpu={};
context.cpu={}; context.cpu.threadAffinityMode = 3;
context.cpu.threadAffinityMode = 3; console.log("MSLITE api test: set threadAffinityMode=3.");
console.log("MSLITE api test: set threadAffinityMode=3."); let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,48,48,3");
expect(input_shape.toString()).assertEqual("1,48,48,3"); let input_elementNum = modelInputs[0].elementNum;
let input_elementNum = modelInputs[0].elementNum; console.log(input_elementNum.toString());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("6912");
expect(input_elementNum.toString()).assertEqual("6912"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("27648");
expect(input_dataSize.toString()).assertEqual("27648"); modelInputs[0].setData(inputBuffer.buffer);
modelInputs[0].setData(inputBuffer.buffer); console.log('=========MSLITE predict start=====');
console.log('=========MSLITE predict start====='); let modelOutputs = await msliteModel.predict(modelInputs);
await msliteModel.predict(modelInputs).then((modelOutputs) => { expect(modelOutputs !== null).assertTrue();
expect(modelOutputs !== null).assertTrue(); console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE new Float32Array start====='); let output0 = new Float32Array(modelOutputs[0].getData());
let output0 = new Float32Array(modelOutputs[0].getData()); expect(output0.length).assertLarger(0);
expect(output0.length).assertLarger(0); console.log('output0.length:' + output0.length);
console.log('output0.length:' + output0.length); for (var i = 0; i < 2; i++) {
for (var i = 0; i < 2; i++) { console.log(output0[i].toString());
console.log(output0[i].toString()); expect(output0[i].toString() !== null).assertTrue();
expect(output0[i].toString() !== null).assertTrue(); }
} const modelInputs0 = msliteModel.getInputs();
console.log('=========MSLITE new Float32Array end====='); console.log(modelInputs0[0].name.toString());
}).catch(err => { console.log('=========MSLITE new Float32Array end=====');
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
...@@ -625,58 +558,50 @@ export default function abilityTest() { ...@@ -625,58 +558,50 @@ export default function abilityTest() {
let inputName = 'ml_face_isface_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
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={};
let context:mindSporeLite.Context={}; context.target = ["cpu"];
context.target = ["cpu"]; context.cpu={};
context.cpu={}; context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.LITTLE_CORES_FIRST;
context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.LITTLE_CORES_FIRST; console.log("MSLITE api test: set threadAffinityMode=2.");
console.log("MSLITE api test: set threadAffinityMode=2."); let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,48,48,3");
expect(input_shape.toString()).assertEqual("1,48,48,3"); let input_elementNum = modelInputs[0].elementNum;
let input_elementNum = modelInputs[0].elementNum; console.log(input_elementNum.toString());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("6912");
expect(input_elementNum.toString()).assertEqual("6912"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("27648");
expect(input_dataSize.toString()).assertEqual("27648"); modelInputs[0].setData(inputBuffer.buffer);
modelInputs[0].setData(inputBuffer.buffer); console.log('=========MSLITE predict start=====');
console.log('=========MSLITE predict start====='); let modelOutputs = await msliteModel.predict(modelInputs);
await msliteModel.predict(modelInputs).then((modelOutputs) => { expect(modelOutputs !== null).assertTrue();
expect(modelOutputs !== null).assertTrue(); console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE new Float32Array start====='); let output0 = new Float32Array(modelOutputs[0].getData());
let output0 = new Float32Array(modelOutputs[0].getData()); expect(output0.length).assertLarger(0);
expect(output0.length).assertLarger(0); console.log('output0.length:' + output0.length);
console.log('output0.length:' + output0.length); for (var i = 0; i < 2; i++) {
for (var i = 0; i < 2; i++) { console.log(output0[i].toString());
console.log(output0[i].toString()); expect(output0[i].toString() !== null).assertTrue();
expect(output0[i].toString() !== null).assertTrue(); }
} const modelInputs0 = msliteModel.getInputs();
console.log('=========MSLITE new Float32Array end====='); console.log(modelInputs0[0].name.toString());
}).catch(err => { console.log('=========MSLITE new Float32Array end=====');
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
...@@ -686,58 +611,50 @@ export default function abilityTest() { ...@@ -686,58 +611,50 @@ export default function abilityTest() {
let inputName = 'ml_face_isface_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
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={};
let context:mindSporeLite.Context={}; context.target = ["cpu"];
context.target = ["cpu"]; context.cpu={};
context.cpu={}; context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.BIG_CORES_FIRST;
context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.BIG_CORES_FIRST; console.log("MSLITE api test: set threadAffinityMode=1.");
console.log("MSLITE api test: set threadAffinityMode=1."); let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,48,48,3")
expect(input_shape.toString()).assertEqual("1,48,48,3") let input_elementNum = modelInputs[0].elementNum;
let input_elementNum = modelInputs[0].elementNum; console.log(input_elementNum.toString());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("6912");
expect(input_elementNum.toString()).assertEqual("6912"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("27648");
expect(input_dataSize.toString()).assertEqual("27648"); modelInputs[0].setData(inputBuffer.buffer);
modelInputs[0].setData(inputBuffer.buffer); console.log('=========MSLITE predict start=====');
console.log('=========MSLITE predict start====='); let modelOutputs = await msliteModel.predict(modelInputs);
await msliteModel.predict(modelInputs).then((modelOutputs) => { expect(modelOutputs !== null).assertTrue();
expect(modelOutputs !== null).assertTrue(); console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE new Float32Array start====='); let output0 = new Float32Array(modelOutputs[0].getData());
let output0 = new Float32Array(modelOutputs[0].getData()); expect(output0.length).assertLarger(0);
expect(output0.length).assertLarger(0); console.log('output0.length:' + output0.length);
console.log('output0.length:' + output0.length); for (var i = 0; i < 2; i++) {
for (var i = 0; i < 2; i++) { console.log(output0[i].toString());
console.log(output0[i].toString()); expect(output0[i].toString() !== null).assertTrue();
expect(output0[i].toString() !== null).assertTrue(); }
} const modelInputs0 = msliteModel.getInputs();
console.log('=========MSLITE new Float32Array end====='); console.log(modelInputs0[0].name.toString());
}).catch(err => { console.log('=========MSLITE new Float32Array end=====');
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
//正常场景:Context设置CPU,绑核设置为0,不绑核 //正常场景:Context设置CPU,绑核设置为0,不绑核
...@@ -746,58 +663,50 @@ export default function abilityTest() { ...@@ -746,58 +663,50 @@ export default function abilityTest() {
let inputName = 'ml_face_isface_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
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={};
let context:mindSporeLite.Context={}; context.target = ["cpu"];
context.target = ["cpu"]; context.cpu={};
context.cpu={}; context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.NO_AFFINITIES;
context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.NO_AFFINITIES; console.log("MSLITE api test: set threadAffinityMode=0.");
console.log("MSLITE api test: set threadAffinityMode=0."); let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,48,48,3")
expect(input_shape.toString()).assertEqual("1,48,48,3") let input_elementNum = modelInputs[0].elementNum;
let input_elementNum = modelInputs[0].elementNum; console.log(input_elementNum.toString());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("6912");
expect(input_elementNum.toString()).assertEqual("6912"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("27648");
expect(input_dataSize.toString()).assertEqual("27648"); modelInputs[0].setData(inputBuffer.buffer);
modelInputs[0].setData(inputBuffer.buffer); console.log('=========MSLITE predict start=====');
console.log('=========MSLITE predict start====='); let modelOutputs = await msliteModel.predict(modelInputs);
await msliteModel.predict(modelInputs).then((modelOutputs) => { expect(modelOutputs !== null).assertTrue();
expect(modelOutputs !== null).assertTrue(); console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE new Float32Array start====='); let output0 = new Float32Array(modelOutputs[0].getData());
let output0 = new Float32Array(modelOutputs[0].getData()); expect(output0.length).assertLarger(0);
expect(output0.length).assertLarger(0); console.log('output0.length:' + output0.length);
console.log('output0.length:' + output0.length); for (var i = 0; i < 2; i++) {
for (var i = 0; i < 2; i++) { console.log(output0[i].toString());
console.log(output0[i].toString()); expect(output0[i].toString() !== null).assertTrue();
expect(output0[i].toString() !== null).assertTrue(); }
} const modelInputs0 = msliteModel.getInputs();
console.log('=========MSLITE new Float32Array end====='); console.log(modelInputs0[0].name.toString());
}).catch(err => { console.log('=========MSLITE new Float32Array end=====');
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
...@@ -808,58 +717,50 @@ export default function abilityTest() { ...@@ -808,58 +717,50 @@ export default function abilityTest() {
let inputName = 'ml_face_isface_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
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={};
let context:mindSporeLite.Context={}; context.target = ["cpu"];
context.target = ["cpu"]; context.cpu={};
context.cpu={}; context.cpu.threadAffinityCoreList = [0, 1, 2, 3];
context.cpu.threadAffinityCoreList = [0, 1, 2, 3]; console.log("MSLITE api test: set threadAffinityCoreList=[0, 1, 2, 3].");
console.log("MSLITE api test: set threadAffinityCoreList=[0, 1, 2, 3]."); let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,48,48,3")
expect(input_shape.toString()).assertEqual("1,48,48,3") let input_elementNum = modelInputs[0].elementNum;
let input_elementNum = modelInputs[0].elementNum; console.log(input_elementNum.toString());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("6912");
expect(input_elementNum.toString()).assertEqual("6912"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("27648");
expect(input_dataSize.toString()).assertEqual("27648"); modelInputs[0].setData(inputBuffer.buffer);
modelInputs[0].setData(inputBuffer.buffer); console.log('=========MSLITE predict start=====');
console.log('=========MSLITE predict start====='); let modelOutputs = await msliteModel.predict(modelInputs);
await msliteModel.predict(modelInputs).then((modelOutputs) => { expect(modelOutputs !== null).assertTrue();
expect(modelOutputs !== null).assertTrue(); console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE new Float32Array start====='); let output0 = new Float32Array(modelOutputs[0].getData());
let output0 = new Float32Array(modelOutputs[0].getData()); expect(output0.length).assertLarger(0);
expect(output0.length).assertLarger(0); console.log('output0.length:' + output0.length);
console.log('output0.length:' + output0.length); for (var i = 0; i < 2; i++) {
for (var i = 0; i < 2; i++) { console.log(output0[i].toString());
console.log(output0[i].toString()); expect(output0[i].toString() !== null).assertTrue();
expect(output0[i].toString() !== null).assertTrue(); }
} const modelInputs0 = msliteModel.getInputs();
console.log('=========MSLITE new Float32Array end====='); console.log(modelInputs0[0].name.toString());
}).catch(err => { console.log('=========MSLITE new Float32Array end=====');
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
//异常场景:ModelBuild,调用model path方法,path为空 //异常场景:ModelBuild,调用model path方法,path为空
...@@ -904,77 +805,69 @@ export default function abilityTest() { ...@@ -904,77 +805,69 @@ export default function abilityTest() {
let inputName = 'ml_ocr_cn_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_ocr_cn.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
let inputBuffer = buffer; console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); let msliteModel = await mindSporeLite.loadModelFromFile(model_file);
await mindSporeLite.loadModelFromFile(model_file).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,32,512,1");
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());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("16384");
expect(input_elementNum.toString()).assertEqual("16384"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("65536");
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 new_dim = new Array([1, 32, 512, 1]); let resize_result = msliteModel.resize(modelInputs, new_dim);
let resize_result = msliteModel.resize(modelInputs, new_dim); expect(resize_result).assertTrue();
expect(resize_result).assertTrue(); console.log('=========MSLITE resize success=====');
console.log('=========MSLITE resize success====='); const modelInputs2 = msliteModel.getInputs();
const modelInputs2 = msliteModel.getInputs(); let input_name2 = modelInputs2[0].name;
let input_name2 = modelInputs2[0].name; console.log(input_name2.toString());
console.log(input_name2.toString()); expect(input_name2.toString()).assertEqual("data");
expect(input_name2.toString()).assertEqual("data"); let input_shape2 = modelInputs2[0].shape;
let input_shape2 = modelInputs2[0].shape; console.log(input_shape2.toString());
console.log(input_shape2.toString()); expect(input_shape2.toString()).assertEqual("1,32,512,1");
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());
console.log(input_elementNum2.toString()); expect(input_elementNum2.toString()).assertEqual("16384");
expect(input_elementNum2.toString()).assertEqual("16384"); let input_dtype2 = modelInputs2[0].dtype;
let input_dtype2 = modelInputs2[0].dtype; console.log(input_dtype2.toString());
console.log(input_dtype2.toString()); expect(input_dtype2).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format2.toString()); expect(input_format2).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format2).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize2 = modelInputs2[0].dataSize;
let input_dataSize2 = modelInputs2[0].dataSize; console.log(input_dataSize2.toString());
console.log(input_dataSize2.toString()); expect(input_dataSize2.toString()).assertEqual("65536");
expect(input_dataSize2.toString()).assertEqual("65536"); modelInputs2[0].setData(inputBuffer.buffer);
modelInputs2[0].setData(inputBuffer.buffer); console.log('=========MSLITE predict start=====');
console.log('=========MSLITE predict start====='); let modelOutputs = await msliteModel.predict(modelInputs2);
await msliteModel.predict(modelInputs2).then((modelOutputs) => { expect(modelOutputs !== null).assertTrue();
expect(modelOutputs !== null).assertTrue(); console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE new Float32Array start====='); let output0 = new Float32Array(modelOutputs[0].getData());
let output0 = new Float32Array(modelOutputs[0].getData()); expect(output0.length).assertLarger(0);
expect(output0.length).assertLarger(0); console.log('output0.length:' + output0.length);
console.log('output0.length:' + output0.length); for (var i = 0; i < 2; i++) {
for (var i = 0; i < 2; i++) { console.log(output0[i].toString());
console.log(output0[i].toString()); expect(output0[i].toString() !== null).assertTrue();
expect(output0[i].toString() !== null).assertTrue(); }
} const modelInputs0 = msliteModel.getInputs();
console.log('=========MSLITE new Float32Array end====='); console.log(modelInputs0[0].name.toString());
}).catch(err => { console.log('=========MSLITE new Float32Array end=====');
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
...@@ -984,77 +877,69 @@ export default function abilityTest() { ...@@ -984,77 +877,69 @@ export default function abilityTest() {
let inputName = 'ml_ocr_cn_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_ocr_cn.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
let inputBuffer = buffer; console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); let msliteModel = await mindSporeLite.loadModelFromFile(model_file);
await mindSporeLite.loadModelFromFile(model_file).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,32,512,1");
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());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("16384");
expect(input_elementNum.toString()).assertEqual("16384"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("65536");
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 new_dim = new Array([1,64,256,1]); let resize_result = msliteModel.resize(modelInputs, new_dim);
let resize_result = msliteModel.resize(modelInputs, new_dim); expect(resize_result).assertTrue();
expect(resize_result).assertTrue(); console.log('=========MSLITE resize success=====');
console.log('=========MSLITE resize success====='); const modelInputs2 = msliteModel.getInputs();
const modelInputs2 = msliteModel.getInputs(); let input_name2 = modelInputs2[0].name;
let input_name2 = modelInputs2[0].name; console.log(input_name2.toString());
console.log(input_name2.toString()); expect(input_name2.toString()).assertEqual("data");
expect(input_name2.toString()).assertEqual("data"); let input_shape2 = modelInputs2[0].shape;
let input_shape2 = modelInputs2[0].shape; console.log(input_shape2.toString());
console.log(input_shape2.toString()); expect(input_shape2.toString()).assertEqual("1,64,256,1");
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());
console.log(input_elementNum2.toString()); expect(input_elementNum2.toString()).assertEqual("16384");
expect(input_elementNum2.toString()).assertEqual("16384"); let input_dtype2 = modelInputs2[0].dtype;
let input_dtype2 = modelInputs2[0].dtype; console.log(input_dtype2.toString());
console.log(input_dtype2.toString()); expect(input_dtype2).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format2.toString()); expect(input_format2).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format2).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize2 = modelInputs2[0].dataSize;
let input_dataSize2 = modelInputs2[0].dataSize; console.log(input_dataSize2.toString());
console.log(input_dataSize2.toString()); expect(input_dataSize2.toString()).assertEqual("65536");
expect(input_dataSize2.toString()).assertEqual("65536"); modelInputs2[0].setData(inputBuffer.buffer);
modelInputs2[0].setData(inputBuffer.buffer); console.log('=========MSLITE predict start=====');
console.log('=========MSLITE predict start====='); let modelOutputs = await msliteModel.predict(modelInputs2);
await msliteModel.predict(modelInputs2).then((modelOutputs) => { expect(modelOutputs !== null).assertTrue();
expect(modelOutputs !== null).assertTrue(); console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE new Float32Array start====='); let output0 = new Float32Array(modelOutputs[0].getData());
let output0 = new Float32Array(modelOutputs[0].getData()); expect(output0.length).assertLarger(0);
expect(output0.length).assertLarger(0); console.log('output0.length:' + output0.length);
console.log('output0.length:' + output0.length); for (var i = 0; i < 2; i++) {
for (var i = 0; i < 2; i++) { console.log(output0[i].toString());
console.log(output0[i].toString()); expect(output0[i].toString() !== null).assertTrue();
expect(output0[i].toString() !== null).assertTrue(); }
} const modelInputs0 = msliteModel.getInputs();
console.log('=========MSLITE new Float32Array end====='); console.log(modelInputs0[0].name.toString());
}).catch(err => { console.log('=========MSLITE new Float32Array end=====');
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
...@@ -1064,42 +949,35 @@ export default function abilityTest() { ...@@ -1064,42 +949,35 @@ export default function abilityTest() {
let inputName = 'ml_ocr_cn_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_ocr_cn.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
let inputBuffer = buffer; console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); let msliteModel = await mindSporeLite.loadModelFromFile(model_file);
await mindSporeLite.loadModelFromFile(model_file).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,32,512,1");
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());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("16384");
expect(input_elementNum.toString()).assertEqual("16384"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("65536");
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 new_dim = new Array([1,32,1]); let resize_result = msliteModel.resize(modelInputs, new_dim);
let resize_result = msliteModel.resize(modelInputs, new_dim); expect(resize_result).assertFalse;
expect(resize_result).assertFalse; console.log('=========MSLITE resize failed=====');
console.log('=========MSLITE resize failed=====');
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
...@@ -1109,40 +987,33 @@ export default function abilityTest() { ...@@ -1109,40 +987,33 @@ export default function abilityTest() {
let inputName = 'ml_face_isface_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
let inputBuffer = buffer; console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); let msliteModel = await mindSporeLite.loadModelFromFile(model_file);
await mindSporeLite.loadModelFromFile(model_file).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); console.log(modelInputs[0].shape.toString());
console.log(modelInputs[0].shape.toString()); expect(modelInputs[0].shape.toString()).assertEqual("1,48,48,3");
expect(modelInputs[0].shape.toString()).assertEqual("1,48,48,3"); console.log(modelInputs[0].elementNum.toString());
console.log(modelInputs[0].elementNum.toString()); expect(modelInputs[0].elementNum.toString()).assertEqual("6912");
expect(modelInputs[0].elementNum.toString()).assertEqual("6912"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("27648");
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 new_dim = new Array([1,96,96,1]); let resize_result = msliteModel.resize(modelInputs, new_dim);
let resize_result = msliteModel.resize(modelInputs, new_dim); expect(resize_result).assertFalse();
expect(resize_result).assertFalse(); console.log('=========MSLITE resize failed=====');
console.log('=========MSLITE resize failed=====');
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
...@@ -1152,42 +1023,35 @@ export default function abilityTest() { ...@@ -1152,42 +1023,35 @@ export default function abilityTest() {
let inputName = 'ml_ocr_cn_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_ocr_cn.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
let inputBuffer = buffer; console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); let msliteModel = await mindSporeLite.loadModelFromFile(model_file);
await mindSporeLite.loadModelFromFile(model_file).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,32,512,1");
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());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("16384");
expect(input_elementNum.toString()).assertEqual("16384"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("65536");
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 new_dim = new Array([1,-32,32,1]); let resize_result = msliteModel.resize(modelInputs, new_dim);
let resize_result = msliteModel.resize(modelInputs, new_dim); expect(resize_result).assertFalse();
expect(resize_result).assertFalse(); console.log('=========MSLITE resize failed=====');
console.log('=========MSLITE resize failed=====');
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
...@@ -1197,62 +1061,53 @@ export default function abilityTest() { ...@@ -1197,62 +1061,53 @@ export default function abilityTest() {
let inputName = 'ml_face_isface_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
let inputBuffer = buffer; console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); let msliteModel = await mindSporeLite.loadModelFromFile(model_file);
await mindSporeLite.loadModelFromFile(model_file).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,48,48,3");
expect(input_shape.toString()).assertEqual("1,48,48,3"); let input_elementNum = modelInputs[0].elementNum;
let input_elementNum = modelInputs[0].elementNum; console.log(input_elementNum.toString());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("6912");
expect(input_elementNum.toString()).assertEqual("6912"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("27648");
expect(input_dataSize.toString()).assertEqual("27648"); modelInputs[0].setData(inputBuffer.buffer);
modelInputs[0].setData(inputBuffer.buffer); console.log('=========MSLITE predict start=====');
console.log('=========MSLITE predict start====='); let num = 0;
let num = 0; for (var i = 0; i < 10; i++) {
for (var i = 0; i < 10; i++) { let modelOutputs = await msliteModel.predict(modelInputs);
await msliteModel.predict(modelInputs).then((modelOutputs) => { expect(modelOutputs !== null).assertTrue();
expect(modelOutputs !== null).assertTrue(); console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE new Float32Array start====='); let output0 = new Float32Array(modelOutputs[0].getData());
let output0 = new Float32Array(modelOutputs[0].getData()); expect(output0.length).assertLarger(0);
expect(output0.length).assertLarger(0); console.log('output0.length:' + output0.length);
console.log('output0.length:' + output0.length); for (var z = 0; z < 2; z++) {
for (var i = 0; i < 2; i++) { console.log(output0[z].toString());
console.log(output0[i].toString()); expect(output0[z].toString() !== null).assertTrue();
expect(output0[i].toString() !== null).assertTrue(); }
} const modelInputs0 = msliteModel.getInputs();
console.log('=========MSLITE new Float32Array end====='); console.log(modelInputs0[0].name.toString());
}).catch(err => { console.log('=========MSLITE new Float32Array end=====');
console.log("predict catch: ", err); console.log('=========i.toString()=====');
}) console.log(i.toString());
console.log('=========MSLITE new Float32Array end====='); ++num;
console.log('=========i.toString()====='); console.log('=========num.toString()=====');
console.log(i.toString()); console.log(num.toString());
++num; }
console.log('=========num.toString()=====');
console.log(num.toString());
}
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
...@@ -1262,56 +1117,48 @@ export default function abilityTest() { ...@@ -1262,56 +1117,48 @@ export default function abilityTest() {
let inputName = 'ml_face_isface_0.input'; 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'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
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++) {
for (var i = 0; i < 10; i++) { mindSporeLite.loadModelFromFile(model_file);
mindSporeLite.loadModelFromFile(model_file); }
} let msliteModel = await mindSporeLite.loadModelFromFile(model_file);
await mindSporeLite.loadModelFromFile(model_file).then(async (msliteModel) => { expect(msliteModel !== null).assertTrue();
expect(msliteModel !== null).assertTrue(); console.log('=========MSLITE loadModel end=====');
console.log('=========MSLITE loadModel end====='); const modelInputs = msliteModel.getInputs();
const modelInputs = msliteModel.getInputs(); let input_name = modelInputs[0].name;
let input_name = modelInputs[0].name; console.log(input_name.toString());
console.log(input_name.toString()); expect(input_name.toString()).assertEqual("data");
expect(input_name.toString()).assertEqual("data"); let input_shape = modelInputs[0].shape;
let input_shape = modelInputs[0].shape; console.log(input_shape.toString());
console.log(input_shape.toString()); expect(input_shape.toString()).assertEqual("1,48,48,3");
expect(input_shape.toString()).assertEqual("1,48,48,3"); let input_elementNum = modelInputs[0].elementNum;
let input_elementNum = modelInputs[0].elementNum; console.log(input_elementNum.toString());
console.log(input_elementNum.toString()); expect(input_elementNum.toString()).assertEqual("6912");
expect(input_elementNum.toString()).assertEqual("6912"); let input_dtype = modelInputs[0].dtype;
let input_dtype = modelInputs[0].dtype; console.log(input_dtype.toString());
console.log(input_dtype.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
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());
console.log(input_format.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); let input_dataSize = modelInputs[0].dataSize;
let input_dataSize = modelInputs[0].dataSize; console.log(input_dataSize.toString());
console.log(input_dataSize.toString()); expect(input_dataSize.toString()).assertEqual("27648");
expect(input_dataSize.toString()).assertEqual("27648"); modelInputs[0].setData(inputBuffer.buffer);
modelInputs[0].setData(inputBuffer.buffer); console.log('=========MSLITE predict start=====');
console.log('=========MSLITE predict start====='); let modelOutputs = await msliteModel.predict(modelInputs);
await msliteModel.predict(modelInputs).then((modelOutputs) => { expect(modelOutputs !== null).assertTrue();
expect(modelOutputs !== null).assertTrue(); console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE new Float32Array start====='); let output0 = new Float32Array(modelOutputs[0].getData());
let output0 = new Float32Array(modelOutputs[0].getData()); expect(output0.length).assertLarger(0);
expect(output0.length).assertLarger(0); console.log('output0.length:' + output0.length);
console.log('output0.length:' + output0.length); for (var i = 0; i < 2; i++) {
for (var i = 0; i < 2; i++) { console.log(output0[i].toString());
console.log(output0[i].toString()); expect(output0[i].toString() !== null).assertTrue();
expect(output0[i].toString() !== null).assertTrue(); }
} const modelInputs0 = msliteModel.getInputs();
console.log('=========MSLITE new Float32Array end====='); console.log(modelInputs0[0].name.toString());
}).catch(err => { console.log('=========MSLITE new Float32Array end=====');
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
...@@ -1321,58 +1168,48 @@ export default function abilityTest() { ...@@ -1321,58 +1168,48 @@ export default function abilityTest() {
let modelName = 'ml_face_isface.ms'; let modelName = 'ml_face_isface.ms';
let inputName = 'ml_face_isface_0.input'; let inputName = 'ml_face_isface_0.input';
let syscontext = globalThis.context; let syscontext = globalThis.context;
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
let inputBuffer = buffer; console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); let modelBuffer = await syscontext.resourceManager.getRawFileContent(modelName);
await syscontext.resourceManager.getRawFileContent(modelName).then(async (model_buffer) => { let msliteModel = await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer);
let modelBuffer = model_buffer; expect(msliteModel !== null).assertTrue();
await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then(async (msliteModel) => { console.log('=========MSLITE loadModel end=====');
expect(msliteModel !== null).assertTrue(); const modelInputs = msliteModel.getInputs();
console.log('=========MSLITE loadModel end====='); let input_name = modelInputs[0].name;
const modelInputs = msliteModel.getInputs(); console.log(input_name.toString());
let input_name = modelInputs[0].name; expect(input_name.toString()).assertEqual("data");
console.log(input_name.toString()); console.log(modelInputs[0].shape.toString());
expect(input_name.toString()).assertEqual("data"); expect(modelInputs[0].shape.toString()).assertEqual("1,48,48,3");
console.log(modelInputs[0].shape.toString()); console.log(modelInputs[0].elementNum.toString());
expect(modelInputs[0].shape.toString()).assertEqual("1,48,48,3"); expect(modelInputs[0].elementNum.toString()).assertEqual("6912");
console.log(modelInputs[0].elementNum.toString()); let input_dtype = modelInputs[0].dtype;
expect(modelInputs[0].elementNum.toString()).assertEqual("6912"); console.log(input_dtype.toString());
let input_dtype = modelInputs[0].dtype; expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
console.log(input_dtype.toString()); let input_format = modelInputs[0].format;
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32); console.log(input_format.toString());
let input_format = modelInputs[0].format; expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
console.log(input_format.toString()); let input_dataSize = modelInputs[0].dataSize;
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); console.log(input_dataSize.toString());
let input_dataSize = modelInputs[0].dataSize; expect(input_dataSize.toString()).assertEqual("27648");
console.log(input_dataSize.toString()); modelInputs[0].setData(inputBuffer.buffer);
expect(input_dataSize.toString()).assertEqual("27648"); let Inputs2 = new Float32Array(modelInputs[0].getData());
modelInputs[0].setData(inputBuffer.buffer); for (var i = 0; i < 5; i++) {
let Inputs2 = new Float32Array(modelInputs[0].getData()); console.log(Inputs2[i].toString());
for (var i = 0; i < 5; i++) {
console.log(Inputs2[i].toString());
} }
console.log('=========MSLITE predict start====='); console.log('=========MSLITE predict start=====');
await msliteModel.predict(modelInputs).then((modelOutputs) => { let modelOutputs = await msliteModel.predict(modelInputs);
expect(modelOutputs !== null).assertTrue(); expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start====='); console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData()); let output0 = new Float32Array(modelOutputs[0].getData());
console.log('output0.length:' + output0.length); console.log('output0.length:' + output0.length);
for (var i = 0; i < 2; i++) { for (var i = 0; i < 2; i++) {
console.log(output0[i].toString()); console.log(output0[i].toString());
expect(output0[i].toString() !== null).assertTrue(); expect(output0[i].toString() !== null).assertTrue();
} }
console.log('=========MSLITE new Float32Array end====='); const modelInputs0 = msliteModel.getInputs();
}).catch(err => { console.log(modelInputs0[0].name.toString());
console.log("predict catch: ", err); console.log('=========MSLITE new Float32Array end=====');
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
})
}) })
...@@ -1383,76 +1220,62 @@ export default function abilityTest() { ...@@ -1383,76 +1220,62 @@ export default function abilityTest() {
let inputName01 = 'ml_video_edit_face_cutout_portraitSeg_deconv_0.input'; let inputName01 = 'ml_video_edit_face_cutout_portraitSeg_deconv_0.input';
let inputName02 = 'ml_video_edit_face_cutout_portraitSeg_deconv_1.input'; let inputName02 = 'ml_video_edit_face_cutout_portraitSeg_deconv_1.input';
let syscontext = globalThis.context; let syscontext = globalThis.context;
await syscontext.resourceManager.getRawFileContent(inputName01).then(async (buffer) => { let inputBuffer01 = await syscontext.resourceManager.getRawFileContent(inputName01);
let inputBuffer01 = buffer; let inputBuffer02 = await syscontext.resourceManager.getRawFileContent(inputName02);
await syscontext.resourceManager.getRawFileContent(inputName02).then(async (buffer) => { console.log('=========MSLITE success, input01 bin bytelength: ' + inputBuffer01.byteLength);
let inputBuffer02 = buffer; console.log('=========MSLITE success, input02 bin bytelength: ' + inputBuffer02.byteLength);
console.log('=========MSLITE success, input01 bin bytelength: ' + inputBuffer01.byteLength); let modelBuffer = await syscontext.resourceManager.getRawFileContent(modelName);
console.log('=========MSLITE success, input02 bin bytelength: ' + inputBuffer02.byteLength); let msliteModel = await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer);
await syscontext.resourceManager.getRawFileContent(modelName).then(async (model_buffer) => { expect(msliteModel !== null).assertTrue();
let modelBuffer = model_buffer; console.log('=========MSLITE loadModel end=====');
await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then(async (msliteModel) => { const modelInputs = msliteModel.getInputs();
expect(msliteModel !== null).assertTrue(); console.log(modelInputs[0].name);
console.log('=========MSLITE loadModel end====='); expect(modelInputs[0].name.toString()).assertEqual("a");
const modelInputs = msliteModel.getInputs(); console.log(modelInputs[0].shape.toString());
console.log(modelInputs[0].name); expect(modelInputs[0].shape.toString()).assertEqual("1,512,512,3");
expect(modelInputs[0].name.toString()).assertEqual("a"); console.log(modelInputs[0].elementNum.toString());
console.log(modelInputs[0].shape.toString()); expect(modelInputs[0].elementNum.toString()).assertEqual("786432");
expect(modelInputs[0].shape.toString()).assertEqual("1,512,512,3"); let input_dtype = modelInputs[0].dtype;
console.log(modelInputs[0].elementNum.toString()); console.log(input_dtype.toString());
expect(modelInputs[0].elementNum.toString()).assertEqual("786432"); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_dtype = modelInputs[0].dtype; let input_format = modelInputs[0].format;
console.log(input_dtype.toString()); console.log(input_format.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_format = modelInputs[0].format; let input_dataSize = modelInputs[0].dataSize;
console.log(input_format.toString()); console.log(input_dataSize.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); expect(input_dataSize.toString()).assertEqual("3145728");
let input_dataSize = modelInputs[0].dataSize;
console.log(input_dataSize.toString()); console.log(modelInputs[1].name);
expect(input_dataSize.toString()).assertEqual("3145728"); expect(modelInputs[1].name.toString()).assertEqual("b");
console.log(modelInputs[1].shape.toString());
console.log(modelInputs[1].name); expect(modelInputs[1].shape.toString()).assertEqual("1,512,512,1");
expect(modelInputs[1].name.toString()).assertEqual("b"); console.log(modelInputs[1].elementNum.toString());
console.log(modelInputs[1].shape.toString()); expect(modelInputs[1].elementNum.toString()).assertEqual("262144");
expect(modelInputs[1].shape.toString()).assertEqual("1,512,512,1"); console.log(modelInputs[1].dtype.toString());
console.log(modelInputs[1].elementNum.toString()); expect(modelInputs[1].dtype.toString()).assertEqual("43");
expect(modelInputs[1].elementNum.toString()).assertEqual("262144"); console.log(modelInputs[1].format.toString());
console.log(modelInputs[1].dtype.toString()); expect(modelInputs[1].format.toString()).assertEqual("1");
expect(modelInputs[1].dtype.toString()).assertEqual("43"); console.log(modelInputs[1].dataSize.toString());
console.log(modelInputs[1].format.toString()); expect(modelInputs[1].dataSize.toString()).assertEqual("1048576");
expect(modelInputs[1].format.toString()).assertEqual("1"); modelInputs[0].setData(inputBuffer01.buffer);
console.log(modelInputs[1].dataSize.toString()); modelInputs[1].setData(inputBuffer02.buffer);
expect(modelInputs[1].dataSize.toString()).assertEqual("1048576"); let Inputs2 = new Float32Array(modelInputs[0].getData());
modelInputs[0].setData(inputBuffer01.buffer); for (var i = 0; i < 5; i++) {
modelInputs[1].setData(inputBuffer02.buffer); console.log(Inputs2[i].toString());
let Inputs2 = new Float32Array(modelInputs[0].getData()); }
for (var i = 0; i < 5; i++) { console.log('=========MSLITE predict start=====');
console.log(Inputs2[i].toString()); let modelOutputs = await msliteModel.predict(modelInputs);
} expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE predict start====='); console.log('=========MSLITE new Float32Array start=====');
await msliteModel.predict(modelInputs).then((modelOutputs) => { let output0 = new Float32Array(modelOutputs[0].getData());
expect(modelOutputs !== null).assertTrue(); console.log('output0.length:' + output0.length);
console.log('=========MSLITE new Float32Array start====='); for (var i = 0; i < 2; i++) {
let output0 = new Float32Array(modelOutputs[0].getData()); console.log(output0[i].toString());
console.log('output0.length:' + output0.length); expect(output0[i].toString() !== null).assertTrue();
for (var i = 0; i < 2; i++) { }
console.log(output0[i].toString()); const modelInputs0 = msliteModel.getInputs();
expect(output0[i].toString() !== null).assertTrue(); console.log(modelInputs0[0].name.toString());
} console.log('=========MSLITE new Float32Array end=====');
console.log('=========MSLITE new Float32Array end=====');
}).catch(err => {
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
})
}) })
...@@ -1463,53 +1286,43 @@ export default function abilityTest() { ...@@ -1463,53 +1286,43 @@ export default function abilityTest() {
let modelName = 'aiy_vision_classifier_plants_V1_3.ms'; let modelName = 'aiy_vision_classifier_plants_V1_3.ms';
let inputName = 'aiy_vision_classifier_plants_V1_3_0.input'; let inputName = 'aiy_vision_classifier_plants_V1_3_0.input';
let syscontext = globalThis.context; let syscontext = globalThis.context;
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
let inputBuffer = buffer; console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); let modelBuffer = await syscontext.resourceManager.getRawFileContent(modelName);
await syscontext.resourceManager.getRawFileContent(modelName).then(async (model_buffer) => { let msliteModel = await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer);
let modelBuffer = model_buffer; expect(msliteModel !== null).assertTrue();
await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then(async (msliteModel) => { console.log('=========MSLITE loadModel end=====');
expect(msliteModel !== null).assertTrue(); const modelInputs = msliteModel.getInputs();
console.log('=========MSLITE loadModel end====='); console.log(modelInputs[0].name);
const modelInputs = msliteModel.getInputs(); expect(modelInputs[0].name.toString()).assertEqual("module/hub_input/images_uint8");
console.log(modelInputs[0].name); console.log(modelInputs[0].shape.toString());
expect(modelInputs[0].name.toString()).assertEqual("module/hub_input/images_uint8"); expect(modelInputs[0].shape.toString()).assertEqual("1,224,224,3");
console.log(modelInputs[0].shape.toString()); console.log(modelInputs[0].elementNum.toString());
expect(modelInputs[0].shape.toString()).assertEqual("1,224,224,3"); expect(modelInputs[0].elementNum.toString()).assertEqual("150528");
console.log(modelInputs[0].elementNum.toString()); console.log(modelInputs[0].dtype.toString());
expect(modelInputs[0].elementNum.toString()).assertEqual("150528"); expect(modelInputs[0].dtype.toString()).assertEqual("37");
console.log(modelInputs[0].dtype.toString()); console.log(modelInputs[0].format.toString());
expect(modelInputs[0].dtype.toString()).assertEqual("37"); expect(modelInputs[0].format.toString()).assertEqual("1");
console.log(modelInputs[0].format.toString()); console.log(modelInputs[0].dataSize.toString());
expect(modelInputs[0].format.toString()).assertEqual("1"); expect(modelInputs[0].dataSize.toString()).assertEqual("150528");
console.log(modelInputs[0].dataSize.toString()); modelInputs[0].setData(inputBuffer.buffer);
expect(modelInputs[0].dataSize.toString()).assertEqual("150528"); let Inputs2 = new Uint8Array(modelInputs[0].getData());
modelInputs[0].setData(inputBuffer.buffer); for (var i = 0; i < 5; i++) {
let Inputs2 = new Uint8Array(modelInputs[0].getData()); console.log(Inputs2[i].toString());
for (var i = 0; i < 5; i++) { }
console.log(Inputs2[i].toString()); console.log('=========MSLITE predict start=====');
} let modelOutputs = await msliteModel.predict(modelInputs);
console.log('=========MSLITE predict start====='); expect(modelOutputs !== null).assertTrue();
await msliteModel.predict(modelInputs).then((modelOutputs) => { console.log('=========MSLITE new Float32Array start=====');
expect(modelOutputs !== null).assertTrue(); let output0 = new Uint8Array(modelOutputs[0].getData());
console.log('=========MSLITE new Float32Array start====='); console.log('output0.length:' + output0.length);
let output0 = new Uint8Array(modelOutputs[0].getData()); for (var i = 0; i < 2; i++) {
console.log('output0.length:' + output0.length); console.log(output0[i].toString());
for (var i = 0; i < 2; i++) { expect(output0[i].toString() !== null).assertTrue();
console.log(output0[i].toString()); }
expect(output0[i].toString() !== null).assertTrue(); const modelInputs0 = msliteModel.getInputs();
} console.log(modelInputs0[0].name.toString());
console.log('=========MSLITE new Float32Array end====='); console.log('=========MSLITE new Float32Array end=====');
}).catch(err => {
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
})
}) })
...@@ -1521,187 +1334,240 @@ export default function abilityTest() { ...@@ -1521,187 +1334,240 @@ export default function abilityTest() {
let inputName02 = 'ml_headpose_pb2tflite_1.input'; let inputName02 = 'ml_headpose_pb2tflite_1.input';
let inputName03 = 'ml_headpose_pb2tflite_2.input'; let inputName03 = 'ml_headpose_pb2tflite_2.input';
let syscontext = globalThis.context let syscontext = globalThis.context
await syscontext.resourceManager.getRawFileContent(inputName01).then(async (buffer) => { let inputBuffer01 = await syscontext.resourceManager.getRawFileContent(inputName01);
let inputBuffer01 = buffer; let inputBuffer02 = await syscontext.resourceManager.getRawFileContent(inputName02);
await syscontext.resourceManager.getRawFileContent(inputName02).then(async (buffer) => { let inputBuffer03 = await syscontext.resourceManager.getRawFileContent(inputName03);
let inputBuffer02 = buffer; console.log('=========MSLITE success, input01 bin bytelength: ' + inputBuffer01.byteLength);
await syscontext.resourceManager.getRawFileContent(inputName03).then(async (buffer) => { console.log('=========MSLITE success, input02 bin bytelength: ' + inputBuffer02.byteLength);
let inputBuffer03 = buffer; console.log('=========MSLITE success, input03 bin bytelength: ' + inputBuffer03.byteLength);
console.log('=========MSLITE success, input01 bin bytelength: ' + inputBuffer01.byteLength); let modelBuffer = await syscontext.resourceManager.getRawFileContent(modelName);
console.log('=========MSLITE success, input02 bin bytelength: ' + inputBuffer02.byteLength); let msliteModel = await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer);
console.log('=========MSLITE success, input03 bin bytelength: ' + inputBuffer03.byteLength); expect(msliteModel !== null).assertTrue();
await syscontext.resourceManager.getRawFileContent(modelName).then(async (model_buffer) => { console.log('=========MSLITE loadModel end=====');
let modelBuffer = model_buffer; const modelInputs = msliteModel.getInputs();
await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then(async (msliteModel) => { console.log(modelInputs[0].name);
expect(msliteModel !== null).assertTrue(); expect(modelInputs[0].name.toString()).assertEqual("input_1");
console.log('=========MSLITE loadModel end====='); console.log(modelInputs[0].shape.toString());
const modelInputs = msliteModel.getInputs(); expect(modelInputs[0].shape.toString()).assertEqual("1,64,64,3");
console.log(modelInputs[0].name); console.log(modelInputs[0].elementNum.toString());
expect(modelInputs[0].name.toString()).assertEqual("input_1"); expect(modelInputs[0].elementNum.toString()).assertEqual("12288");
console.log(modelInputs[0].shape.toString()); let input_dtype = modelInputs[0].dtype;
expect(modelInputs[0].shape.toString()).assertEqual("1,64,64,3"); console.log(input_dtype.toString());
console.log(modelInputs[0].elementNum.toString()); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
expect(modelInputs[0].elementNum.toString()).assertEqual("12288"); let input_format = modelInputs[0].format;
let input_dtype = modelInputs[0].dtype; console.log(input_format.toString());
console.log(input_dtype.toString()); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32); let input_dataSize = modelInputs[0].dataSize;
let input_format = modelInputs[0].format; console.log(input_dataSize.toString());
console.log(input_format.toString()); expect(input_dataSize.toString()).assertEqual("49152");
expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_dataSize = modelInputs[0].dataSize; console.log(modelInputs[1].name);
console.log(input_dataSize.toString()); expect(modelInputs[1].name.toString()).assertEqual("batch_normalization_8/batchnorm/add");
expect(input_dataSize.toString()).assertEqual("49152"); console.log(modelInputs[1].shape.toString());
expect(modelInputs[1].shape.toString()).assertEqual("16");
console.log(modelInputs[1].name); console.log(modelInputs[1].elementNum.toString());
expect(modelInputs[1].name.toString()).assertEqual("batch_normalization_8/batchnorm/add"); expect(modelInputs[1].elementNum.toString()).assertEqual("16");
console.log(modelInputs[1].shape.toString()); console.log(modelInputs[1].dtype.toString());
expect(modelInputs[1].shape.toString()).assertEqual("16"); expect(modelInputs[1].dtype.toString()).assertEqual("43");
console.log(modelInputs[1].elementNum.toString()); console.log(modelInputs[1].format.toString());
expect(modelInputs[1].elementNum.toString()).assertEqual("16"); expect(modelInputs[1].format.toString()).assertEqual("1");
console.log(modelInputs[1].dtype.toString()); console.log(modelInputs[1].dataSize.toString());
expect(modelInputs[1].dtype.toString()).assertEqual("43"); expect(modelInputs[1].dataSize.toString()).assertEqual("64");
console.log(modelInputs[1].format.toString());
expect(modelInputs[1].format.toString()).assertEqual("1"); console.log(modelInputs[2].name);
console.log(modelInputs[1].dataSize.toString()); expect(modelInputs[2].name.toString()).assertEqual("batch_normalization_1/batchnorm/add");
expect(modelInputs[1].dataSize.toString()).assertEqual("64"); console.log(modelInputs[2].shape.toString());
expect(modelInputs[2].shape.toString()).assertEqual("16");
console.log(modelInputs[2].name); console.log(modelInputs[2].elementNum.toString());
expect(modelInputs[2].name.toString()).assertEqual("batch_normalization_1/batchnorm/add"); expect(modelInputs[2].elementNum.toString()).assertEqual("16");
console.log(modelInputs[2].shape.toString()); console.log(modelInputs[2].dtype.toString());
expect(modelInputs[2].shape.toString()).assertEqual("16"); expect(modelInputs[2].dtype.toString()).assertEqual("43");
console.log(modelInputs[2].elementNum.toString()); console.log(modelInputs[2].format.toString());
expect(modelInputs[2].elementNum.toString()).assertEqual("16"); expect(modelInputs[2].format.toString()).assertEqual("1");
console.log(modelInputs[2].dtype.toString()); console.log(modelInputs[2].dataSize.toString());
expect(modelInputs[2].dtype.toString()).assertEqual("43"); expect(modelInputs[2].dataSize.toString()).assertEqual("64");
console.log(modelInputs[2].format.toString()); modelInputs[0].setData(inputBuffer01.buffer);
expect(modelInputs[2].format.toString()).assertEqual("1"); modelInputs[1].setData(inputBuffer02.buffer);
console.log(modelInputs[2].dataSize.toString()); modelInputs[2].setData(inputBuffer03.buffer);
expect(modelInputs[2].dataSize.toString()).assertEqual("64"); let Inputs2 = new Float32Array(modelInputs[0].getData());
modelInputs[0].setData(inputBuffer01.buffer); for (var i = 0; i < 5; i++) {
modelInputs[1].setData(inputBuffer02.buffer); console.log(Inputs2[i].toString());
modelInputs[2].setData(inputBuffer03.buffer); }
let Inputs2 = new Float32Array(modelInputs[0].getData()); console.log('=========MSLITE predict start=====');
for (var i = 0; i < 5; i++) { let modelOutputs = await msliteModel.predict(modelInputs);
console.log(Inputs2[i].toString()); expect(modelOutputs !== null).assertTrue();
} console.log('=========MSLITE new Float32Array start=====');
console.log('=========MSLITE predict start====='); let output0 = new Float32Array(modelOutputs[0].getData());
await msliteModel.predict(modelInputs).then((modelOutputs) => { console.log('output0.length:' + output0.length);
expect(modelOutputs !== null).assertTrue(); for (var i = 0; i < 2; i++) {
console.log('=========MSLITE new Float32Array start====='); console.log(output0[i].toString());
let output0 = new Float32Array(modelOutputs[0].getData()); expect(output0[i].toString() !== null).assertTrue();
console.log('output0.length:' + output0.length); }
for (var i = 0; i < 2; i++) { const modelInputs0 = msliteModel.getInputs();
console.log(output0[i].toString()); console.log(modelInputs0[0].name.toString());
expect(output0[i].toString() !== null).assertTrue(); console.log('=========MSLITE new Float32Array end=====');
}
console.log('=========MSLITE new Float32Array end=====');
}).catch(err => {
console.log("predict catch: ", err);
})
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
})
}) })
// 正常场景:调用loadModelFromFile callback接口设置context // 正常场景:调用loadModelFromFile callback接口设置context
it('Test_load_model_param_model_path_callback', 0, async 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"); console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_callback");
let inputName = 'ml_face_isface_0.input'; function load_model_from_file() {
let syscontext = globalThis.context; return new Promise((resolve) => {
let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms'; let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let context: mindSporeLite.Context = {};
let inputBuffer = buffer; context.target = ["cpu"];
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); context.cpu = {
let context:mindSporeLite.Context={}; "threadNum": 4,
context.target = ["cpu"];
context.cpu = {
"threadNum": 4,
}
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, (msliteModel) => {
try {
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=====');
msliteModel.predict(modelInputs, (modelOutputs) => {
try {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
expect(output0.length).assertLarger(0);
console.log('output0.length:' + output0.length);
for (var i = 0; i < 2; i++) {
console.log(output0[i].toString());
expect(output0[i].toString() !== null).assertTrue();
}
console.log('=========MSLITE new Float32Array end=====');
done();
} catch (error) {
console.info("predict catch: " + error);
done();
}
})
for (var j = 0; j < 10000; j++){
console.log("wait predict end:" + j.toString());
}
} catch (error) {
console.info("loadModel catch: " + error);
done();
} }
context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.BIG_CORES_FIRST;
context.cpu.precisionMode = "preferred_fp16";
context.cpu.threadAffinityCoreList = [0, 1, 2, 3];
mindSporeLite.loadModelFromFile(model_file, context, (msliteModel) => {
resolve(msliteModel);
})
})
}
function case_predict(msliteModel, modelInputs) {
return new Promise((resolve) => {
msliteModel.predict(modelInputs, (modelOutputs) => {
resolve(modelOutputs);
})
}) })
}).catch(err => { }
console.log("getRawFileContent catch: ", err);
done(); let inputName = 'ml_face_isface_0.input';
}) let syscontext = globalThis.context;
let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
console.log('=========MSLITE loadModel start=====');
let msliteModel = null;
msliteModel = await load_model_from_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,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 modelOutputs = await case_predict(msliteModel, modelInputs);
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();
}
const modelInputs0 = msliteModel.getInputs();
console.log(modelInputs0[0].name.toString());
console.log('=========MSLITE new Float32Array end=====');
done();
}) })
// 正常场景:调用loadModelFromBuffer callback接口设置context // 正常场景:调用loadModelFromBuffer callback接口设置context
it('Test_load_model_param_model_buffer_callback', 0, async 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"); console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_buffer_callback");
function load_model_from_buffer() {
return new Promise((resolve) => {
let modelName = 'ml_face_isface.ms';
syscontext.resourceManager.getRawFileContent(modelName).then((model_buffer) => {
let modelBuffer = model_buffer
let context: mindSporeLite.Context = {};
context.target = ["cpu"];
context.cpu = {
"threadNum": 4,
}
context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.BIG_CORES_FIRST;
context.cpu.precisionMode = "preferred_fp16";
context.cpu.threadAffinityCoreList = [0, 1, 2, 3];
mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, context, (msliteModel) => {
resolve(msliteModel);
})
})
})
}
function case_predict(msliteModel, modelInputs) {
return new Promise((resolve) => {
msliteModel.predict(modelInputs, (modelOutputs) => {
resolve(modelOutputs);
})
})
}
let inputName = 'ml_face_isface_0.input'; let inputName = 'ml_face_isface_0.input';
let syscontext = globalThis.context; let syscontext = globalThis.context;
let modelName = 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
let inputBuffer = buffer; console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
await syscontext.resourceManager.getRawFileContent(modelName).then(async (model_buffer) => { console.log('=========MSLITE loadModel start=====');
let modelBuffer = model_buffer; let msliteModel = null;
msliteModel = await load_model_from_buffer();
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 modelOutputs = await case_predict(msliteModel, modelInputs);
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();
}
const modelInputs0 = msliteModel.getInputs();
console.log(modelInputs0[0].name.toString());
console.log('=========MSLITE new Float32Array end=====');
done();
})
// 正常场景:调用loadModelFromFd callback接口设置context
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");
function load_model_from_fd() {
return new Promise((resolve) => {
let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY);
let context:mindSporeLite.Context={}; let context:mindSporeLite.Context={};
context.target = ["cpu"]; context.target = ["cpu"];
context.cpu = { context.cpu = {
...@@ -1710,357 +1576,262 @@ export default function abilityTest() { ...@@ -1710,357 +1576,262 @@ export default function abilityTest() {
context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.BIG_CORES_FIRST; context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.BIG_CORES_FIRST;
context.cpu.precisionMode = "preferred_fp16"; context.cpu.precisionMode = "preferred_fp16";
context.cpu.threadAffinityCoreList = [0, 1, 2, 3]; context.cpu.threadAffinityCoreList = [0, 1, 2, 3];
console.log('=========MSLITE loadModel start====='); mindSporeLite.loadModelFromFd(file.fd, context, (msliteModel) => {
resolve(msliteModel);
mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, context, (msliteModel) => {
try {
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=====');
msliteModel.predict(modelInputs, (modelOutputs) => {
try {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
expect(output0.length).assertLarger(0);
console.log('output0.length:' + output0.length);
for (var i = 0; i < 2; i++) {
console.log(output0[i].toString());
expect(output0[i].toString() !== null).assertTrue();
}
console.log('=========MSLITE new Float32Array end=====');
done();
} catch (error) {
console.info("predict catch: " + error);
done();
}
})
for (var j = 0; j < 10000; j++){
console.log("wait predict end:" + j.toString());
}
} catch (error) {
console.info("loadModel catch: " + error);
done();
}
}) })
}).catch(err => {
console.log("getRawFileContent catch: ", err);
done();
}) })
}).catch(err => { }
console.log("getRawFileContent catch: ", err); function case_predict(msliteModel, modelInputs) {
done(); return new Promise((resolve) => {
}) msliteModel.predict(modelInputs, (modelOutputs) => {
}) resolve(modelOutputs);
})
})
// 正常场景:调用loadModelFromFd callback接口设置context }
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 = 'ml_face_isface_0.input'; 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'; let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); console.log('=========MSLITE loadModel start=====');
let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY); let msliteModel = null;
let context:mindSporeLite.Context={}; msliteModel = await load_model_from_fd();
context.target = ["cpu"]; expect(msliteModel !== null).assertTrue();
context.cpu = { console.log('=========MSLITE loadModel end=====');
"threadNum": 4, const modelInputs = msliteModel.getInputs();
} let input_name = modelInputs[0].name;
context.cpu.threadAffinityMode = mindSporeLite.ThreadAffinityMode.BIG_CORES_FIRST; console.log(input_name.toString());
context.cpu.precisionMode = "preferred_fp16"; expect(input_name.toString()).assertEqual("data");
context.cpu.threadAffinityCoreList = [0, 1, 2, 3]; let input_shape = modelInputs[0].shape;
console.log('=========MSLITE loadModel start====='); console.log(input_shape.toString());
expect(input_shape.toString()).assertEqual("1,48,48,3")
mindSporeLite.loadModelFromFd(file.fd, context, (msliteModel) => { let input_elementNum = modelInputs[0].elementNum;
try { console.log(input_elementNum.toString());
expect(msliteModel !== null).assertTrue(); expect(input_elementNum.toString()).assertEqual("6912");
console.log('=========MSLITE loadModel end====='); let input_dtype = modelInputs[0].dtype;
const modelInputs = msliteModel.getInputs(); console.log(input_dtype.toString());
let input_name = modelInputs[0].name; expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
console.log(input_name.toString()); let input_format = modelInputs[0].format;
expect(input_name.toString()).assertEqual("data"); console.log(input_format.toString());
let input_shape = modelInputs[0].shape; expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
console.log(input_shape.toString()); let input_dataSize = modelInputs[0].dataSize;
expect(input_shape.toString()).assertEqual("1,48,48,3") console.log(input_dataSize.toString());
let input_elementNum = modelInputs[0].elementNum; expect(input_dataSize.toString()).assertEqual("27648");
console.log(input_elementNum.toString()); modelInputs[0].setData(inputBuffer.buffer);
expect(input_elementNum.toString()).assertEqual("6912"); console.log('=========MSLITE predict start=====');
let input_dtype = modelInputs[0].dtype; let modelOutputs = await case_predict(msliteModel, modelInputs);
console.log(input_dtype.toString()); expect(modelOutputs !== null).assertTrue();
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32); console.log('=========MSLITE new Float32Array start=====');
let input_format = modelInputs[0].format; let output0 = new Float32Array(modelOutputs[0].getData());
console.log(input_format.toString()); expect(output0.length).assertLarger(0);
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); console.log('output0.length:' + output0.length);
let input_dataSize = modelInputs[0].dataSize; for (var i = 0; i < 2; i++) {
console.log(input_dataSize.toString()); console.log(output0[i].toString());
expect(input_dataSize.toString()).assertEqual("27648"); expect(output0[i].toString() !== null).assertTrue();
modelInputs[0].setData(inputBuffer.buffer); }
console.log('=========MSLITE predict start====='); const modelInputs0 = msliteModel.getInputs();
msliteModel.predict(modelInputs, (modelOutputs) => { console.log(modelInputs0[0].name.toString());
try { console.log('=========MSLITE new Float32Array end=====');
expect(modelOutputs !== null).assertTrue(); done();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
expect(output0.length).assertLarger(0);
console.log('output0.length:' + output0.length);
for (var i = 0; i < 2; i++) {
console.log(output0[i].toString());
expect(output0[i].toString() !== null).assertTrue();
}
console.log('=========MSLITE new Float32Array end=====');
done();
} catch (error) {
console.info("predict catch: " + error);
done();
}
})
for (var j = 0; j < 10000; j++){
console.log("wait predict end:" + j.toString());
}
} catch (error) {
console.info("loadModel catch: " + error);
done();
}
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
done();
})
}) })
// 正常场景:调用loadModelFromFile callback接口未设置context // 正常场景:调用loadModelFromFile callback接口未设置context
it('Test_load_model_param_model_path_callback_no_context', 0, async 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"); console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_path_callback_no_context");
function load_model_from_file() {
return new Promise((resolve) => {
let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
mindSporeLite.loadModelFromFile(model_file, (msliteModel) => {
resolve(msliteModel);
})
})
}
function case_predict(msliteModel, modelInputs) {
return new Promise((resolve) => {
msliteModel.predict(modelInputs, (modelOutputs) => {
resolve(modelOutputs);
})
})
}
let inputName = 'ml_face_isface_0.input'; 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'; let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
let inputBuffer = buffer; console.log('=========MSLITE loadModel start=====');
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); let msliteModel = null;
console.log('=========MSLITE loadModel start====='); msliteModel = await load_model_from_file();
expect(msliteModel !== null).assertTrue();
mindSporeLite.loadModelFromFile(model_file, (msliteModel) => { console.log('=========MSLITE loadModel end=====');
try { const modelInputs = msliteModel.getInputs();
expect(msliteModel !== null).assertTrue(); let input_name = modelInputs[0].name;
console.log('=========MSLITE loadModel end====='); console.log(input_name.toString());
const modelInputs = msliteModel.getInputs(); expect(input_name.toString()).assertEqual("data");
let input_name = modelInputs[0].name; let input_shape = modelInputs[0].shape;
console.log(input_name.toString()); console.log(input_shape.toString());
expect(input_name.toString()).assertEqual("data"); expect(input_shape.toString()).assertEqual("1,48,48,3")
let input_shape = modelInputs[0].shape; let input_elementNum = modelInputs[0].elementNum;
console.log(input_shape.toString()); console.log(input_elementNum.toString());
expect(input_shape.toString()).assertEqual("1,48,48,3") expect(input_elementNum.toString()).assertEqual("6912");
let input_elementNum = modelInputs[0].elementNum; let input_dtype = modelInputs[0].dtype;
console.log(input_elementNum.toString()); console.log(input_dtype.toString());
expect(input_elementNum.toString()).assertEqual("6912"); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_dtype = modelInputs[0].dtype; let input_format = modelInputs[0].format;
console.log(input_dtype.toString()); console.log(input_format.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_format = modelInputs[0].format; let input_dataSize = modelInputs[0].dataSize;
console.log(input_format.toString()); console.log(input_dataSize.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); expect(input_dataSize.toString()).assertEqual("27648");
let input_dataSize = modelInputs[0].dataSize; modelInputs[0].setData(inputBuffer.buffer);
console.log(input_dataSize.toString()); console.log('=========MSLITE predict start=====');
expect(input_dataSize.toString()).assertEqual("27648"); let modelOutputs = await case_predict(msliteModel, modelInputs);
modelInputs[0].setData(inputBuffer.buffer); expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE predict start====='); console.log('=========MSLITE new Float32Array start=====');
msliteModel.predict(modelInputs, (modelOutputs) => { let output0 = new Float32Array(modelOutputs[0].getData());
try { expect(output0.length).assertLarger(0);
expect(modelOutputs !== null).assertTrue(); console.log('output0.length:' + output0.length);
console.log('=========MSLITE new Float32Array start====='); for (var i = 0; i < 2; i++) {
let output0 = new Float32Array(modelOutputs[0].getData()); console.log(output0[i].toString());
expect(output0.length).assertLarger(0); expect(output0[i].toString() !== null).assertTrue();
console.log('output0.length:' + output0.length); }
for (var i = 0; i < 2; i++) { const modelInputs0 = msliteModel.getInputs();
console.log(output0[i].toString()); console.log(modelInputs0[0].name.toString());
expect(output0[i].toString() !== null).assertTrue(); console.log('=========MSLITE new Float32Array end=====');
} done();
console.log('=========MSLITE new Float32Array end=====');
done();
} catch (error) {
console.info("predict catch: " + error);
done();
}
})
for (var j = 0; j < 10000; j++){
console.log("wait predict end:" + j.toString());
}
} catch (error) {
console.info("loadModel catch: " + error);
done();
}
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
done();
})
}) })
// 正常场景:调用loadModelFromBuffer callback接口未设置context // 正常场景:调用loadModelFromBuffer callback接口未设置context
it('Test_load_model_param_model_buffer_callback_no_context', 0, async 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"); console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_buffer_callback_no_context");
let inputName = 'ml_face_isface_0.input'; function load_model_from_buffer() {
let syscontext = globalThis.context; return new Promise((resolve) => {
let modelName = 'ml_face_isface.ms'; let modelName = 'ml_face_isface.ms';
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { syscontext.resourceManager.getRawFileContent(modelName).then((model_buffer) => {
let inputBuffer = buffer; let modelBuffer = model_buffer
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, (msliteModel) => {
await syscontext.resourceManager.getRawFileContent(modelName).then(async (model_buffer) => { resolve(msliteModel);
let modelBuffer = model_buffer; })
console.log('=========MSLITE loadModel start====='); })
mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, (msliteModel) => { })
try { }
expect(msliteModel !== null).assertTrue(); function case_predict(msliteModel, modelInputs) {
console.log('=========MSLITE loadModel end====='); return new Promise((resolve) => {
const modelInputs = msliteModel.getInputs(); msliteModel.predict(modelInputs, (modelOutputs) => {
let input_name = modelInputs[0].name; resolve(modelOutputs);
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=====');
msliteModel.predict(modelInputs, (modelOutputs) => {
try {
expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE new Float32Array start=====');
let output0 = new Float32Array(modelOutputs[0].getData());
expect(output0.length).assertLarger(0);
console.log('output0.length:' + output0.length);
for (var i = 0; i < 2; i++) {
console.log(output0[i].toString());
expect(output0[i].toString() !== null).assertTrue();
}
console.log('=========MSLITE new Float32Array end=====');
done();
} catch (error) {
console.info("predict catch: " + error);
done();
}
})
for (var j = 0; j < 10000; j++){
console.log("wait predict end:" + j.toString());
}
} catch (error) {
console.info("loadModel catch: " + error);
done();
}
}) })
}).catch(err => {
console.log("getRawFileContent catch: ", err);
done();
}) })
}).catch(err => { }
console.log("getRawFileContent catch: ", err); let inputName = 'ml_face_isface_0.input';
done(); let syscontext = globalThis.context;
}) let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
console.log('=========MSLITE loadModel start=====');
let msliteModel = null;
msliteModel = await load_model_from_buffer();
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 modelOutputs = await case_predict(msliteModel, modelInputs);
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();
}
const modelInputs0 = msliteModel.getInputs();
console.log(modelInputs0[0].name.toString());
console.log('=========MSLITE new Float32Array end=====');
done();
}) })
// 正常场景:调用loadModelFromFd callback接口未设置context // 正常场景:调用loadModelFromFd callback接口未设置context
it('Test_load_model_param_model_fd_callback_no_context', 0, async 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"); console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_fd_callback_no_context");
function load_model_from_fd() {
return new Promise((resolve) => {
let model_file = globalThis.abilityContext.filesDir + '/' + 'ml_face_isface.ms';
let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY);
mindSporeLite.loadModelFromFd(file.fd, (msliteModel) => {
resolve(msliteModel);
})
})
}
function case_predict(msliteModel, modelInputs) {
return new Promise((resolve) => {
msliteModel.predict(modelInputs, (modelOutputs) => {
resolve(modelOutputs);
})
})
}
let inputName = 'ml_face_isface_0.input'; 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'; let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
let inputBuffer = buffer; console.log('=========MSLITE loadModel start=====');
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); let msliteModel = null;
let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY); msliteModel = await load_model_from_fd();
console.log('=========MSLITE loadModel start====='); expect(msliteModel !== null).assertTrue();
mindSporeLite.loadModelFromFd(file.fd, (msliteModel) => { console.log('=========MSLITE loadModel end=====');
try { const modelInputs = msliteModel.getInputs();
expect(msliteModel !== null).assertTrue(); let input_name = modelInputs[0].name;
console.log('=========MSLITE loadModel end====='); console.log(input_name.toString());
const modelInputs = msliteModel.getInputs(); expect(input_name.toString()).assertEqual("data");
let input_name = modelInputs[0].name; let input_shape = modelInputs[0].shape;
console.log(input_name.toString()); console.log(input_shape.toString());
expect(input_name.toString()).assertEqual("data"); expect(input_shape.toString()).assertEqual("1,48,48,3");
let input_shape = modelInputs[0].shape; let input_elementNum = modelInputs[0].elementNum;
console.log(input_shape.toString()); console.log(input_elementNum.toString());
expect(input_shape.toString()).assertEqual("1,48,48,3"); expect(input_elementNum.toString()).assertEqual("6912");
let input_elementNum = modelInputs[0].elementNum; let input_dtype = modelInputs[0].dtype;
console.log(input_elementNum.toString()); console.log(input_dtype.toString());
expect(input_elementNum.toString()).assertEqual("6912"); expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32);
let input_dtype = modelInputs[0].dtype; let input_format = modelInputs[0].format;
console.log(input_dtype.toString()); console.log(input_format.toString());
expect(input_dtype).assertEqual(mindSporeLite.DataType.NUMBER_TYPE_FLOAT32); expect(input_format).assertEqual(mindSporeLite.Format.NHWC);
let input_format = modelInputs[0].format; let input_dataSize = modelInputs[0].dataSize;
console.log(input_format.toString()); console.log(input_dataSize.toString());
expect(input_format).assertEqual(mindSporeLite.Format.NHWC); expect(input_dataSize.toString()).assertEqual("27648");
let input_dataSize = modelInputs[0].dataSize; modelInputs[0].setData(inputBuffer.buffer);
console.log(input_dataSize.toString()); console.log('=========MSLITE predict start=====');
expect(input_dataSize.toString()).assertEqual("27648"); let modelOutputs = await case_predict(msliteModel, modelInputs);
modelInputs[0].setData(inputBuffer.buffer); expect(modelOutputs !== null).assertTrue();
console.log('=========MSLITE predict start====='); console.log('=========MSLITE new Float32Array start=====');
msliteModel.predict(modelInputs, (modelOutputs) => { let output0 = new Float32Array(modelOutputs[0].getData());
try { expect(output0.length).assertLarger(0);
expect(modelOutputs !== null).assertTrue(); console.log('output0.length:' + output0.length);
console.log('=========MSLITE new Float32Array start====='); for (var i = 0; i < 2; i++) {
let output0 = new Float32Array(modelOutputs[0].getData()); console.log(output0[i].toString());
expect(output0.length).assertLarger(0); expect(output0[i].toString() !== null).assertTrue();
console.log('output0.length:' + output0.length); }
for (var i = 0; i < 2; i++) { const modelInputs0 = msliteModel.getInputs();
console.log(output0[i].toString()); console.log(modelInputs0[0].name.toString());
expect(output0[i].toString() !== null).assertTrue(); console.log('=========MSLITE new Float32Array end=====');
} done();
console.log('=========MSLITE new Float32Array end=====');
done();
} catch (error) {
console.info("predict catch: " + error);
done();
}
})
for (var j = 0; j < 10000; j++){
console.log("wait predict end:" + j.toString());
}
} catch (error) {
console.info("loadModel catch: " + error);
done();
}
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
done();
})
}) })
// 正常场景:头文件枚举值测试 // 正常场景:头文件枚举值测试
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册