forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OV JS] Perform inference in electron app in nodejs e2e test (openvin…
…otoolkit#27131) ### Details: - Extend e2e test of Node.js API by performing test inference ### Tickets: - 154192
- Loading branch information
1 parent
ea773b7
commit ed7af95
Showing
2 changed files
with
49 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,39 @@ | ||
const { app } = require('electron'); | ||
const { addon: ov } = require('openvino-node'); | ||
|
||
app.whenReady().then(() => { | ||
console.log('Creating OpenVINO Runtime Core'); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const core = new ov.Core(); | ||
console.log('Created OpenVINO Runtime Core'); | ||
const epsilon = 0.5; // To avoid very small numbers | ||
const pathToModel = '../tests/unit/test_models/test_model_fp32.xml'; | ||
|
||
main(); | ||
|
||
async function main() { | ||
await app.whenReady(); | ||
|
||
try { | ||
console.log('Creating OpenVINO Runtime Core'); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const core = new ov.Core(); | ||
console.log('Created OpenVINO Runtime Core'); | ||
|
||
const model = await core.readModel(pathToModel); | ||
console.log('Model read successfully:', model); | ||
const compiledModel = await core.compileModel(model, 'CPU'); | ||
const inferRequest = compiledModel.createInferRequest(); | ||
console.log('Infer request created:', inferRequest); | ||
|
||
const tensorData = Float32Array.from( | ||
{ length: 3072 }, | ||
() => Math.random() + epsilon, | ||
); | ||
const tensor = new ov.Tensor(ov.element.f32, [1, 3, 32, 32], tensorData); | ||
console.log('Tensor created:', tensor); | ||
|
||
const result = await inferRequest.inferAsync([tensor]); | ||
console.log('Infer request result:', result); | ||
} catch (error) { | ||
console.error('Error:', error); | ||
app.exit(1); | ||
} | ||
|
||
app.exit(0); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters