Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

onnxjs-node

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

onnxjs-node - npm Package Compare versions

Comparing version 0.4.1 to 1.4.0

29

lib/index.js
"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

159

lib/inference-session-override.js
"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;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc