onnxjs-node
Advanced tools
Comparing version 0.4.1 to 1.4.0
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
@@ -25,6 +37,13 @@ }; | ||
} | ||
// force re-assign overwritten property 'InferenceSession' | ||
onnxjs.InferenceSession = require('./inference-session-override').OnnxRuntimeInferenceSession; | ||
// create a new onnx object and assign property 'InferenceSession' | ||
var onnx_1 = Object.create(onnxjs); | ||
Object.defineProperty(onnx_1, 'InferenceSession', { | ||
enumerable: true, | ||
get: function () { | ||
return require('./inference-session-override').OnnxRuntimeInferenceSession; | ||
} | ||
}); | ||
global.onnx = onnx_1; | ||
} | ||
module.exports = onnxjs; | ||
module.exports = onnx; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -37,38 +57,32 @@ }); | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var onnxjs_1 = require("onnxjs"); | ||
var Binding = __importStar(require("./binding")); | ||
var OnnxjsInferenceSession = onnxjs_1.InferenceSession; | ||
exports.OnnxRuntimeInferenceSession = void 0; | ||
var onnxjs = __importStar(require("onnxjs")); | ||
var onnxruntime = __importStar(require("onnxruntime")); | ||
var OnnxRuntimeInferenceSession = /** @class */ (function () { | ||
function OnnxRuntimeInferenceSession(config) { | ||
var useOnnxRuntime = !config || typeof config.backendHint !== 'string' || config.backendHint === 'onnxruntime'; | ||
if (useOnnxRuntime) { | ||
this.binding = new Binding.binding.InferenceSession(); | ||
if (!useOnnxRuntime) { | ||
this.onnxjsFallback = new onnxjs.InferenceSession(config); | ||
console.log('fallback to ONNX.js inference session'); | ||
} | ||
else { | ||
this.onnxjsFallback = new OnnxjsInferenceSession(config); | ||
console.log('fallback'); | ||
} | ||
} | ||
OnnxRuntimeInferenceSession.prototype.loadModel = function (arg0, arg1, arg2) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
if (this.onnxjsFallback) { | ||
return [2 /*return*/, this.onnxjsFallback.loadModel(arg0, arg1, arg2)]; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (this.onnxjsFallback) { | ||
return [2 /*return*/, this.onnxjsFallback.loadModel(arg0, arg1, arg2)]; | ||
} | ||
if (typeof arg0 !== 'string') { | ||
throw new TypeError('a string model path is expected'); | ||
} | ||
_a = this; | ||
return [4 /*yield*/, onnxruntime.InferenceSession.create(arg0)]; | ||
case 1: | ||
_a.binding = _b.sent(); | ||
return [2 /*return*/]; | ||
} | ||
if (typeof arg0 !== 'string') { | ||
throw new TypeError('a string model path is expected'); | ||
} | ||
if (!this.binding) { | ||
throw new Error('binding is not assigned'); | ||
} | ||
this.binding.loadModel(arg0); | ||
return [2 /*return*/]; | ||
}); | ||
@@ -80,2 +94,3 @@ }); | ||
var input, output, result; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
@@ -90,41 +105,33 @@ switch (_a.label) { | ||
} | ||
input = new Array(this.binding.inputNames.length); | ||
if (!(inputFeed instanceof Map)) return [3 /*break*/, 2]; | ||
this.binding.inputNames.forEach(function (name, i) { | ||
var t = inputFeed.get(name); | ||
if (!t) { | ||
throw new Error("missing input '" + name + "'"); | ||
} | ||
input[i] = { data: t.data, dims: t.dims, type: getTensorDataTypeFromString(t.type) }; | ||
}); | ||
input = {}; | ||
if (inputFeed instanceof Map) { | ||
this.binding.inputNames.forEach(function (name) { | ||
var t = inputFeed.get(name); | ||
if (!t) { | ||
throw new Error("missing input '" + name + "'"); | ||
} | ||
input[name] = new onnxruntime.Tensor(t.type, t.data, t.dims); | ||
}); | ||
} | ||
else if (Array.isArray(inputFeed)) { | ||
inputFeed.forEach(function (t, i) { | ||
input[_this.binding.inputNames[i]] = new onnxruntime.Tensor(t.type, t.data, t.dims); | ||
}); | ||
} | ||
else { | ||
this.binding.inputNames.forEach(function (name) { | ||
var t = inputFeed[name]; | ||
if (!t) { | ||
throw new Error("missing input '" + name + "'"); | ||
} | ||
input[name] = new onnxruntime.Tensor(t.type, t.data, t.dims); | ||
}); | ||
} | ||
return [4 /*yield*/, this.binding.run(input)]; | ||
case 1: | ||
output = _a.sent(); | ||
return [3 /*break*/, 6]; | ||
case 2: | ||
if (!Array.isArray(inputFeed)) return [3 /*break*/, 4]; | ||
inputFeed.forEach(function (t, i) { | ||
input[i] = { data: t.data, dims: t.dims, type: getTensorDataTypeFromString(t.type) }; | ||
}); | ||
return [4 /*yield*/, this.binding.run(input)]; | ||
case 3: | ||
output = _a.sent(); | ||
return [3 /*break*/, 6]; | ||
case 4: | ||
this.binding.inputNames.forEach(function (name, i) { | ||
var t = inputFeed[name]; | ||
if (!t) { | ||
throw new Error("missing input '" + name + "'"); | ||
} | ||
input[i] = { data: t.data, dims: t.dims, type: getTensorDataTypeFromString(t.type) }; | ||
}); | ||
return [4 /*yield*/, this.binding.run(input)]; | ||
case 5: | ||
output = _a.sent(); | ||
_a.label = 6; | ||
case 6: | ||
result = new Map(); | ||
this.binding.outputNames.forEach(function (name, i) { | ||
var t = output[i]; | ||
result.set(name, new onnxjs_1.Tensor(t.data, getTensorDataTypeFromEnum(t.type), t.dims)); | ||
this.binding.outputNames.forEach(function (name) { | ||
var t = output[name]; | ||
result.set(name, new onnxjs.Tensor(t.data, t.type, t.dims)); | ||
}); | ||
@@ -151,28 +158,2 @@ return [2 /*return*/, result]; | ||
exports.OnnxRuntimeInferenceSession = OnnxRuntimeInferenceSession; | ||
function getTensorDataTypeFromString(type) { | ||
switch (type) { | ||
case 'float32': | ||
return 1; | ||
case 'int32': | ||
return 6; | ||
case 'bool': | ||
return 9; | ||
default: | ||
return -1; | ||
} | ||
} | ||
function getTensorDataTypeFromEnum(type) { | ||
switch (type) { | ||
case 1: | ||
return 'float32'; | ||
case 6: | ||
return 'int32'; | ||
case 9: | ||
return 'bool'; | ||
case 8: | ||
return 'string'; | ||
default: | ||
throw new Error("unsupported data type: " + type); | ||
} | ||
} | ||
//# sourceMappingURL=inference-session-override.js.map |
{ | ||
"name": "onnxjs-node", | ||
"description": "a Node.js binding of ONNXRuntime that works seamlessly with ONNX.js", | ||
"version": "0.4.1", | ||
"description": "ONNXRuntime backend for ONNX.js", | ||
"version": "1.4.0", | ||
"author": "fs-eire", | ||
"main": "./lib/index.js", | ||
"scripts": { | ||
"install": "node-pre-gyp install --fallback-to-build=false || npm run build", | ||
"prepare": "tsc", | ||
"build": "tsc && node ./scripts/build", | ||
"buildd": "tsc && node ./scripts/build --debug", | ||
"rebuild": "tsc && node ./scripts/build --rebuild", | ||
"rebuildd": "tsc && node ./scripts/build --debug --rebuild", | ||
"test": "mocha ./test/test-main", | ||
@@ -18,12 +13,2 @@ "prepublishOnly": "npm test", | ||
}, | ||
"binary": { | ||
"module_name": "cpu/onnxruntime", | ||
"module_path": "./bin/napi-v{napi_build_version}", | ||
"package_name": "onnxruntime-{platform}-{arch}-{node_napi_label}.tar.gz", | ||
"host": "https://github.com/fs-eire/onnxjs-node/releases/download/", | ||
"remote_path": "v{version}", | ||
"napi_versions": [ | ||
3 | ||
] | ||
}, | ||
"repository": { | ||
@@ -43,21 +28,20 @@ "type": "git", | ||
"engines": { | ||
"node": ">=8.11.2" | ||
"node": ">=12.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/fs-extra": "^7.0.0", | ||
"@types/mocha": "^5.2.7", | ||
"clang-format": "^1.2.4", | ||
"cmake-js": "^5.2.0", | ||
"fs-extra": "^8.0.1", | ||
"globby": "^9.2.0", | ||
"mocha": "^6.1.4", | ||
"node-addon-api": "^1.6.3", | ||
"node-pre-gyp-github": "^1.4.3", | ||
"@types/fs-extra": "^9.0.1", | ||
"@types/mocha": "^8.0.1", | ||
"clang-format": "^1.4.0", | ||
"fs-extra": "^9.0.1", | ||
"globby": "^11.0.1", | ||
"mocha": "^8.1.0", | ||
"onnx-proto": "^4.0.4", | ||
"typescript": "^3.5.1" | ||
"typescript": "^3.9.7" | ||
}, | ||
"dependencies": { | ||
"node-pre-gyp": "^0.13.0", | ||
"onnxjs": "^0.1.6" | ||
"onnxruntime": "^1.4.0" | ||
}, | ||
"peerDependencies": { | ||
"onnxjs": "0.x" | ||
} | ||
} |
@@ -18,7 +18,7 @@ [![npm version](https://badge.fury.io/js/onnxjs-node.svg)](https://badge.fury.io/js/onnxjs-node) | ||
---------|-----|--------|-------------|----------------|--------------------- | ||
Windows | x64 | CPU | v3 | v8.11.2+ | v0.4.0 | ||
Linux | x64 | CPU | v3 | v8.11.2+ | v0.4.0 | ||
macOS | x64 | CPU | v3 | v8.11.2+ | v0.4.0 | ||
Windows | x64 | GPU | v3 | v8.11.2+ | v0.4.0 | ||
Linux | x64 | GPU | v3 | v8.11.2+ | v0.4.0 | ||
Windows | x64 | CPU | v3 | v12.0.0+ | v1.4.0 | ||
Linux | x64 | CPU | v3 | v12.0.0+ | v1.4.0 | ||
macOS | x64 | CPU | v3 | v12.0.0+ | v1.4.0 | ||
Windows | x64 | GPU | v3 | v12.0.0+ | v1.4.0 | ||
Linux | x64 | GPU | v3 | v12.0.0+ | v1.4.0 | ||
@@ -57,5 +57,3 @@ ## Usage | ||
- [ONNX.js Home](https://github.com/Microsoft/onnxjs) | ||
- [ONNXRuntime](https://github.com/Microsoft/onnxruntime) | ||
- [Nuget package: Microsoft.ML.OnnxRuntime](https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime/) | ||
- [Nuget package: Microsoft.ML.OnnxRuntime.Gpu](https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime.Gpu/) | ||
- [ONNXRuntime Node.js binding](https://github.com/Microsoft/onnxruntime/nodejs) | ||
@@ -62,0 +60,0 @@ # License |
@@ -1,2 +0,1 @@ | ||
import * as onnxjs from 'onnxjs'; | ||
export = onnxjs; | ||
export = onnx; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8
0
0
0
14892
6
202
62
1
+ Addedonnxruntime@^1.4.0
+ Added@types/node@22.10.2(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbl@4.1.0(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addeddecompress-response@4.2.1(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedexpand-template@2.0.3(transitive)
+ Addedfs-constants@1.0.0(transitive)
+ Addedgithub-from-package@0.0.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedmimic-response@2.1.0(transitive)
+ Addedmkdirp-classic@0.5.3(transitive)
+ Addednapi-build-utils@1.0.2(transitive)
+ Addednode-abi@2.30.1(transitive)
+ Addedonnxruntime@1.7.0(transitive)
+ Addedprebuild-install@6.1.4(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@3.1.1(transitive)
+ Addedtar-fs@2.1.1(transitive)
+ Addedtar-stream@2.2.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
- Removednode-pre-gyp@^0.13.0
- Removedonnxjs@^0.1.6
- Removed@types/node@22.10.3(transitive)
- Removedabbrev@1.1.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removeddebug@3.2.7(transitive)
- Removedfs-minipass@1.2.7(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedignore-walk@3.0.4(transitive)
- Removedinflight@1.0.6(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedminipass@2.9.0(transitive)
- Removedminizlib@1.3.3(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedms@2.1.3(transitive)
- Removedneedle@2.9.1(transitive)
- Removednode-pre-gyp@0.13.0(transitive)
- Removednopt@4.0.3(transitive)
- Removednpm-bundled@1.1.2(transitive)
- Removednpm-normalize-package-bin@1.0.1(transitive)
- Removednpm-packlist@1.4.8(transitive)
- Removedos-homedir@1.0.2(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedosenv@0.1.5(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedrimraf@2.7.1(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsax@1.4.1(transitive)
- Removedtar@4.4.19(transitive)
- Removedyallist@3.1.1(transitive)