onnxruntime-node 1.11.0-dev.20220228-eb116595d → 1.12.0-dev.20220429-49d7050b8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -29
- package/__commit.txt +1 -1
- package/bin/napi-v3/darwin/arm64/{libonnxruntime.1.11.0.dylib → libonnxruntime.1.12.0.dylib} +0 -0
- package/bin/napi-v3/darwin/arm64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/darwin/x64/{libonnxruntime.1.11.0.dylib → libonnxruntime.1.12.0.dylib} +0 -0
- package/bin/napi-v3/darwin/x64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/linux/arm64/{libonnxruntime.so.1.11.0 → libonnxruntime.so.1.12.0} +0 -0
- package/bin/napi-v3/linux/arm64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/linux/x64/{libonnxruntime.so.1.11.0 → libonnxruntime.so.1.12.0} +0 -0
- package/bin/napi-v3/linux/x64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/win32/arm64/onnxruntime.dll +0 -0
- package/bin/napi-v3/win32/arm64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/win32/arm64/onnxruntime_providers_shared.dll +0 -0
- package/bin/napi-v3/win32/x64/onnxruntime.dll +0 -0
- package/bin/napi-v3/win32/x64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/win32/x64/onnxruntime_providers_shared.dll +0 -0
- package/dist/backend.d.ts +7 -7
- package/dist/backend.js +76 -76
- package/dist/binding.d.ts +31 -31
- package/dist/binding.js +9 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -18
- package/lib/backend.ts +70 -70
- package/lib/binding.ts +43 -43
- package/lib/index.ts +8 -8
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
# ONNX Runtime Node.js Binding
|
|
2
|
-
|
|
3
|
-
ONNX Runtime Node.js binding enables Node.js applications to run ONNX model inference.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
Install the latest stable version:
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
npm install onnxruntime-node
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Refer to [ONNX Runtime JavaScript examples](https://github.com/microsoft/onnxruntime-inference-examples/tree/main/js) for samples and tutorials.
|
|
14
|
-
|
|
15
|
-
## Requirements
|
|
16
|
-
|
|
17
|
-
ONNXRuntime works on Node.js v12.x+ or Electron v5.x+.
|
|
18
|
-
|
|
19
|
-
Following platforms are supported with pre-built binaries:
|
|
20
|
-
|
|
21
|
-
- Windows x64 CPU NAPI_v3
|
|
22
|
-
- Linux x64 CPU NAPI_v3
|
|
23
|
-
- MacOS x64 CPU NAPI_v3
|
|
24
|
-
|
|
25
|
-
To use on platforms without pre-built binaries, you can build Node.js binding from source and consume it by `npm install <onnxruntime_repo_root>/js/node/`. See also [instructions](https://www.onnxruntime.ai/docs/how-to/build.html#apis-and-language-bindings) for building ONNX Runtime Node.js binding locally.
|
|
26
|
-
|
|
27
|
-
## License
|
|
28
|
-
|
|
29
|
-
License information can be found [here](https://github.com/microsoft/onnxruntime/blob/master/README.md#license).
|
|
1
|
+
# ONNX Runtime Node.js Binding
|
|
2
|
+
|
|
3
|
+
ONNX Runtime Node.js binding enables Node.js applications to run ONNX model inference.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Install the latest stable version:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm install onnxruntime-node
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Refer to [ONNX Runtime JavaScript examples](https://github.com/microsoft/onnxruntime-inference-examples/tree/main/js) for samples and tutorials.
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
ONNXRuntime works on Node.js v12.x+ or Electron v5.x+.
|
|
18
|
+
|
|
19
|
+
Following platforms are supported with pre-built binaries:
|
|
20
|
+
|
|
21
|
+
- Windows x64 CPU NAPI_v3
|
|
22
|
+
- Linux x64 CPU NAPI_v3
|
|
23
|
+
- MacOS x64 CPU NAPI_v3
|
|
24
|
+
|
|
25
|
+
To use on platforms without pre-built binaries, you can build Node.js binding from source and consume it by `npm install <onnxruntime_repo_root>/js/node/`. See also [instructions](https://www.onnxruntime.ai/docs/how-to/build.html#apis-and-language-bindings) for building ONNX Runtime Node.js binding locally.
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
|
|
29
|
+
License information can be found [here](https://github.com/microsoft/onnxruntime/blob/master/README.md#license).
|
package/__commit.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
49d7050b88338dd57839159aa4ce8fb0c199b064
|
package/bin/napi-v3/darwin/arm64/{libonnxruntime.1.11.0.dylib → libonnxruntime.1.12.0.dylib}
RENAMED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/backend.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Backend, InferenceSession, SessionHandler } from 'onnxruntime-common';
|
|
2
|
-
declare class OnnxruntimeBackend implements Backend {
|
|
3
|
-
init(): Promise<void>;
|
|
4
|
-
createSessionHandler(pathOrBuffer: string | Uint8Array, options?: InferenceSession.SessionOptions): Promise<SessionHandler>;
|
|
5
|
-
}
|
|
6
|
-
export declare const onnxruntimeBackend: OnnxruntimeBackend;
|
|
7
|
-
export {};
|
|
1
|
+
import { Backend, InferenceSession, SessionHandler } from 'onnxruntime-common';
|
|
2
|
+
declare class OnnxruntimeBackend implements Backend {
|
|
3
|
+
init(): Promise<void>;
|
|
4
|
+
createSessionHandler(pathOrBuffer: string | Uint8Array, options?: InferenceSession.SessionOptions): Promise<SessionHandler>;
|
|
5
|
+
}
|
|
6
|
+
export declare const onnxruntimeBackend: OnnxruntimeBackend;
|
|
7
|
+
export {};
|
package/dist/backend.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
// Licensed under the MIT License.
|
|
4
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
|
|
5
|
-
if (!privateMap.has(receiver)) {
|
|
6
|
-
throw new TypeError("attempted to set private field on non-instance");
|
|
7
|
-
}
|
|
8
|
-
privateMap.set(receiver, value);
|
|
9
|
-
return value;
|
|
10
|
-
};
|
|
11
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
|
|
12
|
-
if (!privateMap.has(receiver)) {
|
|
13
|
-
throw new TypeError("attempted to get private field on non-instance");
|
|
14
|
-
}
|
|
15
|
-
return privateMap.get(receiver);
|
|
16
|
-
};
|
|
17
|
-
var _inferenceSession;
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.onnxruntimeBackend = void 0;
|
|
20
|
-
const binding_1 = require("./binding");
|
|
21
|
-
class OnnxruntimeSessionHandler {
|
|
22
|
-
constructor(pathOrBuffer, options) {
|
|
23
|
-
_inferenceSession.set(this, void 0);
|
|
24
|
-
__classPrivateFieldSet(this, _inferenceSession, new binding_1.binding.InferenceSession());
|
|
25
|
-
if (typeof pathOrBuffer === 'string') {
|
|
26
|
-
__classPrivateFieldGet(this, _inferenceSession).loadModel(pathOrBuffer, options);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
__classPrivateFieldGet(this, _inferenceSession).loadModel(pathOrBuffer.buffer, pathOrBuffer.byteOffset, pathOrBuffer.byteLength, options);
|
|
30
|
-
}
|
|
31
|
-
this.inputNames = __classPrivateFieldGet(this, _inferenceSession).inputNames;
|
|
32
|
-
this.outputNames = __classPrivateFieldGet(this, _inferenceSession).outputNames;
|
|
33
|
-
}
|
|
34
|
-
async dispose() {
|
|
35
|
-
return Promise.resolve();
|
|
36
|
-
}
|
|
37
|
-
startProfiling() {
|
|
38
|
-
// TODO: implement profiling
|
|
39
|
-
}
|
|
40
|
-
endProfiling() {
|
|
41
|
-
// TODO: implement profiling
|
|
42
|
-
}
|
|
43
|
-
async run(feeds, fetches, options) {
|
|
44
|
-
return new Promise((resolve, reject) => {
|
|
45
|
-
process.nextTick(() => {
|
|
46
|
-
try {
|
|
47
|
-
resolve(__classPrivateFieldGet(this, _inferenceSession).run(feeds, fetches, options));
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
// reject if any error is thrown
|
|
51
|
-
reject(e);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
_inferenceSession = new WeakMap();
|
|
58
|
-
class OnnxruntimeBackend {
|
|
59
|
-
async init() {
|
|
60
|
-
return Promise.resolve();
|
|
61
|
-
}
|
|
62
|
-
async createSessionHandler(pathOrBuffer, options) {
|
|
63
|
-
return new Promise((resolve, reject) => {
|
|
64
|
-
process.nextTick(() => {
|
|
65
|
-
try {
|
|
66
|
-
resolve(new OnnxruntimeSessionHandler(pathOrBuffer, options || {}));
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
// reject if any error is thrown
|
|
70
|
-
reject(e);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.onnxruntimeBackend = new OnnxruntimeBackend();
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
|
|
5
|
+
if (!privateMap.has(receiver)) {
|
|
6
|
+
throw new TypeError("attempted to set private field on non-instance");
|
|
7
|
+
}
|
|
8
|
+
privateMap.set(receiver, value);
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
|
|
12
|
+
if (!privateMap.has(receiver)) {
|
|
13
|
+
throw new TypeError("attempted to get private field on non-instance");
|
|
14
|
+
}
|
|
15
|
+
return privateMap.get(receiver);
|
|
16
|
+
};
|
|
17
|
+
var _inferenceSession;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.onnxruntimeBackend = void 0;
|
|
20
|
+
const binding_1 = require("./binding");
|
|
21
|
+
class OnnxruntimeSessionHandler {
|
|
22
|
+
constructor(pathOrBuffer, options) {
|
|
23
|
+
_inferenceSession.set(this, void 0);
|
|
24
|
+
__classPrivateFieldSet(this, _inferenceSession, new binding_1.binding.InferenceSession());
|
|
25
|
+
if (typeof pathOrBuffer === 'string') {
|
|
26
|
+
__classPrivateFieldGet(this, _inferenceSession).loadModel(pathOrBuffer, options);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
__classPrivateFieldGet(this, _inferenceSession).loadModel(pathOrBuffer.buffer, pathOrBuffer.byteOffset, pathOrBuffer.byteLength, options);
|
|
30
|
+
}
|
|
31
|
+
this.inputNames = __classPrivateFieldGet(this, _inferenceSession).inputNames;
|
|
32
|
+
this.outputNames = __classPrivateFieldGet(this, _inferenceSession).outputNames;
|
|
33
|
+
}
|
|
34
|
+
async dispose() {
|
|
35
|
+
return Promise.resolve();
|
|
36
|
+
}
|
|
37
|
+
startProfiling() {
|
|
38
|
+
// TODO: implement profiling
|
|
39
|
+
}
|
|
40
|
+
endProfiling() {
|
|
41
|
+
// TODO: implement profiling
|
|
42
|
+
}
|
|
43
|
+
async run(feeds, fetches, options) {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
process.nextTick(() => {
|
|
46
|
+
try {
|
|
47
|
+
resolve(__classPrivateFieldGet(this, _inferenceSession).run(feeds, fetches, options));
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
// reject if any error is thrown
|
|
51
|
+
reject(e);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
_inferenceSession = new WeakMap();
|
|
58
|
+
class OnnxruntimeBackend {
|
|
59
|
+
async init() {
|
|
60
|
+
return Promise.resolve();
|
|
61
|
+
}
|
|
62
|
+
async createSessionHandler(pathOrBuffer, options) {
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
process.nextTick(() => {
|
|
65
|
+
try {
|
|
66
|
+
resolve(new OnnxruntimeSessionHandler(pathOrBuffer, options || {}));
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
// reject if any error is thrown
|
|
70
|
+
reject(e);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.onnxruntimeBackend = new OnnxruntimeBackend();
|
|
77
77
|
//# sourceMappingURL=backend.js.map
|
package/dist/binding.d.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { InferenceSession, OnnxValue } from 'onnxruntime-common';
|
|
2
|
-
declare type SessionOptions = InferenceSession.SessionOptions;
|
|
3
|
-
declare type FeedsType = {
|
|
4
|
-
[name: string]: OnnxValue;
|
|
5
|
-
};
|
|
6
|
-
declare type FetchesType = {
|
|
7
|
-
[name: string]: OnnxValue | null;
|
|
8
|
-
};
|
|
9
|
-
declare type ReturnType = {
|
|
10
|
-
[name: string]: OnnxValue;
|
|
11
|
-
};
|
|
12
|
-
declare type RunOptions = InferenceSession.RunOptions;
|
|
13
|
-
/**
|
|
14
|
-
* Binding exports a simple synchronized inference session object wrap.
|
|
15
|
-
*/
|
|
16
|
-
export declare namespace Binding {
|
|
17
|
-
interface InferenceSession {
|
|
18
|
-
loadModel(modelPath: string, options: SessionOptions): void;
|
|
19
|
-
loadModel(buffer: ArrayBuffer, byteOffset: number, byteLength: number, options: SessionOptions): void;
|
|
20
|
-
readonly inputNames: string[];
|
|
21
|
-
readonly outputNames: string[];
|
|
22
|
-
run(feeds: FeedsType, fetches: FetchesType, options: RunOptions): ReturnType;
|
|
23
|
-
}
|
|
24
|
-
interface InferenceSessionConstructor {
|
|
25
|
-
new (): InferenceSession;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export declare const binding: {
|
|
29
|
-
InferenceSession: Binding.InferenceSessionConstructor;
|
|
30
|
-
};
|
|
31
|
-
export {};
|
|
1
|
+
import { InferenceSession, OnnxValue } from 'onnxruntime-common';
|
|
2
|
+
declare type SessionOptions = InferenceSession.SessionOptions;
|
|
3
|
+
declare type FeedsType = {
|
|
4
|
+
[name: string]: OnnxValue;
|
|
5
|
+
};
|
|
6
|
+
declare type FetchesType = {
|
|
7
|
+
[name: string]: OnnxValue | null;
|
|
8
|
+
};
|
|
9
|
+
declare type ReturnType = {
|
|
10
|
+
[name: string]: OnnxValue;
|
|
11
|
+
};
|
|
12
|
+
declare type RunOptions = InferenceSession.RunOptions;
|
|
13
|
+
/**
|
|
14
|
+
* Binding exports a simple synchronized inference session object wrap.
|
|
15
|
+
*/
|
|
16
|
+
export declare namespace Binding {
|
|
17
|
+
interface InferenceSession {
|
|
18
|
+
loadModel(modelPath: string, options: SessionOptions): void;
|
|
19
|
+
loadModel(buffer: ArrayBuffer, byteOffset: number, byteLength: number, options: SessionOptions): void;
|
|
20
|
+
readonly inputNames: string[];
|
|
21
|
+
readonly outputNames: string[];
|
|
22
|
+
run(feeds: FeedsType, fetches: FetchesType, options: RunOptions): ReturnType;
|
|
23
|
+
}
|
|
24
|
+
interface InferenceSessionConstructor {
|
|
25
|
+
new (): InferenceSession;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export declare const binding: {
|
|
29
|
+
InferenceSession: Binding.InferenceSessionConstructor;
|
|
30
|
+
};
|
|
31
|
+
export {};
|
package/dist/binding.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
// Licensed under the MIT License.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.binding = void 0;
|
|
6
|
-
// export native binding
|
|
7
|
-
exports.binding =
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
9
|
-
require(`../bin/napi-v3/${process.platform}/${process.arch}/onnxruntime_binding.node`);
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.binding = void 0;
|
|
6
|
+
// export native binding
|
|
7
|
+
exports.binding =
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
9
|
+
require(`../bin/napi-v3/${process.platform}/${process.arch}/onnxruntime_binding.node`);
|
|
10
10
|
//# sourceMappingURL=binding.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from 'onnxruntime-common';
|
|
1
|
+
export * from 'onnxruntime-common';
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
// Licensed under the MIT License.
|
|
4
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
-
if (k2 === undefined) k2 = k;
|
|
6
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
7
|
-
}) : (function(o, m, k, k2) {
|
|
8
|
-
if (k2 === undefined) k2 = k;
|
|
9
|
-
o[k2] = m[k];
|
|
10
|
-
}));
|
|
11
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
12
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
__exportStar(require("onnxruntime-common"), exports);
|
|
16
|
-
const onnxruntime_common_1 = require("onnxruntime-common");
|
|
17
|
-
const backend_1 = require("./backend");
|
|
18
|
-
onnxruntime_common_1.registerBackend('cpu', backend_1.onnxruntimeBackend, 1);
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
7
|
+
}) : (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
o[k2] = m[k];
|
|
10
|
+
}));
|
|
11
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
12
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
__exportStar(require("onnxruntime-common"), exports);
|
|
16
|
+
const onnxruntime_common_1 = require("onnxruntime-common");
|
|
17
|
+
const backend_1 = require("./backend");
|
|
18
|
+
onnxruntime_common_1.registerBackend('cpu', backend_1.onnxruntimeBackend, 1);
|
|
19
19
|
//# sourceMappingURL=index.js.map
|
package/lib/backend.ts
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import {Backend, InferenceSession, SessionHandler} from 'onnxruntime-common';
|
|
5
|
-
import {Binding, binding} from './binding';
|
|
6
|
-
|
|
7
|
-
class OnnxruntimeSessionHandler implements SessionHandler {
|
|
8
|
-
#inferenceSession: Binding.InferenceSession;
|
|
9
|
-
|
|
10
|
-
constructor(pathOrBuffer: string|Uint8Array, options: InferenceSession.SessionOptions) {
|
|
11
|
-
this.#inferenceSession = new binding.InferenceSession();
|
|
12
|
-
if (typeof pathOrBuffer === 'string') {
|
|
13
|
-
this.#inferenceSession.loadModel(pathOrBuffer, options);
|
|
14
|
-
} else {
|
|
15
|
-
this.#inferenceSession.loadModel(pathOrBuffer.buffer, pathOrBuffer.byteOffset, pathOrBuffer.byteLength, options);
|
|
16
|
-
}
|
|
17
|
-
this.inputNames = this.#inferenceSession.inputNames;
|
|
18
|
-
this.outputNames = this.#inferenceSession.outputNames;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async dispose(): Promise<void> {
|
|
22
|
-
return Promise.resolve();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
readonly inputNames: string[];
|
|
26
|
-
readonly outputNames: string[];
|
|
27
|
-
|
|
28
|
-
startProfiling(): void {
|
|
29
|
-
// TODO: implement profiling
|
|
30
|
-
}
|
|
31
|
-
endProfiling(): void {
|
|
32
|
-
// TODO: implement profiling
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async run(feeds: SessionHandler.FeedsType, fetches: SessionHandler.FetchesType, options: InferenceSession.RunOptions):
|
|
36
|
-
Promise<SessionHandler.ReturnType> {
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
process.nextTick(() => {
|
|
39
|
-
try {
|
|
40
|
-
resolve(this.#inferenceSession.run(feeds, fetches, options));
|
|
41
|
-
} catch (e) {
|
|
42
|
-
// reject if any error is thrown
|
|
43
|
-
reject(e);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
class OnnxruntimeBackend implements Backend {
|
|
51
|
-
async init(): Promise<void> {
|
|
52
|
-
return Promise.resolve();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async createSessionHandler(pathOrBuffer: string|Uint8Array, options?: InferenceSession.SessionOptions):
|
|
56
|
-
Promise<SessionHandler> {
|
|
57
|
-
return new Promise((resolve, reject) => {
|
|
58
|
-
process.nextTick(() => {
|
|
59
|
-
try {
|
|
60
|
-
resolve(new OnnxruntimeSessionHandler(pathOrBuffer, options || {}));
|
|
61
|
-
} catch (e) {
|
|
62
|
-
// reject if any error is thrown
|
|
63
|
-
reject(e);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export const onnxruntimeBackend = new OnnxruntimeBackend();
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import {Backend, InferenceSession, SessionHandler} from 'onnxruntime-common';
|
|
5
|
+
import {Binding, binding} from './binding';
|
|
6
|
+
|
|
7
|
+
class OnnxruntimeSessionHandler implements SessionHandler {
|
|
8
|
+
#inferenceSession: Binding.InferenceSession;
|
|
9
|
+
|
|
10
|
+
constructor(pathOrBuffer: string|Uint8Array, options: InferenceSession.SessionOptions) {
|
|
11
|
+
this.#inferenceSession = new binding.InferenceSession();
|
|
12
|
+
if (typeof pathOrBuffer === 'string') {
|
|
13
|
+
this.#inferenceSession.loadModel(pathOrBuffer, options);
|
|
14
|
+
} else {
|
|
15
|
+
this.#inferenceSession.loadModel(pathOrBuffer.buffer, pathOrBuffer.byteOffset, pathOrBuffer.byteLength, options);
|
|
16
|
+
}
|
|
17
|
+
this.inputNames = this.#inferenceSession.inputNames;
|
|
18
|
+
this.outputNames = this.#inferenceSession.outputNames;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async dispose(): Promise<void> {
|
|
22
|
+
return Promise.resolve();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
readonly inputNames: string[];
|
|
26
|
+
readonly outputNames: string[];
|
|
27
|
+
|
|
28
|
+
startProfiling(): void {
|
|
29
|
+
// TODO: implement profiling
|
|
30
|
+
}
|
|
31
|
+
endProfiling(): void {
|
|
32
|
+
// TODO: implement profiling
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async run(feeds: SessionHandler.FeedsType, fetches: SessionHandler.FetchesType, options: InferenceSession.RunOptions):
|
|
36
|
+
Promise<SessionHandler.ReturnType> {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
process.nextTick(() => {
|
|
39
|
+
try {
|
|
40
|
+
resolve(this.#inferenceSession.run(feeds, fetches, options));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
// reject if any error is thrown
|
|
43
|
+
reject(e);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
class OnnxruntimeBackend implements Backend {
|
|
51
|
+
async init(): Promise<void> {
|
|
52
|
+
return Promise.resolve();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async createSessionHandler(pathOrBuffer: string|Uint8Array, options?: InferenceSession.SessionOptions):
|
|
56
|
+
Promise<SessionHandler> {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
process.nextTick(() => {
|
|
59
|
+
try {
|
|
60
|
+
resolve(new OnnxruntimeSessionHandler(pathOrBuffer, options || {}));
|
|
61
|
+
} catch (e) {
|
|
62
|
+
// reject if any error is thrown
|
|
63
|
+
reject(e);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const onnxruntimeBackend = new OnnxruntimeBackend();
|
package/lib/binding.ts
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import {InferenceSession, OnnxValue} from 'onnxruntime-common';
|
|
5
|
-
|
|
6
|
-
type SessionOptions = InferenceSession.SessionOptions;
|
|
7
|
-
type FeedsType = {
|
|
8
|
-
[name: string]: OnnxValue;
|
|
9
|
-
};
|
|
10
|
-
type FetchesType = {
|
|
11
|
-
[name: string]: OnnxValue|null;
|
|
12
|
-
};
|
|
13
|
-
type ReturnType = {
|
|
14
|
-
[name: string]: OnnxValue;
|
|
15
|
-
};
|
|
16
|
-
type RunOptions = InferenceSession.RunOptions;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Binding exports a simple synchronized inference session object wrap.
|
|
21
|
-
*/
|
|
22
|
-
export declare namespace Binding {
|
|
23
|
-
export interface InferenceSession {
|
|
24
|
-
loadModel(modelPath: string, options: SessionOptions): void;
|
|
25
|
-
loadModel(buffer: ArrayBuffer, byteOffset: number, byteLength: number, options: SessionOptions): void;
|
|
26
|
-
|
|
27
|
-
readonly inputNames: string[];
|
|
28
|
-
readonly outputNames: string[];
|
|
29
|
-
|
|
30
|
-
run(feeds: FeedsType, fetches: FetchesType, options: RunOptions): ReturnType;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface InferenceSessionConstructor {
|
|
34
|
-
new(): InferenceSession;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// export native binding
|
|
39
|
-
export const binding =
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
41
|
-
require(`../bin/napi-v3/${process.platform}/${process.arch}/onnxruntime_binding.node`) as
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
43
|
-
{InferenceSession: Binding.InferenceSessionConstructor};
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import {InferenceSession, OnnxValue} from 'onnxruntime-common';
|
|
5
|
+
|
|
6
|
+
type SessionOptions = InferenceSession.SessionOptions;
|
|
7
|
+
type FeedsType = {
|
|
8
|
+
[name: string]: OnnxValue;
|
|
9
|
+
};
|
|
10
|
+
type FetchesType = {
|
|
11
|
+
[name: string]: OnnxValue|null;
|
|
12
|
+
};
|
|
13
|
+
type ReturnType = {
|
|
14
|
+
[name: string]: OnnxValue;
|
|
15
|
+
};
|
|
16
|
+
type RunOptions = InferenceSession.RunOptions;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Binding exports a simple synchronized inference session object wrap.
|
|
21
|
+
*/
|
|
22
|
+
export declare namespace Binding {
|
|
23
|
+
export interface InferenceSession {
|
|
24
|
+
loadModel(modelPath: string, options: SessionOptions): void;
|
|
25
|
+
loadModel(buffer: ArrayBuffer, byteOffset: number, byteLength: number, options: SessionOptions): void;
|
|
26
|
+
|
|
27
|
+
readonly inputNames: string[];
|
|
28
|
+
readonly outputNames: string[];
|
|
29
|
+
|
|
30
|
+
run(feeds: FeedsType, fetches: FetchesType, options: RunOptions): ReturnType;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface InferenceSessionConstructor {
|
|
34
|
+
new(): InferenceSession;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// export native binding
|
|
39
|
+
export const binding =
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
41
|
+
require(`../bin/napi-v3/${process.platform}/${process.arch}/onnxruntime_binding.node`) as
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
43
|
+
{InferenceSession: Binding.InferenceSessionConstructor};
|
package/lib/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
export * from 'onnxruntime-common';
|
|
5
|
-
import {registerBackend} from 'onnxruntime-common';
|
|
6
|
-
import {onnxruntimeBackend} from './backend';
|
|
7
|
-
|
|
8
|
-
registerBackend('cpu', onnxruntimeBackend, 1);
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
export * from 'onnxruntime-common';
|
|
5
|
+
import {registerBackend} from 'onnxruntime-common';
|
|
6
|
+
import {onnxruntimeBackend} from './backend';
|
|
7
|
+
|
|
8
|
+
registerBackend('cpu', onnxruntimeBackend, 1);
|
package/package.json
CHANGED
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
3
|
|
14
14
|
]
|
|
15
15
|
},
|
|
16
|
-
"version": "1.
|
|
16
|
+
"version": "1.12.0-dev.20220429-49d7050b8",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"onnxruntime-common": "~1.
|
|
18
|
+
"onnxruntime-common": "~1.12.0-dev.20220429-49d7050b8"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"buildr": "tsc && node ./script/build --config=RelWithDebInfo",
|
|
@@ -34,18 +34,18 @@
|
|
|
34
34
|
"ONNX Runtime"
|
|
35
35
|
],
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"fs-extra": "^9.
|
|
37
|
+
"@types/fs-extra": "^9.0.6",
|
|
38
|
+
"@types/minimist": "1.2.1",
|
|
39
|
+
"@types/mocha": "^8.2.2",
|
|
40
|
+
"@types/node": "^14.14.37",
|
|
38
41
|
"cmake-js": "^6.2.1",
|
|
42
|
+
"fs-extra": "^9.1.0",
|
|
39
43
|
"jsonc": "^2.0.0",
|
|
40
|
-
"onnx-proto": "^4.0.4",
|
|
41
44
|
"minimist": "^1.2.5",
|
|
42
|
-
"mocha": "^
|
|
43
|
-
"@types/mocha": "^8.2.2",
|
|
44
|
-
"typescript": "^4.2.4",
|
|
45
|
-
"@types/fs-extra": "^9.0.6",
|
|
45
|
+
"mocha": "^9.2.1",
|
|
46
46
|
"node-addon-api": "^3.1.0",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
47
|
+
"onnx-proto": "^4.0.4",
|
|
48
|
+
"typescript": "^4.2.4"
|
|
49
49
|
},
|
|
50
50
|
"main": "dist/index.js",
|
|
51
51
|
"os": [
|