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

@tensorflow/tfjs-node

Package Overview
Dependencies
Maintainers
11
Versions
138
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tensorflow/tfjs-node - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

.nycrc

2

dist/index.js

@@ -9,3 +9,3 @@ "use strict";

return new nodejs_kernel_backend_1.NodeJSKernelBackend(bindings('tfjs_binding.node'));
});
}, 3);
if (tfc.ENV.findBackend('tensorflow') != null) {

@@ -12,0 +12,0 @@ tfc.setBackend('tensorflow');

@@ -45,3 +45,2 @@ "use strict";

var util_1 = require("util");
var io_utils_1 = require("./io_utils");
describe('File system IOHandler', function () {

@@ -252,3 +251,3 @@ var mkdtemp = util_1.promisify(fs.mkdtemp);

_a.sent();
weightsData2 = io_utils_1.toBuffer(new Float32Array([-7.7]).buffer);
weightsData2 = Buffer.from(new Float32Array([-7.7]).buffer);
return [4, writeFile(path.join(testDir, 'weights.2.bin'), weightsData2, 'binary')];

@@ -255,0 +254,0 @@ case 3:

@@ -95,5 +95,5 @@ "use strict";

return __awaiter(this, void 0, void 0, function () {
var exists, stat, readFile, modelJSON, _a, _b, modelArtifacts, dirName, buffers, weightSpecs, _i, _c, group, _d, _e, path, weightFilePath, buffer, _f;
return __generator(this, function (_g) {
switch (_g.label) {
var exists, stat, readFile, modelJSON, _a, _b, modelArtifacts, dirName, buffers, weightSpecs, _i, _c, group, _d, _e, path, weightFilePath, buffer;
return __generator(this, function (_f) {
switch (_f.label) {
case 0:

@@ -106,3 +106,3 @@ if (Array.isArray(this.path)) {

case 1:
if (!(_g.sent())) {
if (!(_f.sent())) {
throw new Error("Path " + this.path + " does not exist: loading failed.");

@@ -113,3 +113,3 @@ }

case 2:
if (!(_g.sent()).isFile()) return [3, 13];
if (!(_f.sent()).isFile()) return [3, 13];
readFile = util_1.promisify(fs.readFile);

@@ -119,3 +119,3 @@ _b = (_a = JSON).parse;

case 3:
modelJSON = _b.apply(_a, [_g.sent()]);
modelJSON = _b.apply(_a, [_f.sent()]);
modelArtifacts = {

@@ -129,3 +129,3 @@ modelTopology: modelJSON.modelTopology,

_i = 0, _c = modelJSON.weightsManifest;
_g.label = 4;
_f.label = 4;
case 4:

@@ -135,3 +135,3 @@ if (!(_i < _c.length)) return [3, 11];

_d = 0, _e = group.paths;
_g.label = 5;
_f.label = 5;
case 5:

@@ -143,11 +143,10 @@ if (!(_d < _e.length)) return [3, 9];

case 6:
if (!(_g.sent())) {
if (!(_f.sent())) {
throw new Error("Weight file " + weightFilePath + " does not exist: loading failed");
}
_f = Buffer.bind;
return [4, readFile(weightFilePath)];
case 7:
buffer = new (_f.apply(Buffer, [void 0, _g.sent()]))();
buffer = _f.sent();
buffers.push(buffer);
_g.label = 8;
_f.label = 8;
case 8:

@@ -158,3 +157,3 @@ _d++;

weightSpecs.push.apply(weightSpecs, group.weights);
_g.label = 10;
_f.label = 10;
case 10:

@@ -166,3 +165,3 @@ _i++;

modelArtifacts.weightData = io_utils_1.toArrayBuffer(buffers);
_g.label = 12;
_f.label = 12;
case 12: return [2, modelArtifacts];

@@ -169,0 +168,0 @@ case 13: throw new Error('The path to load from must be a file. Loading from a directory ' +

@@ -13,3 +13,3 @@ "use strict";

it('Single Buffer', function () {
var buf = new Buffer([10, 20, 30]);
var buf = Buffer.from([10, 20, 30]);
var ab = io_utils_1.toArrayBuffer(buf);

@@ -19,4 +19,4 @@ expect(new Uint8Array(ab)).toEqual(new Uint8Array([10, 20, 30]));

it('Two Buffers', function () {
var buf1 = new Buffer([10, 20, 30]);
var buf2 = new Buffer([40, 50, 60]);
var buf1 = Buffer.from([10, 20, 30]);
var buf2 = Buffer.from([40, 50, 60]);
var ab = io_utils_1.toArrayBuffer([buf1, buf2]);

@@ -28,5 +28,5 @@ expect(new Uint8Array(ab)).toEqual(new Uint8Array([

it('Three Buffers', function () {
var buf1 = new Buffer([10, 20, 30]);
var buf2 = new Buffer([40, 50, 60]);
var buf3 = new Buffer([3, 2, 1]);
var buf1 = Buffer.from([10, 20, 30]);
var buf2 = Buffer.from([40, 50, 60]);
var buf3 = Buffer.from([3, 2, 1]);
var ab = io_utils_1.toArrayBuffer([buf1, buf2, buf3]);

@@ -33,0 +33,0 @@ expect(new Uint8Array(ab)).toEqual(new Uint8Array([

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function toBuffer(ab) {
var buf = new Buffer(ab.byteLength);
var view = new Uint8Array(ab);
view.forEach(function (value, i) {
buf[i] = value;
});
return buf;
return Buffer.from(view);
}

@@ -14,24 +10,19 @@ exports.toBuffer = toBuffer;

if (Array.isArray(buf)) {
var totalLength_1 = 0;
buf.forEach(function (buffer) {
totalLength_1 += buffer.length;
});
var ab = new ArrayBuffer(totalLength_1);
var view_1 = new Uint8Array(ab);
var pos_1 = 0;
buf.forEach(function (buffer) {
for (var i = 0; i < buffer.length; ++i) {
view_1[pos_1++] = buffer[i];
}
});
return ab;
}
else {
var ab = new ArrayBuffer(buf.length);
var totalLength = 0;
for (var _i = 0, buf_1 = buf; _i < buf_1.length; _i++) {
var buffer = buf_1[_i];
totalLength += buffer.length;
}
var ab = new ArrayBuffer(totalLength);
var view = new Uint8Array(ab);
for (var i = 0; i < buf.length; ++i) {
view[i] = buf[i];
var pos = 0;
for (var _a = 0, buf_2 = buf; _a < buf_2.length; _a++) {
var buffer = buf_2[_a];
pos += buffer.copy(view, pos);
}
return ab;
}
else {
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
}
}

@@ -38,0 +29,0 @@ exports.toArrayBuffer = toArrayBuffer;

@@ -21,1 +21,6 @@ "use strict";

});
describe('type casting', function () {
it('exp support int32', function () {
tf.exp(tf.scalar(2, 'int32'));
});
});

@@ -23,3 +23,3 @@ import { BackendTimingInfo, DataType, KernelBackend, Rank, ShapeMap, Tensor, Tensor1D, Tensor2D, Tensor3D, Tensor4D } from '@tensorflow/tfjs-core';

matMul(a: Tensor2D, b: Tensor2D, transposeA: boolean, transposeB: boolean): Tensor2D;
stridedSlice<T extends Tensor<Rank>>(x: T, begin: number[], end: number[], strides: number[], beginMask: number, endMask: number): T;
stridedSlice<T extends Tensor>(x: T, begin: number[], end: number[], strides: number[], beginMask: number, endMask: number): T;
slice<T extends Tensor>(x: T, begin: number[], size: number[]): T;

@@ -32,5 +32,6 @@ reverse<T extends Tensor>(a: T, axis: number[]): T;

multiply(a: Tensor, b: Tensor): Tensor;
realDivide(a: Tensor<Rank>, b: Tensor<Rank>): Tensor<Rank>;
floorDiv(a: Tensor<Rank>, b: Tensor<Rank>): Tensor<Rank>;
realDivide(a: Tensor, b: Tensor): Tensor;
floorDiv(a: Tensor, b: Tensor): Tensor;
divide(a: Tensor, b: Tensor): Tensor;
unsortedSegmentSum<T extends Tensor>(x: T, segmentIds: Tensor1D, numSegments: number): Tensor;
sum(x: Tensor, axes: number[]): Tensor;

@@ -55,2 +56,4 @@ argMin(x: Tensor, axis: number): Tensor;

maximum(a: Tensor, b: Tensor): Tensor;
all(x: Tensor, axes: number[]): Tensor;
any(x: Tensor, axes: number[]): Tensor;
ceil<T extends Tensor>(x: T): T;

@@ -98,4 +101,4 @@ floor<T extends Tensor>(x: T): T;

conv2dDerFilter(x: Tensor4D, dy: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2DDerInput(dy: Tensor<Rank.R4>, filter: Tensor<Rank.R4>, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2DDerFilter(x: Tensor<Rank.R4>, dY: Tensor<Rank.R4>, convInfo: Conv2DInfo): Tensor<Rank.R4>;
depthwiseConv2DDerInput(dy: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2DDerFilter(x: Tensor4D, dY: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2D(input: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;

@@ -113,4 +116,5 @@ maxPool(x: Tensor4D, convInfo: Conv2DInfo): Tensor4D;

resizeBilinear(x: Tensor4D, newHeight: number, newWidth: number, alignCorners: boolean): Tensor4D;
resizeBilinearBackprop(dy: Tensor<Rank.R4>, x: Tensor<Rank.R4>, alignCorners: boolean): Tensor<Rank.R4>;
resizeBilinearBackprop(dy: Tensor4D, x: Tensor4D, alignCorners: boolean): Tensor4D;
resizeNearestNeighbor(x: Tensor4D, newHeight: number, newWidth: number, alignCorners: boolean): Tensor4D;
resizeNearestNeighborBackprop(dy: Tensor4D, x: Tensor4D, alignCorners: boolean): Tensor4D;
batchNormalization(x: Tensor4D, mean: Tensor1D | Tensor4D, variance: Tensor1D | Tensor4D, varianceEpsilon: number, scale?: Tensor1D | Tensor4D, offset?: Tensor1D | Tensor4D): Tensor4D;

@@ -120,3 +124,3 @@ localResponseNormalization4D(x: Tensor4D, radius: number, bias: number, alpha: number, beta: number): Tensor4D;

oneHot(indices: Tensor1D, depth: number, onValue: number, offValue: number): Tensor2D;
cumsum(x: Tensor<Rank>, axis: number, exclusive: boolean, reverse: boolean): Tensor<Rank>;
cumsum(x: Tensor, axis: number, exclusive: boolean, reverse: boolean): Tensor;
fromPixels(pixels: ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement, numChannels: number): Tensor3D;

@@ -123,0 +127,0 @@ memory(): {

@@ -122,5 +122,3 @@ "use strict";

};
NodeJSKernelBackend.prototype.dispose = function () {
throw new Error('Method not implemented.');
};
NodeJSKernelBackend.prototype.dispose = function () { };
NodeJSKernelBackend.prototype.read = function (dataId) {

@@ -241,2 +239,10 @@ return __awaiter(this, void 0, void 0, function () {

};
NodeJSKernelBackend.prototype.unsortedSegmentSum = function (x, segmentIds, numSegments) {
var opAttrs = [
this.createTypeOpAttr('T', x.dtype),
this.createTypeOpAttr('Tindices', 'int32'),
this.createTypeOpAttr('Tnumsegments', 'int32')
];
return this.executeSingleOutput('UnsortedSegmentSum', opAttrs, [x, segmentIds, tfjs_core_1.scalar(numSegments, 'int32')]);
};
NodeJSKernelBackend.prototype.sum = function (x, axes) {

@@ -323,2 +329,18 @@ var axisTensor = tfjs_core_1.tensor1d(axes, 'int32');

};
NodeJSKernelBackend.prototype.all = function (x, axes) {
var opAttrs = [
{ name: 'keep_dims', type: this.binding.TF_ATTR_BOOL, value: false },
this.createTypeOpAttr('Tidx', 'int32')
];
var axesTensor = tfjs_core_1.tensor1d(axes, 'int32');
return this.executeSingleOutput('All', opAttrs, [x, axesTensor]);
};
NodeJSKernelBackend.prototype.any = function (x, axes) {
var opAttrs = [
{ name: 'keep_dims', type: this.binding.TF_ATTR_BOOL, value: false },
this.createTypeOpAttr('Tidx', 'int32')
];
var axesTensor = tfjs_core_1.tensor1d(axes, 'int32');
return this.executeSingleOutput('Any', opAttrs, [x, axesTensor]);
};
NodeJSKernelBackend.prototype.ceil = function (x) {

@@ -331,7 +353,9 @@ return this.executeSingleInput('Ceil', x);

NodeJSKernelBackend.prototype.pow = function (a, b) {
var opAttrs = [this.createTypeOpAttr('T', types_1.upcastType(a.dtype, b.dtype))];
return this.executeSingleOutput('Pow', opAttrs, [a, b]);
var dtype = types_1.upcastType(a.dtype, b.dtype);
var opAttrs = [this.createTypeOpAttr('T', dtype)];
return this.executeSingleOutput('Pow', opAttrs, [a.cast(dtype), b.cast(dtype)]);
};
NodeJSKernelBackend.prototype.exp = function (x) {
return this.executeSingleInput('Exp', x);
var xTensor = x.dtype === 'int32' ? x.toFloat() : x;
return this.executeSingleInput('Exp', xTensor);
};

@@ -748,2 +772,14 @@ NodeJSKernelBackend.prototype.log = function (x) {

};
NodeJSKernelBackend.prototype.resizeNearestNeighborBackprop = function (dy, x, alignCorners) {
var opAttrs = [
this.createTypeOpAttr('T', x.dtype), {
name: 'align_corners',
type: this.binding.TF_ATTR_BOOL,
value: alignCorners
}
];
var _a = x.shape, origHeight = _a[1], origWidth = _a[2];
var size = tfjs_core_1.tensor1d([origHeight, origWidth], 'int32');
return this.executeSingleOutput('ResizeNearestNeighborGrad', opAttrs, [dy, size]);
};
NodeJSKernelBackend.prototype.batchNormalization = function (x, mean, variance, varianceEpsilon, scale, offset) {

@@ -830,3 +866,28 @@ if (mean.rank > 1) {

NodeJSKernelBackend.prototype.fromPixels = function (pixels, numChannels) {
throw new Error('Method not implemented.');
if (pixels == null) {
throw new Error('pixels passed to tf.fromPixels() can not be null');
}
if (pixels.getContext == null) {
throw new Error('When running in node, pixels must be an HTMLCanvasElement ' +
'like the one returned by the `canvas` npm package');
}
var vals = pixels
.getContext('2d')
.getImageData(0, 0, pixels.width, pixels.height)
.data;
var values;
if (numChannels === 4) {
values = new Int32Array(vals);
}
else {
var numPixels = pixels.width * pixels.height;
values = new Int32Array(numPixels * numChannels);
for (var i = 0; i < numPixels; i++) {
for (var channel = 0; channel < numChannels; ++channel) {
values[i * numChannels + channel] = vals[i * 4 + channel];
}
}
}
var outShape = [pixels.height, pixels.width, numChannels];
return tfjs_core_1.tensor3d(values, outShape, 'int32');
};

@@ -833,0 +894,0 @@ NodeJSKernelBackend.prototype.memory = function () {

@@ -5,13 +5,16 @@ "use strict";

var jasmine_util = require("@tensorflow/tfjs-core/dist/jasmine_util");
Error.stackTraceLimit = Infinity;
var jasmineCtor = require('jasmine');
jasmine_util.setBeforeAll(function () { });
jasmine_util.setAfterAll(function () { });
jasmine_util.setBeforeEach(function () { });
jasmine_util.setAfterEach(function () { });
jasmine_util.setTestEnvFeatures([{ BACKEND: 'tensorflow' }]);
var bindings = require("bindings");
var nodejs_kernel_backend_1 = require("./nodejs_kernel_backend");
jasmine_util.setTestEnvs([{
name: 'test-tensorflow',
factory: function () {
return new nodejs_kernel_backend_1.NodeJSKernelBackend(bindings('tfjs_binding.node'));
},
features: {}
}]);
var IGNORE_LIST = [
'depthwiseConv2D',
'separableConv2d',
'IORouterRegistry',
'arrayBufferToBase64String', 'stringByteLength'
];

@@ -22,4 +25,8 @@ var runner = new jasmineCtor();

'src/**/*_test.ts', 'node_modules/@tensorflow/tfjs-core/dist/**/*_test.js'
]
],
random: false
});
if (process.env.JASMINE_SEED) {
runner.seed(process.env.JASMINE_SEED);
}
var env = jasmine.getEnv();

@@ -26,0 +33,0 @@ env.specFilter = function (spec) {

@@ -1,2 +0,2 @@

declare const version = "0.1.7";
declare const version = "0.1.8";
export { version };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var version = '0.1.7';
var version = '0.1.8';
exports.version = version;
{
"name": "@tensorflow/tfjs-node",
"version": "0.1.7",
"version": "0.1.8",
"main": "dist/index.js",

@@ -20,12 +20,15 @@ "types": "dist/index.d.ts",

"test": "ts-node src/run_tests.ts",
"coverage": "nyc ts-node src/run_tests.ts",
"link-local": "yalc link",
"publish-local": "yarn prep && yarn build && yalc push"
},
"devDependencies": {
"@tensorflow/tfjs-core": "~0.11.5",
"@tensorflow/tfjs-core": "~0.12.1",
"@types/bindings": "~1.3.0",
"@types/jasmine": "~2.8.6",
"@types/node": "~9.6.2",
"@types/node": "^10.5.1",
"@types/rimraf": "~2.0.2",
"clang-format": "~1.2.2",
"jasmine": "~3.1.0",
"nyc": "^12.0.2",
"ts-node": "~5.0.0",

@@ -40,4 +43,4 @@ "tslint": "~5.9.1",

"peerDependencies": {
"@tensorflow/tfjs-core": "~0.11.5"
"@tensorflow/tfjs-core": "~0.12.1"
}
}
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