提交 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);
if (fail_count != 0) {
printf("\n fabs(a[i] - b[i])/(fabs(b[i])+1) : %f\n", printf("\n fabs(a[i] - b[i])/(fabs(b[i])+1) : %f\n",
tol / fail_count); tol / fail_count);
printf("\n fabs(a[i] - b[i]) : %f\n", tol1 / 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); 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);
if (fail_count != 0) {
printf("\n fabs(a[i] - b[i])/(fabs(b[i])+1) : %f\n", printf("\n fabs(a[i] - b[i])/(fabs(b[i])+1) : %f\n",
tol / fail_count); tol / fail_count);
printf("\n fabs(a[i] - b[i]) : %f\n", tol1 / 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); 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);
......
...@@ -132,11 +132,9 @@ export default function abilityTest() { ...@@ -132,11 +132,9 @@ 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);
await syscontext.resourceManager.getRawFileContent(modelName).then(async (model_buffer) => { let modelBuffer = await syscontext.resourceManager.getRawFileContent(modelName);
let modelBuffer = model_buffer;
let context: mindSporeLite.Context = {}; let context: mindSporeLite.Context = {};
context.target = ["cpu", "nnrt"]; context.target = ["cpu", "nnrt"];
context.nnrt = {}; context.nnrt = {};
...@@ -145,7 +143,7 @@ export default function abilityTest() { ...@@ -145,7 +143,7 @@ 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];
await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, context).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, context)
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();
...@@ -169,7 +167,7 @@ export default function abilityTest() { ...@@ -169,7 +167,7 @@ export default function abilityTest() {
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=====');
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());
...@@ -178,17 +176,9 @@ export default function abilityTest() { ...@@ -178,17 +176,9 @@ export default function abilityTest() {
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(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,12 +189,11 @@ export default function abilityTest() { ...@@ -199,12 +189,11 @@ 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);
await mindSporeLite.loadModelFromFd(file.fd).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFd(file.fd);
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();
...@@ -213,7 +202,7 @@ export default function abilityTest() { ...@@ -213,7 +202,7 @@ export default function abilityTest() {
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");
...@@ -228,7 +217,7 @@ export default function abilityTest() { ...@@ -228,7 +217,7 @@ export default function abilityTest() {
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=====');
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());
...@@ -237,17 +226,9 @@ export default function abilityTest() { ...@@ -237,17 +226,9 @@ export default function abilityTest() {
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(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);
})
}) })
// 正常场景:ModelBuild,调用loadModelFromFile方法,正常推理 // 正常场景:ModelBuild,调用loadModelFromFile方法,正常推理
...@@ -256,8 +237,7 @@ export default function abilityTest() { ...@@ -256,8 +237,7 @@ 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"];
...@@ -268,7 +248,7 @@ export default function abilityTest() { ...@@ -268,7 +248,7 @@ export default function abilityTest() {
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=====');
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
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();
...@@ -292,7 +272,7 @@ export default function abilityTest() { ...@@ -292,7 +272,7 @@ export default function abilityTest() {
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=====');
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());
...@@ -302,16 +282,9 @@ export default function abilityTest() { ...@@ -302,16 +282,9 @@ export default function abilityTest() {
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(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);
})
}) })
...@@ -321,15 +294,14 @@ export default function abilityTest() { ...@@ -321,15 +294,14 @@ 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,
} }
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
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();
...@@ -353,7 +325,7 @@ export default function abilityTest() { ...@@ -353,7 +325,7 @@ export default function abilityTest() {
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=====');
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());
...@@ -363,16 +335,9 @@ export default function abilityTest() { ...@@ -363,16 +335,9 @@ export default function abilityTest() {
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(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);
})
}) })
...@@ -382,15 +347,14 @@ export default function abilityTest() { ...@@ -382,15 +347,14 @@ 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,
} }
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
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();
...@@ -414,7 +378,7 @@ export default function abilityTest() { ...@@ -414,7 +378,7 @@ export default function abilityTest() {
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=====');
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());
...@@ -424,16 +388,9 @@ export default function abilityTest() { ...@@ -424,16 +388,9 @@ export default function abilityTest() {
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(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);
})
}) })
//正常场景:Context设置CPU,1线程 //正常场景:Context设置CPU,1线程
...@@ -442,15 +399,14 @@ export default function abilityTest() { ...@@ -442,15 +399,14 @@ 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,
} }
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
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();
...@@ -474,7 +430,7 @@ export default function abilityTest() { ...@@ -474,7 +430,7 @@ export default function abilityTest() {
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=====');
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());
...@@ -484,16 +440,9 @@ export default function abilityTest() { ...@@ -484,16 +440,9 @@ export default function abilityTest() {
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(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);
})
}) })
...@@ -503,15 +452,14 @@ export default function abilityTest() { ...@@ -503,15 +452,14 @@ 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,
} }
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
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();
...@@ -535,7 +483,7 @@ export default function abilityTest() { ...@@ -535,7 +483,7 @@ export default function abilityTest() {
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=====');
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());
...@@ -545,16 +493,9 @@ export default function abilityTest() { ...@@ -545,16 +493,9 @@ export default function abilityTest() {
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(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);
})
}) })
...@@ -564,15 +505,14 @@ export default function abilityTest() { ...@@ -564,15 +505,14 @@ 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.");
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
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();
...@@ -596,7 +536,7 @@ export default function abilityTest() { ...@@ -596,7 +536,7 @@ export default function abilityTest() {
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=====');
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());
...@@ -606,16 +546,9 @@ export default function abilityTest() { ...@@ -606,16 +546,9 @@ export default function abilityTest() {
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(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);
})
}) })
...@@ -625,15 +558,14 @@ export default function abilityTest() { ...@@ -625,15 +558,14 @@ 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.");
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
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();
...@@ -657,7 +589,7 @@ export default function abilityTest() { ...@@ -657,7 +589,7 @@ export default function abilityTest() {
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=====');
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());
...@@ -667,16 +599,9 @@ export default function abilityTest() { ...@@ -667,16 +599,9 @@ export default function abilityTest() {
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(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);
})
}) })
...@@ -686,15 +611,14 @@ export default function abilityTest() { ...@@ -686,15 +611,14 @@ 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.");
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
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();
...@@ -718,7 +642,7 @@ export default function abilityTest() { ...@@ -718,7 +642,7 @@ export default function abilityTest() {
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=====');
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());
...@@ -728,16 +652,9 @@ export default function abilityTest() { ...@@ -728,16 +652,9 @@ export default function abilityTest() {
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(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);
})
}) })
//正常场景:Context设置CPU,绑核设置为0,不绑核 //正常场景:Context设置CPU,绑核设置为0,不绑核
...@@ -746,15 +663,14 @@ export default function abilityTest() { ...@@ -746,15 +663,14 @@ 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.");
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
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();
...@@ -778,7 +694,7 @@ export default function abilityTest() { ...@@ -778,7 +694,7 @@ export default function abilityTest() {
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=====');
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());
...@@ -788,16 +704,9 @@ export default function abilityTest() { ...@@ -788,16 +704,9 @@ export default function abilityTest() {
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(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);
})
}) })
...@@ -808,15 +717,14 @@ export default function abilityTest() { ...@@ -808,15 +717,14 @@ 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].");
await mindSporeLite.loadModelFromFile(model_file, context).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file, context);
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();
...@@ -840,7 +748,7 @@ export default function abilityTest() { ...@@ -840,7 +748,7 @@ export default function abilityTest() {
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=====');
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());
...@@ -850,16 +758,9 @@ export default function abilityTest() { ...@@ -850,16 +758,9 @@ export default function abilityTest() {
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(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);
})
}) })
//异常场景:ModelBuild,调用model path方法,path为空 //异常场景:ModelBuild,调用model path方法,path为空
...@@ -904,10 +805,9 @@ export default function abilityTest() { ...@@ -904,10 +805,9 @@ 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);
await mindSporeLite.loadModelFromFile(model_file).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file);
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();
...@@ -955,7 +855,7 @@ export default function abilityTest() { ...@@ -955,7 +855,7 @@ export default function abilityTest() {
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=====');
await msliteModel.predict(modelInputs2).then((modelOutputs) => { let modelOutputs = await msliteModel.predict(modelInputs2);
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());
...@@ -965,16 +865,9 @@ export default function abilityTest() { ...@@ -965,16 +865,9 @@ export default function abilityTest() {
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(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);
})
}) })
...@@ -984,10 +877,9 @@ export default function abilityTest() { ...@@ -984,10 +877,9 @@ 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);
await mindSporeLite.loadModelFromFile(model_file).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file);
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();
...@@ -1035,7 +927,7 @@ export default function abilityTest() { ...@@ -1035,7 +927,7 @@ export default function abilityTest() {
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=====');
await msliteModel.predict(modelInputs2).then((modelOutputs) => { let modelOutputs = await msliteModel.predict(modelInputs2);
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());
...@@ -1045,16 +937,9 @@ export default function abilityTest() { ...@@ -1045,16 +937,9 @@ export default function abilityTest() {
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(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);
})
}) })
...@@ -1064,10 +949,9 @@ export default function abilityTest() { ...@@ -1064,10 +949,9 @@ 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);
await mindSporeLite.loadModelFromFile(model_file).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file);
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();
...@@ -1094,12 +978,6 @@ export default function abilityTest() { ...@@ -1094,12 +978,6 @@ export default function abilityTest() {
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,10 +987,9 @@ export default function abilityTest() { ...@@ -1109,10 +987,9 @@ 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);
await mindSporeLite.loadModelFromFile(model_file).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file);
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();
...@@ -1137,12 +1014,6 @@ export default function abilityTest() { ...@@ -1137,12 +1014,6 @@ export default function abilityTest() {
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,10 +1023,9 @@ export default function abilityTest() { ...@@ -1152,10 +1023,9 @@ 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);
await mindSporeLite.loadModelFromFile(model_file).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file);
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();
...@@ -1182,12 +1052,6 @@ export default function abilityTest() { ...@@ -1182,12 +1052,6 @@ export default function abilityTest() {
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,10 +1061,9 @@ export default function abilityTest() { ...@@ -1197,10 +1061,9 @@ 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);
await mindSporeLite.loadModelFromFile(model_file).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file);
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();
...@@ -1226,20 +1089,18 @@ export default function abilityTest() { ...@@ -1226,20 +1089,18 @@ export default function abilityTest() {
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++) {
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());
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 z = 0; z < 2; z++) {
console.log(output0[i].toString()); console.log(output0[z].toString());
expect(output0[i].toString() !== null).assertTrue(); expect(output0[z].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====='); console.log('=========MSLITE new Float32Array end=====');
console.log('=========i.toString()====='); console.log('=========i.toString()=====');
console.log(i.toString()); console.log(i.toString());
...@@ -1247,12 +1108,6 @@ export default function abilityTest() { ...@@ -1247,12 +1108,6 @@ export default function abilityTest() {
console.log('=========num.toString()====='); console.log('=========num.toString()=====');
console.log(num.toString()); console.log(num.toString());
} }
}).catch(err => {
console.log("loadModel catch: ", err);
})
}).catch(err => {
console.log("getRawFileContent catch: ", err);
})
}) })
...@@ -1262,13 +1117,12 @@ export default function abilityTest() { ...@@ -1262,13 +1117,12 @@ 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);
} }
await mindSporeLite.loadModelFromFile(model_file).then(async (msliteModel) => { let msliteModel = await mindSporeLite.loadModelFromFile(model_file);
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();
...@@ -1292,7 +1146,7 @@ export default function abilityTest() { ...@@ -1292,7 +1146,7 @@ export default function abilityTest() {
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=====');
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());
...@@ -1302,16 +1156,9 @@ export default function abilityTest() { ...@@ -1302,16 +1156,9 @@ export default function abilityTest() {
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(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);
})
}) })
...@@ -1321,12 +1168,10 @@ export default function abilityTest() { ...@@ -1321,12 +1168,10 @@ 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);
await syscontext.resourceManager.getRawFileContent(modelName).then(async (model_buffer) => { let modelBuffer = await syscontext.resourceManager.getRawFileContent(modelName);
let modelBuffer = model_buffer; let msliteModel = await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer);
await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).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();
...@@ -1353,7 +1198,7 @@ export default function abilityTest() { ...@@ -1353,7 +1198,7 @@ export default function abilityTest() {
} }
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());
...@@ -1362,17 +1207,9 @@ export default function abilityTest() { ...@@ -1362,17 +1207,9 @@ export default function abilityTest() {
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(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);
})
})
}) })
...@@ -1383,15 +1220,12 @@ export default function abilityTest() { ...@@ -1383,15 +1220,12 @@ 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) => {
let inputBuffer02 = buffer;
console.log('=========MSLITE success, input01 bin bytelength: ' + inputBuffer01.byteLength); console.log('=========MSLITE success, input01 bin bytelength: ' + inputBuffer01.byteLength);
console.log('=========MSLITE success, input02 bin bytelength: ' + inputBuffer02.byteLength); console.log('=========MSLITE success, input02 bin bytelength: ' + inputBuffer02.byteLength);
await syscontext.resourceManager.getRawFileContent(modelName).then(async (model_buffer) => { let modelBuffer = await syscontext.resourceManager.getRawFileContent(modelName);
let modelBuffer = model_buffer; let msliteModel = await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer);
await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).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();
...@@ -1430,7 +1264,7 @@ export default function abilityTest() { ...@@ -1430,7 +1264,7 @@ export default function abilityTest() {
console.log(Inputs2[i].toString()); 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());
...@@ -1439,20 +1273,9 @@ export default function abilityTest() { ...@@ -1439,20 +1273,9 @@ export default function abilityTest() {
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(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,12 +1286,10 @@ export default function abilityTest() { ...@@ -1463,12 +1286,10 @@ 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);
await syscontext.resourceManager.getRawFileContent(modelName).then(async (model_buffer) => { let modelBuffer = await syscontext.resourceManager.getRawFileContent(modelName);
let modelBuffer = model_buffer; let msliteModel = await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer);
await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).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();
...@@ -1490,7 +1311,7 @@ export default function abilityTest() { ...@@ -1490,7 +1311,7 @@ export default function abilityTest() {
console.log(Inputs2[i].toString()); 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 Uint8Array(modelOutputs[0].getData()); let output0 = new Uint8Array(modelOutputs[0].getData());
...@@ -1499,17 +1320,9 @@ export default function abilityTest() { ...@@ -1499,17 +1320,9 @@ export default function abilityTest() {
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(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,18 +1334,14 @@ export default function abilityTest() { ...@@ -1521,18 +1334,14 @@ 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;
await syscontext.resourceManager.getRawFileContent(inputName03).then(async (buffer) => {
let inputBuffer03 = buffer;
console.log('=========MSLITE success, input01 bin bytelength: ' + inputBuffer01.byteLength); console.log('=========MSLITE success, input01 bin bytelength: ' + inputBuffer01.byteLength);
console.log('=========MSLITE success, input02 bin bytelength: ' + inputBuffer02.byteLength); console.log('=========MSLITE success, input02 bin bytelength: ' + inputBuffer02.byteLength);
console.log('=========MSLITE success, input03 bin bytelength: ' + inputBuffer03.byteLength); console.log('=========MSLITE success, input03 bin bytelength: ' + inputBuffer03.byteLength);
await syscontext.resourceManager.getRawFileContent(modelName).then(async (model_buffer) => { let modelBuffer = await syscontext.resourceManager.getRawFileContent(modelName);
let modelBuffer = model_buffer; let msliteModel = await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer);
await mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).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();
...@@ -1585,7 +1394,7 @@ export default function abilityTest() { ...@@ -1585,7 +1394,7 @@ export default function abilityTest() {
console.log(Inputs2[i].toString()); 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());
...@@ -1594,36 +1403,19 @@ export default function abilityTest() { ...@@ -1594,36 +1403,19 @@ export default function abilityTest() {
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(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);
})
}).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;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
let context:mindSporeLite.Context={};
context.target = ["cpu"]; context.target = ["cpu"];
context.cpu = { context.cpu = {
"threadNum": 4, "threadNum": 4,
...@@ -1631,10 +1423,26 @@ export default function abilityTest() { ...@@ -1631,10 +1423,26 @@ 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.loadModelFromFile(model_file, context, (msliteModel) => { mindSporeLite.loadModelFromFile(model_file, context, (msliteModel) => {
try { 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 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(); expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end====='); console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs(); const modelInputs = msliteModel.getInputs();
...@@ -1658,8 +1466,7 @@ export default function abilityTest() { ...@@ -1658,8 +1466,7 @@ export default function abilityTest() {
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=====');
msliteModel.predict(modelInputs, (modelOutputs) => { let modelOutputs = await case_predict(msliteModel, modelInputs);
try {
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());
...@@ -1669,40 +1476,22 @@ export default function abilityTest() { ...@@ -1669,40 +1476,22 @@ export default function abilityTest() {
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(modelInputs0[0].name.toString());
console.log('=========MSLITE new Float32Array end====='); console.log('=========MSLITE new Float32Array end=====');
done(); 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', 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");
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); let context: mindSporeLite.Context = {};
await syscontext.resourceManager.getRawFileContent(modelName).then(async (model_buffer) => {
let modelBuffer = model_buffer;
let context:mindSporeLite.Context={};
context.target = ["cpu"]; context.target = ["cpu"];
context.cpu = { context.cpu = {
"threadNum": 4, "threadNum": 4,
...@@ -1710,10 +1499,28 @@ export default function abilityTest() { ...@@ -1710,10 +1499,28 @@ 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.loadModelFromBuffer(modelBuffer.buffer, context, (msliteModel) => { mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, context, (msliteModel) => {
try { 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 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(); expect(msliteModel !== null).assertTrue();
console.log('=========MSLITE loadModel end====='); console.log('=========MSLITE loadModel end=====');
const modelInputs = msliteModel.getInputs(); const modelInputs = msliteModel.getInputs();
...@@ -1737,8 +1544,7 @@ export default function abilityTest() { ...@@ -1737,8 +1544,7 @@ export default function abilityTest() {
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=====');
msliteModel.predict(modelInputs, (modelOutputs) => { let modelOutputs = await case_predict(msliteModel, modelInputs);
try {
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());
...@@ -1748,41 +1554,19 @@ export default function abilityTest() { ...@@ -1748,41 +1554,19 @@ export default function abilityTest() {
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(modelInputs0[0].name.toString());
console.log('=========MSLITE new Float32Array end====='); console.log('=========MSLITE new Float32Array end=====');
done(); 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);
done();
})
}) })
// 正常场景:调用loadModelFromFd callback接口设置context // 正常场景:调用loadModelFromFd callback接口设置context
it('Test_load_model_param_model_fd_callback', 0, async function (done) { it('Test_load_model_param_model_fd_callback', 0, async function (done) {
console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_fd_callback"); console.log("MSLITE api test: loadModel param model file.Test_load_model_param_model_fd_callback");
let inputName = 'ml_face_isface_0.input'; function load_model_from_fd() {
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 inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY); let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY);
let context:mindSporeLite.Context={}; let context:mindSporeLite.Context={};
context.target = ["cpu"]; context.target = ["cpu"];
...@@ -1792,10 +1576,26 @@ export default function abilityTest() { ...@@ -1792,10 +1576,26 @@ 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) => { mindSporeLite.loadModelFromFd(file.fd, context, (msliteModel) => {
try { 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 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_fd();
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();
...@@ -1819,8 +1619,7 @@ export default function abilityTest() { ...@@ -1819,8 +1619,7 @@ export default function abilityTest() {
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=====');
msliteModel.predict(modelInputs, (modelOutputs) => { let modelOutputs = await case_predict(msliteModel, modelInputs);
try {
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());
...@@ -1830,41 +1629,38 @@ export default function abilityTest() { ...@@ -1830,41 +1629,38 @@ export default function abilityTest() {
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(modelInputs0[0].name.toString());
console.log('=========MSLITE new Float32Array end====='); console.log('=========MSLITE new Float32Array end=====');
done(); 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) => {
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 msliteModel = null;
mindSporeLite.loadModelFromFile(model_file, (msliteModel) => { msliteModel = await load_model_from_file();
try {
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();
...@@ -1888,8 +1684,7 @@ export default function abilityTest() { ...@@ -1888,8 +1684,7 @@ export default function abilityTest() {
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=====');
msliteModel.predict(modelInputs, (modelOutputs) => { let modelOutputs = await case_predict(msliteModel, modelInputs);
try {
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());
...@@ -1899,42 +1694,41 @@ export default function abilityTest() { ...@@ -1899,42 +1694,41 @@ export default function abilityTest() {
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(modelInputs0[0].name.toString());
console.log('=========MSLITE new Float32Array end====='); console.log('=========MSLITE new Float32Array end=====');
done(); 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");
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
mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, (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'; let inputBuffer = await syscontext.resourceManager.getRawFileContent(inputName);
await syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
await syscontext.resourceManager.getRawFileContent(modelName).then(async (model_buffer) => {
let modelBuffer = model_buffer;
console.log('=========MSLITE loadModel start====='); console.log('=========MSLITE loadModel start=====');
mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, (msliteModel) => { let msliteModel = null;
try { msliteModel = await load_model_from_buffer();
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();
...@@ -1958,8 +1752,7 @@ export default function abilityTest() { ...@@ -1958,8 +1752,7 @@ export default function abilityTest() {
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=====');
msliteModel.predict(modelInputs, (modelOutputs) => { let modelOutputs = await case_predict(msliteModel, modelInputs);
try {
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());
...@@ -1969,45 +1762,39 @@ export default function abilityTest() { ...@@ -1969,45 +1762,39 @@ export default function abilityTest() {
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(modelInputs0[0].name.toString());
console.log('=========MSLITE new Float32Array end====='); console.log('=========MSLITE new Float32Array end=====');
done(); 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);
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) => {
let inputBuffer = buffer;
console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength); console.log('=========MSLITE success, input bin bytelength: ' + inputBuffer.byteLength);
let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY);
console.log('=========MSLITE loadModel start====='); console.log('=========MSLITE loadModel start=====');
mindSporeLite.loadModelFromFd(file.fd, (msliteModel) => { let msliteModel = null;
try { msliteModel = await load_model_from_fd();
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();
...@@ -2031,8 +1818,7 @@ export default function abilityTest() { ...@@ -2031,8 +1818,7 @@ export default function abilityTest() {
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=====');
msliteModel.predict(modelInputs, (modelOutputs) => { let modelOutputs = await case_predict(msliteModel, modelInputs);
try {
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());
...@@ -2042,25 +1828,10 @@ export default function abilityTest() { ...@@ -2042,25 +1828,10 @@ export default function abilityTest() {
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(modelInputs0[0].name.toString());
console.log('=========MSLITE new Float32Array end====='); console.log('=========MSLITE new Float32Array end=====');
done(); 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.
先完成此消息的编辑!
想要评论请 注册