onnxruntime/nodejs/test/e2e/inference-session-run.ts
Yulong Wang 5dfc91db51
Node.js binding for ONNX Runtime (#3613)
* initial commit for Node.js binding

* add c++ code

* add inference session impl

* e2e working

* add settings.json

* add test data

* adjust binding declaration

* refine tensor constructor declaration

* update tests

* enable onnx tests

* simply refine readme

* refine cpp impl

* refine tests

* formatting

* add linting

* move bin folder

* fix linux build

* manually update test filter list

* update C++ API headers: fix crash in release build

* make (manually) prebuild work

* add test into prepack script

* specify prebuild runtime type (N-API)

* build.ts: update rebuild and include regex

* fix lazy load on electron.js

* update dev version, git link and binary host

* support session options and run options

* bump dev version

* update README

* add 1 example

* move folder

* adjust path

* update document for examples

* rename example 01

* add example 02

* add session option: log severity level

* add example 04

* resolve comments

* fix typo

* remove double guard in header files

* add copyright banner

* move BUILD outside from README

* consume test filter list from onnxruntime
2020-05-05 11:45:12 -07:00

26 lines
1,023 B
TypeScript

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as path from 'path';
import {Tensor} from '../../lib';
import {InferenceSession} from '../../lib/inference-session';
import {SQUEEZENET_INPUT0_DATA, SQUEEZENET_OUTPUT0_DATA, TEST_DATA_ROOT} from '../test-utils';
import {assertTensorEqual} from '../test-utils';
describe('E2E Tests - InferenceSession.run()', async () => {
let session: InferenceSession|null = null;
const input0 = new Tensor('float32', SQUEEZENET_INPUT0_DATA, [1, 3, 224, 224]);
const expectedOutput0 = new Tensor('float32', SQUEEZENET_OUTPUT0_DATA, [1, 1000, 1, 1]);
before(async () => {
session = await InferenceSession.create(path.join(TEST_DATA_ROOT, 'squeezenet.onnx'));
});
it('multiple run() calls', async () => {
for (let i = 0; i < 1000; i++) {
const result = await session!.run({'data_0': input0}, ['softmaxout_1']);
assertTensorEqual(result.softmaxout_1, expectedOutput0);
}
}).timeout('60s');
});