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

@tensorflow/tfjs-core

Package Overview
Dependencies
Maintainers
11
Versions
187
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tensorflow/tfjs-core - npm Package Compare versions

Comparing version 0.11.3 to 0.11.4

dist-es6/kernels/webgl/conv_backprop_gpu_depthwise.d.ts

74

dist-es6/io/local_storage_test.js

@@ -0,1 +1,37 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var _this = this;
import * as tf from '../index';

@@ -118,22 +154,22 @@ import { describeWithFlags } from '../jasmine_util';

});
it('Save-load round trip succeeds', function (done) {
var handler1 = tf.io.getSaveHandlers('localstorage://FooModel')[0];
handler1.save(artifacts1)
.then(function (saveResult) {
var handler2 = tf.io.getLoadHandlers('localstorage://FooModel')[0];
handler2.load()
.then(function (loaded) {
expect(loaded.modelTopology).toEqual(modelTopology1);
expect(loaded.weightSpecs).toEqual(weightSpecs1);
expect(loaded.weightData).toEqual(weightData1);
done();
})
.catch(function (err) {
console.error(err.stack);
});
})
.catch(function (err) {
console.error(err.stack);
it('Save-load round trip succeeds', function () { return __awaiter(_this, void 0, void 0, function () {
var handler1, handler2, loaded;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
handler1 = tf.io.getSaveHandlers('localstorage://FooModel')[0];
return [4, handler1.save(artifacts1)];
case 1:
_a.sent();
handler2 = tf.io.getLoadHandlers('localstorage://FooModel')[0];
return [4, handler2.load()];
case 2:
loaded = _a.sent();
expect(loaded.modelTopology).toEqual(modelTopology1);
expect(loaded.weightSpecs).toEqual(weightSpecs1);
expect(loaded.weightData).toEqual(weightData1);
return [2];
}
});
});
}); });
it('Loading nonexistent model fails.', function (done) {

@@ -140,0 +176,0 @@ var handler = tf.io.getSaveHandlers('localstorage://NonexistentModel')[0];

@@ -95,2 +95,4 @@ import { Conv2DInfo } from '../ops/conv_util';

depthwiseConv2D(x: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2DDerInput(dy: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2DDerFilter(x: Tensor4D, dy: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
tile<T extends Tensor>(x: T, reps: number[]): T;

@@ -97,0 +99,0 @@ pad<T extends Tensor>(x: T, paddings: Array<[number, number]>, constantValue: number): T;

@@ -130,2 +130,4 @@ import { TimingInfo } from '../engine';

depthwiseConv2D(x: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2DDerInput(dy: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2DDerFilter(x: Tensor4D, dy: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
maxPool(x: Tensor4D, convInfo: Conv2DInfo): Tensor4D;

@@ -132,0 +134,0 @@ avgPool(x: Tensor4D, convInfo: Conv2DInfo): Tensor4D;

@@ -53,2 +53,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import { Conv2DDerFilterProgram, Conv2DDerInputProgram } from './webgl/conv_backprop_gpu';
import { DepthwiseConv2DDerFilterProgram, DepthwiseConv2DDerInputProgram } from './webgl/conv_backprop_gpu_depthwise';
import { Conv2DProgram } from './webgl/conv_gpu';

@@ -730,2 +731,10 @@ import { DepthwiseConv2DProgram } from './webgl/conv_gpu_depthwise';

};
MathBackendWebGL.prototype.depthwiseConv2DDerInput = function (dy, filter, convInfo) {
var program = new DepthwiseConv2DDerInputProgram(convInfo);
return this.compileAndRun(program, [dy, filter]);
};
MathBackendWebGL.prototype.depthwiseConv2DDerFilter = function (x, dy, convInfo) {
var program = new DepthwiseConv2DDerFilterProgram(convInfo);
return this.compileAndRun(program, [x, dy]);
};
MathBackendWebGL.prototype.maxPool = function (x, convInfo) {

@@ -732,0 +741,0 @@ var program = new Pool2DProgram(convInfo, 'max', false);

@@ -94,2 +94,4 @@ import { Conv2DInfo } from '../ops/conv_util';

depthwiseConv2D(input: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2DDerInput(dy: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2DDerFilter(x: Tensor4D, dY: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
maxPool(x: Tensor4D, convInfo: Conv2DInfo): Tensor4D;

@@ -96,0 +98,0 @@ maxPoolBackprop(dy: Tensor4D, x: Tensor4D, y: Tensor4D, convInfo: Conv2DInfo): Tensor4D;

@@ -165,7 +165,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

}
util.assert(x4D.rank === 4, "Error in depthwiseConv2D: input must be rank 4, but got " +
util.assert(x4D.rank === 4, "Error in depthwiseConv2d: input must be rank 4, but got " +
("rank " + x4D.rank + "."));
util.assert(filter.rank === 4, "Error in depthwiseConv2D: filter must be rank 4, but got rank " +
util.assert(filter.rank === 4, "Error in depthwiseConv2d: filter must be rank 4, but got rank " +
(filter.rank + "."));
util.assert(x4D.shape[3] === filter.shape[2], "Error in depthwiseConv2D: number of input channels " +
util.assert(x4D.shape[3] === filter.shape[2], "Error in depthwiseConv2d: number of input channels " +
("(" + x4D.shape[3] + ") must match the inChannels dimension in ") +

@@ -179,7 +179,15 @@ ("filter " + filter.shape[2] + "."));

if (dimRoundingMode != null) {
util.assert(util.isInt(pad), "Error in depthwiseConv2D: pad must be an integer when using, " +
util.assert(util.isInt(pad), "Error in depthwiseConv2d: pad must be an integer when using, " +
("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + "."));
}
var convInfo = conv_util.computeConv2DInfo(x4D.shape, filter.shape, strides, dilations, pad, dimRoundingMode, true);
var res = ENV.engine.runKernel(function (backend) { return backend.depthwiseConv2D(x4D, filter, convInfo); }, { x4D: x4D, filter: filter });
var grad = function (dy) {
util.assert(tupleValuesAreOne(dilations), 'Error in gradient of depthwiseConv2d: dilation rates greater than ' +
("1 are not yet supported. Got dilations '" + dilations + "'"));
return {
x: function () { return depthwiseConv2dDerInput(x4D.shape, dy, filter, convInfo); },
filter: function () { return depthwiseConv2dDerFilter(x4D, dy, filter.shape, convInfo); },
};
};
var res = ENV.engine.runKernel(function (backend) { return backend.depthwiseConv2D(x4D, filter, convInfo); }, { x: x4D, filter: filter }, grad);
if (reshapedTo4D) {

@@ -266,2 +274,26 @@ return res.as3D(res.shape[1], res.shape[2], res.shape[3]);

}
function depthwiseConv2dDerInput(xShape, dy, filter, convInfo) {
var dy4D = dy;
var reshapedTo4D = false;
if (dy.rank === 3) {
reshapedTo4D = true;
dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]);
}
var res = ENV.engine.runKernel(function (backend) { return backend.depthwiseConv2DDerInput(dy4D, filter, convInfo); }, { dy4D: dy4D });
if (reshapedTo4D) {
return res.as3D(res.shape[1], res.shape[2], res.shape[3]);
}
return res;
}
function depthwiseConv2dDerFilter(x, dy, filterShape, convInfo) {
var x4D = x;
if (x.rank === 3) {
x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);
}
var dy4D = dy;
if (dy4D.rank === 3) {
dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]);
}
return ENV.engine.runKernel(function (backend) { return backend.depthwiseConv2DDerFilter(x4D, dy4D, convInfo); }, { x4D: x4D, dy4D: dy4D });
}
//# sourceMappingURL=conv.js.map

@@ -246,2 +246,127 @@ import * as tf from '../index';

});
describeWithFlags('depthwiseConv2d gradients', ALL_ENVS, function () {
var images;
var filter;
var result;
var stride = 1;
var pad = 'same';
beforeEach(function () {
images = tf.tensor4d([[
[[2, 3, 1], [3, 0, 2]],
[[0, 4, 1], [3, 1, 3]]
], [
[[2, 1, 0], [0, 3, 3]],
[[4, 0, 1], [1, 4, 1]]
]]);
filter = tf.tensor4d([[
[[1, 1], [1, 1], [0, 0]],
[[0, 1], [1, 1], [1, 1]]
], [
[[1, 0], [1, 1], [0, 0]],
[[0, 1], [1, 0], [0, 0]]
]]);
result = tf.tensor4d([[
[[2, 8, 8, 7, 2, 2], [6, 3, 1, 1, 0, 0]],
[[0, 3, 5, 5, 3, 3], [3, 3, 1, 1, 0, 0]]
], [
[[6, 3, 8, 4, 3, 3], [1, 0, 7, 7, 0, 0]],
[[4, 5, 4, 4, 1, 1], [1, 1, 4, 4, 0, 0]]
]]);
});
it('wrt input', function () {
var _a = tf.valueAndGrad(function (x) { return tf.depthwiseConv2d(x, filter, stride, pad); })(images), value = _a.value, grad = _a.grad;
expectArraysClose(value, result);
var expectedGrad = tf.tensor4d([[
[[2., 2., 0.], [3., 4., 2.]],
[[3., 4., 0.], [5., 7., 2.]]
], [
[[2., 2., 0.], [3., 4., 2.]],
[[3., 4., 0.], [5., 7., 2.]]
]]);
expectArraysClose(grad, expectedGrad);
});
it('wrt input, squared output', function () {
var grad = tf.grad(function (x) { return tf.square(tf.depthwiseConv2d(x, filter, stride, pad)); })(images);
var expectedGrad = tf.tensor4d([[
[[20., 30., 0.], [34., 34., 8.]],
[[10., 50., 0.], [46., 44., 12.]]
], [
[[18., 24., 0.], [8., 52., 12.]],
[[30., 40., 0.], [22., 76., 4.]]
]]);
expectArraysClose(grad, expectedGrad);
});
it('wrt filter', function () {
var _a = tf.valueAndGrad(function (f) { return tf.depthwiseConv2d(images, f, stride, pad); })(filter), value = _a.value, grad = _a.grad;
expectArraysClose(value, result);
var expectedGrad = tf.tensor4d([[
[[15., 15.], [16., 16.], [12., 12.]],
[[7., 7.], [8., 8.], [9., 9.]]
], [
[[8., 8.], [9., 9.], [6., 6.]],
[[4., 4.], [5., 5.], [4., 4.]]
]]);
expectArraysClose(grad, expectedGrad);
});
it('wrt filter, squared output', function () {
var grad = tf.grad(function (f) { return tf.square(tf.depthwiseConv2d(images, f, stride, pad)); })(filter);
var expectedGrad = tf.tensor4d([[
[[120., 122.], [180., 166.], [12., 12.]],
[[20., 76.], [90., 66.], [46., 46.]]
], [
[[86., 42.], [122., 114.], [10., 10.]],
[[24., 54.], [80., 46.], [18., 18.]]
]]);
expectArraysClose(grad, expectedGrad);
});
it('throws error on dilations > 1', function () {
var grad = tf.grad(function (x) { return tf.depthwiseConv2d(x, filter, stride, pad, 'NHWC', 2); });
expect(function () { return grad(images); })
.toThrowError(/dilation rates greater than 1 are not yet supported/);
});
it('wrt input, stride=2, pad=valid', function () {
var dx = tf.grad(function (x) { return tf.depthwiseConv2d(x, filter, 2, 'valid'); })(images);
expectArraysClose(dx, tf.tensor4d([[
[[2., 2., 0.], [1., 2., 2.]],
[[1., 2., 0.], [1., 1., 0.]]
], [
[[2., 2., 0.], [1., 2., 2.]],
[[1., 2., 0.], [1., 1., 0.]]
]]));
});
it('wrt filter, stride=2, pad=valid', function () {
var df = tf.grad(function (f) { return tf.depthwiseConv2d(images, f, 2, 'valid'); })(filter);
expectArraysClose(df, tf.tensor4d([[
[[4., 4.], [4., 4.], [1., 1.]],
[[3., 3.], [3., 3.], [5., 5.]]
], [
[[4., 4.], [4., 4.], [2., 2.]],
[[4., 4.], [5., 5.], [4., 4.]]
]]));
});
it('wrt input and filter, 1x3x3x1 and 2x2x1x1', function () {
var fSize = 2;
var pad = 'valid';
var stride = 1;
var chMul = 1;
var inDepth = 1;
var x = tf.tensor4d([
0.230664, 0.987388, 0.0685208, 0.419224, 0.887861, 0.731641,
0.0741907, 0.409265, 0.351377
], [1, 3, 3, inDepth]);
var f = tf.tensor4d([0.303873, 0.229223, 0.144333, 0.803373], [fSize, fSize, inDepth, chMul]);
var _a = tf.grads(function (x, f) { return tf.depthwiseConv2d(x, f, stride, pad); })([x, f]), dx = _a[0], df = _a[1];
expectArraysClose(dx, tf.tensor4d([[
[[0.303873], [0.533096], [0.229223]],
[[0.448206], [1.480802], [1.032596]],
[[0.144333], [0.947706], [0.803373]]
]]));
expectArraysClose(df, tf.tensor4d([
[[[2.525137]], [[2.6754108]]
], [
[[1.7905407]], [[2.380144]]
]
]));
});
});
//# sourceMappingURL=conv2d_depthwise_test.js.map

@@ -41,3 +41,3 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

util.assertArgumentsAreTensors({ condition: condition, a: a, b: b }, 'where');
util.assert(condition.dtype === 'bool' || a.dtype === 'bool' || b.dtype === 'bool', 'Error Array must be of type bool.');
util.assert(condition.dtype === 'bool', 'Error Condition must be of type bool.');
util.assertShapesMatch(a.shape, b.shape, 'Error in where: ');

@@ -44,0 +44,0 @@ if (condition.rank === 1) {

@@ -266,2 +266,11 @@ import * as tf from '../index';

});
it('Invalid condition type', function () {
var c = tf.tensor1d([1, 0, 1, 0], 'int32');
var a = tf.tensor1d([10, 10, 10, 10], 'bool');
var b = tf.tensor1d([20, 20, 20, 20], 'bool');
var f = function () {
tf.where(c, a, b);
};
expect(f).toThrowError();
});
it('Tensor1D', function () {

@@ -268,0 +277,0 @@ var c = tf.tensor1d([1, 0, 1, 0], 'bool');

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

declare const version = "0.11.3";
declare const version = "0.11.4";
export { version };

@@ -1,3 +0,3 @@

var version = '0.11.3';
var version = '0.11.4';
export { version };
//# sourceMappingURL=version.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -120,22 +156,22 @@ var tf = require("../index");

});
it('Save-load round trip succeeds', function (done) {
var handler1 = tf.io.getSaveHandlers('localstorage://FooModel')[0];
handler1.save(artifacts1)
.then(function (saveResult) {
var handler2 = tf.io.getLoadHandlers('localstorage://FooModel')[0];
handler2.load()
.then(function (loaded) {
expect(loaded.modelTopology).toEqual(modelTopology1);
expect(loaded.weightSpecs).toEqual(weightSpecs1);
expect(loaded.weightData).toEqual(weightData1);
done();
})
.catch(function (err) {
console.error(err.stack);
});
})
.catch(function (err) {
console.error(err.stack);
it('Save-load round trip succeeds', function () { return __awaiter(_this, void 0, void 0, function () {
var handler1, handler2, loaded;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
handler1 = tf.io.getSaveHandlers('localstorage://FooModel')[0];
return [4, handler1.save(artifacts1)];
case 1:
_a.sent();
handler2 = tf.io.getLoadHandlers('localstorage://FooModel')[0];
return [4, handler2.load()];
case 2:
loaded = _a.sent();
expect(loaded.modelTopology).toEqual(modelTopology1);
expect(loaded.weightSpecs).toEqual(weightSpecs1);
expect(loaded.weightData).toEqual(weightData1);
return [2];
}
});
});
}); });
it('Loading nonexistent model fails.', function (done) {

@@ -142,0 +178,0 @@ var handler = tf.io.getSaveHandlers('localstorage://NonexistentModel')[0];

@@ -95,2 +95,4 @@ import { Conv2DInfo } from '../ops/conv_util';

depthwiseConv2D(x: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2DDerInput(dy: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2DDerFilter(x: Tensor4D, dy: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
tile<T extends Tensor>(x: T, reps: number[]): T;

@@ -97,0 +99,0 @@ pad<T extends Tensor>(x: T, paddings: Array<[number, number]>, constantValue: number): T;

@@ -130,2 +130,4 @@ import { TimingInfo } from '../engine';

depthwiseConv2D(x: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2DDerInput(dy: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2DDerFilter(x: Tensor4D, dy: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
maxPool(x: Tensor4D, convInfo: Conv2DInfo): Tensor4D;

@@ -132,0 +134,0 @@ avgPool(x: Tensor4D, convInfo: Conv2DInfo): Tensor4D;

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

var conv_backprop_gpu_1 = require("./webgl/conv_backprop_gpu");
var conv_backprop_gpu_depthwise_1 = require("./webgl/conv_backprop_gpu_depthwise");
var conv_gpu_1 = require("./webgl/conv_gpu");

@@ -732,2 +733,10 @@ var conv_gpu_depthwise_1 = require("./webgl/conv_gpu_depthwise");

};
MathBackendWebGL.prototype.depthwiseConv2DDerInput = function (dy, filter, convInfo) {
var program = new conv_backprop_gpu_depthwise_1.DepthwiseConv2DDerInputProgram(convInfo);
return this.compileAndRun(program, [dy, filter]);
};
MathBackendWebGL.prototype.depthwiseConv2DDerFilter = function (x, dy, convInfo) {
var program = new conv_backprop_gpu_depthwise_1.DepthwiseConv2DDerFilterProgram(convInfo);
return this.compileAndRun(program, [x, dy]);
};
MathBackendWebGL.prototype.maxPool = function (x, convInfo) {

@@ -734,0 +743,0 @@ var program = new pool_gpu_1.Pool2DProgram(convInfo, 'max', false);

@@ -94,2 +94,4 @@ import { Conv2DInfo } from '../ops/conv_util';

depthwiseConv2D(input: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2DDerInput(dy: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
depthwiseConv2DDerFilter(x: Tensor4D, dY: Tensor4D, convInfo: Conv2DInfo): Tensor4D;
maxPool(x: Tensor4D, convInfo: Conv2DInfo): Tensor4D;

@@ -96,0 +98,0 @@ maxPoolBackprop(dy: Tensor4D, x: Tensor4D, y: Tensor4D, convInfo: Conv2DInfo): Tensor4D;

@@ -167,7 +167,7 @@ "use strict";

}
util.assert(x4D.rank === 4, "Error in depthwiseConv2D: input must be rank 4, but got " +
util.assert(x4D.rank === 4, "Error in depthwiseConv2d: input must be rank 4, but got " +
("rank " + x4D.rank + "."));
util.assert(filter.rank === 4, "Error in depthwiseConv2D: filter must be rank 4, but got rank " +
util.assert(filter.rank === 4, "Error in depthwiseConv2d: filter must be rank 4, but got rank " +
(filter.rank + "."));
util.assert(x4D.shape[3] === filter.shape[2], "Error in depthwiseConv2D: number of input channels " +
util.assert(x4D.shape[3] === filter.shape[2], "Error in depthwiseConv2d: number of input channels " +
("(" + x4D.shape[3] + ") must match the inChannels dimension in ") +

@@ -181,7 +181,15 @@ ("filter " + filter.shape[2] + "."));

if (dimRoundingMode != null) {
util.assert(util.isInt(pad), "Error in depthwiseConv2D: pad must be an integer when using, " +
util.assert(util.isInt(pad), "Error in depthwiseConv2d: pad must be an integer when using, " +
("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + "."));
}
var convInfo = conv_util.computeConv2DInfo(x4D.shape, filter.shape, strides, dilations, pad, dimRoundingMode, true);
var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.depthwiseConv2D(x4D, filter, convInfo); }, { x4D: x4D, filter: filter });
var grad = function (dy) {
util.assert(tupleValuesAreOne(dilations), 'Error in gradient of depthwiseConv2d: dilation rates greater than ' +
("1 are not yet supported. Got dilations '" + dilations + "'"));
return {
x: function () { return depthwiseConv2dDerInput(x4D.shape, dy, filter, convInfo); },
filter: function () { return depthwiseConv2dDerFilter(x4D, dy, filter.shape, convInfo); },
};
};
var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.depthwiseConv2D(x4D, filter, convInfo); }, { x: x4D, filter: filter }, grad);
if (reshapedTo4D) {

@@ -268,2 +276,26 @@ return res.as3D(res.shape[1], res.shape[2], res.shape[3]);

}
function depthwiseConv2dDerInput(xShape, dy, filter, convInfo) {
var dy4D = dy;
var reshapedTo4D = false;
if (dy.rank === 3) {
reshapedTo4D = true;
dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]);
}
var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.depthwiseConv2DDerInput(dy4D, filter, convInfo); }, { dy4D: dy4D });
if (reshapedTo4D) {
return res.as3D(res.shape[1], res.shape[2], res.shape[3]);
}
return res;
}
function depthwiseConv2dDerFilter(x, dy, filterShape, convInfo) {
var x4D = x;
if (x.rank === 3) {
x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);
}
var dy4D = dy;
if (dy4D.rank === 3) {
dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]);
}
return environment_1.ENV.engine.runKernel(function (backend) { return backend.depthwiseConv2DDerFilter(x4D, dy4D, convInfo); }, { x4D: x4D, dy4D: dy4D });
}
//# sourceMappingURL=conv.js.map

@@ -248,2 +248,127 @@ "use strict";

});
jasmine_util_1.describeWithFlags('depthwiseConv2d gradients', test_util_1.ALL_ENVS, function () {
var images;
var filter;
var result;
var stride = 1;
var pad = 'same';
beforeEach(function () {
images = tf.tensor4d([[
[[2, 3, 1], [3, 0, 2]],
[[0, 4, 1], [3, 1, 3]]
], [
[[2, 1, 0], [0, 3, 3]],
[[4, 0, 1], [1, 4, 1]]
]]);
filter = tf.tensor4d([[
[[1, 1], [1, 1], [0, 0]],
[[0, 1], [1, 1], [1, 1]]
], [
[[1, 0], [1, 1], [0, 0]],
[[0, 1], [1, 0], [0, 0]]
]]);
result = tf.tensor4d([[
[[2, 8, 8, 7, 2, 2], [6, 3, 1, 1, 0, 0]],
[[0, 3, 5, 5, 3, 3], [3, 3, 1, 1, 0, 0]]
], [
[[6, 3, 8, 4, 3, 3], [1, 0, 7, 7, 0, 0]],
[[4, 5, 4, 4, 1, 1], [1, 1, 4, 4, 0, 0]]
]]);
});
it('wrt input', function () {
var _a = tf.valueAndGrad(function (x) { return tf.depthwiseConv2d(x, filter, stride, pad); })(images), value = _a.value, grad = _a.grad;
test_util_1.expectArraysClose(value, result);
var expectedGrad = tf.tensor4d([[
[[2., 2., 0.], [3., 4., 2.]],
[[3., 4., 0.], [5., 7., 2.]]
], [
[[2., 2., 0.], [3., 4., 2.]],
[[3., 4., 0.], [5., 7., 2.]]
]]);
test_util_1.expectArraysClose(grad, expectedGrad);
});
it('wrt input, squared output', function () {
var grad = tf.grad(function (x) { return tf.square(tf.depthwiseConv2d(x, filter, stride, pad)); })(images);
var expectedGrad = tf.tensor4d([[
[[20., 30., 0.], [34., 34., 8.]],
[[10., 50., 0.], [46., 44., 12.]]
], [
[[18., 24., 0.], [8., 52., 12.]],
[[30., 40., 0.], [22., 76., 4.]]
]]);
test_util_1.expectArraysClose(grad, expectedGrad);
});
it('wrt filter', function () {
var _a = tf.valueAndGrad(function (f) { return tf.depthwiseConv2d(images, f, stride, pad); })(filter), value = _a.value, grad = _a.grad;
test_util_1.expectArraysClose(value, result);
var expectedGrad = tf.tensor4d([[
[[15., 15.], [16., 16.], [12., 12.]],
[[7., 7.], [8., 8.], [9., 9.]]
], [
[[8., 8.], [9., 9.], [6., 6.]],
[[4., 4.], [5., 5.], [4., 4.]]
]]);
test_util_1.expectArraysClose(grad, expectedGrad);
});
it('wrt filter, squared output', function () {
var grad = tf.grad(function (f) { return tf.square(tf.depthwiseConv2d(images, f, stride, pad)); })(filter);
var expectedGrad = tf.tensor4d([[
[[120., 122.], [180., 166.], [12., 12.]],
[[20., 76.], [90., 66.], [46., 46.]]
], [
[[86., 42.], [122., 114.], [10., 10.]],
[[24., 54.], [80., 46.], [18., 18.]]
]]);
test_util_1.expectArraysClose(grad, expectedGrad);
});
it('throws error on dilations > 1', function () {
var grad = tf.grad(function (x) { return tf.depthwiseConv2d(x, filter, stride, pad, 'NHWC', 2); });
expect(function () { return grad(images); })
.toThrowError(/dilation rates greater than 1 are not yet supported/);
});
it('wrt input, stride=2, pad=valid', function () {
var dx = tf.grad(function (x) { return tf.depthwiseConv2d(x, filter, 2, 'valid'); })(images);
test_util_1.expectArraysClose(dx, tf.tensor4d([[
[[2., 2., 0.], [1., 2., 2.]],
[[1., 2., 0.], [1., 1., 0.]]
], [
[[2., 2., 0.], [1., 2., 2.]],
[[1., 2., 0.], [1., 1., 0.]]
]]));
});
it('wrt filter, stride=2, pad=valid', function () {
var df = tf.grad(function (f) { return tf.depthwiseConv2d(images, f, 2, 'valid'); })(filter);
test_util_1.expectArraysClose(df, tf.tensor4d([[
[[4., 4.], [4., 4.], [1., 1.]],
[[3., 3.], [3., 3.], [5., 5.]]
], [
[[4., 4.], [4., 4.], [2., 2.]],
[[4., 4.], [5., 5.], [4., 4.]]
]]));
});
it('wrt input and filter, 1x3x3x1 and 2x2x1x1', function () {
var fSize = 2;
var pad = 'valid';
var stride = 1;
var chMul = 1;
var inDepth = 1;
var x = tf.tensor4d([
0.230664, 0.987388, 0.0685208, 0.419224, 0.887861, 0.731641,
0.0741907, 0.409265, 0.351377
], [1, 3, 3, inDepth]);
var f = tf.tensor4d([0.303873, 0.229223, 0.144333, 0.803373], [fSize, fSize, inDepth, chMul]);
var _a = tf.grads(function (x, f) { return tf.depthwiseConv2d(x, f, stride, pad); })([x, f]), dx = _a[0], df = _a[1];
test_util_1.expectArraysClose(dx, tf.tensor4d([[
[[0.303873], [0.533096], [0.229223]],
[[0.448206], [1.480802], [1.032596]],
[[0.144333], [0.947706], [0.803373]]
]]));
test_util_1.expectArraysClose(df, tf.tensor4d([
[[[2.525137]], [[2.6754108]]
], [
[[1.7905407]], [[2.380144]]
]
]));
});
});
//# sourceMappingURL=conv2d_depthwise_test.js.map

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

util.assertArgumentsAreTensors({ condition: condition, a: a, b: b }, 'where');
util.assert(condition.dtype === 'bool' || a.dtype === 'bool' || b.dtype === 'bool', 'Error Array must be of type bool.');
util.assert(condition.dtype === 'bool', 'Error Condition must be of type bool.');
util.assertShapesMatch(a.shape, b.shape, 'Error in where: ');

@@ -46,0 +46,0 @@ if (condition.rank === 1) {

@@ -268,2 +268,11 @@ "use strict";

});
it('Invalid condition type', function () {
var c = tf.tensor1d([1, 0, 1, 0], 'int32');
var a = tf.tensor1d([10, 10, 10, 10], 'bool');
var b = tf.tensor1d([20, 20, 20, 20], 'bool');
var f = function () {
tf.where(c, a, b);
};
expect(f).toThrowError();
});
it('Tensor1D', function () {

@@ -270,0 +279,0 @@ var c = tf.tensor1d([1, 0, 1, 0], 'bool');

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

declare const version = "0.11.3";
declare const version = "0.11.4";
export { version };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var version = '0.11.3';
var version = '0.11.4';
exports.version = version;
//# sourceMappingURL=version.js.map
{
"name": "@tensorflow/tfjs-core",
"version": "0.11.3",
"version": "0.11.4",
"description": "Hardware-accelerated JavaScript library for machine intelligence",

@@ -22,3 +22,3 @@ "private": false,

"clang-format": "~1.2.2",
"jasmine-core": "~2.6.4",
"jasmine-core": "~3.1.0",
"karma": "~1.7.0",

@@ -25,0 +25,0 @@ "karma-browserstack-launcher": "~1.3.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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