human/dist/demo-browser-index.js

34298 lines
1.6 MiB

// dist/human.esm.js
var Hp = Object.defineProperty;
var eL = (n) => Hp(n, "__esModule", {value: true});
var we = (n, t) => () => (t || (t = {exports: {}}, n(t.exports, t)), t.exports);
var vs = (n, t) => {
eL(n);
for (var e in t)
Hp(n, e, {get: t[e], enumerable: true});
};
var Vp = we(() => {
});
var Gp = we(() => {
});
var ws = we(() => {
});
var ei = we((A) => {
"use strict";
Object.defineProperty(A, "__esModule", {value: true});
var uc = function(n, t) {
return uc = Object.setPrototypeOf || {__proto__: []} instanceof Array && function(e, r) {
e.__proto__ = r;
} || function(e, r) {
for (var i in r)
r.hasOwnProperty(i) && (e[i] = r[i]);
}, uc(n, t);
};
function Yn(n, t) {
uc(n, t);
function e() {
this.constructor = n;
}
n.prototype = t === null ? Object.create(t) : (e.prototype = t.prototype, new e());
}
function pe(n, t, e, r) {
return new (e || (e = Promise))(function(i, a) {
function s(l) {
try {
c(r.next(l));
} catch (u) {
a(u);
}
}
function o(l) {
try {
c(r.throw(l));
} catch (u) {
a(u);
}
}
function c(l) {
l.done ? i(l.value) : new e(function(u) {
u(l.value);
}).then(s, o);
}
c((r = r.apply(n, t || [])).next());
});
}
function fe(n, t) {
var e = {label: 0, sent: function() {
if (a[0] & 1)
throw a[1];
return a[1];
}, trys: [], ops: []}, r, i, a, s;
return s = {next: o(0), throw: o(1), return: o(2)}, typeof Symbol == "function" && (s[Symbol.iterator] = function() {
return this;
}), s;
function o(l) {
return function(u) {
return c([l, u]);
};
}
function c(l) {
if (r)
throw new TypeError("Generator is already executing.");
for (; e; )
try {
if (r = 1, i && (a = l[0] & 2 ? i.return : l[0] ? i.throw || ((a = i.return) && a.call(i), 0) : i.next) && !(a = a.call(i, l[1])).done)
return a;
(i = 0, a) && (l = [l[0] & 2, a.value]);
switch (l[0]) {
case 0:
case 1:
a = l;
break;
case 4:
return e.label++, {value: l[1], done: false};
case 5:
e.label++, i = l[1], l = [0];
continue;
case 7:
l = e.ops.pop(), e.trys.pop();
continue;
default:
if (!(a = e.trys, a = a.length > 0 && a[a.length - 1]) && (l[0] === 6 || l[0] === 2)) {
e = 0;
continue;
}
if (l[0] === 3 && (!a || l[1] > a[0] && l[1] < a[3])) {
e.label = l[1];
break;
}
if (l[0] === 6 && e.label < a[1]) {
e.label = a[1], a = l;
break;
}
if (a && e.label < a[2]) {
e.label = a[2], e.ops.push(l);
break;
}
a[2] && e.ops.pop(), e.trys.pop();
continue;
}
l = t.call(n, e);
} catch (u) {
l = [6, u], i = 0;
} finally {
r = a = 0;
}
if (l[0] & 5)
throw l[1];
return {value: l[0] ? l[1] : void 0, done: true};
}
}
var tL = 1e-7, nL = 1e-4, rL = function() {
function n(t, e) {
this.backend = t, this.dataMover = e, this.data = new WeakMap(), this.dataIdsCount = 0;
}
return n.prototype.get = function(t) {
return this.data.has(t) || this.dataMover.moveData(this.backend, t), this.data.get(t);
}, n.prototype.set = function(t, e) {
this.dataIdsCount++, this.data.set(t, e);
}, n.prototype.has = function(t) {
return this.data.has(t);
}, n.prototype.delete = function(t) {
return this.dataIdsCount--, this.data.delete(t);
}, n.prototype.numDataIds = function() {
return this.dataIdsCount;
}, n;
}(), qp = function() {
function n() {
}
return n.prototype.time = function(t) {
return X("time");
}, n.prototype.read = function(t) {
return X("read");
}, n.prototype.readSync = function(t) {
return X("readSync");
}, n.prototype.numDataIds = function() {
return X("numDataIds");
}, n.prototype.disposeData = function(t) {
return X("disposeData");
}, n.prototype.write = function(t, e, r) {
return X("write");
}, n.prototype.move = function(t, e, r, i) {
return X("move");
}, n.prototype.memory = function() {
return X("memory");
}, n.prototype.floatPrecision = function() {
return X("floatPrecision");
}, n.prototype.epsilon = function() {
return this.floatPrecision() === 32 ? tL : nL;
}, n.prototype.batchMatMul = function(t, e, r, i) {
return X("batchMatMul");
}, n.prototype.fusedBatchMatMul = function(t) {
var e = t.a, r = t.b, i = t.transposeA, a = t.transposeB, s = t.bias, o = t.activation, c = t.preluActivationWeights;
return X("fusedBatchMatMul");
}, n.prototype.slice = function(t, e, r) {
return X("slice");
}, n.prototype.stridedSlice = function(t, e, r, i) {
return X("stridedSlice");
}, n.prototype.unstack = function(t, e) {
return X("unstack");
}, n.prototype.reverse = function(t, e) {
return X("reverse");
}, n.prototype.concat = function(t, e) {
return X("concat");
}, n.prototype.neg = function(t) {
return X("neg");
}, n.prototype.add = function(t, e) {
return X("add");
}, n.prototype.addN = function(t) {
return X("addN");
}, n.prototype.subtract = function(t, e) {
return X("subtract");
}, n.prototype.multiply = function(t, e) {
return X("multiply");
}, n.prototype.realDivide = function(t, e) {
return X("realDivide");
}, n.prototype.floorDiv = function(t, e) {
return X("floorDiv");
}, n.prototype.sum = function(t, e) {
return X("sum");
}, n.prototype.prod = function(t, e) {
return X("prod");
}, n.prototype.unsortedSegmentSum = function(t, e, r) {
return X("unsortedSegmentSum");
}, n.prototype.argMin = function(t, e) {
return X("argMin");
}, n.prototype.argMax = function(t, e) {
return X("argMax");
}, n.prototype.equal = function(t, e) {
return X("equal");
}, n.prototype.notEqual = function(t, e) {
return X("notEqual");
}, n.prototype.less = function(t, e) {
return X("less");
}, n.prototype.lessEqual = function(t, e) {
return X("lessEqual");
}, n.prototype.greater = function(t, e) {
return X("greater");
}, n.prototype.greaterEqual = function(t, e) {
return X("greaterEqual");
}, n.prototype.logicalNot = function(t) {
return X("logicalNot");
}, n.prototype.logicalAnd = function(t, e) {
return X("logicalAnd");
}, n.prototype.logicalOr = function(t, e) {
return X("logicalOr");
}, n.prototype.where = function(t) {
return X("where");
}, n.prototype.select = function(t, e, r) {
return X("select");
}, n.prototype.topk = function(t, e, r) {
return X("topk");
}, n.prototype.min = function(t, e) {
return X("min");
}, n.prototype.minimum = function(t, e) {
return X("minimum");
}, n.prototype.mod = function(t, e) {
return X("mod");
}, n.prototype.max = function(t, e) {
return X("max");
}, n.prototype.maximum = function(t, e) {
return X("maximum");
}, n.prototype.all = function(t, e) {
return X("all");
}, n.prototype.any = function(t, e) {
return X("any");
}, n.prototype.squaredDifference = function(t, e) {
return X("squaredDifference");
}, n.prototype.ceil = function(t) {
return X("ceil");
}, n.prototype.floor = function(t) {
return X("floor");
}, n.prototype.round = function(t) {
return X("round");
}, n.prototype.sign = function(t) {
return X("sign");
}, n.prototype.isNaN = function(t) {
return X("isNaN");
}, n.prototype.isInf = function(t) {
return X("isInf");
}, n.prototype.isFinite = function(t) {
return X("isFinite");
}, n.prototype.pow = function(t, e) {
return X("pow");
}, n.prototype.exp = function(t) {
return X("exp");
}, n.prototype.expm1 = function(t) {
return X("expm1");
}, n.prototype.softmax = function(t, e) {
return X("softmax");
}, n.prototype.log = function(t) {
return X("log");
}, n.prototype.log1p = function(t) {
return X("log1p");
}, n.prototype.sqrt = function(t) {
return X("sqrt");
}, n.prototype.rsqrt = function(t) {
return X("rsqrt");
}, n.prototype.square = function(t) {
return X("square");
}, n.prototype.reciprocal = function(t) {
return X("reciprocal");
}, n.prototype.relu = function(t) {
return X("relu");
}, n.prototype.relu6 = function(t) {
return X("relu6");
}, n.prototype.prelu = function(t, e) {
return X("prelu");
}, n.prototype.elu = function(t) {
return X("elu");
}, n.prototype.eluDer = function(t, e) {
return X("eluDer");
}, n.prototype.selu = function(t) {
return X("selu");
}, n.prototype.int = function(t) {
return X("int");
}, n.prototype.clip = function(t, e, r) {
return X("clip");
}, n.prototype.abs = function(t) {
return X("abs");
}, n.prototype.complexAbs = function(t) {
return X("complexAbs");
}, n.prototype.sigmoid = function(t) {
return X("sigmoid");
}, n.prototype.softplus = function(t) {
return X("softplus");
}, n.prototype.sin = function(t) {
return X("sin");
}, n.prototype.cos = function(t) {
return X("cos");
}, n.prototype.tan = function(t) {
return X("tan");
}, n.prototype.asin = function(t) {
return X("asin");
}, n.prototype.acos = function(t) {
return X("acos");
}, n.prototype.atan = function(t) {
return X("atan");
}, n.prototype.atan2 = function(t, e) {
return X("atan2");
}, n.prototype.sinh = function(t) {
return X("sinh");
}, n.prototype.cosh = function(t) {
return X("cosh");
}, n.prototype.tanh = function(t) {
return X("tanh");
}, n.prototype.asinh = function(t) {
return X("asinh");
}, n.prototype.acosh = function(t) {
return X("acosh");
}, n.prototype.atanh = function(t) {
return X("atanh");
}, n.prototype.erf = function(t) {
return X("erf");
}, n.prototype.step = function(t, e) {
return X("step");
}, n.prototype.fusedConv2d = function(t) {
var e = t.input, r = t.filter, i = t.convInfo, a = t.bias, s = t.activation, o = t.preluActivationWeights;
return X("fusedConv2d");
}, n.prototype.conv2d = function(t, e, r) {
return X("conv2d");
}, n.prototype.conv2dDerInput = function(t, e, r) {
return X("conv2dDerInput");
}, n.prototype.conv2dDerFilter = function(t, e, r) {
return X("conv2dDerFilter");
}, n.prototype.fusedDepthwiseConv2D = function(t) {
var e = t.input, r = t.filter, i = t.convInfo, a = t.bias, s = t.activation, o = t.preluActivationWeights;
return X("fusedDepthwiseConv2D");
}, n.prototype.depthwiseConv2D = function(t, e, r) {
return X("depthwiseConv2D");
}, n.prototype.depthwiseConv2DDerInput = function(t, e, r) {
return X("depthwiseConv2DDerInput");
}, n.prototype.depthwiseConv2DDerFilter = function(t, e, r) {
return X("depthwiseConv2DDerFilter");
}, n.prototype.conv3d = function(t, e, r) {
return X("conv3d");
}, n.prototype.conv3dDerInput = function(t, e, r) {
return X("conv3dDerInput");
}, n.prototype.conv3dDerFilter = function(t, e, r) {
return X("conv3dDerFilter");
}, n.prototype.maxPool = function(t, e) {
return X("maxPool");
}, n.prototype.maxPoolBackprop = function(t, e, r, i) {
return X("maxPoolBackprop");
}, n.prototype.avgPool = function(t, e) {
return X("avgPool");
}, n.prototype.avgPoolBackprop = function(t, e, r) {
return X("avgPoolBackprop");
}, n.prototype.avgPool3d = function(t, e) {
return X("avgPool3d");
}, n.prototype.avgPool3dBackprop = function(t, e, r) {
return X("avgPool3dBackprop");
}, n.prototype.maxPool3d = function(t, e) {
return X("maxPool3d");
}, n.prototype.maxPool3dBackprop = function(t, e, r, i) {
return X("maxPool3dBackprop");
}, n.prototype.reshape = function(t, e) {
return X("reshape");
}, n.prototype.cast = function(t, e) {
return X("cast");
}, n.prototype.tile = function(t, e) {
return X("tile");
}, n.prototype.pad = function(t, e, r) {
return X("pad");
}, n.prototype.transpose = function(t, e) {
return X("transpose");
}, n.prototype.gather = function(t, e, r) {
return X("gather");
}, n.prototype.gatherND = function(t, e) {
return X("gatherND");
}, n.prototype.scatterND = function(t, e, r) {
return X("scatterND");
}, n.prototype.batchToSpaceND = function(t, e, r) {
return X("batchToSpaceND");
}, n.prototype.spaceToBatchND = function(t, e, r) {
return X("spaceToBatchND");
}, n.prototype.resizeBilinear = function(t, e, r, i) {
return X("resizeBilinear");
}, n.prototype.resizeBilinearBackprop = function(t, e, r) {
return X("resizeBilinearBackprop");
}, n.prototype.resizeNearestNeighbor = function(t, e, r, i) {
return X("resizeNearestNeighbor");
}, n.prototype.resizeNearestNeighborBackprop = function(t, e, r) {
return X("resizeNearestNeighborBackprop");
}, n.prototype.batchNorm = function(t, e, r, i, a, s) {
return X("batchNorm");
}, n.prototype.localResponseNormalization4D = function(t, e, r, i, a) {
return X("localResponseNormalization4D");
}, n.prototype.LRNGrad = function(t, e, r, i, a, s, o) {
return X("LRNGrad");
}, n.prototype.multinomial = function(t, e, r, i) {
return X("multinomial");
}, n.prototype.oneHot = function(t, e, r, i) {
return X("oneHot");
}, n.prototype.cumsum = function(t, e, r, i) {
return X("cumsum");
}, n.prototype.nonMaxSuppression = function(t, e, r, i, a) {
return X("nonMaxSuppression");
}, n.prototype.fft = function(t) {
return X("fft");
}, n.prototype.ifft = function(t) {
return X("ifft");
}, n.prototype.complex = function(t, e) {
return X("complex");
}, n.prototype.real = function(t) {
return X("real");
}, n.prototype.imag = function(t) {
return X("imag");
}, n.prototype.cropAndResize = function(t, e, r, i, a, s) {
return X("cropAndResize");
}, n.prototype.depthToSpace = function(t, e, r) {
return X("depthToSpace");
}, n.prototype.split = function(t, e, r) {
return X("split");
}, n.prototype.sparseToDense = function(t, e, r, i) {
return X("sparseToDense");
}, n.prototype.diag = function(t) {
return X("diag");
}, n.prototype.fill = function(t, e, r) {
return X("fill");
}, n.prototype.onesLike = function(t) {
return X("onesLike");
}, n.prototype.zerosLike = function(t) {
return X("zerosLike");
}, n.prototype.linspace = function(t, e, r) {
return X("linspace");
}, n.prototype.dispose = function() {
return X("dispose");
}, n;
}();
function X(n) {
throw new Error("'" + n + "' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen");
}
function Yp(n) {
for (var t = n.length, e = 0, r = 0; t > 0; )
r = Math.random() * t | 0, t--, e = n[t], n[t] = n[r], n[r] = e;
}
function ga(n, t, e) {
return Math.max(n, Math.min(t, e));
}
function iL(n) {
return n % 2 === 0 ? n : n + 1;
}
function aL(n) {
for (var t = 0, e = 0; e < n.length; e++)
t += n[e];
return t;
}
function sL(n, t) {
var e = Math.random();
return t * e + (1 - e) * n;
}
function oL(n, t) {
for (var e = 0, r = 0; r < n.length; r++) {
var i = Number(n[r]) - Number(t[r]);
e += i * i;
}
return e;
}
function E(n, t) {
if (!n)
throw new Error(typeof t == "string" ? t : t());
}
function Pe(n, t, e) {
e === void 0 && (e = ""), E(pn(n, t), function() {
return e + (" Shapes " + n + " and " + t + " must match");
});
}
function Br(n) {
E(n != null, function() {
return "The input to the tensor constructor must be a non-null value.";
});
}
function zr(n, t, e) {
if (t === void 0 && (t = []), e === void 0 && (e = false), t == null && (t = []), Array.isArray(n) || Ft(n) && !e)
for (var r = 0; r < n.length; ++r)
zr(n[r], t, e);
else
t.push(n);
return t;
}
function dt(n) {
if (n.length === 0)
return 1;
for (var t = n[0], e = 1; e < n.length; e++)
t *= n[e];
return t;
}
function cL(n) {
return n.length === 0;
}
function pn(n, t) {
if (n === t)
return true;
if (n == null || t == null)
return false;
if (n.length !== t.length)
return false;
for (var e = 0; e < n.length; e++)
if (n[e] !== t[e])
return false;
return true;
}
function ot(n) {
return n % 1 === 0;
}
function lL(n) {
if (Math.tanh != null)
return Math.tanh(n);
if (n === Infinity)
return 1;
if (n === -Infinity)
return -1;
var t = Math.exp(2 * n);
return (t - 1) / (t + 1);
}
function uL(n) {
var t = Math.ceil(Math.sqrt(n));
return [t, Math.ceil(n / t)];
}
function hL(n) {
for (var t = new Uint32Array(n), e = 0; e < n; ++e)
t[e] = e;
return Yp(t), t;
}
function ya(n, t) {
return t <= n.length ? n : n + " ".repeat(t - n.length);
}
function dL(n, t, e) {
return t === void 0 && (t = function(r) {
return 0;
}), new Promise(function(r, i) {
var a = 0, s = function() {
if (n()) {
r();
return;
}
a++;
var o = t(a);
if (e != null && a >= e) {
i();
return;
}
setTimeout(s, o);
};
s();
});
}
function Kp(n, t) {
for (var e = 1, r = -1, i = 0; i < n.length; ++i)
if (n[i] >= 0)
e *= n[i];
else if (n[i] === -1) {
if (r !== -1)
throw Error("Shapes can only have 1 implicit size. " + ("Found -1 at dim " + r + " and dim " + i));
r = i;
} else if (n[i] < 0)
throw Error("Shapes can not be < 0. Found " + n[i] + " at dim " + i);
if (r === -1) {
if (t > 0 && t !== e)
throw Error("Size(" + t + ") must match the product of shape " + n);
return n;
}
if (e === 0)
throw Error("Cannot infer the missing size in [" + n + "] when there are 0 elements");
if (t % e !== 0)
throw Error("The implicit shape can't be a fractional number. " + ("Got " + t + " / " + e));
var a = n.slice();
return a[r] = t / e, a;
}
function rt(n, t) {
var e = t.length;
return n = n == null ? t.map(function(r, i) {
return i;
}) : [].concat(n), E(n.every(function(r) {
return r >= -e && r < e;
}), function() {
return "All values in axis param must be in range [-" + e + ", " + e + ") but " + ("got axis " + n);
}), E(n.every(function(r) {
return ot(r);
}), function() {
return "All values in axis param must be integers but " + ("got axis " + n);
}), n.map(function(r) {
return r < 0 ? e + r : r;
});
}
function jp(n, t) {
for (var e = [], r = [], i = t != null && Array.isArray(t) && t.length === 0, a = t == null || i ? null : rt(t, n).sort(), s = 0, o = 0; o < n.length; ++o) {
if (a != null) {
if (a[s] === o && n[o] !== 1)
throw new Error("Can't squeeze axis " + o + " since its dim '" + n[o] + "' is not 1");
(a[s] == null || a[s] > o) && n[o] === 1 && (e.push(n[o]), r.push(o)), a[s] <= o && s++;
}
n[o] !== 1 && (e.push(n[o]), r.push(o));
}
return {newShape: e, keptDims: r};
}
function bs(n, t) {
var e = null;
if (n == null || n === "float32")
e = new Float32Array(t);
else if (n === "int32")
e = new Int32Array(t);
else if (n === "bool")
e = new Uint8Array(t);
else
throw new Error("Unknown data type " + n);
return e;
}
function $p(n, t) {
var e = null;
if (n == null || n === "float32")
e = new Float32Array(t);
else if (n === "int32")
e = new Int32Array(t);
else if (n === "bool")
e = new Uint8Array(t);
else if (n === "string")
e = new Array(t);
else
throw new Error("Unknown data type " + n);
return e;
}
function Xp(n, t) {
for (var e = 0; e < n.length; e++) {
var r = n[e];
if (isNaN(r) || !isFinite(r))
throw Error("A tensor of type " + t + " being uploaded contains " + r + ".");
}
}
function Jp(n) {
return n === "bool" || n === "complex64" || n === "float32" || n === "int32" || n === "string";
}
function Zp(n, t) {
return t === "complex64" || (t === "float32" && n !== "complex64" || t === "int32" && n !== "float32" && n !== "complex64") ? false : !(t === "bool" && n === "bool");
}
function Ft(n) {
return n instanceof Float32Array || n instanceof Int32Array || n instanceof Uint8Array;
}
function Qp(n) {
if (n === "float32" || n === "int32")
return 4;
if (n === "complex64")
return 8;
if (n === "bool")
return 1;
throw new Error("Unknown dtype " + n);
}
function ef(n) {
if (n == null)
return 0;
var t = 0;
return n.forEach(function(e) {
return t += e.length;
}), t;
}
function lr(n) {
return typeof n == "string" || n instanceof String;
}
function tf(n) {
return typeof n == "boolean";
}
function nf(n) {
return typeof n == "number";
}
function xs(n) {
return Array.isArray(n) ? xs(n[0]) : n instanceof Float32Array ? "float32" : n instanceof Int32Array || n instanceof Uint8Array ? "int32" : nf(n) ? "float32" : lr(n) ? "string" : tf(n) ? "bool" : "float32";
}
function ur(n) {
return !!(n && n.constructor && n.call && n.apply);
}
function Ls(n, t) {
for (var e = t; e < n; ++e)
if (n % e === 0)
return e;
return n;
}
function xi(n) {
var t = n.length;
if (t < 2)
return [];
var e = new Array(t - 1);
e[t - 2] = n[t - 1];
for (var r = t - 3; r >= 0; --r)
e[r] = e[r + 1] * n[r + 1];
return e;
}
function rf(n, t, e) {
var r = new Array();
if (t.length === 1)
for (var i = t[0], a = 0; a < i; a++)
r[a] = e[n + a];
else
for (var i = t[0], s = t.slice(1), o = s.reduce(function(l, u) {
return l * u;
}), a = 0; a < i; a++)
r[a] = rf(n + a * o, s, e);
return r;
}
function Li(n, t) {
if (n.length === 0)
return t[0];
var e = n.reduce(function(r, i) {
return r * i;
});
if (e === 0)
return [];
if (e !== t.length)
throw new Error("[" + n + "] does not match the input size " + t.length + ".");
return rf(0, n, t);
}
function hc(n, t) {
for (var e = Si(n, t), r = 0; r < e.length; r++)
e[r] = 1;
return e;
}
function Si(n, t) {
if (t == null || t === "float32" || t === "complex64")
return new Float32Array(n);
if (t === "int32")
return new Int32Array(n);
if (t === "bool")
return new Uint8Array(n);
throw new Error("Unknown data type " + t);
}
function pL(n, t) {
var e = n.reduce(function(r, i) {
return r * i;
}, 1);
if (t == null || t === "float32")
return Li(n, new Float32Array(e));
if (t === "int32")
return Li(n, new Int32Array(e));
if (t === "bool")
return Li(n, new Uint8Array(e));
throw new Error("Unknown data type " + t);
}
function dc(n) {
n.forEach(function(t) {
E(Number.isInteger(t) && t >= 0, function() {
return "Tensor must have a shape comprised of positive integers but got " + ("shape [" + n + "].");
});
});
}
function fL(n, t, e) {
if (t === 0)
return 0;
if (t === 1)
return n[0];
for (var r = n[n.length - 1], i = 0; i < n.length - 1; ++i)
r += e[i] * n[i];
return r;
}
function mL(n, t, e) {
if (t === 0)
return [];
if (t === 1)
return [n];
for (var r = new Array(t), i = 0; i < r.length - 1; ++i)
r[i] = Math.floor(n / e[i]), n -= r[i] * e[i];
return r[r.length - 1] = n, r;
}
function pc(n) {
return n && n.then && typeof n.then == "function";
}
var af = "tfjsflags", sf = function() {
function n(t) {
this.global = t, this.flags = {}, this.flagRegistry = {}, this.urlFlags = {}, this.populateURLFlags();
}
return n.prototype.setPlatform = function(t, e) {
this.platform != null && console.warn("Platform " + this.platformName + " has already been set. " + ("Overwriting the platform with " + e + ".")), this.platformName = t, this.platform = e;
}, n.prototype.registerFlag = function(t, e, r) {
if (this.flagRegistry[t] = {evaluationFn: e, setHook: r}, this.urlFlags[t] != null) {
var i = this.urlFlags[t];
console.warn("Setting feature override from URL " + t + ": " + i + "."), this.set(t, i);
}
}, n.prototype.getAsync = function(t) {
return pe(this, void 0, void 0, function() {
var e, r;
return fe(this, function(i) {
switch (i.label) {
case 0:
return t in this.flags ? [2, this.flags[t]] : (e = this.flags, r = t, [4, this.evaluateFlag(t)]);
case 1:
return e[r] = i.sent(), [2, this.flags[t]];
}
});
});
}, n.prototype.get = function(t) {
if (t in this.flags)
return this.flags[t];
var e = this.evaluateFlag(t);
if (pc(e))
throw new Error("Flag " + t + " cannot be synchronously evaluated. Please use getAsync() instead.");
return this.flags[t] = e, this.flags[t];
}, n.prototype.getNumber = function(t) {
return this.get(t);
}, n.prototype.getBool = function(t) {
return this.get(t);
}, n.prototype.getFlags = function() {
return this.flags;
}, Object.defineProperty(n.prototype, "features", {get: function() {
return this.flags;
}, enumerable: true, configurable: true}), n.prototype.set = function(t, e) {
if (this.flagRegistry[t] == null)
throw new Error("Cannot set flag " + t + " as it has not been registered.");
this.flags[t] = e, this.flagRegistry[t].setHook != null && this.flagRegistry[t].setHook(e);
}, n.prototype.evaluateFlag = function(t) {
if (this.flagRegistry[t] == null)
throw new Error("Cannot evaluate flag '" + t + "': no evaluation function found.");
return this.flagRegistry[t].evaluationFn();
}, n.prototype.setFlags = function(t) {
this.flags = Object.assign({}, t);
}, n.prototype.reset = function() {
this.flags = {}, this.urlFlags = {}, this.populateURLFlags();
}, n.prototype.populateURLFlags = function() {
var t = this;
if (typeof this.global == "undefined" || typeof this.global.location == "undefined" || typeof this.global.location.search == "undefined")
return;
var e = gL(this.global.location.search);
if (af in e) {
var r = e[af].split(",");
r.forEach(function(i) {
var a = i.split(":"), s = a[0], o = a[1];
t.urlFlags[s] = yL(s, o);
});
}
}, n;
}();
function gL(n) {
var t = {};
return n.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, function(e) {
for (var r = [], i = 1; i < arguments.length; i++)
r[i - 1] = arguments[i];
return vL(t, r[0], r[1]), r.join("=");
}), t;
}
function vL(n, t, e) {
n[decodeURIComponent(t)] = decodeURIComponent(e || "");
}
function yL(n, t) {
if (t = t.toLowerCase(), t === "true" || t === "false")
return t === "true";
if ("" + +t === t)
return +t;
throw new Error("Could not parse value flag value " + t + " for flag " + n + ".");
}
function qe() {
return A.ENV;
}
A.ENV = null;
function wL(n) {
A.ENV = n;
}
var fc;
function of() {
if (fc == null) {
var n = void 0;
if (typeof window != "undefined")
n = window;
else if (typeof global != "undefined")
n = global;
else if (typeof process != "undefined")
n = process;
else if (typeof self != "undefined")
n = self;
else
throw new Error("Could not find a global object");
fc = n;
}
return fc;
}
function bL() {
var n = of();
return n._tfGlobals == null && (n._tfGlobals = new Map()), n._tfGlobals;
}
function cf(n, t) {
var e = bL();
if (e.has(n))
return e.get(n);
var r = t();
return e.set(n, r), e.get(n);
}
var mc = "Abs", gc = "Acos", yc = "Acosh", Ss = "Add", vc = "AddN", lf = "All", uf = "Any", wc = "ArgMax", bc = "ArgMin", xc = "Asin", Lc = "Asinh", Sc = "Atan", Ic = "Atanh", Ac = "Atan2", Tc = "AvgPool", hf = "AvgPoolBackprop", Nc = "AvgPool3D", df = "AvgPool3DBackprop", _c = "BatchMatMul", Cc = "BatchToSpaceND", Rc = "BroadcastTo", Is = "Cast", Oc = "Ceil", Ec = "ClipByValue", pf = "Complex", Dc = "Concat", kc = "Conv2D", ff = "Conv2DBackpropFilter", Fc = "Conv2DBackpropInput", Wc = "Conv3D", mf = "Conv3DBackpropFilterV2", gf = "Conv3DBackpropInputV2", Uc = "Cos", Bc = "Cosh", zc = "Cumsum", yf = "CropAndResize", vf = "DepthToSpace", Pc = "DepthwiseConv2dNative", wf = "DepthwiseConv2dNativeBackpropFilter", bf = "DepthwiseConv2dNativeBackpropInput", xf = "Diag", Mc = "Dilation2D", Lf = "Dilation2DBackpropInput", Sf = "Dilation2DBackpropFilter", Hc = "Div", Vc = "Elu", If = "EluGrad", Gc = "Erf", Af = "Equal", qc = "Exp", Yc = "Expm1", Tf = "FFT", Nf = "Fill", _f = "FlipLeftRight", Kc = "Floor", jc = "FloorDiv", $c = "FusedBatchNorm", Xc = "GatherV2", Cf = "GatherNd", Rf = "Greater", Jc = "GreaterEqual", Zc = "Identity", Of = "IFFT", Ef = "Imag", Qc = "IsFinite", el = "IsInf", tl = "IsNan", Df = "Less", kf = "LessEqual", Ff = "LinSpace", nl = "Log", rl = "Log1p", Wf = "LogicalAnd", Uf = "LogicalNot", Bf = "LogicalOr", il = "LogSoftmax", al = "LRN", zf = "LRNBackprop", sl = "Max", ol = "Maximum", cl = "MaxPool", Pf = "MaxPoolBackprop", ll = "MaxPool3D", Mf = "MaxPool3DBackprop", Hf = "MaxPoolWithArgmax", Vf = "Mean", ul = "Min", hl = "Minimum", dl = "MirrorPad", pl = "Mod", fl = "Multiply", ml = "Negate", Gf = "NotEqual", qf = "NonMaxSuppressionV3", Yf = "NonMaxSuppressionV4", Kf = "NonMaxSuppressionV5", gl = "OnesLike", yl = "OneHot", vl = "PadV2", xL = "Pool", wl = "Pow", bl = "Prelu", jf = "Prod", $f = "Range", Xf = "Real", xl = "Reciprocal", Ll = "Relu", Sl = "Reshape", Il = "ResizeNearestNeighbor", Jf = "ResizeNearestNeighborGrad", Al = "ResizeBilinear", Zf = "ResizeBilinearGrad", Tl = "Relu6", Nl = "Reverse", _l = "Round", Cl = "Rsqrt", Qf = "ScatterNd", Rl = "SelectV2", Ol = "Selu", El = "Slice", Dl = "Sin", kl = "Sinh", Fl = "Sign", Wl = "Sigmoid", Ul = "Softplus", Bl = "Sqrt", zl = "Sum", Pl = "SpaceToBatchND", Ml = "SplitV", Hl = "Softmax", Vl = "SquaredDifference", em = "Square", Gl = "Sub", tm = "SparseToDense", nm = "StridedSlice", ql = "Tan", Yl = "Tanh", Kl = "Tile", rm = "TopK", jl = "Transpose", im = "Unique", $l = "Unpack", Xl = "UnsortedSegmentSum", Jl = "ZerosLike", Zl = "Step", Ql = "FromPixels", am = "RotateWithOffset", eu = "_FusedMatMul", tu = "FusedConv2D", nu = "FusedDepthwiseConv2D";
var Ii = cf("kernelRegistry", function() {
return new Map();
}), va = cf("gradRegistry", function() {
return new Map();
});
function iu(n, t) {
var e = ru(n, t);
return Ii.get(e);
}
function au(n) {
return va.get(n);
}
function As(n) {
for (var t = Ii.entries(), e = []; ; ) {
var r = t.next(), i = r.done, a = r.value;
if (i)
break;
var s = a[0], o = a[1], c = s.split("_")[0];
c === n && e.push(o);
}
return e;
}
function sm(n) {
var t = n.kernelName, e = n.backendName, r = ru(t, e);
Ii.has(r) && console.warn("The kernel '" + t + "' for backend " + ("'" + e + "' is already registered")), Ii.set(r, n);
}
function om(n) {
var t = n.kernelName;
va.has(t) && (qe().getBool("DEBUG") && console.warn("Overriding the gradient for '" + t + "'")), va.set(t, n);
}
function LL(n, t) {
var e = ru(n, t);
if (!Ii.has(e))
throw new Error("The kernel '" + n + "' for backend " + ("'" + t + "' is not registered"));
Ii.delete(e);
}
function SL(n) {
if (!va.has(n))
throw new Error("The gradient '" + n + "' for backend is not registered");
va.delete(n);
}
function IL(n, t) {
var e = As(n);
e.forEach(function(r) {
var i = Object.assign({}, r, {backendName: t});
sm(i);
});
}
function ru(n, t) {
return t + "_" + n;
}
function AL(n, t) {
return t === "string" ? su(n) : Ts([n], t);
}
function TL(n, t) {
return n instanceof Float32Array && t === "float32" || n instanceof Int32Array && t === "int32" || n instanceof Uint8Array && t === "bool";
}
function Ts(n, t) {
if (t === "string")
throw new Error("Cannot convert a string[] to a TypedArray");
if (Array.isArray(n) && (n = zr(n)), qe().getBool("DEBUG") && Xp(n, t), TL(n, t))
return n;
if (t == null || t === "float32" || t === "complex64")
return new Float32Array(n);
if (t === "int32")
return new Int32Array(n);
if (t === "bool") {
for (var e = new Uint8Array(n.length), r = 0; r < e.length; ++r)
Math.round(n[r]) !== 0 && (e[r] = 1);
return e;
} else
throw new Error("Unknown data type " + t);
}
function ou() {
return qe().platform.now();
}
function NL(n, t) {
return qe().platform.fetch(n, t);
}
function su(n, t) {
return t === void 0 && (t = "utf-8"), t = t || "utf-8", qe().platform.encode(n, t);
}
function cu(n, t) {
return t === void 0 && (t = "utf-8"), t = t || "utf-8", qe().platform.decode(n, t);
}
var _L = {__proto__: null, createScalarValue: AL, toTypedArray: Ts, now: ou, fetch: NL, encodeString: su, decodeString: cu, shuffle: Yp, clamp: ga, nearestLargerEven: iL, sum: aL, randUniform: sL, distSquared: oL, assert: E, assertShapesMatch: Pe, assertNonNull: Br, flatten: zr, sizeFromShape: dt, isScalarShape: cL, arraysEqual: pn, isInt: ot, tanh: lL, sizeToSquarishShape: uL, createShuffledIndices: hL, rightPad: ya, repeatedTry: dL, inferFromImplicitShape: Kp, parseAxisParam: rt, squeezeShape: jp, getTypedArrayFromDType: bs, getArrayFromDType: $p, checkConversionForErrors: Xp, isValidDtype: Jp, hasEncodingLoss: Zp, isTypedArray: Ft, bytesPerElement: Qp, bytesFromStringArray: ef, isString: lr, isBoolean: tf, isNumber: nf, inferDtype: xs, isFunction: ur, nearestDivisor: Ls, computeStrides: xi, toNestedArray: Li, makeOnesTypedArray: hc, makeZerosTypedArray: Si, makeZerosNestedTypedArray: pL, assertNonNegativeIntegerDimensions: dc, locToIndex: fL, indexToLoc: mL, isPromise: pc};
var OL = function() {
function n(t, e) {
this.backendTimer = t, this.logger = e, e == null && (this.logger = new RL());
}
return n.prototype.profileKernel = function(t, e, r) {
for (var i, a = function() {
i = r();
}, s = this.backendTimer.time(a), o = function(u) {
var h = i[u];
h.data().then(function(d) {
CL(d, h.dtype, t);
});
}, c = 0; c < i.length; c++)
o(c);
var l = {kernelName: t, outputs: i, inputs: e, timeMs: s.then(function(u) {
return u.kernelMs;
}), extraInfo: s.then(function(u) {
return u.getExtraProfileInfo != null ? u.getExtraProfileInfo() : "";
})};
return l;
}, n.prototype.logKernelProfile = function(t) {
var e = this, r = t.kernelName, i = t.outputs, a = t.timeMs, s = t.inputs, o = t.extraInfo;
i.forEach(function(c) {
Promise.all([c.data(), a, o]).then(function(l) {
e.logger.logKernelProfile(r, c, l[0], l[1], s, l[2]);
});
});
}, n;
}();
function CL(n, t, e) {
if (t !== "float32")
return false;
for (var r = 0; r < n.length; r++) {
var i = n[r];
if (isNaN(i) || !isFinite(i))
return console.warn("Found " + i + " in the result of '" + e + "'"), true;
}
return false;
}
var RL = function() {
function n() {
}
return n.prototype.logKernelProfile = function(t, e, r, i, a, s) {
var o = typeof i == "number" ? ya(i + "ms", 9) : i.error, c = ya(t, 25), l = e.rank, u = e.size, h = ya(e.shape.toString(), 14), d = "";
for (var p in a) {
var f = a[p];
if (f != null) {
var m = f.shape || e.shape, g = m.length;
d += p + ": " + g + "D " + (g > 0 ? m : "") + " ";
}
}
console.log("%c" + c + " %c" + o + " %c" + l + "D " + h + " %c" + u + " %c" + d + " %c" + s, "font-weight:bold", "color:red", "color:blue", "color: orange", "color: green", "color: steelblue");
}, n;
}();
function EL(n, t, e) {
for (var r = {}, i = {}, a = 0; a < t.length; a++)
r[t[a].id] = true;
for (var a = 0; a < n.length; a++) {
var s = n[a], o = s.inputs;
for (var c in o) {
for (var l = o[c], u = false, h = 0; h < t.length; h++)
if (r[l.id]) {
s.outputs.forEach(function(b) {
return r[b.id] = true;
}), u = true, i[s.id] = true;
break;
}
if (u)
break;
}
}
var d = {};
d[e.id] = true;
for (var p = {}, a = n.length - 1; a >= 0; a--)
for (var s = n[a], o = s.inputs, h = 0; h < s.outputs.length; h++)
if (d[s.outputs[h].id]) {
for (var c in o)
d[o[c].id] = true, p[s.id] = true;
break;
}
for (var f = [], a = 0; a < n.length; a++) {
var s = n[a];
if (i[s.id] && p[s.id]) {
var m = {};
for (var c in s.inputs) {
var g = s.inputs[c];
r[g.id] && (m[c] = g);
}
var y = Object.assign({}, s);
y.inputs = m, y.outputs = s.outputs, f.push(y);
}
}
return f;
}
function DL(n, t, e, r) {
for (var i = function(s) {
var o = t[s], c = [];
if (o.outputs.forEach(function(d) {
var p = n[d.id];
p != null ? c.push(p) : c.push(null);
}), o.gradient == null)
throw new Error("Cannot compute gradient: gradient function not found " + ("for " + o.kernelName + "."));
var l = o.gradient(c), u = function(d) {
if (!(d in l))
throw new Error("Cannot backprop through input " + d + ". " + ("Available gradients found: " + Object.keys(l) + "."));
var p = e(function() {
return l[d]();
});
if (p.dtype !== "float32")
throw new Error("Error in gradient for op " + o.kernelName + ". The gradient of input " + (d + " must have 'float32' dtype, but has '" + p.dtype + "'"));
var f = o.inputs[d];
if (!pn(p.shape, f.shape))
throw new Error("Error in gradient for op " + o.kernelName + ". The gradient of input " + ("'" + d + "' has shape '" + p.shape + "', which does not match ") + ("the shape of the input '" + f.shape + "'"));
if (n[f.id] == null)
n[f.id] = p;
else {
var m = n[f.id];
n[f.id] = r(m, p), m.dispose();
}
};
for (var h in o.inputs)
u(h);
}, a = t.length - 1; a >= 0; a--)
i(a);
}
var cm = 20, wa = 3, lu = 7;
function FL(n, t, e, r) {
var i = xi(t), a = kL(n, t, e, i), s = t.length, o = Ns(n, t, e, i, a), c = ["Tensor"];
return r && (c.push(" dtype: " + e), c.push(" rank: " + s), c.push(" shape: [" + t + "]"), c.push(" values:")), c.push(o.map(function(l) {
return " " + l;
}).join(`
`)), c.join(`
`);
}
function kL(n, t, e, r) {
var i = dt(t), a = r[r.length - 1], s = new Array(a).fill(0), o = t.length, c = e === "complex64" ? xa(n) : n;
if (o > 1)
for (var l = 0; l < i / a; l++)
for (var u = l * a, h = 0; h < a; h++)
s[h] = Math.max(s[h], ba(c[u + h], 0, e).length);
return s;
}
function ba(n, t, e) {
var r;
return Array.isArray(n) ? r = parseFloat(n[0].toFixed(lu)) + " + " + (parseFloat(n[1].toFixed(lu)) + "j") : lr(n) ? r = "'" + n + "'" : e === "bool" ? r = lm(n) : r = parseFloat(n.toFixed(lu)).toString(), ya(r, t);
}
function lm(n) {
return n === 0 ? "false" : "true";
}
function Ns(n, t, e, r, i, a) {
a === void 0 && (a = true);
var s = e === "complex64" ? 2 : 1, o = t[0], c = t.length;
if (c === 0) {
if (e === "complex64") {
var l = xa(n);
return [ba(l[0], 0, e)];
}
return e === "bool" ? [lm(n[0])] : [n[0].toString()];
}
if (c === 1) {
if (o > cm) {
var u = wa * s, h = Array.from(n.slice(0, u)), d = Array.from(n.slice((o - wa) * s, o * s));
return e === "complex64" && (h = xa(h), d = xa(d)), ["[" + h.map(function(I, C) {
return ba(I, i[C], e);
}).join(", ") + ", ..., " + d.map(function(I, C) {
return ba(I, i[o - wa + C], e);
}).join(", ") + "]"];
}
var p = e === "complex64" ? xa(n) : Array.from(n);
return ["[" + p.map(function(I, C) {
return ba(I, i[C], e);
}).join(", ") + "]"];
}
var f = t.slice(1), m = r.slice(1), g = r[0] * s, y = [];
if (o > cm) {
for (var w = 0; w < wa; w++) {
var b = w * g, x = b + g;
y.push.apply(y, Ns(n.slice(b, x), f, e, m, i, false));
}
y.push("...");
for (var w = o - wa; w < o; w++) {
var b = w * g, x = b + g;
y.push.apply(y, Ns(n.slice(b, x), f, e, m, i, w === o - 1));
}
} else
for (var w = 0; w < o; w++) {
var b = w * g, x = b + g;
y.push.apply(y, Ns(n.slice(b, x), f, e, m, i, w === o - 1));
}
var L = c === 2 ? "," : "";
y[0] = "[" + y[0] + L;
for (var w = 1; w < y.length - 1; w++)
y[w] = " " + y[w] + L;
for (var N = `,
`, w = 2; w < c; w++)
N += `
`;
return y[y.length - 1] = " " + y[y.length - 1] + "]" + (a ? "" : N), y;
}
function xa(n) {
for (var t = [], e = 0; e < n.length; e += 2)
t.push([n[e], n[e + 1]]);
return t;
}
var _s = function() {
function n(t, e, r) {
var i = this;
if (this.dtype = e, this.shape = t.slice(), this.size = dt(t), r != null) {
var a = r.length;
E(a === this.size, function() {
return "Length of values '" + a + "' does not match the size " + ("inferred by the shape '" + i.size + "'.");
});
}
if (e === "complex64")
throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");
this.values = r || $p(e, this.size), this.strides = xi(t);
}
return n.prototype.set = function(t) {
for (var e = this, r = [], i = 1; i < arguments.length; i++)
r[i - 1] = arguments[i];
r.length === 0 && (r = [0]), E(r.length === this.rank, function() {
return "The number of provided coordinates (" + r.length + ") must " + ("match the rank (" + e.rank + ")");
});
var a = this.locToIndex(r);
this.values[a] = t;
}, n.prototype.get = function() {
for (var t = [], e = 0; e < arguments.length; e++)
t[e] = arguments[e];
t.length === 0 && (t = [0]);
for (var r = 0, i = 0, a = t; i < a.length; i++) {
var s = a[i];
if (s < 0 || s >= this.shape[r]) {
var o = "Requested out of range element at " + t + ". " + (" Buffer shape=" + this.shape);
throw new Error(o);
}
r++;
}
for (var c = t[t.length - 1], l = 0; l < t.length - 1; ++l)
c += this.strides[l] * t[l];
return this.values[c];
}, n.prototype.locToIndex = function(t) {
if (this.rank === 0)
return 0;
if (this.rank === 1)
return t[0];
for (var e = t[t.length - 1], r = 0; r < t.length - 1; ++r)
e += this.strides[r] * t[r];
return e;
}, n.prototype.indexToLoc = function(t) {
if (this.rank === 0)
return [];
if (this.rank === 1)
return [t];
for (var e = new Array(this.shape.length), r = 0; r < e.length - 1; ++r)
e[r] = Math.floor(t / this.strides[r]), t -= e[r] * this.strides[r];
return e[e.length - 1] = t, e;
}, Object.defineProperty(n.prototype, "rank", {get: function() {
return this.shape.length;
}, enumerable: true, configurable: true}), n.prototype.toTensor = function() {
return _n().makeTensor(this.values, this.shape, this.dtype);
}, n;
}(), _n = null, Ai = null;
function WL(n) {
_n = n;
}
function UL(n) {
Ai = n;
}
var K = function() {
function n(t, e, r, i) {
this.kept = false, this.isDisposedInternal = false, this.shape = t.slice(), this.dtype = e || "float32", this.size = dt(t), this.strides = xi(t), this.dataId = r, this.id = i, this.rankType = this.rank < 5 ? this.rank.toString() : "higher";
}
return Object.defineProperty(n.prototype, "rank", {get: function() {
return this.shape.length;
}, enumerable: true, configurable: true}), n.prototype.buffer = function() {
return pe(this, void 0, void 0, function() {
var t;
return fe(this, function(e) {
switch (e.label) {
case 0:
return [4, this.data()];
case 1:
return t = e.sent(), [2, Ai.buffer(this.shape, this.dtype, t)];
}
});
});
}, n.prototype.bufferSync = function() {
return Ai.buffer(this.shape, this.dtype, this.dataSync());
}, n.prototype.array = function() {
return pe(this, void 0, void 0, function() {
var t;
return fe(this, function(e) {
switch (e.label) {
case 0:
return [4, this.data()];
case 1:
return t = e.sent(), [2, Li(this.shape, t)];
}
});
});
}, n.prototype.arraySync = function() {
return Li(this.shape, this.dataSync());
}, n.prototype.data = function() {
return pe(this, void 0, void 0, function() {
var t, e;
return fe(this, function(r) {
switch (r.label) {
case 0:
return this.throwIfDisposed(), t = _n().read(this.dataId), this.dtype === "string" ? [4, t] : [3, 2];
case 1:
e = r.sent();
try {
return [2, e.map(function(i) {
return cu(i);
})];
} catch (i) {
throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
}
r.label = 2;
case 2:
return [2, t];
}
});
});
}, n.prototype.dataSync = function() {
this.throwIfDisposed();
var t = _n().readSync(this.dataId);
if (this.dtype === "string")
try {
return t.map(function(e) {
return cu(e);
});
} catch (e) {
throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
}
return t;
}, n.prototype.bytes = function() {
return pe(this, void 0, void 0, function() {
var t;
return fe(this, function(e) {
switch (e.label) {
case 0:
return this.throwIfDisposed(), [4, _n().read(this.dataId)];
case 1:
return t = e.sent(), this.dtype === "string" ? [2, t] : [2, new Uint8Array(t.buffer)];
}
});
});
}, n.prototype.dispose = function() {
if (this.isDisposed)
return;
_n().disposeTensor(this), this.isDisposedInternal = true;
}, Object.defineProperty(n.prototype, "isDisposed", {get: function() {
return this.isDisposedInternal;
}, enumerable: true, configurable: true}), n.prototype.throwIfDisposed = function() {
if (this.isDisposed)
throw new Error("Tensor is disposed.");
}, n.prototype.print = function(t) {
return t === void 0 && (t = false), Ai.print(this, t);
}, n.prototype.clone = function() {
return this.throwIfDisposed(), Ai.clone(this);
}, n.prototype.toString = function(t) {
t === void 0 && (t = false);
var e = this.dataSync();
return FL(e, this.shape, this.dtype, t);
}, n.prototype.cast = function(t) {
return this.throwIfDisposed(), Ai.cast(this, t);
}, n.prototype.variable = function(t, e, r) {
return t === void 0 && (t = true), this.throwIfDisposed(), _n().makeVariable(this, t, e, r);
}, n;
}();
Object.defineProperty(K, Symbol.hasInstance, {value: function(n) {
return !!n && n.data != null && n.dataSync != null && n.throwIfDisposed != null;
}});
var La = function(n) {
Yn(t, n);
function t(e, r, i, a) {
var s = n.call(this, e.shape, e.dtype, e.dataId, a) || this;
return s.trainable = r, s.name = i, s;
}
return t.prototype.assign = function(e) {
if (e.dtype !== this.dtype)
throw new Error("dtype of the new value (" + e.dtype + ") and " + ("previous value (" + this.dtype + ") must match"));
if (!pn(e.shape, this.shape))
throw new Error("shape of the new value (" + e.shape + ") and " + ("previous value (" + this.shape + ") must match"));
_n().disposeTensor(this), this.dataId = e.dataId, _n().incRef(this, null);
}, t.prototype.dispose = function() {
_n().disposeVariable(this), this.isDisposedInternal = true;
}, t;
}(K);
Object.defineProperty(La, Symbol.hasInstance, {value: function(n) {
return n instanceof K && n.assign != null && n.assign instanceof Function;
}});
(function(n) {
n.R0 = "R0", n.R1 = "R1", n.R2 = "R2", n.R3 = "R3", n.R4 = "R4", n.R5 = "R5", n.R6 = "R6";
})(A.Rank || (A.Rank = {}));
var uu;
(function(n) {
n.float32 = "float32", n.int32 = "int32", n.bool = "int32", n.complex64 = "complex64";
})(uu || (uu = {}));
var hu;
(function(n) {
n.float32 = "float32", n.int32 = "int32", n.bool = "bool", n.complex64 = "complex64";
})(hu || (hu = {}));
var du;
(function(n) {
n.float32 = "float32", n.int32 = "float32", n.bool = "float32", n.complex64 = "complex64";
})(du || (du = {}));
var pu;
(function(n) {
n.float32 = "complex64", n.int32 = "complex64", n.bool = "complex64", n.complex64 = "complex64";
})(pu || (pu = {}));
var BL = {float32: du, int32: uu, bool: hu, complex64: pu};
function Cs(n, t) {
if (n === "string" || t === "string") {
if (n === "string" && t === "string")
return "string";
throw new Error("Can not upcast " + n + " with " + t);
}
return BL[n][t];
}
function zL(n) {
return Cs(n, "int32");
}
function ct(n, t) {
if (n.dtype === t.dtype)
return [n, t];
var e = Cs(n.dtype, t.dtype);
return [n.cast(e), t.cast(e)];
}
function um(n, t) {
E(n.dtype === t.dtype, function() {
return "The dtypes of the first(" + n.dtype + ") and" + (" second(" + t.dtype + ") input must match");
});
}
function PL(n, t) {
return t.some(function(e) {
return e.id === n.id;
});
}
function fu(n) {
var t = [], e = new Set();
return hm(n, t, e), t;
}
function hm(n, t, e) {
if (n == null)
return;
if (n instanceof K) {
t.push(n);
return;
}
if (!ML(n))
return;
var r = n;
for (var i in r) {
var a = r[i];
e.has(a) || (e.add(a), hm(a, t, e));
}
}
function ML(n) {
return Array.isArray(n) || typeof n == "object";
}
var HL = {__proto__: null, makeTypesMatch: ct, assertTypesMatch: um, isTensorInList: PL, getTensorsInContainer: fu};
var dm = function() {
function n() {
this.registeredVariables = {}, this.nextTapeNodeId = 0, this.numBytes = 0, this.numTensors = 0, this.numStringTensors = 0, this.numDataBuffers = 0, this.gradientDepth = 0, this.kernelDepth = 0, this.scopeStack = [], this.numDataMovesStack = [], this.nextScopeId = 0, this.tensorInfo = new WeakMap(), this.profiling = false, this.activeProfile = {newBytes: 0, newTensors: 0, peakBytes: 0, kernels: [], result: null};
}
return n.prototype.dispose = function() {
for (var t in this.registeredVariables)
this.registeredVariables[t].dispose();
}, n;
}(), qL = function() {
function n(t) {
this.ENV = t, this.registry = {}, this.registryFactory = {}, this.pendingBackendInitId = 0, this.state = new dm();
}
return n.prototype.ready = function() {
return pe(this, void 0, void 0, function() {
var t, e, r, i;
return fe(this, function(a) {
switch (a.label) {
case 0:
if (this.pendingBackendInit != null)
return [2, this.pendingBackendInit.then(function() {
})];
if (this.backendInstance != null)
return [2];
t = this.getSortedBackends(), e = 0, a.label = 1;
case 1:
return e < t.length ? (r = t[e], [4, this.initializeBackend(r).success]) : [3, 5];
case 2:
return i = a.sent(), i ? [4, this.setBackend(r)] : [3, 4];
case 3:
return a.sent(), [2];
case 4:
return e++, [3, 1];
case 5:
throw new Error("Could not initialize any backends, all backend initializations failed.");
}
});
});
}, Object.defineProperty(n.prototype, "backend", {get: function() {
if (this.pendingBackendInit != null)
throw new Error("Backend '" + this.backendName + "' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods");
if (this.backendInstance == null) {
var t = this.initializeBackendsAndReturnBest(), e = t.name, r = t.asyncInit;
if (r)
throw new Error("The highest priority backend '" + e + "' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods");
this.setBackend(e);
}
return this.backendInstance;
}, enumerable: true, configurable: true}), n.prototype.backendNames = function() {
return Object.keys(this.registryFactory);
}, n.prototype.findBackend = function(t) {
if (!(t in this.registry))
if (t in this.registryFactory) {
var e = this.initializeBackend(t).asyncInit;
if (e)
return null;
} else
return null;
return this.registry[t];
}, n.prototype.findBackendFactory = function(t) {
return t in this.registryFactory ? this.registryFactory[t].factory : null;
}, n.prototype.registerBackend = function(t, e, r) {
return r === void 0 && (r = 1), t in this.registryFactory ? (console.warn(t + " backend was already registered. Reusing existing backend factory."), false) : (this.registryFactory[t] = {factory: e, priority: r}, true);
}, n.prototype.setBackend = function(t) {
return pe(this, void 0, void 0, function() {
var e, r, i, a, s;
return fe(this, function(o) {
switch (o.label) {
case 0:
if (this.registryFactory[t] == null)
throw new Error("Backend name '" + t + "' not found in registry");
return this.backendName = t, this.registry[t] == null ? (this.backendInstance = null, e = this.initializeBackend(t), r = e.success, i = e.asyncInit, i ? [4, r] : [3, 2]) : [3, 4];
case 1:
return s = o.sent(), [3, 3];
case 2:
s = r, o.label = 3;
case 3:
if (a = s, !a)
return [2, false];
o.label = 4;
case 4:
return this.backendInstance = this.registry[t], this.setupRegisteredKernels(), this.profiler = new OL(this.backendInstance), [2, true];
}
});
});
}, n.prototype.setupRegisteredKernels = function() {
var t = this, e = As(this.backendName);
e.forEach(function(r) {
r.setupFunc != null && r.setupFunc(t.backendInstance);
});
}, n.prototype.disposeRegisteredKernels = function(t) {
var e = this, r = As(t);
r.forEach(function(i) {
i.disposeFunc != null && i.disposeFunc(e.registry[t]);
});
}, n.prototype.initializeBackend = function(t) {
var e = this, r = this.registryFactory[t];
if (r == null)
throw new Error("Cannot initialize backend " + t + ", no registration found.");
try {
var i = r.factory();
if (i && !(i instanceof qp) && typeof i.then == "function") {
var a = ++this.pendingBackendInitId, s = i.then(function(o) {
return a < e.pendingBackendInitId ? false : (e.registry[t] = o, e.pendingBackendInit = null, true);
}).catch(function(o) {
return a < e.pendingBackendInitId || (e.pendingBackendInit = null, console.warn("Initialization of backend " + t + " failed"), console.warn(o.stack || o.message)), false;
});
return this.pendingBackendInit = s, {success: s, asyncInit: true};
} else
return this.registry[t] = i, {success: true, asyncInit: false};
} catch (o) {
return console.warn("Initialization of backend " + t + " failed"), console.warn(o.stack || o.message), {success: false, asyncInit: false};
}
}, n.prototype.removeBackend = function(t) {
if (!(t in this.registryFactory))
throw new Error(t + " backend not found in registry");
this.backendName === t && this.pendingBackendInit != null && this.pendingBackendInitId++, t in this.registry && (this.disposeRegisteredKernels(t), this.registry[t].dispose(), delete this.registry[t]), delete this.registryFactory[t], this.backendName === t && (this.pendingBackendInit = null, this.backendName = null, this.backendInstance = null);
}, n.prototype.getSortedBackends = function() {
var t = this;
if (Object.keys(this.registryFactory).length === 0)
throw new Error("No backend found in registry.");
return Object.keys(this.registryFactory).sort(function(e, r) {
return t.registryFactory[r].priority - t.registryFactory[e].priority;
});
}, n.prototype.initializeBackendsAndReturnBest = function() {
for (var t = this.getSortedBackends(), e = 0; e < t.length; e++) {
var r = t[e], i = this.initializeBackend(r), a = i.success, s = i.asyncInit;
if (s || a)
return {name: r, asyncInit: s};
}
throw new Error("Could not initialize any backends, all backend initializations failed.");
}, n.prototype.moveData = function(t, e) {
var r = this.state.tensorInfo.get(e), i = r.backend, a = this.readSync(e);
i.disposeData(e), r.backend = t, t.move(e, a, r.shape, r.dtype), this.shouldCheckForMemLeaks() && this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1]++;
}, n.prototype.tidy = function(t, e) {
var r = this, i = null;
if (e == null) {
if (typeof t != "function")
throw new Error("Please provide a function to tidy()");
e = t;
} else {
if (typeof t != "string" && !(t instanceof String))
throw new Error("When calling with two arguments, the first argument to tidy() must be a string");
if (typeof e != "function")
throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");
i = t;
}
var a;
return this.scopedRun(function() {
return r.startScope(i);
}, function() {
return r.endScope(a);
}, function() {
return a = e(), a instanceof Promise && console.error("Cannot return a Promise inside of tidy."), a;
});
}, n.prototype.scopedRun = function(t, e, r) {
t();
try {
var i = r();
return e(), i;
} catch (a) {
throw e(), a;
}
}, n.prototype.nextTensorId = function() {
return n.nextTensorId++;
}, n.prototype.nextVariableId = function() {
return n.nextVariableId++;
}, n.prototype.clone = function(t) {
var e = this.makeTensorFromDataId(t.dataId, t.shape, t.dtype), r = {x: t}, i = function(s) {
return {x: function() {
var o = "float32", c = {x: s}, l = {dtype: o};
return z.runKernelFunc(function(u) {
return u.cast(s, o);
}, c, null, Is, l);
}};
}, a = [];
return this.addTapeNode(this.state.activeScope.name, r, [e], i, a, {}), e;
}, n.prototype.runKernel = function(t, e, r, i, a) {
var s = null, o = null;
return this.runKernelFunc(s, e, o, t, r, i, a);
}, n.prototype.shouldCheckForMemLeaks = function() {
return this.ENV.getBool("IS_TEST");
}, n.prototype.checkKernelForMemLeak = function(t, e, r) {
var i = this.backend.numDataIds(), a = 0;
r.forEach(function(c) {
a += c.dtype === "complex64" ? 3 : 1;
});
var s = this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1], o = i - e - a - s;
if (o > 0)
throw new Error("Backend '" + this.backendName + "' has an internal memory leak " + ("(" + o + " data ids) after running '" + t + "'"));
}, n.prototype.runKernelFunc = function(t, e, r, i, a, s, o) {
var c = this, l, u = [], h = this.isTapeOn();
i == null && (i = this.state.activeScope != null ? this.state.activeScope.name : "");
var d = this.state.numBytes, p = this.state.numTensors;
this.shouldCheckForMemLeaks() && this.state.numDataMovesStack.push(0);
var f, m = iu(i, this.backendName), g;
if (m != null)
f = function() {
var b = c.backend.numDataIds();
g = m.kernelFunc({inputs: e, attrs: a, backend: c.backend});
var x = Array.isArray(g) ? g : [g];
c.shouldCheckForMemLeaks() && c.checkKernelForMemLeak(i, b, x);
var L = x.map(function(C) {
var O = C.dataId, D = C.shape, F = C.dtype;
return c.makeTensorFromDataId(O, D, F);
});
if (h) {
var N = c.getTensorsForGradient(i, e, L);
if (N == null) {
o == null && (o = []);
var I = L.filter(function(C, O) {
return o[O];
});
N = (s || []).slice().concat(I);
}
u = c.saveTensorsForBackwardMode(N);
}
return L;
};
else {
var y = function(b) {
if (!h)
return;
u = b.map(function(x) {
return c.keep(c.clone(x));
});
};
f = function() {
var b = c.backend.numDataIds();
g = c.tidy(function() {
return t(c.backend, y);
});
var x = Array.isArray(g) ? g : [g];
return c.shouldCheckForMemLeaks() && c.checkKernelForMemLeak(i, b, x), x;
};
}
var w;
return this.scopedRun(function() {
return c.state.kernelDepth++;
}, function() {
return c.state.kernelDepth--;
}, function() {
!c.ENV.getBool("DEBUG") && !c.state.profiling ? l = f() : (w = c.profiler.profileKernel(i, e, function() {
return f();
}), c.ENV.getBool("DEBUG") && c.profiler.logKernelProfile(w), l = w.outputs);
}), h && this.addTapeNode(i, e, l, r, u, a), this.state.profiling && this.state.activeProfile.kernels.push({name: i, bytesAdded: this.state.numBytes - d, totalBytesSnapshot: this.state.numBytes, tensorsAdded: this.state.numTensors - p, totalTensorsSnapshot: this.state.numTensors, inputShapes: Object.keys(e).map(function(b) {
return e[b] != null ? e[b].shape : null;
}), outputShapes: l.map(function(b) {
return b.shape;
}), kernelTimeMs: w.timeMs, extraInfo: w.extraInfo}), Array.isArray(g) ? l : l[0];
}, n.prototype.saveTensorsForBackwardMode = function(t) {
var e = this, r = t.map(function(i) {
return e.keep(e.clone(i));
});
return r;
}, n.prototype.getTensorsForGradient = function(t, e, r) {
var i = au(t);
if (i != null) {
var a = i.inputsToSave || [], s = i.outputsToSave || [], o = void 0;
i.saveAllInputs ? (E(Array.isArray(e), function() {
return "saveAllInputs is true, expected inputs to be an array.";
}), o = Object.keys(e).map(function(l) {
return e[l];
})) : o = a.map(function(l) {
return e[l];
});
var c = r.filter(function(l, u) {
return s[u];
});
return o.concat(c);
}
return null;
}, n.prototype.makeTensor = function(t, e, r, i) {
if (t == null)
throw new Error("Values passed to engine.makeTensor() are null");
r = r || "float32", i = i || this.backend;
var a = t;
r === "string" && lr(t[0]) && (a = t.map(function(u) {
return su(u);
}));
var s = i.write(a, e, r), o = new K(e, r, s, this.nextTensorId());
if (this.incRef(o, i), r === "string") {
var c = this.state.tensorInfo.get(s), l = ef(a);
this.state.numBytes += l - c.bytes, c.bytes = l;
}
return o;
}, n.prototype.makeTensorFromDataId = function(t, e, r, i) {
r = r || "float32";
var a = new K(e, r, t, this.nextTensorId());
return this.incRef(a, i), a;
}, n.prototype.makeVariable = function(t, e, r, i) {
e === void 0 && (e = true), r = r || this.nextVariableId().toString(), i != null && i !== t.dtype && (t = t.cast(i));
var a = new La(t, e, r, this.nextTensorId());
if (this.state.registeredVariables[a.name] != null)
throw new Error("Variable with name " + a.name + " was already registered");
return this.state.registeredVariables[a.name] = a, this.incRef(a, this.backend), a;
}, n.prototype.incRef = function(t, e) {
var r = this.state.tensorInfo.has(t.dataId) ? this.state.tensorInfo.get(t.dataId).refCount : 0;
if (this.state.numTensors++, t.dtype === "string" && this.state.numStringTensors++, r === 0) {
this.state.numDataBuffers++;
var i = 0;
t.dtype !== "complex64" && t.dtype !== "string" && (i = t.size * Qp(t.dtype)), this.state.tensorInfo.set(t.dataId, {backend: e || this.backend, dtype: t.dtype, shape: t.shape, bytes: i, refCount: 0}), this.state.numBytes += i;
}
this.state.tensorInfo.get(t.dataId).refCount++, t instanceof La || this.track(t);
}, n.prototype.disposeTensor = function(t) {
if (!this.state.tensorInfo.has(t.dataId))
return;
this.state.numTensors--, t.dtype === "string" && this.state.numStringTensors--;
var e = this.state.tensorInfo.get(t.dataId), r = e.refCount;
r <= 1 ? (t.dtype !== "complex64" && (this.state.numBytes -= e.bytes), this.state.numDataBuffers--, e.backend.disposeData(t.dataId), this.state.tensorInfo.delete(t.dataId)) : this.state.tensorInfo.get(t.dataId).refCount--;
}, n.prototype.disposeVariables = function() {
for (var t in this.state.registeredVariables) {
var e = this.state.registeredVariables[t];
this.disposeVariable(e);
}
}, n.prototype.disposeVariable = function(t) {
this.disposeTensor(t), this.state.registeredVariables[t.name] != null && delete this.state.registeredVariables[t.name];
}, n.prototype.memory = function() {
var t = this.backend.memory();
return t.numTensors = this.state.numTensors, t.numDataBuffers = this.state.numDataBuffers, t.numBytes = this.state.numBytes, this.state.numStringTensors > 0 && (t.unreliable = true, t.reasons == null && (t.reasons = []), t.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")), t;
}, n.prototype.profile = function(t) {
return pe(this, void 0, void 0, function() {
var e, r, i, a, s, o, c, l;
return fe(this, function(u) {
switch (u.label) {
case 0:
return this.state.profiling = true, e = this.state.numBytes, r = this.state.numTensors, this.state.activeProfile.kernels = [], i = this.state.activeProfile, [4, t()];
case 1:
i.result = u.sent(), this.state.profiling = false, this.state.activeProfile.peakBytes = Math.max.apply(Math, this.state.activeProfile.kernels.map(function(h) {
return h.totalBytesSnapshot;
})), this.state.activeProfile.newBytes = this.state.numBytes - e, this.state.activeProfile.newTensors = this.state.numTensors - r, a = 0, s = this.state.activeProfile.kernels, u.label = 2;
case 2:
return a < s.length ? (o = s[a], c = o, [4, o.kernelTimeMs]) : [3, 6];
case 3:
return c.kernelTimeMs = u.sent(), l = o, [4, o.extraInfo];
case 4:
l.extraInfo = u.sent(), u.label = 5;
case 5:
return a++, [3, 2];
case 6:
return [2, this.state.activeProfile];
}
});
});
}, n.prototype.isTapeOn = function() {
return this.state.gradientDepth > 0 && this.state.kernelDepth === 0;
}, n.prototype.addTapeNode = function(t, e, r, i, a, s) {
var o = this, c = {id: this.state.nextTapeNodeId++, kernelName: t, inputs: e, outputs: r, saved: a}, l = au(t);
l != null && (i = l.gradFunc), i != null && (c.gradient = function(u) {
return u = u.map(function(h, d) {
if (h == null) {
var p = r[d], f = Si(p.size, p.dtype);
return o.makeTensor(f, p.shape, p.dtype);
}
return h;
}), i(u.length > 1 ? u : u[0], a, s);
}), this.state.activeTape.push(c);
}, n.prototype.keep = function(t) {
return t.kept = true, t;
}, n.prototype.startTape = function() {
this.state.gradientDepth === 0 && (this.state.activeTape = []), this.state.gradientDepth++;
}, n.prototype.endTape = function() {
this.state.gradientDepth--;
}, n.prototype.startScope = function(t) {
var e = {track: [], name: "unnamed scope", id: this.state.nextScopeId++};
t && (e.name = t), this.state.scopeStack.push(e), this.state.activeScope = e;
}, n.prototype.endScope = function(t) {
for (var e = this, r = fu(t), i = new Set(r.map(function(c) {
return c.id;
})), a = 0; a < this.state.activeScope.track.length; a++) {
var s = this.state.activeScope.track[a];
!s.kept && !i.has(s.id) && s.dispose();
}
var o = this.state.scopeStack.pop();
this.state.activeScope = this.state.scopeStack.length === 0 ? null : this.state.scopeStack[this.state.scopeStack.length - 1], r.forEach(function(c) {
!c.kept && c.scopeId === o.id && e.track(c);
});
}, n.prototype.gradients = function(t, e, r, i) {
var a = this;
if (i === void 0 && (i = false), E(e.length > 0, function() {
return "gradients() received an empty list of xs.";
}), r != null && r.dtype !== "float32")
throw new Error("dy must have 'float32' dtype, but has '" + r.dtype + "'");
var s = this.scopedRun(function() {
return a.startTape();
}, function() {
return a.endTape();
}, function() {
return a.tidy("forward", t);
});
E(s instanceof K, function() {
return "The result y returned by f() must be a tensor.";
});
var o = EL(this.state.activeTape, e, s);
if (!i && o.length === 0 && e.length > 0)
throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that the f you passed encloses all operations that lead from x to y.");
return this.tidy("backward", function() {
var c = {};
c[s.id] = r != null ? r : VL(s.shape), DL(c, o, function(u) {
return a.tidy(u);
}, GL);
var l = e.map(function(u) {
return c[u.id];
});
return a.state.gradientDepth === 0 && (a.state.activeTape.forEach(function(u) {
for (var h = 0, d = u.saved; h < d.length; h++) {
var p = d[h];
p.dispose();
}
}), a.state.activeTape = null), {value: s, grads: l};
});
}, n.prototype.customGrad = function(t) {
var e = this;
return E(ur(t), function() {
return "The f passed in customGrad(f) must be a function.";
}), function() {
for (var r = [], i = 0; i < arguments.length; i++)
r[i] = arguments[i];
E(r.every(function(o) {
return o instanceof K;
}), function() {
return "The args passed in customGrad(f)(x1, x2,...) must all be tensors";
});
var a, s = {};
return r.forEach(function(o, c) {
s[c] = o;
}), e.runKernelFunc(function(o, c) {
return a = t.apply(void 0, r.concat([c])), E(a.value instanceof K, function() {
return "The function f passed in customGrad(f) must return an object where `obj.value` is a tensor";
}), E(ur(a.gradFunc), function() {
return "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function.";
}), a.value;
}, s, function(o, c) {
var l = a.gradFunc(o, c), u = Array.isArray(l) ? l : [l];
E(u.length === r.length, function() {
return "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns the same number of tensors as inputs passed to f(...).";
}), E(u.every(function(d) {
return d instanceof K;
}), function() {
return "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors.";
});
var h = {};
return u.forEach(function(d, p) {
h[p] = function() {
return d;
};
}), h;
});
};
}, n.prototype.readSync = function(t) {
var e = this.state.tensorInfo.get(t);
return e.backend.readSync(t);
}, n.prototype.read = function(t) {
var e = this.state.tensorInfo.get(t);
return e.backend.read(t);
}, n.prototype.time = function(t) {
return pe(this, void 0, void 0, function() {
var e, r;
return fe(this, function(i) {
switch (i.label) {
case 0:
return e = ou(), [4, this.backend.time(t)];
case 1:
return r = i.sent(), r.wallMs = ou() - e, [2, r];
}
});
});
}, n.prototype.track = function(t) {
return this.state.activeScope != null && (t.scopeId = this.state.activeScope.id, this.state.activeScope.track.push(t)), t;
}, Object.defineProperty(n.prototype, "registeredVariables", {get: function() {
return this.state.registeredVariables;
}, enumerable: true, configurable: true}), n.prototype.reset = function() {
this.pendingBackendInitId++, this.state.dispose(), this.ENV.reset(), this.state = new dm();
for (var t in this.registry)
this.disposeRegisteredKernels(t), this.registry[t].dispose(), delete this.registry[t];
this.backendName = null, this.backendInstance = null, this.pendingBackendInit = null;
}, n.nextTensorId = 0, n.nextVariableId = 0, n;
}();
function VL(n) {
var t = hc(dt(n), "float32");
return z.makeTensor(t, n, "float32");
}
function pm() {
var n = of();
if (n._tfengine == null) {
var t = new sf(n);
n._tfengine = new qL(t);
}
return wL(n._tfengine.ENV), WL(function() {
return n._tfengine;
}), n._tfengine;
}
var z = pm();
function GL(n, t) {
var e = {a: n, b: t};
return z.runKernelFunc(function(r, i) {
var a = r.add(n, t);
return i([n, t]), a;
}, e, null, Ss);
}
function YL() {
return typeof navigator != "undefined" && navigator != null;
}
function KL() {
if (YL()) {
var n = navigator.userAgent || navigator.vendor || window.opera;
return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(n) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(n.substr(0, 4));
}
return false;
}
function fm() {
return typeof window != "undefined" && window.document != null || typeof WorkerGlobalScope != "undefined";
}
var jL = {__proto__: null, isMobile: KL, isBrowser: fm};
var Kn = qe();
Kn.registerFlag("DEBUG", function() {
return false;
}, function(n) {
n && console.warn("Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.");
});
Kn.registerFlag("IS_BROWSER", function() {
return fm();
});
Kn.registerFlag("IS_NODE", function() {
return typeof process != "undefined" && typeof process.versions != "undefined" && typeof process.versions.node != "undefined";
});
Kn.registerFlag("IS_CHROME", function() {
return typeof navigator != "undefined" && navigator != null && navigator.userAgent != null && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
});
Kn.registerFlag("PROD", function() {
return false;
});
Kn.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY", function() {
return Kn.getBool("DEBUG");
});
Kn.registerFlag("DEPRECATION_WARNINGS_ENABLED", function() {
return true;
});
Kn.registerFlag("IS_TEST", function() {
return false;
});
function Cn(n, t) {
var e = n;
if (Ft(n))
return t === "string" ? [] : [n.length];
if (!Array.isArray(n))
return [];
for (var r = []; Array.isArray(e) || Ft(e) && t !== "string"; )
r.push(e.length), e = e[0];
return Array.isArray(n) && qe().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY") && mm(n, r, []), r;
}
function mm(n, t, e) {
if (e = e || [], !Array.isArray(n) && !Ft(n)) {
E(t.length === 0, function() {
return "Element arr[" + e.join("][") + "] is a primitive, " + ("but should be an array/TypedArray of " + t[0] + " elements");
});
return;
}
E(t.length > 0, function() {
return "Element arr[" + e.join("][") + "] should be a primitive, " + ("but is an array of " + n.length + " elements");
}), E(n.length === t[0], function() {
return "Element arr[" + e.join("][") + "] should have " + t[0] + " " + ("elements, but has " + n.length + " elements");
});
for (var r = t.slice(1), i = 0; i < n.length; ++i)
mm(n[i], r, e.concat(i));
}
function gm(n, t, e, r) {
if (n == null)
return;
if (n !== "numeric" && n !== t || n === "numeric" && t === "string")
throw new Error("Argument '" + e + "' passed to '" + r + "' must " + ("be " + n + " tensor, but got " + t + " tensor"));
}
function R(n, t, e, r) {
if (r === void 0 && (r = "numeric"), n instanceof K)
return gm(r, n.dtype, t, e), n;
var i = xs(n);
if (i !== "string" && ["bool", "int32", "float32"].indexOf(r) >= 0 && (i = r), gm(r, i, t, e), n == null || !Ft(n) && !Array.isArray(n) && typeof n != "number" && typeof n != "boolean" && typeof n != "string") {
var a = n == null ? "null" : n.constructor.name;
throw new Error("Argument '" + t + "' passed to '" + e + "' must be a " + ("Tensor or TensorLike, but got '" + a + "'"));
}
var s = Cn(n, i);
!Ft(n) && !Array.isArray(n) && (n = [n]);
var o = true, c = i !== "string" ? Ts(n, i) : zr(n, [], o);
return z.makeTensor(c, s, i);
}
function Sa(n, t, e, r) {
if (r === void 0 && (r = "numeric"), !Array.isArray(n))
throw new Error("Argument " + t + " passed to " + e + " must be a `Tensor[]` or `TensorLike[]`");
var i = n;
return i.map(function(a, s) {
return R(a, t + "[" + s + "]", e);
}, r);
}
var ym = "__op";
function U(n) {
var t = Object.keys(n);
if (t.length !== 1)
throw new Error("Please provide an object with a single key (operation name) mapping to a function. Got an object with " + (t.length + " keys."));
var e = t[0], r = n[e];
e.endsWith("_") && (e = e.substring(0, e.length - 1)), e = e + ym;
var i = function() {
for (var a = [], s = 0; s < arguments.length; s++)
a[s] = arguments[s];
z.startScope(e);
try {
var o = r.apply(void 0, a);
return pc(o) && console.error("Cannot return a Promise inside of tidy."), z.endScope(o), o;
} catch (c) {
throw z.endScope(null), c;
}
};
return Object.defineProperty(i, "name", {value: e, configurable: true}), i;
}
function $L(n, t) {
var e = R(n, "real", "complex"), r = R(t, "imag", "complex");
Pe(e.shape, r.shape, "real and imag shapes, " + e.shape + " and " + r.shape + ", must match in call to tf.complex().");
var i = function(s) {
return s.complex(e, r);
}, a = {real: e, imag: r};
return z.runKernelFunc(i, a, null, pf);
}
var hr = U({complex_: $L});
function dr(n, t, e, r) {
if (r == null && (r = xs(n)), r === "complex64")
throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).");
if (!Ft(n) && !Array.isArray(n) && typeof n != "number" && typeof n != "boolean" && typeof n != "string")
throw new Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray");
if (t != null) {
dc(t);
var i = dt(t), a = dt(e);
E(i === a, function() {
return "Based on the provided shape, [" + t + "], the tensor should have " + (i + " values but has " + a);
});
for (var s = 0; s < e.length; ++s) {
var o = e[s], c = s === e.length - 1 ? o !== dt(t.slice(s)) : true;
E(e[s] === t[s] || !c, function() {
return "Error creating a new Tensor. Inferred shape " + ("(" + e + ") does not match the provided ") + ("shape (" + t + "). ");
});
}
}
return !Ft(n) && !Array.isArray(n) && (n = [n]), t = t || e, n = r !== "string" ? Ts(n, r) : zr(n, [], true), z.makeTensor(n, t, r);
}
function pr(n, t, e) {
var r = Cn(n, e);
return dr(n, t, r, e);
}
var mu = {float32: 4, float16: 2, int32: 4, uint16: 2, uint8: 1, bool: 1, complex64: 8};
var Rs = 4;
function JL(n, t) {
return pe(this, void 0, void 0, function() {
var e, r, i, a, s, o, c = this;
return fe(this, function(l) {
switch (l.label) {
case 0:
for (e = [], r = [], i = Array.isArray(n) ? n.map(function(u) {
return u.name;
}) : Object.keys(n), a = function(u) {
var h = i[u], d = Array.isArray(n) ? n[u].tensor : n[h];
if (d.dtype !== "float32" && d.dtype !== "int32" && d.dtype !== "bool" && d.dtype !== "string" && d.dtype !== "complex64")
throw new Error("Unsupported dtype in weight '" + h + "': " + d.dtype);
var p = {name: h, shape: d.shape, dtype: d.dtype};
if (d.dtype === "string") {
var f = new Promise(function(m) {
return pe(c, void 0, void 0, function() {
var g, y, w, b, x, L, N;
return fe(this, function(I) {
switch (I.label) {
case 0:
return [4, d.bytes()];
case 1:
for (g = I.sent(), y = g.reduce(function(C, O) {
return C + O.length;
}, 0) + Rs * g.length, w = new Uint8Array(y), b = 0, x = 0; x < g.length; x++)
L = g[x], N = new Uint8Array(new Uint32Array([L.length]).buffer), w.set(N, b), b += Rs, w.set(L, b), b += L.length;
return m(w), [2];
}
});
});
});
r.push(f);
} else
r.push(d.data());
t != null && (p.group = t), e.push(p);
}, s = 0; s < i.length; ++s)
a(s);
return [4, Promise.all(r)];
case 1:
return o = l.sent(), [2, {data: XL(o), specs: e}];
}
});
});
}
function vm(n, t) {
for (var e = {}, r, i = 0, a = 0, s = t; a < s.length; a++) {
var o = s[a], c = o.name, l = o.dtype, u = o.shape, h = dt(u), d = void 0;
if ("quantization" in o) {
var p = o.quantization;
if (p.dtype === "uint8" || p.dtype === "uint16") {
if (!("min" in p && "scale" in p))
throw new Error("Weight " + o.name + " with quantization " + p.dtype + " doesn't have corresponding metadata min and scale.");
} else if (p.dtype === "float16") {
if (l !== "float32")
throw new Error("Weight " + o.name + " is quantized with " + p.dtype + " " + ("which only supports weights of type float32 not " + l + "."));
} else
throw new Error("Weight " + o.name + " has unknown " + ("quantization dtype " + p.dtype + ". ") + "Supported quantization dtypes are: 'uint8', 'uint16', and 'float16'.");
var f = mu[p.dtype], m = n.slice(i, i + h * f), g = p.dtype === "uint8" ? new Uint8Array(m) : new Uint16Array(m);
if (l === "float32")
if (p.dtype === "uint8" || p.dtype === "uint16") {
d = new Float32Array(g.length);
for (var y = 0; y < g.length; y++) {
var w = g[y];
d[y] = w * p.scale + p.min;
}
} else if (p.dtype === "float16")
r === void 0 && (r = ZL()), d = r(g);
else
throw new Error("Unsupported quantization type " + p.dtype + " for weight type float32.");
else if (l === "int32") {
if (p.dtype !== "uint8" && p.dtype !== "uint16")
throw new Error("Unsupported quantization type " + p.dtype + " for weight type int32.");
d = new Int32Array(g.length);
for (var y = 0; y < g.length; y++) {
var w = g[y];
d[y] = Math.round(w * p.scale + p.min);
}
} else
throw new Error("Unsupported dtype in weight '" + c + "': " + l);
i += h * f;
} else if (l === "string") {
var b = dt(o.shape);
d = [];
for (var y = 0; y < b; y++) {
var x = new Uint32Array(n.slice(i, i + Rs))[0];
i += Rs;
var L = new Uint8Array(n.slice(i, i + x));
d.push(L), i += x;
}
} else {
var N = mu[l], m = n.slice(i, i + h * N);
if (l === "float32")
d = new Float32Array(m);
else if (l === "int32")
d = new Int32Array(m);
else if (l === "bool")
d = new Uint8Array(m);
else if (l === "complex64") {
d = new Float32Array(m);
for (var I = new Float32Array(d.length / 2), C = new Float32Array(d.length / 2), y = 0; y < I.length; y++)
I[y] = d[y * 2], C[y] = d[y * 2 + 1];
var O = pr(I, u, "float32"), D = pr(C, u, "float32");
e[c] = hr(O, D), O.dispose(), D.dispose();
} else
throw new Error("Unsupported dtype in weight '" + c + "': " + l);
i += h * N;
}
l !== "complex64" && (e[c] = pr(d, u, l));
}
return e;
}
function XL(n) {
if (n === null)
throw new Error("Invalid input value: " + JSON.stringify(n));
var t = 0, e = [];
n.forEach(function(a) {
if (t += a.byteLength, e.push(a.byteLength === a.buffer.byteLength ? a : new a.constructor(a)), !(a instanceof Float32Array || a instanceof Int32Array || a instanceof Uint8Array))
throw new Error("Unsupported TypedArray subtype: " + a.constructor.name);
});
var r = new Uint8Array(t), i = 0;
return e.forEach(function(a) {
r.set(new Uint8Array(a.buffer), i), i += a.byteLength;
}), r.buffer;
}
var gu = typeof Buffer != "undefined" && (typeof Blob == "undefined" || typeof atob == "undefined" || typeof btoa == "undefined");
function wm(n) {
return gu ? Buffer.byteLength(n) : new Blob([n]).size;
}
function QL(n) {
if (gu)
return Buffer.from(n).toString("base64");
for (var t = new Uint8Array(n), e = "", r = 0, i = t.length; r < i; r++)
e += String.fromCharCode(t[r]);
return btoa(e);
}
function eS(n) {
if (gu) {
var t = Buffer.from(n, "base64");
return t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength);
}
for (var e = atob(n), r = new Uint8Array(e.length), i = 0; i < e.length; ++i)
r.set([e.charCodeAt(i)], i);
return r.buffer;
}
function yu(n) {
if (n.length === 1)
return n[0];
var t = 0;
n.forEach(function(i) {
t += i.byteLength;
});
var e = new Uint8Array(t), r = 0;
return n.forEach(function(i) {
e.set(new Uint8Array(i), r), r += i.byteLength;
}), e.buffer;
}
function bm(n) {
var t = "/";
for (n = n.trim(); n.endsWith(t); )
n = n.slice(0, n.length - 1);
var e = n.split(t);
return e[e.length - 1];
}
function Ia(n) {
if (n.modelTopology instanceof ArrayBuffer)
throw new Error("Expected JSON model topology, received ArrayBuffer.");
return {dateSaved: new Date(), modelTopologyType: "JSON", modelTopologyBytes: n.modelTopology == null ? 0 : wm(JSON.stringify(n.modelTopology)), weightSpecsBytes: n.weightSpecs == null ? 0 : wm(JSON.stringify(n.weightSpecs)), weightDataBytes: n.weightData == null ? 0 : n.weightData.byteLength};
}
function tS() {
var n = function(r) {
for (var i = r << 13, a = 0; (i & 8388608) === 0; )
a -= 8388608, i <<= 1;
return i &= ~8388608, a += 947912704, i | a;
}, t = new Uint32Array(2048);
t[0] = 0;
for (var e = 1; e < 1024; e++)
t[e] = n(e);
for (var e = 1024; e < 2048; e++)
t[e] = 939524096 + (e - 1024 << 13);
return t;
}
function nS() {
var n = new Uint32Array(64);
n[0] = 0, n[31] = 1199570944, n[32] = 2147483648, n[63] = 3347054592;
for (var t = 1; t < 31; t++)
n[t] = t << 23;
for (var t = 33; t < 63; t++)
n[t] = 2147483648 + (t - 32 << 23);
return n;
}
function rS() {
for (var n = new Uint32Array(64), t = 0; t < 64; t++)
n[t] = 1024;
return n[0] = n[32] = 0, n;
}
function ZL() {
var n = tS(), t = nS(), e = rS();
return function(r) {
for (var i = new ArrayBuffer(4 * r.length), a = new Uint32Array(i), s = 0; s < r.length; s++) {
var o = r[s], c = n[e[o >> 10] + (o & 1023)] + t[o >> 10];
a[s] = c;
}
return new Float32Array(i);
};
}
var rn = function() {
function n() {
this.saveRouters = [], this.loadRouters = [];
}
return n.getInstance = function() {
return n.instance == null && (n.instance = new n()), n.instance;
}, n.registerSaveRouter = function(t) {
n.getInstance().saveRouters.push(t);
}, n.registerLoadRouter = function(t) {
n.getInstance().loadRouters.push(t);
}, n.getSaveHandlers = function(t) {
return n.getHandlers(t, "save");
}, n.getLoadHandlers = function(t, e) {
return n.getHandlers(t, "load", e);
}, n.getHandlers = function(t, e, r) {
var i = [], a = e === "load" ? n.getInstance().loadRouters : n.getInstance().saveRouters;
return a.forEach(function(s) {
var o = s(t, r);
o !== null && i.push(o);
}), i;
}, n;
}(), iS = function(n) {
return rn.registerSaveRouter(n);
}, aS = function(n) {
return rn.registerLoadRouter(n);
}, sS = function(n) {
return rn.getSaveHandlers(n);
}, oS = function(n, t) {
return rn.getLoadHandlers(n, t);
};
var vu = "tensorflowjs", wu = 1, Pr = "models_store", fr = "model_info_store";
function xm() {
if (!qe().getBool("IS_BROWSER"))
throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser.");
var n = typeof window == "undefined" ? self : window, t = n.indexedDB || n.mozIndexedDB || n.webkitIndexedDB || n.msIndexedDB || n.shimIndexedDB;
if (t == null)
throw new Error("The current browser does not appear to support IndexedDB.");
return t;
}
function bu(n) {
var t = n.result;
t.createObjectStore(Pr, {keyPath: "modelPath"}), t.createObjectStore(fr, {keyPath: "modelPath"});
}
var Ti = function() {
function n(t) {
if (this.indexedDB = xm(), t == null || !t)
throw new Error("For IndexedDB, modelPath must not be null, undefined or empty.");
this.modelPath = t;
}
return n.prototype.save = function(t) {
return pe(this, void 0, void 0, function() {
return fe(this, function(e) {
if (t.modelTopology instanceof ArrayBuffer)
throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");
return [2, this.databaseAction(this.modelPath, t)];
});
});
}, n.prototype.load = function() {
return pe(this, void 0, void 0, function() {
return fe(this, function(t) {
return [2, this.databaseAction(this.modelPath)];
});
});
}, n.prototype.databaseAction = function(t, e) {
var r = this;
return new Promise(function(i, a) {
var s = r.indexedDB.open(vu, wu);
s.onupgradeneeded = function() {
return bu(s);
}, s.onsuccess = function() {
var o = s.result;
if (e == null) {
var c = o.transaction(Pr, "readonly"), l = c.objectStore(Pr), u = l.get(r.modelPath);
u.onsuccess = function() {
if (u.result == null)
return o.close(), a(new Error("Cannot find model with path '" + r.modelPath + "' in IndexedDB."));
i(u.result.modelArtifacts);
}, u.onerror = function(g) {
return o.close(), a(u.error);
}, c.oncomplete = function() {
return o.close();
};
} else {
var h = Ia(e), d = o.transaction(fr, "readwrite"), p = d.objectStore(fr), f = p.put({modelPath: r.modelPath, modelArtifactsInfo: h}), m;
f.onsuccess = function() {
m = o.transaction(Pr, "readwrite");
var g = m.objectStore(Pr), y = g.put({modelPath: r.modelPath, modelArtifacts: e, modelArtifactsInfo: h});
y.onsuccess = function() {
return i({modelArtifactsInfo: h});
}, y.onerror = function(w) {
p = d.objectStore(fr);
var b = p.delete(r.modelPath);
b.onsuccess = function() {
return o.close(), a(y.error);
}, b.onerror = function(x) {
return o.close(), a(y.error);
};
};
}, f.onerror = function(g) {
return o.close(), a(f.error);
}, d.oncomplete = function() {
m == null ? o.close() : m.oncomplete = function() {
return o.close();
};
};
}
}, s.onerror = function(o) {
return a(s.error);
};
});
}, n.URL_SCHEME = "indexeddb://", n;
}(), Lm = function(n) {
return qe().getBool("IS_BROWSER") && (!Array.isArray(n) && n.startsWith(Ti.URL_SCHEME)) ? cS(n.slice(Ti.URL_SCHEME.length)) : null;
};
rn.registerSaveRouter(Lm);
rn.registerLoadRouter(Lm);
function cS(n) {
return new Ti(n);
}
function lS(n) {
return n.startsWith(Ti.URL_SCHEME) ? n.slice(Ti.URL_SCHEME.length) : n;
}
var uS = function() {
function n() {
this.indexedDB = xm();
}
return n.prototype.listModels = function() {
return pe(this, void 0, void 0, function() {
var t = this;
return fe(this, function(e) {
return [2, new Promise(function(r, i) {
var a = t.indexedDB.open(vu, wu);
a.onupgradeneeded = function() {
return bu(a);
}, a.onsuccess = function() {
var s = a.result, o = s.transaction(fr, "readonly"), c = o.objectStore(fr), l = c.getAll();
l.onsuccess = function() {
for (var u = {}, h = 0, d = l.result; h < d.length; h++) {
var p = d[h];
u[p.modelPath] = p.modelArtifactsInfo;
}
r(u);
}, l.onerror = function(u) {
return s.close(), i(l.error);
}, o.oncomplete = function() {
return s.close();
};
}, a.onerror = function(s) {
return i(a.error);
};
})];
});
});
}, n.prototype.removeModel = function(t) {
return pe(this, void 0, void 0, function() {
var e = this;
return fe(this, function(r) {
return t = lS(t), [2, new Promise(function(i, a) {
var s = e.indexedDB.open(vu, wu);
s.onupgradeneeded = function() {
return bu(s);
}, s.onsuccess = function() {
var o = s.result, c = o.transaction(fr, "readwrite"), l = c.objectStore(fr), u = l.get(t), h;
u.onsuccess = function() {
if (u.result == null)
return o.close(), a(new Error("Cannot find model with path '" + t + "' in IndexedDB."));
var d = l.delete(t), p = function() {
h = o.transaction(Pr, "readwrite");
var f = h.objectStore(Pr), m = f.delete(t);
m.onsuccess = function() {
return i(u.result.modelArtifactsInfo);
}, m.onerror = function(g) {
return a(u.error);
};
};
d.onsuccess = p, d.onerror = function(f) {
return p(), o.close(), a(u.error);
};
}, u.onerror = function(d) {
return o.close(), a(u.error);
}, c.oncomplete = function() {
h == null ? o.close() : h.oncomplete = function() {
return o.close();
};
};
}, s.onerror = function(o) {
return a(s.error);
};
})];
});
});
}, n;
}();
var jn = "/", Ni = "tensorflowjs_models", Sm = "info", hS = "model_topology", dS = "weight_specs", pS = "weight_data", fS = "model_metadata";
function Im(n) {
return {info: [Ni, n, Sm].join(jn), topology: [Ni, n, hS].join(jn), weightSpecs: [Ni, n, dS].join(jn), weightData: [Ni, n, pS].join(jn), modelMetadata: [Ni, n, fS].join(jn)};
}
function mS(n) {
var t = n.split(jn);
if (t.length < 3)
throw new Error("Invalid key format: " + n);
return t.slice(1, t.length - 1).join(jn);
}
function gS(n) {
return n.startsWith(_i.URL_SCHEME) ? n.slice(_i.URL_SCHEME.length) : n;
}
var _i = function() {
function n(t) {
if (!qe().getBool("IS_BROWSER") || typeof window == "undefined" || typeof window.localStorage == "undefined")
throw new Error("The current environment does not support local storage.");
if (this.LS = window.localStorage, t == null || !t)
throw new Error("For local storage, modelPath must not be null, undefined or empty.");
this.modelPath = t, this.keys = Im(this.modelPath);
}
return n.prototype.save = function(t) {
return pe(this, void 0, void 0, function() {
var e, r, i;
return fe(this, function(a) {
if (t.modelTopology instanceof ArrayBuffer)
throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");
e = JSON.stringify(t.modelTopology), r = JSON.stringify(t.weightSpecs), i = Ia(t);
try {
return this.LS.setItem(this.keys.info, JSON.stringify(i)), this.LS.setItem(this.keys.topology, e), this.LS.setItem(this.keys.weightSpecs, r), this.LS.setItem(this.keys.weightData, QL(t.weightData)), this.LS.setItem(this.keys.modelMetadata, JSON.stringify({format: t.format, generatedBy: t.generatedBy, convertedBy: t.convertedBy, userDefinedMetadata: t.userDefinedMetadata})), [2, {modelArtifactsInfo: i}];
} catch (s) {
throw this.LS.removeItem(this.keys.info), this.LS.removeItem(this.keys.topology), this.LS.removeItem(this.keys.weightSpecs), this.LS.removeItem(this.keys.weightData), this.LS.removeItem(this.keys.modelMetadata), new Error("Failed to save model '" + this.modelPath + "' to local storage: size quota being exceeded is a possible cause of this failure: " + ("modelTopologyBytes=" + i.modelTopologyBytes + ", ") + ("weightSpecsBytes=" + i.weightSpecsBytes + ", ") + ("weightDataBytes=" + i.weightDataBytes + "."));
}
return [2];
});
});
}, n.prototype.load = function() {
return pe(this, void 0, void 0, function() {
var t, e, r, i, a, s, o;
return fe(this, function(c) {
if (t = JSON.parse(this.LS.getItem(this.keys.info)), t == null)
throw new Error("In local storage, there is no model with name '" + this.modelPath + "'");
if (t.modelTopologyType !== "JSON")
throw new Error("BrowserLocalStorage does not support loading non-JSON model topology yet.");
if (e = {}, r = JSON.parse(this.LS.getItem(this.keys.topology)), r == null)
throw new Error("In local storage, the topology of model '" + this.modelPath + "' is missing.");
if (e.modelTopology = r, i = JSON.parse(this.LS.getItem(this.keys.weightSpecs)), i == null)
throw new Error("In local storage, the weight specs of model '" + this.modelPath + "' are missing.");
if (e.weightSpecs = i, a = this.LS.getItem(this.keys.modelMetadata), a != null && (s = JSON.parse(a), e.format = s.format, e.generatedBy = s.generatedBy, e.convertedBy = s.convertedBy, e.userDefinedMetadata = s.userDefinedMetadata), o = this.LS.getItem(this.keys.weightData), o == null)
throw new Error("In local storage, the binary weight values of model " + ("'" + this.modelPath + "' are missing."));
return e.weightData = eS(o), [2, e];
});
});
}, n.URL_SCHEME = "localstorage://", n;
}(), Am = function(n) {
return qe().getBool("IS_BROWSER") && (!Array.isArray(n) && n.startsWith(_i.URL_SCHEME)) ? yS(n.slice(_i.URL_SCHEME.length)) : null;
};
rn.registerSaveRouter(Am);
rn.registerLoadRouter(Am);
function yS(n) {
return new _i(n);
}
var vS = function() {
function n() {
E(qe().getBool("IS_BROWSER"), function() {
return "Current environment is not a web browser";
}), E(typeof window == "undefined" || typeof window.localStorage != "undefined", function() {
return "Current browser does not appear to support localStorage";
}), this.LS = window.localStorage;
}
return n.prototype.listModels = function() {
return pe(this, void 0, void 0, function() {
var t, e, r, i, a, s;
return fe(this, function(o) {
for (t = {}, e = Ni + jn, r = jn + Sm, i = 0; i < this.LS.length; ++i)
a = this.LS.key(i), a.startsWith(e) && a.endsWith(r) && (s = mS(a), t[s] = JSON.parse(this.LS.getItem(a)));
return [2, t];
});
});
}, n.prototype.removeModel = function(t) {
return pe(this, void 0, void 0, function() {
var e, r;
return fe(this, function(i) {
if (t = gS(t), e = Im(t), this.LS.getItem(e.info) == null)
throw new Error("Cannot find model at path '" + t + "'");
return r = JSON.parse(this.LS.getItem(e.info)), this.LS.removeItem(e.info), this.LS.removeItem(e.topology), this.LS.removeItem(e.weightSpecs), this.LS.removeItem(e.weightData), [2, r];
});
});
}, n;
}();
var Ci = "://", mr = function() {
function n() {
this.managers = {};
}
return n.getInstance = function() {
return n.instance == null && (n.instance = new n()), n.instance;
}, n.registerManager = function(t, e) {
E(t != null, function() {
return "scheme must not be undefined or null.";
}), t.endsWith(Ci) && (t = t.slice(0, t.indexOf(Ci))), E(t.length > 0, function() {
return "scheme must not be an empty string.";
});
var r = n.getInstance();
E(r.managers[t] == null, function() {
return "A model store manager is already registered for scheme '" + t + "'.";
}), r.managers[t] = e;
}, n.getManager = function(t) {
var e = this.getInstance().managers[t];
if (e == null)
throw new Error("Cannot find model manager for scheme '" + t + "'");
return e;
}, n.getSchemes = function() {
return Object.keys(this.getInstance().managers);
}, n;
}();
function Os(n) {
if (n.indexOf(Ci) === -1)
throw new Error("The url string provided does not contain a scheme. Supported schemes are: " + ("" + mr.getSchemes().join(",")));
return {scheme: n.split(Ci)[0], path: n.split(Ci)[1]};
}
function Tm(n, t, e) {
return e === void 0 && (e = false), pe(this, void 0, void 0, function() {
var r, i, a, s, o, c, l, u, h;
return fe(this, function(d) {
switch (d.label) {
case 0:
return E(n !== t, function() {
return "Old path and new path are the same: '" + n + "'";
}), r = rn.getLoadHandlers(n), E(r.length > 0, function() {
return "Copying failed because no load handler is found for source URL " + n + ".";
}), E(r.length < 2, function() {
return "Copying failed because more than one (" + r.length + ") " + ("load handlers for source URL " + n + ".");
}), i = r[0], a = rn.getSaveHandlers(t), E(a.length > 0, function() {
return "Copying failed because no save handler is found for destination " + ("URL " + t + ".");
}), E(a.length < 2, function() {
return "Copying failed because more than one (" + r.length + ") " + ("save handlers for destination URL " + t + ".");
}), s = a[0], o = Os(n).scheme, c = Os(n).path, l = o === Os(n).scheme, [4, i.load()];
case 1:
return u = d.sent(), e && l ? [4, mr.getManager(o).removeModel(c)] : [3, 3];
case 2:
d.sent(), d.label = 3;
case 3:
return [4, s.save(u)];
case 4:
return h = d.sent(), e && !l ? [4, mr.getManager(o).removeModel(c)] : [3, 6];
case 5:
d.sent(), d.label = 6;
case 6:
return [2, h.modelArtifactsInfo];
}
});
});
}
function wS() {
return pe(this, void 0, void 0, function() {
var n, t, e, r, i, a, s, o;
return fe(this, function(c) {
switch (c.label) {
case 0:
n = mr.getSchemes(), t = {}, e = 0, r = n, c.label = 1;
case 1:
return e < r.length ? (i = r[e], [4, mr.getManager(i).listModels()]) : [3, 4];
case 2:
a = c.sent();
for (s in a)
o = i + Ci + s, t[o] = a[s];
c.label = 3;
case 3:
return e++, [3, 1];
case 4:
return [2, t];
}
});
});
}
function bS(n) {
return pe(this, void 0, void 0, function() {
var t, e;
return fe(this, function(r) {
return t = Os(n), e = mr.getManager(t.scheme), [2, e.removeModel(t.path)];
});
});
}
function xS(n, t) {
return pe(this, void 0, void 0, function() {
var e;
return fe(this, function(r) {
return e = false, [2, Tm(n, t, e)];
});
});
}
function LS(n, t) {
return pe(this, void 0, void 0, function() {
var e;
return fe(this, function(r) {
return e = true, [2, Tm(n, t, e)];
});
});
}
var SS = function() {
function n() {
}
return n.prototype.fetch = function(t, e) {
return fetch(t, e);
}, n.prototype.now = function() {
return performance.now();
}, n.prototype.encode = function(t, e) {
if (e !== "utf-8" && e !== "utf8")
throw new Error("Browser's encoder only supports utf-8, but got " + e);
return this.textEncoder == null && (this.textEncoder = new TextEncoder()), this.textEncoder.encode(t);
}, n.prototype.decode = function(t, e) {
return new TextDecoder(e).decode(t);
}, n;
}();
if (qe().get("IS_BROWSER")) {
qe().setPlatform("browser", new SS());
try {
mr.registerManager(_i.URL_SCHEME, new vS());
} catch (n) {
}
try {
mr.registerManager(Ti.URL_SCHEME, new uS());
} catch (n) {
}
}
var IS = {importFetch: function() {
return Vp();
}}, xu, AS = function() {
function n() {
this.util = Gp(), this.textEncoder = new this.util.TextEncoder();
}
return n.prototype.fetch = function(t, e) {
return qe().global.fetch != null ? qe().global.fetch(t, e) : (xu == null && (xu = IS.importFetch()), xu(t, e));
}, n.prototype.now = function() {
var t = process.hrtime();
return t[0] * 1e3 + t[1] / 1e6;
}, n.prototype.encode = function(t, e) {
if (e !== "utf-8" && e !== "utf8")
throw new Error("Node built-in encoder only supports utf-8, but got " + e);
return this.textEncoder.encode(t);
}, n.prototype.decode = function(t, e) {
return t.length === 0 ? "" : new this.util.TextDecoder(e).decode(t);
}, n;
}();
qe().get("IS_NODE") && qe().setPlatform("node", new AS());
function Rn(n, t, e) {
return t === void 0 && (t = "float32"), t = t || "float32", dc(n), new _s(n, t, e);
}
function TS(n, t) {
var e = R(n, "x", "cast");
if (!Jp(t))
throw new Error("Failed to cast to unknown dtype " + t);
if (t === "string" && e.dtype !== "string" || t !== "string" && e.dtype === "string")
throw new Error("Only strings can be casted to strings");
var r = {x: e}, i = {dtype: t};
return z.runKernelFunc(function(a) {
return a.cast(e, t);
}, r, null, Is, i);
}
var he = U({cast_: TS});
function NS(n) {
var t = R(n, "x", "clone", null), e = function() {
return z.makeTensorFromDataId(t.dataId, t.shape, t.dtype);
}, r = {x: t};
return z.runKernelFunc(e, r, null, Zc);
}
var Mr = U({clone_: NS});
function Nm(n, t) {
t === void 0 && (t = false), console.log(n.toString(t));
}
pm();
var _S = {buffer: Rn, cast: he, clone: Mr, print: Nm};
UL(_S);
var CS = "model", RS = ".json", OS = ".weights.bin";
function _m(n) {
return new Promise(function(t) {
return setTimeout(t);
}).then(n);
}
var Lu = function() {
function n(t) {
if (!qe().getBool("IS_BROWSER"))
throw new Error("browserDownloads() cannot proceed because the current environment is not a browser.");
t.startsWith(n.URL_SCHEME) && (t = t.slice(n.URL_SCHEME.length)), (t == null || t.length === 0) && (t = CS), this.modelTopologyFileName = t + RS, this.weightDataFileName = t + OS;
}
return n.prototype.save = function(t) {
return pe(this, void 0, void 0, function() {
var e, r, i, a, s, o;
return fe(this, function(c) {
switch (c.label) {
case 0:
if (typeof document == "undefined")
throw new Error("Browser downloads are not supported in this environment since `document` is not present");
if (e = window.URL.createObjectURL(new Blob([t.weightData], {type: "application/octet-stream"})), !(t.modelTopology instanceof ArrayBuffer))
return [3, 1];
throw new Error("BrowserDownloads.save() does not support saving model topology in binary formats yet.");
case 1:
return r = [{paths: ["./" + this.weightDataFileName], weights: t.weightSpecs}], i = {modelTopology: t.modelTopology, format: t.format, generatedBy: t.generatedBy, convertedBy: t.convertedBy, weightsManifest: r}, a = window.URL.createObjectURL(new Blob([JSON.stringify(i)], {type: "application/json"})), s = this.jsonAnchor == null ? document.createElement("a") : this.jsonAnchor, s.download = this.modelTopologyFileName, s.href = a, [4, _m(function() {
return s.dispatchEvent(new MouseEvent("click"));
})];
case 2:
return c.sent(), t.weightData != null ? (o = this.weightDataAnchor == null ? document.createElement("a") : this.weightDataAnchor, o.download = this.weightDataFileName, o.href = e, [4, _m(function() {
return o.dispatchEvent(new MouseEvent("click"));
})]) : [3, 4];
case 3:
c.sent(), c.label = 4;
case 4:
return [2, {modelArtifactsInfo: Ia(t)}];
}
});
});
}, n.URL_SCHEME = "downloads://", n;
}(), ES = function() {
function n(t) {
if (t == null || t.length < 1)
throw new Error("When calling browserFiles, at least 1 file is required, " + ("but received " + t));
this.files = t;
}
return n.prototype.load = function() {
return pe(this, void 0, void 0, function() {
var t, e, r = this;
return fe(this, function(i) {
return t = this.files[0], e = this.files.slice(1), [2, new Promise(function(a, s) {
var o = new FileReader();
o.onload = function(c) {
var l = JSON.parse(c.target.result), u = l.modelTopology;
if (u == null) {
s(new Error("modelTopology field is missing from file " + t.name));
return;
}
e.length === 0 && a({modelTopology: u});
var h = l.weightsManifest;
if (h == null) {
s(new Error("weightManifest field is missing from file " + t.name));
return;
}
var d;
try {
d = r.checkManifestAndWeightFiles(h, e);
} catch (g) {
s(g);
return;
}
var p = [], f = [], m = [];
h.forEach(function(g) {
g.paths.forEach(function(y) {
f.push(y), m.push(null);
}), p.push.apply(p, g.weights);
}), h.forEach(function(g) {
g.paths.forEach(function(y) {
var w = new FileReader();
w.onload = function(b) {
var x = b.target.result, L = f.indexOf(y);
m[L] = x, m.indexOf(null) === -1 && a({modelTopology: u, weightSpecs: p, weightData: yu(m), format: l.format, generatedBy: l.generatedBy, convertedBy: l.convertedBy, userDefinedMetadata: l.userDefinedMetadata});
}, w.onerror = function(b) {
return s("Failed to weights data from file of path '" + y + "'.");
}, w.readAsArrayBuffer(d[y]);
});
});
}, o.onerror = function(c) {
return s("Failed to read model topology and weights manifest JSON " + ("from file '" + t.name + "'. BrowserFiles supports loading ") + "Keras-style tf.Model artifacts only.");
}, o.readAsText(t);
})];
});
});
}, n.prototype.checkManifestAndWeightFiles = function(t, e) {
for (var r = [], i = e.map(function(l) {
return bm(l.name);
}), a = {}, s = 0, o = t; s < o.length; s++) {
var c = o[s];
c.paths.forEach(function(l) {
var u = bm(l);
if (r.indexOf(u) !== -1)
throw new Error("Duplicate file basename found in weights manifest: " + ("'" + u + "'"));
if (r.push(u), i.indexOf(u) === -1)
throw new Error("Weight file with basename '" + u + "' is not provided.");
a[l] = e[i.indexOf(u)];
});
}
if (r.length !== e.length)
throw new Error("Mismatch in the number of files in weights manifest " + ("(" + r.length + ") and the number of weight files provided ") + ("(" + e.length + ")."));
return a;
}, n;
}(), kS = function(n) {
return qe().getBool("IS_BROWSER") && (!Array.isArray(n) && n.startsWith(Lu.URL_SCHEME)) ? DS(n.slice(Lu.URL_SCHEME.length)) : null;
};
rn.registerSaveRouter(kS);
function DS(n) {
return n === void 0 && (n = "model"), new Lu(n);
}
function FS(n) {
return new ES(n);
}
function Cm(n, t, e, r) {
s(n), e = e != null ? e : 0, r = r != null ? r : 1, o(e, r);
var i = 0, a = function(c) {
return c.then(function(l) {
var u = e + ++i / n.length * (r - e);
return t(u), l;
}), c;
};
function s(c) {
E(c != null && Array.isArray(c) && c.length > 0, function() {
return "promises must be a none empty array";
});
}
function o(c, l) {
E(c >= 0 && c <= 1, function() {
return "Progress fraction must be in range [0, 1], but " + ("got startFraction " + c);
}), E(l >= 0 && l <= 1, function() {
return "Progress fraction must be in range [0, 1], but " + ("got endFraction " + l);
}), E(l >= c, function() {
return "startFraction must be no more than endFraction, but " + ("got startFraction " + c + " and endFraction ") + ("" + l);
});
}
return Promise.all(n.map(a));
}
function Rm(n, t) {
return pe(this, void 0, void 0, function() {
var e, r, i, a, s, o, c, l, u, h, d;
return fe(this, function(p) {
switch (p.label) {
case 0:
return t == null && (t = {}), e = t.fetchFunc == null ? qe().platform.fetch : t.fetchFunc, r = n.map(function(f) {
return e(f, t.requestInit, {isBinary: true});
}), i = 0, a = 0.5, t.onProgress == null ? [4, Promise.all(r)] : [3, 2];
case 1:
return o = p.sent(), [3, 4];
case 2:
return [4, Cm(r, t.onProgress, i, a)];
case 3:
o = p.sent(), p.label = 4;
case 4:
return s = o, c = s.map(function(f) {
return f.arrayBuffer();
}), l = 0.5, u = 1, t.onProgress == null ? [4, Promise.all(c)] : [3, 6];
case 5:
return d = p.sent(), [3, 8];
case 6:
return [4, Cm(c, t.onProgress, l, u)];
case 7:
d = p.sent(), p.label = 8;
case 8:
return h = d, [2, h];
}
});
});
}
function WS(n, t, e, r) {
return t === void 0 && (t = ""), pe(this, void 0, void 0, function() {
var i, a;
return fe(this, function(s) {
return i = function(o) {
return Rm(o, {requestInit: r});
}, a = Om(i), [2, a(n, t, e)];
});
});
}
function Om(n) {
var t = this;
return function(e, r, i) {
return r === void 0 && (r = ""), pe(t, void 0, void 0, function() {
var a, s, o, c, l, u, h, d, p, f;
return fe(this, function(m) {
switch (m.label) {
case 0:
if (a = e.map(function() {
return false;
}), s = {}, o = i != null ? i.map(function() {
return false;
}) : [], c = [], e.forEach(function(g, y) {
var w = 0;
g.weights.forEach(function(b) {
var x = "quantization" in b ? b.quantization.dtype : b.dtype, L = mu[x] * dt(b.shape), N = function() {
a[y] = true, s[y] == null && (s[y] = []), s[y].push({manifestEntry: b, groupOffset: w, sizeBytes: L});
};
i != null ? i.forEach(function(I, C) {
I === b.name && (N(), o[C] = true);
}) : N(), c.push(b.name), w += L;
});
}), !o.every(function(g) {
return g;
}))
throw l = i.filter(function(g, y) {
return !o[y];
}), new Error("Could not find weights in manifest with names: " + (l.join(", ") + `.
`) + "Manifest JSON has weights with names: " + (c.join(", ") + "."));
return u = a.reduce(function(g, y, w) {
return y && g.push(w), g;
}, []), h = [], u.forEach(function(g) {
e[g].paths.forEach(function(y) {
var w = r + (r.endsWith("/") ? "" : "/") + y;
h.push(w);
});
}), [4, n(h)];
case 1:
return d = m.sent(), p = {}, f = 0, u.forEach(function(g) {
for (var y = e[g].paths.length, w = 0, b = 0; b < y; b++)
w += d[f + b].byteLength;
for (var x = new ArrayBuffer(w), L = new Uint8Array(x), N = 0, I = 0; I < y; I++) {
var C = new Uint8Array(d[f + I]);
L.set(C, N), N += C.byteLength;
}
var O = s[g];
O.forEach(function(D) {
var F = x.slice(D.groupOffset, D.groupOffset + D.sizeBytes), k = vm(F, [D.manifestEntry]);
for (var B in k)
p[B] = k[B];
}), f += y;
}), [2, p];
}
});
});
};
}
var US = "application/octet-stream", BS = "application/json", Em = function() {
function n(t, e) {
if (this.DEFAULT_METHOD = "POST", e == null && (e = {}), this.weightPathPrefix = e.weightPathPrefix, this.onProgress = e.onProgress, this.weightUrlConverter = e.weightUrlConverter, e.fetchFunc != null ? (E(typeof e.fetchFunc == "function", function() {
return "Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)";
}), this.fetch = e.fetchFunc) : this.fetch = qe().platform.fetch, E(t != null && t.length > 0, function() {
return "URL path for http must not be null, undefined or empty.";
}), Array.isArray(t) && E(t.length === 2, function() {
return "URL paths for http must have a length of 2, " + ("(actual length is " + t.length + ").");
}), this.path = t, e.requestInit != null && e.requestInit.body != null)
throw new Error("requestInit is expected to have no pre-existing body, but has one.");
this.requestInit = e.requestInit || {};
}
return n.prototype.save = function(t) {
return pe(this, void 0, void 0, function() {
var e, r, i, a;
return fe(this, function(s) {
switch (s.label) {
case 0:
if (t.modelTopology instanceof ArrayBuffer)
throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");
return e = Object.assign({method: this.DEFAULT_METHOD}, this.requestInit), e.body = new FormData(), r = [{paths: ["./model.weights.bin"], weights: t.weightSpecs}], i = {modelTopology: t.modelTopology, format: t.format, generatedBy: t.generatedBy, convertedBy: t.convertedBy, userDefinedMetadata: t.userDefinedMetadata, weightsManifest: r}, e.body.append("model.json", new Blob([JSON.stringify(i)], {type: BS}), "model.json"), t.weightData != null && e.body.append("model.weights.bin", new Blob([t.weightData], {type: US}), "model.weights.bin"), [4, this.fetch(this.path, e)];
case 1:
if (a = s.sent(), a.ok)
return [2, {modelArtifactsInfo: Ia(t), responses: [a]}];
throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status " + (a.status + "."));
}
});
});
}, n.prototype.load = function() {
return pe(this, void 0, void 0, function() {
var t, e, r, i, a, s, o, c, l, u, h, d, p, f, m;
return fe(this, function(g) {
switch (g.label) {
case 0:
return [4, this.fetch(this.path, this.requestInit)];
case 1:
if (t = g.sent(), !t.ok)
throw new Error("Request to " + this.path + " failed with status code " + (t.status + ". Please verify this URL points to ") + "the model JSON of the model to load.");
g.label = 2;
case 2:
return g.trys.push([2, 4, , 5]), [4, t.json()];
case 3:
return e = g.sent(), [3, 5];
case 4:
throw r = g.sent(), i = "Failed to parse model JSON of response from " + this.path + ".", this.path.endsWith(".pb") ? i += " Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository." : i += " Please make sure the server is serving valid JSON for this request.", new Error(i);
case 5:
if (a = e.modelTopology, s = e.weightsManifest, o = e.generatedBy, c = e.convertedBy, l = e.format, u = e.userDefinedMetadata, a == null && s == null)
throw new Error("The JSON from HTTP path " + this.path + " contains neither model topology or manifest for weights.");
return s != null ? [4, this.loadWeights(s)] : [3, 7];
case 6:
p = g.sent(), h = p[0], d = p[1], g.label = 7;
case 7:
return f = {modelTopology: a, weightSpecs: h, weightData: d, userDefinedMetadata: u, generatedBy: o, convertedBy: c, format: l}, m = e.modelInitializer, m && (f.modelInitializer = m), [2, f];
}
});
});
}, n.prototype.loadWeights = function(t) {
return pe(this, void 0, void 0, function() {
var e, r, i, a, s, o, c, l, u, h, d, p, f, m, g, y, w, b, x, L, N;
return fe(this, function(I) {
switch (I.label) {
case 0:
for (e = Array.isArray(this.path) ? this.path[1] : this.path, r = zS(e), i = r[0], a = r[1], s = this.weightPathPrefix || i, o = [], c = 0, l = t; c < l.length; c++)
u = l[c], o.push.apply(o, u.weights);
for (h = [], d = [], p = 0, f = t; p < f.length; p++)
for (m = f[p], g = 0, y = m.paths; g < y.length; g++)
w = y[g], this.weightUrlConverter != null ? d.push(this.weightUrlConverter(w)) : h.push(s + w + a);
return this.weightUrlConverter ? (x = (b = h.push).apply, L = [h], [4, Promise.all(d)]) : [3, 2];
case 1:
x.apply(b, L.concat([I.sent()])), I.label = 2;
case 2:
return [4, Rm(h, {requestInit: this.requestInit, fetchFunc: this.fetch, onProgress: this.onProgress})];
case 3:
return N = I.sent(), [2, [o, yu(N)]];
}
});
});
}, n.URL_SCHEME_REGEX = /^https?:\/\//, n;
}();
function zS(n) {
var t = n.lastIndexOf("/"), e = n.lastIndexOf("?"), r = n.substring(0, t), i = e > t ? n.substring(e) : "";
return [r + "/", i];
}
function Su(n) {
return n.match(Em.URL_SCHEME_REGEX) != null;
}
var Dm = function(n, t) {
if (typeof fetch == "undefined" && (t == null || t.fetchFunc == null))
return null;
var e = true;
return Array.isArray(n) ? e = n.every(function(r) {
return Su(r);
}) : e = Su(n), e ? Iu(n, t) : null;
};
rn.registerSaveRouter(Dm);
rn.registerLoadRouter(Dm);
function Iu(n, t) {
return new Em(n, t);
}
function PS(n, t) {
return Iu(n, t);
}
var Au = function() {
function n(t) {
this.modelArtifacts = t;
}
return n.prototype.load = function() {
return pe(this, void 0, void 0, function() {
return fe(this, function(t) {
return [2, this.modelArtifacts];
});
});
}, n;
}(), MS = function() {
function n(t) {
this.saveHandler = t;
}
return n.prototype.save = function(t) {
return pe(this, void 0, void 0, function() {
return fe(this, function(e) {
return [2, this.saveHandler(t)];
});
});
}, n;
}();
function HS(n, t, e, r) {
if (arguments.length === 1) {
var i = n.modelTopology != null || n.weightSpecs != null;
return i ? new Au(n) : (console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."), new Au({modelTopology: n}));
} else
return console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."), new Au({modelTopology: n, weightSpecs: t, weightData: e, trainingConfig: r});
}
function VS(n) {
return new MS(n);
}
var GS = {__proto__: null, browserFiles: FS, browserHTTPRequest: PS, concatenateArrayBuffers: yu, decodeWeights: vm, encodeWeights: JL, fromMemory: HS, getLoadHandlers: oS, getModelArtifactsInfoForJSON: Ia, getSaveHandlers: sS, http: Iu, isHTTPScheme: Su, loadWeights: WS, registerLoadRouter: aS, registerSaveRouter: iS, weightsLoaderFactory: Om, withSaveHandler: VS, copyModel: xS, listModels: wS, moveModel: LS, removeModel: bS};
function qS(n, t) {
var e = R(n, "x", "reshape", null), r = {x: e}, i = {shape: t}, a = function(s, o) {
return t = Kp(t, e.size), E(e.size === dt(t), function() {
return "new shape and old shape must have the same number of elements.";
}), o([e]), s.reshape(e, t);
};
return z.runKernelFunc(a, r, null, Sl, i);
}
var Y = U({reshape_: qS});
function YS(n, t, e, r) {
var i;
e === void 0 && (e = false), r === void 0 && (r = false);
var a = R(n, "a", "matMul"), s = R(t, "b", "matMul");
i = ct(a, s), a = i[0], s = i[1];
var o = function(u, h) {
h([a, s]);
var d = e ? a.shape[a.rank - 2] : a.shape[a.rank - 1], p = r ? s.shape[s.rank - 1] : s.shape[s.rank - 2], f = e ? a.shape[a.rank - 1] : a.shape[a.rank - 2], m = r ? s.shape[s.rank - 2] : s.shape[s.rank - 1], g = a.shape.slice(0, -2), y = s.shape.slice(0, -2), w = dt(g), b = dt(y), x = w === b || w === 1 || b === 1;
E(a.rank >= 2 && s.rank >= 2 && x, function() {
return "Error in matMul: the input batch dimensions must either be the same or at least one input batch dimension must be 1. Got input " + ("batch dimensions of (" + g + ") and (" + y + ").");
}), E(d === p, function() {
return "Error in matMul: inner shapes (" + d + ") and (" + (p + ") of Tensors with shapes " + a.shape + " and ") + (s.shape + " and transposeA=" + e) + (" and transposeB=" + r + " must match.");
});
var L = w > b ? g : y, N = L.concat([f, m]), I = e ? Y(a, [w, d, f]) : Y(a, [w, f, d]), C = r ? Y(s, [b, m, p]) : Y(s, [b, p, m]), O = u.batchMatMul(I, C, e, r);
return Y(O, N);
}, c = {a, b: s}, l = {transposeA: e, transposeB: r};
return z.runKernelFunc(o, c, null, _c, l);
}
var Ue = U({matMul_: YS});
function KS(n, t, e, r) {
if (e === void 0 && (e = 1), r === void 0 && (r = 0), t < 2)
throw new Error("Error in oneHot: depth must be >=2, but it is " + t);
var i = R(n, "indices", "oneHot", "int32"), a = i.shape.concat([t]), s = function(l, u) {
return u([i]), Y(l.oneHot(Y(i, [i.size]), t, e, r), a);
}, o = {indices: i}, c = {depth: t, onValue: e, offValue: r};
return z.runKernelFunc(s, o, null, yl, c);
}
var Es = U({oneHot_: KS});
function jS(n, t) {
var e = R(n, "x", "transpose");
if (t == null && (t = e.shape.map(function(a, s) {
return s;
}).reverse()), E(e.rank === t.length, function() {
return "Error in transpose: rank of input " + e.rank + " " + ("must match length of perm " + t + ".");
}), t.forEach(function(a) {
E(a >= 0 && a < e.rank, function() {
return "All entries in 'perm' must be between 0 and " + (e.rank - 1) + (" but got " + t);
});
}), e.rank <= 1)
return e.clone();
var r = {x: e}, i = {perm: t};
return z.runKernelFunc(function(a) {
return a.transpose(e, t);
}, r, null, jl, i);
}
var Tt = U({transpose_: jS});
function $S(n, t, e) {
var r = R(n, "labels", "confusionMatrix"), i = R(t, "predictions", "confusionMatrix");
E(e == null || e > 0 && Number.isInteger(e), function() {
return "If provided, numClasses must be a positive integer, " + ("but got " + e);
}), E(r.rank === 1, function() {
return "Expected the rank of labels to be 1, but got " + r.rank;
}), E(i.rank === 1, function() {
return "Expected the rank of predictions to be 1, " + ("but got " + i.rank);
}), E(r.shape[0] === i.shape[0], function() {
return "Mismatch in the number of examples: " + (r.shape[0] + " vs. " + i.shape[0] + ". ") + "Labels and predictions should have the same number of elements.";
}), E(e > 0 && Number.isInteger(e), function() {
return "numClasses is required to be a positive integer, but got " + ("" + e);
});
var a = Es(he(r, "int32"), e), s = Es(he(i, "int32"), e), o = Tt(a), c = Ue(o, s);
return he(c, "int32");
}
var XS = U({confusionMatrix_: $S});
var JS = {__proto__: null, confusionMatrix: XS};
function km(n, t, e) {
if (Br(n), t != null && t.length !== 3)
throw new Error("tensor3d() requires shape to have three numbers");
var r = Cn(n, e);
if (r.length !== 3 && r.length !== 1)
throw new Error("tensor3d() requires values to be number[][][] or flat/TypedArray");
if (r.length === 1 && t == null)
throw new Error("tensor3d() requires shape to be provided when `values` are a flat array");
return dr(n, t, r, e);
}
var Ri;
function ZS(n, t) {
if (t === void 0 && (t = 3), t > 4)
throw new Error("Cannot construct Tensor with more than 4 channels from pixels.");
if (n == null)
throw new Error("pixels passed to tf.browser.fromPixels() can not be null");
var e = false, r = false, i = false, a = false, s = false;
if (n.data instanceof Uint8Array)
e = true;
else if (typeof ImageData != "undefined" && n instanceof ImageData)
r = true;
else if (typeof HTMLVideoElement != "undefined" && n instanceof HTMLVideoElement)
i = true;
else if (typeof HTMLImageElement != "undefined" && n instanceof HTMLImageElement)
a = true;
else if (n.getContext != null)
s = true;
else
throw new Error("pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData in browser, or OffscreenCanvas, ImageData in webworker or {data: Uint32Array, width: number, height: number}, " + ("but was " + n.constructor.name));
if (i) {
var o = 2;
if (i && n.readyState < o)
throw new Error("The video element has not loaded data yet. Please wait for `loadeddata` event on the <video> element.");
}
var c = iu(Ql, z.backendName);
if (c != null) {
var l = {pixels: n}, u = {numChannels: t};
return z.runKernel(Ql, l, u);
}
var h = i ? [n.videoWidth, n.videoHeight] : [n.width, n.height], d = h[0], p = h[1], f;
s ? f = n.getContext("2d").getImageData(0, 0, d, p).data : r || e ? f = n.data : (a || i) && (Ri == null && (Ri = document.createElement("canvas").getContext("2d")), Ri.canvas.width = d, Ri.canvas.height = p, Ri.drawImage(n, 0, 0, d, p), f = Ri.getImageData(0, 0, d, p).data);
var m;
if (t === 4)
m = new Int32Array(f);
else {
var g = d * p;
m = new Int32Array(g * t);
for (var y = 0; y < g; y++)
for (var w = 0; w < t; ++w)
m[y * t + w] = f[y * 4 + w];
}
var b = [p, d, t];
return km(m, b, "int32");
}
function QS(n, t) {
return pe(this, void 0, void 0, function() {
var e, r, i, a, s, o, c, l, u, h, d, p, f, m, g, y;
return fe(this, function(w) {
switch (w.label) {
case 0:
if (e = R(n, "img", "toPixels"), n instanceof K || (r = e, e = he(r, "int32"), r.dispose()), e.rank !== 2 && e.rank !== 3)
throw new Error("toPixels only supports rank 2 or 3 tensors, got rank " + e.rank + ".");
if (i = e.shape.slice(0, 2), a = i[0], s = i[1], o = e.rank === 2 ? 1 : e.shape[2], o > 4 || o === 2)
throw new Error("toPixels only supports depth of size " + ("1, 3 or 4 but got " + o));
if (e.dtype !== "float32" && e.dtype !== "int32")
throw new Error("Unsupported type for toPixels: " + e.dtype + ". Please use float32 or int32 tensors.");
return [4, e.data()];
case 1:
for (c = w.sent(), l = e.dtype === "float32" ? 255 : 1, u = new Uint8ClampedArray(s * a * 4), h = 0; h < a * s; ++h) {
for (d = [0, 0, 0, 255], p = 0; p < o; p++) {
if (f = c[h * o + p], e.dtype === "float32") {
if (f < 0 || f > 1)
throw new Error("Tensor values for a float32 Tensor must be in the " + ("range [0 - 1] but encountered " + f + "."));
} else if (e.dtype === "int32" && (f < 0 || f > 255))
throw new Error("Tensor values for a int32 Tensor must be in the " + ("range [0 - 255] but encountered " + f + "."));
o === 1 ? (d[0] = f * l, d[1] = f * l, d[2] = f * l) : d[p] = f * l;
}
m = h * 4, u[m + 0] = Math.round(d[0]), u[m + 1] = Math.round(d[1]), u[m + 2] = Math.round(d[2]), u[m + 3] = Math.round(d[3]);
}
return t != null && (t.width = s, t.height = a, g = t.getContext("2d"), y = new ImageData(u, s, a), g.putImageData(y, 0, 0)), e !== n && e.dispose(), [2, u];
}
});
});
}
var eI = U({fromPixels_: ZS}), tI = {__proto__: null, toPixels: QS, fromPixels: eI};
function Fm(n, t) {
if (n.rank < 1)
throw new Error("tf.gatherND() expects the input to be rank 1 or higher," + (" but the rank was " + n.rank + "."));
if (t.rank < 1)
throw new Error("tf.gatherND() expects the indices to be rank 1 or higher," + (" but the rank was " + t.rank + "."));
if (t.dtype !== "int32")
throw new Error("tf.gatherND() expects the indices to be int32 type," + (" but the dtype was " + t.dtype + "."));
if (t.shape[t.rank - 1] > n.rank)
throw new Error("index innermost dimension length must be <= tensor rank; saw: " + (t.shape[t.rank - 1] + " vs. " + n.rank));
if (n.size === 0)
throw new Error("Requested more than 0 entries, but input is empty." + (" Input shape: " + n.shape + "."));
for (var e = t.shape, r = e[e.length - 1], i = 1, a = 0; a < e.length - 1; ++a)
i *= e[a];
var s = n.shape, o = e.slice();
o.pop();
for (var c = 1, a = r; a < n.rank; ++a)
c *= s[a], o.push(s[a]);
var l = xi(n.shape).map(function(u) {
return u / c;
}).concat([1]).slice(0, r);
return [o, i, c, l];
}
var nI = {__proto__: null, prepareAndValidate: Fm};
function Tu(n, t, e) {
var r = t.rank > 1 ? t.shape[t.rank - 1] : 1, i = t.rank > 1 ? t.rank - 1 : 1, a = "Must have updates.shape = indices.shape[:batchDim] + " + ("shape[sliceDim:], got updates.shape: " + e.shape) + (", indices.shape: " + t.shape + ", shape: " + n) + (", sliceDim: " + r + ", and batchDim: " + i + ".");
if (e.rank < i)
throw new Error(a + (" update.rank < " + i + ". "));
if (n.length < r + (e.rank - i))
throw new Error(a + (" Output shape length < " + (r + (e.rank - i))));
if (e.rank !== i + n.length - r)
throw new Error(a + (" update.rank != " + (i + n.length - r)));
for (var s = 0; s < i; ++s)
if (e.shape[s] !== t.shape[s])
throw new Error(a + (" updates.shape[" + s + "] (" + e.shape[s] + ") != indices.shape[" + s + "] (" + t.shape[s] + ")."));
for (var s = 0; s < e.rank - i; ++s)
if (e.shape[s + i] !== n[s + r])
throw new Error(a + (" updates.shape[" + (s + i) + "] (" + e.shape[s + i] + ") != shape[" + (s + i) + "] (" + n[s + i] + ")"));
}
function Nu(n, t, e) {
if (t.rank < 1)
throw new Error("tf.scatterND() expects the indices to be rank 1 or higher," + (" but the rank was " + t.rank + "."));
if (n.rank < 1)
throw new Error("tf.scatterND() expects the updates to be rank 1 or higher," + (" but the rank was " + n.rank + "."));
if (t.dtype !== "int32")
throw new Error("The dtype of 'indices' should be int32, but got dtype: " + t.dtype);
if (e.length < 1)
throw new Error("Output rank must be greater or equal to 1, but got shape: " + e);
if (e.length === 0) {
if (t.size === 0)
throw new Error("Indices specified for empty output. indices shape: " + t.shape);
if (n.size === 0)
throw new Error("Updates specified for empty output. updates shape: " + n.shape);
}
Tu(e, t, n);
}
function Wm(n, t, e) {
for (var r = t.shape.length, i = r > 1 ? t.shape[r - 1] : 1, a = e.length, s = 1, o = i; o < a; ++o)
s *= e[o];
var c = i < 1 ? 1 : i, l = dt(t.shape) / c, u = xi(e.slice(0, i)).concat([1]), h = dt(e);
return {sliceRank: i, numUpdates: l, sliceSize: s, strides: u, outputSize: h};
}
var rI = {__proto__: null, validateUpdateShape: Tu, validateInput: Nu, calculateShapes: Wm};
function Um(n, t, e) {
var r = n.shape.length;
E(r === t.length, function() {
return "Error in slice" + r + "D: Length of begin " + t + " must " + ("match the rank of the array (" + r + ").");
}), E(r === e.length, function() {
return "Error in slice" + r + "D: Length of size " + e + " must " + ("match the rank of the array (" + r + ").");
});
for (var i = function(s) {
E(t[s] + e[s] <= n.shape[s], function() {
return "Error in slice" + r + "D: begin[" + s + "] + size[" + s + "] " + ("(" + (t[s] + e[s]) + ") would overflow input.shape[" + s + "] (" + n.shape[s] + ")");
});
}, a = 0; a < r; ++a)
i(a);
}
function Ds(n) {
for (var t = [], e = 0; n > 0; )
n & 1 && t.push(e), n /= 2, e++;
return t;
}
function Bm(n, t, e) {
for (var r = [], i = 0; i < n.length; i++)
r[i] = Math.ceil((t[i] - n[i]) / e[i]);
return r;
}
function zm(n, t, e, r) {
for (var i = n.slice(), a = i.length; a < r.length; a++)
i.push(1);
for (var a = 0; a < e; a++)
a === 0 ? i[t] = 1 : (i.splice(t, 0, 1), i.pop());
return i;
}
function Pm(n, t, e) {
return e <= n ? e : e - (t - 1);
}
function Mm(n, t) {
for (var e = [], r = 0; r < n; r++)
e.push(t + r);
return e;
}
function Km(n, t, e, r, i, a, s, o, c) {
var l = n.length, u = new Array(l), h = new Array(l), d = new Array(l);
if (t.length && e > 0) {
var p = t[0], f = e + 1;
u = Hm(s, p, f, r, n), h = Vm(o, p, f, i, n), d = zm(a, p, f, n);
} else
for (var m = 0; m < l; m++)
u[m] = qm(s, r, a, n, m, c), h[m] = Ym(o, i, a, n, m, c), d[m] = Gm(a, m, c);
return {begin: u, end: h, strides: d};
}
function Hm(n, t, e, r, i) {
for (var a = i.slice(), s = Mm(e, t), o = 0; o < a.length; o++)
if (s.indexOf(o) > -1)
a[o] = 0;
else {
var c = Pm(t, e, o), l = r[c];
n & 1 << c && (l = 0), a[o] = l;
}
return a;
}
function Vm(n, t, e, r, i) {
for (var a = i.slice(), s = Mm(e, t), o = 0; o < a.length; o++)
if (s.indexOf(o) > -1)
a[o] = Number.MAX_SAFE_INTEGER;
else {
var c = Pm(t, e, o), l = r[c];
n & 1 << c && (l = Number.MAX_SAFE_INTEGER), a[o] = l;
}
for (var u = 0; u < a.length; u++) {
var h = i[u];
a[u] < 0 && (a[u] += h), a[u] = ga(0, a[u], i[u]);
}
return a;
}
function Gm(n, t, e) {
var r = n[t];
return (e & 1 << t || r == null) && (r = 1), r;
}
function qm(n, t, e, r, i, a) {
var s = t[i], o = e[i] || 1;
(n & 1 << i || a & 1 << i || s == null) && (o > 0 ? s = Number.MIN_SAFE_INTEGER : s = Number.MAX_SAFE_INTEGER);
var c = r[i];
return s < 0 && (s += c), s = ga(0, s, c - 1), s;
}
function Ym(n, t, e, r, i, a) {
var s = t[i], o = e[i] || 1;
(n & 1 << i || a & 1 << i || s == null) && (o > 0 ? s = Number.MAX_SAFE_INTEGER : s = Number.MIN_SAFE_INTEGER);
var c = r[i];
return s < 0 && (s += c), o > 0 ? s = ga(0, s, c) : s = ga(-1, s, c - 1), s;
}
function iI(n, t, e) {
for (var r = e.length, i = 0; i < e.length; i++)
if (e[i] > 1) {
r = i;
break;
}
for (var i = r + 1; i < e.length; i++)
if (t[i] > 0 || e[i] !== n[i])
return false;
return true;
}
function aI(n, t) {
for (var e = n.length > 0 ? n[n.length - 1] : 1, r = 0; r < n.length - 1; r++)
e += n[r] * t[r];
return e;
}
function _u(n, t, e) {
var r, i = n.shape.length;
typeof t == "number" ? r = [t].concat(new Array(i - 1).fill(0)) : t.length < i ? r = t.concat(new Array(i - t.length).fill(0)) : r = t.slice(), r.forEach(function(s) {
E(s !== -1, function() {
return "slice() does not support negative begin indexing.";
});
});
var a;
return e == null ? a = new Array(i).fill(-1) : typeof e == "number" ? a = [e].concat(new Array(i - 1).fill(-1)) : e.length < i ? a = e.concat(new Array(i - e.length).fill(-1)) : a = e, a = a.map(function(s, o) {
return s >= 0 ? s : (E(s === -1, function() {
return "Negative size values should be exactly -1 but got " + (s + " for the slice() size at index " + o + ".");
}), n.shape[o] - r[o]);
}), [r, a];
}
var jm = {__proto__: null, assertParamsValid: Um, maskToAxes: Ds, computeOutShape: Bm, stridesWithElidedDims: zm, getNormalizedAxes: Km, startIndicesWithElidedDims: Hm, stopIndicesWithElidedDims: Vm, stridesForAxis: Gm, startForAxis: qm, stopForAxis: Ym, isSliceContinous: iI, computeFlatOffset: aI, parseSliceParams: _u};
var $m = function() {
function n() {
}
return n.prototype.getClassName = function() {
return this.constructor.className;
}, n.fromConfig = function(t, e) {
return new t(e);
}, n;
}(), Xm = function() {
function n() {
this.classNameMap = {};
}
return n.getMap = function() {
return n.instance == null && (n.instance = new n()), n.instance;
}, n.register = function(t) {
n.getMap().classNameMap[t.className] = [t, t.fromConfig];
}, n;
}();
function gr(n) {
E(n.className != null, function() {
return "Class being registered does not have the static className property defined.";
}), E(typeof n.className == "string", function() {
return "className is required to be a string, but got type " + typeof n.className;
}), E(n.className.length > 0, function() {
return "Class being registered has an empty-string as its className, which is disallowed.";
}), Xm.register(n);
}
var sI = {__proto__: null, Serializable: $m, SerializationMap: Xm, registerClass: gr};
var oI = 1e-3, Jm = 0.1;
function cI(n, t, e) {
return e == null && (e = Cu()), Ru(n, t, function(r, i) {
return Ou(r, i, e);
});
}
function Cu() {
return z.backend.floatPrecision() === 32 ? oI : Jm;
}
function Ru(n, t, e) {
var r = true;
if ((Ft(n) || Ft(t)) && (r = false), Ft(n) && Ft(t) && (r = true), r) {
var i = n.constructor.name, a = t.constructor.name;
if (i !== a)
throw new Error("Arrays are of different type. Actual: " + i + ". " + ("Expected: " + a));
}
if (Array.isArray(n) && Array.isArray(t)) {
var s = Cn(n), o = Cn(t);
if (!pn(s, o))
throw new Error("Arrays have different shapes. " + ("Actual: [" + s + "]. Expected: [" + o + "]"));
}
var c = Ft(n) ? n : zr(n), l = Ft(t) ? t : zr(t);
if (c.length !== l.length)
throw new Error("Arrays have different lengths actual: " + c.length + " vs " + ("expected: " + l.length + `.
`) + ("Actual: " + c + `.
`) + ("Expected: " + l + "."));
for (var u = 0; u < l.length; ++u) {
var h = c[u], d = l[u];
if (!e(h, d))
throw new Error("Arrays differ: actual[" + u + "] = " + h + ", expected[" + u + "] = " + d + `.
` + ("Actual: " + c + `.
`) + ("Expected: " + l + "."));
}
}
function lI(n, t) {
n().then(function() {
return t.fail();
}, function() {
return t();
});
}
function uI(n, t) {
var e = typeof t == "string" || typeof t == "number" || typeof t == "boolean" ? [t] : t;
return lr(n) || lr(n[0]) || lr(t) || lr(t[0]) ? Ru(n, e, function(r, i) {
return r == i;
}) : Ru(n, t, function(r, i) {
return Ou(r, i, 0);
});
}
function hI(n, t, e) {
if (e == null && (e = Cu()), !Ou(n, t, e))
throw new Error("Numbers differ: actual === " + n + ", expected === " + t);
}
function Ou(n, t, e) {
return !isFinite(n) && !isFinite(t) ? true : !(isNaN(n) || isNaN(t) || Math.abs(n - t) > e);
}
function dI(n, t, e) {
for (var r = 0; r < n.length; r++)
if (n[r] < t || n[r] > e)
throw new Error("Value out of range:" + n[r] + " low: " + t + ", high: " + e);
}
function pI(n, t) {
expect(new Float32Array(n)).toEqual(new Float32Array(t));
}
var fI = {__proto__: null, TEST_EPSILON_FLOAT16: Jm, expectArraysClose: cI, testEpsilon: Cu, expectPromiseToFail: lI, expectArraysEqual: uI, expectNumbersClose: hI, expectValuesInRange: dI, expectArrayBuffersEqual: pI};
var mI = "2.7.0";
function gI() {
qe().set("PROD", true);
}
function yI() {
qe().set("DEBUG", true);
}
function vI() {
qe().set("DEPRECATION_WARNINGS_ENABLED", false), console.warn("TensorFlow.js deprecation warnings have been disabled.");
}
function Nt(n) {
qe().getBool("DEPRECATION_WARNINGS_ENABLED") && console.warn(n + " You can disable deprecation warnings with tf.disableDeprecationWarnings().");
}
function wI() {
z.disposeVariables();
}
function bI() {
return z;
}
function xI() {
return z.memory();
}
function LI(n) {
return z.profile(n);
}
function wt(n, t) {
return z.tidy(n, t);
}
function Pt(n) {
var t = fu(n);
t.forEach(function(e) {
return e.dispose();
});
}
function Zm(n) {
return z.keep(n);
}
function SI(n) {
return z.time(n);
}
function II(n) {
return z.setBackend(n);
}
function AI() {
return z.ready();
}
function TI() {
return z.backendName;
}
function NI(n) {
z.removeBackend(n);
}
function _I(n) {
return z.findBackend(n);
}
function CI(n) {
return z.findBackendFactory(n);
}
function RI(n, t, e) {
return e === void 0 && (e = 1), z.registerBackend(n, t, e);
}
function OI() {
return z.backend;
}
function EI(n, t) {
qe().setPlatform(n, t);
}
function DI(n, t) {
var e, r = R(n, "a", "add"), i = R(t, "b", "add");
e = ct(r, i), r = e[0], i = e[1];
var a = function(o, c) {
var l = o.add(r, i);
return c([r, i]), l;
}, s = {a: r, b: i};
return z.runKernelFunc(a, s, null, Ss);
}
var ge = U({add_: DI});
function kI(n, t) {
var e, r = R(n, "a", "floorDiv"), i = R(t, "b", "floorDiv");
e = ct(r, i), r = e[0], i = e[1];
var a = function(o, c) {
var l = o.floorDiv(r, i);
return c([r, i]), l;
}, s = {a: r, b: i};
return z.runKernelFunc(a, s, null, jc);
}
var Eu = U({floorDiv_: kI});
function FI(n, t) {
var e, r = R(n, "a", "div"), i = R(t, "b", "div");
if (e = ct(r, i), r = e[0], i = e[1], r.dtype === "int32" && i.dtype === "int32")
return Eu(r, i);
var a = function(c, l) {
var u = c.realDivide(r, i);
return l([r, i]), u;
}, s = {a: r, b: i}, o = {};
return z.runKernelFunc(a, s, null, Hc, o);
}
var Ne = U({div_: FI});
function WI(n, t) {
var e, r = R(n, "a", "mul"), i = R(t, "b", "mul");
e = ct(r, i), r = e[0], i = e[1];
var a = function(o, c) {
var l = o.multiply(r, i);
return c([r, i]), l;
}, s = {a: r, b: i};
return z.runKernelFunc(a, s, null, fl);
}
var Z = U({mul_: WI});
function UI(n) {
var t = R(n, "x", "abs"), e = {x: t};
return z.runKernelFunc(function(r, i) {
return i([t]), t.dtype === "complex64" ? r.complexAbs(t) : r.abs(t);
}, e, null, mc);
}
var $t = U({abs_: UI});
function BI(n) {
var t = R(n, "x", "acos"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.acos(t);
return i([t]), a;
}, e, null, gc);
}
var Qm = U({acos_: BI});
function zI(n) {
var t = R(n, "x", "acosh"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.acosh(t);
return i([t]), a;
}, e, null, yc);
}
var eg = U({acosh_: zI});
function PI(n) {
E(Array.isArray(n), function() {
return "The argument passed to tf.addN() must be a list of tensors";
}), E(n.length >= 1, function() {
return "Must pass at least one tensor to tf.addN(), but got " + ("" + n.length);
});
var t = n.map(function(a, s) {
return R(a, "tensors" + s, "addN");
}), e = t[0];
t.forEach(function(a) {
if (a.dtype !== e.dtype)
throw new Error("All tensors passed to tf.addN() must have the same dtype");
}), t.forEach(function(a) {
if (!pn(a.shape, e.shape))
throw new Error("All tensors passed to tf.addN() must have the same shape");
});
var r = function(a, s) {
var o = a.addN(t);
return s(t), o;
}, i = t;
return z.runKernelFunc(r, i, null, vc);
}
var MI = U({addN_: PI});
function Du(n, t) {
for (var e = 0; e < n.length; ++e)
if (n[n.length - e - 1] !== t - 1 - e)
return false;
return true;
}
function tg(n, t, e) {
for (var r = n.length + t.length, i = [], a = 0, s = 0, o = 0; o < r; o++)
e.indexOf(o) === -1 ? i.push(n[a++]) : i.push(t[s++]);
return i;
}
function ng(n, t) {
for (var e = [], r = n.length, i = 0; i < r; i++)
t.indexOf(i) === -1 && e.push(n[i]);
var a = t.map(function(s) {
return n[s];
});
return [e, a];
}
function an(n, t) {
var e = t.map(function(r) {
return 1;
});
return tg(n, e, t);
}
function HI(n, t, e) {
E(Du(t, e), function() {
return n + " supports only inner-most axes for now. " + ("Got axes " + t + " and rank-" + e + " input.");
});
}
function fn(n, t) {
if (Du(n, t))
return null;
for (var e = [], r = 0; r < t; ++r)
n.indexOf(r) === -1 && e.push(r);
return n.forEach(function(i) {
return e.push(i);
}), e;
}
function ks(n) {
return n.map(function(t, e) {
return [e, t];
}).sort(function(t, e) {
return t[1] - e[1];
}).map(function(t) {
return t[0];
});
}
function On(n, t) {
for (var e = [], r = t - n; r < t; ++r)
e.push(r);
return e;
}
function VI(n, t, e) {
t === void 0 && (t = null), e === void 0 && (e = false);
var r = R(n, "x", "all", "bool"), i = function(o) {
var c = rt(t, r.shape), l = c, u = fn(l, r.rank);
u != null && (r = Tt(r, u), l = On(l.length, r.rank));
var h = o.all(r, l);
if (e) {
var d = an(h.shape, c);
return Y(h, d);
}
return h;
}, a = {x: r}, s = {axis: t, keepDims: e};
return z.runKernelFunc(i, a, null, lf, s);
}
var rg = U({all_: VI});
function GI(n, t, e) {
t === void 0 && (t = null), e === void 0 && (e = false);
var r = R(n, "x", "any", "bool"), i = function(o) {
var c = rt(t, r.shape), l = c, u = fn(l, r.rank);
u != null && (r = Tt(r, u), l = On(l.length, r.rank));
var h = o.any(r, l);
if (e) {
var d = an(h.shape, c);
return Y(h, d);
}
return h;
}, a = {x: r}, s = {axis: t, keepDims: e};
return z.runKernelFunc(i, a, null, uf, s);
}
var ig = U({any_: GI});
function qI(n, t) {
t === void 0 && (t = 0);
var e = R(n, "x", "argMax"), r = function(s, o) {
o([e]);
var c = rt(t, e.shape), l = fn(c, e.rank);
return l != null && (e = Tt(e, l), c = On(c.length, e.rank)), s.argMax(e, c[0]);
}, i = {x: e}, a = {axis: t};
return z.runKernelFunc(r, i, null, wc, a);
}
var ag = U({argMax_: qI});
function YI(n, t) {
t === void 0 && (t = 0);
var e = R(n, "x", "argMin"), r = function(s, o) {
o([e]), t == null && (t = 0);
var c = rt(t, e.shape), l = fn(c, e.rank);
return l != null && (e = Tt(e, l), c = On(c.length, e.rank)), s.argMin(e, c[0]);
}, i = {x: e}, a = {axis: t};
return z.runKernelFunc(r, i, null, bc, a);
}
var sg = U({argMin_: YI});
function KI(n) {
var t = R(n, "x", "asin"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.asin(t);
return i([t]), a;
}, e, null, xc);
}
var og = U({asin_: KI});
function jI(n) {
var t = R(n, "x", "asinh"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.asinh(t);
return i([t]), a;
}, e, null, Lc);
}
var cg = U({asinh_: jI});
function $I(n) {
var t = R(n, "x", "atan"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.atan(t);
return i([t]), a;
}, e, null, Sc);
}
var lg = U({atan_: $I});
function XI(n, t) {
var e, r = R(n, "a", "atan2"), i = R(t, "b", "atan2");
e = ct(r, i), r = e[0], i = e[1];
var a = function(o, c) {
var l = o.atan2(r, i);
return c([r, i]), l;
}, s = {a: r, b: i};
return z.runKernelFunc(a, s, null, Ac);
}
var ug = U({atan2_: XI});
function JI(n) {
var t = R(n, "x", "atanh"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.atanh(t);
return i([t]), a;
}, e, null, Ic);
}
var hg = U({atanh_: JI});
function ZI(n, t, e, r, i, a) {
i === void 0 && (i = "NHWC");
var s = n[3], o = t.concat([s]), c = Aa(i);
return mn(n, o, e, a, r, null, null, c);
}
function Oi(n, t, e, r, i, a, s) {
s === void 0 && (s = "channelsLast");
var o = Fs(t), c = o[0], l = o[1], u;
if (s === "channelsLast")
u = [c, l, n[3], n[3]];
else if (s === "channelsFirst")
u = [c, l, n[1], n[1]];
else
throw new Error("Unknown dataFormat " + s);
return mn(n, u, e, r, i, a, false, s);
}
function Na(n, t, e, r, i, a, s) {
s === void 0 && (s = "NDHWC");
var o = ku(t), c = o[0], l = o[1], u = o[2], h, d;
if (s === "NDHWC")
d = "channelsLast", h = [c, l, u, n[4], n[4]];
else if (s === "NCDHW")
d = "channelsFirst", h = [c, l, u, n[1], n[1]];
else
throw new Error("Unknown dataFormat " + s);
return Ta(n, h, e, r, i, false, d, a);
}
function mn(n, t, e, r, i, a, s, o) {
s === void 0 && (s = false), o === void 0 && (o = "channelsLast");
var c = [-1, -1, -1, -1], l = c[0], u = c[1], h = c[2], d = c[3];
if (o === "channelsLast")
l = n[0], u = n[1], h = n[2], d = n[3];
else if (o === "channelsFirst")
l = n[0], d = n[1], u = n[2], h = n[3];
else
throw new Error("Unknown dataFormat " + o);
var p = t[0], f = t[1], m = t[3], g = Fs(e), y = g[0], w = g[1], b = Fs(r), x = b[0], L = b[1], N = Ei(p, x), I = Ei(f, L), C = QI(i, u, h, y, w, N, I, a, o), O = C.padInfo, D = C.outHeight, F = C.outWidth, k = s ? m * d : m, B;
return o === "channelsFirst" ? B = [l, k, D, F] : o === "channelsLast" && (B = [l, D, F, k]), {batchSize: l, dataFormat: o, inHeight: u, inWidth: h, inChannels: d, outHeight: D, outWidth: F, outChannels: k, padInfo: O, strideHeight: y, strideWidth: w, filterHeight: p, filterWidth: f, effectiveFilterHeight: N, effectiveFilterWidth: I, dilationHeight: x, dilationWidth: L, inShape: n, outShape: B, filterShape: t};
}
function Ta(n, t, e, r, i, a, s, o) {
a === void 0 && (a = false), s === void 0 && (s = "channelsLast");
var c = [-1, -1, -1, -1, -1], l = c[0], u = c[1], h = c[2], d = c[3], p = c[4];
if (s === "channelsLast")
l = n[0], u = n[1], h = n[2], d = n[3], p = n[4];
else if (s === "channelsFirst")
l = n[0], p = n[1], u = n[2], h = n[3], d = n[4];
else
throw new Error("Unknown dataFormat " + s);
var f = t[0], m = t[1], g = t[2], y = t[4], w = ku(e), b = w[0], x = w[1], L = w[2], N = ku(r), I = N[0], C = N[1], O = N[2], D = Ei(f, I), F = Ei(m, C), k = Ei(g, O), B = eA(i, u, h, d, b, x, L, D, F, k, o), V = B.padInfo, P = B.outDepth, G = B.outHeight, j = B.outWidth, q = a ? y * p : y, H;
return s === "channelsFirst" ? H = [l, q, P, G, j] : s === "channelsLast" && (H = [l, P, G, j, q]), {batchSize: l, dataFormat: s, inDepth: u, inHeight: h, inWidth: d, inChannels: p, outDepth: P, outHeight: G, outWidth: j, outChannels: q, padInfo: V, strideDepth: b, strideHeight: x, strideWidth: L, filterDepth: f, filterHeight: m, filterWidth: g, effectiveFilterDepth: D, effectiveFilterHeight: F, effectiveFilterWidth: k, dilationDepth: I, dilationHeight: C, dilationWidth: O, inShape: n, outShape: H, filterShape: t};
}
function tA(n, t, e, r, i) {
r == null && (r = Fu(n, t, e));
var a = n[0], s = n[1], o = Hr((a - t + 2 * r) / e + 1, i);
E(ot(o), function() {
return "The output # of rows (" + o + ") must be an integer. Change the stride and/or zero pad parameters";
});
var c = Hr((s - t + 2 * r) / e + 1, i);
return E(ot(c), function() {
return "The output # of columns (" + c + ") must be an integer. Change the stride and/or zero pad parameters";
}), [o, c];
}
function nA(n, t, e, r, i, a) {
i == null && (i = Fu(n, t, r));
var s = n[0], o = n[1], c = n[2], l = Hr((s - t + 2 * i) / r + 1, a);
E(ot(l), function() {
return "The output # of depths (" + l + ") must be an integer. Change the stride and/or zero pad parameters";
});
var u = Hr((o - t + 2 * i) / r + 1, a);
E(ot(u), function() {
return "The output # of rows (" + u + ") must be an integer. Change the stride and/or zero pad parameters";
});
var h = Hr((c - t + 2 * i) / r + 1, a);
return E(ot(h), function() {
return "The output # of columns (" + h + ") must be an integer. Change the stride and/or zero pad parameters";
}), [l, u, h, e];
}
function Fu(n, t, e, r) {
r === void 0 && (r = 1);
var i = Ei(t, r);
return Math.floor((n[0] * (e - 1) - e + i) / 2);
}
function Fs(n) {
return typeof n == "number" ? [n, n, n] : n.length === 2 ? [n[0], n[1], 1] : n;
}
function ku(n) {
return typeof n == "number" ? [n, n, n] : n;
}
function Ei(n, t) {
return t <= 1 ? n : n + (n - 1) * (t - 1);
}
function QI(n, t, e, r, i, a, s, o, c) {
var l, u, h;
if (typeof n == "number") {
var d = n === 0 ? "VALID" : "NUMBER";
l = {top: n, bottom: n, left: n, right: n, type: d};
var p = tA([t, e], a, r, n, o);
u = p[0], h = p[1];
} else if (n === "same") {
u = Math.ceil(t / r), h = Math.ceil(e / i);
var f = Math.max(0, (u - 1) * r + a - t), m = Math.max(0, (h - 1) * i + s - e), g = Math.floor(f / 2), y = f - g, w = Math.floor(m / 2), b = m - w;
l = {top: g, bottom: y, left: w, right: b, type: "SAME"};
} else if (n === "valid")
l = {top: 0, bottom: 0, left: 0, right: 0, type: "VALID"}, u = Math.ceil((t - a + 1) / r), h = Math.ceil((e - s + 1) / i);
else if (typeof n == "object") {
var x = c === "channelsLast" ? n[1][0] : n[2][0], y = c === "channelsLast" ? n[1][1] : n[2][1], w = c === "channelsLast" ? n[2][0] : n[3][0], b = c === "channelsLast" ? n[2][1] : n[3][1], d = x === 0 && y === 0 && w === 0 && b === 0 ? "VALID" : "EXPLICIT";
l = {top: x, bottom: y, left: w, right: b, type: d}, u = Hr((t - a + x + y) / r + 1, o), h = Hr((e - s + w + b) / i + 1, o);
} else
throw Error("Unknown padding parameter: " + n);
return {padInfo: l, outHeight: u, outWidth: h};
}
function eA(n, t, e, r, i, a, s, o, c, l, u) {
var h, d, p, f;
if (typeof n == "number") {
var m = n === 0 ? "VALID" : "NUMBER";
h = {top: n, bottom: n, left: n, right: n, front: n, back: n, type: m};
var g = nA([t, e, r, 1], o, 1, i, n, u);
d = g[0], p = g[1], f = g[2];
} else if (n === "same") {
d = Math.ceil(t / i), p = Math.ceil(e / a), f = Math.ceil(r / s);
var y = (d - 1) * i + o - t, w = (p - 1) * a + c - e, b = (f - 1) * s + l - r, x = Math.floor(y / 2), L = y - x, N = Math.floor(w / 2), I = w - N, C = Math.floor(b / 2), O = b - C;
h = {top: N, bottom: I, left: C, right: O, front: x, back: L, type: "SAME"};
} else if (n === "valid")
h = {top: 0, bottom: 0, left: 0, right: 0, front: 0, back: 0, type: "VALID"}, d = Math.ceil((t - o + 1) / i), p = Math.ceil((e - c + 1) / a), f = Math.ceil((r - l + 1) / s);
else
throw Error("Unknown padding parameter: " + n);
return {padInfo: h, outDepth: d, outHeight: p, outWidth: f};
}
function Hr(n, t) {
if (!t)
return n;
switch (t) {
case "round":
return Math.round(n);
case "ceil":
return Math.ceil(n);
case "floor":
return Math.floor(n);
default:
throw new Error("Unknown roundingMode " + t);
}
}
function yr(n) {
var t = Fs(n), e = t[0], r = t[1], i = t[2];
return e === 1 && r === 1 && i === 1;
}
function Mt(n, t) {
return yr(n) || yr(t);
}
function Aa(n) {
if (n === "NHWC")
return "channelsLast";
if (n === "NCHW")
return "channelsFirst";
throw new Error("Unknown dataFormat " + n);
}
function rA(n, t, e, r, i) {
var a = R(n, "x", "avgPool", "float32"), s = 1;
E(Mt(e, s), function() {
return "Error in avgPool: Either strides or dilations must be 1. " + ("Got strides " + e + " and dilations '" + s + "'");
});
var o = a, c = false;
a.rank === 3 && (c = true, o = Y(a, [1, a.shape[0], a.shape[1], a.shape[2]])), E(o.rank === 4, function() {
return "Error in avgPool: x must be rank 4 but got rank " + o.rank + ".";
}), i != null && E(ot(r), function() {
return "Error in avgPool: pad must be an integer when using, " + ("dimRoundingMode " + i + " but got pad " + r + ".");
});
var l = function(p, f) {
var m = Oi(o.shape, t, e, 1, r, i);
return f([o]), m.filterWidth === 1 && m.filterHeight === 1 && pn(m.inShape, m.outShape) ? o.clone() : p.avgPool(o, m);
}, u = {x: o}, h = {filterSize: t, strides: e, pad: r, dimRoundingMode: i}, d = z.runKernelFunc(l, u, null, Tc, h);
return d = he(d, a.dtype), c ? Y(d, [d.shape[1], d.shape[2], d.shape[3]]) : d;
}
var Wu = U({avgPool_: rA});
function iA(n, t, e, r, i, a, s) {
a === void 0 && (a = "NDHWC"), s == null ? s = [1, 1, 1] : Nt("dilations is deprecated, this field will be gone in v3.0.0.");
var o = R(n, "x", "avgPool3d", "float32"), c = o, l = false;
o.rank === 4 && (l = true, c = Y(o, [1, o.shape[0], o.shape[1], o.shape[2], o.shape[3]])), E(c.rank === 5, function() {
return "Error in avgPool3d: x must be rank 5 but got rank " + c.rank + ".";
}), E(a === "NDHWC", function() {
return "Error in avgPool3d: Only NDHWC is currently supported, " + ("but got dataFormat of " + a);
}), E(Mt(e, s), function() {
return "Error in avgPool3d: Either strides or dilations must be 1. " + ("Got strides " + e + " and dilations '" + s + "'");
}), i != null && E(ot(r), function() {
return "Error in avgPool3d: pad must be an integer when using, " + ("dimRoundingMode " + i + " but got pad " + r + ".");
});
var u = function(f, m) {
s == null && (s = [1, 1, 1]);
var g = Na(c.shape, t, e, s, r, i, a);
return m([c]), f.avgPool3d(c, g);
}, h = {x: c}, d = {filterSize: t, strides: e, pad: r, dimRoundingMode: i, dataFormat: a, dilations: s}, p = z.runKernelFunc(u, h, null, Nc, d);
return p = he(p, c.dtype), l ? Y(p, [p.shape[1], p.shape[2], p.shape[3], p.shape[4]]) : p;
}
var aA = U({avgPool3d_: iA});
function dg(n, t) {
var e = n[0].length;
n.forEach(function(i, a) {
E(i.length === e, function() {
return "Error in concat" + e + "D: rank of tensors[" + a + "] must be the same " + ("as the rank of the rest (" + e + ")");
});
}), E(t >= 0 && t < e, function() {
return "Error in concat" + e + "D: axis must be between 0 and " + (e - 1) + ".";
});
var r = n[0];
n.forEach(function(i, a) {
for (var s = 0; s < e; s++)
E(s === t || i[s] === r[s], function() {
return "Error in concat" + e + "D: Shape of tensors[" + a + "] (" + i + ") " + ("does not match the shape of the rest (" + r + ") ") + ("along the non-concatenated axis " + a + ".");
});
});
}
function pg(n, t) {
for (var e = n[0].slice(), r = 1; r < n.length; r++)
e[t] += n[r][t];
return e;
}
function sA(n, t) {
t === void 0 && (t = 0), E(n.length >= 1, function() {
return "Pass at least one tensor to concat";
});
var e = Sa(n, "tensors", "concat");
e[0].dtype === "complex64" && e.forEach(function(s) {
if (s.dtype !== "complex64")
throw new Error(`Cannot concatenate complex64 tensors with a tensor
with dtype ` + s.dtype + ". ");
});
var r = function(s, o) {
var c = rt(t, e[0].shape)[0], l = pg(e.map(function(d) {
return d.shape;
}), c);
if (dt(l) === 0)
return pr([], l);
if (e = e.filter(function(d) {
return d.size > 0;
}), e.length === 1)
return e[0];
var u = e.map(function(d) {
return d.shape;
});
dg(u, c);
var h = s.concat(e, c);
return o(e), h;
}, i = e, a = {axis: t};
return z.runKernelFunc(r, i, null, Dc, a);
}
var Et = U({concat_: sA});
function oA(n) {
var t = R(n, "x", "sigmoid"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.sigmoid(t);
return i([a]), a;
}, e, null, Wl);
}
var Vr = U({sigmoid_: oA});
function cA(n, t, e) {
var r = R(n, "x", "slice");
if (r.rank === 0)
throw new Error("Slicing scalar is not possible");
var i = function(o, c) {
var l = _u(r, t, e), u = l[0], h = l[1];
return Um(r, u, h), c([r]), o.slice(r, u, h);
}, a = {x: r}, s = {begin: t, size: e};
return z.runKernelFunc(i, a, null, El, s);
}
var Me = U({slice_: cA});
function lA(n) {
var t = R(n, "x", "tanh"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.tanh(t);
return i([a]), a;
}, e, null, Yl);
}
var Ws = U({tanh_: lA});
function uA(n, t, e, r, i, a) {
var s = R(n, "forgetBias", "basicLSTMCell"), o = R(t, "lstmKernel", "basicLSTMCell"), c = R(e, "lstmBias", "basicLSTMCell"), l = R(r, "data", "basicLSTMCell"), u = R(i, "c", "basicLSTMCell"), h = R(a, "h", "basicLSTMCell"), d = Et([l, h], 1), p = Ue(d, o), f = ge(p, c), m = f.shape[0], g = f.shape[1] / 4, y = [m, g], w = Me(f, [0, 0], y), b = Me(f, [0, g], y), x = Me(f, [0, g * 2], y), L = Me(f, [0, g * 3], y), N = ge(Z(Vr(w), Ws(b)), Z(u, Vr(ge(s, x)))), I = Z(Ws(N), Vr(L));
return [N, I];
}
var hA = U({basicLSTMCell_: uA});
function dA(n, t, e) {
var r = R(n, "x", "batchToSpaceND"), i = t.reduce(function(c, l) {
return c * l;
});
E(r.rank >= 1 + t.length, function() {
return "input rank is " + r.rank + " but should be > than blockShape.length " + t.length;
}), E(e.length === t.length, function() {
return "crops.length is " + e.length + " but should be equal to blockShape.length " + t.length;
}), E(r.shape[0] % i === 0, function() {
return "input tensor batch is " + r.shape[0] + " but is not divisible by the product of " + ("the elements of blockShape " + t.join(" * ") + " === " + i);
});
var a = function(c) {
return c.batchToSpaceND(r, t, e);
}, s = {x: r}, o = {blockShape: t, crops: e};
return z.runKernelFunc(a, s, null, Cc, o);
}
var Us = U({batchToSpaceND_: dA});
function pA(n) {
var t;
return n.rank === 0 || n.rank === 1 ? t = Y(n, [1, 1, 1, n.size]) : n.rank === 2 ? t = Y(n, [1, 1, n.shape[0], n.shape[1]]) : n.rank === 3 ? t = Y(n, [1, n.shape[0], n.shape[1], n.shape[2]]) : t = n, t;
}
function fA(n, t, e, r, i, a) {
a == null && (a = 1e-3);
var s = R(n, "x", "batchNorm"), o = R(t, "mean", "batchNorm"), c = R(e, "variance", "batchNorm"), l;
i != null && (l = R(i, "scale", "batchNorm"));
var u;
r != null && (u = R(r, "offset", "batchNorm")), E(o.rank === c.rank, function() {
return "Batch normalization gradient requires mean and variance to have equal ranks.";
}), E(u == null || o.rank === u.rank, function() {
return "Batch normalization gradient requires mean and offset to have equal ranks.";
}), E(l == null || o.rank === l.rank, function() {
return "Batch normalization gradient requires mean and scale to have equal ranks.";
});
var h = pA(s), d = function(g, y) {
return y([h, o, c, l]), g.batchNorm(h, Bs(o), Bs(c), Bs(u), Bs(l), a);
}, p = {x: h, scale: l, offset: u, mean: o, variance: c}, f = {varianceEpsilon: a}, m = z.runKernelFunc(d, p, null, $c, f);
return Y(m, s.shape);
}
function Bs(n) {
return n == null ? null : n.rank === 0 ? Y(n, [n.size]) : n.rank === 1 ? n : n.rank === 2 ? Y(n, [1, 1, n.shape[0], n.shape[1]]) : n.rank === 3 ? Y(n, [1, n.shape[0], n.shape[1], n.shape[2]]) : n;
}
var _a = U({batchNorm_: fA});
function mA(n, t, e, r, i, a) {
var s = R(n, "x", "batchNorm"), o = R(t, "mean", "batchNorm"), c = R(e, "variance", "batchNorm"), l;
i != null && (l = R(i, "scale", "batchNorm"));
var u;
return r != null && (u = R(r, "offset", "batchNorm")), E(s.rank === 2, function() {
return "Error in batchNorm2D: x must be rank 2 but got rank " + (s.rank + ".");
}), E(o.rank === 2 || o.rank === 1, function() {
return "Error in batchNorm2D: mean must be rank 2 or rank 1 but " + ("got rank " + o.rank + ".");
}), E(c.rank === 2 || c.rank === 1, function() {
return "Error in batchNorm2D: variance must be rank 2 or rank 1 " + ("but got rank " + c.rank + ".");
}), l != null && E(l.rank === 2 || l.rank === 1, function() {
return "Error in batchNorm2D: scale must be rank 2 or rank 1 " + ("but got rank " + l.rank + ".");
}), u != null && E(u.rank === 2 || u.rank === 1, function() {
return "Error in batchNorm2D: offset must be rank 2 or rank 1 " + ("but got rank " + u.rank + ".");
}), _a(s, o, c, u, l, a);
}
var gA = U({batchNorm2d_: mA});
function yA(n, t, e, r, i, a) {
var s = R(n, "x", "batchNorm"), o = R(t, "mean", "batchNorm"), c = R(e, "variance", "batchNorm"), l;
i != null && (l = R(i, "scale", "batchNorm"));
var u;
return r != null && (u = R(r, "offset", "batchNorm")), E(s.rank === 3, function() {
return "Error in batchNorm3D: x must be rank 3 but got rank " + (s.rank + ".");
}), E(o.rank === 3 || o.rank === 1, function() {
return "Error in batchNorm3D: mean must be rank 3 or rank 1 but " + ("got rank " + o.rank + ".");
}), E(c.rank === 3 || c.rank === 1, function() {
return "Error in batchNorm3D: variance must be rank 3 or rank 1 " + ("but got rank " + c.rank + ".");
}), l != null && E(l.rank === 3 || l.rank === 1, function() {
return "Error in batchNorm3D: scale must be rank 3 or rank 1 " + ("but got rank " + l.rank + ".");
}), u != null && E(u.rank === 3 || u.rank === 1, function() {
return "Error in batchNorm3D: offset must be rank 3 or rank 1 " + ("but got rank " + u.rank + ".");
}), _a(s, o, c, u, l, a);
}
var vA = U({batchNorm3d_: yA});
function wA(n, t, e, r, i, a) {
var s = R(n, "x", "batchNorm"), o = R(t, "mean", "batchNorm"), c = R(e, "variance", "batchNorm"), l;
i != null && (l = R(i, "scale", "batchNorm"));
var u;
return r != null && (u = R(r, "offset", "batchNorm")), E(s.rank === 4, function() {
return "Error in batchNorm4D: x must be rank 4 but got rank " + (s.rank + ".");
}), E(o.rank === 4 || o.rank === 1, function() {
return "Error in batchNorm4D: mean must be rank 4 or rank 1 but " + ("got rank " + o.rank + ".");
}), E(c.rank === 4 || c.rank === 1, function() {
return "Error in batchNorm4D: variance must be rank 4 or rank 1 " + ("but got rank " + c.rank + ".");
}), l != null && E(l.rank === 4 || l.rank === 1, function() {
return "Error in batchNorm4D: scale must be rank 4 or rank 1 " + ("but got rank " + l.rank + ".");
}), u != null && E(u.rank === 4 || u.rank === 1, function() {
return "Error in batchNorm4D: offset must be rank 4 or rank 1 " + ("but got rank " + u.rank + ".");
}), _a(s, o, c, u, l, a);
}
var bA = U({batchNorm4d_: wA});
function xA(n, t) {
var e = R(n, "broadcastTo", "x"), r = e.shape;
if (t.some(function(d) {
return !(d > 0) || d % 1 !== 0;
}))
throw new Error("broadcastTo(): Invalid broadcast shape [" + t + "].");
if (t.length < e.rank)
throw new Error("broadcastTo(): shape.length=" + t.length + " < input.rank=" + e.rank + ".");
if (t.length > e.rank) {
for (var i = e.shape.slice(); i.length < t.length; )
i.unshift(1);
e = Y(e, i);
}
for (var a = e.shape, s = Array.from(t), o = t.length - 1; o >= 0; o--)
if (a[o] === t[o])
s[o] = 1;
else if (e.shape[o] !== 1)
throw new Error("broadcastTo(): [" + r + "] cannot be broadcast to [" + t + "].");
var c = s.map(function(d, p) {
return d > 1 ? p : -1;
}).filter(function(d) {
return d >= 0;
});
if (c.length === 0)
return Mr(e);
var l = function(d) {
return d.tile(e, s);
}, u = {x: e}, h = {shape: t, inputShape: a};
return z.runKernelFunc(l, u, null, Rc, h);
}
var zs = U({broadcastTo_: xA});
function LA(n) {
var t = R(n, "x", "ceil"), e = {x: t};
return z.runKernelFunc(function(r) {
return r.ceil(t);
}, e, null, Oc);
}
var fg = U({ceil_: LA});
function SA(n, t, e) {
var r = R(n, "x", "clipByValue");
E(t <= e, function() {
return "Error in clip: min (" + t + ") must be " + ("less than or equal to max (" + e + ").");
});
var i = {x: r}, a = {clipValueMin: t, clipValueMax: e};
return z.runKernelFunc(function(s, o) {
var c = s.clip(r, t, e);
return o([r]), c;
}, i, null, Ec, a);
}
var mg = U({clipByValue_: SA});
function IA(n) {
return Et(n, 0);
}
var AA = U({concat1d_: IA});
function TA(n, t) {
return Et(n, t);
}
var NA = U({concat2d_: TA});
function _A(n, t) {
return Et(n, t);
}
var CA = U({concat3d_: _A});
function RA(n, t) {
return Et(n, t);
}
var OA = U({concat4d_: RA});
function EA(n, t, e, r, i, a, s) {
i === void 0 && (i = "NHWC"), a === void 0 && (a = [1, 1]);
var o = R(n, "x", "conv2d"), c = R(t, "filter", "conv2d"), l = o, u = false;
o.rank === 3 && (u = true, l = Y(o, [1, o.shape[0], o.shape[1], o.shape[2]])), E(l.rank === 4, function() {
return "Error in conv2d: input must be rank 4, but got rank " + l.rank + ".";
}), E(c.rank === 4, function() {
return "Error in conv2d: filter must be rank 4, but got rank " + (c.rank + ".");
}), s != null && E(ot(r), function() {
return "Error in conv2d: pad must be an integer when using, " + ("dimRoundingMode " + s + " but got pad " + r + ".");
});
var h = i === "NHWC" ? l.shape[3] : l.shape[1];
E(h === c.shape[2], function() {
return "Error in conv2d: depth of input (" + h + ") must match " + ("input depth for filter " + c.shape[2] + ".");
}), E(Mt(e, a), function() {
return "Error in conv2D: Either strides or dilations must be 1. " + ("Got strides " + e + " and dilations '" + a + "'");
});
var d = function(g, y) {
var w = Aa(i), b = mn(l.shape, c.shape, e, a, r, s, false, w), x = g.conv2d(l, c, b);
return y([l, c]), x;
}, p = {x: l, filter: c}, f = {strides: e, pad: r, dataFormat: i, dilations: a, dimRoundingMode: s}, m = z.runKernelFunc(d, p, null, kc, f);
return u ? Y(m, [m.shape[1], m.shape[2], m.shape[3]]) : m;
}
var Di = U({conv2d_: EA});
function DA(n, t, e, r, i, a, s) {
i === void 0 && (i = "NWC"), a === void 0 && (a = 1);
var o = R(n, "x", "conv1d"), c = R(t, "filter", "conv1d"), l = o, u = false;
o.rank === 2 && (u = true, l = Y(o, [1, o.shape[0], o.shape[1]])), E(l.rank === 3, function() {
return "Error in conv1d: input must be rank 3, but got rank " + l.rank + ".";
}), E(c.rank === 3, function() {
return "Error in conv1d: filter must be rank 3, but got rank " + (c.rank + ".");
}), s != null && E(ot(r), function() {
return "Error in conv1d: pad must be an integer when using, " + ("dimRoundingMode " + s + " but got pad " + r + ".");
}), E(l.shape[2] === c.shape[1], function() {
return "Error in conv1d: depth of input (" + l.shape[2] + ") must match " + ("input depth for filter " + c.shape[1] + ".");
}), E(Mt(e, a), function() {
return "Error in conv1D: Either stride or dilation must be 1. " + ("Got stride " + e + " and dilation '" + a + "'");
}), E(i === "NWC", function() {
return "Error in conv1d: got dataFormat of " + i + " but only NWC is currently supported.";
});
var h = Y(c, [1, c.shape[0], c.shape[1], c.shape[2]]), d = Y(l, [l.shape[0], 1, l.shape[1], l.shape[2]]), p = [1, e], f = [1, a], m = "NHWC", g = Di(d, h, p, r, m, f, s);
return u ? Y(g, [g.shape[2], g.shape[3]]) : Y(g, [g.shape[0], g.shape[2], g.shape[3]]);
}
var gg = U({conv1d_: DA});
function kA(n, t, e, r, i, a, s) {
a === void 0 && (a = "NHWC"), E(n.length === t.rank, function() {
return "Length of inShape " + ("(" + n.length + ") and rank of dy (" + t.rank + ") must match");
});
var o = n, c = t, l = false;
t.rank === 3 && (l = true, c = Y(t, [1, t.shape[0], t.shape[1], t.shape[2]]), o = [1, n[0], n[1], n[2]]), E(o.length === 4, function() {
return "Error in conv2dDerInput: inShape must be length 4, but got length " + (o.length + ".");
}), E(c.rank === 4, function() {
return "Error in conv2dDerInput: dy must be rank 4, but got " + ("rank " + c.rank);
}), E(e.rank === 4, function() {
return "Error in conv2dDerInput: filter must be rank 4, but got " + ("rank " + e.rank);
});
var u = a === "NHWC" ? o[3] : o[1], h = a === "NHWC" ? c.shape[3] : c.shape[1];
E(u === e.shape[2], function() {
return "Error in conv2dDerInput: depth of input (" + u + ") must " + ("match input depth for filter " + e.shape[2] + ".");
}), E(h === e.shape[3], function() {
return "Error in conv2dDerInput: depth of output (" + h + ") must " + ("match output depth for filter " + e.shape[3] + ".");
}), s != null && E(ot(i), function() {
return "Error in conv2dDerInput: pad must be an integer when using, " + ("dimRoundingMode " + s + " but got pad " + i + ".");
});
var d = function(g, y) {
var w = 1, b = Aa(a), x = mn(o, e.shape, r, w, i, s, false, b), L = g.conv2dDerInput(c, e, x);
return y([c, e]), L;
}, p = {dy: c, filter: e}, f = {strides: r, pad: i, dataFormat: a, dimRoundingMode: s, inputShape: o}, m = z.runKernelFunc(d, p, null, Fc, f);
return l ? Y(m, [m.shape[1], m.shape[2], m.shape[3]]) : m;
}
var Uu = U({conv2DBackpropInput_: kA});
function FA(n, t, e, r, i, a) {
var s = R(n, "x", "conv2dTranspose"), o = R(t, "filter", "conv2dTranspose");
return Uu(e, s, o, r, i, "NHWC", a);
}
var yg = U({conv2dTranspose_: FA});
function WA(n, t, e, r, i, a) {
i === void 0 && (i = "NDHWC"), a === void 0 && (a = [1, 1, 1]);
var s = R(n, "x", "conv3d"), o = R(t, "filter", "conv3d"), c = s, l = false;
s.rank === 4 && (l = true, c = Y(s, [1, s.shape[0], s.shape[1], s.shape[2], s.shape[3]])), E(c.rank === 5, function() {
return "Error in conv3d: input must be rank 5, but got rank " + c.rank + ".";
}), E(o.rank === 5, function() {
return "Error in conv3d: filter must be rank 5, but got rank " + (o.rank + ".");
}), E(c.shape[4] === o.shape[3], function() {
return "Error in conv3d: depth of input (" + c.shape[4] + ") must match " + ("input depth for filter " + o.shape[3] + ".");
}), E(Mt(e, a), function() {
return "Error in conv3D: Either strides or dilations must be 1. " + ("Got strides " + e + " and dilations '" + a + "'");
}), E(i === "NDHWC", function() {
return "Error in conv3d: got dataFormat of " + i + " but only NDHWC is currently supported.";
});
var u = function(f, m) {
var g = Ta(c.shape, o.shape, e, a, r), y = f.conv3d(c, o, g);
return m([c, o]), y;
}, h = {x: c, filter: o}, d = {strides: e, pad: r, dataFormat: i, dilations: a}, p = z.runKernelFunc(u, h, null, Wc, d);
return l ? Y(p, [p.shape[1], p.shape[2], p.shape[3], p.shape[4]]) : p;
}
var UA = U({conv3d_: WA});
function BA(n, t, e, r, i) {
E(n.length === t.rank, function() {
return "Length of inShape " + ("(" + n.length + ") and rank of dy (" + t.rank + ") must match");
});
var a = n, s = t, o = false;
t.rank === 4 && (o = true, s = Y(t, [1, t.shape[0], t.shape[1], t.shape[2], t.shape[3]]), a = [1, n[0], n[1], n[2], n[3]]);
var c = a[4], l = s.shape[4];
E(a.length === 5, function() {
return "Error in conv3dDerInput: inShape must be length 5, but got length " + (a.length + ".");
}), E(s.rank === 5, function() {
return "Error in conv3dDerInput: dy must be rank 5, but got " + ("rank " + s.rank);
}), E(e.rank === 5, function() {
return "Error in conv3dDerInput: filter must be rank 5, but got " + ("rank " + e.rank);
}), E(c === e.shape[3], function() {
return "Error in conv3dDerInput: depth of input (" + c + ") must " + ("match input depth for filter " + e.shape[3] + ".");
}), E(l === e.shape[4], function() {
return "Error in conv3dDerInput: depth of output (" + l + ") must " + ("match output depth for filter " + e.shape[4] + ".");
});
var u = function(f) {
var m = 1, g = Ta(a, e.shape, r, m, i);
return f.conv3dDerInput(s, e, g);
}, h = {dy: s, filter: e}, d = {pad: i, strides: r, inputShape: a}, p = z.runKernelFunc(u, h, null, gf, d);
return o ? Y(p, [p.shape[1], p.shape[2], p.shape[3], p.shape[4]]) : p;
}
var vg = U({conv3DBackpropInput_: BA});
function zA(n, t, e, r, i) {
var a = R(n, "x", "conv3dTranspose"), s = R(t, "filter", "conv3dTranspose");
return vg(e, a, s, r, i);
}
var PA = U({conv3dTranspose_: zA});
function MA(n) {
var t = R(n, "x", "cos"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.cos(t);
return i([t]), a;
}, e, null, Uc);
}
var Ps = U({cos_: MA});
function HA(n) {
var t = R(n, "x", "cosh"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.cosh(t);
return i([t]), a;
}, e, null, Bc);
}
var Bu = U({cosh_: HA});
function VA(n, t, e, r) {
t === void 0 && (t = 0), e === void 0 && (e = false), r === void 0 && (r = false);
var i = R(n, "x", "cumsum"), a = function(c, l) {
var u = fn([t], i.rank), h = i;
u != null && (h = Tt(i, u));
var d = On(1, i.rank)[0], p = c.cumsum(h, d, e, r);
if (l([i]), u != null) {
var f = ks(u);
p = Tt(p, f);
}
return p;
}, s = {x: i}, o = {axis: t, exclusive: e, reverse: r};
return z.runKernelFunc(a, s, null, zc, o);
}
var zu = U({cumsum_: VA});
function GA(n, t, e) {
e === void 0 && (e = "NHWC");
var r = R(n, "x", "depthToSpace"), i = e === "NHWC" ? r.shape[1] : r.shape[2], a = e === "NHWC" ? r.shape[2] : r.shape[3], s = e === "NHWC" ? r.shape[3] : r.shape[1];
E(i * t >= 0, function() {
return `Negative dimension size caused by overflow when multiplying
` + i + " and " + t + ` for depthToSpace with input shape
` + r.shape;
}), E(a * t >= 0, function() {
return `Negative dimension size caused by overflow when multiplying
` + a + " and " + t + ` for depthToSpace with input shape
` + r.shape;
}), E(s % (t * t) === 0, function() {
return "Dimension size must be evenly divisible by " + t * t + " but is " + s + " for depthToSpace with input shape " + r.shape;
});
var o = function(u) {
return u.depthToSpace(r, t, e);
}, c = {x: r}, l = {blockSize: t, dataFormat: e};
return z.runKernelFunc(o, c, null, vf, l);
}
var wg = U({depthToSpace_: GA});
function qA(n, t, e, r, i, a, s) {
i === void 0 && (i = "NHWC"), a === void 0 && (a = [1, 1]);
var o = R(n, "x", "depthwiseConv2d"), c = R(t, "filter", "depthwiseConv2d"), l = o, u = false;
o.rank === 3 && (u = true, l = Y(o, [1, o.shape[0], o.shape[1], o.shape[2]])), E(l.rank === 4, function() {
return "Error in depthwiseConv2d: input must be rank 4, but got " + ("rank " + l.rank + ".");
}), E(c.rank === 4, function() {
return "Error in depthwiseConv2d: filter must be rank 4, but got rank " + (c.rank + ".");
}), E(l.shape[3] === c.shape[2], function() {
return "Error in depthwiseConv2d: number of input channels " + ("(" + l.shape[3] + ") must match the inChannels dimension in ") + ("filter " + c.shape[2] + ".");
}), s != null && E(ot(r), function() {
return "Error in depthwiseConv2d: pad must be an integer when using, " + ("dimRoundingMode " + s + " but got pad " + r + ".");
});
var h = function(m, g) {
a == null && (a = [1, 1]), E(Mt(e, a), function() {
return "Error in depthwiseConv2d: Either strides or dilations must be " + ("1. Got strides " + e + " and dilations '" + a + "'");
});
var y = mn(l.shape, c.shape, e, a, r, s, true), w = m.depthwiseConv2D(l, c, y);
return g([l, c]), w;
}, d = {x: l, filter: c}, p = {strides: e, pad: r, dataFormat: i, dilations: a, dimRoundingMode: s}, f = z.runKernelFunc(h, d, null, Pc, p);
return u ? Y(f, [f.shape[1], f.shape[2], f.shape[3]]) : f;
}
var Ca = U({depthwiseConv2d_: qA});
function YA(n) {
var t = R(n, "x", "diag"), e = function(i) {
var a = Y(t, [t.size]), s = i.diag(a), o = n.shape.concat(n.shape);
return Y(s, o);
}, r = {x: t};
return z.runKernelFunc(e, r, null, xf);
}
var KA = U({diag_: YA});
function jA(n, t, e, r, i, a) {
i === void 0 && (i = [1, 1]), a === void 0 && (a = "NHWC");
var s = R(n, "x", "dilation2d"), o = R(t, "filter", "dilation2d");
E(s.rank === 3 || s.rank === 4, function() {
return "Error in dilation2d: input must be rank 3 or 4, but got rank " + (s.rank + ".");
}), E(o.rank === 3, function() {
return "Error in dilation2d: filter must be rank 3, but got rank " + (o.rank + ".");
}), E(a === "NHWC", function() {
return "Error in dilation2d: Only NHWC is currently supported, " + ("but got dataFormat of " + a);
});
var c = s, l = false;
s.rank === 3 && (c = Y(s, [1, s.shape[0], s.shape[1], s.shape[2]]), l = true);
var u = {x: c, filter: o}, h = {strides: e, pad: r, dilations: i}, d = z.runKernel(Mc, u, h);
return l ? Y(d, [d.shape[1], d.shape[2], d.shape[3]]) : d;
}
var bg = U({dilation2d_: jA});
function $A(n, t) {
for (var e = n.length, r = [], i = 0; i < e; i++) {
var a = e - 1 - i, s = n[a] || 1, o = t[t.length - 1 - i] || 1;
o > 1 && s === 1 && r.unshift(a);
}
return r;
}
function bt(n, t) {
for (var e = [], r = 0; r < t.length; r++) {
var i = n[n.length - r - 1], a = t.length - r - 1, s = t[a];
(i == null || i === 1 && s > 1) && e.unshift(a);
}
return e;
}
function it(n, t) {
for (var e = [], r = Math.max(n.length, t.length), i = 0; i < r; i++) {
var a = n[n.length - i - 1];
a == null && (a = 1);
var s = t[t.length - i - 1];
if (s == null && (s = 1), a === 1)
e.unshift(s);
else if (s === 1)
e.unshift(a);
else if (a !== s) {
var o = "Operands could not be broadcast together with shapes " + (n + " and " + t + ".");
throw Error(o);
} else
e.unshift(a);
}
return e;
}
function XA(n, t) {
var e, r = R(n, "a", "equal"), i = R(t, "b", "equal");
e = ct(r, i), r = e[0], i = e[1], it(r.shape, i.shape);
var a = function(o) {
return o.equal(r, i);
}, s = {a: r, b: i};
return z.runKernelFunc(a, s, null, Af);
}
var Ra = U({equal_: XA});
function JA(n, t, e) {
var r = R(t, "a", "where"), i = R(e, "b", "where"), a = R(n, "condition", "where", "bool"), s = it(r.shape, i.shape), o = zs(r, s), c = zs(i, s);
a.rank === 1 && E(a.shape[0] === r.shape[0], function() {
return "The first dimension of `a` must match the size of `condition`.";
}), a.rank !== 1 && Pe(a.shape, c.shape, "Error in where: ");
var l = function(h, d) {
var p = h.select(a, o, c);
return d([a]), p;
}, u = {condition: a, t: o, e: c};
return z.runKernelFunc(l, u, null, Rl);
}
var gn = U({where_: JA});
function ZA(n) {
var t = R(n, "x", "zerosLike"), e = {x: t};
return z.runKernelFunc(function(r) {
return r.zerosLike(t);
}, e, null, Jl);
}
var ke = U({zerosLike_: ZA});
function QA(n, t) {
var e, r = R(n, "a", "div"), i = R(t, "b", "div");
e = ct(r, i), r = e[0], i = e[1];
var a = Ne(r, i), s = ke(a), o = Ra(i, s);
return gn(o, s, a);
}
var xg = U({divNoNan_: QA});
function e5(n, t) {
var e = R(n, "t1", "dot"), r = R(t, "t2", "dot");
E((e.rank === 1 || e.rank === 2) && (r.rank === 1 || r.rank === 2), function() {
return "Error in dot: inputs must all be rank 1 or 2, but got ranks " + (e.rank + " and " + r.rank + ".");
});
var i = e.rank === 1 ? e.size : e.shape[1], a = r.rank === 1 ? r.size : r.shape[0];
if (E(i === a, function() {
return "Error in dot: inner dimensions of inputs must match, but got " + (i + " and " + a + ".");
}), e.rank === 1 && r.rank === 1) {
var s = Y(e, [1, -1]), o = Y(r, [-1, 1]), c = Ue(s, o);
return Y(c, []);
} else if (e.rank === 1 && r.rank === 2) {
var s = Y(e, [1, -1]), o = Y(r, [r.shape[0], r.shape[1]]), c = Ue(s, o);
return Y(c, [c.size]);
} else if (e.rank === 2 && r.rank === 1) {
var o = Y(r, [-1, 1]), c = Ue(e, o);
return Y(c, [c.size]);
} else {
var o = Y(r, [r.shape[0], r.shape[1]]), c = Ue(e, o);
return c;
}
}
var Lg = U({dot_: e5});
function t5(n) {
var t = R(n, "x", "elu"), e = function(i, a) {
var s = i.elu(t);
return a([s]), s;
}, r = {x: t};
return z.runKernelFunc(e, r, null, Vc);
}
var Pu = U({elu_: t5});
function n5(n) {
var t = R(n, "x", "erf");
E(t.dtype === "int32" || t.dtype === "float32", function() {
return "Input dtype must be `int32` or `float32`.";
}), t.dtype === "int32" && (t = he(t, "float32"));
var e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.erf(t);
return i([t]), a;
}, e, null, Gc);
}
var Sg = U({erf_: n5});
function r5(n) {
var t = R(n, "x", "exp"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.exp(t);
return i([a]), a;
}, e, null, qc);
}
var yn = U({exp_: r5});
function i5(n, t) {
t === void 0 && (t = 0);
var e = null, r = R(n, "x", "expandDims", e);
E(t <= r.rank, function() {
return "Axis must be <= rank of the tensor";
});
var i = r.shape.slice();
return t < 0 && (E(-(r.rank + 1) <= t, function() {
return "Axis must be in the interval [" + -(r.rank + 1) + ", " + r.rank + "]";
}), t = r.rank + t + 1), i.splice(t, 0, 1), Y(r, i);
}
var vn = U({expandDims_: i5});
function a5(n) {
var t = R(n, "x", "expm1"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.expm1(t);
return i([t]), a;
}, e, null, Yc);
}
var Ig = U({expm1_: a5});
function s5(n, t) {
var e = null, r = R(n, "x", "tile", e);
E(r.rank === t.length, function() {
return "Error in transpose: rank of input " + r.rank + " " + ("must match length of reps " + t + ".");
});
var i = function(c, l) {
var u = c.tile(r, t);
return l([r]), u;
}, a = [r], s = {x: r}, o = {reps: t};
return z.runKernelFunc(i, s, null, Kl, o, a);
}
var ki = U({tile_: s5});
function o5(n, t, e, r) {
r === void 0 && (r = "float32"), t == null && (t = n);
for (var i = Rn([n, t], r), a = n <= t ? n : t, s = 0; s < a; ++s)
i.set(1, s, s);
var o = Y(i.toTensor(), [n, t]);
if (e == null)
return o;
if (e.length === 1)
return ki(vn(o, 0), [e[0], 1, 1]);
if (e.length === 2)
return ki(vn(vn(o, 0), 0), [e[0], e[1], 1, 1]);
if (e.length === 3)
return ki(vn(vn(vn(o, 0), 0), 0), [e[0], e[1], e[2], 1, 1]);
throw new Error("eye() currently supports only 1D and 2D " + ("batchShapes, but received " + e.length + "D."));
}
var Ag = U({eye_: o5});
function Mu(n, t, e) {
var r = {shape: n, value: t, dtype: e};
return z.runKernelFunc(function(i) {
return i.fill(n, t, e);
}, {}, null, Nf, r);
}
function c5(n) {
var t = R(n, "x", "floor"), e = {x: t};
return z.runKernelFunc(function(r) {
return r.floor(t);
}, e, null, Kc);
}
var Ms = U({floor_: c5});
var Hu = 30;
function l5(n) {
return n <= Hu ? n : Ls(n, Math.floor(Math.sqrt(n)));
}
function u5(n, t) {
var e = false, r;
for (n <= Hu ? (r = n, e = true) : r = Ls(n, Math.floor(Math.sqrt(n))); !e; )
r > t || r === n ? e = true : r = Ls(n, r + 1);
return r;
}
function h5(n, t, e) {
for (var r = [], i = n.length, a = 0; a < i; a++)
a !== t ? r.push(n[a]) : r.push(e);
return r;
}
function Tg(n, t, e) {
for (var r = n.shape[e], i = [], a = 1, s = 1, o = 0; o < e; o++)
i.push(n.shape[o]), a *= n.shape[o];
for (var o = 0; o < t.rank; o++)
i.push(t.shape[o]);
for (var o = e + 1; o < n.rank; o++)
i.push(n.shape[o]), s *= n.shape[o];
return {batchSize: a, sliceSize: s, dimSize: r, outputShape: i};
}
var d5 = {__proto__: null, segOpComputeOptimalWindowSize: u5, computeOutShape: h5, collectGatherOpShapeInfo: Tg};
function p5(n, t, e) {
e === void 0 && (e = 0);
var r = R(n, "x", "gather"), i = R(t, "indices", "gather", "int32"), a = {x: r, indices: i}, s = {axis: e}, o = function(c, l) {
var u = rt(e, r.shape)[0], h = Tg(r, i, u), d = c.gather(r, Y(i, [i.size]), u);
return l([r, i]), Y(d, h.outputShape);
};
return z.runKernelFunc(o, a, null, Xc, s);
}
var Hs = U({gather_: p5});
function f5(n, t) {
var e, r = R(n, "a", "greater"), i = R(t, "b", "greater");
e = ct(r, i), r = e[0], i = e[1], it(r.shape, i.shape);
var a = function(o) {
return o.greater(r, i);
}, s = {a: r, b: i};
return z.runKernelFunc(a, s, null, Rf);
}
var vr = U({greater_: f5});
function m5(n, t) {
var e, r = R(n, "a", "greaterEqual"), i = R(t, "b", "greaterEqual");
e = ct(r, i), r = e[0], i = e[1], it(r.shape, i.shape);
var a = function(o, c) {
var l = o.greaterEqual(r, i);
return c([r, i]), l;
}, s = {a: r, b: i};
return z.runKernelFunc(a, s, null, Jc);
}
var Gr = U({greaterEqual_: m5});
function g5(n) {
var t = R(n, "input", "imag"), e = function(i) {
return i.imag(t);
}, r = {input: t};
return z.runKernelFunc(e, r, null, Ef);
}
var Vs = U({imag_: g5});
function y5(n) {
var t = R(n, "x", "isFinite"), e = {x: t};
return z.runKernelFunc(function(r) {
return r.isFinite(t);
}, e, null, Qc);
}
var Ng = U({isFinite_: y5});
function v5(n) {
var t = R(n, "x", "isInf"), e = {x: t};
return z.runKernelFunc(function(r) {
return r.isInf(t);
}, e, null, el);
}
var _g = U({isInf_: v5});
function w5(n) {
var t = R(n, "x", "isNaN"), e = {x: t};
return z.runKernelFunc(function(r) {
return r.isNaN(t);
}, e, null, tl);
}
var Cg = U({isNaN_: w5});
function b5(n, t) {
var e, r = R(n, "a", "maximum"), i = R(t, "b", "maximum");
e = ct(r, i), r = e[0], i = e[1], r.dtype === "bool" && (r = he(r, "int32"), i = he(i, "int32")), it(r.shape, i.shape);
var a = function(o, c) {
var l = o.maximum(r, i);
return c([r, i]), l;
}, s = {a: r, b: i};
return z.runKernelFunc(a, s, null, ol);
}
var Fi = U({maximum_: b5});
function Le(n, t) {
if ((Ft(n) && t !== "string" || Array.isArray(n)) && t !== "complex64")
throw new Error("Error creating a new Scalar: value must be a primitive (number|boolean|string)");
if (t === "string" && Ft(n) && !(n instanceof Uint8Array))
throw new Error("When making a scalar from encoded string, the value must be `Uint8Array`.");
var e = [], r = [];
return dr(n, e, r, t);
}
function x5(n, t) {
t === void 0 && (t = 0.2);
var e = R(n, "x", "leakyRelu");
return Fi(Z(Le(t), e), e);
}
var Rg = U({leakyRelu_: x5});
function L5(n, t) {
var e, r = R(n, "a", "less"), i = R(t, "b", "less");
e = ct(r, i), r = e[0], i = e[1], it(r.shape, i.shape);
var a = function(o) {
return o.less(r, i);
}, s = {a: r, b: i};
return z.runKernelFunc(a, s, null, Df);
}
var Gs = U({less_: L5});
function S5(n, t) {
var e, r = R(n, "a", "lessEqual"), i = R(t, "b", "lessEqual");
e = ct(r, i), r = e[0], i = e[1], it(r.shape, i.shape);
var a = function(o, c) {
var l = o.lessEqual(r, i);
return c([r, i]), l;
}, s = {a: r, b: i};
return z.runKernelFunc(a, s, null, kf);
}
var qr = U({lessEqual_: S5});
function I5(n, t, e) {
if (e <= 0)
throw new Error("The number of values should be positive.");
var r = {start: n, stop: t, num: e};
return z.runKernelFunc(function(i) {
return i.linspace(n, t, e);
}, {}, null, Ff, r);
}
function A5(n, t, e, r, i) {
t === void 0 && (t = 5), e === void 0 && (e = 1), r === void 0 && (r = 1), i === void 0 && (i = 0.5);
var a = R(n, "x", "localResponseNormalization");
E(a.rank === 4 || a.rank === 3, function() {
return `Error in localResponseNormalization: x must be rank 3 or 4 but got
rank ` + a.rank + ".";
}), E(ot(t), function() {
return "Error in localResponseNormalization: depthRadius must be an " + ("integer but got depthRadius " + t + ".");
});
var s = a, o = false;
a.rank === 3 && (o = true, s = Y(a, [1, a.shape[0], a.shape[1], a.shape[2]]));
var c = function(d, p) {
var f = d.localResponseNormalization4D(s, t, e, r, i);
return p([s, f]), f;
}, l = {x: s}, u = {depthRadius: t, bias: e, alpha: r, beta: i}, h = z.runKernelFunc(c, l, null, al, u);
return o ? Y(h, [h.shape[1], h.shape[2], h.shape[3]]) : h;
}
var Og = U({localResponseNormalization_: A5});
function T5(n) {
var t = R(n, "x", "log"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.log(t);
return i([t]), a;
}, e, null, nl);
}
var Yr = U({log_: T5});
function N5(n) {
var t = R(n, "x", "log1p"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.log1p(t);
return i([t]), a;
}, e, null, rl);
}
var Vu = U({log1p_: N5});
function _5(n) {
return E(ur(n), function() {
return "The f passed in grad(f) must be a function";
}), function(t, e) {
var r = R(t, "x", "tf.grad", null), i = e != null ? R(e, "dy", "tf.grad") : null;
return z.tidy(function() {
var a = z.gradients(function() {
return n(r);
}, [r], i), s = a.value, o = a.grads;
return i != null && Pe(s.shape, i.shape, "The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"), qs(o), o[0];
});
};
}
function C5(n) {
return E(ur(n), function() {
return "The f passed in grads(f) must be a function";
}), function(t, e) {
E(Array.isArray(t), function() {
return "The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s";
});
var r = Sa(t, "args", "tf.grads", null), i = e != null ? R(e, "dy", "tf.grads") : null;
return z.tidy(function() {
var a = z.gradients(function() {
return n.apply(void 0, r);
}, r, i), s = a.value, o = a.grads;
return i != null && Pe(s.shape, i.shape, "The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"), qs(o), o;
});
};
}
function R5(n) {
return E(ur(n), function() {
return "The f passed in valueAndGrad(f) must be a function";
}), function(t, e) {
E(t instanceof K, function() {
return "The x passed in valueAndGrad(f)(x) must be a tensor";
}), E(e == null || e instanceof K, function() {
return "The dy passed in valueAndGrad(f)(x, dy) must be a tensor";
});
var r = z.gradients(function() {
return n(t);
}, [t], e), i = r.grads, a = r.value;
return qs(i), {grad: i[0], value: a};
};
}
function O5(n) {
return E(ur(n), function() {
return "The f passed in valueAndGrads(f) must be a function";
}), function(t, e) {
E(Array.isArray(t) && t.every(function(i) {
return i instanceof K;
}), function() {
return "The args passed in valueAndGrads(f)(args) must be array of tensors";
}), E(e == null || e instanceof K, function() {
return "The dy passed in valueAndGrads(f)(args, dy) must be a tensor";
});
var r = z.gradients(function() {
return n.apply(void 0, t);
}, t, e);
return e != null && Pe(r.value.shape, e.shape, "The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"), qs(r.grads), r;
};
}
function Eg(n, t) {
E(ur(n), function() {
return "The f passed in variableGrads(f) must be a function";
}), E(t == null || Array.isArray(t) && t.every(function(h) {
return h instanceof La;
}), function() {
return "The varList passed in variableGrads(f, varList) must be an array of variables";
});
var e = t != null;
if (!e) {
t = [];
for (var r in z.registeredVariables)
t.push(z.registeredVariables[r]);
}
var i = e ? t.filter(function(h) {
return !h.trainable;
}) : null, a = t.length;
t = t.filter(function(h) {
return h.trainable;
}), E(t.length > 0, function() {
return "variableGrads() expects at least one of the input variables to " + ("be trainable, but none of the " + a + " variables is ") + "trainable.";
});
var s = true, o = z.gradients(n, t, null, s), c = o.value, l = o.grads;
E(l.some(function(h) {
return h != null;
}), function() {
return "Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize().";
}), E(c.rank === 0, function() {
return "The f passed in variableGrads(f) must return a scalar, but it " + ("returned a rank-" + c.rank + " tensor");
});
var u = {};
return t.forEach(function(h, d) {
l[d] != null && (u[h.name] = l[d]);
}), i != null && i.forEach(function(h) {
return u[h.name] = null;
}), {value: c, grads: u};
}
function En(n) {
return z.customGrad(n);
}
function qs(n) {
var t = n.filter(function(e) {
return e == null;
}).length;
if (t > 0)
throw new Error(`Cannot compute gradient of y=f(x) with respect to x. Make sure that
the f you passed encloses all operations that lead from x to y.`);
}
function E5(n) {
var t = R(n, "x", "neg"), e = {x: t};
return z.runKernelFunc(function(r) {
return r.neg(t);
}, e, null, ml);
}
var xt = U({neg_: E5});
function D5(n) {
var t = R(n, "x", "softplus"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.softplus(t);
return i([t]), a;
}, e, null, Ul);
}
var Gu = U({softplus_: D5});
function k5(n) {
var t = R(n, "x", "logSigmoid"), e = En(function(r) {
var i = xt(Gu(xt(r))), a = function(s) {
var o = Z(s, Vr(xt(r)));
return o;
};
return {value: i, gradFunc: a};
});
return e(t);
}
var Dg = U({logSigmoid_: k5});
function F5(n, t, e) {
t === void 0 && (t = null), e === void 0 && (e = false);
var r = R(n, "x", "max"), i = function(o, c) {
var l = rt(t, r.shape), u = l, h = fn(u, r.rank), d = r;
h != null && (d = Tt(r, h), u = On(u.length, d.rank));
var p = o.max(d, u);
h != null && d.dispose();
var f = p;
if (e) {
var m = an(f.shape, rt(t, r.shape));
f = Y(f, m), p.dispose();
}
return c([r, f]), f;
}, a = {x: r}, s = {reductionIndices: t, keepDims: e};
return z.runKernelFunc(i, a, null, sl, s);
}
var Kr = U({max_: F5});
function W5(n, t) {
var e, r = R(n, "a", "sub"), i = R(t, "b", "sub");
e = ct(r, i), r = e[0], i = e[1];
var a = function(o, c) {
var l = o.subtract(r, i);
return c([r, i]), l;
}, s = {a: r, b: i};
return z.runKernelFunc(a, s, null, Gl);
}
var be = U({sub_: W5});
function U5(n, t, e) {
t === void 0 && (t = null), e === void 0 && (e = false);
var r = R(n, "x", "sum");
r.dtype === "bool" && (r = he(r, "int32"));
var i = function(o, c) {
c([r]);
var l = rt(t, r.shape), u = fn(l, r.rank), h = l, d = r;
u != null && (d = Tt(r, u), h = On(h.length, r.rank));
var p = o.sum(d, h);
if (e) {
var f = an(p.shape, l);
p = Y(p, f);
}
return p;
}, a = {x: r}, s = {axis: t, keepDims: e};
return z.runKernelFunc(i, a, null, zl, s);
}
var _e = U({sum_: U5});
function B5(n, t) {
t === void 0 && (t = -1);
var e = R(n, "logits", "logSoftmax");
if (t === -1 && (t = e.rank - 1), t !== e.rank - 1)
throw Error("Log Softmax along a non-last dimension is not yet supported. " + ("Logits was rank " + e.rank + " and axis was " + t));
var r = function(s, o) {
var c = true, l = Kr(n, t, true), u = be(n, l), h = be(he(u, "float32"), Yr(_e(yn(u), t, c)));
return o([h]), h;
}, i = {logits: e}, a = {axis: t};
return z.runKernelFunc(r, i, null, il, a);
}
var kg = U({logSoftmax_: B5});
function z5(n, t, e) {
t === void 0 && (t = null), e === void 0 && (e = false);
var r = R(n, "x", "logSumExp"), i = rt(t, r.shape), a = Kr(r, i, true), s = be(r, a), o = yn(s), c = _e(o, i), l = Yr(c), u = ge(Y(a, l.shape), l);
if (e) {
var h = an(u.shape, i);
return Y(u, h);
}
return u;
}
var qu = U({logSumExp_: z5});
function P5(n, t) {
var e = R(n, "a", "logicalAnd", "bool"), r = R(t, "b", "logicalAnd", "bool");
it(e.shape, r.shape);
var i = {a: e, b: r};
return z.runKernelFunc(function(a) {
return a.logicalAnd(e, r);
}, i, null, Wf);
}
var jr = U({logicalAnd_: P5});
function M5(n) {
var t = R(n, "x", "logicalNot", "bool"), e = {x: t};
return z.runKernelFunc(function(r) {
return r.logicalNot(t);
}, e, null, Uf);
}
var Ys = U({logicalNot_: M5});
function H5(n, t) {
var e = R(n, "a", "logicalOr", "bool"), r = R(t, "b", "logicalOr", "bool");
it(e.shape, r.shape);
var i = {a: e, b: r};
return z.runKernelFunc(function(a) {
return a.logicalOr(e, r);
}, i, null, Bf);
}
var Yu = U({logicalOr_: H5});
function V5(n, t) {
var e = R(n, "a", "logicalXor", "bool"), r = R(t, "b", "logicalXor", "bool");
return it(e.shape, r.shape), jr(Yu(n, t), Ys(jr(n, t)));
}
var Fg = U({logicalXor_: V5});
function G5(n, t, e, r, i) {
var a = R(n, "x", "maxPool"), s = 1, o = a, c = false;
a.rank === 3 && (c = true, o = Y(a, [1, a.shape[0], a.shape[1], a.shape[2]])), E(o.rank === 4, function() {
return "Error in maxPool: input must be rank 4 but got rank " + o.rank + ".";
}), E(Mt(e, s), function() {
return "Error in maxPool: Either strides or dilations must be 1. " + ("Got strides " + e + " and dilations '" + s + "'");
}), i != null && E(ot(r), function() {
return "Error in maxPool: pad must be an integer when using, " + ("dimRoundingMode " + i + " but got pad " + r + ".");
});
var l = function(p, f) {
var m = Oi(o.shape, t, e, 1, r, i), g;
return m.filterWidth === 1 && m.filterHeight === 1 && pn(m.inShape, m.outShape) ? g = o.clone() : g = p.maxPool(o, m), f([o, g]), g;
}, u = {x: o}, h = {filterSize: t, strides: e, pad: r, dimRoundingMode: i}, d = z.runKernelFunc(l, u, null, cl, h);
return c ? Y(d, [d.shape[1], d.shape[2], d.shape[3]]) : d;
}
var Ku = U({maxPool_: G5});
function q5(n, t, e, r, i, a, s) {
t === void 0 && (t = [1, 1, 1]), a === void 0 && (a = "NDHWC"), s == null ? s = [1, 1, 1] : Nt("dilations is deprecated, this field will be gone in v3.0.0.");
var o = R(n, "x", "maxPool3d"), c = o, l = false;
o.rank === 4 && (l = true, c = Y(o, [1, o.shape[0], o.shape[1], o.shape[2], o.shape[3]])), E(c.rank === 5, function() {
return "Error in maxPool3d: x must be rank 5 but got rank " + c.rank + ".";
}), E(a === "NDHWC", function() {
return "Error in maxPool3d: Only NDHWC is currently supported, " + ("but got dataFormat of " + a);
}), E(Mt(e, s), function() {
return "Error in maxPool3d: Either strides or dilations must be 1. " + ("Got strides " + e + " and dilations '" + s + "'");
}), i != null && E(ot(r), function() {
return "Error in maxPool3d: pad must be an integer when using, " + ("dimRoundingMode " + i + " but got pad " + r + ".");
});
var u = function(f, m) {
s == null && (s = [1, 1, 1]);
var g = Na(c.shape, t, e, s, r, i, a), y = f.maxPool3d(c, g);
return m([c, y]), y;
}, h = {x: c}, d = {filterSize: t, strides: e, pad: r, dimRoundingMode: i, dataFormat: a, dilations: s}, p = z.runKernelFunc(u, h, null, ll, d);
return l ? Y(p, [p.shape[1], p.shape[2], p.shape[3], p.shape[4]]) : p;
}
var Y5 = U({maxPool3d_: q5});
function K5(n, t, e, r, i) {
i === void 0 && (i = false);
var a = R(n, "x", "maxPoolWithArgmax"), s = {x: a}, o = {filterSize: t, strides: e, pad: r, includeBatchInIndex: i}, c = z.runKernel(Hf, s, o);
return {result: c[0], indexes: c[1]};
}
var j5 = U({maxPoolWithArgmax_: K5});
function $n(n, t) {
if (t === void 0 && (t = "float32"), t === "complex64") {
var e = $n(n, "float32"), r = $n(n, "float32");
return hr(e, r);
}
var i = Si(dt(n), t);
return z.makeTensor(i, n, t);
}
function Wi(n, t) {
if (t === void 0 && (t = "float32"), t === "complex64") {
var e = Wi(n, "float32"), r = $n(n, "float32");
return hr(e, r);
}
var i = hc(dt(n), t);
return z.makeTensor(i, n, t);
}
function $5(n, t, e) {
t === void 0 && (t = null), e === void 0 && (e = false);
var r = R(n, "x", "mean"), i = rt(t, r.shape), a = ng(r.shape, i), s = a[1], o = dt(s), c = {x: r}, l = {axis: t, keepDims: e}, u = function() {
var d = Le(o), p = d.dtype === r.dtype ? r : he(r, d.dtype), f = Ne(p, d);
return _e(f, t, e);
}, h = En(function(d) {
var p = z.runKernelFunc(u, c, null, Vf, l), f = function(m) {
var g = d.shape.slice();
i.forEach(function(b) {
g[b] = 1;
});
var y = Y(m, g), w = Ne(Z(y, Wi(d.shape, "float32")), o);
return w;
};
return {value: p, gradFunc: f};
});
return h(r);
}
var Oa = U({mean_: $5});
function X5(n, t, e) {
t === void 0 && (t = null), e === void 0 && (e = false);
var r = R(n, "x", "min"), i = function(o, c) {
var l = rt(t, r.shape), u = l, h = fn(u, r.rank), d = r;
h != null && (d = Tt(r, h), u = On(u.length, r.rank));
var p = o.min(d, u);
h != null && d.dispose();
var f = p;
if (e) {
var m = an(f.shape, l);
f = Y(p, m), p.dispose();
}
return c([r, f]), f;
}, a = {x: r}, s = {axis: t, keepDims: e};
return z.runKernelFunc(i, a, null, ul, s);
}
var Ks = U({min_: X5});
function J5(n, t) {
var e, r = R(n, "a", "minimum"), i = R(t, "b", "minimum");
e = ct(r, i), r = e[0], i = e[1], r.dtype === "bool" && (r = he(r, "int32"), i = he(i, "int32")), it(r.shape, i.shape);
var a = function(o, c) {
var l = o.minimum(r, i);
return c([r, i]), l;
}, s = {a: r, b: i};
return z.runKernelFunc(a, s, null, hl);
}
var js = U({minimum_: J5});
function Z5(n, t, e) {
E(e === "reflect" || e === "symmetric", function() {
return "Invalid mode. Mode must be either reflect or symmetric. " + ("Got " + e + ".");
});
var r = R(n, "x", "mirrorPad");
if (r.rank === 0)
throw new Error("mirrorPad(scalar) is not defined. Pass non-scalar to mirrorPad");
E(t.length === r.rank, function() {
return "Padding doesn't match input. Must be " + r.rank + ". " + ("Got " + t.length + ".");
});
for (var i = e === "reflect" ? 1 : 0, a = function(l) {
E(t[l].length === 2, function() {
return "Invalid number of paddings. Must be length of 2 each.";
}), E(t[l][0] >= 0 && t[l][0] <= r.shape[l] - i && t[l][1] >= 0 && t[l][1] <= r.shape[l] - i, function() {
return "Padding in dimension " + l + " cannot be greater than or equal " + ("to " + (r.shape[l] - i) + " or less than 0 for input of ") + ("shape " + r.shape);
});
}, s = 0; s < r.rank; s++)
a(s);
var o = {paddings: t, mode: e}, c = {x: r};
return z.runKernel(dl, c, o);
}
var Wg = U({mirrorPad_: Z5});
function Q5(n, t) {
var e, r = R(n, "a", "mod"), i = R(t, "b", "mod");
e = ct(r, i), r = e[0], i = e[1];
var a = function(o, c) {
var l = o.mod(r, i);
return c([r, i]), l;
}, s = {a: r, b: i};
return z.runKernelFunc(a, s, null, pl);
}
var ju = U({mod_: Q5});
function eT(n) {
var t = R(n, "x", "square"), e = {}, r = [t], i = [];
return z.runKernelFunc(function(a, s) {
return s([t]), a.square(t);
}, {x: t}, null, "Square", e, r, i);
}
var $e = U({square_: eT});
function tT(n, t, e) {
t === void 0 && (t = null), e === void 0 && (e = false), n = R(n, "x", "moments");
var r = rt(t, n.shape), i = Oa(n, r, e), a = i.shape;
e || (a = an(i.shape, r));
var s = $e(be(he(n, "float32"), Y(i, a))), o = Oa(s, r, e);
return {mean: i, variance: o};
}
var nT = U({moments_: tT});
function rT(n, t, e, r) {
for (var i = R(t, "data", "multiRNNCell"), a = Sa(e, "c", "multiRNNCell"), s = Sa(r, "h", "multiRNNCell"), o = i, c = [], l = 0; l < n.length; l++) {
var u = n[l](o, a[l], s[l]);
c.push(u[0]), c.push(u[1]), o = u[1];
}
for (var h = [], d = [], l = 0; l < c.length; l += 2)
h.push(c[l]), d.push(c[l + 1]);
return [h, d];
}
var iT = U({multiRNNCell_: rT});
function aT(n, t, e, r) {
r === void 0 && (r = false);
var i = R(n, "logits", "multinomial"), a = i.size, s = i.rank;
if (a < 2)
throw new Error("Error in multinomial: you need at least 2 outcomes, but got " + (a + "."));
if (s > 2)
throw new Error("Rank of probabilities must be 1 or 2, but is " + s);
e = e || Math.random();
var o = s === 1 ? Y(i, [1, -1]) : i, c = z.runKernelFunc(function(l) {
return l.multinomial(o, r, t, e);
}, {logits2D: o});
return s === 1 ? Y(c, [c.size]) : c;
}
var sT = U({multinomial_: aT});
function oT(n, t) {
var e, r = R(n, "a", "notEqual"), i = R(t, "b", "notEqual");
e = ct(r, i), r = e[0], i = e[1], it(r.shape, i.shape);
var a = function(o) {
return o.notEqual(r, i);
}, s = {a: r, b: i};
return z.runKernelFunc(a, s, null, Gf);
}
var $s = U({notEqual_: oT});
function cT(n) {
var t = R(n, "input", "real"), e = function(i) {
return i.real(t);
}, r = {input: t};
return z.runKernelFunc(e, r, null, Xf);
}
var Ea = U({real_: cT});
function lT(n) {
var t = R(n, "x", "onesLike"), e = function(i, a) {
if (t.dtype === "complex64") {
var s = $u(Ea(t)), o = ke(Vs(t));
return hr(s, o);
}
return i.onesLike(t);
}, r = {x: t};
return z.runKernelFunc(e, r, null, gl);
}
var $u = U({onesLike_: lT});
function uT(n, t) {
var e = R(n, "v1", "outerProduct"), r = R(t, "v2", "outerProduct");
E(e.rank === 1 && r.rank === 1, function() {
return "Error in outerProduct: inputs must be rank 1, but got ranks " + (e.rank + " and " + r.rank + ".");
});
var i = Y(e, [-1, 1]), a = Y(r, [1, -1]);
return Ue(i, a);
}
var hT = U({outerProduct_: uT});
function dT(n, t, e) {
e === void 0 && (e = 0);
var r = R(n, "x", "pad");
if (r.rank === 0)
throw new Error("pad(scalar) is not defined. Pass non-scalar to pad");
var i = function(o, c) {
return c([r]), o.pad(r, t, e);
}, a = {paddings: t, constantValue: e}, s = {x: r};
return z.runKernelFunc(i, s, null, vl, a);
}
var $r = U({pad_: dT});
function pT(n, t, e) {
return e === void 0 && (e = 0), E(t.length === 2, function() {
return "Invalid number of paddings. Must be length of 2.";
}), $r(n, [t], e);
}
var fT = U({pad1d_: pT});
function mT(n, t, e) {
return e === void 0 && (e = 0), E(t.length === 2 && t[0].length === 2 && t[1].length === 2, function() {
return "Invalid number of paddings. Must be length of 2 each.";
}), $r(n, t, e);
}
var gT = U({pad2d_: mT});
function yT(n, t, e) {
return e === void 0 && (e = 0), E(t.length === 3 && t[0].length === 2 && t[1].length === 2 && t[2].length === 2, function() {
return "Invalid number of paddings. Must be length of 2 each.";
}), $r(n, t, e);
}
var vT = U({pad3d_: yT});
function wT(n, t, e) {
return e === void 0 && (e = 0), E(t.length === 4 && t[0].length === 2 && t[1].length === 2 && t[2].length === 2 && t[3].length === 2, function() {
return "Invalid number of paddings. Must be length of 2 each.";
}), $r(n, t, e);
}
var bT = U({pad4d_: wT});
function xT(n, t, e) {
var r = R(n, "x", "spaceToBatchND");
E(r.rank >= 1 + t.length, function() {
return "input rank " + r.rank + " should be > than [blockShape] " + t.length;
}), E(e.length === t.length, function() {
return "paddings.shape[0] " + e.length + " must be equal to [blockShape] " + t.length;
}), E(r.shape.reduce(function(o, c, l) {
return l > 0 && l <= t.length ? o && (c + e[l - 1][0] + e[l - 1][1]) % t[l - 1] === 0 : o;
}, true), function() {
return "input spatial dimensions " + r.shape.slice(1) + " with paddings " + e.toString() + " must be divisible by blockShapes " + t.toString();
});
var i = function(o) {
return o.spaceToBatchND(r, t, e);
}, a = {x: r}, s = {blockShape: t, paddings: e};
return z.runKernelFunc(i, a, null, Pl, s);
}
var Xs = U({spaceToBatchND_: xT});
function IT(n, t, e, r, i, a) {
i == null && (i = [1, 1]), a == null && (a = 1), r === 0 && (r = "valid");
var s = R(n, "x", "maxPool"), o = s, c = false;
s.rank === 3 && (c = true, o = Y(s, [1, s.shape[0], s.shape[1], s.shape[2]])), E(Mt(a, i), function() {
return "Error in pool: Either strides or dilations must be 1. " + ("Got strides " + a + " and dilations '" + i + "'");
});
var l = Oi(o.shape, t, a, i, r), u = [l.dilationHeight, l.dilationWidth], h;
r === "same" ? h = ST([l.filterHeight, l.filterWidth], u) : h = [[0, 0], [0, 0]];
var d = u[0] === 1 && u[1] === 1, p = LT([l.inHeight, l.inWidth], u, h), f = p[0], m = p[1], g = d ? r : "valid", y = d ? o : Xs(o, u, f), w = e === "avg" ? function() {
return Wu(y, t, a, g);
} : function() {
return Ku(y, t, a, g);
}, b = w(), x = d ? b : Us(b, u, m);
return c ? Y(x, [x.shape[1], x.shape[2], x.shape[3]]) : x;
}
function LT(n, t, e) {
var r = e.map(function(u) {
return u[0];
}), i = e.map(function(u) {
return u[1];
}), a = n.concat(r, i), s = t.map(function(u, h) {
return (u - a[h] % u) % u;
}), o = i.map(function(u, h) {
return u + s[h];
}), c = t.map(function(u, h) {
return [r[h], o[h]];
}), l = t.map(function(u, h) {
return [0, s[h]];
});
return [c, l];
}
function ST(n, t) {
var e = n.map(function(s, o) {
return s + (s - 1) * (t[o] - 1);
}), r = e.map(function(s) {
return s - 1;
}), i = r.map(function(s) {
return Math.floor(s / 2);
}), a = r.map(function(s, o) {
return s - i[o];
});
return r.map(function(s, o) {
return [i[o], a[o]];
});
}
var Ug = U({pool_: IT});
function AT(n, t) {
var e, r = R(n, "base", "pow"), i = R(t, "exp", "pow");
e = ct(r, i), r = e[0], i = e[1];
var a = {a: r, b: i}, s = function(o, c) {
var l = o.pow(r, i);
return c([r, i, l]), l;
};
return z.runKernelFunc(s, a, null, wl);
}
var Xn = U({pow_: AT});
function TT(n, t) {
var e = R(n, "x", "prelu"), r = R(t, "alpha", "prelu"), i = function(s, o) {
var c = s.prelu(e, r);
return o([e, r]), c;
}, a = {x: e, alpha: r};
return z.runKernelFunc(i, a, null, bl);
}
var Xu = U({prelu_: TT});
function NT(n, t, e) {
t === void 0 && (t = null), e === void 0 && (e = false);
var r = R(n, "x", "prod");
r.dtype === "bool" && (r = he(r, "int32"));
var i = function(o) {
var c = rt(t, r.shape), l = fn(c, r.rank), u = c, h = r;
l != null && (h = Tt(r, l), u = On(u.length, r.rank));
var d = o.prod(h, u);
if (e) {
var p = an(d.shape, c);
d = Y(d, p);
}
return d;
}, a = {x: r}, s = {axis: t, keepDims: e};
return z.runKernelFunc(i, a, null, jf, s);
}
var Bg = U({prod_: NT});
function _T(n, t, e) {
var r = dt(n), i = null;
if (e == null || e === "float32")
i = new Float32Array(r);
else if (e === "int32")
i = new Int32Array(r);
else if (e === "bool")
i = new Uint8Array(r);
else
throw new Error("Unknown data type " + e);
for (var a = 0; a < r; a++)
i[a] = t();
return z.makeTensor(i, n, e);
}
var CT = U({rand_: _T}), Ui = typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : {};
function Xr(n, t) {
return t = {exports: {}}, n(t, t.exports), t.exports;
}
var RT = Xr(function(n) {
(function(t, e, r) {
function i(c) {
var l = this, u = o();
l.next = function() {
var h = 2091639 * l.s0 + l.c * 23283064365386963e-26;
return l.s0 = l.s1, l.s1 = l.s2, l.s2 = h - (l.c = h | 0);
}, l.c = 1, l.s0 = u(" "), l.s1 = u(" "), l.s2 = u(" "), l.s0 -= u(c), l.s0 < 0 && (l.s0 += 1), l.s1 -= u(c), l.s1 < 0 && (l.s1 += 1), l.s2 -= u(c), l.s2 < 0 && (l.s2 += 1), u = null;
}
function a(c, l) {
return l.c = c.c, l.s0 = c.s0, l.s1 = c.s1, l.s2 = c.s2, l;
}
function s(c, l) {
var u = new i(c), h = l && l.state, d = u.next;
return d.int32 = function() {
return u.next() * 4294967296 | 0;
}, d.double = function() {
return d() + (d() * 2097152 | 0) * 11102230246251565e-32;
}, d.quick = d, h && (typeof h == "object" && a(h, u), d.state = function() {
return a(u, {});
}), d;
}
function o() {
var c = 4022871197, l = function(u) {
u = u.toString();
for (var h = 0; h < u.length; h++) {
c += u.charCodeAt(h);
var d = 0.02519603282416938 * c;
c = d >>> 0, d -= c, d *= c, c = d >>> 0, d -= c, c += d * 4294967296;
}
return (c >>> 0) * 23283064365386963e-26;
};
return l;
}
e && e.exports ? e.exports = s : r && r.amd ? r(function() {
return s;
}) : this.alea = s;
})(Ui, n, false);
}), OT = Xr(function(n) {
(function(t, e, r) {
function i(o) {
var c = this, l = "";
c.x = 0, c.y = 0, c.z = 0, c.w = 0, c.next = function() {
var h = c.x ^ c.x << 11;
return c.x = c.y, c.y = c.z, c.z = c.w, c.w ^= c.w >>> 19 ^ h ^ h >>> 8;
}, o === (o | 0) ? c.x = o : l += o;
for (var u = 0; u < l.length + 64; u++)
c.x ^= l.charCodeAt(u) | 0, c.next();
}
function a(o, c) {
return c.x = o.x, c.y = o.y, c.z = o.z, c.w = o.w, c;
}
function s(o, c) {
var l = new i(o), u = c && c.state, h = function() {
return (l.next() >>> 0) / 4294967296;
};
return h.double = function() {
do
var d = l.next() >>> 11, p = (l.next() >>> 0) / 4294967296, f = (d + p) / (1 << 21);
while (f === 0);
return f;
}, h.int32 = l.next, h.quick = h, u && (typeof u == "object" && a(u, l), h.state = function() {
return a(l, {});
}), h;
}
e && e.exports ? e.exports = s : r && r.amd ? r(function() {
return s;
}) : this.xor128 = s;
})(Ui, n, false);
}), ET = Xr(function(n) {
(function(t, e, r) {
function i(o) {
var c = this, l = "";
c.next = function() {
var h = c.x ^ c.x >>> 2;
return c.x = c.y, c.y = c.z, c.z = c.w, c.w = c.v, (c.d = c.d + 362437 | 0) + (c.v = c.v ^ c.v << 4 ^ (h ^ h << 1)) | 0;
}, c.x = 0, c.y = 0, c.z = 0, c.w = 0, c.v = 0, o === (o | 0) ? c.x = o : l += o;
for (var u = 0; u < l.length + 64; u++)
c.x ^= l.charCodeAt(u) | 0, u == l.length && (c.d = c.x << 10 ^ c.x >>> 4), c.next();
}
function a(o, c) {
return c.x = o.x, c.y = o.y, c.z = o.z, c.w = o.w, c.v = o.v, c.d = o.d, c;
}
function s(o, c) {
var l = new i(o), u = c && c.state, h = function() {
return (l.next() >>> 0) / 4294967296;
};
return h.double = function() {
do
var d = l.next() >>> 11, p = (l.next() >>> 0) / 4294967296, f = (d + p) / (1 << 21);
while (f === 0);
return f;
}, h.int32 = l.next, h.quick = h, u && (typeof u == "object" && a(u, l), h.state = function() {
return a(l, {});
}), h;
}
e && e.exports ? e.exports = s : r && r.amd ? r(function() {
return s;
}) : this.xorwow = s;
})(Ui, n, false);
}), DT = Xr(function(n) {
(function(t, e, r) {
function i(o) {
var c = this;
c.next = function() {
var u = c.x, h = c.i, d, p;
return d = u[h], d ^= d >>> 7, p = d ^ d << 24, d = u[h + 1 & 7], p ^= d ^ d >>> 10, d = u[h + 3 & 7], p ^= d ^ d >>> 3, d = u[h + 4 & 7], p ^= d ^ d << 7, d = u[h + 7 & 7], d = d ^ d << 13, p ^= d ^ d << 9, u[h] = p, c.i = h + 1 & 7, p;
};
function l(u, h) {
var d, p, f = [];
if (h === (h | 0))
p = f[0] = h;
else
for (h = "" + h, d = 0; d < h.length; ++d)
f[d & 7] = f[d & 7] << 15 ^ h.charCodeAt(d) + f[d + 1 & 7] << 13;
for (; f.length < 8; )
f.push(0);
for (d = 0; d < 8 && f[d] === 0; ++d)
;
for (d == 8 ? p = f[7] = -1 : p = f[d], u.x = f, u.i = 0, d = 256; d > 0; --d)
u.next();
}
l(c, o);
}
function a(o, c) {
return c.x = o.x.slice(), c.i = o.i, c;
}
function s(o, c) {
o == null && (o = +new Date());
var l = new i(o), u = c && c.state, h = function() {
return (l.next() >>> 0) / 4294967296;
};
return h.double = function() {
do
var d = l.next() >>> 11, p = (l.next() >>> 0) / 4294967296, f = (d + p) / (1 << 21);
while (f === 0);
return f;
}, h.int32 = l.next, h.quick = h, u && (u.x && a(u, l), h.state = function() {
return a(l, {});
}), h;
}
e && e.exports ? e.exports = s : r && r.amd ? r(function() {
return s;
}) : this.xorshift7 = s;
})(Ui, n, false);
}), kT = Xr(function(n) {
(function(t, e, r) {
function i(o) {
var c = this;
c.next = function() {
var u = c.w, h = c.X, d = c.i, p, f;
return c.w = u = u + 1640531527 | 0, f = h[d + 34 & 127], p = h[d = d + 1 & 127], f ^= f << 13, p ^= p << 17, f ^= f >>> 15, p ^= p >>> 12, f = h[d] = f ^ p, c.i = d, f + (u ^ u >>> 16) | 0;
};
function l(u, h) {
var d, p, f, m, g, y = [], w = 128;
for (h === (h | 0) ? (p = h, h = null) : (h = h + "\0", p = 0, w = Math.max(w, h.length)), f = 0, m = -32; m < w; ++m)
h && (p ^= h.charCodeAt((m + 32) % h.length)), m === 0 && (g = p), p ^= p << 10, p ^= p >>> 15, p ^= p << 4, p ^= p >>> 13, m >= 0 && (g = g + 1640531527 | 0, d = y[m & 127] ^= p + g, f = d == 0 ? f + 1 : 0);
for (f >= 128 && (y[(h && h.length || 0) & 127] = -1), f = 127, m = 4 * 128; m > 0; --m)
p = y[f + 34 & 127], d = y[f = f + 1 & 127], p ^= p << 13, d ^= d << 17, p ^= p >>> 15, d ^= d >>> 12, y[f] = p ^ d;
u.w = g, u.X = y, u.i = f;
}
l(c, o);
}
function a(o, c) {
return c.i = o.i, c.w = o.w, c.X = o.X.slice(), c;
}
function s(o, c) {
o == null && (o = +new Date());
var l = new i(o), u = c && c.state, h = function() {
return (l.next() >>> 0) / 4294967296;
};
return h.double = function() {
do
var d = l.next() >>> 11, p = (l.next() >>> 0) / 4294967296, f = (d + p) / (1 << 21);
while (f === 0);
return f;
}, h.int32 = l.next, h.quick = h, u && (u.X && a(u, l), h.state = function() {
return a(l, {});
}), h;
}
e && e.exports ? e.exports = s : r && r.amd ? r(function() {
return s;
}) : this.xor4096 = s;
})(Ui, n, false);
}), FT = Xr(function(n) {
(function(t, e, r) {
function i(o) {
var c = this, l = "";
c.next = function() {
var h = c.b, d = c.c, p = c.d, f = c.a;
return h = h << 25 ^ h >>> 7 ^ d, d = d - p | 0, p = p << 24 ^ p >>> 8 ^ f, f = f - h | 0, c.b = h = h << 20 ^ h >>> 12 ^ d, c.c = d = d - p | 0, c.d = p << 16 ^ d >>> 16 ^ f, c.a = f - h | 0;
}, c.a = 0, c.b = 0, c.c = 2654435769 | 0, c.d = 1367130551, o === Math.floor(o) ? (c.a = o / 4294967296 | 0, c.b = o | 0) : l += o;
for (var u = 0; u < l.length + 20; u++)
c.b ^= l.charCodeAt(u) | 0, c.next();
}
function a(o, c) {
return c.a = o.a, c.b = o.b, c.c = o.c, c.d = o.d, c;
}
function s(o, c) {
var l = new i(o), u = c && c.state, h = function() {
return (l.next() >>> 0) / 4294967296;
};
return h.double = function() {
do
var d = l.next() >>> 11, p = (l.next() >>> 0) / 4294967296, f = (d + p) / (1 << 21);
while (f === 0);
return f;
}, h.int32 = l.next, h.quick = h, u && (typeof u == "object" && a(u, l), h.state = function() {
return a(l, {});
}), h;
}
e && e.exports ? e.exports = s : r && r.amd ? r(function() {
return s;
}) : this.tychei = s;
})(Ui, n, false);
}), Jr = Xr(function(n) {
(function(t, e) {
var r = this, i = 256, a = 6, s = 52, o = "random", c = e.pow(i, a), l = e.pow(2, s), u = l * 2, h = i - 1, d;
function p(x, L, N) {
var I = [];
L = L == true ? {entropy: true} : L || {};
var C = y(g(L.entropy ? [x, b(t)] : x != null ? x : w(), 3), I), O = new f(I), D = function() {
for (var F = O.g(a), k = c, B = 0; F < l; )
F = (F + B) * i, k *= i, B = O.g(1);
for (; F >= u; )
F /= 2, k /= 2, B >>>= 1;
return (F + B) / k;
};
return D.int32 = function() {
return O.g(4) | 0;
}, D.quick = function() {
return O.g(4) / 4294967296;
}, D.double = D, y(b(O.S), t), (L.pass || N || function(F, k, B, V) {
return V && (V.S && m(V, O), F.state = function() {
return m(O, {});
}), B ? (e[o] = F, k) : F;
})(D, C, "global" in L ? L.global : this == e, L.state);
}
e["seed" + o] = p;
function f(x) {
var L, N = x.length, I = this, C = 0, O = I.i = I.j = 0, D = I.S = [];
for (N || (x = [N++]); C < i; )
D[C] = C++;
for (C = 0; C < i; C++)
D[C] = D[O = h & O + x[C % N] + (L = D[C])], D[O] = L;
(I.g = function(F) {
for (var k, B = 0, V = I.i, P = I.j, G = I.S; F--; )
k = G[V = h & V + 1], B = B * i + G[h & (G[V] = G[P = h & P + k]) + (G[P] = k)];
return I.i = V, I.j = P, B;
})(i);
}
function m(x, L) {
return L.i = x.i, L.j = x.j, L.S = x.S.slice(), L;
}
function g(x, L) {
var N = [], I = typeof x, C;
if (L && I == "object")
for (C in x)
try {
N.push(g(x[C], L - 1));
} catch (O) {
}
return N.length ? N : I == "string" ? x : x + "\0";
}
function y(x, L) {
for (var N = x + "", I, C = 0; C < N.length; )
L[h & C] = h & (I ^= L[h & C] * 19) + N.charCodeAt(C++);
return b(L);
}
function w() {
try {
var x;
return d && (x = d.randomBytes) ? x = x(i) : (x = new Uint8Array(i), (r.crypto || r.msCrypto).getRandomValues(x)), b(x);
} catch (I) {
var L = r.navigator, N = L && L.plugins;
return [+new Date(), r, N, r.screen, b(t)];
}
}
function b(x) {
return String.fromCharCode.apply(0, x);
}
if (y(e.random(), t), n.exports) {
n.exports = p;
try {
d = ws();
} catch (x) {
}
}
})([], Math);
});
Jr.alea = RT;
Jr.xor128 = OT;
Jr.xorwow = ET;
Jr.xorshift7 = DT;
Jr.xor4096 = kT;
Jr.tychei = FT;
var WT = Jr, Ju = WT.alea;
var Zu = function() {
function n(t, e, r, i, a) {
this.mean = t, this.stdDev = e, this.dtype = r, this.nextVal = NaN, this.truncated = i, this.truncated && (this.upper = this.mean + this.stdDev * 2, this.lower = this.mean - this.stdDev * 2);
var s = a || Math.random();
this.random = Ju(s.toString());
}
return n.prototype.nextValue = function() {
if (!isNaN(this.nextVal)) {
var t = this.nextVal;
return this.nextVal = NaN, t;
}
for (var e, r, i = false; !i; ) {
var a = void 0, s = void 0, o = void 0;
do
a = 2 * this.random() - 1, s = 2 * this.random() - 1, o = a * a + s * s;
while (o >= 1 || o === 0);
var c = Math.sqrt(-2 * Math.log(o) / o);
e = this.mean + this.stdDev * a * c, r = this.mean + this.stdDev * s * c, (!this.truncated || this.isValidTruncated(e)) && (i = true);
}
return (!this.truncated || this.isValidTruncated(r)) && (this.nextVal = this.convertValue(r)), this.convertValue(e);
}, n.prototype.convertValue = function(t) {
return this.dtype == null || this.dtype === "float32" ? t : Math.round(t);
}, n.prototype.isValidTruncated = function(t) {
return t <= this.upper && t >= this.lower;
}, n;
}(), UT = function() {
function n(t, e, r, i) {
this.alpha = t, this.beta = 1 / e, this.dtype = r;
var a = i || Math.random();
this.randu = Ju(a.toString()), this.randn = new Zu(0, 1, r, false, this.randu()), t < 1 ? this.d = t + 2 / 3 : this.d = t - 1 / 3, this.c = 1 / Math.sqrt(9 * this.d);
}
return n.prototype.nextValue = function() {
for (var t, e, r, i, a, s; ; ) {
do
i = this.randn.nextValue(), s = 1 + this.c * i;
while (s <= 0);
if (s *= s * s, t = i * i, e = 1 - 0.331 * t * t, r = 0.5 * t + this.d * (1 - s + Math.log(s)), a = this.randu(), a < e || Math.log(a) < r)
break;
}
return s = 1 / this.beta * this.d * s, this.alpha < 1 && (s *= Math.pow(this.randu(), 1 / this.alpha)), this.convertValue(s);
}, n.prototype.convertValue = function(t) {
return this.dtype === "float32" ? t : Math.round(t);
}, n;
}(), BT = function() {
function n(t, e, r, i) {
var a = this;
if (t === void 0 && (t = 0), e === void 0 && (e = 1), this.canReturnFloat = function() {
return a.dtype == null || a.dtype === "float32";
}, this.min = t, this.range = e - t, this.dtype = r, i == null && (i = Math.random()), typeof i == "number" && (i = i.toString()), !this.canReturnFloat() && this.range <= 1)
throw new Error("The difference between " + t + " - " + e + " <= 1 and dtype is not float");
this.random = Ju(i);
}
return n.prototype.convertValue = function(t) {
return this.canReturnFloat() ? t : Math.round(t);
}, n.prototype.nextValue = function() {
return this.convertValue(this.min + this.range * this.random());
}, n;
}();
function zT(n, t, e, r, i) {
if (e === void 0 && (e = 1), r === void 0 && (r = "float32"), e == null && (e = 1), r == null && (r = "float32"), r !== "float32" && r !== "int32")
throw new Error("Unsupported data type " + r);
for (var a = new UT(t, e, r, i), s = Rn(n, r), o = 0; o < s.values.length; o++)
s.values[o] = a.nextValue();
return s.toTensor();
}
var PT = U({randomGamma_: zT});
function MT(n, t, e, r, i) {
if (t === void 0 && (t = 0), e === void 0 && (e = 1), r != null && r === "bool")
throw new Error("Unsupported data type " + r);
for (var a = new Zu(t, e, r, false, i), s = Rn(n, r), o = 0; o < s.values.length; o++)
s.values[o] = a.nextValue();
return s.toTensor();
}
var HT = U({randomNormal_: MT});
function VT(n, t, e, r, i) {
t === void 0 && (t = 0), e === void 0 && (e = 1), r === void 0 && (r = "float32");
for (var a = Rn(n, r), s = new BT(t, e, null, i), o = 0; o < a.values.length; o++)
a.values[o] = s.nextValue();
return a.toTensor();
}
var zg = U({randomUniform_: VT});
function Bi(n, t) {
Br(n);
var e = Cn(n, t);
if (e.length !== 1)
throw new Error("tensor1d() requires values to be a flat/TypedArray");
var r = null;
return dr(n, r, e, t);
}
function Qu(n, t, e, r) {
if (e === void 0 && (e = 1), r === void 0 && (r = "float32"), e === 0)
throw new Error("Cannot have a step of zero");
var i = function() {
var s = n === t, o = n < t && e < 0, c = t < n && e > 1;
if (s || o || c)
return $n([0], r);
var l = Math.abs(Math.ceil((t - n) / e)), u = Si(l, r);
t < n && e === 1 && (e = -1), u[0] = n;
for (var h = 1; h < u.length; h++)
u[h] = u[h - 1] + e;
return Bi(u, r);
}, a = {start: n, stop: t, step: e, dtype: r};
return z.runKernelFunc(i, {}, null, $f, a);
}
function GT(n) {
var t = R(n, "x", "reciprocal"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.reciprocal(t);
return i([t]), a;
}, e, null, xl);
}
var Pg = U({reciprocal_: GT});
function qT(n) {
var t = R(n, "x", "relu"), e = function(i, a) {
return a([t]), t.dtype === "bool" ? he(t, "int32") : i.relu(t);
}, r = {x: t};
return z.runKernelFunc(e, r, null, Ll);
}
var Da = U({relu_: qT});
function YT(n) {
var t = R(n, "x", "relu6"), e = function(i, a) {
return a([t]), t.dtype === "bool" ? he(t, "int32") : i.relu6(t);
}, r = {x: t};
return z.runKernelFunc(e, r, null, Tl);
}
var eh = U({relu6_: YT});
function KT(n, t) {
var e = R(n, "x", "reverse"), r = function(s) {
var o = rt(t, e.shape);
if (e.rank === 0)
return Mr(e);
var c = s.reverse(e, o);
return Y(c, e.shape);
}, i = {x: e}, a = {dims: t};
return z.runKernelFunc(r, i, null, Nl, a);
}
var Jn = U({reverse_: KT});
function jT(n) {
var t = R(n, "x", "reverse");
return E(t.rank === 1, function() {
return "Error in reverse1D: x must be rank 1 but got rank " + t.rank + ".";
}), Jn(t, 0);
}
var $T = U({reverse1d_: jT});
function XT(n, t) {
var e = R(n, "x", "reverse");
return E(e.rank === 2, function() {
return "Error in reverse2D: x must be rank 2 but got rank " + e.rank + ".";
}), Jn(e, t);
}
var JT = U({reverse2d_: XT});
function ZT(n, t) {
var e = R(n, "x", "reverse");
return E(e.rank === 3, function() {
return "Error in reverse3D: x must be rank 3 but got rank " + e.rank + ".";
}), Jn(e, t);
}
var QT = U({reverse3d_: ZT});
function eN(n, t) {
var e = R(n, "x", "reverse");
return E(e.rank === 4, function() {
return "Error in reverse4D: x must be rank 4 but got rank " + e.rank + ".";
}), Jn(e, t);
}
var tN = U({reverse4d_: eN});
function nN(n) {
var t = R(n, "x", "round"), e = {x: t};
return z.runKernelFunc(function(r) {
return r.round(t);
}, e, null, _l);
}
var Mg = U({round_: nN});
function rN(n) {
var t = R(n, "x", "rsqrt"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.rsqrt(t);
return i([t]), a;
}, e, null, Cl);
}
var th = U({rsqrt_: rN});
function iN(n) {
var t = R(n, "x", "selu"), e = function(i, a) {
var s = i.selu(t);
return a([t]), s;
}, r = {x: t};
return z.runKernelFunc(e, r, null, Ol);
}
var Hg = U({selu_: iN});
function aN(n, t, e, r, i, a, s) {
a === void 0 && (a = [1, 1]), s === void 0 && (s = "NHWC");
var o = R(n, "x", "separableConv2d"), c = R(t, "depthwiseFilter", "separableConv2d"), l = R(e, "pointwiseFilter", "separableConv2d"), u = o, h = false;
if (o.rank === 3 && (h = true, u = Y(o, [1, o.shape[0], o.shape[1], o.shape[2]])), s === "NCHW")
throw new Error("separableConv2d currently does not support dataFormat NCHW; only NHWC is supported");
E(u.rank === 4, function() {
return "Error in separableConv2d: input must be rank 4, but got " + ("rank " + u.rank + ".");
}), E(c.rank === 4, function() {
return "Error in separableConv2d: depthwise filter must be rank 4, but " + ("got rank " + c.rank + ".");
}), E(l.rank === 4, function() {
return "Error in separableConv2d: pointwise filter must be rank 4, but " + ("got rank " + c.rank + ".");
}), E(l.shape[0] === 1, function() {
return "Error in separableConv2d: the first dimension of pointwise filter " + (" must be 1, but got " + l.shape[0] + ".");
}), E(l.shape[1] === 1, function() {
return "Error in separableConv2d: the second dimension of pointwise " + ("filter must be 1, but got " + l.shape[1] + ".");
});
var d = c.shape[2], p = c.shape[3];
E(l.shape[2] === d * p, function() {
return "Error in separableConv2d: the third dimension of pointwise filter " + ("must be " + d * p + ", ") + ("but got " + l.shape[2] + ".");
});
var f = Ca(u, c, r, i, s, a), m = 1, g = Di(f, l, m, "valid", s);
return h ? Y(g, [g.shape[1], g.shape[2], g.shape[3]]) : g;
}
var Vg = U({separableConv2d_: aN});
function sN(n, t) {
return pe(this, void 0, void 0, function() {
var e, r, i, a, s, o, c, l, u, c, h;
return fe(this, function(d) {
switch (d.label) {
case 0:
return e = R(n, "x", "setdiff1d"), r = R(t, "y", "setdiff1d"), E(e.dtype === r.dtype, function() {
return "x and y should have the same dtype, but got x (" + e.dtype + ") and y (" + r.dtype + ").";
}), E(e.rank === 1, function() {
return "x should be 1D tensor, but got x (" + e.shape + ").";
}), E(r.rank === 1, function() {
return "y should be 1D tensor, but got y (" + r.shape + ").";
}), [4, e.data()];
case 1:
return i = d.sent(), [4, r.data()];
case 2:
for (a = d.sent(), s = new Set(a), o = 0, c = 0; c < i.length; c++)
s.has(i[c]) || o++;
for (l = new _s([o], e.dtype), u = new _s([o], "int32"), c = 0, h = 0; c < i.length; c++)
s.has(i[c]) || (l.values[h] = i[c], u.values[h] = c, h++);
return [2, [l.toTensor(), u.toTensor()]];
}
});
});
}
var oN = sN;
function cN(n) {
var t = R(n, "x", "sign"), e = {x: t};
return z.runKernelFunc(function(r) {
return r.sign(t);
}, e, null, Fl);
}
var Gg = U({sign_: cN});
function lN(n) {
var t = R(n, "x", "sin"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.sin(t);
return i([t]), a;
}, e, null, Dl);
}
var nh = U({sin_: lN});
function uN(n) {
var t = R(n, "x", "sinh"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.sinh(t);
return i([t]), a;
}, e, null, kl);
}
var rh = U({sinh_: uN});
function hN(n, t, e) {
var r = R(n, "x", "slice1d");
return E(r.rank === 1, function() {
return "slice1d expects a rank-1 tensor, but got a rank-" + r.rank + " tensor";
}), Me(r, [t], [e]);
}
var dN = U({slice1d_: hN});
function pN(n, t, e) {
var r = R(n, "x", "slice2d");
return E(r.rank === 2, function() {
return "slice2d expects a rank-2 tensor, but got a rank-" + r.rank + " tensor";
}), Me(r, t, e);
}
var fN = U({slice2d_: pN});
function mN(n, t, e) {
var r = R(n, "x", "slice3d");
return E(r.rank === 3, function() {
return "slice3d expects a rank-3 tensor, but got a rank-" + r.rank + " tensor";
}), Me(r, t, e);
}
var gN = U({slice3d_: mN});
function yN(n, t, e) {
var r = R(n, "x", "slice4d");
return E(r.rank === 4, function() {
return "slice4d expects a rank-4 tensor, but got a rank-" + r.rank + " tensor";
}), Me(r, t, e);
}
var vN = U({slice4d_: yN});
function wN(n, t) {
t === void 0 && (t = -1);
var e = R(n, "logits", "softmax", "float32");
if (t === -1 && (t = e.rank - 1), t !== e.rank - 1)
throw Error("Softmax along a non-last dimension is not yet supported. " + ("Logits was rank " + e.rank + " and dim was " + t));
var r = {logits: e}, i = {dim: t};
return z.runKernelFunc(function(a, s) {
var o = a.softmax(e, t);
return s([o]), o;
}, r, null, Hl, i);
}
var qg = U({softmax_: wN});
function bN(n) {
E(n.dtype === "complex64", function() {
return "The dtype for tf.spectral.fft() must be complex64 " + ("but got " + n.dtype + ".");
});
var t = {input: n};
return z.runKernelFunc(function(e) {
var r = n.shape[n.shape.length - 1], i = n.size / r, a = n.as2D(i, r), s = e.fft(a);
return s.reshape(n.shape);
}, t, null, Tf);
}
var Js = U({fft_: bN});
function xN(n) {
E(n.dtype === "complex64", function() {
return "The dtype for tf.spectral.ifft() must be complex64 " + ("but got " + n.dtype + ".");
});
var t = {input: n};
return z.runKernelFunc(function(e) {
var r = n.shape[n.shape.length - 1], i = n.size / r, a = Y(n, [i, r]), s = e.ifft(a);
return Y(s, n.shape);
}, t, null, Of);
}
var ka = U({ifft_: xN});
function LN(n) {
var t = n.shape[n.shape.length - 1], e = n.size / t, r;
if (t <= 2) {
var i = Y(n, [e, t]);
r = ka(i);
} else {
var a = [e, 2 * (t - 1)], s = Y(Ea(n), [e, t]), o = Y(Vs(n), [e, t]), c = Jn(Me(s, [0, 1], [e, t - 2]), 1), l = Z(Jn(Me(o, [0, 1], [e, t - 2]), 1), Le(-1)), u = Et([s, c], 1), h = Et([o, l], 1), i = Y(hr(u, h), [a[0], a[1]]);
r = ka(i);
}
if (r = Ea(r), n.rank === 3 && n.shape[0] !== 0) {
var d = r, p = n.shape[0];
r = Y(r, [p, r.shape[0] / p, r.shape[1]]), d.dispose();
}
return r;
}
var ih = U({irfft_: LN});
function Yg(n, t, e) {
e === void 0 && (e = 0);
var r = [];
if (typeof t == "number")
E(n.shape[e] % t === 0, function() {
return "Number of splits must evenly divide the axis.";
}), r = new Array(t).fill(n.shape[e] / t);
else {
var i = t.reduce(function(o, c) {
return c === -1 && (o += 1), o;
}, 0);
E(i <= 1, function() {
return "There should be only one negative value in split array.";
});
var a = t.indexOf(-1);
if (a !== -1) {
var s = t.reduce(function(o, c) {
return c > 0 ? o + c : o;
});
t[a] = n.shape[e] - s;
}
E(n.shape[e] === t.reduce(function(o, c) {
return o + c;
}), function() {
return "The sum of sizes must match the size of the axis dimension.";
}), r = t;
}
return r;
}
function SN(n, t, e) {
e === void 0 && (e = 0);
var r = R(n, "x", "split"), i = function(o, c) {
var l = rt(e, r.shape)[0], u = Yg(r, t, l);
return o.split(r, u, l);
}, a = {x: r}, s = {numOrSizeSplits: t, axis: e};
return z.runKernelFunc(i, a, null, Ml, s);
}
var zi = U({split_: SN});
function IN(n, t) {
E(n.dtype === "float32", function() {
return "The dtype for rfft() must be real value but got " + n.dtype;
});
var e = n.shape[n.shape.length - 1], r = n.size / e, i;
if (t != null && t < e) {
var a = n.shape.map(function(y) {
return 0;
}), s = n.shape.map(function(y) {
return y;
});
s[n.shape.length - 1] = t, i = Me(n, a, s), e = t;
} else if (t != null && t > e) {
var o = n.shape.map(function(y) {
return y;
});
o[n.shape.length - 1] = t - e, i = Et([n, $n(o)], n.shape.length - 1), e = t;
} else
i = n;
var c = ke(i), l = Y(hr(i, c), [r, e]), u = Js(l), h = Math.floor(e / 2) + 1, d = Ea(u), p = Vs(u), f = zi(d, [h, e - h], d.shape.length - 1), m = zi(p, [h, e - h], p.shape.length - 1), g = i.shape.slice();
return g[i.shape.length - 1] = h, Y(hr(f[0], m[0]), g);
}
var Zs = U({rfft_: IN});
function AN(n) {
var t = R(n, "x", "sqrt"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.sqrt(t);
return i([t]), a;
}, e, null, Bl);
}
var Ht = U({sqrt_: AN});
function TN(n, t) {
var e, r = R(n, "a", "squaredDifference"), i = R(t, "b", "squaredDifference");
e = ct(r, i), r = e[0], i = e[1], it(r.shape, i.shape);
var a = function(c, l) {
var u = c.squaredDifference(r, i);
return l([r, i]), u;
}, s = {a: r, b: i}, o = {};
return z.runKernelFunc(a, s, null, Vl, o);
}
var Qs = U({squaredDifference_: TN});
function NN(n, t) {
var e = R(n, "x", "squeeze");
return Y(e, jp(e.shape, t).newShape);
}
var eo = U({squeeze_: NN});
function _N(n, t) {
t === void 0 && (t = 0);
var e = Sa(n, "tensors", "stack");
if (E(e.length >= 1, function() {
return "Pass at least one tensor to tf.stack";
}), e.length === 1)
return vn(e[0], t);
var r = e[0].rank, i = e[0].shape, a = e[0].dtype;
E(t <= r, function() {
return "Axis must be <= rank of the tensor";
}), e.forEach(function(o) {
Pe(i, o.shape, "All tensors passed to stack must have matching shapes"), E(a === o.dtype, function() {
return "All tensors passed to stack must have matching dtypes";
});
});
var s = e.map(function(o) {
return vn(o, t);
});
return Et(s, t);
}
var Zr = U({stack_: _N});
function CN(n, t) {
t === void 0 && (t = 0);
var e = R(n, "x", "step"), r = {x: e}, i = {alpha: t};
return z.runKernelFunc(function(a) {
return a.step(e, t);
}, r, null, Zl, i);
}
var Pi = U({step_: CN});
function RN(n, t, e, r, i, a, s, o, c) {
i === void 0 && (i = 0), a === void 0 && (a = 0), s === void 0 && (s = 0), o === void 0 && (o = 0), c === void 0 && (c = 0);
var l = R(n, "x", "stridedSlice"), u = function(p) {
r == null && (r = new Array(t.length));
var f = Ds(s);
if (f.length > 1)
throw new Error("Multiple ellipses in slice is not allowed.");
if (s !== 0 && o !== 0)
throw new Error("Using both ellipsisMask and newAxisMask is not yet supported.");
if (s !== 0 && c !== 0)
throw new Error("Using both ellipsisMask and shrinkAxisMask is not yet supported.");
var m = l.rank - t.length, g = Ds(o), y = l.shape.slice();
g.forEach(function(F) {
t[F] = 0, e[F] = 1, y.splice(F, 0, 1);
}), l = Y(l, y);
var w = Km(l.shape, f, m, t, e, r, i, a, s), b = w.begin, x = w.end, L = w.strides;
t = b, e = x, r = L;
var N = Ds(c);
N.forEach(function(F) {
e[F] = t[F] + 1, r[F] = 1;
});
var I = Bm(t, e, r), C = I.filter(function(F, k) {
return N.indexOf(k) === -1;
}), O = r.every(function(F) {
return F === 1;
});
if (O)
return Y(Me(l, t, I), C);
var D = p.stridedSlice(l, t, e, r);
return Y(D, C);
}, h = {x: l}, d = {begin: t, end: e, strides: r, beginMask: i, endMask: a, ellipsisMask: s, newAxisMask: o, shrinkAxisMask: c};
return z.runKernelFunc(u, h, null, nm, d);
}
var Kg = U({stridedSlice_: RN});
function ON(n) {
var t = R(n, "x", "tan"), e = {x: t};
return z.runKernelFunc(function(r, i) {
var a = r.tan(t);
return i([t]), a;
}, e, null, ql);
}
var jg = U({tan_: ON});
function Fa(n, t, e) {
if (Br(n), t != null && t.length !== 2)
throw new Error("tensor2d() requires shape to have two numbers");
var r = Cn(n, e);
if (r.length !== 2 && r.length !== 1)
throw new Error("tensor2d() requires values to be number[][] or flat/TypedArray");
if (r.length === 1 && t == null)
throw new Error("tensor2d() requires shape to be provided when `values` are a flat/TypedArray");
return dr(n, t, r, e);
}
function EN(n, t, e) {
if (Br(n), t != null && t.length !== 4)
throw new Error("tensor4d() requires shape to have four numbers");
var r = Cn(n, e);
if (r.length !== 4 && r.length !== 1)
throw new Error("tensor4d() requires values to be number[][][][] or flat/TypedArray");
if (r.length === 1 && t == null)
throw new Error("tensor4d() requires shape to be provided when `values` are a flat array");
return dr(n, t, r, e);
}
function DN(n, t, e) {
if (Br(n), t != null && t.length !== 5)
throw new Error("tensor5d() requires shape to have five numbers");
var r = Cn(n, e);
if (r.length !== 5 && r.length !== 1)
throw new Error("tensor5d() requires values to be number[][][][][] or flat/TypedArray");
if (r.length === 1 && t == null)
throw new Error("tensor5d() requires shape to be provided when `values` are a flat array");
return dr(n, t, r, e);
}
function kN(n, t, e) {
if (Br(n), t != null && t.length !== 6)
throw new Error("tensor6d() requires shape to have six numbers");
var r = Cn(n, e);
if (r.length !== 6 && r.length !== 1)
throw new Error("tensor6d() requires values to be number[][][][][][] or flat/TypedArray");
if (r.length === 1 && t == null)
throw new Error("tensor6d() requires shape to be provided when `values` are a flat array");
return t = t || r, dr(n, t, r, e);
}
function FN(n, t, e) {
t === void 0 && (t = 1), e === void 0 && (e = true);
var r = R(n, "x", "topk");
if (r.rank === 0)
throw new Error("topk() expects the input to be of rank 1 or higher");
var i = r.shape[r.shape.length - 1];
if (t > i)
throw new Error("'k' passed to topk() must be <= the last dimension (" + i + ") " + ("but got " + t));
var a = {x: r}, s = {k: t, sorted: e}, o = z.runKernelFunc(function(u) {
return u.topk(r, t, e);
}, a, null, rm, s), c = o[0], l = o[1];
return {values: c, indices: l};
}
var $g = U({topk_: FN});
function WN(n, t, e, r, i) {
if (t === void 0 && (t = 0), e === void 0 && (e = 1), r != null && r === "bool")
throw new Error("Unsupported data type $ { dtype }");
for (var a = new Zu(t, e, r, true, i), s = Rn(n, r), o = 0; o < s.values.length; o++)
s.values[o] = a.nextValue();
return s.toTensor();
}
var UN = U({truncatedNormal_: WN});
function BN(n, t) {
t === void 0 && (t = 0);
var e = R(n, "x", "unique", null);
E(e.rank > 0, function() {
return "The input tensor must be at least 1D";
});
var r = {x: e}, i = {axis: t}, a = z.runKernel(im, r, i), s = a[0], o = a[1];
return {values: s, indices: o};
}
var Xg = U({unique_: BN});
function zN(n, t, e) {
var r = R(n, "x", "unsortedSegmentSum"), i = R(t, "segmentIds", "unsortedSegmentSum", "int32");
E(ot(e), function() {
return "numSegments must be of dtype int";
});
var a = {x: r, segmentIds: i}, s = {numSegments: e}, o = function(c, l) {
var u = c.unsortedSegmentSum(r, i, e);
return l([i]), u;
};
return z.runKernelFunc(o, a, null, Xl, s);
}
var ah = U({unsortedSegmentSum_: zN});
function PN(n, t) {
t === void 0 && (t = 0);
var e = R(n, "x", "unstack");
E(t >= -e.shape.length && t < e.shape.length, function() {
return "Axis = " + t + " is not in [-" + e.shape.length + ", " + e.shape.length + ")";
}), t < 0 && (t += e.shape.length);
var r = {value: e}, i = {axis: t}, a = function(s) {
return s.unstack(e, t);
};
return z.runKernelFunc(a, r, null, $l, i);
}
var to = U({unstack_: PN});
function MN(n, t, e, r) {
return t === void 0 && (t = true), z.makeVariable(n, t, e, r);
}
function Jg(n, t) {
for (var e = [], r = 0; r < t.length; r++)
t[r] && e.push(r);
for (var i = Rn(n, "int32"), a = Rn([e.length, n.length], "int32"), r = 0; r < e.length; r++) {
var s = i.indexToLoc(e[r]), o = r * n.length;
a.values.set(s, o);
}
return a.toTensor();
}
function HN(n) {
return pe(this, void 0, void 0, function() {
var t, e, r;
return fe(this, function(i) {
switch (i.label) {
case 0:
return t = R(n, "condition", "whereAsync", "bool"), [4, t.data()];
case 1:
return e = i.sent(), r = Jg(t.shape, e), n !== t && t.dispose(), [2, r];
}
});
});
}
var Zg = HN;
function VN(n, t, e) {
return pe(this, void 0, void 0, function() {
var r, i, a, s, o, c, l, u, h, d, p, f, m;
return fe(this, function(g) {
switch (g.label) {
case 0:
for (r = R(n, "tensor", "boolMask"), i = R(t, "mask", "boolMask", "bool"), a = e != null ? e : 0, s = i.rank, o = r.shape, E(s > 0, function() {
return "mask cannot be scalar";
}), Pe(o.slice(a, a + s), i.shape, "mask's shape must match the first K dimensions of tensor's shape,"), c = 1, l = a; l < a + s; l++)
c *= o[l];
return u = o.slice(0, a).concat([c], o.slice(a + s)), h = Y(r, u), d = Y(i, [-1]), [4, Zg(d)];
case 1:
return p = g.sent(), f = eo(p, [1]), m = Hs(h, f, a), n !== r && r.dispose(), t !== i && i.dispose(), f.dispose(), h.dispose(), d.dispose(), p.dispose(), [2, m];
}
});
});
}
var GN = VN;
function qN(n, t) {
Nt("strict variants of ops have been deprecated and will be removed in future");
var e = R(n, "a", "notEqualStrict"), r = R(t, "b", "notEqualStrict");
return Pe(e.shape, r.shape, "Error in notEqualStrict: "), $s(e, r);
}
function YN(n, t) {
Nt("strict variants of ops have been deprecated and will be removed in future");
var e = R(n, "a", "lessStrict"), r = R(t, "b", "lessStrict");
return Pe(e.shape, r.shape, "Error in lessStrict: "), Gs(e, r);
}
function KN(n, t) {
Nt("strict variants of ops have been deprecated and will be removed in future");
var e = R(n, "a", "equalStrict"), r = R(t, "b", "equalStrict");
return Pe(e.shape, r.shape, "Error in equalStrict: "), Ra(e, r);
}
function jN(n, t) {
Nt("strict variants of ops have been deprecated and will be removed in future");
var e = R(n, "a", "lessEqualStrict"), r = R(t, "b", "lessEqualStrict");
return Pe(e.shape, r.shape, "Error in lessEqualStrict: "), qr(e, r);
}
function $N(n, t) {
Nt("strict variants of ops have been deprecated and will be removed in future");
var e = R(n, "a", "greaterStrict"), r = R(t, "b", "greaterStrict");
return Pe(e.shape, r.shape, "Error in greaterStrict: "), vr(e, r);
}
function XN(n, t) {
Nt("strict variants of ops have been deprecated and will be removed in future");
var e = R(n, "a", "greaterEqualStrict"), r = R(t, "b", "greaterEqualStrict");
return Pe(e.shape, r.shape, "Error in greaterEqualStrict: "), Gr(e, r);
}
var Qg = U({equalStrict_: KN}), e0 = U({greaterEqualStrict_: XN}), t0 = U({greaterStrict_: $N}), n0 = U({lessEqualStrict_: jN}), r0 = U({lessStrict_: YN}), i0 = U({notEqualStrict_: qN});
function JN(n, t) {
Nt("strict variants of ops have been deprecated and will be removed in future");
var e = R(n, "a", "addStrict"), r = R(t, "b", "addStrict");
return Pe(e.shape, r.shape, "Error in addStrict: "), ge(e, r);
}
function ZN(n, t) {
Nt("strict variants of ops have been deprecated and will be removed in future");
var e = R(n, "a", "subStrict"), r = R(t, "b", "subStrict");
return Pe(e.shape, r.shape, "Error in subStrict: "), be(e, r);
}
function QN(n, t) {
return Nt("strict variants of ops have been deprecated and will be removed in future"), Pe(n.shape, t.shape, "Error in powStrict: "), Xn(n, t);
}
function e_(n, t) {
Nt("strict variants of ops have been deprecated and will be removed in future");
var e = R(n, "a", "mul"), r = R(t, "b", "mul");
return Pe(e.shape, r.shape, "Error in multiplyStrict: "), Z(e, r);
}
function t_(n, t) {
Nt("strict variants of ops have been deprecated and will be removed in future");
var e = R(n, "a", "div"), r = R(t, "b", "div");
return Pe(e.shape, r.shape, "Error in divideStrict: "), Ne(e, r);
}
function n_(n, t) {
Nt("strict variants of ops have been deprecated and will be removed in future");
var e = R(n, "a", "modStrict"), r = R(t, "b", "modStrict");
return Pe(e.shape, r.shape, "Error in modStrict: "), ju(e, r);
}
function r_(n, t) {
Nt("strict variants of ops have been deprecated and will be removed in future");
var e = R(n, "a", "minimumStrict"), r = R(t, "b", "minimumStrict");
return Pe(e.shape, r.shape, "Error in minimumStrict: "), js(e, r);
}
function i_(n, t) {
Nt("strict variants of ops have been deprecated and will be removed in future");
var e = R(n, "a", "maximumStrict"), r = R(t, "b", "maximumStrict");
return Pe(e.shape, r.shape, "Error in maximumStrict: "), Fi(e, r);
}
function a_(n, t) {
Nt("strict variants of ops have been deprecated and will be removed in future");
var e = R(n, "a", "squaredDifferenceStrict"), r = R(t, "b", "squaredDifferenceStrict");
return Pe(e.shape, r.shape, "Error in squaredDifferenceStrict: "), Qs(e, r);
}
var a0 = U({addStrict_: JN}), s0 = U({divStrict_: t_}), o0 = U({maximumStrict_: i_}), c0 = U({minimumStrict_: r_}), l0 = U({modStrict_: n_}), u0 = U({mulStrict_: e_}), h0 = U({powStrict_: QN}), d0 = U({squaredDifferenceStrict_: a_}), p0 = U({subStrict_: ZN});
function s_(n, t, e, r) {
t === void 0 && (t = "euclidean"), e === void 0 && (e = null), r === void 0 && (r = false), n = R(n, "x", "norm");
var i = f0(n, t, e), a = i.shape;
if (r) {
var s = rt(e, n.shape);
a = an(i.shape, s);
}
return Y(i, a);
}
function f0(n, t, e) {
if (e === void 0 && (e = null), n.rank === 0)
return $t(n);
if (n.rank !== 1 && e === null)
return f0(Y(n, [-1]), t, e);
if (n.rank === 1 || typeof e == "number" || Array.isArray(e) && e.length === 1) {
if (t === 1)
return _e($t(n), e);
if (t === Infinity)
return Kr($t(n), e);
if (t === -Infinity)
return Ks($t(n), e);
if (t === "euclidean" || t === 2)
return Ht(_e(Xn($t(n), Le(2, "int32")), e));
throw new Error("Error in norm: invalid ord value: " + t);
}
if (Array.isArray(e) && e.length === 2) {
if (t === 1)
return Kr(_e($t(n), e[0]), e[1] - 1);
if (t === Infinity)
return Kr(_e($t(n), e[1]), e[0]);
if (t === -Infinity)
return Ks(_e($t(n), e[1]), e[0]);
if (t === "fro" || t === "euclidean")
return Ht(_e($e(n), e));
throw new Error("Error in norm: invalid ord value: " + t);
}
throw new Error("Error in norm: invalid axis: " + e);
}
var no = U({norm_: s_});
function o_(n, t, e, r, i) {
i === void 0 && (i = true);
var a = R(n, "v", "movingAverage"), s = R(t, "x", "movingAverage"), o = R(e, "decay", "movingAverage");
um(a, s), E(pn(a.shape, s.shape), function() {
return "Shape mismatch in v and x";
});
var c = Le(1), l = be(c, o), u = Z(be(s, a), l);
if (i) {
E(r != null, function() {
return "When using zeroDebias: true, step is required.";
});
var h = R(r, "step", "movingAverage");
u = Ne(u, be(c, Xn(o, h)));
}
return ge(a, u);
}
var c_ = U({movingAverage_: o_});
function l_(n, t, e) {
var r = R(n, "indices", "scatterND", "int32"), i = R(t, "updates", "scatterND");
Nu(i, r, e);
var a = function(c) {
return c.scatterND(r, i, e);
}, s = {indices: r, updates: i}, o = {shape: e};
return z.runKernelFunc(a, s, null, Qf, o);
}
var u_ = U({scatterND_: l_});
function h_(n, t, e, r) {
if (n.dtype !== "int32")
throw new Error("tf.sparseToDense() expects the indices to be int32 type," + (" but the dtype was " + n.dtype + "."));
if (n.rank > 2)
throw new Error("sparseIndices should be a scalar, vector, or matrix," + (" but got shape " + n.shape + "."));
var i = n.rank > 0 ? n.shape[0] : 1, a = n.rank > 1 ? n.shape[1] : 1;
if (e.length !== a)
throw new Error("outputShape has incorrect number of elements:," + (" " + e.length + ", should be: " + a + "."));
var s = t.size;
if (!(t.rank === 0 || t.rank === 1 && s === i))
throw new Error("sparseValues has incorrect shape " + (t.shape + ", should be [] or [" + i + "]"));
if (t.dtype !== r.dtype)
throw new Error("sparseValues.dtype must match defaultValues.dtype");
}
function d_(n, t, e, r) {
r === void 0 && (r = 0);
var i = R(n, "sparseIndices", "sparseToDense", "int32"), a = R(t, "sparseValues", "sparseToDense"), s = R(r, "defaultValue", "sparseToDense", a.dtype);
h_(i, a, e, s);
var o = {sparseIndices: i, sparseValues: a, defaultValue: s}, c = {outputShape: e};
return z.runKernelFunc(function(l) {
return l.sparseToDense(i, a, e, s);
}, o, null, tm, c);
}
var p_ = U({sparseToDense_: d_});
function f_(n, t) {
var e = R(t, "indices", "gatherND", "int32"), r = R(n, "x", "gatherND"), i = function(s) {
return s.gatherND(r, e);
}, a = {params: r, indices: e};
return z.runKernelFunc(i, a, null, Cf);
}
var m_ = U({gatherND_: f_});
function g_(n, t) {
if (t == null)
return n.shape.slice();
if (pn(n.shape, t))
return t;
if (n.shape.length === t.length) {
for (var e = [], r = 0; r < n.shape.length; r++)
t[r] == null && n.shape[r] != null ? e.push(n.shape[r]) : e.push(t[r]);
return e;
}
return t;
}
function y_(n, t, e, r) {
var i = R(n, "x", "dropout");
if (E(i.dtype === "float32", function() {
return "x has to be a floating point tensor since it's going to be " + ("scaled, but got a " + i.dtype + " tensor instead.");
}), E(t >= 0 && t < 1, function() {
return "rate must be a float in the range [0, 1), but got " + t + ".";
}), t === 0)
return n instanceof K ? i.clone() : i;
var a = g_(i, e), s = 1 - t, o = Ne(Ms(ge(zg(a, 0, 1, "float32", r), s)), s);
return Z(i, o);
}
var v_ = U({dropout_: y_});
function m0(n) {
return Math.floor(Math.pow(2, Math.ceil(Math.log(n) / Math.log(2))));
}
function sh(n, t, e) {
for (var r = 1 - n % 2, i = new Float32Array(n), a = 0; a < n; ++a) {
var s = 2 * Math.PI * a / (n + r - 1);
i[a] = t - e * Math.cos(s);
}
return Bi(i, "float32");
}
function w_(n, t, e) {
return e === void 0 && (e = 1), pe(this, void 0, void 0, function() {
var r, i, a, s, o, c, l, u, h, d, p, f, m, g, g;
return fe(this, function(y) {
switch (y.label) {
case 0:
return r = R(n, "predictions", "inTopK"), i = R(t, "targets", "inTopK"), E(r.rank > 1, function() {
return "inTopK() expects the predictions to be of rank 2 or higher, " + ("but got " + r.rank);
}), E(r.rank - 1 === i.rank, function() {
return "predictions rank should be 1 larger than targets rank, but got predictions rank " + (r.rank + " and targets rank " + i.rank);
}), Pe(r.shape.slice(0, r.shape.length - 1), i.shape, "predictions's shape should be align with the targets' shape, except the last dimension."), a = r.shape[r.shape.length - 1], E(e > 0 && e <= a, function() {
return "'k' passed to inTopK() must be > 0 && <= the predictions last " + ("dimension (" + a + "), but got " + e);
}), [4, r.data()];
case 1:
return s = y.sent(), [4, i.data()];
case 2:
for (o = y.sent(), c = [s.length / a, a], l = c[0], u = c[1], h = bs("bool", l), d = 0; d < l; d++) {
for (p = d * u, f = s.subarray(p, p + u), m = [], g = 0; g < f.length; g++)
m.push({value: f[g], index: g});
for (m.sort(function(w, b) {
return b.value - w.value;
}), h[d] = 0, g = 0; g < e; g++)
if (m[g].index === o[d]) {
h[d] = 1;
break;
}
}
return n !== r && r.dispose(), t !== i && i.dispose(), [2, pr(h, i.shape, "bool")];
}
});
});
}
var b_ = w_;
function x_(n, t, e, r, i, a, s) {
a === void 0 && (a = "NHWC");
var o = n;
n.rank === 3 && (o = Y(n, [1, n.shape[0], n.shape[1], n.shape[2]]));
var c = t;
c.rank === 3 && (c = Y(t, [1, t.shape[0], t.shape[1], t.shape[2]])), E(o.rank === 4, function() {
return "Error in conv2dDerFilter: input must be rank 4, but got shape " + (o.shape + ".");
}), E(c.rank === 4, function() {
return "Error in conv2dDerFilter: dy must be rank 4, but got shape " + (c.shape + ".");
}), E(e.length === 4, function() {
return "Error in conv2dDerFilter: filterShape must be length 4, but got " + (e + ".");
});
var l = a === "NHWC" ? o.shape[3] : o.shape[1], u = a === "NHWC" ? c.shape[3] : c.shape[1];
E(l === e[2], function() {
return "Error in conv2dDerFilter: depth of input " + l + ") must " + ("match input depth in filter (" + e[2] + ".");
}), E(u === e[3], function() {
return "Error in conv2dDerFilter: depth of dy (" + u + ") must " + ("match output depth for filter (" + e[3] + ").");
}), s != null && E(ot(i), function() {
return "Error in conv2dDerFilter: pad must be an integer when using, " + ("dimRoundingMode " + s + " but got pad " + i + ".");
});
var h = function(f) {
var m = 1, g = Aa(a), y = mn(o.shape, e, r, m, i, s, false, g);
return f.conv2dDerFilter(o, c, y);
}, d = {x: o, dy: c}, p = {strides: r, pad: i, dataFormat: a, dimRoundingMode: s, filterShape: e};
return z.runKernelFunc(h, d, null, ff, p);
}
var oh = U({conv2DBackpropFilter_: x_});
function ro(n, t, e) {
if (e == null || e === "linear")
return n;
if (e === "relu")
return Z(n, Pi(t));
throw new Error("Cannot compute gradient for fused activation " + e + ".");
}
function io(n, t) {
var e = t, r = bt(n.shape, t.shape);
return r.length > 0 && (e = _e(e, r)), Y(e, n.shape);
}
function ao(n, t, e) {
if (t === "linear")
return n;
if (t === "relu")
return Da(n);
if (t === "elu")
return Pu(n);
if (t === "relu6")
return eh(n);
if (t === "prelu")
return Xu(n, e);
throw new Error("Unknown fused activation " + t + ".");
}
var so = function(n, t) {
var e = n > 0;
return !e || t === "linear";
};
function L_(n) {
var t = n.x, e = n.filter, r = n.strides, i = n.pad, a = n.dataFormat, s = a === void 0 ? "NHWC" : a, o = n.dilations, c = o === void 0 ? [1, 1] : o, l = n.dimRoundingMode, u = n.bias, h = n.activation, d = h === void 0 ? "linear" : h, p = n.preluActivationWeights;
if (d = d || "linear", so(z.state.gradientDepth, d) === false) {
var f = Di(t, e, r, i, s, c, l);
return u != null && (f = ge(f, u)), ao(f, d, p);
}
var m = R(t, "x", "conv2d"), g = R(e, "filter", "conv2d"), y = m, w = false;
m.rank === 3 && (w = true, y = Y(m, [1, m.shape[0], m.shape[1], m.shape[2]])), E(y.rank === 4, function() {
return "Error in fused conv2d: input must be rank 4, but got rank " + (y.rank + ".");
}), E(g.rank === 4, function() {
return "Error in fused conv2d: filter must be rank 4, but got rank " + (g.rank + ".");
}), l != null && E(ot(i), function() {
return "Error in fused conv2d: pad must be an integer when using, " + ("dimRoundingMode " + l + " but got pad " + i + ".");
}), E(y.shape[3] === g.shape[2], function() {
return "Error in conv2d: depth of input (" + y.shape[3] + ") must match " + ("input depth for filter " + g.shape[2] + ".");
}), E(Mt(r, c), function() {
return "Error in conv2D: Either strides or dilations must be 1. " + ("Got strides " + r + " and dilations '" + c + "'");
}), E(s === "NHWC", function() {
return "Error in conv2d: got dataFormat of " + s + " but only NHWC is currently supported.";
});
var b = mn(y.shape, g.shape, r, c, i, l), x;
u != null && (x = R(u, "bias", "fused conv2d"), x = ct(x, m)[0], it(b.outShape, x.shape));
var L;
p != null && (L = R(p, "prelu weights", "fused conv2d"));
var N = function(k, B) {
var V = B, P = V[0], G = V[1], j = V[2], q = V[3], H = ro(k, j, d);
E(yr(c), function() {
return "Error in gradient of fused conv2D: dilation rates greater than 1 " + ("are not yet supported in gradients. Got dilations '" + c + "'");
});
var J = Uu(G.shape, H, P, r, i), $ = oh(G, H, P.shape, r, i), ee = [J, $];
if (q != null) {
var te = io(q, H);
ee.push(te);
}
return ee;
}, I = function(k) {
var B = k.fusedConv2d({input: y, filter: g, convInfo: b, bias: x, activation: d, preluActivationWeights: L});
return B;
}, C = {x: y, filter: g, bias: x, preluActivationWeights: L}, O = {strides: r, pad: i, dataFormat: s, dilations: c, dimRoundingMode: l, activation: d};
if (u == null) {
var D = En(function(k, B, V) {
var P = z.runKernelFunc(I, C, null, tu, O);
return V([B, k, P]), w && (P = Y(P, [P.shape[1], P.shape[2], P.shape[3]])), {value: P, gradFunc: N};
});
return D(y, g);
} else {
var F = En(function(k, B, V, P) {
var G = z.runKernelFunc(I, C, null, tu, O);
return P([B, k, G, V]), w && (G = Y(G, [G.shape[1], G.shape[2], G.shape[3]])), {value: G, gradFunc: N};
});
return F(y, g, x);
}
}
var S_ = U({fusedConv2d_: L_});
function I_(n, t, e, r, i, a, s) {
a === void 0 && (a = [1, 1]);
var o = n;
n.rank === 3 && (o = Y(n, [1, n.shape[0], n.shape[1], n.shape[2]]));
var c = t;
c.rank === 3 && (c = Y(t, [1, t.shape[0], t.shape[1], t.shape[2]]));
var l = function(d) {
var p = mn(n.shape, e, r, a, i, s, true);
return d.depthwiseConv2DDerFilter(o, c, p);
}, u = {x: o, dy: c}, h = {strides: r, pad: i, dimRoundingMode: s, dilations: a, filterShape: e};
return z.runKernelFunc(l, u, null, wf, h);
}
var g0 = U({depthwiseConv2dNativeBackpropFilter_: I_});
function A_(n, t, e, r, i, a, s) {
a === void 0 && (a = [1, 1]);
var o = t, c = false;
t.rank === 3 && (c = true, o = Y(t, [1, t.shape[0], t.shape[1], t.shape[2]]));
var l = function(p) {
var f = mn(n, e.shape, r, a, i, s, true);
return p.depthwiseConv2DDerInput(o, e, f);
}, u = {dy: o, filter: e}, h = {strides: r, pad: i, dimRoundingMode: s, dilations: a, inputShape: n}, d = z.runKernelFunc(l, u, null, bf, h);
return c ? Y(d, [d.shape[1], d.shape[2], d.shape[3]]) : d;
}
var y0 = U({depthwiseConv2dNativeBackpropInput_: A_});
function T_(n) {
var t = n.x, e = n.filter, r = n.strides, i = n.pad, a = n.dataFormat, s = a === void 0 ? "NHWC" : a, o = n.dilations, c = o === void 0 ? [1, 1] : o, l = n.dimRoundingMode, u = n.bias, h = n.activation, d = h === void 0 ? "linear" : h, p = n.preluActivationWeights;
if (so(z.state.gradientDepth, d) === false) {
var f = Ca(t, e, r, i, s, c, l);
return u != null && (f = ge(f, u)), ao(f, d, p);
}
var m = R(t, "x", "depthwiseConv2d"), g = R(e, "filter", "depthwiseConv2d"), y = m, w = false;
m.rank === 3 && (w = true, y = Y(m, [1, m.shape[0], m.shape[1], m.shape[2]])), E(y.rank === 4, function() {
return "Error in fused depthwiseConv2d: input must be rank 4, but got " + ("rank " + y.rank + ".");
}), E(g.rank === 4, function() {
return "Error in fused depthwiseConv2d: filter must be rank 4, " + ("but got rank " + g.rank + ".");
}), E(y.shape[3] === g.shape[2], function() {
return "Error in fused depthwiseConv2d: number of input channels " + ("(" + y.shape[3] + ") must match the inChannels dimension in ") + ("filter " + g.shape[2] + ".");
}), c == null && (c = [1, 1]), E(Mt(r, c), function() {
return "Error in fused depthwiseConv2d: Either strides or dilations must " + ("be 1. Got strides " + r + " and dilations '" + c + "'");
}), l != null && E(ot(i), function() {
return "Error in fused depthwiseConv2d: pad must be an integer when " + ("using dimRoundingMode " + l + " but got pad " + i + ".");
});
var b = mn(y.shape, g.shape, r, c, i, l, true), x;
u != null && (x = R(u, "bias", "fused conv2d"), x = ct(x, m)[0], it(b.outShape, x.shape));
var L;
p != null && (L = R(p, "prelu weights", "fused depthwiseConv2d"));
var N = function(k, B) {
E(yr(c), function() {
return "Error in gradient of fused depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations " + ("'" + c + "'");
});
var V = B[0], P = B[1], G = B[2], j = B[3], q = ro(k, G, d), H = y0(P.shape, q, V, r, i, c, l), J = g0(P, q, V.shape, r, i, c, l);
if (j != null) {
var $ = io(x, q);
return [H, J, $];
}
return [H, J];
}, I = function(k) {
var B = k.fusedDepthwiseConv2D({input: y, filter: g, convInfo: b, bias: x, activation: d, preluActivationWeights: L});
return B;
}, C = {x: y, filter: g, bias: x, preluActivationWeights: L}, O = {strides: r, pad: i, dataFormat: s, dilations: c, dimRoundingMode: l, activation: d};
if (u == null) {
var D = En(function(k, B, V) {
var P = z.runKernelFunc(I, C, null, nu, O);
return V([B, k, P]), w && (P = Y(P, [P.shape[1], P.shape[2], P.shape[3]])), {value: P, gradFunc: N};
});
return D(y, g);
} else {
var F = En(function(k, B, V, P) {
var G = z.runKernelFunc(I, C, null, nu, O);
return P([B, k, G, V]), w && (G = Y(G, [G.shape[1], G.shape[2], G.shape[3]])), {value: G, gradFunc: N};
});
return F(y, g, x);
}
}
var N_ = U({fusedDepthwiseConv2d_: T_});
function __(n) {
var t, e = n.a, r = n.b, i = n.transposeA, a = i === void 0 ? false : i, s = n.transposeB, o = s === void 0 ? false : s, c = n.bias, l = n.activation, u = l === void 0 ? "linear" : l, h = n.preluActivationWeights;
if (so(z.state.gradientDepth, u) === false) {
var d = Ue(e, r, a, o);
return c != null && (d = ge(d, c)), ao(d, u, h);
}
var p = R(e, "a", "fused matMul"), f = R(r, "b", "fused matMul");
t = ct(p, f), p = t[0], f = t[1];
var m = a ? p.shape[p.rank - 2] : p.shape[p.rank - 1], g = o ? f.shape[f.rank - 1] : f.shape[f.rank - 2], y = a ? p.shape[p.rank - 1] : p.shape[p.rank - 2], w = o ? f.shape[f.rank - 2] : f.shape[f.rank - 1], b = p.shape.slice(0, -2), x = f.shape.slice(0, -2), L = dt(b), N = dt(x);
E(p.rank >= 2 && f.rank >= 2 && p.rank === f.rank, function() {
return "Error in fused matMul: inputs must have the same rank of at least " + ("2, got ranks " + p.rank + " and " + f.rank + ".");
}), E(pn(b, x), function() {
return "Error in fused matMul: outer dimensions (" + b + ") and (" + (x + ") of Tensors with shapes " + p.shape + " and ") + (f.shape + " must match.");
}), E(m === g, function() {
return "Error in fused matMul: inner shapes (" + m + ") and (" + (g + ") of Tensors with shapes " + p.shape + " and ") + (f.shape + " and transposeA=" + a) + (" and transposeB=" + o + " must match.");
});
var I = p.shape.slice(0, -2).concat([y, w]), C = a ? Y(p, [L, m, y]) : Y(p, [L, y, m]), O = o ? Y(f, [N, w, g]) : Y(f, [N, g, w]), D;
c != null && (D = R(c, "bias", "fused matMul"), D = ct(D, p)[0], it(I, D.shape));
var F;
h != null && (F = R(h, "prelu weights", "fused matMul"));
var k = function(q, H) {
var J = H[0], $ = H[1], ee = H[2], te = H[3], ne = ro(Y(q, ee.shape), ee, u), re, ie;
if (!a && !o ? (re = Ue(ne, $, false, true), ie = Ue(J, ne, true, false)) : !a && o ? (re = Ue(ne, $, false, false), ie = Ue(ne, J, true, false)) : a && !o ? (re = Ue($, ne, false, true), ie = Ue(J, ne, false, false)) : (re = Ue($, ne, true, true), ie = Ue(ne, J, true, true)), c != null) {
var oe = io(te, ne);
return [re, ie, oe];
} else
return [re, ie];
}, B = function(q) {
var H = q.fusedBatchMatMul({a: C, b: O, transposeA: a, transposeB: o, bias: D, activation: u, preluActivationWeights: F});
return H;
}, V = {a: C, b: O, bias: D, preluActivationWeights: F}, P = {transposeA: a, transposeB: o, activation: u};
if (c == null) {
var G = En(function(q, H, J) {
var $ = z.runKernelFunc(B, V, null, eu, P);
return J([q, H, $]), {value: Y($, I), gradFunc: k};
});
return G(C, O);
} else {
var j = En(function(q, H, J, $) {
var ee = z.runKernelFunc(B, V, null, eu, P);
return $([q, H, ee, J]), {value: Y(ee, I), gradFunc: k};
});
return j(C, O, D);
}
}
var C_ = U({fusedMatMul_: __});
var R_ = {__proto__: null, conv2d: S_, depthwiseConv2d: N_, matMul: C_};
function O_(n) {
return sh(n, 0.54, 0.46);
}
var E_ = U({hammingWindow_: O_});
function D_(n) {
return sh(n, 0.5, 0.5);
}
var v0 = U({hannWindow_: D_});
function k_(n, t, e, r, i) {
r === void 0 && (r = false), i === void 0 && (i = 0);
for (var a = 0, s = []; a + t <= n.size; )
s.push(Me(n, a, t)), a += e;
if (r)
for (; a < n.size; ) {
var o = a + t - n.size, c = Et([Me(n, a, t - o), Mu([o], i)]);
s.push(c), a += e;
}
return s.length === 0 ? Fa([], [0, t]) : Y(Et(s), [s.length, t]);
}
var w0 = U({frame_: k_});
function F_(n, t, e, r, i) {
i === void 0 && (i = v0), r == null && (r = m0(t));
for (var a = w0(n, t, e), s = Z(a, i(t)), o = [], c = 0; c < a.shape[0]; c++)
o.push(Zs(Me(s, [c, 0], [1, t]), r));
return Et(o);
}
var W_ = U({stft_: F_});
function U_(n, t, e, r, i, a) {
var s = R(n, "image", "cropAndResize"), o = R(t, "boxes", "cropAndResize", "float32"), c = R(e, "boxInd", "cropAndResize", "int32");
i = i || "bilinear", a = a || 0;
var l = o.shape[0];
E(s.rank === 4, function() {
return "Error in cropAndResize: image must be rank 4," + ("but got rank " + s.rank + ".");
}), E(o.rank === 2 && o.shape[1] === 4, function() {
return "Error in cropAndResize: boxes must be have size [" + l + ",4] " + ("but had shape " + o.shape + ".");
}), E(c.rank === 1 && c.shape[0] === l, function() {
return "Error in cropAndResize: boxInd must be have size [" + l + "] " + ("but had shape " + o.shape + ".");
}), E(r.length === 2, function() {
return "Error in cropAndResize: cropSize must be of length 2, but got " + ("length " + r.length + ".");
}), E(r[0] >= 1 && r[1] >= 1, function() {
return "cropSize must be atleast [1,1], but was " + r;
}), E(i === "bilinear" || i === "nearest", function() {
return "method must be bilinear or nearest, but was " + i;
});
var u = function(f) {
return f.cropAndResize(s, o, c, r, i, a);
}, h = {image: s, boxes: o, boxInd: c}, d = {method: i, extrapolationValue: a, cropSize: r}, p = z.runKernelFunc(u, h, null, yf, d);
return p;
}
var B_ = U({cropAndResize_: U_});
function z_(n) {
var t = R(n, "image", "flipLeftRight", "float32");
E(t.rank === 4, function() {
return "Error in flipLeftRight: image must be rank 4," + ("but got rank " + t.rank + ".");
});
var e = {image: t}, r = z.runKernel(_f, e, {});
return r;
}
var P_ = U({flipLeftRight_: z_});
function M_(n, t, e, r) {
e === void 0 && (e = 0), r === void 0 && (r = 0.5);
var i = R(n, "image", "rotateWithOffset", "float32");
E(i.rank === 4, function() {
return "Error in rotateWithOffset: image must be rank 4," + ("but got rank " + i.rank + ".");
});
var a = {image: i}, s = {radians: t, fillValue: e, center: r}, o = z.runKernel(am, a, s);
return o;
}
var H_ = U({rotateWithOffset_: M_});
function Mi(n, t, e, r, i, a) {
r == null && (r = 0.5), i == null && (i = Number.NEGATIVE_INFINITY), a == null && (a = 0);
var s = n.shape[0];
return e = Math.min(e, s), E(0 <= r && r <= 1, function() {
return "iouThreshold must be in [0, 1], but was '" + r + "'";
}), E(n.rank === 2, function() {
return "boxes must be a 2D tensor, but was of rank '" + n.rank + "'";
}), E(n.shape[1] === 4, function() {
return "boxes must have 4 columns, but 2nd dimension was " + n.shape[1];
}), E(t.rank === 1, function() {
return "scores must be a 1D tensor";
}), E(t.shape[0] === s, function() {
return "scores has incompatible shape with boxes. Expected " + s + ", " + ("but was " + t.shape[0]);
}), E(0 <= a && a <= 1, function() {
return "softNmsSigma must be in [0, 1], but was '" + a + "'";
}), {maxOutputSize: e, iouThreshold: r, scoreThreshold: i, softNmsSigma: a};
}
function V_(n, t, e, r, i) {
r === void 0 && (r = 0.5), i === void 0 && (i = Number.NEGATIVE_INFINITY);
var a = R(n, "boxes", "nonMaxSuppression"), s = R(t, "scores", "nonMaxSuppression"), o = Mi(a, s, e, r, i);
e = o.maxOutputSize, r = o.iouThreshold, i = o.scoreThreshold;
var c = {maxOutputSize: e, iouThreshold: r, scoreThreshold: i};
return z.runKernelFunc(function(l) {
return l.nonMaxSuppression(a, s, e, r, i);
}, {boxes: a, scores: s}, null, qf, c);
}
var G_ = U({nonMaxSuppression_: V_});
function Y_(n, t, e) {
var r = q_(n, t, e), i = r < 0 ? -(r + 1) : r;
n.splice(i, 0, t);
}
function q_(n, t, e) {
return j_(n, t, e || K_);
}
function K_(n, t) {
return n > t ? 1 : n < t ? -1 : 0;
}
function j_(n, t, e) {
for (var r = 0, i = n.length, a = 0, s = false; r < i; ) {
a = r + (i - r >>> 1);
var o = e(t, n[a]);
o > 0 ? r = a + 1 : (i = a, s = !o);
}
return s ? r : -r - 1;
}
function b0(n, t, e, r, i) {
return ch(n, t, e, r, i, 0).selectedIndices;
}
function x0(n, t, e, r, i, a) {
return ch(n, t, e, r, i, 0, false, a, true);
}
function L0(n, t, e, r, i, a) {
return ch(n, t, e, r, i, a, true);
}
function ch(n, t, e, r, i, a, s, o, c) {
s === void 0 && (s = false), o === void 0 && (o = false), c === void 0 && (c = false);
for (var l = [], u = 0; u < t.length; u++)
t[u] > i && l.push({score: t[u], boxIndex: u, suppressBeginIndex: 0});
l.sort(S0);
for (var h = a > 0 ? -0.5 / a : 0, d = [], p = []; d.length < e && l.length > 0; ) {
var f = l.pop(), m = f.score, g = f.boxIndex, y = f.suppressBeginIndex;
if (m < i)
break;
for (var w = false, b = d.length - 1; b >= y; --b) {
var x = $_(n, g, d[b]);
if (x >= r) {
w = true;
break;
}
if (f.score = f.score * X_(r, h, x), f.score <= i)
break;
}
f.suppressBeginIndex = d.length, w || (f.score === m ? (d.push(g), p.push(f.score)) : f.score > i && Y_(l, f, S0));
}
var L = d.length, N = e - L;
o && N > 0 && (d.push.apply(d, new Array(N).fill(0)), p.push.apply(p, new Array(N).fill(0)));
var I = {selectedIndices: Bi(d, "int32")};
return s && (I.selectedScores = Bi(p, "float32")), c && (I.validOutputs = Le(L, "int32")), I;
}
function $_(n, t, e) {
var r = n.subarray(t * 4, t * 4 + 4), i = n.subarray(e * 4, e * 4 + 4), a = Math.min(r[0], r[2]), s = Math.min(r[1], r[3]), o = Math.max(r[0], r[2]), c = Math.max(r[1], r[3]), l = Math.min(i[0], i[2]), u = Math.min(i[1], i[3]), h = Math.max(i[0], i[2]), d = Math.max(i[1], i[3]), p = (o - a) * (c - s), f = (h - l) * (d - u);
if (p <= 0 || f <= 0)
return 0;
var m = Math.max(a, l), g = Math.max(s, u), y = Math.min(o, h), w = Math.min(c, d), b = Math.max(y - m, 0) * Math.max(w - g, 0);
return b / (p + f - b);
}
function X_(n, t, e) {
var r = Math.exp(t * e * e);
return e <= n ? r : 0;
}
function S0(n, t) {
return n.score - t.score || n.score === t.score && t.boxIndex - n.boxIndex;
}
function J_(n, t, e, r, i) {
return r === void 0 && (r = 0.5), i === void 0 && (i = Number.NEGATIVE_INFINITY), pe(this, void 0, void 0, function() {
var a, s, o, c, l, u, h;
return fe(this, function(d) {
switch (d.label) {
case 0:
return a = R(n, "boxes", "nonMaxSuppressionAsync"), s = R(t, "scores", "nonMaxSuppressionAsync"), o = Mi(a, s, e, r, i), e = o.maxOutputSize, r = o.iouThreshold, i = o.scoreThreshold, [4, Promise.all([a.data(), s.data()])];
case 1:
return c = d.sent(), l = c[0], u = c[1], h = b0(l, u, e, r, i), a !== n && a.dispose(), s !== t && s.dispose(), [2, h];
}
});
});
}
var Z_ = J_;
function Q_(n, t, e, r, i, a) {
r === void 0 && (r = 0.5), i === void 0 && (i = Number.NEGATIVE_INFINITY), a === void 0 && (a = 0);
var s = R(n, "boxes", "nonMaxSuppression"), o = R(t, "scores", "nonMaxSuppression"), c = Mi(s, o, e, r, i, a);
e = c.maxOutputSize, r = c.iouThreshold, i = c.scoreThreshold, a = c.softNmsSigma;
var l = {boxes: s, scores: o}, u = {maxOutputSize: e, iouThreshold: r, scoreThreshold: i, softNmsSigma: a}, h = z.runKernel(Kf, l, u);
return {selectedIndices: h[0], selectedScores: h[1]};
}
var eC = U({nonMaxSuppressionWithScore_: Q_});
function tC(n, t, e, r, i, a) {
return r === void 0 && (r = 0.5), i === void 0 && (i = Number.NEGATIVE_INFINITY), a === void 0 && (a = 0), pe(this, void 0, void 0, function() {
var s, o, c, l, u, h, d;
return fe(this, function(p) {
switch (p.label) {
case 0:
return s = R(n, "boxes", "nonMaxSuppressionAsync"), o = R(t, "scores", "nonMaxSuppressionAsync"), c = Mi(s, o, e, r, i, a), e = c.maxOutputSize, r = c.iouThreshold, i = c.scoreThreshold, a = c.softNmsSigma, [4, Promise.all([s.data(), o.data()])];
case 1:
return l = p.sent(), u = l[0], h = l[1], d = L0(u, h, e, r, i, a), s !== n && s.dispose(), o !== t && o.dispose(), [2, d];
}
});
});
}
var nC = tC;
function rC(n, t, e, r, i, a) {
r === void 0 && (r = 0.5), i === void 0 && (i = Number.NEGATIVE_INFINITY), a === void 0 && (a = false);
var s = R(n, "boxes", "nonMaxSuppression"), o = R(t, "scores", "nonMaxSuppression"), c = Mi(s, o, e, r, i, null), l = c.maxOutputSize, u = c.iouThreshold, h = c.scoreThreshold, d = {boxes: s, scores: o}, p = {maxOutputSize: l, iouThreshold: u, scoreThreshold: h, padToMaxOutputSize: a}, f = z.runKernel(Yf, d, p);
return {selectedIndices: f[0], validOutputs: f[1]};
}
var iC = U({nonMaxSuppressionPadded_: rC});
function aC(n, t, e, r, i, a) {
return r === void 0 && (r = 0.5), i === void 0 && (i = Number.NEGATIVE_INFINITY), a === void 0 && (a = false), pe(this, void 0, void 0, function() {
var s, o, c, l, u, h, d, p, f, m;
return fe(this, function(g) {
switch (g.label) {
case 0:
return s = R(n, "boxes", "nonMaxSuppressionAsync"), o = R(t, "scores", "nonMaxSuppressionAsync"), c = Mi(s, o, e, r, i, null), l = c.maxOutputSize, u = c.iouThreshold, h = c.scoreThreshold, [4, Promise.all([s.data(), o.data()])];
case 1:
return d = g.sent(), p = d[0], f = d[1], m = x0(p, f, l, u, h, a), s !== n && s.dispose(), o !== t && o.dispose(), [2, m];
}
});
});
}
var sC = aC;
function oC(n, t, e) {
e === void 0 && (e = false);
var r = R(n, "images", "resizeBilinear");
E(r.rank === 3 || r.rank === 4, function() {
return "Error in resizeBilinear: x must be rank 3 or 4, but got " + ("rank " + r.rank + ".");
}), E(t.length === 2, function() {
return "Error in resizeBilinear: new shape must 2D, but got shape " + (t + ".");
});
var i = r, a = false;
r.rank === 3 && (a = true, i = Y(r, [1, r.shape[0], r.shape[1], r.shape[2]]));
var s = t[0], o = t[1], c = function(d, p) {
return p([i]), d.resizeBilinear(i, s, o, e);
}, l = {images: i}, u = {alignCorners: e, size: t}, h = z.runKernelFunc(c, l, null, Al, u);
return a ? Y(h, [h.shape[1], h.shape[2], h.shape[3]]) : h;
}
var I0 = U({resizeBilinear_: oC});
function cC(n, t, e) {
e === void 0 && (e = false);
var r = R(n, "images", "resizeNearestNeighbor");
E(r.rank === 3 || r.rank === 4, function() {
return "Error in resizeNearestNeighbor: x must be rank 3 or 4, but got " + ("rank " + r.rank + ".");
}), E(t.length === 2, function() {
return "Error in resizeNearestNeighbor: new shape must 2D, but got shape " + (t + ".");
}), E(r.dtype === "float32" || r.dtype === "int32", function() {
return "`images` must have `int32` or `float32` as dtype";
});
var i = r, a = false;
r.rank === 3 && (a = true, i = Y(r, [1, r.shape[0], r.shape[1], r.shape[2]]));
var s = t[0], o = t[1], c = {images: i}, l = {alignCorners: e, size: t}, u = function(d, p) {
return p([i]), d.resizeNearestNeighbor(i, s, o, e);
}, h = z.runKernelFunc(u, c, null, Il, l);
return a ? Y(h, [h.shape[1], h.shape[2], h.shape[3]]) : h;
}
var A0 = U({resizeNearestNeighbor_: cC});
function lC(n, t, e) {
E(t % 1 === 0, function() {
return "bandPart(): numLower must be an integer, got " + t + ".";
}), E(e % 1 === 0, function() {
return "bandPart(): numUpper must be an integer, got " + e + ".";
});
var r = R(n, "a", "bandPart");
E(r.rank >= 2, function() {
return "bandPart(): Rank must be at least 2, got " + r.rank + ".";
});
var i = r.shape, a = r.shape.slice(-2), s = a[0], o = a[1];
if (!(t <= s))
throw new Error("bandPart(): numLower (" + t + ")" + (" must not be greater than the number of rows (" + s + ")."));
if (!(e <= o))
throw new Error("bandPart(): numUpper (" + e + ")" + (" must not be greater than the number of columns (" + o + ")."));
t < 0 && (t = s), e < 0 && (e = o);
var c = Y(Qu(0, s, 1, "int32"), [-1, 1]), l = Qu(0, o, 1, "int32"), u = be(c, l), h = jr(qr(u, Le(+t, "int32")), Gr(u, Le(-e, "int32"))), d = $n([s, o], r.dtype);
return Y(Zr(to(Y(r, [-1, s, o])).map(function(p) {
return gn(h, p, d);
})), i);
}
var uC = U({bandPart_: lC});
function hC(n) {
var t;
if (Array.isArray(n)) {
t = false, E(n != null && n.length > 0, function() {
return "Gram-Schmidt process: input must not be null, undefined, or empty";
});
for (var e = n[0].shape[0], r = function(c) {
E(n[c].shape[0] === e, function() {
return "Gram-Schmidt: Non-unique lengths found in the input vectors: " + ("(" + n[c].shape[0] + " vs. " + e + ")");
});
}, i = 1; i < n.length; ++i)
r(i);
} else
t = true, n = zi(n, n.shape[0], 0).map(function(c) {
return eo(c, [0]);
});
E(n.length <= n[0].shape[0], function() {
return "Gram-Schmidt: Number of vectors (" + n.length + ") exceeds " + ("number of dimensions (" + n[0].shape[0] + ").");
});
for (var a = [], s = n, o = function(c) {
a.push(z.tidy(function() {
var l = s[c];
if (c > 0)
for (var u = 0; u < c; ++u) {
var h = Z(_e(Z(a[u], l)), a[u]);
l = be(l, h);
}
return Ne(l, no(l, "euclidean"));
}));
}, i = 0; i < n.length; ++i)
o(i);
return t ? Zr(a, 0) : a;
}
var dC = U({gramSchmidt_: hC});
function pC(n, t) {
if (t === void 0 && (t = false), E(n.rank >= 2, function() {
return "qr() requires input tensor to have a rank >= 2, but got rank " + n.rank;
}), n.rank === 2)
return T0(n, t);
var e = n.shape.slice(0, n.shape.length - 2).reduce(function(c, l) {
return c * l;
}), r = to(Y(n, [e, n.shape[n.shape.length - 2], n.shape[n.shape.length - 1]]), 0), i = [], a = [];
r.forEach(function(c) {
var l = T0(c, t), u = l[0], h = l[1];
i.push(u), a.push(h);
});
var s = Y(Zr(i, 0), n.shape), o = Y(Zr(a, 0), n.shape);
return [s, o];
}
function T0(n, t) {
return t === void 0 && (t = false), z.tidy(function() {
E(n.shape.length === 2, function() {
return "qr2d() requires a 2D Tensor, but got a " + n.shape.length + "D Tensor.";
});
for (var e = n.shape[0], r = n.shape[1], i = Ag(e), a = Mr(n), s = Fa([[1]], [1, 1]), o = Mr(s), c = e >= r ? r : e, l = function(h) {
var d, p = a, f = o, m = i;
d = z.tidy(function() {
var g = Me(a, [h, h], [e - h, 1]), y = no(g), w = Me(a, [h, h], [1, 1]), b = gn(vr(w, 0), Fa([[-1]]), Fa([[1]])), x = be(w, Z(b, y)), L = Ne(g, x);
L.shape[0] === 1 ? o = Mr(s) : o = Et([s, Me(L, [1, 0], [L.shape[0] - 1, L.shape[1]])], 0);
var N = xt(Ne(Ue(b, x), y)), I = Me(a, [h, 0], [e - h, r]), C = Z(N, o), O = Tt(o);
if (h === 0)
a = be(I, Ue(C, Ue(O, I)));
else {
var D = be(I, Ue(C, Ue(O, I)));
a = Et([Me(a, [0, 0], [h, r]), D], 0);
}
var F = Tt(C), k = Me(i, [0, h], [e, i.shape[1] - h]);
if (h === 0)
i = be(k, Ue(Ue(k, o), F));
else {
var B = be(k, Ue(Ue(k, o), F));
i = Et([Me(i, [0, 0], [e, h]), B], 1);
}
return [o, a, i];
}), o = d[0], a = d[1], i = d[2], Pt([p, f, m]);
}, u = 0; u < c; ++u)
l(u);
return !t && e > r && (i = Me(i, [0, 0], [e, r]), a = Me(a, [0, 0], [r, r])), [i, a];
});
}
var fC = U({qr_: pC});
(function(n) {
n[n.NONE = 0] = "NONE", n[n.MEAN = 1] = "MEAN", n[n.SUM = 2] = "SUM", n[n.SUM_BY_NONZERO_WEIGHTS = 3] = "SUM_BY_NONZERO_WEIGHTS";
})(A.Reduction || (A.Reduction = {}));
function mC(n, t, e) {
e === void 0 && (e = A.Reduction.SUM_BY_NONZERO_WEIGHTS);
var r = R(n, "losses", "computeWeightedLoss"), i = null;
t != null && (i = R(t, "weights", "computeWeightedLoss"));
var a = i == null ? r : Z(r, i);
if (e === A.Reduction.NONE)
return a;
if (e === A.Reduction.SUM)
return _e(a);
if (e === A.Reduction.MEAN) {
if (i == null)
return Oa(a);
var s = r.size / i.size, o = Ne(_e(a), _e(i));
return s > 1 ? Ne(o, Le(s)) : o;
}
if (e === A.Reduction.SUM_BY_NONZERO_WEIGHTS) {
if (i == null)
return Ne(_e(a), Le(r.size));
var c = Z(i, Wi(r.shape)), l = he(_e($s(c, Le(0))), "float32");
return Ne(_e(a), l);
}
throw Error("Unknown reduction: " + e);
}
var Zn = U({computeWeightedLoss_: mC});
function gC(n, t, e, r) {
r === void 0 && (r = A.Reduction.SUM_BY_NONZERO_WEIGHTS);
var i = R(n, "labels", "absoluteDifference"), a = R(t, "predictions", "absoluteDifference"), s = null;
e != null && (s = R(e, "weights", "absoluteDifference")), Pe(i.shape, a.shape, "Error in absoluteDifference: ");
var o = $t(be(i, a));
return Zn(o, s, r);
}
var yC = U({absoluteDifference_: gC});
function vC(n, t, e, r, i) {
i === void 0 && (i = A.Reduction.SUM_BY_NONZERO_WEIGHTS);
var a = R(n, "labels", "cosineDistance"), s = R(t, "predictions", "cosineDistance"), o = null;
r != null && (o = R(r, "weights", "cosineDistance")), Pe(a.shape, s.shape, "Error in cosineDistance: ");
var c = Le(1), l = be(c, _e(Z(a, s), e, true));
return Zn(l, o, i);
}
var wC = U({cosineDistance_: vC});
function bC(n, t, e, r) {
r === void 0 && (r = A.Reduction.SUM_BY_NONZERO_WEIGHTS);
var i = R(n, "labels", "hingeLoss"), a = R(t, "predictions", "hingeLoss"), s = null;
e != null && (s = R(e, "weights", "hingeLoss")), Pe(i.shape, a.shape, "Error in hingeLoss: ");
var o = Le(1);
i = be(Z(Le(2), i), o);
var c = Da(be(o, Z(i, a)));
return Zn(c, s, r);
}
var xC = U({hingeLoss_: bC});
function LC(n, t, e, r, i) {
r === void 0 && (r = 1), i === void 0 && (i = A.Reduction.SUM_BY_NONZERO_WEIGHTS);
var a = R(n, "labels", "huberLoss"), s = R(t, "predictions", "huberLoss"), o = null;
e != null && (o = R(e, "weights", "huberLoss")), Pe(a.shape, s.shape, "Error in huberLoss: ");
var c = Le(r), l = $t(be(s, a)), u = js(l, c), h = be(l, u), d = ge(Z(Le(0.5), $e(u)), Z(c, h));
return Zn(d, o, i);
}
var SC = U({huberLoss_: LC});
function IC(n, t, e, r, i) {
r === void 0 && (r = 1e-7), i === void 0 && (i = A.Reduction.SUM_BY_NONZERO_WEIGHTS);
var a = R(n, "labels", "logLoss"), s = R(t, "predictions", "logLoss"), o = null;
e != null && (o = R(e, "weights", "logLoss")), Pe(a.shape, s.shape, "Error in logLoss: ");
var c = Le(1), l = Le(r), u = xt(Z(a, Yr(ge(s, l)))), h = Z(be(c, a), Yr(ge(be(c, s), l))), d = be(u, h);
return Zn(d, o, i);
}
var AC = U({logLoss_: IC});
function TC(n, t, e, r) {
r === void 0 && (r = A.Reduction.SUM_BY_NONZERO_WEIGHTS);
var i = R(n, "labels", "meanSquaredError"), a = R(t, "predictions", "meanSquaredError"), s = null;
e != null && (s = R(e, "weights", "meanSquaredError")), Pe(i.shape, a.shape, "Error in meanSquaredError: ");
var o = Qs(i, a);
return Zn(o, s, r);
}
var NC = U({meanSquaredError_: TC});
function _C(n, t) {
var e = R(n, "labels", "sigmoidCrossEntropyWithLogits"), r = R(t, "logits", "sigmoidCrossEntropyWithLogits");
Pe(e.shape, r.shape, "Error in sigmoidCrossEntropyWithLogits: ");
var i = Da(r), a = Z(r, e), s = Vu(yn(xt($t(r))));
return ge(be(i, a), s);
}
function CC(n, t, e, r, i) {
r === void 0 && (r = 0), i === void 0 && (i = A.Reduction.SUM_BY_NONZERO_WEIGHTS);
var a = R(n, "multiClassLabels", "sigmoidCrossEntropy"), s = R(t, "logits", "sigmoidCrossEntropy"), o = null;
if (e != null && (o = R(e, "weights", "sigmoidCrossEntropy")), Pe(a.shape, s.shape, "Error in sigmoidCrossEntropy: "), r > 0) {
var c = Le(r), l = Le(1), u = Le(0.5);
a = ge(Z(a, be(l, c)), Z(u, c));
}
var h = _C(a, s);
return Zn(h, o, i);
}
var RC = U({sigmoidCrossEntropy_: CC});
function OC(n, t, e) {
if (e === void 0 && (e = -1), e === -1 && (e = t.rank - 1), e !== t.rank - 1)
throw Error("Softmax cross entropy along a non-last dimension is not yet " + ("supported. Labels / logits was rank " + t.rank + " ") + ("and dim was " + e));
var r = En(function(i, a, s) {
var o = true, c = qu(a, [e], o), l = be(he(a, "float32"), c);
s([i, l]);
var u = xt(Z(l, i)), h = _e(u, [e]), d = function(p, f) {
var m = f[0], g = f[1], y = an(p.shape, [e]);
return [Z(Y(p, y), be(he(m, "float32"), yn(g))), Z(Y(p, y), be(yn(g), he(m, "float32")))];
};
return {value: h, gradFunc: d};
});
return r(n, t);
}
function EC(n, t, e, r, i) {
r === void 0 && (r = 0), i === void 0 && (i = A.Reduction.SUM_BY_NONZERO_WEIGHTS);
var a = R(n, "onehotLabels", "softmaxCrossEntropy"), s = R(t, "logits", "softmaxCrossEntropy"), o = null;
if (e != null && (o = R(e, "weights", "softmaxCrossEntropy")), Pe(a.shape, s.shape, "Error in softmaxCrossEntropy: "), r > 0) {
var c = Le(r), l = Le(1), u = Le(a.shape[1]);
a = ge(Z(a, be(l, c)), Ne(c, u));
}
var h = OC(a, s);
return Zn(h, o, i);
}
var DC = U({softmaxCrossEntropy_: EC});
var kC = {fft: Js, ifft: ka, rfft: Zs, irfft: ih}, FC = {hammingWindow: E_, hannWindow: v0, frame: w0, stft: W_}, WC = {flipLeftRight: P_, resizeNearestNeighbor: A0, resizeBilinear: I0, rotateWithOffset: H_, cropAndResize: B_, nonMaxSuppression: G_, nonMaxSuppressionAsync: Z_, nonMaxSuppressionWithScore: eC, nonMaxSuppressionWithScoreAsync: nC, nonMaxSuppressionPadded: iC, nonMaxSuppressionPaddedAsync: sC}, UC = {bandPart: uC, gramSchmidt: dC, qr: fC}, BC = {absoluteDifference: yC, computeWeightedLoss: Zn, cosineDistance: wC, hingeLoss: xC, huberLoss: SC, logLoss: AC, meanSquaredError: NC, sigmoidCrossEntropy: RC, softmaxCrossEntropy: DC};
var wr = function(n) {
Yn(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.minimize = function(e, r, i) {
r === void 0 && (r = false);
var a = this.computeGradients(e, i), s = a.value, o = a.grads;
if (i != null) {
var c = i.map(function(l) {
return {name: l.name, tensor: o[l.name]};
});
this.applyGradients(c);
} else
this.applyGradients(o);
return Pt(o), r ? s : (s.dispose(), null);
}, Object.defineProperty(t.prototype, "iterations", {get: function() {
return this.iterations_ == null && (this.iterations_ = 0), this.iterations_;
}, enumerable: true, configurable: true}), t.prototype.incrementIterations = function() {
this.iterations_ = this.iterations + 1;
}, t.prototype.computeGradients = function(e, r) {
return Eg(e, r);
}, t.prototype.dispose = function() {
this.iterations_ != null && Pt(this.iterations_);
}, t.prototype.saveIterations = function() {
return pe(this, void 0, void 0, function() {
return fe(this, function(e) {
return this.iterations_ == null && (this.iterations_ = 0), [2, {name: "iter", tensor: Le(this.iterations_, "int32")}];
});
});
}, t.prototype.getWeights = function() {
return pe(this, void 0, void 0, function() {
return fe(this, function(e) {
throw new Error("getWeights() is not implemented for this optimizer yet.");
});
});
}, t.prototype.setWeights = function(e) {
return pe(this, void 0, void 0, function() {
return fe(this, function(r) {
throw new Error("setWeights() is not implemented for this optimizer class " + ("" + this.getClassName()));
});
});
}, t.prototype.extractIterations = function(e) {
return pe(this, void 0, void 0, function() {
var r;
return fe(this, function(i) {
switch (i.label) {
case 0:
return r = this, [4, e[0].tensor.data()];
case 1:
return r.iterations_ = i.sent()[0], [2, e.slice(1)];
}
});
});
}, t;
}($m);
Object.defineProperty(wr, Symbol.hasInstance, {value: function(n) {
return n.minimize != null && n.computeGradients != null && n.applyGradients != null;
}});
var lh = function(n) {
Yn(t, n);
function t(e, r, i) {
i === void 0 && (i = null);
var a = n.call(this) || this;
return a.learningRate = e, a.rho = r, a.epsilon = i, a.accumulatedGrads = [], a.accumulatedUpdates = [], i == null && (a.epsilon = z.backend.epsilon()), a;
}
return t.prototype.applyGradients = function(e) {
var r = this, i = Array.isArray(e) ? e.map(function(a) {
return a.name;
}) : Object.keys(e);
i.forEach(function(a, s) {
var o = z.registeredVariables[a], c = false;
r.accumulatedGrads[s] == null && (r.accumulatedGrads[s] = {originalName: a + "/accum_grad", variable: wt(function() {
return ke(o).variable(c);
})}), r.accumulatedUpdates[s] == null && (r.accumulatedUpdates[s] = {originalName: a + "/accum_var", variable: wt(function() {
return ke(o).variable(c);
})});
var l = Array.isArray(e) ? e[s].tensor : e[a];
if (l == null)
return;
var u = r.accumulatedGrads[s].variable, h = r.accumulatedUpdates[s].variable;
wt(function() {
var d = ge(Z(u, r.rho), Z($e(l), 1 - r.rho)), p = Z(Ne(Ht(ge(h, r.epsilon)), Ht(ge(u, r.epsilon))), l), f = ge(Z(h, r.rho), Z($e(p), 1 - r.rho));
u.assign(d), h.assign(f);
var m = ge(Z(p, -r.learningRate), o);
o.assign(m);
});
}), this.incrementIterations();
}, t.prototype.dispose = function() {
this.accumulatedUpdates != null && (Pt(this.accumulatedGrads.map(function(e) {
return e.variable;
})), Pt(this.accumulatedUpdates.map(function(e) {
return e.variable;
})));
}, t.prototype.getWeights = function() {
return pe(this, void 0, void 0, function() {
var e;
return fe(this, function(r) {
switch (r.label) {
case 0:
return e = this.accumulatedGrads.concat(this.accumulatedUpdates), [4, this.saveIterations()];
case 1:
return [2, [r.sent()].concat(e.map(function(i) {
return {name: i.originalName, tensor: i.variable};
}))];
}
});
});
}, t.prototype.setWeights = function(e) {
return pe(this, void 0, void 0, function() {
var r, i;
return fe(this, function(a) {
switch (a.label) {
case 0:
return [4, this.extractIterations(e)];
case 1:
return e = a.sent(), r = e.length / 2, i = false, this.accumulatedGrads = e.slice(0, r).map(function(s) {
return {originalName: s.name, variable: s.tensor.variable(i)};
}), this.accumulatedUpdates = e.slice(r, r * 2).map(function(s) {
return {originalName: s.name, variable: s.tensor.variable(i)};
}), [2];
}
});
});
}, t.prototype.getConfig = function() {
return {learningRate: this.learningRate, rho: this.rho, epsilon: this.epsilon};
}, t.fromConfig = function(e, r) {
return new e(r.learningRate, r.rho, r.epsilon);
}, t.className = "Adadelta", t;
}(wr);
gr(lh);
var uh = function(n) {
Yn(t, n);
function t(e, r) {
r === void 0 && (r = 0.1);
var i = n.call(this) || this;
return i.learningRate = e, i.initialAccumulatorValue = r, i.accumulatedGrads = [], i;
}
return t.prototype.applyGradients = function(e) {
var r = this, i = Array.isArray(e) ? e.map(function(a) {
return a.name;
}) : Object.keys(e);
i.forEach(function(a, s) {
var o = z.registeredVariables[a];
if (r.accumulatedGrads[s] == null) {
var c = false;
r.accumulatedGrads[s] = {originalName: a + "/accumulator", variable: wt(function() {
return Mu(o.shape, r.initialAccumulatorValue).variable(c);
})};
}
var l = Array.isArray(e) ? e[s].tensor : e[a];
if (l == null)
return;
var u = r.accumulatedGrads[s].variable;
wt(function() {
var h = ge(u, $e(l));
u.assign(h);
var d = ge(Z(Ne(l, Ht(ge(h, z.backend.epsilon()))), -r.learningRate), o);
o.assign(d);
});
}), this.incrementIterations();
}, t.prototype.dispose = function() {
this.accumulatedGrads != null && Pt(this.accumulatedGrads.map(function(e) {
return e.variable;
}));
}, t.prototype.getWeights = function() {
return pe(this, void 0, void 0, function() {
return fe(this, function(e) {
switch (e.label) {
case 0:
return [4, this.saveIterations()];
case 1:
return [2, [e.sent()].concat(this.accumulatedGrads.map(function(r) {
return {name: r.originalName, tensor: r.variable};
}))];
}
});
});
}, t.prototype.setWeights = function(e) {
return pe(this, void 0, void 0, function() {
var r;
return fe(this, function(i) {
switch (i.label) {
case 0:
return [4, this.extractIterations(e)];
case 1:
return e = i.sent(), r = false, this.accumulatedGrads = e.map(function(a) {
return {originalName: a.name, variable: a.tensor.variable(r)};
}), [2];
}
});
});
}, t.prototype.getConfig = function() {
return {learningRate: this.learningRate, initialAccumulatorValue: this.initialAccumulatorValue};
}, t.fromConfig = function(e, r) {
return new e(r.learningRate, r.initialAccumulatorValue);
}, t.className = "Adagrad", t;
}(wr);
gr(uh);
var hh = function(n) {
Yn(t, n);
function t(e, r, i, a) {
a === void 0 && (a = null);
var s = n.call(this) || this;
return s.learningRate = e, s.beta1 = r, s.beta2 = i, s.epsilon = a, s.accumulatedFirstMoment = [], s.accumulatedSecondMoment = [], wt(function() {
s.accBeta1 = Le(r).variable(), s.accBeta2 = Le(i).variable();
}), a == null && (s.epsilon = z.backend.epsilon()), s;
}
return t.prototype.applyGradients = function(e) {
var r = this, i = Array.isArray(e) ? e.map(function(a) {
return a.name;
}) : Object.keys(e);
wt(function() {
var a = be(1, r.accBeta1), s = be(1, r.accBeta2);
i.forEach(function(o, c) {
var l = z.registeredVariables[o], u = false;
r.accumulatedFirstMoment[c] == null && (r.accumulatedFirstMoment[c] = {originalName: o + "/m", variable: wt(function() {
return ke(l).variable(u);
})}), r.accumulatedSecondMoment[c] == null && (r.accumulatedSecondMoment[c] = {originalName: o + "/v", variable: wt(function() {
return ke(l).variable(u);
})});
var h = Array.isArray(e) ? e[c].tensor : e[o];
if (h == null)
return;
var d = r.accumulatedFirstMoment[c].variable, p = r.accumulatedSecondMoment[c].variable, f = ge(Z(d, r.beta1), Z(h, 1 - r.beta1)), m = ge(Z(p, r.beta2), Z($e(h), 1 - r.beta2)), g = Ne(f, a), y = Ne(m, s);
d.assign(f), p.assign(m);
var w = ge(Z(Ne(g, ge(Ht(y), r.epsilon)), -r.learningRate), l);
l.assign(w);
}), r.accBeta1.assign(Z(r.accBeta1, r.beta1)), r.accBeta2.assign(Z(r.accBeta2, r.beta2));
}), this.incrementIterations();
}, t.prototype.dispose = function() {
this.accBeta1.dispose(), this.accBeta2.dispose(), this.accumulatedFirstMoment != null && Pt(this.accumulatedFirstMoment.map(function(e) {
return e.variable;
})), this.accumulatedSecondMoment != null && Pt(this.accumulatedSecondMoment.map(function(e) {
return e.variable;
}));
}, t.prototype.getWeights = function() {
return pe(this, void 0, void 0, function() {
var e;
return fe(this, function(r) {
switch (r.label) {
case 0:
return e = this.accumulatedFirstMoment.concat(this.accumulatedSecondMoment), [4, this.saveIterations()];
case 1:
return [2, [r.sent()].concat(e.map(function(i) {
return {name: i.originalName, tensor: i.variable};
}))];
}
});
});
}, t.prototype.setWeights = function(e) {
return pe(this, void 0, void 0, function() {
var r, i, a = this;
return fe(this, function(s) {
switch (s.label) {
case 0:
return [4, this.extractIterations(e)];
case 1:
return e = s.sent(), wt(function() {
a.accBeta1.assign(Xn(a.beta1, a.iterations_ + 1)), a.accBeta2.assign(Xn(a.beta2, a.iterations_ + 1));
}), r = e.length / 2, i = false, this.accumulatedFirstMoment = e.slice(0, r).map(function(o) {
return {originalName: o.name, variable: o.tensor.variable(i)};
}), this.accumulatedSecondMoment = e.slice(r, r * 2).map(function(o) {
return {originalName: o.name, variable: o.tensor.variable(i)};
}), [2];
}
});
});
}, t.prototype.getConfig = function() {
return {learningRate: this.learningRate, beta1: this.beta1, beta2: this.beta2, epsilon: this.epsilon};
}, t.fromConfig = function(e, r) {
return new e(r.learningRate, r.beta1, r.beta2, r.epsilon);
}, t.className = "Adam", t;
}(wr);
gr(hh);
var dh = function(n) {
Yn(t, n);
function t(e, r, i, a, s) {
a === void 0 && (a = null), s === void 0 && (s = 0);
var o = n.call(this) || this;
return o.learningRate = e, o.beta1 = r, o.beta2 = i, o.epsilon = a, o.decay = s, o.accumulatedFirstMoment = [], o.accumulatedWeightedInfNorm = [], wt(function() {
o.iteration = Le(0).variable(), o.accBeta1 = Le(r).variable();
}), a == null && (o.epsilon = z.backend.epsilon()), o;
}
return t.prototype.applyGradients = function(e) {
var r = this, i = Array.isArray(e) ? e.map(function(a) {
return a.name;
}) : Object.keys(e);
wt(function() {
var a = be(1, r.accBeta1), s = Ne(-r.learningRate, ge(Z(r.iteration, r.decay), 1));
i.forEach(function(o, c) {
var l = z.registeredVariables[o], u = false;
r.accumulatedFirstMoment[c] == null && (r.accumulatedFirstMoment[c] = {originalName: o + "/m", variable: ke(l).variable(u)}), r.accumulatedWeightedInfNorm[c] == null && (r.accumulatedWeightedInfNorm[c] = {originalName: o + "/v", variable: ke(l).variable(u)});
var h = Array.isArray(e) ? e[c].tensor : e[o];
if (h == null)
return;
var d = r.accumulatedFirstMoment[c].variable, p = r.accumulatedWeightedInfNorm[c].variable, f = ge(Z(d, r.beta1), Z(h, 1 - r.beta1)), m = Z(p, r.beta2), g = $t(h), y = Fi(m, g);
d.assign(f), p.assign(y);
var w = ge(Z(Ne(s, a), Ne(f, ge(y, r.epsilon))), l);
l.assign(w);
}), r.iteration.assign(ge(r.iteration, 1)), r.accBeta1.assign(Z(r.accBeta1, r.beta1));
}), this.incrementIterations();
}, t.prototype.dispose = function() {
this.accBeta1.dispose(), this.iteration.dispose(), this.accumulatedFirstMoment != null && Pt(this.accumulatedFirstMoment.map(function(e) {
return e.variable;
})), this.accumulatedWeightedInfNorm != null && Pt(this.accumulatedWeightedInfNorm.map(function(e) {
return e.variable;
}));
}, t.prototype.getWeights = function() {
return pe(this, void 0, void 0, function() {
return fe(this, function(e) {
throw new Error("getWeights() is not implemented for Adamax yet.");
});
});
}, t.prototype.setWeights = function(e) {
return pe(this, void 0, void 0, function() {
return fe(this, function(r) {
throw new Error("setWeights() is not implemented for Adamax yet.");
});
});
}, t.prototype.getConfig = function() {
return {learningRate: this.learningRate, beta1: this.beta1, beta2: this.beta2, epsilon: this.epsilon, decay: this.decay};
}, t.fromConfig = function(e, r) {
return new e(r.learningRate, r.beta1, r.beta2, r.epsilon, r.decay);
}, t.className = "Adamax", t;
}(wr);
gr(dh);
var oo = function(n) {
Yn(t, n);
function t(e) {
var r = n.call(this) || this;
return r.learningRate = e, r.setLearningRate(e), r;
}
return t.prototype.applyGradients = function(e) {
var r = this, i = Array.isArray(e) ? e.map(function(a) {
return a.name;
}) : Object.keys(e);
i.forEach(function(a, s) {
var o = Array.isArray(e) ? e[s].tensor : e[a];
if (o == null)
return;
var c = z.registeredVariables[a];
wt(function() {
var l = ge(Z(r.c, o), c);
c.assign(l);
});
}), this.incrementIterations();
}, t.prototype.setLearningRate = function(e) {
this.learningRate = e, this.c != null && this.c.dispose(), this.c = Zm(Le(-e));
}, t.prototype.dispose = function() {
this.c.dispose();
}, t.prototype.getWeights = function() {
return pe(this, void 0, void 0, function() {
return fe(this, function(e) {
switch (e.label) {
case 0:
return [4, this.saveIterations()];
case 1:
return [2, [e.sent()]];
}
});
});
}, t.prototype.setWeights = function(e) {
return pe(this, void 0, void 0, function() {
return fe(this, function(r) {
switch (r.label) {
case 0:
return [4, this.extractIterations(e)];
case 1:
if (e = r.sent(), e.length !== 0)
throw new Error("SGD optimizer does not have settable weights.");
return [2];
}
});
});
}, t.prototype.getConfig = function() {
return {learningRate: this.learningRate};
}, t.fromConfig = function(e, r) {
return new e(r.learningRate);
}, t.className = "SGD", t;
}(wr);
gr(oo);
var ph = function(n) {
Yn(t, n);
function t(e, r, i) {
i === void 0 && (i = false);
var a = n.call(this, e) || this;
return a.learningRate = e, a.momentum = r, a.useNesterov = i, a.accumulations = [], a.m = Le(a.momentum), a;
}
return t.prototype.applyGradients = function(e) {
var r = this, i = Array.isArray(e) ? e.map(function(a) {
return a.name;
}) : Object.keys(e);
i.forEach(function(a, s) {
var o = z.registeredVariables[a];
if (r.accumulations[s] == null) {
var c = false;
r.accumulations[s] = {originalName: a + "/momentum", variable: wt(function() {
return ke(o).variable(c);
})};
}
var l = r.accumulations[s].variable, u = Array.isArray(e) ? e[s].tensor : e[a];
if (u == null)
return;
wt(function() {
var h, d = ge(Z(r.m, l), u);
r.useNesterov ? h = ge(Z(r.c, ge(u, Z(d, r.m))), o) : h = ge(Z(r.c, d), o), l.assign(d), o.assign(h);
});
}), this.incrementIterations();
}, t.prototype.dispose = function() {
this.m.dispose(), this.accumulations != null && Pt(this.accumulations.map(function(e) {
return e.variable;
}));
}, t.prototype.setMomentum = function(e) {
this.momentum = e;
}, t.prototype.getWeights = function() {
return pe(this, void 0, void 0, function() {
return fe(this, function(e) {
switch (e.label) {
case 0:
return [4, this.saveIterations()];
case 1:
return [2, [e.sent()].concat(this.accumulations.map(function(r) {
return {name: r.originalName, tensor: r.variable};
}))];
}
});
});
}, t.prototype.setWeights = function(e) {
return pe(this, void 0, void 0, function() {
var r;
return fe(this, function(i) {
switch (i.label) {
case 0:
return [4, this.extractIterations(e)];
case 1:
return e = i.sent(), r = false, this.accumulations = e.map(function(a) {
return {originalName: a.name, variable: a.tensor.variable(r)};
}), [2];
}
});
});
}, t.prototype.getConfig = function() {
return {learningRate: this.learningRate, momentum: this.momentum, useNesterov: this.useNesterov};
}, t.fromConfig = function(e, r) {
return new e(r.learningRate, r.momentum, r.useNesterov);
}, t.className = "Momentum", t;
}(oo);
gr(ph);
var fh = function(n) {
Yn(t, n);
function t(e, r, i, a, s) {
r === void 0 && (r = 0.9), i === void 0 && (i = 0), a === void 0 && (a = null), s === void 0 && (s = false);
var o = n.call(this) || this;
if (o.learningRate = e, o.decay = r, o.momentum = i, o.epsilon = a, o.accumulatedMeanSquares = [], o.accumulatedMoments = [], o.accumulatedMeanGrads = [], o.centered = s, a == null && (o.epsilon = z.backend.epsilon()), e == null)
throw new Error("learningRate for RMSPropOptimizer must be defined.");
return o;
}
return t.prototype.applyGradients = function(e) {
var r = this, i = Array.isArray(e) ? e.map(function(a) {
return a.name;
}) : Object.keys(e);
i.forEach(function(a, s) {
var o = z.registeredVariables[a], c = false;
r.accumulatedMeanSquares[s] == null && (r.accumulatedMeanSquares[s] = {originalName: a + "/rms", variable: wt(function() {
return ke(o).variable(c);
})}), r.accumulatedMoments[s] == null && (r.accumulatedMoments[s] = {originalName: a + "/momentum", variable: wt(function() {
return ke(o).variable(c);
})}), r.accumulatedMeanGrads[s] == null && r.centered && (r.accumulatedMeanGrads[s] = {originalName: a + "/mg", variable: wt(function() {
return ke(o).variable(c);
})});
var l = Array.isArray(e) ? e[s].tensor : e[a];
if (l == null)
return;
var u = r.accumulatedMeanSquares[s].variable, h = r.accumulatedMoments[s].variable;
wt(function() {
var d = ge(Z(u, r.decay), Z($e(l), 1 - r.decay));
if (r.centered) {
var p = r.accumulatedMeanGrads[s].variable, f = ge(Z(p, r.decay), Z(l, 1 - r.decay)), m = Ne(Z(l, r.learningRate), Ht(be(d, ge($e(f), r.epsilon)))), g = ge(Z(h, r.momentum), m);
u.assign(d), p.assign(f), h.assign(g);
var y = be(o, g);
o.assign(y);
} else {
var w = ge(Z(u, r.decay), Z($e(l), 1 - r.decay)), g = ge(Z(h, r.momentum), Ne(Z(l, r.learningRate), Ht(ge(w, r.epsilon))));
u.assign(w), h.assign(g);
var y = be(o, g);
o.assign(y);
}
});
}), this.incrementIterations();
}, t.prototype.dispose = function() {
this.accumulatedMeanSquares != null && Pt(this.accumulatedMeanSquares.map(function(e) {
return e.variable;
})), this.accumulatedMeanGrads != null && this.centered && Pt(this.accumulatedMeanGrads.map(function(e) {
return e.variable;
})), this.accumulatedMoments != null && Pt(this.accumulatedMoments.map(function(e) {
return e.variable;
}));
}, t.prototype.getWeights = function() {
return pe(this, void 0, void 0, function() {
var e;
return fe(this, function(r) {
switch (r.label) {
case 0:
return e = this.accumulatedMeanSquares.concat(this.accumulatedMoments), this.centered && e.push.apply(e, this.accumulatedMeanGrads), [4, this.saveIterations()];
case 1:
return [2, [r.sent()].concat(e.map(function(i) {
return {name: i.originalName, tensor: i.variable};
}))];
}
});
});
}, t.prototype.setWeights = function(e) {
return pe(this, void 0, void 0, function() {
var r, i;
return fe(this, function(a) {
switch (a.label) {
case 0:
return [4, this.extractIterations(e)];
case 1:
return e = a.sent(), r = this.centered ? e.length / 3 : e.length / 2, i = false, this.accumulatedMeanSquares = e.slice(0, r).map(function(s) {
return {originalName: s.name, variable: s.tensor.variable(i)};
}), this.accumulatedMoments = e.slice(r, r * 2).map(function(s) {
return {originalName: s.name, variable: s.tensor.variable(i)};
}), this.centered && (this.accumulatedMeanGrads = e.slice(r * 2, r * 3).map(function(s) {
return {originalName: s.name, variable: s.tensor.variable(i)};
})), [2];
}
});
});
}, t.prototype.getConfig = function() {
return {learningRate: this.learningRate, decay: this.decay, momentum: this.momentum, epsilon: this.epsilon, centered: this.centered};
}, t.fromConfig = function(e, r) {
return new e(r.learningRate, r.decay, r.momentum, r.epsilon, r.centered);
}, t.className = "RMSProp", t;
}(wr);
gr(fh);
var Qr = function() {
function n() {
}
return n.sgd = function(t) {
return new oo(t);
}, n.momentum = function(t, e, r) {
return r === void 0 && (r = false), new ph(t, e, r);
}, n.rmsprop = function(t, e, r, i, a) {
return e === void 0 && (e = 0.9), r === void 0 && (r = 0), i === void 0 && (i = null), a === void 0 && (a = false), new fh(t, e, r, i, a);
}, n.adam = function(t, e, r, i) {
return t === void 0 && (t = 1e-3), e === void 0 && (e = 0.9), r === void 0 && (r = 0.999), i === void 0 && (i = null), new hh(t, e, r, i);
}, n.adadelta = function(t, e, r) {
return t === void 0 && (t = 1e-3), e === void 0 && (e = 0.95), r === void 0 && (r = null), new lh(t, e, r);
}, n.adamax = function(t, e, r, i, a) {
return t === void 0 && (t = 2e-3), e === void 0 && (e = 0.9), r === void 0 && (r = 0.999), i === void 0 && (i = null), a === void 0 && (a = 0), new dh(t, e, r, i, a);
}, n.adagrad = function(t, e) {
return e === void 0 && (e = 0.1), new uh(t, e);
}, n;
}();
var zC = {sgd: Qr.sgd, momentum: Qr.momentum, adadelta: Qr.adadelta, adagrad: Qr.adagrad, rmsprop: Qr.rmsprop, adamax: Qr.adamax, adam: Qr.adam};
var PC = function() {
return typeof requestAnimationFrame != "undefined" ? requestAnimationFrame : typeof setImmediate != "undefined" ? setImmediate : function(n) {
return n();
};
}();
function MC() {
return new Promise(function(n) {
return PC(function() {
return n();
});
});
}
function HC(n, t, e) {
var r = e * (typeof n == "number" ? n : n[0]), i = t * (typeof n == "number" ? n : n[1]);
return [r, i];
}
function VC(n, t, e, r) {
r === void 0 && (r = true);
var i = [];
if (r)
i = i.concat(t.slice(0)), i.push(n[0] / e), i = i.concat(n.slice(1));
else {
i = i.concat(n[0]);
for (var a = t.length, s = 0; s < a; ++s)
i = i.concat([n[s + 1] / t[s], t[s]]);
i = i.concat(n.slice(a + 1));
}
return i;
}
function GC(n, t, e) {
e === void 0 && (e = true);
var r = [];
if (e) {
r.push(t);
for (var i = t + 1; i < n; ++i)
i <= 2 * t ? (r.push(i), r.push(i - (t + 1))) : r.push(i);
} else {
for (var a = [], s = [], i = 1; i < n; ++i)
i >= t * 2 + 1 || i % 2 === 1 ? s.push(i) : a.push(i);
r.push.apply(r, a), r.push(0), r.push.apply(r, s);
}
return r;
}
function qC(n, t, e, r) {
r === void 0 && (r = true);
var i = [];
r ? i.push(n[0] / e) : i.push(n[0] * e);
for (var a = 1; a < n.length; ++a)
a <= t.length ? r ? i.push(t[a - 1] * n[a]) : i.push(n[a] / t[a - 1]) : i.push(n[a]);
return i;
}
function YC(n, t) {
for (var e = [0], r = 0; r < t; ++r)
e.push(n[r][0]);
return e;
}
function KC(n, t, e) {
for (var r = n.slice(0, 1), i = 0; i < e; ++i)
r.push(n[i + 1] - t[i][0] - t[i][1]);
return r;
}
var N0 = 1.7580993408473768, _0 = 1.0507009873554805;
var jC = 0.3275911, $C = 0.254829592, XC = -0.284496736, JC = 1.421413741, ZC = -1.453152027, QC = 1.061405429;
function eR() {
for (var n = [], t = 0; t < arguments.length; t++)
n[t] = arguments[t];
qe().getBool("IS_TEST") || console.warn.apply(console, n);
}
function tR() {
for (var n = [], t = 0; t < arguments.length; t++)
n[t] = arguments[t];
qe().getBool("IS_TEST") || console.log.apply(console, n);
}
function nR(n, t) {
if (n.length !== t.length)
throw new Error("Cannot merge real and imag arrays of different lengths. real:" + (n.length + ", imag: " + t.length + "."));
for (var e = new Float32Array(n.length * 2), r = 0; r < e.length; r += 2)
e[r] = n[r / 2], e[r + 1] = t[r / 2];
return e;
}
function rR(n) {
for (var t = new Float32Array(n.length / 2), e = new Float32Array(n.length / 2), r = 0; r < n.length; r += 2)
t[r / 2] = n[r], e[r / 2] = n[r + 1];
return {real: t, imag: e};
}
function iR(n) {
for (var t = Math.ceil(n.length / 4), e = new Float32Array(t), r = new Float32Array(t), i = 0; i < n.length; i += 4)
e[Math.floor(i / 4)] = n[i], r[Math.floor(i / 4)] = n[i + 1];
return {real: e, imag: r};
}
function aR(n) {
for (var t = Math.floor(n.length / 4), e = new Float32Array(t), r = new Float32Array(t), i = 2; i < n.length; i += 4)
e[Math.floor(i / 4)] = n[i], r[Math.floor(i / 4)] = n[i + 1];
return {real: e, imag: r};
}
function sR(n, t) {
var e = n[t * 2], r = n[t * 2 + 1];
return {real: e, imag: r};
}
function oR(n, t, e, r) {
n[r * 2] = t, n[r * 2 + 1] = e;
}
function cR(n, t) {
for (var e = new Float32Array(n / 2), r = new Float32Array(n / 2), i = 0; i < Math.ceil(n / 2); i++) {
var a = (t ? 2 : -2) * Math.PI * (i / n);
e[i] = Math.cos(a), r[i] = Math.sin(a);
}
return {real: e, imag: r};
}
function lR(n, t, e) {
var r = (e ? 2 : -2) * Math.PI * (n / t), i = Math.cos(r), a = Math.sin(r);
return {real: i, imag: a};
}
function uR(n, t, e) {
if (t === "complex64") {
if (n.dtype === "complex64")
return n.clone();
var r = $n(n.shape), i = he(n, "float32"), a = e.complex(i, r);
return r.dispose(), i.dispose(), a;
}
if (!Zp(n.dtype, t))
return z.makeTensorFromDataId(n.dataId, n.shape, t);
if (n.dtype === "complex64") {
var s = e.real(n), a = he(s, t);
return s.dispose(), a;
}
if (t === "int32")
return e.int(n);
if (t === "bool") {
var o = Le(0, n.dtype), a = e.notEqual(n, o);
return o.dispose(), a;
} else
throw new Error("Error in Cast: failed to cast " + n.dtype + " to " + t);
}
function hR(n, t) {
return z.makeTensorFromDataId(n.dataId, t, n.dtype);
}
function dR(n, t, e) {
var r = (t - n) / (e - 1), i = Si(e, "float32");
i[0] = n;
for (var a = 1; a < i.length; a++)
i[a] = i[a - 1] + r;
return Bi(i, "float32");
}
var pR = {__proto__: null, slice_util: jm, segment_util: d5, castTensor: uR, reshapeTensor: hR, linspaceImpl: dR, upcastType: Cs, axesAreInnerMostDims: Du, combineLocations: tg, computeOutAndReduceShapes: ng, expandShapeToKeepDim: an, assertAxesAreInnerMostDims: HI, getAxesPermutation: fn, getUndoAxesPermutation: ks, getInnerMostAxes: On, getBroadcastDims: $A, getReductionAxes: bt, assertAndGetBroadcastShape: it, assertParamsConsistent: dg, computeOutShape: pg, computeDilation2DInfo: ZI, computePool2DInfo: Oi, computePool3DInfo: Na, computeConv2DInfo: mn, computeConv3DInfo: Ta, computeDefaultPad: Fu, tupleValuesAreOne: yr, eitherStridesOrDilationsAreOne: Mt, convertConv2DDataFormat: Aa, getFusedDyActivation: ro, getFusedBiasGradient: io, applyActivation: ao, shouldFuse: so, PARALLELIZE_THRESHOLD: Hu, computeOptimalWindowSize: l5, getImageCenter: HC, getReshaped: VC, getPermuted: GC, getReshapedPermuted: qC, getSliceBeginCoords: YC, getSliceSize: KC, prepareAndValidate: Fm, validateUpdateShape: Tu, validateInput: Nu, calculateShapes: Wm, SELU_SCALEALPHA: N0, SELU_SCALE: _0, ERF_P: jC, ERF_A1: $C, ERF_A2: XC, ERF_A3: JC, ERF_A4: ZC, ERF_A5: QC, warn: eR, log: tR, mergeRealAndImagArrays: nR, splitRealAndImagArrays: rR, complexWithEvenIndex: iR, complexWithOddIndex: aR, getComplexWithIndex: sR, assignToTypedArray: oR, exponents: cR, exponent: lR, prepareSplitSize: Yg};
function fR(n, t, e) {
var r = new Array(n.rank).fill(0), i = n.shape.slice();
return t.map(function(a) {
var s = i.slice();
s[e] = a;
var o = Me(n, r, s);
return r[e] += a, o;
});
}
function mR(n, t) {
for (var e = new Array(n.rank), r = 0; r < e.length; r++)
e[r] = n.shape[r] * t[r];
for (var i = Rn(e, n.dtype), r = 0; r < i.values.length; ++r) {
for (var a = i.indexToLoc(r), s = new Array(n.rank), o = 0; o < s.length; o++)
s[o] = a[o] % n.shape[o];
var c = n.locToIndex(s);
i.values[r] = n.values[c];
}
return i.toTensor();
}
function gR(n, t, e, r, i) {
for (var a = t[t.length - 1], s = [n.length / a, a], o = s[0], c = s[1], l = bs(e, o * r), u = bs("int32", o * r), h = 0; h < o; h++) {
for (var d = h * c, p = n.subarray(d, d + c), f = [], m = 0; m < p.length; m++)
f.push({value: p[m], index: m});
f.sort(function(x, L) {
return L.value - x.value;
});
for (var g = h * r, y = l.subarray(g, g + r), w = u.subarray(g, g + r), m = 0; m < r; m++)
y[m] = f[m].value, w[m] = f[m].index;
}
var b = t.slice();
return b[b.length - 1] = r, [pr(l, b, e), pr(u, b, "int32")];
}
var yR = {__proto__: null, nonMaxSuppressionV3Impl: b0, nonMaxSuppressionV4Impl: x0, nonMaxSuppressionV5Impl: L0, split: fR, tile: mR, topkImpl: gR, whereImpl: Jg};
var vR = {kernelName: mc, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Z(n, Pi(he(e, "float32"), -1));
}};
}};
var wR = {kernelName: gc, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
var r = $e(he(e, "float32")), i = Ht(be(Le(1), r));
return xt(Ne(n, i));
}};
}};
var bR = {kernelName: yc, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
var r = Ht(be($e(he(e, "float32")), 1));
return Ne(n, r);
}};
}};
var xR = {kernelName: Ss, inputsToSave: ["a", "b"], gradFunc: function(n, t) {
var e = t[0], r = t[1], i = it(e.shape, r.shape), a = function() {
var o = n, c = bt(e.shape, i);
return c.length > 0 && (o = _e(o, c)), Y(o, e.shape);
}, s = function() {
var o = n, c = bt(r.shape, i);
return c.length > 0 && (o = _e(o, c)), Y(o, r.shape);
};
return {a, b: s};
}};
var LR = {kernelName: vc, saveAllInputs: true, gradFunc: function(n, t) {
var e = {};
return t.forEach(function(r, i) {
e[i] = function() {
return n.clone();
};
}), e;
}};
var SR = {kernelName: wc, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return ke(e);
}};
}};
var IR = {kernelName: bc, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return ke(e);
}};
}};
var AR = {kernelName: xc, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Ne(n, Ht(be(Le(1), $e(he(e, "float32")))));
}};
}};
var TR = {kernelName: Lc, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
var r = Ht(ge(Le(1), $e(he(e, "float32"))));
return Ne(n, r);
}};
}};
var NR = {kernelName: Ac, inputsToSave: ["a", "b"], gradFunc: function(n, t) {
var e = t[0], r = t[1], i = it(e.shape, r.shape), a = function() {
var o = ge($e(e), $e(r)), c = Z(n, Ne(r, o)), l = bt(e.shape, i);
return l.length > 0 && (c = _e(c, l)), Y(c, e.shape);
}, s = function() {
var o = ge($e(e), $e(r)), c = xt(Z(n, Ne(e, o))), l = bt(r.shape, i);
return l.length > 0 && (c = _e(c, l)), Y(c, r.shape);
};
return {a, b: s};
}};
var _R = {kernelName: Sc, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Ne(n, ge($e(he(e, "float32")), 1));
}};
}};
var CR = {kernelName: Ic, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Ne(n, be(Le(1), $e(he(e, "float32"))));
}};
}};
function RR(n, t, e, r, i, a, s) {
i === void 0 && (i = [1, 1, 1]);
var o = R(n, "dy", "avgPool3dBackprop"), c = R(t, "input", "avgPool3dBackprop"), l = o, u = c, h = false;
c.rank === 4 && (h = true, l = Y(o, [1, o.shape[0], o.shape[1], o.shape[2], o.shape[3]]), u = Y(c, [1, c.shape[0], c.shape[1], c.shape[2], c.shape[3]])), E(l.rank === 5, function() {
return "Error in avgPool3dBackprop: dy must be rank 5 but got rank " + (l.rank + ".");
}), E(u.rank === 5, function() {
return "Error in avgPool3dBackprop: input must be rank 5 but got rank " + (u.rank + ".");
}), E(Mt(r, i), function() {
return "Error in avgPool3dBackprop: Either strides or dilations " + ("must be 1. Got strides " + r + " and dilations '" + i + "'");
}), s != null && E(ot(a), function() {
return "Error in maxPool3dBackprop: pad must be an integer when " + ("using, dimRoundingMode " + s + " but got pad " + a + ".");
});
var d = function(g) {
var y = Na(u.shape, e, r, i, a, s);
return g.avgPool3dBackprop(l, u, y);
}, p = {dy: l, input: u}, f = {filterSize: e, strides: r, dilations: i, pad: a, dimRoundingMode: s}, m = z.runKernelFunc(d, p, null, df, f);
return h ? Y(m, [m.shape[1], m.shape[2], m.shape[3], m.shape[4]]) : m;
}
var OR = U({avgPool3dBackprop_: RR});
var ER = {kernelName: Nc, inputsToSave: ["x"], gradFunc: function(n, t, e) {
var r = t[0], i = e, a = i.filterSize, s = i.strides, o = i.dilations, c = i.pad, l = i.dimRoundingMode, u = o != null ? o : [1, 1, 1];
return {x: function() {
return OR(n, r, a, s, u, c, l);
}};
}};
function DR(n, t, e, r, i) {
var a = R(n, "dy", "avgPoolBackprop"), s = R(t, "input", "avgPoolBackprop");
E(s.rank === a.rank, function() {
return "Rank of input (" + s.rank + ") does not match rank of dy (" + a.rank + ")";
});
var o = s, c = a, l = false;
s.rank === 3 && (l = true, o = Y(s, [1, s.shape[0], s.shape[1], s.shape[2]]), c = Y(a, [1, a.shape[0], a.shape[1], a.shape[2]])), E(c.rank === 4, function() {
return "Error in avgPoolBackprop: dy must be rank 4 but got rank " + (c.rank + ".");
}), E(o.rank === 4, function() {
return "Error in avgPoolBackprop: input must be rank 4 but got rank " + (o.rank + ".");
});
var u = function(f) {
var m = Oi(o.shape, e, r, 1, i);
return f.avgPoolBackprop(c, o, m);
}, h = {dy: c, input: o}, d = {filterSize: e, strides: r, pad: i}, p = z.runKernelFunc(u, h, null, hf, d);
return l ? Y(p, [p.shape[1], p.shape[2], p.shape[3]]) : p;
}
var kR = U({avgPoolBackprop_: DR});
var FR = {kernelName: Tc, inputsToSave: ["x"], gradFunc: function(n, t, e) {
var r = t[0], i = e, a = i.filterSize, s = i.strides, o = i.pad;
return {x: function() {
return kR(n, r, a, s, o);
}};
}};
var WR = {kernelName: _c, inputsToSave: ["a", "b"], gradFunc: function(n, t, e) {
var r = t[0], i = t[1], a = e, s = a.transposeA, o = a.transposeB;
return !s && !o ? {a: function() {
return Ue(n, i, false, true);
}, b: function() {
return Ue(r, n, true, false);
}} : !s && o ? {a: function() {
return Ue(n, i, false, false);
}, b: function() {
return Ue(n, r, true, false);
}} : s && !o ? {a: function() {
return Ue(i, n, false, true);
}, b: function() {
return Ue(r, n, false, false);
}} : {a: function() {
return Ue(i, n, true, true);
}, b: function() {
return Ue(n, r, true, true);
}};
}};
var UR = {kernelName: Cc, gradFunc: function(n, t, e) {
var r = e, i = r.blockShape, a = r.crops;
return {x: function() {
return Xs(n, i, a);
}};
}};
var BR = {kernelName: Rc, gradFunc: function(n, t, e) {
for (var r = e, i = r.inputShape, a = r.shape, s = Array.from(a), o = i.length - 1; o >= 0; o--)
if (i[o] === a[o])
s[o] = 1;
else if (i[o] !== 1)
throw new Error("broadcastTo(): [" + i + "] cannot be broadcast to [" + a + "].");
for (var c = [], o = 0; o < s.length; o++)
s[o] > 1 && c.push(o);
return {x: function() {
return _e(n, c, true);
}};
}};
var zR = {kernelName: Is, gradFunc: function(n) {
return {x: function() {
return n.clone();
}};
}};
var PR = {kernelName: Oc, gradFunc: function(n) {
return {x: function() {
return ke(n);
}};
}};
var MR = {kernelName: Ec, inputsToSave: ["x"], gradFunc: function(n, t, e) {
var r = t[0], i = e, a = i.clipValueMin, s = i.clipValueMax;
return {x: function() {
return gn(jr(Gr(r, a), qr(r, s)), n, ke(n));
}};
}};
var HR = {kernelName: Dc, saveAllInputs: true, gradFunc: function(n, t, e) {
var r = t.map(function(c) {
return c.shape;
}), i = e.axis, a = rt(i, t[0].shape)[0], s = r.map(function(c) {
return c[a];
}), o = zi(n, s, a);
return o.map(function(c) {
return function() {
return c;
};
});
}};
var VR = {kernelName: kc, inputsToSave: ["x", "filter"], gradFunc: function(n, t, e) {
var r = t, i = r[0], a = r[1], s = e, o = s.dilations, c = s.strides, l = s.pad, u = s.dataFormat;
return E(yr(o), function() {
return "Error in gradient of conv2D: dilation rates greater than 1 " + ("are not yet supported in gradients. Got dilations '" + o + "'");
}), {x: function() {
return Uu(i.shape, n, a, c, l, u);
}, filter: function() {
return oh(i, n, a.shape, c, l, u);
}};
}};
var GR = {kernelName: Fc, inputsToSave: ["dy", "filter"], gradFunc: function(n, t, e) {
var r = t, i = r[0], a = r[1], s = e, o = s.strides, c = s.pad, l = s.dataFormat, u = s.dimRoundingMode;
return {dy: function() {
return Di(n, a, o, c, l, 1, u);
}, filter: function() {
return oh(n, i, a.shape, o, c, l, u);
}};
}};
function qR(n, t, e, r, i) {
var a = n;
n.rank === 4 && (a = Y(n, [1, n.shape[0], n.shape[1], n.shape[2], n.shape[3]]));
var s = t;
s.rank === 4 && (s = Y(t, [1, t.shape[0], t.shape[1], t.shape[2], t.shape[3]])), E(a.rank === 5, function() {
return "Error in conv3dDerFilter: input must be rank 5, but got shape " + (a.shape + ".");
}), E(s.rank === 5, function() {
return "Error in conv3dDerFilter: dy must be rank 5, but got shape " + (s.shape + ".");
}), E(e.length === 5, function() {
return "Error in conv3dDerFilter: filterShape must be length 5, but got " + (e + ".");
}), E(a.shape[4] === e[3], function() {
return "Error in conv3dDerFilter: depth of input " + a.shape[4] + ") must " + ("match input depth in filter (" + e[3] + ".");
}), E(s.shape[4] === e[4], function() {
return "Error in conv3dDerFilter: depth of dy (" + s.shape[4] + ") must " + ("match output depth for filter (" + e[4] + ").");
});
var o = function(u) {
var h = 1, d = Ta(a.shape, e, r, h, i);
return u.conv3dDerFilter(a, s, d);
}, c = {x: a, dy: s}, l = {strides: r, pad: i, filterShape: e};
return z.runKernelFunc(o, c, null, mf, l);
}
var YR = U({conv3DBackpropFilter_: qR});
var KR = {kernelName: Wc, inputsToSave: ["x", "filter"], gradFunc: function(n, t, e) {
var r = e, i = r.dilations, a = r.strides, s = r.pad;
E(yr(i), function() {
return "Error in gradient of conv3D: dilation rates greater than 1 are " + ("not yet supported in gradients. Got dilations '" + i + "'");
});
var o = t[0], c = t[1];
return {x: function() {
return vg(o.shape, n, c, a, s);
}, filter: function() {
return YR(o, n, c.shape, a, s);
}};
}};
var jR = {kernelName: Uc, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Z(xt(nh(he(e, "float32"))), n);
}};
}};
var $R = {kernelName: Bc, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Z(rh(he(e, "float32")), n);
}};
}};
var XR = {kernelName: zc, inputsToSave: ["x"], gradFunc: function(n, t, e) {
var r = t[0], i = e, a = i.axis, s = i.exclusive, o = i.reverse;
return {x: function() {
var c = fn([a], r.rank), l = zu(n, a, s, !o);
return c != null && (l = Tt(l, c)), l;
}};
}};
var JR = {kernelName: Pc, inputsToSave: ["x", "filter"], gradFunc: function(n, t, e) {
var r = e, i = r.dilations, a = r.strides, s = r.pad, o = r.dimRoundingMode, c = i != null ? i : [1, 1];
E(yr(c), function() {
return "Error in gradient of depthwiseConv2dNative: dilation rates greater than 1 are not yet supported. Got dilations " + ("'" + c + "'");
});
var l = t, u = l[0], h = l[1];
return E(u.rank === 4, function() {
return "Error in gradient of depthwiseConv2dNative: input must be " + ("rank 4, but got rank " + u.rank + ".");
}), E(h.rank === 4, function() {
return "Error in gradient of depthwiseConv2dNative: filter must be " + ("rank 4, but got rank " + h.rank + ".");
}), E(u.shape[3] === h.shape[2], function() {
return "Error in gradient of depthwiseConv2d: number of input " + ("channels (" + u.shape[3] + ") must match the inChannels dimension ") + ("in filter " + h.shape[2] + ".");
}), E(Mt(a, c), function() {
return "Error in gradient of depthwiseConv2d: Either strides or " + ("dilations must be 1. Got strides " + a + " and dilations ") + ("'" + c + "'.");
}), o != null && E(ot(s), function() {
return "Error in depthwiseConv2d: pad must be an integer when using, " + ("dimRoundingMode " + o + " but got pad " + s + ".");
}), {x: function() {
return y0(u.shape, n, h, a, s, i, o);
}, filter: function() {
return g0(u, n, h.shape, a, s, i, o);
}};
}};
var ZR = {kernelName: Mc, inputsToSave: ["x", "filter"], gradFunc: function(n, t, e) {
var r = t, i = r[0], a = r[1], s = {x: i, filter: a, dy: n}, o = {x: i, filter: a, dy: n};
return {x: function() {
return z.runKernel(Lf, s, e);
}, filter: function() {
return z.runKernel(Sf, o, e);
}};
}};
var QR = {kernelName: Hc, inputsToSave: ["a", "b"], gradFunc: function(n, t) {
var e = t[0], r = t[1], i = it(e.shape, r.shape), a = function() {
var o = Ne(n, he(r, "float32")), c = bt(e.shape, i);
return c.length > 0 ? Y(_e(o, c), e.shape) : o;
}, s = function() {
var o = Z(n, he(e, "float32")), c = bt(r.shape, i);
c.length > 0 && (o = Y(_e(o, c), r.shape));
var l = $e(r);
return xt(Ne(o, he(l, "float32")));
};
return {a, b: s};
}};
var e3 = {kernelName: Vc, outputsToSave: [true], gradFunc: function(n, t) {
var e = t[0], r = function(a) {
return a.eluDer(n, e);
}, i = {dy: n, y: e};
return {x: function() {
return z.runKernelFunc(r, i, null, If);
}};
}};
var t3 = {kernelName: Gc, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0], r = Z(yn(xt($e(e))), 2 / Math.sqrt(Math.PI));
return {x: function() {
return Z(n, r);
}};
}};
var n3 = {kernelName: qc, outputsToSave: [true], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Z(n, e);
}};
}};
var r3 = {kernelName: Yc, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Z(n, yn(e));
}};
}};
var i3 = {kernelName: Kc, gradFunc: function(n) {
return {x: function() {
return ke(n);
}};
}};
var a3 = {kernelName: jc, inputsToSave: ["a", "b"], gradFunc: function(n, t) {
var e = t[0], r = t[1], i = it(e.shape, r.shape), a = function() {
var o = Ne(n, he(r, "float32")), c = bt(e.shape, i);
return c.length > 0 ? Y(_e(o, c), e.shape) : o;
}, s = function() {
var o = Z(n, he(e, "float32")), c = bt(r.shape, i);
c.length > 0 && (o = Y(_e(o, c), r.shape));
var l = $e(r);
return xt(Ne(o, he(l, "float32")));
};
return {a, b: s};
}};
var s3 = {kernelName: $c, inputsToSave: ["x", "mean", "variance", "scale"], gradFunc: function(n, t, e) {
var r = e.varianceEpsilon, i = t[0], a = t[1], s = t[2], o = t[3], c = o != null ? o : Le(1), l = bt(a.shape, i.shape), u = [];
if (a.rank === 1) {
for (var h = 0; h < i.shape.length - 1; ++h)
u.push(i.shape[h]);
u.push(1);
}
var d = be(i, a), p = Z(n, c), f = th(ge(s, Le(r))), m = Z(Z(Z(f, f), f), Le(-0.5)), g = function() {
return a.rank === 1 ? Y(Z(Z(n, ki(Y(f, [1, 1, 1, a.shape[0]]), u)), c), i.shape) : Y(Z(Z(n, f), c), i.shape);
}, y = function() {
var L = Z(Z(f, Le(-1)), p);
return a.rank === 1 && (L = _e(L, l)), Y(L, a.shape);
}, w = function() {
var L = Z(Z(m, d), p);
return a.rank === 1 && (L = _e(L, l)), Y(L, a.shape);
}, b = function() {
var L = Z(d, f), N = Z(n, L);
return a.rank === 1 && (N = _e(N, l)), Y(N, a.shape);
}, x = function() {
var L = n;
return a.rank === 1 && (L = _e(L, l)), Y(L, a.shape);
};
return {x: g, mean: y, variance: w, scale: b, offset: x};
}};
var o3 = {kernelName: Xc, inputsToSave: ["x", "indices"], gradFunc: function(n, t, e) {
var r = t[0], i = t[1], a = e.axis, s = rt(a, r.shape)[0], o = function() {
var c = r.shape, l = i.size, u = c.slice(0, s), h = u.length, d = c.slice(a, c.length).slice(1), p = d.length, f = C0(0, h), m = C0(h + 1, h + 1 + p), g = R0([u, [l], d]), y = Y(n, g), w = Y(i, [l]), b = R0([[h], f, m]), x = Tt(y, b), L = ah(x, w, r.shape[s]), N = ks(b);
return L = Tt(L, N), L;
};
return {x: o, indices: function() {
return i;
}};
}};
function C0(n, t) {
for (var e = [], r = n; r < t; ++r)
e.push(r);
return e;
}
function R0(n) {
for (var t = [], e = 0; e < n.length; ++e)
for (var r = 0; r < n[e].length; ++r)
t.push(n[e][r]);
return t;
}
var c3 = {kernelName: Jc, inputsToSave: ["a", "b"], gradFunc: function(n, t) {
var e = t[0], r = t[1];
return {a: function() {
return ke(e);
}, b: function() {
return ke(r);
}};
}};
var l3 = {kernelName: Zc, gradFunc: function(n) {
return {x: function() {
return he(n, "float32");
}};
}};
var u3 = {kernelName: Qc, gradFunc: function(n) {
return {x: function() {
return ke(n);
}};
}};
var h3 = {kernelName: el, gradFunc: function(n) {
return {x: function() {
return ke(n);
}};
}};
var d3 = {kernelName: tl, gradFunc: function(n) {
return {x: function() {
return ke(n);
}};
}};
var p3 = {kernelName: rl, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Ne(n, ge(e, 1));
}};
}};
var f3 = {kernelName: nl, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Ne(n, he(e, "float32"));
}};
}};
var m3 = {kernelName: il, inputsToSave: [], outputsToSave: [true], gradFunc: function(n, t, e) {
var r = t[0], i = e.axis;
return {logits: function() {
var a = true, s = yn(r);
return be(n, Z(_e(n, i, a), s));
}};
}};
function g3(n, t, e, r, i, a, s) {
r === void 0 && (r = 5), i === void 0 && (i = 1), a === void 0 && (a = 1), s === void 0 && (s = 0.5);
var o = function(u) {
return u.LRNGrad(e, n, t, r, i, a, s);
}, c = {x: n, y: t, dy: e}, l = {depthRadius: r, bias: i, alpha: a, beta: s};
return z.runKernelFunc(o, c, null, zf, l);
}
var y3 = U({localResponseNormalizationBackprop_: g3});
var v3 = {kernelName: al, inputsToSave: ["x"], outputsToSave: [true], gradFunc: function(n, t, e) {
var r = t, i = r[0], a = r[1], s = e, o = s.depthRadius, c = s.bias, l = s.alpha, u = s.beta;
return {x: function() {
return y3(i, a, n, o, c, l, u);
}};
}};
function O0(n, t, e, r) {
return t.rank < e.rank && (t = Y(t, an(t.shape, r))), n.rank < e.rank && (n = Y(n, an(n.shape, r))), {x: function() {
var i = Z(n, he(Ra(e, t), n.dtype));
return i;
}};
}
var E0 = {kernelName: sl, inputsToSave: ["x"], outputsToSave: [true], gradFunc: function(n, t, e) {
var r = e, i = r.reductionIndices, a = t[0], s = t[1], o = rt(i, a.shape), c = O0(n, s, a, o);
return {x: function() {
return c.x();
}};
}};
var w3 = {kernelName: ol, inputsToSave: ["a", "b"], gradFunc: function(n, t) {
var e = t[0], r = t[1], i = function() {
return Z(n, he(Gr(e, r), "float32"));
}, a = function() {
return Z(n, he(Gs(e, r), "float32"));
};
return {a: i, b: a};
}};
function b3(n, t, e, r, i, a, s, o) {
a === void 0 && (a = [1, 1, 1]);
var c = R(n, "dy", "maxPool3dBackprop"), l = R(t, "input", "maxPool3dBackprop"), u = R(e, "output", "maxPool3dBackprop"), h = c, d = l, p = u, f = false;
l.rank === 4 && (f = true, h = Y(c, [1, c.shape[0], c.shape[1], c.shape[2], c.shape[3]]), d = Y(l, [1, l.shape[0], l.shape[1], l.shape[2], l.shape[3]]), p = Y(u, [1, u.shape[0], u.shape[1], u.shape[2], u.shape[3]])), E(h.rank === 5, function() {
return "Error in maxPool3dBackprop: dy must be rank 5 but got rank " + (h.rank + ".");
}), E(d.rank === 5, function() {
return "Error in maxPool3dBackprop: input must be rank 5 but got rank " + (d.rank + ".");
}), E(p.rank === 5, function() {
return "Error in maxPool3dBackprop: output must be rank 5 but got rank " + (p.rank + ".");
}), E(Mt(i, a), function() {
return "Error in maxPool3dBackprop: Either strides or dilations " + ("must be 1. Got strides " + i + " and dilations '" + a + "'");
}), o != null && E(ot(s), function() {
return "Error in maxPool3dBackprop: pad must be an integer when " + ("using, dimRoundingMode " + o + " but got pad " + s + ".");
});
var m = function(b) {
var x = Na(d.shape, r, i, a, s, o);
return b.maxPool3dBackprop(h, d, p, x);
}, g = {dy: h, input: d, output: p}, y = {filterSize: r, strides: i, dilations: a, pad: s, dimRoundingMode: o}, w = z.runKernelFunc(m, g, null, Mf, y);
return f ? Y(w, [w.shape[1], w.shape[2], w.shape[3], w.shape[4]]) : w;
}
var x3 = U({maxPool3dBackprop_: b3});
var L3 = {kernelName: ll, inputsToSave: ["x"], outputsToSave: [true], gradFunc: function(n, t, e) {
var r = t, i = r[0], a = r[1], s = e, o = s.filterSize, c = s.strides, l = s.dilations, u = s.pad, h = s.dimRoundingMode, d = l != null ? l : [1, 1, 1];
return {x: function() {
return x3(n, i, a, o, c, d, u, h);
}};
}};
function S3(n, t, e, r, i, a, s) {
var o = R(n, "dy", "maxPoolBackprop"), c = R(t, "input", "maxPoolBackprop"), l = R(e, "output", "maxPoolBackprop");
E(c.rank === o.rank, function() {
return "Rank of input (" + c.rank + ") does not match rank of dy " + ("(" + o.rank + ")");
}), E(o.rank === 4, function() {
return "Error in maxPoolBackprop: dy must be rank 4 but got rank " + (o.rank + ".");
}), E(c.rank === 4, function() {
return "Error in maxPoolBackprop: input must be rank 4 but got rank " + (c.rank + ".");
}), s != null && E(ot(a), function() {
return "Error in maxPoolBackprop: pad must be an integer when using, " + ("dimRoundingMode " + s + " but got pad " + a + ".");
});
var u = function(p) {
var f = Oi(c.shape, r, i, 1, a, s);
return p.maxPoolBackprop(o, c, l, f);
}, h = {dy: o, input: c, output: l}, d = {filterSize: r, strides: i, pad: a, dimRoundingMode: s};
return z.runKernelFunc(u, h, null, Pf, d);
}
var I3 = U({maxPoolBackprop_: S3});
var A3 = {kernelName: cl, inputsToSave: ["x"], outputsToSave: [true], gradFunc: function(n, t, e) {
var r = t, i = r[0], a = r[1], s = e, o = s.filterSize, c = s.strides, l = s.pad;
return {x: function() {
return I3(n, i, a, o, c, l);
}};
}};
var T3 = {kernelName: ul, inputsToSave: ["x"], outputsToSave: [true], gradFunc: function(n, t, e) {
var r = e, i = r.axis, a = t[0], s = t[1], o = rt(i, a.shape), c = O0(n, s, a, o);
return {x: function() {
return c.x();
}};
}};
var N3 = {kernelName: hl, inputsToSave: ["a", "b"], gradFunc: function(n, t) {
var e = t[0], r = t[1], i = function() {
return Z(n, he(qr(e, r), "float32"));
}, a = function() {
return Z(n, he(vr(e, r), "float32"));
};
return {a: i, b: a};
}};
var _3 = {kernelName: dl, inputsToSave: ["x"], gradFunc: function(n, t, e) {
var r = t[0], i = e.paddings, a = i.map(function(s) {
return s[0];
});
return {x: function() {
return Me(n, a, r.shape);
}};
}};
var C3 = {kernelName: pl, inputsToSave: ["a", "b"], gradFunc: function(n, t) {
var e = t[0], r = t[1], i = it(e.shape, r.shape), a = function() {
var o = bt(e.shape, i);
return o.length > 0 ? Y(_e(n, o), e.shape) : n;
}, s = function() {
var o = Z(n, xt(Ms(Ne(e, r)))), c = bt(r.shape, i);
return c.length > 0 ? Y(_e(o, c), r.shape) : o;
};
return {a, b: s};
}};
var R3 = {kernelName: fl, inputsToSave: ["a", "b"], gradFunc: function(n, t) {
var e = t[0], r = t[1], i = it(e.shape, r.shape), a = function() {
var o = Z(n, he(r, "float32")), c = bt(e.shape, i);
return c.length > 0 ? Y(_e(o, c), e.shape) : o;
}, s = function() {
var o = Z(n, he(e, "float32")), c = bt(r.shape, i);
return c.length > 0 ? Y(_e(o, c), r.shape) : o;
};
return {a, b: s};
}};
var O3 = {kernelName: ml, gradFunc: function(n) {
return {x: function() {
return xt(n);
}};
}};
var E3 = {kernelName: yl, inputsToSave: ["indices"], gradFunc: function(n, t) {
var e = t[0];
return {indices: function() {
return $n(e.shape, "float32");
}};
}};
var D3 = {kernelName: gl, gradFunc: function(n) {
return {x: function() {
return ke(n);
}};
}};
var D0 = {kernelName: vl, inputsToSave: ["x"], gradFunc: function(n, t, e) {
var r = t[0], i = e.paddings, a = i.map(function(s) {
return s[0];
});
return {x: function() {
return Me(n, a, r.shape);
}};
}};
var k3 = {kernelName: wl, inputsToSave: ["a", "b"], outputsToSave: [true], gradFunc: function(n, t) {
var e = t[0], r = t[1], i = t[2], a = e, s = r, o = it(a.shape, s.shape), c = function() {
var u = he(s, "float32"), h = Z(n, Z(u, Xn(a, be(u, Le(1))))), d = bt(a.shape, o);
return d.length > 0 && (h = _e(h, d)), Y(h, a.shape);
}, l = function() {
var u = vr(a, 0), h = gn(u, Yr(a), ke(a)), d = Z(n, Z(i, h)), p = bt(s.shape, o);
return p.length > 0 && (d = _e(d, p)), Y(d, s.shape);
};
return {a: c, b: l};
}};
var F3 = {kernelName: bl, inputsToSave: ["x", "alpha"], gradFunc: function(n, t) {
var e = t[0], r = t[1], i = vr(e, 0);
return {x: function() {
return gn(i, n, Z(n, r));
}, alpha: function() {
var a = gn(i, ke(n), Z(n, e)), s = bt(r.shape, n.shape);
return s.length > 0 && (a = _e(a, s)), Y(a, r.shape);
}};
}};
var W3 = {kernelName: xl, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Ne(n, xt($e(e)));
}};
}};
var U3 = {kernelName: Tl, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0], r = Z(qr(e, 6), Pi(e));
return {x: function() {
return Z(n, he(r, "float32"));
}};
}};
var B3 = {kernelName: Ll, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Z(n, he(Pi(e), "float32"));
}};
}};
var z3 = {kernelName: Sl, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Y(n, e.shape);
}};
}};
var P3 = {kernelName: Al, inputsToSave: ["images"], gradFunc: function(n, t, e) {
var r = t[0], i = function(o) {
var c = e.alignCorners;
return o.resizeBilinearBackprop(n, r, c);
}, a = {images: r}, s = function() {
return z.runKernelFunc(i, a, null, Zf, e);
};
return {images: s};
}};
var M3 = {kernelName: Il, inputsToSave: ["images"], gradFunc: function(n, t, e) {
var r = t[0], i = function(o) {
var c = e.alignCorners;
return o.resizeNearestNeighborBackprop(n, r, c);
}, a = {images: r}, s = function() {
return z.runKernelFunc(i, a, null, Jf, e);
};
return {images: s};
}};
var H3 = {kernelName: Nl, gradFunc: function(n, t, e) {
var r = e.dims, i = rt(r, n.shape);
return {x: function() {
return Jn(n, i);
}};
}};
var V3 = {kernelName: _l, gradFunc: function(n) {
return {x: function() {
return ke(n);
}};
}};
var G3 = {kernelName: Cl, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return xt(Ne(n, Z(Xn(e, 1.5), 2)));
}};
}};
var q3 = {kernelName: Rl, inputsToSave: ["condition"], gradFunc: function(n, t) {
var e = t[0];
return {condition: function() {
return he(ke(e), "float32");
}, t: function() {
return Z(n, he(e, n.dtype));
}, e: function() {
return Z(n, he(Ys(e), n.dtype));
}};
}};
var Y3 = {kernelName: Ol, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
var r = vr(e, Le(0)), i = Le(N0), a = Le(_0), s = Z(n, a), o = Z(Z(n, i), yn(he(e, "float32")));
return gn(r, s, o);
}};
}};
var K3 = {kernelName: Wl, outputsToSave: [true], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Z(n, Z(e, be(Le(1), e)));
}};
}};
var j3 = {kernelName: Fl, gradFunc: function(n) {
return {x: function() {
return ke(n);
}};
}};
var $3 = {kernelName: Dl, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Z(Ps(he(e, "float32")), n);
}};
}};
var X3 = {kernelName: kl, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Z(Bu(he(e, "float32")), n);
}};
}};
var J3 = {kernelName: El, inputsToSave: ["x"], gradFunc: function(n, t, e) {
for (var r = t[0], i = e, a = i.begin, s = i.size, o = r.shape, c = _u(r, a, s), l = c[0], u = c[1], h = [], d = 0; d < n.rank; d++)
h.push([l[d], o[d] - l[d] - u[d]]);
return {x: function() {
return $r(n, h);
}};
}};
var Z3 = {kernelName: Hl, outputsToSave: [true], gradFunc: function(n, t, e) {
var r = t[0], i = e.dim, a = true, s = Z(n, r);
return {logits: function() {
return be(s, Z(_e(s, [i], a), r));
}};
}};
var Q3 = {kernelName: Ul, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Z(n, Vr(e));
}};
}};
var k0 = {kernelName: Pl, gradFunc: function(n, t, e) {
var r = e, i = r.blockShape, a = r.paddings;
return {x: function() {
return Us(n, i, a);
}};
}};
var F0 = {kernelName: Ml, gradFunc: function(n, t, e) {
var r = e.axis;
return {x: function() {
return Et(n, r);
}};
}};
var eO = {kernelName: Bl, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Ne(n, Z(Ht(he(e, "float32")), 2));
}};
}};
var tO = {kernelName: em, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Z(n, Z(he(e, "float32"), 2));
}};
}};
var nO = {kernelName: Vl, inputsToSave: ["a", "b"], gradFunc: function(n, t) {
var e = t[0], r = t[1], i = Le(2), a = function() {
return Z(n, Z(i, be(e, r)));
}, s = function() {
return Z(n, Z(i, be(r, e)));
};
return {a, b: s};
}};
var rO = {kernelName: Zl, gradFunc: function(n) {
return {x: function() {
return ke(n);
}};
}};
var iO = {kernelName: Gl, inputsToSave: ["a", "b"], gradFunc: function(n, t) {
var e = t[0], r = t[1], i = it(e.shape, r.shape), a = function() {
var o = n, c = bt(e.shape, i);
return c.length > 0 && (o = _e(o, c)), Y(o, e.shape);
}, s = function() {
var o = n, c = bt(r.shape, i);
return c.length > 0 && (o = _e(o, c)), Y(xt(o), r.shape);
};
return {a, b: s};
}};
var aO = {kernelName: zl, inputsToSave: ["x"], gradFunc: function(n, t, e) {
var r = t[0], i = r.shape.slice(), a = e.axis, s = rt(a, r.shape);
s.forEach(function(l) {
i[l] = 1;
});
var o = Y(n, i), c = Z(o, Wi(r.shape, "float32"));
return {x: function() {
return c;
}};
}};
var sO = {kernelName: ql, inputsToSave: ["x"], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Ne(n, $e(Ps(e)));
}};
}};
var oO = {kernelName: Yl, outputsToSave: [true], gradFunc: function(n, t) {
var e = t[0];
return {x: function() {
return Z(be(Le(1), $e(e)), n);
}};
}};
var cO = {kernelName: Kl, inputsToSave: ["x"], gradFunc: function(n, t, e) {
var r = t[0], i = e.reps, a = function() {
var s = ke(r);
if (r.rank === 1)
for (var o = 0; o < i[0]; ++o)
s = ge(s, Me(n, [o * r.shape[0]], [r.shape[0]]));
else if (r.rank === 2)
for (var o = 0; o < i[0]; ++o)
for (var c = 0; c < i[1]; ++c)
s = ge(s, Me(n, [o * r.shape[0], c * r.shape[1]], [r.shape[0], r.shape[1]]));
else if (r.rank === 3)
for (var o = 0; o < i[0]; ++o)
for (var c = 0; c < i[1]; ++c)
for (var l = 0; l < i[2]; ++l)
s = ge(s, Me(n, [o * r.shape[0], c * r.shape[1], l * r.shape[2]], [r.shape[0], r.shape[1], r.shape[2]]));
else if (r.rank === 4)
for (var o = 0; o < i[0]; ++o)
for (var c = 0; c < i[1]; ++c)
for (var l = 0; l < i[2]; ++l)
for (var u = 0; u < i[3]; ++u)
s = ge(s, Me(n, [o * r.shape[0], c * r.shape[1], l * r.shape[2], u * r.shape[3]], [r.shape[0], r.shape[1], r.shape[2], r.shape[3]]));
else
throw new Error("Gradient for tile operation is not implemented for rank-" + (r.rank + " tensors yet."));
return s;
};
return {x: a};
}};
var lO = {kernelName: jl, gradFunc: function(n, t, e) {
var r = e, i = r.perm, a = ks(i);
return {x: function() {
return Tt(n, a);
}};
}};
var uO = {kernelName: $l, gradFunc: function(n, t, e) {
var r = e, i = r.axis;
return {value: function() {
return Zr(n, i);
}};
}};
var dO = {kernelName: Xl, inputsToSave: ["segmentIds"], gradFunc: function(n, t) {
var e = t[0], r = function() {
return hO(n, e);
};
return {x: r};
}};
function hO(n, t) {
for (var e = Fi(t, ke(t)), r = Hs(n, e), i = Gr(t, Le(0, "int32")), a = r.rank - i.rank, s = 0; s < a; ++s)
i = vn(i, s + 1);
i = jr(i, Wi(r.shape, "bool"));
var o = ke(r);
return gn(i, r, o);
}
var pO = {kernelName: Jl, gradFunc: function(n) {
return {x: function() {
return ke(n);
}};
}};
var fO = [vR, wR, bR, xR, LR, SR, IR, AR, TR, NR, _R, CR, ER, FR, WR, UR, BR, zR, PR, MR, HR, GR, VR, KR, jR, $R, XR, JR, ZR, QR, e3, t3, n3, r3, a3, i3, s3, o3, c3, l3, u3, h3, d3, p3, f3, m3, v3, E0, E0, w3, L3, A3, T3, N3, _3, C3, R3, O3, E3, D3, D0, D0, k3, F3, W3, U3, B3, z3, P3, M3, H3, V3, G3, q3, Y3, K3, j3, $3, X3, J3, Z3, Q3, k0, k0, F0, F0, eO, nO, tO, rO, iO, aO, sO, oO, cO, lO, uO, dO, pO];
for (var mh = 0, W0 = fO; mh < W0.length; mh++) {
var mO = W0[mh];
om(mO);
}
K.prototype.abs = function() {
return this.throwIfDisposed(), $t(this);
};
K.prototype.acos = function() {
return this.throwIfDisposed(), Qm(this);
};
K.prototype.acosh = function() {
return this.throwIfDisposed(), eg(this);
};
K.prototype.addStrict = function(n) {
return this.throwIfDisposed(), a0(this, n);
};
K.prototype.add = function(n) {
return this.throwIfDisposed(), ge(this, n);
};
K.prototype.all = function(n, t) {
return this.throwIfDisposed(), rg(this, n, t);
};
K.prototype.any = function(n, t) {
return this.throwIfDisposed(), ig(this, n, t);
};
K.prototype.argMax = function(n) {
return this.throwIfDisposed(), ag(this, n);
};
K.prototype.argMin = function(n) {
return this.throwIfDisposed(), sg(this, n);
};
K.prototype.asScalar = function() {
return this.throwIfDisposed(), E(this.size === 1, function() {
return "The array must have only 1 element.";
}), Y(this, []);
};
K.prototype.asType = function(n) {
return this.throwIfDisposed(), he(this, n);
};
K.prototype.as1D = function() {
return this.throwIfDisposed(), Y(this, [this.size]);
};
K.prototype.as2D = function(n, t) {
return this.throwIfDisposed(), Y(this, [n, t]);
};
K.prototype.as3D = function(n, t, e) {
return this.throwIfDisposed(), Y(this, [n, t, e]);
};
K.prototype.as4D = function(n, t, e, r) {
return this.throwIfDisposed(), Y(this, [n, t, e, r]);
};
K.prototype.as5D = function(n, t, e, r, i) {
return this.throwIfDisposed(), Y(this, [n, t, e, r, i]);
};
K.prototype.asin = function() {
return this.throwIfDisposed(), og(this);
};
K.prototype.asinh = function() {
return this.throwIfDisposed(), cg(this);
};
K.prototype.atan = function() {
return this.throwIfDisposed(), lg(this);
};
K.prototype.atan2 = function(n) {
return this.throwIfDisposed(), ug(this, n);
};
K.prototype.atanh = function() {
return this.throwIfDisposed(), hg(this);
};
K.prototype.avgPool = function(n, t, e, r) {
return this.throwIfDisposed(), Wu(this, n, t, e, r);
};
K.prototype.batchToSpaceND = function(n, t) {
return this.throwIfDisposed(), Us(this, n, t);
};
K.prototype.batchNorm = function(n, t, e, r, i) {
return this.throwIfDisposed(), _a(this, n, t, e, r, i);
};
K.prototype.broadcastTo = function(n) {
return this.throwIfDisposed(), zs(this, n);
};
K.prototype.cast = function(n) {
return this.throwIfDisposed(), he(this, n);
};
K.prototype.ceil = function() {
return this.throwIfDisposed(), fg(this);
};
K.prototype.clipByValue = function(n, t) {
return this.throwIfDisposed(), mg(this, n, t);
};
K.prototype.concat = function(n, t) {
return this.throwIfDisposed(), n instanceof K && (n = [n]), Et([this].concat(n), t);
};
K.prototype.conv1d = function(n, t, e, r, i, a) {
return this.throwIfDisposed(), gg(this, n, t, e, r, i, a);
};
K.prototype.conv2dTranspose = function(n, t, e, r, i) {
return this.throwIfDisposed(), yg(this, n, t, e, r, i);
};
K.prototype.conv2d = function(n, t, e, r, i, a) {
return this.throwIfDisposed(), Di(this, n, t, e, r, i, a);
};
K.prototype.cos = function() {
return this.throwIfDisposed(), Ps(this);
};
K.prototype.cosh = function() {
return this.throwIfDisposed(), Bu(this);
};
K.prototype.cumsum = function(n, t, e) {
return this.throwIfDisposed(), zu(this, n, t, e);
};
K.prototype.depthToSpace = function(n, t) {
return this.throwIfDisposed(), wg(this, n, t);
};
K.prototype.depthwiseConv2D = function(n, t, e, r, i, a) {
return Nt("depthwiseConv2D is deprecated, use depthwiseConv2d instead"), this.throwIfDisposed(), Ca(this, n, t, e, r, i, a);
};
K.prototype.depthwiseConv2d = function(n, t, e, r, i, a) {
return this.throwIfDisposed(), Ca(this, n, t, e, r, i, a);
};
K.prototype.dilation2d = function(n, t, e, r, i) {
return this.throwIfDisposed(), bg(this, n, t, e, r, i);
};
K.prototype.divNoNan = function(n) {
return this.throwIfDisposed(), xg(this, n);
};
K.prototype.divStrict = function(n) {
return this.throwIfDisposed(), s0(this, n);
};
K.prototype.div = function(n) {
return this.throwIfDisposed(), Ne(this, n);
};
K.prototype.dot = function(n) {
return this.throwIfDisposed(), Lg(this, n);
};
K.prototype.elu = function() {
return this.throwIfDisposed(), Pu(this);
};
K.prototype.equalStrict = function(n) {
return this.throwIfDisposed(), Qg(this, n);
};
K.prototype.equal = function(n) {
return this.throwIfDisposed(), Ra(this, n);
};
K.prototype.erf = function() {
return this.throwIfDisposed(), Sg(this);
};
K.prototype.exp = function() {
return this.throwIfDisposed(), yn(this);
};
K.prototype.expandDims = function(n) {
return this.throwIfDisposed(), vn(this, n);
};
K.prototype.expm1 = function() {
return this.throwIfDisposed(), Ig(this);
};
K.prototype.fft = function() {
return this.throwIfDisposed(), Js(this);
};
K.prototype.flatten = function() {
return this.throwIfDisposed(), Y(this, [this.size]);
};
K.prototype.floor = function() {
return this.throwIfDisposed(), Ms(this);
};
K.prototype.floorDiv = function(n) {
return this.throwIfDisposed(), Eu(this, n);
};
K.prototype.gather = function(n, t) {
return this.throwIfDisposed(), Hs(this, n, t);
};
K.prototype.greaterEqualStrict = function(n) {
return this.throwIfDisposed(), e0(this, n);
};
K.prototype.greaterEqual = function(n) {
return this.throwIfDisposed(), Gr(this, n);
};
K.prototype.greaterStrict = function(n) {
return this.throwIfDisposed(), t0(this, n);
};
K.prototype.greater = function(n) {
return this.throwIfDisposed(), vr(this, n);
};
K.prototype.ifft = function() {
return this.throwIfDisposed(), ka(this);
};
K.prototype.irfft = function() {
return this.throwIfDisposed(), ih(this);
};
K.prototype.isFinite = function() {
return this.throwIfDisposed(), Ng(this);
};
K.prototype.isInf = function() {
return this.throwIfDisposed(), _g(this);
};
K.prototype.isNaN = function() {
return this.throwIfDisposed(), Cg(this);
};
K.prototype.leakyRelu = function(n) {
return this.throwIfDisposed(), Rg(this, n);
};
K.prototype.lessEqualStrict = function(n) {
return this.throwIfDisposed(), n0(this, n);
};
K.prototype.lessEqual = function(n) {
return this.throwIfDisposed(), qr(this, n);
};
K.prototype.lessStrict = function(n) {
return this.throwIfDisposed(), r0(this, n);
};
K.prototype.less = function(n) {
return this.throwIfDisposed(), Gs(this, n);
};
K.prototype.localResponseNormalization = function(n, t, e, r) {
return this.throwIfDisposed(), Og(this, n, t, e, r);
};
K.prototype.logSigmoid = function() {
return this.throwIfDisposed(), Dg(this);
};
K.prototype.logSoftmax = function(n) {
return this.throwIfDisposed(), kg(this, n);
};
K.prototype.logSumExp = function(n, t) {
return this.throwIfDisposed(), qu(this, n, t);
};
K.prototype.log = function() {
return this.throwIfDisposed(), Yr(this);
};
K.prototype.log1p = function() {
return this.throwIfDisposed(), Vu(this);
};
K.prototype.logicalAnd = function(n) {
return this.throwIfDisposed(), jr(this, n);
};
K.prototype.logicalNot = function() {
return this.throwIfDisposed(), Ys(this);
};
K.prototype.logicalOr = function(n) {
return this.throwIfDisposed(), Yu(this, n);
};
K.prototype.logicalXor = function(n) {
return this.throwIfDisposed(), Fg(this, n);
};
K.prototype.matMul = function(n, t, e) {
return this.throwIfDisposed(), Ue(this, n, t, e);
};
K.prototype.maxPool = function(n, t, e, r) {
return this.throwIfDisposed(), Ku(this, n, t, e, r);
};
K.prototype.max = function(n, t) {
return this.throwIfDisposed(), Kr(this, n, t);
};
K.prototype.maximumStrict = function(n) {
return this.throwIfDisposed(), o0(this, n);
};
K.prototype.maximum = function(n) {
return this.throwIfDisposed(), Fi(this, n);
};
K.prototype.mean = function(n, t) {
return this.throwIfDisposed(), Oa(this, n, t);
};
K.prototype.min = function(n, t) {
return this.throwIfDisposed(), Ks(this, n, t);
};
K.prototype.minimumStrict = function(n) {
return this.throwIfDisposed(), c0(this, n);
};
K.prototype.minimum = function(n) {
return this.throwIfDisposed(), js(this, n);
};
K.prototype.mirrorPad = function(n, t) {
return this.throwIfDisposed(), Wg(this, n, t);
};
K.prototype.modStrict = function(n) {
return this.throwIfDisposed(), l0(this, n);
};
K.prototype.mod = function(n) {
return this.throwIfDisposed(), ju(this, n);
};
K.prototype.mulStrict = function(n) {
return this.throwIfDisposed(), u0(this, n);
};
K.prototype.mul = function(n) {
return this.throwIfDisposed(), Z(this, n);
};
K.prototype.neg = function() {
return this.throwIfDisposed(), xt(this);
};
K.prototype.norm = function(n, t, e) {
return this.throwIfDisposed(), no(this, n, t, e);
};
K.prototype.notEqualStrict = function(n) {
return this.throwIfDisposed(), i0(this, n);
};
K.prototype.notEqual = function(n) {
return this.throwIfDisposed(), $s(this, n);
};
K.prototype.oneHot = function(n, t, e) {
return t === void 0 && (t = 1), e === void 0 && (e = 0), this.throwIfDisposed(), Es(this, n, t, e);
};
K.prototype.onesLike = function() {
return this.throwIfDisposed(), $u(this);
};
K.prototype.pad = function(n, t) {
return this.throwIfDisposed(), $r(this, n, t);
};
K.prototype.pool = function(n, t, e, r, i) {
return this.throwIfDisposed(), Ug(this, n, t, e, r, i);
};
K.prototype.powStrict = function(n) {
return this.throwIfDisposed(), h0(this, n);
};
K.prototype.pow = function(n) {
return this.throwIfDisposed(), Xn(this, n);
};
K.prototype.prelu = function(n) {
return this.throwIfDisposed(), Xu(this, n);
};
K.prototype.prod = function(n, t) {
return this.throwIfDisposed(), Bg(this, n, t);
};
K.prototype.reciprocal = function() {
return this.throwIfDisposed(), Pg(this);
};
K.prototype.relu = function() {
return this.throwIfDisposed(), Da(this);
};
K.prototype.relu6 = function() {
return this.throwIfDisposed(), eh(this);
};
K.prototype.reshapeAs = function(n) {
return this.throwIfDisposed(), Y(this, n.shape);
};
K.prototype.reshape = function(n) {
return this.throwIfDisposed(), Y(this, n);
};
K.prototype.resizeBilinear = function(n, t) {
return this.throwIfDisposed(), I0(this, n, t);
};
K.prototype.resizeNearestNeighbor = function(n, t) {
return this.throwIfDisposed(), A0(this, n, t);
};
K.prototype.reverse = function(n) {
return this.throwIfDisposed(), Jn(this, n);
};
K.prototype.rfft = function() {
return this.throwIfDisposed(), Zs(this);
};
K.prototype.round = function() {
return this.throwIfDisposed(), Mg(this);
};
K.prototype.rsqrt = function() {
return this.throwIfDisposed(), th(this);
};
K.prototype.selu = function() {
return this.throwIfDisposed(), Hg(this);
};
K.prototype.separableConv2d = function(n, t, e, r, i, a) {
return this.throwIfDisposed(), Vg(this, n, t, e, r, i, a);
};
K.prototype.sigmoid = function() {
return this.throwIfDisposed(), Vr(this);
};
K.prototype.sign = function() {
return this.throwIfDisposed(), Gg(this);
};
K.prototype.sin = function() {
return this.throwIfDisposed(), nh(this);
};
K.prototype.sinh = function() {
return this.throwIfDisposed(), rh(this);
};
K.prototype.slice = function(n, t) {
return this.throwIfDisposed(), Me(this, n, t);
};
K.prototype.softmax = function(n) {
return this.throwIfDisposed(), qg(this, n);
};
K.prototype.softplus = function() {
return this.throwIfDisposed(), Gu(this);
};
K.prototype.spaceToBatchND = function(n, t) {
return this.throwIfDisposed(), Xs(this, n, t);
};
K.prototype.split = function(n, t) {
return this.throwIfDisposed(), zi(this, n, t);
};
K.prototype.sqrt = function() {
return this.throwIfDisposed(), Ht(this);
};
K.prototype.square = function() {
return this.throwIfDisposed(), $e(this);
};
K.prototype.squaredDifference = function(n) {
return this.throwIfDisposed(), Qs(this, n);
};
K.prototype.squaredDifferenceStrict = function(n) {
return this.throwIfDisposed(), d0(this, n);
};
K.prototype.squeeze = function(n) {
return this.throwIfDisposed(), eo(this, n);
};
K.prototype.stack = function(n, t) {
this.throwIfDisposed();
var e = n instanceof K ? [this, n] : [this].concat(n);
return Zr(e, t);
};
K.prototype.step = function(n) {
return this.throwIfDisposed(), Pi(this, n);
};
K.prototype.stridedSlice = function(n, t, e, r, i, a, s, o) {
return this.throwIfDisposed(), Kg(this, n, t, e, r, i, a, s, o);
};
K.prototype.subStrict = function(n) {
return this.throwIfDisposed(), p0(this, n);
};
K.prototype.sub = function(n) {
return this.throwIfDisposed(), be(this, n);
};
K.prototype.sum = function(n, t) {
return this.throwIfDisposed(), _e(this, n, t);
};
K.prototype.tan = function() {
return this.throwIfDisposed(), jg(this);
};
K.prototype.tanh = function() {
return this.throwIfDisposed(), Ws(this);
};
K.prototype.tile = function(n) {
return this.throwIfDisposed(), ki(this, n);
};
K.prototype.toBool = function() {
return this.throwIfDisposed(), he(this, "bool");
};
K.prototype.toFloat = function() {
return this.throwIfDisposed(), he(this, "float32");
};
K.prototype.toInt = function() {
return this.throwIfDisposed(), he(this, "int32");
};
K.prototype.topk = function(n, t) {
return this.throwIfDisposed(), $g(this, n, t);
};
K.prototype.transpose = function(n) {
return this.throwIfDisposed(), Tt(this, n);
};
K.prototype.unique = function(n) {
return this.throwIfDisposed(), Xg(this, n);
};
K.prototype.unsortedSegmentSum = function(n, t) {
return this.throwIfDisposed(), ah(this, n, t);
};
K.prototype.unstack = function(n) {
return this.throwIfDisposed(), to(this, n);
};
K.prototype.where = function(n, t) {
return this.throwIfDisposed(), gn(n, this, t);
};
K.prototype.zerosLike = function() {
return this.throwIfDisposed(), ke(this);
};
A.Abs = mc;
A.Acos = gc;
A.Acosh = yc;
A.AdadeltaOptimizer = lh;
A.AdagradOptimizer = uh;
A.AdamOptimizer = hh;
A.AdamaxOptimizer = dh;
A.Add = Ss;
A.AddN = vc;
A.All = lf;
A.Any = uf;
A.ArgMax = wc;
A.ArgMin = bc;
A.Asin = xc;
A.Asinh = Lc;
A.Atan = Sc;
A.Atan2 = Ac;
A.Atanh = Ic;
A.AvgPool = Tc;
A.AvgPool3D = Nc;
A.AvgPool3DBackprop = df;
A.AvgPoolBackprop = hf;
A.BatchMatMul = _c;
A.BatchToSpaceND = Cc;
A.BroadcastTo = Rc;
A.Cast = Is;
A.Ceil = Oc;
A.ClipByValue = Ec;
A.Complex = pf;
A.Concat = Dc;
A.Conv2D = kc;
A.Conv2DBackpropFilter = ff;
A.Conv2DBackpropInput = Fc;
A.Conv3D = Wc;
A.Conv3DBackpropFilterV2 = mf;
A.Conv3DBackpropInputV2 = gf;
A.Cos = Uc;
A.Cosh = Bc;
A.CropAndResize = yf;
A.Cumsum = zc;
A.DataStorage = rL;
A.DepthToSpace = vf;
A.DepthwiseConv2dNative = Pc;
A.DepthwiseConv2dNativeBackpropFilter = wf;
A.DepthwiseConv2dNativeBackpropInput = bf;
A.Diag = xf;
A.Dilation2D = Mc;
A.Dilation2DBackpropFilter = Sf;
A.Dilation2DBackpropInput = Lf;
A.Div = Hc;
A.Elu = Vc;
A.EluGrad = If;
A.Environment = sf;
A.Equal = Af;
A.Erf = Gc;
A.Exp = qc;
A.Expm1 = Yc;
A.FFT = Tf;
A.Fill = Nf;
A.FlipLeftRight = _f;
A.Floor = Kc;
A.FloorDiv = jc;
A.FromPixels = Ql;
A.FusedBatchNorm = $c;
A.FusedConv2D = tu;
A.FusedDepthwiseConv2D = nu;
A.GatherNd = Cf;
A.GatherV2 = Xc;
A.Greater = Rf;
A.GreaterEqual = Jc;
A.IFFT = Of;
A.Identity = Zc;
A.Imag = Ef;
A.IsFinite = Qc;
A.IsInf = el;
A.IsNan = tl;
A.KernelBackend = qp;
A.LRN = al;
A.LRNBackprop = zf;
A.Less = Df;
A.LessEqual = kf;
A.LinSpace = Ff;
A.Log = nl;
A.Log1p = rl;
A.LogSoftmax = il;
A.LogicalAnd = Wf;
A.LogicalNot = Uf;
A.LogicalOr = Bf;
A.Max = sl;
A.MaxPool = cl;
A.MaxPool3D = ll;
A.MaxPool3DBackprop = Mf;
A.MaxPoolBackprop = Pf;
A.MaxPoolWithArgmax = Hf;
A.Maximum = ol;
A.Mean = Vf;
A.Min = ul;
A.Minimum = hl;
A.MirrorPad = dl;
A.Mod = pl;
A.MomentumOptimizer = ph;
A.Multiply = fl;
A.Negate = ml;
A.NonMaxSuppressionV3 = qf;
A.NonMaxSuppressionV4 = Yf;
A.NonMaxSuppressionV5 = Kf;
A.NotEqual = Gf;
A.OP_SCOPE_SUFFIX = ym;
A.OneHot = yl;
A.OnesLike = gl;
A.Optimizer = wr;
A.PadV2 = vl;
A.Pool = xL;
A.Pow = wl;
A.Prelu = bl;
A.Prod = jf;
A.RMSPropOptimizer = fh;
A.Range = $f;
A.Real = Xf;
A.Reciprocal = xl;
A.Relu = Ll;
A.Relu6 = Tl;
A.Reshape = Sl;
A.ResizeBilinear = Al;
A.ResizeBilinearGrad = Zf;
A.ResizeNearestNeighbor = Il;
A.ResizeNearestNeighborGrad = Jf;
A.Reverse = Nl;
A.RotateWithOffset = am;
A.Round = _l;
A.Rsqrt = Cl;
A.SGDOptimizer = oo;
A.ScatterNd = Qf;
A.SelectV2 = Rl;
A.Selu = Ol;
A.Sigmoid = Wl;
A.Sign = Fl;
A.Sin = Dl;
A.Sinh = kl;
A.Slice = El;
A.Softmax = Hl;
A.Softplus = Ul;
A.SpaceToBatchND = Pl;
A.SparseToDense = tm;
A.SplitV = Ml;
A.Sqrt = Bl;
A.Square = em;
A.SquaredDifference = Vl;
A.Step = Zl;
A.StridedSlice = nm;
A.Sub = Gl;
A.Sum = zl;
A.Tan = ql;
A.Tanh = Yl;
A.Tensor = K;
A.TensorBuffer = _s;
A.Tile = Kl;
A.TopK = rm;
A.Transpose = jl;
A.Unique = im;
A.Unpack = $l;
A.UnsortedSegmentSum = Xl;
A.Variable = La;
A.ZerosLike = Jl;
A._FusedMatMul = eu;
A.abs = $t;
A.acos = Qm;
A.acosh = eg;
A.add = ge;
A.addN = MI;
A.addStrict = a0;
A.all = rg;
A.any = ig;
A.argMax = ag;
A.argMin = sg;
A.asin = og;
A.asinh = cg;
A.atan = lg;
A.atan2 = ug;
A.atanh = hg;
A.avgPool = Wu;
A.avgPool3d = aA;
A.backend = OI;
A.backend_util = pR;
A.basicLSTMCell = hA;
A.batchNorm = _a;
A.batchNorm2d = gA;
A.batchNorm3d = vA;
A.batchNorm4d = bA;
A.batchToSpaceND = Us;
A.booleanMaskAsync = GN;
A.broadcastTo = zs;
A.browser = tI;
A.buffer = Rn;
A.cast = he;
A.ceil = fg;
A.clipByValue = mg;
A.clone = Mr;
A.complex = hr;
A.concat = Et;
A.concat1d = AA;
A.concat2d = NA;
A.concat3d = CA;
A.concat4d = OA;
A.conv1d = gg;
A.conv2d = Di;
A.conv2dTranspose = yg;
A.conv3d = UA;
A.conv3dTranspose = PA;
A.copyRegisteredKernels = IL;
A.cos = Ps;
A.cosh = Bu;
A.cosineWindow = sh;
A.cumsum = zu;
A.customGrad = En;
A.deprecationWarn = Nt;
A.depthToSpace = wg;
A.depthwiseConv2d = Ca;
A.device_util = jL;
A.diag = KA;
A.dilation2d = bg;
A.disableDeprecationWarnings = vI;
A.dispose = Pt;
A.disposeVariables = wI;
A.div = Ne;
A.divNoNan = xg;
A.divStrict = s0;
A.dot = Lg;
A.dropout = v_;
A.elu = Pu;
A.enableDebugMode = yI;
A.enableProdMode = gI;
A.enclosingPowerOfTwo = m0;
A.engine = bI;
A.env = qe;
A.equal = Ra;
A.equalStrict = Qg;
A.erf = Sg;
A.exp = yn;
A.expandDims = vn;
A.expm1 = Ig;
A.eye = Ag;
A.fft = Js;
A.fill = Mu;
A.findBackend = _I;
A.findBackendFactory = CI;
A.floor = Ms;
A.floorDiv = Eu;
A.fused = R_;
A.gather = Hs;
A.gatherND = m_;
A.gather_util = nI;
A.getBackend = TI;
A.getGradient = au;
A.getKernel = iu;
A.getKernelsForBackend = As;
A.grad = _5;
A.grads = C5;
A.greater = vr;
A.greaterEqual = Gr;
A.greaterEqualStrict = e0;
A.greaterStrict = t0;
A.ifft = ka;
A.imag = Vs;
A.image = WC;
A.inTopKAsync = b_;
A.io = GS;
A.irfft = ih;
A.isFinite = Ng;
A.isInf = _g;
A.isNaN = Cg;
A.keep = Zm;
A.kernel_impls = yR;
A.leakyRelu = Rg;
A.less = Gs;
A.lessEqual = qr;
A.lessEqualStrict = n0;
A.lessStrict = r0;
A.linalg = UC;
A.linspace = I5;
A.localResponseNormalization = Og;
A.log = Yr;
A.log1p = Vu;
A.logSigmoid = Dg;
A.logSoftmax = kg;
A.logSumExp = qu;
A.logicalAnd = jr;
A.logicalNot = Ys;
A.logicalOr = Yu;
A.logicalXor = Fg;
A.losses = BC;
A.matMul = Ue;
A.math = JS;
A.max = Kr;
A.maxPool = Ku;
A.maxPool3d = Y5;
A.maxPoolWithArgmax = j5;
A.maximum = Fi;
A.maximumStrict = o0;
A.mean = Oa;
A.memory = xI;
A.min = Ks;
A.minimum = js;
A.minimumStrict = c0;
A.mirrorPad = Wg;
A.mod = ju;
A.modStrict = l0;
A.moments = nT;
A.movingAverage = c_;
A.mul = Z;
A.mulStrict = u0;
A.multiRNNCell = iT;
A.multinomial = sT;
A.neg = xt;
A.nextFrame = MC;
A.norm = no;
A.notEqual = $s;
A.notEqualStrict = i0;
A.oneHot = Es;
A.ones = Wi;
A.onesLike = $u;
A.op = U;
A.outerProduct = hT;
A.pad = $r;
A.pad1d = fT;
A.pad2d = gT;
A.pad3d = vT;
A.pad4d = bT;
A.pool = Ug;
A.pow = Xn;
A.powStrict = h0;
A.prelu = Xu;
A.print = Nm;
A.prod = Bg;
A.profile = LI;
A.rand = CT;
A.randomGamma = PT;
A.randomNormal = HT;
A.randomUniform = zg;
A.range = Qu;
A.ready = AI;
A.real = Ea;
A.reciprocal = Pg;
A.registerBackend = RI;
A.registerGradient = om;
A.registerKernel = sm;
A.relu = Da;
A.relu6 = eh;
A.removeBackend = NI;
A.reshape = Y;
A.reverse = Jn;
A.reverse1d = $T;
A.reverse2d = JT;
A.reverse3d = QT;
A.reverse4d = tN;
A.rfft = Zs;
A.round = Mg;
A.rsqrt = th;
A.scalar = Le;
A.scatterND = u_;
A.scatter_util = rI;
A.selu = Hg;
A.separableConv2d = Vg;
A.serialization = sI;
A.setBackend = II;
A.setPlatform = EI;
A.setdiff1dAsync = oN;
A.sigmoid = Vr;
A.sign = Gg;
A.signal = FC;
A.sin = nh;
A.sinh = rh;
A.slice = Me;
A.slice1d = dN;
A.slice2d = fN;
A.slice3d = gN;
A.slice4d = vN;
A.slice_util = jm;
A.softmax = qg;
A.softplus = Gu;
A.spaceToBatchND = Xs;
A.sparseToDense = p_;
A.spectral = kC;
A.split = zi;
A.sqrt = Ht;
A.square = $e;
A.squaredDifference = Qs;
A.squaredDifferenceStrict = d0;
A.squeeze = eo;
A.stack = Zr;
A.step = Pi;
A.stridedSlice = Kg;
A.sub = be;
A.subStrict = p0;
A.sum = _e;
A.sumOutType = zL;
A.tan = jg;
A.tanh = Ws;
A.tensor = pr;
A.tensor1d = Bi;
A.tensor2d = Fa;
A.tensor3d = km;
A.tensor4d = EN;
A.tensor5d = DN;
A.tensor6d = kN;
A.tensor_util = HL;
A.test_util = fI;
A.tidy = wt;
A.tile = ki;
A.time = SI;
A.topk = $g;
A.train = zC;
A.transpose = Tt;
A.truncatedNormal = UN;
A.unique = Xg;
A.unregisterGradient = SL;
A.unregisterKernel = LL;
A.unsortedSegmentSum = ah;
A.unstack = to;
A.upcastType = Cs;
A.util = _L;
A.valueAndGrad = R5;
A.valueAndGrads = O5;
A.variable = MN;
A.variableGrads = Eg;
A.version_core = mI;
A.where = gn;
A.whereAsync = Zg;
A.zeros = $n;
A.zerosLike = ke;
});
var l1 = we((tt) => {
"use strict";
Object.defineProperty(tt, "__esModule", {value: true});
var v = ei();
var gh = function(n, t) {
return gh = Object.setPrototypeOf || {__proto__: []} instanceof Array && function(e, r) {
e.__proto__ = r;
} || function(e, r) {
for (var i in r)
r.hasOwnProperty(i) && (e[i] = r[i]);
}, gh(n, t);
};
function Q(n, t) {
gh(n, t);
function e() {
this.constructor = n;
}
n.prototype = t === null ? Object.create(t) : (e.prototype = t.prototype, new e());
}
var Xt = function() {
return Xt = Object.assign || function(t) {
for (var e, r = 1, i = arguments.length; r < i; r++) {
e = arguments[r];
for (var a in e)
Object.prototype.hasOwnProperty.call(e, a) && (t[a] = e[a]);
}
return t;
}, Xt.apply(this, arguments);
};
function gO(n, t) {
var e = {};
for (var r in n)
Object.prototype.hasOwnProperty.call(n, r) && t.indexOf(r) < 0 && (e[r] = n[r]);
if (n != null && typeof Object.getOwnPropertySymbols == "function")
for (var i = 0, r = Object.getOwnPropertySymbols(n); i < r.length; i++)
t.indexOf(r[i]) < 0 && (e[r[i]] = n[r[i]]);
return e;
}
function Ae(n, t, e, r) {
return new (e || (e = Promise))(function(i, a) {
function s(l) {
try {
c(r.next(l));
} catch (u) {
a(u);
}
}
function o(l) {
try {
c(r.throw(l));
} catch (u) {
a(u);
}
}
function c(l) {
l.done ? i(l.value) : new e(function(u) {
u(l.value);
}).then(s, o);
}
c((r = r.apply(n, t || [])).next());
});
}
function xe(n, t) {
var e = {label: 0, sent: function() {
if (a[0] & 1)
throw a[1];
return a[1];
}, trys: [], ops: []}, r, i, a, s;
return s = {next: o(0), throw: o(1), return: o(2)}, typeof Symbol == "function" && (s[Symbol.iterator] = function() {
return this;
}), s;
function o(l) {
return function(u) {
return c([l, u]);
};
}
function c(l) {
if (r)
throw new TypeError("Generator is already executing.");
for (; e; )
try {
if (r = 1, i && (a = l[0] & 2 ? i.return : l[0] ? i.throw || ((a = i.return) && a.call(i), 0) : i.next) && !(a = a.call(i, l[1])).done)
return a;
(i = 0, a) && (l = [l[0] & 2, a.value]);
switch (l[0]) {
case 0:
case 1:
a = l;
break;
case 4:
return e.label++, {value: l[1], done: false};
case 5:
e.label++, i = l[1], l = [0];
continue;
case 7:
l = e.ops.pop(), e.trys.pop();
continue;
default:
if (!(a = e.trys, a = a.length > 0 && a[a.length - 1]) && (l[0] === 6 || l[0] === 2)) {
e = 0;
continue;
}
if (l[0] === 3 && (!a || l[1] > a[0] && l[1] < a[3])) {
e.label = l[1];
break;
}
if (l[0] === 6 && e.label < a[1]) {
e.label = a[1], a = l;
break;
}
if (a && e.label < a[2]) {
e.label = a[2], e.ops.push(l);
break;
}
a[2] && e.ops.pop(), e.trys.pop();
continue;
}
l = t.call(n, e);
} catch (u) {
l = [6, u], i = 0;
} finally {
r = a = 0;
}
if (l[0] & 5)
throw l[1];
return {value: l[0] ? l[1] : void 0, done: true};
}
}
var yh;
function Lt() {
return yh == null && (yh = v.backend().epsilon()), yh;
}
function wn() {
return "channelsLast";
}
var br = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return Object.setPrototypeOf(r, t.prototype), r;
}
return t;
}(Error), Dn = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return Object.setPrototypeOf(r, t.prototype), r;
}
return t;
}(Error), M = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return Object.setPrototypeOf(r, t.prototype), r;
}
return t;
}(Error), Re = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return Object.setPrototypeOf(r, t.prototype), r;
}
return t;
}(Error), yO = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return Object.setPrototypeOf(r, t.prototype), r;
}
return t;
}(Error), oG = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return Object.setPrototypeOf(r, t.prototype), r;
}
return t;
}(Error);
function ti(n, t) {
if (Array.isArray(n)) {
for (var e = [], r = 0; r < t; r++)
e = e.concat(n);
return e;
} else {
var e = new Array(t);
return e.fill(n), e;
}
}
function kn(n, t) {
if (!n)
throw new yO(t);
}
function U0(n, t) {
for (var e = 0, r = 0, i = n; r < i.length; r++) {
var a = i[r];
a === t && e++;
}
return e;
}
function Vt(n) {
return n.length === 1 ? n[0] : n;
}
function nt(n) {
return Array.isArray(n) ? n : [n];
}
function Qn(n) {
var t = n.replace(/(.)([A-Z][a-z0-9]+)/g, "$1_$2"), e = t.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
return e[0] !== "_" ? e : "private" + e;
}
function ni(n) {
return n.length <= 1 || n.indexOf("_") === -1 ? n : n.replace(/[_]+(\w|$)/g, function(t, e) {
return e.toUpperCase();
});
}
var un = {};
function vh(n) {
if (n == null)
return null;
var t = {};
return t.className = n.getClassName(), t.config = n.getConfig(), t;
}
function wh(n) {
if (n == null || typeof n != "object")
return;
if (Array.isArray(n))
n.forEach(function(s) {
return wh(s);
});
else
for (var t = Object.keys(n), e = 0, r = t; e < r.length; e++) {
var i = r[e], a = n[i];
a != null && typeof a == "object" && (!Array.isArray(a) && a.type === "ndarray" && typeof a.value == "number" ? n[i] = a.value : wh(a));
}
}
function Wa(n, t, e, r, i) {
var a, s, o;
if (t === void 0 && (t = {}), e === void 0 && (e = {}), r === void 0 && (r = "object"), i === void 0 && (i = false), typeof n == "string") {
var c = n, l = void 0;
if (c in e)
l = e[c];
else if (c in un)
l = un[c];
else if (l = t[c], l == null)
throw new M("Unknown " + r + ": " + n + `. This may be due to one of the following reasons:
` + ("1. The " + r + " is defined in Python, in which ") + `case it needs to be ported to TensorFlow.js or your JavaScript code.
` + ("2. The custom " + r + " is defined in JavaScript, ") + "but is not registered properly with tf.serialization.registerClass().");
return l;
} else {
var u = n;
if (u.className == null || u.config == null)
throw new M(r + ": Improper config format: " + (JSON.stringify(u) + `.
`) + "'className' and 'config' must set.");
var h = u.className, d = void 0, p = void 0;
if (h in e ? (a = e[h], d = a[0], p = a[1]) : h in un ? (s = un.className, d = s[0], p = s[1]) : h in t && (o = t[h], d = o[0], p = o[1]), d == null)
throw new M("Unknown " + r + ": " + h + `. This may be due to one of the following reasons:
` + ("1. The " + r + " is defined in Python, in which ") + `case it needs to be ported to TensorFlow.js or your JavaScript code.
` + ("2. The custom " + r + " is defined in JavaScript, ") + "but is not registered properly with tf.serialization.registerClass().");
if (p != null) {
for (var f = {}, m = 0, g = Object.keys(un); m < g.length; m++) {
var y = g[m];
f[y] = un[y];
}
for (var w = 0, b = Object.keys(e); w < b.length; w++) {
var y = b[w];
f[y] = e[y];
}
var x = u.config;
x.customObjects = f;
for (var L = Xt({}, un), N = 0, I = Object.keys(e); N < I.length; N++) {
var y = I[N];
un[y] = e[y];
}
wh(u.config);
var C = p(d, u.config, e, i);
return un = Xt({}, L), C;
} else {
for (var L = Xt({}, un), O = 0, D = Object.keys(e); O < D.length; O++) {
var y = D[O];
un[y] = e[y];
}
var C = new d(u.config);
return un = Xt({}, L), C;
}
}
}
function vO(n, t) {
return n < t ? -1 : n > t ? 1 : 0;
}
function co(n, t) {
return -1 * vO(n, t);
}
function xr(n) {
if (n == null)
return n;
for (var t = [], e = 0, r = n; e < r.length; e++) {
var i = r[e];
t.indexOf(i) === -1 && t.push(i);
}
return t;
}
function wO(n) {
if (n == null)
throw new M("Invalid value in obj: " + JSON.stringify(n));
for (var t in n)
if (n.hasOwnProperty(t))
return false;
return true;
}
function Hi(n, t, e) {
if (e == null)
return;
if (n.indexOf(e) < 0)
throw new M(e + " is not a valid " + t + ". Valid values are " + n + " or null/undefined.");
}
function bh(n, t, e, r) {
return e === void 0 && (e = 0), r === void 0 && (r = Infinity), kn(e >= 0), kn(r >= e), Array.isArray(n) && n.length >= e && n.length <= r && n.every(function(i) {
return typeof i === t;
});
}
function _t(n, t) {
Array.isArray(n) ? (v.util.assert(n.length > 0, function() {
return t + " is unexpectedly an empty array.";
}), n.forEach(function(e, r) {
return _t(e, "element " + (r + 1) + " of " + t);
})) : v.util.assert(Number.isInteger(n) && n > 0, function() {
return "Expected " + t + " to be a positive integer, but got " + (B0(n) + ".");
});
}
function B0(n) {
return n === null ? "null" : Array.isArray(n) ? "[" + n.map(function(t) {
return B0(t);
}).join(",") + "]" : typeof n == "string" ? '"' + n + '"' : "" + n;
}
function bO(n, t) {
var e = v.util.now(), r, i = function() {
for (var a = [], s = 0; s < arguments.length; s++)
a[s] = arguments[s];
var o = v.util.now();
return o - e < t || (e = o, r = n.apply(void 0, a)), r;
};
return i;
}
function z0(n) {
return n === "relu" ? "relu" : n === "linear" ? "linear" : n === "elu" ? "elu" : null;
}
function xh(n, t) {
return v.tidy(function() {
return v.sqrt(v.sum(v.mul(n, n), t, true));
});
}
var Ua = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.getConfig = function() {
return {};
}, t;
}(v.serialization.Serializable), P0 = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this) || this;
return r.defaultMaxValue = 2, r.defaultAxis = 0, r.maxValue = e.maxValue != null ? e.maxValue : r.defaultMaxValue, r.axis = e.axis != null ? e.axis : r.defaultAxis, r;
}
return t.prototype.apply = function(e) {
var r = this;
return v.tidy(function() {
var i = xh(e, r.axis), a = v.clipByValue(i, 0, r.maxValue);
return v.mul(e, v.div(a, v.add(Lt(), i)));
});
}, t.prototype.getConfig = function() {
return {maxValue: this.maxValue, axis: this.axis};
}, t.className = "MaxNorm", t;
}(Ua);
v.serialization.registerClass(P0);
var M0 = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this) || this;
return r.defaultAxis = 0, r.axis = e.axis != null ? e.axis : r.defaultAxis, r;
}
return t.prototype.apply = function(e) {
var r = this;
return v.tidy(function() {
return v.div(e, v.add(Lt(), xh(e, r.axis)));
});
}, t.prototype.getConfig = function() {
return {axis: this.axis};
}, t.className = "UnitNorm", t;
}(Ua);
v.serialization.registerClass(M0);
var H0 = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e) {
return v.relu(e);
}, t.className = "NonNeg", t;
}(Ua);
v.serialization.registerClass(H0);
var V0 = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this) || this;
return r.defaultMinValue = 0, r.defaultMaxValue = 1, r.defaultRate = 1, r.defaultAxis = 0, r.minValue = e.minValue != null ? e.minValue : r.defaultMinValue, r.maxValue = e.maxValue != null ? e.maxValue : r.defaultMaxValue, r.rate = e.rate != null ? e.rate : r.defaultRate, r.axis = e.axis != null ? e.axis : r.defaultAxis, r;
}
return t.prototype.apply = function(e) {
var r = this;
return v.tidy(function() {
var i = xh(e, r.axis), a = v.add(v.mul(r.rate, v.clipByValue(i, r.minValue, r.maxValue)), v.mul(1 - r.rate, i));
return v.mul(e, v.div(a, v.add(Lt(), i)));
});
}, t.prototype.getConfig = function() {
return {minValue: this.minValue, maxValue: this.maxValue, rate: this.rate, axis: this.axis};
}, t.className = "MinMaxNorm", t;
}(Ua);
v.serialization.registerClass(V0);
var G0 = {maxNorm: "MaxNorm", minMaxNorm: "MinMaxNorm", nonNeg: "NonNeg", unitNorm: "UnitNorm"};
function St(n) {
return vh(n);
}
function q0(n, t) {
return t === void 0 && (t = {}), Wa(n, v.serialization.SerializationMap.getMap().classNameMap, t, "constraint");
}
function It(n) {
if (n == null)
return null;
if (typeof n == "string") {
var t = n in G0 ? G0[n] : n, e = {className: t, config: {}};
return q0(e);
} else
return n instanceof Ua ? n : q0(n);
}
function xO(n) {
return new P0(n);
}
function LO(n) {
return new M0(n);
}
function SO() {
return new H0();
}
function IO(n) {
return new V0(n);
}
var AO = {__proto__: null, maxNorm: xO, unitNorm: LO, nonNeg: SO, minMaxNorm: IO};
var TO = ["channelsFirst", "channelsLast"], NO = ["valid", "same", "causal"], _O = ["max", "avg"], CO = ["sum", "mul", "concat", "ave"];
var Vi = new Map();
function mt(n) {
Hi(TO, "DataFormat", n);
}
function sn(n) {
Hi(NO, "PaddingMode", n);
}
function Y0(n) {
Hi(_O, "PoolMode", n);
}
var Ba = [], K0 = "/";
function ri(n, t) {
Ba.push(n);
try {
var e = t();
return Ba.pop(), e;
} catch (r) {
throw Ba.pop(), r;
}
}
function RO() {
return Ba.length === 0 ? "" : Ba.join(K0) + K0;
}
function $0(n) {
if (!j0(n))
throw new Error("Not a valid tensor name: '" + n + "'");
return RO() + n;
}
function X0(n) {
if (!j0(n))
throw new Error("Not a valid tensor name: '" + n + "'");
Vi.has(n) || Vi.set(n, 0);
var t = Vi.get(n);
if (Vi.set(n, Vi.get(n) + 1), t > 0) {
var e = n + "_" + t;
return Vi.set(e, 1), e;
} else
return n;
}
var OO = new RegExp(/^[A-Za-z0-9][-A-Za-z0-9\._\/]*$/);
function j0(n) {
return !!n.match(OO);
}
function EO(n) {
return n === parseInt(n.toString(), 10);
}
function Lr(n, t, e) {
t == null && (t = 0), e == null && (e = n.length);
for (var r = 1, i = t; i < e; ++i)
r *= n[i];
return r;
}
function J0(n) {
return n = Array.isArray(n) ? new Float32Array(n) : n, v.tensor1d(n);
}
function Gi(n) {
return v.min(J0(n)).dataSync()[0];
}
function Sr(n) {
return v.max(J0(n)).dataSync()[0];
}
function bn(n, t) {
if (t < n)
throw new M("end (" + t + ") < begin (" + n + ") is forbidden.");
for (var e = [], r = n; r < t; ++r)
e.push(r);
return e;
}
function za(n, t) {
return n.asType(t);
}
function Pa(n, t) {
t === void 0 && (t = -1);
var e = n.shape.slice();
return t < 0 && (t = e.length + t + 1), e.splice(t, 0, 1), n.reshape(e);
}
function DO(n, t) {
return v.tidy(function() {
if (n.shape.length !== 2)
throw new M("repeat() expects a rank-2 tensor, but received a " + ("rank-" + n.shape.length + " tensor."));
var e = Pa(n, 1);
return Lh(e, [1, t, 1]);
});
}
function kO(n) {
var t = [Lr(n.shape)];
return n.reshape(t);
}
function FO(n) {
if (n.rank <= 1)
throw new M("batchFlatten requires a minimum rank of 2. Got rank: " + n.rank + ".");
var t = [n.shape[0], Lr(n.shape, 1)];
return n.reshape(t);
}
function ii(n, t, e) {
return v.tidy(function() {
switch (n.rank) {
case 1:
return v.slice1d(n, t, e);
case 2:
return v.slice2d(n, [t, 0], [e, n.shape[1]]);
case 3:
return v.slice3d(n, [t, 0, 0], [e, n.shape[1], n.shape[2]]);
case 4:
return v.slice4d(n, [t, 0, 0, 0], [e, n.shape[1], n.shape[2], n.shape[3]]);
case 5:
return v.slice(n, [t, 0, 0, 0, 0], [e, n.shape[1], n.shape[2], n.shape[3], n.shape[4]]);
case 6:
return v.slice(n, [t, 0, 0, 0, 0, 0], [e, n.shape[1], n.shape[2], n.shape[3], n.shape[4], n.shape[5]]);
default:
throw new M("sliceAlongFirstAxis() received an unsupported tensor rank: " + ("" + n.rank));
}
});
}
function Sh(n, t, e) {
return v.tidy(function() {
switch (n.rank) {
case 1:
return v.slice1d(n, t, e);
case 2:
return v.slice2d(n, [0, t], [n.shape[0], e]);
case 3:
return v.slice3d(n, [0, 0, t], [n.shape[0], n.shape[1], e]);
case 4:
return v.slice4d(n, [0, 0, 0, t], [n.shape[0], n.shape[1], n.shape[2], e]);
default:
throw new M("sliceAlongLastAxis() received an unsupported tensor rank: " + ("" + n.rank));
}
});
}
function lo(n, t, e, r) {
return v.tidy(function() {
switch (n.rank) {
case 1:
return v.slice1d(n, t, e);
case 2:
switch (r) {
case 1:
return ii(n, t, e);
case 2:
return Sh(n, t, e);
default:
throw new M("The axis is not within the rank of the tensor " + ("" + r));
}
case 3:
switch (r) {
case 1:
return ii(n, t, e);
case 2:
return v.slice3d(n, [0, t, 0], [n.shape[0], e, n.shape[2]]);
case 3:
return Sh(n, t, e);
default:
throw new M("The axis is not within the rank of the tensor " + ("" + r));
}
case 4:
switch (r) {
case 1:
return ii(n, t, e);
case 2:
return v.slice4d(n, [0, t, 0, 0], [n.shape[0], e, n.shape[2], n.shape[3]]);
case 3:
return v.slice4d(n, [0, 0, t, 0], [n.shape[0], n.shape[1], e, n.shape[3]]);
case 4:
return Sh(n, t, e);
default:
throw new M("The axis is not within the rank of the tensor " + ("" + r));
}
default:
throw new M("sliceAlongLastAxis() received an unsupported tensor rank: " + ("" + n.rank));
}
});
}
function Ih(n, t) {
t === void 0 && (t = -1);
var e;
return t < 0 && (e = n[0].rank, e !== 0 ? t = e : t = 0), t === n[0].rank && (t = -1), v.concat(n, t);
}
function Z0(n, t) {
switch (n.rank) {
case 1:
return v.concat1d([n, t]);
case 2:
return v.concat2d([n, t], 0);
case 3:
return v.concat3d([n, t], 0);
case 4:
return v.concat4d([n, t], 0);
default:
throw new M("concatAlongFirstAxis() received an unsupported " + ("tensor rank: " + n.rank));
}
}
function Lh(n, t) {
if (Array.isArray(t) || (t = [t]), n.rank !== t.length)
throw new M("The length of input n (" + t.length + ") does not match " + ("the number of dimensions in input x (" + n.rank + ")"));
return v.tile(n, t);
}
function uo(n, t, e, r, i) {
return t === void 0 && (t = 0), e === void 0 && (e = 1), v.randomNormal(n, t, e, r, i);
}
function Fn(n, t, e, r) {
if (n.rank < 2 || t.rank < 2)
throw new Re("dot requires both inputs to be rank >= 2" + (" but got x shape = " + n.shape + " and y shape = " + t.shape));
if (t.rank >= 3) {
var i = n.shape.slice(-1)[0], a = t.shape.slice(-2)[0];
if (i !== a)
throw new Re("If rank y >= 3, then the second last dim" + (" of y must equal the last dim of x but got x shape = " + n.shape + " and ") + (" y shape = " + t.shape));
}
if (n.rank === 2 && t.rank === 2) {
var s = false, o = false;
return v.fused.matMul({a: n, b: t, transposeA: s, transposeB: o, bias: r ? Ah(n.rank, r, wn()) : null, activation: e});
} else {
var c = n.shape.slice(), l = c.pop();
n = n.reshape([-1, l]);
var u = t.shape.slice(), h = u.pop(), a = u.pop(), d = u.concat([h]), p = Array.from({length: t.rank}, function(w, b) {
return b === 0 ? t.rank - 2 : b <= t.rank - 2 ? b - 1 : b;
});
t = t.transpose(p).reshape([a, -1]);
var f = c.concat(d), s = false, o = false;
return v.fused.matMul({a: n, b: t, transposeA: s, transposeB: o, bias: r ? Ah(n.rank, r, wn()) : null, activation: e}).reshape(f);
}
}
function Q0(n, t, e) {
return v.tidy(function() {
return Array.isArray(t) ? t = v.tensor1d(t, "int32") : t = t.toInt(), v.gather(n, t, e);
});
}
function Ma(n) {
return v.mul(n, n);
}
function Ah(n, t, e) {
var r = t.shape;
if (t.rank !== 1 && t.rank !== n)
throw new M("Unexpected bias dimensions: " + t.rank + ("; expected it to be 1 or " + n));
if (n === 5) {
if (e === "channelsFirst")
return r.length === 1 ? t.reshape([1, r[0], 1, 1, 1]) : t.reshape([1, r[3], r[0], r[1], r[2]]);
if (e === "channelsLast")
return r.length === 1 ? t.reshape([1, 1, 1, 1, r[0]]) : t.reshape([1].concat(r));
} else if (n === 4) {
if (e === "channelsFirst")
return r.length === 1 ? t.reshape([1, r[0], 1, 1]) : t.reshape([1, r[2], r[0], r[1]]);
if (e === "channelsLast")
return r.length === 1 ? t.reshape([1, 1, 1, r[0]]) : t.reshape([1].concat(r));
} else if (n === 3) {
if (e === "channelsFirst")
return r.length === 1 ? t.reshape([1, r[0], 1]) : t.reshape([1, r[1], r[0]]);
if (e === "channelsLast")
return r.length === 1 ? t.reshape([1, 1, r[0]]) : t.reshape([1].concat(r));
} else if (n < 3)
return t;
throw new M("Unsupported input rank by biasAdd: " + t.rank);
}
function Wn(n, t, e) {
return v.tidy(function() {
return e == null && (e = wn()), mt(e), n.add(Ah(n.rank, t, e));
});
}
function WO(n, t) {
if (t === void 0 && (t = 1), t !== 1)
throw new Re("Support for alpha values other than 1 (" + t + ") is not implemented yet.");
return v.elu(n);
}
function UO(n) {
return v.tidy(function() {
return v.div(n, v.abs(n).add(1));
});
}
function ey(n, t, e, r) {
return v.tidy(function() {
return v.dropout(n, t, e, r);
});
}
function BO(n) {
return v.tidy(function() {
var t = v.add(0.5, v.mul(0.2, n));
return v.clipByValue(t, 0, 1);
});
}
function Ha(n, t, e) {
return e === void 0 && (e = false), e ? n() : t();
}
var zO = ["fanIn", "fanOut", "fanAvg"], PO = ["normal", "uniform", "truncatedNormal"];
function MO(n) {
Hi(zO, "FanMode", n);
}
function HO(n) {
Hi(PO, "Distribution", n);
}
var hn = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.fromConfigUsesCustomObjects = function() {
return false;
}, t.prototype.getConfig = function() {
return {};
}, t;
}(v.serialization.Serializable), ty = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e, r) {
return v.zeros(e, r);
}, t.className = "Zeros", t;
}(hn);
v.serialization.registerClass(ty);
var Th = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e, r) {
return v.ones(e, r);
}, t.className = "Ones", t;
}(hn);
v.serialization.registerClass(Th);
var ny = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this) || this;
if (typeof e != "object")
throw new M("Expected argument of type ConstantConfig but got " + e);
if (e.value === void 0)
throw new M("config must have value set but got " + e);
return r.value = e.value, r;
}
return t.prototype.apply = function(e, r) {
var i = this;
return v.tidy(function() {
return v.mul(v.scalar(i.value), v.ones(e, r));
});
}, t.prototype.getConfig = function() {
return {value: this.value};
}, t.className = "Constant", t;
}(hn);
v.serialization.registerClass(ny);
var ry = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this) || this;
return r.DEFAULT_MINVAL = -0.05, r.DEFAULT_MAXVAL = 0.05, r.minval = e.minval || r.DEFAULT_MINVAL, r.maxval = e.maxval || r.DEFAULT_MAXVAL, r.seed = e.seed, r;
}
return t.prototype.apply = function(e, r) {
return v.randomUniform(e, this.minval, this.maxval, r);
}, t.prototype.getConfig = function() {
return {minval: this.minval, maxval: this.maxval, seed: this.seed};
}, t.className = "RandomUniform", t;
}(hn);
v.serialization.registerClass(ry);
var iy = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this) || this;
return r.DEFAULT_MEAN = 0, r.DEFAULT_STDDEV = 0.05, r.mean = e.mean || r.DEFAULT_MEAN, r.stddev = e.stddev || r.DEFAULT_STDDEV, r.seed = e.seed, r;
}
return t.prototype.apply = function(e, r) {
if (r = r || "float32", r !== "float32" && r !== "int32")
throw new Re("randomNormal does not support dType " + r + ".");
return uo(e, this.mean, this.stddev, r, this.seed);
}, t.prototype.getConfig = function() {
return {mean: this.mean, stddev: this.stddev, seed: this.seed};
}, t.className = "RandomNormal", t;
}(hn);
v.serialization.registerClass(iy);
var ay = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this) || this;
return r.DEFAULT_MEAN = 0, r.DEFAULT_STDDEV = 0.05, r.mean = e.mean || r.DEFAULT_MEAN, r.stddev = e.stddev || r.DEFAULT_STDDEV, r.seed = e.seed, r;
}
return t.prototype.apply = function(e, r) {
if (r = r || "float32", r !== "float32" && r !== "int32")
throw new Re("truncatedNormal does not support dType " + r + ".");
return v.truncatedNormal(e, this.mean, this.stddev, r, this.seed);
}, t.prototype.getConfig = function() {
return {mean: this.mean, stddev: this.stddev, seed: this.seed};
}, t.className = "TruncatedNormal", t;
}(hn);
v.serialization.registerClass(ay);
var sy = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this) || this;
return r.gain = e.gain != null ? e.gain : 1, r;
}
return t.prototype.apply = function(e, r) {
var i = this;
return v.tidy(function() {
if (e.length !== 2 || e[0] !== e[1])
throw new M("Identity matrix initializer can only be used for 2D square matrices.");
return v.mul(i.gain, v.eye(e[0]));
});
}, t.prototype.getConfig = function() {
return {gain: this.gain};
}, t.className = "Identity", t;
}(hn);
v.serialization.registerClass(sy);
function VO(n, t) {
t === void 0 && (t = "channelsLast");
var e, r;
if (mt(t), n.length === 2)
e = n[0], r = n[1];
else if ([3, 4, 5].indexOf(n.length) !== -1) {
if (t === "channelsFirst") {
var i = Lr(n, 2);
e = n[1] * i, r = n[0] * i;
} else if (t === "channelsLast") {
var i = Lr(n, 0, n.length - 2);
e = n[n.length - 2] * i, r = n[n.length - 1] * i;
}
} else {
var a = Lr(n);
e = Math.sqrt(a), r = Math.sqrt(a);
}
return [e, r];
}
var Jt = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this) || this;
if (e.scale < 0)
throw new M("scale must be a positive float. Got: " + e.scale);
return r.scale = e.scale == null ? 1 : e.scale, r.mode = e.mode == null ? "fanIn" : e.mode, MO(r.mode), r.distribution = e.distribution == null ? "normal" : e.distribution, HO(r.distribution), r.seed = e.seed, r;
}
return t.prototype.apply = function(e, r) {
var i = VO(e), a = i[0], s = i[1], o = this.scale;
if (this.mode === "fanIn" ? o /= Math.max(1, a) : this.mode === "fanOut" ? o /= Math.max(1, s) : o /= Math.max(1, (a + s) / 2), this.distribution === "normal") {
var c = Math.sqrt(o);
if (r = r || "float32", r !== "float32" && r !== "int32")
throw new Re(this.getClassName() + " does not support dType " + r + ".");
return v.truncatedNormal(e, 0, c, r, this.seed);
} else {
var l = Math.sqrt(3 * o);
return v.randomUniform(e, -l, l, r);
}
}, t.prototype.getConfig = function() {
return {scale: this.scale, mode: this.mode, distribution: this.distribution, seed: this.seed};
}, t.className = "VarianceScaling", t;
}(hn);
v.serialization.registerClass(Jt);
var Nh = function(n) {
Q(t, n);
function t(e) {
return n.call(this, {scale: 1, mode: "fanAvg", distribution: "uniform", seed: e == null ? null : e.seed}) || this;
}
return t.prototype.getClassName = function() {
return Jt.className;
}, t.className = "GlorotUniform", t;
}(Jt);
v.serialization.registerClass(Nh);
var _h = function(n) {
Q(t, n);
function t(e) {
return n.call(this, {scale: 1, mode: "fanAvg", distribution: "normal", seed: e == null ? null : e.seed}) || this;
}
return t.prototype.getClassName = function() {
return Jt.className;
}, t.className = "GlorotNormal", t;
}(Jt);
v.serialization.registerClass(_h);
var Ch = function(n) {
Q(t, n);
function t(e) {
return n.call(this, {scale: 2, mode: "fanIn", distribution: "normal", seed: e == null ? null : e.seed}) || this;
}
return t.prototype.getClassName = function() {
return Jt.className;
}, t.className = "HeNormal", t;
}(Jt);
v.serialization.registerClass(Ch);
var Rh = function(n) {
Q(t, n);
function t(e) {
return n.call(this, {scale: 2, mode: "fanIn", distribution: "uniform", seed: e == null ? null : e.seed}) || this;
}
return t.prototype.getClassName = function() {
return Jt.className;
}, t.className = "HeUniform", t;
}(Jt);
v.serialization.registerClass(Rh);
var Oh = function(n) {
Q(t, n);
function t(e) {
return n.call(this, {scale: 1, mode: "fanIn", distribution: "normal", seed: e == null ? null : e.seed}) || this;
}
return t.prototype.getClassName = function() {
return Jt.className;
}, t.className = "LeCunNormal", t;
}(Jt);
v.serialization.registerClass(Oh);
var Eh = function(n) {
Q(t, n);
function t(e) {
return n.call(this, {scale: 1, mode: "fanIn", distribution: "uniform", seed: e == null ? null : e.seed}) || this;
}
return t.prototype.getClassName = function() {
return Jt.className;
}, t.className = "LeCunNormal", t;
}(Jt);
v.serialization.registerClass(Eh);
var oy = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this) || this;
if (r.DEFAULT_GAIN = 1, r.gain = e.gain == null ? r.DEFAULT_GAIN : e.gain, r.seed = e.seed, r.seed != null)
throw new Re("Random seed is not implemented for Orthogonal Initializer yet.");
return r;
}
return t.prototype.apply = function(e, r) {
var i = this;
return v.tidy(function() {
if (e.length < 2)
throw new Re("Shape must be at least 2D.");
e[0] * e[1] > 2e3 && console.warn("Orthogonal initializer is being called on a matrix with more " + ("than 2000 (" + e[0] * e[1] + ") elements: ") + "Slowness may result.");
var a = e[0] > e[1] ? [e[1], e[0]] : e, s = uo(a, 0, 1, "float32"), o = v.linalg.gramSchmidt(s);
return e[0] > e[1] && (o = o.transpose()), v.mul(i.gain, o);
});
}, t.prototype.getConfig = function() {
return {gain: this.gain, seed: this.seed};
}, t.className = "Orthogonal", t;
}(hn);
v.serialization.registerClass(oy);
var cy = {constant: "Constant", glorotNormal: "GlorotNormal", glorotUniform: "GlorotUniform", heNormal: "HeNormal", heUniform: "HeUniform", identity: "Identity", leCunNormal: "LeCunNormal", leCunUniform: "LeCunUniform", ones: "Ones", orthogonal: "Orthogonal", randomNormal: "RandomNormal", randomUniform: "RandomUniform", truncatedNormal: "TruncatedNormal", varianceScaling: "VarianceScaling", zeros: "Zeros"};
function ly(n, t) {
return t === void 0 && (t = {}), Wa(n, v.serialization.SerializationMap.getMap().classNameMap, t, "initializer");
}
function lt(n) {
return vh(n);
}
function at(n) {
if (typeof n == "string") {
var t = n in cy ? cy[n] : n;
if (t === "GlorotNormal")
return new _h();
if (t === "GlorotUniform")
return new Nh();
if (t === "HeNormal")
return new Ch();
if (t === "HeUniform")
return new Rh();
if (t === "LeCunNormal")
return new Oh();
if (t === "LeCunUniform")
return new Eh();
var e = {};
return e.className = t, e.config = {}, ly(e);
} else
return n instanceof hn ? n : ly(n);
}
function GO() {
return new ty();
}
function qO() {
return new Th();
}
function YO(n) {
return new ny(n);
}
function KO(n) {
return new ry(n);
}
function jO(n) {
return new iy(n);
}
function $O(n) {
return new ay(n);
}
function XO(n) {
return new sy(n);
}
function JO(n) {
return new Jt(n);
}
function ZO(n) {
return new Nh(n);
}
function QO(n) {
return new _h(n);
}
function eE(n) {
return new Ch(n);
}
function tE(n) {
return new Rh(n);
}
function nE(n) {
return new Oh(n);
}
function rE(n) {
return new Eh(n);
}
function iE(n) {
return new oy(n);
}
var aE = {__proto__: null, zeros: GO, ones: qO, constant: YO, randomUniform: KO, randomNormal: jO, truncatedNormal: $O, identity: XO, varianceScaling: JO, glorotUniform: ZO, glorotNormal: QO, heNormal: eE, heUniform: tE, leCunNormal: nE, leCunUniform: rE, orthogonal: iE};
var sE = 0;
function uy() {
return sE++;
}
var ho = {};
function po(n) {
return n === void 0 && (n = ""), n in ho || (ho[n] = 0), ho[n] += 1, n + ho[n].toString();
}
function Dh(n) {
return Array.isArray(n) && Array.isArray(n[0]);
}
function fo(n) {
return n.length === 0 ? [] : Array.isArray(n[0]) ? n : [n];
}
function Oe(n) {
var t;
if (Array.isArray(n)) {
if (n.length !== 1)
throw new M("Expected Tensor length to be 1; got " + n.length);
t = n[0];
} else
t = n;
return t;
}
function Xe(n) {
if (Array.isArray(n) && Array.isArray(n[0])) {
if (n.length === 1)
return n = n, n[0];
throw new M("Expected exactly 1 Shape; got " + n.length);
} else
return n;
}
function mo(n) {
for (var t = 0, e = 0, r = n; e < r.length; e++) {
var i = r[e];
i.shape.length === 0 ? t += 1 : t += i.shape.reduce(function(a, s) {
return a * s;
});
}
return t;
}
var hy = "Variable", dy = function() {
function n(t, e, r, i, a) {
e === void 0 && (e = "float32"), r === void 0 && (r = hy), i === void 0 && (i = true), a === void 0 && (a = null), this.dtype = e != null ? e : "float32", this.shape = t.shape, this.id = uy(), r = r != null ? r : hy, this.originalName = $0(r), this.name = X0(this.originalName), this.trainable_ = i, this.constraint = a, this.val = v.variable(t, this.trainable_, this.name, this.dtype);
}
return n.prototype.read = function() {
return this.assertNotDisposed(), this.val;
}, n.prototype.write = function(t) {
return this.assertNotDisposed(), oE(this.val, t), this.val.id !== t.id && (this.val.assign(t), this.constraint != null && this.val.assign(this.constraint.apply(this.val))), this;
}, n.prototype.dispose = function() {
this.assertNotDisposed(), this.val.dispose();
}, n.prototype.assertNotDisposed = function() {
if (this.val.isDisposed)
throw new Error("LayersVariable " + this.name + " is already disposed.");
}, Object.defineProperty(n.prototype, "trainable", {get: function() {
return this.trainable_;
}, set: function(t) {
this.trainable_ = t, this.val.trainable = t;
}, enumerable: true, configurable: true}), n;
}();
function oE(n, t) {
if (n.shape.toString() !== t.shape.toString())
throw new Error("Shape mismatch: " + JSON.stringify(n.shape) + " vs. " + JSON.stringify(t.shape));
}
function kh(n) {
return n.map(function(t) {
return t.read();
});
}
function Fh(n) {
n.forEach(function(t) {
var e = t[0];
e.write(t[1]);
});
}
var Ct = function() {
function n(t) {
this.dtype = t.dtype, this.shape = t.shape, t.shape != null ? this.ndim = t.shape.length : this.ndim = t.ndim, this.maxNDim = t.maxNDim, this.minNDim = t.minNDim, this.axes = t.axes || {};
}
return n;
}(), xn = function() {
function n(t, e, r, i, a, s, o) {
this.dtype = t, this.shape = e, this.sourceLayer = r, this.inputs = i, this.callArgs = a, this.outputTensorIndex = o, this.id = uy(), s != null && (this.originalName = $0(s), this.name = X0(this.originalName)), this.rank = e.length;
}
return n;
}(), cE = 0, go = function() {
function n(t, e) {
this.callArgs = e, this.id = cE++, this.outboundLayer = t.outboundLayer, this.inboundLayers = t.inboundLayers, this.nodeIndices = t.nodeIndices, this.tensorIndices = t.tensorIndices, this.inputTensors = t.inputTensors, this.outputTensors = t.outputTensors, this.inputMasks = t.inputMasks, this.outputMasks = t.outputMasks, this.inputShapes = t.inputShapes, this.outputShapes = t.outputShapes;
for (var r = 0, i = t.inboundLayers; r < i.length; r++) {
var a = i[r];
a != null && a.outboundNodes.push(this);
}
t.outboundLayer.inboundNodes.push(this);
}
return n.prototype.getConfig = function() {
for (var t = [], e = 0, r = this.inboundLayers; e < r.length; e++) {
var i = r[e];
i != null ? t.push(i.name) : t.push(null);
}
return {outboundLayer: this.outboundLayer ? this.outboundLayer.name : null, inboundLayers: t, nodeIndices: this.nodeIndices, tensorIndices: this.tensorIndices};
}, n;
}(), lE = 0, Fe = function(n) {
Q(t, n);
function t(e) {
e === void 0 && (e = {});
var r = n.call(this) || this;
r._callHook = null, r._addedWeightNames = [], r._stateful = false, r.id = lE++, r.activityRegularizer = null, r.inputSpec = null, r.supportsMasking = false, r._trainableWeights = [], r._nonTrainableWeights = [], r._losses = [], r._updates = [], r._built = false, r.inboundNodes = [], r.outboundNodes = [];
var i = e.name;
if (!i) {
var a = r.getClassName();
i = Qn(a) + "_" + po(a);
}
if (r.name = i, r.trainable_ = e.trainable == null ? true : e.trainable, e.inputShape != null || e.batchInputShape != null) {
var s = void 0;
if (e.batchInputShape != null)
s = e.batchInputShape;
else if (e.inputShape != null) {
var o = null;
e.batchSize != null && (o = e.batchSize), s = [o].concat(e.inputShape);
}
r.batchInputShape = s;
var c = e.dtype;
c == null && (c = e.inputDType), c == null && (c = "float32"), r.dtype = c;
}
return e.weights != null ? r.initialWeights = e.weights : r.initialWeights = null, r._refCount = null, r.fastWeightInitDuringBuild = false, r;
}
return t.nodeKey = function(e, r) {
return e.name + "_ib-" + r.toString();
}, t.prototype.getNodeAtIndex = function(e, r) {
if (this.inboundNodes.length === 0)
throw new Dn("The layer has never been called " + ("and thus has no defined " + r + "."));
if (this.inboundNodes.length <= e)
throw new M("Asked to get " + r + " at node " + e + ", " + ("but the layer has only " + this.inboundNodes.length + " inbound nodes."));
return this.inboundNodes[e];
}, t.prototype.getInputAt = function(e) {
return Vt(this.getNodeAtIndex(e, "input").inputTensors);
}, t.prototype.getOutputAt = function(e) {
return Vt(this.getNodeAtIndex(e, "output").outputTensors);
}, Object.defineProperty(t.prototype, "input", {get: function() {
if (this.inboundNodes.length > 1)
throw new br("Layer " + this.name + ' has multiple inbound nodes, hence the notion of "layer input" is ill-defined. Use `getInputAt(nodeIndex)` instead.');
if (this.inboundNodes.length === 0)
throw new br("Layer " + this.name + " is not connected, no input to return.");
return Vt(this.getNodeAtIndex(0, "input").inputTensors);
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "output", {get: function() {
if (this.inboundNodes.length === 0)
throw new br("Layer " + this.name + " has no inbound nodes.");
if (this.inboundNodes.length > 1)
throw new br("Layer " + this.name + ' has multiple inbound nodes, hence the notion of "layer output" is ill-defined. Use `getOutputAt(nodeIndex)` instead.');
return Vt(this.getNodeAtIndex(0, "output").outputTensors);
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "losses", {get: function() {
return this._losses;
}, enumerable: true, configurable: true}), t.prototype.calculateLosses = function() {
return this.losses.map(function(e) {
return e();
});
}, Object.defineProperty(t.prototype, "updates", {get: function() {
return this._updates;
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "built", {get: function() {
return this._built;
}, set: function(e) {
this._built = e;
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "trainable", {get: function() {
return this.trainable_;
}, set: function(e) {
this._trainableWeights.forEach(function(r) {
return r.trainable = e;
}), this.trainable_ = e;
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "trainableWeights", {get: function() {
return this.trainable_ ? this._trainableWeights.filter(function(e) {
return e.trainable;
}) : [];
}, set: function(e) {
this._trainableWeights = e;
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "nonTrainableWeights", {get: function() {
return this.trainable ? this._trainableWeights.filter(function(e) {
return !e.trainable;
}).concat(this._nonTrainableWeights) : this._trainableWeights.concat(this._nonTrainableWeights);
}, set: function(e) {
this._nonTrainableWeights = e;
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "weights", {get: function() {
return this.trainableWeights.concat(this.nonTrainableWeights);
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "stateful", {get: function() {
return this._stateful;
}, enumerable: true, configurable: true}), t.prototype.resetStates = function() {
if (!this.stateful)
throw new Error("Cannot call the resetStates() method of a non-stateful Layer object.");
}, t.prototype.assertInputCompatibility = function(e) {
if (e = nt(e), this.inputSpec == null || this.inputSpec.length === 0)
return;
var r = nt(this.inputSpec);
if (e.length !== r.length)
throw new M("Layer " + this.name + " expects " + r.length + " inputs, " + ("but it received " + e.length + " input tensors. ") + ("Input received: " + e));
for (var i = 0; i < e.length; i++) {
var a = e[i], s = r[i];
if (s == null)
continue;
var o = a.rank;
if (s.ndim != null && o !== s.ndim)
throw new M("Input " + i + " is incompatible with layer " + this.name + ": " + ("expected ndim=" + s.ndim + ", found ndim=" + o));
if (s.maxNDim != null && o > s.maxNDim)
throw new M("Input " + i + " is incompatible with layer " + this.name + (": expected max_ndim=" + s.maxNDim + ", found ndim=" + o));
if (s.minNDim != null && o < s.minNDim)
throw new M("Input " + i + " is incompatible with layer " + this.name + (": expected min_ndim=" + s.minNDim + ", found ndim=" + o + "."));
if (s.dtype != null && a.dtype !== s.dtype)
throw new M("Input " + i + " is incompatible with layer " + this.name + " " + (": expected dtype=" + s.dtype + ", found dtype=" + a.dtype + "."));
if (s.axes) {
var c = a.shape;
for (var l in s.axes) {
var u = Number(l), h = s.axes[l], d = u >= 0 ? c[u] : c[c.length + u];
if (h != null && [h, null].indexOf(d) === -1)
throw new M("Input " + i + " is incompatible with layer " + (this.name + ": expected axis " + u + " of input shape to ") + ("have value " + h + " but got shape " + c + "."));
}
}
if (s.shape != null)
for (var p = 0; p < s.shape.length; ++p) {
var f = s.shape[p], m = a.shape[p];
if (f != null && m != null && f !== m)
throw new M("Input " + i + " is incompatible with layer " + (this.name + ": expected shape=" + s.shape + ", ") + ("found shape=" + a.shape + "."));
}
}
}, t.prototype.call = function(e, r) {
return e;
}, t.prototype.invokeCallHook = function(e, r) {
this._callHook != null && this._callHook(e, r);
}, t.prototype.setCallHook = function(e) {
this._callHook = e;
}, t.prototype.clearCallHook = function() {
this._callHook = null;
}, t.prototype.apply = function(e, r) {
var i = this;
r = r || {}, this.assertNotDisposed();
for (var a = nt(e), s = true, o = 0, c = a; o < c.length; o++) {
var l = c[o];
if (!(l instanceof xn)) {
s = false;
break;
}
}
for (var u = true, h = 0, d = a; h < d.length; h++) {
var l = d[h];
if (l instanceof xn) {
u = false;
break;
}
}
if (s === u)
throw new M("Arguments to apply() must be all SymbolicTensors or all Tensors");
return ri(this.name, function() {
if (!i.built) {
i.assertInputCompatibility(e);
for (var p = [], f = 0, m = nt(e); f < m.length; f++) {
var g = m[f];
p.push(g.shape);
}
i.build(Vt(p)), i.built = true, i.initialWeights && i.setWeights(i.initialWeights), i._refCount === null && u && (i._refCount = 1);
}
if (i.assertInputCompatibility(e), u) {
for (var y = i.call(e, r), w = nt(y), b = [], x = 0, L = w; x < L.length; x++) {
var N = L[x];
a.indexOf(N) !== -1 && (N = N.clone()), b.push(N);
}
if (y = Vt(b), i.activityRegularizer != null)
throw new Re("Layer invocation in the presence of activity regularizer(s) is not supported yet.");
return y;
} else {
var I = uE(e), C = i.computeOutputShape(I), y = void 0, O = hE(e);
if (i.warnOnIncompatibleInputShape(Array.isArray(e) ? I[0] : I), C != null && C.length > 0 && Array.isArray(C[0]) ? y = C.map(function(F, k) {
return new xn(O, F, i, nt(e), r, i.name, k);
}) : y = new xn(O, C, i, nt(e), r, i.name), i.addInboundNode(e, y, null, null, I, C, r), i._refCount++, i.activityRegularizer != null)
throw new Re("Layer invocation in the presence of activity regularizer(s) is not supported yet.");
return y;
}
});
}, t.prototype.warnOnIncompatibleInputShape = function(e) {
if (this.batchInputShape == null)
return;
if (e.length !== this.batchInputShape.length)
console.warn("The rank of the input tensor provided (shape: " + (JSON.stringify(e) + ") does not match that of the ") + ("batchInputShape (" + JSON.stringify(this.batchInputShape) + ") ") + ("of the layer " + this.name));
else {
var r = false;
this.batchInputShape.forEach(function(i, a) {
i != null && e[a] != null && e[a] !== i && (r = true);
}), r && console.warn("The shape of the input tensor " + ("(" + JSON.stringify(e) + ") does not ") + ("match the expectation of layer " + this.name + ": ") + ("" + JSON.stringify(this.batchInputShape)));
}
}, Object.defineProperty(t.prototype, "outputShape", {get: function() {
if (this.inboundNodes == null || this.inboundNodes.length === 0)
throw new br("The layer " + this.name + " has never been called and thus has no defined output shape.");
for (var e = [], r = 0, i = this.inboundNodes; r < i.length; r++) {
var a = i[r], s = JSON.stringify(a.outputShapes);
e.indexOf(s) === -1 && e.push(s);
}
if (e.length === 1) {
var o = this.inboundNodes[0].outputShapes;
return Array.isArray(o) && Array.isArray(o[0]) && o.length === 1 ? o[0] : o;
} else
throw new br("The layer " + this.name + ' has multiple inbound nodes with different output shapes. Hence the notion of "output shape" is ill-defined for the layer.');
}, enumerable: true, configurable: true}), t.prototype.countParams = function() {
if (!this.built)
throw new Dn("You tried to call countParams() on " + this.name + ", but the layer is not built yet. Build it first by calling build(batchInputShape).");
return mo(this.weights);
}, t.prototype.build = function(e) {
this.built = true;
}, t.prototype.getWeights = function(e) {
return e === void 0 && (e = false), kh(e ? this.trainableWeights : this.weights);
}, t.prototype.setWeights = function(e) {
var r = this;
v.tidy(function() {
var i = r.weights;
if (i.length !== e.length)
throw new M('You called setWeights(weights) on layer "' + r.name + '" ' + ("with a weight list of length " + e.length + ", ") + ("but the layer was expecting " + i.length + " weights. ") + ("Provided weights: " + e + "..."));
if (i.length === 0)
return;
for (var a = [], s = kh(i), o = 0; o < s.length; ++o) {
var c = s[o], l = i[o], u = e[o];
if (!v.util.arraysEqual(c.shape, u.shape))
throw new M("Layer weight shape " + c.shape + " " + ("not compatible with provided weight shape " + u.shape));
a.push([l, u]);
}
Fh(a);
});
}, t.prototype.addWeight = function(e, r, i, a, s, o, c) {
if (this._addedWeightNames.indexOf(e) !== -1)
throw new M("Duplicate weight name " + e + " for layer " + this.name);
this._addedWeightNames.push(e), i == null && (i = "float32"), this.fastWeightInitDuringBuild && (a = at("zeros"));
var l = a.apply(r, i), u = new dy(l, i, e, o, c);
return l.dispose(), s != null && this.addLoss(function() {
return s.apply(u.read());
}), o == null && (o = true), o ? this._trainableWeights.push(u) : this._nonTrainableWeights.push(u), u;
}, t.prototype.setFastWeightInitDuringBuild = function(e) {
this.fastWeightInitDuringBuild = e;
}, t.prototype.addLoss = function(e) {
var r;
if (e == null || Array.isArray(e) && e.length === 0)
return;
e = nt(e), this._losses !== void 0 && this._losses !== null && (r = this.losses).push.apply(r, e);
}, t.prototype.computeOutputShape = function(e) {
return e;
}, t.prototype.computeMask = function(e, r) {
var i = this;
if (!this.supportsMasking) {
if (r != null)
if (Array.isArray(r))
r.forEach(function(a) {
if (a != null)
throw new TypeError("Layer " + i.name + " does not support masking, but was passed an inputMask.");
});
else
throw new TypeError("Layer " + this.name + " does not support masking, but was passed an inputMask.");
return null;
}
return r;
}, t.prototype.addInboundNode = function(e, r, i, a, s, o, c) {
c === void 0 && (c = null);
var l = nt(e);
r = nt(r), i = nt(i), a = nt(a), s = fo(s), o = fo(o);
for (var u = [], h = [], d = [], p = 0, f = l; p < f.length; p++) {
var m = f[p];
u.push(m.sourceLayer), h.push(m.nodeIndex), d.push(m.tensorIndex);
}
new go({outboundLayer: this, inboundLayers: u, nodeIndices: h, tensorIndices: d, inputTensors: l, outputTensors: r, inputMasks: i, outputMasks: a, inputShapes: s, outputShapes: o}, c);
for (var g = 0; g < r.length; g++)
r[g].sourceLayer = this, r[g].nodeIndex = this.inboundNodes.length - 1, r[g].tensorIndex = g;
}, t.prototype.getConfig = function() {
var e = {name: this.name, trainable: this.trainable};
return this.batchInputShape != null && (e.batchInputShape = this.batchInputShape), this.dtype != null && (e.dtype = this.dtype), e;
}, t.prototype.disposeWeights = function() {
return this.weights.forEach(function(e) {
return e.dispose();
}), this.weights.length;
}, t.prototype.assertNotDisposed = function() {
if (this._refCount === 0)
throw new Error("Layer '" + this.name + "' is already disposed.");
}, t.prototype.dispose = function() {
if (!this.built)
throw new Error("Cannot dispose Layer " + this.name + " because it has not been built yet.");
if (this._refCount === null)
throw new Error("Cannot dispose Layer " + this.name + " because it has not been used yet.");
this.assertNotDisposed();
var e = 0;
return --this._refCount === 0 && (e = this.disposeWeights()), {refCountAfterDispose: this._refCount, numDisposedVariables: e};
}, t;
}(v.serialization.Serializable);
function uE(n) {
n = nt(n);
for (var t = [], e = 0, r = n; e < r.length; e++) {
var i = r[e];
t.push(i.shape);
}
return Vt(t);
}
function hE(n) {
return "float32";
}
function py(n, t, e) {
if ((t == null || e != null && e > 0) && (t = n.sourceLayer, e = n.nodeIndex), t.inboundNodes.length === 0)
return [n];
var r = t.inboundNodes[e];
if (r.inboundLayers.length === 0)
return r.inputTensors;
for (var i = [], a = 0; a < r.inboundLayers.length; a++)
for (var s = r.inputTensors[a], o = r.inboundLayers[a], c = r.nodeIndices[a], l = py(s, o, c), u = 0, h = l; u < h.length; u++) {
var d = h[u];
i.indexOf(d) === -1 && i.push(d);
}
return i;
}
var Va = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, {dtype: e.dtype, name: e.name != null ? e.name : po("input").toString()}) || this;
if (e.batchSize == null && (e.batchSize = null), e.sparse == null && (e.sparse = false), r.trainable = false, r.built = true, r.sparse = e.sparse, e.inputShape != null && e.batchInputShape != null)
throw new M("Only provide the inputShape OR batchInputShape argument to inputLayer, not both at the same time.");
var i = e.batchInputShape;
if (i == null) {
if (e.inputShape == null)
throw new M("An InputLayer should be passed either a `batchInputShape` or an `inputShape`.");
i = [e.batchSize].concat(e.inputShape);
} else if (e.batchSize != null)
throw new M("Cannot specify batchSize if batchInputShape is specified when creating an InputLayer.");
var a = e.dtype || "float32";
r.batchInputShape = i, r.dtype = a, r.inputSpec = [{shape: i}];
var s = new xn(r.dtype, r.batchInputShape, r, [], {}, r.name);
return s.nodeIndex = 0, s.tensorIndex = 0, new go({outboundLayer: r, inboundLayers: [], nodeIndices: [], tensorIndices: [], inputTensors: [s], outputTensors: [s], inputMasks: [null], outputMasks: [null], inputShapes: [i], outputShapes: [i]}), r;
}
return t.prototype.apply = function(e, r) {
throw new M("Cannot pass any input to an " + ("InputLayer's apply() method. InputLayer name: " + this.name));
}, t.prototype.dispose = function() {
return {refCountAfterDispose: this._refCount, numDisposedVariables: 0};
}, t.prototype.getConfig = function() {
return {batchInputShape: this.batchInputShape, dtype: this.dtype, sparse: this.sparse, name: this.name};
}, t.className = "InputLayer", t;
}(Fe);
v.serialization.registerClass(Va);
function fy(n) {
if (n.batchShape == null && n.shape == null)
throw new Error("Please provide to Input either a `shape` or a `batchShape` argument. Note that `shape` does not include the batch dimension.");
if (n.batchShape != null && n.shape != null)
throw new M("Please provide either a `shape` or `batchShape` argument to Input, but not both.");
var t = n.batchShape;
n.shape != null && t == null && (t = [null].concat(n.shape));
var e = n.dtype;
e == null && (e = "float32");
var r = new Va({batchInputShape: t, name: n.name, dtype: e, sparse: n.sparse}), i = r.inboundNodes[0].outputTensors;
return i[0];
}
function Ir(n) {
return Ae(this, void 0, void 0, function() {
var t, e, r, i, a, s, o, c;
return xe(this, function(l) {
switch (l.label) {
case 0:
if (n == null)
return [2];
t = [], e = [], r = [];
for (i in n)
a = n[i], typeof a != "number" && (s = a, t.push(s.data()), e.push(i), r.push(s));
return t.length > 0 ? [4, Promise.all(t)] : [3, 2];
case 1:
for (o = l.sent(), c = 0; c < o.length; ++c)
n[e[c]] = o[c][0];
v.dispose(r), l.label = 2;
case 2:
return [2];
}
});
});
}
function my(n) {
if (n == null)
return;
for (var t in n) {
var e = n[t];
typeof e != "number" && e.dispose();
}
}
var gy;
(function(n) {
n[n.SILENT = 0] = "SILENT", n[n.VERBOSE = 1] = "VERBOSE";
})(gy || (gy = {}));
var dE = 125, qi = function() {
function n() {
this.validationData = null;
}
return n.prototype.setParams = function(t) {
this.params = t;
}, n.prototype.onEpochBegin = function(t, e) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(r) {
return [2];
});
});
}, n.prototype.onEpochEnd = function(t, e) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(r) {
return [2];
});
});
}, n.prototype.onBatchBegin = function(t, e) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(r) {
return [2];
});
});
}, n.prototype.onBatchEnd = function(t, e) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(r) {
return [2];
});
});
}, n.prototype.onTrainBegin = function(t) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(e) {
return [2];
});
});
}, n.prototype.onTrainEnd = function(t) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(e) {
return [2];
});
});
}, n.prototype.setModel = function(t) {
}, n;
}(), yy = function() {
function n(t, e) {
e === void 0 && (e = 10), t == null && (t = []), this.callbacks = t, this.queueLength = e;
}
return n.prototype.append = function(t) {
this.callbacks.push(t);
}, n.prototype.setParams = function(t) {
for (var e = 0, r = this.callbacks; e < r.length; e++) {
var i = r[e];
i.setParams(t);
}
}, n.prototype.setModel = function(t) {
for (var e = 0, r = this.callbacks; e < r.length; e++) {
var i = r[e];
i.setModel(t);
}
}, n.prototype.onEpochBegin = function(t, e) {
return Ae(this, void 0, void 0, function() {
var r, i, a;
return xe(this, function(s) {
switch (s.label) {
case 0:
e == null && (e = {}), r = 0, i = this.callbacks, s.label = 1;
case 1:
return r < i.length ? (a = i[r], [4, a.onEpochBegin(t, e)]) : [3, 4];
case 2:
s.sent(), s.label = 3;
case 3:
return r++, [3, 1];
case 4:
return [2];
}
});
});
}, n.prototype.onEpochEnd = function(t, e) {
return Ae(this, void 0, void 0, function() {
var r, i, a;
return xe(this, function(s) {
switch (s.label) {
case 0:
e == null && (e = {}), r = 0, i = this.callbacks, s.label = 1;
case 1:
return r < i.length ? (a = i[r], [4, a.onEpochEnd(t, e)]) : [3, 4];
case 2:
s.sent(), s.label = 3;
case 3:
return r++, [3, 1];
case 4:
return [2];
}
});
});
}, n.prototype.onBatchBegin = function(t, e) {
return Ae(this, void 0, void 0, function() {
var r, i, a;
return xe(this, function(s) {
switch (s.label) {
case 0:
e == null && (e = {}), r = 0, i = this.callbacks, s.label = 1;
case 1:
return r < i.length ? (a = i[r], [4, a.onBatchBegin(t, e)]) : [3, 4];
case 2:
s.sent(), s.label = 3;
case 3:
return r++, [3, 1];
case 4:
return [2];
}
});
});
}, n.prototype.onBatchEnd = function(t, e) {
return Ae(this, void 0, void 0, function() {
var r, i, a;
return xe(this, function(s) {
switch (s.label) {
case 0:
e == null && (e = {}), r = 0, i = this.callbacks, s.label = 1;
case 1:
return r < i.length ? (a = i[r], [4, a.onBatchEnd(t, e)]) : [3, 4];
case 2:
s.sent(), s.label = 3;
case 3:
return r++, [3, 1];
case 4:
return [2];
}
});
});
}, n.prototype.onTrainBegin = function(t) {
return Ae(this, void 0, void 0, function() {
var e, r, i;
return xe(this, function(a) {
switch (a.label) {
case 0:
t == null && (t = {}), e = 0, r = this.callbacks, a.label = 1;
case 1:
return e < r.length ? (i = r[e], [4, i.onTrainBegin(t)]) : [3, 4];
case 2:
a.sent(), a.label = 3;
case 3:
return e++, [3, 1];
case 4:
return [2];
}
});
});
}, n.prototype.onTrainEnd = function(t) {
return Ae(this, void 0, void 0, function() {
var e, r, i;
return xe(this, function(a) {
switch (a.label) {
case 0:
t == null && (t = {}), e = 0, r = this.callbacks, a.label = 1;
case 1:
return e < r.length ? (i = r[e], [4, i.onTrainEnd(t)]) : [3, 4];
case 2:
a.sent(), a.label = 3;
case 3:
return e++, [3, 1];
case 4:
return [2];
}
});
});
}, n;
}(), pE = function(n) {
Q(t, n);
function t() {
return n.call(this) || this;
}
return t.prototype.onEpochBegin = function(e) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(r) {
return this.seen = 0, this.totals = {}, [2];
});
});
}, t.prototype.onBatchEnd = function(e, r) {
return Ae(this, void 0, void 0, function() {
var i, a, s, o, c = this;
return xe(this, function(l) {
r == null && (r = {}), i = r.size == null ? 0 : r.size, this.seen += i, a = function(u) {
var h = r[u];
if (typeof h == "number")
s.totals.hasOwnProperty(u) || (s.totals[u] = 0), s.totals[u] = s.totals[u] + h * i;
else {
var d = void 0;
u in s.totals ? d = s.totals[u] : s.totals[u] = 0;
var p = v.tidy(function() {
return v.add(c.totals[u], v.mul(h, i));
});
s.totals[u] = p, d != null && d.dispose();
}
}, s = this;
for (o in r)
a(o);
return [2];
});
});
}, t.prototype.onEpochEnd = function(e, r) {
return Ae(this, void 0, void 0, function() {
var i, a, s, o, c, l = this;
return xe(this, function(u) {
if (r != null)
for (i = function(h) {
if (a.totals[h] == null)
return "continue";
typeof a.totals[h] == "number" ? r[h] = a.totals[h] / a.seen : v.tidy(function() {
var d = v.mul(v.div(1, l.seen), l.totals[h]);
r[h] = d, l.totals[h].dispose(), v.keep(r[h]);
});
}, a = this, s = 0, o = this.params.metrics; s < o.length; s++)
c = o[s], i(c);
return [2];
});
});
}, t;
}(qi), vy = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.onTrainBegin = function(e) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(r) {
return this.epoch = [], this.history = {}, [2];
});
});
}, t.prototype.onEpochEnd = function(e, r) {
return Ae(this, void 0, void 0, function() {
var i;
return xe(this, function(a) {
r == null && (r = {}), this.epoch.push(e);
for (i in r)
this.history[i] == null && (this.history[i] = []), this.history[i].push(r[i]);
return [2];
});
});
}, t.prototype.syncData = function() {
return Ae(this, void 0, void 0, function() {
var e, r, i, a, s, o, c, l, u, h;
return xe(this, function(d) {
switch (d.label) {
case 0:
e = [], r = [], i = [];
for (a in this.history)
for (s = this.history[a], o = 0; o < s.length; ++o)
typeof s[o] != "number" && (c = s[o], e.push(c.data()), r.push(a), i.push(o));
return [4, Promise.all(e)];
case 1:
for (l = d.sent(), u = 0; u < l.length; ++u)
h = this.history[r[u]][i[u]], h.dispose(), this.history[r[u]][i[u]] = l[u][0];
return [2];
}
});
});
}, t;
}(qi), wy = function(n) {
Q(t, n);
function t(e, r) {
var i = n.call(this) || this;
if (i.currentEpoch = 0, i.yieldEvery = r || "auto", i.yieldEvery === "auto" && (i.yieldEvery = dE), i.yieldEvery === "never" && e.onYield != null)
throw new Error("yieldEvery is `never` but you provided an `onYield` callback. Either change `yieldEvery` or remove the callback");
return v.util.isNumber(i.yieldEvery) && (i.maybeWait = bO(i.maybeWait.bind(i), i.yieldEvery)), i.trainBegin = e.onTrainBegin, i.trainEnd = e.onTrainEnd, i.epochBegin = e.onEpochBegin, i.epochEnd = e.onEpochEnd, i.batchBegin = e.onBatchBegin, i.batchEnd = e.onBatchEnd, i.yield = e.onYield, i;
}
return t.prototype.maybeWait = function(e, r, i) {
return Ae(this, void 0, void 0, function() {
var a;
return xe(this, function(s) {
switch (s.label) {
case 0:
return a = [], this.yield != null ? [4, Ir(i)] : [3, 2];
case 1:
s.sent(), a.push(this.yield(e, r, i)), s.label = 2;
case 2:
return a.push(v.nextFrame()), [4, Promise.all(a)];
case 3:
return s.sent(), [2];
}
});
});
}, t.prototype.onEpochBegin = function(e, r) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(i) {
switch (i.label) {
case 0:
return this.currentEpoch = e, this.epochBegin != null ? [4, Ir(r)] : [3, 3];
case 1:
return i.sent(), [4, this.epochBegin(e, r)];
case 2:
i.sent(), i.label = 3;
case 3:
return [2];
}
});
});
}, t.prototype.onEpochEnd = function(e, r) {
return Ae(this, void 0, void 0, function() {
var i;
return xe(this, function(a) {
switch (a.label) {
case 0:
return i = [], this.epochEnd != null ? [4, Ir(r)] : [3, 2];
case 1:
a.sent(), i.push(this.epochEnd(e, r)), a.label = 2;
case 2:
return this.yieldEvery === "epoch" && i.push(v.nextFrame()), [4, Promise.all(i)];
case 3:
return a.sent(), [2];
}
});
});
}, t.prototype.onBatchBegin = function(e, r) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(i) {
switch (i.label) {
case 0:
return this.batchBegin != null ? [4, Ir(r)] : [3, 3];
case 1:
return i.sent(), [4, this.batchBegin(e, r)];
case 2:
i.sent(), i.label = 3;
case 3:
return [2];
}
});
});
}, t.prototype.onBatchEnd = function(e, r) {
return Ae(this, void 0, void 0, function() {
var i;
return xe(this, function(a) {
switch (a.label) {
case 0:
return i = [], this.batchEnd != null ? [4, Ir(r)] : [3, 2];
case 1:
a.sent(), i.push(this.batchEnd(e, r)), a.label = 2;
case 2:
return this.yieldEvery === "batch" ? i.push(v.nextFrame()) : v.util.isNumber(this.yieldEvery) && i.push(this.maybeWait(this.currentEpoch, e, r)), [4, Promise.all(i)];
case 3:
return a.sent(), [2];
}
});
});
}, t.prototype.onTrainBegin = function(e) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(r) {
switch (r.label) {
case 0:
return this.trainBegin != null ? [4, Ir(e)] : [3, 3];
case 1:
return r.sent(), [4, this.trainBegin(e)];
case 2:
r.sent(), r.label = 3;
case 3:
return [2];
}
});
});
}, t.prototype.onTrainEnd = function(e) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(r) {
switch (r.label) {
case 0:
return this.trainEnd != null ? [4, Ir(e)] : [3, 3];
case 1:
return r.sent(), [4, this.trainEnd(e)];
case 2:
r.sent(), r.label = 3;
case 3:
return [2];
}
});
});
}, t;
}(qi);
function by(n, t) {
if (n == null && (n = {}), n instanceof qi)
return [n];
if (Array.isArray(n) && n[0] instanceof qi)
return n;
var e = nt(n);
return e.map(function(r) {
return new wy(r, t);
});
}
var xy = function() {
function n() {
}
return n.registerCallbackConstructor = function(t, e) {
v.util.assert(t >= 0 && Number.isInteger(t), function() {
return "Verbosity level is expected to be an integer >= 0, " + ("but got " + t);
}), n.checkForDuplicate(e), n.constructors[t] == null && (n.constructors[t] = []), n.constructors[t].push(e);
}, n.checkForDuplicate = function(t) {
for (var e in n.constructors) {
var r = n.constructors[+e];
r.forEach(function(i) {
if (i === t)
throw new M("Duplicate callback constructor.");
});
}
}, n.clear = function() {
n.constructors = {};
}, n.createCallbacks = function(t) {
var e = [];
for (var r in n.constructors) {
var i = +r;
t >= i && e.push.apply(e, n.constructors[i]);
}
return e.map(function(a) {
return new a();
});
}, n.constructors = {}, n;
}();
function Ly(n, t, e, r, i, a, s, o, c) {
var l = new vy(), u = [new pE()].concat(xy.createCallbacks(t));
n != null && u.push.apply(u, n), u.push(l);
var h = new yy(u);
return h.setParams({epochs: e, initialEpoch: r, samples: i, steps: a, batchSize: s, verbose: t, doValidation: o, metrics: c}), {callbackList: h, history: l};
}
function Ln(n, t, e) {
return t === void 0 && (t = {}), e === void 0 && (e = false), Wa(n, v.serialization.SerializationMap.getMap().classNameMap, t, "layer", e);
}
function yo(n, t) {
return v.tidy(function() {
n.dtype !== "float32" && (n = n.asType("float32"));
var e = v.sum(Ma(n), t, true), r = v.fill(e.shape, Lt()), i = v.sqrt(v.maximum(e, r));
return v.div(n, i);
});
}
function ai(n, t) {
return v.tidy(function() {
return v.mean(Ma(v.sub(t, n)), -1);
});
}
function vo(n, t) {
return v.tidy(function() {
return v.mean(v.abs(v.sub(t, n)), -1);
});
}
function Yi(n, t) {
return v.tidy(function() {
var e = v.sub(n, t), r = v.clipByValue(v.abs(n), Lt(), Number.MAX_VALUE), i = v.abs(v.div(e, r));
return v.mul(100, v.mean(i, -1));
});
}
function fE(n, t) {
return v.tidy(function() {
var e = v.clipByValue(t, Lt(), Number.MAX_VALUE), r = v.log(v.add(1, e)), i = v.clipByValue(n, Lt(), Number.MAX_VALUE), a = v.log(v.add(1, i));
return v.mean(Ma(v.sub(r, a)), -1);
});
}
function mE(n, t) {
return v.tidy(function() {
var e = v.maximum(0, v.sub(1, v.mul(n, t)));
return v.mean(Ma(e), -1);
});
}
function gE(n, t) {
return v.tidy(function() {
var e = v.maximum(0, v.sub(1, v.mul(n, t)));
return v.mean(e, -1);
});
}
function yE(n, t) {
return v.tidy(function() {
var e = v.sum(v.mul(n, t), -1), r = v.max(v.mul(v.sub(1, n), t), -1);
return v.maximum(0, v.add(1, v.sub(r, e)));
});
}
function vE(n, t) {
return v.tidy(function() {
var e = Math.log(2), r = v.sub(t, n), i = v.sub(v.add(r, v.softplus(v.mul(-2, r))), e);
return v.mean(i, -1);
});
}
function Ga(n, t, e) {
return e === void 0 && (e = false), v.tidy(function() {
if (e)
t = v.softmax(t);
else {
var r = v.sum(t, t.shape.length - 1, true);
t = v.div(t, r);
}
return t = v.clipByValue(t, Lt(), 1 - Lt()), v.neg(v.sum(v.mul(n.toFloat(), v.log(t)), t.shape.length - 1));
});
}
function wo(n, t, e) {
return e === void 0 && (e = false), v.tidy(function() {
var r = v.floor(kO(n)).toInt();
t = v.clipByValue(t, Lt(), 1 - Lt());
var i = t.shape, a = v.oneHot(r, i[i.length - 1]).reshape(i);
return Ga(a, t, e);
});
}
function wE(n, t) {
if (!v.util.arraysEqual(n.shape, t.shape))
throw new M("logits and labels must have the same shape, but got shapes " + (JSON.stringify(n.shape) + " and " + JSON.stringify(t.shape)));
return v.tidy(function() {
var e = t.relu(), r = t.abs().neg();
return e.sub(t.mul(n)).add(r.exp().log1p());
});
}
function bo(n, t) {
return v.tidy(function() {
var e;
return e = v.clipByValue(t, Lt(), 1 - Lt()), e = v.log(v.div(e, v.sub(1, e))), v.mean(wE(n, e), -1);
});
}
function bE(n, t) {
return v.tidy(function() {
var e = v.clipByValue(n, Lt(), 1), r = v.clipByValue(t, Lt(), 1);
return v.sum(v.mul(n, v.log(v.div(e, r))), -1);
});
}
function xE(n, t) {
return v.tidy(function() {
var e = v.log(v.add(Lt(), t));
return v.mean(v.sub(t, v.mul(n, e)), -1);
});
}
function Wh(n, t) {
return v.tidy(function() {
var e = yo(n, -1), r = yo(t, -1), i = v.mul(e, r);
return v.neg(v.sum(i, -1));
});
}
var xo = {meanSquaredError: ai, meanAbsoluteError: vo, meanAbsolutePercentageError: Yi, meanSquaredLogarithmicError: fE, squaredHinge: mE, hinge: gE, categoricalHinge: yE, logcosh: vE, categoricalCrossentropy: Ga, sparseCategoricalCrossentropy: wo, binaryCrossentropy: bo, kullbackLeiblerDivergence: bE, poisson: xE, cosineProximity: Wh};
function Uh(n) {
if (typeof n == "string") {
if (n in xo)
return xo[n];
var t = "Unknown loss " + n;
throw n.toLowerCase().includes("softmaxcrossentropy") && (t = "Unknown loss " + n + '. Use "categoricalCrossentropy" as the string name for tf.losses.softmaxCrossEntropy'), new M(t);
} else
return n;
}
function Bh(n, t) {
return v.tidy(function() {
var e = v.mul(0.5, v.onesLike(t)), r = za(v.greater(t, e), n.dtype);
return v.mean(v.equal(n, r), -1);
});
}
function zh(n, t) {
return v.tidy(function() {
return za(v.equal(v.argMax(n, -1), v.argMax(t, -1)), "float32");
});
}
function Sy(n, t) {
return v.tidy(function() {
return v.logicalAnd(n.equal(1), t.equal(1)).sum().cast("float32");
});
}
function LE(n, t) {
return v.tidy(function() {
return v.logicalAnd(n.equal(1), t.equal(0)).sum().cast("float32");
});
}
function SE(n, t) {
return v.tidy(function() {
return v.logicalAnd(n.equal(0), t.equal(1)).sum().cast("float32");
});
}
function Iy(n, t) {
return v.tidy(function() {
var e = Sy(n, t), r = SE(n, t), i = e.add(r);
return v.where(v.greater(i, 0), e.div(i), 0).cast("float32");
});
}
function IE(n, t) {
return v.tidy(function() {
var e = Sy(n, t), r = LE(n, t), i = e.add(r);
return v.where(v.greater(i, 0), e.div(i), 0).cast("float32");
});
}
function Ay(n, t) {
return bo(n, t);
}
function Ty(n, t) {
return n.rank === t.rank && (n = n.squeeze([n.rank - 1])), t = t.argMax(-1), t.dtype !== n.dtype && (t = t.asType(n.dtype)), v.equal(n, t).asType("float32");
}
var AE = ai, TE = ai, NE = vo, _E = vo, CE = Yi, RE = Yi, Ph = Ga, OE = Wh, Ny = wo, Lo = {binaryAccuracy: Bh, categoricalAccuracy: zh, precision: Iy, categoricalCrossentropy: Ph, sparseCategoricalCrossentropy: Ny, mse: AE, MSE: TE, mae: NE, MAE: _E, mape: CE, MAPE: RE, cosine: OE};
function EE(n) {
if (typeof n == "string" && n in Lo)
return Lo[n];
if (typeof n != "string" && n != null)
return n;
throw new M("Unknown metric " + n);
}
function So(n) {
if (kn(n !== null, "Unknown LossOrMetricFn " + n), typeof n == "string")
return n;
for (var t = void 0, e = 0, r = Object.keys(xo); e < r.length; e++) {
var i = r[e];
if (xo[i] === n) {
t = i;
break;
}
}
if (t !== void 0)
return t;
for (var a = 0, s = Object.keys(Lo); a < s.length; a++) {
var i = s[a];
if (Lo[i] === n) {
t = i;
break;
}
}
return t !== void 0 ? t : n.name;
}
function DE(n) {
var t = {Adagrad: function() {
return v.train.adagrad(0.01);
}, Adadelta: function() {
return v.train.adadelta(1, 0.95, Lt());
}, Adam: function() {
return v.train.adam(1e-3, 0.9, 0.999, Lt());
}, Adamax: function() {
return v.train.adamax(2e-3, 0.9, 0.999, Lt(), 0);
}, RMSProp: function() {
return v.train.rmsprop(1e-3, 0.9, 0, Lt());
}, SGD: function() {
return v.train.sgd(0.01);
}};
if (t.adagrad = t.Adagrad, t.adadelta = t.Adadelta, t.adam = t.Adam, t.adamax = t.Adamax, t.rmsprop = t.RMSProp, t.sgd = t.SGD, n in t)
return t[n]();
throw new M("Unknown Optimizer " + n);
}
var _y = 1 * 1024 * 1024;
function Cy(n, t, e) {
if (e === void 0 && (e = false), n == null || typeof n != "object" || Object.getPrototypeOf(n) !== Object.prototype || !Mh(n))
throw new Error("User-defined metadata is expected to be a JSON object, but is not.");
if (e) {
var r = JSON.stringify(n);
r.length > _y && console.warn('User-defined metadata of model "' + t + '" is too large in ' + ("size (length=" + r.length + " when serialized). It is not ") + "recommended to store such large objects in user-defined metadata. Please make sure its serialized length is <= " + (_y + "."));
}
}
function Mh(n) {
if (n === null)
return true;
if (typeof n == "object")
if (Object.getPrototypeOf(n) === Object.prototype) {
for (var t = Object.keys(n), e = 0, r = t; e < r.length; e++) {
var i = r[e];
if (typeof i != "string")
return false;
if (!Mh(n[i]))
return false;
}
return true;
} else if (Array.isArray(n)) {
for (var a = 0, s = n; a < s.length; a++) {
var o = s[a];
if (!Mh(o))
return false;
}
return true;
} else
return false;
else {
var c = typeof n;
return c === "string" || c === "number" || c === "boolean";
}
}
function BE(n, t, e, r) {
r === void 0 && (r = console.log);
var i = FE(n), a = ["Layer (type)", "Output shape", "Param #"];
i ? (t = t || 65, e = e || [0.45, 0.85, 1]) : (t = t || 98, e = e || [0.33, 0.55, 0.67, 1]), e[e.length - 1] <= 1 && (e = e.map(function(d) {
return Math.floor(t * d);
}));
var s;
if (!i) {
a.push("Receives inputs"), s = [];
for (var o in n.nodesByDepth)
s.push.apply(s, n.nodesByDepth[o]);
}
r("_".repeat(t)), Io(a, e, r), r("=".repeat(t));
for (var c = n.layers, l = 0; l < c.length; ++l)
i ? WE(c[l], e, r) : UE(c[l], e, s, r), r((l === c.length - 1 ? "=" : "_").repeat(t));
n.checkTrainableWeightsConsistency();
var u = kE(n), h = mo(n.nonTrainableWeights);
r("Total params: " + (u + h)), r("Trainable params: " + u), r("Non-trainable params: " + h), r("_".repeat(t));
}
function kE(n) {
var t;
return n.collectedTrainableWeights != null ? t = mo(n.collectedTrainableWeights) : t = mo(n.trainableWeights), t;
}
function FE(n) {
var t = true, e = [], r = [];
for (var i in n.nodesByDepth)
e.push(n.nodesByDepth[i]);
for (var a = 0, s = e; a < s.length; a++) {
var o = s[a];
if (o.length > 1 || o.length === 1 && o[0].inboundLayers.length > 1) {
t = false;
break;
}
r.push.apply(r, o);
}
if (t)
for (var c = 0, l = n.layers; c < l.length; c++) {
for (var u = l[c], h = false, d = 0, p = u.inboundNodes; d < p.length; d++) {
var f = p[d];
if (r.indexOf(f) !== -1)
if (h) {
t = false;
break;
} else
h = true;
}
if (!t)
break;
}
return t;
}
function Io(n, t, e) {
e === void 0 && (e = console.log);
for (var r = "", i = 0; i < n.length; ++i)
i > 0 && (r = r.slice(0, r.length - 1) + " "), r += n[i], r = r.slice(0, t[i]), r += " ".repeat(t[i] - r.length);
e(r);
}
function WE(n, t, e) {
var r;
try {
r = JSON.stringify(n.outputShape);
} catch (o) {
r = "multiple";
}
var i = n.name, a = n.getClassName(), s = [i + " (" + a + ")", r, n.countParams().toString()];
Io(s, t, e);
}
function UE(n, t, e, r) {
var i;
try {
i = JSON.stringify(n.outputShape);
} catch (y) {
i = "multiple";
}
for (var a = [], s = 0, o = n.inboundNodes; s < o.length; s++) {
var c = o[s];
if (e != null && e.length > 0 && e.indexOf(c) === -1)
continue;
for (var l = 0; l < c.inboundLayers.length; ++l) {
var u = c.inboundLayers[l].name, h = c.nodeIndices[l], d = c.tensorIndices[l];
a.push(u + "[" + h + "][" + d + "]");
}
}
var p = n.name, f = n.getClassName(), m = a.length === 0 ? "" : a[0], g = [p + " (" + f + ")", i, n.countParams().toString(), m];
Io(g, t, r);
for (var l = 1; l < a.length; ++l)
Io(["", "", "", a[l]], t, r);
}
function Ry(n, t, e) {
return (n === "inboundNodes" || n === "outputLayers" || n === "inputLayers") && t === 0 && typeof e == "string";
}
function qa(n, t) {
if (n === null)
return null;
if (typeof n == "string")
return ni(n);
if (typeof n == "number" || typeof n == "boolean")
return n;
if (n instanceof Array) {
for (var e = [], r = n.length, i = 0; i < r; ++i) {
var a = n[i];
Ry(t, i, a) ? e.push(a) : e.push(qa(a, t));
}
return e;
} else {
for (var s = {}, o = 0, c = Object.keys(n); o < c.length; o++) {
var l = c[o], u = n[l];
if (l === "name" && typeof u == "string")
s[l] = u;
else {
var h = ni(l);
s[h] = qa(u, h);
}
}
return s;
}
}
function Hh(n, t) {
if (n == null)
return null;
if (typeof n == "string")
return Qn(n);
if (typeof n == "number" || typeof n == "boolean")
return n;
if (n instanceof Array) {
for (var e = [], r = n.length, i = 0; i < r; ++i) {
var a = n[i];
Ry(t, i, a) ? e.push(a) : e.push(Hh(a, t));
}
return e;
} else {
for (var s = {}, o = 0, c = Object.keys(n); o < c.length; o++) {
var l = c[o], u = n[l], h = Qn(l);
(l === "name" || l === "className") && typeof u == "string" ? s[h] = u : s[h] = Hh(u, l);
}
return s;
}
}
var Vh = "2.7.0";
function zE(n, t) {
if (n.dtype == null || n.dtype === t.dtype)
return t;
try {
return v.cast(t, n.dtype);
} catch (e) {
throw new M("The dtype of the feed (" + t.dtype + ") can not be cast to the dtype " + ("of the key '" + n.name + "' (" + n.dtype + ")."));
}
}
var Ki = function() {
function n(t) {
if (this.id2Value = {}, this.id2Mask = {}, this.name2Id = {}, t instanceof n)
for (var e in t.id2Value)
this.id2Value[e] = t.id2Value[e], e in t.id2Mask && (this.id2Mask[e] = t.id2Mask[e]);
else {
if (t == null)
return;
for (var r = 0, i = t; r < i.length; r++) {
var a = i[r];
this.add(a.key, a.value);
}
}
}
return n.prototype.add = function(t, e, r) {
if (this.id2Value[t.id] == null)
this.id2Value[t.id] = zE(t, e), this.name2Id[t.name] = t.id, r != null && (this.id2Mask[t.id] = r);
else
throw new M("Duplicate key: name=" + t.name + ", id=" + t.id);
return this;
}, n.prototype.addFeed = function(t) {
this.add(t.key, t.value);
}, n.prototype.hasKey = function(t) {
return this.id2Value[t.id] != null;
}, n.prototype.names = function() {
return Object.keys(this.name2Id);
}, n.prototype.getValue = function(t) {
if (t instanceof xn) {
if (this.id2Value[t.id] == null)
throw new M("Nonexistent key: " + t.name);
return this.id2Value[t.id];
} else {
var e = this.name2Id[t];
if (e == null)
throw new M("Feed dict has no SymbolicTensor name: " + t);
return this.id2Value[e];
}
}, n.prototype.getMask = function(t) {
if (t instanceof xn) {
if (this.id2Value[t.id] == null)
throw new M("Nonexistent key: " + t.name);
return this.id2Mask[t.id];
} else {
var e = this.name2Id[t];
if (e == null)
throw new M("Feed dict has no SymbolicTensor name: " + t);
return this.id2Mask[e];
}
}, n.prototype.disposeMasks = function() {
this.id2Mask != null && v.dispose(this.id2Mask);
}, n;
}(), Gh = {}, Oy = {};
function Ya(n, t, e, r) {
for (var i = e == null ? false : e.training, a = Array.isArray(n), s = a ? n : [n], o = s.map(function($) {
return $.name;
}), c = [], l = t.names(), u = 0, h = o; u < h.length; u++) {
var d = h[u];
l.indexOf(d) !== -1 ? c.push(t.getValue(d)) : c.push(null);
}
r != null && (r.maxNumTensors = -Infinity, r.minNumTensors = Infinity);
var p = o.join(",") + "|" + t.names().join(","), f, m;
if (Gh[p] == null) {
var g = PE(s, t);
f = g.sorted, m = g.recipientCounts, Gh[p] = f, Oy[p] = m;
}
f = Gh[p], m = {}, i || Object.assign(m, Oy[p]);
for (var y = new Ki(t), w = 0; w < f.length; ++w) {
if (r != null) {
var b = v.memory().numTensors;
b > r.maxNumTensors && (r.maxNumTensors = b), b < r.minNumTensors && (r.minNumTensors = b);
}
var x = f[w], L = x.sourceLayer;
if (L instanceof Va)
continue;
for (var N = [], I = [], C = [], O = false, D = 0, F = x.inputs; D < F.length; D++) {
var k = F[D], B = y.getValue(k), V = y.getMask(k);
N.push(B), I.push(V), V != null && (O = true), i || (m[k.name]--, m[k.name] === 0 && !t.hasKey(k) && o.indexOf(k.name) === -1 && !B.isDisposed && k.sourceLayer.stateful !== true && C.push(B));
}
O && (e = e || {}, e.mask = I[0]);
var P = nt(L.apply(N, e)), G = null;
L.supportsMasking && (G = L.computeMask(N, I));
for (var j = ME(x), q = Array.isArray(j) ? j : [j], H = 0; H < q.length; ++H) {
y.hasKey(q[H]) || y.add(q[H], P[H], Array.isArray(G) ? G[0] : G);
var J = o.indexOf(q[H].name);
J !== -1 && (c[J] = P[H]);
}
i || v.dispose(C);
}
return y.disposeMasks(), a ? c : c[0];
}
function PE(n, t) {
v.util.assert(n != null && n.length > 0, function() {
return "Expected at least one fetch, got none";
});
var e = [], r = {};
if (n.length === 1) {
var i = Ey(n[0], t);
e = i.sorted, r = i.recipientMap;
} else
for (var a = new Set(), s = 0, o = n; s < o.length; s++) {
for (var c = o[s], l = Ey(c, t), u = l.sorted, h = l.recipientMap, d = 0, p = u; d < p.length; d++) {
var f = p[d];
a.has(f.name) || (e.push(f), a.add(f.name));
}
var m = function(y) {
r[y] == null && (r[y] = new Set()), h[y].forEach(function(w) {
return r[y].add(w);
});
};
for (var g in h)
m(g);
}
return {sorted: e, recipientCounts: HE(r)};
}
function HE(n) {
var t = {};
for (var e in n)
t[e] = n[e].size;
return t;
}
function Ey(n, t) {
for (var e = new Set(), r = [], i = {}, a = 0, s = t.names(); a < s.length; a++) {
var o = s[a];
e.add(o);
}
var c = [], l = [];
for (c.push(n); c.length > 0; ) {
var u = c[c.length - 1];
if (e.has(u.name)) {
c.pop();
continue;
}
var h = l[l.length - 1] === c.length - 1;
if (u.inputs.length === 0 || h)
c.pop(), r.push(u), e.add(u.name), h && l.pop();
else {
l.push(c.length - 1);
for (var d = 0, p = u.inputs; d < p.length; d++) {
var f = p[d];
if (i[f.name] == null && (i[f.name] = new Set()), i[f.name].add(u.name), e.has(f.name))
continue;
c.push(f);
}
}
}
return {sorted: r, recipientMap: i};
}
function ME(n) {
var t;
if (n.sourceLayer.inboundNodes.length === 1)
t = n.sourceLayer.output;
else {
for (var e = null, r = 0; r < n.sourceLayer.inboundNodes.length; ++r)
for (var i = 0, a = n.sourceLayer.inboundNodes[r].outputTensors; i < a.length; i++) {
var s = a[i];
if (s.id === n.id) {
e = r;
break;
}
}
t = n.sourceLayer.getOutputAt(e);
}
return t;
}
var VE = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, {}) || this;
if (r.containerNodes = new Set(), r.name = e.name, r.name == null) {
var i = r.getClassName().toLowerCase();
r.name = po(i);
}
if (r.supportsMasking = false, r.trainable_ = true, Array.isArray(e.inputs) ? r.inputs = e.inputs.slice() : r.inputs = [e.inputs], Array.isArray(e.outputs) ? r.outputs = e.outputs.slice() : r.outputs = [e.outputs], xr(r.inputs).length !== r.inputs.length)
throw new M("The list of inputs passed to the model is redundant. All inputs should only appear once. Found: " + ("" + r.inputs.map(function(Te) {
return Te.name;
})));
xr(r.outputs).length !== r.outputs.length && console.warn("The list of outputs passed to the model is redundant. All outputs should only appear once. Found: " + ("" + r.outputs.map(function(Te) {
return Te.name;
}))), r.inputLayers = [], r.inputLayersNodeIndices = [], r.inputLayersTensorIndices = [], r.outputLayers = [], r.outputLayersNodeIndices = [], r.outputLayersTensorIndices = [], r.layers = [], r.internalContainerRefs = [];
for (var a = 0, s = r.outputs; a < s.length; a++) {
var o = s[a], c = o.sourceLayer, l = o.nodeIndex, u = o.tensorIndex;
r.outputLayers.push(c), r.outputLayersNodeIndices.push(l), r.outputLayersTensorIndices.push(u);
}
for (var h = 0, d = r.inputs; h < d.length; h++) {
var o = d[h], c = o.sourceLayer, l = o.nodeIndex, u = o.tensorIndex;
kn(l === 0, "input layer has >1 nodes"), kn(u === 0, "input layer has >1 tensors"), r.inputLayers.push(c), r.inputLayersNodeIndices.push(l), r.inputLayersTensorIndices.push(u);
}
r.inputNames = [], r.outputNames = [], r.feedInputShapes = [], r.feedInputNames = [], r.feedOutputNames = [];
for (var p = 0; p < r.inputLayers.length; p++) {
var c = r.inputLayers[p];
if (!(c instanceof Va))
throw new TypeError("Input layers to a LayersModel must be InputLayer objects. " + ("Received inputs: " + e.inputs + ". ") + ("Input " + p + " (0-based) originates ") + ("from layer type " + c.getClassName() + "."));
r.inputNames.push(c.name), r.feedInputShapes.push(c.batchInputShape), r.feedInputNames.push(c.name);
}
for (var f = 0, m = r.outputLayers; f < m.length; f++) {
var c = m[f];
r.outputNames.push(c.name);
}
r.internalInputShapes = r.inputs.map(function(Te) {
return Te.shape;
}), r.internalOutputShapes = r.outputs.map(function(Te) {
return Te.shape;
});
for (var g = {}, y = {}, w = {}, b = {}, x = {}, L = [], N = function(Te, ht, ft, Ge, jt, qn) {
(Ge == null || jt == null || qn == null) && (Ge = Te.sourceLayer, jt = Te.nodeIndex, qn = Te.tensorIndex);
var kt = Ge.inboundNodes[jt];
if (ft.indexOf(kt) !== -1)
throw new Dn("The tensor " + Te.name + ' at layer "' + Ge.name + '" is part of a cycle.');
if (ht.indexOf(kt) !== -1)
return;
r.containerNodes.add(t.nodeKey(Ge, jt)), Ge.id in x || (x[Ge.id] = Object.keys(x).length), ft.indexOf(kt) === -1 && ft.push(kt);
for (var ma = kt.inboundLayers.length, cr = 0; cr < ma; cr++) {
var bi = kt.inputTensors[cr], cc = kt.inboundLayers[cr], lc = kt.nodeIndices[cr], Qx = kt.tensorIndices[cr];
N(bi, ht, ft, cc, lc, Qx);
}
for (ht.push(kt); ft.indexOf(kt) >= 0; )
ft.splice(ft.indexOf(kt), 1);
L.push(kt);
}, I = [], C = [], O = 0, D = r.outputs; O < D.length; O++) {
var o = D[O];
N(o, I, C);
}
for (var F = L.slice().reverse(), k = 0, B = F; k < B.length; k++) {
var V = B[k];
y[V.id] = V, V.id in g || (g[V.id] = 0);
var P = g[V.id], G = w[V.outboundLayer.id] == null ? 0 : w[V.outboundLayer.id];
P = Math.max(P, G), w[V.outboundLayer.id] = P, b[V.outboundLayer.id] = V.outboundLayer, g[V.id] = P;
for (var p = 0; p < V.inboundLayers.length; p++) {
var j = V.inboundLayers[p], l = V.nodeIndices[p], q = j.inboundNodes[l], H = g[q.id] == null ? 0 : g[q.id];
g[q.id] = Math.max(P + 1, H), y[q.id] = q;
}
}
var J = {};
for (var $ in g) {
var P = g[$];
P in J || (J[P] = []), J[P].push(y[$]);
}
var ee = {};
for (var te in w) {
var P = w[te];
P in ee || (ee[P] = []), ee[P].push(b[te]);
}
var ne = Object.keys(ee).map(function(Te) {
return parseInt(Te, 10);
}).sort(co);
r.layers = [];
for (var re = 0, ie = ne; re < ie.length; re++) {
var P = ie[re], oe = ee[P];
oe.sort(function(ht, ft) {
var Ge = x[ht.id], jt = x[ft.id];
return Ge < jt ? -1 : Ge > jt ? 1 : 0;
});
for (var se = 0, me = oe; se < me.length; se++) {
var c = me[se];
c instanceof t && r.internalContainerRefs.push(c), r.layers.push(c);
}
}
r.layersByDepth = ee, ne = Object.keys(J).map(function(Te) {
return parseInt(Te, 10);
}).sort(co);
for (var ye = r.inputs.slice(), ve = [], Ee = 0, Be = ne; Ee < Be.length; Ee++)
for (var P = Be[Ee], We = 0, Ke = J[P]; We < Ke.length; We++) {
var V = Ke[We], c = V.outboundLayer;
if (c != null) {
for (var ze = 0, Ie = V.inputTensors; ze < Ie.length; ze++) {
var o = Ie[ze];
if (ye.indexOf(o) === -1)
throw new Dn("Graph disconnected: cannot obtain value for tensor " + o + (' at layer "' + c.name + '". ') + "The following previous layers were accessed without " + ("issue: " + ve));
}
for (var ue = 0, Qe = V.outputTensors; ue < Qe.length; ue++) {
var o = Qe[ue];
ye.push(o);
}
ve.push(c.name);
}
}
r.nodesByDepth = J;
for (var pt = r.layers.map(function(Te) {
return Te.name;
}), He = function(Te) {
var ht = pt.filter(function(ft) {
return ft === Te;
}).length;
if (ht !== 1)
throw new Dn('The name "' + Te + '" is used ' + ht + " times in the model. All layer names should be unique. Layer names: " + JSON.stringify(pt));
}, Ot = 0, ut = pt; Ot < ut.length; Ot++) {
var vt = ut[Ot];
He(vt);
}
return r.outboundNodes = [], r.inboundNodes = [], new go({outboundLayer: r, inboundLayers: [], nodeIndices: [], tensorIndices: [], inputTensors: r.inputs, outputTensors: r.outputs, inputMasks: r.inputs.map(function(Te) {
return null;
}), outputMasks: r.outputs.map(function(Te) {
return null;
}), inputShapes: r.inputs.map(function(Te) {
return Te.shape;
}), outputShapes: r.outputs.map(function(Te) {
return Te.shape;
})}), r.built = true, r._refCount = 1, r;
}
return t.prototype.assertNotDisposed = function() {
if (this._refCount === 0)
throw new Error("Container '" + this.name + "' is already disposed.");
}, t.prototype.dispose = function() {
this.assertNotDisposed();
var e = {refCountAfterDispose: null, numDisposedVariables: 0};
if (--this._refCount === 0) {
for (var r = 0, i = this.layers; r < i.length; r++) {
var a = i[r];
e.numDisposedVariables += a.dispose().numDisposedVariables;
}
for (var s = 0, o = this.internalContainerRefs; s < o.length; s++) {
var c = o[s];
e.numDisposedVariables += c.dispose().numDisposedVariables;
}
}
return e.refCountAfterDispose = this._refCount, e;
}, Object.defineProperty(t.prototype, "trainable", {get: function() {
return this.trainable_;
}, set: function(e) {
this.layers.forEach(function(r) {
r._trainableWeights.forEach(function(i) {
return i.trainable = e;
});
}), this.trainable_ = e;
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "trainableWeights", {get: function() {
if (this._trainableWeights.length > 0)
throw new M("Container instance unexpectedly contains _trainableWeights.The trainable weights of a Container are a union of the trainable weights of its consituent Layers. Its own _trainableWeights must remain an empty Array.");
if (!this.trainable)
return [];
for (var e = [], r = 0, i = this.layers; r < i.length; r++) {
var a = i[r];
e = e.concat(a.trainableWeights);
}
return e;
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "nonTrainableWeights", {get: function() {
for (var e = [], r = 0, i = this.layers; r < i.length; r++) {
var a = i[r];
e.push.apply(e, a.nonTrainableWeights);
}
if (!this.trainable) {
for (var s = [], o = 0, c = this.layers; o < c.length; o++) {
var a = c[o];
s.push.apply(s, a.trainableWeights);
}
return s.concat(e);
}
return e;
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "weights", {get: function() {
return this.trainableWeights.concat(this.nonTrainableWeights);
}, enumerable: true, configurable: true}), t.prototype.loadWeights = function(e, r) {
r === void 0 && (r = true);
for (var i = {}, a = 0, s = 0, o = this.layers; s < o.length; s++)
for (var c = o[s], l = 0, u = c.weights; l < u.length; l++) {
var h = u[l];
if (i[h.originalName] != null)
throw new M("Duplicate weight name: " + h.originalName);
i[h.originalName] = h, a++;
}
var d = [];
for (var p in e) {
var f = p;
if (i[p] == null) {
var m = p.split("/"), g = m.slice(0, -2).concat([m[m.length - 1]]);
f = g.join("/");
}
if (i[f] != null)
d.push([i[f], e[p]]);
else if (r)
throw new M("Provided weight data has no target variable: " + p);
delete i[f];
}
if (r) {
var y = [];
for (var w in i)
y.push(w);
if (y.length > 0)
throw new M(y.length + " of " + a + " weights are not set: " + ("" + y));
}
Fh(d);
}, t.prototype.updatedConfig = function() {
var e = this.getConfig(), r = {};
return r.className = this.getClassName(), r.config = e, r.kerasVersion = "tfjs-layers " + Vh, r.backend = "TensorFlow.js", r;
}, t.prototype.toJSON = function(e, r) {
r === void 0 && (r = true);
var i = Hh(this.updatedConfig());
return r ? JSON.stringify(i) : i;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
e = nt(e);
for (var a = new Ki(), s = 0; s < i.inputs.length; ++s)
a.add(i.inputs[s], e[s]);
return Ya(i.outputs, a, r);
});
}, t.prototype.computeMask = function(e, r) {
var i = this;
return v.tidy(function() {
e = nt(e);
var a;
return r == null ? a = ti(null, e.length) : a = nt(r), i.runInternalGraph(e, a)[1];
});
}, t.prototype.computeOutputShape = function(e) {
var r = fo(e);
if (r.length !== this.inputLayers.length)
throw new M("Invalid inputShape argument " + e + ": " + ("model has " + this.inputLayers.length + " tensor inputs."));
for (var i = {}, a = 0; a < r.length; a++) {
var s = this.inputLayers[a], o = r[a], c = s.name + "_0_0";
i[c] = o;
}
var l = Object.keys(this.nodesByDepth).map(function(B) {
return parseInt(B, 10);
}).sort(co);
if (l.length > 1)
for (var u = 0, h = l; u < h.length; u++)
for (var d = h[u], p = this.nodesByDepth[d], f = 0, m = p; f < m.length; f++) {
var g = m[f], s = g.outboundLayer;
if (this.inputLayers.map(function(V) {
return V.id;
}).indexOf(s.id) !== -1)
continue;
for (var y = [], w = 0; w < g.inboundLayers.length; w++) {
var b = g.inboundLayers[w], x = g.nodeIndices[w], L = g.tensorIndices[w], c = b.name + "_" + x + "_" + L, N = i[c];
y.push(N);
}
for (var I = s.computeOutputShape(Vt(y)), C = fo(I), O = s.inboundNodes.indexOf(g), w = 0; w < C.length; w++) {
var c = s.name + "_" + O + "_" + w;
i[c] = C[w];
}
}
for (var D = [], F = [], a = 0; a < this.outputLayers.length; a++) {
var s = this.outputLayers[a], O = this.outputLayersNodeIndices[a], L = this.outputLayersTensorIndices[a], c = s.name + "_" + O + "_" + L;
F.push(c);
}
for (var a = 0; a < F.length; a++) {
var k = F[a];
kn(k in i), D.push(i[k]);
}
return Vt(D);
}, t.prototype.runInternalGraph = function(e, r) {
r == null && (r = ti(null, e.length));
for (var i = {}, a = 0; a < this.inputs.length; ++a) {
var s = this.inputs[a], o = e[a], c = r[a];
i[s.id] = [o, c];
}
for (var l = Object.keys(this.nodesByDepth).map(function(ee) {
return parseInt(ee, 10);
}).sort(co), u = 0, h = l; u < h.length; u++)
for (var d = h[u], p = this.nodesByDepth[d], f = 0, m = p; f < m.length; f++) {
for (var g = m[f], y = g.outboundLayer, w = g.inputTensors, b = g.outputTensors, x = new Array(), L = 0, N = w; L < N.length; L++) {
var s = N[L];
s.id in i && x.push(i[s.id]);
}
if (x.length === w.length) {
var I = {}, C = void 0, O = void 0, D = void 0, F = void 0;
if (g.callArgs != null && (I = g.callArgs), x.length === 1) {
var k = x[0], B = k[0], V = k[1];
I.mask == null && (I.mask = V), D = nt(y.call(B, I)), F = nt(y.computeMask(B, V)), C = [B], O = [V];
} else
C = x.map(function(ee) {
return ee[0];
}), O = x.map(function(ee) {
return ee[1];
}), I.mask == null && (I.mask = O), D = nt(y.call(C, I)), F = nt(y.computeMask(C, O));
if (y.activityRegularizer)
throw new Re("LayersModel invocation with concrete Tensor value(s) in the presence of activity regularizer(s) is not supported yet.");
for (var a = 0; a < b.length; ++a) {
var s = b[a], o = D[a], c = F[a];
i[s.id] = [o, c];
}
}
}
for (var P = [], G = [], j = [], q = 0, H = this.outputs; q < H.length; q++) {
var s = H[q];
kn(s.id in i, "Could not compute output " + s.name + " : " + s.id);
var J = i[s.id], $ = J[0], c = J[1];
j.push($.shape), P.push($), G.push(c);
}
return [P, G, j];
}, t.prototype.buildNodeConversionMap = function(e) {
for (var r = {}, i, a = 0, s = this.layers; a < s.length; a++) {
var o = s[a];
i = o instanceof t ? 1 : 0;
for (var c = 0; c < o.inboundNodes.length; c++) {
var l = t.nodeKey(o, c);
this.containerNodes.has(l) && (r[l] = i, i += 1);
}
}
return r;
}, t.prototype.getLayer = function(e, r) {
if (r != null) {
if (this.layers.length <= r)
throw new M("Was asked to retrieve layer at index " + r + ", but model only " + ("has " + this.layers.length + " layer(s)."));
return this.layers[r];
} else if (e == null)
throw new M("Provide either a layer name or layer index");
for (var i = 0, a = this.layers; i < a.length; i++) {
var s = a[i];
if (s.name === e)
return s;
}
throw new M("No such layer: " + e);
}, t.prototype.calculateLosses = function() {
var e = this;
return v.tidy(function() {
for (var r = [], i = 0, a = e.layers; i < a.length; i++)
for (var s = a[i], o = 0; o < s.inboundNodes.length; ++o) {
var c = t.nodeKey(s, o);
e.containerNodes.has(c) && r.push.apply(r, s.calculateLosses());
}
return r;
});
}, t.prototype.getConfig = function() {
for (var e = {name: this.name}, r = this.buildNodeConversionMap(this.layers), i = [], a = 0, s = this.layers; a < s.length; a++) {
for (var o = s[a], c = o.getClassName(), l = o.getConfig(), u = [], h = 0; h < o.inboundNodes.length; h++) {
var d = o.inboundNodes[h], p = t.nodeKey(o, h), f = {};
if (this.containerNodes.has(p)) {
if (d.callArgs)
try {
JSON.stringify(d.callArgs), f = d.callArgs;
} catch (O) {
console.warn("Layer " + o.name + " was passed non-serializable keyword arguments: " + (d.callArgs + ". They will not be included ") + "in the serialized model (and thus will be missing at deserialization time)."), f = {};
}
if (d.inboundLayers.length > 0) {
for (var m = [], g = 0; g < d.inboundLayers.length; g++) {
var y = d.inboundLayers[g], w = d.nodeIndices[g], b = d.tensorIndices[g], x = t.nodeKey(y, w), L = r[x];
L == null && (L = 0), m.push([y.name, L, b, f]);
}
u.push(m);
}
}
}
var N = {};
N.name = o.name, N.className = c, N.config = l, N.inboundNodes = u, i.push(N);
}
e.layers = i;
for (var I = [], g = 0; g < this.inputLayers.length; g++) {
var o = this.inputLayers[g], w = this.inputLayersNodeIndices[g], p = t.nodeKey(o, w);
if (!this.containerNodes.has(p))
continue;
var L = r[p];
L == null && (L = 0);
var b = this.inputLayersTensorIndices[g];
I.push([o.name, L, b]);
}
e.inputLayers = I;
for (var C = [], g = 0; g < this.outputLayers.length; g++) {
var o = this.outputLayers[g], w = this.outputLayersNodeIndices[g], p = t.nodeKey(o, w);
if (!this.containerNodes.has(p))
continue;
var L = r[p];
L == null && (L = 0);
var b = this.outputLayersTensorIndices[g];
C.push([o.name, L, b]);
}
return e.outputLayers = C, e;
}, t.fromConfig = function(e, r, i, a) {
a === void 0 && (a = false);
var s = {}, o = {};
function c(H, J) {
H.name in o ? o[H.name].push(J) : o[H.name] = [J];
}
function l(H, J) {
for (var $ = [], ee, te = 0, ne = J; te < ne.length; te++) {
var re = ne[te], ie = re[0], oe = re[1], se = re[2];
if (ee = re[3] == null ? {} : re[3], !(ie in s)) {
c(H, J);
return;
}
var me = s[ie];
if (me.inboundNodes.length <= oe) {
c(H, J);
return;
}
var ye = me.inboundNodes[oe];
$.push(ye.outputTensors[se]);
}
$.length > 0 && H.apply(Vt($), ee);
}
function u(H) {
var J = H.name, $ = Ln(H, r.customObjects != null ? r.customObjects : {});
$.setFastWeightInitDuringBuild(a), s[J] = $;
var ee = H.inboundNodes;
ee.forEach(function(te) {
if (!(te instanceof Array))
throw new M("Corrupted configuration, expected array for nodeData: " + te);
c($, te);
});
}
for (var h = r.name, d = r.layers, p = 0, f = d; p < f.length; p++) {
var m = f[p];
u(m);
}
for (; !wO(o); )
for (var g = 0, y = d; g < y.length; g++) {
var m = y[g], w = s[m.name];
if (w.name in o) {
var b = o[w.name];
delete o[w.name];
for (var x = 0, L = b; x < L.length; x++) {
var N = L[x];
l(w, N);
}
}
}
for (var I = [], C = [], O = r.inputLayers, D = 0, F = O; D < F.length; D++) {
var m = F[D], k = m[0], B = m[1], V = m[2];
kn(k in s);
var w = s[k], P = w.inboundNodes[B].outputTensors;
I.push(P[V]);
}
for (var G = r.outputLayers, j = 0, q = G; j < q.length; j++) {
var m = q[j], k = m[0], B = m[1], V = m[2];
kn(k in s);
var w = s[k], P = w.inboundNodes[B].outputTensors;
C.push(P[V]);
}
return new e({inputs: I, outputs: C, name: h});
}, Object.defineProperty(t.prototype, "stateful", {get: function() {
if (this._stateful)
throw new M("Container instance unexpectedly has _stateful = true. The statefulness of a Container is determined by the Layers it contains. Its _stateful property must remain the default false.");
for (var e = 0, r = this.layers; e < r.length; e++) {
var i = r[e];
if (i.stateful)
return true;
}
return false;
}, enumerable: true, configurable: true}), t.prototype.resetStates = function() {
var e = this;
v.tidy(function() {
e.layers.forEach(function(r) {
r.stateful && r.resetStates();
});
});
}, t;
}(Fe);
function GE(n, t, e) {
var r = t.length;
if (n == null || Array.isArray(n) && n.length === 0)
return t.map(function(a) {
return null;
});
if (r === 1)
return Array.isArray(n) && n.length === 1 ? n : typeof n == "object" && t[0] in n ? [n[t[0]]] : [n];
if (Array.isArray(n)) {
if (n.length !== r)
throw new Error("Provided " + e + " is an array of " + n.length + " " + ("element(s), but the model has " + r + " outputs. ") + "Make sure a set of weights is provided for each model output.");
return n;
} else if (typeof n == "object" && Object.keys(n).length > 0 && typeof n[Object.keys(n)[0]] == "object") {
var i = [];
return t.forEach(function(a) {
a in n ? i.push(n[a]) : i.push(null);
}), i;
} else
throw new Error("The model has multiple (" + r + ") outputs, " + ("so " + e + " must be either an array with ") + (r + " elements or an object with " + t + " keys. ") + ("Provided " + e + " not understood: " + JSON.stringify(n)));
}
function Dy(n, t) {
return GE(n, t, "classWeight");
}
function ky(n, t, e, r) {
return Ae(this, void 0, void 0, function() {
var i, a, s, o, c;
return xe(this, function(l) {
switch (l.label) {
case 0:
if (t != null || r != null)
throw new Error("Support sampleWeight is not implemented yet");
return e != null ? (i = v.tidy(function() {
if (n.shape.length === 1)
return n.clone();
if (n.shape.length === 2)
if (n.shape[1] > 1) {
var u = 1;
return n.argMax(u);
} else {
if (n.shape[1] === 1)
return n.reshape([n.shape[0]]);
throw new Error("Encountered unexpected last-dimension size (" + n.shape[1] + ") during handling of class weights. The size is expected to be >= 1.");
}
else
throw new Error("Unexpected rank of target (y) tensor (" + n.rank + ") during handling of class weights. The rank is expected to be 1 or 2.");
}), o = (s = Array).from, [4, i.data()]) : [3, 2];
case 1:
return a = o.apply(s, [l.sent()]), v.dispose(i), c = [], a.forEach(function(u) {
if (e[u] == null)
throw new Error("classWeight must contain all classes in the training data. " + ("The class " + u + " exists in the data but not in ") + "classWeight");
c.push(e[u]);
}), [2, v.tensor1d(c, "float32")];
case 2:
return [2, null];
}
});
});
}
function qE(n, t) {
return v.mul(n, t);
}
var YE = 32;
function Wy(n, t) {
var e, r, i = t;
e = i.xs, r = i.ys, v.util.assert(e != null && r != null, function() {
return "A Dataset iterator for fitDataset() is expected to generate objects of the form `{xs: xVal, ys: yVal}`, where the two values may be `tf.Tensor`, an array of Tensors, or a map of string to Tensor. The provided Dataset instead generates " + ("" + t);
});
var a = Fy("input", n.inputNames, e), s = Fy("output", n.outputNames, r), o = a[0].shape[0];
v.util.assert(a.length === n.inputs.length, function() {
return "LayersModel has " + n.inputs.length + " inputs, but the dataset " + ("provides " + a.length + " inputs. (Expected input keys: ") + (JSON.stringify(n.inputNames) + ")");
}), v.util.assert(s.length === n.outputs.length, function() {
return "LayersModel has " + n.outputs.length + " outputs, but the dataset " + ("provides " + s.length + " outputs. (Expected output keys: ") + (JSON.stringify(n.outputNames) + ")");
});
for (var c = function(d) {
v.util.assert(a[d].shape[0] === o, function() {
return "Batch size mismatch: input " + (n.inputNames[d] + " has " + a[d].shape[0] + "; ") + ("expected " + o + " based on input " + n.inputNames[0] + ".");
});
}, l = 0; l < a.length; l++)
c(l);
for (var u = function(d) {
v.util.assert(s[d].shape[0] === o, function() {
return "Batch size mismatch: output " + (n.outputNames[d] + " has " + s[d].shape[0] + "; ") + ("expected " + o + " based on input " + n.inputNames[0] + ".");
});
}, h = 0; h < s.length; h++)
u(h);
return {xs: a, ys: s};
}
function Fy(n, t, e) {
if (e instanceof v.Tensor)
return [e];
if (Array.isArray(e))
return v.util.assert(e.length === t.length, function() {
return "Received an array of " + e.length + " Tensors, but expected " + t.length + " to match the " + n + " keys " + t + ".";
}), e;
for (var r = [], i = 0, a = t; i < a.length; i++) {
var s = a[i];
if (e[s] == null)
throw new M("The feature data generated by the dataset lacks the required " + (n + " key '" + s + "'."));
r.push(e[s]);
}
return r;
}
function KE(n) {
if (n.length === 3)
throw new Re("Validation with sample weights is not implemented yet.");
return {xs: n[0], ys: n[1]};
}
function $E(n, t, e) {
return Ae(this, void 0, void 0, function() {
var r, i, a, s, o, c, l, u, h, d, p, f, m, g, y, w, b, x, L, N, I, C, O, D, F, k, B, V, P, G, k, j, q, H, J, k;
return xe(this, function($) {
switch ($.label) {
case 0:
if (r = e.batchesPerEpoch != null, v.util.assert(n.optimizer != null, function() {
return "You must compile a model before training/testing. Use LayersModel.compile(modelCompileConfig).";
}), v.util.assert(e != null, function() {
return "For fitDataset(), the 2nd argument (config) is required, but it is not provided in this call.";
}), v.util.assert(e.epochs != null && e.epochs > 0 && Number.isInteger(e.epochs), function() {
return "For fitDataset(), config.epochs is expected to be a positive " + ("integer, but got " + e.epochs);
}), v.util.assert(!r || e.batchesPerEpoch > 0 && Number.isInteger(e.batchesPerEpoch), function() {
return "For fitDataset(), config.batchesPerEpoch is expected to be a " + ("positive integer if specified, but got " + e.batchesPerEpoch);
}), v.util.assert(e.validationSplit == null, function() {
return "`validationSplit` is not supported by `fitDataset()`. Use validationData instead.";
}), n.isTraining)
throw new Error("Cannot start training because another fit() call is ongoing.");
n.isTraining = true, $.label = 1;
case 1:
return $.trys.push([1, , 26, 27]), i = e.validationData != null, a = void 0, s = void 0, i && (Uy(e.validationData) ? v.util.assert(e.validationBatches == null || e.validationBatches > 0 && Number.isInteger(e.validationBatches), function() {
return "For fitDataset() with dataset-based validation, config.validationBatches is expected not to be provided, or to be a positive integer, " + ("but got " + e.validationBatches);
}) : (o = KE(e.validationData), a = o.xs, s = o.ys)), c = n.makeTrainFunction(), l = n.getDedupedMetricsNames(), u = void 0, i ? u = l.slice().concat(l.map(function(ee) {
return "val_" + ee;
})) : u = l.slice(), h = by(e.callbacks, e.yieldEvery), d = e.verbose == null ? 1 : e.verbose, p = Ly(h, d, e.epochs, null, null, jE(t, e), null, i, u), f = p.callbackList, m = p.history, f.setModel(n), n.history = m, [4, f.onTrainBegin()];
case 2:
return $.sent(), n.stopTraining_ = false, g = e.initialEpoch == null ? 0 : e.initialEpoch, [4, t.iterator()];
case 3:
y = $.sent(), $.label = 4;
case 4:
return g < e.epochs ? (w = {}, [4, f.onEpochBegin(g)]) : [3, 23];
case 5:
return $.sent(), b = 0, x = 0, r ? [3, 7] : [4, t.iterator()];
case 6:
y = $.sent(), $.label = 7;
case 7:
return (r ? b < e.batchesPerEpoch : true) ? [4, y.next()] : [3, 21];
case 8:
return L = $.sent(), r && L.done ? (console.warn("You provided `batchesPerEpoch` as " + (e.batchesPerEpoch + ", ") + "but your dataset iterator ran out of data after " + (b + " batches; ") + "interrupting training. Make sure that your dataset can generate at least `batchesPerEpoch * epochs` batches (in this case, " + (e.batchesPerEpoch * e.epochs + " batches). ") + "You may need to use the repeat() function when building your dataset."), [3, 21]) : L.value != null ? (N = Wy(n, L.value), I = N.xs, C = N.ys, O = {}, O.batch = x, O.size = I[0].shape[0], [4, f.onBatchBegin(x, O)]) : [3, 15];
case 9:
if ($.sent(), D = [], !(e.classWeight != null))
return [3, 13];
F = Dy(e.classWeight, n.outputNames), k = 0, $.label = 10;
case 10:
return k < F.length ? (V = (B = D).push, [4, ky(C[k], null, F[k])]) : [3, 13];
case 11:
V.apply(B, [$.sent()]), $.label = 12;
case 12:
return ++k, [3, 10];
case 13:
for (P = I.concat(C).concat(D), G = c(P), v.dispose(P), k = 0; k < l.length; ++k)
j = l[k], q = G[k], O[j] = q, v.keep(q);
return [4, f.onBatchEnd(x, O)];
case 14:
$.sent(), my(O), x++, b++, $.label = 15;
case 15:
return (r ? b >= e.batchesPerEpoch : L.done) ? i ? (H = void 0, Uy(e.validationData) ? (J = nt, [4, n.evaluateDataset(e.validationData, {batches: e.validationBatches})]) : [3, 17]) : [3, 19] : [3, 20];
case 16:
return H = J.apply(void 0, [$.sent()]), [3, 18];
case 17:
H = nt(n.evaluate(a, s, {batchSize: e.validationBatchSize == null ? YE : e.validationBatchSize, verbose: 0})), $.label = 18;
case 18:
for (k = 0; k < n.metricsNames.length; ++k)
w["val_" + n.metricsNames[k]] = H[k];
$.label = 19;
case 19:
return [3, 21];
case 20:
return n.stopTraining_ ? [3, 21] : [3, 7];
case 21:
return [4, f.onEpochEnd(g, w)];
case 22:
return $.sent(), g++, n.stopTraining_ ? [3, 23] : [3, 4];
case 23:
return [4, f.onTrainEnd()];
case 24:
return $.sent(), [4, n.history.syncData()];
case 25:
return $.sent(), [2, n.history];
case 26:
return n.isTraining = false, [7];
case 27:
return [2];
}
});
});
}
function jE(n, t) {
var e = null;
return t.batchesPerEpoch != null ? e = t.batchesPerEpoch : Number.isFinite(n.size) && (e = n.size), e;
}
function Uy(n) {
return typeof n.iterator == "function";
}
function XE(n) {
return typeof n.next == "function";
}
function JE(n, t, e) {
return Ae(this, void 0, void 0, function() {
var r, i, a, s, o, c, l, u, h, d, p;
return xe(this, function(f) {
switch (f.label) {
case 0:
if (e = e || {}, r = e.batches != null, i = n.testFunction, a = [], e.verbose > 0)
throw new Re("Verbose mode is not implemented yet.");
return v.util.assert(!r || e.batches > 0 && Number.isInteger(e.batches), function() {
return "Test loop expects `batches` to be a positive integer, but " + ("received " + JSON.stringify(e.batches));
}), XE(t) ? (o = t, [3, 3]) : [3, 1];
case 1:
return [4, t.iterator()];
case 2:
o = f.sent(), f.label = 3;
case 3:
s = o, c = 0, l = 0, u = function() {
var m;
return xe(this, function(g) {
switch (g.label) {
case 0:
return [4, s.next()];
case 1:
return m = g.sent(), a = v.tidy(function() {
if (m.value) {
var y = Wy(n, m.value), w = y.xs, b = y.ys, x = w.concat(b), L = v.tidy(function() {
return i(x);
});
if (v.dispose(x), l === 0)
for (var N = 0; N < L.length; ++N)
a.push(v.scalar(0));
for (var I = x[0].shape[0], C = function(O) {
var D = L[O], F = a[O];
a[O] = v.tidy(function() {
return v.add(a[O], v.mul(I, D));
}), l > 0 && v.dispose(F);
}, N = 0; N < L.length; ++N)
C(N);
v.dispose(L), c += I, ++l;
}
return a;
}), m.done ? (r && console.warn("Your dataset iterator ran out of data during evaluateDataset(). Interrupting evalution. Make sure that your dataset can generate at least `batches` " + ("batches (in this case, " + e.batches + " batches). ") + "You may need to use the repeat() function when building your dataset."), [2, "break"]) : [2];
}
});
}, f.label = 4;
case 4:
return (r ? l < e.batches : true) ? [5, u()] : [3, 6];
case 5:
return h = f.sent(), h === "break" ? [3, 6] : [3, 4];
case 6:
for (d = 0; d < a.length; ++d)
p = a[d], a[d] = v.div(a[d], c), v.dispose(p);
return [2, Vt(a)];
}
});
});
}
function qh(n) {
v.util.assert(n > 0 && Number.isInteger(n), function() {
return "batchSize is required to be a positive integer, but got " + n;
});
}
function Ka(n, t, e) {
return n == null ? [null] : Array.isArray(n) ? n.map(function(r) {
return ii(r, t, e - t);
}) : ii(n, t, e - t);
}
function Yh(n, t) {
return v.tidy(function() {
return n == null ? null : Array.isArray(n) ? n.map(function(e) {
return Yh(e, t);
}) : Q0(n, t.dtype === "int32" ? t : t.toInt());
});
}
function Kh(n, t) {
for (var e = [], r = 0, i = null; r < n; )
i = r + t, i >= n && (i = n), e.push([r, i]), r = i;
return e;
}
function ZE(n, t, e, r, i, a, s, o, c, l, u, h, d, p, f) {
return Ae(this, void 0, void 0, function() {
var m, g, y, w, b, x, L, N, I;
return xe(this, function(C) {
switch (C.label) {
case 0:
if (i == null && (i = 32), a == null && (a = 1), u == null && (u = true), d == null && (d = 0), m = false, c != null && l != null && (m = true), f != null && (m = true, p == null))
throw new M("Can only use `validationSteps` when doing step-wise training, i.e., `stepsPerEpoch` must be set.");
return g = n.checkNumSamples(e, i, p, "steps_per_epoch"), g != null && (y = bn(0, g)), s == null && (s = 1), w = Ly(o, s, a, d, g, p, i, m, h), b = w.callbackList, x = w.history, b.setModel(n), n.history = x, [4, b.onTrainBegin()];
case 1:
C.sent(), n.stopTraining_ = false, L = function(O) {
var D, F, k, B, V, P;
return xe(this, function(G) {
switch (G.label) {
case 0:
return [4, b.onEpochBegin(O)];
case 1:
if (G.sent(), D = {}, !(p != null))
return [3, 2];
throw new Re("stepsPerEpoch mode is not implemented yet.");
case 2:
if (u === "batch")
throw new Re("batch shuffling is not implemneted yet");
u && v.util.shuffle(y), F = v.tensor1d(y), k = Kh(g, i), B = function(j) {
var q;
return xe(this, function(H) {
switch (H.label) {
case 0:
return q = {}, [4, b.onBatchBegin(j, q)];
case 1:
return H.sent(), v.tidy(function() {
var J = k[j][0], $ = k[j][1], ee = ii(F, J, $ - J);
q.batch = j, q.size = $ - J;
for (var te = Yh(e, ee), ne = t(te), re = 0; re < r.length; ++re) {
var ie = r[re], oe = ne[re];
q[ie] = oe, v.keep(oe);
}
if (j === k.length - 1 && m)
for (var se = n.testLoop(c, l, i), re = 0; re < r.length; ++re) {
var ie = r[re], oe = se[re];
v.keep(oe), D["val_" + ie] = oe;
}
}), [4, b.onBatchEnd(j, q)];
case 2:
return H.sent(), my(q), n.stopTraining_ ? [2, "break"] : [2];
}
});
}, V = 0, G.label = 3;
case 3:
return V < k.length ? [5, B(V)] : [3, 6];
case 4:
if (P = G.sent(), P === "break")
return [3, 6];
G.label = 5;
case 5:
return ++V, [3, 3];
case 6:
F.dispose(), G.label = 7;
case 7:
return [4, b.onEpochEnd(O, D)];
case 8:
return G.sent(), n.stopTraining_ ? [2, "break"] : [2];
}
});
}, N = d, C.label = 2;
case 2:
return N < a ? [5, L(N)] : [3, 5];
case 3:
if (I = C.sent(), I === "break")
return [3, 5];
C.label = 4;
case 4:
return ++N, [3, 2];
case 5:
return [4, b.onTrainEnd()];
case 6:
return C.sent(), [4, n.history.syncData()];
case 7:
return C.sent(), [2, n.history];
}
});
});
}
function QE(n, t, e, r) {
return r === void 0 && (r = {}), Ae(this, void 0, void 0, function() {
var i, a, s, o, c, l, u, h, d, p, f, m, g, y, w, b, x, L, N, I, C, O, D;
return xe(this, function(F) {
switch (F.label) {
case 0:
if (n.isTraining)
throw new Error("Cannot start training because another fit() call is ongoing.");
n.isTraining = true, F.label = 1;
case 1:
return F.trys.push([1, , 7, 8]), h = r.batchSize == null ? 32 : r.batchSize, qh(h), d = false, [4, n.standardizeUserData(t, e, r.sampleWeight, r.classWeight, d, h)];
case 2:
if (p = F.sent(), i = p[0], a = p[1], u = p[2], f = false, m = void 0, !(r.validationData != null && r.validationData.length > 0))
return [3, 4];
if (f = true, r.validationData.length === 2)
s = r.validationData[0], o = r.validationData[1];
else
throw r.validationData.length === 3 ? new Re("validationData including sample weights is not supported yet.") : new M("When passing validation data, it must contain 2 (valX, valY) or 3 (valX, valY, valSampleWeight) items; " + (r.validationData + " is invalid."));
return g = true, [4, n.standardizeUserData(s, o, null, null, g, h)];
case 3:
return y = F.sent(), c = y[0], l = y[1], m = c.concat(l), [3, 5];
case 4:
r.validationSplit != null && r.validationSplit > 0 && r.validationSplit < 1 ? (f = true, w = Math.floor(i[0].shape[0] * (1 - r.validationSplit)), b = i[0].shape[0], c = Ka(i, w, b), i = Ka(i, 0, w), l = Ka(a, w, b), a = Ka(a, 0, w), m = c.concat(l)) : r.validationSteps != null && (f = true), F.label = 5;
case 5:
return x = i.concat(a).concat(u), n.checkTrainableWeightsConsistency(), L = n.makeTrainFunction(), N = n.getDedupedMetricsNames(), I = void 0, C = void 0, f ? (n.makeTestFunction(), I = n.testFunction, C = N.slice().concat(N.map(function(k) {
return "val_" + k;
}))) : (I = null, m = [], C = N.slice()), O = by(r.callbacks, r.yieldEvery), [4, ZE(n, L, x, N, h, r.epochs, r.verbose, O, I, m, r.shuffle, C, r.initialEpoch, null, null)];
case 6:
return D = F.sent(), [2, D];
case 7:
return n.isTraining = false, si(i, t), si(a, e), si(c, s), si(l, o), u != null && v.dispose(u), [7];
case 8:
return [2];
}
});
});
}
function By(n) {
var t = [];
n instanceof v.Tensor && (n = [n]);
for (var e = 0; e < n.length; ++e) {
var r = n[e];
if (r.rank === 1)
t.push(Pa(r, 1));
else {
if (r.rank === 0)
throw new Error("Expected tensor to be at least 1D, but received a 0D tensor (scalar).");
t.push(r);
}
}
return t;
}
function si(n, t) {
if (n == null)
return;
var e = [];
if (t instanceof v.Tensor)
e.push(t.id);
else if (Array.isArray(t))
t.forEach(function(c) {
return e.push(c.id);
});
else if (t != null)
for (var r in t) {
var i = t[r];
e.push(i.id);
}
var a = [];
if (n instanceof v.Tensor)
e.indexOf(n.id) === -1 && a.push(n);
else if (Array.isArray(n))
n.forEach(function(c) {
e.indexOf(c.id) === -1 && a.push(c);
});
else if (n != null)
for (var s in n) {
var o = n[s];
e.indexOf(o.id) === -1 && a.push(o);
}
a.forEach(function(c) {
c.isDisposed || c.dispose();
});
}
function e7(n) {
return n instanceof v.Tensor;
}
function jh(n) {
return Array.isArray(n);
}
function zy(n) {
return !e7(n) && !jh(n);
}
function Py(n, t, e, r, i) {
if (r === void 0 && (r = true), i === void 0 && (i = ""), t == null || t.length === 0) {
if (n != null) {
var a = false;
if (jh(n) && n.length > 0)
a = true;
else if (zy(n)) {
for (var s in n)
if (n.hasOwnProperty(s)) {
a = true;
break;
}
} else
a = true;
if (a)
throw new M("Error when checking model " + i + " expected no data, " + ("but got " + n));
}
return [];
}
if (n == null)
return t.map(function(g) {
return null;
});
var o;
if (zy(n)) {
n = n, o = [];
for (var c = 0, l = t; c < l.length; c++) {
var u = l[c];
if (n[u] == null)
throw new M('No data provided for "' + u + '". Need data for each key in: ' + ("" + t));
o.push(n[u]);
}
} else if (jh(n)) {
if (n = n, n.length !== t.length)
throw new M("Error when checking model " + i + ": the Array of Tensors that you are passing to your model is not the size the " + ("model expected. Expected to see " + t.length + " Tensor(s), but ") + ("instead got the following list of Tensor(s): " + n));
o = n;
} else {
if (n = n, t.length > 1)
throw new M("The model " + i + " expects " + t.length + " Tensor(s), " + ("but only received one Tensor. Found: Tensor with shape " + n.shape));
o = [n];
}
if (o = By(o), e != null)
for (var h = 0; h < t.length; ++h) {
if (e[h] == null)
continue;
var d = o[h];
if (d.shape.length !== e[h].length)
throw new M("Error when checking " + i + ": expected " + t[h] + " " + ("to have " + e[h].length + " dimension(s). but got array with ") + ("shape " + d.shape));
for (var p = 0; p < e[h].length; ++p) {
if (p === 0 && !r)
continue;
var f = d.shape[p], m = e[h][p];
if (m != null && m >= 0 && f !== m)
throw new M("Error when checking " + i + ": expected " + t[h] + " " + ("to have shape [" + e[h] + "], but got array with shape ") + ("[" + d.shape + "]."));
}
}
return o;
}
function t7(n, t, e) {
var r = xr(n.map(function(a) {
return a.shape[0];
}));
r.sort();
var i = xr(t.map(function(a) {
return a.shape[0];
}));
if (i.sort(), r.length > 1)
throw new M("All input Tensors (x) should have the same number of samples. Got array shapes: " + ("" + JSON.stringify(n.map(function(a) {
return a.shape;
}))));
if (i.length > 1)
throw new M("All target Tensors (y) should have the same number of samples. Got array shapes: " + ("" + JSON.stringify(t.map(function(a) {
return a.shape;
}))));
if (r.length > 0 && i.length > 0 && !v.util.arraysEqual(r, i))
throw new M("Input Tensors should have the same number of samples as target " + ("Tensors. Found " + r[0] + " input sample(s) and " + i[0] + " target ") + "sample(s).");
}
function n7(n, t, e) {
for (var r = [ai, bo, Ga], i = 0; i < n.length; ++i) {
var a = n[i], s = t[i], o = e[i];
if (s == null)
continue;
if (s === Ga && a.shape[a.shape.length - 1] === 1)
throw new M("You are passing a target array of shape " + a.shape + " while using a loss 'categorical_crossentropy'. 'categorical_crossentropy'expects targets to be binary matrices (1s and 0s) of shape [samples, classes].");
if (r.indexOf(s) !== -1)
for (var c = a.shape.slice(1), l = o.slice(1), u = 0; u < c.length; ++u) {
var h = c[u], d = l[u];
if (d != null && h !== d)
throw new M("A target Tensor with shape " + a.shape + " was passed for an " + ("output of shape " + o + ", while using a loss function that ") + "expects targets to have the same shape as the output.");
}
}
}
function My(n, t, e, r, i) {
r === void 0 && (r = true), i === void 0 && (i = "");
var a;
if (Array.isArray(n)) {
if (n.length !== t.length)
throw new M("Error when checking model " + i + ": the Array of Tensors that you are passing to your model is not the size the " + ("the model expected. Expected to see " + t.length + " Tensor(s),") + (" but instead got " + n.length + " Tensors(s)."));
a = n;
} else {
if (t.length > 1)
throw new M("The model expects " + t.length + " " + i + " Tensors, but only received one Tensor. Found: array with shape " + (JSON.stringify(n.shape) + "."));
a = [n];
}
if (e != null)
for (var s = 0; s < t.length; ++s) {
if (e[s] == null)
continue;
var o = a[s];
if (o.shape.length !== e[s].length)
throw new M("Error when checking " + i + ": expected " + t[s] + " " + ("to have " + e[s].length + " dimension(s), but got array with ") + ("shape " + JSON.stringify(o.shape)));
for (var c = 0; c < e[s].length; ++c) {
if (c === 0 && !r)
continue;
var l = o.shape[c], u = e[s][c];
if (u != null && u !== l)
throw new M("Error when checking " + i + ": expected " + (t[s] + " to have shape " + JSON.stringify(e[s]) + " but ") + ("got array with shape " + JSON.stringify(o.shape) + "."));
}
}
}
function r7(n, t) {
if (n == null || Array.isArray(n) && n.length === 0)
return t.map(function(c) {
return [];
});
var e;
if (typeof n == "string" || typeof n == "function")
e = [n];
else if (Array.isArray(n) || typeof n == "object")
e = n;
else
throw new TypeError("Type of metrics argument not understood. Expected an string," + ("function, Array, or Object, found: " + n));
if (Array.isArray(e))
return t.map(function(c) {
return e;
});
for (var r = [], i = 0, a = t; i < a.length; i++) {
var s = a[i], o = e.hasOwnProperty(s) ? e[s] : [];
Array.isArray(o) || (o = [o]), r.push(o);
}
return r;
}
var i7 = "layers-model", Ar = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.isTraining = false, r;
}
return t.prototype.summary = function(e, r, i) {
if (i === void 0 && (i = console.log), !this.built)
throw new M("This model has never been called, thus its weights have not been created yet. So no summary can be displayed. Build the model first (e.g., by calling it on some test data).");
BE(this, e, r, i);
}, t.prototype.compile = function(e) {
var r = this;
if (e.loss == null && (e.loss = []), this.loss = e.loss, typeof e.optimizer == "string")
this.optimizer_ = DE(e.optimizer), this.isOptimizerOwned = true;
else {
if (!(e.optimizer instanceof v.Optimizer))
throw new M("User-defined optimizer must be an instance of tf.Optimizer.");
this.optimizer_ = e.optimizer, this.isOptimizerOwned = false;
}
var i = [];
if (!Array.isArray(e.loss) && typeof e.loss != "string" && typeof e.loss != "function") {
e.loss = e.loss;
for (var a in e.loss)
if (this.outputNames.indexOf(a) === -1)
throw new M('Unknown entry in loss dictionary: "' + a + '". ' + ("Only expected the following keys: " + this.outputNames));
for (var s = 0, o = this.outputNames; s < o.length; s++) {
var c = o[s];
e.loss[c] == null && console.warn('Output "' + c + '" is missing from loss dictionary. We assume this was done on purpose, and we will not be expecting data ' + ("to be passed to " + c + " during training")), i.push(Uh(e.loss[c]));
}
} else if (Array.isArray(e.loss)) {
if (e.loss.length !== this.outputs.length)
throw new M("When passing an Array as loss, it should have one entry per " + ("model output. The model has " + this.outputs.length + " output(s), ") + ("but you passed loss=" + e.loss + "."));
var l = e.loss;
i = l.map(function(y) {
return Uh(y);
});
} else {
var u = Uh(e.loss);
this.outputs.forEach(function(y) {
i.push(u);
});
}
this.lossFunctions = i, this.feedOutputNames = [], this.feedOutputShapes = [], this.feedLossFns = [];
for (var h = 0; h < this.outputs.length; ++h) {
var d = this.internalOutputShapes[h], p = this.outputNames[h];
this.feedOutputNames.push(p), this.feedOutputShapes.push(d), this.feedLossFns.push(this.lossFunctions[h]);
}
var f = [];
this.metrics = e.metrics, this.metricsNames = ["loss"], this.metricsTensors = [], ri("loss", function() {
for (var y = 0; y < r.outputs.length; ++y) {
if (f.indexOf(y) !== -1)
continue;
var w = r.lossFunctions[y];
r.outputs.length > 1 && (r.metricsTensors.push([w, y]), r.metricsNames.push(r.outputNames[y] + "_loss"));
}
});
var m = r7(e.metrics, this.outputNames), g = function(y, w, b) {
r.outputNames.length > 1 && (w = r.outputNames[y] + "_" + w), r.metricsNames.push(w), r.metricsTensors.push([b, y]);
};
ri("metric", function() {
for (var y = function(b) {
if (f.indexOf(b) !== -1)
return "continue";
var x = m[b], L = function(N) {
for (var I = "", C, O, D, F = function(P) {
if (typeof P == "string" && ["accuracy", "acc", "crossentropy", "ce"].indexOf(P) !== -1) {
var G = r.internalOutputShapes[b];
G[G.length - 1] === 1 || r.lossFunctions[b] === bo ? ["accuracy", "acc"].indexOf(P) !== -1 ? O = Bh : ["crossentropy", "ce"].indexOf(P) !== -1 && (O = Ay) : r.lossFunctions[b] === wo ? ["accuracy", "acc"].indexOf(P) !== -1 ? O = Ty : ["crossentropy", "ce"].indexOf(P) !== -1 && (O = Ny) : ["accuracy", "acc"].indexOf(P) !== -1 ? O = zh : ["crossentropy", "ce"].indexOf(P) !== -1 && (O = Ph);
var j = void 0;
["accuracy", "acc"].indexOf(P) !== -1 ? j = "acc" : ["crossentropy", "ce"].indexOf(P) !== -1 && (j = "ce"), D = O, C = I + j;
} else {
var q = EE(P);
D = q, C = I + So(P);
}
var H;
ri(C, function() {
H = D;
}), g(b, C, H);
}, k = 0, B = N; k < B.length; k++) {
var V = B[k];
F(V);
}
};
L(x);
}, w = 0; w < r.outputs.length; ++w)
y(w);
}), this.collectedTrainableWeights = this.trainableWeights;
}, t.prototype.checkTrainableWeightsConsistency = function() {
if (this.collectedTrainableWeights == null)
return;
this.trainableWeights.length !== this.collectedTrainableWeights.length && console.warn("Discrepancy between trainableweights and collected trainable weights. Did you set `model.trainable` without calling `model.compile()` afterwards?");
}, t.prototype.evaluate = function(e, r, i) {
i === void 0 && (i = {});
var a = i.batchSize == null ? 32 : i.batchSize;
qh(a);
var s = true, o = this.standardizeUserDataXY(e, r, s, a);
try {
var c = o[0].concat(o[1]);
this.makeTestFunction();
var l = this.testFunction, u = this.testLoop(l, c, a, i.verbose, i.steps);
return Vt(u);
} finally {
si(o[0], e), si(o[1], r);
}
}, t.prototype.evaluateDataset = function(e, r) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(i) {
return this.makeTestFunction(), [2, JE(this, e, r)];
});
});
}, t.prototype.checkNumSamples = function(e, r, i, a) {
a === void 0 && (a = "steps");
var s;
if (i != null) {
if (s = null, r != null)
throw new M("If " + a + " is set, batchSize must be null or undefined." + ("Got batchSize = " + r));
} else if (e != null)
Array.isArray(e) ? s = e[0].shape[0] : s = e.shape[0];
else
throw new M("Either the input data should have a defined shape, or " + (a + " shoud be specified."));
return s;
}, t.prototype.execute = function(e, r) {
if (Array.isArray(r) && r.length === 0)
throw new M("`outputs` is an empty Array, which is not allowed.");
var i = Array.isArray(r), a = i ? r : [r], s = this.retrieveSymbolicTensors(a), o = new Ki();
if (e instanceof v.Tensor && (e = [e]), Array.isArray(e)) {
if (e.length !== this.inputs.length)
throw new M("The number of inputs provided (" + e.length + ") does not match the number of inputs of this model " + ("(" + this.inputs.length + ")."));
for (var c = 0; c < this.inputs.length; ++c)
o.add(this.inputs[c], e[c]);
} else
for (var l = 0, u = this.inputs; l < u.length; l++) {
var h = u[l], d = e[h.name];
if (d == null)
throw new M("No value is provided for the model's input " + h.name);
o.add(h, d);
}
var p = Ya(s, o);
return i ? p : p[0];
}, t.prototype.retrieveSymbolicTensors = function(e) {
for (var r = ti(null, e.length), i = e.length, a = 0, s = this.layers; a < s.length; a++) {
for (var o = s[a], c = Array.isArray(o.output) ? o.output : [o.output], l = c.map(function(p) {
return p.name;
}), u = 0; u < e.length; ++u) {
var h = l.indexOf(e[u]);
if (h !== -1 && (r[u] = c[h], i--), i === 0)
break;
}
if (i === 0)
break;
}
if (i > 0) {
var d = [];
throw r.forEach(function(p, f) {
p == null && d.push(e[f]);
}), new M("Cannot find SymbolicTensors for output name(s): " + ("" + JSON.stringify(d)));
}
return r;
}, t.prototype.predictLoop = function(e, r, i) {
var a = this;
return r === void 0 && (r = 32), i === void 0 && (i = false), v.tidy(function() {
var s = a.checkNumSamples(e);
if (i)
throw new Re("Verbose predictLoop() is not implemented yet.");
for (var o = Kh(s, r), c = a.outputs.map(function(h) {
return [];
}), l = function(h) {
var d = v.tidy(function() {
var p = o[h][0], f = o[h][1], m = Ka(e, p, f), g = [];
if (Array.isArray(m))
for (var y = 0; y < m.length; ++y)
g.push({key: a.inputs[y], value: m[y]});
else
g.push({key: a.inputs[0], value: m});
var w = new Ki(g);
return Ya(a.outputs, w);
});
d.forEach(function(p, f) {
return c[f].push(p);
});
}, u = 0; u < o.length; ++u)
l(u);
return Vt(c.map(function(h) {
return v.concat(h, 0);
}));
});
}, t.prototype.predict = function(e, r) {
r === void 0 && (r = {});
var i = By(e);
My(i, this.inputNames, this.feedInputShapes, false);
try {
var a = r.batchSize == null ? 32 : r.batchSize;
return qh(a), this.predictLoop(i, a);
} finally {
si(i, e);
}
}, t.prototype.predictOnBatch = function(e) {
My(e, this.inputNames, this.feedInputShapes, true);
var r = (Array.isArray(e) ? e[0] : e).shape[0];
return this.predictLoop(e, r);
}, t.prototype.standardizeUserDataXY = function(e, r, i, a) {
if (this.optimizer_ == null)
throw new Dn("You must compile a model before training/testing. Use LayersModel.compile(modelCompileArgs).");
for (var s = [], o = 0; o < this.feedOutputShapes.length; ++o) {
var c = this.feedOutputShapes[o], l = this.feedLossFns[o];
l === wo ? s.push(c.slice(0, c.length - 1).concat([1])) : s.push(c);
}
if (e = Py(e, this.feedInputNames, this.feedInputShapes, false, "input"), r = Py(r, this.feedOutputNames, s, false, "target"), t7(e, r), n7(r, this.feedLossFns, this.feedOutputShapes), this.stateful && a != null && a > 0 && e[0].shape[0] % a !== 0)
throw new M("In a stateful network, you should only pass inputs with a number of samples that is divisible by the batch size " + (a + ". Found: " + e[0].shape[0] + " sample(s)."));
return [e, r];
}, t.prototype.standardizeUserData = function(e, r, i, a, s, o) {
return s === void 0 && (s = true), Ae(this, void 0, void 0, function() {
var c, l, u, h, d, p, f, m;
return xe(this, function(g) {
switch (g.label) {
case 0:
if (c = this.standardizeUserDataXY(e, r, s, o), l = c[0], u = c[1], i != null)
throw new Error("sample weight is not supported yet.");
if (h = null, !(a != null))
return [3, 4];
d = Dy(a, this.outputNames), h = [], p = 0, g.label = 1;
case 1:
return p < d.length ? (m = (f = h).push, [4, ky(u[p], null, d[p])]) : [3, 4];
case 2:
m.apply(f, [g.sent()]), g.label = 3;
case 3:
return ++p, [3, 1];
case 4:
return [2, [l, u, h]];
}
});
});
}, t.prototype.testLoop = function(e, r, i, a, s) {
var o = this;
return a === void 0 && (a = 0), v.tidy(function() {
var c = o.checkNumSamples(r, i, s, "steps"), l = [];
if (a > 0)
throw new Re("Verbose mode is not implemented yet.");
if (s != null)
throw new Re("steps mode in testLoop() is not implemented yet");
for (var u = Kh(c, i), h = v.tensor1d(bn(0, c)), d = 0; d < u.length; ++d) {
var p = u[d][0], f = u[d][1], m = ii(h, p, f - p), g = Yh(r, m), y = e(g);
if (d === 0)
for (var w = 0; w < y.length; ++w)
l.push(v.scalar(0));
for (var w = 0; w < y.length; ++w) {
var b = y[w];
l[w] = v.add(l[w], v.mul(f - p, b));
}
}
for (var w = 0; w < l.length; ++w)
l[w] = v.div(l[w], c);
return l;
});
}, t.prototype.getDedupedMetricsNames = function() {
for (var e = this.metricsNames, r = [], i = 0; i < e.length; ++i) {
var a = e[i], s = a;
if (U0(e, a) > 1) {
var o = U0(e.slice(0, i), a);
s += "_" + o;
}
r.push(s);
}
return r;
}, t.prototype.makeTrainFunction = function() {
var e = this;
return function(r) {
var i = [], a = r.slice(0, e.inputs.length), s = r.slice(e.inputs.length, e.inputs.length + e.outputs.length), o = r.slice(e.inputs.length + e.outputs.length, e.inputs.length + e.outputs.length * 2), c = [], l = function() {
for (var p = [], f = 0; f < e.inputs.length; ++f)
p.push({key: e.inputs[f], value: a[f]});
for (var m = new Ki(p), g = Ya(e.outputs, m, {training: true}), y, f = 0; f < e.lossFunctions.length; ++f) {
var w = e.lossFunctions[f], b = w(s[f], g[f]);
o[f] != null && (b = qE(b, o[f]));
var x = v.mean(b);
i.push(x), f === 0 ? y = b : y = v.add(y, b);
}
for (var f = 0; f < e.metricsTensors.length; ++f) {
var L = void 0;
if (e.outputs.length > 1 && f < e.outputs.length)
L = i[f];
else {
var N = e.metricsTensors[f][0], I = e.metricsTensors[f][1];
L = v.mean(N(s[I], g[I]));
}
v.keep(L), c.push(L);
}
return y = v.mean(y), e.calculateLosses().forEach(function(C) {
y = v.add(y, C);
}), y;
}, u = e.collectedTrainableWeights.map(function(p) {
return p.read();
}), h = true, d = e.optimizer_.minimize(l, h, u);
return [d].concat(c);
};
}, t.prototype.makeTestFunction = function() {
var e = this;
this.testFunction = function(r) {
return v.tidy(function() {
for (var i = [], a, s = r.slice(0, e.inputs.length), o = r.slice(e.inputs.length, e.inputs.length + e.outputs.length), c = [], l = 0; l < e.inputs.length; ++l)
c.push({key: e.inputs[l], value: s[l]});
for (var u = new Ki(c), h = Ya(e.outputs, u), l = 0; l < e.lossFunctions.length; ++l) {
var d = e.lossFunctions[l], p = v.mean(d(o[l], h[l]));
l === 0 ? a = p : a = v.add(a, p), i.push(a);
}
for (var l = 0; l < e.metricsTensors.length; ++l) {
var f = e.metricsTensors[l][0], m = e.metricsTensors[l][1], g = v.mean(f(o[m], h[m]));
i.push(g);
}
return i;
});
};
}, t.prototype.fit = function(e, r, i) {
return i === void 0 && (i = {}), Ae(this, void 0, void 0, function() {
return xe(this, function(a) {
return [2, QE(this, e, r, i)];
});
});
}, t.prototype.fitDataset = function(e, r) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(i) {
return [2, $E(this, e, r)];
});
});
}, t.prototype.trainOnBatch = function(e, r) {
return Ae(this, void 0, void 0, function() {
var i, a, s, o, c, l, u, h, d, p;
return xe(this, function(f) {
switch (f.label) {
case 0:
return [4, this.standardizeUserData(e, r)];
case 1:
i = f.sent(), a = i[0], s = i[1], o = this.makeTrainFunction(), c = o(a.concat(s)), l = [], u = 0, h = c, f.label = 2;
case 2:
return u < h.length ? (d = h[u], [4, d.data()]) : [3, 5];
case 3:
p = f.sent(), l.push(p[0]), f.label = 4;
case 4:
return u++, [3, 2];
case 5:
return v.dispose(c), [2, Vt(l)];
}
});
});
}, t.prototype.getNamedWeights = function(e) {
for (var r = [], i = e != null && e.trainableOnly, a = i ? this.trainableWeights : this.weights, s = this.getWeights(i), o = 0; o < a.length; ++o) {
if (i && !a[o].trainable)
continue;
r.push({name: a[o].originalName, tensor: s[o]});
}
return r;
}, Object.defineProperty(t.prototype, "stopTraining", {get: function() {
return this.stopTraining_;
}, set: function(e) {
this.stopTraining_ = e;
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "optimizer", {get: function() {
return this.optimizer_;
}, set: function(e) {
this.optimizer_ !== e && (this.optimizer_ = e, this.isOptimizerOwned = false);
}, enumerable: true, configurable: true}), t.prototype.dispose = function() {
var e = n.prototype.dispose.call(this);
if (e.refCountAfterDispose === 0 && this.optimizer != null && this.isOptimizerOwned) {
var r = v.memory().numTensors;
this.optimizer_.dispose(), e.numDisposedVariables += r - v.memory().numTensors;
}
return e;
}, t.prototype.getLossIdentifiers = function() {
var e;
if (typeof this.loss == "string")
e = Qn(this.loss);
else if (Array.isArray(this.loss)) {
for (var r = 0, i = this.loss; r < i.length; r++) {
var a = i[r];
if (typeof a != "string")
throw new Error("Serialization of non-string loss is not supported.");
}
e = this.loss.map(function(h) {
return Qn(h);
});
} else {
var s = Object.keys(this.loss);
e = {};
for (var o = this.loss, c = 0, l = s; c < l.length; c++) {
var u = l[c];
if (typeof o[u] == "string")
e[u] = Qn(o[u]);
else
throw new Error("Serialization of non-string loss is not supported.");
}
}
return e;
}, t.prototype.getMetricIdentifiers = function() {
if (typeof this.metrics == "string" || typeof this.metrics == "function")
return [Qn(So(this.metrics))];
if (Array.isArray(this.metrics))
return this.metrics.map(function(i) {
return Qn(So(i));
});
var e = {};
for (var r in this.metrics)
e[r] = Qn(So(this.metrics[r]));
return e;
}, t.prototype.getTrainingConfig = function() {
return {loss: this.getLossIdentifiers(), metrics: this.getMetricIdentifiers(), optimizer_config: {class_name: this.optimizer.getClassName(), config: this.optimizer.getConfig()}};
}, t.prototype.loadTrainingConfig = function(e) {
if (e.weighted_metrics != null)
throw new Error("Loading weight_metrics is not supported yet.");
if (e.loss_weights != null)
throw new Error("Loading loss_weights is not supported yet.");
if (e.sample_weight_mode != null)
throw new Error("Loading sample_weight_mode is not supported yet.");
var r = qa(e.optimizer_config), i = Ln(r), a;
if (typeof e.loss == "string")
a = ni(e.loss);
else if (Array.isArray(e.loss))
a = e.loss.map(function(c) {
return ni(c);
});
else if (e.loss != null) {
a = {};
for (var s in e.loss)
a[s] = ni(e.loss[s]);
}
var o;
if (Array.isArray(e.metrics))
o = e.metrics.map(function(c) {
return ni(c);
});
else if (e.metrics != null) {
o = {};
for (var s in e.metrics)
o[s] = ni(e.metrics[s]);
}
this.compile({loss: a, metrics: o, optimizer: i});
}, t.prototype.save = function(e, r) {
return Ae(this, void 0, void 0, function() {
var i, a, s, o, c, l, u, h, d, p, f, m, g, y, w;
return xe(this, function(b) {
switch (b.label) {
case 0:
if (typeof e == "string") {
if (i = v.io.getSaveHandlers(e), i.length === 0)
throw new M("Cannot find any save handlers for URL '" + e + "'");
if (i.length > 1)
throw new M("Found more than one (" + i.length + ") save handlers for " + ("URL '" + e + "'"));
e = i[0];
}
if (e.save == null)
throw new M("LayersModel.save() cannot proceed because the IOHandler provided does not have the `save` attribute defined.");
return [4, v.io.encodeWeights(this.getNamedWeights(r))];
case 1:
return a = b.sent(), s = false, o = null, c = this.toJSON(o, s), l = {modelTopology: c, format: i7, generatedBy: "TensorFlow.js tfjs-layers v" + Vh, convertedBy: null}, u = r == null ? false : r.includeOptimizer, u && this.optimizer != null ? (l.trainingConfig = this.getTrainingConfig(), h = "optimizer", g = (m = v.io).encodeWeights, [4, this.optimizer.getWeights()]) : [3, 4];
case 2:
return [4, g.apply(m, [b.sent(), h])];
case 3:
d = b.sent(), p = d.data, f = d.specs, (w = a.specs).push.apply(w, f), a.data = v.io.concatenateArrayBuffers([a.data, p]), b.label = 4;
case 4:
return this.userDefinedMetadata != null && (y = true, Cy(this.userDefinedMetadata, this.name, y), l.userDefinedMetadata = this.userDefinedMetadata), l.weightData = a.data, l.weightSpecs = a.specs, [2, e.save(l)];
}
});
});
}, t.prototype.setUserDefinedMetadata = function(e) {
Cy(e, this.name), this.userDefinedMetadata = e;
}, t.prototype.getUserDefinedMetadata = function() {
return this.userDefinedMetadata;
}, t.className = "Model", t;
}(VE);
v.serialization.registerClass(Ar);
var a7 = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.className = "Functional", t;
}(Ar);
v.serialization.registerClass(a7);
function s7(n, t) {
return Ae(this, void 0, void 0, function() {
var e, r, i, a, s, o, c, l;
return xe(this, function(u) {
switch (u.label) {
case 0:
return "modelTopology" in n || (n = {modelTopology: n}), n = n, e = n.modelTopology, e.model_config != null && (e = e.model_config), r = qa(e), i = Ln(r, t), n.weightsManifest != null ? [4, v.io.loadWeights(n.weightsManifest, n.pathPrefix, i.weights.map(function(h) {
return h.originalName;
}))] : [3, 2];
case 1:
for (a = u.sent(), s = {}, o = 0, c = i.weights; o < c.length; o++)
l = c[o], s[l.originalName] = a[l.originalName];
i.loadWeights(s), v.dispose(a), u.label = 2;
case 2:
return [2, i];
}
});
});
}
function c7(n, t) {
return Ae(this, void 0, void 0, function() {
var e;
return xe(this, function(r) {
if (t == null && (t = {}), typeof n == "string") {
if (e = v.io.getLoadHandlers(n, t), e.length === 0)
e.push(v.io.browserHTTPRequest(n, t));
else if (e.length > 1)
throw new M("Found more than one (" + e.length + ") load handlers for " + ("URL '" + n + "'"));
n = e[0];
}
return [2, o7(n, void 0, t)];
});
});
}
function o7(n, t, e) {
return Ae(this, void 0, void 0, function() {
var r, i, a, s, o, c, l, u, h;
return xe(this, function(d) {
switch (d.label) {
case 0:
if (e == null && (e = {}), n.load == null)
throw new M("Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.");
return [4, n.load()];
case 1:
if (r = d.sent(), i = r.modelTopology, i.model_config != null && (i = i.model_config), a = e.strict == null ? true : e.strict, s = r.weightData != null && r.weightSpecs != null && a, o = Ln(qa(i), t, s), c = r.trainingConfig, c != null && o.loadTrainingConfig(c), r.userDefinedMetadata != null && o.setUserDefinedMetadata(r.userDefinedMetadata), !(r.weightData != null))
return [3, 4];
if (r.weightSpecs == null)
throw new M("LayersModel artifacts contains weight data, but not weight specs. Therefore loading of weights cannot proceed.");
return l = l7(r.weightData, r.weightSpecs), u = l.modelWeights, h = l.optimizerWeights, o.loadWeights(u, a), o.optimizer != null && h.length > 0 ? [4, o.optimizer.setWeights(h)] : [3, 3];
case 2:
d.sent(), d.label = 3;
case 3:
v.dispose(u), v.dispose(h.map(function(p) {
return p.tensor;
})), d.label = 4;
case 4:
return [2, o];
}
});
});
}
function l7(n, t) {
var e = v.io.decodeWeights(n, t), r = {}, i = [];
return t.forEach(function(a) {
a.group === "optimizer" ? i.push({name: a.name, tensor: e[a.name]}) : r[a.name] = e[a.name];
}), {modelWeights: r, optimizerWeights: i};
}
var $h = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, {inputs: [], outputs: []}) || this;
if (e = e || {}, r.trainable = true, r.built = false, r.name = e.name != null ? e.name : po("sequential_"), e.layers != null)
for (var i = 0, a = e.layers; i < a.length; i++) {
var s = a[i];
r.add(s);
}
return r;
}
return t.prototype.checkShape = function(e) {
var r = e.inboundNodes[0].outputTensors[0].shape;
if (r.some(function(i) {
return i < 0;
}))
throw new M("Negative dimension size caused by adding layer " + (e.name + " with input shape [") + (e.inboundNodes[0].inputTensors[0].shape + "]"));
}, t.prototype.add = function(e) {
var r = e instanceof t || e instanceof Ar, i;
if (r) {
if (i = e, i.outputs.length !== 1)
throw new M("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API.");
if (i.inputs.length !== 1)
throw new M("All layers in a Sequential model should have a single input tensor. For multi-input layers, use the functional API.");
}
if (this.outputs.length === 0) {
if (e.inboundNodes.length === 0) {
if (e.batchInputShape == null)
throw new M("The first layer in a Sequential model must get an `inputShape` or `batchInputShape` argument.");
var a = fy({batchShape: e.batchInputShape, dtype: e.dtype, name: e.name + "_input"});
e.apply(a);
}
if (r)
this.outputs = i.outputs, this.inputs = i.inputs;
else {
if (e.inboundNodes.length !== 1)
throw new M("A layer added to a Sequential model must not already be " + ("connected somewhere else. LayersModel received layer " + e.name + " ") + ("which has " + e.inboundNodes.length + " pre-existing inbound ") + "connections.");
if (e.inboundNodes[0].outputTensors.length !== 1)
throw new M("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API.");
this.checkShape(e), this.outputs = [e.inboundNodes[0].outputTensors[0]], this.inputs = py(this.outputs[0]);
}
this.inboundNodes = [], new go({outboundLayer: this, inboundLayers: [], nodeIndices: [], tensorIndices: [], inputTensors: this.inputs, outputTensors: this.outputs, inputMasks: ti(null, this.inputs.length), outputMasks: [null], inputShapes: this.inputs.map(function(o) {
return o.shape;
}), outputShapes: this.outputs[0].shape});
} else {
var s = e.apply(this.outputs[0]);
if (Array.isArray(s))
throw new TypeError("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API.");
this.checkShape(e), this.outputs = [s], this.inboundNodes[0].outputTensors = this.outputs, this.inboundNodes[0].outputShapes = [this.outputs[0].shape];
}
this.layers.push(e), this.built = false;
}, t.prototype.pop = function() {
if (this.layers.length === 0)
throw new TypeError("There are no layers in the model.");
if (this.layers.pop(), this.layers.length === 0)
this.outputs = [], this.inboundNodes = [], this.outboundNodes = [];
else {
var e = this.layers.length - 1;
this.layers[e].outboundNodes = [], this.outputs = [this.layers[e].output], this.inboundNodes[0].outputTensors = this.outputs, this.inboundNodes[0].outputShapes = [this.outputs[0].shape];
}
}, t.prototype.call = function(e, r) {
return this.model == null && this.build(), this.model.call(e, r);
}, t.prototype.build = function(e) {
if (Xe(e), this.inputs.length === 0 || this.outputs.length === 0)
throw new TypeError("Sequential model cannot be built: model is empty. Add some layers first.");
this.model = new Ar({inputs: this.inputs, outputs: this.outputs[0], name: this.name + "_model"}), this.model.trainable = this.trainable, this.supportsMasking = this.model.supportsMasking, this.inputLayers = this.model.inputLayers, this.inputLayersNodeIndices = this.model.inputLayersNodeIndices, this.inputLayersTensorIndices = this.model.inputLayersTensorIndices, this.outputLayers = this.model.outputLayers, this.outputLayersNodeIndices = this.model.outputLayersNodeIndices, this.outputLayersTensorIndices = this.model.outputLayersTensorIndices, this.nodesByDepth = this.model.nodesByDepth, this.containerNodes = this.model.containerNodes, this.outputNames = this.model.outputNames, this.inputNames = this.model.inputNames, this.built = true;
}, t.prototype.countParams = function() {
return this.built || this.build(), n.prototype.countParams.call(this);
}, t.prototype.summary = function(e, r, i) {
i === void 0 && (i = console.log), this.built || this.build(), n.prototype.summary.call(this, e, r, i);
}, t.prototype.setWeights = function(e) {
this.model == null && this.build(), this.model.setWeights(e);
}, t.prototype.evaluate = function(e, r, i) {
if (i === void 0 && (i = {}), !this.built)
throw new Dn("The model needs to be compiled before being used.");
return this.model.evaluate(e, r, i);
}, t.prototype.evaluateDataset = function(e, r) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(i) {
if (!this.built)
throw new Dn("The model needs to be compiled before being used.");
return [2, this.model.evaluateDataset(e, r)];
});
});
}, t.prototype.predict = function(e, r) {
return r === void 0 && (r = {}), this.model == null && this.build(), this.model.predict(e, r);
}, t.prototype.predictOnBatch = function(e) {
return this.model == null && this.build(), this.model.predictOnBatch(e);
}, t.prototype.compile = function(e) {
this.build(), this.model.compile(e), this.optimizer_ = this.model.optimizer, this.isOptimizerOwned = this.model.isOptimizerOwned, this.loss = this.model.loss, this.metrics = this.model.metrics, this.metricsTensors = this.model.metricsTensors, this.metricsNames = this.model.metricsNames;
}, Object.defineProperty(t.prototype, "optimizer", {get: function() {
return this.model == null ? void 0 : this.model.optimizer;
}, set: function(e) {
this.model.optimizer = e;
}, enumerable: true, configurable: true}), t.prototype.fit = function(e, r, i) {
return i === void 0 && (i = {}), Ae(this, void 0, void 0, function() {
return xe(this, function(a) {
if (!this.built)
throw new Dn("The model needs to be compiled before being used.");
return [2, this.model.fit(e, r, i)];
});
});
}, t.prototype.fitDataset = function(e, r) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(i) {
if (!this.built)
throw new Dn("The model needs to be compiled before being used.");
return [2, this.model.fitDataset(e, r)];
});
});
}, t.prototype.trainOnBatch = function(e, r) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(i) {
return [2, this.model.trainOnBatch(e, r)];
});
});
}, t.fromConfig = function(e, r, i, a) {
a === void 0 && (a = false);
var s, o = {};
if (r instanceof Array) {
if (!(r[0].className != null) || r[0].className === "Merge")
throw new M("Legacy serialization format not supported yet.");
s = r;
} else
v.util.assert(r.layers != null, function() {
return "When the config data for a Sequential model is not an Array, it must be an Object that contains the 'layers' field.";
}), s = r.layers, delete r.layers, o = r;
var c = new e(o);
if (!(c instanceof t))
throw new Re("Sequential.fromConfig called on non-Sequential input: " + c);
for (var l = 0, u = s; l < u.length; l++) {
var h = u[l], d = void 0, p = Ln(h, d, a);
a && p.setFastWeightInitDuringBuild(true), c.add(p);
}
return c;
}, Object.defineProperty(t.prototype, "stopTraining", {get: function() {
if (this.model == null)
throw new M("Cannot get the stopTraining property of a sequential model before it is compiled.");
return this.model.stopTraining;
}, set: function(e) {
if (this.model == null)
throw new M("Cannot set the stopTraining property of a sequential model before it is compiled.");
this.model.stopTraining = e;
}, enumerable: true, configurable: true}), t.prototype.getConfig = function() {
for (var e = [], r = 0, i = this.layers; r < i.length; r++) {
var a = i[r], s = {};
s.className = a.getClassName(), s.config = a.getConfig(), e.push(s);
}
return {name: this.name, layers: e};
}, t.className = "Sequential", t;
}(Ar);
v.serialization.registerClass($h);
function u7(n) {
return new Ar(n);
}
function h7(n) {
return new $h(n);
}
function d7(n, t) {
return t == null && (t = {}), c7(n, t);
}
function Hy(n) {
return fy(n);
}
function p7(n, t) {
xy.registerCallbackConstructor(n, t);
}
var Zt = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.getConfig = function() {
return {};
}, t;
}(v.serialization.Serializable), f7 = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e, r) {
return r === void 0 && (r = 1), WO(e, r);
}, t.className = "elu", t;
}(Zt);
v.serialization.registerClass(f7);
var m7 = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e) {
return v.selu(e);
}, t.className = "selu", t;
}(Zt);
v.serialization.registerClass(m7);
var g7 = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e) {
return v.relu(e);
}, t.className = "relu", t;
}(Zt);
v.serialization.registerClass(g7);
var y7 = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e) {
return v.tidy(function() {
return v.minimum(6, v.relu(e));
});
}, t.className = "relu6", t;
}(Zt);
v.serialization.registerClass(y7);
var v7 = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e) {
return e;
}, t.className = "linear", t;
}(Zt);
v.serialization.registerClass(v7);
var w7 = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e) {
return v.sigmoid(e);
}, t.className = "sigmoid", t;
}(Zt);
v.serialization.registerClass(w7);
var b7 = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e) {
return BO(e);
}, t.className = "hardSigmoid", t;
}(Zt);
v.serialization.registerClass(b7);
var x7 = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e) {
return v.softplus(e);
}, t.className = "softplus", t;
}(Zt);
v.serialization.registerClass(x7);
var L7 = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e) {
return UO(e);
}, t.className = "softsign", t;
}(Zt);
v.serialization.registerClass(L7);
var S7 = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e) {
return v.tanh(e);
}, t.className = "tanh", t;
}(Zt);
v.serialization.registerClass(S7);
var Vy = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e, r) {
return r === void 0 && (r = -1), v.softmax(e, r);
}, t.className = "softmax", t;
}(Zt);
v.serialization.registerClass(Vy);
var I7 = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e, r) {
return r === void 0 && (r = -1), v.logSoftmax(e, r);
}, t.className = "logSoftmax", t;
}(Zt);
v.serialization.registerClass(I7);
var A7 = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.apply = function(e, r) {
return r === void 0 && (r = 1), v.tidy(function() {
return v.sigmoid(e.mul(r)).mul(e);
});
}, t.className = "swish", t;
}(Zt);
v.serialization.registerClass(A7);
function Tr(n) {
return n.getClassName();
}
function Xh(n, t) {
return t === void 0 && (t = {}), Wa(n, v.serialization.SerializationMap.getMap().classNameMap, t, "activation");
}
function Nr(n) {
if (n == null) {
var t = {};
return t.className = "linear", t.config = {}, Xh(t);
}
if (typeof n == "string") {
var t = {};
return t.className = n, t.config = {}, Xh(t);
} else
return n instanceof Zt ? n : Xh(n);
}
function Jh(n) {
if (n != null && typeof n != "object")
throw new Error("Argument to L1L2 regularizer's constructor is expected to be an " + ("object, but received: " + n));
}
var Gy = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t;
}(v.serialization.Serializable), Ao = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this) || this;
return Jh(e), r.l1 = e == null || e.l1 == null ? 0.01 : e.l1, r.l2 = e == null || e.l2 == null ? 0.01 : e.l2, r.hasL1 = r.l1 !== 0, r.hasL2 = r.l2 !== 0, r;
}
return t.prototype.apply = function(e) {
var r = this;
return v.tidy(function() {
var i = v.zeros([1]);
return r.hasL1 && (i = v.add(i, v.sum(v.mul(r.l1, v.abs(e))))), r.hasL2 && (i = v.add(i, v.sum(v.mul(r.l2, Ma(e))))), i.asScalar();
});
}, t.prototype.getConfig = function() {
return {l1: this.l1, l2: this.l2};
}, t.fromConfig = function(e, r) {
return new e({l1: r.l1, l2: r.l2});
}, t.className = "L1L2", t;
}(Gy);
v.serialization.registerClass(Ao);
function T7(n) {
return Jh(n), new Ao({l1: n != null ? n.l1 : null, l2: 0});
}
function N7(n) {
return Jh(n), new Ao({l2: n != null ? n.l2 : null, l1: 0});
}
var qy = {l1l2: "L1L2"};
function Je(n) {
return vh(n);
}
function Yy(n, t) {
return t === void 0 && (t = {}), Wa(n, v.serialization.SerializationMap.getMap().classNameMap, t, "regularizer");
}
function st(n) {
if (n == null)
return null;
if (typeof n == "string") {
var t = n in qy ? qy[n] : n, e = {className: t, config: {}};
return Yy(e);
} else
return n instanceof Gy ? n : Yy(n);
}
var Ky = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e != null ? e : {}) || this;
return r.supportsMasking = true, e != null && (r.maxValue = e.maxValue), r;
}
return t.prototype.call = function(e, r) {
e = Oe(e);
var i = v.relu(e);
return this.maxValue != null && (i = v.clipByValue(i, 0, this.maxValue)), i;
}, t.prototype.computeOutputShape = function(e) {
return e;
}, t.prototype.getConfig = function() {
var e = {maxValue: this.maxValue}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "ReLU", t;
}(Fe);
v.serialization.registerClass(Ky);
var jy = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e != null ? e : {}) || this;
return r.DEFAULT_ALPHA = 0.3, e == null && (e = {}), r.alpha = e.alpha == null ? r.DEFAULT_ALPHA : e.alpha, r;
}
return t.prototype.call = function(e, r) {
var i = Oe(e);
return v.leakyRelu(i, this.alpha);
}, t.prototype.computeOutputShape = function(e) {
return e;
}, t.prototype.getConfig = function() {
var e = {alpha: this.alpha}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "LeakyReLU", t;
}(Fe);
v.serialization.registerClass(jy);
var $y = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e != null ? e : {}) || this;
if (r.DEFAULT_ALPHA_INITIALIZER = "zeros", e == null && (e = {}), r.supportsMasking = true, r.alphaInitializer = at(e.alphaInitializer || r.DEFAULT_ALPHA_INITIALIZER), r.alphaRegularizer = st(e.alphaRegularizer), r.alphaConstraint = It(e.alphaConstraint), e.sharedAxes == null)
r.sharedAxes = null;
else if (Array.isArray(e.sharedAxes))
r.sharedAxes = e.sharedAxes;
else if (typeof e.sharedAxes == "number")
r.sharedAxes = [e.sharedAxes];
else
throw new M("Expected sharedAxes to be a number or an array of numbers, " + ("but got " + e.sharedAxes));
return r;
}
return t.prototype.build = function(e) {
e = Xe(e);
var r = e.slice(1);
if (this.sharedAxes != null)
for (var i = 0, a = this.sharedAxes; i < a.length; i++) {
var s = a[i];
r[s - 1] = 1;
}
this.alpha = this.addWeight("alpha", r, "float32", this.alphaInitializer, this.alphaRegularizer, true, this.alphaConstraint);
var o = {};
if (this.sharedAxes != null)
for (var s = 1; s < e.length; ++s)
o[s] = e[s];
this.inputSpec = [new Ct({ndim: e.length, axes: o})], this.built = true;
}, t.prototype.call = function(e, r) {
return e = Oe(e), v.prelu(e, this.alpha.read());
}, t.prototype.getConfig = function() {
var e = {alphaInitializer: lt(this.alphaInitializer), alphaRegularizer: Je(this.alphaRegularizer), alphaConstraint: St(this.alphaConstraint), sharedAxes: this.sharedAxes}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "PReLU", t;
}(Fe);
v.serialization.registerClass($y);
var Xy = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e != null ? e : {}) || this;
if (r.DEFAULT_ALPHA = 1, e == null && (e = {}), e.alpha != null && e.alpha !== r.DEFAULT_ALPHA)
throw new Re("Non-default alpha value (" + e.alpha + ") is not supported by the ELU layer yet.");
return r.alpha = e.alpha == null ? r.DEFAULT_ALPHA : e.alpha, r;
}
return t.prototype.call = function(e, r) {
var i = Oe(e);
return v.elu(i);
}, t.prototype.computeOutputShape = function(e) {
return e;
}, t.prototype.getConfig = function() {
var e = {alpha: this.alpha}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "ELU", t;
}(Fe);
v.serialization.registerClass(Xy);
var Jy = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e != null ? e : {}) || this;
return r.DEFAULT_THETA = 1, e == null && (e = {}), r.theta = e.theta == null ? r.DEFAULT_THETA : e.theta, r;
}
return t.prototype.call = function(e, r) {
var i = Oe(e);
return i.mul(za(i.greater(this.theta), "float32"));
}, t.prototype.computeOutputShape = function(e) {
return e;
}, t.prototype.getConfig = function() {
var e = {theta: this.theta}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "ThresholdedReLU", t;
}(Fe);
v.serialization.registerClass(Jy);
var Zy = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e != null ? e : {}) || this;
return r.DEFAULT_AXIS = 1, e == null && (e = {}), r.softmax = new Vy().apply, r.axis = e.axis == null ? r.DEFAULT_AXIS : e.axis, r;
}
return t.prototype.call = function(e, r) {
var i = Oe(e);
return this.softmax(i, this.axis);
}, t.prototype.computeOutputShape = function(e) {
return e;
}, t.prototype.getConfig = function() {
var e = {axis: this.axis}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "Softmax", t;
}(Fe);
v.serialization.registerClass(Zy);
function ji(n, t, e) {
if (typeof n == "number")
return ti(n, t);
if (n.length !== t)
throw new M("The " + e + " argument must be an integer or tuple of " + t + " integers." + (" Received: " + n.length + " elements."));
for (var r = 0; r < t; ++r) {
var i = n[r];
if (!EO(i))
throw new M("The " + e + " argument must be an integer or tuple of " + t + (" integers. Received: " + JSON.stringify(n) + " including a") + (" non-integer number " + i));
}
return n;
}
function Sn(n, t, e, r, i) {
if (i === void 0 && (i = 1), n == null)
return n;
var a = t + (t - 1) * (i - 1), s;
return e === "same" ? s = n : s = n - a + 1, Math.floor((s + r - 1) / r);
}
function To(n, t, e, r) {
if (n == null)
return null;
if (r === "valid")
n = n * t + Sr([e - t, 0]);
else if (r === "same")
n = n * t;
else
throw new M("Unsupport padding mode: " + r + ".");
return n;
}
function Zh(n, t) {
return v.tidy(function() {
return mt(t), t === "channelsFirst" ? v.transpose(n, [0, 2, 3, 1]) : n;
});
}
function Qy(n, t) {
return v.tidy(function() {
return mt(t), t === "channelsFirst" ? v.transpose(n, [0, 2, 3, 4, 1]) : n;
});
}
function _7(n, t, e, r, i, a, s) {
return r === void 0 && (r = 1), i === void 0 && (i = "valid"), s === void 0 && (s = 1), v.tidy(function() {
if (a == null && (a = wn()), mt(a), n.shape.length !== 3)
throw new M("The input of a conv1dWithBias operation should be 3, but is " + (n.shape.length + " instead."));
if (t.shape.length !== 3)
throw new M("The kernel for a conv1dWithBias operation should be 3, but is " + (t.shape.length + " instead"));
if (e != null && e.shape.length !== 1)
throw new M("The bias for a conv1dWithBias operation should be 1, but is " + (t.shape.length + " instead"));
if (a === "channelsFirst" && (n = v.transpose(n, [0, 2, 1])), i === "causal")
throw new Re("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet.");
var o = v.conv1d(n, t, r, i === "same" ? "same" : "valid", "NWC", s);
return e != null && (o = Wn(o, e)), o;
});
}
function ev(n, t, e, r, i, a, s, o) {
return r === void 0 && (r = [1, 1]), i === void 0 && (i = "valid"), o === void 0 && (o = null), v.tidy(function() {
if (a == null && (a = wn()), mt(a), n.rank !== 3 && n.rank !== 4)
throw new M("conv2dWithBiasActivation expects input to be of rank 3 or 4, " + ("but received " + n.rank + "."));
if (t.rank !== 3 && t.rank !== 4)
throw new M("conv2dWithBiasActivation expects kernel to be of rank 3 or 4, " + ("but received " + n.rank + "."));
var c = Zh(n, a);
if (i === "causal")
throw new Re("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet.");
return c = v.fused.conv2d({x: c, filter: t, strides: r, pad: i === "same" ? "same" : "valid", dilations: s, dataFormat: "NHWC", bias: e, activation: o}), a === "channelsFirst" && (c = v.transpose(c, [0, 3, 1, 2])), c;
});
}
function C7(n, t, e, r, i, a, s) {
return r === void 0 && (r = [1, 1, 1]), i === void 0 && (i = "valid"), v.tidy(function() {
if (a == null && (a = wn()), mt(a), n.rank !== 4 && n.rank !== 5)
throw new M("conv3dWithBias expects input to be of rank 4 or 5, but received " + (n.rank + "."));
if (t.rank !== 4 && t.rank !== 5)
throw new M("conv3dWithBias expects kernel to be of rank 4 or 5, but received " + (n.rank + "."));
var o = Qy(n, a);
if (i === "causal")
throw new Re("The support for CAUSAL padding mode in conv3dWithBias is not implemented yet.");
return o = v.conv3d(o, t, r, i === "same" ? "same" : "valid", "NDHWC", s), e != null && (o = Wn(o, e)), a === "channelsFirst" && (o = v.transpose(o, [0, 4, 1, 2, 3])), o;
});
}
var tv = function(n) {
Q(t, n);
function t(e, r) {
var i = n.call(this, r) || this;
if (i.bias = null, i.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", i.DEFAULT_BIAS_INITIALIZER = "zeros", t.verifyArgs(r), i.rank = e, _t(i.rank, "rank"), i.rank !== 1 && i.rank !== 2 && i.rank !== 3)
throw new Re("Convolution layer for rank other than 1, 2, or 3 (" + i.rank + ") is not implemented yet.");
if (i.kernelSize = ji(r.kernelSize, e, "kernelSize"), i.strides = ji(r.strides == null ? 1 : r.strides, e, "strides"), i.padding = r.padding == null ? "valid" : r.padding, sn(i.padding), i.dataFormat = r.dataFormat == null ? "channelsLast" : r.dataFormat, mt(i.dataFormat), i.activation = Nr(r.activation), i.useBias = r.useBias == null ? true : r.useBias, i.biasInitializer = at(r.biasInitializer || i.DEFAULT_BIAS_INITIALIZER), i.biasConstraint = It(r.biasConstraint), i.biasRegularizer = st(r.biasRegularizer), i.activityRegularizer = st(r.activityRegularizer), i.dilationRate = ji(r.dilationRate == null ? 1 : r.dilationRate, e, "dilationRate"), i.rank === 1 && Array.isArray(i.dilationRate) && i.dilationRate.length !== 1)
throw new M("dilationRate must be a number or an array of a single number for 1D convolution, but received " + ("" + JSON.stringify(i.dilationRate)));
if (i.rank === 2) {
if (typeof i.dilationRate == "number")
i.dilationRate = [i.dilationRate, i.dilationRate];
else if (i.dilationRate.length !== 2)
throw new M("dilationRate must be a number or array of two numbers for 2D " + ("convolution, but received " + JSON.stringify(i.dilationRate)));
} else if (i.rank === 3) {
if (typeof i.dilationRate == "number")
i.dilationRate = [i.dilationRate, i.dilationRate, i.dilationRate];
else if (i.dilationRate.length !== 3)
throw new M("dilationRate must be a number or array of three numbers for 3D " + ("convolution, but received " + JSON.stringify(i.dilationRate)));
}
return i;
}
return t.verifyArgs = function(e) {
if (kn("kernelSize" in e, "required key 'kernelSize' not in config"), typeof e.kernelSize != "number" && !bh(e.kernelSize, "number", 1, 3))
throw new M("BaseConv expects config.kernelSize to be number or number[] with " + ("length 1, 2, or 3, but received " + JSON.stringify(e.kernelSize) + "."));
}, t.prototype.getConfig = function() {
var e = {kernelSize: this.kernelSize, strides: this.strides, padding: this.padding, dataFormat: this.dataFormat, dilationRate: this.dilationRate, activation: Tr(this.activation), useBias: this.useBias, biasInitializer: lt(this.biasInitializer), biasRegularizer: Je(this.biasRegularizer), activityRegularizer: Je(this.activityRegularizer), biasConstraint: St(this.biasConstraint)}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t;
}(Fe), No = function(n) {
Q(t, n);
function t(e, r) {
var i = n.call(this, e, r) || this;
return i.kernel = null, t.verifyArgs(r), i.filters = r.filters, _t(i.filters, "filters"), i.kernelInitializer = at(r.kernelInitializer || i.DEFAULT_KERNEL_INITIALIZER), i.kernelConstraint = It(r.kernelConstraint), i.kernelRegularizer = st(r.kernelRegularizer), i;
}
return t.prototype.build = function(e) {
var r;
e = Xe(e);
var i = this.dataFormat === "channelsFirst" ? 1 : e.length - 1;
if (e[i] == null)
throw new M("The channel dimension of the input should be defined. " + ("Found " + e[i]));
var a = e[i], s = this.kernelSize.concat([a, this.filters]);
this.kernel = this.addWeight("kernel", s, null, this.kernelInitializer, this.kernelRegularizer, true, this.kernelConstraint), this.useBias && (this.bias = this.addWeight("bias", [this.filters], null, this.biasInitializer, this.biasRegularizer, true, this.biasConstraint)), this.inputSpec = [{ndim: this.rank + 2, axes: (r = {}, r[i] = a, r)}], this.built = true;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
e = Oe(e);
var a, s = i.bias == null ? null : i.bias.read(), o = z0(i.activation.getClassName());
if (o != null && i.rank === 2)
a = ev(e, i.kernel.read(), s, i.strides, i.padding, i.dataFormat, i.dilationRate, o);
else {
if (i.rank === 1)
a = _7(e, i.kernel.read(), s, i.strides[0], i.padding, i.dataFormat, i.dilationRate[0]);
else if (i.rank === 2)
a = ev(e, i.kernel.read(), s, i.strides, i.padding, i.dataFormat, i.dilationRate);
else if (i.rank === 3)
a = C7(e, i.kernel.read(), s, i.strides, i.padding, i.dataFormat, i.dilationRate);
else
throw new Re("convolutions greater than 3D are not implemented yet.");
i.activation != null && (a = i.activation.apply(a));
}
return a;
});
}, t.prototype.computeOutputShape = function(e) {
e = Xe(e);
for (var r = [], i = this.dataFormat === "channelsLast" ? e.slice(1, e.length - 1) : e.slice(2), a = 0; a < i.length; ++a) {
var s = Sn(i[a], this.kernelSize[a], this.padding, this.strides[a], typeof this.dilationRate == "number" ? this.dilationRate : this.dilationRate[a]);
r.push(s);
}
var o = [e[0]];
return this.dataFormat === "channelsLast" ? (o = o.concat(r), o.push(this.filters)) : (o.push(this.filters), o = o.concat(r)), o;
}, t.prototype.getConfig = function() {
var e = {filters: this.filters, kernelInitializer: lt(this.kernelInitializer), kernelRegularizer: Je(this.kernelRegularizer), kernelConstraint: St(this.kernelConstraint)}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.verifyArgs = function(e) {
if (!("filters" in e) || typeof e.filters != "number" || e.filters < 1)
throw new M("Convolution layer expected config.filters to be a 'number' > 0 " + ("but got " + JSON.stringify(e.filters)));
}, t;
}(tv), Qh = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, 2, e) || this;
return t.verifyArgs(e), r;
}
return t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this);
return delete e.rank, e;
}, t.verifyArgs = function(e) {
if (typeof e.kernelSize != "number" && !bh(e.kernelSize, "number", 1, 2))
throw new M("Conv2D expects config.kernelSize to be number or number[] with " + ("length 1 or 2, but received " + JSON.stringify(e.kernelSize) + "."));
}, t.className = "Conv2D", t;
}(No);
v.serialization.registerClass(Qh);
var nv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, 3, e) || this;
return t.verifyArgs(e), r;
}
return t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this);
return delete e.rank, e;
}, t.verifyArgs = function(e) {
if (typeof e.kernelSize != "number" && !(Array.isArray(e.kernelSize) && (e.kernelSize.length === 1 || e.kernelSize.length === 3)))
throw new M("Conv3D expects config.kernelSize to be number or" + (" [number, number, number], but received " + JSON.stringify(e.kernelSize) + "."));
}, t.className = "Conv3D", t;
}(No);
v.serialization.registerClass(nv);
var rv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
if (r.inputSpec = [new Ct({ndim: 4})], r.padding !== "same" && r.padding !== "valid")
throw new M("Conv2DTranspose currently supports only padding modes 'same' " + ("and 'valid', but received padding mode " + r.padding));
return r;
}
return t.prototype.build = function(e) {
var r;
if (e = Xe(e), e.length !== 4)
throw new M("Input should have rank 4; Received input shape: " + JSON.stringify(e));
var i = this.dataFormat === "channelsFirst" ? 1 : e.length - 1;
if (e[i] == null)
throw new M("The channel dimension of the inputs should be defined. Found `None`.");
var a = e[i], s = this.kernelSize.concat([this.filters, a]);
this.kernel = this.addWeight("kernel", s, "float32", this.kernelInitializer, this.kernelRegularizer, true, this.kernelConstraint), this.useBias && (this.bias = this.addWeight("bias", [this.filters], "float32", this.biasInitializer, this.biasRegularizer, true, this.biasConstraint)), this.inputSpec = [new Ct({ndim: 4, axes: (r = {}, r[i] = a, r)})], this.built = true;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
var a = Oe(e);
if (a.shape.length !== 4)
throw new M("Conv2DTranspose.call() expects input tensor to be rank-4, but " + ("received a tensor of rank-" + a.shape.length));
var s = a.shape, o = s[0], c, l;
i.dataFormat === "channelsFirst" ? (c = 2, l = 3) : (c = 1, l = 2);
var u = s[c], h = s[l], d = i.kernelSize[0], p = i.kernelSize[1], f = i.strides[0], m = i.strides[1], g = To(u, f, d, i.padding), y = To(h, m, p, i.padding), w = [o, g, y, i.filters];
i.dataFormat !== "channelsLast" && (a = v.transpose(a, [0, 2, 3, 1]));
var b = v.conv2dTranspose(a, i.kernel.read(), w, i.strides, i.padding);
return i.dataFormat !== "channelsLast" && (b = v.transpose(b, [0, 3, 1, 2])), i.bias != null && (b = Wn(b, i.bias.read(), i.dataFormat)), i.activation != null && (b = i.activation.apply(b)), b;
});
}, t.prototype.computeOutputShape = function(e) {
e = Xe(e);
var r = e.slice(), i, a, s;
this.dataFormat === "channelsFirst" ? (i = 1, a = 2, s = 3) : (i = 3, a = 1, s = 2);
var o = this.kernelSize[0], c = this.kernelSize[1], l = this.strides[0], u = this.strides[1];
return r[i] = this.filters, r[a] = To(r[a], l, o, this.padding), r[s] = To(r[s], u, c, this.padding), r;
}, t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this);
return delete e.dilationRate, e;
}, t.className = "Conv2DTranspose", t;
}(Qh);
v.serialization.registerClass(rv);
var R7 = function(n) {
Q(t, n);
function t(e, r) {
var i = n.call(this, e, r) || this;
if (i.DEFAULT_DEPTHWISE_INITIALIZER = "glorotUniform", i.DEFAULT_POINTWISE_INITIALIZER = "glorotUniform", i.depthwiseKernel = null, i.pointwiseKernel = null, r.filters == null)
throw new M("The `filters` configuration field is required by SeparableConv, but is unspecified.");
if (r.kernelInitializer != null || r.kernelRegularizer != null || r.kernelConstraint != null)
throw new M("Fields kernelInitializer, kernelRegularizer and kernelConstraint are invalid for SeparableConv2D. Use depthwiseInitializer, depthwiseRegularizer, depthwiseConstraint, pointwiseInitializer, pointwiseRegularizer and pointwiseConstraint instead.");
if (r.padding != null && r.padding !== "same" && r.padding !== "valid")
throw new M("SeparableConv" + i.rank + "D supports only padding modes: " + ("'same' and 'valid', but received " + JSON.stringify(r.padding)));
return i.depthMultiplier = r.depthMultiplier == null ? 1 : r.depthMultiplier, i.depthwiseInitializer = at(r.depthwiseInitializer || i.DEFAULT_DEPTHWISE_INITIALIZER), i.depthwiseRegularizer = st(r.depthwiseRegularizer), i.depthwiseConstraint = It(r.depthwiseConstraint), i.pointwiseInitializer = at(r.depthwiseInitializer || i.DEFAULT_POINTWISE_INITIALIZER), i.pointwiseRegularizer = st(r.pointwiseRegularizer), i.pointwiseConstraint = It(r.pointwiseConstraint), i;
}
return t.prototype.build = function(e) {
var r;
if (e = Xe(e), e.length < this.rank + 2)
throw new M("Inputs to SeparableConv" + this.rank + "D should have rank " + (this.rank + 2 + ", but received input shape: ") + ("" + JSON.stringify(e)));
var i = this.dataFormat === "channelsFirst" ? 1 : e.length - 1;
if (e[i] == null || e[i] < 0)
throw new M("The channel dimension of the inputs should be defined, " + ("but found " + JSON.stringify(e[i])));
for (var a = e[i], s = this.kernelSize.concat([a, this.depthMultiplier]), o = [], c = 0; c < this.rank; ++c)
o.push(1);
o.push(a * this.depthMultiplier, this.filters);
var l = true;
this.depthwiseKernel = this.addWeight("depthwise_kernel", s, "float32", this.depthwiseInitializer, this.depthwiseRegularizer, l, this.depthwiseConstraint), this.pointwiseKernel = this.addWeight("pointwise_kernel", o, "float32", this.pointwiseInitializer, this.pointwiseRegularizer, l, this.pointwiseConstraint), this.useBias ? this.bias = this.addWeight("bias", [this.filters], "float32", this.biasInitializer, this.biasRegularizer, l, this.biasConstraint) : this.bias = null, this.inputSpec = [new Ct({ndim: this.rank + 2, axes: (r = {}, r[i] = a, r)})], this.built = true;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
e = Oe(e);
var a;
if (i.rank === 1)
throw new Re("1D separable convolution is not implemented yet.");
return i.rank === 2 && (i.dataFormat === "channelsFirst" && (e = v.transpose(e, [0, 2, 3, 1])), a = v.separableConv2d(e, i.depthwiseKernel.read(), i.pointwiseKernel.read(), i.strides, i.padding, i.dilationRate, "NHWC")), i.useBias && (a = Wn(a, i.bias.read(), i.dataFormat)), i.activation != null && (a = i.activation.apply(a)), i.dataFormat === "channelsFirst" && (a = v.transpose(a, [0, 3, 1, 2])), a;
});
}, t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this);
return delete e.rank, delete e.kernelInitializer, delete e.kernelRegularizer, delete e.kernelConstraint, e.depthwiseInitializer = lt(this.depthwiseInitializer), e.pointwiseInitializer = lt(this.pointwiseInitializer), e.depthwiseRegularizer = Je(this.depthwiseRegularizer), e.pointwiseRegularizer = Je(this.pointwiseRegularizer), e.depthwiseConstraint = St(this.depthwiseConstraint), e.pointwiseConstraint = St(this.pointwiseConstraint), e;
}, t.className = "SeparableConv", t;
}(No), iv = function(n) {
Q(t, n);
function t(e) {
return n.call(this, 2, e) || this;
}
return t.className = "SeparableConv2D", t;
}(R7);
v.serialization.registerClass(iv);
var av = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, 1, e) || this;
return t.verifyArgs(e), r.inputSpec = [{ndim: 3}], r;
}
return t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this);
return delete e.rank, delete e.dataFormat, e;
}, t.verifyArgs = function(e) {
if (typeof e.kernelSize != "number" && !bh(e.kernelSize, "number", 1, 1))
throw new M("Conv1D expects config.kernelSize to be number or number[] with " + ("length 1, but received " + JSON.stringify(e.kernelSize) + "."));
}, t.className = "Conv1D", t;
}(No);
v.serialization.registerClass(av);
var sv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return typeof e.cropping == "number" ? r.cropping = [[e.cropping, e.cropping], [e.cropping, e.cropping]] : typeof e.cropping[0] == "number" ? r.cropping = [[e.cropping[0], e.cropping[0]], [e.cropping[1], e.cropping[1]]] : r.cropping = e.cropping, r.dataFormat = e.dataFormat === void 0 ? "channelsLast" : e.dataFormat, r.inputSpec = [{ndim: 4}], r;
}
return t.prototype.computeOutputShape = function(e) {
return this.dataFormat === "channelsFirst" ? [e[0], e[1], e[2] - this.cropping[0][0] - this.cropping[0][1], e[3] - this.cropping[1][0] - this.cropping[1][1]] : [e[0], e[1] - this.cropping[0][0] - this.cropping[0][1], e[2] - this.cropping[1][0] - this.cropping[1][1], e[3]];
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
if (e = Oe(e), i.dataFormat === "channelsLast") {
var a = lo(e, i.cropping[0][0], e.shape[1] - i.cropping[0][0] - i.cropping[0][1], 2);
return lo(a, i.cropping[1][0], e.shape[2] - i.cropping[1][1] - i.cropping[1][0], 3);
} else {
var a = lo(e, i.cropping[0][0], e.shape[2] - i.cropping[0][0] - i.cropping[0][1], 3);
return lo(a, i.cropping[1][0], e.shape[3] - i.cropping[1][1] - i.cropping[1][0], 4);
}
});
}, t.prototype.getConfig = function() {
var e = {cropping: this.cropping, dataFormat: this.dataFormat}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "Cropping2D", t;
}(Fe);
v.serialization.registerClass(sv);
var ov = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.DEFAULT_SIZE = [2, 2], r.inputSpec = [{ndim: 4}], r.size = e.size == null ? r.DEFAULT_SIZE : e.size, r.dataFormat = e.dataFormat == null ? "channelsLast" : e.dataFormat, r;
}
return t.prototype.computeOutputShape = function(e) {
if (this.dataFormat === "channelsFirst") {
var r = e[2] == null ? null : this.size[0] * e[2], i = e[3] == null ? null : this.size[1] * e[3];
return [e[0], e[1], r, i];
} else {
var r = e[1] == null ? null : this.size[0] * e[1], i = e[2] == null ? null : this.size[1] * e[2];
return [e[0], r, i, e[3]];
}
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
var a = Oe(e), s = a.shape;
if (i.dataFormat === "channelsFirst") {
a = v.transpose(a, [0, 2, 3, 1]);
var o = i.size[0] * s[2], c = i.size[1] * s[3], l = a.resizeNearestNeighbor([o, c]);
return v.transpose(l, [0, 3, 1, 2]);
} else {
var o = i.size[0] * s[1], c = i.size[1] * s[2];
return a.resizeNearestNeighbor([o, c]);
}
});
}, t.prototype.getConfig = function() {
var e = {size: this.size, dataFormat: this.dataFormat}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "UpSampling2D", t;
}(Fe);
v.serialization.registerClass(ov);
function O7(n, t, e, r, i, a) {
return e === void 0 && (e = [1, 1]), r === void 0 && (r = "valid"), v.tidy(function() {
i == null && (i = wn()), mt(i);
var s = Zh(n, i);
if (n.rank !== 4)
throw new M("Input for depthwiseConv2d is required to be 4-D, but is instead " + (n.rank + "-D"));
if (t.rank !== 4)
throw new M("depthwiseKernel is required to be 4-D, but is instead " + (t.rank + "-D"));
return s = v.depthwiseConv2d(s, t, e, r === "same" ? "same" : "valid", "NHWC", a), i === "channelsFirst" && (s = v.transpose(s, [0, 3, 1, 2])), s;
});
}
var cv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, 2, e) || this;
return r.depthwiseKernel = null, r.depthMultiplier = e.depthMultiplier == null ? 1 : e.depthMultiplier, r.depthwiseInitializer = at(e.depthwiseInitializer || r.DEFAULT_KERNEL_INITIALIZER), r.depthwiseConstraint = It(e.depthwiseConstraint), r.depthwiseRegularizer = st(e.depthwiseRegularizer), r;
}
return t.prototype.build = function(e) {
if (e = Xe(e), e.length < 4)
throw new M("Inputs to DepthwiseConv2D should have rank 4. " + ("Received input shape: " + JSON.stringify(e) + "."));
var r = this.dataFormat === "channelsFirst" ? 1 : 3;
if (e[r] == null || e[r] < 0)
throw new M("The channel dimension of the inputs to DepthwiseConv2D should " + ("be defined, but is not (" + e[r] + ")."));
var i = e[r], a = [this.kernelSize[0], this.kernelSize[1], i, this.depthMultiplier];
this.depthwiseKernel = this.addWeight("depthwise_kernel", a, null, this.depthwiseInitializer, this.depthwiseRegularizer, true, this.depthwiseConstraint), this.useBias ? this.bias = this.addWeight("bias", [i * this.depthMultiplier], null, this.biasInitializer, this.biasRegularizer, true, this.biasConstraint) : this.bias = null, this.built = true;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
e = Oe(e);
var a = O7(e, i.depthwiseKernel.read(), i.strides, i.padding, i.dataFormat, null);
return i.useBias && (a = Wn(a, i.bias.read(), i.dataFormat)), i.activation != null && (a = i.activation.apply(a)), a;
});
}, t.prototype.computeOutputShape = function(e) {
e = Xe(e);
var r = this.dataFormat === "channelsFirst" ? e[2] : e[1], i = this.dataFormat === "channelsFirst" ? e[3] : e[2], a = this.dataFormat === "channelsFirst" ? e[1] * this.depthMultiplier : e[3] * this.depthMultiplier, s = Sn(r, this.kernelSize[0], this.padding, this.strides[0]), o = Sn(i, this.kernelSize[1], this.padding, this.strides[1]);
return this.dataFormat === "channelsFirst" ? [e[0], a, s, o] : [e[0], s, o, a];
}, t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this);
return e.depthMultiplier = this.depthMultiplier, e.depthwiseInitializer = lt(this.depthwiseInitializer), e.depthwiseRegularizer = Je(this.depthwiseRegularizer), e.depthwiseConstraint = St(this.depthwiseRegularizer), e;
}, t.className = "DepthwiseConv2D", t;
}(tv);
v.serialization.registerClass(cv);
function lv(n, t, e, r) {
if (Array.isArray(n)) {
if (t != null || e != null)
throw new M("When inputs is an array, neither initialState or constants should be provided");
r != null && (e = n.slice(n.length - r, n.length), n = n.slice(0, n.length - r)), n.length > 1 && (t = n.slice(1, n.length)), n = n[0];
}
function i(a) {
return a == null || Array.isArray(a) ? a : [a];
}
return t = i(t), e = i(e), {inputs: n, initialState: t, constants: e};
}
function uv(n, t, e, r, i, a, s, o) {
return r === void 0 && (r = false), s === void 0 && (s = false), o === void 0 && (o = false), v.tidy(function() {
var c = t.shape.length;
if (c < 3)
throw new M("Input should be at least 3D, but is " + c + "D.");
var l = [1, 0].concat(bn(2, c));
if (t = v.transpose(t, l), a != null)
throw new Re("The rnn() functoin of the deeplearn.js backend does not support constants yet.");
s && console.warn("Backend rnn(): the unroll = true option is not applicable to the imperative deeplearn.js backend."), i != null && (i = i.asType("bool").asType("float32"), i.rank === c - 1 && (i = v.expandDims(i, -1)), i = v.transpose(i, l)), r && (t = v.reverse(t, 0), i != null && (i = v.reverse(i, 0)));
var u = [], h, d = e, p = t.shape[0], f = v.unstack(t), m;
i != null && (m = v.unstack(i));
for (var g = function(x) {
var L = f[x], N = v.tidy(function() {
return n(L, d);
});
if (i == null)
h = N[0], d = N[1];
else {
var I = v.tidy(function() {
var C = m[x], O = v.onesLike(C).sub(C), D = N[0].mul(C).add(d[0].mul(O)), F = d.map(function(k, B) {
return N[1][B].mul(C).add(k.mul(O));
});
return {output: D, newStates: F};
});
h = I.output, d = I.newStates;
}
o && u.push(h);
}, y = 0; y < p; ++y)
g(y);
var w;
if (o) {
var b = 1;
w = v.stack(u, b);
}
return [h, w, d];
});
}
var _r = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this, i;
if (e.cell == null)
throw new M("cell property is missing for the constructor of RNN.");
if (Array.isArray(e.cell) ? i = new ed({cells: e.cell}) : i = e.cell, i.stateSize == null)
throw new M("The RNN cell should have an attribute `stateSize` (tuple of integers, one integer per RNN state).");
return r.cell = i, r.returnSequences = e.returnSequences == null ? false : e.returnSequences, r.returnState = e.returnState == null ? false : e.returnState, r.goBackwards = e.goBackwards == null ? false : e.goBackwards, r._stateful = e.stateful == null ? false : e.stateful, r.unroll = e.unroll == null ? false : e.unroll, r.supportsMasking = true, r.inputSpec = [new Ct({ndim: 3})], r.stateSpec = null, r.states_ = null, r.numConstants = null, r.keptStates = [], r;
}
return t.prototype.getStates = function() {
if (this.states_ == null) {
var e = Array.isArray(this.cell.stateSize) ? this.cell.stateSize.length : 1;
return bn(0, e).map(function(r) {
return null;
});
} else
return this.states_;
}, t.prototype.setStates = function(e) {
this.states_ = e;
}, t.prototype.computeOutputShape = function(e) {
Dh(e) && (e = e[0]), e = e;
var r = this.cell.stateSize;
Array.isArray(r) || (r = [r]);
var i = r[0], a;
if (this.returnSequences ? a = [e[0], e[1], i] : a = [e[0], i], this.returnState) {
for (var s = [], o = 0, c = r; o < c.length; o++) {
var l = c[o];
s.push([e[0], l]);
}
return [a].concat(s);
} else
return a;
}, t.prototype.computeMask = function(e, r) {
var i = this;
return v.tidy(function() {
Array.isArray(r) && (r = r[0]);
var a = i.returnSequences ? r : null;
if (i.returnState) {
var s = i.states.map(function(o) {
return null;
});
return [a].concat(s);
} else
return a;
});
}, Object.defineProperty(t.prototype, "states", {get: function() {
if (this.states_ == null) {
for (var e = Array.isArray(this.cell.stateSize) ? this.cell.stateSize.length : 1, r = [], i = 0; i < e; ++i)
r.push(null);
return r;
} else
return this.states_;
}, set: function(e) {
this.states_ = e;
}, enumerable: true, configurable: true}), t.prototype.build = function(e) {
if (this.numConstants != null)
throw new Re("Constants support is not implemented in RNN yet.");
Dh(e) && (e = e[0]), e = e;
var r = this.stateful ? e[0] : null, i = e.slice(2);
this.inputSpec[0] = new Ct({shape: [r, null].concat(i)});
var a = [e[0]].concat(e.slice(2));
this.cell.build(a);
var s;
if (Array.isArray(this.cell.stateSize) ? s = this.cell.stateSize : s = [this.cell.stateSize], this.stateSpec != null) {
if (!v.util.arraysEqual(this.stateSpec.map(function(o) {
return o.shape[o.shape.length - 1];
}), s))
throw new M("An initialState was passed that is not compatible with " + ("cell.stateSize. Received stateSpec=" + this.stateSpec + "; ") + ("However cell.stateSize is " + this.cell.stateSize));
} else
this.stateSpec = s.map(function(o) {
return new Ct({shape: [null, o]});
});
this.stateful && this.resetStates();
}, t.prototype.resetStates = function(e, r) {
var i = this;
r === void 0 && (r = false), v.tidy(function() {
if (!i.stateful)
throw new br("Cannot call resetStates() on an RNN Layer that is not stateful.");
var a = i.inputSpec[0].shape[0];
if (a == null)
throw new M("If an RNN is stateful, it needs to know its batch size. Specify the batch size of your input tensors: \n- If using a Sequential model, specify the batch size by passing a `batchInputShape` option to your first layer.\n- If using the functional API, specify the batch size by passing a `batchShape` option to your Input layer.");
if (i.states_ == null)
Array.isArray(i.cell.stateSize) ? i.states_ = i.cell.stateSize.map(function(u) {
return v.zeros([a, u]);
}) : i.states_ = [v.zeros([a, i.cell.stateSize])];
else if (e == null)
v.dispose(i.states_), i.keptStates != null && (v.dispose(i.keptStates), i.keptStates = []), Array.isArray(i.cell.stateSize) ? i.states_ = i.cell.stateSize.map(function(u) {
return v.zeros([a, u]);
}) : i.states_[0] = v.zeros([a, i.cell.stateSize]);
else {
if (Array.isArray(e) || (e = [e]), e.length !== i.states_.length)
throw new M("Layer " + i.name + " expects " + i.states_.length + " state(s), " + ("but it received " + e.length + " state value(s). Input ") + ("received: " + e));
r === true ? i.keptStates.push(i.states_.slice()) : v.dispose(i.states_);
for (var s = 0; s < i.states_.length; ++s) {
var o = e[s], c = Array.isArray(i.cell.stateSize) ? i.cell.stateSize[s] : i.cell.stateSize, l = [a, c];
if (!v.util.arraysEqual(o.shape, l))
throw new M("State " + s + " is incompatible with layer " + i.name + ": " + ("expected shape=" + l + ", received shape=" + o.shape));
i.states_[s] = o;
}
}
i.states_ = i.states_.map(function(u) {
return v.keep(u.clone());
});
});
}, t.prototype.apply = function(e, r) {
var i = r == null ? null : r.initialState, a = r == null ? null : r.constants;
r == null && (r = {});
var s = lv(e, i, a, this.numConstants);
e = s.inputs, i = s.initialState, a = s.constants;
var o = [], c = [];
if (i != null) {
r.initialState = i, o = o.concat(i), this.stateSpec = [];
for (var l = 0, u = i; l < u.length; l++) {
var h = u[l];
this.stateSpec.push(new Ct({shape: h.shape}));
}
c = c.concat(this.stateSpec);
}
a != null && (r.constants = a, o = o.concat(a), this.numConstants = a.length);
var d = o[0] instanceof xn;
if (d) {
var p = [e].concat(o), f = this.inputSpec.concat(c), m = this.inputSpec;
this.inputSpec = f;
var g = n.prototype.apply.call(this, p, r);
return this.inputSpec = m, g;
} else
return n.prototype.apply.call(this, e, r);
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
var a = r == null ? null : r.mask, s = r == null ? null : r.training, o = r == null ? null : r.initialState;
e = Oe(e), o == null && (i.stateful ? o = i.states_ : o = i.getInitialState(e));
var c = Array.isArray(i.cell.stateSize) ? i.cell.stateSize.length : 1;
if (o.length !== c)
throw new M("RNN Layer has " + c + " state(s) but was passed " + (o.length + " initial state(s)."));
i.unroll && console.warn("Ignoring unroll = true for RNN layer, due to imperative backend.");
var l = {training: s}, u = function(g, y) {
var w = i.cell.call([g].concat(y), l);
return [w[0], w.slice(1)];
}, h = uv(u, e, o, i.goBackwards, a, null, i.unroll, i.returnSequences), d = h[0], p = h[1], f = h[2];
i.stateful && i.resetStates(f, s);
var m = i.returnSequences ? p : d;
return i.returnState ? [m].concat(f) : m;
});
}, t.prototype.getInitialState = function(e) {
var r = this;
return v.tidy(function() {
var i = v.zeros(e.shape);
return i = v.sum(i, [1, 2]), i = Pa(i), Array.isArray(r.cell.stateSize) ? r.cell.stateSize.map(function(a) {
return a > 1 ? Lh(i, [1, a]) : i;
}) : r.cell.stateSize > 1 ? [Lh(i, [1, r.cell.stateSize])] : [i];
});
}, Object.defineProperty(t.prototype, "trainableWeights", {get: function() {
return this.trainable ? this.cell.trainableWeights : [];
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "nonTrainableWeights", {get: function() {
return this.trainable ? this.cell.nonTrainableWeights : this.cell.weights;
}, enumerable: true, configurable: true}), t.prototype.setFastWeightInitDuringBuild = function(e) {
n.prototype.setFastWeightInitDuringBuild.call(this, e), this.cell != null && this.cell.setFastWeightInitDuringBuild(e);
}, t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this), r = {returnSequences: this.returnSequences, returnState: this.returnState, goBackwards: this.goBackwards, stateful: this.stateful, unroll: this.unroll};
this.numConstants != null && (r.numConstants = this.numConstants);
var i = this.cell.getConfig();
return this.getClassName() === t.className && (r.cell = {className: this.cell.getClassName(), config: i}), Xt({}, i, e, r);
}, t.fromConfig = function(e, r, i) {
i === void 0 && (i = {});
var a = r.cell, s = Ln(a, i);
return new e(Object.assign(r, {cell: s}));
}, t.className = "RNN", t;
}(Fe);
v.serialization.registerClass(_r);
var $i = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t;
}(Fe), td = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.DEFAULT_ACTIVATION = "tanh", r.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", r.DEFAULT_RECURRENT_INITIALIZER = "orthogonal", r.DEFAULT_BIAS_INITIALIZER = "zeros", r.units = e.units, _t(r.units, "units"), r.activation = Nr(e.activation == null ? r.DEFAULT_ACTIVATION : e.activation), r.useBias = e.useBias == null ? true : e.useBias, r.kernelInitializer = at(e.kernelInitializer || r.DEFAULT_KERNEL_INITIALIZER), r.recurrentInitializer = at(e.recurrentInitializer || r.DEFAULT_RECURRENT_INITIALIZER), r.biasInitializer = at(e.biasInitializer || r.DEFAULT_BIAS_INITIALIZER), r.kernelRegularizer = st(e.kernelRegularizer), r.recurrentRegularizer = st(e.recurrentRegularizer), r.biasRegularizer = st(e.biasRegularizer), r.kernelConstraint = It(e.kernelConstraint), r.recurrentConstraint = It(e.recurrentConstraint), r.biasConstraint = It(e.biasConstraint), r.dropout = Gi([1, Sr([0, e.dropout == null ? 0 : e.dropout])]), r.recurrentDropout = Gi([1, Sr([0, e.recurrentDropout == null ? 0 : e.recurrentDropout])]), r.stateSize = r.units, r.dropoutMask = null, r.recurrentDropoutMask = null, r;
}
return t.prototype.build = function(e) {
e = Xe(e), this.kernel = this.addWeight("kernel", [e[e.length - 1], this.units], null, this.kernelInitializer, this.kernelRegularizer, true, this.kernelConstraint), this.recurrentKernel = this.addWeight("recurrent_kernel", [this.units, this.units], null, this.recurrentInitializer, this.recurrentRegularizer, true, this.recurrentConstraint), this.useBias ? this.bias = this.addWeight("bias", [this.units], null, this.biasInitializer, this.biasRegularizer, true, this.biasConstraint) : this.bias = null, this.built = true;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
if (e = e, e.length !== 2)
throw new M("SimpleRNNCell expects 2 input Tensors, got " + e.length + ".");
var a = e[1];
e = e[0];
var s = r.training == null ? false : r.training;
0 < i.dropout && i.dropout < 1 && i.dropoutMask == null && (i.dropoutMask = Cr({ones: function() {
return v.onesLike(e);
}, rate: i.dropout, training: s})), 0 < i.recurrentDropout && i.recurrentDropout < 1 && i.recurrentDropoutMask == null && (i.recurrentDropoutMask = Cr({ones: function() {
return v.onesLike(a);
}, rate: i.recurrentDropout, training: s}));
var o, c = i.dropoutMask, l = i.recurrentDropoutMask;
c != null ? o = Fn(v.mul(e, c), i.kernel.read()) : o = Fn(e, i.kernel.read()), i.bias != null && (o = Wn(o, i.bias.read())), l != null && (a = v.mul(a, l));
var u = v.add(o, Fn(a, i.recurrentKernel.read()));
return i.activation != null && (u = i.activation.apply(u)), [u, u];
});
}, t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this), r = {units: this.units, activation: Tr(this.activation), useBias: this.useBias, kernelInitializer: lt(this.kernelInitializer), recurrentInitializer: lt(this.recurrentInitializer), biasInitializer: lt(this.biasInitializer), kernelRegularizer: Je(this.kernelRegularizer), recurrentRegularizer: Je(this.recurrentRegularizer), biasRegularizer: Je(this.biasRegularizer), activityRegularizer: Je(this.activityRegularizer), kernelConstraint: St(this.kernelConstraint), recurrentConstraint: St(this.recurrentConstraint), biasConstraint: St(this.biasConstraint), dropout: this.dropout, recurrentDropout: this.recurrentDropout};
return Xt({}, e, r);
}, t.className = "SimpleRNNCell", t;
}($i);
v.serialization.registerClass(td);
var hv = function(n) {
Q(t, n);
function t(e) {
var r = this;
return e.cell = new td(e), r = n.call(this, e) || this, r;
}
return t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
i.cell.dropoutMask != null && (v.dispose(i.cell.dropoutMask), i.cell.dropoutMask = null), i.cell.recurrentDropoutMask != null && (v.dispose(i.cell.recurrentDropoutMask), i.cell.recurrentDropoutMask = null);
var a = r == null ? null : r.mask, s = r == null ? null : r.training, o = r == null ? null : r.initialState;
return n.prototype.call.call(i, e, {mask: a, training: s, initialState: o});
});
}, t.fromConfig = function(e, r) {
return new e(r);
}, t.className = "SimpleRNN", t;
}(_r);
v.serialization.registerClass(hv);
var nd = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
if (r.DEFAULT_ACTIVATION = "tanh", r.DEFAULT_RECURRENT_ACTIVATION = "hardSigmoid", r.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", r.DEFAULT_RECURRENT_INITIALIZER = "orthogonal", r.DEFAULT_BIAS_INITIALIZER = "zeros", e.resetAfter)
throw new M("GRUCell does not support reset_after parameter set to true.");
return r.units = e.units, _t(r.units, "units"), r.activation = Nr(e.activation === void 0 ? r.DEFAULT_ACTIVATION : e.activation), r.recurrentActivation = Nr(e.recurrentActivation === void 0 ? r.DEFAULT_RECURRENT_ACTIVATION : e.recurrentActivation), r.useBias = e.useBias == null ? true : e.useBias, r.kernelInitializer = at(e.kernelInitializer || r.DEFAULT_KERNEL_INITIALIZER), r.recurrentInitializer = at(e.recurrentInitializer || r.DEFAULT_RECURRENT_INITIALIZER), r.biasInitializer = at(e.biasInitializer || r.DEFAULT_BIAS_INITIALIZER), r.kernelRegularizer = st(e.kernelRegularizer), r.recurrentRegularizer = st(e.recurrentRegularizer), r.biasRegularizer = st(e.biasRegularizer), r.kernelConstraint = It(e.kernelConstraint), r.recurrentConstraint = It(e.recurrentConstraint), r.biasConstraint = It(e.biasConstraint), r.dropout = Gi([1, Sr([0, e.dropout == null ? 0 : e.dropout])]), r.recurrentDropout = Gi([1, Sr([0, e.recurrentDropout == null ? 0 : e.recurrentDropout])]), r.implementation = e.implementation, r.stateSize = r.units, r.dropoutMask = null, r.recurrentDropoutMask = null, r;
}
return t.prototype.build = function(e) {
e = Xe(e);
var r = e[e.length - 1];
this.kernel = this.addWeight("kernel", [r, this.units * 3], null, this.kernelInitializer, this.kernelRegularizer, true, this.kernelConstraint), this.recurrentKernel = this.addWeight("recurrent_kernel", [this.units, this.units * 3], null, this.recurrentInitializer, this.recurrentRegularizer, true, this.recurrentConstraint), this.useBias ? this.bias = this.addWeight("bias", [this.units * 3], null, this.biasInitializer, this.biasRegularizer, true, this.biasConstraint) : this.bias = null, this.built = true;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
if (e = e, e.length !== 2)
throw new M("GRUCell expects 2 input Tensors (inputs, h, c), got " + (e.length + "."));
var a = r.training == null ? false : r.training, s = e[1];
e = e[0], 0 < i.dropout && i.dropout < 1 && i.dropoutMask == null && (i.dropoutMask = Cr({ones: function() {
return v.onesLike(e);
}, rate: i.dropout, training: a, count: 3})), 0 < i.recurrentDropout && i.recurrentDropout < 1 && i.recurrentDropoutMask == null && (i.recurrentDropoutMask = Cr({ones: function() {
return v.onesLike(s);
}, rate: i.recurrentDropout, training: a, count: 3}));
var o = i.dropoutMask, c = i.recurrentDropoutMask, l, u, h;
0 < i.dropout && i.dropout < 1 && (e = v.mul(e, o[0]));
var d = Fn(e, i.kernel.read());
i.useBias && (d = Wn(d, i.bias.read())), 0 < i.recurrentDropout && i.recurrentDropout < 1 && (s = v.mul(s, c[0]));
var p = i.recurrentKernel.read(), f = v.split(p, [2 * i.units, i.units], p.rank - 1), m = f[0], g = f[1], y = Fn(s, m), w = v.split(d, 3, d.rank - 1), b = w[0], x = w[1], L = w[2], N = v.split(y, 2, y.rank - 1), I = N[0], C = N[1];
l = i.recurrentActivation.apply(v.add(b, I)), u = i.recurrentActivation.apply(v.add(x, C));
var O = Fn(v.mul(u, s), g);
h = i.activation.apply(v.add(L, O));
var D = v.add(v.mul(l, s), v.mul(v.add(1, v.neg(l)), h));
return [D, D];
});
}, t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this), r = {units: this.units, activation: Tr(this.activation), recurrentActivation: Tr(this.recurrentActivation), useBias: this.useBias, kernelInitializer: lt(this.kernelInitializer), recurrentInitializer: lt(this.recurrentInitializer), biasInitializer: lt(this.biasInitializer), kernelRegularizer: Je(this.kernelRegularizer), recurrentRegularizer: Je(this.recurrentRegularizer), biasRegularizer: Je(this.biasRegularizer), activityRegularizer: Je(this.activityRegularizer), kernelConstraint: St(this.kernelConstraint), recurrentConstraint: St(this.recurrentConstraint), biasConstraint: St(this.biasConstraint), dropout: this.dropout, recurrentDropout: this.recurrentDropout, implementation: this.implementation, resetAfter: false};
return Xt({}, e, r);
}, t.className = "GRUCell", t;
}($i);
v.serialization.registerClass(nd);
var dv = function(n) {
Q(t, n);
function t(e) {
var r = this;
return e.implementation === 0 && console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."), e.cell = new nd(e), r = n.call(this, e) || this, r;
}
return t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
i.cell.dropoutMask != null && (v.dispose(i.cell.dropoutMask), i.cell.dropoutMask = null), i.cell.recurrentDropoutMask != null && (v.dispose(i.cell.recurrentDropoutMask), i.cell.recurrentDropoutMask = null);
var a = r == null ? null : r.mask, s = r == null ? null : r.training, o = r == null ? null : r.initialState;
return n.prototype.call.call(i, e, {mask: a, training: s, initialState: o});
});
}, t.fromConfig = function(e, r) {
return r.implmentation === 0 && (r.implementation = 1), new e(r);
}, t.className = "GRU", t;
}(_r);
v.serialization.registerClass(dv);
var _o = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.DEFAULT_ACTIVATION = "tanh", r.DEFAULT_RECURRENT_ACTIVATION = "hardSigmoid", r.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", r.DEFAULT_RECURRENT_INITIALIZER = "orthogonal", r.DEFAULT_BIAS_INITIALIZER = "zeros", r.units = e.units, _t(r.units, "units"), r.activation = Nr(e.activation === void 0 ? r.DEFAULT_ACTIVATION : e.activation), r.recurrentActivation = Nr(e.recurrentActivation === void 0 ? r.DEFAULT_RECURRENT_ACTIVATION : e.recurrentActivation), r.useBias = e.useBias == null ? true : e.useBias, r.kernelInitializer = at(e.kernelInitializer || r.DEFAULT_KERNEL_INITIALIZER), r.recurrentInitializer = at(e.recurrentInitializer || r.DEFAULT_RECURRENT_INITIALIZER), r.biasInitializer = at(e.biasInitializer || r.DEFAULT_BIAS_INITIALIZER), r.unitForgetBias = e.unitForgetBias, r.kernelRegularizer = st(e.kernelRegularizer), r.recurrentRegularizer = st(e.recurrentRegularizer), r.biasRegularizer = st(e.biasRegularizer), r.kernelConstraint = It(e.kernelConstraint), r.recurrentConstraint = It(e.recurrentConstraint), r.biasConstraint = It(e.biasConstraint), r.dropout = Gi([1, Sr([0, e.dropout == null ? 0 : e.dropout])]), r.recurrentDropout = Gi([1, Sr([0, e.recurrentDropout == null ? 0 : e.recurrentDropout])]), r.implementation = e.implementation, r.stateSize = [r.units, r.units], r.dropoutMask = null, r.recurrentDropoutMask = null, r;
}
return t.prototype.build = function(e) {
var r;
e = Xe(e);
var i = e[e.length - 1];
this.kernel = this.addWeight("kernel", [i, this.units * 4], null, this.kernelInitializer, this.kernelRegularizer, true, this.kernelConstraint), this.recurrentKernel = this.addWeight("recurrent_kernel", [this.units, this.units * 4], null, this.recurrentInitializer, this.recurrentRegularizer, true, this.recurrentConstraint);
var a;
if (this.useBias) {
if (this.unitForgetBias) {
var s = this.biasInitializer, o = this.units;
a = new (r = function(c) {
Q(l, c);
function l() {
return c !== null && c.apply(this, arguments) || this;
}
return l.prototype.apply = function(u, h) {
var d = s.apply([o]), p = new Th().apply([o]), f = s.apply([o * 2]);
return Z0(Z0(d, p), f);
}, l;
}(hn), r.className = "CustomInit", r)();
} else
a = this.biasInitializer;
this.bias = this.addWeight("bias", [this.units * 4], null, a, this.biasRegularizer, true, this.biasConstraint);
} else
this.bias = null;
this.built = true;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
var a = r.training == null ? false : r.training;
if (e = e, e.length !== 3)
throw new M("LSTMCell expects 3 input Tensors (inputs, h, c), got " + (e.length + "."));
var s = e[1], o = e[2];
e = e[0], 0 < i.dropout && i.dropout < 1 && i.dropoutMask == null && (i.dropoutMask = Cr({ones: function() {
return v.onesLike(e);
}, rate: i.dropout, training: a, count: 4})), 0 < i.recurrentDropout && i.recurrentDropout < 1 && i.recurrentDropoutMask == null && (i.recurrentDropoutMask = Cr({ones: function() {
return v.onesLike(s);
}, rate: i.recurrentDropout, training: a, count: 4}));
var c = i.dropoutMask, l = i.recurrentDropoutMask, u, h, d, p;
0 < i.dropout && i.dropout < 1 && (e = v.mul(e, c[0]));
var f = Fn(e, i.kernel.read());
0 < i.recurrentDropout && i.recurrentDropout < 1 && (s = v.mul(s, l[0])), f = v.add(f, Fn(s, i.recurrentKernel.read())), i.useBias && (f = Wn(f, i.bias.read()));
var m = v.split(f, 4, f.rank - 1), g = m[0], y = m[1], w = m[2], b = m[3];
u = i.recurrentActivation.apply(g), h = i.recurrentActivation.apply(y), d = v.add(v.mul(h, o), v.mul(u, i.activation.apply(w))), p = i.recurrentActivation.apply(b);
var x = v.mul(p, i.activation.apply(d));
return [x, x, d];
});
}, t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this), r = {units: this.units, activation: Tr(this.activation), recurrentActivation: Tr(this.recurrentActivation), useBias: this.useBias, kernelInitializer: lt(this.kernelInitializer), recurrentInitializer: lt(this.recurrentInitializer), biasInitializer: lt(this.biasInitializer), unitForgetBias: this.unitForgetBias, kernelRegularizer: Je(this.kernelRegularizer), recurrentRegularizer: Je(this.recurrentRegularizer), biasRegularizer: Je(this.biasRegularizer), activityRegularizer: Je(this.activityRegularizer), kernelConstraint: St(this.kernelConstraint), recurrentConstraint: St(this.recurrentConstraint), biasConstraint: St(this.biasConstraint), dropout: this.dropout, recurrentDropout: this.recurrentDropout, implementation: this.implementation};
return Xt({}, e, r);
}, t.className = "LSTMCell", t;
}($i);
v.serialization.registerClass(_o);
var pv = function(n) {
Q(t, n);
function t(e) {
var r = this;
return e.implementation === 0 && console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."), e.cell = new _o(e), r = n.call(this, e) || this, r;
}
return t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
i.cell.dropoutMask != null && (v.dispose(i.cell.dropoutMask), i.cell.dropoutMask = null), i.cell.recurrentDropoutMask != null && (v.dispose(i.cell.recurrentDropoutMask), i.cell.recurrentDropoutMask = null);
var a = r == null ? null : r.mask, s = r == null ? null : r.training, o = r == null ? null : r.initialState;
return n.prototype.call.call(i, e, {mask: a, training: s, initialState: o});
});
}, t.fromConfig = function(e, r) {
return r.implmentation === 0 && (r.implementation = 1), new e(r);
}, t.className = "LSTM", t;
}(_r);
v.serialization.registerClass(pv);
var ed = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.cells = e.cells, r;
}
return Object.defineProperty(t.prototype, "stateSize", {get: function() {
for (var e = [], r = 0, i = this.cells.slice().reverse(); r < i.length; r++) {
var a = i[r];
Array.isArray(a.stateSize) ? e.push.apply(e, a.stateSize) : e.push(a.stateSize);
}
return e;
}, enumerable: true, configurable: true}), t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
e = e;
for (var a = e.slice(1), s = [], o = 0, c = i.cells.slice().reverse(); o < c.length; o++) {
var l = c[o];
Array.isArray(l.stateSize) ? s.push(a.splice(0, l.stateSize.length)) : s.push(a.splice(0, 1));
}
s.reverse();
for (var u = [], h, d = 0; d < i.cells.length; ++d) {
var l = i.cells[d];
a = s[d], d === 0 ? h = [e[0]].concat(a) : h = [h[0]].concat(a), h = l.call(h, r), u.push(h.slice(1));
}
a = [];
for (var p = 0, f = u.slice().reverse(); p < f.length; p++) {
var m = f[p];
a.push.apply(a, m);
}
return [h[0]].concat(a);
});
}, t.prototype.build = function(e) {
Dh(e) && (e = e[0]), e = e;
var r;
this.cells.forEach(function(i, a) {
ri("RNNCell_" + a, function() {
i.build(e), Array.isArray(i.stateSize) ? r = i.stateSize[0] : r = i.stateSize, e = [e[0], r];
});
}), this.built = true;
}, t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this), r = function(s) {
return {className: s.getClassName(), config: s.getConfig()};
}, i = this.cells.map(r), a = {cells: i};
return Xt({}, e, a);
}, t.fromConfig = function(e, r, i) {
i === void 0 && (i = {});
for (var a = [], s = 0, o = r.cells; s < o.length; s++) {
var c = o[s];
a.push(Ln(c, i));
}
return new e({cells: a});
}, Object.defineProperty(t.prototype, "trainableWeights", {get: function() {
if (!this.trainable)
return [];
for (var e = [], r = 0, i = this.cells; r < i.length; r++) {
var a = i[r];
e.push.apply(e, a.trainableWeights);
}
return e;
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "nonTrainableWeights", {get: function() {
for (var e = [], r = 0, i = this.cells; r < i.length; r++) {
var a = i[r];
e.push.apply(e, a.nonTrainableWeights);
}
if (!this.trainable) {
for (var s = [], o = 0, c = this.cells; o < c.length; o++) {
var a = c[o];
s.push.apply(s, a.trainableWeights);
}
return s.concat(e);
}
return e;
}, enumerable: true, configurable: true}), t.prototype.getWeights = function() {
for (var e = [], r = 0, i = this.cells; r < i.length; r++) {
var a = i[r];
e.push.apply(e, a.weights);
}
return kh(e);
}, t.prototype.setWeights = function(e) {
for (var r = [], i = 0, a = this.cells; i < a.length; i++)
for (var s = a[i], o = s.weights.length, c = e.splice(o), l = 0; l < s.weights.length; ++l)
r.push([s.weights[l], c[l]]);
Fh(r);
}, t.className = "StackedRNNCells", t;
}($i);
v.serialization.registerClass(ed);
function Cr(n) {
var t = n.ones, e = n.rate, r = n.training, i = r === void 0 ? false : r, a = n.count, s = a === void 0 ? 1 : a, o = function() {
return ey(t(), e);
}, c = function() {
return Ha(o, t, i);
};
if (!s || s <= 1)
return v.keep(c().clone());
var l = Array(s).fill(void 0).map(c);
return l.map(function(u) {
return v.keep(u.clone());
});
}
var cG = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t;
}($i), E7 = function(n) {
Q(t, n);
function t(e) {
var r = this;
if (e.unroll)
throw new Re("Unrolling is not possible with convolutional RNNs.");
if (Array.isArray(e.cell))
throw new Re("It is not possible at the moment to stack convolutional cells.");
return r = n.call(this, e) || this, r.inputSpec = [new Ct({ndim: 5})], r;
}
return t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
if (i.cell.dropoutMask != null && (v.dispose(i.cell.dropoutMask), i.cell.dropoutMask = null), i.cell.recurrentDropoutMask != null && (v.dispose(i.cell.recurrentDropoutMask), i.cell.recurrentDropoutMask = null), r && r.constants)
throw new M("ConvRNN2D cell does not support constants");
var a = r == null ? null : r.mask, s = r == null ? null : r.training, o = r == null ? null : r.initialState;
return n.prototype.call.call(i, e, {mask: a, training: s, initialState: o});
});
}, t.prototype.computeOutputShape = function(e) {
var r = this.computeSingleOutputShape(e);
return this.returnSequences || (r = [r[0]].concat(r.slice(2))), this.returnState && (r = [r].concat(Array(2).fill([e[0]].concat(r.slice(-3))))), r;
}, t.prototype.getInitialState = function(e) {
var r = this;
return v.tidy(function() {
var i = r.cell.stateSize, a = e.shape, s = r.computeSingleOutputShape(a), o = [s[0]].concat(s.slice(2)), c = v.zeros(o);
return Array.isArray(i) ? Array(i.length).fill(c) : [c];
});
}, t.prototype.resetStates = function(e, r) {
var i = this;
r === void 0 && (r = false), v.tidy(function() {
if (!i.stateful)
throw new br("Cannot call resetStates() on an RNN Layer that is not stateful.");
var a = i.inputSpec[0].shape, s = i.computeSingleOutputShape(a), o = [s[0]].concat(s.slice(2)), c = a[0];
if (c == null)
throw new M("If an RNN is stateful, it needs to know its batch size. Specify the batch size of your input tensors: \n- If using a Sequential model, specify the batch size by passing a `batchInputShape` option to your first layer.\n- If using the functional API, specify the batch size by passing a `batchShape` option to your Input layer.");
if (i.getStates() == null)
Array.isArray(i.cell.stateSize) ? i.states_ = i.cell.stateSize.map(function() {
return v.zeros(o);
}) : i.states_ = [v.zeros(o)];
else if (e == null)
v.dispose(i.states_), i.keptStates != null && (v.dispose(i.keptStates), i.keptStates = []), Array.isArray(i.cell.stateSize) ? i.states_ = i.cell.stateSize.map(function() {
return v.zeros(o);
}) : i.states_[0] = v.zeros(o);
else {
if (Array.isArray(e) || (e = [e]), e.length !== i.states_.length)
throw new M("Layer " + i.name + " expects " + i.states_.length + " state(s), " + ("but it received " + e.length + " state value(s). Input ") + ("received: " + e));
r ? i.keptStates.push(i.states_.slice()) : v.dispose(i.states_);
for (var l = 0; l < i.states_.length; ++l) {
var u = e[l], h = o;
if (!v.util.arraysEqual(u.shape, h))
throw new M("State " + l + " is incompatible with layer " + i.name + ": " + ("expected shape=" + h + ", received shape=" + u.shape));
i.states_[l] = u;
}
}
i.states_ = i.states_.map(function(d) {
return v.keep(d.clone());
});
});
}, t.prototype.computeSingleOutputShape = function(e) {
var r = this.cell, i = r.dataFormat, a = r.filters, s = r.kernelSize, o = r.padding, c = r.strides, l = r.dilationRate, u = i === "channelsFirst", h = e[u ? 3 : 2], d = e[u ? 4 : 3], p = Sn(h, s[0], o, c[0], l[0]), f = Sn(d, s[1], o, c[1], l[1]), m = e.slice(0, 2).concat(u ? [a, p, f] : [p, f, a]);
return m;
}, t.className = "ConvRNN2D", t;
}(_r), rd = function(n) {
Q(t, n);
function t(e) {
var r = this, i = e.filters, a = e.kernelSize, s = e.strides, o = e.padding, c = e.dataFormat, l = e.dilationRate;
return r = n.call(this, Xt({}, e, {units: i})) || this, r.filters = i, _t(r.filters, "filters"), r.kernelSize = ji(a, 2, "kernelSize"), r.kernelSize.forEach(function(u) {
return _t(u, "kernelSize");
}), r.strides = ji(s || 1, 2, "strides"), r.strides.forEach(function(u) {
return _t(u, "strides");
}), r.padding = o || "valid", sn(r.padding), r.dataFormat = c || "channelsLast", mt(r.dataFormat), r.dilationRate = ji(l || 1, 2, "dilationRate"), r.dilationRate.forEach(function(u) {
return _t(u, "dilationRate");
}), r;
}
return t.prototype.build = function(e) {
var r;
e = Xe(e);
var i = this.dataFormat === "channelsFirst" ? 1 : e.length - 1;
if (e[i] == null)
throw new M("The channel dimension of the input should be defined. " + ("Found " + e[i]));
var a = e[i], s = 4, o = this.kernelSize.concat([a, this.filters * s]);
this.kernel = this.addWeight("kernel", o, null, this.kernelInitializer, this.kernelRegularizer, true, this.kernelConstraint);
var c = this.kernelSize.concat([this.filters, this.filters * s]);
if (this.recurrentKernel = this.addWeight("recurrent_kernel", c, null, this.recurrentInitializer, this.recurrentRegularizer, true, this.recurrentConstraint), this.useBias) {
var l = void 0;
if (this.unitForgetBias) {
var u = this.biasInitializer, h = this.filters;
l = new (r = function(d) {
Q(p, d);
function p() {
return d !== null && d.apply(this, arguments) || this;
}
return p.prototype.apply = function(f, m) {
var g = u.apply([h]), y = v.ones([h]), w = u.apply([h * 2]);
return Ih([g, y, w]);
}, p;
}(hn), r.className = "CustomInit", r)();
} else
l = this.biasInitializer;
this.bias = this.addWeight("bias", [this.filters * s], null, l, this.biasRegularizer, true, this.biasConstraint);
}
this.built = true;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
if (e.length !== 3)
throw new M("ConvLSTM2DCell expects 3 input Tensors (inputs, h, c), got " + (e.length + "."));
var a = r.training || false, s = e[0], o = e[1], c = e[2], l = 4;
0 < i.dropout && i.dropout < 1 && i.dropoutMask == null && (i.dropoutMask = Cr({ones: function() {
return v.onesLike(s);
}, rate: i.dropout, training: a, count: l}));
var u = i.dropoutMask, h = function(re, ie, oe) {
return !ie || !ie[oe] ? re : v.mul(ie[oe], re);
}, d = h(s, u, 0), p = h(s, u, 1), f = h(s, u, 2), m = h(s, u, 3);
0 < i.recurrentDropout && i.recurrentDropout < 1 && i.recurrentDropoutMask == null && (i.recurrentDropoutMask = Cr({ones: function() {
return v.onesLike(o);
}, rate: i.recurrentDropout, training: a, count: l}));
var g = i.recurrentDropoutMask, y = h(o, g, 0), w = h(o, g, 1), b = h(o, g, 2), x = h(o, g, 3), L = 3, N = v.split(i.kernel.read(), l, L), I = N[0], C = N[1], O = N[2], D = N[3], F = i.useBias ? v.split(i.bias.read(), l) : [null, null, null, null], k = F[0], B = F[1], V = F[2], P = F[3];
d = i.inputConv(d, I, k, i.padding), p = i.inputConv(p, C, B, i.padding), f = i.inputConv(f, O, V, i.padding), m = i.inputConv(m, D, P, i.padding);
var G = v.split(i.recurrentKernel.read(), l, L), j = G[0], q = G[1], H = G[2], J = G[3];
y = i.recurrentConv(y, j), w = i.recurrentConv(w, q), b = i.recurrentConv(b, H), x = i.recurrentConv(x, J);
var $ = i.recurrentActivation.apply(v.add(d, y)), ee = i.recurrentActivation.apply(v.add(p, w)), te = v.add(v.mul(ee, c), v.mul($, i.activation.apply(v.add(f, b)))), ne = v.mul(i.recurrentActivation.apply(v.add(m, x)), i.activation.apply(te));
return [ne, ne, te];
});
}, t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this), r = e.units, i = gO(e, ["units"]), a = {filters: this.filters, kernelSize: this.kernelSize, padding: this.padding, dataFormat: this.dataFormat, dilationRate: this.dilationRate, strides: this.strides};
return Xt({}, i, a);
}, t.prototype.inputConv = function(e, r, i, a) {
var s = v.conv2d(e, r, this.strides, a || "valid", this.dataFormat === "channelsFirst" ? "NCHW" : "NHWC", this.dilationRate);
return i ? Wn(s, i, this.dataFormat) : s;
}, t.prototype.recurrentConv = function(e, r) {
var i = 1;
return v.conv2d(e, r, i, "same", this.dataFormat === "channelsFirst" ? "NCHW" : "NHWC");
}, t.className = "ConvLSTM2DCell", t;
}(_o);
v.serialization.registerClass(rd);
var fv = function(n) {
Q(t, n);
function t(e) {
var r = this, i = new rd(e);
return r = n.call(this, Xt({}, e, {cell: i})) || this, r;
}
return t.fromConfig = function(e, r) {
return new e(r);
}, t.className = "ConvLSTM2D", t;
}(E7);
v.serialization.registerClass(fv);
var id = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.rate = Math.max(Math.min(e.rate, 1), 0), r.noiseShape = e.noiseShape, r.seed = e.seed, r.supportsMasking = true, r;
}
return t.prototype.getNoiseShape = function(e) {
if (this.noiseShape == null)
return this.noiseShape;
for (var r = e.shape, i = [], a = 0; a < this.noiseShape.length; ++a)
i.push(this.noiseShape[a] == null ? r[a] : this.noiseShape[a]);
return i;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
i.invokeCallHook(e, r);
var a = Oe(e);
if (0 < i.rate && i.rate < 1) {
var s = r.training == null ? false : r.training, o = i.getNoiseShape(a), c = Ha(function() {
return ey(a, i.rate, o, i.seed);
}, function() {
return a;
}, s);
return c;
}
return e;
});
}, t.prototype.getConfig = function() {
var e = {rate: this.rate, noiseShape: this.noiseShape, seed: this.seed}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.prototype.dispose = function() {
return n.prototype.dispose.call(this);
}, t.className = "Dropout", t;
}(Fe);
v.serialization.registerClass(id);
var mv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.inputSpec = [{ndim: 3}], r;
}
return t.prototype.getNoiseShape = function(e) {
var r = e.shape;
return [r[0], 1, r[2]];
}, t.className = "SpatialDropout1D", t;
}(id);
v.serialization.registerClass(mv);
var gv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
if (r.activation = null, r.useBias = true, r.kernel = null, r.bias = null, r.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", r.DEFAULT_BIAS_INITIALIZER = "zeros", e.batchInputShape == null && e.inputShape == null && e.inputDim != null) {
var i = null;
e.batchSize != null && (i = e.batchSize), r.batchInputShape = [i, e.inputDim];
}
return r.units = e.units, _t(r.units, "units"), r.activation = Nr(e.activation), e.useBias != null && (r.useBias = e.useBias), r.kernelInitializer = at(e.kernelInitializer || r.DEFAULT_KERNEL_INITIALIZER), r.biasInitializer = at(e.biasInitializer || r.DEFAULT_BIAS_INITIALIZER), r.kernelConstraint = It(e.kernelConstraint), r.biasConstraint = It(e.biasConstraint), r.kernelRegularizer = st(e.kernelRegularizer), r.biasRegularizer = st(e.biasRegularizer), r.activityRegularizer = st(e.activityRegularizer), r.supportsMasking = true, r.inputSpec = [{minNDim: 2}], r;
}
return t.prototype.build = function(e) {
var r;
e = Xe(e);
var i = e[e.length - 1];
this.kernel == null && (this.kernel = this.addWeight("kernel", [i, this.units], null, this.kernelInitializer, this.kernelRegularizer, true, this.kernelConstraint), this.useBias && (this.bias = this.addWeight("bias", [this.units], null, this.biasInitializer, this.biasRegularizer, true, this.biasConstraint))), this.inputSpec = [{minNDim: 2, axes: (r = {}, r[-1] = i, r)}], this.built = true;
}, t.prototype.computeOutputShape = function(e) {
e = Xe(e);
var r = e.slice();
return r[r.length - 1] = this.units, r;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
i.invokeCallHook(e, r);
var a = Oe(e), s = z0(i.activation.getClassName()), o;
return s != null ? o = Fn(a, i.kernel.read(), s, i.bias ? i.bias.read() : null) : (o = Fn(a, i.kernel.read()), i.bias != null && (o = Wn(o, i.bias.read())), i.activation != null && (o = i.activation.apply(o))), o;
});
}, t.prototype.getConfig = function() {
var e = {units: this.units, activation: Tr(this.activation), useBias: this.useBias, kernelInitializer: lt(this.kernelInitializer), biasInitializer: lt(this.biasInitializer), kernelRegularizer: Je(this.kernelRegularizer), biasRegularizer: Je(this.biasRegularizer), activityRegularizer: Je(this.activityRegularizer), kernelConstraint: St(this.kernelConstraint), biasConstraint: St(this.biasConstraint)}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "Dense", t;
}(Fe);
v.serialization.registerClass(gv);
var yv = function(n) {
Q(t, n);
function t(e) {
var r = this;
return e = e || {}, r = n.call(this, e) || this, r.inputSpec = [{minNDim: 3}], r.dataFormat = e.dataFormat, r;
}
return t.prototype.computeOutputShape = function(e) {
e = Xe(e);
for (var r = 0, i = e.slice(1); r < i.length; r++) {
var a = i[r];
if (a == null)
throw new M('The shape of the input to "Flatten" is not fully defined ' + ("(got " + e.slice(1) + "). Make sure to pass a complete ") + '"input_shape" or "batch_input_shape" argument to the first layer in your model.');
}
return [e[0], Lr(e, 1)];
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
i.invokeCallHook(e, r);
var a = Oe(e);
if (i.dataFormat === "channelsFirst" && a.rank > 1) {
for (var s = [0], o = 2; o < a.rank; ++o)
s.push(o);
s.push(1), a = a.transpose(s);
}
return FO(a);
});
}, t.prototype.getConfig = function() {
var e = {};
this.dataFormat != null && (e.dataFormat = this.dataFormat);
var r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "Flatten", t;
}(Fe);
v.serialization.registerClass(yv);
var vv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.supportsMasking = true, r.activation = Nr(e.activation), r;
}
return t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
i.invokeCallHook(e, r);
var a = Oe(e);
return i.activation.apply(a);
});
}, t.prototype.getConfig = function() {
var e = {activation: Tr(this.activation)}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "Activation", t;
}(Fe);
v.serialization.registerClass(vv);
var wv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.n = e.n, r.inputSpec = [{ndim: 2}], r;
}
return t.prototype.computeOutputShape = function(e) {
return [e[0], this.n, e[1]];
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
return e = Oe(e), DO(e, i.n);
});
}, t.prototype.getConfig = function() {
var e = {n: this.n}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "RepeatVector", t;
}(Fe);
v.serialization.registerClass(wv);
var bv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
r.targetShape = e.targetShape;
for (var i = 0; i < r.targetShape.length; ++i)
r.isUnknown(r.targetShape[i]) && (r.targetShape[i] = null);
return r;
}
return t.prototype.isUnknown = function(e) {
return e < 0 || e == null;
}, t.prototype.fixUnknownDimension = function(e, r) {
for (var i = "Total size of new array must be unchanged.", a = r.slice(), s = 1, o = null, c = 0; c < a.length; ++c) {
var l = a[c];
if (this.isUnknown(l))
if (o === null)
o = c;
else
throw new M("Can only specifiy one unknown dimension.");
else
s *= l;
}
var u = Lr(e);
if (o !== null) {
if (s === 0 || u % s !== 0)
throw new M(i);
a[o] = u / s;
} else if (u !== s)
throw new M(i);
return a;
}, t.prototype.computeOutputShape = function(e) {
for (var r = false, i = 0; i < e.length; ++i)
if (this.isUnknown(e[i])) {
r = true;
break;
}
return r ? e.slice(0, 1).concat(this.targetShape) : e.slice(0, 1).concat(this.fixUnknownDimension(e.slice(1), this.targetShape));
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
i.invokeCallHook(e, r);
var a = Oe(e), s = a.shape, o = s.slice(0, 1).concat(i.fixUnknownDimension(s.slice(1), i.targetShape));
return a.reshape(o);
});
}, t.prototype.getConfig = function() {
var e = {targetShape: this.targetShape}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "Reshape", t;
}(Fe);
v.serialization.registerClass(bv);
var xv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
if (e.dims == null)
throw new Error("Required configuration field `dims` is missing during Permute constructor call.");
if (!Array.isArray(e.dims))
throw new Error("Permute constructor requires `dims` to be an Array, but received " + (e.dims + " instead."));
var i = bn(1, e.dims.length + 1);
if (!v.util.arraysEqual(e.dims.slice().sort(), i))
throw new Error("Invalid permutation `dims`: " + JSON.stringify(e.dims) + " `dims` must contain consecutive integers starting from 1.");
return r.dims = e.dims, r.dimsIncludingBatch = [0].concat(r.dims), r.inputSpec = [new Ct({ndim: r.dims.length + 1})], r;
}
return t.prototype.computeOutputShape = function(e) {
e = Xe(e);
var r = e.slice();
return this.dims.forEach(function(i, a) {
r[a + 1] = e[i];
}), r;
}, t.prototype.call = function(e, r) {
return v.transpose(Oe(e), this.dimsIncludingBatch);
}, t.prototype.getConfig = function() {
var e = {dims: this.dims}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "Permute", t;
}(Fe);
v.serialization.registerClass(xv);
var Lv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e != null ? e : {}) || this;
return r.supportsMasking = true, e != null ? r.maskValue = e.maskValue == null ? 0 : e.maskValue : r.maskValue = 0, r;
}
return t.prototype.computeOutputShape = function(e) {
return e;
}, t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this), r = {maskValue: this.maskValue};
return Object.assign(r, e), r;
}, t.prototype.computeMask = function(e, r) {
var i = Oe(e), a = -1;
return v.any(v.notEqual(i, this.maskValue), a);
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
i.invokeCallHook(e, r);
var a = Oe(e), s = -1, o = true, c = v.any(v.notEqual(a, i.maskValue), s, o), l = a.mul(c.asType(a.dtype));
return l;
});
}, t.className = "Masking", t;
}(Fe);
v.serialization.registerClass(Lv);
var Sv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
if (r.embeddings = null, r.DEFAULT_EMBEDDINGS_INITIALIZER = "randomUniform", e.batchInputShape == null && e.inputShape == null) {
var i = null;
e.batchSize != null && (i = e.batchSize), e.inputLength == null ? r.batchInputShape = [i, null] : r.batchInputShape = [i].concat(nt(e.inputLength));
}
return r.inputDim = e.inputDim, _t(r.inputDim, "inputDim"), r.outputDim = e.outputDim, _t(r.outputDim, "outputDim"), r.embeddingsInitializer = at(e.embeddingsInitializer || r.DEFAULT_EMBEDDINGS_INITIALIZER), r.embeddingsRegularizer = st(e.embeddingsRegularizer), r.activityRegularizer = st(e.activityRegularizer), r.embeddingsConstraint = It(e.embeddingsConstraint), r.maskZero = e.maskZero, r.supportsMasking = e.maskZero, r.inputLength = e.inputLength, r;
}
return t.prototype.build = function(e) {
this.embeddings = this.addWeight("embeddings", [this.inputDim, this.outputDim], this.dtype, this.embeddingsInitializer, this.embeddingsRegularizer, true, this.embeddingsConstraint), this.built = true;
}, t.prototype.warnOnIncompatibleInputShape = function(e) {
}, t.prototype.computeMask = function(e, r) {
var i = this;
return v.tidy(function() {
return i.maskZero ? (e = Oe(e), v.notEqual(e, v.zerosLike(e))) : null;
});
}, t.prototype.computeOutputShape = function(e) {
if (e = Xe(e), this.inputLength == null)
return e.concat([this.outputDim]);
var r = nt(this.inputLength);
if (r.length !== e.length - 1)
throw new M('"inputLength" is ' + this.inputLength + ", but received " + ("input shape has shape " + e));
for (var i = 0, a = 0; a < r.length; ++a) {
var s = r[a], o = e[a + 1];
if (s != null && o != null && s !== o)
throw new M('"inputLength" is ' + this.inputLength + ", but received " + ("input shape has shape " + e));
s == null && (r[i] = o), i++;
}
return [e[0]].concat(r, [this.outputDim]);
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
i.invokeCallHook(e, r);
var a = Oe(e);
a.dtype !== "int32" && (a = za(a, "int32"));
var s = Q0(i.embeddings.read(), a.as1D());
return s.reshape(Xe(i.computeOutputShape(a.shape)));
});
}, t.prototype.getConfig = function() {
var e = {inputDim: this.inputDim, outputDim: this.outputDim, embeddingsInitializer: lt(this.embeddingsInitializer), embeddingsRegularizer: Je(this.embeddingsRegularizer), activityRegularizer: Je(this.activityRegularizer), embeddingsConstraint: St(this.embeddingsConstraint), maskZero: this.maskZero, inputLength: this.inputLength}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "Embedding", t;
}(Fe);
v.serialization.registerClass(Sv);
var oi = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e || {}) || this;
return r.supportsMasking = true, r;
}
return t.prototype.mergeFunction = function(e) {
throw new Re();
}, t.prototype.computeElementwiseOpOutputShape = function(e, r) {
if (e == null || r == null)
return null;
if (e.length < r.length)
return this.computeElementwiseOpOutputShape(r, e);
if (r.length === 0)
return e;
for (var i = e.slice(0, e.length - r.length), a = 0; a < r.length; ++a) {
var s = e[e.length - r.length + a], o = r[a];
if (s == null || o == null || s < 0 || o < 0)
i.push(null);
else if (s === 1)
i.push(o);
else if (o === 1)
i.push(s);
else {
if (s !== o)
throw new M("Operands could not be broadcast together with shapes " + JSON.stringify(e) + " " + JSON.stringify(r));
i.push(s);
}
}
return i;
}, t.prototype.build = function(e) {
if (Array.isArray(e) && !Array.isArray(e[0]) && (e = [Xe(e)]), e = e, e.length < 2)
throw new M("A merge layer should be called on an Array of at least 2 inputs." + (" Got " + e.length + " input(s)."));
for (var r = [], i = 0, a = e; i < a.length; i++) {
var s = a[i];
s != null && s[0] !== null && r.push(s[0]);
}
if (r = xr(r), r.length > 1)
throw new M("Can not merge tensors with different batch sizes. " + ("Got tensors with shapes: " + JSON.stringify(e) + "."));
for (var o = e[0] == null ? null : e[0].slice(1), c = 1; c < e.length; ++c) {
var s = e[c] == null ? null : e[c].slice(1);
o = this.computeElementwiseOpOutputShape(o, s);
}
var l = e.map(function(u) {
return u.length;
});
e.indexOf(null) === -1 && xr(l).length === 1 ? this.reshapeRequired = false : this.reshapeRequired = true;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
if (e = e, i.reshapeRequired) {
var a = [], s = e.map(function(O) {
return O.rank;
});
if (s.indexOf(null) === -1) {
for (var o = Sr(s), c = 0, l = e; c < l.length; c++) {
for (var u = l[c], h = u.rank, d = 0; d < o - h; ++d)
u = Pa(u, 1);
a.push(u);
}
return i.mergeFunction(a);
} else {
for (var p = false, f = 0, m = e; f < m.length; f++) {
var u = m[f], h = u.rank;
if (h == null) {
var g = u.shape, y = g[0], w = g.slice(1).concat([y]), b = u.reshape([y].concat(Lr(g.slice(1))));
b = v.transpose(b, [1, 0]), b = b.reshape(w), a.push(b), p = true;
} else if (h > 1) {
var x = bn(1, h).concat([0]);
a.push(v.transpose(u, x)), p = true;
} else
a.push(u);
}
var L = i.mergeFunction(a), N = L.rank;
if (p) {
if (N == null) {
var I = L.shape, C = I.length, y = I[C - 1], w = [y].concat(I.slice(0, I.length - 1));
L = v.transpose(L.reshape([-1, y]), [1, 0]).reshape(w);
} else if (N > 1) {
var x = [N - 1].concat(bn(0, N - 1));
L = v.transpose(L, x);
}
}
return L;
}
} else
return i.mergeFunction(e);
});
}, t.prototype.computeOutputShape = function(e) {
e = e;
var r;
e[0] == null ? r = null : r = e[0].slice(1);
for (var i = 1; i < e.length; ++i) {
var a = e[i] == null ? null : e[i].slice(1);
r = this.computeElementwiseOpOutputShape(r, a);
}
for (var s = [], o = 0, c = e; o < c.length; o++) {
var a = c[o];
a != null && a[0] !== null && s.push(a[0]);
}
return s = xr(s), s.length === 1 ? r = s.concat(r) : r = [null].concat(r), r;
}, t.prototype.computeMask = function(e, r) {
return v.tidy(function() {
if (r == null)
return null;
if (!Array.isArray(r))
throw new M("`mask` should be an Array");
if (!Array.isArray(e))
throw new M("`inputs` should be an Array");
if (r.length !== e.length)
throw new M("The Array 'inputs' and 'mask' are expected to have the same length, but have different lengths " + ("(" + e.length + " vs " + r.length + ")"));
if (r.every(function(s) {
return s == null;
}))
return null;
r = r.map(function(s) {
return s == null ? s : v.expandDims(s, 0);
});
for (var i = r[0], a = 1; a < r.length - 1; ++a)
i = v.logicalAnd(i, r[a]);
return i;
});
}, t;
}(Fe), Iv = function(n) {
Q(t, n);
function t(e) {
return n.call(this, e) || this;
}
return t.prototype.mergeFunction = function(e) {
return v.tidy(function() {
for (var r = e[0].clone(), i = 1; i < e.length; ++i)
r = v.add(r, e[i]);
return r;
});
}, t.className = "Add", t;
}(oi);
v.serialization.registerClass(Iv);
var Av = function(n) {
Q(t, n);
function t(e) {
return n.call(this, e) || this;
}
return t.prototype.mergeFunction = function(e) {
return v.tidy(function() {
for (var r = e[0].clone(), i = 1; i < e.length; ++i)
r = v.mul(r, e[i]);
return r;
});
}, t.className = "Multiply", t;
}(oi);
v.serialization.registerClass(Av);
var Tv = function(n) {
Q(t, n);
function t(e) {
return n.call(this, e) || this;
}
return t.prototype.mergeFunction = function(e) {
return v.tidy(function() {
for (var r = e[0].clone(), i = 1; i < e.length; ++i)
r = v.add(r, e[i]);
return v.mul(1 / e.length, r);
});
}, t.className = "Average", t;
}(oi);
v.serialization.registerClass(Tv);
var Nv = function(n) {
Q(t, n);
function t(e) {
return n.call(this, e) || this;
}
return t.prototype.mergeFunction = function(e) {
return v.tidy(function() {
for (var r = e[0], i = 1; i < e.length; ++i)
r = v.maximum(r, e[i]);
return r;
});
}, t.className = "Maximum", t;
}(oi);
v.serialization.registerClass(Nv);
var _v = function(n) {
Q(t, n);
function t(e) {
return n.call(this, e) || this;
}
return t.prototype.mergeFunction = function(e) {
return v.tidy(function() {
for (var r = e[0], i = 1; i < e.length; ++i)
r = v.minimum(r, e[i]);
return r;
});
}, t.className = "Minimum", t;
}(oi);
v.serialization.registerClass(_v);
var Cv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.DEFAULT_AXIS = -1, e == null && (e = {}), r.axis = e.axis == null ? r.DEFAULT_AXIS : e.axis, r.supportsMasking = true, r.reshapeRequired = false, r;
}
return t.prototype.build = function(e) {
if (!(Array.isArray(e) && Array.isArray(e[0])) || e.length === 1)
throw new M("A `Concatenate` layer should be called on a list of at least 2 inputs");
e = e;
for (var r = true, i = 0, a = e; i < a.length; i++) {
var s = a[i];
if (s != null) {
r = false;
break;
}
}
if (r)
return;
for (var o = [], c = 0; c < e.length; ++c) {
var l = e[c].slice();
l.splice(this.axis, 1);
for (var u = false, h = 0, d = o; h < d.length; h++) {
var s = d[h];
if (v.util.arraysEqual(s, l)) {
u = true;
break;
}
}
u || o.push(l);
}
if (o.length > 1)
throw new M("A `Concatenate` layer requires inputs with matching shapes except for the concat axis. Got input shapes: " + JSON.stringify(e));
}, t.prototype.mergeFunction = function(e) {
var r = this;
return v.tidy(function() {
return Ih(e, r.axis);
});
}, t.prototype.computeOutputShape = function(e) {
if (!(Array.isArray(e) && Array.isArray(e[0])))
throw new M("A `Concatenate` layer should be called on a list of inputs.");
for (var r = e, i = r[0].slice(), a = this.axis < 0 ? i.length + this.axis : this.axis, s = 0, o = r.slice(1); s < o.length; s++) {
var c = o[s];
if (i[a] == null || c[a] == null) {
i[a] = null;
break;
}
i[a] += c[a];
}
return i;
}, t.prototype.computeMask = function(e, r) {
var i = this;
if (r == null)
return null;
if (!Array.isArray(r))
throw new M("`mask` should be an array for Concatenate");
if (!Array.isArray(e))
throw new M("`inputs` should be an array for Concatenate");
if (r.length !== e.length)
throw new M("Mismatch in the length of mask (" + r.length + ") " + ("and the legnth of inputs (" + e.length + ")"));
return v.tidy(function() {
var a = true;
if (r.forEach(function(l) {
if (l != null) {
a = false;
return;
}
}), a)
return null;
for (var s = [], o = 0; o < e.length; ++o)
r[o] == null ? s.push(v.onesLike(e[o]).asType("bool")) : r[o].rank < e[o].rank ? s.push(v.expandDims(r[o], -1)) : s.push(r[o]);
var c = v.concat(s, i.axis);
return v.all(c, -1, false);
});
}, t.prototype.getConfig = function() {
var e = {axis: this.axis}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "Concatenate", t;
}(oi);
v.serialization.registerClass(Cv);
function ja(n, t) {
for (; n < 0; )
n += t;
return n;
}
function D7(n, t, e) {
if (n.shape.length > 3 || t.shape.length > 3)
throw new Re("batchDot is not implemented for tensors of 4D or higher rank yet");
if (v.util.assert(n.shape.length >= 2, function() {
return "batchDot requires the rank of x to be >= 2, " + ("but got " + n.shape.length);
}), v.util.assert(n.shape.length >= 2, function() {
return "batchDot requires the rank of y to be >= 2, " + ("but got " + t.shape.length);
}), typeof e == "number" && (e = [e, e]), n.dtype === "complex64" || t.dtype === "complex64")
throw new Re("batchDot is not implemented for complex64-type Tensors yet.");
var r = n.shape.length, i = t.shape.length;
e == null && (e = [r - 1, i - 2]);
var a = e;
return v.tidy(function() {
var s;
if (r > i) {
s = r - i;
for (var o = [], c = 0; c < s; ++c)
o.push(1);
t = t.reshape(t.shape.concat(o));
} else if (i > r) {
s = i - r;
for (var o = [], c = 0; c < s; ++c)
o.push(1);
n = n.reshape(n.shape.concat(o));
} else
s = 0;
var l;
if (n.shape.length === 2 && t.shape.length === 2)
a[0] === a[1] ? l = n.mul(t).sum(a[0]) : l = n.transpose([1, 0]).mul(t).sum(a[1]);
else {
var u = a[0] !== n.shape.length - 1, h = a[1] === t.shape.length - 1;
l = n.matMul(t, u, h);
}
if (s > 0) {
var d = void 0;
r > i ? d = r + i - 3 : d = r - 1;
for (var p = [], c = d; c < d + s; ++c)
p.push(c);
l = l.squeeze(p);
}
return l.shape.length === 1 && (l = l.expandDims(1)), l;
});
}
var Rv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.axes = e.axes, r.normalize = e.normalize == null ? false : e.normalize, r.supportsMasking = true, r.reshapeRequired = false, r;
}
return t.prototype.build = function(e) {
v.util.assert(Array.isArray(e) && e.length === 2 && Array.isArray(e[0]) && Array.isArray(e[1]), function() {
return "A `Dot` layer should be called on a list of exactly 2 inputs.";
});
var r = e[0], i = e[1];
if (r.length > 3 || i.length > 3)
throw new Re("Dot layer does not support tensors of 4D or higher rank yet.");
var a = this.interpretAxes(r, i);
if (r[a[0]] !== i[a[1]])
throw new M("Dimension incompatibility: " + (r[a[0]] + " !== " + i[a[1]]));
}, t.prototype.mergeFunction = function(e) {
if (e.length !== 2)
throw new M("A `Dot` layer must be called on exactly 2 inputs, " + ("but received " + e.length + " input(s)."));
var r = e[0], i = e[1], a;
return Array.isArray(this.axes) ? a = this.axes.map(function(s, o) {
return ja(s, e[o].shape.length);
}) : a = [ja(this.axes, r.shape.length), ja(this.axes, i.shape.length)], this.normalize && (r = yo(r, a[0]), i = yo(i, a[1])), D7(r, i, a);
}, t.prototype.interpretAxes = function(e, r) {
var i;
return Array.isArray(this.axes) ? i = this.axes : i = [ja(this.axes, e.length), ja(this.axes, r.length)], i;
}, t.prototype.computeOutputShape = function(e) {
v.util.assert(Array.isArray(e) && e.length === 2 && Array.isArray(e[0]) && Array.isArray(e[1]), function() {
return "A `Dot` layer should be called on a list of exactly 2 inputs.";
});
var r = e[0].slice(), i = e[1].slice();
if (r.length > 3 || i.length > 3)
throw new Re("Dot layer does not support tensors of 4D or higher rank yet.");
var a = this.interpretAxes(r, i);
r.splice(a[0], 1), i.splice(a[1], 1), i.splice(0, 1);
var s = r.concat(i);
return s.length === 1 && s.push(1), s;
}, t.prototype.computeMask = function(e, r) {
return null;
}, t.prototype.getConfig = function() {
var e = {axes: this.axes, normalize: this.normalize}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "Dot", t;
}(oi);
v.serialization.registerClass(Rv);
var Ov = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.supportsMasking = true, r.stddev = e.stddev, r;
}
return t.prototype.computeOutputShape = function(e) {
return e;
}, t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this), r = {stddev: this.stddev};
return Object.assign(r, e), r;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
i.invokeCallHook(e, r);
var a = Oe(e), s = function() {
return uo(a.shape, 0, i.stddev).add(a);
}, o = Ha(s, function() {
return a;
}, r.training || false);
return o;
});
}, t.className = "GaussianNoise", t;
}(Fe);
v.serialization.registerClass(Ov);
var Ev = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.supportsMasking = true, r.rate = e.rate, r;
}
return t.prototype.computeOutputShape = function(e) {
return e;
}, t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this), r = {rate: this.rate};
return Object.assign(r, e), r;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
i.invokeCallHook(e, r);
var a = Oe(e);
if (i.rate > 0 && i.rate < 1) {
var s = function() {
var o = Math.sqrt(i.rate / (1 - i.rate));
return a.mul(uo(a.shape, 1, o));
};
return Ha(s, function() {
return a;
}, r.training || false);
}
return a;
});
}, t.className = "GaussianDropout", t;
}(Fe);
v.serialization.registerClass(Ev);
var Dv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.supportsMasking = true, r.rate = e.rate, r.noiseShape = e.noiseShape, r;
}
return t.prototype._getNoiseShape = function(e) {
return this.noiseShape || Oe(e).shape;
}, t.prototype.computeOutputShape = function(e) {
return e;
}, t.prototype.getConfig = function() {
var e = n.prototype.getConfig.call(this), r = {rate: this.rate};
return Object.assign(r, e), r;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
if (i.rate < 1 && i.rate > 0) {
var a = i._getNoiseShape(e), s = function() {
var o = Oe(e), c = 1.6732632423543772, l = 1.0507009873554805, u = -c * l, h = v.greaterEqual(v.randomUniform(a), i.rate);
h = za(h, "float32");
var d = Math.pow((1 - i.rate) * (1 + i.rate * Math.pow(u, 2)), -0.5), p = -d * u * i.rate, f = o.mul(h).add(h.add(-1).mul(u));
return f.mul(d).add(p);
};
return Ha(s, function() {
return Oe(e);
}, r.training || false);
}
return e;
});
}, t.className = "AlphaDropout", t;
}(Fe);
v.serialization.registerClass(Dv);
function $a(n, t, e, r, i, a) {
a === void 0 && (a = 1e-3);
var s;
if (n.rank === 2)
s = v.batchNorm2d(n, t, e, r, i, a);
else if (n.rank === 3)
s = v.batchNorm3d(n, t, e, r, i, a);
else if (n.rank === 4)
s = v.batchNorm4d(n, t, e, r, i, a);
else
throw new Re("batchNormalization is not implemented for array of rank " + n.rank + " yet");
return s;
}
function k7(n, t, e, r, i) {
return i === void 0 && (i = 1e-3), v.tidy(function() {
var a = v.moments(n, r), s = a.mean, o = a.variance, c = $a(n, s, o, e, t, i);
return [c, s, o];
});
}
function F7(n, t, e, r, i) {
return i === void 0 && (i = 1e-3), v.tidy(function() {
for (var a = v.moments(n, r), s = a.mean, o = a.variance, c = [], l = 0, u = bn(0, n.rank); l < u.length; l++) {
var h = u[l];
r.indexOf(h) !== -1 ? c.push(1) : c.push(n.shape[h]);
}
var d = s.reshape(c), p = o.reshape(c), f = t == null ? null : t.reshape(c), m = e == null ? null : e.reshape(c), g = $a(n, d, p, m, f, i);
return [g, s, o];
});
}
function W7(n, t, e, r, i) {
return i === void 0 && (i = 1e-3), v.util.arraysEqual(r.slice().sort(), bn(0, n.rank - 1)) ? k7(n, t, e, r, i) : F7(n, t, e, r, i);
}
var kv = function(n) {
Q(t, n);
function t(e) {
var r = this;
return e == null && (e = {}), r = n.call(this, e) || this, r.supportsMasking = true, r.axis = e.axis == null ? -1 : e.axis, r.momentum = e.momentum == null ? 0.99 : e.momentum, r.epsilon = e.epsilon == null ? 1e-3 : e.epsilon, r.center = e.center == null ? true : e.center, r.scale = e.scale == null ? true : e.scale, r.betaInitializer = at(e.betaInitializer || "zeros"), r.gammaInitializer = at(e.gammaInitializer || "ones"), r.movingMeanInitializer = at(e.movingMeanInitializer || "zeros"), r.movingVarianceInitializer = at(e.movingVarianceInitializer || "ones"), r.betaConstraint = It(e.betaConstraint), r.gammaConstraint = It(e.gammaConstraint), r.betaRegularizer = st(e.betaRegularizer), r.gammaRegularizer = st(e.gammaRegularizer), r;
}
return t.prototype.build = function(e) {
var r;
e = Xe(e);
var i = this.axis >= 0 ? this.axis : this.axis + e.length, a = e[i];
if (a == null)
throw new M("Axis " + i + " of input tensor should have a defined dimension but the layer received an input with shape " + (JSON.stringify(e) + "."));
this.inputSpec = [new Ct({ndim: e.length, axes: (r = {}, r[i] = a, r)})];
var s = [a];
this.scale && (this.gamma = this.addWeight("gamma", s, null, this.gammaInitializer, this.gammaRegularizer, true, this.gammaConstraint)), this.center && (this.beta = this.addWeight("beta", s, null, this.betaInitializer, this.betaRegularizer, true, this.betaConstraint)), this.movingMean = this.addWeight("moving_mean", s, null, this.movingMeanInitializer, null, false), this.movingVariance = this.addWeight("moving_variance", s, null, this.movingVarianceInitializer, null, false), this.built = true;
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
var a = r.training == null ? false : r.training, s = Oe(e), o = s.shape, c = o.length, l = bn(0, c), u = i.axis >= 0 ? i.axis : i.axis + c;
l.splice(u, 1);
var h = ti(1, c);
h[u] = o[u];
var d = l.slice();
d.sort();
var p = !v.util.arraysEqual(d, bn(0, c).slice(0, c - 1)), f = function() {
if (p) {
var L = i.movingMean.read().reshape(h), N = i.movingVariance.read().reshape(h), I = i.center ? i.beta.read().reshape(h) : null, C = i.scale ? i.gamma.read().reshape(h) : null;
return $a(s, L, N, I, C, i.epsilon);
} else
return $a(s, i.movingMean.read(), i.movingVariance.read(), i.beta == null ? null : i.beta.read(), i.gamma == null ? null : i.gamma.read(), i.epsilon);
};
if (!a)
return f();
var m = W7(s, i.gamma.read(), i.beta.read(), l, i.epsilon), g = m[0], y = m[1], w = m[2], b = function(L, N, I) {
v.tidy(function() {
var C = 1 - I, O = L.read(), D = O.sub(N).mul(C);
L.write(O.sub(D));
});
}, x = function() {
b(i.movingMean, y, i.momentum), b(i.movingVariance, w, i.momentum);
};
return x(), g;
});
}, t.prototype.getConfig = function() {
var e = {axis: this.axis, momentum: this.momentum, epsilon: this.epsilon, center: this.center, scale: this.scale, betaInitializer: lt(this.betaInitializer), gammaInitializer: lt(this.gammaInitializer), movingMeanInitializer: lt(this.movingMeanInitializer), movingVarianceInitializer: lt(this.movingVarianceInitializer), betaRegularizer: Je(this.betaRegularizer), gammaRegularizer: Je(this.gammaRegularizer), betaConstraint: St(this.betaConstraint), gammaConstraint: St(this.gammaConstraint)}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "BatchNormalization", t;
}(Fe);
v.serialization.registerClass(kv);
var Fv = function(n) {
Q(t, n);
function t(e) {
var r = this;
if (e == null && (e = {}), r = n.call(this, e) || this, r.axis = e.axis == null ? -1 : e.axis, typeof r.axis == "number") {
if (!Number.isInteger(r.axis))
throw new Error("Expected axis to be an integer, but received " + r.axis);
} else if (Array.isArray(r.axis))
for (var i = 0, a = r.axis; i < a.length; i++) {
var s = a[i];
if (!Number.isInteger(s))
throw new Error("Expected axis to be an array of integers, " + ("but received " + JSON.stringify(r.axis)));
}
else
throw new Error("Expected axis to be an integer or an array of integers, " + ("but received " + JSON.stringify(r.axis)));
return r.epsilon = e.epsilon == null ? 1e-3 : e.epsilon, r.center = e.center == null ? true : e.center, r.scale = e.scale == null ? true : e.scale, r.betaInitializer = at(e.betaInitializer || "zeros"), r.gammaInitializer = at(e.gammaInitializer || "ones"), r.betaRegularizer = st(e.betaRegularizer), r.gammaRegularizer = st(e.gammaRegularizer), r.supportsMasking = true, r;
}
return t.prototype.build = function(e) {
e = Xe(e);
var r = e.length;
typeof this.axis == "number" && (this.axis = [this.axis]);
for (var i = 0; i < this.axis.length; ++i)
this.axis[i] < 0 && (this.axis[i] += r);
for (var a = 0, s = this.axis; a < s.length; a++) {
var o = s[a];
if (o < 0 || o >= r)
throw new Error("Invalid axis: " + o);
}
if (this.axis.length !== xr(this.axis).length)
throw new Error("Found duplicate axes in: " + this.axis);
var c = this.axis.map(function(u) {
return e[u];
}), l = true;
this.scale ? this.gamma = this.addWeight("gamma", c, "float32", this.gammaInitializer, this.gammaRegularizer, l) : this.gamma = null, this.center ? this.beta = this.addWeight("beta", c, "float32", this.betaInitializer, this.betaRegularizer, l) : this.beta = null, this.built = true;
}, t.prototype.call = function(e, r) {
var i = this, a = Oe(e), s = a.shape, o = s.length;
return v.tidy(function() {
for (var c = true, l = v.moments(a, i.axis, c), u = l.mean, h = l.variance, d = ti(1, o), p = 0, f = i.axis; p < f.length; p++) {
var m = f[p];
d[m] = s[m];
}
for (var g = function(N) {
return N != null && N.shape.length !== o && i.axis !== [o - 1] ? N.reshape(d) : N;
}, y = g(i.gamma.read()), w = g(i.beta.read()), b = [], x = [], L = 0; L < o; ++L)
i.axis.indexOf(L) !== -1 ? (b.push(s[L]), x.push(1)) : (b.push(1), x.push(s[L]));
return u = u.tile(b), h = h.tile(b), y = y.tile(x), w = w.tile(x), $a(a, u, h, w, y, i.epsilon);
});
}, t.prototype.getConfig = function() {
var e = {axis: this.axis, epsilon: this.epsilon, center: this.center, scale: this.scale, betaInitializer: lt(this.betaInitializer), gammaInitializer: lt(this.gammaInitializer), betaRegularizer: Je(this.betaRegularizer), gammaRegularizer: Je(this.gammaRegularizer)}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "LayerNormalization", t;
}(Fe);
v.serialization.registerClass(Fv);
function U7(n, t, e) {
return v.tidy(function() {
if (n.rank !== 4)
throw new M("temporalPadding expects input tensor to be 4-D, but received a " + (n.rank + "-D tensor."));
if (t == null && (t = [[1, 1], [1, 1]]), t.length !== 2 || t[0].length !== 2 || t[1].length !== 2)
throw new M("spatial2dPadding expects `padding` to be an Array of two Arrays, each of which is an Array of two integers.");
if (e == null && (e = wn()), e !== "channelsLast" && e !== "channelsFirst")
throw new M("Unknown data format: " + e + ". Supported data formats are 'channelsLast' and 'channelsFirst.");
var r;
return e === "channelsFirst" ? r = [[0, 0], [0, 0], t[0], t[1]] : r = [[0, 0], t[0], t[1], [0, 0]], v.pad(n, r);
});
}
var Wv = function(n) {
Q(t, n);
function t(e) {
var r = this;
if (e == null && (e = {}), r = n.call(this, e) || this, r.dataFormat = e.dataFormat == null ? wn() : e.dataFormat, e.padding == null)
r.padding = [[1, 1], [1, 1]];
else if (typeof e.padding == "number")
r.padding = [[e.padding, e.padding], [e.padding, e.padding]];
else {
if (e.padding = e.padding, e.padding.length !== 2)
throw new M("ZeroPadding2D expects padding to be a length-2 array, but " + ("received a length-" + e.padding.length + " array."));
var i = void 0, a = void 0;
if (typeof e.padding[0] == "number")
i = [e.padding[0], e.padding[0]], a = [e.padding[1], e.padding[1]];
else {
if (e.padding = e.padding, e.padding[0].length !== 2)
throw new M("ZeroPadding2D expects height padding to be a length-2 array, " + ("but received a length-" + e.padding[0].length + " array."));
if (i = e.padding[0], e.padding[1].length !== 2)
throw new M("ZeroPadding2D expects width padding to be a length-2 array, " + ("but received a length-" + e.padding[1].length + " array."));
a = e.padding[1];
}
r.padding = [i, a];
}
return r.inputSpec = [new Ct({ndim: 4})], r;
}
return t.prototype.computeOutputShape = function(e) {
e = Xe(e);
var r, i;
return this.dataFormat === "channelsFirst" ? (e[2] != null && e[2] >= 0 ? r = e[2] + this.padding[0][0] + this.padding[0][1] : r = null, e[3] != null && e[3] >= 0 ? i = e[3] + this.padding[1][0] + this.padding[1][1] : i = null, [e[0], e[1], r, i]) : (e[1] != null && e[1] >= 0 ? r = e[1] + this.padding[0][0] + this.padding[0][1] : r = null, e[2] != null && e[2] >= 0 ? i = e[2] + this.padding[1][0] + this.padding[1][1] : i = null, [e[0], r, i, e[3]]);
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
return U7(Oe(e), i.padding, i.dataFormat);
});
}, t.prototype.getConfig = function() {
var e = {padding: this.padding, dataFormat: this.dataFormat}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.className = "ZeroPadding2D", t;
}(Fe);
v.serialization.registerClass(Wv);
function Co(n, t, e, r, i, a) {
return v.tidy(function() {
mt(i), Y0(a), sn(r), e == null && (e = [1, 1]), r == null && (r = "valid"), i == null && (i = wn()), a == null && (a = "max"), n = Zh(n, i);
var s, o = r === "same" ? "same" : "valid";
return a === "max" ? s = v.maxPool(n, t, e, o) : s = v.avgPool(n, t, e, o), i === "channelsFirst" && (s = v.transpose(s, [0, 3, 1, 2])), s;
});
}
function Uv(n, t, e, r, i, a) {
return v.tidy(function() {
mt(i), Y0(a), sn(r), e == null && (e = [1, 1, 1]), r == null && (r = "valid"), i == null && (i = wn()), a == null && (a = "max"), n = Qy(n, i);
var s, o = r === "same" ? "same" : "valid";
return a === "max" ? s = v.maxPool3d(n, t, e, o) : s = v.avgPool3d(n, t, e, o), i === "channelsFirst" && (s = v.transpose(s, [0, 4, 1, 2, 3])), s;
});
}
var Bv = function(n) {
Q(t, n);
function t(e) {
var r = this;
if (e.poolSize == null && (e.poolSize = 2), r = n.call(this, e) || this, typeof e.poolSize == "number")
r.poolSize = [e.poolSize];
else if (Array.isArray(e.poolSize) && e.poolSize.length === 1 && typeof e.poolSize[0] == "number")
r.poolSize = e.poolSize;
else
throw new M("poolSize for 1D convolutional layer must be a number or an Array of a single number, but received " + ("" + JSON.stringify(e.poolSize)));
if (_t(r.poolSize, "poolSize"), e.strides == null)
r.strides = r.poolSize;
else if (typeof e.strides == "number")
r.strides = [e.strides];
else if (Array.isArray(e.strides) && e.strides.length === 1 && typeof e.strides[0] == "number")
r.strides = e.strides;
else
throw new M("strides for 1D convolutional layer must be a number or an Array of a single number, but received " + ("" + JSON.stringify(e.strides)));
return _t(r.strides, "strides"), r.padding = e.padding == null ? "valid" : e.padding, sn(r.padding), r.inputSpec = [new Ct({ndim: 3})], r;
}
return t.prototype.computeOutputShape = function(e) {
e = Xe(e);
var r = Sn(e[1], this.poolSize[0], this.padding, this.strides[0]);
return [e[0], r, e[2]];
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
i.invokeCallHook(e, r), e = Pa(Oe(e), 2);
var a = i.poolingFunction(Oe(e), [i.poolSize[0], 1], [i.strides[0], 1], i.padding, "channelsLast");
return v.squeeze(a, [2]);
});
}, t.prototype.getConfig = function() {
var e = {poolSize: this.poolSize, padding: this.padding, strides: this.strides}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t;
}(Fe), zv = function(n) {
Q(t, n);
function t(e) {
return n.call(this, e) || this;
}
return t.prototype.poolingFunction = function(e, r, i, a, s) {
return mt(s), sn(a), Co(e, r, i, a, s, "max");
}, t.className = "MaxPooling1D", t;
}(Bv);
v.serialization.registerClass(zv);
var Pv = function(n) {
Q(t, n);
function t(e) {
return n.call(this, e) || this;
}
return t.prototype.poolingFunction = function(e, r, i, a, s) {
return mt(s), sn(a), Co(e, r, i, a, s, "avg");
}, t.className = "AveragePooling1D", t;
}(Bv);
v.serialization.registerClass(Pv);
var Mv = function(n) {
Q(t, n);
function t(e) {
var r = this;
if (e.poolSize == null && (e.poolSize = [2, 2]), r = n.call(this, e) || this, r.poolSize = Array.isArray(e.poolSize) ? e.poolSize : [e.poolSize, e.poolSize], e.strides == null)
r.strides = r.poolSize;
else if (Array.isArray(e.strides)) {
if (e.strides.length !== 2)
throw new M("If the strides property of a 2D pooling layer is an Array, it is expected to have a length of 2, but received length " + (e.strides.length + "."));
r.strides = e.strides;
} else
r.strides = [e.strides, e.strides];
return _t(r.poolSize, "poolSize"), _t(r.strides, "strides"), r.padding = e.padding == null ? "valid" : e.padding, r.dataFormat = e.dataFormat == null ? "channelsLast" : e.dataFormat, mt(r.dataFormat), sn(r.padding), r.inputSpec = [new Ct({ndim: 4})], r;
}
return t.prototype.computeOutputShape = function(e) {
e = Xe(e);
var r = this.dataFormat === "channelsFirst" ? e[2] : e[1], i = this.dataFormat === "channelsFirst" ? e[3] : e[2];
return r = Sn(r, this.poolSize[0], this.padding, this.strides[0]), i = Sn(i, this.poolSize[1], this.padding, this.strides[1]), this.dataFormat === "channelsFirst" ? [e[0], e[1], r, i] : [e[0], r, i, e[3]];
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
return i.invokeCallHook(e, r), i.poolingFunction(Oe(e), i.poolSize, i.strides, i.padding, i.dataFormat);
});
}, t.prototype.getConfig = function() {
var e = {poolSize: this.poolSize, padding: this.padding, strides: this.strides, dataFormat: this.dataFormat}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t;
}(Fe), Hv = function(n) {
Q(t, n);
function t(e) {
return n.call(this, e) || this;
}
return t.prototype.poolingFunction = function(e, r, i, a, s) {
return mt(s), sn(a), Co(e, r, i, a, s, "max");
}, t.className = "MaxPooling2D", t;
}(Mv);
v.serialization.registerClass(Hv);
var Vv = function(n) {
Q(t, n);
function t(e) {
return n.call(this, e) || this;
}
return t.prototype.poolingFunction = function(e, r, i, a, s) {
return mt(s), sn(a), Co(e, r, i, a, s, "avg");
}, t.className = "AveragePooling2D", t;
}(Mv);
v.serialization.registerClass(Vv);
var Gv = function(n) {
Q(t, n);
function t(e) {
var r = this;
if (e.poolSize == null && (e.poolSize = [2, 2, 2]), r = n.call(this, e) || this, r.poolSize = Array.isArray(e.poolSize) ? e.poolSize : [e.poolSize, e.poolSize, e.poolSize], e.strides == null)
r.strides = r.poolSize;
else if (Array.isArray(e.strides)) {
if (e.strides.length !== 3)
throw new M("If the strides property of a 3D pooling layer is an Array, it is expected to have a length of 3, but received length " + (e.strides.length + "."));
r.strides = e.strides;
} else
r.strides = [e.strides, e.strides, e.strides];
return _t(r.poolSize, "poolSize"), _t(r.strides, "strides"), r.padding = e.padding == null ? "valid" : e.padding, r.dataFormat = e.dataFormat == null ? "channelsLast" : e.dataFormat, mt(r.dataFormat), sn(r.padding), r.inputSpec = [new Ct({ndim: 5})], r;
}
return t.prototype.computeOutputShape = function(e) {
e = Xe(e);
var r = this.dataFormat === "channelsFirst" ? e[2] : e[1], i = this.dataFormat === "channelsFirst" ? e[3] : e[2], a = this.dataFormat === "channelsFirst" ? e[4] : e[3];
return r = Sn(r, this.poolSize[0], this.padding, this.strides[0]), i = Sn(i, this.poolSize[1], this.padding, this.strides[1]), a = Sn(a, this.poolSize[2], this.padding, this.strides[2]), this.dataFormat === "channelsFirst" ? [e[0], e[1], r, i, a] : [e[0], r, i, a, e[4]];
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
return i.invokeCallHook(e, r), i.poolingFunction(Oe(e), i.poolSize, i.strides, i.padding, i.dataFormat);
});
}, t.prototype.getConfig = function() {
var e = {poolSize: this.poolSize, padding: this.padding, strides: this.strides, dataFormat: this.dataFormat}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t;
}(Fe), qv = function(n) {
Q(t, n);
function t(e) {
return n.call(this, e) || this;
}
return t.prototype.poolingFunction = function(e, r, i, a, s) {
return mt(s), sn(a), Uv(e, r, i, a, s, "max");
}, t.className = "MaxPooling3D", t;
}(Gv);
v.serialization.registerClass(qv);
var Yv = function(n) {
Q(t, n);
function t(e) {
return n.call(this, e) || this;
}
return t.prototype.poolingFunction = function(e, r, i, a, s) {
return mt(s), sn(a), Uv(e, r, i, a, s, "avg");
}, t.className = "AveragePooling3D", t;
}(Gv);
v.serialization.registerClass(Yv);
var Kv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.inputSpec = [new Ct({ndim: 3})], r;
}
return t.prototype.computeOutputShape = function(e) {
return [e[0], e[2]];
}, t.prototype.call = function(e, r) {
throw new Re();
}, t;
}(Fe), jv = function(n) {
Q(t, n);
function t(e) {
return n.call(this, e || {}) || this;
}
return t.prototype.call = function(e, r) {
return v.tidy(function() {
var i = Oe(e);
return v.mean(i, 1);
});
}, t.className = "GlobalAveragePooling1D", t;
}(Kv);
v.serialization.registerClass(jv);
var $v = function(n) {
Q(t, n);
function t(e) {
return n.call(this, e || {}) || this;
}
return t.prototype.call = function(e, r) {
return v.tidy(function() {
var i = Oe(e);
return v.max(i, 1);
});
}, t.className = "GlobalMaxPooling1D", t;
}(Kv);
v.serialization.registerClass($v);
var Xv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.dataFormat = e.dataFormat == null ? "channelsLast" : e.dataFormat, mt(r.dataFormat), r.inputSpec = [new Ct({ndim: 4})], r;
}
return t.prototype.computeOutputShape = function(e) {
return e = e, this.dataFormat === "channelsLast" ? [e[0], e[3]] : [e[0], e[1]];
}, t.prototype.call = function(e, r) {
throw new Re();
}, t.prototype.getConfig = function() {
var e = {dataFormat: this.dataFormat}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t;
}(Fe), Jv = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
var a = Oe(e);
return i.dataFormat === "channelsLast" ? v.mean(a, [1, 2]) : v.mean(a, [2, 3]);
});
}, t.className = "GlobalAveragePooling2D", t;
}(Xv);
v.serialization.registerClass(Jv);
var Zv = function(n) {
Q(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
var a = Oe(e);
return i.dataFormat === "channelsLast" ? v.max(a, [1, 2]) : v.max(a, [2, 3]);
});
}, t.className = "GlobalMaxPooling2D", t;
}(Xv);
v.serialization.registerClass(Zv);
var Qv = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.layer = e.layer, r;
}
return t.prototype.build = function(e) {
this.built = true;
}, Object.defineProperty(t.prototype, "trainable", {get: function() {
return this.layer != null ? this.layer.trainable : false;
}, set: function(e) {
this.layer != null && (this.layer.trainable = e);
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "trainableWeights", {get: function() {
return this.layer.trainableWeights;
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "nonTrainableWeights", {get: function() {
return this.layer.nonTrainableWeights;
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "updates", {get: function() {
return this.layer._updates;
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "losses", {get: function() {
return this.layer.losses;
}, enumerable: true, configurable: true}), t.prototype.getWeights = function() {
return this.layer.getWeights();
}, t.prototype.setWeights = function(e) {
this.layer.setWeights(e);
}, t.prototype.getConfig = function() {
var e = {layer: {className: this.layer.getClassName(), config: this.layer.getConfig()}}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.prototype.setFastWeightInitDuringBuild = function(e) {
n.prototype.setFastWeightInitDuringBuild.call(this, e), this.layer != null && this.layer.setFastWeightInitDuringBuild(e);
}, t.fromConfig = function(e, r, i) {
i === void 0 && (i = {});
var a = r.layer, s = Ln(a, i);
delete r.layer;
var o = {layer: s};
return Object.assign(o, r), new e(o);
}, t;
}(Fe), e1 = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this;
return r.supportsMasking = true, r;
}
return t.prototype.build = function(e) {
if (e = Xe(e), e.length < 3)
throw new M("TimeDistributed layer expects an input shape >= 3D, but received " + ("input shape " + JSON.stringify(e)));
this.inputSpec = [{shape: e}];
var r = [e[0]].concat(e.slice(2));
this.layer.built || (this.layer.build(r), this.layer.built = true), n.prototype.build.call(this, e);
}, t.prototype.computeOutputShape = function(e) {
e = Xe(e);
var r = [e[0]].concat(e.slice(2)), i = this.layer.computeOutputShape(r), a = e[1];
return [i[0], a].concat(i.slice(1));
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
e = Oe(e);
var a = function(c, l) {
var u = Oe(i.layer.call(c, r));
return [u, []];
}, s = uv(a, e, [], false, null, null, false, true), o = s[1];
return o;
});
}, t.className = "TimeDistributed", t;
}(Qv);
v.serialization.registerClass(e1);
function B7(n) {
Hi(CO, "BidirectionalMergeMode", n);
}
var z7 = "concat", t1 = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this, e) || this, i = e.layer.getConfig(), a = {};
a.className = e.layer.getClassName(), a.config = i, r.forwardLayer = Ln(a), i.goBackwards = !(i.goBackwards === true);
var s = {};
if (s.className = e.layer.getClassName(), s.config = i, r.backwardLayer = Ln(s), r.forwardLayer.name = "forward_" + r.forwardLayer.name, r.backwardLayer.name = "backward_" + r.backwardLayer.name, r.mergeMode = e.mergeMode === void 0 ? z7 : e.mergeMode, B7(r.mergeMode), e.weights)
throw new Re("weights support is not implemented for Bidirectional layer yet.");
return r._stateful = e.layer.stateful, r.returnSequences = e.layer.returnSequences, r.returnState = e.layer.returnState, r.supportsMasking = true, r._trainable = true, r.inputSpec = e.layer.inputSpec, r.numConstants = null, r;
}
return Object.defineProperty(t.prototype, "trainable", {get: function() {
return this._trainable;
}, set: function(e) {
this._trainable = e, this.forwardLayer != null && (this.forwardLayer.trainable = e), this.backwardLayer != null && (this.backwardLayer.trainable = e);
}, enumerable: true, configurable: true}), t.prototype.getWeights = function() {
return this.forwardLayer.getWeights().concat(this.backwardLayer.getWeights());
}, t.prototype.setWeights = function(e) {
var r = e.length, i = Math.floor(r / 2);
this.forwardLayer.setWeights(e.slice(0, i)), this.backwardLayer.setWeights(e.slice(i));
}, t.prototype.computeOutputShape = function(e) {
var r = this.forwardLayer.computeOutputShape(e);
Array.isArray(r) && Array.isArray(r[0]) || (r = [r]), r = r;
var i, a, s;
return this.returnState && (s = r.slice(1)), i = r[0], i = i, this.mergeMode === "concat" ? (i[i.length - 1] *= 2, a = [i]) : this.mergeMode == null ? a = [i, i.slice()] : a = [i], this.returnState ? this.mergeMode == null ? a.concat(s).concat(s.slice()) : [i].concat(s).concat(s.slice()) : Vt(a);
}, t.prototype.apply = function(e, r) {
var i = r == null ? null : r.initialState, a = r == null ? null : r.constants;
r == null && (r = {});
var s = lv(e, i, a, this.numConstants);
if (e = s.inputs, i = s.initialState, a = s.constants, Array.isArray(e) && (i = e.slice(1), e = e[0]), (i == null || i.length === 0) && a == null)
return n.prototype.apply.call(this, e, r);
var o = [], c = [];
if (i != null) {
var l = i.length;
if (l % 2 > 0)
throw new M("When passing `initialState` to a Bidrectional RNN, the state should be an Array containing the states of the underlying RNNs.");
r.initialState = i, o.push.apply(o, i);
var u = i.map(function(b) {
return new Ct({shape: b.shape});
});
this.forwardLayer.stateSpec = u.slice(0, l / 2), this.backwardLayer.stateSpec = u.slice(l / 2), c.push.apply(c, u);
}
if (a != null)
throw new Re("Support for constants in Bidirectional layers is not implemented yet.");
for (var h = o[0] instanceof xn, d = 0, p = o; d < p.length; d++) {
var f = p[d];
if (f instanceof xn !== h)
throw new M("The initial state of a Bidirectional layer cannot be specified as a mix of symbolic and non-symbolic tensors");
}
if (h) {
var m = [e].concat(o), g = this.inputSpec.concat(c), y = this.inputSpec;
this.inputSpec = g;
var w = n.prototype.apply.call(this, m, r);
return this.inputSpec = y, w;
} else
return n.prototype.apply.call(this, e, r);
}, t.prototype.call = function(e, r) {
var i = this;
return v.tidy(function() {
var a = r.initialState, s, o;
if (a == null)
s = i.forwardLayer.call(e, r), o = i.backwardLayer.call(e, r);
else {
var c = a.slice(0, a.length / 2), l = a.slice(a.length / 2);
s = i.forwardLayer.call(e, Object.assign(r, {initialState: c})), o = i.backwardLayer.call(e, Object.assign(r, {initialState: l}));
}
var u;
i.returnState && (Array.isArray(s) && (u = s.slice(1).concat(o.slice(1))), s = s[0], o = o[0]), i.returnSequences && (o = v.reverse(o, 1));
var h;
return i.mergeMode === "concat" ? h = Ih([s, o]) : i.mergeMode === "sum" ? h = v.add(s, o) : i.mergeMode === "ave" ? h = v.mul(0.5, v.add(s, o)) : i.mergeMode === "mul" ? h = v.mul(s, o) : i.mergeMode == null && (h = [s, o]), i.returnState ? i.mergeMode == null ? h.concat(u) : [h].concat(u) : h;
});
}, t.prototype.resetStates = function(e) {
this.forwardLayer.resetStates(), this.backwardLayer.resetStates();
}, t.prototype.build = function(e) {
var r = this;
ri(this.forwardLayer.name, function() {
r.forwardLayer.build(e);
}), ri(this.backwardLayer.name, function() {
r.backwardLayer.build(e);
}), this.built = true;
}, t.prototype.computeMask = function(e, r) {
Array.isArray(r) && (r = r[0]);
var i;
if (this.returnSequences ? this.mergeMode == null ? i = [r, r] : i = r : this.mergeMode == null ? i = [null, null] : i = null, this.returnState) {
var a = this.forwardLayer.states, s = a.map(function(o) {
return null;
});
return Array.isArray(i) ? i.concat(s).concat(s) : [i].concat(s).concat(s);
} else
return i;
}, Object.defineProperty(t.prototype, "trainableWeights", {get: function() {
return this.forwardLayer.trainableWeights.concat(this.backwardLayer.trainableWeights);
}, enumerable: true, configurable: true}), Object.defineProperty(t.prototype, "nonTrainableWeights", {get: function() {
return this.forwardLayer.nonTrainableWeights.concat(this.backwardLayer.nonTrainableWeights);
}, enumerable: true, configurable: true}), t.prototype.setFastWeightInitDuringBuild = function(e) {
n.prototype.setFastWeightInitDuringBuild.call(this, e), this.forwardLayer != null && this.forwardLayer.setFastWeightInitDuringBuild(e), this.backwardLayer != null && this.backwardLayer.setFastWeightInitDuringBuild(e);
}, t.prototype.getConfig = function() {
var e = {mergeMode: this.mergeMode}, r = n.prototype.getConfig.call(this);
return Object.assign(e, r), e;
}, t.fromConfig = function(e, r) {
var i = Ln(r.layer);
if (delete r.layer, r.numConstants != null)
throw new Re("Deserialization of a Bidirectional layer with numConstants present is not supported yet.");
var a = r;
return a.layer = i, new e(a);
}, t.className = "Bidirectional", t;
}(Qv);
v.serialization.registerClass(t1);
function P7(n) {
return new Va(n);
}
function M7(n) {
return new Xy(n);
}
function H7(n) {
return new Ky(n);
}
function V7(n) {
return new jy(n);
}
function G7(n) {
return new $y(n);
}
function q7(n) {
return new Zy(n);
}
function Y7(n) {
return new Jy(n);
}
function K7(n) {
return new av(n);
}
function j7(n) {
return new Qh(n);
}
function $7(n) {
return new rv(n);
}
function X7(n) {
return new nv(n);
}
function J7(n) {
return new iv(n);
}
function Z7(n) {
return new sv(n);
}
function Q7(n) {
return new ov(n);
}
function e4(n) {
return new cv(n);
}
function t4(n) {
return new vv(n);
}
function n4(n) {
return new gv(n);
}
function r4(n) {
return new id(n);
}
function i4(n) {
return new mv(n);
}
function a4(n) {
return new yv(n);
}
function s4(n) {
return new wv(n);
}
function o4(n) {
return new bv(n);
}
function c4(n) {
return new xv(n);
}
function l4(n) {
return new Sv(n);
}
function u4(n) {
return new Iv(n);
}
function h4(n) {
return new Tv(n);
}
function d4(n) {
return new Cv(n);
}
function p4(n) {
return new Nv(n);
}
function f4(n) {
return new _v(n);
}
function m4(n) {
return new Av(n);
}
function g4(n) {
return new Rv(n);
}
function y4(n) {
return new kv(n);
}
function v4(n) {
return new Fv(n);
}
function w4(n) {
return new Wv(n);
}
function ad(n) {
return new Pv(n);
}
function b4(n) {
return ad(n);
}
function x4(n) {
return ad(n);
}
function sd(n) {
return new Vv(n);
}
function L4(n) {
return sd(n);
}
function S4(n) {
return sd(n);
}
function od(n) {
return new Yv(n);
}
function I4(n) {
return od(n);
}
function A4(n) {
return od(n);
}
function T4(n) {
return new jv(n);
}
function N4(n) {
return new Jv(n);
}
function n1(n) {
return new $v(n);
}
function r1(n) {
return new Zv(n);
}
function i1(n) {
return new zv(n);
}
function a1(n) {
return new Hv(n);
}
function _4(n) {
return new qv(n);
}
function C4(n) {
return new dv(n);
}
function R4(n) {
return new nd(n);
}
function O4(n) {
return new pv(n);
}
function E4(n) {
return new _o(n);
}
function D4(n) {
return new hv(n);
}
function k4(n) {
return new td(n);
}
function F4(n) {
return new fv(n);
}
function W4(n) {
return new rd(n);
}
function U4(n) {
return new _r(n);
}
function B4(n) {
return new ed(n);
}
function z4(n) {
return new t1(n);
}
function P4(n) {
return new e1(n);
}
var M4 = n1, H4 = r1, V4 = i1, G4 = a1;
function q4(n) {
return new Ov(n);
}
function Y4(n) {
return new Ev(n);
}
function K4(n) {
return new Dv(n);
}
function j4(n) {
return new Lv(n);
}
var $4 = {__proto__: null, inputLayer: P7, elu: M7, reLU: H7, leakyReLU: V7, prelu: G7, softmax: q7, thresholdedReLU: Y7, conv1d: K7, conv2d: j7, conv2dTranspose: $7, conv3d: X7, separableConv2d: J7, cropping2D: Z7, upSampling2d: Q7, depthwiseConv2d: e4, activation: t4, dense: n4, dropout: r4, spatialDropout1d: i4, flatten: a4, repeatVector: s4, reshape: o4, permute: c4, embedding: l4, add: u4, average: h4, concatenate: d4, maximum: p4, minimum: f4, multiply: m4, dot: g4, batchNormalization: y4, layerNormalization: v4, zeroPadding2d: w4, averagePooling1d: ad, avgPool1d: b4, avgPooling1d: x4, averagePooling2d: sd, avgPool2d: L4, avgPooling2d: S4, averagePooling3d: od, avgPool3d: I4, avgPooling3d: A4, globalAveragePooling1d: T4, globalAveragePooling2d: N4, globalMaxPooling1d: n1, globalMaxPooling2d: r1, maxPooling1d: i1, maxPooling2d: a1, maxPooling3d: _4, gru: C4, gruCell: R4, lstm: O4, lstmCell: E4, simpleRNN: D4, simpleRNNCell: k4, convLstm2d: F4, convLstm2dCell: W4, rnn: U4, stackedRNNCells: B4, bidirectional: z4, timeDistributed: P4, globalMaxPool1d: M4, globalMaxPool2d: H4, maxPool1d: V4, maxPool2d: G4, Layer: Fe, RNN: _r, RNNCell: $i, input: Hy, gaussianNoise: q4, gaussianDropout: Y4, alphaDropout: K4, masking: j4};
function X4(n, t) {
return Bh(n, t);
}
function J4(n, t) {
return Ay(n, t);
}
function Z4(n, t) {
return Ty(n, t);
}
function Q4(n, t) {
return zh(n, t);
}
function eD(n, t) {
return Ph(n, t);
}
function tD(n, t) {
return Iy(n, t);
}
function nD(n, t) {
return IE(n, t);
}
function rD(n, t) {
return Wh(n, t);
}
function iD(n, t) {
return vo(n, t);
}
function aD(n, t) {
return Yi(n, t);
}
function sD(n, t) {
return Yi(n, t);
}
function oD(n, t) {
return Yi(n, t);
}
function cD(n, t) {
return ai(n, t);
}
function lD(n, t) {
return ai(n, t);
}
function uD(n, t) {
return ai(n, t);
}
var hD = {__proto__: null, binaryAccuracy: X4, binaryCrossentropy: J4, sparseCategoricalAccuracy: Z4, categoricalAccuracy: Q4, categoricalCrossentropy: eD, precision: tD, recall: nD, cosineProximity: rD, meanAbsoluteError: iD, meanAbsolutePercentageError: aD, MAPE: sD, mape: oD, meanSquaredError: cD, MSE: lD, mse: uD};
var dD = {__proto__: null, modelFromJSON: s7};
function pD(n) {
return new Ao(n);
}
function fD(n) {
return T7(n);
}
function mD(n) {
return N7(n);
}
var gD = {__proto__: null, l1l2: pD, l1: fD, l2: mD};
var s1 = function(n) {
Q(t, n);
function t() {
var e = n !== null && n.apply(this, arguments) || this;
return e.model = null, e;
}
return t.prototype.setModel = function(e) {
if (!(e instanceof Ar))
throw new Error("model must be a LayersModel, not some other Container");
this.model = e;
}, t;
}(qi);
function Ro(n, t) {
return n < t;
}
function o1(n, t) {
return n > t;
}
var c1 = function(n) {
Q(t, n);
function t(e) {
var r = n.call(this) || this;
if (e == null && (e = {}), e.restoreBestWeights)
throw new Re("restoreBestWeights = True is not implemented in EarlyStopping yet.");
return r.monitor = e.monitor || "val_loss", r.minDelta = Math.abs(e.minDelta || 0), r.patience = e.patience || 0, r.verbose = e.verbose || 0, r.mode = e.mode || "auto", r.baseline = e.baseline, ["auto", "min", "max"].indexOf(r.mode) === -1 && (console.warn("EarlyStopping mode '" + r.mode + "' is invalid. Falling back to mode 'auto'."), r.mode = "auto"), r.mode === "min" ? r.monitorFunc = Ro : r.mode === "max" || r.monitor.indexOf("acc") !== -1 ? r.monitorFunc = o1 : r.monitorFunc = Ro, r.monitorFunc === Ro && (r.minDelta *= -1), r;
}
return t.prototype.onTrainBegin = function(e) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(r) {
return this.wait = 0, this.stoppedEpoch = 0, this.baseline != null ? this.best = this.baseline : this.best = this.monitorFunc === Ro ? Infinity : -Infinity, [2];
});
});
}, t.prototype.onEpochEnd = function(e, r) {
return Ae(this, void 0, void 0, function() {
var i;
return xe(this, function(a) {
switch (a.label) {
case 0:
return [4, Ir(r)];
case 1:
return a.sent(), i = this.getMonitorValue(r), i == null ? [2] : (this.monitorFunc(i - this.minDelta, this.best) ? (this.best = i, this.wait = 0) : (this.wait++, this.wait >= this.patience && (this.stoppedEpoch = e, this.model.stopTraining = true)), [2]);
}
});
});
}, t.prototype.onTrainEnd = function(e) {
return Ae(this, void 0, void 0, function() {
return xe(this, function(r) {
return this.stoppedEpoch > 0 && this.verbose && console.log("Epoch " + this.stoppedEpoch + ": early stopping."), [2];
});
});
}, t.prototype.getMonitorValue = function(e) {
e == null && (e = {});
var r = e[this.monitor];
return r == null && console.warn("Metric for EarlyStopping " + this.monitor + " is not available. " + ("Available metrics are: " + Object.keys(e))), r;
}, t;
}(s1);
function yD(n) {
return new c1(n);
}
var vD = {earlyStopping: yD};
tt.Callback = s1;
tt.CallbackList = yy;
tt.CustomCallback = wy;
tt.EarlyStopping = c1;
tt.History = vy;
tt.InputSpec = Ct;
tt.LayerVariable = dy;
tt.LayersModel = Ar;
tt.RNN = _r;
tt.Sequential = $h;
tt.SymbolicTensor = xn;
tt.callbacks = vD;
tt.constraints = AO;
tt.initializers = aE;
tt.input = Hy;
tt.layers = $4;
tt.loadLayersModel = d7;
tt.metrics = hD;
tt.model = u7;
tt.models = dD;
tt.registerCallbackConstructor = p7;
tt.regularizers = gD;
tt.sequential = h7;
tt.version_layers = Vh;
});
var I1 = we((ci) => {
"use strict";
Object.defineProperty(ci, "__esModule", {value: true});
var W = ei();
var u1 = Object.assign || function(t) {
for (var e, r = 1, i = arguments.length; r < i; r++) {
e = arguments[r];
for (var a in e)
Object.prototype.hasOwnProperty.call(e, a) && (t[a] = e[a]);
}
return t;
};
function on(n, t, e, r) {
return new (e || (e = Promise))(function(i, a) {
function s(l) {
try {
c(r.next(l));
} catch (u) {
a(u);
}
}
function o(l) {
try {
c(r.throw(l));
} catch (u) {
a(u);
}
}
function c(l) {
l.done ? i(l.value) : new e(function(u) {
u(l.value);
}).then(s, o);
}
c((r = r.apply(n, t || [])).next());
});
}
function Qt(n, t) {
var e = {label: 0, sent: function() {
if (a[0] & 1)
throw a[1];
return a[1];
}, trys: [], ops: []}, r, i, a, s;
return s = {next: o(0), throw: o(1), return: o(2)}, typeof Symbol == "function" && (s[Symbol.iterator] = function() {
return this;
}), s;
function o(l) {
return function(u) {
return c([l, u]);
};
}
function c(l) {
if (r)
throw new TypeError("Generator is already executing.");
for (; e; )
try {
if (r = 1, i && (a = i[l[0] & 2 ? "return" : l[0] ? "throw" : "next"]) && !(a = a.call(i, l[1])).done)
return a;
(i = 0, a) && (l = [0, a.value]);
switch (l[0]) {
case 0:
case 1:
a = l;
break;
case 4:
return e.label++, {value: l[1], done: false};
case 5:
e.label++, i = l[1], l = [0];
continue;
case 7:
l = e.ops.pop(), e.trys.pop();
continue;
default:
if (!(a = e.trys, a = a.length > 0 && a[a.length - 1]) && (l[0] === 6 || l[0] === 2)) {
e = 0;
continue;
}
if (l[0] === 3 && (!a || l[1] > a[0] && l[1] < a[3])) {
e.label = l[1];
break;
}
if (l[0] === 6 && e.label < a[1]) {
e.label = a[1], a = l;
break;
}
if (a && e.label < a[2]) {
e.label = a[2], e.ops.push(l);
break;
}
a[2] && e.ops.pop(), e.trys.pop();
continue;
}
l = t.call(n, e);
} catch (u) {
l = [6, u], i = 0;
} finally {
r = a = 0;
}
if (l[0] & 5)
throw l[1];
return {value: l[0] ? l[1] : void 0, done: true};
}
}
function gt(n, t) {
var e = typeof Symbol == "function" && n[Symbol.iterator];
if (!e)
return n;
var r = e.call(n), i, a = [], s;
try {
for (; (t === void 0 || t-- > 0) && !(i = r.next()).done; )
a.push(i.value);
} catch (o) {
s = {error: o};
} finally {
try {
i && !i.done && (e = r.return) && e.call(r);
} finally {
if (s)
throw s.error;
}
}
return a;
}
function Rr() {
for (var n = [], t = 0; t < arguments.length; t++)
n = n.concat(gt(arguments[t]));
return n;
}
var In;
(function(n) {
n[n.DT_INVALID = 0] = "DT_INVALID", n[n.DT_FLOAT = 1] = "DT_FLOAT", n[n.DT_DOUBLE = 2] = "DT_DOUBLE", n[n.DT_INT32 = 3] = "DT_INT32", n[n.DT_UINT8 = 4] = "DT_UINT8", n[n.DT_INT16 = 5] = "DT_INT16", n[n.DT_INT8 = 6] = "DT_INT8", n[n.DT_STRING = 7] = "DT_STRING", n[n.DT_COMPLEX64 = 8] = "DT_COMPLEX64", n[n.DT_INT64 = 9] = "DT_INT64", n[n.DT_BOOL = 10] = "DT_BOOL", n[n.DT_QINT8 = 11] = "DT_QINT8", n[n.DT_QUINT8 = 12] = "DT_QUINT8", n[n.DT_QINT32 = 13] = "DT_QINT32", n[n.DT_BFLOAT16 = 14] = "DT_BFLOAT16", n[n.DT_FLOAT_REF = 101] = "DT_FLOAT_REF", n[n.DT_DOUBLE_REF = 102] = "DT_DOUBLE_REF", n[n.DT_INT32_REF = 103] = "DT_INT32_REF", n[n.DT_UINT8_REF = 104] = "DT_UINT8_REF", n[n.DT_INT16_REF = 105] = "DT_INT16_REF", n[n.DT_INT8_REF = 106] = "DT_INT8_REF", n[n.DT_STRING_REF = 107] = "DT_STRING_REF", n[n.DT_COMPLEX64_REF = 108] = "DT_COMPLEX64_REF", n[n.DT_INT64_REF = 109] = "DT_INT64_REF", n[n.DT_BOOL_REF = 110] = "DT_BOOL_REF", n[n.DT_QINT8_REF = 111] = "DT_QINT8_REF", n[n.DT_QUINT8_REF = 112] = "DT_QUINT8_REF", n[n.DT_QINT32_REF = 113] = "DT_QINT32_REF", n[n.DT_BFLOAT16_REF = 114] = "DT_BFLOAT16_REF";
})(In || (In = {}));
var h1;
(function(n) {
var t;
(function(e) {
e[e.LEGACY = 0] = "LEGACY", e[e.V1 = 1] = "V1", e[e.V2 = 2] = "V2";
})(t = n.CheckpointFormatVersion || (n.CheckpointFormatVersion = {}));
})(h1 || (h1 = {}));
var cd = {};
function wD(n, t) {
var e = {tfOpName: n, category: "custom", inputs: [], attrs: [], customExecutor: t};
cd[n] = e;
}
function d1(n) {
return cd[n];
}
function bD(n) {
delete cd[n];
}
function T(n, t, e, r, i) {
var a = t.inputParams[n];
if (a && a.inputIndexStart !== void 0) {
var s = a.inputIndexStart, o = a.inputIndexEnd === 0 ? void 0 : a.inputIndexEnd === void 0 ? s + 1 : a.inputIndexEnd;
if (a.type === "tensor")
return Gt(t.inputNames[a.inputIndexStart], e, r, i);
if (a.type === "tensors") {
var c = t.inputNames.slice(s, o);
return c.map(function(d) {
return Gt(d, e, r, i);
});
}
var l = Gt(t.inputNames.slice(s)[0], e, r, i), u = l.dataSync();
return a.type === "number" ? u[0] : W.util.toNestedArray(l.shape, u);
}
var h = t.attrParams[n];
return h && h.value;
}
function Gt(n, t, e, r) {
var i = gt(en(n), 2), a = i[0], s = i[1];
if (r != null) {
var o = r.getHashTableHandleByName(a);
if (o != null)
return o;
}
var c = e.currentContextIds.find(function(l) {
return !!t[Oo(a, l)];
});
return c !== void 0 ? t[Oo(a, c)][s] : void 0;
}
function xD(n, t, e) {
return t[Oo(n, e.currentContextId)];
}
function er(n, t) {
var e = gt(en(n), 2), r = e[0], i = e[1];
return [Oo(r, t && t.currentContextId), i];
}
function Oo(n, t) {
return t ? n + "-" + t : n;
}
function en(n) {
var t = n.split(":");
if (t.length === 1)
return [n, 0];
var e = t[0];
return [e, Number(t[t.length - 1])];
}
function Eo(n, t, e) {
var r = T("pad", n, t, e);
if (r === "explicit") {
r = T("explicitPaddings", n, t, e);
for (var i = [[0, 0], [0, 0], [0, 0], [0, 0]], a = 0; a < 4; a++)
i[a][0] = r[a * 2], i[a][1] = r[a * 2 + 1];
return i;
}
return r;
}
function tr(n) {
return n.kept ? n : W.clone(n);
}
var LD = [{tfOpName: "Add", category: "arithmetic", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "AddV2", category: "arithmetic", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "AddN", category: "arithmetic", inputs: [{start: 0, end: 0, name: "tensors", type: "tensors"}]}, {tfOpName: "BiasAdd", category: "arithmetic", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Sub", category: "arithmetic", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "RealDiv", category: "arithmetic", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Div", category: "arithmetic", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "DivNoNan", category: "arithmetic", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "FloorDiv", category: "arithmetic", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Mul", category: "arithmetic", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Maximum", category: "arithmetic", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}]}, {tfOpName: "Minimum", category: "arithmetic", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}]}, {tfOpName: "Pow", category: "arithmetic", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "SquaredDifference", category: "arithmetic", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Mod", category: "arithmetic", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "FloorMod", category: "arithmetic", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}], SD = {__proto__: null, json: LD};
var ID = [{tfOpName: "Abs", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Acos", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Asin", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Atan", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Atan2", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "y", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Ceil", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "ClipByValue", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "clip_value_min", name: "clipValueMin", type: "number"}, {tfName: "clip_value_max", name: "clipValueMax", type: "number"}]}, {tfOpName: "Complex", category: "basic_math", inputs: [{start: 0, name: "real", type: "tensor"}, {start: 1, name: "imag", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "ComplexAbs", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Cos", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Cosh", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Elu", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Exp", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Floor", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Log", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Imag", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}, {tfName: "Tout", name: "outputType", type: "dtype", notSupported: true}]}, {tfOpName: "Neg", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Real", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}, {tfName: "Tout", name: "outputType", type: "dtype", notSupported: true}]}, {tfOpName: "Prelu", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "alpha", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Relu", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Relu6", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}, {tfName: "clipValueMin", name: "clipValueMin", type: "number", defaultValue: 0}, {tfName: "clipValueMax", name: "clipValueMax", type: "number", defaultValue: 6}]}, {tfOpName: "Selu", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Sigmoid", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Sin", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Sinh", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Sqrt", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Rsqrt", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Square", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Tan", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Tanh", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Sign", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Round", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Expm1", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Log1p", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Reciprocal", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Softplus", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Asinh", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Acosh", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Atanh", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Erf", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Prod", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "axes", type: "number[]"}], attrs: [{tfName: "keep_dims", name: "keepDims", type: "bool", notSupported: true}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "LeakyRelu", category: "basic_math", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "alpha", name: "alpha", type: "number", defaultValue: 0.2}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}], AD = {__proto__: null, json: ID}, TD = [{tfOpName: "LoopCond", category: "control", inputs: [{start: 0, name: "pred", type: "tensor"}]}, {tfOpName: "Switch", category: "control", inputs: [{start: 0, name: "data", type: "tensor"}, {start: 1, name: "pred", type: "tensor"}]}, {tfOpName: "Merge", category: "control", inputs: [{start: 0, end: 0, name: "tensors", type: "tensors"}]}, {tfOpName: "Enter", category: "control", inputs: [{start: 0, name: "tensor", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}, {tfName: "frame_name", name: "frameName", type: "string"}, {tfName: "is_constant", name: "isConstant", type: "bool"}]}, {tfOpName: "Exit", category: "control", inputs: [{start: 0, name: "tensor", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "NextIteration", category: "control", inputs: [{start: 0, name: "tensor", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "TensorArrayV3", category: "control", inputs: [{start: 0, name: "size", type: "number"}], attrs: [{tfName: "dtype", name: "dtype", type: "dtype"}, {tfName: "element_shape", name: "elementShape", type: "shape"}, {tfName: "dynamic_size", name: "dynamicSize", type: "bool"}, {tfName: "clear_after_read", name: "clearAfterRead", type: "bool"}, {tfName: "identical_element_shapes", name: "identicalElementShapes", type: "bool"}, {tfName: "tensor_array_name", name: "name", type: "string"}]}, {tfOpName: "TensorArrayWriteV3", category: "control", inputs: [{start: 0, name: "tensorArrayId", type: "tensor"}, {start: 1, name: "index", type: "number"}, {start: 2, name: "tensor", type: "tensor"}, {start: 3, name: "flowIn", type: "number"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "TensorArrayReadV3", category: "control", inputs: [{start: 0, name: "tensorArrayId", type: "tensor"}, {start: 1, name: "index", type: "number"}, {start: 2, name: "flowIn", type: "number"}], attrs: [{tfName: "dtype", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "TensorArrayGatherV3", category: "control", inputs: [{start: 0, name: "tensorArrayId", type: "tensor"}, {start: 1, name: "indices", type: "number[]"}, {start: 2, name: "flowIn", type: "number"}], attrs: [{tfName: "dtype", name: "dtype", type: "dtype"}, {tfName: "element_shape", name: "elementShape", type: "shape"}]}, {tfOpName: "TensorArrayScatterV3", category: "control", inputs: [{start: 0, name: "tensorArrayId", type: "tensor"}, {start: 1, name: "indices", type: "number[]"}, {start: 2, name: "tensor", type: "tensor"}, {start: 3, name: "flowIn", type: "number"}], attrs: [{tfName: "T", name: "dtype", type: "dtype"}]}, {tfOpName: "TensorArrayConcatV3", category: "control", inputs: [{start: 0, name: "tensorArrayId", type: "tensor"}, {start: 1, name: "flowIn", type: "number"}], attrs: [{tfName: "dtype", name: "dtype", type: "dtype"}, {tfName: "element_shape_except0", name: "elementShapeExcept0", type: "shape", notSupported: true}]}, {tfOpName: "TensorArraySplitV3", category: "control", inputs: [{start: 0, name: "tensorArrayId", type: "tensor"}, {start: 1, name: "tensor", type: "tensor"}, {start: 2, name: "lengths", type: "number[]"}, {start: 3, name: "flowIn", type: "number"}], attrs: [{tfName: "T", name: "dtype", type: "dtype"}]}, {tfOpName: "TensorArraySizeV3", category: "control", inputs: [{start: 0, name: "tensorArrayId", type: "tensor"}, {start: 1, name: "flowIn", type: "number"}]}, {tfOpName: "TensorArrayCloseV3", category: "control", inputs: [{start: 0, name: "tensorArrayId", type: "tensor"}]}, {tfOpName: "StatelessIf", category: "control", inputs: [{start: 0, name: "cond", type: "tensor"}, {start: 1, end: 0, name: "args", type: "tensors"}], attrs: [{tfName: "then_branch", name: "thenBranch", type: "func"}, {tfName: "else_branch", name: "elseBranch", type: "func"}]}, {tfOpName: "If", category: "control", inputs: [{start: 0, name: "cond", type: "tensor"}, {start: 1, end: 0, name: "args", type: "tensors"}], attrs: [{tfName: "then_branch", name: "thenBranch", type: "func"}, {tfName: "else_branch", name: "elseBranch", type: "func"}]}, {tfOpName: "StatelessWhile", category: "control", inputs: [{start: 0, end: 0, name: "args", type: "tensors"}], attrs: [{tfName: "cond", name: "cond", type: "func"}, {tfName: "body", name: "body", type: "func"}]}, {tfOpName: "While", category: "control", inputs: [{start: 0, end: 0, name: "args", type: "tensors"}], attrs: [{tfName: "cond", name: "cond", type: "func"}, {tfName: "body", name: "body", type: "func"}]}, {tfOpName: "TensorListScatter", category: "control", inputs: [{start: 0, name: "tensor", type: "tensor"}, {start: 1, name: "indices", type: "number[]"}, {start: 2, name: "elementShape", type: "shape"}], attrs: [{tfName: "element_dtype", name: "elementDType", type: "dtype"}]}, {tfOpName: "TensorListScatterV2", category: "control", inputs: [{start: 0, name: "tensor", type: "tensor"}, {start: 1, name: "indices", type: "number[]"}, {start: 2, name: "elementShape", type: "shape"}, {start: 3, name: "numElements", type: "number"}], attrs: [{tfName: "element_dtype", name: "elementDType", type: "dtype"}]}, {tfOpName: "TensorListGather", category: "control", inputs: [{start: 0, name: "tensorListId", type: "tensor"}, {start: 1, name: "indices", type: "number[]"}, {start: 2, name: "elementShape", type: "shape"}], attrs: [{tfName: "element_dtype", name: "elementDType", type: "dtype"}]}, {tfOpName: "TensorListGetItem", category: "control", inputs: [{start: 0, name: "tensorListId", type: "tensor"}, {start: 1, name: "index", type: "number"}, {start: 2, name: "elementShape", type: "shape"}], attrs: [{tfName: "element_dtype", name: "elementDType", type: "dtype"}]}, {tfOpName: "TensorListSetItem", category: "control", inputs: [{start: 0, name: "tensorListId", type: "tensor"}, {start: 1, name: "index", type: "number"}, {start: 2, name: "tensor", type: "tensor"}], attrs: [{tfName: "element_dtype", name: "elementDType", type: "dtype"}]}, {tfOpName: "TensorListReserve", category: "control", inputs: [{start: 0, name: "elementShape", type: "shape"}, {start: 1, name: "numElements", type: "number"}], attrs: [{tfName: "element_dtype", name: "elementDType", type: "dtype"}]}, {tfOpName: "TensorListFromTensor", category: "control", inputs: [{start: 0, name: "tensor", type: "tensor"}, {start: 1, name: "elementShape", type: "shape"}], attrs: [{tfName: "element_dtype", name: "elementDType", type: "dtype"}]}, {tfOpName: "TensorListStack", category: "control", inputs: [{start: 0, name: "tensorListId", type: "tensor"}, {start: 1, name: "elementShape", type: "shape"}], attrs: [{tfName: "element_dtype", name: "elementDType", type: "dtype"}, {tfName: "num_elements", name: "numElements", type: "dtype"}]}, {tfOpName: "TensorListSplit", category: "control", inputs: [{start: 0, name: "tensor", type: "tensor"}, {start: 1, name: "elementShape", type: "shape"}, {start: 2, name: "lengths", type: "number[]"}], attrs: [{tfName: "element_dtype", name: "elementDType", type: "dtype"}]}, {tfOpName: "TensorListConcat", category: "control", inputs: [{start: 0, name: "tensorListId", type: "tensor"}], attrs: [{tfName: "element_shape", name: "elementShape", type: "shape"}, {tfName: "element_dtype", name: "elementDType", type: "dtype"}]}, {tfOpName: "TensorListPopBack", category: "control", inputs: [{start: 0, name: "tensorListId", type: "tensor"}, {start: 1, name: "elementShape", type: "shape"}], attrs: [{tfName: "element_dtype", name: "elementDType", type: "dtype"}]}, {tfOpName: "TensorListPushBack", category: "control", inputs: [{start: 0, name: "tensorListId", type: "tensor"}, {start: 1, name: "tensor", type: "tensor"}], attrs: [{tfName: "element_dtype", name: "elementDType", type: "dtype"}]}], ND = {__proto__: null, json: TD};
var _D = [{tfOpName: "AvgPool", category: "convolution", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "strides", name: "strides", type: "number[]"}, {tfName: "padding", name: "pad", type: "string"}, {tfName: "data_format", name: "dataFormat", type: "string", notSupported: true}, {tfName: "ksize", name: "kernelSize", type: "number[]"}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "MaxPool", category: "convolution", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "strides", name: "strides", type: "number[]"}, {tfName: "padding", name: "pad", type: "string"}, {tfName: "data_format", name: "dataFormat", type: "string", notSupported: true}, {tfName: "ksize", name: "kernelSize", type: "number[]"}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "MaxPoolWithArgmax", category: "convolution", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "strides", name: "strides", type: "number[]"}, {tfName: "padding", name: "pad", type: "string"}, {tfName: "ksize", name: "kernelSize", type: "number[]"}, {tfName: "include_batch_in_index", name: "includeBatchInIndex", type: "bool"}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "AvgPool3D", category: "convolution", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "strides", name: "strides", type: "number[]"}, {tfName: "padding", name: "pad", type: "string"}, {tfName: "data_format", name: "dataFormat", type: "string", notSupported: true}, {tfName: "ksize", name: "kernelSize", type: "number[]"}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "MaxPool3D", category: "convolution", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "strides", name: "strides", type: "number[]"}, {tfName: "padding", name: "pad", type: "string"}, {tfName: "data_format", name: "dataFormat", type: "string", notSupported: true}, {tfName: "ksize", name: "kernelSize", type: "number[]"}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Conv1D", category: "convolution", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "filter", type: "tensor"}], attrs: [{tfName: "stride", name: "stride", type: "number"}, {tfName: "padding", name: "pad", type: "string"}, {tfName: "data_format", name: "dataFormat", type: "string", defaultValue: "NWC"}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}, {tfName: "dilation", name: "dilation", type: "number", defaultValue: 1}]}, {tfOpName: "Conv2D", category: "convolution", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "filter", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}, {tfName: "strides", name: "strides", type: "number[]"}, {tfName: "padding", name: "pad", type: "string"}, {tfName: "useCudnnOnGpu", name: "useCudnnOnGpu", type: "bool"}, {tfName: "data_format", name: "dataFormat", type: "string", defaultValue: "NHWC"}, {tfName: "explicit_paddings", name: "explicitPaddings", type: "number[]", defaultValue: []}, {tfName: "dilations", name: "dilations", type: "number[]"}]}, {tfOpName: "_FusedConv2D", category: "convolution", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "filter", type: "tensor"}, {start: 2, end: 0, name: "args", type: "tensors"}], attrs: [{tfName: "num_args", name: "numArgs", type: "number"}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}, {tfName: "strides", name: "strides", type: "number[]"}, {tfName: "padding", name: "pad", type: "string"}, {tfName: "explicit_paddings", name: "explicitPaddings", type: "number[]", defaultValue: []}, {tfName: "use_cudnn_on_gpu", name: "useCudnnOnGpu", type: "bool", defaultValue: true}, {tfName: "data_format", name: "dataFormat", type: "string", defaultValue: "NHWC"}, {tfName: "dilations", name: "dilations", type: "number[]", defaultValue: [1, 1, 1, 1]}, {tfName: "fused_ops", name: "fusedOps", type: "string[]", defaultValue: []}, {tfName: "epsilon", name: "epsilon", type: "number", defaultValue: 1e-4}]}, {tfOpName: "Conv2DBackpropInput", category: "convolution", inputs: [{start: 2, name: "x", type: "tensor"}, {start: 1, name: "filter", type: "tensor"}, {start: 0, name: "outputShape", type: "number[]"}], attrs: [{tfName: "strides", name: "strides", type: "number[]"}, {tfName: "padding", name: "pad", type: "string"}, {tfName: "data_format", name: "dataFormat", type: "string", notSupported: true}, {tfName: "explicit_paddings", name: "explicitPaddings", type: "number[]", defaultValue: []}]}, {tfOpName: "DepthwiseConv2d", category: "convolution", inputs: [{start: 0, name: "input", type: "tensor"}, {start: 1, name: "filter", type: "tensor"}], attrs: [{tfName: "strides", name: "strides", type: "number[]"}, {tfName: "padding", name: "pad", type: "string"}, {tfName: "data_format", name: "dataFormat", type: "string", defaultValue: "NHWC"}, {tfName: "explicit_paddings", name: "explicitPaddings", type: "number[]", defaultValue: []}, {tfName: "dilations", name: "dilations", type: "number[]"}]}, {tfOpName: "DepthwiseConv2dNative", category: "convolution", inputs: [{start: 0, name: "input", type: "tensor"}, {start: 1, name: "filter", type: "tensor"}], attrs: [{tfName: "strides", name: "strides", type: "number[]"}, {tfName: "padding", name: "pad", type: "string"}, {tfName: "data_format", name: "dataFormat", type: "string", defaultValue: "NHWC"}, {tfName: "explicit_paddings", name: "explicitPaddings", type: "number[]", defaultValue: []}, {tfName: "dilations", name: "dilations", type: "number[]"}]}, {tfOpName: "FusedDepthwiseConv2dNative", category: "convolution", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "filter", type: "tensor"}, {start: 2, end: 0, name: "args", type: "tensors"}], attrs: [{tfName: "num_args", name: "numArgs", type: "number"}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}, {tfName: "strides", name: "strides", type: "number[]"}, {tfName: "padding", name: "pad", type: "string"}, {tfName: "data_format", name: "dataFormat", type: "string", defaultValue: "NHWC"}, {tfName: "dilations", name: "dilations", type: "number[]", defaultValue: [1, 1, 1, 1]}, {tfName: "fused_ops", name: "fusedOps", type: "string[]", defaultValue: []}]}, {tfOpName: "Conv3D", category: "convolution", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "filter", type: "tensor"}], attrs: [{tfName: "strides", name: "strides", type: "number[]"}, {tfName: "padding", name: "pad", type: "string"}, {tfName: "data_format", name: "dataFormat", type: "string", defaultValue: "NHWC"}, {tfName: "dilations", name: "dilations", type: "number[]"}]}, {tfOpName: "Dilation2D", category: "convolution", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "filter", type: "tensor"}], attrs: [{tfName: "strides", name: "strides", type: "number[]"}, {tfName: "rates", name: "dilations", type: "number[]"}, {tfName: "padding", name: "pad", type: "string"}]}], CD = {__proto__: null, json: _D};
var RD = [{tfOpName: "Fill", category: "creation", inputs: [{start: 0, name: "shape", type: "number[]"}, {start: 1, name: "value", type: "number"}], attrs: [{tfName: "T", name: "dtype", type: "dtype"}]}, {tfOpName: "LinSpace", category: "creation", inputs: [{start: 0, name: "start", type: "number"}, {start: 1, name: "stop", type: "number"}, {start: 2, name: "num", type: "number"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "OneHot", category: "creation", inputs: [{start: 0, name: "indices", type: "tensor"}, {start: 1, name: "depth", type: "number"}, {start: 2, name: "onValue", type: "number", defaultValue: 1}, {start: 3, name: "offValue", type: "number", defaultValue: 0}], attrs: [{tfName: "axis", name: "axis", type: "number", notSupported: true}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Ones", category: "creation", inputs: [{start: 0, name: "shape", type: "number[]"}], attrs: [{tfName: "T", name: "dtype", type: "dtype"}]}, {tfOpName: "OnesLike", category: "creation", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "dtype", name: "dtype", type: "dtype"}]}, {tfOpName: "RandomUniform", category: "creation", inputs: [{start: 0, name: "shape", type: "number[]"}], attrs: [{tfName: "minval", name: "minval", type: "number", defaultValue: 0}, {tfName: "maxval", name: "maxval", type: "number", defaultValue: 1}, {tfName: "dtype", name: "dtype", type: "dtype"}, {tfName: "seed", name: "seed", type: "number", defaultValue: 0}, {tfName: "seed2", name: "seed2", type: "number", defaultValue: 0, notSupported: true}, {tfName: "T", name: "T", type: "number", notSupported: true}]}, {tfOpName: "Range", category: "creation", inputs: [{start: 0, name: "start", type: "number"}, {start: 1, name: "stop", type: "number"}, {start: 2, name: "step", type: "number", defaultValue: 0}], attrs: [{tfName: "Tidx", name: "dtype", type: "dtype"}]}, {tfOpName: "TruncatedNormal", category: "creation", inputs: [{start: 0, name: "shape", type: "number[]"}], attrs: [{tfName: "means", name: "mean", type: "number", defaultValue: 0}, {tfName: "stddev", name: "stdDev", type: "number", defaultValue: 1}, {tfName: "seed", name: "seed", type: "number"}, {tfName: "seed2", name: "seed2", type: "number", defaultValue: 0, notSupported: true}, {tfName: "dtype", name: "dtype", type: "dtype"}, {tfName: "T", name: "T", type: "number", notSupported: true}]}, {tfOpName: "Zeros", category: "creation", inputs: [{start: 0, name: "shape", type: "number[]"}], attrs: [{tfName: "T", name: "dtype", type: "dtype"}]}, {tfOpName: "ZerosLike", category: "creation", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype"}]}, {tfOpName: "Multinomial", category: "creation", inputs: [{start: 0, name: "logits", type: "tensor"}, {start: 1, name: "numSamples", type: "number"}], attrs: [{tfName: "seed", name: "seed", type: "number"}, {tfName: "seed2", name: "seed2", type: "number"}, {tfName: "T", name: "dtype", type: "dtype"}, {tfName: "output_dtype", name: "output_dtype", type: "dtype"}]}], OD = {__proto__: null, json: RD};
var ED = [{tfOpName: "NonMaxSuppressionV2", category: "dynamic", inputs: [{start: 0, name: "boxes", type: "tensor"}, {start: 1, name: "scores", type: "tensor"}, {start: 2, name: "maxOutputSize", type: "number"}, {start: 3, name: "iouThreshold", type: "number"}]}, {tfOpName: "NonMaxSuppressionV3", category: "dynamic", inputs: [{start: 0, name: "boxes", type: "tensor"}, {start: 1, name: "scores", type: "tensor"}, {start: 2, name: "maxOutputSize", type: "number"}, {start: 3, name: "iouThreshold", type: "number"}, {start: 4, name: "scoreThreshold", type: "number"}]}, {tfOpName: "NonMaxSuppressionV4", category: "dynamic", inputs: [{start: 0, name: "boxes", type: "tensor"}, {start: 1, name: "scores", type: "tensor"}, {start: 2, name: "maxOutputSize", type: "number"}, {start: 3, name: "iouThreshold", type: "number"}, {start: 4, name: "scoreThreshold", type: "number"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}, {tfName: "T_threshold", name: "threshold", type: "dtype", notSupported: true}, {tfName: "pad_to_max_output_size", name: "padToMaxOutputSize", type: "bool"}]}, {tfOpName: "NonMaxSuppressionV5", category: "dynamic", inputs: [{start: 0, name: "boxes", type: "tensor"}, {start: 1, name: "scores", type: "tensor"}, {start: 2, name: "maxOutputSize", type: "number"}, {start: 3, name: "iouThreshold", type: "number"}, {start: 4, name: "scoreThreshold", type: "number"}, {start: 5, name: "softNmsSigma", type: "number"}]}, {tfOpName: "Where", category: "dynamic", inputs: [{start: 0, name: "condition", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "ListDiff", category: "dynamic", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "y", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}], DD = {__proto__: null, json: ED};
var kD = [{tfOpName: "TopKV2", category: "evaluation", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "k", type: "number"}], attrs: [{tfName: "sorted", name: "sorted", type: "bool"}]}, {tfOpName: "Unique", category: "evaluation", inputs: [{start: 0, name: "x", type: "tensor"}]}, {tfOpName: "UniqueV2", category: "evaluation", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "axis", type: "number"}]}], FD = {__proto__: null, json: kD};
var WD = [{tfOpName: "PlaceholderWithDefault", category: "graph", inputs: [{start: 0, name: "default", type: "tensor"}], attrs: [{tfName: "shape", name: "shape", type: "shape"}, {tfName: "dtype", name: "dtype", type: "dtype"}]}, {tfOpName: "Placeholder", category: "graph", attrs: [{tfName: "shape", name: "shape", type: "shape"}, {tfName: "dtype", name: "dtype", type: "dtype"}]}, {tfOpName: "Const", category: "graph"}, {tfOpName: "Identity", category: "graph", inputs: [{start: 0, name: "x", type: "tensor"}]}, {tfOpName: "IdentityN", category: "graph", inputs: [{start: 0, end: 0, name: "x", type: "tensors"}]}, {tfOpName: "Snapshot", category: "graph", inputs: [{start: 0, name: "x", type: "tensor"}]}, {tfOpName: "Rank", category: "graph", inputs: [{start: 0, name: "x", type: "tensor"}]}, {tfOpName: "Size", category: "graph", inputs: [{start: 0, name: "x", type: "tensor"}]}, {tfOpName: "Shape", category: "graph", inputs: [{start: 0, name: "x", type: "tensor"}]}, {tfOpName: "ShapeN", category: "graph", inputs: [{start: 0, end: 0, name: "x", type: "tensors"}]}, {tfOpName: "Print", category: "graph", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "data", type: "tensors"}], attrs: [{tfName: "message", name: "message", type: "string"}, {tfName: "first_n", name: "firstN", type: "number", notSupported: true}, {tfName: "summarize", name: "summarize", type: "number", defaultValue: 3}]}, {tfOpName: "NoOp", category: "graph", inputs: []}, {tfOpName: "StopGradient", category: "graph", inputs: [{start: 0, name: "x", type: "tensor"}]}, {tfOpName: "FakeQuantWithMinMaxVars", category: "graph", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "min", name: "min", type: "number"}, {tfName: "max", name: "max", type: "number"}]}], UD = {__proto__: null, json: WD}, BD = [{tfOpName: "HashTable", category: "hash_table", inputs: [], attrs: [{tfName: "shared_name", name: "sharedName", type: "string"}, {tfName: "use_node_name_sharing", name: "useNodeNameSharing", type: "bool"}, {tfName: "key_dtype", name: "keyDType", type: "dtype"}, {tfName: "value_dtype", name: "valueDType", type: "dtype"}]}, {tfOpName: "HashTableV2", category: "hash_table", inputs: [], attrs: [{tfName: "shared_name", name: "sharedName", type: "string"}, {tfName: "use_node_name_sharing", name: "useNodeNameSharing", type: "bool"}, {tfName: "key_dtype", name: "keyDType", type: "dtype"}, {tfName: "value_dtype", name: "valueDType", type: "dtype"}]}, {tfOpName: "LookupTableImport", category: "hash_table", inputs: [{start: 0, name: "tableHandle", type: "tensor"}, {start: 1, name: "keys", type: "tensor"}, {start: 2, name: "values", type: "tensor"}], attrs: [{tfName: "Tin", name: "tIn", type: "dtype", notSupported: true}, {tfName: "Tout", name: "tOut", type: "dtype", notSupported: true}]}, {tfOpName: "LookupTableImportV2", category: "hash_table", inputs: [{start: 0, name: "tableHandle", type: "tensor"}, {start: 1, name: "keys", type: "tensor"}, {start: 2, name: "values", type: "tensor"}], attrs: [{tfName: "Tin", name: "tIn", type: "dtype", notSupported: true}, {tfName: "Tout", name: "tOut", type: "dtype", notSupported: true}]}, {tfOpName: "LookupTableFind", category: "hash_table", inputs: [{start: 0, name: "tableHandle", type: "tensor"}, {start: 1, name: "keys", type: "tensor"}, {start: 2, name: "defaultValue", type: "tensor"}], attrs: [{tfName: "Tin", name: "tIn", type: "dtype", notSupported: true}, {tfName: "Tout", name: "tOut", type: "dtype", notSupported: true}]}, {tfOpName: "LookupTableFindV2", category: "hash_table", inputs: [{start: 0, name: "tableHandle", type: "tensor"}, {start: 1, name: "keys", type: "tensor"}, {start: 2, name: "defaultValue", type: "tensor"}], attrs: [{tfName: "Tin", name: "tIn", type: "dtype", notSupported: true}, {tfName: "Tout", name: "tOut", type: "dtype", notSupported: true}]}], zD = {__proto__: null, json: BD};
var PD = [{tfOpName: "ResizeBilinear", category: "image", inputs: [{start: 0, name: "images", type: "tensor"}, {start: 1, name: "size", type: "number[]"}], attrs: [{tfName: "align_corners", name: "alignCorners", type: "bool"}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "ResizeNearestNeighbor", category: "image", inputs: [{start: 0, name: "images", type: "tensor"}, {start: 1, name: "size", type: "number[]"}], attrs: [{tfName: "align_corners", name: "alignCorners", type: "bool"}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "CropAndResize", category: "image", inputs: [{start: 0, name: "image", type: "tensor"}, {start: 1, name: "boxes", type: "tensor"}, {start: 2, name: "boxInd", type: "tensor"}, {start: 3, name: "cropSize", type: "number[]"}], attrs: [{tfName: "method", name: "method", type: "string"}, {tfName: "extrapolation_value", name: "extrapolationValue", type: "number"}]}], MD = {__proto__: null, json: PD};
var HD = [{tfOpName: "Equal", category: "logical", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "NotEqual", category: "logical", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Greater", category: "logical", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "GreaterEqual", category: "logical", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Less", category: "logical", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "LessEqual", category: "logical", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "LogicalAnd", category: "logical", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "LogicalNot", category: "logical", inputs: [{start: 0, name: "a", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "LogicalOr", category: "logical", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Select", category: "logical", inputs: [{start: 0, name: "condition", type: "tensor"}, {start: 1, name: "a", type: "tensor"}, {start: 2, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "SelectV2", category: "logical", inputs: [{start: 0, name: "condition", type: "tensor"}, {start: 1, name: "a", type: "tensor"}, {start: 2, name: "b", type: "tensor"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}], VD = {__proto__: null, json: HD};
var GD = [{tfOpName: "_FusedMatMul", category: "matrices", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}, {start: 2, end: 0, name: "args", type: "tensors"}], attrs: [{tfName: "num_args", name: "numArgs", type: "number"}, {tfName: "fused_ops", name: "fusedOps", type: "string[]", defaultValue: []}, {tfName: "epsilon", name: "epsilon", type: "number", defaultValue: 1e-4}, {tfName: "transpose_a", name: "transposeA", type: "bool", defaultValue: false}, {tfName: "transpose_b", name: "transposeB", type: "bool", defaultValue: false}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "MatMul", category: "matrices", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "transpose_a", name: "transposeA", type: "bool", defaultValue: false}, {tfName: "transpose_b", name: "transposeB", type: "bool", defaultValue: false}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "BatchMatMul", category: "matrices", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "adj_x", name: "transposeA", type: "bool", defaultValue: false}, {tfName: "adj_y", name: "transposeB", type: "bool", defaultValue: false}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "BatchMatMulV2", category: "matrices", inputs: [{start: 0, name: "a", type: "tensor"}, {start: 1, name: "b", type: "tensor"}], attrs: [{tfName: "adj_x", name: "transposeA", type: "bool", defaultValue: false}, {tfName: "adj_y", name: "transposeB", type: "bool", defaultValue: false}, {tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}, {tfOpName: "Transpose", category: "matrices", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "perm", type: "number[]"}], attrs: [{tfName: "T", name: "dtype", type: "dtype", notSupported: true}]}], qD = {__proto__: null, json: GD};
var YD = [{tfOpName: "FusedBatchNorm", category: "normalization", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "scale", type: "tensor"}, {start: 2, name: "offset", type: "tensor"}, {start: 3, name: "mean", type: "tensor"}, {start: 4, name: "variance", type: "tensor"}], attrs: [{tfName: "epsilon", name: "epsilon", type: "number", defaultValue: 1e-3}, {tfName: "data_format", name: "dataFormat", type: "string", notSupported: true}]}, {tfOpName: "FusedBatchNormV2", category: "normalization", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "scale", type: "tensor"}, {start: 2, name: "offset", type: "tensor"}, {start: 3, name: "mean", type: "tensor"}, {start: 4, name: "variance", type: "tensor"}], attrs: [{tfName: "epsilon", name: "epsilon", type: "number", defaultValue: 1e-3}, {tfName: "data_format", name: "dataFormat", type: "string", notSupported: true}]}, {tfOpName: "FusedBatchNormV3", category: "normalization", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "scale", type: "tensor"}, {start: 2, name: "offset", type: "tensor"}, {start: 3, name: "mean", type: "tensor"}, {start: 4, name: "variance", type: "tensor"}], attrs: [{tfName: "epsilon", name: "epsilon", type: "number", defaultValue: 1e-3}, {tfName: "data_format", name: "dataFormat", type: "string", notSupported: true}]}, {tfOpName: "LRN", category: "normalization", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "depth_radius", name: "radius", type: "number", defaultValue: 5}, {tfName: "bias", name: "bias", type: "number", defaultValue: 1}, {tfName: "alpha", name: "alpha", type: "number", defaultValue: 1}, {tfName: "beta", name: "beta", type: "number", defaultValue: 0.5}]}, {tfOpName: "Softmax", category: "normalization", inputs: [{start: 0, name: "x", type: "tensor"}]}, {tfOpName: "LogSoftmax", category: "normalization", inputs: [{start: 0, name: "x", type: "tensor"}]}, {tfOpName: "SparseToDense", category: "normalization", inputs: [{start: 0, name: "sparseIndices", type: "tensor"}, {start: 1, name: "outputShape", type: "number[]"}, {start: 2, name: "sparseValues", type: "tensor"}, {start: 3, name: "defaultValue", type: "tensor"}], attrs: [{tfName: "validate_indices", name: "validateIndices", type: "bool", defaultValue: true, notSupported: true}]}], KD = {__proto__: null, json: YD};
var jD = [{tfOpName: "Max", category: "reduction", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "axis", type: "number[]"}], attrs: [{tfName: "keep_dims", name: "keepDims", type: "bool"}]}, {tfOpName: "Mean", category: "reduction", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "axis", type: "number[]"}], attrs: [{tfName: "keep_dims", name: "keepDims", type: "bool"}]}, {tfOpName: "Min", category: "reduction", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "axis", type: "number[]"}], attrs: [{tfName: "keep_dims", name: "keepDims", type: "bool"}]}, {tfOpName: "Sum", category: "reduction", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "axis", type: "number[]"}], attrs: [{tfName: "keep_dims", name: "keepDims", type: "bool"}]}, {tfOpName: "All", category: "reduction", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "axis", type: "number[]"}], attrs: [{tfName: "keep_dims", name: "keepDims", type: "bool"}]}, {tfOpName: "Any", category: "reduction", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "axis", type: "number[]"}], attrs: [{tfName: "keep_dims", name: "keepDims", type: "bool"}]}, {tfOpName: "ArgMax", category: "reduction", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "axis", type: "number"}]}, {tfOpName: "ArgMin", category: "reduction", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "axis", type: "number"}]}, {tfOpName: "Prod", category: "reduction", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "axis", type: "number[]"}], attrs: [{tfName: "keep_dims", name: "keepDims", type: "bool"}]}, {tfOpName: "Cumsum", category: "reduction", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "axis", type: "number"}], attrs: [{tfName: "exclusive", name: "exclusive", type: "bool"}, {tfName: "reverse", name: "reverse", type: "bool"}]}], $D = {__proto__: null, json: jD};
var XD = [{tfOpName: "ConcatV2", category: "slice_join", inputs: [{start: 0, end: -1, name: "tensors", type: "tensors"}, {start: -1, name: "axis", type: "number"}], attrs: [{tfName: "N", name: "n", type: "number", defaultValue: 2}]}, {tfOpName: "Concat", category: "slice_join", inputs: [{start: 1, end: 0, name: "tensors", type: "tensors"}, {start: 0, name: "axis", type: "number"}], attrs: [{tfName: "N", name: "n", type: "number", defaultValue: 2}]}, {tfOpName: "GatherV2", category: "slice_join", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "indices", type: "tensor"}, {start: 2, name: "axis", type: "number", defaultValue: 0}]}, {tfOpName: "Gather", category: "slice_join", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "indices", type: "tensor"}], attrs: [{tfName: "axis", name: "axis", type: "number", defaultValue: 0}, {tfName: "validate_indices", name: "validateIndices", type: "bool", notSupported: true}]}, {tfOpName: "Reverse", category: "slice_join", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "dims", type: "bool", notSupported: true}]}, {tfOpName: "ReverseV2", category: "slice_join", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "axis", type: "number[]"}]}, {tfOpName: "Slice", category: "slice_join", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "begin", type: "number[]"}, {start: 2, name: "size", type: "number[]"}]}, {tfOpName: "StridedSlice", category: "slice_join", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "begin", type: "number[]"}, {start: 2, name: "end", type: "number[]"}, {start: 3, name: "strides", type: "number[]"}], attrs: [{tfName: "begin_mask", name: "beginMask", type: "number", defaultValue: 0}, {tfName: "end_mask", name: "endMask", type: "number", defaultValue: 0}, {tfName: "new_axis_mask", name: "newAxisMask", type: "number", defaultValue: 0}, {tfName: "ellipsis_mask", name: "ellipsisMask", type: "number", defaultValue: 0}, {tfName: "shrink_axis_mask", name: "shrinkAxisMask", type: "number", defaultValue: 0}]}, {tfOpName: "Pack", category: "slice_join", inputs: [{start: 0, end: 0, name: "tensors", type: "tensors"}], attrs: [{tfName: "axis", name: "axis", type: "number", defaultValue: 0}]}, {tfOpName: "Unpack", category: "slice_join", inputs: [{start: 0, name: "tensor", type: "tensor"}], attrs: [{tfName: "axis", name: "axis", type: "number", defaultValue: 0}, {tfName: "num", name: "num", type: "number", defaultValue: 0, notSupported: true}]}, {tfOpName: "Tile", category: "slice_join", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "reps", type: "number[]"}]}, {tfOpName: "Split", category: "slice_join", inputs: [{start: 0, name: "axis", type: "number", defaultValue: 0}, {start: 1, name: "x", type: "tensor"}], attrs: [{tfName: "num_split", name: "numOrSizeSplits", type: "number", defaultValue: 1}]}, {tfOpName: "SplitV", category: "slice_join", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "numOrSizeSplits", type: "number[]"}, {start: 2, name: "axis", type: "number", defaultValue: 0}]}, {tfOpName: "ScatterNd", category: "slice_join", inputs: [{start: 0, name: "indices", type: "tensor"}, {start: 1, name: "values", type: "tensor"}, {start: 2, name: "shape", type: "number[]"}]}, {tfOpName: "GatherNd", category: "slice_join", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "indices", type: "tensor"}]}, {tfOpName: "SparseToDense", category: "slice_join", inputs: [{start: 0, name: "sparseIndices", type: "tensor"}, {start: 1, name: "outputShape", type: "number[]"}, {start: 2, name: "sparseValues", type: "tensor"}, {start: 3, name: "defaultValue", type: "tensor"}], attrs: [{tfName: "validate_indices", name: "validateIndices", type: "bool", defaultValue: false, notSupported: true}]}], JD = {__proto__: null, json: XD};
var ZD = [{tfOpName: "FFT", category: "spectral", inputs: [{start: 0, name: "x", type: "tensor"}]}, {tfOpName: "IFFT", category: "spectral", inputs: [{start: 0, name: "x", type: "tensor"}]}, {tfOpName: "RFFT", category: "spectral", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "fft_length", type: "number", notSupported: true}]}, {tfOpName: "IRFFT", category: "spectral", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "fft_length", type: "number", notSupported: true}]}], QD = {__proto__: null, json: ZD};
var ek = [{tfOpName: "Cast", category: "transformation", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "SrcT", name: "sdtype", type: "dtype", notSupported: true}, {tfName: "DstT", name: "dtype", type: "dtype"}]}, {tfOpName: "ExpandDims", category: "transformation", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "axis", type: "number"}]}, {tfOpName: "MirrorPad", category: "transformation", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "padding", type: "number[]"}], attrs: [{tfName: "mode", name: "mode", type: "string"}]}, {tfOpName: "Pad", category: "transformation", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "padding", type: "number[]"}], attrs: [{tfName: "constant_value", name: "constantValue", type: "number", defaultValue: 0}]}, {tfOpName: "PadV2", category: "transformation", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "padding", type: "number[]"}, {start: 2, name: "constantValue", type: "number", defaultValue: 0}]}, {tfOpName: "Reshape", category: "transformation", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "shape", type: "number[]"}]}, {tfOpName: "Squeeze", category: "transformation", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "axis", tfDeprecatedName: "squeeze_dims", name: "axis", type: "number[]"}]}, {tfOpName: "SpaceToBatchND", category: "transformation", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "blockShape", type: "number[]"}, {start: 2, name: "paddings", type: "number[]"}]}, {tfOpName: "BatchToSpaceND", category: "transformation", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "blockShape", type: "number[]"}, {start: 2, name: "crops", type: "number[]"}]}, {tfOpName: "DepthToSpace", category: "transformation", inputs: [{start: 0, name: "x", type: "tensor"}], attrs: [{tfName: "block_size", name: "blockSize", type: "number"}, {tfName: "data_format", name: "dataFormat", type: "string"}]}, {tfOpName: "BroadcastTo", category: "transformation", inputs: [{start: 0, name: "x", type: "tensor"}, {start: 1, name: "shape", type: "number[]"}], attrs: []}], tk = {__proto__: null, json: ek};
var f1 = function() {
function n() {
var t = [SD, AD, ND, CD, OD, DD, FD, VD, MD, UD, qD, KD, $D, JD, QD, tk, zD], e = [].concat.apply([], Rr(t.map(function(r) {
return r.json;
})));
this.opMappers = e.reduce(function(r, i) {
return r[i.tfOpName] = i, r;
}, {});
}
return Object.defineProperty(n, "Instance", {get: function() {
return this._instance || (this._instance = new this());
}, enumerable: true, configurable: true}), n.prototype.transformGraph = function(t, e) {
var r = this;
e === void 0 && (e = {});
var i = t.node, a = [], s = [], o = [], c = i.reduce(function(g, y) {
return g[y.name] = r.mapNode(y), y.op.startsWith("Placeholder") ? a.push(g[y.name]) : y.op === "Const" ? s.push(g[y.name]) : (y.input == null || y.input.length === 0) && o.push(g[y.name]), g;
}, {}), l = [], u = [], h = {}, d = {};
e != null && (h = this.mapSignatureEntries(e.inputs), d = this.mapSignatureEntries(e.outputs));
var p = Object.keys(c);
p.forEach(function(g) {
var y = c[g];
y.inputNames.forEach(function(w) {
var b = gt(er(w), 1), x = b[0];
y.inputs.push(c[x]), c[x].children.push(y);
});
}), Object.keys(d).length === 0 ? p.forEach(function(g) {
var y = c[g];
y.children.length === 0 && u.push(y);
}) : Object.keys(d).forEach(function(g) {
var y = gt(er(g), 1), w = y[0], b = c[w];
b != null && (b.signatureKey = d[g], u.push(b));
}), Object.keys(h).length > 0 ? Object.keys(h).forEach(function(g) {
var y = gt(er(g), 1), w = y[0], b = c[w];
b && (b.signatureKey = h[g], l.push(b));
}) : l = a;
var f = {};
t.library != null && t.library.function != null && (f = t.library.function.reduce(function(g, y) {
return g[y.signature.name] = r.mapFunction(y), g;
}, {}));
var m = {nodes: c, inputs: l, outputs: u, weights: s, placeholders: a, signature: e, functions: f};
return o.length > 0 && (m.initNodes = o), m;
}, n.prototype.mapSignatureEntries = function(t) {
return Object.keys(t || {}).reduce(function(e, r) {
return e[t[r].name] = r, e;
}, {});
}, n.prototype.mapNode = function(t) {
var e = d1(t.op) || this.opMappers[t.op] || {};
t.attr == null && (t.attr = {});
var r = {name: t.name, op: t.op, category: e.category, inputNames: (t.input || []).map(function(i) {
return i.startsWith("^") ? i.substr(1) : i;
}), inputs: [], children: [], inputParams: {}, attrParams: {}, rawAttrs: t.attr};
return e.inputs != null && (r.inputParams = e.inputs.reduce(function(i, a) {
return i[a.name] = {type: a.type, inputIndexStart: a.start, inputIndexEnd: a.end}, i;
}, {})), e.attrs != null && (r.attrParams = e.attrs.reduce(function(i, a) {
var s = a.type, o = void 0;
switch (a.type) {
case "string":
o = ld(t.attr, a.tfName, a.defaultValue), o === void 0 && !!a.tfDeprecatedName && (o = ld(t.attr, a.tfDeprecatedName, a.defaultValue));
break;
case "string[]":
o = yd(t.attr, a.tfName, a.defaultValue), o === void 0 && !!a.tfDeprecatedName && (o = yd(t.attr, a.tfDeprecatedName, a.defaultValue));
break;
case "number":
o = hd(t.attr, a.tfName, a.defaultValue || 0), o === void 0 && !!a.tfDeprecatedName && (o = hd(t.attr, a.tfDeprecatedName, a.defaultValue));
break;
case "number[]":
o = gd(t.attr, a.tfName, a.defaultValue), o === void 0 && !!a.tfDeprecatedName && (o = gd(t.attr, a.tfDeprecatedName, a.defaultValue));
break;
case "bool":
o = ud(t.attr, a.tfName, a.defaultValue), o === void 0 && !!a.tfDeprecatedName && (o = ud(t.attr, a.tfDeprecatedName, a.defaultValue));
break;
case "bool[]":
o = wd(t.attr, a.tfName, a.defaultValue), o === void 0 && !!a.tfDeprecatedName && (o = wd(t.attr, a.tfDeprecatedName, a.defaultValue));
break;
case "shape":
o = md(t.attr, a.tfName, a.defaultValue), o === void 0 && !!a.tfDeprecatedName && (o = md(t.attr, a.tfDeprecatedName, a.defaultValue));
break;
case "shape[]":
o = vd(t.attr, a.tfName, a.defaultValue), o === void 0 && !!a.tfDeprecatedName && (o = vd(t.attr, a.tfDeprecatedName, a.defaultValue));
break;
case "dtype":
o = pd(t.attr, a.tfName, a.defaultValue), o === void 0 && !!a.tfDeprecatedName && (o = pd(t.attr, a.tfDeprecatedName, a.defaultValue));
break;
case "dtype[]":
o = fd(t.attr, a.tfName, a.defaultValue), o === void 0 && !!a.tfDeprecatedName && (o = fd(t.attr, a.tfDeprecatedName, a.defaultValue));
break;
case "func":
o = p1(t.attr, a.tfName, a.defaultValue), o === void 0 && !!a.tfDeprecatedName && (o = p1(t.attr, a.tfDeprecatedName, a.defaultValue));
break;
case "tensor":
case "tensors":
break;
default:
throw new Error("Unsupported param type: " + a.type + " for op: " + t.op);
}
return i[a.name] = {value: o, type: s}, i;
}, {})), r;
}, n.prototype.mapFunction = function(t) {
var e = this, r = t.nodeDef, i = [], a = [], s = {};
r != null && (s = r.reduce(function(d, p) {
return d[p.name] = e.mapNode(p), p.op === "Const" && a.push(d[p.name]), d;
}, {}));
var o = [], c = [];
t.signature.inputArg.forEach(function(d) {
var p = gt(er(d.name), 1), f = p[0], m = {name: f, op: "Placeholder", inputs: [], inputNames: [], category: "graph", inputParams: {}, attrParams: {dtype: {value: dd(d.type), type: "dtype"}}, children: []};
m.signatureKey = d.name, o.push(m), s[f] = m;
});
var l = Object.keys(s);
l.forEach(function(d) {
var p = s[d];
p.inputNames.forEach(function(f) {
var m = gt(er(f), 1), g = m[0];
p.inputs.push(s[g]), s[g].children.push(p);
});
});
var u = t.ret;
t.signature.outputArg.forEach(function(d) {
var p = gt(er(u[d.name]), 2), f = p[0], m = p[1], g = s[f];
g != null && (g.defaultOutput = m, c.push(g));
});
var h = this.mapArgsToSignature(t);
return {nodes: s, inputs: o, outputs: c, weights: a, placeholders: i, signature: h};
}, n.prototype.mapArgsToSignature = function(t) {
var e = this;
return {methodName: t.signature.name, inputs: t.signature.inputArg.reduce(function(r, i) {
return r[i.name] = e.mapArgToTensorInfo(i), r;
}, {}), outputs: t.signature.outputArg.reduce(function(r, i) {
return r[i.name] = e.mapArgToTensorInfo(i, t.ret), r;
}, {})};
}, n.prototype.mapArgToTensorInfo = function(t, e) {
var r = t.name;
return e != null && (r = e[r]), {name: r, dtype: t.type};
}, n;
}();
function nk(n) {
var t = W.env().global;
if (typeof t.atob != "undefined")
return t.atob(n);
if (typeof Buffer != "undefined")
return new Buffer(n, "base64").toString();
throw new Error("Unable to decode base64 in this environment. Missing built-in atob() or Buffer()");
}
function m1(n, t) {
var e = Array.isArray(n) ? String.fromCharCode.apply(null, n) : nk(n);
return t ? e : e.toLowerCase();
}
function ld(n, t, e, r) {
r === void 0 && (r = false);
var i = n[t];
return i != null ? m1(i.s, r) : e;
}
function ud(n, t, e) {
var r = n[t];
return r ? r.b : e;
}
function hd(n, t, e) {
var r = n[t] || {}, i = r.i != null ? r.i : r.f != null ? r.f : e;
return typeof i == "number" ? i : parseInt(i, 10);
}
function dd(n) {
typeof n == "string" && (n = In[n]);
switch (n) {
case In.DT_FLOAT:
return "float32";
case In.DT_INT32:
case In.DT_INT64:
case In.DT_INT8:
case In.DT_UINT8:
return "int32";
case In.DT_BOOL:
return "bool";
case In.DT_DOUBLE:
return "float32";
case In.DT_STRING:
return "string";
default:
return null;
}
}
function p1(n, t, e) {
var r = n[t];
return r && r.func ? r.func.name : e;
}
function pd(n, t, e) {
var r = n[t];
return r && r.type ? dd(r.type) : e;
}
function fd(n, t, e) {
var r = n[t];
return r && r.list && r.list.type ? r.list.type.map(function(i) {
return dd(i);
}) : e;
}
function g1(n) {
return n.unknownRank ? void 0 : n.dim != null ? n.dim.map(function(t) {
return typeof t.size == "number" ? t.size : parseInt(t.size, 10);
}) : [];
}
function md(n, t, e) {
var r = n[t];
return r && r.shape ? g1(r.shape) : e;
}
function gd(n, t, e) {
var r = n[t];
return r ? ((r.list.f && r.list.f.length ? r.list.f : r.list.i) || []).map(function(i) {
return typeof i == "number" ? i : parseInt(i, 10);
}) : e;
}
function yd(n, t, e, r) {
r === void 0 && (r = false);
var i = n[t];
return i && i.list && i.list.s ? i.list.s.map(function(a) {
return m1(a, r);
}) : e;
}
function vd(n, t, e) {
var r = n[t];
return r && r.list && r.list.shape ? r.list.shape.map(function(i) {
return g1(i);
}) : e;
}
function wd(n, t, e) {
var r = n[t];
return r && r.list && r.list.b ? r.list.b : e;
}
var rk = function() {
function n(t, e, r) {
var i = this;
this.node = t, this.tensorMap = e, this.context = r, this.inputs = [], this.attrs = {}, this.inputs = t.inputNames.map(function(a) {
return i.getInput(a);
}), t.rawAttrs != null && (this.attrs = Object.keys(t.rawAttrs).reduce(function(a, s) {
return a[s] = i.getAttr(s), a;
}, {}));
}
return n.prototype.getInput = function(t) {
return Gt(t, this.tensorMap, this.context);
}, n.prototype.getAttr = function(t, e) {
var r = this.node.rawAttrs[t];
if (r.tensor != null)
return Gt(t, this.tensorMap, this.context);
if (r.i != null || r.f != null)
return hd(this.node.rawAttrs, t, e);
if (r.s != null)
return ld(this.node.rawAttrs, t, e);
if (r.b != null)
return ud(this.node.rawAttrs, t, e);
if (r.shape != null)
return md(this.node.rawAttrs, t, e);
if (r.type != null)
return pd(this.node.rawAttrs, t, e);
if (r.list != null) {
if (r.list.i != null || r.list.f != null)
return gd(this.node.rawAttrs, t, e);
if (r.list.s != null)
return yd(this.node.rawAttrs, t, e);
if (r.list.shape != null)
return vd(this.node.rawAttrs, t, e);
if (r.list.b != null)
return wd(this.node.rawAttrs, t, e);
if (r.list.type != null)
return fd(this.node.rawAttrs, t, e);
}
return e;
}, n;
}();
var ik = function(n, t, e) {
switch (n.op) {
case "BiasAdd":
case "AddV2":
case "Add":
return [W.add(T("a", n, t, e), T("b", n, t, e))];
case "AddN":
return [W.addN(T("tensors", n, t, e))];
case "FloorMod":
case "Mod":
return [W.mod(T("a", n, t, e), T("b", n, t, e))];
case "Mul":
return [W.mul(T("a", n, t, e), T("b", n, t, e))];
case "RealDiv":
case "Div":
return [W.div(T("a", n, t, e), T("b", n, t, e))];
case "DivNoNan":
return [W.divNoNan(T("a", n, t, e), T("b", n, t, e))];
case "FloorDiv":
return [W.floorDiv(T("a", n, t, e), T("b", n, t, e))];
case "Sub":
return [W.sub(T("a", n, t, e), T("b", n, t, e))];
case "Minimum":
return [W.minimum(T("a", n, t, e), T("b", n, t, e))];
case "Maximum":
return [W.maximum(T("a", n, t, e), T("b", n, t, e))];
case "Pow":
return [W.pow(T("a", n, t, e), T("b", n, t, e))];
case "SquaredDifference":
return [W.squaredDifference(T("a", n, t, e), T("b", n, t, e))];
default:
throw TypeError("Node type " + n.op + " is not implemented");
}
};
var ak = function(n, t, e) {
switch (n.op) {
case "Abs":
case "ComplexAbs":
return [W.abs(T("x", n, t, e))];
case "Acos":
return [W.acos(T("x", n, t, e))];
case "Acosh":
return [W.acosh(T("x", n, t, e))];
case "Asin":
return [W.asin(T("x", n, t, e))];
case "Asinh":
return [W.asinh(T("x", n, t, e))];
case "Atan":
return [W.atan(T("x", n, t, e))];
case "Atan2":
return [W.atan2(T("x", n, t, e), T("y", n, t, e))];
case "Atanh":
return [W.atanh(T("x", n, t, e))];
case "Ceil":
return [W.ceil(T("x", n, t, e))];
case "Complex":
return [W.complex(T("real", n, t, e), T("imag", n, t, e))];
case "Cos":
return [W.cos(T("x", n, t, e))];
case "Cosh":
return [W.cosh(T("x", n, t, e))];
case "Elu":
return [W.elu(T("x", n, t, e))];
case "Erf":
return [W.erf(T("x", n, t, e))];
case "Exp":
return [W.exp(T("x", n, t, e))];
case "Expm1":
return [W.expm1(T("x", n, t, e))];
case "Floor":
return [W.floor(T("x", n, t, e))];
case "Log":
return [W.log(T("x", n, t, e))];
case "Log1p":
return [W.log1p(T("x", n, t, e))];
case "Imag":
return [W.imag(T("x", n, t, e))];
case "Neg":
return [W.neg(T("x", n, t, e))];
case "Reciprocal":
return [W.reciprocal(T("x", n, t, e))];
case "Real":
return [W.real(T("x", n, t, e))];
case "Relu":
return [W.relu(T("x", n, t, e))];
case "Round":
return [W.round(T("x", n, t, e))];
case "Selu":
return [W.selu(T("x", n, t, e))];
case "Sigmoid":
return [W.sigmoid(T("x", n, t, e))];
case "Sin":
return [W.sin(T("x", n, t, e))];
case "Sign":
return [W.sign(T("x", n, t, e))];
case "Sinh":
return [W.sinh(T("x", n, t, e))];
case "Softplus":
return [W.softplus(T("x", n, t, e))];
case "Sqrt":
return [W.sqrt(T("x", n, t, e))];
case "Square":
return [W.square(T("x", n, t, e))];
case "Tanh":
return [W.tanh(T("x", n, t, e))];
case "Tan":
return [W.tan(T("x", n, t, e))];
case "Relu6":
case "ClipByValue":
return [W.clipByValue(T("x", n, t, e), T("clipValueMin", n, t, e), T("clipValueMax", n, t, e))];
case "Rsqrt":
return [W.rsqrt(Gt(n.inputNames[0], t, e))];
case "Prod":
return [W.prod(T("x", n, t, e), T("axes", n, t, e))];
case "LeakyRelu":
return [W.leakyRelu(T("x", n, t, e), T("alpha", n, t, e))];
case "Prelu":
return [W.prelu(T("x", n, t, e), T("alpha", n, t, e))];
default:
throw TypeError("Node type " + n.op + " is not implemented");
}
};
function dn(n, t, e) {
e === void 0 && (e = ""), W.util.assert(sk(n, t), function() {
return e + (" Shapes " + n + " and " + t + " must match");
});
}
function sk(n, t) {
if (n.length !== t.length)
return false;
for (var e = 0; e < n.length; e++)
if (n[e] !== -1 && t[e] !== -1 && n[e] !== t[e])
return false;
return true;
}
var ok = function() {
function n(t, e, r, i, a, s, o) {
this.name = t, this.dtype = e, this.maxSize = r, this.elementShape = i, this.identicalElementShapes = a, this.dynamicSize = s, this.clearAfterRead = o, this.tensors = [], this.closed_ = false, this.idTensor = W.scalar(0), W.keep(this.idTensor);
}
return Object.defineProperty(n.prototype, "id", {get: function() {
return this.idTensor.id;
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "closed", {get: function() {
return this.closed_;
}, enumerable: true, configurable: true}), n.prototype.clearAndClose = function(t) {
this.tensors.forEach(function(e) {
(t == null || !t.has(e.tensor.id)) && e.tensor.dispose();
}), this.tensors = [], this.closed_ = true, this.idTensor.dispose();
}, n.prototype.size = function() {
return this.tensors.length;
}, n.prototype.read = function(t) {
if (this.closed_)
throw new Error("TensorArray " + this.name + " has already been closed.");
if (t < 0 || t >= this.size())
throw new Error("Tried to read from index " + t + ", but array size is: " + this.size());
var e = this.tensors[t];
if (e.cleared)
throw new Error("TensorArray " + this.name + ": Could not read index " + t + " twice because it was cleared after a previous read (perhaps try setting clear_after_read = false?).");
return this.clearAfterRead && (e.cleared = true), e.read = true, e.tensor;
}, n.prototype.readMany = function(t) {
var e = this;
return t.map(function(r) {
return e.read(r);
});
}, n.prototype.write = function(t, e) {
if (this.closed_)
throw new Error("TensorArray " + this.name + " has already been closed.");
if (t < 0 || !this.dynamicSize && t >= this.maxSize)
throw new Error("Tried to write to index " + t + ", but array is not resizeable and size is: " + this.maxSize);
var r = this.tensors[t] || {};
if (e.dtype !== this.dtype)
throw new Error("TensorArray " + this.name + ": Could not write to TensorArray index " + t + `,
because the value dtype is ` + e.dtype + ", but TensorArray dtype is " + this.dtype + ".");
if (this.size() === 0 && (this.elementShape == null || this.elementShape.length === 0) && (this.elementShape = e.shape), dn(this.elementShape, e.shape, "TensorArray " + this.name + ": Could not write to TensorArray index " + t + "."), r.read)
throw new Error("TensorArray " + this.name + ": Could not write to TensorArray index " + t + ", because it has already been read.");
if (r.written)
throw new Error("TensorArray " + this.name + ": Could not write to TensorArray index " + t + ", because it has already been written.");
r.tensor = e, W.keep(e), r.written = true, this.tensors[t] = r;
}, n.prototype.writeMany = function(t, e) {
var r = this;
if (t.length !== e.length)
throw new Error("TensorArray " + this.name + ": could not write multiple tensors," + ("because the index size: " + t.length + " is not the same as tensors size: " + e.length + "."));
t.forEach(function(i, a) {
return r.write(i, e[a]);
});
}, n.prototype.gather = function(t, e) {
if (!!e && e !== this.dtype)
throw new Error("TensorArray dtype is " + this.dtype + " but gather requested dtype " + e);
if (t)
t = t.slice(0, this.size());
else {
t = [];
for (var r = 0; r < this.size(); r++)
t.push(r);
}
if (t.length === 0)
return W.tensor([], [0].concat(this.elementShape));
var i = this.readMany(t);
return dn(this.elementShape, i[0].shape, "TensorArray shape mismatch: "), W.stack(i, 0);
}, n.prototype.concat = function(t) {
if (!!t && t !== this.dtype)
throw new Error("TensorArray dtype is " + this.dtype + " but concat requested dtype " + t);
if (this.size() === 0)
return W.tensor([], [0].concat(this.elementShape));
for (var e = [], r = 0; r < this.size(); r++)
e.push(r);
var i = this.readMany(e);
return dn(this.elementShape, i[0].shape, "TensorArray shape mismatch: tensor array shape (" + this.elementShape + ") vs first tensor shape (" + i[0].shape + ")"), W.concat(i, 0);
}, n.prototype.scatter = function(t, e) {
if (e.dtype !== this.dtype)
throw new Error("TensorArray dtype is " + this.dtype + " but tensor has dtype " + e.dtype);
if (t.length !== e.shape[0])
throw new Error("Expected len(indices) == tensor.shape[0], but saw: " + t.length + " vs. " + e.shape[0]);
var r = Math.max.apply(Math, Rr(t));
if (!this.dynamicSize && r >= this.maxSize)
throw new Error("Max index must be < array size (" + r + " vs. " + this.maxSize + ")");
this.writeMany(t, W.unstack(e, 0));
}, n.prototype.split = function(t, e) {
var r = this;
if (e.dtype !== this.dtype)
throw new Error("TensorArray dtype is " + this.dtype + " but tensor has dtype " + e.dtype);
var i = 0, a = t.map(function(u) {
return i += u, i;
});
if (i !== e.shape[0])
throw new Error(`Expected sum of lengths to be equal to
tensor.shape[0], but sum of lengths is
` + i + ", and tensor's shape is: " + e.shape);
if (!this.dynamicSize && t.length !== this.maxSize)
throw new Error("TensorArray's size is not equal to the size of lengths (" + this.maxSize + " vs. " + t.length + "), and the TensorArray is not marked as dynamically resizeable");
var s = i === 0 ? 0 : e.size / i, o = [];
W.tidy(function() {
e = W.reshape(e, [1, i, s]);
for (var u = 0; u < t.length; ++u) {
var h = u === 0 ? 0 : a[u - 1], d = [0, h, 0], p = [1, t[u], s];
o[u] = W.reshape(W.slice(e, d, p), r.elementShape);
}
return o;
});
for (var c = [], l = 0; l < t.length; l++)
c[l] = l;
this.writeMany(c, o);
}, n;
}();
var Do = function() {
function n(t, e, r, i) {
i === void 0 && (i = -1), this.tensors = t, this.elementShape = e, this.elementDtype = r, t != null && t.forEach(function(a) {
if (r !== a.dtype)
throw new Error("Invalid data types; op elements " + r + ", but list elements " + a.dtype);
dn(e, a.shape, "TensorList shape mismatch: "), W.keep(a);
}), this.idTensor = W.scalar(0), this.maxNumElements = i, W.keep(this.idTensor);
}
return Object.defineProperty(n.prototype, "id", {get: function() {
return this.idTensor.id;
}, enumerable: true, configurable: true}), n.prototype.copy = function() {
return new n(Rr(this.tensors), this.elementShape, this.elementDtype);
}, n.prototype.clearAndClose = function(t) {
this.tensors.forEach(function(e) {
(t == null || !t.has(e.id)) && e.dispose();
}), this.tensors.length = 0, this.idTensor.dispose();
}, n.prototype.size = function() {
return this.tensors.length;
}, n.prototype.stack = function(t, e, r) {
var i = this;
if (r === void 0 && (r = -1), e !== this.elementDtype)
throw new Error("Invalid data types; op elements " + e + ", but list elements " + this.elementDtype);
if (r !== -1 && this.tensors.length !== r)
throw new Error("Operation expected a list with " + r + " elements but got a list with " + this.tensors.length + " elements.");
return dn(t, this.elementShape, "TensorList shape mismatch: "), W.tidy(function() {
var a = i.tensors.map(function(s) {
return W.reshape(s, t);
});
return W.stack(a, 0);
});
}, n.prototype.popBack = function(t, e) {
if (e !== this.elementDtype)
throw new Error("Invalid data types; op elements " + e + ", but list elements " + this.elementDtype);
if (this.size() === 0)
throw new Error("Trying to pop from an empty list.");
var r = this.tensors.pop();
return dn(r.shape, t, "TensorList shape mismatch: "), W.reshape(r, t);
}, n.prototype.pushBack = function(t) {
if (t.dtype !== this.elementDtype)
throw new Error("Invalid data types; op elements " + t.dtype + ", but list elements " + this.elementDtype);
if (dn(t.shape, this.elementShape, "TensorList shape mismatch: "), this.maxNumElements === this.size())
throw new Error("Trying to push element into a full list.");
W.keep(t), this.tensors.push(t);
}, n.prototype.resize = function(t) {
if (t < 0)
throw new Error("TensorListResize expects size to be non-negative. Got: " + t);
if (this.maxNumElements !== -1 && t > this.maxNumElements)
throw new Error("TensorListResize input size " + t + " is greater maxNumElement " + this.maxNumElements + ".");
this.tensors.length = t;
}, n.prototype.getItem = function(t, e, r) {
if (r !== this.elementDtype)
throw new Error("Invalid data types; op elements " + r + ", but list elements " + this.elementDtype);
if (t < 0 || t > this.tensors.length)
throw new Error("Trying to access element " + t + " in a list with " + this.tensors.length + " elements.");
if (this.tensors[t] == null)
throw new Error("element at index " + t + " is null.");
return dn(this.tensors[t].shape, e, "TensorList shape mismatch: "), this.tensors[t];
}, n.prototype.setItem = function(t, e) {
if (e.dtype !== this.elementDtype)
throw new Error("Invalid data types; op elements " + e.dtype + ", but list elements " + this.elementDtype);
if (t < 0 || this.maxNumElements !== -1 && t >= this.maxNumElements)
throw new Error("Trying to set element " + t + " in a list with max " + this.maxNumElements + " elements.");
dn(this.elementShape, e.shape, "TensorList shape mismatch: "), W.keep(e), this.tensors[t] = e;
}, n.prototype.gather = function(t, e, r) {
var i = this;
if (e !== this.elementDtype)
throw new Error("Invalid data types; op elements " + e + ", but list elements " + this.elementDtype);
return dn(this.elementShape, r, "TensorList shape mismatch: "), t = t.slice(0, this.size()), t.length === 0 ? W.tensor([], [0].concat(this.elementShape)) : W.tidy(function() {
var a = t.map(function(s) {
return W.reshape(i.tensors[s], r);
});
return W.stack(a, 0);
});
}, n.prototype.concat = function(t, e) {
var r = this;
if (!!t && t !== this.elementDtype)
throw new Error("TensorList dtype is " + this.elementDtype + " but concat requested dtype " + t);
return dn(this.elementShape, e, "TensorList shape mismatch: "), this.size() === 0 ? W.tensor([], [0].concat(this.elementShape)) : W.tidy(function() {
var i = r.tensors.map(function(a) {
return W.reshape(a, e);
});
return W.concat(i, 0);
});
}, n;
}();
function ck(n, t, e) {
var r = n.dtype;
if (n.shape.length < 1)
throw new Error("Tensor must be at least a vector, but saw shape: " + n.shape);
if (n.dtype !== e)
throw new Error("Invalid data types; op elements " + n.dtype + ", but list elements " + e);
var i = n.shape.slice(1);
dn(i, t, "TensorList shape mismatch: ");
var a = W.unstack(n);
return new Do(a, t, r);
}
function lk(n, t, e) {
return new Do([], n, t, e);
}
function uk(n, t, e, r) {
if (t.length !== n.shape[0])
throw new Error("Expected len(indices) == tensor.shape[0], but saw: " + t.length + " vs. " + n.shape[0]);
var i = Math.max.apply(Math, Rr(t));
if (r != null && r !== -1 && i >= r)
throw new Error("Max index must be < array size (" + i + " vs. " + r + ")");
var a = new Do([], e, n.dtype, r), s = W.unstack(n, 0);
return t.forEach(function(o, c) {
a.setItem(o, s[c]);
}), a;
}
function hk(n, t, e) {
var r = 0, i = t.map(function(l) {
return r += l, r;
});
if (r !== n.shape[0])
throw new Error(`Expected sum of lengths to be equal to
tensor.shape[0], but sum of lengths is
` + r + ", and tensor's shape is: " + n.shape);
for (var a = r === 0 ? 0 : n.size / r, s = W.tidy(function() {
var l = [];
n = W.reshape(n, [1, r, a]);
for (var u = 0; u < t.length; ++u) {
var h = u === 0 ? 0 : i[u - 1], d = [0, h, 0], p = [1, t[u], a];
l[u] = W.reshape(W.slice(n, d, p), e);
}
return n.dispose(), l;
}), o = new Do([], e, n.dtype, t.length), c = 0; c < s.length; c++)
o.setItem(c, s[c]);
return o;
}
var dk = void 0, pk = function(n, t, e) {
return on(dk, void 0, void 0, function() {
var r, i, a, s, o, c, l, u, o, h, d, c, p, f, m, m, g, y, g, w, g, g, g, b, x, L, N, I, C, O, D, F, k, B, V, P, G, j, q, H, J, $, ee, te, ne, re, ie, oe, se, me, ye, ve, Ee, Be, We, Ke, ze, Ie, k, B, ue, Ie, G, L, Qe, ue, te, ne, L, pt, ue, L, He, pt, ue, q, H, L, He, ue, Ie, L, He, pt, ue, Ot, L, He, ue, ie, ue, se, L, Ie, B, ue, Ie, L, Qe, ue, ye, L, ve, ue;
return Qt(this, function(ut) {
switch (ut.label) {
case 0:
r = n.op;
switch (r) {
case "If":
return [3, 1];
case "StatelessIf":
return [3, 1];
case "While":
return [3, 3];
case "StatelessWhile":
return [3, 3];
case "LoopCond":
return [3, 9];
case "Switch":
return [3, 10];
case "Merge":
return [3, 12];
case "Enter":
return [3, 13];
case "Exit":
return [3, 14];
case "NextIteration":
return [3, 15];
case "TensorArrayV3":
return [3, 16];
case "TensorArrayWriteV3":
return [3, 17];
case "TensorArrayReadV3":
return [3, 18];
case "TensorArrayGatherV3":
return [3, 19];
case "TensorArrayScatterV3":
return [3, 20];
case "TensorArrayConcatV3":
return [3, 21];
case "TensorArraySplitV3":
return [3, 22];
case "TensorArraySizeV3":
return [3, 23];
case "TensorArrayCloseV3":
return [3, 24];
case "TensorListSetItem":
return [3, 25];
case "TensorListGetItem":
return [3, 26];
case "TensorListScatterV2":
return [3, 27];
case "TensorListScatter":
return [3, 27];
case "TensorListReserve":
return [3, 28];
case "TensorListGather":
return [3, 29];
case "TensorListStack":
return [3, 30];
case "TensorListFromTensor":
return [3, 31];
case "TensorListConcat":
return [3, 32];
case "TensorListPushBack":
return [3, 33];
case "TensorListPopBack":
return [3, 34];
case "TensorListSplit":
return [3, 35];
}
return [3, 36];
case 1:
return i = T("thenBranch", n, t, e), a = T("elseBranch", n, t, e), s = T("cond", n, t, e), o = T("args", n, t, e), [4, s.data()];
case 2:
return c = ut.sent(), c[0] ? [2, e.functionMap[i].executeFunctionAsync(o, e.tensorArrayMap, e.tensorListMap)] : [2, e.functionMap[a].executeFunctionAsync(o, e.tensorArrayMap, e.tensorListMap)];
case 3:
return l = T("body", n, t, e), u = T("cond", n, t, e), o = T("args", n, t, e), [4, e.functionMap[u].executeFunctionAsync(o, e.tensorArrayMap, e.tensorListMap)];
case 4:
return h = ut.sent(), d = o.map(function(vt) {
return vt.id;
}), [4, h[0].data()];
case 5:
c = ut.sent(), h.forEach(function(vt) {
!vt.kept && d.indexOf(vt.id) === -1 && vt.dispose();
}), p = o, f = function() {
var vt, Te, ht;
return Qt(this, function(ft) {
switch (ft.label) {
case 0:
return vt = p, [4, e.functionMap[l].executeFunctionAsync(p, e.tensorArrayMap, e.tensorListMap)];
case 1:
return p = ft.sent(), Te = p.map(function(Ge) {
return Ge.id;
}), vt.forEach(function(Ge) {
!Ge.kept && d.indexOf(Ge.id) === -1 && Te.indexOf(Ge.id) === -1 && Ge.dispose();
}), [4, e.functionMap[u].executeFunctionAsync(p, e.tensorArrayMap, e.tensorListMap)];
case 2:
return ht = ft.sent(), [4, ht[0].data()];
case 3:
return c = ft.sent(), ht.forEach(function(Ge) {
!Ge.kept && d.indexOf(Ge.id) === -1 && Te.indexOf(Ge.id) === -1 && Ge.dispose();
}), [2];
}
});
}, ut.label = 6;
case 6:
return c[0] ? [5, f()] : [3, 8];
case 7:
return ut.sent(), [3, 6];
case 8:
return [2, p];
case 9:
return m = T("pred", n, t, e), [2, [tr(m)]];
case 10:
return m = T("pred", n, t, e), g = T("data", n, t, e), g.kept || (g = tr(g)), [4, m.data()];
case 11:
return [2, ut.sent()[0] ? [void 0, g] : [g, void 0]];
case 12:
return y = n.inputNames.find(function(vt) {
return Gt(vt, t, e) !== void 0;
}), y ? (g = Gt(y, t, e), [2, [tr(g)]]) : [2, void 0];
case 13:
return w = T("frameName", n, t, e), g = T("tensor", n, t, e), e.enterFrame(w), [2, [tr(g)]];
case 14:
return g = T("tensor", n, t, e), e.exitFrame(), [2, [tr(g)]];
case 15:
return g = T("tensor", n, t, e), e.nextIteration(), [2, [tr(g)]];
case 16:
return b = T("size", n, t, e), x = T("dtype", n, t, e), L = T("elementShape", n, t, e), N = T("dynamicSize", n, t, e), I = T("clearAfterRead", n, t, e), C = T("identicalElementShapes", n, t, e), O = T("name", n, t, e), D = new ok(O, x, b, L, C, N, I), e.addTensorArray(D), [2, [D.idTensor, W.scalar(1)]];
case 17:
return F = T("tensorArrayId", n, t, e), k = T("index", n, t, e), B = T("tensor", n, t, e), V = e.getTensorArray(F.id), V.write(k, B), [2, [V.idTensor]];
case 18:
return P = T("tensorArrayId", n, t, e), G = T("index", n, t, e), j = e.getTensorArray(P.id), [2, [j.read(G)]];
case 19:
return q = T("tensorArrayId", n, t, e), H = T("indices", n, t, e), J = T("dtype", n, t, e), $ = e.getTensorArray(q.id), [2, [$.gather(H, J)]];
case 20:
return ee = T("tensorArrayId", n, t, e), te = T("indices", n, t, e), ne = T("tensor", n, t, e), re = e.getTensorArray(ee.id), re.scatter(te, ne), [2, [re.idTensor]];
case 21:
return ie = T("tensorArrayId", n, t, e), oe = e.getTensorArray(ie.id), se = T("dtype", n, t, e), [2, [oe.concat(se)]];
case 22:
return me = T("tensorArrayId", n, t, e), ye = T("tensor", n, t, e), ve = T("lengths", n, t, e), Ee = e.getTensorArray(me.id), Ee.split(ve, ye), [2, [Ee.idTensor]];
case 23:
return Be = T("tensorArrayId", n, t, e), We = e.getTensorArray(Be.id), [2, [W.scalar(We.size(), "int32")]];
case 24:
return Ke = T("tensorArrayId", n, t, e), ze = e.getTensorArray(Ke.id), ze.clearAndClose(), [2, [ze.idTensor]];
case 25:
return Ie = T("tensorListId", n, t, e), k = T("index", n, t, e), B = T("tensor", n, t, e), ue = e.getTensorList(Ie.id), ue.setItem(k, B), [2, [ue.idTensor]];
case 26:
return Ie = T("tensorListId", n, t, e), G = T("index", n, t, e), L = T("elementShape", n, t, e), Qe = T("elementDType", n, t, e), ue = e.getTensorList(Ie.id), [2, [ue.getItem(G, L, Qe)]];
case 27:
return te = T("indices", n, t, e), ne = T("tensor", n, t, e), L = T("elementShape", n, t, e), pt = T("numElements", n, t, e), ue = uk(ne, te, L, pt), e.addTensorList(ue), [2, [ue.idTensor]];
case 28:
return L = T("elementShape", n, t, e), He = T("elementDType", n, t, e), pt = T("numElements", n, t, e), ue = lk(L, He, pt), e.addTensorList(ue), [2, [ue.idTensor]];
case 29:
return q = T("tensorListId", n, t, e), H = T("indices", n, t, e), L = T("elementShape", n, t, e), He = T("elementDType", n, t, e), ue = e.getTensorList(q.id), [2, [ue.gather(H, He, L)]];
case 30:
return Ie = T("tensorListId", n, t, e), L = T("elementShape", n, t, e), He = T("elementDType", n, t, e), pt = T("numElements", n, t, e), ue = e.getTensorList(Ie.id), [2, [ue.stack(L, He, pt)]];
case 31:
return Ot = T("tensor", n, t, e), L = T("elementShape", n, t, e), He = T("elementDType", n, t, e), ue = ck(Ot, L, He), e.addTensorList(ue), [2, [ue.idTensor]];
case 32:
return ie = T("tensorListId", n, t, e), ue = e.getTensorList(ie.id), se = T("dtype", n, t, e), L = T("elementShape", n, t, e), [2, [ue.concat(se, L)]];
case 33:
return Ie = T("tensorListId", n, t, e), B = T("tensor", n, t, e), ue = e.getTensorList(Ie.id), ue.pushBack(B), [2, [ue.idTensor]];
case 34:
return Ie = T("tensorListId", n, t, e), L = T("elementShape", n, t, e), Qe = T("elementDType", n, t, e), ue = e.getTensorList(Ie.id), [2, [ue.popBack(L, Qe)]];
case 35:
return ye = T("tensor", n, t, e), L = T("elementShape", n, t, e), ve = T("lengths", n, t, e), ue = hk(ye, ve, L), e.addTensorList(ue), [2, [ue.idTensor]];
case 36:
throw TypeError("Node type " + n.op + " is not implemented");
}
});
});
};
function y1(n, t, e) {
var r = gt(T("fusedOps", n, t, e), 2), i = r[0], a = r[1], s = i === "biasadd", o = a === "prelu", c = i === "fusedbatchnorm", l = T("numArgs", n, t, e);
if (s) {
if (o && l !== 2)
throw new Error("FusedConv2d and DepthwiseConv2d with BiasAdd and Prelu must have two extra arguments: bias and alpha.");
if (!o && l !== 1)
throw new Error("FusedConv2d and DepthwiseConv2d with BiasAdd must have one extra argument: bias.");
}
if (c)
throw new Error("FusedConv2d and DepthwiseConv2d with FusedBatchNorm is not supported.");
var u = T("strides", n, t, e), h = Eo(n, t, e), d = T("dataFormat", n, t, e).toUpperCase(), p = T("dilations", n, t, e), f = gt(T("args", n, t, e), 2), m = f[0], g = f[1];
return {stride: u, pad: h, dataFormat: d, dilations: p, biasArg: m, preluArg: g, activationFunc: a};
}
var fk = function(n, t, e) {
switch (n.op) {
case "Conv1D": {
var r = T("stride", n, t, e), i = T("pad", n, t, e), a = T("dataFormat", n, t, e).toUpperCase(), s = T("dilation", n, t, e);
return [W.conv1d(T("x", n, t, e), T("filter", n, t, e), r, i, a, s)];
}
case "Conv2D": {
var r = T("strides", n, t, e), i = Eo(n, t, e), a = T("dataFormat", n, t, e).toUpperCase(), o = T("dilations", n, t, e);
return [W.conv2d(T("x", n, t, e), T("filter", n, t, e), [r[1], r[2]], i, a, [o[1], o[2]])];
}
case "_FusedConv2D": {
var c = y1(n, t, e), r = c.stride, i = c.pad, a = c.dataFormat, o = c.dilations, l = c.biasArg, u = c.preluArg, h = c.activationFunc;
return [W.fused.conv2d({x: T("x", n, t, e), filter: T("filter", n, t, e), strides: [r[1], r[2]], pad: i, dataFormat: a, dilations: [o[1], o[2]], bias: l, activation: h, preluActivationWeights: u})];
}
case "FusedDepthwiseConv2dNative": {
var d = y1(n, t, e), r = d.stride, i = d.pad, a = d.dataFormat, o = d.dilations, l = d.biasArg, u = d.preluArg, h = d.activationFunc;
return [W.fused.depthwiseConv2d({x: T("x", n, t, e), filter: T("filter", n, t, e), strides: [r[1], r[2]], pad: i, dataFormat: a, dilations: [o[1], o[2]], bias: l, activation: h, preluActivationWeights: u})];
}
case "Conv2DBackpropInput":
case "Conv2dTranspose": {
var p = T("outputShape", n, t, e), r = T("strides", n, t, e), i = Eo(n, t, e);
return [W.conv2dTranspose(T("x", n, t, e), T("filter", n, t, e), p, [r[1], r[2]], i)];
}
case "DepthwiseConv2dNative":
case "DepthwiseConv2d": {
var r = T("strides", n, t, e), i = Eo(n, t, e), o = T("dilations", n, t, e), a = T("dataFormat", n, t, e).toUpperCase();
return [W.depthwiseConv2d(T("input", n, t, e), T("filter", n, t, e), [r[1], r[2]], i, a, [o[1], o[2]])];
}
case "Conv3D": {
var r = T("strides", n, t, e), i = T("pad", n, t, e), a = T("dataFormat", n, t, e).toUpperCase(), o = T("dilations", n, t, e);
return [W.conv3d(T("x", n, t, e), T("filter", n, t, e), [r[1], r[2], r[3]], i, a, [o[1], o[2], o[3]])];
}
case "AvgPool": {
var r = T("strides", n, t, e), i = T("pad", n, t, e), f = T("kernelSize", n, t, e);
return [W.avgPool(T("x", n, t, e), [f[1], f[2]], [r[1], r[2]], i)];
}
case "MaxPool": {
var r = T("strides", n, t, e), i = T("pad", n, t, e), f = T("kernelSize", n, t, e);
return [W.maxPool(T("x", n, t, e), [f[1], f[2]], [r[1], r[2]], i)];
}
case "MaxPoolWithArgmax": {
var r = T("strides", n, t, e), i = T("pad", n, t, e), f = T("kernelSize", n, t, e), m = T("includeBatchInIndex", n, t, e), g = W.maxPoolWithArgmax(T("x", n, t, e), [f[1], f[2]], [r[1], r[2]], i, m), y = g.result, w = g.indexes;
return [y, w];
}
case "AvgPool3D": {
var r = T("strides", n, t, e), i = T("pad", n, t, e), f = T("kernelSize", n, t, e);
return [W.avgPool3d(T("x", n, t, e), [f[1], f[2], f[3]], [r[1], r[2], r[3]], i)];
}
case "MaxPool3D": {
var r = T("strides", n, t, e), i = T("pad", n, t, e), f = T("kernelSize", n, t, e);
return [W.maxPool3d(T("x", n, t, e), [f[1], f[2], f[3]], [r[1], r[2], r[3]], i)];
}
case "Dilation2D": {
var b = T("strides", n, t, e), i = T("pad", n, t, e), o = T("dilations", n, t, e), x = b[1], L = b[2], N = o[1], I = o[2];
return [W.dilation2d(T("x", n, t, e), T("filter", n, t, e), [x, L], i, [N, I], "NHWC")];
}
default:
throw TypeError("Node type " + n.op + " is not implemented");
}
};
var mk = function(n, t, e) {
switch (n.op) {
case "Fill": {
var r = T("shape", n, t, e), i = T("dtype", n, t, e), a = T("value", n, t, e);
return [W.fill(r, a, i)];
}
case "LinSpace": {
var s = T("start", n, t, e), o = T("stop", n, t, e), c = T("num", n, t, e);
return [W.linspace(s, o, c)];
}
case "Multinomial": {
var l = T("logits", n, t, e), u = T("numSamples", n, t, e), h = T("seed", n, t, e);
return [W.multinomial(l, u, h)];
}
case "OneHot": {
var d = T("indices", n, t, e), p = T("depth", n, t, e), f = T("onValue", n, t, e), m = T("offValue", n, t, e);
return [W.oneHot(d, p, f, m)];
}
case "Ones":
return [W.ones(T("shape", n, t, e), T("dtype", n, t, e))];
case "OnesLike":
return [W.onesLike(T("x", n, t, e))];
case "RandomUniform":
return [W.randomUniform(T("shape", n, t, e), T("minval", n, t, e), T("maxval", n, t, e), T("dtype", n, t, e))];
case "Range": {
var s = T("start", n, t, e), g = T("stop", n, t, e), y = T("step", n, t, e);
return [W.range(s, g, y, T("dtype", n, t, e))];
}
case "TruncatedNormal": {
var r = T("shape", n, t, e), w = T("mean", n, t, e), b = T("stdDev", n, t, e), h = T("seed", n, t, e);
return [W.truncatedNormal(r, w, b, T("dtype", n, t, e), h)];
}
case "Zeros":
return [W.zeros(T("shape", n, t, e), T("dtype", n, t, e))];
case "ZerosLike":
return [W.zerosLike(T("x", n, t, e))];
default:
throw TypeError("Node type " + n.op + " is not implemented");
}
};
var gk = void 0;
function bd(n, t, e) {
var r = T("boxes", n, t, e), i = T("scores", n, t, e), a = T("maxOutputSize", n, t, e), s = T("iouThreshold", n, t, e), o = T("scoreThreshold", n, t, e), c = T("softNmsSigma", n, t, e);
return {boxes: r, scores: i, maxOutputSize: a, iouThreshold: s, scoreThreshold: o, softNmsSigma: c};
}
var yk = function(n, t, e) {
return on(gk, void 0, void 0, function() {
var r, i, a, s, o, c, l, u, h, d, a, s, o, c, l, p, h, f, a, s, o, c, l, m, h;
return Qt(this, function(g) {
switch (g.label) {
case 0:
r = n.op;
switch (r) {
case "NonMaxSuppressionV5":
return [3, 1];
case "NonMaxSuppressionV4":
return [3, 3];
case "NonMaxSuppressionV3":
return [3, 5];
case "NonMaxSuppressionV2":
return [3, 5];
case "Where":
return [3, 7];
case "ListDiff":
return [3, 9];
}
return [3, 10];
case 1:
return i = bd(n, t, e), a = i.boxes, s = i.scores, o = i.maxOutputSize, c = i.iouThreshold, l = i.scoreThreshold, u = i.softNmsSigma, [4, W.image.nonMaxSuppressionWithScoreAsync(a, s, o, c, l, u)];
case 2:
return h = g.sent(), [2, [h.selectedIndices, h.selectedScores]];
case 3:
return d = bd(n, t, e), a = d.boxes, s = d.scores, o = d.maxOutputSize, c = d.iouThreshold, l = d.scoreThreshold, p = T("padToMaxOutputSize", n, t, e), [4, W.image.nonMaxSuppressionPaddedAsync(a, s, o, c, l, p)];
case 4:
return h = g.sent(), [2, [h.selectedIndices, h.validOutputs]];
case 5:
return f = bd(n, t, e), a = f.boxes, s = f.scores, o = f.maxOutputSize, c = f.iouThreshold, l = f.scoreThreshold, [4, W.image.nonMaxSuppressionAsync(a, s, o, c, l)];
case 6:
return [2, [g.sent()]];
case 7:
return m = W.cast(T("condition", n, t, e), "bool"), [4, W.whereAsync(m)];
case 8:
return h = [g.sent()], m.dispose(), [2, h];
case 9:
return [2, W.setdiff1dAsync(T("x", n, t, e), T("y", n, t, e))];
case 10:
throw TypeError("Node type " + n.op + " is not implemented");
}
});
});
};
var vk = function(n, t, e) {
switch (n.op) {
case "TopKV2": {
var r = T("x", n, t, e), i = T("k", n, t, e), a = T("sorted", n, t, e), s = W.topk(r, i, a);
return [s.values, s.indices];
}
case "Unique": {
var r = T("x", n, t, e), s = W.unique(r);
return [s.values, s.indices];
}
case "UniqueV2": {
var r = T("x", n, t, e), o = T("axis", n, t, e), s = W.unique(r, o);
return [s.values, s.indices];
}
default:
throw TypeError("Node type " + n.op + " is not implemented");
}
};
var wk = function(n, t, e) {
switch (n.op) {
case "Const":
return t[n.name];
case "PlaceholderWithDefault":
var r = T("default", n, t, e);
return [Gt(n.name, t, e) || r];
case "Placeholder":
return [Gt(n.name, t, e)];
case "Identity":
case "StopGradient":
case "FakeQuantWithMinMaxVars": {
var i = T("x", n, t, e);
return [tr(i)];
}
case "IdentityN":
return T("x", n, t, e).map(function(h) {
return tr(h);
});
case "Snapshot":
var a = T("x", n, t, e);
return [tr(a)];
case "Shape":
return [W.tensor1d(T("x", n, t, e).shape, "int32")];
case "ShapeN":
return T("x", n, t, e).map(function(h) {
return W.tensor1d(h.shape);
});
case "Size":
return [W.scalar(T("x", n, t, e).size, "int32")];
case "Rank":
return [W.scalar(T("x", n, t, e).rank, "int32")];
case "NoOp":
return [W.scalar(1)];
case "Print":
var s = T("x", n, t, e), o = T("data", n, t, e), c = T("message", n, t, e), l = T("summarize", n, t, e);
console.warn("The graph has a tf.print() operation,usually used for debugging, which slows down performance."), console.log(c);
for (var u = 0; u < o.length; u++)
console.log(Array.prototype.slice.call(o[u].dataSync()).slice(0, l));
return [s];
default:
throw TypeError("Node type " + n.op + " is not implemented");
}
}, bk = function() {
function n(t, e) {
this.keyDType = t, this.valueDType = e, this.handle = W.scalar(0), this.tensorMap = new Map(), W.keep(this.handle);
}
return Object.defineProperty(n.prototype, "id", {get: function() {
return this.handle.id;
}, enumerable: true, configurable: true}), n.prototype.clearAndClose = function() {
this.tensorMap.forEach(function(t) {
return t.dispose();
}), this.tensorMap.clear(), this.handle.dispose();
}, n.prototype.size = function() {
return this.tensorMap.size;
}, n.prototype.import = function(t, e) {
return on(this, void 0, void 0, function() {
var r, i = this;
return Qt(this, function(a) {
switch (a.label) {
case 0:
return this.checkKeyAndValueTensor(t, e), [4, t.data()];
case 1:
return r = a.sent(), this.tensorMap.forEach(function(s) {
return s.dispose();
}), this.tensorMap.clear(), [2, W.tidy(function() {
var s = W.unstack(e), o = r.length, c = s.length;
W.util.assert(o === c, function() {
return "The number of elements doesn't match, keys has " + (o + " elements, the values has " + c + " ") + "elements.";
});
for (var l = 0; l < o; l++) {
var u = r[l], h = s[l];
W.keep(h), i.tensorMap.set(u, h);
}
return i.handle;
})];
}
});
});
}, n.prototype.find = function(t, e) {
return on(this, void 0, void 0, function() {
var r, i = this;
return Qt(this, function(a) {
switch (a.label) {
case 0:
return this.checkKeyAndValueTensor(t, e), [4, t.data()];
case 1:
return r = a.sent(), [2, W.tidy(function() {
for (var s = [], o = 0; o < r.length; o++) {
var c = r[o], l = i.findWithDefault(c, e);
s.push(l);
}
return W.stack(s);
})];
}
});
});
}, n.prototype.findWithDefault = function(t, e) {
var r = this.tensorMap.get(t);
return r != null ? r : e;
}, n.prototype.checkKeyAndValueTensor = function(t, e) {
if (t.dtype !== this.keyDType)
throw new Error("Expect key dtype " + this.keyDType + ", but got " + ("" + t.dtype));
if (e.dtype !== this.valueDType)
throw new Error("Expect value dtype " + this.valueDType + ", but got " + ("" + e.dtype));
}, n;
}();
var xk = void 0, Lk = function(n, t, e, r) {
return on(xk, void 0, void 0, function() {
var i, a, s, o, c, l, u, o, c, l, h, o;
return Qt(this, function(d) {
switch (d.label) {
case 0:
i = n.op;
switch (i) {
case "HashTable":
return [3, 1];
case "HashTableV2":
return [3, 1];
case "LookupTableImport":
return [3, 2];
case "LookupTableImportV2":
return [3, 2];
case "LookupTableFind":
return [3, 4];
case "LookupTableFindV2":
return [3, 4];
}
return [3, 6];
case 1:
return a = T("keyDType", n, t, e), s = T("valueDType", n, t, e), o = new bk(a, s), r.addHashTable(n.name, o), [2, [o.handle]];
case 2:
return c = T("tableHandle", n, t, e, r), l = T("keys", n, t, e), u = T("values", n, t, e), o = r.getHashTableById(c.id), [4, o.import(l, u)];
case 3:
return [2, [d.sent()]];
case 4:
return c = T("tableHandle", n, t, e, r), l = T("keys", n, t, e), h = T("defaultValue", n, t, e), o = r.getHashTableById(c.id), [4, o.find(l, h)];
case 5:
return [2, [d.sent()]];
case 6:
throw TypeError("Node type " + n.op + " is not implemented");
}
});
});
};
var Sk = function(n, t, e) {
switch (n.op) {
case "ResizeBilinear": {
var r = T("images", n, t, e), i = T("size", n, t, e), a = T("alignCorners", n, t, e);
return [W.image.resizeBilinear(r, [i[0], i[1]], a)];
}
case "ResizeNearestNeighbor": {
var r = T("images", n, t, e), i = T("size", n, t, e), a = T("alignCorners", n, t, e);
return [W.image.resizeNearestNeighbor(r, [i[0], i[1]], a)];
}
case "CropAndResize": {
var s = T("image", n, t, e), o = T("boxes", n, t, e), c = T("boxInd", n, t, e), l = T("cropSize", n, t, e), u = T("method", n, t, e), h = T("extrapolationValue", n, t, e);
return [W.image.cropAndResize(s, o, c, l, u, h)];
}
default:
throw TypeError("Node type " + n.op + " is not implemented");
}
};
var Ik = function(n, t, e) {
switch (n.op) {
case "Equal":
return [W.equal(T("a", n, t, e), T("b", n, t, e))];
case "NotEqual":
return [W.notEqual(T("a", n, t, e), T("b", n, t, e))];
case "Greater":
return [W.greater(T("a", n, t, e), T("b", n, t, e))];
case "GreaterEqual":
return [W.greaterEqual(T("a", n, t, e), T("b", n, t, e))];
case "Less":
return [W.less(T("a", n, t, e), T("b", n, t, e))];
case "LessEqual":
return [W.lessEqual(T("a", n, t, e), T("b", n, t, e))];
case "LogicalAnd":
return [W.logicalAnd(T("a", n, t, e), T("b", n, t, e))];
case "LogicalNot":
return [W.logicalNot(T("a", n, t, e))];
case "LogicalOr":
return [W.logicalOr(T("a", n, t, e), T("b", n, t, e))];
case "Select":
case "SelectV2":
return [W.where(T("condition", n, t, e), T("a", n, t, e), T("b", n, t, e))];
default:
throw TypeError("Node type " + n.op + " is not implemented");
}
};
var Ak = function(n, t, e) {
switch (n.op) {
case "BatchMatMul":
case "BatchMatMulV2":
case "MatMul":
return [W.matMul(T("a", n, t, e), T("b", n, t, e), T("transposeA", n, t, e), T("transposeB", n, t, e))];
case "Transpose":
return [W.transpose(T("x", n, t, e), T("perm", n, t, e))];
case "_FusedMatMul":
var r = gt(T("fusedOps", n, t, e), 2), i = r[0], a = r[1], s = i === "biasadd", o = a === "prelu", c = T("numArgs", n, t, e);
if (s) {
if (o && c !== 2)
throw new Error("Fused MatMul with BiasAdd and Prelu must have two extra arguments: bias and alpha.");
if (!o && c !== 1)
throw new Error("Fused MatMul with BiasAdd must have one extra argument: bias.");
}
var l = gt(T("args", n, t, e), 2), u = l[0], h = l[1];
return [W.fused.matMul({a: T("a", n, t, e), b: T("b", n, t, e), transposeA: T("transposeA", n, t, e), transposeB: T("transposeB", n, t, e), bias: u, activation: a, preluActivationWeights: h})];
default:
throw TypeError("Node type " + n.op + " is not implemented");
}
};
var Tk = function(n, t, e) {
switch (n.op) {
case "FusedBatchNorm":
case "FusedBatchNormV2":
return [W.batchNorm(T("x", n, t, e), T("mean", n, t, e), T("variance", n, t, e), T("offset", n, t, e), T("scale", n, t, e), T("epsilon", n, t, e))];
case "FusedBatchNormV3":
return [W.batchNorm(T("x", n, t, e), T("mean", n, t, e), T("variance", n, t, e), T("offset", n, t, e), T("scale", n, t, e), T("epsilon", n, t, e))];
case "LRN":
return [W.localResponseNormalization(T("x", n, t, e), T("radius", n, t, e), T("bias", n, t, e), T("alpha", n, t, e), T("beta", n, t, e))];
case "Softmax":
return [W.softmax(T("x", n, t, e))];
case "LogSoftmax":
return [W.logSoftmax(T("x", n, t, e))];
case "SparseToDense":
return [W.sparseToDense(T("sparseIndices", n, t, e), T("outputShape", n, t, e), T("sparseValues", n, t, e), T("defaultValue", n, t, e))];
default:
throw TypeError("Node type " + n.op + " is not implemented");
}
};
var Nk = function(n, t, e) {
switch (n.op) {
case "Max": {
var r = T("axis", n, t, e), i = T("keepDims", n, t, e);
return [W.max(T("x", n, t, e), r, i)];
}
case "Mean": {
var r = T("axis", n, t, e), i = T("keepDims", n, t, e);
return [W.mean(T("x", n, t, e), r, i)];
}
case "Min": {
var r = T("axis", n, t, e), i = T("keepDims", n, t, e);
return [W.min(T("x", n, t, e), r, i)];
}
case "Sum": {
var r = T("axis", n, t, e), i = T("keepDims", n, t, e);
return [W.sum(T("x", n, t, e), r, i)];
}
case "All": {
var r = T("axis", n, t, e), i = T("keepDims", n, t, e);
return [W.all(T("x", n, t, e), r, i)];
}
case "Any": {
var r = T("axis", n, t, e), i = T("keepDims", n, t, e);
return [W.any(T("x", n, t, e), r, i)];
}
case "ArgMax": {
var r = T("axis", n, t, e);
return [W.argMax(T("x", n, t, e), r)];
}
case "ArgMin": {
var r = T("axis", n, t, e);
return [W.argMin(T("x", n, t, e), r)];
}
case "Prod": {
var r = T("axis", n, t, e), i = T("keepDims", n, t, e);
return [W.prod(T("x", n, t, e), r, i)];
}
case "Cumsum": {
var r = T("axis", n, t, e), a = T("exclusive", n, t, e), s = T("reverse", n, t, e);
return [W.cumsum(T("x", n, t, e), r, a, s)];
}
default:
throw TypeError("Node type " + n.op + " is not implemented");
}
};
var _k = function(n, t, e) {
switch (n.op) {
case "ConcatV2":
case "Concat": {
var r = T("n", n, t, e), i = T("axis", n, t, e), a = T("tensors", n, t, e);
return a = a.slice(0, r), [W.concat(a, i)];
}
case "GatherV2":
case "Gather": {
var i = T("axis", n, t, e), s = T("x", n, t, e), o = T("indices", n, t, e);
return [W.gather(s, W.cast(o, "int32"), i)];
}
case "ReverseV2":
case "Reverse": {
var i = T("axis", n, t, e), s = T("x", n, t, e);
return [W.reverse(s, i)];
}
case "Slice": {
var c = T("begin", n, t, e), l = T("size", n, t, e);
return [W.slice(T("x", n, t, e), c, l)];
}
case "StridedSlice": {
var c = T("begin", n, t, e), u = T("end", n, t, e), h = T("strides", n, t, e), d = T("beginMask", n, t, e), p = T("endMask", n, t, e), f = T("ellipsisMask", n, t, e), m = T("newAxisMask", n, t, e), g = T("shrinkAxisMask", n, t, e), y = T("x", n, t, e);
return [W.stridedSlice(y, c, u, h, d, p, f, m, g)];
}
case "Pack":
return W.tidy(function() {
var O = T("axis", n, t, e), D = T("tensors", n, t, e), F = D[0].shape, k = W.squeeze(D[0]).shape, B = D.map(function(V) {
var P = W.util.arraysEqual(V.shape, F);
if (!P && !W.util.arraysEqual(W.squeeze(V).shape, k))
throw new Error("the input tensors shape does not match");
return P ? V : W.reshape(V, F);
});
return [W.stack(B, O)];
});
case "Unpack": {
var i = T("axis", n, t, e), y = T("tensor", n, t, e);
return W.unstack(y, i);
}
case "Tile": {
var w = T("reps", n, t, e);
return [W.tile(T("x", n, t, e), w)];
}
case "Split":
case "SplitV": {
var i = T("axis", n, t, e), b = T("numOrSizeSplits", n, t, e), y = T("x", n, t, e);
return W.split(y, b, i);
}
case "ScatterNd": {
var o = T("indices", n, t, e), x = T("values", n, t, e), L = T("shape", n, t, e);
return [W.scatterND(o, x, L)];
}
case "GatherNd": {
var N = T("x", n, t, e), o = T("indices", n, t, e);
return [W.gatherND(N, o)];
}
case "SparseToDense": {
var o = T("sparseIndices", n, t, e), L = T("outputShape", n, t, e), I = T("sparseValues", n, t, e), C = T("defaultValue", n, t, e);
return [W.sparseToDense(o, I, L, I.dtype === C.dtype ? C : W.cast(C, I.dtype))];
}
default:
throw TypeError("Node type " + n.op + " is not implemented");
}
};
var Ck = function(n, t, e) {
switch (n.op) {
case "FFT":
return [W.fft(T("x", n, t, e))];
case "IFFT":
return [W.ifft(T("x", n, t, e))];
case "RFFT":
return [W.rfft(T("x", n, t, e))];
case "IRFFT":
return [W.irfft(T("x", n, t, e))];
default:
throw TypeError("Node type " + n.op + " is not implemented");
}
};
var Rk = function(n, t, e) {
switch (n.op) {
case "Cast":
return [W.cast(T("x", n, t, e), T("dtype", n, t, e))];
case "ExpandDims": {
var r = T("axis", n, t, e);
return [W.expandDims(T("x", n, t, e), r)];
}
case "Squeeze": {
var r = T("axis", n, t, e);
return [W.squeeze(T("x", n, t, e), r)];
}
case "Reshape":
return [W.reshape(T("x", n, t, e), T("shape", n, t, e))];
case "MirrorPad":
return [W.mirrorPad(T("x", n, t, e), T("padding", n, t, e), T("mode", n, t, e))];
case "PadV2":
case "Pad":
return [W.pad(T("x", n, t, e), T("padding", n, t, e), T("constantValue", n, t, e))];
case "SpaceToBatchND": {
var i = T("blockShape", n, t, e), a = T("paddings", n, t, e);
return [W.spaceToBatchND(T("x", n, t, e), i, a)];
}
case "BatchToSpaceND": {
var i = T("blockShape", n, t, e), s = T("crops", n, t, e);
return [W.batchToSpaceND(T("x", n, t, e), i, s)];
}
case "DepthToSpace": {
var o = T("blockSize", n, t, e), c = T("dataFormat", n, t, e).toUpperCase();
return [W.depthToSpace(T("x", n, t, e), o, c)];
}
case "BroadcastTo":
return [W.broadcastTo(T("x", n, t, e), T("shape", n, t, e))];
default:
throw TypeError("Node type " + n.op + " is not implemented");
}
};
function v1(n, t, e, r) {
var i = function(a, s, o) {
switch (a.category) {
case "arithmetic":
return W.tidy(function() {
return ik(a, s, o);
});
case "basic_math":
return W.tidy(function() {
return ak(a, s, o);
});
case "control":
return pk(a, s, o);
case "convolution":
return W.tidy(function() {
return fk(a, s, o);
});
case "creation":
return W.tidy(function() {
return mk(a, s, o);
});
case "dynamic":
return yk(a, s, o);
case "evaluation":
return W.tidy(function() {
return vk(a, s, o);
});
case "image":
return W.tidy(function() {
return Sk(a, s, o);
});
case "graph":
return W.tidy(function() {
return wk(a, s, o);
});
case "logical":
return W.tidy(function() {
return Ik(a, s, o);
});
case "matrices":
return W.tidy(function() {
return Ak(a, s, o);
});
case "normalization":
return W.tidy(function() {
return Tk(a, s, o);
});
case "reduction":
return W.tidy(function() {
return Nk(a, s, o);
});
case "slice_join":
return W.tidy(function() {
return _k(a, s, o);
});
case "spectral":
return W.tidy(function() {
return Ck(a, s, o);
});
case "transformation":
return W.tidy(function() {
return Rk(a, s, o);
});
case "hash_table":
return Lk(a, s, o, r);
case "custom":
var c = d1(a.op);
if (c && c.customExecutor)
return c.customExecutor(new rk(a, s, o));
throw TypeError("Custom op " + a.op + " is not registered.");
default:
throw TypeError("Unknown op '" + a.op + "'. File an issue at https://github.com/tensorflow/tfjs/issues so we can add it, or register a custom execution with tf.registerOp()");
}
}(n, t, e);
return W.util.isPromise(i) ? i.then(function(a) {
return [].concat(a);
}) : [].concat(i);
}
var w1 = function() {
function n(t, e, r, i) {
t === void 0 && (t = {}), e === void 0 && (e = {}), r === void 0 && (r = {}), i === void 0 && (i = {}), this.weightMap = t, this.tensorArrayMap = e, this.tensorListMap = r, this.functionMap = i, this.rootContext = {id: 0, frameName: "", iterationId: 0}, this.contexts = [this.rootContext], this.lastId = 0, this.generateCurrentContextIds();
}
return n.prototype.newFrame = function(t, e) {
return {id: t, frameName: e, iterationId: 0};
}, Object.defineProperty(n.prototype, "currentContext", {get: function() {
return this.contexts;
}, set: function(t) {
this.contexts !== t && (this.contexts = t, this.generateCurrentContextIds());
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "currentContextId", {get: function() {
return this._currentContextIds[0];
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "currentContextIds", {get: function() {
return this._currentContextIds;
}, enumerable: true, configurable: true}), n.prototype.generateCurrentContextIds = function() {
for (var t = [], e = 0; e < this.contexts.length - 1; e++) {
var r = this.contexts.slice(0, this.contexts.length - e);
t.push(this.contextIdforContexts(r));
}
t.push(""), this._currentContextIds = t;
}, n.prototype.contextIdforContexts = function(t) {
return t ? t.map(function(e) {
return e.id === 0 && e.iterationId === 0 ? "" : e.frameName + "-" + e.iterationId;
}).join("/") : "";
}, n.prototype.enterFrame = function(t) {
this.contexts && (this.lastId++, this.contexts = this.contexts.slice(), this.contexts.push(this.newFrame(this.lastId, t)), this._currentContextIds.unshift(this.contextIdforContexts(this.contexts)));
}, n.prototype.exitFrame = function() {
if (this.contexts && this.contexts.length > 1)
this.contexts = this.contexts.slice(), this.contexts.splice(-1), this.currentContextIds.shift();
else
throw new Error("Cannot exit frame, the context is empty");
}, n.prototype.nextIteration = function() {
if (this.contexts && this.contexts.length > 0) {
this.contexts = this.contexts.slice(), this.lastId++;
var t = Object.assign({}, this.contexts[this.contexts.length - 1]);
t.iterationId += 1, t.id = this.lastId, this.contexts.splice(-1, 1, t), this._currentContextIds.splice(0, 1, this.contextIdforContexts(this.contexts));
} else
throw new Error("Cannot increase frame iteration, the context is empty");
}, n.prototype.getWeight = function(t) {
return this.weightMap[t];
}, n.prototype.addTensorArray = function(t) {
this.tensorArrayMap[t.id] = t;
}, n.prototype.getTensorArray = function(t) {
return this.tensorArrayMap[t];
}, n.prototype.addTensorList = function(t) {
this.tensorListMap[t.id] = t;
}, n.prototype.getTensorList = function(t) {
return this.tensorListMap[t];
}, n.prototype.dispose = function(t) {
for (var e in this.tensorArrayMap)
this.tensorArrayMap[e].clearAndClose(t);
for (var e in this.tensorListMap)
this.tensorListMap[e].clearAndClose(t);
}, n;
}();
function x1(n, t, e, r) {
var i = new Set(), a = [], s = null, o = null, c = new Set(), l = Object.keys(n).map(function(p) {
return en(p)[0];
}), u = [];
r != null && (u = r.map(function(p) {
return en(p.name)[0];
}));
for (var h = Rr(t); h.length > 0; ) {
var d = h.pop();
if ((b1(d) || Ok(d) || Ek(d)) && (s == null && (s = d, o = s.children.map(function(p) {
return p.name;
}).filter(function(p) {
return i.has(p);
}))), i.add(d.name), e[d.name] != null)
continue;
if (l.indexOf(d.name) !== -1)
continue;
if (u.indexOf(d.name) !== -1)
continue;
if (d.inputs.length === 0) {
a.push(d.name);
continue;
}
d.inputs.forEach(function(p) {
if (c.has(p.name))
return;
c.add(p.name), h.push(p);
});
}
return {inputs: n, outputs: t, usedNodes: i, missingInputs: a, dynamicNode: s, syncInputs: o};
}
function Dk(n, t, e) {
var r = e.usedNodes, i = e.inputs, a = [], s = Object.keys(i).map(function(h) {
return en(h)[0];
}).map(function(h) {
return n.nodes[h];
}), o = n.initNodes;
s.forEach(function(h) {
r.has(h.name) && a.push(h);
}), n.weights.forEach(function(h) {
r.has(h.name) && a.push(h);
}), o != null && o.forEach(function(h) {
r.has(h.name) && a.push(h);
});
for (var c = new Set(), l = []; a.length > 0; ) {
var u = a.pop();
c.add(u.name), t[u.name] || l.push(u), u.children.forEach(function(h) {
!c.has(h.name) && r.has(h.name) && h.inputs.every(function(d) {
return c.has(d.name);
}) && a.push(h);
});
}
return l;
}
var kk = ["Switch", "Merge", "Enter", "Exit", "NextIteration", "StatelessIf", "StatelessWhile", "if", "While"], Fk = ["NonMaxSuppressionV2", "NonMaxSuppressionV3", "NonMaxSuppressionV5", "Where"], Wk = ["HashTable", "HashTableV2", "LookupTableImport", "LookupTableImportV2", "LookupTableFind", "LookupTableFindV2"];
function b1(n) {
return kk.indexOf(n.op) >= 0;
}
function Ok(n) {
return Fk.indexOf(n.op) >= 0;
}
function Ek(n) {
return Wk.indexOf(n.op) >= 0;
}
var L1 = function() {
function n(t, e) {
var r = this;
this.graph = t, this.parent = e, this.compiledMap = new Map(), this._weightMap = {}, this.SEPERATOR = ",", this._functions = {}, this._functionExecutorMap = {}, this._outputs = t.outputs, this._inputs = t.inputs, this._initNodes = t.initNodes, this._signature = t.signature, this._functions = t.functions, t.functions != null && Object.keys(t.functions).forEach(function(i) {
r._functionExecutorMap[i] = new n(t.functions[i], r);
});
}
return Object.defineProperty(n.prototype, "weightIds", {get: function() {
return this.parent ? this.parent.weightIds : this._weightIds;
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "functionExecutorMap", {get: function() {
return this.parent ? this.parent.functionExecutorMap : this._functionExecutorMap;
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "weightMap", {get: function() {
return this.parent ? this.parent.weightMap : this._weightMap;
}, set: function(t) {
var e = Object.keys(t).map(function(r) {
return t[r].map(function(i) {
return i.id;
});
});
this._weightIds = [].concat.apply([], Rr(e)), this._weightMap = t;
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "resourceManager", {set: function(t) {
this._resourceManager = t;
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "inputs", {get: function() {
return this._inputs.map(function(t) {
return {name: t.name, shape: t.attrParams.shape ? t.attrParams.shape.value : void 0, dtype: t.attrParams.dtype ? t.attrParams.dtype.value : void 0};
});
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "outputs", {get: function() {
return this._outputs.map(function(t) {
return {name: t.name, shape: t.attrParams.shape ? t.attrParams.shape.value : void 0, dtype: t.attrParams.dtype ? t.attrParams.dtype.value : void 0};
});
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "inputNodes", {get: function() {
return this._inputs.map(function(t) {
return t.signatureKey || t.name;
});
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "outputNodes", {get: function() {
return this._outputs.map(function(t) {
var e = t.signatureKey || t.name;
return t.defaultOutput ? e + ":" + t.defaultOutput : e;
});
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "functions", {get: function() {
var t = this;
return Object.keys(this._functions).reduce(function(e, r) {
return e[r] = t._functions[r].signature, e;
}, {});
}, enumerable: true, configurable: true}), n.prototype.getCompilationKey = function(t, e) {
var r = t.map(function(a) {
return a.name;
}).sort(), i = e.map(function(a) {
return a.name;
}).sort();
return r.join(this.SEPERATOR) + "--" + i.join(this.SEPERATOR);
}, n.prototype.compile = function(t, e) {
var r = x1(t, e, this.weightMap, this._initNodes), i = r.missingInputs, a = r.dynamicNode, s = r.syncInputs;
if (a != null)
throw new Error("This execution contains the node '" + a.name + "', which has " + ("the dynamic op '" + a.op + "'. Please use ") + "model.executeAsync() instead. Alternatively, to avoid the " + ("dynamic ops, specify the inputs [" + s + "]"));
if (i.length > 0) {
var o = e.map(function(l) {
return l.name;
}), c = Object.keys(t);
throw new Error("Cannot compute the outputs [" + o + "] from the provided inputs " + ("[" + c + "]. Missing the following inputs: [" + i + "]"));
}
return Dk(this.graph, this.weightMap, r);
}, n.prototype.execute = function(t, e) {
var r = this;
t = this.mapInputs(t);
var i = Object.keys(t).sort();
this.checkInputs(t), this.checkInputShapeAndType(t), e = this.mapOutputs(e), this.checkOutputs(e);
var a = i.map(function(d) {
return r.graph.nodes[en(d)[0]];
}), s = e.map(function(d) {
return en(d)[0];
}), o = s.map(function(d) {
return r.graph.nodes[d];
});
o.length === 0 && (o = this._outputs);
var c = this.getCompilationKey(a, o), l = this.compiledMap.get(c);
l == null && (l = this.compile(t, o), this.compiledMap.set(c, l));
var u = {}, h = {};
return W.tidy(function() {
var d = new w1(r.weightMap, u, h, r.functionExecutorMap), p = u1({}, r.weightMap);
Object.keys(t).forEach(function(b) {
var x = gt(en(b), 2), L = x[0], N = x[1], I = [];
I[N] = t[b], p[L] = I;
});
for (var f = r.getFrozenTensorIds(p), m = {}, g = 0; g < l.length; g++) {
var y = l[g];
if (!p[y.name]) {
var w = v1(y, p, d, r._resourceManager);
if (W.util.isPromise(w))
throw new Error("The execution of the op '" + y.op + "' returned a promise. Please use model.executeAsync() instead.");
p[y.name] = w, r.checkTensorForDisposal(y.name, y, p, d, f, s, m);
}
}
return r.parent == null && d.dispose(f), e.map(function(b) {
return Gt(b, p, d);
});
});
}, n.prototype.getFrozenTensorIds = function(t) {
var e = [].concat.apply([], Object.keys(t).map(function(r) {
return t[r];
}).map(function(r) {
return r.map(function(i) {
return i.id;
});
}));
return new Set(e);
}, n.prototype.checkTensorForDisposal = function(t, e, r, i, a, s, o) {
if (e.category === "control" || s.indexOf(t) !== -1)
return;
r[t].forEach(function(c) {
c != null && (o[c.id] = (o[c.id] || 0) + e.children.length);
}), e.inputs.forEach(function(c) {
if (c.category !== "control") {
var l = xD(c.name, r, i);
l != null && l.forEach(function(u) {
if (u && !a.has(u.id)) {
var h = o[u.id];
h === 1 ? (u.dispose(), delete o[u.id]) : h != null && o[u.id]--;
}
});
}
});
}, n.prototype.executeAsync = function(t, e) {
return on(this, void 0, void 0, function() {
return Qt(this, function(r) {
return [2, this._executeAsync(t, e)];
});
});
}, n.prototype._executeAsync = function(t, e, r, i, a) {
return r === void 0 && (r = false), i === void 0 && (i = {}), a === void 0 && (a = {}), on(this, void 0, void 0, function() {
var s, o, c, l, u, h;
return Qt(this, function(d) {
switch (d.label) {
case 0:
return r || (t = this.mapInputs(t), this.checkInputs(t), this.checkInputShapeAndType(t), e = this.mapOutputs(e), this.checkOutputs(e)), s = new w1(this.weightMap, i, a, this.functionExecutorMap), [4, this.executeWithControlFlow(t, s, e, r)];
case 1:
return o = d.sent(), c = e.map(function(p) {
return Gt(p, o, s);
}), l = c.map(function(p) {
return p.id;
}), u = Object.keys(t).map(function(p) {
return t[p].id;
}), h = new Set(Rr(l, u, this.weightIds)), Object.keys(o).forEach(function(p) {
var f = o[p];
f.forEach(function(m) {
m && !m.isDisposed && !h.has(m.id) && m.dispose();
});
}), this.parent == null && s.dispose(h), [2, c];
}
});
});
}, n.prototype.executeFunctionAsync = function(t, e, r) {
return on(this, void 0, void 0, function() {
var i, a = this;
return Qt(this, function(s) {
return i = t.reduce(function(o, c, l) {
return o[a.inputs[l].name] = c, o;
}, {}), [2, this._executeAsync(i, this.outputNodes, true, e, r)];
});
});
}, n.prototype.executeWithControlFlow = function(t, e, r, i) {
return on(this, void 0, void 0, function() {
var a, s, o, c, l, u, h, d, p, f, m, g, y, w, b, x, L, N = this;
return Qt(this, function(I) {
switch (I.label) {
case 0:
a = Object.keys(t), s = a.map(function(C) {
return N.graph.nodes[en(C)[0]];
}), o = r.map(function(C) {
return en(C)[0];
}), c = o.map(function(C) {
return N.graph.nodes[C];
}), c.length === 0 && (c = this._outputs), l = x1(t, c, this.weightMap, this._initNodes), u = l.usedNodes, h = l.missingInputs, d = l.dynamicNode, p = l.syncInputs, f = Rr(s, this.graph.weights, this._initNodes || []).map(function(C) {
return {node: C, contexts: e.currentContext};
}), m = u1({}, this.weightMap), Object.keys(t).forEach(function(C) {
var O = gt(en(C), 2), D = O[0], F = O[1], k = [];
k[F] = t[C], m[D] = k;
}), g = {}, y = this.getFrozenTensorIds(m), w = {}, I.label = 1;
case 1:
return f.length > 0 ? (b = this.processStack(s, f, e, m, w, y, o, g, u), [4, Promise.all(b)]) : [3, 3];
case 2:
return I.sent(), [3, 1];
case 3:
if (d == null && !i && console.warn("This model execution did not contain any nodes with control flow or dynamic output shapes. You can use model.execute() instead."), x = c.filter(function(C) {
return !b1(C) && !Gt(C.name, m, e);
}).map(function(C) {
return C.name;
}), x.length > 0)
throw L = "", d != null && (L = "Alternatively, to avoid the dynamic ops, use model.execute() " + ("and specify the inputs [" + p + "]")), new Error("Cannot compute the outputs [" + x + "] from the provided " + ("inputs [" + a + "]. Consider providing the following inputs: ") + ("[" + h + "]. " + L));
return [2, m];
}
});
});
}, n.prototype.processStack = function(t, e, r, i, a, s, o, c, l) {
for (var u = this, h = [], d = function() {
var f, m, g = e.pop();
r.currentContext = g.contexts;
var y = "";
if (g.node.op === "Enter" && T("isConstant", g.node, i, r) && (f = gt(er(g.node.name, r), 1), y = f[0]), i[g.node.name] == null) {
var w = v1(g.node, i, r, p._resourceManager);
y || (m = gt(er(g.node.name, r), 1), y = m[0]);
var b = r.currentContext;
W.util.isPromise(w) ? h.push(w.then(function(x) {
return i[y] = x, r.currentContext = b, u.checkTensorForDisposal(y, g.node, i, r, s, o, c), u.processChildNodes(g.node, e, r, i, a, l), x;
})) : (i[y] = w, p.checkTensorForDisposal(y, g.node, i, r, s, o, c), p.processChildNodes(g.node, e, r, i, a, l));
} else
p.processChildNodes(g.node, e, r, i, a, l);
}, p = this; e.length > 0; )
d();
return h;
}, n.prototype.processChildNodes = function(t, e, r, i, a, s) {
t.children.forEach(function(o) {
var c = gt(er(o.name, r), 1), l = c[0];
if (a[l] || !s.has(o.name))
return;
o.op === "Merge" ? o.inputNames.some(function(u) {
return !!Gt(u, i, r);
}) && (a[l] = true, e.push({contexts: r.currentContext, node: o})) : o.inputNames.every(function(u) {
return !!Gt(u, i, r);
}) && (a[l] = true, e.push({contexts: r.currentContext, node: o}));
});
}, n.prototype.dispose = function() {
var t = this;
Object.keys(this.weightMap).forEach(function(e) {
return t.weightMap[e].forEach(function(r) {
return r.dispose();
});
});
}, n.prototype.checkInputShapeAndType = function(t) {
var e = this;
Object.keys(t).forEach(function(r) {
var i = t[r], a = gt(en(r), 1), s = a[0], o = e.graph.nodes[s];
if (o.attrParams.shape && o.attrParams.shape.value) {
var c = o.attrParams.shape.value, l = c.length === i.shape.length && i.shape.every(function(u, h) {
return c[h] === -1 || c[h] === u;
});
W.util.assert(l, function() {
return "The shape of dict['" + o.name + "'] provided in " + ("model.execute(dict) must be [" + c + "], but was ") + ("[" + i.shape + "]");
});
}
o.attrParams.dtype && o.attrParams.dtype.value && W.util.assert(i.dtype === o.attrParams.dtype.value, function() {
return "The dtype of dict['" + o.name + "'] provided in model.execute(dict) must be " + (o.attrParams.dtype.value + ", but was " + i.dtype);
});
});
}, n.prototype.mapInputs = function(t) {
var e = {};
for (var r in t)
if (this._signature != null && this._signature.inputs != null && this._signature.inputs[r] != null) {
var i = this._signature.inputs[r];
e[i.name] = t[r];
} else
e[r] = t[r];
return e;
}, n.prototype.checkInputs = function(t) {
var e = this, r = Object.keys(t).filter(function(i) {
var a = gt(en(i), 1), s = a[0];
return e.graph.nodes[s] == null;
});
if (r.length > 0)
throw new Error("The dict provided in model.execute(dict) has " + ("keys: [" + r + "] that are not part of graph"));
}, n.prototype.mapOutputs = function(t) {
var e = this;
return t.map(function(r) {
if (e._signature != null && e._signature.outputs != null && e._signature.outputs[r] != null) {
var i = e._signature.outputs[r];
return i.name;
}
return r;
}, {});
}, n.prototype.checkOutputs = function(t) {
var e = this;
t.forEach(function(r) {
var i = gt(en(r), 1), a = i[0];
if (!e.graph.nodes[a])
throw new Error("The output '" + r + "' is not found in the graph");
});
}, n;
}(), Uk = function() {
function n(t, e) {
t === void 0 && (t = {}), e === void 0 && (e = {}), this.hashTableNameToHandle = t, this.hashTableMap = e;
}
return n.prototype.addHashTable = function(t, e) {
this.hashTableNameToHandle[t] = e.handle, this.hashTableMap[e.id] = e;
}, n.prototype.getHashTableHandleByName = function(t) {
return this.hashTableNameToHandle[t];
}, n.prototype.getHashTableById = function(t) {
return this.hashTableMap[t];
}, n.prototype.dispose = function() {
for (var t in this.hashTableMap)
this.hashTableMap[t].clearAndClose(), delete this.hashTableMap[t];
for (var e in this.hashTableNameToHandle)
this.hashTableNameToHandle[e].dispose(), delete this.hashTableNameToHandle[e];
}, n;
}();
var Bk = "?tfjs-format=file", zk = "model.json", S1 = function() {
function n(t, e) {
e === void 0 && (e = {}), this.modelUrl = t, this.loadOptions = e, this.version = "n/a", e == null && (this.loadOptions = {}), this.resourceManager = new Uk();
}
return Object.defineProperty(n.prototype, "modelVersion", {get: function() {
return this.version;
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "inputNodes", {get: function() {
return this.executor.inputNodes;
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "outputNodes", {get: function() {
return this.executor.outputNodes;
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "inputs", {get: function() {
return this.executor.inputs;
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "outputs", {get: function() {
return this.executor.outputs;
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "weights", {get: function() {
return this.executor.weightMap;
}, enumerable: true, configurable: true}), n.prototype.findIOHandler = function() {
var t = this.modelUrl;
if (t.load != null)
this.handler = t;
else if (this.loadOptions.requestInit != null)
this.handler = W.io.browserHTTPRequest(t, this.loadOptions);
else {
var e = W.io.getLoadHandlers(t, this.loadOptions);
if (e.length === 0)
e.push(W.io.browserHTTPRequest(t, this.loadOptions));
else if (e.length > 1)
throw new Error("Found more than one (" + e.length + ") load handlers for " + ("URL '" + [t] + "'"));
this.handler = e[0];
}
}, n.prototype.load = function() {
return on(this, void 0, void 0, function() {
var t;
return Qt(this, function(e) {
switch (e.label) {
case 0:
if (this.findIOHandler(), this.handler.load == null)
throw new Error("Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.");
return [4, this.handler.load()];
case 1:
return t = e.sent(), [2, this.loadSync(t)];
}
});
});
}, n.prototype.loadSync = function(t) {
this.artifacts = t;
var e = this.artifacts.modelTopology, r = {};
this.artifacts.userDefinedMetadata != null && (r = this.artifacts.userDefinedMetadata.signature), this.version = e.versions.producer + "." + e.versions.minConsumer;
var i = W.io.decodeWeights(this.artifacts.weightData, this.artifacts.weightSpecs);
if (this.executor = new L1(f1.Instance.transformGraph(e, r)), this.executor.weightMap = this.convertTensorMapToTensorsMap(i), this.executor.resourceManager = this.resourceManager, t.modelInitializer != null) {
var a = f1.Instance.transformGraph(t.modelInitializer);
this.initializer = new L1(a), this.initializer.weightMap = this.executor.weightMap, this.initializer.resourceManager = this.resourceManager, this.initializer.executeAsync({}, []);
}
return true;
}, n.prototype.save = function(t, e) {
return on(this, void 0, void 0, function() {
var r;
return Qt(this, function(i) {
if (typeof t == "string") {
if (r = W.io.getSaveHandlers(t), r.length === 0)
throw new Error("Cannot find any save handlers for URL '" + t + "'");
if (r.length > 1)
throw new Error("Found more than one (" + r.length + ") save handlers for " + ("URL '" + t + "'"));
t = r[0];
}
if (t.save == null)
throw new Error("GraphModel.save() cannot proceed because the IOHandler provided does not have the `save` attribute defined.");
return [2, t.save(this.artifacts)];
});
});
}, n.prototype.predict = function(t, e) {
return this.execute(t, this.outputNodes);
}, n.prototype.normalizeInputs = function(t) {
if (!(t instanceof W.Tensor) && !Array.isArray(t))
return t;
if (t = Array.isArray(t) ? t : [t], t.length !== this.inputNodes.length)
throw new Error("Input tensor count mismatch," + ("the graph model has " + this.inputNodes.length + " placeholders, ") + ("while there are " + t.length + " input tensors."));
return this.inputNodes.reduce(function(e, r, i) {
return e[r] = t[i], e;
}, {});
}, n.prototype.normalizeOutputs = function(t) {
return t = t || this.outputNodes, Array.isArray(t) ? t : [t];
}, n.prototype.execute = function(t, e) {
t = this.normalizeInputs(t), e = this.normalizeOutputs(e);
var r = this.executor.execute(t, e);
return r.length > 1 ? r : r[0];
}, n.prototype.executeAsync = function(t, e) {
return on(this, void 0, void 0, function() {
var r;
return Qt(this, function(i) {
switch (i.label) {
case 0:
return t = this.normalizeInputs(t), e = this.normalizeOutputs(e), [4, this.executor.executeAsync(t, e)];
case 1:
return r = i.sent(), [2, r.length > 1 ? r : r[0]];
}
});
});
}, n.prototype.convertTensorMapToTensorsMap = function(t) {
return Object.keys(t).reduce(function(e, r) {
return e[r] = [t[r]], e;
}, {});
}, n.prototype.dispose = function() {
this.executor.dispose(), this.initializer && this.initializer.dispose(), this.resourceManager.dispose();
}, n;
}();
function Pk(n, t) {
return t === void 0 && (t = {}), on(this, void 0, void 0, function() {
var e;
return Qt(this, function(r) {
switch (r.label) {
case 0:
if (n == null)
throw new Error("modelUrl in loadGraphModel() cannot be null. Please provide a url or an IOHandler that loads the model");
return t == null && (t = {}), t.fromTFHub && (n.load == null && (n.endsWith("/") || (n = n + "/"), n = "" + n + zk + Bk)), e = new S1(n, t), [4, e.load()];
case 1:
return r.sent(), [2, e];
}
});
});
}
var Mk = "2.7.0";
ci.GraphModel = S1;
ci.deregisterOp = bD;
ci.loadGraphModel = Pk;
ci.registerOp = wD;
ci.version_converter = Mk;
});
var A1 = we(() => {
});
var q1 = we((qt) => {
"use strict";
Object.defineProperty(qt, "__esModule", {value: true});
var Ce = ei();
var xd = function(n, t) {
return xd = Object.setPrototypeOf || {__proto__: []} instanceof Array && function(e, r) {
e.__proto__ = r;
} || function(e, r) {
for (var i in r)
r.hasOwnProperty(i) && (e[i] = r[i]);
}, xd(n, t);
};
function Ye(n, t) {
xd(n, t);
function e() {
this.constructor = n;
}
n.prototype = t === null ? Object.create(t) : (e.prototype = t.prototype, new e());
}
function ce(n, t, e, r) {
return new (e || (e = Promise))(function(i, a) {
function s(l) {
try {
c(r.next(l));
} catch (u) {
a(u);
}
}
function o(l) {
try {
c(r.throw(l));
} catch (u) {
a(u);
}
}
function c(l) {
l.done ? i(l.value) : new e(function(u) {
u(l.value);
}).then(s, o);
}
c((r = r.apply(n, t || [])).next());
});
}
function le(n, t) {
var e = {label: 0, sent: function() {
if (a[0] & 1)
throw a[1];
return a[1];
}, trys: [], ops: []}, r, i, a, s;
return s = {next: o(0), throw: o(1), return: o(2)}, typeof Symbol == "function" && (s[Symbol.iterator] = function() {
return this;
}), s;
function o(l) {
return function(u) {
return c([l, u]);
};
}
function c(l) {
if (r)
throw new TypeError("Generator is already executing.");
for (; e; )
try {
if (r = 1, i && (a = l[0] & 2 ? i.return : l[0] ? i.throw || ((a = i.return) && a.call(i), 0) : i.next) && !(a = a.call(i, l[1])).done)
return a;
(i = 0, a) && (l = [l[0] & 2, a.value]);
switch (l[0]) {
case 0:
case 1:
a = l;
break;
case 4:
return e.label++, {value: l[1], done: false};
case 5:
e.label++, i = l[1], l = [0];
continue;
case 7:
l = e.ops.pop(), e.trys.pop();
continue;
default:
if (!(a = e.trys, a = a.length > 0 && a[a.length - 1]) && (l[0] === 6 || l[0] === 2)) {
e = 0;
continue;
}
if (l[0] === 3 && (!a || l[1] > a[0] && l[1] < a[3])) {
e.label = l[1];
break;
}
if (l[0] === 6 && e.label < a[1]) {
e.label = a[1], a = l;
break;
}
if (a && e.label < a[2]) {
e.label = a[2], e.ops.push(l);
break;
}
a[2] && e.ops.pop(), e.trys.pop();
continue;
}
l = t.call(n, e);
} catch (u) {
l = [6, u], i = 0;
} finally {
r = a = 0;
}
if (l[0] & 5)
throw l[1];
return {value: l[0] ? l[1] : void 0, done: true};
}
}
var Xi = typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : {};
function li(n, t) {
return t = {exports: {}}, n(t, t.exports), t.exports;
}
var Hk = li(function(n) {
(function(t, e, r) {
function i(c) {
var l = this, u = o();
l.next = function() {
var h = 2091639 * l.s0 + l.c * 23283064365386963e-26;
return l.s0 = l.s1, l.s1 = l.s2, l.s2 = h - (l.c = h | 0);
}, l.c = 1, l.s0 = u(" "), l.s1 = u(" "), l.s2 = u(" "), l.s0 -= u(c), l.s0 < 0 && (l.s0 += 1), l.s1 -= u(c), l.s1 < 0 && (l.s1 += 1), l.s2 -= u(c), l.s2 < 0 && (l.s2 += 1), u = null;
}
function a(c, l) {
return l.c = c.c, l.s0 = c.s0, l.s1 = c.s1, l.s2 = c.s2, l;
}
function s(c, l) {
var u = new i(c), h = l && l.state, d = u.next;
return d.int32 = function() {
return u.next() * 4294967296 | 0;
}, d.double = function() {
return d() + (d() * 2097152 | 0) * 11102230246251565e-32;
}, d.quick = d, h && (typeof h == "object" && a(h, u), d.state = function() {
return a(u, {});
}), d;
}
function o() {
var c = 4022871197, l = function(u) {
u = u.toString();
for (var h = 0; h < u.length; h++) {
c += u.charCodeAt(h);
var d = 0.02519603282416938 * c;
c = d >>> 0, d -= c, d *= c, c = d >>> 0, d -= c, c += d * 4294967296;
}
return (c >>> 0) * 23283064365386963e-26;
};
return l;
}
e && e.exports ? e.exports = s : r && r.amd ? r(function() {
return s;
}) : this.alea = s;
})(Xi, n, false);
}), Vk = li(function(n) {
(function(t, e, r) {
function i(o) {
var c = this, l = "";
c.x = 0, c.y = 0, c.z = 0, c.w = 0, c.next = function() {
var h = c.x ^ c.x << 11;
return c.x = c.y, c.y = c.z, c.z = c.w, c.w ^= c.w >>> 19 ^ h ^ h >>> 8;
}, o === (o | 0) ? c.x = o : l += o;
for (var u = 0; u < l.length + 64; u++)
c.x ^= l.charCodeAt(u) | 0, c.next();
}
function a(o, c) {
return c.x = o.x, c.y = o.y, c.z = o.z, c.w = o.w, c;
}
function s(o, c) {
var l = new i(o), u = c && c.state, h = function() {
return (l.next() >>> 0) / 4294967296;
};
return h.double = function() {
do
var d = l.next() >>> 11, p = (l.next() >>> 0) / 4294967296, f = (d + p) / (1 << 21);
while (f === 0);
return f;
}, h.int32 = l.next, h.quick = h, u && (typeof u == "object" && a(u, l), h.state = function() {
return a(l, {});
}), h;
}
e && e.exports ? e.exports = s : r && r.amd ? r(function() {
return s;
}) : this.xor128 = s;
})(Xi, n, false);
}), Gk = li(function(n) {
(function(t, e, r) {
function i(o) {
var c = this, l = "";
c.next = function() {
var h = c.x ^ c.x >>> 2;
return c.x = c.y, c.y = c.z, c.z = c.w, c.w = c.v, (c.d = c.d + 362437 | 0) + (c.v = c.v ^ c.v << 4 ^ (h ^ h << 1)) | 0;
}, c.x = 0, c.y = 0, c.z = 0, c.w = 0, c.v = 0, o === (o | 0) ? c.x = o : l += o;
for (var u = 0; u < l.length + 64; u++)
c.x ^= l.charCodeAt(u) | 0, u == l.length && (c.d = c.x << 10 ^ c.x >>> 4), c.next();
}
function a(o, c) {
return c.x = o.x, c.y = o.y, c.z = o.z, c.w = o.w, c.v = o.v, c.d = o.d, c;
}
function s(o, c) {
var l = new i(o), u = c && c.state, h = function() {
return (l.next() >>> 0) / 4294967296;
};
return h.double = function() {
do
var d = l.next() >>> 11, p = (l.next() >>> 0) / 4294967296, f = (d + p) / (1 << 21);
while (f === 0);
return f;
}, h.int32 = l.next, h.quick = h, u && (typeof u == "object" && a(u, l), h.state = function() {
return a(l, {});
}), h;
}
e && e.exports ? e.exports = s : r && r.amd ? r(function() {
return s;
}) : this.xorwow = s;
})(Xi, n, false);
}), qk = li(function(n) {
(function(t, e, r) {
function i(o) {
var c = this;
c.next = function() {
var u = c.x, h = c.i, d, p;
return d = u[h], d ^= d >>> 7, p = d ^ d << 24, d = u[h + 1 & 7], p ^= d ^ d >>> 10, d = u[h + 3 & 7], p ^= d ^ d >>> 3, d = u[h + 4 & 7], p ^= d ^ d << 7, d = u[h + 7 & 7], d = d ^ d << 13, p ^= d ^ d << 9, u[h] = p, c.i = h + 1 & 7, p;
};
function l(u, h) {
var d, p, f = [];
if (h === (h | 0))
p = f[0] = h;
else
for (h = "" + h, d = 0; d < h.length; ++d)
f[d & 7] = f[d & 7] << 15 ^ h.charCodeAt(d) + f[d + 1 & 7] << 13;
for (; f.length < 8; )
f.push(0);
for (d = 0; d < 8 && f[d] === 0; ++d)
;
for (d == 8 ? p = f[7] = -1 : p = f[d], u.x = f, u.i = 0, d = 256; d > 0; --d)
u.next();
}
l(c, o);
}
function a(o, c) {
return c.x = o.x.slice(), c.i = o.i, c;
}
function s(o, c) {
o == null && (o = +new Date());
var l = new i(o), u = c && c.state, h = function() {
return (l.next() >>> 0) / 4294967296;
};
return h.double = function() {
do
var d = l.next() >>> 11, p = (l.next() >>> 0) / 4294967296, f = (d + p) / (1 << 21);
while (f === 0);
return f;
}, h.int32 = l.next, h.quick = h, u && (u.x && a(u, l), h.state = function() {
return a(l, {});
}), h;
}
e && e.exports ? e.exports = s : r && r.amd ? r(function() {
return s;
}) : this.xorshift7 = s;
})(Xi, n, false);
}), Yk = li(function(n) {
(function(t, e, r) {
function i(o) {
var c = this;
c.next = function() {
var u = c.w, h = c.X, d = c.i, p, f;
return c.w = u = u + 1640531527 | 0, f = h[d + 34 & 127], p = h[d = d + 1 & 127], f ^= f << 13, p ^= p << 17, f ^= f >>> 15, p ^= p >>> 12, f = h[d] = f ^ p, c.i = d, f + (u ^ u >>> 16) | 0;
};
function l(u, h) {
var d, p, f, m, g, y = [], w = 128;
for (h === (h | 0) ? (p = h, h = null) : (h = h + "\0", p = 0, w = Math.max(w, h.length)), f = 0, m = -32; m < w; ++m)
h && (p ^= h.charCodeAt((m + 32) % h.length)), m === 0 && (g = p), p ^= p << 10, p ^= p >>> 15, p ^= p << 4, p ^= p >>> 13, m >= 0 && (g = g + 1640531527 | 0, d = y[m & 127] ^= p + g, f = d == 0 ? f + 1 : 0);
for (f >= 128 && (y[(h && h.length || 0) & 127] = -1), f = 127, m = 4 * 128; m > 0; --m)
p = y[f + 34 & 127], d = y[f = f + 1 & 127], p ^= p << 13, d ^= d << 17, p ^= p >>> 15, d ^= d >>> 12, y[f] = p ^ d;
u.w = g, u.X = y, u.i = f;
}
l(c, o);
}
function a(o, c) {
return c.i = o.i, c.w = o.w, c.X = o.X.slice(), c;
}
function s(o, c) {
o == null && (o = +new Date());
var l = new i(o), u = c && c.state, h = function() {
return (l.next() >>> 0) / 4294967296;
};
return h.double = function() {
do
var d = l.next() >>> 11, p = (l.next() >>> 0) / 4294967296, f = (d + p) / (1 << 21);
while (f === 0);
return f;
}, h.int32 = l.next, h.quick = h, u && (u.X && a(u, l), h.state = function() {
return a(l, {});
}), h;
}
e && e.exports ? e.exports = s : r && r.amd ? r(function() {
return s;
}) : this.xor4096 = s;
})(Xi, n, false);
}), Kk = li(function(n) {
(function(t, e, r) {
function i(o) {
var c = this, l = "";
c.next = function() {
var h = c.b, d = c.c, p = c.d, f = c.a;
return h = h << 25 ^ h >>> 7 ^ d, d = d - p | 0, p = p << 24 ^ p >>> 8 ^ f, f = f - h | 0, c.b = h = h << 20 ^ h >>> 12 ^ d, c.c = d = d - p | 0, c.d = p << 16 ^ d >>> 16 ^ f, c.a = f - h | 0;
}, c.a = 0, c.b = 0, c.c = 2654435769 | 0, c.d = 1367130551, o === Math.floor(o) ? (c.a = o / 4294967296 | 0, c.b = o | 0) : l += o;
for (var u = 0; u < l.length + 20; u++)
c.b ^= l.charCodeAt(u) | 0, c.next();
}
function a(o, c) {
return c.a = o.a, c.b = o.b, c.c = o.c, c.d = o.d, c;
}
function s(o, c) {
var l = new i(o), u = c && c.state, h = function() {
return (l.next() >>> 0) / 4294967296;
};
return h.double = function() {
do
var d = l.next() >>> 11, p = (l.next() >>> 0) / 4294967296, f = (d + p) / (1 << 21);
while (f === 0);
return f;
}, h.int32 = l.next, h.quick = h, u && (typeof u == "object" && a(u, l), h.state = function() {
return a(l, {});
}), h;
}
e && e.exports ? e.exports = s : r && r.amd ? r(function() {
return s;
}) : this.tychei = s;
})(Xi, n, false);
}), ui2 = li(function(n) {
(function(t, e) {
var r = this, i = 256, a = 6, s = 52, o = "random", c = e.pow(i, a), l = e.pow(2, s), u = l * 2, h = i - 1, d;
function p(x, L, N) {
var I = [];
L = L == true ? {entropy: true} : L || {};
var C = y(g(L.entropy ? [x, b(t)] : x != null ? x : w(), 3), I), O = new f(I), D = function() {
for (var F = O.g(a), k = c, B = 0; F < l; )
F = (F + B) * i, k *= i, B = O.g(1);
for (; F >= u; )
F /= 2, k /= 2, B >>>= 1;
return (F + B) / k;
};
return D.int32 = function() {
return O.g(4) | 0;
}, D.quick = function() {
return O.g(4) / 4294967296;
}, D.double = D, y(b(O.S), t), (L.pass || N || function(F, k, B, V) {
return V && (V.S && m(V, O), F.state = function() {
return m(O, {});
}), B ? (e[o] = F, k) : F;
})(D, C, "global" in L ? L.global : this == e, L.state);
}
e["seed" + o] = p;
function f(x) {
var L, N = x.length, I = this, C = 0, O = I.i = I.j = 0, D = I.S = [];
for (N || (x = [N++]); C < i; )
D[C] = C++;
for (C = 0; C < i; C++)
D[C] = D[O = h & O + x[C % N] + (L = D[C])], D[O] = L;
(I.g = function(F) {
for (var k, B = 0, V = I.i, P = I.j, G = I.S; F--; )
k = G[V = h & V + 1], B = B * i + G[h & (G[V] = G[P = h & P + k]) + (G[P] = k)];
return I.i = V, I.j = P, B;
})(i);
}
function m(x, L) {
return L.i = x.i, L.j = x.j, L.S = x.S.slice(), L;
}
function g(x, L) {
var N = [], I = typeof x, C;
if (L && I == "object")
for (C in x)
try {
N.push(g(x[C], L - 1));
} catch (O) {
}
return N.length ? N : I == "string" ? x : x + "\0";
}
function y(x, L) {
for (var N = x + "", I, C = 0; C < N.length; )
L[h & C] = h & (I ^= L[h & C] * 19) + N.charCodeAt(C++);
return b(L);
}
function w() {
try {
var x;
return d && (x = d.randomBytes) ? x = x(i) : (x = new Uint8Array(i), (r.crypto || r.msCrypto).getRandomValues(x)), b(x);
} catch (I) {
var L = r.navigator, N = L && L.plugins;
return [+new Date(), r, N, r.screen, b(t)];
}
}
function b(x) {
return String.fromCharCode.apply(0, x);
}
if (y(e.random(), t), n.exports) {
n.exports = p;
try {
d = ws();
} catch (x) {
}
}
})([], Math);
});
ui2.alea = Hk;
ui2.xor128 = Vk;
ui2.xorwow = Gk;
ui2.xorshift7 = qk;
ui2.xor4096 = Yk;
ui2.tychei = Kk;
var jk = ui2, T1 = jk.alea;
function $k(n, t) {
return ko(n, t);
}
function ko(n, t, e, r) {
if (e === void 0 && (e = new Map()), r === void 0 && (r = new Set()), n == null)
return null;
if (r.has(n))
throw new Error("Circular references are not supported.");
if (e.has(n))
return e.get(n);
var i = t(n);
if (i.recurse && i.value !== null)
throw new Error("A deep map function may not return both a value and recurse=true.");
if (i.recurse)
if (Ji(n)) {
var a = Array.isArray(n) ? [] : {};
r.add(n);
for (var s in n) {
var o = n[s], c = ko(o, t, e, r);
a[s] = c;
}
return r.delete(n), a;
} else
throw new Error("Can't recurse into non-iterable type: " + n);
else
return e.set(n, i.value), i.value;
}
function Xk(n, t) {
return t === void 0 && (t = _1), N1(n, t);
}
function N1(n, t, e) {
e === void 0 && (e = new Set());
var r = n[0];
if (e.has(r))
throw new Error("Circular references are not supported.");
var i = t(n);
if (i.recurse && i.value !== null)
throw new Error("A deep zip function may not return both a value and recurse=true.");
if (i.recurse)
if (Ji(r)) {
var a = Array.isArray(r) ? [] : {};
e.add(r);
var s = function(c) {
var l = n.map(function(h) {
return h[c];
}), u = N1(l, t, e);
a[c] = u;
};
for (var o in r)
s(o);
return e.delete(r), a;
} else
throw new Error("Can't recurse into non-iterable type: " + r);
else
return i.value;
}
function _1(n) {
return n === null ? null : Ji(n[0]) ? {value: null, recurse: true} : {value: n, recurse: false};
}
function C1(n, t) {
return ce(this, void 0, void 0, function() {
var e, r, i, a, s, o, c;
return le(this, function(l) {
switch (l.label) {
case 0:
e = new Map(), ko(n, t, e), r = 0, i = Array.from(e.keys()), l.label = 1;
case 1:
return r < i.length ? (a = i[r], s = e.get(a), Ce.util.isPromise(s) ? [4, s] : [3, 3]) : [3, 4];
case 2:
o = l.sent(), e.set(a, o), l.label = 3;
case 3:
return r++, [3, 1];
case 4:
return c = ko(n, t, e), [2, c];
}
});
});
}
function Ji(n) {
return n != null && !ArrayBuffer.isView(n) && (Array.isArray(n) || typeof n == "object" && !(n instanceof Ce.Tensor));
}
function Zk(n) {
return n == null || Jk(n) || Array.isArray(n) || typeof n == "object" && n instanceof Ce.Tensor || Ce.util.isTypedArray(n);
}
function Jk(n) {
return n === null || typeof n != "object" && typeof n != "function";
}
function e6(n) {
return $k(n, Qk);
}
function Qk(n) {
return n instanceof Ce.Tensor ? {value: n.clone(), recurse: false} : Ji(n) ? {value: null, recurse: true} : {value: n, recurse: false};
}
var R1 = function() {
function n(t) {
if (this.capacity = t, this.begin = 0, this.end = 0, t == null)
throw new RangeError("Can't create a ring buffer of unknown capacity.");
if (t < 1)
throw new RangeError("Can't create ring buffer of capacity < 1.");
this.data = new Array(t), this.doubledCapacity = 2 * t;
}
return n.prototype.wrap = function(t) {
for (; t < 0; )
t += this.doubledCapacity;
return t % this.doubledCapacity;
}, n.prototype.get = function(t) {
if (t < 0)
throw new RangeError("Can't get item at a negative index.");
return this.data[t % this.capacity];
}, n.prototype.set = function(t, e) {
if (t < 0)
throw new RangeError("Can't set item at a negative index.");
this.data[t % this.capacity] = e;
}, n.prototype.length = function() {
var t = this.end - this.begin;
return t < 0 && (t = this.doubledCapacity + t), t;
}, n.prototype.isFull = function() {
return this.length() === this.capacity;
}, n.prototype.isEmpty = function() {
return this.length() === 0;
}, n.prototype.push = function(t) {
if (this.isFull())
throw new RangeError("Ring buffer is full.");
this.set(this.end, t), this.end = this.wrap(this.end + 1);
}, n.prototype.pushAll = function(t) {
for (var e = 0, r = t; e < r.length; e++) {
var i = r[e];
this.push(i);
}
}, n.prototype.pop = function() {
if (this.isEmpty())
throw new RangeError("Ring buffer is empty.");
this.end = this.wrap(this.end - 1);
var t = this.get(this.end);
return this.set(this.end, void 0), t;
}, n.prototype.unshift = function(t) {
if (this.isFull())
throw new RangeError("Ring buffer is full.");
this.begin = this.wrap(this.begin - 1), this.set(this.begin, t);
}, n.prototype.shift = function() {
if (this.isEmpty())
throw new RangeError("Ring buffer is empty.");
var t = this.get(this.begin);
return this.set(this.begin, void 0), this.begin = this.wrap(this.begin + 1), t;
}, n.prototype.shuffleExcise = function(t) {
if (this.isEmpty())
throw new RangeError("Ring buffer is empty.");
var e = this.wrap(this.begin + t), r = this.get(e);
return this.set(e, this.pop()), r;
}, n;
}();
var t6 = function(n) {
Ye(t, n);
function t() {
return n.call(this, t.INITIAL_CAPACITY) || this;
}
return t.prototype.isFull = function() {
return false;
}, t.prototype.push = function(e) {
n.prototype.isFull.call(this) && this.expand(), n.prototype.push.call(this, e);
}, t.prototype.unshift = function(e) {
n.prototype.isFull.call(this) && this.expand(), n.prototype.unshift.call(this, e);
}, t.prototype.expand = function() {
for (var e = this.capacity * 2, r = new Array(e), i = this.length(), a = 0; a < i; a++)
r[a] = this.get(this.wrap(this.begin + a));
this.data = r, this.capacity = e, this.doubledCapacity = 2 * this.capacity, this.begin = 0, this.end = i;
}, t.INITIAL_CAPACITY = 32, t;
}(R1);
function O1(n) {
return new n6(n);
}
function Ld(n) {
return new r6(n);
}
function i6(n, t) {
return new E1(n, t);
}
function s6(n, t) {
return t === void 0 && (t = Or.FAIL), new a6(n, t);
}
var Rt = function() {
function n() {
}
return n.prototype.toArray = function() {
return ce(this, void 0, void 0, function() {
var t, e;
return le(this, function(r) {
switch (r.label) {
case 0:
return t = [], [4, this.next()];
case 1:
e = r.sent(), r.label = 2;
case 2:
return e.done ? [3, 4] : (t.push(e.value), [4, this.next()]);
case 3:
return e = r.sent(), [3, 2];
case 4:
return [2, t];
}
});
});
}, n.prototype.toArrayForTest = function() {
return ce(this, void 0, void 0, function() {
var t, e, r;
return le(this, function(i) {
switch (i.label) {
case 0:
return t = this.prefetch(100), e = [], [4, t.next()];
case 1:
r = i.sent(), i.label = 2;
case 2:
return r.done ? [3, 4] : (e.push(r.value), [4, t.next()]);
case 3:
return r = i.sent(), [3, 2];
case 4:
return [2, e];
}
});
});
}, n.prototype.resolveFully = function() {
return ce(this, void 0, void 0, function() {
var t;
return le(this, function(e) {
switch (e.label) {
case 0:
return [4, this.next()];
case 1:
t = e.sent(), e.label = 2;
case 2:
return t.done ? [3, 4] : [4, this.next()];
case 3:
return t = e.sent(), [3, 2];
case 4:
return [2];
}
});
});
}, n.prototype.resolveWhile = function(t) {
return ce(this, void 0, void 0, function() {
var e, r;
return le(this, function(i) {
switch (i.label) {
case 0:
return [4, this.next()];
case 1:
e = i.sent(), r = t(e.value), i.label = 2;
case 2:
return !e.done && r ? [4, this.next()] : [3, 4];
case 3:
return e = i.sent(), r = t(e.value), [3, 2];
case 4:
return [2];
}
});
});
}, n.prototype.handleErrors = function(t) {
return new p6(this, t);
}, n.prototype.filter = function(t) {
return new h6(this, t);
}, n.prototype.map = function(t) {
return new d6(this, t);
}, n.prototype.mapAsync = function(t) {
return new D1(this, t);
}, n.prototype.serialMapAsync = function(t) {
return new D1(this, t).serial();
}, n.prototype.flatmap = function(t) {
return new f6(this, t);
}, n.prototype.forEachAsync = function(t) {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
return [2, this.map(t).resolveFully()];
});
});
}, n.prototype.serialForEach = function(t) {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
return [2, this.serialMapAsync(t).resolveWhile(function(r) {
return r === true;
})];
});
});
}, n.prototype.rowMajorBatch = function(t, e) {
return e === void 0 && (e = true), new u6(this, t, e);
}, n.prototype.columnMajorBatch = function(t, e, r) {
e === void 0 && (e = true), r === void 0 && (r = _1);
var i = this.rowMajorBatch(t, e);
return i.map(function(a) {
return Xk(a, r);
});
}, n.prototype.concatenate = function(t, e) {
return new E1(O1([this, t]), e);
}, n.prototype.take = function(t) {
return t < 0 || t == null ? this : new l6(this, t);
}, n.prototype.skip = function(t) {
return t < 0 || t == null ? this : new c6(this, t);
}, n.prototype.prefetch = function(t) {
return new k1(this, t);
}, n.prototype.shuffle = function(t, e) {
return new m6(this, t, e);
}, n.prototype.serial = function() {
return new o6(this);
}, n;
}(), n6 = function(n) {
Ye(t, n);
function t(e) {
var r = n.call(this) || this;
return r.items = e, r.trav = 0, r;
}
return t.prototype.summary = function() {
return "Array of " + this.items.length + " items";
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
var e;
return le(this, function(r) {
return this.trav >= this.items.length ? [2, {value: null, done: true}] : (e = this.items[this.trav], this.trav++, [2, {value: e6(e), done: false}]);
});
});
}, t;
}(Rt), r6 = function(n) {
Ye(t, n);
function t(e) {
var r = n.call(this) || this;
return r.nextFn = e, r;
}
return t.prototype.summary = function() {
return "Function call";
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
try {
return [2, this.nextFn()];
} catch (r) {
throw r.message = "Error thrown while iterating through a dataset: " + r.message, r;
}
return [2];
});
});
}, t;
}(Rt), o6 = function(n) {
Ye(t, n);
function t(e) {
var r = n.call(this) || this;
return r.upstream = e, r.lastRead = Promise.resolve({value: null, done: false}), r;
}
return t.prototype.summary = function() {
return this.upstream.summary() + " -> Serial";
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
var e = this;
return le(this, function(r) {
return this.lastRead = this.lastRead.then(function() {
return e.serialNext();
}), [2, this.lastRead];
});
});
}, t.prototype.serialNext = function() {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
return [2, this.upstream.next()];
});
});
}, t;
}(Rt), c6 = function(n) {
Ye(t, n);
function t(e, r) {
var i = n.call(this) || this;
return i.upstream = e, i.maxCount = r, i.count = 0, i.lastRead = Promise.resolve({value: null, done: false}), i;
}
return t.prototype.summary = function() {
return this.upstream.summary() + " -> Skip";
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
var e = this;
return le(this, function(r) {
return this.lastRead = this.lastRead.then(function() {
return e.serialNext();
}), [2, this.lastRead];
});
});
}, t.prototype.serialNext = function() {
return ce(this, void 0, void 0, function() {
var e;
return le(this, function(r) {
switch (r.label) {
case 0:
return this.count++ < this.maxCount ? [4, this.upstream.next()] : [3, 2];
case 1:
return e = r.sent(), e.done ? [2, e] : (Ce.dispose(e.value), [3, 0]);
case 2:
return [2, this.upstream.next()];
}
});
});
}, t;
}(Rt), l6 = function(n) {
Ye(t, n);
function t(e, r) {
var i = n.call(this) || this;
return i.upstream = e, i.maxCount = r, i.count = 0, i;
}
return t.prototype.summary = function() {
return this.upstream.summary() + " -> Take";
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
return this.count++ >= this.maxCount ? [2, {value: null, done: true}] : [2, this.upstream.next()];
});
});
}, t;
}(Rt), u6 = function(n) {
Ye(t, n);
function t(e, r, i) {
i === void 0 && (i = true);
var a = n.call(this) || this;
return a.upstream = e, a.batchSize = r, a.enableSmallLastBatch = i, a.lastRead = Promise.resolve({value: null, done: false}), a;
}
return t.prototype.summary = function() {
return this.upstream.summary() + " -> RowMajorBatch";
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
var e = this;
return le(this, function(r) {
return this.lastRead = this.lastRead.then(function() {
return e.serialNext();
}), [2, this.lastRead];
});
});
}, t.prototype.serialNext = function() {
return ce(this, void 0, void 0, function() {
var e, r;
return le(this, function(i) {
switch (i.label) {
case 0:
e = [], i.label = 1;
case 1:
return e.length < this.batchSize ? [4, this.upstream.next()] : [3, 3];
case 2:
return r = i.sent(), r.done ? this.enableSmallLastBatch && e.length > 0 ? [2, {value: e, done: false}] : [2, {value: null, done: true}] : (e.push(r.value), [3, 1]);
case 3:
return [2, {value: e, done: false}];
}
});
});
}, t;
}(Rt), h6 = function(n) {
Ye(t, n);
function t(e, r) {
var i = n.call(this) || this;
return i.upstream = e, i.predicate = r, i.lastRead = Promise.resolve({value: null, done: false}), i;
}
return t.prototype.summary = function() {
return this.upstream.summary() + " -> Filter";
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
var e = this;
return le(this, function(r) {
return this.lastRead = this.lastRead.then(function() {
return e.serialNext();
}), [2, this.lastRead];
});
});
}, t.prototype.serialNext = function() {
return ce(this, void 0, void 0, function() {
var e;
return le(this, function(r) {
switch (r.label) {
case 0:
return [4, this.upstream.next()];
case 1:
return e = r.sent(), e.done || this.predicate(e.value) ? [2, e] : (Ce.dispose(e.value), [3, 0]);
case 2:
return [2];
}
});
});
}, t;
}(Rt), d6 = function(n) {
Ye(t, n);
function t(e, r) {
var i = n.call(this) || this;
return i.upstream = e, i.transform = r, i;
}
return t.prototype.summary = function() {
return this.upstream.summary() + " -> Map";
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
var e, r, i, a, s, o, c;
return le(this, function(l) {
switch (l.label) {
case 0:
return [4, this.upstream.next()];
case 1:
if (e = l.sent(), e.done)
return [2, {value: null, done: true}];
for (r = Ce.tensor_util.getTensorsInContainer(e.value), i = this.transform(e.value), a = Ce.tensor_util.getTensorsInContainer(i), s = 0, o = r; s < o.length; s++)
c = o[s], Ce.tensor_util.isTensorInList(c, a) || c.dispose();
return [2, {value: i, done: false}];
}
});
});
}, t;
}(Rt), p6 = function(n) {
Ye(t, n);
function t(e, r) {
var i = n.call(this) || this;
return i.upstream = e, i.handler = r, i.count = 0, i.lastRead = Promise.resolve({value: null, done: false}), i;
}
return t.prototype.summary = function() {
return this.upstream.summary() + " -> handleErrors";
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
var e = this;
return le(this, function(r) {
return this.lastRead = this.lastRead.then(function() {
return e.serialNext();
}), [2, this.lastRead];
});
});
}, t.prototype.serialNext = function() {
return ce(this, void 0, void 0, function() {
var e;
return le(this, function(r) {
switch (r.label) {
case 0:
r.label = 1;
case 1:
return r.trys.push([1, 3, , 4]), [4, this.upstream.next()];
case 2:
return [2, r.sent()];
case 3:
return e = r.sent(), this.handler(e) ? [3, 4] : [2, {value: null, done: true}];
case 4:
return [3, 0];
case 5:
return [2];
}
});
});
}, t;
}(Rt), D1 = function(n) {
Ye(t, n);
function t(e, r) {
var i = n.call(this) || this;
return i.upstream = e, i.transform = r, i;
}
return t.prototype.summary = function() {
return this.upstream.summary() + " -> AsyncMap";
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
var e, r, i, a, s, o, c;
return le(this, function(l) {
switch (l.label) {
case 0:
return [4, this.upstream.next()];
case 1:
return e = l.sent(), e.done ? [2, {value: null, done: true}] : (r = Ce.tensor_util.getTensorsInContainer(e.value), [4, this.transform(e.value)]);
case 2:
for (i = l.sent(), a = Ce.tensor_util.getTensorsInContainer(i), s = 0, o = r; s < o.length; s++)
c = o[s], Ce.tensor_util.isTensorInList(c, a) || c.dispose();
return [2, {value: i, done: false}];
}
});
});
}, t;
}(Rt), Sd = function(n) {
Ye(t, n);
function t() {
var e = n.call(this) || this;
return e.outputQueue = new t6(), e.lastRead = Promise.resolve({value: null, done: false}), e;
}
return t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
var e = this;
return le(this, function(r) {
return this.lastRead = this.lastRead.then(function() {
return e.serialNext();
}), [2, this.lastRead];
});
});
}, t.prototype.serialNext = function() {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
switch (e.label) {
case 0:
return this.outputQueue.length() === 0 ? [4, this.pump()] : [3, 2];
case 1:
return e.sent() ? [3, 0] : [2, {value: null, done: true}];
case 2:
return [2, {value: this.outputQueue.shift(), done: false}];
}
});
});
}, t;
}(Rt), f6 = function(n) {
Ye(t, n);
function t(e, r) {
var i = n.call(this) || this;
return i.upstream = e, i.transform = r, i;
}
return t.prototype.summary = function() {
return this.upstream.summary() + " -> Flatmap";
}, t.prototype.pump = function() {
return ce(this, void 0, void 0, function() {
var e, r, i, a, s, o, c;
return le(this, function(l) {
switch (l.label) {
case 0:
return [4, this.upstream.next()];
case 1:
if (e = l.sent(), e.done)
return [2, false];
for (r = Ce.tensor_util.getTensorsInContainer(e.value), i = this.transform(e.value), a = Ce.tensor_util.getTensorsInContainer(i), this.outputQueue.pushAll(i), s = 0, o = r; s < o.length; s++)
c = o[s], Ce.tensor_util.isTensorInList(c, a) || c.dispose();
return [2, true];
}
});
});
}, t;
}(Sd), E1 = function(n) {
Ye(t, n);
function t(e, r) {
var i = n.call(this) || this;
return i.baseErrorHandler = r, i.lastRead = null, i.iterator = null, i.moreIterators = e, i;
}
return t.prototype.summary = function() {
var e = "TODO: fill in upstream of chained summaries";
return e + " -> Chained";
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
return this.lastRead = this.readFromChain(this.lastRead), [2, this.lastRead];
});
});
}, t.prototype.readFromChain = function(e) {
return ce(this, void 0, void 0, function() {
var r, i;
return le(this, function(a) {
switch (a.label) {
case 0:
return [4, e];
case 1:
return a.sent(), this.iterator == null ? [4, this.moreIterators.next()] : [3, 3];
case 2:
if (r = a.sent(), r.done)
return [2, {value: null, done: true}];
this.iterator = r.value, this.baseErrorHandler != null && (this.iterator = this.iterator.handleErrors(this.baseErrorHandler)), a.label = 3;
case 3:
return [4, this.iterator.next()];
case 4:
return i = a.sent(), i.done ? (this.iterator = null, [2, this.readFromChain(e)]) : [2, i];
}
});
});
}, t;
}(Rt), Or;
(function(n) {
n[n.FAIL = 0] = "FAIL", n[n.SHORTEST = 1] = "SHORTEST", n[n.LONGEST = 2] = "LONGEST";
})(Or || (Or = {}));
var a6 = function(n) {
Ye(t, n);
function t(e, r) {
r === void 0 && (r = Or.FAIL);
var i = n.call(this) || this;
return i.iterators = e, i.mismatchMode = r, i.count = 0, i.currentPromise = null, i;
}
return t.prototype.summary = function() {
var e = "TODO: fill in upstream of zip summaries";
return "{" + e + "} -> Zip";
}, t.prototype.nextState = function(e) {
return ce(this, void 0, void 0, function() {
function r(o) {
if (o instanceof Rt) {
var c = o.next();
return {value: c.then(function(l) {
return i++, l.done && a++, l.value;
}), recurse: false};
} else
return {value: null, recurse: true};
}
var i, a, s;
return le(this, function(o) {
switch (o.label) {
case 0:
return [4, e];
case 1:
return o.sent(), i = 0, a = 0, [4, C1(this.iterators, r)];
case 2:
if (s = o.sent(), i === a)
return [2, {value: null, done: true}];
if (a > 0)
switch (this.mismatchMode) {
case Or.FAIL:
throw new Error("Zipped streams should have the same length. " + ("Mismatched at element " + this.count + "."));
case Or.SHORTEST:
return [2, {value: null, done: true}];
case Or.LONGEST:
}
return this.count++, [2, {value: s, done: false}];
}
});
});
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
return this.currentPromise = this.nextState(this.currentPromise), [2, this.currentPromise];
});
});
}, t;
}(Rt), k1 = function(n) {
Ye(t, n);
function t(e, r) {
var i = n.call(this) || this;
return i.upstream = e, i.bufferSize = r, i.buffer = new R1(r), i;
}
return t.prototype.summary = function() {
return this.upstream.summary() + " -> Prefetch";
}, t.prototype.refill = function() {
for (; !this.buffer.isFull(); ) {
var e = this.upstream.next();
this.buffer.push(e);
}
}, t.prototype.next = function() {
return this.refill(), this.buffer.shift();
}, t;
}(Rt), m6 = function(n) {
Ye(t, n);
function t(e, r, i) {
var a = n.call(this, e, r) || this;
return a.upstream = e, a.windowSize = r, a.upstreamExhausted = false, a.random = T1(i || Ce.util.now().toString()), a.lastRead = Promise.resolve({value: null, done: false}), a;
}
return t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
var e = this;
return le(this, function(r) {
return this.lastRead = this.lastRead.then(function() {
return e.serialNext();
}), [2, this.lastRead];
});
});
}, t.prototype.randomInt = function(e) {
return Math.floor(this.random() * e);
}, t.prototype.chooseIndex = function() {
return this.randomInt(this.buffer.length());
}, t.prototype.serialNext = function() {
return ce(this, void 0, void 0, function() {
var e, r;
return le(this, function(i) {
switch (i.label) {
case 0:
this.upstreamExhausted || this.refill(), i.label = 1;
case 1:
return this.buffer.isEmpty() ? [3, 3] : (e = this.chooseIndex(), [4, this.buffer.shuffleExcise(e)]);
case 2:
if (r = i.sent(), r.done)
this.upstreamExhausted = true;
else
return this.refill(), [2, r];
return [3, 1];
case 3:
return [2, {value: null, done: true}];
}
});
});
}, t;
}(k1);
var Xa = function() {
function n() {
this.size = null;
}
return n.prototype.batch = function(t, e) {
var r = this;
e === void 0 && (e = true);
var i = this;
Ce.util.assert(t > 0, function() {
return `batchSize needs to be positive, but it is
` + t;
});
var a;
return this.size === Infinity || this.size == null ? a = this.size : e ? a = Math.ceil(this.size / t) : a = Math.floor(this.size / t), tn(function() {
return ce(r, void 0, void 0, function() {
return le(this, function(s) {
switch (s.label) {
case 0:
return [4, i.iterator()];
case 1:
return [2, s.sent().columnMajorBatch(t, e, g6)];
}
});
});
}, a);
}, n.prototype.concatenate = function(t) {
var e = this, r = this, i;
return this.size === Infinity || t.size === Infinity ? i = Infinity : this.size != null && t.size != null ? i = this.size + t.size : i = null, tn(function() {
return ce(e, void 0, void 0, function() {
var a, s;
return le(this, function(o) {
switch (o.label) {
case 0:
return [4, r.iterator()];
case 1:
return s = (a = o.sent()).concatenate, [4, t.iterator()];
case 2:
return [2, s.apply(a, [o.sent()])];
}
});
});
}, i);
}, n.prototype.filter = function(t) {
var e = this, r = this, i;
return this.size === Infinity ? i = Infinity : i = null, tn(function() {
return ce(e, void 0, void 0, function() {
return le(this, function(a) {
switch (a.label) {
case 0:
return [4, r.iterator()];
case 1:
return [2, a.sent().filter(function(s) {
return Ce.tidy(function() {
return t(s);
});
})];
}
});
});
}, i);
}, n.prototype.forEachAsync = function(t) {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
switch (e.label) {
case 0:
return [4, this.iterator()];
case 1:
return [2, e.sent().forEachAsync(t)];
}
});
});
}, n.prototype.map = function(t) {
var e = this, r = this;
return tn(function() {
return ce(e, void 0, void 0, function() {
return le(this, function(i) {
switch (i.label) {
case 0:
return [4, r.iterator()];
case 1:
return [2, i.sent().map(function(a) {
return Ce.tidy(function() {
return t(a);
});
})];
}
});
});
}, this.size);
}, n.prototype.mapAsync = function(t) {
var e = this, r = this;
return tn(function() {
return ce(e, void 0, void 0, function() {
return le(this, function(i) {
switch (i.label) {
case 0:
return [4, r.iterator()];
case 1:
return [2, i.sent().mapAsync(t)];
}
});
});
}, this.size);
}, n.prototype.prefetch = function(t) {
var e = this;
if (t == null)
throw new RangeError("`Dataset.prefetch()` requires bufferSize to be specified.");
var r = this;
return tn(function() {
return ce(e, void 0, void 0, function() {
return le(this, function(i) {
switch (i.label) {
case 0:
return [4, r.iterator()];
case 1:
return [2, i.sent().prefetch(t)];
}
});
});
}, this.size);
}, n.prototype.repeat = function(t) {
var e = this, r = this, i;
return this.size != null && t > 0 ? i = this.size * t : t === 0 ? i = 0 : this.size != null && (t === void 0 || t < 0) ? i = Infinity : i = null, tn(function() {
return ce(e, void 0, void 0, function() {
var a, s = this;
return le(this, function(o) {
return a = Ld(function() {
return ce(s, void 0, void 0, function() {
var c;
return le(this, function(l) {
switch (l.label) {
case 0:
return c = {}, [4, r.iterator()];
case 1:
return [2, (c.value = l.sent(), c.done = false, c)];
}
});
});
}), [2, i6(a.take(t))];
});
});
}, i);
}, n.prototype.skip = function(t) {
var e = this, r = this, i;
return this.size != null && t >= 0 && this.size >= t ? i = this.size - t : this.size != null && (this.size < t || t === void 0 || t < 0) ? i = 0 : i = null, tn(function() {
return ce(e, void 0, void 0, function() {
return le(this, function(a) {
switch (a.label) {
case 0:
return [4, r.iterator()];
case 1:
return [2, a.sent().skip(t)];
}
});
});
}, i);
}, n.prototype.shuffle = function(t, e, r) {
var i = this;
if (r === void 0 && (r = true), t == null || t < 0)
throw this.size == null ? new RangeError("`Dataset.shuffle()` requires bufferSize to be specified.") : new RangeError("`Dataset.shuffle()` requires bufferSize to be specified. If your data fits in main memory (for regular JS objects), and/or GPU memory (for `tf.Tensor`s), consider setting " + ("bufferSize to the dataset size (" + this.size + " elements)"));
var a = this, s = T1(e || Ce.util.now().toString());
return tn(function() {
return ce(i, void 0, void 0, function() {
var o;
return le(this, function(c) {
switch (c.label) {
case 0:
return o = s.int32(), r && (o += s.int32()), [4, a.iterator()];
case 1:
return [2, c.sent().shuffle(t, o.toString())];
}
});
});
}, this.size);
}, n.prototype.take = function(t) {
var e = this, r = this, i;
return this.size != null && this.size > t ? i = t : this.size != null && this.size <= t ? i = this.size : i = null, tn(function() {
return ce(e, void 0, void 0, function() {
return le(this, function(a) {
switch (a.label) {
case 0:
return [4, r.iterator()];
case 1:
return [2, a.sent().take(t)];
}
});
});
}, i);
}, n.prototype.toArray = function() {
return ce(this, void 0, void 0, function() {
return le(this, function(t) {
switch (t.label) {
case 0:
if (this.size === Infinity)
throw new Error("Can not convert infinite data stream to array.");
return [4, this.iterator()];
case 1:
return [2, t.sent().toArray()];
}
});
});
}, n.prototype.toArrayForTest = function() {
return ce(this, void 0, void 0, function() {
return le(this, function(t) {
switch (t.label) {
case 0:
if (this.size === Infinity)
throw new Error("Can not convert infinite data stream to array.");
return [4, this.iterator()];
case 1:
return [2, t.sent().toArrayForTest()];
}
});
});
}, n.MAX_BUFFER_SIZE = 1e4, n;
}();
function tn(n, t) {
return t === void 0 && (t = null), new (function(e) {
Ye(r, e);
function r() {
var i = e !== null && e.apply(this, arguments) || this;
return i.size = t, i;
}
return r.prototype.iterator = function() {
return ce(this, void 0, void 0, function() {
return le(this, function(i) {
return [2, n()];
});
});
}, r;
}(Xa))();
}
function y6(n) {
var t = this;
return tn(function() {
return ce(t, void 0, void 0, function() {
return le(this, function(e) {
return [2, O1(n)];
});
});
}, n.length);
}
function v6(n) {
var t = this;
if (!Ji(n))
throw new Error("The argument to zip() must be an object or array.");
var e;
if (Array.isArray(n))
for (var r = 0; r < n.length; r++)
e = e == null ? n[r].size : Math.min(e, n[r].size);
else if (n instanceof Object)
for (var i in n)
e = e == null ? n[i].size : Math.min(e, n[i].size);
return tn(function() {
return ce(t, void 0, void 0, function() {
var a;
return le(this, function(s) {
switch (s.label) {
case 0:
return [4, C1(n, function(o) {
if (o instanceof Xa)
return {value: o.iterator(), recurse: false};
if (Ji(o))
return {value: null, recurse: true};
throw new Error("Leaves of the structure passed to zip() must be Datasets, not primitives.");
})];
case 1:
return a = s.sent(), [2, s6(a, Or.SHORTEST)];
}
});
});
}, e);
}
function g6(n) {
if (n === null)
return null;
var t = n[0];
if (Zk(t)) {
var e = w6(n);
return {value: e, recurse: false};
}
return {value: null, recurse: true};
}
function w6(n) {
if (n.length === 0)
throw new Error("Can't make a batch of zero elements.");
return n[0] instanceof Ce.Tensor ? Ce.stack(n) : Ce.tensor(n);
}
var F1 = function(n) {
Ye(t, n);
function t(e) {
var r = n.call(this) || this;
return r.input = e, r;
}
return t.prototype.iterator = function() {
return ce(this, void 0, void 0, function() {
var e, r, i;
return le(this, function(a) {
switch (a.label) {
case 0:
return [4, this.input.iterator()];
case 1:
return e = a.sent(), r = e.decodeUTF8(), i = r.split(`
`).map(function(s) {
return s.endsWith("\r") && (s = s.slice(0, -1)), s;
}), [2, i];
}
});
});
}, t;
}(Xa);
var Fo = '"', Ja = Symbol("out"), W1 = Symbol("field"), Wo = Symbol("quote"), Id = Symbol("quoteafterquote"), U1 = Symbol("quoteinquote"), B1 = function(n) {
Ye(t, n);
function t(e, r) {
var i = n.call(this) || this;
return i.input = e, i.hasHeader = true, i.fullColumnNames = null, i.columnNamesValidated = false, i.columnConfigs = null, i.configuredColumnsOnly = false, i.delimiter = ",", i.delimWhitespace = false, i.base = new F1(e), r || (r = {}), i.hasHeader = !(r.hasHeader === false), i.fullColumnNames = r.columnNames, i.columnConfigs = r.columnConfigs, i.configuredColumnsOnly = r.configuredColumnsOnly, r.delimWhitespace ? (Ce.util.assert(r.delimiter == null, function() {
return "Delimiter should not be provided when delimWhitespace is true.";
}), i.delimWhitespace = true, i.delimiter = " ") : i.delimiter = r.delimiter ? r.delimiter : ",", i;
}
return t.prototype.columnNames = function() {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
switch (e.label) {
case 0:
return this.columnNamesValidated ? [3, 2] : [4, this.setColumnNames()];
case 1:
e.sent(), e.label = 2;
case 2:
return [2, this.configuredColumnsOnly ? Object.keys(this.columnConfigs) : this.fullColumnNames];
}
});
});
}, t.prototype.setColumnNames = function() {
return ce(this, void 0, void 0, function() {
var e, r, i, a, s, o, c, l = this;
return le(this, function(u) {
switch (u.label) {
case 0:
return [4, this.maybeReadHeaderLine()];
case 1:
if (e = u.sent(), !this.fullColumnNames && !e)
throw new Error("Column names must be provided if there is no header line.");
if (this.fullColumnNames && e && Ce.util.assert(e.length === this.fullColumnNames.length, function() {
return "The length of provided columnNames (" + l.fullColumnNames.length.toString() + ") does not match the length of the header line read from file (" + e.length.toString() + ").";
}), this.fullColumnNames || (this.fullColumnNames = e), r = this.fullColumnNames.reduce(function(h, d) {
return h[d] = h[d] + 1 || 1, h;
}, {}), i = Object.keys(r).filter(function(h) {
return r[h] > 1;
}), Ce.util.assert(i.length === 0, function() {
return "Duplicate column names found: " + i.toString();
}), this.columnConfigs) {
for (a = 0, s = Object.keys(this.columnConfigs); a < s.length; a++)
if (o = s[a], c = this.fullColumnNames.indexOf(o), c === -1)
throw new Error('The key "' + o + '" provided in columnConfigs does not match any of the column names (' + this.fullColumnNames.toString() + ").");
}
return this.columnNamesValidated = true, [2];
}
});
});
}, t.prototype.maybeReadHeaderLine = function() {
return ce(this, void 0, void 0, function() {
var e, r, i, a;
return le(this, function(s) {
switch (s.label) {
case 0:
return this.hasHeader ? [4, this.base.iterator()] : [3, 3];
case 1:
return e = s.sent(), [4, e.next()];
case 2:
if (r = s.sent(), r.done)
throw new Error("No data was found for CSV parsing.");
return i = r.value, a = this.parseRow(i, false), [2, a];
case 3:
return [2, null];
}
});
});
}, t.prototype.iterator = function() {
return ce(this, void 0, void 0, function() {
var e, r = this;
return le(this, function(i) {
switch (i.label) {
case 0:
return this.columnNamesValidated ? [3, 2] : [4, this.setColumnNames()];
case 1:
i.sent(), i.label = 2;
case 2:
return [4, this.base.iterator()];
case 3:
return e = i.sent(), this.hasHeader && (e = e.skip(1)), [2, e.map(function(a) {
return r.makeDataElement(a);
})];
}
});
});
}, t.prototype.makeDataElement = function(e) {
for (var r = this.parseRow(e), i = {}, a = {}, s = 0; s < this.fullColumnNames.length; s++) {
var o = this.fullColumnNames[s], c = this.columnConfigs ? this.columnConfigs[o] : null;
if (this.configuredColumnsOnly && !c)
continue;
var l = r[s], u = null;
if (l === "")
if (c && c.default !== void 0)
u = c.default;
else {
if (c && (c.required || c.isLabel))
throw new Error("Required column " + o + " is empty in this line: " + e);
u = void 0;
}
else {
var h = Number(l);
if (isNaN(h))
c && c.dtype === "bool" ? u = this.getBoolean(l) : u = l;
else if (!c || !c.dtype)
u = h;
else
switch (c.dtype) {
case "float32":
u = h;
break;
case "int32":
u = Math.floor(h);
break;
case "bool":
u = this.getBoolean(l);
break;
default:
u = h;
}
}
c && c.isLabel ? a[o] = u : i[o] = u;
}
return Object.keys(a).length === 0 ? i : {xs: i, ys: a};
}, t.prototype.getBoolean = function(e) {
return e === "1" || e.toLowerCase() === "true" ? 1 : 0;
}, t.prototype.parseRow = function(e, r) {
r === void 0 && (r = true);
for (var i = [], a = 0, s = e.length, o = Ja, c = 0; c < s; c++)
switch (o) {
case Ja:
switch (e.charAt(c)) {
case Fo:
a = c + 1, o = Wo;
break;
case this.delimiter:
if (a = c + 1, this.delimiter === " " && this.delimWhitespace)
break;
i.push(""), o = Ja;
break;
default:
o = W1, a = c;
break;
}
break;
case W1:
switch (e.charAt(c)) {
case this.delimiter:
i.push(e.substring(a, c)), o = Ja, a = c + 1;
break;
}
break;
case Wo:
switch (e.charAt(c)) {
case Fo:
o = Id;
break;
}
break;
case Id:
switch (e.charAt(c)) {
case this.delimiter:
i.push(e.substring(a, c - 1)), o = Ja, a = c + 1;
break;
case Fo:
o = Wo;
break;
default:
o = U1;
break;
}
break;
case U1:
switch (e.charAt(c)) {
case Fo:
o = Wo;
break;
}
break;
}
if (o === Id ? i.push(e.substring(a, s - 1)) : i.push(e.substring(a)), r && i.length !== this.fullColumnNames.length)
throw new Error("Invalid row in csv file. Should have " + this.fullColumnNames.length + " elements in a row, but got " + i);
return i;
}, t;
}(Xa);
var b6 = function(n) {
Ye(t, n);
function t(e) {
var r = n.call(this) || this;
r.microphoneConfig = e, r.isClosed = false, r.fftSize = e.fftSize || 1024;
var i = Math.log2(r.fftSize);
if (r.fftSize < 0 || i < 4 || i > 14 || !Number.isInteger(i))
throw new Error("Invalid fftSize: it must be a power of 2 between " + ("2 to 4 and 2 to 14, but got " + r.fftSize));
if (r.numFrames = e.numFramesPerSpectrogram || 43, r.sampleRateHz = e.sampleRateHz, r.columnTruncateLength = e.columnTruncateLength || r.fftSize, r.audioTrackConstraints = e.audioTrackConstraints, r.smoothingTimeConstant = e.smoothingTimeConstant || 0, r.includeSpectrogram = !(e.includeSpectrogram === false), r.includeWaveform = e.includeWaveform === true, !r.includeSpectrogram && !r.includeWaveform)
throw new Error("Both includeSpectrogram and includeWaveform are false. At least one type of data should be returned.");
return r;
}
return t.prototype.summary = function() {
return "microphone";
}, t.create = function(e) {
return e === void 0 && (e = {}), ce(this, void 0, void 0, function() {
var r;
return le(this, function(i) {
switch (i.label) {
case 0:
if (Ce.env().get("IS_NODE"))
throw new Error("microphone API is only supported in browser environment.");
return r = new t(e), [4, r.start()];
case 1:
return i.sent(), [2, r];
}
});
});
}, t.prototype.start = function() {
return ce(this, void 0, void 0, function() {
var e, r, i, a;
return le(this, function(s) {
switch (s.label) {
case 0:
return s.trys.push([0, 2, , 3]), e = this, [4, navigator.mediaDevices.getUserMedia({audio: this.audioTrackConstraints == null ? true : this.audioTrackConstraints, video: false})];
case 1:
return e.stream = s.sent(), [3, 3];
case 2:
throw r = s.sent(), new Error("Error thrown while initializing video stream: " + r.message);
case 3:
if (!this.stream)
throw new Error("Could not obtain audio from microphone.");
if (i = window.AudioContext || window.webkitAudioContext, this.audioContext = new i(), !this.sampleRateHz)
this.sampleRateHz = this.audioContext.sampleRate;
else if (this.audioContext.sampleRate !== this.sampleRateHz)
throw new Error("Mismatch in sampling rate: " + ("Expected: " + this.sampleRateHz + "; ") + ("Actual: " + this.audioContext.sampleRate));
return a = this.audioContext.createMediaStreamSource(this.stream), this.analyser = this.audioContext.createAnalyser(), this.analyser.fftSize = this.fftSize * 2, this.analyser.smoothingTimeConstant = this.smoothingTimeConstant, a.connect(this.analyser), this.freqData = new Float32Array(this.fftSize), this.timeData = new Float32Array(this.fftSize), [2];
}
});
});
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
var e, r, i, a, s;
return le(this, function(o) {
switch (o.label) {
case 0:
return this.isClosed ? [2, {value: null, done: true}] : [4, this.getAudioData()];
case 1:
return i = o.sent(), this.includeSpectrogram && (a = this.flattenQueue(i.freqDataQueue), e = this.getTensorFromAudioDataArray(a, [this.numFrames, this.columnTruncateLength, 1])), this.includeWaveform && (s = this.flattenQueue(i.timeDataQueue), r = this.getTensorFromAudioDataArray(s, [this.numFrames * this.fftSize, 1])), [2, {value: {spectrogram: e, waveform: r}, done: false}];
}
});
});
}, t.prototype.capture = function() {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
switch (e.label) {
case 0:
return [4, this.next()];
case 1:
return [2, e.sent().value];
}
});
});
}, t.prototype.getAudioData = function() {
return ce(this, void 0, void 0, function() {
var e, r, i, a = this;
return le(this, function(s) {
return e = [], r = [], i = 0, [2, new Promise(function(o) {
var c = setInterval(function() {
a.includeSpectrogram && (a.analyser.getFloatFrequencyData(a.freqData), a.freqData[0] === -Infinity && o({freqDataQueue: e, timeDataQueue: r}), e.push(a.freqData.slice(0, a.columnTruncateLength))), a.includeWaveform && (a.analyser.getFloatTimeDomainData(a.timeData), r.push(a.timeData.slice())), ++i === a.numFrames && (clearInterval(c), o({freqDataQueue: e, timeDataQueue: r}));
}, a.fftSize / a.sampleRateHz * 1e3);
})];
});
});
}, t.prototype.stop = function() {
this.isClosed || (this.isClosed = true, this.analyser.disconnect(), this.audioContext.close(), this.stream != null && this.stream.getTracks().length > 0 && this.stream.getTracks()[0].stop());
}, t.prototype.toArray = function() {
throw new Error("Can not convert infinite audio stream to array.");
}, t.prototype.getSampleRate = function() {
return this.sampleRateHz;
}, t.prototype.flattenQueue = function(e) {
var r = e[0].length, i = new Float32Array(e.length * r);
return e.forEach(function(a, s) {
return i.set(a, s * r);
}), i;
}, t.prototype.getTensorFromAudioDataArray = function(e, r) {
var i = new Float32Array(Ce.util.sizeFromShape(r));
return i.set(e, i.length - e.length), Ce.tensor(i, r);
}, t;
}(Rt);
var x6 = function(n) {
Ye(t, n);
function t(e, r) {
var i = n.call(this) || this;
if (i.webcamVideoElement = e, i.webcamConfig = r, i.isClosed = true, i.resize = false, i.needToResize())
if (i.resize = true, i.cropSize = [i.webcamConfig.resizeHeight, i.webcamConfig.resizeWidth], i.cropBoxInd = Ce.tensor1d([0], "int32"), i.webcamConfig.centerCrop) {
var a = i.webcamConfig.resizeWidth * 1 / i.webcamVideoElement.width, s = i.webcamConfig.resizeHeight * 1 / i.webcamVideoElement.height, o = (1 - a) / 2, c = (1 - s) / 2, l = o + a, u = s + c;
i.cropBox = Ce.tensor2d([c, o, u, l], [1, 4]);
} else
i.cropBox = Ce.tensor2d([0, 0, 1, 1], [1, 4]);
return i;
}
return t.prototype.summary = function() {
return "webcam";
}, t.create = function(e, r) {
return r === void 0 && (r = {}), ce(this, void 0, void 0, function() {
var i;
return le(this, function(a) {
switch (a.label) {
case 0:
if (Ce.env().get("IS_NODE"))
throw new Error("tf.data.webcam is only supported in browser environment.");
if (!e) {
if (e = document.createElement("video"), !r.resizeWidth || !r.resizeHeight)
throw new Error("Please provide webcam video element, or resizeWidth and resizeHeight to create a hidden video element.");
e.width = r.resizeWidth, e.height = r.resizeHeight;
}
return i = new t(e, r), [4, i.start()];
case 1:
return a.sent(), [2, i];
}
});
});
}, t.prototype.start = function() {
return ce(this, void 0, void 0, function() {
var e, r, i = this;
return le(this, function(a) {
switch (a.label) {
case 0:
this.webcamConfig.facingMode && Ce.util.assert(this.webcamConfig.facingMode === "user" || this.webcamConfig.facingMode === "environment", function() {
return "Invalid webcam facing mode: " + i.webcamConfig.facingMode + ". Please provide 'user' or 'environment'";
}), a.label = 1;
case 1:
return a.trys.push([1, 3, , 4]), e = this, [4, navigator.mediaDevices.getUserMedia({video: {deviceId: this.webcamConfig.deviceId, facingMode: this.webcamConfig.facingMode ? this.webcamConfig.facingMode : "user", width: this.webcamVideoElement.width, height: this.webcamVideoElement.height}})];
case 2:
return e.stream = a.sent(), [3, 4];
case 3:
throw r = a.sent(), r.message = "Error thrown while initializing video stream: " + r.message, r;
case 4:
if (!this.stream)
throw new Error("Could not obtain video from webcam.");
try {
this.webcamVideoElement.srcObject = this.stream;
} catch (s) {
console.log(s), this.webcamVideoElement.src = window.URL.createObjectURL(this.stream);
}
return this.webcamVideoElement.play(), this.isClosed = false, [2, new Promise(function(s) {
i.webcamVideoElement.onloadedmetadata = function() {
s();
};
})];
}
});
});
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
var e;
return le(this, function(r) {
if (this.isClosed)
return [2, {value: null, done: true}];
try {
e = Ce.browser.fromPixels(this.webcamVideoElement);
} catch (i) {
throw new Error("Error thrown converting video to pixels: " + JSON.stringify(i));
}
if (this.resize)
try {
return [2, {value: this.cropAndResizeFrame(e), done: false}];
} catch (i) {
throw new Error("Error thrown cropping the video: " + i.message);
} finally {
e.dispose();
}
else
return [2, {value: e, done: false}];
return [2];
});
});
}, t.prototype.needToResize = function() {
return !!(this.webcamConfig.resizeWidth && this.webcamConfig.resizeHeight && (this.webcamVideoElement.width !== this.webcamConfig.resizeWidth || this.webcamVideoElement.height !== this.webcamConfig.resizeHeight));
}, t.prototype.cropAndResizeFrame = function(e) {
var r = this;
return Ce.tidy(function() {
var i = e.toFloat().expandDims(0), a;
a = Ce.image.cropAndResize(i, r.cropBox, r.cropBoxInd, r.cropSize, "bilinear");
var s = a.shape;
return a.reshape(s.slice(1));
});
}, t.prototype.capture = function() {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
switch (e.label) {
case 0:
return [4, this.next()];
case 1:
return [2, e.sent().value];
}
});
});
}, t.prototype.stop = function() {
var e = this.stream.getTracks();
e.forEach(function(r) {
return r.stop();
});
try {
this.webcamVideoElement.srcObject = null;
} catch (r) {
console.log(r), this.webcamVideoElement.src = null;
}
this.isClosed = true;
}, t.prototype.toArray = function() {
throw new Error("Can not convert infinite video stream to array.");
}, t;
}(Rt);
var z1 = function() {
function n() {
}
return n;
}();
var P1 = function(n) {
Ye(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.split = function(e) {
return new L6(this, e);
}, t;
}(Rt), L6 = function(n) {
Ye(t, n);
function t(e, r) {
var i = n.call(this) || this;
return i.upstream = e, i.impl = new S6(e, r), i;
}
return t.prototype.summary = function() {
return this.impl.summary();
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
return [2, this.impl.next()];
});
});
}, t;
}(P1), S6 = function(n) {
Ye(t, n);
function t(e, r) {
var i = n.call(this) || this;
return i.upstream = e, i.separator = r, i.carryover = "", i;
}
return t.prototype.summary = function() {
return this.upstream.summary() + " -> Split('" + this.separator + "')";
}, t.prototype.pump = function() {
return ce(this, void 0, void 0, function() {
var e, r, i, a, s;
return le(this, function(o) {
switch (o.label) {
case 0:
return [4, this.upstream.next()];
case 1:
if (e = o.sent(), e.done)
return this.carryover === "" ? [2, false] : (this.outputQueue.push(this.carryover), this.carryover = "", [2, true]);
for (r = e.value.split(this.separator), r[0] = this.carryover + r[0], i = 0, a = r.slice(0, -1); i < a.length; i++)
s = a[i], this.outputQueue.push(s);
return this.carryover = r[r.length - 1], [2, true];
}
});
});
}, t;
}(Sd);
var A6 = function(n) {
Ye(t, n);
function t() {
return n !== null && n.apply(this, arguments) || this;
}
return t.prototype.decodeUTF8 = function() {
return new I6(this);
}, t;
}(Rt), I6 = function(n) {
Ye(t, n);
function t(e) {
var r = n.call(this) || this;
return r.upstream = e, r.impl = new T6(e), r;
}
return t.prototype.summary = function() {
return this.impl.summary();
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
return [2, this.impl.next()];
});
});
}, t;
}(P1), T6 = function(n) {
Ye(t, n);
function t(e) {
var r = n.call(this) || this;
if (r.upstream = e, Ce.env().get("IS_BROWSER"))
r.decoder = new TextDecoder("utf-8");
else {
var i = A1().StringDecoder;
r.decoder = new i("utf8");
}
return r;
}
return t.prototype.summary = function() {
return this.upstream.summary() + " -> Utf8";
}, t.prototype.pump = function() {
return ce(this, void 0, void 0, function() {
var e, r, i;
return le(this, function(a) {
switch (a.label) {
case 0:
return [4, this.upstream.next()];
case 1:
return e = a.sent(), e.done ? [2, false] : (r = e.value, Ce.env().get("IS_BROWSER") ? i = this.decoder.decode(r, {stream: true}) : i = this.decoder.write(Buffer.from(r.buffer)), this.outputQueue.push(i), [2, true]);
}
});
});
}, t;
}(Sd);
var M1 = function(n) {
Ye(t, n);
function t(e, r) {
r === void 0 && (r = {});
var i = n.call(this) || this;
return i.file = e, i.options = r, Ce.util.assert(e instanceof Uint8Array || (Ce.env().get("IS_BROWSER") ? e instanceof File || e instanceof Blob : false), function() {
return "FileChunkIterator only supports File, Blob and Uint8Array right now.";
}), i.offset = r.offset || 0, i.chunkSize = r.chunkSize || 1024 * 1024, i;
}
return t.prototype.summary = function() {
return "FileChunks " + this.file;
}, t.prototype.next = function() {
return ce(this, void 0, void 0, function() {
var e, r, i = this;
return le(this, function(a) {
switch (a.label) {
case 0:
return this.offset >= (this.file instanceof Uint8Array ? this.file.byteLength : this.file.size) ? [2, {value: null, done: true}] : (e = new Promise(function(s, o) {
var c = i.offset + i.chunkSize;
if (i.file instanceof Uint8Array)
s(new Uint8Array(i.file.slice(i.offset, c)));
else {
var l = new FileReader();
l.onload = function(h) {
var d = l.result;
if (d instanceof ArrayBuffer && (d = new Uint8Array(d)), !(d instanceof Uint8Array))
return o(new TypeError("FileReader returned unknown type."));
s(d);
}, l.onabort = function(h) {
return o(new Error("Aborted"));
}, l.onerror = function(h) {
return o(new Error(h.type));
};
var u = i.file.slice(i.offset, c);
l.readAsArrayBuffer(u);
}
i.offset = c;
}), r = {}, [4, e]);
case 1:
return [2, (r.value = a.sent(), r.done = false, r)];
}
});
});
}, t;
}(A6);
function _6(n, t) {
return t === void 0 && (t = {}), ce(this, void 0, void 0, function() {
var e, r, i, a, s;
return le(this, function(o) {
switch (o.label) {
case 0:
return typeof n == "string" ? e = n : (e = n.url, r = N6(n)), [4, Ce.util.fetch(e, r)];
case 1:
return i = o.sent(), i.ok ? (s = Uint8Array.bind, [4, i.arrayBuffer()]) : [3, 3];
case 2:
return a = new (s.apply(Uint8Array, [void 0, o.sent()]))(), [2, new M1(a, t)];
case 3:
throw new Error(i.statusText);
}
});
});
}
var N6 = function(n) {
var t = {method: n.method, headers: n.headers, body: n.body, mode: n.mode, credentials: n.credentials, cache: n.cache, redirect: n.redirect, referrer: n.referrer, integrity: n.integrity};
return t;
};
function H1(n) {
return typeof n == "string" && n.substr(0, 7) === "file://";
}
var V1 = function(n) {
Ye(t, n);
function t(e, r) {
r === void 0 && (r = {});
var i = n.call(this) || this;
return i.input = e, i.options = r, i;
}
return t.prototype.iterator = function() {
return ce(this, void 0, void 0, function() {
var e;
return le(this, function(r) {
return H1(this.input) && Ce.env().get("IS_NODE") && (e = require("fs"), this.input = e.readFileSync(this.input.substr(7))), [2, new M1(this.input, this.options)];
});
});
}, t;
}(z1);
var G1 = function(n) {
Ye(t, n);
function t(e, r) {
r === void 0 && (r = {});
var i = n.call(this) || this;
return i.url = e, i.fileOptions = r, i;
}
return t.prototype.iterator = function() {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
return H1(this.url) ? [2, new V1(this.url, this.fileOptions).iterator()] : [2, _6(this.url, this.fileOptions)];
});
});
}, t;
}(z1);
function C6(n, t) {
return t === void 0 && (t = {}), new B1(new G1(n), t);
}
function R6(n) {
var t = this, e = Ld(n);
return tn(function() {
return ce(t, void 0, void 0, function() {
return le(this, function(r) {
return [2, e];
});
});
});
}
function O6(n) {
var t = this;
return tn(function() {
return ce(t, void 0, void 0, function() {
var e;
return le(this, function(r) {
switch (r.label) {
case 0:
return [4, n()];
case 1:
return e = r.sent(), [2, Ld(function() {
return e.next();
})];
}
});
});
});
}
function E6(n, t) {
return ce(this, void 0, void 0, function() {
return le(this, function(e) {
return [2, x6.create(n, t)];
});
});
}
function D6(n) {
return ce(this, void 0, void 0, function() {
return le(this, function(t) {
return [2, b6.create(n)];
});
});
}
var k6 = "2.7.0";
qt.CSVDataset = B1;
qt.Dataset = Xa;
qt.FileDataSource = V1;
qt.TextLineDataset = F1;
qt.URLDataSource = G1;
qt.array = y6;
qt.csv = C6;
qt.func = R6;
qt.generator = O6;
qt.microphone = D6;
qt.version_data = k6;
qt.webcam = E6;
qt.zip = v6;
});
var K1 = we((Y1, Ad) => {
(function(n, t, e) {
function r(o) {
var c = this, l = s();
c.next = function() {
var u = 2091639 * c.s0 + c.c * 23283064365386963e-26;
return c.s0 = c.s1, c.s1 = c.s2, c.s2 = u - (c.c = u | 0);
}, c.c = 1, c.s0 = l(" "), c.s1 = l(" "), c.s2 = l(" "), c.s0 -= l(o), c.s0 < 0 && (c.s0 += 1), c.s1 -= l(o), c.s1 < 0 && (c.s1 += 1), c.s2 -= l(o), c.s2 < 0 && (c.s2 += 1), l = null;
}
function i(o, c) {
return c.c = o.c, c.s0 = o.s0, c.s1 = o.s1, c.s2 = o.s2, c;
}
function a(o, c) {
var l = new r(o), u = c && c.state, h = l.next;
return h.int32 = function() {
return l.next() * 4294967296 | 0;
}, h.double = function() {
return h() + (h() * 2097152 | 0) * 11102230246251565e-32;
}, h.quick = h, u && (typeof u == "object" && i(u, l), h.state = function() {
return i(l, {});
}), h;
}
function s() {
var o = 4022871197, c = function(l) {
l = l.toString();
for (var u = 0; u < l.length; u++) {
o += l.charCodeAt(u);
var h = 0.02519603282416938 * o;
o = h >>> 0, h -= o, h *= o, o = h >>> 0, h -= o, o += h * 4294967296;
}
return (o >>> 0) * 23283064365386963e-26;
};
return c;
}
t && t.exports ? t.exports = a : e && e.amd ? e(function() {
return a;
}) : this.alea = a;
})(Y1, typeof Ad == "object" && Ad, typeof define == "function" && define);
});
var $1 = we((j1, Td) => {
(function(n, t, e) {
function r(s) {
var o = this, c = "";
o.x = 0, o.y = 0, o.z = 0, o.w = 0, o.next = function() {
var u = o.x ^ o.x << 11;
return o.x = o.y, o.y = o.z, o.z = o.w, o.w ^= o.w >>> 19 ^ u ^ u >>> 8;
}, s === (s | 0) ? o.x = s : c += s;
for (var l = 0; l < c.length + 64; l++)
o.x ^= c.charCodeAt(l) | 0, o.next();
}
function i(s, o) {
return o.x = s.x, o.y = s.y, o.z = s.z, o.w = s.w, o;
}
function a(s, o) {
var c = new r(s), l = o && o.state, u = function() {
return (c.next() >>> 0) / 4294967296;
};
return u.double = function() {
do
var h = c.next() >>> 11, d = (c.next() >>> 0) / 4294967296, p = (h + d) / (1 << 21);
while (p === 0);
return p;
}, u.int32 = c.next, u.quick = u, l && (typeof l == "object" && i(l, c), u.state = function() {
return i(c, {});
}), u;
}
t && t.exports ? t.exports = a : e && e.amd ? e(function() {
return a;
}) : this.xor128 = a;
})(j1, typeof Td == "object" && Td, typeof define == "function" && define);
});
var J1 = we((X1, Nd) => {
(function(n, t, e) {
function r(s) {
var o = this, c = "";
o.next = function() {
var u = o.x ^ o.x >>> 2;
return o.x = o.y, o.y = o.z, o.z = o.w, o.w = o.v, (o.d = o.d + 362437 | 0) + (o.v = o.v ^ o.v << 4 ^ (u ^ u << 1)) | 0;
}, o.x = 0, o.y = 0, o.z = 0, o.w = 0, o.v = 0, s === (s | 0) ? o.x = s : c += s;
for (var l = 0; l < c.length + 64; l++)
o.x ^= c.charCodeAt(l) | 0, l == c.length && (o.d = o.x << 10 ^ o.x >>> 4), o.next();
}
function i(s, o) {
return o.x = s.x, o.y = s.y, o.z = s.z, o.w = s.w, o.v = s.v, o.d = s.d, o;
}
function a(s, o) {
var c = new r(s), l = o && o.state, u = function() {
return (c.next() >>> 0) / 4294967296;
};
return u.double = function() {
do
var h = c.next() >>> 11, d = (c.next() >>> 0) / 4294967296, p = (h + d) / (1 << 21);
while (p === 0);
return p;
}, u.int32 = c.next, u.quick = u, l && (typeof l == "object" && i(l, c), u.state = function() {
return i(c, {});
}), u;
}
t && t.exports ? t.exports = a : e && e.amd ? e(function() {
return a;
}) : this.xorwow = a;
})(X1, typeof Nd == "object" && Nd, typeof define == "function" && define);
});
var Q1 = we((Z1, _d) => {
(function(n, t, e) {
function r(s) {
var o = this;
o.next = function() {
var l = o.x, u = o.i, h, d, p;
return h = l[u], h ^= h >>> 7, d = h ^ h << 24, h = l[u + 1 & 7], d ^= h ^ h >>> 10, h = l[u + 3 & 7], d ^= h ^ h >>> 3, h = l[u + 4 & 7], d ^= h ^ h << 7, h = l[u + 7 & 7], h = h ^ h << 13, d ^= h ^ h << 9, l[u] = d, o.i = u + 1 & 7, d;
};
function c(l, u) {
var h, d, p = [];
if (u === (u | 0))
d = p[0] = u;
else
for (u = "" + u, h = 0; h < u.length; ++h)
p[h & 7] = p[h & 7] << 15 ^ u.charCodeAt(h) + p[h + 1 & 7] << 13;
for (; p.length < 8; )
p.push(0);
for (h = 0; h < 8 && p[h] === 0; ++h)
;
for (h == 8 ? d = p[7] = -1 : d = p[h], l.x = p, l.i = 0, h = 256; h > 0; --h)
l.next();
}
c(o, s);
}
function i(s, o) {
return o.x = s.x.slice(), o.i = s.i, o;
}
function a(s, o) {
s == null && (s = +new Date());
var c = new r(s), l = o && o.state, u = function() {
return (c.next() >>> 0) / 4294967296;
};
return u.double = function() {
do
var h = c.next() >>> 11, d = (c.next() >>> 0) / 4294967296, p = (h + d) / (1 << 21);
while (p === 0);
return p;
}, u.int32 = c.next, u.quick = u, l && (l.x && i(l, c), u.state = function() {
return i(c, {});
}), u;
}
t && t.exports ? t.exports = a : e && e.amd ? e(function() {
return a;
}) : this.xorshift7 = a;
})(Z1, typeof _d == "object" && _d, typeof define == "function" && define);
});
var tw = we((ew, Cd) => {
(function(n, t, e) {
function r(s) {
var o = this;
o.next = function() {
var l = o.w, u = o.X, h = o.i, d, p;
return o.w = l = l + 1640531527 | 0, p = u[h + 34 & 127], d = u[h = h + 1 & 127], p ^= p << 13, d ^= d << 17, p ^= p >>> 15, d ^= d >>> 12, p = u[h] = p ^ d, o.i = h, p + (l ^ l >>> 16) | 0;
};
function c(l, u) {
var h, d, p, f, m, g = [], y = 128;
for (u === (u | 0) ? (d = u, u = null) : (u = u + "\0", d = 0, y = Math.max(y, u.length)), p = 0, f = -32; f < y; ++f)
u && (d ^= u.charCodeAt((f + 32) % u.length)), f === 0 && (m = d), d ^= d << 10, d ^= d >>> 15, d ^= d << 4, d ^= d >>> 13, f >= 0 && (m = m + 1640531527 | 0, h = g[f & 127] ^= d + m, p = h == 0 ? p + 1 : 0);
for (p >= 128 && (g[(u && u.length || 0) & 127] = -1), p = 127, f = 4 * 128; f > 0; --f)
d = g[p + 34 & 127], h = g[p = p + 1 & 127], d ^= d << 13, h ^= h << 17, d ^= d >>> 15, h ^= h >>> 12, g[p] = d ^ h;
l.w = m, l.X = g, l.i = p;
}
c(o, s);
}
function i(s, o) {
return o.i = s.i, o.w = s.w, o.X = s.X.slice(), o;
}
function a(s, o) {
s == null && (s = +new Date());
var c = new r(s), l = o && o.state, u = function() {
return (c.next() >>> 0) / 4294967296;
};
return u.double = function() {
do
var h = c.next() >>> 11, d = (c.next() >>> 0) / 4294967296, p = (h + d) / (1 << 21);
while (p === 0);
return p;
}, u.int32 = c.next, u.quick = u, l && (l.X && i(l, c), u.state = function() {
return i(c, {});
}), u;
}
t && t.exports ? t.exports = a : e && e.amd ? e(function() {
return a;
}) : this.xor4096 = a;
})(ew, typeof Cd == "object" && Cd, typeof define == "function" && define);
});
var rw = we((nw, Rd) => {
(function(n, t, e) {
function r(s) {
var o = this, c = "";
o.next = function() {
var u = o.b, h = o.c, d = o.d, p = o.a;
return u = u << 25 ^ u >>> 7 ^ h, h = h - d | 0, d = d << 24 ^ d >>> 8 ^ p, p = p - u | 0, o.b = u = u << 20 ^ u >>> 12 ^ h, o.c = h = h - d | 0, o.d = d << 16 ^ h >>> 16 ^ p, o.a = p - u | 0;
}, o.a = 0, o.b = 0, o.c = 2654435769 | 0, o.d = 1367130551, s === Math.floor(s) ? (o.a = s / 4294967296 | 0, o.b = s | 0) : c += s;
for (var l = 0; l < c.length + 20; l++)
o.b ^= c.charCodeAt(l) | 0, o.next();
}
function i(s, o) {
return o.a = s.a, o.b = s.b, o.c = s.c, o.d = s.d, o;
}
function a(s, o) {
var c = new r(s), l = o && o.state, u = function() {
return (c.next() >>> 0) / 4294967296;
};
return u.double = function() {
do
var h = c.next() >>> 11, d = (c.next() >>> 0) / 4294967296, p = (h + d) / (1 << 21);
while (p === 0);
return p;
}, u.int32 = c.next, u.quick = u, l && (typeof l == "object" && i(l, c), u.state = function() {
return i(c, {});
}), u;
}
t && t.exports ? t.exports = a : e && e.amd ? e(function() {
return a;
}) : this.tychei = a;
})(nw, typeof Rd == "object" && Rd, typeof define == "function" && define);
});
var iw = we((fG, Uo) => {
(function(n, t) {
var e = this, r = 256, i = 6, a = 52, s = "random", o = t.pow(r, i), c = t.pow(2, a), l = c * 2, u = r - 1, h;
function d(b, x, L) {
var N = [];
x = x == true ? {entropy: true} : x || {};
var I = g(m(x.entropy ? [b, w(n)] : b != null ? b : y(), 3), N), C = new p(N), O = function() {
for (var D = C.g(i), F = o, k = 0; D < c; )
D = (D + k) * r, F *= r, k = C.g(1);
for (; D >= l; )
D /= 2, F /= 2, k >>>= 1;
return (D + k) / F;
};
return O.int32 = function() {
return C.g(4) | 0;
}, O.quick = function() {
return C.g(4) / 4294967296;
}, O.double = O, g(w(C.S), n), (x.pass || L || function(D, F, k, B) {
return B && (B.S && f(B, C), D.state = function() {
return f(C, {});
}), k ? (t[s] = D, F) : D;
})(O, I, "global" in x ? x.global : this == t, x.state);
}
t["seed" + s] = d;
function p(b) {
var x, L = b.length, N = this, I = 0, C = N.i = N.j = 0, O = N.S = [];
for (L || (b = [L++]); I < r; )
O[I] = I++;
for (I = 0; I < r; I++)
O[I] = O[C = u & C + b[I % L] + (x = O[I])], O[C] = x;
(N.g = function(D) {
for (var F, k = 0, B = N.i, V = N.j, P = N.S; D--; )
F = P[B = u & B + 1], k = k * r + P[u & (P[B] = P[V = u & V + F]) + (P[V] = F)];
return N.i = B, N.j = V, k;
})(r);
}
function f(b, x) {
return x.i = b.i, x.j = b.j, x.S = b.S.slice(), x;
}
function m(b, x) {
var L = [], N = typeof b, I;
if (x && N == "object")
for (I in b)
try {
L.push(m(b[I], x - 1));
} catch (C) {
}
return L.length ? L : N == "string" ? b : b + "\0";
}
function g(b, x) {
for (var L = b + "", N, I = 0; I < L.length; )
x[u & I] = u & (N ^= x[u & I] * 19) + L.charCodeAt(I++);
return w(x);
}
function y() {
try {
var b;
return h && (b = h.randomBytes) ? b = b(r) : (b = new Uint8Array(r), (e.crypto || e.msCrypto).getRandomValues(b)), w(b);
} catch (N) {
var x = e.navigator, L = x && x.plugins;
return [+new Date(), e, L, e.screen, w(n)];
}
}
function w(b) {
return String.fromCharCode.apply(0, b);
}
if (g(t.random(), n), typeof Uo == "object" && Uo.exports) {
Uo.exports = d;
try {
h = ws();
} catch (b) {
}
} else
typeof define == "function" && define.amd && define(function() {
return d;
});
})([], Math);
});
var sw = we((mG, aw) => {
var F6 = K1(), W6 = $1(), U6 = J1(), B6 = Q1(), z6 = tw(), P6 = rw(), hi = iw();
hi.alea = F6;
hi.xor128 = W6;
hi.xorwow = U6;
hi.xorshift7 = B6;
hi.xor4096 = z6;
hi.tychei = P6;
aw.exports = hi;
});
var Pw = we((Za) => {
"use strict";
Object.defineProperty(Za, "__esModule", {value: true});
var S = ei(), M6 = sw();
var Od = function(n, t) {
return Od = Object.setPrototypeOf || {__proto__: []} instanceof Array && function(e, r) {
e.__proto__ = r;
} || function(e, r) {
for (var i in r)
r.hasOwnProperty(i) && (e[i] = r[i]);
}, Od(n, t);
};
function H6(n, t) {
Od(n, t);
function e() {
this.constructor = n;
}
n.prototype = t === null ? Object.create(t) : (e.prototype = t.prototype, new e());
}
function ow(n, t, e, r) {
function i(a) {
return a instanceof e ? a : new e(function(s) {
s(a);
});
}
return new (e || (e = Promise))(function(a, s) {
function o(u) {
try {
l(r.next(u));
} catch (h) {
s(h);
}
}
function c(u) {
try {
l(r.throw(u));
} catch (h) {
s(h);
}
}
function l(u) {
u.done ? a(u.value) : i(u.value).then(o, c);
}
l((r = r.apply(n, t || [])).next());
});
}
function cw(n, t) {
var e = {label: 0, sent: function() {
if (a[0] & 1)
throw a[1];
return a[1];
}, trys: [], ops: []}, r, i, a, s;
return s = {next: o(0), throw: o(1), return: o(2)}, typeof Symbol == "function" && (s[Symbol.iterator] = function() {
return this;
}), s;
function o(l) {
return function(u) {
return c([l, u]);
};
}
function c(l) {
if (r)
throw new TypeError("Generator is already executing.");
for (; e; )
try {
if (r = 1, i && (a = l[0] & 2 ? i.return : l[0] ? i.throw || ((a = i.return) && a.call(i), 0) : i.next) && !(a = a.call(i, l[1])).done)
return a;
(i = 0, a) && (l = [l[0] & 2, a.value]);
switch (l[0]) {
case 0:
case 1:
a = l;
break;
case 4:
return e.label++, {value: l[1], done: false};
case 5:
e.label++, i = l[1], l = [0];
continue;
case 7:
l = e.ops.pop(), e.trys.pop();
continue;
default:
if (!(a = e.trys, a = a.length > 0 && a[a.length - 1]) && (l[0] === 6 || l[0] === 2)) {
e = 0;
continue;
}
if (l[0] === 3 && (!a || l[1] > a[0] && l[1] < a[3])) {
e.label = l[1];
break;
}
if (l[0] === 6 && e.label < a[1]) {
e.label = a[1], a = l;
break;
}
if (a && e.label < a[2]) {
e.label = a[2], e.ops.push(l);
break;
}
a[2] && e.ops.pop(), e.trys.pop();
continue;
}
l = t.call(n, e);
} catch (u) {
l = [6, u], i = 0;
} finally {
r = a = 0;
}
if (l[0] & 5)
throw l[1];
return {value: l[0] ? l[1] : void 0, done: true};
}
}
function ae(n, t) {
Array.isArray(n) || (n = [n]), n.forEach(function(e) {
e != null && S.util.assert(e.dtype !== "complex64", function() {
return t + " does not support complex64 tensors in the CPU backend.";
});
});
}
var V6 = S.kernel_impls.nonMaxSuppressionV3Impl, G6 = S.kernel_impls.split, q6 = S.kernel_impls.tile, Y6 = S.kernel_impls.topkImpl, K6 = S.kernel_impls.whereImpl, lw = function(n) {
H6(t, n);
function t() {
var e = n.call(this) || this;
return e.blockSize = 48, e.firstUse = true, e.data = new S.DataStorage(e, S.engine()), e;
}
return t.prototype.write = function(e, r, i) {
this.firstUse && (this.firstUse = false, S.env().get("IS_NODE") && S.backend_util.warn(`
============================
Hi there \u{1F44B}. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node, or npm i @tensorflow/tfjs-node-gpu if you have CUDA. Then call require('@tensorflow/tfjs-node'); (-gpu suffix for CUDA) at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details.
============================`));
var a = {};
return this.data.set(a, {values: e, dtype: i, refCount: 1}), a;
}, t.prototype.makeTensorInfo = function(e, r, i) {
var a;
if (r === "string" && i != null && i.length > 0 && S.util.isString(i[0])) {
var s = i.map(function(o) {
return S.util.encodeString(o);
});
a = this.write(s, e, r);
} else
a = this.write(i, e, r);
return {dataId: a, shape: e, dtype: r};
}, t.prototype.incRef = function(e) {
var r = this.data.get(e);
r.refCount++;
}, t.prototype.decRef = function(e) {
if (this.data.has(e)) {
var r = this.data.get(e);
r.refCount--;
}
}, t.prototype.move = function(e, r, i, a) {
this.data.set(e, {values: r, dtype: a, refCount: 1});
}, t.prototype.numDataIds = function() {
return this.data.numDataIds();
}, t.prototype.read = function(e) {
return ow(this, void 0, void 0, function() {
return cw(this, function(r) {
return [2, this.readSync(e)];
});
});
}, t.prototype.readSync = function(e) {
var r = this.data.get(e), i = r.dtype, a = r.complexTensorInfos;
if (i === "complex64") {
var s = this.readSync(a.real.dataId), o = this.readSync(a.imag.dataId);
return S.backend_util.mergeRealAndImagArrays(s, o);
}
return this.data.get(e).values;
}, t.prototype.bufferSync = function(e) {
var r = this.readSync(e.dataId), i = r;
if (e.dtype === "string")
try {
i = r.map(function(a) {
return S.util.decodeString(a);
});
} catch (a) {
throw new Error("Failed to decode encoded string bytes into utf-8");
}
return S.buffer(e.shape, e.dtype, i);
}, t.prototype.makeOutput = function(e, r, i) {
var a = this.write(e, r, i);
return S.engine().makeTensorFromDataId(a, r, i, this);
}, t.prototype.disposeData = function(e) {
if (this.data.has(e)) {
var r = this.data.get(e).complexTensorInfos;
r != null && (this.disposeData(r.real.dataId), this.disposeData(r.imag.dataId)), this.data.delete(e);
}
}, t.prototype.disposeIntermediateTensorInfo = function(e) {
var r = e.dataId;
if (this.data.has(r)) {
var i = this.data.get(r);
i.refCount--, i.refCount < 1 && this.disposeData(r);
}
}, t.prototype.time = function(e) {
return ow(this, void 0, void 0, function() {
var r, i;
return cw(this, function(a) {
return r = S.util.now(), e(), i = S.util.now() - r, [2, {kernelMs: i}];
});
});
}, t.prototype.memory = function() {
return {unreliable: true, reasons: ["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]};
}, t.prototype.stridedSlice = function(e, r, i, a) {
ae(e, "stridedSlice");
var s = S.slice_util.computeOutShape(r, i, a);
if (s.some(function(p) {
return p === 0;
}))
return S.tensor([], s);
for (var o = S.buffer(s, e.dtype), c = this.bufferSync(e), l = 0; l < o.size; l++) {
for (var u = o.indexToLoc(l), h = new Array(u.length), d = 0; d < h.length; d++)
h[d] = u[d] * a[d] + r[d];
o.set.apply(o, [c.get.apply(c, h)].concat(u));
}
return o.toTensor();
}, t.prototype.diag = function(e) {
for (var r = this.readSync(e.dataId), i = S.buffer([e.size, e.size], e.dtype), a = i.values, s = 0; s < r.length; s++)
a[s * e.size + s] = r[s];
return i.toTensor();
}, t.prototype.unstack = function(e, r) {
for (var i = e.shape[r], a = new Array(e.rank - 1), s = 0, o = 0; o < e.rank; o++)
o !== r && (a[s++] = e.shape[o]);
var c = new Array(e.rank).fill(0), l = e.shape.slice();
l[r] = 1;
for (var u = new Array(i), o = 0; o < u.length; o++)
c[r] = o, u[o] = S.slice(e, c, l).reshape(a);
return u;
}, t.prototype.reverse = function(e, r) {
ae(e, "reverse");
for (var i = S.buffer(e.shape, e.dtype), a = this.bufferSync(e), s = function(c) {
var l = i.indexToLoc(c), u = l.slice();
r.forEach(function(h) {
return u[h] = e.shape[h] - 1 - u[h];
}), i.set.apply(i, [a.get.apply(a, u)].concat(l));
}, o = 0; o < i.size; o++)
s(o);
return i.toTensor();
}, t.prototype.neg = function(e) {
return ae(e, "neg"), S.mul(S.scalar(-1), e);
}, t.prototype.addN = function(e) {
var r = this;
ae(e, "addN");
for (var i = e.map(function(u) {
return r.readSync(u.dataId);
}), a = S.buffer(e[0].shape, e[0].dtype), s = a.values, o = 0; o < e.length; o++)
for (var c = i[o], l = 0; l < s.length; l++)
s[l] += c[l];
return a.toTensor();
}, t.prototype.softmax = function(e, r) {
var i = S.util.parseAxisParam([r], e.shape), a = S.max(e, i), s = S.backend_util.expandShapeToKeepDim(a.shape, i), o = S.sub(e, a.reshape(s)), c = S.exp(o), l = this.sum(c, i).reshape(s);
return S.div(c, l);
}, t.prototype.pow = function(e, r) {
return ae([e, r], "pow"), this.broadcastedBinaryOp(e, r, e.dtype, function(i, a) {
return Math.pow(i, a);
});
}, t.prototype.floorDiv = function(e, r) {
ae([e, r], "floorDiv");
var i = function(s, o) {
return Math.floor(s / o);
}, a = "int32";
return this.broadcastedBinaryOp(e, r, a, i);
}, t.prototype.sum = function(e, r) {
ae(e, "sum"), S.backend_util.assertAxesAreInnerMostDims("sum", r, e.rank);
for (var i = S.backend_util.computeOutAndReduceShapes(e.shape, r), a = i[0], s = i[1], o = S.upcastType(e.dtype, "int32"), c = S.zeros(a, o), l = S.util.sizeFromShape(s), u = this.readSync(c.dataId), h = this.readSync(e.dataId), d = 0; d < u.length; ++d) {
for (var p = d * l, f = 0, m = 0; m < l; ++m)
f += h[p + m];
u[d] = f;
}
return c;
}, t.prototype.prod = function(e, r) {
ae(e, "sum");
for (var i = S.backend_util.computeOutAndReduceShapes(e.shape, r), a = i[0], s = i[1], o = S.upcastType(e.dtype, "int32"), c = S.zeros(a, o), l = S.util.sizeFromShape(s), u = this.readSync(c.dataId), h = this.readSync(e.dataId), d = 0; d < u.length; ++d) {
for (var p = d * l, f = 1, m = 0; m < l; ++m)
f *= h[p + m];
u[d] = f;
}
return c;
}, t.prototype.unsortedSegmentSum = function(e, r, i) {
ae(e, "unsortedSegmentSum");
for (var a = [], s = e.rank - r.rank, o = 0; o < s; ++o)
r = r.expandDims(o + 1);
for (var o = 0; o < i; ++o) {
var c = S.scalar(o, "int32"), l = S.equal(c, r).asType("float32"), u = l.mul(e).sum(0);
a.push(u);
}
return S.stack(a);
}, t.prototype.argMin = function(e, r) {
ae(e, "argMin");
var i = [r];
S.backend_util.assertAxesAreInnerMostDims("argMin", i, e.rank);
for (var a = S.backend_util.computeOutAndReduceShapes(e.shape, i), s = a[0], o = a[1], c = S.zeros(s, "int32"), l = S.util.sizeFromShape(o), u = this.readSync(c.dataId), h = this.readSync(e.dataId), d = 0; d < u.length; ++d) {
for (var p = d * l, f = h[p], m = 0, g = 0; g < l; ++g) {
var y = h[p + g];
y < f && (f = y, m = g);
}
u[d] = m;
}
return c;
}, t.prototype.argMax = function(e, r) {
ae(e, "argMax");
var i = [r];
S.backend_util.assertAxesAreInnerMostDims("argMax", i, e.rank);
for (var a = S.backend_util.computeOutAndReduceShapes(e.shape, i), s = a[0], o = a[1], c = S.zeros(s, "int32"), l = S.util.sizeFromShape(o), u = this.readSync(c.dataId), h = this.readSync(e.dataId), d = 0; d < u.length; ++d) {
for (var p = d * l, f = h[p], m = 0, g = 0; g < l; ++g) {
var y = h[p + g];
y > f && (f = y, m = g);
}
u[d] = m;
}
return c;
}, t.prototype.cumsum = function(e, r, i, a) {
if (ae(e, "cumsum"), r !== e.rank - 1)
throw new Error("backend.cumsum in CPU expects an inner-most axis=" + (e.rank - 1) + " " + ("but got axis=" + r));
for (var s = S.upcastType(e.dtype, "int32"), o = S.zeros(e.shape, s), c = this.readSync(o.dataId), l = this.readSync(e.dataId), u = e.shape[e.rank - 1], h = a ? function(g, y) {
return g + u - y - 1;
} : function(g, y) {
return g + y;
}, d = 0; d < l.length; d += u)
for (var p = 0; p < u; p++) {
var f = h(d, p);
if (p === 0)
c[f] = i ? 0 : l[f];
else {
var m = h(d, p - 1);
c[f] = i ? l[m] + c[m] : l[f] + c[m];
}
}
return o;
}, t.prototype.equal = function(e, r) {
return ae([e, r], "equal"), this.broadcastedBinaryOp(e, r, "bool", function(i, a) {
return i === a ? 1 : 0;
});
}, t.prototype.notEqual = function(e, r) {
return ae([e, r], "notEqual"), this.broadcastedBinaryOp(e, r, "bool", function(i, a) {
return i !== a ? 1 : 0;
});
}, t.prototype.less = function(e, r) {
return ae([e, r], "less"), this.broadcastedBinaryOp(e, r, "bool", function(i, a) {
return i < a ? 1 : 0;
});
}, t.prototype.lessEqual = function(e, r) {
return ae([e, r], "lessEqual"), this.broadcastedBinaryOp(e, r, "bool", function(i, a) {
return i <= a ? 1 : 0;
});
}, t.prototype.greater = function(e, r) {
return ae([e, r], "greater"), this.broadcastedBinaryOp(e, r, "bool", function(i, a) {
return i > a ? 1 : 0;
});
}, t.prototype.greaterEqual = function(e, r) {
return ae([e, r], "greaterEqual"), this.broadcastedBinaryOp(e, r, "bool", function(i, a) {
return i >= a ? 1 : 0;
});
}, t.prototype.logicalAnd = function(e, r) {
return ae([e, r], "logicalAnd"), this.broadcastedBinaryOp(e, r, "bool", function(i, a) {
return i && a;
});
}, t.prototype.logicalOr = function(e, r) {
return ae([e, r], "logicalOr"), this.broadcastedBinaryOp(e, r, "bool", function(i, a) {
return i || a;
});
}, t.prototype.select = function(e, r, i) {
ae([e, r, i], "select");
for (var a = this.readSync(e.dataId), s = this.readSync(r.dataId), o = this.readSync(i.dataId), c = S.zeros(r.shape, S.upcastType(r.dtype, i.dtype)), l = this.readSync(c.dataId), u = 0, h = e.rank === 0 || e.rank > 1 || r.rank === 1 ? 1 : S.util.sizeFromShape(r.shape.slice(1)), d = 0; d < a.length; d++)
for (var p = 0; p < h; p++)
a[d] === 1 ? l[u++] = s[d] : l[u++] = o[d];
return c;
}, t.prototype.where = function(e) {
ae([e], "where");
var r = this.readSync(e.dataId);
return K6(e.shape, r);
}, t.prototype.topk = function(e, r, i) {
ae(e, "topk");
var a = this.readSync(e.dataId);
return Y6(a, e.shape, e.dtype, r, i);
}, t.prototype.min = function(e, r) {
ae(e, "min"), S.backend_util.assertAxesAreInnerMostDims("min", r, e.rank);
for (var i = S.backend_util.computeOutAndReduceShapes(e.shape, r), a = i[0], s = i[1], o = S.zeros(a, e.dtype), c = S.util.sizeFromShape(s), l = this.readSync(o.dataId), u = this.readSync(e.dataId), h = 0; h < l.length; ++h) {
for (var d = h * c, p = u[d], f = 0; f < c; ++f) {
var m = u[d + f];
m < p && (p = m);
}
l[h] = p;
}
return o;
}, t.prototype.minimum = function(e, r) {
return ae([e, r], "minimum"), this.broadcastedBinaryOp(e, r, e.dtype, function(i, a) {
return Math.min(i, a);
});
}, t.prototype.mod = function(e, r) {
return ae([e, r], "mod"), this.broadcastedBinaryOp(e, r, e.dtype, function(i, a) {
var s = i % a;
return i < 0 && a < 0 || i >= 0 && a >= 0 ? s : (s + a) % a;
});
}, t.prototype.maximum = function(e, r) {
return ae([e, r], "maximum"), this.broadcastedBinaryOp(e, r, e.dtype, function(i, a) {
return Math.max(i, a);
});
}, t.prototype.all = function(e, r) {
ae(e, "all"), S.backend_util.assertAxesAreInnerMostDims("all", r, e.rank);
for (var i = S.backend_util.computeOutAndReduceShapes(e.shape, r), a = i[0], s = i[1], o = S.zeros(a, e.dtype), c = S.util.sizeFromShape(s), l = this.readSync(o.dataId), u = this.readSync(e.dataId), h = 0; h < l.length; ++h) {
for (var d = h * c, p = u[d], f = 0; f < c; ++f) {
var m = u[d + f];
p = p && m;
}
l[h] = p;
}
return o;
}, t.prototype.any = function(e, r) {
ae(e, "any"), S.backend_util.assertAxesAreInnerMostDims("any", r, e.rank);
for (var i = S.backend_util.computeOutAndReduceShapes(e.shape, r), a = i[0], s = i[1], o = S.zeros(a, e.dtype), c = S.util.sizeFromShape(s), l = this.readSync(o.dataId), u = this.readSync(e.dataId), h = 0; h < l.length; ++h) {
for (var d = h * c, p = u[d], f = 0; f < c; ++f) {
var m = u[d + f];
p = p || m;
}
l[h] = p;
}
return o;
}, t.prototype.squaredDifference = function(e, r) {
return ae([e, r], "squaredDifference"), this.broadcastedBinaryOp(e, r, e.dtype, function(i, a) {
var s = i - a;
return s * s;
});
}, t.prototype.eluDer = function(e, r) {
ae([e, r], "eluDer");
for (var i = new Float32Array(r.size), a = this.readSync(r.dataId), s = this.readSync(e.dataId), o = 0; o < a.length; ++o) {
var c = a[o];
c >= 1 ? i[o] = s[o] : i[o] = s[o] * (c + 1);
}
return this.makeOutput(i, r.shape, "float32");
}, t.prototype.atan2 = function(e, r) {
return ae([e, r], "atan2"), this.broadcastedBinaryOp(e, r, e.dtype, function(i, a) {
return Math.atan2(i, a);
});
}, t.prototype.tile = function(e, r) {
return ae(e, "tile"), q6(this.bufferSync(e), r);
}, t.prototype.gather = function(e, r, i) {
ae([e, r], "gather");
var a = e.shape.slice(), s = this.readSync(r.dataId);
a[i] = s.length;
for (var o = S.buffer(a, e.dtype), c = this.bufferSync(e), l = 0; l < o.size; ++l) {
var u = o.indexToLoc(l), h = u.slice();
h[i] = s[u[i]];
var d = c.locToIndex(h);
o.values[l] = c.values[d];
}
return o.toTensor();
}, t.prototype.batchToSpaceND = function(e, r, i) {
ae([e], "batchToSpaceND");
var a = r.reduce(function(h, d) {
return h * d;
}), s = S.backend_util.getReshaped(e.shape, r, a), o = S.backend_util.getPermuted(s.length, r.length), c = S.backend_util.getReshapedPermuted(e.shape, r, a), l = S.backend_util.getSliceBeginCoords(i, r.length), u = S.backend_util.getSliceSize(c, i, r.length);
return S.transpose(e.reshape(s), o).reshape(c).slice(l, u);
}, t.prototype.pool3d = function(e, r, i) {
ae(e, "pool3d");
for (var a = r.strideDepth, s = r.strideHeight, o = r.strideWidth, c = r.dilationDepth, l = r.dilationHeight, u = r.dilationWidth, h = r.effectiveFilterDepth, d = r.effectiveFilterHeight, p = r.effectiveFilterWidth, f = r.padInfo.front, m = r.padInfo.top, g = r.padInfo.left, y = i === "max" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY, w = this.readSync(e.dataId), b = S.buffer(r.outShape, e.dtype), x = b.values, L = r.outShape[1] * r.outShape[2] * r.outShape[3] * r.outShape[4], N = r.outShape[2] * r.outShape[3] * r.outShape[4], I = r.outShape[3] * r.outShape[4], C = r.outShape[4], O = 0; O < r.batchSize; ++O)
for (var D = O * L, F = O * e.strides[0], k = 0; k < r.inChannels; ++k)
for (var B = 0; B < r.outDepth; ++B) {
for (var V = B * a - f, P = V; P < 0; )
P += c;
for (var G = Math.min(r.inDepth, h + V), j = D + B * N, q = 0; q < r.outHeight; ++q) {
for (var H = q * s - m, J = H; J < 0; )
J += l;
for (var $ = Math.min(r.inHeight, d + H), ee = j + q * I, te = 0; te < r.outWidth; ++te) {
for (var ne = te * o - g, re = ne; re < 0; )
re += u;
for (var ie = Math.min(r.inWidth, p + ne), oe = ee + te * C, se = y, me = 0, ye = 0, ve = P; ve < G; ve += c) {
for (var Ee = F + ve * e.strides[1], Be = J; Be < $; Be += l) {
for (var We = Ee + Be * e.strides[2], Ke = re; Ke < ie; Ke += u) {
var ze = We + Ke * e.strides[3], Ie = w[ze + k];
if (i === "max" && Ie > se ? se = Ie : i === "avg" && (me += Ie, ye++), isNaN(se))
break;
}
if (isNaN(se))
break;
}
if (isNaN(se))
break;
}
var ue = oe + k;
x[ue] = i === "avg" ? me / ye : se;
}
}
}
return b.toTensor();
}, t.prototype.avgPool3d = function(e, r) {
return ae(e, "avgPool3d"), this.pool3d(e, r, "avg").toFloat();
}, t.prototype.avgPool3dBackprop = function(e, r, i) {
ae([e, r], "avgPool3dBackprop");
for (var a = i.strideDepth, s = i.strideHeight, o = i.strideWidth, c = i.filterDepth, l = i.filterHeight, u = i.filterWidth, h = i.dilationDepth, d = i.dilationHeight, p = i.dilationWidth, f = i.effectiveFilterDepth, m = i.effectiveFilterHeight, g = i.effectiveFilterWidth, y = f - 1 - i.padInfo.front, w = g - 1 - i.padInfo.left, b = m - 1 - i.padInfo.top, x = S.buffer(r.shape, "float32"), L = 1 / (c * l * u), N = this.bufferSync(e), I = 0; I < i.batchSize; ++I)
for (var C = 0; C < i.inChannels; ++C)
for (var O = 0; O < i.inDepth; ++O)
for (var D = 0; D < i.inHeight; ++D)
for (var F = 0; F < i.inWidth; ++F) {
for (var k = O - y, B = D - b, V = F - w, P = 0, G = 0; G < f; G += h) {
var j = (k + G) / a;
if (j < 0 || j >= i.outDepth || Math.floor(j) !== j)
continue;
for (var q = 0; q < m; q += d) {
var H = (B + q) / s;
if (H < 0 || H >= i.outHeight || Math.floor(H) !== H)
continue;
for (var J = 0; J < g; J += p) {
var $ = (V + J) / o;
if ($ < 0 || $ >= i.outWidth || Math.floor($) !== $)
continue;
var ee = N.get(I, j, H, $, C);
P += ee;
}
}
}
x.set(P * L, I, O, D, F, C);
}
return x.toTensor();
}, t.prototype.maxPool3d = function(e, r) {
return ae(e, "maxPool3d"), this.pool3d(e, r, "max").toFloat();
}, t.prototype.maxPool3dPositions = function(e, r) {
for (var i = S.buffer(r.outShape, "int32"), a = r.strideDepth, s = r.strideHeight, o = r.strideWidth, c = r.dilationDepth, l = r.dilationHeight, u = r.dilationWidth, h = r.effectiveFilterDepth, d = r.effectiveFilterHeight, p = r.effectiveFilterWidth, f = r.padInfo.front, m = r.padInfo.top, g = r.padInfo.left, y = this.bufferSync(e), w = 0; w < r.batchSize; ++w)
for (var b = 0; b < r.inChannels; ++b)
for (var x = 0; x < r.outDepth; ++x) {
for (var L = x * a - f, N = L; N < 0; )
N += c;
for (var I = Math.min(r.inDepth, h + L), C = 0; C < r.outHeight; ++C) {
for (var O = C * s - m, D = O; D < 0; )
D += l;
for (var F = Math.min(r.inHeight, d + O), k = 0; k < r.outWidth; ++k) {
for (var B = k * o - g, V = B; V < 0; )
V += u;
for (var P = Math.min(r.inWidth, p + B), G = Number.NEGATIVE_INFINITY, j = -1, q = N; q < I; q += c)
for (var H = q - L, J = D; J < F; J += l)
for (var $ = J - O, ee = V; ee < P; ee += u) {
var te = ee - B, ne = y.get(w, q, J, ee, b);
ne >= G && (G = ne, j = H * d * p + $ * d + te);
}
i.set(j, w, x, C, k, b);
}
}
}
return i.toTensor();
}, t.prototype.maxPool3dBackprop = function(e, r, i, a) {
ae([r, i], "maxPool3dBackprop");
for (var s = this.maxPool3dPositions(r, a), o = a.strideDepth, c = a.strideHeight, l = a.strideWidth, u = a.dilationDepth, h = a.dilationHeight, d = a.dilationWidth, p = a.effectiveFilterDepth, f = a.effectiveFilterHeight, m = a.effectiveFilterWidth, g = p - 1 - a.padInfo.front, y = m - 1 - a.padInfo.left, w = f - 1 - a.padInfo.top, b = S.buffer(r.shape, "float32"), x = this.bufferSync(s), L = this.bufferSync(e), N = 0; N < a.batchSize; ++N)
for (var I = 0; I < a.inChannels; ++I)
for (var C = 0; C < a.inDepth; ++C)
for (var O = 0; O < a.inHeight; ++O)
for (var D = 0; D < a.inWidth; ++D) {
for (var F = C - g, k = O - w, B = D - y, V = 0, P = 0; P < p; P += u) {
var G = (F + P) / o;
if (G < 0 || G >= a.outDepth || Math.floor(G) !== G)
continue;
for (var j = 0; j < f; j += h) {
var q = (k + j) / c;
if (q < 0 || q >= a.outHeight || Math.floor(q) !== q)
continue;
for (var H = 0; H < m; H += d) {
var J = (B + H) / l;
if (J < 0 || J >= a.outWidth || Math.floor(J) !== J)
continue;
var $ = p * f * m - 1 - x.get(N, G, q, J, I), ee = P * f * m + j * m + H, te = $ === ee ? 1 : 0;
if (te === 0)
continue;
var ne = L.get(N, G, q, J, I);
V += ne * te;
}
}
}
b.set(V, N, C, O, D, I);
}
return b.toTensor();
}, t.prototype.resizeBilinear = function(e, r, i, a) {
ae(e, "resizeBilinear");
for (var s = e.shape, o = s[0], c = s[1], l = s[2], u = s[3], h = this.readSync(e.dataId), d = new Float32Array(S.util.sizeFromShape([o, r, i, u])), p = [a && r > 1 ? c - 1 : c, a && i > 1 ? l - 1 : l], f = [a && r > 1 ? r - 1 : r, a && i > 1 ? i - 1 : i], m = 0, g = p[0] / f[0], y = p[1] / f[1], w = 0; w < o; w++)
for (var b = 0; b < r; b++)
for (var x = g * b, L = Math.floor(x), N = x - L, I = Math.min(c - 1, Math.ceil(x)), C = w * e.strides[0] + L * e.strides[1], O = w * e.strides[0] + I * e.strides[1], D = 0; D < i; D++)
for (var F = y * D, k = Math.floor(F), B = F - k, V = Math.min(l - 1, Math.ceil(F)), P = C + k * e.strides[2], G = O + k * e.strides[2], j = C + V * e.strides[2], q = O + V * e.strides[2], H = 0; H < u; H++) {
var J = h[P + H], $ = h[G + H], ee = h[j + H], te = h[q + H], ne = J + (ee - J) * B, re = $ + (te - $) * B, ie = ne + (re - ne) * N;
d[m++] = ie;
}
return S.tensor(d, [o, r, i, u]);
}, t.prototype.resizeBilinearBackprop = function(e, r, i) {
ae([e, r], "resizeBilinearBackprop");
for (var a = r.shape, s = a[0], o = a[1], c = a[2], l = a[3], u = e.shape, h = u[1], d = u[2], p = new Float32Array(s * o * c * l), f = [i && h > 1 ? o - 1 : o, i && d > 1 ? c - 1 : c], m = [i && h > 1 ? h - 1 : h, i && d > 1 ? d - 1 : d], g = f[0] / m[0], y = f[1] / m[1], w = this.readSync(e.dataId), b = 0, x = 0; x < s; x++)
for (var L = x * r.strides[0], N = 0; N < h; N++)
for (var I = N * g, C = Math.floor(I), O = Math.min(Math.ceil(I), o - 1), D = L + C * r.strides[1], F = L + O * r.strides[1], k = I - C, B = 1 - k, V = 0; V < d; V++)
for (var P = V * y, G = Math.floor(P), j = Math.min(Math.ceil(P), c - 1), q = P - G, H = 1 - q, J = D + G * r.strides[2], $ = D + j * r.strides[2], ee = F + G * r.strides[2], te = F + j * r.strides[2], ne = B * H, re = B * q, ie = k * H, oe = k * q, se = 0; se < l; se++) {
var me = w[b++];
p[J + se] += me * ne, p[$ + se] += me * re, p[ee + se] += me * ie, p[te + se] += me * oe;
}
return S.tensor4d(p, [s, c, o, l], r.dtype);
}, t.prototype.resizeNearestNeighbor = function(e, r, i, a) {
ae(e, "resizeNearestNeighbor");
for (var s = e.shape, o = s[0], c = s[1], l = s[2], u = s[3], h = this.readSync(e.dataId), d = new Float32Array(o * r * i * u), p = [a && r > 1 ? c - 1 : c, a && i > 1 ? l - 1 : l], f = [a && r > 1 ? r - 1 : r, a && i > 1 ? i - 1 : i], m = p[0] / f[0], g = p[1] / f[1], y = 0, w = 0; w < o; w++)
for (var b = w * e.strides[0], x = 0; x < r; x++)
for (var L = m * x, N = Math.min(c - 1, a ? Math.round(L) : Math.floor(L)), I = b + N * e.strides[1], C = 0; C < i; C++)
for (var O = g * C, D = Math.min(l - 1, a ? Math.round(O) : Math.floor(O)), F = I + D * e.strides[2], k = 0; k < u; k++) {
var B = h[F + k];
d[y++] = B;
}
return S.tensor(d, [o, r, i, u], e.dtype);
}, t.prototype.resizeNearestNeighborBackprop = function(e, r, i) {
ae([e, r], "resizeNearestNeighborBackprop");
for (var a = r.shape, s = a[0], o = a[1], c = a[2], l = a[3], u = e.shape, h = u[1], d = u[2], p = new Float32Array(s * o * c * l), f = this.readSync(e.dataId), m = [i && h > 1 ? o - 1 : o, i && d > 1 ? c - 1 : c], g = [i && h > 1 ? h - 1 : h, i && d > 1 ? d - 1 : d], y = m[0] / g[0], w = m[1] / g[1], b = 1 / y, x = 1 / w, L = Math.ceil(b) * 2 + 2, N = Math.ceil(x) * 2 + 2, I = 0; I < s; I++)
for (var C = I * r.strides[0], O = 0; O < o; O++)
for (var D = C + O * r.strides[1], F = Math.floor(O * b), k = Math.floor(F - L / 2), B = 0; B < c; B++)
for (var V = D + B * r.strides[2], P = Math.floor(B * x), G = Math.floor(P - N / 2), j = 0; j < l; j++) {
for (var q = 0, H = 0; H < L; H++) {
var J = H + k;
if (J < 0 || J >= h)
continue;
var $ = C + J * e.strides[1], ee = J * y, te = Math.min(o - 1, i ? Math.round(ee) : Math.floor(ee));
if (O !== te)
continue;
for (var ne = 0; ne < N; ne++) {
var re = ne + G;
if (re < 0 || re >= d)
continue;
var ie = $ + re * e.strides[2], oe = re * w, se = Math.min(c - 1, i ? Math.round(oe) : Math.floor(oe));
B === se && (q += f[ie + j]);
}
}
p[V + j] = q;
}
return S.tensor4d(p, r.shape, r.dtype);
}, t.prototype.localResponseNormalization4D = function(e, r, i, a, s) {
ae(e, "localResponseNormalization4D");
var o = e.shape[3], c = o - 1, l = this.readSync(e.dataId), u = e.size, h = new Float32Array(u);
function d(g) {
for (var y = g % o, w = g - y + Math.max(0, y - r), b = g - y + Math.min(y + r, c), x = 0; w <= b; w++) {
var L = l[w];
x += L * L;
}
return x;
}
for (var p = 0; p < u; p++) {
var f = d(p), m = l[p] * Math.pow(i + a * f, -s);
h[p] = m;
}
return S.tensor4d(h, e.shape);
}, t.prototype.LRNGrad = function(e, r, i, a, s, o, c) {
ae(e, "LRNGrad");
for (var l = e.shape[3], u = this.readSync(e.dataId), h = this.readSync(r.dataId), d = this.readSync(i.dataId), p = new Float32Array(e.size), f = e.size, m = 0; m < f; m++) {
for (var g = m % l, y = m - g + Math.max(0, g - a), w = m - g + Math.min(l, g + a + 1), b = 0, x = y; x < w; x++)
b += Math.pow(h[x], 2);
b = o * b + s;
for (var x = y; x < w; x++) {
var L = -2 * o * c * h[x] * d[m] / b;
m === x && (L += Math.pow(b, -c)), L *= u[m], p[x] += L;
}
}
return S.tensor4d(p, e.shape);
}, t.prototype.multinomial = function(e, r, i, a) {
ae(e, "multinomial");
for (var s = r ? e : S.softmax(e), o = s.shape[0], c = s.shape[1], l = S.zeros([o, i], "int32"), u = this.readSync(l.dataId), h = this.readSync(s.dataId), d = 0; d < o; ++d) {
var p = d * c, f = new Float32Array(c - 1);
f[0] = h[p];
for (var m = 1; m < f.length; ++m)
f[m] = f[m - 1] + h[p + m];
for (var g = M6.alea(a.toString()), y = d * i, w = 0; w < i; ++w) {
var b = g();
u[y + w] = f.length;
for (var x = 0; x < f.length; x++)
if (b < f[x]) {
u[y + w] = x;
break;
}
}
}
return l;
}, t.prototype.oneHot = function(e, r, i, a) {
ae(e, "oneHot");
var s = new Float32Array(e.size * r);
s.fill(a);
for (var o = this.readSync(e.dataId), c = 0; c < e.size; ++c)
o[c] >= 0 && o[c] < r && (s[c * r + o[c]] = i);
return S.tensor2d(s, [e.size, r], "int32");
}, t.prototype.nonMaxSuppression = function(e, r, i, a, s) {
ae(e, "nonMaxSuppression");
var o = this.readSync(e.dataId), c = this.readSync(r.dataId);
return V6(o, c, i, a, s);
}, t.prototype.depthToSpace = function(e, r, i) {
S.util.assert(i === "NHWC", function() {
return "Only NHWC dataFormat supported on CPU for depthToSpace. Got " + i;
}), S.util.assert(r > 1, function() {
return "blockSize should be > 1 for depthToSpace, but was: " + r;
});
for (var a = e.shape[0], s = e.shape[1], o = e.shape[2], c = e.shape[3], l = s * r, u = o * r, h = c / (r * r), d = this.readSync(e.dataId), p = new Float32Array(a * l * u * h), f = 0, m = 0; m < a; ++m)
for (var g = 0; g < l; ++g)
for (var y = Math.floor(g / r), w = g % r, b = 0; b < u; ++b)
for (var x = Math.floor(b / r), L = b % r, N = (w * r + L) * h, I = 0; I < h; ++I) {
var C = I + N, O = C + c * (x + o * (y + s * m));
p[f++] = d[O];
}
return S.tensor4d(p, [a, l, u, h]);
}, t.prototype.broadcastedBinaryOp = function(e, r, i, a) {
var s = S.backend_util.assertAndGetBroadcastShape(e.shape, r.shape), o = S.buffer(s, i), c = this.readSync(e.dataId), l = this.readSync(r.dataId), u = S.backend_util.getBroadcastDims(e.shape, s), h = S.backend_util.getBroadcastDims(r.shape, s), d = o.values;
if (u.length + h.length === 0)
for (var p = 0; p < d.length; ++p)
d[p] = a(c[p % c.length], l[p % l.length]);
else
for (var f = this.bufferSync(e), m = this.bufferSync(r), g = function(y) {
var w = o.indexToLoc(y), b = w.slice(-e.rank);
u.forEach(function(I) {
return b[I] = 0;
});
var x = f.locToIndex(b), L = w.slice(-r.rank);
h.forEach(function(I) {
return L[I] = 0;
});
var N = m.locToIndex(L);
d[y] = a(c[x], l[N]);
}, p = 0; p < d.length; ++p)
g(p);
return o.toTensor();
}, t.prototype.split = function(e, r, i) {
return G6(e, r, i);
}, t.prototype.dispose = function() {
}, t.prototype.floatPrecision = function() {
return 32;
}, t.prototype.epsilon = function() {
return n.prototype.epsilon.call(this);
}, t.prototype.cropAndResize = function(e, r, i, a, s, o) {
for (var c = e.shape, l = c[0], u = c[1], h = c[2], d = c[3], p = r.shape[0], f = a[0], m = a[1], g = S.buffer([p, f, m, d], "float32"), y = this.readSync(r.dataId), w = this.readSync(i.dataId), b = this.readSync(e.dataId), x = e.strides, L = g.strides, N = 0; N < p; N++) {
var I = N * 4, C = y[I], O = y[I + 1], D = y[I + 2], F = y[I + 3], k = w[N];
if (k >= l)
continue;
for (var B = f > 1 ? (D - C) * (u - 1) / (f - 1) : 0, V = m > 1 ? (F - O) * (h - 1) / (m - 1) : 0, P = 0; P < f; P++) {
var G = f > 1 ? C * (u - 1) + P * B : 0.5 * (C + D) * (u - 1);
if (G < 0 || G > u - 1) {
for (var j = 0; j < m; j++)
for (var q = 0; q < d; q++) {
var H = q + j * L[2] + P * L[1] + N * L[0];
g.values[H] = o;
}
continue;
}
if (s === "bilinear")
for (var J = Math.floor(G), $ = Math.ceil(G), ee = G - J, j = 0; j < m; j++) {
var te = m > 1 ? O * (h - 1) + j * V : 0.5 * (O + F) * (h - 1);
if (te < 0 || te > h - 1) {
for (var q = 0; q < d; q++) {
var H = q + j * L[2] + P * L[1] + N * L[0];
g.values[H] = o;
}
continue;
}
for (var ne = Math.floor(te), re = Math.ceil(te), ie = te - ne, q = 0; q < d; q++) {
var H = q + ne * x[2] + J * x[1] + k * x[0], oe = b[H];
H = q + re * x[2] + J * x[1] + k * x[0];
var se = b[H];
H = q + ne * x[2] + $ * x[1] + k * x[0];
var me = b[H];
H = q + re * x[2] + $ * x[1] + k * x[0];
var ye = b[H], ve = oe + (se - oe) * ie, Ee = me + (ye - me) * ie;
H = q + j * L[2] + P * L[1] + N * L[0], g.values[H] = ve + (Ee - ve) * ee;
}
}
else
for (var j = 0; j < m; ++j) {
var te = m > 1 ? O * (h - 1) + j * V : 0.5 * (O + F) * (h - 1);
if (te < 0 || te > h - 1) {
for (var q = 0; q < d; q++) {
var H = q + j * L[2] + P * L[1] + N * L[0];
g.values[H] = o;
}
continue;
}
for (var Be = Math.round(te), We = Math.round(G), q = 0; q < d; q++) {
var Ke = q + Be * x[2] + We * x[1] + k * x[0], ze = q + j * L[2] + P * L[1] + N * L[0];
g.values[ze] = b[Ke];
}
}
}
}
return g.toTensor();
}, t.prototype.sparseToDense = function(e, r, i, a) {
var s = S.backend_util.calculateShapes(r, e, i), o = s.sliceRank, c = s.numUpdates, l = s.sliceSize, u = s.strides, h = s.outputSize, d = false;
return this.scatter(e, r, i, h, l, c, o, u, a, d);
}, t.prototype.gatherND = function(e, r) {
var i = r.shape, a = i[i.length - 1], s = S.backend_util.prepareAndValidate(e, r), o = s[0], c = s[1], l = s[2], u = s[3];
if (c === 0)
return S.tensor([], o, e.dtype);
for (var h = new S.TensorBuffer([c, l], e.dtype), d = this.readSync(r.dataId), p = this.readSync(e.dataId), f = 0; f < c; f++) {
for (var m = [], g = 0, y = 0; y < a; y++) {
var w = d[f * a + y];
g += w * u[y], m.push(w);
}
if (g < 0 || g >= e.size / l)
throw new Error("Invalid indices: " + m + " does not index into " + e.shape);
for (var b = 0; b < l; b++)
h.values[f * l + b] = p[g * l + b];
}
return h.toTensor().reshape(o);
}, t.prototype.scatterND = function(e, r, i) {
var a = S.backend_util.calculateShapes(r, e, i), s = a.sliceRank, o = a.numUpdates, c = a.sliceSize, l = a.strides, u = a.outputSize, h = S.scalar(0), d = true;
return this.scatter(e, r, i, u, c, o, s, l, h, d);
}, t.prototype.onesLike = function(e) {
if (e.dtype === "string")
throw new Error("onesLike is not supported for string tensors");
return S.fill(e.shape, 1, e.dtype);
}, t.prototype.zerosLike = function(e) {
var r = S.util.getArrayFromDType(e.dtype, S.util.sizeFromShape(e.shape));
return this.makeOutput(r, e.shape, e.dtype);
}, t.prototype.linspace = function(e, r, i) {
return S.backend_util.linspaceImpl(e, r, i);
}, t.prototype.scatter = function(e, r, i, a, s, o, c, l, u, h) {
var d = [a / s, s], p = this.readSync(e.dataId), f = this.readSync(r.dataId);
if (a === 0)
return S.tensor([], i, r.dtype);
var m = new S.TensorBuffer(d, r.dtype);
m.values.fill(this.readSync(u.dataId)[0]);
for (var g = 0; g < o; g++) {
for (var y = [], w = 0, b = 0; b < c; b++) {
var x = p[g * c + b];
y.push(x), w += x * l[b];
}
if (w < 0 || w >= a / s)
throw new Error("Invalid indices: " + y + " does not index into " + i);
for (var L = 0; L < s; L++)
h ? m.values[w * s + L] += f[g * s + L] : m.values[w * s + L] = r.rank === 0 ? f[0] : f[g * s + L];
}
return m.toTensor().reshape(i);
}, t;
}(S.KernelBackend);
function uw(n) {
for (var t = new Float32Array(n.length), e = 0; e < n.length; ++e)
t[e] = Math.abs(n[e]);
return t;
}
var j6 = function(n) {
var t = n.inputs.x, e = n.backend, r = new Float32Array(S.util.sizeFromShape(t.shape));
if (t.dtype !== "complex64") {
var i = e.data.get(t.dataId).values;
r = uw(i);
} else
for (var a = e.data.get(t.dataId), s = a.complexTensorInfos.real, o = a.complexTensorInfos.imag, c = e.data.get(s.dataId).values, l = e.data.get(o.dataId).values, u = 0; u < c.length; u++) {
var h = c[u], d = l[u];
r[u] = Math.hypot(h, d);
}
return e.makeOutput(r, t.shape, "float32");
}, $6 = {kernelName: S.Abs, backendName: "cpu", kernelFunc: j6};
function Er(n) {
return function(t, e, r, i, a) {
var s = S.backend_util.assertAndGetBroadcastShape(t, e), o = s.length, c = S.util.computeStrides(s), l = S.util.sizeFromShape(s), u = S.util.getTypedArrayFromDType(a, l), h = t.length, d = e.length, p = S.util.computeStrides(t), f = S.util.computeStrides(e), m = S.backend_util.getBroadcastDims(t, s), g = S.backend_util.getBroadcastDims(e, s);
if (m.length + g.length === 0)
for (var y = 0; y < u.length; ++y)
u[y] = n(r[y % r.length], i[y % i.length]);
else
for (var w = function(b) {
var x = S.util.indexToLoc(b, o, c), L = x.slice(-h);
m.forEach(function(O) {
return L[O] = 0;
});
var N = S.util.locToIndex(L, h, p), I = x.slice(-d);
g.forEach(function(O) {
return I[O] = 0;
});
var C = S.util.locToIndex(I, d, f);
u[b] = n(r[N], i[C]);
}, y = 0; y < u.length; ++y)
w(y);
return [u, s];
};
}
function An(n) {
var t = n.inputs, e = n.backend, r = t.real, i = t.imag, a = e.data.get(r.dataId).values, s = e.data.get(i.dataId).values, o = e.makeTensorInfo(r.shape, "complex64"), c = e.data.get(o.dataId);
return c.complexTensorInfos = {real: e.makeTensorInfo(r.shape, "float32", a), imag: e.makeTensorInfo(i.shape, "float32", s)}, o;
}
var X6 = {kernelName: S.Complex, backendName: "cpu", kernelFunc: An};
function di(n) {
var t = n.inputs, e = n.backend, r = t.x;
return e.incRef(r.dataId), {dataId: r.dataId, shape: r.shape, dtype: r.dtype};
}
var J6 = {kernelName: S.Identity, backendName: "cpu", kernelFunc: di};
function Qa(n) {
var t = n.inputs, e = n.backend, r = t.input, i = e.data.get(r.dataId).complexTensorInfos.real, a = e.data.get(i.dataId).values;
return e.makeTensorInfo(i.shape, i.dtype, a);
}
var Z6 = {kernelName: S.Real, backendName: "cpu", kernelFunc: Qa};
function es(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = r.dtype;
if (a === "complex64") {
if (i.dtype === "complex64")
return di({inputs: {x: i}, backend: e});
var s = S.zeros(i.shape), o = es({inputs: {x: i}, backend: e, attrs: {dtype: "float32"}}), c = An({inputs: {real: o, imag: s}, backend: e});
return s.dispose(), e.disposeIntermediateTensorInfo(o), c;
}
if (i.dtype === "complex64") {
var l = Qa({inputs: {input: i}, backend: e}), c = es({inputs: {x: l}, backend: e, attrs: {dtype: a}});
return e.disposeIntermediateTensorInfo(l), c;
}
if (!S.util.hasEncodingLoss(i.dtype, a)) {
var c = di({inputs: {x: i}, backend: e});
return {dataId: c.dataId, shape: c.shape, dtype: a};
}
if (a === "int32") {
var u = e.data.get(i.dataId).values, h = Int32Array.from(u);
return e.makeTensorInfo(i.shape, "int32", h);
}
if (a === "bool") {
var d = e.data.get(i.dataId).values, p = S.util.toTypedArray([0], i.dtype), f = Er(function(y, w) {
return y !== w ? 1 : 0;
})(i.shape, [], d, p, "bool"), m = f[0], g = f[1];
return e.makeTensorInfo(g, "bool", m);
}
throw new Error("Error in Cast: failed to cast " + i.dtype + " to " + a);
}
var Q6 = {kernelName: S.Cast, backendName: "cpu", kernelFunc: es};
function Zi(n, t, e, r) {
return e == null ? function(i) {
var a = i.inputs, s = i.backend, o = a, c = o.a, l = o.b, u = s;
ae([c, l], n);
var h = u.data.get(c.dataId).values, d = u.data.get(l.dataId).values, p = r || c.dtype, f = t(c.shape, l.shape, h, d, p), m = f[0], g = f[1];
return u.makeTensorInfo(g, p, m);
} : function(i) {
var a = i.inputs, s = i.backend, o = a, c = o.a, l = o.b, u = s;
if (c.dtype === "complex64" || l.dtype === "complex64") {
var h = es({inputs: {x: c}, backend: u, attrs: {dtype: "complex64"}}), d = u.data.get(h.dataId), p = d.complexTensorInfos.real, f = d.complexTensorInfos.imag, m = u.data.get(p.dataId).values, g = u.data.get(f.dataId).values, y = es({inputs: {x: l}, backend: u, attrs: {dtype: "complex64"}}), w = u.data.get(y.dataId), b = w.complexTensorInfos.real, x = w.complexTensorInfos.imag, L = u.data.get(b.dataId).values, N = u.data.get(x.dataId).values, I = e(c.shape, l.shape, m, g, L, N), C = I[0], O = I[1], D = I[2], F = u.makeTensorInfo(D, "float32", C), k = u.makeTensorInfo(D, "float32", O), B = An({inputs: {real: F, imag: k}, backend: u});
return u.disposeIntermediateTensorInfo(h), u.disposeIntermediateTensorInfo(y), u.disposeIntermediateTensorInfo(F), u.disposeIntermediateTensorInfo(k), B;
} else {
var V = u.data.get(c.dataId).values, P = u.data.get(l.dataId).values, G = r || c.dtype, j = t(c.shape, l.shape, V, P, G), q = j[0], D = j[1];
return u.makeTensorInfo(D, G, q);
}
};
}
function Ed(n) {
return function(t, e, r, i, a, s) {
var o = S.backend_util.assertAndGetBroadcastShape(t, e), c = S.util.sizeFromShape(o), l = o.length, u = S.util.computeStrides(o), h = S.util.getTypedArrayFromDType("float32", c), d = S.util.getTypedArrayFromDType("float32", c), p = S.backend_util.getBroadcastDims(t, o), f = S.backend_util.getBroadcastDims(e, o), m = S.backend_util.mergeRealAndImagArrays(r, i), g = S.backend_util.mergeRealAndImagArrays(a, s), y = t.length, w = S.util.computeStrides(t), b = e.length, x = S.util.computeStrides(e);
if (p.length + f.length === 0)
for (var L = 0; L < h.length; L++) {
var N = L % m.length, I = L % g.length, C = n(m[N * 2], m[N * 2 + 1], g[I * 2], g[I * 2 + 1]);
h[L] = C.real, d[L] = C.imag;
}
else
for (var O = function(D) {
var F = S.util.indexToLoc(D, l, u), k = F.slice(-y);
p.forEach(function(j) {
return k[j] = 0;
});
var B = S.util.locToIndex(k, y, w), V = F.slice(-b);
f.forEach(function(j) {
return V[j] = 0;
});
var P = S.util.locToIndex(V, b, x), G = n(m[B * 2], m[B * 2 + 1], g[P * 2], g[P * 2 + 1]);
h[D] = G.real, d[D] = G.imag;
}, L = 0; L < h.length; L++)
O(L);
return [h, d, o];
};
}
var hw = Er(function(n, t) {
return n + t;
}), e8 = Ed(function(n, t, e, r) {
return {real: n + e, imag: t + r};
}), ts = Zi(S.Add, hw, e8), t8 = {kernelName: S.Add, backendName: "cpu", kernelFunc: ts};
function Qi(n) {
return function(t, e, r) {
for (var i = S.util.getTypedArrayFromDType(e, t.length), a = 0; a < t.length; ++a)
i[a] = n(t[a], r);
return i;
};
}
function je(n, t, e) {
return function(r) {
var i = r.inputs, a = r.attrs, s = r.backend, o = i.x;
if (ae(o, n), o.dtype === "string" || e === "string")
throw new Error("unaryKernelFunc does not support string input/output");
for (var c = s, l = c.data.get(o.dataId).values, u = S.util.sizeFromShape(o.shape), h = e || o.dtype, d = S.util.getArrayFromDType(h, u), p = 0; p < u; ++p)
d[p] = t(l[p], a);
return c.makeTensorInfo(o.shape, h, d);
};
}
function ea(n, t, e) {
return function(r) {
var i = r.inputs, a = r.attrs, s = r.backend, o = i.x;
if (ae(o, n), o.dtype === "string" || e === "string")
throw new Error("unaryKernelFunc does not support string input/output");
var c = s, l = c.data.get(o.dataId).values, u = e || o.dtype, h = t(l, u, a);
return c.makeTensorInfo(o.shape, u, h);
};
}
var dw = Qi(function(n) {
return Math.ceil(n);
}), n8 = ea(S.Ceil, dw), r8 = {kernelName: S.Ceil, backendName: "cpu", kernelFunc: n8};
var pw = Qi(function(n) {
return Math.exp(n);
}), i8 = ea(S.Exp, pw), a8 = {kernelName: S.Exp, backendName: "cpu", kernelFunc: i8};
var fw = Qi(function(n) {
return Math.expm1(n);
}), s8 = ea(S.Expm1, fw), o8 = {kernelName: S.Expm1, backendName: "cpu", kernelFunc: s8};
var mw = Qi(function(n) {
return Math.floor(n);
}), c8 = ea(S.Floor, mw), l8 = {kernelName: S.Floor, backendName: "cpu", kernelFunc: c8};
var gw = Qi(function(n) {
return Math.log(n);
}), u8 = ea(S.Log, gw), h8 = {kernelName: S.Log, backendName: "cpu", kernelFunc: u8};
function yw(n, t, e, r) {
for (var i = S.util.getTypedArrayFromDType(r, S.util.sizeFromShape(e)), a = 0; a < i.length; ++a) {
for (var s = a * t, o = n[s], c = 0; c < t; ++c) {
var l = n[s + c];
l > o && (o = l);
}
i[a] = o;
}
return i;
}
var vw = Er(function(n, t) {
return n * t;
}), d8 = Ed(function(n, t, e, r) {
return {real: n * e - t * r, imag: n * r + t * e};
}), ww = Zi(S.Multiply, vw, d8), p8 = {kernelName: S.Multiply, backendName: "cpu", kernelFunc: ww};
var bw = Er(function(n, t) {
return n !== t ? 1 : 0;
}), f8 = Zi(S.NotEqual, bw, null, "bool"), m8 = {kernelName: S.NotEqual, backendName: "cpu", kernelFunc: f8};
var xw = Qi(function(n) {
return 1 / Math.sqrt(n);
}), g8 = ea(S.Rsqrt, xw), y8 = {kernelName: S.Rsqrt, backendName: "cpu", kernelFunc: g8};
function Lw(n, t, e, r, i) {
var a = S.slice_util.isSliceContinous(r, t, e), s = S.util.sizeFromShape(e), o = S.util.computeStrides(r);
if (a) {
var c = S.slice_util.computeFlatOffset(t, o);
return n.subarray(c, c + s);
}
for (var l = S.util.getTypedArrayFromDType(i, s), u = 0; u < s; ++u) {
var h = e.length, d = S.util.computeStrides(e), p = S.util.indexToLoc(u, h, d), f = p.map(function(g, y) {
return g + t[y];
}), m = S.util.locToIndex(f, r.length, o);
l[u] = n[m];
}
return l;
}
function Dd(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = r.begin, s = r.size;
ae(i, "slice");
var o = S.slice_util.parseSliceParams(i, a, s), c = o[0], l = o[1];
S.slice_util.assertParamsValid(i, c, l);
var u = e.data.get(i.dataId).values, h = Lw(u, c, l, i.shape, i.dtype);
return e.makeTensorInfo(l, i.dtype, h);
}
var v8 = {kernelName: S.Slice, backendName: "cpu", kernelFunc: Dd};
var Sw = Er(function(n, t) {
var e = n - t;
return e * e;
}), w8 = Zi(S.SquaredDifference, Sw), b8 = {kernelName: S.SquaredDifference, backendName: "cpu", kernelFunc: w8};
var Iw = Er(function(n, t) {
return n - t;
}), x8 = Ed(function(n, t, e, r) {
return {real: n - e, imag: t - r};
}), Aw = Zi(S.Sub, Iw, x8), L8 = {kernelName: S.Sub, backendName: "cpu", kernelFunc: Aw};
function kd(n, t, e, r, i) {
for (var a = t.length, s = S.util.sizeFromShape(t), o = S.util.computeStrides(t), c = S.util.computeStrides(i), l = S.util.getTypedArrayFromDType(e, S.util.sizeFromShape(i)), u = 0; u < s; ++u) {
for (var h = S.util.indexToLoc(u, a, o), d = new Array(h.length), p = 0; p < d.length; p++)
d[p] = h[r[p]];
var f = S.util.locToIndex(d, a, c);
l[f] = n[u];
}
return l;
}
function Tw(n, t, e, r) {
for (var i = S.util.parseAxisParam(t, e)[0], a = [1, e[0], 1], s = 0; s < i; s++)
a[0] *= e[s];
a[1] = e[i];
for (var s = i + 1; s < e.length; s++)
a[2] *= e[s];
for (var o = {}, c = new Int32Array(e[i]), l = new S.TensorBuffer(a, r, n), u = [], h = a[0] === 1 && a[2] === 1, s = 0; s < e[i]; s++) {
var d = void 0;
if (h)
d = n[s].toString();
else {
for (var p = [], f = 0; f < a[0]; f++)
for (var m = 0; m < a[2]; m++)
p.push(l.get(f, s, m));
d = p.join(",");
}
if (o[d] !== void 0)
c[s] = o[d];
else {
var g = Object.keys(o).length;
o[d] = g, c[s] = g, u.push(s);
}
}
var y = a.slice();
y[1] = Object.keys(o).length;
var w = new S.TensorBuffer(y, r);
u.forEach(function(x, L) {
for (var N = 0; N < a[0]; N++)
for (var I = 0; I < a[2]; I++)
w.set(l.get(N, x, I), N, L, I);
});
var b = e.slice();
return b[i] = y[1], {outputValues: w.values, outputShape: b, indices: c};
}
var S8 = {__proto__: null, simpleAbsImpl: uw, addImpl: hw, ceilImpl: dw, expImpl: pw, expm1Impl: fw, floorImpl: mw, logImpl: gw, maxImpl: yw, multiplyImpl: vw, notEqualImpl: bw, rsqrtImpl: xw, sliceImpl: Lw, squaredDifferenceImpl: Sw, subImpl: Iw, transposeImpl: kd, uniqueImpl: Tw};
var I8 = "2.7.0";
S.registerBackend("cpu", function() {
return new lw();
}, 1);
var Nw = je(S.Elu, function(n) {
return n >= 0 ? n : Math.exp(n) - 1;
}), A8 = {kernelName: S.Elu, backendName: "cpu", kernelFunc: Nw};
var T8 = Er(function(n, t) {
return n < 0 ? t * n : n;
});
function _w(n) {
var t = n.inputs, e = n.backend, r = t.x, i = t.alpha;
ae([r, i], "prelu");
var a = e.data.get(r.dataId).values, s = e.data.get(i.dataId).values, o = T8(r.shape, i.shape, a, s, r.dtype), c = o[0], l = o[1];
return e.makeTensorInfo(l, r.dtype, c);
}
var N8 = {kernelName: S.Prelu, backendName: "cpu", kernelFunc: _w};
var Cw = je(S.Relu, function(n) {
return Math.max(0, n);
}), _8 = {kernelName: S.Relu, backendName: "cpu", kernelFunc: Cw};
var Rw = je(S.Relu6, function(n) {
return Math.min(Math.max(0, n), 6);
}), C8 = {kernelName: S.Relu6, backendName: "cpu", kernelFunc: Rw};
function Fd(n, t, e, r) {
if (e === "linear")
return di({inputs: {x: t}, backend: n});
if (e === "relu")
return Cw({inputs: {x: t}, backend: n});
if (e === "elu")
return Nw({inputs: {x: t}, backend: n});
if (e === "relu6")
return Rw({inputs: {x: t}, backend: n});
if (e === "prelu")
return _w({inputs: {x: t, alpha: r}, backend: n});
throw new Error("Activation " + e + " has not been implemented for the CPU backend.");
}
function Un(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = r.shape, s = S.util.sizeFromShape(i.shape), o = S.util.inferFromImplicitShape(a, s), c = S.util.sizeFromShape(o);
S.util.assert(s === c, function() {
return "The new shape (" + o + ") has " + c + " elements and the old " + ("shape (" + i.shape + ") has " + s + " elements. The new shape and old ") + "shape must have the same number of elements.";
}), e.incRef(i.dataId);
var l = e.data.get(i.dataId);
if (l.complexTensorInfos != null) {
var u = l.complexTensorInfos.real, h = l.complexTensorInfos.imag;
u.shape = o, h.shape = o;
}
return {dataId: i.dataId, shape: o, dtype: i.dtype};
}
var R8 = {kernelName: S.Reshape, backendName: "cpu", kernelFunc: Un};
function Ow(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.a, a = t.b, s = r.transposeA, o = r.transposeB;
ae([i, a], "matMul");
var c = i.shape.length, l = a.shape.length, u = s ? i.shape[c - 2] : i.shape[c - 1], h = o ? a.shape[l - 1] : a.shape[l - 2], d = s ? i.shape[c - 1] : i.shape[c - 2], p = o ? a.shape[l - 2] : a.shape[l - 1], f = i.shape.slice(0, -2), m = a.shape.slice(0, -2), g = S.util.sizeFromShape(f), y = S.util.sizeFromShape(m), w = g === y || g === 1 || y === 1;
S.util.assert(c >= 2 && l >= 2 && w, function() {
return "Error in matMul: the input batch dimensions must either be the same or at least one input batch dimension must be 1. Got input " + ("batch dimensions of (" + f + ") and (" + m + ").");
});
var b = g > y ? i.shape.slice(0, -2) : a.shape.slice(0, -2), x = b.concat([d, p]);
S.util.assert(u === h, function() {
return "Error in matMul: inner shapes (" + u + ") and (" + (h + ") of Tensors with shapes " + i.shape + " and ") + (a.shape + " and transposeA=" + s) + (" and transposeB=" + o + " must match.");
});
for (var L = s ? [g, u, d] : [g, d, u], N = o ? [y, p, h] : [y, h, p], I = Un({inputs: {x: i}, backend: e, attrs: {shape: L}}), C = Un({inputs: {x: a}, backend: e, attrs: {shape: N}}), O = s ? I.shape[1] : I.shape[2], D = s ? I.shape[2] : I.shape[1], F = o ? C.shape[1] : C.shape[2], k = Math.max(g, y), B = e.data.get(I.dataId).values, V = e.data.get(C.dataId).values, P = S.util.computeStrides(I.shape), G = S.util.computeStrides(C.shape), j = s ? [P[0], 1, P[1]] : [P[0], P[1], 1], q = j[0], H = j[1], J = j[2], $ = o ? [1, G[1], G[0]] : [G[1], 1, G[0]], ee = $[0], te = $[1], ne = $[2], re = D * F, ie = S.buffer([k, D, F], I.dtype), oe = ie.values, se = e.blockSize, me = 0; me < k; me++)
for (var ye = 0; ye < D; ye += se)
for (var ve = 0; ve < F; ve += se)
for (var Ee = 0; Ee < O; Ee += se)
for (var Be = Math.min(ye + se, D), We = Math.min(ve + se, F), Ke = Math.min(Ee + se, O), ze = ye; ze < Be; ze++)
for (var Ie = ve; Ie < We; Ie++) {
for (var ue = 0, Qe = Ee; Qe < Ke; Qe++) {
var pt = Math.min(me, g - 1) * q, He = Math.min(me, y - 1) * ne, Ot = B[pt + ze * H + Qe * J], ut = V[Qe * ee + Ie * te + He];
ue += Ot * ut;
}
oe[me * re + (ze * F + Ie)] += ue;
}
return e.disposeIntermediateTensorInfo(I), e.disposeIntermediateTensorInfo(C), e.makeTensorInfo(x, ie.dtype, ie.values);
}
var O8 = {kernelName: S.BatchMatMul, backendName: "cpu", kernelFunc: Ow};
function E8(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.a, a = t.b, s = t.bias, o = t.preluActivationWeights, c = r.transposeA, l = r.transposeB, u = r.activation, h, d, p, f = [], m = Ow({inputs: {a: i, b: a}, attrs: {transposeA: c, transposeB: l}, backend: e});
h = m, s && (d = ts({inputs: {a: h, b: s}, backend: e}), f.push(h), h = d), u && (p = Fd(e, h, u, o), f.push(h), h = p);
for (var g = 0, y = f; g < y.length; g++) {
var w = y[g];
e.disposeIntermediateTensorInfo(w);
}
return h;
}
var D8 = {kernelName: S._FusedMatMul, backendName: "cpu", kernelFunc: E8};
var k8 = je(S.Acos, function(n) {
return Math.acos(n);
}), F8 = {kernelName: S.Acos, backendName: "cpu", kernelFunc: k8};
var W8 = je(S.Acosh, function(n) {
return Math.acosh(n);
}), U8 = {kernelName: S.Acosh, backendName: "cpu", kernelFunc: W8};
var B8 = je(S.Asin, function(n) {
return Math.asin(n);
}), z8 = {kernelName: S.Asin, backendName: "cpu", kernelFunc: B8};
var P8 = je(S.Asinh, function(n) {
return Math.asinh(n);
}), M8 = {kernelName: S.Asinh, backendName: "cpu", kernelFunc: P8};
var H8 = je(S.Atan, function(n) {
return Math.atan(n);
}), V8 = {kernelName: S.Atan, backendName: "cpu", kernelFunc: H8};
var G8 = je(S.Atanh, function(n) {
return Math.atanh(n);
}), q8 = {kernelName: S.Atanh, backendName: "cpu", kernelFunc: G8};
function Wd(n, t, e, r, i, a) {
for (var s = i.strideHeight, o = i.strideWidth, c = i.dilationHeight, l = i.dilationWidth, u = i.effectiveFilterHeight, h = i.effectiveFilterWidth, d = i.padInfo.top, p = i.padInfo.left, f = a === "max" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY, m = S.buffer(i.outShape, e), g = m.values, y = i.outShape[1] * i.outShape[2] * i.outShape[3], w = i.outShape[2] * i.outShape[3], b = i.outShape[3], x = 0; x < i.batchSize; ++x)
for (var L = x * y, N = x * r[0], I = 0; I < i.inChannels; ++I)
for (var C = 0; C < i.outHeight; ++C)
for (var O = C * s - d, D = Math.max(0, O), F = Math.min(i.inHeight, u + O), k = L + C * w, B = 0; B < i.outWidth; ++B) {
for (var V = B * o - p, P = Math.max(0, V), G = Math.min(i.inWidth, h + V), j = f, q = 0, H = 0, J = D; J < F; J += c) {
for (var $ = N + J * r[1], ee = P; ee < G; ee += l) {
var te = $ + ee * r[2], ne = n[te + I];
a === "max" && ne > j ? j = ne : a === "avg" && (q += ne, H++);
}
if (isNaN(j))
break;
}
var re = k + B * b + I;
g[re] = a === "avg" ? q / H : j;
}
return m;
}
function Ew(n, t, e, r, i, a) {
i === void 0 && (i = false), a === void 0 && (a = false);
for (var s = S.buffer(r.outShape, "int32"), o = r.strideHeight, c = r.strideWidth, l = r.dilationHeight, u = r.dilationWidth, h = r.effectiveFilterHeight, d = r.effectiveFilterWidth, p = r.padInfo.top, f = r.padInfo.left, m = S.buffer(t, e, n), g = 0; g < r.batchSize; ++g)
for (var y = 0; y < r.inChannels; ++y)
for (var w = 0; w < r.outHeight; ++w) {
for (var b = w * o - p, x = b; x < 0; )
x += l;
for (var L = Math.min(r.inHeight, h + b), N = 0; N < r.outWidth; ++N) {
for (var I = N * c - f, C = I; C < 0; )
C += u;
for (var O = Math.min(r.inWidth, d + I), D = Number.NEGATIVE_INFINITY, F = -1, k = x; k < L; k += l)
for (var B = k - b, V = C; V < O; V += u) {
var P = V - I, G = m.get(g, k, V, y);
G > D && (D = G, i ? F = a ? ((g * r.inHeight + k) * r.inWidth + V) * r.inChannels + y : (k * r.inWidth + V) * r.inChannels + y : F = B * d + P);
}
s.set(F, g, w, N, y);
}
}
return s;
}
function Y8(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x;
ae(i, "avgPool");
var a = r.filterSize, s = r.strides, o = r.pad, c = r.dimRoundingMode, l = 1;
S.util.assert(S.backend_util.eitherStridesOrDilationsAreOne(s, l), function() {
return "Error in avgPool: Either strides or dilations must be 1. " + ("Got strides " + s + " and dilations '" + l + "'");
});
var u = S.backend_util.computePool2DInfo(i.shape, a, s, l, o, c), h;
if (u.filterWidth === 1 && u.filterHeight === 1 && S.util.arraysEqual(u.inShape, u.outShape))
h = di({inputs: {x: i}, backend: e});
else {
var d = e.data.get(i.dataId).values, p = S.util.computeStrides(i.shape), f = Wd(d, i.shape, i.dtype, p, u, "avg");
h = e.makeTensorInfo(u.outShape, i.dtype, f.values);
}
return h;
}
var K8 = {kernelName: S.AvgPool, backendName: "cpu", kernelFunc: Y8};
function j8(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.dy, a = t.input, s = a;
ae([i, a], "avgPoolBackprop");
for (var o = r.filterSize, c = r.strides, l = r.pad, u = S.backend_util.computePool2DInfo(s.shape, o, c, 1, l), h = u.strideHeight, d = u.strideWidth, p = u.filterHeight, f = u.filterWidth, m = u.dilationHeight, g = u.dilationWidth, y = u.effectiveFilterHeight, w = u.effectiveFilterWidth, b = w - 1 - u.padInfo.left, x = y - 1 - u.padInfo.top, L = S.buffer(s.shape, "float32"), N = 1 / (p * f), I = e.data.get(i.dataId).values, C = S.buffer(i.shape, "float32", I), O = 0; O < u.batchSize; ++O)
for (var D = 0; D < u.inChannels; ++D)
for (var F = 0; F < u.inHeight; ++F)
for (var k = 0; k < u.inWidth; ++k) {
for (var B = F - x, V = k - b, P = 0, G = 0; G < y; G += m) {
var j = (B + G) / h;
if (j < 0 || j >= u.outHeight || Math.floor(j) !== j)
continue;
for (var q = 0; q < w; q += g) {
var H = (V + q) / d;
if (H < 0 || H >= u.outWidth || Math.floor(H) !== H)
continue;
var J = C.get(O, j, H, D);
P += J;
}
}
L.set(P * N, O, F, k, D);
}
return e.makeTensorInfo(L.shape, L.dtype, L.values);
}
var $8 = {kernelName: S.AvgPoolBackprop, backendName: "cpu", kernelFunc: j8};
function X8(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = t.scale, s = t.offset, o = t.mean, c = t.variance;
S.util.assert(o.shape.length === c.shape.length, function() {
return "Batch normalization gradient requires mean and variance to have equal ranks.";
}), S.util.assert(s == null || o.shape.length === s.shape.length, function() {
return "Batch normalization gradient requires mean and offset to have equal ranks.";
}), S.util.assert(a == null || o.shape.length === a.shape.length, function() {
return "Batch normalization gradient requires mean and scale to have equal ranks.";
}), ae([i, o, c, a, s], "batchNorm");
var l = r.varianceEpsilon;
l == null && (l = 1e-3);
for (var u = e.data.get(i.dataId).values, h = e.data.get(o.dataId).values, d = e.data.get(c.dataId).values, p = a ? e.data.get(a.dataId).values : new Float32Array([1]), f = s ? e.data.get(s.dataId).values : new Float32Array([0]), m = new Float32Array(u.length), g = f.length, y = p.length, w = d.length, b = h.length, x = 0, L = 0, N = 0, I = 0, C = 0; C < u.length; ++C)
m[C] = f[x++] + (u[C] - h[L++]) * p[N++] / Math.sqrt(d[I++] + l), x >= g && (x = 0), L >= b && (L = 0), N >= y && (N = 0), I >= w && (I = 0);
return e.makeTensorInfo(i.shape, i.dtype, m);
}
var J8 = {kernelName: S.FusedBatchNorm, backendName: "cpu", kernelFunc: X8};
var Z8 = je(S.ClipByValue, function(n, t) {
var e = t;
return n > e.clipValueMax ? e.clipValueMax : n < e.clipValueMin ? e.clipValueMin : n;
}), Q8 = {kernelName: S.ClipByValue, backendName: "cpu", kernelFunc: Z8};
function Bo(n) {
var t = n.inputs, e = n.backend, r = t.input, i = e.data.get(r.dataId).complexTensorInfos.imag, a = e.data.get(i.dataId).values;
return e.makeTensorInfo(i.shape, i.dtype, a);
}
var e9 = {kernelName: S.Imag, backendName: "cpu", kernelFunc: Bo};
function ns(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = r.axis, a = S.util.parseAxisParam(i, t[0].shape)[0], s = S.backend_util.computeOutShape(t.map(function(x) {
return x.shape;
}), a);
if (S.util.sizeFromShape(s) === 0)
return e.makeTensorInfo(s, t[0].dtype, []);
var o = t.filter(function(x) {
return S.util.sizeFromShape(x.shape) > 0;
});
if (o.length === 1)
return o[0];
var c = o.map(function(x) {
return x.shape;
});
if (S.backend_util.assertParamsConsistent(c, a), o[0].dtype === "complex64") {
var l = o.map(function(x) {
return Qa({inputs: {input: x}, backend: e});
}), u = o.map(function(x) {
return Bo({inputs: {input: x}, backend: e});
}), h = ns({inputs: l, backend: e, attrs: {axis: a}}), d = ns({inputs: u, backend: e, attrs: {axis: a}}), p = An({inputs: {real: h, imag: d}, backend: e});
return l.forEach(function(x) {
return e.disposeIntermediateTensorInfo(x);
}), u.forEach(function(x) {
return e.disposeIntermediateTensorInfo(x);
}), e.disposeIntermediateTensorInfo(h), e.disposeIntermediateTensorInfo(d), p;
}
var f = o.map(function(x) {
var L = S.util.sizeFromShape(x.shape.slice(a)), N = [-1, L];
return Un({inputs: {x}, backend: e, attrs: {shape: N}});
});
s = S.backend_util.computeOutShape(f.map(function(x) {
return x.shape;
}), 1);
var m = S.util.getTypedArrayFromDType(o[0].dtype, S.util.sizeFromShape(s));
if (f[0].shape[0] === 1) {
var g = 0;
f.forEach(function(x) {
var L = e.data.get(x.dataId).values, N = S.util.sizeFromShape(x.shape);
m.set(L, g), g += N;
});
} else {
var y = 0;
f.forEach(function(x) {
for (var L = e.data.get(x.dataId).values, N = 0, I = 0; I < x.shape[0]; ++I)
for (var C = I * s[1] + y, O = 0; O < x.shape[1]; ++O)
m[C + O] = L[N++];
y += x.shape[1];
});
}
var w = S.backend_util.computeOutShape(o.map(function(x) {
return x.shape;
}), a), b = e.makeTensorInfo(w, t[0].dtype, m);
return f.forEach(function(x) {
return e.disposeIntermediateTensorInfo(x);
}), b;
}
var t9 = {kernelName: S.Concat, backendName: "cpu", kernelFunc: ns};
function Dw(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = t.filter, s = r.strides, o = r.pad, c = r.dataFormat, l = r.dilations, u = r.dimRoundingMode;
ae([i, a], "conv2d");
for (var h = S.backend_util.convertConv2DDataFormat(c), d = S.backend_util.computeConv2DInfo(i.shape, a.shape, s, l, o, u, false, h), p = d.filterHeight, f = d.filterWidth, m = d.dilationHeight, g = d.dilationWidth, y = d.padInfo.left, w = d.padInfo.top, b = d.dataFormat === "channelsLast", x = new S.TensorBuffer(d.outShape, i.dtype), L = S.util.computeStrides(i.shape), N = S.util.computeStrides(a.shape), I = L[0], C = b ? L[1] : L[2], O = b ? L[2] : 1, D = b ? 1 : L[1], F = x.strides[0], k = b ? x.strides[1] : x.strides[2], B = b ? x.strides[2] : 1, V = b ? 1 : x.strides[1], P = e.data.get(i.dataId).values, G = e.data.get(a.dataId).values, j = x.values, q = 0; q < d.batchSize; ++q)
for (var H = q * I, J = q * F, $ = 0; $ < d.outHeight; ++$)
for (var ee = J + $ * k, te = $ * d.strideHeight - w, ne = 0; ne < p; ++ne) {
var re = te + ne * m;
if (re < 0 || re >= d.inHeight)
continue;
for (var ie = ne * N[0], oe = H + re * C, se = 0; se < d.outWidth; ++se)
for (var me = ee + se * B, ye = se * d.strideWidth - y, ve = 0; ve < f; ++ve) {
var Ee = ye + ve * g;
if (Ee < 0 || Ee >= d.inWidth)
continue;
for (var Be = ie + ve * N[1], We = oe + Ee * O, Ke = Be, ze = 0; ze < d.inChannels; ++ze) {
for (var Ie = P[We + ze * D], ue = 0; ue < d.outChannels; ++ue)
j[me + ue * V] += Ie * G[Ke + ue];
Ke += d.outChannels;
}
}
}
return e.makeTensorInfo(x.shape, x.dtype, j);
}
var n9 = {kernelName: S.Conv2D, backendName: "cpu", kernelFunc: Dw};
function r9(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = t.dy, s = r.strides, o = r.pad, c = r.dataFormat, l = r.dimRoundingMode, u = r.filterShape;
ae([i, a], "conv2dBackpropFilter");
for (var h = S.backend_util.convertConv2DDataFormat(c), d = S.backend_util.computeConv2DInfo(i.shape, u, s, 1, o, l, false, h), p = d.strideHeight, f = d.strideWidth, m = d.filterHeight, g = d.filterWidth, y = d.dataFormat === "channelsLast", w = new S.TensorBuffer(d.filterShape, "float32"), b = d.padInfo.left, x = d.padInfo.top, L = e.data.get(i.dataId).values, N = e.data.get(a.dataId).values, I = new S.TensorBuffer(i.shape, i.dtype, L), C = new S.TensorBuffer(a.shape, a.dtype, N), O = 0; O < m; ++O)
for (var D = Math.max(0, Math.ceil((x - O) / p)), F = Math.min(d.outHeight, (d.inHeight + x - O) / p), k = 0; k < g; ++k)
for (var B = Math.max(0, Math.ceil((b - k) / f)), V = Math.min(d.outWidth, (d.inWidth + b - k) / f), P = 0; P < d.inChannels; ++P)
for (var G = 0; G < d.outChannels; ++G) {
for (var j = 0, q = 0; q < d.batchSize; ++q)
for (var H = D; H < F; ++H)
for (var J = O + H * p - x, $ = B; $ < V; ++$) {
var ee = k + $ * f - b;
y ? j += I.get(q, J, ee, P) * C.get(q, H, $, G) : j += I.get(q, P, J, ee) * C.get(q, G, H, $);
}
w.set(j, O, k, P, G);
}
return e.makeTensorInfo(w.shape, w.dtype, w.values);
}
var i9 = {kernelName: S.Conv2DBackpropFilter, backendName: "cpu", kernelFunc: r9};
function a9(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.dy, a = t.filter, s = r.inputShape, o = r.strides, c = r.pad, l = r.dataFormat, u = r.dimRoundingMode;
ae([i, a], "conv2dBackpropInput");
var h = S.util.computeStrides(a.shape), d = S.util.computeStrides(i.shape), p = S.backend_util.convertConv2DDataFormat(l), f = S.backend_util.computeConv2DInfo(s, a.shape, o, 1, c, u, false, p), m = new S.TensorBuffer(f.inShape, "float32"), g = m.values, y = e.data.get(i.dataId).values, w = e.data.get(a.dataId).values, b = h[0], x = h[1], L = h[2], N = f.batchSize, I = f.filterHeight, C = f.filterWidth, O = f.inChannels, D = f.inHeight, F = f.inWidth, k = f.outChannels, B = f.outHeight, V = f.outWidth, P = f.strideHeight, G = f.strideWidth;
p = f.dataFormat;
for (var j = I - 1 - f.padInfo.top, q = C - 1 - f.padInfo.left, H = p === "channelsLast", J = m.strides[0], $ = H ? m.strides[1] : m.strides[2], ee = H ? m.strides[2] : 1, te = H ? 1 : m.strides[1], ne = d[0], re = H ? d[1] : d[2], ie = H ? d[2] : 1, oe = H ? 1 : d[1], se = 0; se < N; ++se)
for (var me = 0; me < O; ++me)
for (var ye = 0; ye < D; ++ye)
for (var ve = ye - j, Ee = Math.max(0, Math.ceil(ve / P)), Be = Math.min(B, (I + ve) / P), We = 0; We < F; ++We) {
for (var Ke = We - q, ze = Math.max(0, Math.ceil(Ke / G)), Ie = Math.min(V, (C + Ke) / G), ue = 0, Qe = Ee; Qe < Be; ++Qe)
for (var pt = Qe * P - ve, He = ze; He < Ie; ++He)
for (var Ot = He * G - Ke, ut = ne * se + re * Qe + ie * He, vt = b * (I - 1 - pt) + x * (C - 1 - Ot) + L * me, Te = 0; Te < k; ++Te) {
var ht = y[ut + oe * Te], ft = w[vt + Te];
ue += ht * ft;
}
var Ge = J * se + $ * ye + ee * We + te * me;
g[Ge] = ue;
}
return e.makeTensorInfo(m.shape, m.dtype, m.values);
}
var s9 = {kernelName: S.Conv2DBackpropInput, backendName: "cpu", kernelFunc: a9};
function o9(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = t.filter, s = r.strides, o = r.pad, c = r.dilations;
ae([i, a], "conv3d");
for (var l = S.backend_util.computeConv3DInfo(i.shape, a.shape, s, c, o), u = l.filterDepth, h = l.filterHeight, d = l.filterWidth, p = l.dilationDepth, f = l.dilationHeight, m = l.dilationWidth, g = l.padInfo, y = g.front, w = g.left, b = g.top, x = new S.TensorBuffer(l.outShape, i.dtype), L = e.data.get(i.dataId).values, N = e.data.get(a.dataId).values, I = x.values, C = S.util.computeStrides(i.shape), O = S.util.computeStrides(a.shape), D = 0; D < l.batchSize; ++D)
for (var F = D * C[0], k = D * x.strides[0], B = 0; B < l.outDepth; ++B)
for (var V = k + B * x.strides[1], P = B * l.strideDepth - y, G = 0; G < u; ++G) {
var j = P + G * p;
if (j < 0 || j >= l.inDepth)
continue;
for (var q = G * O[0], H = F + j * C[1], J = 0; J < l.outHeight; ++J)
for (var $ = V + J * x.strides[2], ee = J * l.strideHeight - b, te = 0; te < h; ++te) {
var ne = ee + te * f;
if (ne < 0 || ne >= l.inHeight)
continue;
for (var re = q + te * O[1], ie = H + ne * C[2], oe = 0; oe < l.outWidth; ++oe)
for (var se = $ + oe * l.outChannels, me = oe * l.strideWidth - w, ye = 0; ye < d; ++ye) {
var ve = me + ye * m;
if (ve < 0 || ve >= l.inWidth)
continue;
for (var Ee = re + ye * O[2], Be = ie + ve * l.inChannels, We = Ee, Ke = 0; Ke < l.inChannels; ++Ke) {
for (var ze = L[Be + Ke], Ie = 0; Ie < l.outChannels; ++Ie)
I[se + Ie] += ze * N[We + Ie];
We += l.outChannels;
}
}
}
}
return e.makeTensorInfo(x.shape, x.dtype, x.values);
}
var c9 = {kernelName: S.Conv3D, backendName: "cpu", kernelFunc: o9};
function l9(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = t.dy, s = r.strides, o = r.pad, c = r.filterShape;
ae([i, a], "conv3dBackpropFilterV2");
for (var l = S.util.computeStrides(i.shape), u = S.util.computeStrides(a.shape), h = S.backend_util.computeConv3DInfo(i.shape, c, s, 1, o), d = h.strideDepth, p = h.strideHeight, f = h.strideWidth, m = h.filterDepth, g = h.filterHeight, y = h.filterWidth, w = new S.TensorBuffer(h.filterShape, "float32"), b = w.values, x = w.strides, L = x[0], N = x[1], I = x[2], C = x[3], O = e.data.get(a.dataId).values, D = u[0], F = u[1], k = u[2], B = u[3], V = e.data.get(i.dataId).values, P = l[0], G = l[1], j = l[2], q = l[3], H = h.padInfo.front, J = h.padInfo.left, $ = h.padInfo.top, ee = 0; ee < m; ++ee)
for (var te = Math.max(0, Math.ceil((H - ee) / d)), ne = Math.min(h.outDepth, (h.inDepth + H - ee) / d), re = ee * L, ie = 0; ie < g; ++ie)
for (var oe = Math.max(0, Math.ceil(($ - ie) / p)), se = Math.min(h.outHeight, (h.inHeight + $ - ie) / p), me = ie * N + re, ye = 0; ye < y; ++ye)
for (var ve = Math.max(0, Math.ceil((J - ye) / f)), Ee = Math.min(h.outWidth, (h.inWidth + J - ye) / f), Be = ye * I + me, We = 0; We < h.inChannels; ++We)
for (var Ke = We * C + Be, ze = 0; ze < h.outChannels; ++ze) {
for (var Ie = 0, ue = 0; ue < h.batchSize; ++ue)
for (var Qe = ue * P, pt = ue * D, He = te; He < ne; ++He)
for (var Ot = ee + He * d - H, ut = Ot * G + Qe, vt = He * F + pt, Te = oe; Te < se; ++Te)
for (var ht = ie + Te * p - $, ft = ht * j + ut, Ge = Te * k + vt, jt = ve; jt < Ee; ++jt) {
var qn = ye + jt * f - J, kt = qn * q + ft, ma = jt * B + Ge;
Ie += V[kt + We] * O[ma + ze];
}
b[Ke + ze] = Ie;
}
return e.makeTensorInfo(w.shape, w.dtype, w.values);
}
var u9 = {kernelName: S.Conv3DBackpropFilterV2, backendName: "cpu", kernelFunc: l9};
function h9(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.dy, a = t.filter, s = r.pad, o = r.strides, c = r.inputShape;
ae([i], "conv3dBackpropInputV2");
for (var l = S.util.computeStrides(i.shape), u = S.util.computeStrides(a.shape), h = S.backend_util.computeConv3DInfo(c, a.shape, o, 1, s), d = new S.TensorBuffer(h.inShape, "float32"), p = d.values, f = d.strides, m = f[0], g = f[1], y = f[2], w = f[3], b = e.data.get(i.dataId).values, x = l[0], L = l[1], N = l[2], I = l[3], C = e.data.get(a.dataId).values, O = u[0], D = u[1], F = u[2], k = u[3], B = h.batchSize, V = h.filterDepth, P = h.filterHeight, G = h.filterWidth, j = h.inChannels, q = h.inDepth, H = h.inHeight, J = h.inWidth, $ = h.outChannels, ee = h.outDepth, te = h.outHeight, ne = h.outWidth, re = h.strideDepth, ie = h.strideHeight, oe = h.strideWidth, se = V - 1 - h.padInfo.front, me = P - 1 - h.padInfo.top, ye = G - 1 - h.padInfo.left, ve = 0; ve < B; ++ve)
for (var Ee = 0; Ee < j; ++Ee)
for (var Be = 0; Be < q; ++Be)
for (var We = Be - se, Ke = Math.max(0, Math.ceil(We / re)), ze = Math.min(ee, (V + We) / re), Ie = 0; Ie < H; ++Ie)
for (var ue = Ie - me, Qe = Math.max(0, Math.ceil(ue / ie)), pt = Math.min(te, (P + ue) / ie), He = 0; He < J; ++He) {
for (var Ot = He - ye, ut = Math.max(0, Math.ceil(Ot / oe)), vt = Math.min(ne, (G + Ot) / oe), Te = 0, ht = Ke; ht < ze; ++ht)
for (var ft = ht * re - We, Ge = Qe; Ge < pt; ++Ge)
for (var jt = Ge * ie - ue, qn = ut; qn < vt; ++qn)
for (var kt = qn * oe - Ot, ma = x * ve + L * ht + N * Ge + I * qn, cr = O * (V - 1 - ft) + D * (P - 1 - jt) + F * (G - 1 - kt) + k * Ee, bi = 0; bi < $; ++bi) {
var cc = b[ma + bi], lc = C[cr + bi];
Te += cc * lc;
}
p[m * ve + g * Be + y * Ie + w * He + Ee] = Te;
}
return e.makeTensorInfo(d.shape, d.dtype, d.values);
}
var d9 = {kernelName: S.Conv3DBackpropInputV2, backendName: "cpu", kernelFunc: h9};
var p9 = je(S.Cos, function(n) {
return Math.cos(n);
}), f9 = {kernelName: S.Cos, backendName: "cpu", kernelFunc: p9};
var m9 = je(S.Cosh, function(n) {
return Math.cosh(n);
}), g9 = {kernelName: S.Cosh, backendName: "cpu", kernelFunc: m9};
function kw(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = t.filter, s = r.strides, o = r.pad, c = r.dilations, l = r.dimRoundingMode;
ae([i, a], "depthwiseConv2DNative");
var u = S.util.computeStrides(i.shape), h = S.util.computeStrides(a.shape), d = c;
d == null && (d = [1, 1]), S.util.assert(S.backend_util.eitherStridesOrDilationsAreOne(s, d), function() {
return "Error in depthwiseConv2d: Either strides or dilations must be " + ("1. Got strides " + s + " and dilations '" + d + "'");
});
for (var p = S.backend_util.computeConv2DInfo(i.shape, a.shape, s, d, o, l, true), f = p.filterHeight, m = p.filterWidth, g = p.dilationHeight, y = p.dilationWidth, w = p.padInfo, b = w.left, x = w.top, L = p.outChannels / p.inChannels, N = new S.TensorBuffer(p.outShape, i.dtype), I = e.data.get(i.dataId).values, C = e.data.get(a.dataId).values, O = N.values, D = 0; D < p.batchSize; ++D)
for (var F = D * u[0], k = D * N.strides[0], B = 0; B < p.outHeight; ++B)
for (var V = k + B * N.strides[1], P = B * p.strideHeight - b, G = 0; G < f; ++G) {
var j = P + G * g;
if (j < 0 || j >= p.inHeight)
continue;
for (var q = G * h[0], H = F + j * u[1], J = 0; J < p.outWidth; ++J)
for (var $ = V + J * N.strides[2], ee = J * p.strideWidth - x, te = 0; te < m; ++te) {
var ne = ee + te * y;
if (ne < 0 || ne >= p.inWidth)
continue;
for (var re = q + te * h[1], ie = H + ne * p.inChannels, oe = $, se = re, me = 0; me < p.inChannels; ++me) {
for (var ye = I[ie + me], ve = 0; ve < L; ++ve)
O[oe + ve] += ye * C[se + ve];
oe += L, se += L;
}
}
}
return e.makeTensorInfo(N.shape, N.dtype, N.values);
}
var y9 = {kernelName: S.DepthwiseConv2dNative, backendName: "cpu", kernelFunc: kw};
function v9(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = t.dy, s = r.strides, o = r.dilations, c = r.pad, l = r.dimRoundingMode, u = r.filterShape;
ae([i, a], "depthwiseConv2dNativeBackpropFilter");
for (var h = S.backend_util.computeConv2DInfo(i.shape, u, s, o, c, l, true), d = h.strideHeight, p = h.strideWidth, f = h.filterHeight, m = h.filterWidth, g = new S.TensorBuffer(h.filterShape, "float32"), y = h.padInfo.left, w = h.padInfo.top, b = h.outChannels / h.inChannels, x = e.data.get(i.dataId).values, L = new S.TensorBuffer(i.shape, i.dtype, x), N = e.data.get(a.dataId).values, I = new S.TensorBuffer(a.shape, a.dtype, N), C = 0; C < f; ++C)
for (var O = Math.max(0, Math.ceil((w - C) / d)), D = Math.min(h.outHeight, (h.inHeight + w - C) / d), F = 0; F < m; ++F)
for (var k = Math.max(0, Math.ceil((y - F) / p)), B = Math.min(h.outWidth, (h.inWidth + y - F) / p), V = 0; V < h.outChannels; ++V) {
for (var P = Math.trunc(V / b), G = V % b, j = 0, q = 0; q < h.batchSize; ++q)
for (var H = O; H < D; ++H)
for (var J = C + H * d - w, $ = k; $ < B; ++$) {
var ee = F + $ * p - y;
j += L.get(q, J, ee, P) * I.get(q, H, $, V);
}
g.set(j, C, F, P, G);
}
return e.makeTensorInfo(g.shape, g.dtype, g.values);
}
var w9 = {kernelName: S.DepthwiseConv2dNativeBackpropFilter, backendName: "cpu", kernelFunc: v9};
function b9(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.dy, a = t.filter, s = r.strides, o = r.dilations, c = r.pad, l = r.dimRoundingMode, u = r.inputShape;
ae([i, a], "depthwiseConv2DNativeBackpropInput");
for (var h = S.util.computeStrides(i.shape), d = S.util.computeStrides(a.shape), p = S.backend_util.computeConv2DInfo(u, a.shape, s, o, c, l, true), f = new S.TensorBuffer(p.inShape, "float32"), m = f.values, g = f.strides, y = g[0], w = g[1], b = g[2], x = e.data.get(i.dataId).values, L = h[0], N = h[1], I = h[2], C = e.data.get(a.dataId).values, O = d[0], D = d[1], F = d[2], k = p.batchSize, B = p.filterHeight, V = p.filterWidth, P = p.inChannels, G = p.inHeight, j = p.inWidth, q = p.outChannels, H = p.outHeight, J = p.outWidth, $ = p.strideHeight, ee = p.strideWidth, te = B - 1 - p.padInfo.top, ne = V - 1 - p.padInfo.left, re = q / P, ie = 0; ie < k; ++ie)
for (var oe = 0; oe < P; ++oe)
for (var se = 0; se < G; ++se)
for (var me = se - te, ye = Math.max(0, Math.ceil(me / $)), ve = Math.min(H, (B + me) / $), Ee = 0; Ee < j; ++Ee) {
for (var Be = Ee - ne, We = Math.max(0, Math.ceil(Be / ee)), Ke = Math.min(J, (V + Be) / ee), ze = 0, Ie = ye; Ie < ve; ++Ie)
for (var ue = Ie * $ - me, Qe = We; Qe < Ke; ++Qe)
for (var pt = Qe * ee - Be, He = L * ie + N * Ie + I * Qe, Ot = O * (B - 1 - ue) + D * (V - 1 - pt) + F * oe, ut = 0; ut < re; ++ut) {
var vt = oe * re + ut, Te = x[He + vt], ht = C[Ot + ut];
ze += Te * ht;
}
m[y * ie + w * se + b * Ee + oe] = ze;
}
return e.makeTensorInfo(f.shape, f.dtype, f.values);
}
var x9 = {kernelName: S.DepthwiseConv2dNativeBackpropInput, backendName: "cpu", kernelFunc: b9};
var L9 = {kernelName: S.Dilation2D, backendName: "cpu", kernelFunc: function(n) {
for (var t = n.inputs, e = n.backend, r = n.attrs, i = t, a = i.x, s = i.filter, o = r, c = o.strides, l = o.pad, u = o.dilations, h = e, d = h.data.get(a.dataId).values, p = a.shape.length, f = h.data.get(s.dataId).values, m = s.shape.length, g = S.backend_util.computeDilation2DInfo(a.shape, s.shape, c, l, "NHWC", u), y = g.batchSize, w = g.inHeight, b = g.inWidth, x = g.inChannels, L = g.outHeight, N = g.outWidth, I = g.padInfo, C = g.strideHeight, O = g.strideWidth, D = g.filterHeight, F = g.filterWidth, k = g.dilationHeight, B = g.dilationWidth, V = g.outShape, P = S.util.sizeFromShape(V), G = V.length, j = S.util.getArrayFromDType(a.dtype, P), q = 0; q < y; ++q)
for (var H = 0; H < L; ++H)
for (var J = H * C - I.top, $ = 0; $ < N; ++$)
for (var ee = $ * O - I.left, te = 0; te < x; ++te) {
for (var ne = Number.MIN_SAFE_INTEGER, re = 0; re < D; ++re) {
var ie = J + re * k;
if (ie >= 0 && ie < w)
for (var oe = 0; oe < F; ++oe) {
var se = ee + oe * B;
if (se >= 0 && se < b) {
var me = S.util.locToIndex([q, ie, se, te], p, S.util.computeStrides(a.shape)), ye = S.util.locToIndex([re, oe, te], m, S.util.computeStrides(s.shape)), ve = d[me] + f[ye];
ve > ne && (ne = ve);
}
}
}
var Ee = S.util.locToIndex([q, H, $, te], G, S.util.computeStrides(V));
j[Ee] = ne;
}
var Be = h.write(S.util.toTypedArray(j, a.dtype), V, a.dtype);
return {dataId: Be, shape: V, dtype: a.dtype};
}};
var S9 = {kernelName: S.Dilation2DBackpropFilter, backendName: "cpu", kernelFunc: function(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t, a = i.x, s = i.filter, o = i.dy, c = r, l = c.strides, u = c.pad, h = c.dilations, d = e, p = S.util.toNestedArray(a.shape, d.data.get(a.dataId).values), f = S.util.toNestedArray(s.shape, d.data.get(s.dataId).values), m = S.backend_util.computeDilation2DInfo(a.shape, s.shape, l, u, "NHWC", h), g = m.batchSize, y = m.inHeight, w = m.inWidth, b = m.inChannels, x = m.outHeight, L = m.outWidth, N = m.padInfo, I = m.strideHeight, C = m.strideWidth, O = m.filterHeight, D = m.filterWidth, F = m.dilationHeight, k = m.dilationWidth, B = m.outShape;
S.util.assert(o.rank === B.length, function() {
return "Error in " + S.Dilation2DBackpropFilter + ", dy " + ("must have the same rank as output " + B.length + ", but got ") + ("" + o.rank);
});
for (var V = S.util.toNestedArray(B, d.data.get(o.dataId).values), P = S.util.makeZerosNestedTypedArray(s.shape, s.dtype), G = 0; G < g; ++G)
for (var j = 0; j < x; ++j)
for (var q = j * I - N.top, H = 0; H < L; ++H)
for (var J = H * C - N.left, $ = 0; $ < b; ++$) {
for (var ee = Number.MIN_SAFE_INTEGER, te = 0, ne = 0, re = 0; re < O; ++re) {
var ie = q + re * F;
if (ie >= 0 && ie < y)
for (var oe = 0; oe < D; ++oe) {
var se = J + oe * k;
if (se >= 0 && se < w) {
var me = p[G][ie][se][$] + f[re][oe][$];
me > ee && (ee = me, te = re, ne = oe);
}
}
}
P[te][ne][$] += V[G][j][H][$];
}
var ye = d.write(S.util.toTypedArray(P, a.dtype), s.shape, s.dtype);
return {dataId: ye, shape: s.shape, dtype: s.dtype};
}};
var I9 = {kernelName: S.Dilation2DBackpropInput, backendName: "cpu", kernelFunc: function(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t, a = i.x, s = i.filter, o = i.dy, c = r, l = c.strides, u = c.pad, h = c.dilations, d = e, p = S.util.toNestedArray(a.shape, d.data.get(a.dataId).values), f = S.util.toNestedArray(s.shape, d.data.get(s.dataId).values), m = S.backend_util.computeDilation2DInfo(a.shape, s.shape, l, u, "NHWC", h), g = m.batchSize, y = m.inHeight, w = m.inWidth, b = m.inChannels, x = m.outHeight, L = m.outWidth, N = m.padInfo, I = m.strideHeight, C = m.strideWidth, O = m.filterHeight, D = m.filterWidth, F = m.dilationHeight, k = m.dilationWidth, B = m.outShape;
S.util.assert(o.rank === B.length, function() {
return "Error in " + S.Dilation2DBackpropInput + ", dy " + ("must have the same rank as output " + B.length + ", but got ") + ("" + o.rank);
});
for (var V = S.util.toNestedArray(B, d.data.get(o.dataId).values), P = S.util.makeZerosNestedTypedArray(a.shape, a.dtype), G = 0; G < g; ++G)
for (var j = 0; j < x; ++j)
for (var q = j * I - N.top, H = 0; H < L; ++H)
for (var J = H * C - N.left, $ = 0; $ < b; ++$) {
for (var ee = Number.MIN_SAFE_INTEGER, te = q < 0 ? 0 : q, ne = J < 0 ? 0 : J, re = 0; re < O; ++re) {
var ie = q + re * F;
if (ie >= 0 && ie < y)
for (var oe = 0; oe < D; ++oe) {
var se = J + oe * k;
if (se >= 0 && se < w) {
var me = p[G][ie][se][$] + f[re][oe][$];
me > ee && (ee = me, te = ie, ne = se);
}
}
}
P[G][te][ne][$] += V[G][j][H][$];
}
var ye = d.write(S.util.toTypedArray(P, a.dtype), a.shape, a.dtype);
return {dataId: ye, shape: a.shape, dtype: a.dtype};
}};
var A9 = Er(function(n, t) {
return n / t;
}), T9 = Zi(S.Div, A9), Ud = {kernelName: S.Div, backendName: "cpu", kernelFunc: T9};
var N9 = S.backend_util.ERF_P, _9 = S.backend_util.ERF_A1, C9 = S.backend_util.ERF_A2, R9 = S.backend_util.ERF_A3, O9 = S.backend_util.ERF_A4, E9 = S.backend_util.ERF_A5, D9 = je(S.Erf, function(n) {
var t = Math.sign(n), e = Math.abs(n), r = 1 / (1 + N9 * e);
return t * (1 - ((((E9 * r + O9) * r + R9) * r + C9) * r + _9) * r * Math.exp(-e * e));
}), k9 = {kernelName: S.Erf, backendName: "cpu", kernelFunc: D9};
function Fw(n, t, e) {
for (var r = n.shape, i = r[0], a = r[1], s = e.data.get(n.dataId), o = s.complexTensorInfos.real, c = s.complexTensorInfos.imag, l = [i, a], u = S.util.sizeFromShape(l), h = S.util.getTypedArrayFromDType("float32", u), d = S.util.getTypedArrayFromDType("float32", u), p = 0; p < i; p++) {
for (var f = Dd({inputs: {x: o}, backend: e, attrs: {begin: [p, 0], size: [1, a]}}), m = Dd({inputs: {x: c}, backend: e, attrs: {begin: [p, 0], size: [1, a]}}), g = An({inputs: {real: f, imag: m}, backend: e}), y = F9(g, t, e), w = y.real, b = y.imag, x = S.backend_util.mergeRealAndImagArrays(w, b), L = 0; L < a; L++) {
var N = S.backend_util.getComplexWithIndex(x, L);
h[p * a + L] = N.real, d[p * a + L] = N.imag;
}
e.disposeIntermediateTensorInfo(f), e.disposeIntermediateTensorInfo(m), e.disposeIntermediateTensorInfo(g);
}
var I = e.makeTensorInfo(l, "float32", h), C = e.makeTensorInfo(l, "float32", d), O = An({inputs: {real: I, imag: C}, backend: e});
return e.disposeIntermediateTensorInfo(I), e.disposeIntermediateTensorInfo(C), O;
}
function F9(n, t, e) {
var r = S.util.sizeFromShape(n.shape), i = e.data.get(n.dataId), a = e.data.get(i.complexTensorInfos.real.dataId).values, s = e.data.get(i.complexTensorInfos.imag.dataId).values;
if (W9(r)) {
var o = Bd(a, s, r, t, e), c = [n.shape[0], n.shape[1]];
if (t) {
var l = e.makeTensorInfo(c, "float32", o.real), u = e.makeTensorInfo(c, "float32", o.imag), h = e.makeTensorInfo([], "float32", S.util.createScalarValue(r, "float32")), d = di({inputs: {x: h}, backend: e}), p = Ud.kernelFunc({inputs: {a: l, b: h}, backend: e}), f = Ud.kernelFunc({inputs: {a: u, b: d}, backend: e}), m = e.data.get(p.dataId).values, g = e.data.get(f.dataId).values;
return e.disposeIntermediateTensorInfo(l), e.disposeIntermediateTensorInfo(u), e.disposeIntermediateTensorInfo(h), e.disposeIntermediateTensorInfo(d), e.disposeIntermediateTensorInfo(p), e.disposeIntermediateTensorInfo(f), {real: m, imag: g};
}
return o;
} else {
var y = S.backend_util.mergeRealAndImagArrays(a, s), w = U9(y, r, t);
return S.backend_util.splitRealAndImagArrays(w);
}
}
function W9(n) {
return (n & n - 1) === 0;
}
function Bd(n, t, e, r, i) {
if (e === 1)
return {real: n, imag: t};
var a = S.backend_util.mergeRealAndImagArrays(n, t), s = e / 2, o = S.backend_util.complexWithEvenIndex(a), c = o.real, l = o.imag, u = [c.length], h = i.makeTensorInfo(u, "float32", c), d = i.makeTensorInfo(u, "float32", l), p = An({inputs: {real: h, imag: d}, backend: i}), f = S.backend_util.complexWithOddIndex(a), m = f.real, g = f.imag, y = [m.length], w = i.makeTensorInfo(y, "float32", m), b = i.makeTensorInfo(y, "float32", g), x = An({inputs: {real: w, imag: b}, backend: i}), L = Bd(c, l, s, r, i), N = L.real, I = L.imag, C = [N.length], O = i.makeTensorInfo(C, "float32", N), D = i.makeTensorInfo(C, "float32", I), F = An({inputs: {real: O, imag: D}, backend: i}), k = Bd(m, g, s, r, i), B = k.real, V = k.imag, P = [B.length], G = i.makeTensorInfo(P, "float32", B), j = i.makeTensorInfo(P, "float32", V), q = An({inputs: {real: G, imag: j}, backend: i}), H = S.backend_util.exponents(e, r), J = [H.real.length], $ = i.makeTensorInfo(J, "float32", H.real), ee = i.makeTensorInfo(J, "float32", H.imag), te = An({inputs: {real: $, imag: ee}, backend: i}), ne = ww({inputs: {a: te, b: q}, backend: i}), re = ts({inputs: {a: F, b: ne}, backend: i}), ie = Aw({inputs: {a: F, b: ne}, backend: i}), oe = Qa({inputs: {input: re}, backend: i}), se = Qa({inputs: {input: ie}, backend: i}), me = Bo({inputs: {input: re}, backend: i}), ye = Bo({inputs: {input: ie}, backend: i}), ve = ns({inputs: [oe, se], backend: i, attrs: {axis: 0}}), Ee = ns({inputs: [me, ye], backend: i, attrs: {axis: 0}}), Be = i.data.get(ve.dataId).values, We = i.data.get(Ee.dataId).values;
return i.disposeIntermediateTensorInfo(h), i.disposeIntermediateTensorInfo(d), i.disposeIntermediateTensorInfo(p), i.disposeIntermediateTensorInfo(w), i.disposeIntermediateTensorInfo(b), i.disposeIntermediateTensorInfo(x), i.disposeIntermediateTensorInfo(O), i.disposeIntermediateTensorInfo(D), i.disposeIntermediateTensorInfo(F), i.disposeIntermediateTensorInfo(G), i.disposeIntermediateTensorInfo(j), i.disposeIntermediateTensorInfo(q), i.disposeIntermediateTensorInfo($), i.disposeIntermediateTensorInfo(ee), i.disposeIntermediateTensorInfo(te), i.disposeIntermediateTensorInfo(ne), i.disposeIntermediateTensorInfo(re), i.disposeIntermediateTensorInfo(ie), i.disposeIntermediateTensorInfo(oe), i.disposeIntermediateTensorInfo(me), i.disposeIntermediateTensorInfo(se), i.disposeIntermediateTensorInfo(ye), i.disposeIntermediateTensorInfo(ve), i.disposeIntermediateTensorInfo(Ee), {real: Be, imag: We};
}
function U9(n, t, e) {
for (var r = new Float32Array(t * 2), i = 0; i < t; i++) {
for (var a = 0, s = 0, o = 0; o < t; o++) {
var c = S.backend_util.exponent(i * o, t, e), l = S.backend_util.getComplexWithIndex(n, o);
a += l.real * c.real - l.imag * c.imag, s += l.real * c.imag + l.imag * c.real;
}
e && (a /= t, s /= t), S.backend_util.assignToTypedArray(r, a, s, i);
}
return r;
}
function B9(n) {
var t = n.inputs, e = n.backend, r = t.input, i = S.util.sizeFromShape(r.shape), a = r.shape[r.shape.length - 1], s = i / a, o = Un({inputs: {x: r}, backend: e, attrs: {shape: [s, a]}}), c = Fw(o, false, e), l = Un({inputs: {x: c}, backend: e, attrs: {shape: r.shape}});
return e.disposeIntermediateTensorInfo(o), e.disposeIntermediateTensorInfo(c), l;
}
var z9 = {kernelName: S.FFT, backendName: "cpu", kernelFunc: B9};
function M9(n) {
var t = n.backend, e = n.attrs, r = e.shape, i = e.value, a = e.dtype, s = a || S.util.inferDtype(i), o = S.util.getArrayFromDType(s, S.util.sizeFromShape(r));
return P9(o, i, s), t.makeTensorInfo(r, s, o);
}
var H9 = {kernelName: S.Fill, backendName: "cpu", kernelFunc: M9};
function P9(n, t, e) {
e === "string", n.fill(t);
}
var V9 = {kernelName: S.FlipLeftRight, backendName: "cpu", kernelFunc: function(n) {
for (var t = n.inputs, e = n.attrs, r = n.backend, i = t.image, a = r, s = S.util.getTypedArrayFromDType(i.dtype, S.util.sizeFromShape(i.shape)), o = i.shape, c = o[0], l = o[1], u = o[2], h = o[3], d = a.data.get(i.dataId).values, p = 0; p < c; p++)
for (var f = p * u * l * h, m = 0; m < l; m++)
for (var g = m * (u * h), y = 0; y < u; y++)
for (var w = y * h, b = 0; b < h; b++) {
var x = [c, m, y, b], L = x[2], N = Math.round(u - L), I = f + g + w + b, C = d[I];
if (N >= 0 && N < u) {
var O = N * h, D = f + g + O + b;
C = d[D];
}
s[I] = C;
}
var F = a.write(s, i.shape, i.dtype);
return {dataId: F, shape: i.shape, dtype: i.dtype};
}};
function G9(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = t.filter, s = t.bias, o = t.preluActivationWeights, c = r.strides, l = r.pad, u = r.dataFormat, h = r.dilations, d = r.dimRoundingMode, p = r.activation, f = Dw({inputs: {x: i, filter: a}, backend: e, attrs: {strides: c, pad: l, dataFormat: u, dilations: h, dimRoundingMode: d}});
if (s) {
var m = f;
f = ts({inputs: {a: f, b: s}, backend: e}), e.disposeIntermediateTensorInfo(m);
}
if (p) {
var m = f;
f = Fd(e, f, p, o), e.disposeIntermediateTensorInfo(m);
}
return f;
}
var q9 = {kernelName: S.FusedConv2D, backendName: "cpu", kernelFunc: G9};
function Y9(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = t.filter, s = t.bias, o = t.preluActivationWeights, c = r.strides, l = r.pad, u = r.dataFormat, h = r.dilations, d = r.dimRoundingMode, p = r.activation, f = kw({inputs: {x: i, filter: a}, backend: e, attrs: {strides: c, pad: l, dataFormat: u, dilations: h, dimRoundingMode: d}});
if (s) {
var m = f;
f = ts({inputs: {a: f, b: s}, backend: e}), e.disposeIntermediateTensorInfo(m);
}
if (p) {
var m = f;
f = Fd(e, f, p, o), e.disposeIntermediateTensorInfo(m);
}
return f;
}
var K9 = {kernelName: S.FusedDepthwiseConv2D, backendName: "cpu", kernelFunc: Y9};
function j9(n) {
var t = n.inputs, e = n.backend, r = t.input, i = S.util.sizeFromShape(r.shape), a = r.shape[r.shape.length - 1], s = i / a, o = Un({inputs: {x: r}, backend: e, attrs: {shape: [s, a]}}), c = Fw(o, true, e), l = Un({inputs: {x: c}, backend: e, attrs: {shape: r.shape}});
return e.disposeIntermediateTensorInfo(o), e.disposeIntermediateTensorInfo(c), l;
}
var $9 = {kernelName: S.IFFT, backendName: "cpu", kernelFunc: j9};
var X9 = je(S.IsFinite, function(n) {
return Number.isFinite(n) ? 1 : 0;
}, "bool"), J9 = {kernelName: S.IsFinite, backendName: "cpu", kernelFunc: X9};
var Z9 = je(S.IsInf, function(n) {
return Math.abs(n) === Infinity ? 1 : 0;
}, "bool"), Q9 = {kernelName: S.IsInf, backendName: "cpu", kernelFunc: Z9};
var eF = je(S.IsNan, function(n) {
return Number.isNaN(n) ? 1 : 0;
}, "bool"), tF = {kernelName: S.IsNan, backendName: "cpu", kernelFunc: eF};
var nF = je(S.Log1p, function(n) {
return Math.log1p(n);
}), rF = {kernelName: S.Log1p, backendName: "cpu", kernelFunc: nF};
var iF = je(S.LogicalNot, function(n) {
return n ? 0 : 1;
}, "bool"), aF = {kernelName: S.LogicalNot, backendName: "cpu", kernelFunc: iF};
var sF = {kernelName: S.Max, backendName: "cpu", kernelFunc: function(n) {
var t = n.inputs, e = n.attrs, r = n.backend, i = t.x, a = e, s = a.reductionIndices, o = a.keepDims, c = r, l = i.shape, u = l.length, h = S.util.parseAxisParam(s, l), d = h, p = S.backend_util.getAxesPermutation(d, u), f = c.data.get(i.dataId).values;
if (p != null) {
for (var m = new Array(u), g = 0; g < m.length; g++)
m[g] = l[p[g]];
f = kd(f, l, i.dtype, p, m), d = S.backend_util.getInnerMostAxes(d.length, u), l = m;
}
ae(i, "max"), S.backend_util.assertAxesAreInnerMostDims("max", d, u);
var y = S.backend_util.computeOutAndReduceShapes(l, d), w = y[0], b = y[1], x = S.util.sizeFromShape(b), L = yw(f, x, w, i.dtype), N = c.write(L, w, i.dtype), I = w;
if (o) {
var m = S.backend_util.expandShapeToKeepDim(w, h);
I = m;
}
return {dataId: N, shape: I, dtype: i.dtype};
}};
function oF(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x;
ae(i, "maxPool");
var a = r.filterSize, s = r.strides, o = r.pad, c = r.dimRoundingMode, l = 1;
S.util.assert(S.backend_util.eitherStridesOrDilationsAreOne(s, l), function() {
return "Error in maxPool: Either strides or dilations must be 1. " + ("Got strides " + s + " and dilations '" + l + "'");
});
var u = S.backend_util.computePool2DInfo(i.shape, a, s, l, o, c), h;
if (u.filterWidth === 1 && u.filterHeight === 1 && S.util.arraysEqual(u.inShape, u.outShape))
h = di({inputs: {x: i}, backend: e});
else {
var d = e.data.get(i.dataId).values, p = S.util.computeStrides(i.shape), f = Wd(d, i.shape, i.dtype, p, u, "max");
h = e.makeTensorInfo(u.outShape, i.dtype, f.values);
}
return h;
}
var cF = {kernelName: S.MaxPool, backendName: "cpu", kernelFunc: oF};
function lF(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.dy, a = t.input, s = t.output, o = a;
ae([a, s], "maxPoolBackprop");
for (var c = r.filterSize, l = r.strides, u = r.pad, h = r.dimRoundingMode, d = S.backend_util.computePool2DInfo(o.shape, c, l, 1, u, h), p = e.data.get(o.dataId).values, f = S.buffer(d.outShape, o.dtype, Ew(p, o.shape, o.dtype, d).values), m = d.strideHeight, g = d.strideWidth, y = d.dilationHeight, w = d.dilationWidth, b = d.effectiveFilterHeight, x = d.effectiveFilterWidth, L = x - 1 - d.padInfo.left, N = b - 1 - d.padInfo.top, I = S.buffer(o.shape, "float32"), C = e.data.get(i.dataId).values, O = S.buffer(i.shape, "float32", C), D = 0; D < d.batchSize; ++D)
for (var F = 0; F < d.inChannels; ++F)
for (var k = 0; k < d.inHeight; ++k)
for (var B = 0; B < d.inWidth; ++B) {
for (var V = k - N, P = B - L, G = 0, j = 0; j < b; j += y) {
var q = (V + j) / m;
if (q < 0 || q >= d.outHeight || Math.floor(q) !== q)
continue;
for (var H = 0; H < x; H += w) {
var J = (P + H) / g;
if (J < 0 || J >= d.outWidth || Math.floor(J) !== J)
continue;
var $ = b * x - 1 - f.get(D, q, J, F), ee = j * x + H, te = $ === ee ? 1 : 0;
if (te === 0)
continue;
var ne = O.get(D, q, J, F);
G += ne * te;
}
}
I.set(G, D, k, B, F);
}
return e.makeTensorInfo(I.shape, I.dtype, I.values);
}
var uF = {kernelName: S.MaxPoolBackprop, backendName: "cpu", kernelFunc: lF};
function hF(n, t, e, r, i) {
var a = S.util.computeStrides(t), s = Wd(n, t, e, a, i, "max"), o = Ew(n, t, e, i, true, r);
return [s.values, o.values];
}
var dF = {kernelName: S.MaxPoolWithArgmax, backendName: "cpu", kernelFunc: function(n) {
var t = n.inputs, e = n.attrs, r = n.backend, i = t.x, a = e, s = a.filterSize, o = a.strides, c = a.pad, l = a.includeBatchInIndex, u = r;
ae(i, "MaxPoolWithArgmax");
var h = u.data.get(i.dataId).values, d = S.backend_util.computePool2DInfo(i.shape, s, o, [1, 1], c), p = hF(h, i.shape, i.dtype, l, d), f = p[0], m = p[1], g = u.write(f, d.outShape, i.dtype), y = u.write(m, d.outShape, i.dtype);
return [{dataId: g, shape: d.outShape, dtype: i.dtype}, {dataId: y, shape: d.outShape, dtype: "int32"}];
}};
function pF(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = r.paddings, s = r.mode;
ae(i, "mirrorPad");
for (var o = a.map(function(I, C) {
return I[0] + i.shape[C] + I[1];
}), c = a.map(function(I) {
return I[0];
}), l = a.map(function(I, C) {
return I[0] + i.shape[C];
}), u = s === "reflect" ? 0 : 1, h = e.data.get(i.dataId).values, d = i.shape.length, p = S.util.computeStrides(i.shape), f = S.util.sizeFromShape(o), m = o.length, g = S.util.computeStrides(o), y = S.util.getTypedArrayFromDType(i.dtype, f), w = 0; w < f; w++) {
for (var b = S.util.indexToLoc(w, m, g), x = 0; x < m; x++)
b[x] < c[x] ? b[x] = c[x] * 2 - b[x] - u : b[x] >= l[x] && (b[x] = (l[x] - 1) * 2 - b[x] + u);
b = b.map(function(I, C) {
return I - c[C];
});
var L = S.util.locToIndex(b, d, p);
y[w] = h[L];
}
var N = e.write(y, o, i.dtype);
return {dataId: N, shape: o, dtype: i.dtype};
}
var fF = {kernelName: S.MirrorPad, backendName: "cpu", kernelFunc: pF};
var mF = S.kernel_impls.nonMaxSuppressionV4Impl, gF = {kernelName: S.NonMaxSuppressionV4, backendName: "cpu", kernelFunc: function(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t, a = i.boxes, s = i.scores, o = r, c = o.maxOutputSize, l = o.iouThreshold, u = o.scoreThreshold, h = o.padToMaxOutputSize, d = e;
ae(a, "NonMaxSuppressionPadded");
var p = d.data.get(a.dataId).values, f = d.data.get(s.dataId).values, m = mF(p, f, c, l, u, h), g = m.selectedIndices, y = m.validOutputs;
return [g, y];
}};
var yF = S.kernel_impls.nonMaxSuppressionV5Impl, vF = {kernelName: S.NonMaxSuppressionV5, backendName: "cpu", kernelFunc: function(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t, a = i.boxes, s = i.scores, o = r, c = o.maxOutputSize, l = o.iouThreshold, u = o.scoreThreshold, h = o.softNmsSigma, d = e;
ae(a, "NonMaxSuppressionWithScore");
var p = d.data.get(a.dataId).values, f = d.data.get(s.dataId).values, m = c, g = l, y = u, w = h, b = yF(p, f, m, g, y, w), x = b.selectedIndices, L = b.selectedScores;
return [x, L];
}};
function wF(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = r.paddings, s = r.constantValue;
ae(i, "pad");
var o = a.map(function(N, I) {
return N[0] + i.shape[I] + N[1];
}), c = a.map(function(N) {
return N[0];
}), l = e.data.get(i.dataId).values, u = S.util.sizeFromShape(i.shape), h = i.shape.length, d = S.util.computeStrides(i.shape), p = S.util.sizeFromShape(o), f = o.length, m = S.util.computeStrides(o), g = S.util.getTypedArrayFromDType(i.dtype, p);
s !== 0 && g.fill(s);
for (var y = 0; y < u; y++) {
var w = S.util.indexToLoc(y, h, d), b = w.map(function(N, I) {
return N + c[I];
}), x = S.util.locToIndex(b, f, m);
g[x] = l[y];
}
var L = e.write(g, o, i.dtype);
return {dataId: L, shape: o, dtype: i.dtype};
}
var Ww = {kernelName: S.PadV2, backendName: "cpu", kernelFunc: wF};
var bF = je(S.Reciprocal, function(n) {
return 1 / n;
}), xF = {kernelName: S.Reciprocal, backendName: "cpu", kernelFunc: bF};
var LF = {kernelName: S.RotateWithOffset, backendName: "cpu", kernelFunc: function(n) {
for (var t = n.inputs, e = n.attrs, r = n.backend, i = t.image, a = e, s = a.radians, o = a.fillValue, c = a.center, l = r, u = S.util.getTypedArrayFromDType(i.dtype, S.util.sizeFromShape(i.shape)), h = i.shape, d = h[0], p = h[1], f = h[2], m = h[3], g = S.backend_util.getImageCenter(c, p, f), y = g[0], w = g[1], b = 255, x = Math.sin(s), L = Math.cos(s), N = l.data.get(i.dataId).values, I = 0; I < d; I++)
for (var C = I * f * p * m, O = 0; O < p; O++)
for (var D = O * (f * m), F = 0; F < f; F++)
for (var k = F * m, B = 0; B < m; B++) {
var V = [d, O, F, B], P = V[2], G = V[1], j = (P - y) * L - (G - w) * x, q = (P - y) * x + (G - w) * L;
j = Math.round(j + y), q = Math.round(q + w);
var H = o;
if (typeof o != "number" && (B === 3 ? H = b : H = o[B]), j >= 0 && j < f && q >= 0 && q < p) {
var J = q * (f * m), $ = j * m, ee = C + J + $ + B;
H = N[ee];
}
var te = C + D + k + B;
u[te] = H;
}
var ne = l.write(u, i.shape, i.dtype);
return {dataId: ne, shape: i.shape, dtype: i.dtype};
}};
var SF = je(S.Round, function(n) {
var t = Math.floor(n);
return n - t < 0.5 ? Math.floor(n) : n - t > 0.5 ? Math.ceil(n) : t % 2 === 0 ? t : t + 1;
}), IF = {kernelName: S.Round, backendName: "cpu", kernelFunc: SF};
var AF = S.backend_util.SELU_SCALEALPHA, TF = S.backend_util.SELU_SCALE, NF = je(S.Selu, function(n) {
return n >= 0 ? TF * n : AF * (Math.exp(n) - 1);
}), _F = {kernelName: S.Selu, backendName: "cpu", kernelFunc: NF};
var CF = je(S.Sigmoid, function(n) {
return 1 / (1 + Math.exp(-n));
}), RF = {kernelName: S.Sigmoid, backendName: "cpu", kernelFunc: CF};
var OF = je(S.Sign, function(n) {
return n < 0 ? -1 : n > 0 ? 1 : 0;
}), EF = {kernelName: S.Sign, backendName: "cpu", kernelFunc: OF};
var DF = je(S.Sin, function(n) {
return Math.sin(n);
}), kF = {kernelName: S.Sin, backendName: "cpu", kernelFunc: DF};
var FF = je(S.Sinh, function(n) {
return Math.sinh(n);
}), WF = {kernelName: S.Sinh, backendName: "cpu", kernelFunc: FF};
var UF = 11920928955078125e-23, Uw = Math.log(UF) + 2, BF = je(S.Softplus, function(n) {
var t = n > -Uw, e = n < Uw, r = Math.exp(n), i;
return e ? i = r : t ? i = n : i = Math.log(1 + r), i;
}), zF = {kernelName: S.Softplus, backendName: "cpu", kernelFunc: BF};
function Bw(n) {
var t = n.inputs, e = n.attrs, r = n.backend, i = t.x, a = e.perm;
ae(i, "transpose");
for (var s = i.shape.length, o = new Array(s), c = 0; c < o.length; c++)
o[c] = i.shape[a[c]];
var l = r.data.get(i.dataId).values, u = kd(l, i.shape, i.dtype, a, o), h = r.write(u, o, i.dtype);
return {dataId: h, shape: o, dtype: i.dtype};
}
var PF = {kernelName: S.Transpose, backendName: "cpu", kernelFunc: Bw};
function MF(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = r.blockShape, s = r.paddings;
ae([i], "spaceToBatchND");
var o = S.util.sizeFromShape(a), c = [[0, 0]];
c.push.apply(c, s);
for (var l = 1 + a.length; l < i.shape.length; ++l)
c.push([0, 0]);
var u = Ww.kernelFunc({inputs: {x: i}, backend: e, attrs: {paddings: c, constantValue: 0}}), h = S.backend_util.getReshaped(u.shape, a, o, false), d = S.backend_util.getPermuted(h.length, a.length, false), p = S.backend_util.getReshapedPermuted(u.shape, a, o, false), f = {x: u}, m = {shape: h}, g = Un({inputs: f, backend: e, attrs: m}), y = {x: g}, w = {perm: d}, b = Bw({inputs: y, backend: e, attrs: w}), x = {x: b}, L = {shape: p}, N = Un({inputs: x, backend: e, attrs: L});
return e.disposeIntermediateTensorInfo(u), e.disposeIntermediateTensorInfo(g), e.disposeIntermediateTensorInfo(b), N;
}
var HF = {kernelName: S.SpaceToBatchND, backendName: "cpu", kernelFunc: MF};
var VF = je(S.Sqrt, function(n) {
return Math.sqrt(n);
}), GF = {kernelName: S.Sqrt, backendName: "cpu", kernelFunc: VF};
var qF = {kernelName: S.Square, backendName: "cpu", kernelFunc: function(n) {
var t = n.inputs, e = n.backend, r = t.x, i = e;
ae(r, "square");
for (var a = i.data.get(r.dataId).values, s = new Float32Array(a.length), o = 0; o < a.length; ++o) {
var c = a[o];
s[o] = c * c;
}
var l = i.write(s, r.shape, r.dtype);
return {dataId: l, shape: r.shape, dtype: r.dtype};
}};
var YF = je(S.Step, function(n, t) {
var e = t;
return isNaN(n) ? NaN : n > 0 ? 1 : e.alpha;
}), KF = {kernelName: S.Step, backendName: "cpu", kernelFunc: YF};
var jF = je(S.Tan, function(n) {
return Math.tan(n);
}), $F = {kernelName: S.Tan, backendName: "cpu", kernelFunc: jF};
var XF = je(S.Tanh, function(n) {
return Math.tanh(n);
}), JF = {kernelName: S.Tanh, backendName: "cpu", kernelFunc: XF};
function ZF(n) {
var t = n.inputs, e = n.attrs, r = n.backend, i = e.axis, a = t.x;
ae(a, "unique");
var s = r.data.get(a.dataId).values, o = Tw(s, i, a.shape, a.dtype), c = o.outputValues, l = o.outputShape, u = o.indices;
return [r.makeTensorInfo(l, a.dtype, c), r.makeTensorInfo([u.length], "int32", u)];
}
var QF = {kernelName: S.Unique, backendName: "cpu", kernelFunc: ZF};
var eW = [D8, $6, F8, U8, t8, z8, M8, V8, q8, K8, $8, O8, J8, Q6, r8, Q8, X6, t9, i9, s9, n9, u9, d9, c9, f9, g9, y9, w9, x9, L9, I9, S9, Ud, A8, k9, a8, o8, z9, H9, V9, l8, q9, K9, J6, $9, e9, J9, Q9, tF, h8, rF, aF, cF, uF, dF, sF, fF, p8, gF, vF, m8, Ww, N8, Z6, xF, _8, C8, R8, LF, IF, y8, _F, RF, EF, kF, WF, v8, zF, HF, GF, qF, b8, KF, L8, $F, JF, PF, QF];
for (var zd = 0, zw = eW; zd < zw.length; zd++) {
var tW = zw[zd];
S.registerKernel(tW);
}
Za.MathBackendCPU = lw;
Za.shared = S8;
Za.version_cpu = I8;
});
var T2 = we((Bn) => {
"use strict";
Object.defineProperty(Bn, "__esModule", {value: true});
var _ = ei();
var Pd = function(n, t) {
return Pd = Object.setPrototypeOf || {__proto__: []} instanceof Array && function(e, r) {
e.__proto__ = r;
} || function(e, r) {
for (var i in r)
r.hasOwnProperty(i) && (e[i] = r[i]);
}, Pd(n, t);
};
function nW(n, t) {
Pd(n, t);
function e() {
this.constructor = n;
}
n.prototype = t === null ? Object.create(t) : (e.prototype = t.prototype, new e());
}
function zo(n, t, e, r) {
function i(a) {
return a instanceof e ? a : new e(function(s) {
s(a);
});
}
return new (e || (e = Promise))(function(a, s) {
function o(u) {
try {
l(r.next(u));
} catch (h) {
s(h);
}
}
function c(u) {
try {
l(r.throw(u));
} catch (h) {
s(h);
}
}
function l(u) {
u.done ? a(u.value) : i(u.value).then(o, c);
}
l((r = r.apply(n, t || [])).next());
});
}
function Po(n, t) {
var e = {label: 0, sent: function() {
if (a[0] & 1)
throw a[1];
return a[1];
}, trys: [], ops: []}, r, i, a, s;
return s = {next: o(0), throw: o(1), return: o(2)}, typeof Symbol == "function" && (s[Symbol.iterator] = function() {
return this;
}), s;
function o(l) {
return function(u) {
return c([l, u]);
};
}
function c(l) {
if (r)
throw new TypeError("Generator is already executing.");
for (; e; )
try {
if (r = 1, i && (a = l[0] & 2 ? i.return : l[0] ? i.throw || ((a = i.return) && a.call(i), 0) : i.next) && !(a = a.call(i, l[1])).done)
return a;
(i = 0, a) && (l = [l[0] & 2, a.value]);
switch (l[0]) {
case 0:
case 1:
a = l;
break;
case 4:
return e.label++, {value: l[1], done: false};
case 5:
e.label++, i = l[1], l = [0];
continue;
case 7:
l = e.ops.pop(), e.trys.pop();
continue;
default:
if (!(a = e.trys, a = a.length > 0 && a[a.length - 1]) && (l[0] === 6 || l[0] === 2)) {
e = 0;
continue;
}
if (l[0] === 3 && (!a || l[1] > a[0] && l[1] < a[3])) {
e.label = l[1];
break;
}
if (l[0] === 6 && e.label < a[1]) {
e.label = a[1], a = l;
break;
}
if (a && e.label < a[2]) {
e.label = a[2], e.ops.push(l);
break;
}
a[2] && e.ops.pop(), e.trys.pop();
continue;
}
l = t.call(n, e);
} catch (u) {
l = [6, u], i = 0;
} finally {
r = a = 0;
}
if (l[0] & 5)
throw l[1];
return {value: l[0] ? l[1] : void 0, done: true};
}
}
var pi = {}, Md = {alpha: false, antialias: false, premultipliedAlpha: false, preserveDrawingBuffer: false, depth: false, stencil: false, failIfMajorPerformanceCaveat: true};
function Mw(n, t) {
pi[n] = t;
}
function zn(n) {
if (!(n in pi)) {
var t = rW(n);
if (t !== null)
pi[n] = t;
else
return console.log("Could not get context for WebGL version", n), null;
}
var e = pi[n];
return e.isContextLost() ? (delete pi[n], zn(n)) : (e.disable(e.DEPTH_TEST), e.disable(e.STENCIL_TEST), e.disable(e.BLEND), e.disable(e.DITHER), e.disable(e.POLYGON_OFFSET_FILL), e.disable(e.SAMPLE_COVERAGE), e.enable(e.SCISSOR_TEST), e.enable(e.CULL_FACE), e.cullFace(e.BACK), pi[n]);
}
function iW(n) {
if (typeof OffscreenCanvas != "undefined" && n === 2)
return new OffscreenCanvas(300, 150);
if (typeof document != "undefined")
return document.createElement("canvas");
throw new Error("Cannot create a canvas in this context");
}
function rW(n) {
if (n !== 1 && n !== 2)
throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");
var t = iW(n);
return t.addEventListener("webglcontextlost", function(e) {
e.preventDefault(), delete pi[n];
}, false), n === 1 ? t.getContext("webgl", Md) || t.getContext("experimental-webgl", Md) : t.getContext("webgl2", Md);
}
var rs;
(function(n) {
n[n.DENSE = 0] = "DENSE", n[n.SHARED_BATCH = 1] = "SHARED_BATCH";
})(rs || (rs = {}));
var cn;
(function(n) {
n[n.RENDER = 0] = "RENDER", n[n.UPLOAD = 1] = "UPLOAD", n[n.PIXELS = 2] = "PIXELS", n[n.DOWNLOAD = 3] = "DOWNLOAD";
})(cn || (cn = {}));
var Dt;
(function(n) {
n[n.UNPACKED_FLOAT16 = 0] = "UNPACKED_FLOAT16", n[n.UNPACKED_FLOAT32 = 1] = "UNPACKED_FLOAT32", n[n.PACKED_4X1_UNSIGNED_BYTE = 2] = "PACKED_4X1_UNSIGNED_BYTE", n[n.PACKED_2X2_FLOAT32 = 3] = "PACKED_2X2_FLOAT32", n[n.PACKED_2X2_FLOAT16 = 4] = "PACKED_2X2_FLOAT16";
})(Dt || (Dt = {}));
function is(n, t) {
return [t, n];
}
function aW(n, t) {
return n * t;
}
function as(n) {
var t = _.util.sizeFromShape(n), e = Math.ceil(t / 4);
return _.util.sizeToSquarishShape(e);
}
function ta(n, t) {
return [Math.max(1, Math.ceil(t / 2)), Math.max(1, Math.ceil(n / 2))];
}
function sW(n, t) {
var e = ta(n, t), r = e[0], i = e[1];
return r * i * 4;
}
function Hd(n, t) {
var e = n, r, i, a, s, o, c, l, u, h, d;
return _.env().getNumber("WEBGL_VERSION") === 2 ? (r = e.R32F, i = e.R16F, a = e.RGBA16F, s = e.RGBA32F, o = e.RED, l = 4, u = 1, h = e.HALF_FLOAT, d = e.FLOAT) : (r = n.RGBA, i = n.RGBA, a = n.RGBA, s = e.RGBA, o = n.RGBA, l = 4, u = 4, h = t != null ? t.HALF_FLOAT_OES : null, d = n.FLOAT), c = n.RGBA, {internalFormatFloat: r, internalFormatHalfFloat: i, internalFormatPackedHalfFloat: a, internalFormatPackedFloat: s, textureFormatFloat: o, downloadTextureFormat: c, downloadUnpackNumChannels: l, defaultNumChannels: u, textureTypeHalfFloat: h, textureTypeFloat: d};
}
function de(n, t) {
var e = t();
return _.env().getBool("DEBUG") && oW(n), e;
}
function oW(n) {
var t = n.getError();
if (t !== n.NO_ERROR)
throw new Error("WebGL Error: " + Hw(n, t));
}
var cW = 596e-10, lW = 65504;
function Vw(n) {
return !!(_.env().getBool("WEBGL_RENDER_FLOAT32_ENABLED") || n === 0 || cW < Math.abs(n) && Math.abs(n) < lW);
}
function Hw(n, t) {
switch (t) {
case n.NO_ERROR:
return "NO_ERROR";
case n.INVALID_ENUM:
return "INVALID_ENUM";
case n.INVALID_VALUE:
return "INVALID_VALUE";
case n.INVALID_OPERATION:
return "INVALID_OPERATION";
case n.INVALID_FRAMEBUFFER_OPERATION:
return "INVALID_FRAMEBUFFER_OPERATION";
case n.OUT_OF_MEMORY:
return "OUT_OF_MEMORY";
case n.CONTEXT_LOST_WEBGL:
return "CONTEXT_LOST_WEBGL";
default:
return "Unknown error code " + t;
}
}
function ss(n, t) {
return nr(n, function() {
return n.getExtension(t);
}, 'Extension "' + t + '" not supported on this browser.');
}
function Gw(n, t) {
var e = nr(n, function() {
return n.createShader(n.VERTEX_SHADER);
}, "Unable to create vertex WebGLShader.");
if (de(n, function() {
return n.shaderSource(e, t);
}), de(n, function() {
return n.compileShader(e);
}), n.getShaderParameter(e, n.COMPILE_STATUS) === false)
throw console.log(n.getShaderInfoLog(e)), new Error("Failed to compile vertex shader.");
return e;
}
function qw(n, t) {
var e = nr(n, function() {
return n.createShader(n.FRAGMENT_SHADER);
}, "Unable to create fragment WebGLShader.");
if (de(n, function() {
return n.shaderSource(e, t);
}), de(n, function() {
return n.compileShader(e);
}), n.getShaderParameter(e, n.COMPILE_STATUS) === false)
throw uW(t, n.getShaderInfoLog(e)), new Error("Failed to compile fragment shader.");
return e;
}
var hW = /ERROR: [0-9]+:([0-9]+):/g;
function uW(n, t) {
var e = hW.exec(t);
if (e == null) {
console.log("Couldn't parse line number in error: " + t), console.log(n);
return;
}
for (var r = +e[1], i = n.split(`
`), a = i.length.toString().length + 2, s = i.map(function(d, p) {
return _.util.rightPad((p + 1).toString(), a) + d;
}), o = 0, c = 0; c < s.length; c++)
o = Math.max(s[c].length, o);
var l = s.slice(0, r - 1), u = s.slice(r - 1, r), h = s.slice(r);
console.log(l.join(`
`)), console.log(t.split(`
`)[0]), console.log("%c " + _.util.rightPad(u[0], o), "border:1px solid red; background-color:#e3d2d2; color:#a61717"), console.log(h.join(`
`));
}
function Yw(n) {
return nr(n, function() {
return n.createProgram();
}, "Unable to create WebGLProgram.");
}
function Kw(n, t) {
if (de(n, function() {
return n.linkProgram(t);
}), n.getProgramParameter(t, n.LINK_STATUS) === false)
throw console.log(n.getProgramInfoLog(t)), new Error("Failed to link vertex and fragment shaders.");
}
function Mo(n, t) {
if (de(n, function() {
return n.validateProgram(t);
}), n.getProgramParameter(t, n.VALIDATE_STATUS) === false)
throw console.log(n.getProgramInfoLog(t)), new Error("Shader program validation failed.");
}
function jw(n, t) {
var e = nr(n, function() {
return n.createBuffer();
}, "Unable to create WebGLBuffer");
return de(n, function() {
return n.bindBuffer(n.ARRAY_BUFFER, e);
}), de(n, function() {
return n.bufferData(n.ARRAY_BUFFER, t, n.STATIC_DRAW);
}), e;
}
function $w(n, t) {
var e = nr(n, function() {
return n.createBuffer();
}, "Unable to create WebGLBuffer");
return de(n, function() {
return n.bindBuffer(n.ELEMENT_ARRAY_BUFFER, e);
}), de(n, function() {
return n.bufferData(n.ELEMENT_ARRAY_BUFFER, t, n.STATIC_DRAW);
}), e;
}
function dW() {
return _.env().getNumber("WEBGL_VERSION") === 2 ? 1 : 4;
}
function Xw(n) {
return nr(n, function() {
return n.createTexture();
}, "Unable to create WebGLTexture.");
}
function Jw(n, t) {
var e = _.env().getNumber("WEBGL_MAX_TEXTURE_SIZE");
if (n <= 0 || t <= 0) {
var r = "[" + n + "x" + t + "]";
throw new Error("Requested texture size " + r + " is invalid.");
}
if (n > e || t > e) {
var r = "[" + n + "x" + t + "]", i = "[" + e + "x" + e + "]";
throw new Error("Requested texture size " + r + " greater than WebGL maximum on this browser / GPU " + i + ".");
}
}
function Zw(n) {
return nr(n, function() {
return n.createFramebuffer();
}, "Unable to create WebGLFramebuffer.");
}
function Vd(n, t, e, r, i, a, s) {
var o = n.getAttribLocation(t, e);
return o === -1 ? false : (de(n, function() {
return n.bindBuffer(n.ARRAY_BUFFER, r);
}), de(n, function() {
return n.vertexAttribPointer(o, i, n.FLOAT, false, a, s);
}), de(n, function() {
return n.enableVertexAttribArray(o);
}), true);
}
function eb(n, t, e) {
Qw(n, e), de(n, function() {
return n.activeTexture(n.TEXTURE0 + e);
}), de(n, function() {
return n.bindTexture(n.TEXTURE_2D, t);
});
}
function pW(n, t) {
Qw(n, t), de(n, function() {
return n.activeTexture(n.TEXTURE0 + t);
}), de(n, function() {
return n.bindTexture(n.TEXTURE_2D, null);
});
}
function tb(n, t, e) {
return nr(n, function() {
return n.getUniformLocation(t, e);
}, 'uniform "' + e + '" not present in program.');
}
function nb(n, t, e) {
return n.getUniformLocation(t, e);
}
function rb(n, t, e, r) {
de(n, function() {
return eb(n, t, r);
}), de(n, function() {
return n.uniform1i(e, r);
});
}
function fW(n) {
de(n, function() {
return n.bindFramebuffer(n.FRAMEBUFFER, null);
}), de(n, function() {
return n.viewport(0, 0, n.canvas.width, n.canvas.height);
}), de(n, function() {
return n.scissor(0, 0, n.canvas.width, n.canvas.height);
});
}
function Ho(n, t, e) {
de(n, function() {
return n.bindFramebuffer(n.FRAMEBUFFER, e);
}), de(n, function() {
return n.framebufferTexture2D(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.TEXTURE_2D, t, 0);
});
}
function Gd(n, t) {
de(n, function() {
return n.bindFramebuffer(n.FRAMEBUFFER, t);
}), de(n, function() {
return n.framebufferTexture2D(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.TEXTURE_2D, null, 0);
});
}
function os(n) {
var t = n.checkFramebufferStatus(n.FRAMEBUFFER);
if (t !== n.FRAMEBUFFER_COMPLETE)
throw new Error("Error binding framebuffer: " + ib(n, t));
}
function ib(n, t) {
switch (t) {
case n.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
return "FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
case n.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
return "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
case n.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
return "FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
case n.FRAMEBUFFER_UNSUPPORTED:
return "FRAMEBUFFER_UNSUPPORTED";
default:
return "unknown error " + t;
}
}
function nr(n, t, e) {
var r = de(n, function() {
return t();
});
if (r == null)
throw new Error(e);
return r;
}
function Qw(n, t) {
var e = n.MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1, r = t + n.TEXTURE0;
if (r < n.TEXTURE0 || r > e) {
var i = "[gl.TEXTURE0, gl.TEXTURE" + e + "]";
throw new Error("textureUnit must be in " + i + ".");
}
}
function fi(n, t) {
return t === void 0 && (t = 2), _.util.sizeFromShape(n.slice(0, n.length - t));
}
function mi(n) {
if (n.length === 0)
throw Error("Cannot get rows and columns of an empty shape array.");
return [n.length > 1 ? n[n.length - 2] : 1, n[n.length - 1]];
}
function Vo(n) {
var t = [1, 1, 1], e = n.length === 0 || n.length === 1 && n[0] === 1;
return e || (t = [fi(n)].concat(mi(n))), t;
}
function ab(n, t) {
var e;
t === void 0 && (t = false);
var r = _.env().getNumber("WEBGL_MAX_TEXTURE_SIZE");
if (t && (r = r * 2, n = n.map(function(l, u) {
return u >= n.length - 2 ? _.util.nearestLargerEven(n[u]) : n[u];
}), n.length === 1 && (n = [2, n[0]])), n.length !== 2) {
var i = _.util.squeezeShape(n);
n = i.newShape;
}
var a = _.util.sizeFromShape(n);
if (n.length <= 1 && a <= r)
return [1, a];
if (n.length === 2 && n[0] <= r && n[1] <= r)
return n;
if (n.length === 3 && n[0] * n[1] <= r && n[2] <= r)
return [n[0] * n[1], n[2]];
if (n.length === 3 && n[0] <= r && n[1] * n[2] <= r)
return [n[0], n[1] * n[2]];
if (n.length === 4 && n[0] * n[1] * n[2] <= r && n[3] <= r)
return [n[0] * n[1] * n[2], n[3]];
if (n.length === 4 && n[0] <= r && n[1] * n[2] * n[3] <= r)
return [n[0], n[1] * n[2] * n[3]];
if (t) {
var s = fi(n), o = 2, c = 2;
return n.length && (e = mi(n), o = e[0], c = e[1]), a = s * (o / 2) * (c / 2), _.util.sizeToSquarishShape(a).map(function(l) {
return l * 2;
});
}
return _.util.sizeToSquarishShape(a);
}
function Go(n) {
return n % 2 === 0;
}
function cs(n, t) {
if (n = n.slice(-2), t = t.slice(-2), _.util.arraysEqual(n, t))
return true;
if (!n.length || !t.length)
return true;
if (n[0] === 0 || n[1] === 0 || t[0] === 0 || t[1] === 0)
return true;
if (n.length !== t.length) {
var e = n.slice(-1)[0], r = t.slice(-1)[0];
if (e === r)
return true;
if (Go(e) && Go(r) && (n[0] === 1 || t[0] === 1))
return true;
}
return n[1] === t[1] && Go(n[0]) && Go(t[0]);
}
var qo, Yo;
function sb(n) {
if (qo == null) {
var t = zn(n);
qo = t.getParameter(t.MAX_TEXTURE_SIZE);
}
return qo;
}
function mW() {
qo = null;
}
function gW() {
Yo = null;
}
function ob(n) {
if (Yo == null) {
var t = zn(n);
Yo = t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);
}
return Math.min(16, Yo);
}
function cb(n) {
if (n === 0)
return 0;
var t, e = zn(n);
return ln(e, "EXT_disjoint_timer_query_webgl2") && n === 2 ? t = 2 : ln(e, "EXT_disjoint_timer_query") ? t = 1 : t = 0, t;
}
function ln(n, t) {
var e = n.getExtension(t);
return e != null;
}
function qd(n) {
try {
var t = zn(n);
if (t != null)
return true;
} catch (e) {
return console.log("Error when getting WebGL context: ", e), false;
}
return false;
}
function lb(n) {
if (n === 0)
return false;
var t = zn(n);
if (n === 1) {
if (!ln(t, "OES_texture_float"))
return false;
} else if (!ln(t, "EXT_color_buffer_float"))
return false;
var e = Yd(t);
return e;
}
function ub(n) {
if (n === 0)
return false;
var t = zn(n);
if (n === 1) {
if (!ln(t, "OES_texture_float"))
return false;
if (!ln(t, "WEBGL_color_buffer_float"))
return false;
} else {
if (ln(t, "EXT_color_buffer_float"))
return Yd(t);
var e = "EXT_color_buffer_half_float";
if (ln(t, e)) {
var r = t.getExtension(e);
return yW(t, r);
}
return false;
}
var i = Yd(t);
return i;
}
function Yd(n) {
var t = Hd(n), e = n.createTexture();
n.bindTexture(n.TEXTURE_2D, e);
var r = 1, i = 1;
n.texImage2D(n.TEXTURE_2D, 0, t.internalFormatFloat, r, i, 0, t.textureFormatFloat, t.textureTypeFloat, null);
var a = n.createFramebuffer();
n.bindFramebuffer(n.FRAMEBUFFER, a), n.framebufferTexture2D(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.TEXTURE_2D, e, 0);
var s = n.checkFramebufferStatus(n.FRAMEBUFFER) === n.FRAMEBUFFER_COMPLETE;
return n.bindTexture(n.TEXTURE_2D, null), n.bindFramebuffer(n.FRAMEBUFFER, null), n.deleteTexture(e), n.deleteFramebuffer(a), s;
}
function yW(n, t) {
var e = Hd(n, t), r = n.createTexture();
n.bindTexture(n.TEXTURE_2D, r);
var i = 1, a = 1;
n.texImage2D(n.TEXTURE_2D, 0, e.internalFormatHalfFloat, i, a, 0, e.textureFormatFloat, e.textureTypeHalfFloat, null);
var s = n.createFramebuffer();
n.bindFramebuffer(n.FRAMEBUFFER, s), n.framebufferTexture2D(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.TEXTURE_2D, r, 0);
var o = n.checkFramebufferStatus(n.FRAMEBUFFER) === n.FRAMEBUFFER_COMPLETE;
return n.bindTexture(n.TEXTURE_2D, null), n.bindFramebuffer(n.FRAMEBUFFER, null), n.deleteTexture(r), n.deleteFramebuffer(s), o;
}
function hb(n) {
if (n !== 2)
return false;
var t = zn(n), e = t.fenceSync != null;
return e;
}
function na(n, t) {
Array.isArray(n) || (n = [n]), n.forEach(function(e) {
e != null && _.util.assert(e.dtype !== "complex64", function() {
return t + " does not support complex64 tensors in the WebGL backend.";
});
});
}
var vW = {__proto__: null, callAndCheck: de, canBeRepresented: Vw, getWebGLErrorMessage: Hw, getExtensionOrThrow: ss, createVertexShader: Gw, createFragmentShader: qw, createProgram: Yw, linkProgram: Kw, validateProgram: Mo, createStaticVertexBuffer: jw, createStaticIndexBuffer: $w, getNumChannels: dW, createTexture: Xw, validateTextureSize: Jw, createFramebuffer: Zw, bindVertexBufferToProgramAttribute: Vd, bindTextureUnit: eb, unbindTextureUnit: pW, getProgramUniformLocationOrThrow: tb, getProgramUniformLocation: nb, bindTextureToProgramUniformSampler: rb, bindCanvasToFramebuffer: fW, bindColorTextureToFramebuffer: Ho, unbindColorTextureFromFramebuffer: Gd, validateFramebuffer: os, getFramebufferErrorMessage: ib, getBatchDim: fi, getRowsCols: mi, getShapeAs3D: Vo, getTextureShapeFromLogicalShape: ab, isReshapeFree: cs, getWebGLMaxTextureSize: sb, resetMaxTextureSize: mW, resetMaxTexturesInShader: gW, getMaxTexturesInShader: ob, getWebGLDisjointQueryTimerVersion: cb, hasExtension: ln, isWebGLVersionEnabled: qd, isCapableOfRenderingToFloatTexture: lb, isDownloadFloatTextureEnabled: ub, isWebGLFenceEnabled: hb, assertNotComplex: na};
var Se = _.env();
Se.registerFlag("HAS_WEBGL", function() {
return Se.getNumber("WEBGL_VERSION") > 0;
});
Se.registerFlag("WEBGL_VERSION", function() {
return qd(2) ? 2 : qd(1) ? 1 : 0;
});
Se.registerFlag("WEBGL_CHECK_NUMERICAL_PROBLEMS", function() {
return false;
});
Se.registerFlag("WEBGL_BUFFER_SUPPORTED", function() {
return Se.get("WEBGL_VERSION") === 2;
});
Se.registerFlag("WEBGL_CPU_FORWARD", function() {
return true;
});
Se.registerFlag("WEBGL_FORCE_F16_TEXTURES", function() {
return false;
});
Se.registerFlag("WEBGL_PACK", function() {
return Se.getBool("HAS_WEBGL");
});
Se.registerFlag("WEBGL_PACK_NORMALIZATION", function() {
return Se.getBool("WEBGL_PACK");
});
Se.registerFlag("WEBGL_PACK_CLIP", function() {
return Se.getBool("WEBGL_PACK");
});
Se.registerFlag("WEBGL_PACK_DEPTHWISECONV", function() {
return false;
});
Se.registerFlag("WEBGL_PACK_BINARY_OPERATIONS", function() {
return Se.getBool("WEBGL_PACK");
});
Se.registerFlag("WEBGL_PACK_UNARY_OPERATIONS", function() {
return Se.getBool("WEBGL_PACK");
});
Se.registerFlag("WEBGL_PACK_ARRAY_OPERATIONS", function() {
return Se.getBool("WEBGL_PACK");
});
Se.registerFlag("WEBGL_PACK_IMAGE_OPERATIONS", function() {
return Se.getBool("WEBGL_PACK");
});
Se.registerFlag("WEBGL_PACK_REDUCE", function() {
return Se.getBool("WEBGL_PACK");
});
Se.registerFlag("WEBGL_LAZILY_UNPACK", function() {
return Se.getBool("WEBGL_PACK");
});
Se.registerFlag("WEBGL_CONV_IM2COL", function() {
return Se.getBool("WEBGL_PACK");
});
Se.registerFlag("WEBGL_MAX_TEXTURE_SIZE", function() {
return sb(Se.getNumber("WEBGL_VERSION"));
});
Se.registerFlag("WEBGL_MAX_TEXTURES_IN_SHADER", function() {
return ob(Se.getNumber("WEBGL_VERSION"));
});
Se.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION", function() {
var n = Se.getNumber("WEBGL_VERSION");
return n === 0 ? 0 : cb(n);
});
Se.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE", function() {
return Se.getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") > 0 && !_.device_util.isMobile();
});
Se.registerFlag("WEBGL_RENDER_FLOAT32_CAPABLE", function() {
return lb(Se.getNumber("WEBGL_VERSION"));
});
Se.registerFlag("WEBGL_RENDER_FLOAT32_ENABLED", function() {
return Se.getBool("WEBGL_FORCE_F16_TEXTURES") ? false : Se.getBool("WEBGL_RENDER_FLOAT32_CAPABLE");
});
Se.registerFlag("WEBGL_DOWNLOAD_FLOAT_ENABLED", function() {
return ub(Se.getNumber("WEBGL_VERSION"));
});
Se.registerFlag("WEBGL_FENCE_API_ENABLED", function() {
return hb(Se.getNumber("WEBGL_VERSION"));
});
Se.registerFlag("WEBGL_SIZE_UPLOAD_UNIFORM", function() {
var n = Se.getBool("WEBGL_RENDER_FLOAT32_ENABLED");
return n ? 4 : 0;
});
Se.registerFlag("WEBGL_DELETE_TEXTURE_THRESHOLD", function() {
return -1;
}, function(n) {
if (n < 0 && n !== -1)
throw new Error("WEBGL_DELETE_TEXTURE_THRESHOLD must be -1 (indicating never " + ("delete) or at least 0, but got " + n + "."));
});
function wW(n) {
const t = new Float32Array(n.length);
for (let e = 0; e < n.length; ++e)
t[e] = Math.abs(n[e]);
return t;
}
function Kd(n) {
return (t, e, r, i, a) => {
const s = _.backend_util.assertAndGetBroadcastShape(t, e), o = s.length, c = _.util.computeStrides(s), l = _.util.sizeFromShape(s), u = _.util.getTypedArrayFromDType(a, l), h = t.length, d = e.length, p = _.util.computeStrides(t), f = _.util.computeStrides(e), m = _.backend_util.getBroadcastDims(t, s), g = _.backend_util.getBroadcastDims(e, s);
if (m.length + g.length === 0)
for (let y = 0; y < u.length; ++y)
u[y] = n(r[y % r.length], i[y % i.length]);
else
for (let y = 0; y < u.length; ++y) {
const w = _.util.indexToLoc(y, o, c), b = w.slice(-h);
m.forEach((I) => b[I] = 0);
const x = _.util.locToIndex(b, h, p), L = w.slice(-d);
g.forEach((I) => L[I] = 0);
const N = _.util.locToIndex(L, d, f);
u[y] = n(r[x], i[N]);
}
return [u, s];
};
}
const bW = Kd((n, t) => n + t);
function ra(n) {
return (t, e, r) => {
const i = _.util.getTypedArrayFromDType(e, t.length);
for (let a = 0; a < t.length; ++a)
i[a] = n(t[a], r);
return i;
};
}
const xW = ra((n) => Math.ceil(n));
const LW = ra((n) => Math.exp(n));
const SW = ra((n) => Math.expm1(n));
const IW = ra((n) => Math.floor(n));
const AW = ra((n) => Math.log(n));
function TW(n, t, e, r) {
const i = _.util.getTypedArrayFromDType(r, _.util.sizeFromShape(e));
for (let a = 0; a < i.length; ++a) {
const s = a * t;
let o = n[s];
for (let c = 0; c < t; ++c) {
const l = n[s + c];
l > o && (o = l);
}
i[a] = o;
}
return i;
}
const NW = Kd((n, t) => n * t);
const _W = ra((n) => 1 / Math.sqrt(n));
function CW(n, t, e, r, i) {
const a = _.slice_util.isSliceContinous(r, t, e), s = _.util.sizeFromShape(e), o = _.util.computeStrides(r);
if (a) {
const l = _.slice_util.computeFlatOffset(t, o);
return n.subarray(l, l + s);
}
const c = _.util.getTypedArrayFromDType(i, s);
for (let l = 0; l < s; ++l) {
const u = e.length, h = _.util.computeStrides(e), d = _.util.indexToLoc(l, u, h), p = d.map((m, g) => m + t[g]), f = _.util.locToIndex(p, r.length, o);
c[l] = n[f];
}
return c;
}
const RW = Kd((n, t) => n - t);
function OW(n, t, e, r, i) {
const a = t.length, s = _.util.sizeFromShape(t), o = _.util.computeStrides(t), c = _.util.computeStrides(i), l = _.util.getTypedArrayFromDType(e, _.util.sizeFromShape(i));
for (let u = 0; u < s; ++u) {
const h = _.util.indexToLoc(u, a, o), d = new Array(h.length);
for (let f = 0; f < d.length; f++)
d[f] = h[r[f]];
const p = _.util.locToIndex(d, a, c);
l[p] = n[u];
}
return l;
}
function EW(n, t, e, r) {
const i = _.util.parseAxisParam(t, e)[0], a = [1, e[0], 1];
for (let f = 0; f < i; f++)
a[0] *= e[f];
a[1] = e[i];
for (let f = i + 1; f < e.length; f++)
a[2] *= e[f];
const s = {}, o = new Int32Array(e[i]), c = new _.TensorBuffer(a, r, n), l = [], u = a[0] === 1 && a[2] === 1;
for (let f = 0; f < e[i]; f++) {
let m;
if (u)
m = n[f].toString();
else {
const g = [];
for (let y = 0; y < a[0]; y++)
for (let w = 0; w < a[2]; w++)
g.push(c.get(y, f, w));
m = g.join(",");
}
if (s[m] !== void 0)
o[f] = s[m];
else {
const g = Object.keys(s).length;
s[m] = g, o[f] = g, l.push(f);
}
}
const h = a.slice();
h[1] = Object.keys(s).length;
const d = new _.TensorBuffer(h, r);
l.forEach((f, m) => {
for (let g = 0; g < a[0]; g++)
for (let y = 0; y < a[2]; y++)
d.set(c.get(g, f, y), g, m, y);
});
const p = e.slice();
return p[i] = h[1], {outputValues: d.values, outputShape: p, indices: o};
}
var DW = wW, kW = bW, FW = xW, WW = LW, UW = SW, BW = IW, zW = AW, PW = TW, MW = NW, HW = _W, VW = CW, GW = RW, jd = OW, qW = EW;
var YW = function() {
function n(t, e) {
this.outputShape = [], this.outputShape = t, this.variableNames = e.map(function(a, s) {
return "T" + s;
});
var r = [];
this.variableNames.forEach(function(a) {
r.push("float v" + a + " = get" + a + "AtOutCoords();");
});
var i = this.variableNames.map(function(a) {
return "v" + a;
}).join(" + ");
this.userCode = `
void main() {
` + r.join(`
`) + `
float result = ` + i + `;
setOutput(result);
}
`;
}
return n;
}();
var KW = function() {
function n(t, e) {
this.outputShape = [], this.packedInputs = true, this.packedOutput = true, this.outputShape = t, this.variableNames = e.map(function(a, s) {
return "T" + s;
});
var r = [];
this.variableNames.forEach(function(a) {
r.push("vec4 v" + a + " = get" + a + "AtOutCoords();");
});
var i = this.variableNames.map(function(a) {
return "v" + a;
}).join(" + ");
this.userCode = `
void main() {
` + r.join(`
`) + `
vec4 result = ` + i + `;
setOutput(result);
}
`;
}
return n;
}();
var jW = function() {
function n(t, e, r) {
this.variableNames = ["A"];
var i = t.windowSize, a = t.batchSize, s = t.outSize;
r || this.variableNames.push("bestIndicesA"), this.outputShape = [a, s];
var o = e === "max" ? ">" : "<", c = r ? "inOffset + i;" : "round(getBestIndicesA(batch, inOffset + i));";
this.userCode = `
void main() {
ivec2 coords = getOutputCoords();
int batch = coords[0];
int outIdx = coords[1];
int inOffset = outIdx * ` + i + `;
int bestIndex = inOffset;
float bestValue = getA(batch, bestIndex);
for (int i = 0; i < ` + i + `; i++) {
int inIdx = ` + c + `;
float candidate = getA(batch, inIdx);
if (candidate ` + o + ` bestValue) {
bestValue = candidate;
bestIndex = inIdx;
}
}
setOutput(float(bestIndex));
}
`;
}
return n;
}();
function db(n, t) {
return ["x", "y", "z", "w", "u", "v"].slice(0, t).map(function(e) {
return n + "." + e;
});
}
function Ut(n, t) {
return t === 1 ? [n] : db(n, t);
}
function $W(n, t) {
if (n === 1)
return "rc";
for (var e = "", r = 0; r < n; r++)
e += t[r], r < n - 1 && (e += ",");
return e;
}
function Bt() {
var n, t, e, r, i, a, s, o, c, l;
return _.env().getNumber("WEBGL_VERSION") === 2 ? (n = "#version 300 es", t = "in", e = "out", r = "in", i = "texture", a = "outputColor", s = "out vec4 outputColor;", o = `
bool isnan_custom(float val) {
return (val > 0.0 || val < 0.0) ? false : val != 0.0;
}
bvec4 isnan_custom(vec4 val) {
return bvec4(isnan_custom(val.x),
isnan_custom(val.y), isnan_custom(val.z), isnan_custom(val.w));
}
#define isnan(value) isnan_custom(value)
`, c = "", l = `
#define round(value) newRound(value)
int newRound(float value) {
return int(floor(value + 0.5));
}
ivec4 newRound(vec4 value) {
return ivec4(floor(value + vec4(0.5)));
}
`) : (n = "", t = "attribute", e = "varying", r = "varying", i = "texture2D", a = "gl_FragColor", s = "", o = `
#define isnan(value) isnan_custom(value)
bool isnan_custom(float val) {
return (val > 0. || val < 1. || val == 0.) ? false : true;
}
bvec4 isnan_custom(vec4 val) {
return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));
}
`, c = `
uniform float INFINITY;
bool isinf(float val) {
return abs(val) == INFINITY;
}
bvec4 isinf(vec4 val) {
return equal(abs(val), vec4(INFINITY));
}
`, l = `
int round(float value) {
return int(floor(value + 0.5));
}
ivec4 round(vec4 value) {
return ivec4(floor(value + vec4(0.5)));
}
`), {version: n, attribute: t, varyingVs: e, varyingFs: r, texture2D: i, output: a, defineOutput: s, defineSpecialNaN: o, defineSpecialInf: c, defineRound: l};
}
function gi(n, t, e) {
e === void 0 && (e = "index");
var r = _.util.computeStrides(t);
return r.map(function(i, a) {
var s = "int " + n[a] + " = " + e + " / " + i, o = a === r.length - 1 ? "int " + n[a + 1] + " = " + e + " - " + n[a] + " * " + i : "index -= " + n[a] + " * " + i;
return s + "; " + o + ";";
}).join("");
}
function $d(n) {
var t = _.util.computeStrides(n).map(function(e) {
return e.toString();
});
return `
int getFlatIndex(ivec3 coords) {
return coords.x * ` + t[0] + " + coords.y * " + t[1] + ` + coords.z;
}
`;
}
var pb = `
const float FLOAT_MAX = 1.70141184e38;
const float FLOAT_MIN = 1.17549435e-38;
lowp vec4 encode_float(highp float v) {
if (isnan(v)) {
return vec4(255, 255, 255, 255);
}
highp float av = abs(v);
if(av < FLOAT_MIN) {
return vec4(0.0, 0.0, 0.0, 0.0);
} else if(v > FLOAT_MAX) {
return vec4(0.0, 0.0, 128.0, 127.0) / 255.0;
} else if(v < -FLOAT_MAX) {
return vec4(0.0, 0.0, 128.0, 255.0) / 255.0;
}
highp vec4 c = vec4(0,0,0,0);
highp float e = floor(log2(av));
highp float m = exp2(fract(log2(av))) - 1.0;
c[2] = floor(128.0 * m);
m -= c[2] / 128.0;
c[1] = floor(32768.0 * m);
m -= c[1] / 32768.0;
c[0] = floor(8388608.0 * m);
highp float ebias = e + 127.0;
c[3] = floor(ebias / 2.0);
ebias -= c[3] * 2.0;
c[2] += floor(ebias) * 128.0;
c[3] += 128.0 * step(0.0, -v);
return c / 255.0;
}
`;
var fb = _.backend_util.getBroadcastDims;
function iU(n, t, e, r) {
var i = [];
n.forEach(function(f) {
var m = _.util.sizeFromShape(f.shapeInfo.logicalShape);
f.shapeInfo.isUniform ? i.push("uniform float " + f.name + (m > 1 ? "[" + m + "]" : "") + ";") : (i.push("uniform sampler2D " + f.name + ";"), i.push("uniform int offset" + f.name + ";"));
});
var a = i.join(`
`), s = n.map(function(f) {
return XW(f, t, r);
}).join(`
`), o = t.texShape, c = Bt(), l = QW(c), u, h, d = nU(c);
t.isPacked ? (u = JW(t.logicalShape, o), h = tU(c)) : (u = ZW(t.logicalShape, o), h = eU(c)), r && (d += rU);
var p = [d, l, h, a, u, s, e].join(`
`);
return p;
}
function ia(n) {
var t = n.shapeInfo.logicalShape;
switch (t.length) {
case 0:
return aU(n);
case 1:
return sU(n);
case 2:
return oU(n);
case 3:
return cU(n);
case 4:
return lU(n);
case 5:
return uU(n);
case 6:
return hU(n);
default:
throw new Error(t.length + "-D input sampling is not yet supported");
}
}
function mb(n) {
var t = n.shapeInfo.logicalShape;
switch (t.length) {
case 0:
return dU(n);
case 1:
return pU(n);
case 2:
return fU(n);
case 3:
return mU(n);
default:
return gU(n);
}
}
function XW(n, t, e) {
e === void 0 && (e = false);
var r = "";
e ? r += mb(n) : r += ia(n);
var i = n.shapeInfo.logicalShape, a = t.logicalShape;
return i.length <= a.length && (e ? r += yU(n, t) : r += vU(n, t)), r;
}
function JW(n, t) {
switch (n.length) {
case 0:
return gb();
case 1:
return wU(n, t);
case 2:
return LU(n, t);
case 3:
return bU(n, t);
default:
return xU(n, t);
}
}
function ZW(n, t) {
switch (n.length) {
case 0:
return gb();
case 1:
return SU(n, t);
case 2:
return _U(n, t);
case 3:
return IU(n, t);
case 4:
return AU(n, t);
case 5:
return TU(n, t);
case 6:
return NU(n, t);
default:
throw new Error(n.length + "-D output sampling is not yet supported");
}
}
function QW(n) {
return `
float sampleTexture(sampler2D textureSampler, vec2 uv) {
return ` + n.texture2D + `(textureSampler, uv).r;
}
`;
}
function eU(n) {
return `
void setOutput(float val) {
` + n.output + ` = vec4(val, 0, 0, 0);
}
`;
}
function tU(n) {
return `
void setOutput(vec4 val) {
` + n.output + ` = val;
}
`;
}
function nU(n) {
var t = n.version + `
precision highp float;
precision highp int;
precision highp sampler2D;
` + n.varyingFs + ` vec2 resultUV;
` + n.defineOutput + `
const vec2 halfCR = vec2(0.5, 0.5);
struct ivec5
{
int x;
int y;
int z;
int w;
int u;
};
struct ivec6
{
int x;
int y;
int z;
int w;
int u;
int v;
};
uniform float NAN;
` + n.defineSpecialNaN + `
` + n.defineSpecialInf + `
` + n.defineRound + `
int imod(int x, int y) {
return x - y * (x / y);
}
int idiv(int a, int b, float sign) {
int res = a / b;
int mod = imod(a, b);
if (sign < 0. && mod != 0) {
res -= 1;
}
return res;
}
//Based on the work of Dave Hoskins
//https://www.shadertoy.com/view/4djSRW
#define HASHSCALE1 443.8975
float random(float seed){
vec2 p = resultUV * seed;
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE1);
p3 += dot(p3, p3.yzx + 19.19);
return fract((p3.x + p3.y) * p3.z);
}
` + CU + `
` + RU + `
` + OU + `
`;
return t;
}
var CU = `
vec2 uvFromFlat(int texNumR, int texNumC, int index) {
int texR = index / texNumC;
int texC = index - texR * texNumC;
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
}
vec2 packedUVfrom1D(int texNumR, int texNumC, int index) {
int texelIndex = index / 2;
int texR = texelIndex / texNumC;
int texC = texelIndex - texR * texNumC;
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
}
`, RU = `
vec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,
int texNumC, int row, int col) {
int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);
int texR = texelIndex / texNumC;
int texC = texelIndex - texR * texNumC;
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
}
`, OU = `
vec2 packedUVfrom3D(int texNumR, int texNumC,
int texelsInBatch, int texelsInLogicalRow, int b,
int row, int col) {
int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2);
int texR = index / texNumC;
int texC = index - texR * texNumC;
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
}
`, rU = `
float getChannel(vec4 frag, vec2 innerDims) {
vec2 modCoord = mod(innerDims, 2.);
return modCoord.x == 0. ?
(modCoord.y == 0. ? frag.r : frag.g) :
(modCoord.y == 0. ? frag.b : frag.a);
}
float getChannel(vec4 frag, int dim) {
float modCoord = mod(float(dim), 2.);
return modCoord == 0. ? frag.r : frag.g;
}
`;
function gb() {
return `
int getOutputCoords() {
return 0;
}
`;
}
function wU(n, t) {
var e = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)];
return e[0] === 1 ? `
int getOutputCoords() {
return 2 * int(resultUV.x * ` + e[1] + `.0);
}
` : e[1] === 1 ? `
int getOutputCoords() {
return 2 * int(resultUV.y * ` + e[0] + `.0);
}
` : `
int getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(` + e[0] + ", " + e[1] + `));
return 2 * (resTexRC.x * ` + e[1] + ` + resTexRC.y);
}
`;
}
function SU(n, t) {
return t[0] === 1 ? `
int getOutputCoords() {
return int(resultUV.x * ` + t[1] + `.0);
}
` : t[1] === 1 ? `
int getOutputCoords() {
return int(resultUV.y * ` + t[0] + `.0);
}
` : `
int getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(` + t[0] + ", " + t[1] + `));
return resTexRC.x * ` + t[1] + ` + resTexRC.y;
}
`;
}
function bU(n, t) {
var e = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)], r = Math.ceil(n[2] / 2), i = r * Math.ceil(n[1] / 2);
return `
ivec3 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(` + e[0] + ", " + e[1] + `));
int index = resTexRC.x * ` + e[1] + ` + resTexRC.y;
int b = index / ` + i + `;
index -= b * ` + i + `;
int r = 2 * (index / ` + r + `);
int c = imod(index, ` + r + `) * 2;
return ivec3(b, r, c);
}
`;
}
function IU(n, t) {
var e = gi(["r", "c", "d"], n);
return `
ivec3 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(` + t[0] + ", " + t[1] + `));
int index = resTexRC.x * ` + t[1] + ` + resTexRC.y;
` + e + `
return ivec3(r, c, d);
}
`;
}
function xU(n, t) {
for (var e = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)], r = Math.ceil(n[n.length - 1] / 2), i = r * Math.ceil(n[n.length - 2] / 2), a = i, s = "", o = "b, r, c", c = 2; c < n.length - 1; c++)
a *= n[n.length - c - 1], s = `
int b` + c + " = index / " + a + `;
index -= b` + c + " * " + a + `;
` + s, o = "b" + c + ", " + o;
return `
ivec` + n.length + ` getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(` + e[0] + ", " + e[1] + `));
int index = resTexRC.x * ` + e[1] + ` + resTexRC.y;
` + s + `
int b = index / ` + i + `;
index -= b * ` + i + `;
int r = 2 * (index / ` + r + `);
int c = imod(index, ` + r + `) * 2;
return ivec` + n.length + "(" + o + `);
}
`;
}
function AU(n, t) {
var e = gi(["r", "c", "d", "d2"], n);
return `
ivec4 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(` + t[0] + ", " + t[1] + `));
int index = resTexRC.x * ` + t[1] + ` + resTexRC.y;
` + e + `
return ivec4(r, c, d, d2);
}
`;
}
function TU(n, t) {
var e = gi(["r", "c", "d", "d2", "d3"], n);
return `
ivec5 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx * vec2(` + t[0] + `,
` + t[1] + `));
int index = resTexRC.x * ` + t[1] + ` + resTexRC.y;
` + e + `
ivec5 outShape = ivec5(r, c, d, d2, d3);
return outShape;
}
`;
}
function NU(n, t) {
var e = gi(["r", "c", "d", "d2", "d3", "d4"], n);
return `
ivec6 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(` + t[0] + ", " + t[1] + `));
int index = resTexRC.x * ` + t[1] + ` + resTexRC.y;
` + e + `
ivec6 result = ivec6(r, c, d, d2, d3, d4);
return result;
}
`;
}
function LU(n, t) {
var e = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)];
if (_.util.arraysEqual(n, t))
return `
ivec2 getOutputCoords() {
return 2 * ivec2(resultUV.yx * vec2(` + e[0] + ", " + e[1] + `));
}
`;
var r = Math.ceil(n[1] / 2);
return `
ivec2 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(` + e[0] + ", " + e[1] + `));
int index = resTexRC.x * ` + e[1] + ` + resTexRC.y;
int r = 2 * (index / ` + r + `);
int c = imod(index, ` + r + `) * 2;
return ivec2(r, c);
}
`;
}
function _U(n, t) {
return _.util.arraysEqual(n, t) ? `
ivec2 getOutputCoords() {
return ivec2(resultUV.yx * vec2(` + t[0] + ", " + t[1] + `));
}
` : n[1] === 1 ? `
ivec2 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(` + t[0] + ", " + t[1] + `));
int index = resTexRC.x * ` + t[1] + ` + resTexRC.y;
return ivec2(index, 0);
}
` : n[0] === 1 ? `
ivec2 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(` + t[0] + ", " + t[1] + `));
int index = resTexRC.x * ` + t[1] + ` + resTexRC.y;
return ivec2(0, index);
}
` : `
ivec2 getOutputCoords() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(` + t[0] + ", " + t[1] + `));
int index = resTexRC.x * ` + t[1] + ` + resTexRC.y;
int r = index / ` + n[1] + `;
int c = index - r * ` + n[1] + `;
return ivec2(r, c);
}
`;
}
function yi(n) {
return "offset" + n;
}
function dU(n) {
var t = n.name, e = "get" + t.charAt(0).toUpperCase() + t.slice(1), r = Bt();
return `
vec4 ` + e + `() {
return ` + r.texture2D + "(" + t + `, halfCR);
}
`;
}
function aU(n) {
var t = n.name, e = "get" + t.charAt(0).toUpperCase() + t.slice(1);
if (n.shapeInfo.isUniform)
return "float " + e + "() {return " + t + ";}";
var r = n.shapeInfo.texShape, i = r[0], a = r[1];
if (i === 1 && a === 1)
return `
float ` + e + `() {
return sampleTexture(` + t + `, halfCR);
}
`;
var s = n.shapeInfo.texShape, o = s[0], c = s[1], l = yi(t);
return `
float ` + e + `() {
vec2 uv = uvFromFlat(` + o + ", " + c + ", " + l + `);
return sampleTexture(` + t + `, uv);
}
`;
}
function pU(n) {
var t = n.name, e = "get" + t.charAt(0).toUpperCase() + t.slice(1), r = n.shapeInfo.texShape, i = [Math.ceil(r[0] / 2), Math.ceil(r[1] / 2)], a = Bt();
return `
vec4 ` + e + `(int index) {
vec2 uv = packedUVfrom1D(
` + i[0] + ", " + i[1] + `, index);
return ` + a.texture2D + "(" + t + `, uv);
}
`;
}
function sU(n) {
var t = n.name, e = "get" + t.charAt(0).toUpperCase() + t.slice(1);
if (n.shapeInfo.isUniform)
return `
float ` + e + `(int index) {
` + aa(n) + `
}
`;
var r = n.shapeInfo.texShape, i = r[0], a = r[1];
if (a === 1 && i === 1)
return `
float ` + e + `(int index) {
return sampleTexture(` + t + `, halfCR);
}
`;
var s = yi(t);
return a === 1 ? `
float ` + e + `(int index) {
vec2 uv = vec2(0.5, (float(index + ` + s + ") + 0.5) / " + i + `.0);
return sampleTexture(` + t + `, uv);
}
` : i === 1 ? `
float ` + e + `(int index) {
vec2 uv = vec2((float(index + ` + s + ") + 0.5) / " + a + `.0, 0.5);
return sampleTexture(` + t + `, uv);
}
` : `
float ` + e + `(int index) {
vec2 uv = uvFromFlat(` + i + ", " + a + ", index + " + s + `);
return sampleTexture(` + t + `, uv);
}
`;
}
function fU(n) {
var t = n.shapeInfo.logicalShape, e = n.name, r = "get" + e.charAt(0).toUpperCase() + e.slice(1), i = n.shapeInfo.texShape, a = i[0], s = i[1], o = Bt();
if (i != null && _.util.arraysEqual(t, i))
return `
vec4 ` + r + `(int row, int col) {
vec2 uv = (vec2(col, row) + halfCR) / vec2(` + s + ".0, " + a + `.0);
return ` + o.texture2D + "(" + e + `, uv);
}
`;
var c = [Math.ceil(i[0] / 2), Math.ceil(i[1] / 2)], l = Math.ceil(t[1] / 2);
return `
vec4 ` + r + `(int row, int col) {
vec2 uv = packedUVfrom2D(` + l + ", " + c[0] + ", " + c[1] + `, row, col);
return ` + o.texture2D + "(" + e + `, uv);
}
`;
}
function oU(n) {
var t = n.shapeInfo.logicalShape, e = n.name, r = "get" + e.charAt(0).toUpperCase() + e.slice(1), i = n.shapeInfo.texShape;
if (i != null && _.util.arraysEqual(t, i)) {
var a = i[0], s = i[1];
return `
float ` + r + `(int row, int col) {
vec2 uv = (vec2(col, row) + halfCR) / vec2(` + s + ".0, " + a + `.0);
return sampleTexture(` + e + `, uv);
}
`;
}
var o = _.util.squeezeShape(t), c = o.newShape, l = o.keptDims, u = c;
if (u.length < t.length) {
var h = sa(n, u), d = ["row", "col"];
return `
` + ia(h) + `
float ` + r + `(int row, int col) {
return ` + r + "(" + oa(d, l) + `);
}
`;
}
if (n.shapeInfo.isUniform)
return `
float ` + r + `(int row, int col) {
int index = round(dot(vec2(row, col), vec2(` + t[1] + `, 1)));
` + aa(n) + `
}
`;
var p = i[0], f = i[1], m = yi(e);
return f === 1 ? `
float ` + r + `(int row, int col) {
float index = dot(vec3(row, col, ` + m + "), vec3(" + t[1] + `, 1, 1));
vec2 uv = vec2(0.5, (index + 0.5) / ` + p + `.0);
return sampleTexture(` + e + `, uv);
}
` : p === 1 ? `
float ` + r + `(int row, int col) {
float index = dot(vec3(row, col, ` + m + "), vec3(" + t[1] + `, 1, 1));
vec2 uv = vec2((index + 0.5) / ` + f + `.0, 0.5);
return sampleTexture(` + e + `, uv);
}
` : `
float ` + r + `(int row, int col) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * ` + t[1] + " + col + " + m + `;
vec2 uv = uvFromFlat(` + p + ", " + f + `, index);
return sampleTexture(` + e + `, uv);
}
`;
}
function mU(n) {
var t = n.shapeInfo.logicalShape, e = n.name, r = "get" + e.charAt(0).toUpperCase() + e.slice(1), i = n.shapeInfo.texShape, a = [Math.ceil(i[0] / 2), Math.ceil(i[1] / 2)];
if (t[0] === 1) {
var s = t.slice(1), o = [1, 2], c = sa(n, s), l = ["b", "row", "col"];
return `
` + mb(c) + `
vec4 ` + r + `(int b, int row, int col) {
return ` + r + "(" + oa(l, o) + `);
}
`;
}
var u = a[0], h = a[1], d = Math.ceil(t[2] / 2), p = d * Math.ceil(t[1] / 2), f = Bt();
return `
vec4 ` + r + `(int b, int row, int col) {
vec2 uv = packedUVfrom3D(
` + u + ", " + h + ", " + p + ", " + d + `, b, row, col);
return ` + f.texture2D + "(" + e + `, uv);
}
`;
}
function cU(n) {
var t = n.shapeInfo.logicalShape, e = n.name, r = "get" + e.charAt(0).toUpperCase() + e.slice(1), i = t[1] * t[2], a = t[2], s = _.util.squeezeShape(t), o = s.newShape, c = s.keptDims, l = o;
if (l.length < t.length) {
var u = sa(n, l), h = ["row", "col", "depth"];
return `
` + ia(u) + `
float ` + r + `(int row, int col, int depth) {
return ` + r + "(" + oa(h, c) + `);
}
`;
}
if (n.shapeInfo.isUniform)
return `
float ` + r + `(int row, int col, int depth) {
int index = round(dot(vec3(row, col, depth),
vec3(` + i + ", " + a + `, 1)));
` + aa(n) + `
}
`;
var d = n.shapeInfo.texShape, p = d[0], f = d[1], m = n.shapeInfo.flatOffset;
if (f === i && m == null)
return `
float ` + r + `(int row, int col, int depth) {
float texR = float(row);
float texC = dot(vec2(col, depth), vec2(` + a + `, 1));
vec2 uv = (vec2(texC, texR) + halfCR) /
vec2(` + f + ".0, " + p + `.0);
return sampleTexture(` + e + `, uv);
}
`;
if (f === a && m == null)
return `
float ` + r + `(int row, int col, int depth) {
float texR = dot(vec2(row, col), vec2(` + t[1] + `, 1));
float texC = float(depth);
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(` + f + ".0, " + p + `.0);
return sampleTexture(` + e + `, uv);
}
`;
var g = yi(e);
return `
float ` + r + `(int row, int col, int depth) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * ` + i + " + col * " + a + " + depth + " + g + `;
vec2 uv = uvFromFlat(` + p + ", " + f + `, index);
return sampleTexture(` + e + `, uv);
}
`;
}
function gU(n) {
for (var t = n.shapeInfo.logicalShape, e = t.length, r = n.name, i = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = n.shapeInfo.texShape, s = [Math.ceil(a[0] / 2), Math.ceil(a[1] / 2)], o = s[0], c = s[1], l = Math.ceil(t[e - 1] / 2), u = l * Math.ceil(t[e - 2] / 2), h = "int b, int row, int col", d = "b * " + u + " + (row / 2) * " + l + " + (col / 2)", p = 2; p < e - 1; p++)
h = "int b" + p + ", " + h, u *= t[e - p - 1], d = "b" + p + " * " + u + " + " + d;
var f = Bt();
return `
vec4 ` + i + "(" + h + `) {
int index = ` + d + `;
int texR = index / ` + c + `;
int texC = index - texR * ` + c + `;
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(` + c + ", " + o + `);
return ` + f.texture2D + "(" + r + `, uv);
}
`;
}
function lU(n) {
var t = n.shapeInfo.logicalShape, e = n.name, r = "get" + e.charAt(0).toUpperCase() + e.slice(1), i = t[3], a = t[2] * i, s = t[1] * a, o = _.util.squeezeShape(t), c = o.newShape, l = o.keptDims;
if (c.length < t.length) {
var u = sa(n, c), h = ["row", "col", "depth", "depth2"];
return `
` + ia(u) + `
float ` + r + `(int row, int col, int depth, int depth2) {
return ` + r + "(" + oa(h, l) + `);
}
`;
}
if (n.shapeInfo.isUniform)
return `
float ` + r + `(int row, int col, int depth, int depth2) {
int index = round(dot(vec4(row, col, depth, depth2),
vec4(` + s + ", " + a + ", " + i + `, 1)));
` + aa(n) + `
}
`;
var d = n.shapeInfo.flatOffset, p = n.shapeInfo.texShape, f = p[0], m = p[1];
if (m === s && d == null)
return `
float ` + r + `(int row, int col, int depth, int depth2) {
float texR = float(row);
float texC =
dot(vec3(col, depth, depth2),
vec3(` + a + ", " + i + `, 1));
vec2 uv = (vec2(texC, texR) + halfCR) /
vec2(` + m + ".0, " + f + `.0);
return sampleTexture(` + e + `, uv);
}
`;
if (m === i && d == null)
return `
float ` + r + `(int row, int col, int depth, int depth2) {
float texR = dot(vec3(row, col, depth),
vec3(` + t[1] * t[2] + ", " + t[2] + `, 1));
float texC = float(depth2);
vec2 uv = (vec2(texC, texR) + halfCR) /
vec2(` + m + ".0, " + f + `.0);
return sampleTexture(` + e + `, uv);
}
`;
var g = yi(e);
return `
float ` + r + `(int row, int col, int depth, int depth2) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * ` + s + " + col * " + a + ` +
depth * ` + i + ` + depth2;
vec2 uv = uvFromFlat(` + f + ", " + m + ", index + " + g + `);
return sampleTexture(` + e + `, uv);
}
`;
}
function uU(n) {
var t = n.shapeInfo.logicalShape, e = n.name, r = "get" + e.charAt(0).toUpperCase() + e.slice(1), i = t[4], a = t[3] * i, s = t[2] * a, o = t[1] * s, c = _.util.squeezeShape(t), l = c.newShape, u = c.keptDims;
if (l.length < t.length) {
var h = sa(n, l), d = ["row", "col", "depth", "depth2", "depth3"];
return `
` + ia(h) + `
float ` + r + `(int row, int col, int depth, int depth2, int depth3) {
return ` + r + "(" + oa(d, u) + `);
}
`;
}
if (n.shapeInfo.isUniform)
return `
float ` + r + `(int row, int col, int depth, int depth2, int depth3) {
float index = dot(
vec4(row, col, depth, depth2),
vec4(` + o + ", " + s + ", " + a + ", " + i + `)) +
depth3;
` + aa(n) + `
}
`;
var p = n.shapeInfo.flatOffset, f = n.shapeInfo.texShape, m = f[0], g = f[1];
if (g === o && p == null)
return `
float ` + r + `(int row, int col, int depth, int depth2, int depth3) {
int texR = row;
float texC = dot(vec4(col, depth, depth2, depth3),
vec4(` + s + ", " + a + ", " + i + `, 1));
vec2 uv = (vec2(texC, texR) + halfCR) /
vec2(` + g + ".0, " + m + `.0);
return sampleTexture(` + e + `, uv);
}
`;
if (g === i && p == null)
return `
float ` + r + `(int row, int col, int depth, int depth2, int depth3) {
float texR = dot(
vec4(row, col, depth, depth2),
vec4(` + t[1] * t[2] * t[3] + `,
` + t[2] * t[3] + ", " + t[3] + `, 1));
int texC = depth3;
vec2 uv = (vec2(texC, texR) + halfCR) /
vec2(` + g + ".0, " + m + `.0);
return sampleTexture(` + e + `, uv);
}
`;
var y = yi(e);
return `
float ` + r + `(int row, int col, int depth, int depth2, int depth3) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * ` + o + " + col * " + s + " + depth * " + a + ` +
depth2 * ` + i + " + depth3 + " + y + `;
vec2 uv = uvFromFlat(` + m + ", " + g + `, index);
return sampleTexture(` + e + `, uv);
}
`;
}
function hU(n) {
var t = n.shapeInfo.logicalShape, e = n.name, r = "get" + e.charAt(0).toUpperCase() + e.slice(1), i = _.util.squeezeShape(t), a = i.newShape, s = i.keptDims;
if (a.length < t.length) {
var o = sa(n, a), c = ["row", "col", "depth", "depth2", "depth3", "depth4"];
return `
` + ia(o) + `
float ` + r + `(int row, int col, int depth,
int depth2, int depth3, int depth4) {
return ` + r + "(" + oa(c, s) + `);
}
`;
}
var l = t[5], u = t[4] * l, h = t[3] * u, d = t[2] * h, p = t[1] * d;
if (n.shapeInfo.isUniform)
return `
float ` + r + `(int row, int col, int depth,
int depth2, int depth3, int depth4) {
int index = round(dot(
vec4(row, col, depth, depth2),
vec4(` + p + ", " + d + ", " + h + ", " + u + `)) +
dot(
vec2(depth3, depth4),
vec2(` + l + `, 1)));
` + aa(n) + `
}
`;
var f = n.shapeInfo.flatOffset, m = n.shapeInfo.texShape, g = m[0], y = m[1];
if (y === p && f == null)
return `
float ` + r + `(int row, int col, int depth,
int depth2, int depth3, int depth4) {
int texR = row;
float texC = dot(vec4(col, depth, depth2, depth3),
vec4(` + d + ", " + h + ", " + u + ", " + l + `)) +
float(depth4);
vec2 uv = (vec2(texC, texR) + halfCR) /
vec2(` + y + ".0, " + g + `.0);
return sampleTexture(` + e + `, uv);
}
`;
if (y === l && f == null)
return `
float ` + r + `(int row, int col, int depth,
int depth2, int depth3, int depth4) {
float texR = dot(vec4(row, col, depth, depth2),
vec4(` + t[1] * t[2] * t[3] * t[4] + `,
` + t[2] * t[3] * t[4] + `,
` + t[3] * t[4] + `,
` + t[4] + `)) + float(depth3);
int texC = depth4;
vec2 uv = (vec2(texC, texR) + halfCR) /
vec2(` + y + ".0, " + g + `.0);
return sampleTexture(` + e + `, uv);
}
`;
var w = yi(e);
return `
float ` + r + `(int row, int col, int depth,
int depth2, int depth3, int depth4) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * ` + p + " + col * " + d + " + depth * " + h + ` +
depth2 * ` + u + " + depth3 * " + l + " + depth4 + " + w + `;
vec2 uv = uvFromFlat(` + g + ", " + y + `, index);
return sampleTexture(` + e + `, uv);
}
`;
}
function aa(n) {
var t = n.name, e = _.util.sizeFromShape(n.shapeInfo.logicalShape);
return e < 2 ? "return " + t + ";" : `
for (int i = 0; i < ` + e + `; i++) {
if (i == index) {
return ` + t + `[i];
}
}
`;
}
function yU(n, t) {
var e = n.name, r = e.charAt(0).toUpperCase() + e.slice(1), i = "get" + r + "AtOutCoords", a = n.shapeInfo.logicalShape.length, s = t.logicalShape.length, o = fb(n.shapeInfo.logicalShape, t.logicalShape), c = Ze(s), l = s - a, u, h = ["x", "y", "z", "w", "u", "v"];
a === 0 ? u = "" : s < 2 && o.length >= 1 ? u = "coords = 0;" : u = o.map(function(x) {
return "coords." + h[x + l] + " = 0;";
}).join(`
`);
var d = "";
s < 2 && a > 0 ? d = "coords" : d = n.shapeInfo.logicalShape.map(function(x, L) {
return "coords." + h[L + l];
}).join(", ");
var p = "return outputValue;", f = _.util.sizeFromShape(n.shapeInfo.logicalShape), m = f === 1, g = _.util.sizeFromShape(t.logicalShape), y = g === 1;
if (a === 1 && !m && !y)
p = `
return vec4(outputValue.xy, outputValue.xy);
`;
else if (m && !y)
s === 1 ? p = `
return vec4(outputValue.x, outputValue.x, 0., 0.);
` : p = `
return vec4(outputValue.x);
`;
else if (o.length) {
var w = a - 2, b = a - 1;
o.indexOf(w) > -1 && o.indexOf(b) > -1 ? p = "return vec4(outputValue.x);" : o.indexOf(w) > -1 ? p = "return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);" : o.indexOf(b) > -1 && (p = "return vec4(outputValue.xx, outputValue.zz);");
}
return `
vec4 ` + i + `() {
` + c + ` coords = getOutputCoords();
` + u + `
vec4 outputValue = get` + r + "(" + d + `);
` + p + `
}
`;
}
function vU(n, t) {
var e = n.name, r = e.charAt(0).toUpperCase() + e.slice(1), i = "get" + r + "AtOutCoords", a = t.texShape, s = n.shapeInfo.texShape, o = n.shapeInfo.logicalShape.length, c = t.logicalShape.length;
if (!n.shapeInfo.isUniform && o === c && n.shapeInfo.flatOffset == null && _.util.arraysEqual(s, a))
return `
float ` + i + `() {
return sampleTexture(` + e + `, resultUV);
}
`;
var l = Ze(c), u = fb(n.shapeInfo.logicalShape, t.logicalShape), h = c - o, d, p = ["x", "y", "z", "w", "u", "v"];
o === 0 ? d = "" : c < 2 && u.length >= 1 ? d = "coords = 0;" : d = u.map(function(m) {
return "coords." + p[m + h] + " = 0;";
}).join(`
`);
var f = "";
return c < 2 && o > 0 ? f = "coords" : f = n.shapeInfo.logicalShape.map(function(m, g) {
return "coords." + p[g + h];
}).join(", "), `
float ` + i + `() {
` + l + ` coords = getOutputCoords();
` + d + `
return get` + r + "(" + f + `);
}
`;
}
function Ze(n) {
if (n <= 1)
return "int";
if (n === 2)
return "ivec2";
if (n === 3)
return "ivec3";
if (n === 4)
return "ivec4";
if (n === 5)
return "ivec5";
if (n === 6)
return "ivec6";
throw Error("GPU for rank " + n + " is not yet supported");
}
function sa(n, t) {
var e = JSON.parse(JSON.stringify(n));
return e.shapeInfo.logicalShape = t, e;
}
function oa(n, t) {
return t.map(function(e) {
return n[e];
}).join(", ");
}
var EU = function() {
function n(t, e, r, i) {
this.variableNames = ["A"], this.packedInputs = true, this.packedOutput = true, _.util.assert(t.length > 2, function() {
return "Packed arg" + (r.charAt(0).toUpperCase() + r.slice(1)) + " supports only inputs with rank above 2.";
});
var a = t[t.length - 1], s = Math.ceil(a / e);
this.outputShape = t.slice(0, -1), s > 1 && this.outputShape.push(s), i || this.variableNames.push("bestIndicesA");
var o = this.outputShape, c = o.length, l = Ze(c), u = Ut("coords", c), h, d;
if (s === 1) {
d = c + 1;
var p = Ze(d);
h = `
` + p + " sourceLocR = " + p + "(" + u.join() + `, 0);
++` + u[c - 1] + `;
` + p + " sourceLocG = " + p + "(" + u.join() + `, 0);
++` + u[c - 2] + `;
` + p + " sourceLocA = " + p + "(" + u.join() + `, 0);
--` + u[c - 1] + `;
` + p + " sourceLocB = " + p + "(" + u.join() + `, 0);
--` + u[c - 2] + ";";
} else
d = c, h = `
` + l + ` sourceLocR = coords;
++` + u[c - 1] + `;
` + l + ` sourceLocG = coords;
++` + u[c - 2] + `;
` + l + ` sourceLocA = coords;
--` + u[c - 1] + `;
` + l + ` sourceLocB = coords;
--` + u[c - 2] + ";";
var f = ["x", "y", "z", "w", "u", "v"].slice(0, d), m = "." + f[d - 1], g = f.map(function(O) {
return "int " + O;
}), y = Ut("sourceLocR", d - 1).concat("inIdx.r"), w = Ut("sourceLocG", d - 1).concat("inIdx.g"), b = Ut("sourceLocB", d - 1).concat("inIdx.b"), x = Ut("sourceLocA", d - 1).concat("inIdx.a"), L = r === "max" ? "greaterThan" : "lessThan", N = i ? "" : `
inIdx = round(vec4(getBestIndicesAChannel(` + y.join() + `),
getBestIndicesAChannel(` + w.join() + `),
getBestIndicesAChannel(` + b.join() + `),
getBestIndicesAChannel(` + x.join() + ")));", I = `vec4(
getAChannel(` + y.join() + `),
hasNextCol ? getAChannel(` + w.join() + `) : 0.,
hasNextRow ? getAChannel(` + b.join() + `) : 0.,
hasNextRow && hasNextCol ? getAChannel(` + x.join() + ") : 0.)", C = i ? "" : `
float getBestIndicesAChannel(` + g.join() + `) {
return getChannel(getBestIndicesA(` + f.join() + `),
vec2(` + f.slice(-2).join() + `));
}`;
this.userCode = `
float getAChannel(` + g.join() + `) {
return getChannel(getA(` + f.join() + `),
vec2(` + f.slice(-2).join() + `));
}
` + C + `
void main() {
` + l + ` coords = getOutputCoords();
bool hasNextCol = ` + u[c - 1] + " < " + (o[c - 1] - 1) + `;
bool hasNextRow = ` + u[c - 2] + " < " + (o[c - 2] - 1) + `;
` + h + `
ivec4 srcIdx = ivec4(sourceLocR` + m + ", sourceLocG" + m + `,
sourceLocB` + m + ", sourceLocA" + m + ") * " + e + `;
ivec4 inIdx = srcIdx;
vec4 bestIndex = vec4(inIdx);
vec4 bestValue = ` + I + `;
for (int i = 0; i < ` + e + `; i++) {
inIdx = srcIdx;
` + N + `
vec4 candidate = ` + I + `;
bvec4 nan = isnan(candidate);
bvec4 replace = bvec4(
vec4(` + L + `(candidate, bestValue)) * (vec4(1.0) - vec4(nan)));
bestValue = vec4(replace.x ? candidate.x : bestValue.x,
replace.y ? candidate.y : bestValue.y,
replace.z ? candidate.z : bestValue.z,
replace.w ? candidate.w : bestValue.w);
bestIndex = mix(bestIndex, vec4(inIdx), vec4(replace));
srcIdx++;
}
setOutput(bestIndex);
}
`;
}
return n;
}();
var DU = function() {
function n(t) {
this.variableNames = ["dy"], this.outputShape = t.inShape;
var e = t.filterHeight, r = t.filterWidth, i = t.strideHeight, a = t.strideWidth, s = t.dilationHeight, o = t.dilationWidth, c = t.effectiveFilterHeight, l = t.effectiveFilterWidth, u = c - 1 - t.padInfo.top, h = l - 1 - t.padInfo.left, d = 1 / (e * r);
this.userCode = `
const ivec2 pads = ivec2(` + u + ", " + h + `);
const float avgMultiplier = float(` + d + `);
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int d = coords[3];
ivec2 dyRCCorner = coords.yz - pads;
int dyRCorner = dyRCCorner.x;
int dyCCorner = dyRCCorner.y;
// Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0;
for (int wR = 0; wR < ` + c + `;
wR += ` + s + `) {
float dyR = float(dyRCorner + wR) / ` + i + `.0;
if (dyR < 0.0 || dyR >= ` + t.outHeight + `.0 || fract(dyR) > 0.0) {
continue;
}
int idyR = int(dyR);
for (int wC = 0; wC < ` + l + `;
wC+= ` + o + `) {
float dyC = float(dyCCorner + wC) / ` + a + `.0;
if (dyC < 0.0 || dyC >= ` + t.outWidth + `.0 ||
fract(dyC) > 0.0) {
continue;
}
int idyC = int(dyC);
float dyValue = getDy(b, idyR, idyC, d);
dotProd += dyValue * avgMultiplier;
}
}
setOutput(dotProd);
}
`;
}
return n;
}(), kU = function() {
function n(t) {
this.variableNames = ["dy"], this.outputShape = t.inShape;
var e = t.filterDepth, r = t.filterHeight, i = t.filterWidth, a = t.strideDepth, s = t.strideHeight, o = t.strideWidth, c = t.dilationDepth, l = t.dilationHeight, u = t.dilationWidth, h = t.effectiveFilterDepth, d = t.effectiveFilterHeight, p = t.effectiveFilterWidth, f = h - 1 - t.padInfo.front, m = d - 1 - t.padInfo.top, g = p - 1 - t.padInfo.left, y = 1 / (e * r * i);
this.userCode = `
const ivec3 pads = ivec3(` + f + ", " + m + ", " + g + `);
const float avgMultiplier = float(` + y + `);
void main() {
ivec5 coords = getOutputCoords();
int batch = coords.x;
int ch = coords.u;
ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;
int dyDCorner = dyCorner.x;
int dyRCorner = dyCorner.y;
int dyCCorner = dyCorner.z;
// Convolve dy(?, ?, ?, d) with pos mask(:, :, :, ch) to get
// dx(xD, xR, xC, ch).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0;
for (int wD = 0; wD < ` + h + `;
wD += ` + c + `) {
float dyD = float(dyDCorner + wD) / ` + a + `.0;
if (dyD < 0.0 || dyD >= ` + t.outDepth + `.0 || fract(dyD) > 0.0) {
continue;
}
int idyD = int(dyD);
for (int wR = 0; wR < ` + d + `;
wR += ` + l + `) {
float dyR = float(dyRCorner + wR) / ` + s + `.0;
if (dyR < 0.0 || dyR >= ` + t.outHeight + `.0 ||
fract(dyR) > 0.0) {
continue;
}
int idyR = int(dyR);
for (int wC = 0; wC < ` + p + `;
wC += ` + u + `) {
float dyC = float(dyCCorner + wC) / ` + o + `.0;
if (dyC < 0.0 || dyC >= ` + t.outWidth + `.0 ||
fract(dyC) > 0.0) {
continue;
}
int idyC = int(dyC);
float dyValue = getDy(batch, idyD, idyR, idyC, ch);
dotProd += dyValue * avgMultiplier;
}
}
}
setOutput(dotProd);
}
`;
}
return n;
}();
var yb = `
if (isnan(a)) return a;
if (isnan(b)) return b;
`, FU = `
float s = sign(a) * sign(b);
int ia = round(a);
int ib = round(b);
if (ib != 0) {
// Windows (D3D) wants guaranteed non-zero int division at compile-time.
return float(idiv(ia, ib, s));
} else {
return NAN;
}
`, WU = `
if(a < 0.0 && floor(b) < b){
return NAN;
}
if (b == 0.0) {
return 1.0;
}
return (round(mod(b, 2.0)) != 1) ?
pow(abs(a), b) : sign(a) * pow(abs(a), b);
`, UU = "return float(a == b);", BU = "return float(a < b);", zU = "return float(a <= b);", PU = "return float(a > b);", MU = "return float(a >= b);", HU = "return float(a >= 1.0 && b >= 1.0);", VU = "return float(a >= 1.0 || b >= 1.0);", GU = yb + `
return max(a, b);
`, qU = yb + `
return min(a, b);
`, YU = `if (b == 0.0) return NAN;
return mod(a, b);`, KU = "return (b >= 1.0) ? a : a * (b + 1.0);", vb = "return (a < 0.) ? b * a : a;", Wt = function() {
function n(t, e, r) {
this.variableNames = ["A", "B"], this.outputShape = _.backend_util.assertAndGetBroadcastShape(e, r), this.userCode = `
float binaryOperation(float a, float b) {
` + t + `
}
void main() {
float a = getAAtOutCoords();
float b = getBAtOutCoords();
setOutput(binaryOperation(a, b));
}
`;
}
return n;
}();
var Ko = `
result.r = isNaN.r > 0. ? NAN : result.r;
result.g = isNaN.g > 0. ? NAN : result.g;
result.b = isNaN.b > 0. ? NAN : result.b;
result.a = isNaN.a > 0. ? NAN : result.a;
`, jU = `
ivec4 ia = round(a);
ivec4 ib = round(b);
bvec4 cond = notEqual(ib, ivec4(0));
ivec4 result = ivec4(0);
vec4 s = sign(a) * sign(b);
// Windows (D3D) wants guaranteed non-zero int division at compile-time.
if (cond[0]) {
result[0] = idiv(ia[0], ib[0], s[0]);
}
if (cond[1]) {
result[1] = idiv(ia[1], ib[1], s[1]);
}
if (cond[2]) {
result[2] = idiv(ia[2], ib[2], s[2]);
}
if (cond[3]) {
result[3] = idiv(ia[3], ib[3], s[3]);
}
return vec4(result);
`, $U = `
// isModRound1 has 1 for components with round(mod(b, 2.0)) == 1, 0 otherwise.
vec4 isModRound1 = vec4(equal(round(mod(b, 2.0)), ivec4(1)));
vec4 multiplier = sign(a) * isModRound1 + (vec4(1.0) - isModRound1);
vec4 result = multiplier * pow(abs(a), b);
// Ensure that a^0 = 1, including 0^0 = 1 as this correspond to TF and JS
bvec4 isExpZero = equal(b, vec4(0.0));
result.r = isExpZero.r ? 1.0 : result.r;
result.g = isExpZero.g ? 1.0 : result.g;
result.b = isExpZero.b ? 1.0 : result.b;
result.a = isExpZero.a ? 1.0 : result.a;
vec4 isNaN = vec4(lessThan(a, vec4(0.0))) * vec4(lessThan(floor(b), b));
` + Ko + `
return result;
`, wb = `
vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));
return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);
`, XU = `
vec4 bGTEZero = vec4(greaterThanEqual(b, vec4(0.)));
return (bGTEZero * a) + ((vec4(1.0) - bGTEZero) * (a * (b + vec4(1.0))));
`, JU = `
return vec4(equal(a, b));
`, ZU = `
return vec4(lessThan(a, b));
`, QU = `
return vec4(lessThanEqual(a, b));
`, eB = `
return vec4(greaterThan(a, b));
`, tB = `
return vec4(greaterThanEqual(a, b));
`, nB = `
return vec4(
vec4(greaterThanEqual(a, vec4(1.0))) *
vec4(greaterThanEqual(b, vec4(1.0))));
`, rB = `
return min(
vec4(greaterThanEqual(a, vec4(1.0))) +
vec4(greaterThanEqual(b, vec4(1.0))),
vec4(1.0));
`, iB = `
vec4 result = vec4(max(a, b));
vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));
` + Ko + `
return result;
`, aB = `
vec4 result = vec4(min(a, b));
vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));
` + Ko + `
return result;
`, sB = `
vec4 result = mod(a, b);
vec4 isNaN = vec4(equal(b, vec4(0.0)));
` + Ko + `
return result;
`, rr = function() {
function n(t, e, r, i) {
i === void 0 && (i = false), this.variableNames = ["A", "B"], this.supportsBroadcasting = true, this.packedInputs = true, this.packedOutput = true, this.outputShape = _.backend_util.assertAndGetBroadcastShape(e, r);
var a = this.outputShape.length, s = "";
if (i)
if (a === 0 || _.util.sizeFromShape(this.outputShape) === 1)
s = `
result.y = 0.;
result.z = 0.;
result.w = 0.;
`;
else {
var o = Ze(a);
if (s = `
` + o + ` coords = getOutputCoords();
`, a === 1)
s += `
result.y = (coords + 1) >= ` + this.outputShape[0] + ` ? 0. : result.y;
result.z = 0.;
result.w = 0.;
`;
else {
var c = Ut("coords", a);
s += `
bool nextRowOutOfBounds =
(` + c[a - 2] + " + 1) >= " + this.outputShape[a - 2] + `;
bool nextColOutOfBounds =
(` + c[a - 1] + " + 1) >= " + this.outputShape[a - 1] + `;
result.y = nextColOutOfBounds ? 0. : result.y;
result.z = nextRowOutOfBounds ? 0. : result.z;
result.w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result.w;
`;
}
}
this.userCode = `
vec4 binaryOperation(vec4 a, vec4 b) {
` + t + `
}
void main() {
vec4 a = getAAtOutCoords();
vec4 b = getBAtOutCoords();
vec4 result = binaryOperation(a, b);
` + s + `
setOutput(result);
}
`;
}
return n;
}();
var oB = function() {
function n(t) {
this.variableNames = ["A"], this.outputShape = t, this.userCode = `
uniform float minVal;
uniform float maxVal;
void main() {
float value = getAAtOutCoords();
if (isnan(value)) {
setOutput(value);
return;
}
setOutput(clamp(value, minVal, maxVal));
}
`;
}
return n.prototype.getCustomSetupFunc = function(t, e) {
var r = this;
return function(i, a) {
r.minLoc == null && (r.minLoc = i.getUniformLocationNoThrow(a, "minVal"), r.maxLoc = i.getUniformLocationNoThrow(a, "maxVal")), i.gl.uniform1f(r.minLoc, t), i.gl.uniform1f(r.maxLoc, e);
};
}, n;
}();
var cB = function() {
function n(t) {
this.variableNames = ["A"], this.packedInputs = true, this.packedOutput = true, this.outputShape = t, this.userCode = `
uniform float minVal;
uniform float maxVal;
void main() {
vec4 value = getAAtOutCoords();
if (any(isnan(value))) {
setOutput(value);
return;
}
setOutput(clamp(value, vec4(minVal), vec4(maxVal)));
}
`;
}
return n.prototype.getCustomSetupFunc = function(t, e) {
var r = this;
return function(i, a) {
r.minLoc == null && (r.minLoc = i.getUniformLocationNoThrow(a, "minVal"), r.maxLoc = i.getUniformLocationNoThrow(a, "maxVal")), i.gl.uniform1f(r.minLoc, t), i.gl.uniform1f(r.maxLoc, e);
};
}, n;
}();
var lB = function() {
function n(t) {
this.variableNames = ["real", "imag"], this.outputShape = t, this.userCode = `
void main() {
float re = abs(getRealAtOutCoords());
float im = abs(getImagAtOutCoords());
float mx = max(re, im);
// sadly the length function in glsl is not underflow-safe
// (at least not on Intel GPUs). So the safe solution is
// to ensure underflow-safety in all cases.
setOutput(
mx == 0.0 ? 0.0 : mx * length(vec2(1, min(re, im)/mx))
);
}
`;
}
return n;
}();
var uB = function() {
function n(t) {
this.variableNames = ["x", "dy"], this.outputShape = t.filterShape;
var e = t.strideHeight, r = t.strideWidth, i = t.padInfo.top, a = t.padInfo.left, s = t.dataFormat === "channelsLast";
this.userCode = `
void main() {
ivec4 coords = getOutputCoords();
int wR = coords.x;
int wC = coords.y;
int d1 = coords.z;
int d2 = coords.w;
// Convolve x(?, ?, d1) with dy(:, :, d2) to get dw(wR, wC, d1, d2).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0;
for (int b = 0; b < ` + t.batchSize + `; b++) {
for (int yR = 0; yR < ` + t.outHeight + `; yR++) {
int xR = wR + yR * ` + e + " - " + i + `;
if (xR < 0 || xR >= ` + t.inHeight + `) {
continue;
}
for (int yC = 0; yC < ` + t.outWidth + `; yC++) {
int xC = wC + yC * ` + r + " - " + a + `;
if (xC < 0 || xC >= ` + t.inWidth + `) {
continue;
}
if (` + s + `) {
float dyValue = getDy(b, yR, yC, d2);
float xValue = getX(b, xR, xC, d1);
dotProd += (xValue * dyValue);
} else {
float dyValue = getDy(b, d2, yR, yC);
float xValue = getX(b, d1, xR, xC);
dotProd += (xValue * dyValue);
}
}
}
}
setOutput(dotProd);
}
`;
}
return n;
}(), hB = function() {
function n(t) {
this.variableNames = ["dy", "W"], this.outputShape = t.inShape;
var e = t.filterHeight, r = t.filterWidth, i = t.strideHeight, a = t.strideWidth, s = t.dataFormat === "channelsLast", o = e - 1 - t.padInfo.top, c = r - 1 - t.padInfo.left, l = s ? 1 : 2, u = s ? 2 : 3, h = s ? 3 : 1;
this.userCode = `
const ivec2 pads = ivec2(` + o + ", " + c + `);
void main() {
ivec4 coords = getOutputCoords();
int batch = coords[0];
int d1 = coords[` + h + `];
ivec2 dyCorner = ivec2(coords[` + l + "], coords[" + u + `]) - pads;
int dyRCorner = dyCorner.x;
int dyCCorner = dyCorner.y;
// Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0;
for (int wR = 0; wR < ` + e + `; wR++) {
float dyR = float(dyRCorner + wR) / ` + i + `.0;
if (dyR < 0.0 || dyR >= ` + t.outHeight + `.0 || fract(dyR) > 0.0) {
continue;
}
int idyR = int(dyR);
int wRPerm = ` + e + ` - 1 - wR;
for (int wC = 0; wC < ` + r + `; wC++) {
float dyC = float(dyCCorner + wC) / ` + a + `.0;
if (dyC < 0.0 || dyC >= ` + t.outWidth + `.0 ||
fract(dyC) > 0.0) {
continue;
}
int idyC = int(dyC);
int wCPerm = ` + r + ` - 1 - wC;
for (int d2 = 0; d2 < ` + t.outChannels + `; d2++) {
if (` + s + `) {
float xValue = getDy(batch, idyR, idyC, d2);
float wValue = getW(wRPerm, wCPerm, d1, d2);
dotProd += xValue * wValue;
} else {
float xValue = getDy(batch, d2, idyR, idyC);
float wValue = getW(wRPerm, wCPerm, d1, d2);
dotProd += xValue * wValue;
}
}
}
}
setOutput(dotProd);
}
`;
}
return n;
}(), dB = function() {
function n(t) {
this.variableNames = ["x", "dy"], this.outputShape = t.filterShape;
var e = t.strideDepth, r = t.strideHeight, i = t.strideWidth, a = t.padInfo.front, s = t.padInfo.top, o = t.padInfo.left;
this.userCode = `
void main() {
ivec5 coords = getOutputCoords();
int wF = coords.x;
int wR = coords.y;
int wC = coords.z;
int d1 = coords.w;
int d2 = coords.u;
float dotProd = 0.0;
for (int b = 0; b < ` + t.batchSize + `; b++) {
for (int yF = 0; yF < ` + t.outDepth + `; yF++) {
int xF = wF + yF * ` + e + " - " + a + `;
if (xF < 0 || xF >= ` + t.inDepth + `) {
continue;
}
for (int yR = 0; yR < ` + t.outHeight + `; yR++) {
int xR = wR + yR * ` + r + " - " + s + `;
if (xR < 0 || xR >= ` + t.inHeight + `) {
continue;
}
for (int yC = 0; yC < ` + t.outWidth + `; yC++) {
int xC = wC + yC * ` + i + " - " + o + `;
if (xC < 0 || xC >= ` + t.inWidth + `) {
continue;
}
float dyValue = getDy(b, yF, yR, yC, d2);
float xValue = getX(b, xF, xR, xC, d1);
dotProd += (xValue * dyValue);
}
}
}
}
setOutput(dotProd);
}
`;
}
return n;
}(), pB = function() {
function n(t) {
this.variableNames = ["dy", "W"], this.outputShape = t.inShape;
var e = t.filterDepth, r = t.filterHeight, i = t.filterWidth, a = t.strideDepth, s = t.strideHeight, o = t.strideWidth, c = e - 1 - t.padInfo.front, l = r - 1 - t.padInfo.top, u = i - 1 - t.padInfo.left;
this.userCode = `
const ivec3 pads = ivec3(` + c + ", " + l + ", " + u + `);
void main() {
ivec5 coords = getOutputCoords();
int batch = coords.x;
int d1 = coords.u;
ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;
int dyFCorner = dyCorner.x;
int dyRCorner = dyCorner.y;
int dyCCorner = dyCorner.z;
float dotProd = 0.0;
for (int wF = 0; wF < ` + e + `; wF++) {
float dyF = float(dyFCorner + wF) / ` + a + `.0;
if (dyF < 0.0 || dyF >= ` + t.outDepth + `.0 || fract(dyF) > 0.0) {
continue;
}
int idyF = int(dyF);
int wFPerm = ` + e + ` - 1 - wF;
for (int wR = 0; wR < ` + r + `; wR++) {
float dyR = float(dyRCorner + wR) / ` + s + `.0;
if (dyR < 0.0 || dyR >= ` + t.outHeight + `.0 ||
fract(dyR) > 0.0) {
continue;
}
int idyR = int(dyR);
int wRPerm = ` + r + ` - 1 - wR;
for (int wC = 0; wC < ` + i + `; wC++) {
float dyC = float(dyCCorner + wC) / ` + o + `.0;
if (dyC < 0.0 || dyC >= ` + t.outWidth + `.0 ||
fract(dyC) > 0.0) {
continue;
}
int idyC = int(dyC);
int wCPerm = ` + i + ` - 1 - wC;
for (int d2 = 0; d2 < ` + t.outChannels + `; d2++) {
float xValue = getDy(batch, idyF, idyR, idyC, d2);
float wValue = getW(wFPerm, wRPerm, wCPerm, d1, d2);
dotProd += xValue * wValue;
}
}
}
}
setOutput(dotProd);
}
`;
}
return n;
}();
var fB = function() {
function n(t) {
this.variableNames = ["x", "dy"], this.outputShape = t.filterShape;
var e = t.strideHeight, r = t.strideWidth, i = t.padInfo.top, a = t.padInfo.left, s = t.outChannels / t.inChannels;
this.userCode = `
void main() {
ivec4 coords = getOutputCoords();
int wR = coords.x;
int wC = coords.y;
int d1 = coords.z;
int dm = coords.w;
int d2 = d1 * ` + s + ` + dm;
float dotProd = 0.0;
// TO DO: Vec4 over the batch size
for (int b = 0; b < ` + t.batchSize + `; b++) {
for (int yR = 0; yR < ` + t.outHeight + `; yR++) {
int xR = wR + yR * ` + e + " - " + i + `;
if (xR < 0 || xR >= ` + t.inHeight + `) {
continue;
}
for (int yC = 0; yC < ` + t.outWidth + `; yC++) {
int xC = wC + yC * ` + r + " - " + a + `;
if (xC < 0 || xC >= ` + t.inWidth + `) {
continue;
}
float dyValue = getDy(b, yR, yC, d2);
float xValue = getX(b, xR, xC, d1);
dotProd += (xValue * dyValue);
}
}
}
setOutput(dotProd);
}
`;
}
return n;
}(), mB = function() {
function n(t) {
this.variableNames = ["dy", "W"], this.outputShape = t.inShape;
var e = t.filterHeight, r = t.filterWidth, i = t.strideHeight, a = t.strideWidth, s = e - 1 - t.padInfo.top, o = r - 1 - t.padInfo.left, c = t.outChannels / t.inChannels;
this.userCode = `
const ivec2 pads = ivec2(` + s + ", " + o + `);
void main() {
ivec4 coords = getOutputCoords();
int batch = coords[0];
int d1 = coords[3];
ivec2 dyCorner = coords.yz - pads;
int dyRCorner = dyCorner.x;
int dyCCorner = dyCorner.y;
float dotProd = 0.0;
for (int wR = 0; wR < ` + e + `; wR++) {
float dyR = float(dyRCorner + wR) / ` + i + `.0;
if (dyR < 0.0 || dyR >= ` + t.outHeight + `.0 || fract(dyR) > 0.0) {
continue;
}
int idyR = int(dyR);
int wRPerm = ` + e + ` - 1 - wR;
for (int wC = 0; wC < ` + r + `; wC++) {
float dyC = float(dyCCorner + wC) / ` + a + `.0;
if (dyC < 0.0 || dyC >= ` + t.outWidth + `.0 ||
fract(dyC) > 0.0) {
continue;
}
int idyC = int(dyC);
int wCPerm = ` + r + ` - 1 - wC;
// TO DO: Vec4 over the channelMul
for (int dm = 0; dm < ` + c + `; dm++) {
int d2 = d1 * ` + c + ` + dm;
float xValue = getDy(batch, idyR, idyC, d2);
float wValue = getW(wRPerm, wCPerm, d1, dm);
dotProd += xValue * wValue;
}
}
}
setOutput(dotProd);
}
`;
}
return n;
}();
var bb = function() {
function n(t, e, r, i) {
e === void 0 && (e = false), r === void 0 && (r = null), i === void 0 && (i = false), this.variableNames = ["x", "W"], this.outputShape = t.outShape;
var a = t.padInfo.top, s = t.padInfo.left, o = t.strideHeight, c = t.strideWidth, l = t.dilationHeight, u = t.dilationWidth, h = t.filterHeight, d = t.filterWidth, p = Math.floor(t.inChannels / 4) * 4, f = t.inChannels % 4, m = t.dataFormat === "channelsLast", g = m ? 1 : 2, y = m ? 2 : 3, w = m ? 3 : 1, b = "", x = "";
r && (i ? b = `float activation(float a) {
float b = getPreluActivationWeightsAtOutCoords();
` + r + `
}` : b = `
float activation(float x) {
` + r + `
}
`, x = "result = activation(result);");
var L = e ? "result += getBiasAtOutCoords();" : "";
e && this.variableNames.push("bias"), i && this.variableNames.push("preluActivationWeights"), this.userCode = `
` + b + `
const ivec2 strides = ivec2(` + o + ", " + c + `);
const ivec2 pads = ivec2(` + a + ", " + s + `);
void main() {
ivec4 coords = getOutputCoords();
int batch = coords[0];
int d2 = coords[` + w + `];
ivec2 xRCCorner =
ivec2(coords[` + g + "], coords[" + y + `]) * strides - pads;
int xRCorner = xRCCorner.x;
int xCCorner = xRCCorner.y;
// Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0;
for (int wR = 0; wR < ` + h + `; wR++) {
int xR = xRCorner + wR * ` + l + `;
if (xR < 0 || xR >= ` + t.inHeight + `) {
continue;
}
for (int wC = 0; wC < ` + d + `; wC++) {
int xC = xCCorner + wC * ` + u + `;
if (xC < 0 || xC >= ` + t.inWidth + `) {
continue;
}
for (int d1 = 0; d1 < ` + p + `; d1 += 4) {
vec4 wValues = vec4(
getW(wR, wC, d1, d2),
getW(wR, wC, d1 + 1, d2),
getW(wR, wC, d1 + 2, d2),
getW(wR, wC, d1 + 3, d2)
);
if (` + m + `) {
vec4 xValues = vec4(
getX(batch, xR, xC, d1),
getX(batch, xR, xC, d1 + 1),
getX(batch, xR, xC, d1 + 2),
getX(batch, xR, xC, d1 + 3)
);
dotProd += dot(xValues, wValues);
} else {
vec4 xValues = vec4(
getX(batch, d1, xR, xC),
getX(batch, d1 + 1, xR, xC),
getX(batch, d1 + 2, xR, xC),
getX(batch, d1 + 3, xR, xC)
);
dotProd += dot(xValues, wValues);
}
}
if (` + (f === 1) + `) {
if (` + m + `) {
dotProd +=
getX(batch, xR, xC, ` + p + `) *
getW(wR, wC, ` + p + `, d2);
} else {
dotProd +=
getX(batch, ` + p + `, xR, xC) *
getW(wR, wC, ` + p + `, d2);
}
} else if (` + (f === 2) + `) {
vec2 wValues = vec2(
getW(wR, wC, ` + p + `, d2),
getW(wR, wC, ` + p + ` + 1, d2)
);
if (` + m + `) {
vec2 xValues = vec2(
getX(batch, xR, xC, ` + p + `),
getX(batch, xR, xC, ` + p + ` + 1)
);
dotProd += dot(xValues, wValues);
} else {
vec2 xValues = vec2(
getX(batch, ` + p + `, xR, xC),
getX(batch, ` + p + ` + 1, xR, xC)
);
dotProd += dot(xValues, wValues);
}
} else if (` + (f === 3) + `) {
vec3 wValues = vec3(
getW(wR, wC, ` + p + `, d2),
getW(wR, wC, ` + p + ` + 1, d2),
getW(wR, wC, ` + p + ` + 2, d2)
);
if (` + m + `) {
vec3 xValues = vec3(
getX(batch, xR, xC, ` + p + `),
getX(batch, xR, xC, ` + p + ` + 1),
getX(batch, xR, xC, ` + p + ` + 2)
);
dotProd += dot(xValues, wValues);
} else {
vec3 xValues = vec3(
getX(batch, ` + p + `, xR, xC),
getX(batch, ` + p + ` + 1, xR, xC),
getX(batch, ` + p + ` + 2, xR, xC)
);
dotProd += dot(xValues, wValues);
}
}
}
}
float result = dotProd;
` + L + `
` + x + `
setOutput(result);
}
`;
}
return n;
}(), gB = function() {
function n(t) {
this.variableNames = ["x", "W"], this.outputShape = t.outShape;
var e = t.padInfo.front, r = t.padInfo.top, i = t.padInfo.left, a = t.strideDepth, s = t.strideHeight, o = t.strideWidth, c = t.dilationDepth, l = t.dilationHeight, u = t.dilationWidth, h = t.filterDepth, d = t.filterHeight, p = t.filterWidth, f = Math.floor(t.inChannels / 4) * 4, m = t.inChannels % 4;
this.userCode = `
const ivec3 strides = ivec3(` + a + ", " + s + ", " + o + `);
const ivec3 pads = ivec3(` + e + ", " + r + ", " + i + `);
void main() {
ivec5 coords = getOutputCoords();
int batch = coords.x;
int d2 = coords.u;
ivec3 xFRCCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;
int xFCorner = xFRCCorner.x;
int xRCorner = xFRCCorner.y;
int xCCorner = xFRCCorner.z;
// Convolve x(?, ?, ?, d1) with w(:, :, :, d1, d2) to get
// y(yF, yR, yC, d2). ? = to be determined. : = across all
// values in that axis.
float dotProd = 0.0;
for (int wF = 0; wF < ` + h + `; wF++) {
int xF = xFCorner + wF * ` + c + `;
if (xF < 0 || xF >= ` + t.inDepth + `) {
continue;
}
for (int wR = 0; wR < ` + d + `; wR++) {
int xR = xRCorner + wR * ` + l + `;
if (xR < 0 || xR >= ` + t.inHeight + `) {
continue;
}
for (int wC = 0; wC < ` + p + `; wC++) {
int xC = xCCorner + wC * ` + u + `;
if (xC < 0 || xC >= ` + t.inWidth + `) {
continue;
}
for (int d1 = 0; d1 < ` + f + `; d1 += 4) {
vec4 xValues = vec4(
getX(batch, xF, xR, xC, d1),
getX(batch, xF, xR, xC, d1 + 1),
getX(batch, xF, xR, xC, d1 + 2),
getX(batch, xF, xR, xC, d1 + 3)
);
vec4 wValues = vec4(
getW(wF, wR, wC, d1, d2),
getW(wF, wR, wC, d1 + 1, d2),
getW(wF, wR, wC, d1 + 2, d2),
getW(wF, wR, wC, d1 + 3, d2)
);
dotProd += dot(xValues, wValues);
}
if (` + (m === 1) + `) {
dotProd +=
getX(batch, xF, xR, xC, ` + f + `) *
getW(wF, wR, wC, ` + f + `, d2);
} else if (` + (m === 2) + `) {
vec2 xValues = vec2(
getX(batch, xF, xR, xC, ` + f + `),
getX(batch, xF, xR, xC, ` + f + ` + 1)
);
vec2 wValues = vec2(
getW(wF, wR, wC, ` + f + `, d2),
getW(wF, wR, wC, ` + f + ` + 1, d2)
);
dotProd += dot(xValues, wValues);
} else if (` + (m === 3) + `) {
vec3 xValues = vec3(
getX(batch, xF, xR, xC, ` + f + `),
getX(batch, xF, xR, xC, ` + f + ` + 1),
getX(batch, xF, xR, xC, ` + f + ` + 2)
);
vec3 wValues = vec3(
getW(wF, wR, wC, ` + f + `, d2),
getW(wF, wR, wC, ` + f + ` + 1, d2),
getW(wF, wR, wC, ` + f + ` + 2, d2)
);
dotProd += dot(xValues, wValues);
}
}
}
}
setOutput(dotProd);
}
`;
}
return n;
}();
var xb = function() {
function n(t, e, r, i) {
e === void 0 && (e = false), r === void 0 && (r = null), i === void 0 && (i = false), this.variableNames = ["x", "W"], this.outputShape = t.outShape;
var a = t.inHeight, s = t.inWidth, o = t.padInfo.top, c = t.padInfo.left, l = t.strideHeight, u = t.strideWidth, h = t.dilationHeight, d = t.dilationWidth, p = t.filterHeight, f = t.filterWidth, m = t.outChannels / t.inChannels, g = "", y = "";
r && (i ? g = `float activation(float a) {
float b = getPreluActivationWeightsAtOutCoords();
` + r + `
}` : g = `
float activation(float x) {
` + r + `
}
`, y = "result = activation(result);");
var w = e ? "result += getBiasAtOutCoords();" : "";
e && this.variableNames.push("bias"), i && this.variableNames.push("preluActivationWeights"), this.userCode = `
` + g + `
const ivec2 strides = ivec2(` + l + ", " + u + `);
const ivec2 pads = ivec2(` + o + ", " + c + `);
void main() {
ivec4 coords = getOutputCoords();
int batch = coords.x;
ivec2 xRCCorner = coords.yz * strides - pads;
int d2 = coords.w;
int d1 = d2 / ` + m + `;
int q = d2 - d1 * ` + m + `;
int xRCorner = xRCCorner.x;
int xCCorner = xRCCorner.y;
// Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0;
// TO DO(dsmilkov): Flatten the two for loops and vec4 the operations.
for (int wR = 0; wR < ` + p + `; wR++) {
int xR = xRCorner + wR * ` + h + `;
if (xR < 0 || xR >= ` + a + `) {
continue;
}
for (int wC = 0; wC < ` + f + `; wC++) {
int xC = xCCorner + wC * ` + d + `;
if (xC < 0 || xC >= ` + s + `) {
continue;
}
float xVal = getX(batch, xR, xC, d1);
float wVal = getW(wR, wC, d1, q);
dotProd += xVal * wVal;
}
}
float result = dotProd;
` + w + `
` + y + `
setOutput(result);
}
`;
}
return n;
}();
var Lb = function() {
function n(t, e, r, i) {
e === void 0 && (e = false), r === void 0 && (r = null), i === void 0 && (i = false), this.variableNames = ["x", "W"], this.packedInputs = true, this.packedOutput = true, this.outputShape = t.outShape;
for (var a = t.inHeight, s = t.inWidth, o = t.padInfo.top, c = t.padInfo.left, l = t.strideHeight, u = t.strideWidth, h = t.dilationHeight, d = t.dilationWidth, p = t.filterHeight, f = t.filterWidth, m = f, g = "int xR; int xC; int xCOffset;", y = 0; y < p; y++)
for (var w = 0; w < f; w++)
g += `
vec4 xTexelR` + y + "C" + w * 2 + ` = vec4(0.);
vec4 wR` + y + "C" + w + ` = vec4(0.);
vec4 xR` + y + "C" + w + " = vec4(0.);";
for (var y = 0; y < p; y++)
for (var b = 0; b < m; b++) {
var w = b * 2;
if (g += `
xR = xRCorner + ` + y * h + `;
xC = xCCorner + ` + w * d + `;
`, u === 1) {
if (w < f && (c % 2 === 1 ? g += `
xCOffset = xC + 1;
if(xR >= 0 && xR < ` + a + " && xCOffset >= 0 && xCOffset < " + s + `) {
xTexelR` + y + "C" + w + ` = getX(batch, xR, xCOffset, d1);
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if(xCOffset + 1 >= ` + s + `) {
xTexelR` + y + "C" + w + `.zw = vec2(0.);
}
} else {
xTexelR` + y + "C" + w + ` = vec4(0.);
}
xCOffset = xC + 1 - 2;
if(xR >= 0 && xR < ` + a + " && xCOffset >= 0 && xCOffset < " + s + `) {
vec4 previous = getX(batch, xR, xCOffset, d1);
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if(xCOffset + 1 >= ` + s + `) {
previous.zw = vec2(0.);
}
xR` + y + "C" + w + " = vec4(previous.zw, xTexelR" + y + "C" + w + `.xy);
} else {
xR` + y + "C" + w + " = vec4(0, 0, xTexelR" + y + "C" + w + `.xy);
}
` : g += `
if(xR >= 0 && xR < ` + a + " && xC >= 0 && xC < " + s + `) {
xTexelR` + y + "C" + w + ` = getX(batch, xR, xC, d1);
} else {
xTexelR` + y + "C" + w + ` = vec4(0.);
}
xR` + y + "C" + w + " = xTexelR" + y + "C" + w + `;
`, w + 1 < f)) {
var x = c % 2 === 0 ? _.util.nearestLargerEven(d) : d;
d % 2 === 0 && c % 2 === 1 || d % 2 !== 0 && c % 2 !== 1 ? (g += `
xCOffset = xC + ` + c % 2 + " + " + x + `;
if(xR >= 0 && xR < ` + a + ` &&
xCOffset >= 0 && xCOffset < ` + s + `) {
xTexelR` + y + "C" + (w + 2) + ` = getX(batch, xR, xCOffset, d1);
}
`, d > 1 && (g += `
xCOffset -= 2;
if(xR >= 0 && xR < ` + a + ` &&
xCOffset >= 0 && xCOffset < ` + s + `) {
xTexelR` + y + "C" + w + ` = getX(batch, xR, xCOffset, d1);
} else {
xTexelR` + y + "C" + w + ` = vec4(0.);
}
`), g += `
xR` + y + "C" + (w + 1) + ` = vec4(
xTexelR` + y + "C" + w + ".zw, xTexelR" + y + "C" + (w + 2) + `.xy);
`) : g += `
xCOffset = xC + ` + x + `;
if(xR >= 0 && xR < ` + a + ` &&
xCOffset >= 0 && xCOffset < ` + s + `) {
xTexelR` + y + "C" + (w + 2) + ` = getX(batch, xR, xCOffset, d1);
}
xR` + y + "C" + (w + 1) + " = xTexelR" + y + "C" + (w + 2) + `;
`;
}
} else
w < f && (g += `
if(xR >= 0 && xR < ` + a + `) {
`, c % 2 === 1 ? (g += `
xCOffset = xC + 1 - ` + u + `;
if(xCOffset >= 0 && xCOffset < ` + s + `) {
xTexelR` + y + "C" + w + ` = getX(batch, xR, xCOffset, d1);
} else {
xTexelR` + y + "C" + w + ` = vec4(0.);
}
if(xC + 1 >= 0 && xC + 1 < ` + s + `) {
xTexelR` + y + "C" + (w + 2) + ` = getX(batch, xR, xC + 1, d1);
} else {
xTexelR` + y + "C" + (w + 2) + ` = vec4(0.);
}
xR` + y + "C" + w + ` = vec4(
xTexelR` + y + "C" + w + ".zw, xTexelR" + y + "C" + (w + 2) + `.zw);
`, w + 1 < f && (g += `
vec4 final = vec4(0.);
xCOffset = xC + 1 + ` + u + `;
if(xCOffset >= 0 && xCOffset < ` + s + `) {
final = getX(batch, xR, xCOffset, d1);
}
xR` + y + "C" + (w + 1) + " = vec4(xTexelR" + y + "C" + (w + 2) + `.xy, final.xy);
`)) : (g += `
if(xC >= 0 && xC < ` + s + `) {
xTexelR` + y + "C" + w + ` = getX(batch, xR, xC, d1);
} else {
xTexelR` + y + "C" + w + ` = vec4(0.);
}
xCOffset = xC + ` + u + `;
if(xCOffset >= 0 && xCOffset < ` + s + `) {
xTexelR` + y + "C" + (w + 2) + ` = getX(batch, xR, xCOffset, d1);
} else {
xTexelR` + y + "C" + (w + 2) + ` = vec4(0.);
}
xR` + y + "C" + w + ` = vec4(
xTexelR` + y + "C" + w + ".xy, xTexelR" + y + "C" + (w + 2) + `.xy);
`, w + 1 < f && (g += `
xR` + y + "C" + (w + 1) + ` = vec4(
xTexelR` + y + "C" + w + ".zw, xTexelR" + y + "C" + (w + 2) + `.zw);
`)), g += "}");
w < f && (g += `
vec4 wTexelR` + y + "C" + w + " = getW(" + y + ", " + w + `, d1, q);
wR` + y + "C" + w + " = vec4(wTexelR" + y + "C" + w + ".xz, wTexelR" + y + "C" + w + `.xz);
`, w + 1 < f && (g += `
vec4 wTexelR` + y + "C" + (w + 1) + " = getW(" + y + ", " + (w + 1) + `, d1, q);
wR` + y + "C" + (w + 1) + ` =
vec4(wTexelR` + y + "C" + (w + 1) + ".xz, wTexelR" + y + "C" + (w + 1) + ".xz);"));
}
for (var y = 0; y < p; y++)
for (var w = 0; w < f; w++)
g += "dotProd += xR" + y + "C" + w + " * wR" + y + "C" + w + ";";
var L = "", N = "";
r && (i ? L = `vec4 activation(vec4 a) {
vec4 b = getPreluActivationWeightsAtOutCoords();
` + r + `
}` : L = `vec4 activation(vec4 x) {
` + r + `
}`, N = "result = activation(result);");
var I = e ? "result += getBiasAtOutCoords();" : "";
e && this.variableNames.push("bias"), i && this.variableNames.push("preluActivationWeights"), this.userCode = `
` + L + `
const ivec2 strides = ivec2(` + l + ", " + u + `);
const ivec2 pads = ivec2(` + o + ", " + c + `);
void main() {
ivec4 coords = getOutputCoords();
int batch = coords.x;
ivec2 xRCCorner = coords.yz * strides - pads;
int d2 = coords.w;
int d1 = d2;
int q = 0;
int xRCorner = xRCCorner.x;
int xCCorner = xRCCorner.y;
vec4 dotProd = vec4(0.);
` + g + `
vec4 result = dotProd;
` + I + `
` + N + `
setOutput(result);
}
`;
}
return n;
}();
var yB = function() {
function n(t, e, r, i, a) {
this.variableNames = ["Image", "Boxes", "BoxInd"], this.outputShape = [];
var s = t[0], o = t[1], c = t[2], l = t[3], u = e[0], h = r[0], d = r[1];
this.outputShape = [u, h, d, l];
var p = i === "bilinear" ? 1 : 0, f = [o - 1 + ".0", c - 1 + ".0"], m = f[0], g = f[1], y = h > 1 ? ["" + (o - 1) / (h - 1), "(y2-y1) * height_ratio", "y1*" + m + " + float(y)*(height_scale)"] : ["0.0", "0.0", "0.5 * (y1+y2) * " + m], w = y[0], b = y[1], x = y[2], L = d > 1 ? ["" + (c - 1) / (d - 1), "(x2-x1) * width_ratio", "x1*" + g + " + float(x)*(width_scale)"] : ["0.0", "0.0", "0.5 * (x1+x2) * " + g], N = L[0], I = L[1], C = L[2];
this.userCode = `
const float height_ratio = float(` + w + `);
const float width_ratio = float(` + N + `);
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int y = coords[1];
int x = coords[2];
int d = coords[3];
// get box vals
float y1 = getBoxes(b,0);
float x1 = getBoxes(b,1);
float y2 = getBoxes(b,2);
float x2 = getBoxes(b,3);
// get image in batch index
int bInd = round(getBoxInd(b));
if(bInd < 0 || bInd >= ` + s + `) {
return;
}
float height_scale = ` + b + `;
float width_scale = ` + I + `;
float in_y = ` + x + `;
if( in_y < 0.0 || in_y > ` + m + ` ) {
setOutput(float(` + a + `));
return;
}
float in_x = ` + C + `;
if( in_x < 0.0 || in_x > ` + g + ` ) {
setOutput(float(` + a + `));
return;
}
vec2 sourceFracIndexCR = vec2(in_x,in_y);
if(` + p + ` == 1) {
// Compute the four integer indices.
ivec2 sourceFloorCR = ivec2(sourceFracIndexCR);
ivec2 sourceCeilCR = ivec2(ceil(sourceFracIndexCR));
float topLeft = getImage(b, sourceFloorCR.y, sourceFloorCR.x, d);
float bottomLeft = getImage(b, sourceCeilCR.y, sourceFloorCR.x, d);
float topRight = getImage(b, sourceFloorCR.y, sourceCeilCR.x, d);
float bottomRight = getImage(b, sourceCeilCR.y, sourceCeilCR.x, d);
vec2 fracCR = sourceFracIndexCR - vec2(sourceFloorCR);
float top = topLeft + (topRight - topLeft) * fracCR.x;
float bottom = bottomLeft + (bottomRight - bottomLeft) * fracCR.x;
float newValue = top + (bottom - top) * fracCR.y;
setOutput(newValue);
} else {
// Compute the coordinators of nearest neighbor point.
ivec2 sourceNearestCR = ivec2(floor(
sourceFracIndexCR + vec2(0.5,0.5)));
float newValue = getImage(b, sourceNearestCR.y, sourceNearestCR.x, d);
setOutput(newValue);
}
}
`;
}
return n;
}(), Ab = function() {
function n(t, e, r) {
this.variableNames = ["x"], this.outputShape = t;
var i = t.length, a = e ? "0.0" : "getX(" + Sb(i, "coords") + ")", s = t[t.length - 1], o = "", c = "";
e ? (o = r ? "end != " + (s - 1) : "end != 0", c = r ? "end + 1" : "end - 1") : (o = r ? "end + pow2 < " + s : "end >= pow2", c = r ? "end + pow2" : "end - pow2"), this.userCode = `
uniform float index;
void main() {
` + Ze(i) + ` coords = getOutputCoords();
int end = ` + Ib(i, "coords") + `;
float val = ` + a + `;
int pow2 = int(pow(2.0, index));
if (` + o + `) {
int idx = ` + c + `;
` + Ib(i, "coords") + ` = idx;
val += getX(` + Sb(i, "coords") + `);
}
setOutput(val);
}
`;
}
return n.prototype.getCustomSetupFunc = function(t) {
var e = this;
return function(r, i) {
e.index == null && (e.index = r.getUniformLocation(i, "index")), r.gl.uniform1f(e.index, t);
};
}, n;
}();
function Sb(n, t) {
if (n === 1)
return "" + t;
if (n === 2)
return t + ".x, " + t + ".y";
if (n === 3)
return t + ".x, " + t + ".y, " + t + ".z";
if (n === 4)
return t + ".x, " + t + ".y, " + t + ".z, " + t + ".w";
throw Error("Cumulative sum for rank " + n + " is not yet supported");
}
function Ib(n, t) {
if (n === 1)
return "" + t;
if (n === 2)
return t + ".y";
if (n === 3)
return t + ".z";
if (n === 4)
return t + ".w";
throw Error("Cumulative sum for rank " + n + " is not yet supported");
}
var vB = function() {
function n(t) {
this.variableNames = ["A"], this.packedInputs = false, this.packedOutput = true, this.outPackingScheme = rs.DENSE;
var e = as(t), r = Bt();
this.outputShape = t, this.userCode = `
ivec3 outCoordsFromFlatIndex(int index) {
` + gi(["r", "c", "d"], t) + `
return ivec3(r, c, d);
}
void main() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(` + e[0] + ", " + e[1] + `));
int index = 4 * (resTexRC.x * ` + e[1] + ` + resTexRC.y);
vec4 result = vec4(0.);
for (int i=0; i<4; i++) {
int flatIndex = index + i;
ivec3 rc = outCoordsFromFlatIndex(flatIndex);
result[i] = getA(rc.x, rc.y, rc.z);
}
` + r.output + ` = result;
}
`;
}
return n;
}();
var wB = function() {
function n(t) {
this.variableNames = ["A"], this.packedInputs = true, this.packedOutput = true, this.outPackingScheme = rs.DENSE;
var e = as(t), r = Bt();
this.outputShape = t, this.userCode = `
ivec3 outCoordsFromFlatIndex(int index) {
` + gi(["r", "c", "d"], t) + `
return ivec3(r, c, d);
}
void main() {
ivec2 resTexRC = ivec2(resultUV.yx *
vec2(` + e[0] + ", " + e[1] + `));
int index = 4 * (resTexRC.x * ` + e[1] + ` + resTexRC.y);
vec4 result = vec4(0.);
for (int i=0; i<4; i++) {
int flatIndex = index + i;
ivec3 rc = outCoordsFromFlatIndex(flatIndex);
result[i] = getChannel(getA(rc.x, rc.y, rc.z), vec2(rc.y, rc.z));
}
` + r.output + ` = result;
}
`;
}
return n;
}();
var bB = function() {
function n(t, e, r) {
this.variableNames = ["x"], this.outputShape = [], this.outputShape = t, this.blockSize = e, this.dataFormat = r, this.userCode = `
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int h = ` + this.getHeightCoordString() + `;
int w = ` + this.getWidthCoordString() + `;
int d = ` + this.getDepthCoordString() + `;
int in_h = h / ` + e + `;
int offset_h = imod(h, ` + e + `);
int in_w = w / ` + e + `;
int offset_w = imod(w, ` + e + `);
int offset_d = (offset_h * ` + e + ` + offset_w) *
` + this.getOutputDepthSize() + `;
int in_d = d + offset_d;
float result = ` + this.getInputSamplingString() + `;
setOutput(result);
}
`;
}
return n.prototype.getHeightCoordString = function() {
return this.dataFormat === "NHWC" ? "coords[1]" : "coords[2]";
}, n.prototype.getWidthCoordString = function() {
return this.dataFormat === "NHWC" ? "coords[2]" : "coords[3]";
}, n.prototype.getDepthCoordString = function() {
return this.dataFormat === "NHWC" ? "coords[3]" : "coords[1]";
}, n.prototype.getOutputDepthSize = function() {
return this.dataFormat === "NHWC" ? this.outputShape[3] : this.outputShape[1];
}, n.prototype.getInputSamplingString = function() {
return this.dataFormat === "NHWC" ? "getX(b, in_h, in_w, in_d)" : "getX(b, in_d, in_h, in_w)";
}, n;
}();
var xB = function() {
function n(t) {
this.variableNames = ["X"], this.outputShape = [t, t], this.userCode = `
void main() {
ivec2 coords = getOutputCoords();
float val = coords[0] == coords[1] ? getX(coords[0]) : 0.0;
setOutput(val);
}
`;
}
return n;
}();
var LB = function() {
function n(t) {
this.variableNames = ["A"], this.outTexUsage = cn.DOWNLOAD;
var e = Bt();
this.outputShape = t, this.userCode = `
` + pb + `
void main() {
float x = getAAtOutCoords();
` + e.output + ` = encode_float(x);
}
`;
}
return n;
}();
var SB = function() {
function n(t) {
this.variableNames = ["A"], this.packedInputs = true, this.packedOutput = false, this.outTexUsage = cn.DOWNLOAD;
var e = Bt();
this.outputShape = t, this.userCode = `
` + pb + `
void main() {
ivec3 coords = getOutputCoords();
float x = getChannel(getAAtOutCoords(), vec2(coords.y, coords.z));
` + e.output + ` = encode_float(x);
}
`;
}
return n;
}();
var IB = function() {
function n(t, e, r) {
r === void 0 && (r = false), this.variableNames = ["A"];
var i = Bt(), a = e[0], s = e[1];
this.outputShape = t;
var o = "result";
r && (o = "floor(result * 255. + 0.5)"), this.userCode = `
` + $d(t) + `
void main() {
ivec3 coords = getOutputCoords();
int flatIndex = getFlatIndex(coords);
int offset = imod(flatIndex, 4);
flatIndex = idiv(flatIndex, 4, 1.);
int r = flatIndex / ` + s + `;
int c = imod(flatIndex, ` + s + `);
vec2 uv = (vec2(c, r) + halfCR) / vec2(` + s + ".0, " + a + `.0);
vec4 values = ` + i.texture2D + `(A, uv);
float result;
if(offset == 0) {
result = values[0];
} else if(offset == 1) {
result = values[1];
} else if(offset == 2) {
result = values[2];
} else {
result = values[3];
}
` + i.output + " = vec4(" + o + `, 0., 0., 0.);
}
`;
}
return n;
}();
var AB = function() {
function n(t, e, r) {
r === void 0 && (r = false), this.variableNames = ["A"], this.packedInputs = false, this.packedOutput = true;
var i = Bt(), a = e[0], s = e[1];
this.outputShape = t;
var o = "", c = "result";
r && (c = "floor(result * 255. + 0.5)");
for (var l = 0; l <= 1; l++)
for (var u = 0; u <= 1; u++) {
var h = l * 2 + u;
o += `
localCoords = coords;
if(localCoords[2] + ` + u + " < " + t[2] + `) {
localCoords[2] += ` + u + `;
if(localCoords[1] + ` + l + " < " + t[1] + `) {
localCoords[1] += ` + l + `;
flatIndex = getFlatIndex(localCoords);
offset = imod(flatIndex, 4);
flatIndex = idiv(flatIndex, 4, 1.);
r = flatIndex / ` + s + `;
c = imod(flatIndex, ` + s + `);
uv = (vec2(c, r) + halfCR) / vec2(` + s + ".0, " + a + `.0);
values = ` + i.texture2D + `(A, uv);
if(offset == 0) {
result[` + h + `] = values[0];
} else if(offset == 1) {
result[` + h + `] = values[1];
} else if(offset == 2) {
result[` + h + `] = values[2];
} else {
result[` + h + `] = values[3];
}
}
}
`;
}
this.userCode = `
` + $d(t) + `
void main() {
ivec3 coords = getOutputCoords();
vec4 result = vec4(0.);
int flatIndex, r, c, offset;
ivec3 localCoords;
vec2 uv;
vec4 values;
` + o + `
` + i.output + " = " + c + `;
}
`;
}
return n;
}();
var TB = function() {
function n(t, e) {
this.outputShape = [], this.variableNames = ["x"], this.outputShape = t, this.userCode = `
uniform float value;
void main() {
// Input can be obtained from uniform value.
setOutput(value);
}
`;
}
return n.prototype.getCustomSetupFunc = function(t) {
var e = this;
return function(r, i) {
e.valueLoc == null && (e.valueLoc = r.getUniformLocationNoThrow(i, "value")), r.gl.uniform1f(e.valueLoc, t);
};
}, n;
}();
var _B = function() {
function n(t, e, r) {
this.variableNames = ["A", "indices"];
var i = t.slice();
i[r] = e, this.outputShape = i, this.rank = i.length;
var a = Ze(this.rank), s = NB(t, r);
this.userCode = `
void main() {
` + a + ` resRC = getOutputCoords();
setOutput(getA(` + s + `));
}
`;
}
return n;
}();
function NB(n, t) {
var e = n.length;
if (e > 4)
throw Error("Gather for rank " + e + " is not yet supported");
if (e === 1)
return "int(getIndices(resRC))";
for (var r = ["resRC.x", "resRC.y", "resRC.z", "resRC.w"], i = [], a = 0; a < n.length; a++)
a === t ? i.push("int(getIndices(" + r[a] + "))") : i.push("" + r[a]);
return i.join();
}
var CB = function() {
function n(t, e, r) {
this.sliceDim = t, this.strides = e, this.variableNames = ["x", "indices"], this.outputShape = r;
var i = Ze(e.length), a = Ze(r.length), s = this.sliceDim > 1 ? "strides[j]" : "strides";
this.userCode = `
` + i + " strides = " + i + "(" + this.strides + `);
void main() {
` + a + ` coords = getOutputCoords();
int flattenIndex = 0;
for (int j = 0; j < ` + this.sliceDim + `; j++) {
int index = round(getIndices(coords[0], j));
flattenIndex += index * ` + s + `;
}
setOutput(getX(flattenIndex, coords[1]));
}
`;
}
return n;
}();
function Tb(n) {
var t = Bt(), e = t.version + `
precision highp float;
` + t.attribute + ` vec3 clipSpacePos;
` + t.attribute + ` vec2 uv;
` + t.varyingVs + ` vec2 resultUV;
void main() {
gl_Position = vec4(clipSpacePos, 1);
resultUV = uv;
}`;
return Gw(n, e);
}
function Nb(n) {
var t = new Float32Array([-1, 1, 0, 0, 1, -1, -1, 0, 0, 0, 1, 1, 0, 1, 1, 1, -1, 0, 1, 0]);
return jw(n, t);
}
function _b(n) {
var t = new Uint16Array([0, 1, 2, 2, 1, 3]);
return $w(n, t);
}
function ls(n, t, e, r, i, a) {
Jw(t, e);
var s = Xw(n), o = n.TEXTURE_2D;
return de(n, function() {
return n.bindTexture(o, s);
}), de(n, function() {
return n.texParameteri(o, n.TEXTURE_WRAP_S, n.CLAMP_TO_EDGE);
}), de(n, function() {
return n.texParameteri(o, n.TEXTURE_WRAP_T, n.CLAMP_TO_EDGE);
}), de(n, function() {
return n.texParameteri(o, n.TEXTURE_MIN_FILTER, n.NEAREST);
}), de(n, function() {
return n.texParameteri(o, n.TEXTURE_MAG_FILTER, n.NEAREST);
}), de(n, function() {
return n.texImage2D(o, 0, r, t, e, 0, i, a, null);
}), de(n, function() {
return n.bindTexture(n.TEXTURE_2D, null);
}), s;
}
function Xd(n) {
return n.internalFormatFloat;
}
function Cb(n, t, e, r) {
var i = is(t, e), a = i[0], s = i[1];
return ls(n, a, s, Xd(r), r.textureFormatFloat, n.FLOAT);
}
function Jd(n) {
return n.internalFormatHalfFloat;
}
function Rb(n, t, e, r) {
var i = is(t, e), a = i[0], s = i[1];
return ls(n, a, s, Jd(r), r.textureFormatFloat, r.textureTypeHalfFloat);
}
function Zd(n) {
return n.downloadTextureFormat;
}
function Ob(n, t, e, r) {
var i = is(t, e), a = i[0], s = i[1];
return ls(n, a, s, Zd(r), n.RGBA, n.UNSIGNED_BYTE);
}
function Qd(n) {
return n.internalFormatPackedFloat;
}
function Eb(n, t, e, r) {
var i = ta(t, e), a = i[0], s = i[1];
return ls(n, a, s, Qd(r), n.RGBA, n.FLOAT);
}
function ep(n) {
return n.internalFormatPackedHalfFloat;
}
function Db(n, t, e, r) {
var i = ta(t, e), a = i[0], s = i[1];
return ls(n, a, s, ep(r), n.RGBA, r.textureTypeHalfFloat);
}
function kb(n, t, e) {
var r = 0, i = 3 * 4, a = 3 * 4 + 2 * 4;
de(n, function() {
return n.bindBuffer(n.ARRAY_BUFFER, e);
});
var s = Vd(n, t, "clipSpacePos", e, 3, a, r);
return s && Vd(n, t, "uv", e, 2, a, i);
}
function Fb(n, t, e, r, i, a) {
de(n, function() {
return n.bindTexture(n.TEXTURE_2D, t);
});
var s, o, c;
i instanceof Uint8Array ? (s = new Uint8Array(e * r * 4), o = n.UNSIGNED_BYTE, c = n.RGBA) : (s = new Float32Array(e * r * 4), o = n.FLOAT, c = a.internalFormatPackedFloat), s.set(i), de(n, function() {
return n.texImage2D(n.TEXTURE_2D, 0, c, e, r, 0, n.RGBA, o, s);
}), de(n, function() {
return n.bindTexture(n.TEXTURE_2D, null);
});
}
function Wb(n, t, e) {
de(n, function() {
return n.bindTexture(n.TEXTURE_2D, t);
}), e.data instanceof Uint8Array ? de(n, function() {
return n.texImage2D(n.TEXTURE_2D, 0, n.RGBA, e.width, e.height, 0, n.RGBA, n.UNSIGNED_BYTE, e.data);
}) : de(n, function() {
return n.texImage2D(n.TEXTURE_2D, 0, n.RGBA, n.RGBA, n.UNSIGNED_BYTE, e);
}), de(n, function() {
return n.bindTexture(n.TEXTURE_2D, null);
});
}
function Ub(n, t, e, r) {
var i = n.createBuffer();
de(n, function() {
return n.bindBuffer(n.PIXEL_PACK_BUFFER, i);
});
var a = 4, s = 4, o = a * s * t * e;
return de(n, function() {
return n.bufferData(n.PIXEL_PACK_BUFFER, o, n.STREAM_READ);
}), de(n, function() {
return n.readPixels(0, 0, e, t, n.RGBA, n.FLOAT, 0);
}), de(n, function() {
return n.bindBuffer(n.PIXEL_PACK_BUFFER, null);
}), i;
}
function Bb(n, t, e) {
var r = n, i = new Float32Array(e);
return r.bindBuffer(r.PIXEL_PACK_BUFFER, t), r.getBufferSubData(r.PIXEL_PACK_BUFFER, 0, i), r.bindBuffer(r.PIXEL_PACK_BUFFER, null), i;
}
function zb(n, t, e, r) {
var i = is(t, e), a = i[0], s = i[1], o = 4, c = new Uint8Array(aW(t * e, o));
return de(n, function() {
return n.readPixels(0, 0, a, s, r.downloadTextureFormat, n.UNSIGNED_BYTE, c);
}), new Float32Array(c.buffer);
}
function Pb(n, t, e, r, i, a, s, o) {
var c = n, l = new Float32Array(sW(a, s));
return c.bindBuffer(c.PIXEL_PACK_BUFFER, t), c.getBufferSubData(c.PIXEL_PACK_BUFFER, 0, l), c.bindBuffer(c.PIXEL_PACK_BUFFER, null), l;
}
function Mb(n, t, e) {
var r = new Float32Array(t * e * 4);
return de(n, function() {
return n.readPixels(0, 0, e, t, n.RGBA, n.FLOAT, r);
}), r;
}
var RB = {__proto__: null, createVertexShader: Tb, createVertexBuffer: Nb, createIndexBuffer: _b, getInternalFormatForFloat32MatrixTexture: Xd, createFloat32MatrixTexture: Cb, getInternalFormatForFloat16MatrixTexture: Jd, createFloat16MatrixTexture: Rb, getInternalFormatForUnsignedBytesMatrixTexture: Zd, createUnsignedBytesMatrixTexture: Ob, getInternalFormatForPackedMatrixTexture: Qd, createPackedMatrixTexture: Eb, getInternalFormatForFloat16PackedMatrixTexture: ep, createFloat16PackedMatrixTexture: Db, bindVertexProgramAttributeStreams: kb, uploadDenseMatrixToTexture: Fb, uploadPixelDataToTexture: Wb, createBufferFromOutputTexture: Ub, downloadFloat32MatrixFromBuffer: Bb, downloadByteEncodedFloatMatrixFromOutputTexture: zb, downloadPackedMatrixFromBuffer: Pb, downloadMatrixFromPackedOutputTexture: Mb};
var Hb = function() {
function n(t) {
this.outputTexture = null, this.program = null, this.disposed = false, this.vertexAttrsAreBound = false, this.itemsToPoll = [];
var e = _.env().getNumber("WEBGL_VERSION");
t != null ? (this.gl = t, Mw(e, t)) : this.gl = zn(e);
var r = "WEBGL_color_buffer_float", i = "EXT_color_buffer_half_float";
if (_.env().getNumber("WEBGL_VERSION") === 1) {
var a = "OES_texture_float", s = "OES_texture_half_float";
if (this.textureFloatExtension = ss(this.gl, a), ln(this.gl, s))
this.textureHalfFloatExtension = ss(this.gl, s);
else if (_.env().get("WEBGL_FORCE_F16_TEXTURES"))
throw new Error("GL context does not support half float textures, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.");
if (this.colorBufferFloatExtension = this.gl.getExtension(r), ln(this.gl, i))
this.colorBufferHalfFloatExtension = ss(this.gl, i);
else if (_.env().get("WEBGL_FORCE_F16_TEXTURES"))
throw new Error("GL context does not support color renderable half floats, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.");
} else if (r = "EXT_color_buffer_float", ln(this.gl, r))
this.colorBufferFloatExtension = this.gl.getExtension(r);
else if (ln(this.gl, i))
this.colorBufferHalfFloatExtension = this.gl.getExtension(i);
else
throw new Error("GL context does not support color renderable floats");
this.vertexBuffer = Nb(this.gl), this.indexBuffer = _b(this.gl), this.framebuffer = Zw(this.gl), this.textureConfig = Hd(this.gl, this.textureHalfFloatExtension);
}
return Object.defineProperty(n.prototype, "debug", {get: function() {
return _.env().getBool("DEBUG");
}, enumerable: true, configurable: true}), n.prototype.dispose = function() {
var t = this;
if (this.disposed)
return;
this.program != null && console.warn("Disposing a GPGPUContext that still has a bound WebGLProgram. This is probably a resource leak, delete the program with GPGPUContext.deleteProgram before disposing."), this.outputTexture != null && console.warn("Disposing a GPGPUContext that still has a bound output matrix texture. This is probably a resource leak, delete the output matrix texture with GPGPUContext.deleteMatrixTexture before disposing.");
var e = this.gl;
de(e, function() {
return e.finish();
}), de(e, function() {
return e.bindFramebuffer(e.FRAMEBUFFER, null);
}), de(e, function() {
return e.deleteFramebuffer(t.framebuffer);
}), de(e, function() {
return e.bindBuffer(e.ARRAY_BUFFER, null);
}), de(e, function() {
return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, null);
}), de(e, function() {
return e.deleteBuffer(t.indexBuffer);
}), this.disposed = true;
}, n.prototype.createFloat32MatrixTexture = function(t, e) {
return this.throwIfDisposed(), Cb(this.gl, t, e, this.textureConfig);
}, n.prototype.createFloat16MatrixTexture = function(t, e) {
return this.throwIfDisposed(), Rb(this.gl, t, e, this.textureConfig);
}, n.prototype.createUnsignedBytesMatrixTexture = function(t, e) {
return this.throwIfDisposed(), Ob(this.gl, t, e, this.textureConfig);
}, n.prototype.uploadPixelDataToTexture = function(t, e) {
this.throwIfDisposed(), Wb(this.gl, t, e);
}, n.prototype.uploadDenseMatrixToTexture = function(t, e, r, i) {
this.throwIfDisposed(), Fb(this.gl, t, e, r, i, this.textureConfig);
}, n.prototype.createFloat16PackedMatrixTexture = function(t, e) {
return this.throwIfDisposed(), Db(this.gl, t, e, this.textureConfig);
}, n.prototype.createPackedMatrixTexture = function(t, e) {
return this.throwIfDisposed(), Eb(this.gl, t, e, this.textureConfig);
}, n.prototype.deleteMatrixTexture = function(t) {
var e = this;
this.throwIfDisposed(), this.outputTexture === t && (Gd(this.gl, this.framebuffer), this.outputTexture = null), de(this.gl, function() {
return e.gl.deleteTexture(t);
});
}, n.prototype.downloadByteEncodedFloatMatrixFromOutputTexture = function(t, e, r) {
var i = this;
return this.downloadMatrixDriver(t, function() {
return zb(i.gl, e, r, i.textureConfig);
});
}, n.prototype.downloadPackedMatrixFromBuffer = function(t, e, r, i, a, s) {
return Pb(this.gl, t, e, r, i, a, s, this.textureConfig);
}, n.prototype.downloadFloat32MatrixFromBuffer = function(t, e) {
return Bb(this.gl, t, e);
}, n.prototype.createBufferFromTexture = function(t, e, r) {
this.bindTextureToFrameBuffer(t);
var i = Ub(this.gl, e, r, this.textureConfig);
return this.unbindTextureToFrameBuffer(), i;
}, n.prototype.createAndWaitForFence = function() {
var t = this.createFence(this.gl);
return this.pollFence(t);
}, n.prototype.createFence = function(t) {
var e = this, r, i;
if (_.env().getBool("WEBGL_FENCE_API_ENABLED")) {
var a = t, s = a.fenceSync(a.SYNC_GPU_COMMANDS_COMPLETE, 0);
t.flush(), i = function() {
var o = a.clientWaitSync(s, 0, 0);
return o === a.ALREADY_SIGNALED || o === a.CONDITION_SATISFIED;
}, r = s;
} else
_.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") > 0 ? (r = this.beginQuery(), this.endQuery(), i = function() {
return e.isQueryAvailable(r, _.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"));
}) : i = function() {
return true;
};
return {query: r, isFencePassed: i};
}, n.prototype.downloadMatrixFromPackedTexture = function(t, e, r) {
var i = this;
return this.downloadMatrixDriver(t, function() {
return Mb(i.gl, e, r);
});
}, n.prototype.createProgram = function(t) {
this.throwIfDisposed();
var e = this.gl, r = qw(e, t), i = Tb(e), a = Yw(e);
return de(e, function() {
return e.attachShader(a, i);
}), de(e, function() {
return e.attachShader(a, r);
}), Kw(e, a), this.debug && Mo(e, a), this.vertexAttrsAreBound || (this.setProgram(a), this.vertexAttrsAreBound = kb(e, this.program, this.vertexBuffer)), a;
}, n.prototype.deleteProgram = function(t) {
var e = this;
this.throwIfDisposed(), t === this.program && (this.program = null), t != null && de(this.gl, function() {
return e.gl.deleteProgram(t);
});
}, n.prototype.setProgram = function(t) {
var e = this;
this.throwIfDisposed(), this.program = t, this.program != null && this.debug && Mo(this.gl, this.program), de(this.gl, function() {
return e.gl.useProgram(t);
});
}, n.prototype.getUniformLocation = function(t, e, r) {
return r === void 0 && (r = true), this.throwIfDisposed(), r ? tb(this.gl, t, e) : nb(this.gl, t, e);
}, n.prototype.getAttributeLocation = function(t, e) {
var r = this;
return this.throwIfDisposed(), de(this.gl, function() {
return r.gl.getAttribLocation(t, e);
});
}, n.prototype.getUniformLocationNoThrow = function(t, e) {
return this.throwIfDisposed(), this.gl.getUniformLocation(t, e);
}, n.prototype.setInputMatrixTexture = function(t, e, r) {
this.throwIfDisposed(), this.throwIfNoProgram(), rb(this.gl, t, e, r);
}, n.prototype.setOutputMatrixTexture = function(t, e, r) {
this.setOutputMatrixTextureDriver(t, r, e);
}, n.prototype.setOutputPackedMatrixTexture = function(t, e, r) {
this.throwIfDisposed();
var i = ta(e, r), a = i[0], s = i[1];
this.setOutputMatrixTextureDriver(t, a, s);
}, n.prototype.setOutputMatrixWriteRegion = function(t, e, r, i) {
this.setOutputMatrixWriteRegionDriver(r, t, i, e);
}, n.prototype.setOutputPackedMatrixWriteRegion = function(t, e, r, i) {
throw new Error("setOutputPackedMatrixWriteRegion not implemented.");
}, n.prototype.debugValidate = function() {
this.program != null && Mo(this.gl, this.program), os(this.gl);
}, n.prototype.executeProgram = function() {
this.throwIfDisposed(), this.throwIfNoProgram();
var t = this.gl;
this.debug && this.debugValidate(), de(t, function() {
return t.drawElements(t.TRIANGLES, 6, t.UNSIGNED_SHORT, 0);
});
}, n.prototype.blockUntilAllProgramsCompleted = function() {
var t = this;
this.throwIfDisposed(), de(this.gl, function() {
return t.gl.finish();
});
}, n.prototype.getQueryTimerExtension = function() {
return this.disjointQueryTimerExtension == null && (this.disjointQueryTimerExtension = ss(this.gl, _.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") === 2 ? "EXT_disjoint_timer_query_webgl2" : "EXT_disjoint_timer_query")), this.disjointQueryTimerExtension;
}, n.prototype.getQueryTimerExtensionWebGL2 = function() {
return this.getQueryTimerExtension();
}, n.prototype.getQueryTimerExtensionWebGL1 = function() {
return this.getQueryTimerExtension();
}, n.prototype.beginQuery = function() {
if (_.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") === 2) {
var t = this.gl, e = this.getQueryTimerExtensionWebGL2(), r = t.createQuery();
return t.beginQuery(e.TIME_ELAPSED_EXT, r), r;
}
var i = this.getQueryTimerExtensionWebGL1(), a = i.createQueryEXT();
return i.beginQueryEXT(i.TIME_ELAPSED_EXT, a), a;
}, n.prototype.endQuery = function() {
if (_.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") === 2) {
var t = this.gl, e = this.getQueryTimerExtensionWebGL2();
t.endQuery(e.TIME_ELAPSED_EXT);
return;
}
var r = this.getQueryTimerExtensionWebGL1();
r.endQueryEXT(r.TIME_ELAPSED_EXT);
}, n.prototype.waitForQueryAndGetTime = function(t) {
return zo(this, void 0, void 0, function() {
var e = this;
return Po(this, function(r) {
switch (r.label) {
case 0:
return [4, _.util.repeatedTry(function() {
return e.disposed || e.isQueryAvailable(t, _.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"));
})];
case 1:
return r.sent(), [2, this.getQueryTime(t, _.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))];
}
});
});
}, n.prototype.getQueryTime = function(t, e) {
if (e === 0)
return null;
if (e === 2) {
var r = this.gl, i = r.getQueryParameter(t, r.QUERY_RESULT);
return i / 1e6;
} else {
var a = this.getQueryTimerExtensionWebGL1(), i = a.getQueryObjectEXT(t, a.QUERY_RESULT_EXT);
return i / 1e6;
}
}, n.prototype.isQueryAvailable = function(t, e) {
if (e === 0)
return true;
if (e === 2) {
var r = this.gl, i = this.getQueryTimerExtensionWebGL2(), a = r.getQueryParameter(t, r.QUERY_RESULT_AVAILABLE);
return this.disjoint == null && (this.disjoint = this.gl.getParameter(i.GPU_DISJOINT_EXT)), a && !this.disjoint;
} else {
var i = this.getQueryTimerExtensionWebGL1(), a = i.getQueryObjectEXT(t, i.QUERY_RESULT_AVAILABLE_EXT);
return this.disjoint == null && (this.disjoint = this.gl.getParameter(i.GPU_DISJOINT_EXT)), a && !this.disjoint;
}
}, n.prototype.pollFence = function(t) {
var e = this;
return new Promise(function(r) {
e.addItemToPoll(function() {
return t.isFencePassed();
}, function() {
return r();
});
});
}, n.prototype.pollItems = function() {
for (var t = OB(this.itemsToPoll.map(function(i) {
return i.isDoneFn;
})), e = 0; e <= t; ++e) {
var r = this.itemsToPoll[e].resolveFn;
r();
}
this.itemsToPoll = this.itemsToPoll.slice(t + 1);
}, n.prototype.addItemToPoll = function(t, e) {
var r = this;
if (this.itemsToPoll.push({isDoneFn: t, resolveFn: e}), this.itemsToPoll.length > 1)
return;
_.util.repeatedTry(function() {
return r.pollItems(), r.itemsToPoll.length === 0;
});
}, n.prototype.bindTextureToFrameBuffer = function(t) {
this.throwIfDisposed(), Ho(this.gl, t, this.framebuffer), this.debug && os(this.gl);
}, n.prototype.unbindTextureToFrameBuffer = function() {
this.outputTexture != null ? (Ho(this.gl, this.outputTexture, this.framebuffer), this.debug && os(this.gl)) : Gd(this.gl, this.framebuffer);
}, n.prototype.downloadMatrixDriver = function(t, e) {
this.bindTextureToFrameBuffer(t);
var r = e();
return this.unbindTextureToFrameBuffer(), r;
}, n.prototype.setOutputMatrixTextureDriver = function(t, e, r) {
this.throwIfDisposed();
var i = this.gl;
Ho(i, t, this.framebuffer), this.debug && os(i), this.outputTexture = t, de(i, function() {
return i.viewport(0, 0, e, r);
}), de(i, function() {
return i.scissor(0, 0, e, r);
});
}, n.prototype.setOutputMatrixWriteRegionDriver = function(t, e, r, i) {
var a = this;
this.throwIfDisposed(), de(this.gl, function() {
return a.gl.scissor(t, e, r, i);
});
}, n.prototype.throwIfDisposed = function() {
if (this.disposed)
throw new Error("Attempted to use disposed GPGPUContext.");
}, n.prototype.throwIfNoProgram = function() {
if (this.program == null)
throw new Error("No GPU program is currently set.");
}, n;
}();
function OB(n) {
for (var t = 0; t < n.length; ++t) {
var e = n[t]();
if (!e)
break;
}
return t - 1;
}
function EB(n, t, e, r) {
var i = t.userCode, a = e.map(function(g, y) {
var w = {logicalShape: g.shape, texShape: g.isUniform ? null : g.texData.texShape, isUniform: g.isUniform, isPacked: g.isUniform ? false : g.texData.isPacked, flatOffset: null};
return g.texData != null && g.texData.slice != null && g.texData.slice.flatOffset > 0 && (w.flatOffset = g.texData.slice.flatOffset), {name: t.variableNames[y], shapeInfo: w};
}), s = a.map(function(g) {
return g.shapeInfo;
}), o = {logicalShape: r.shape, texShape: r.texData.texShape, isUniform: false, isPacked: r.texData.isPacked, flatOffset: null}, c = iU(a, o, i, t.packedInputs), l = n.createProgram(c), u = null, h = n.getUniformLocation(l, "NAN", false);
_.env().getNumber("WEBGL_VERSION") === 1 && (u = n.getUniformLocation(l, "INFINITY", false));
for (var d = {}, p = 0; p < t.variableNames.length; p++) {
var f = t.variableNames[p], m = false;
d[f] = n.getUniformLocation(l, f, m), d["offset" + f] = n.getUniformLocation(l, "offset" + f, m);
}
return {program: t, source: c, webGLProgram: l, uniformLocations: d, inShapeInfos: s, outShapeInfo: o, infLoc: u, nanLoc: h};
}
function Vb(n, t) {
if (n.length !== t.length)
throw Error("Binary was compiled with " + n.length + " inputs, but " + ("was executed with " + t.length + " inputs"));
n.forEach(function(e, r) {
var i = e.logicalShape, a = t[r], s = a.shape;
if (!_.util.arraysEqual(i, s))
throw Error("Binary was compiled with different shapes than " + ("the current args. Shapes " + i + " and " + s + " must match"));
if (e.isUniform && a.isUniform)
return;
var o = e.texShape, c = a.isUniform ? null : a.texData.texShape;
if (!_.util.arraysEqual(o, c))
throw Error("Binary was compiled with different texture shapes than the" + (" current args. Shape " + o + " and " + c + " must match"));
});
}
function DB(n, t, e, r, i) {
Vb(t.inShapeInfos, e), Vb([t.outShapeInfo], [r]);
var a = r.texData.texture, s = r.texData.texShape;
r.texData.isPacked ? n.setOutputPackedMatrixTexture(a, s[0], s[1]) : n.setOutputMatrixTexture(a, s[0], s[1]), n.setProgram(t.webGLProgram), _.env().getNumber("WEBGL_VERSION") === 1 && (t.infLoc !== null && n.gl.uniform1f(t.infLoc, Infinity)), t.nanLoc !== null && n.gl.uniform1f(t.nanLoc, NaN), e.forEach(function(o, c) {
var l = t.program.variableNames[c], u = t.uniformLocations[l], h = t.uniformLocations["offset" + l];
if (u == null)
return;
if (o.isUniform) {
if (_.util.sizeFromShape(o.shape) < 2)
n.gl.uniform1f(u, o.uniformValues[0]);
else {
var d = o.uniformValues;
d instanceof Float32Array || (d = new Float32Array(d)), n.gl.uniform1fv(u, d);
}
return;
}
o.texData.slice != null && h != null && n.gl.uniform1i(h, o.texData.slice.flatOffset), n.setInputMatrixTexture(o.texData.texture, u, c);
}), i != null && i(n, t.webGLProgram), n.executeProgram();
}
function kB(n, t, e) {
var r = "";
t.concat(e).forEach(function(s) {
var o = s.texData != null && s.texData.slice != null && s.texData.slice.flatOffset > 0, c = s.isUniform ? "uniform" : s.texData.texShape;
r += s.shape + "_" + c + "_" + o;
});
var i = n.userCode, a = n.constructor.name;
return a += "_" + r + "_" + i, a;
}
var FB = function() {
function n(t, e, r) {
this.variableNames = ["A"], this.packedInputs = true, this.packedOutput = true, this.outputShape = t;
for (var i = r.filterWidth, a = r.inChannels, s = r.strideWidth, o = r.strideHeight, c = r.padInfo, l = r.outWidth, u = r.dilationWidth, h = r.dilationHeight, d = r.dataFormat, p = c.left, f = c.top, m = a * i, g = Bt(), y = d === "channelsLast", w = y ? 0 : 1, b = y ? 1 : 2, x = "", L = 0; L <= 1; L++)
for (var N = 0; N <= 1; N++)
x += `
blockIndex = rc.y + ` + N + `;
pos = rc.x + ` + L + `;
if(blockIndex < ` + t[1] + " && pos < " + t[0] + `) {
offsetY = int(blockIndex / (` + l + ")) * " + o + " - " + f + `;
d0 = offsetY + ` + h + " * (pos / " + m + `);
if(d0 < ` + e[w] + ` && d0 >= 0) {
offsetX = int(mod(float(blockIndex), ` + l + ".) * " + s + ". - " + p + `.);
d1 = offsetX + ` + u + " * (int(mod(float(pos), " + m + ".) / " + a + `.));
if(d1 < ` + e[b] + ` && d1 >= 0) {
ch = int(mod(float(pos), ` + a + `.));
if (` + y + `) {
innerDims = vec2(d1, ch);
result[` + (L * 2 + N) + `] = getChannel(
getA(d0, int(innerDims.x),
int(innerDims.y)), innerDims);
} else {
innerDims = vec2(d0, d1);
result[` + (L * 2 + N) + `] = getChannel(
getA(ch, int(innerDims.x),
int(innerDims.y)), innerDims);
}
}
}
}
`;
this.userCode = `
void main() {
ivec2 rc = getOutputCoords();
vec4 result = vec4(0);
int blockIndex, pos, offsetY, d0, offsetX, d1, ch;
vec2 innerDims;
` + x + `
` + g.output + ` = result;
}
`;
}
return n;
}();
var WB = function() {
function n(t, e, r, i, a) {
this.variableNames = ["x"], this.outputShape = [];
var s = e, o = t[3] - 1;
this.outputShape = t;
var c, l = "float(" + r + ") + float(" + i + ") * sum";
a === 0.5 ? c = "inversesqrt(" + l + ")" : a === 1 ? c = "1.0/(" + l + ")" : c = "exp(log(" + l + ") * float(-" + a + "));", this.userCode = `
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int r = coords[1];
int c = coords[2];
int d = coords[3];
float x = getX(b, r, c, d);
float sum = 0.0;
for (int j = -` + s + "; j <= " + s + `; j++) {
int idx = d + j;
if (idx >= 0 && idx <= ` + o + `) {
float z = getX(b, r, c, idx);
sum += z * z;
}
}
float val = x * ` + c + `;
setOutput(val);
}
`;
}
return n;
}();
var UB = function() {
function n(t, e, r, i, a) {
this.variableNames = ["inputImage", "outputImage", "dy"], this.outputShape = [], this.outputShape = t, this.depth = t[3], this.depthRadius = e, this.bias = r, this.alpha = i, this.beta = a, this.userCode = `
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int r = coords[1];
int c = coords[2];
float result = 0.0;
for (int d = 0; d < ` + this.depth + `; ++d) {
int depthBegin = int(max(0.0, float(d - ` + e + `)));
int depthEnd = int(min(float(` + this.depth + `),
float(d + ` + e + ` + 1)));
const int MIN_DEPTH_BEGIN = 0;
const int MAX_DEPTH_END = ` + this.depth + `;
float norm = 0.0;
for (int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k) {
if (k < depthBegin){
continue;
}
else if (k >= depthBegin && k < depthEnd) {
norm += getInputImage(b, r, c, k) * getInputImage(b, r, c, k);
}
else {
break;
}
}
norm = float(` + i + ") * norm + float(" + r + `);
for(int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k){
if (k < depthBegin){
continue;
}
else if (k >= depthBegin && k < depthEnd){
float dyi = -2.0 * float(` + i + `)
* float(` + a + `)
* getInputImage(b ,r ,c, k) * getOutputImage(b, r, c, d)
/ norm;
if (k == d) {
dyi += pow(norm, -1.0 * ` + a + `);
}
if (k == coords[3]) {
dyi *= getDy(b, r, c, d);
result += dyi;
}
}
else {
break;
}
}
}
setOutput(result);
}
`;
}
return n;
}();
var BB = function() {
function n(t, e, r, i, a) {
this.variableNames = ["x"], this.outputShape = [], this.packedInputs = true, this.packedOutput = true;
var s = e, o = t[3] - 1;
this.outputShape = t;
var c, l = "float(" + r + ") + float(" + i + ") * sum";
a === 0.5 ? c = "inversesqrt(" + l + ")" : a === 1 ? c = "1.0/(" + l + ")" : c = "exp(log(" + l + ") * float(-" + a + "));", this.userCode = `
void main() {
ivec4 coords = getOutputCoords();
int b = coords.x;
int r = coords.y;
int c = coords.z;
int d = coords.w;
bool hasNextCol = d < ` + this.outputShape[3] + `;
bool hasNextRow = c < ` + this.outputShape[2] + `;
vec4 sum = vec4(0.);
vec4 xFragAtOutputCoords = getX(b, r, c, d);
vec4 xAtOutputCoords = vec4(
getChannel(xFragAtOutputCoords, vec2(c, d)),
hasNextCol ?
getChannel(xFragAtOutputCoords, vec2(c, d + 1)) : 0.0,
hasNextRow ?
getChannel(xFragAtOutputCoords , vec2(c + 1, d)) : 0.0,
(hasNextRow && hasNextCol) ?
getChannel(xFragAtOutputCoords, vec2(c + 1, d + 1)) : 0.0
);
int firstChannel = d - ` + s + `;
vec2 cache = vec2(0.);
if(firstChannel >= 0){
vec4 firstChannelFrag = getX(b, r, c, firstChannel);
cache.x = getChannel(firstChannelFrag, vec2(c, firstChannel));
if(hasNextRow){
cache.y = getChannel(firstChannelFrag, vec2(c + 1, firstChannel));
}
}
ivec2 depth = ivec2(d, d + 1);
for (int j = - ` + s + "; j <= " + s + `; j++) {
ivec2 idx = depth + j;
bvec2 aboveLowerBound = greaterThanEqual(idx, ivec2(0));
bvec2 belowUpperBound = lessThanEqual(idx, ivec2(` + o + `));
bool depthInRange = aboveLowerBound.x && belowUpperBound.x;
bool depthPlusOneInRange = aboveLowerBound.y && belowUpperBound.y;
if(depthInRange || depthPlusOneInRange){
vec4 z = vec4(0.);
vec4 xFragAtCurrentDepth;
z.xz = cache.xy;
if(depthPlusOneInRange && hasNextCol){
xFragAtCurrentDepth = idx.y != d ?
getX(b, r, c, idx.y) : xFragAtOutputCoords;
z.y = getChannel(xFragAtCurrentDepth, vec2(c, idx.y));
if(hasNextRow){
z.w = getChannel(xFragAtCurrentDepth, vec2(c + 1, idx.y));
}
}
cache.xy = z.yw;
sum += z * z;
}
}
vec4 result = xAtOutputCoords * ` + c + `;
setOutput(result);
}
`;
}
return n;
}();
var zB = function() {
function n(t) {
this.variableNames = ["dy", "maxPos"], this.outputShape = t.inShape;
var e = t.strideHeight, r = t.strideWidth, i = t.dilationHeight, a = t.effectiveFilterHeight, s = t.effectiveFilterWidth, o = a - 1 - t.padInfo.top, c = s - 1 - t.padInfo.left, l = a * s - 1;
this.userCode = `
const ivec2 pads = ivec2(` + o + ", " + c + `);
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int d = coords[3];
ivec2 dyRCCorner = coords.yz - pads;
int dyRCorner = dyRCCorner.x;
int dyCCorner = dyRCCorner.y;
// Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0;
for (int wR = 0; wR < ` + a + `;
wR += ` + i + `) {
float dyR = float(dyRCorner + wR) / ` + e + `.0;
if (dyR < 0.0 || dyR >= ` + t.outHeight + `.0 || fract(dyR) > 0.0) {
continue;
}
int idyR = int(dyR);
for (int wC = 0; wC < ` + s + `; wC++) {
float dyC = float(dyCCorner + wC) / ` + r + `.0;
if (dyC < 0.0 || dyC >= ` + t.outWidth + `.0 ||
fract(dyC) > 0.0) {
continue;
}
int idyC = int(dyC);
float dyValue = getDy(b, idyR, idyC, d);
int maxPosValue = ` + l + ` - int(getMaxPos(b, idyR, idyC, d));
// Get the current value, check it against the value from the
// position matrix.
int curPosValue = wR * ` + s + ` + wC;
float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);
dotProd += dyValue * mask;
}
}
setOutput(dotProd);
}
`;
}
return n;
}(), PB = function() {
function n(t) {
this.variableNames = ["dy", "maxPos"], this.outputShape = t.inShape;
var e = t.strideDepth, r = t.strideHeight, i = t.strideWidth, a = t.dilationDepth, s = t.dilationHeight, o = t.dilationWidth, c = t.effectiveFilterDepth, l = t.effectiveFilterHeight, u = t.effectiveFilterWidth, h = c - 1 - t.padInfo.front, d = l - 1 - t.padInfo.top, p = u - 1 - t.padInfo.left, f = c * l * u - 1;
this.userCode = `
const ivec3 pads = ivec3(` + h + ", " + d + ", " + p + `);
void main() {
ivec5 coords = getOutputCoords();
int batch = coords.x;
int ch = coords.u;
ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;
int dyDCorner = dyCorner.x;
int dyRCorner = dyCorner.y;
int dyCCorner = dyCorner.z;
// Convolve dy(?, ?, ?, ch) with pos mask(:, :, :, d) to get
// dx(xD, xR, xC, ch).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0;
for (int wD = 0; wD < ` + c + `;
wD += ` + a + `) {
float dyD = float(dyDCorner + wD) / ` + e + `.0;
if (dyD < 0.0 || dyD >= ` + t.outDepth + `.0 || fract(dyD) > 0.0) {
continue;
}
int idyD = int(dyD);
for (int wR = 0; wR < ` + l + `;
wR += ` + s + `) {
float dyR = float(dyRCorner + wR) / ` + r + `.0;
if (dyR < 0.0 || dyR >= ` + t.outHeight + `.0 ||
fract(dyR) > 0.0) {
continue;
}
int idyR = int(dyR);
for (int wC = 0; wC < ` + u + `;
wC += ` + o + `) {
float dyC = float(dyCCorner + wC) / ` + i + `.0;
if (dyC < 0.0 || dyC >= ` + t.outWidth + `.0 ||
fract(dyC) > 0.0) {
continue;
}
int idyC = int(dyC);
float dyValue = getDy(batch, idyD, idyR, idyC, ch);
int maxPosValue = ` + f + ` -
int(getMaxPos(batch, idyD, idyR, idyC, ch));
// Get the current value, check it against the value from the
// position matrix.
int curPosValue =
wD * ` + l + " * " + u + ` +
wR * ` + u + ` + wC;
float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);
dotProd += dyValue * mask;
}
}
}
setOutput(dotProd);
}
`;
}
return n;
}();
var tp = function() {
function n(t, e, r, i, a, s, o, c) {
i === void 0 && (i = false), a === void 0 && (a = false), s === void 0 && (s = false), o === void 0 && (o = null), c === void 0 && (c = false), this.variableNames = ["matrixA", "matrixB"], this.packedInputs = true, this.packedOutput = true, this.outputShape = r;
var l = i ? t[1] : t[2], u = Math.ceil(l / 2), h = i ? "i * 2, rc.y" : "rc.y, i * 2", d = a ? "rc.z, i * 2" : "i * 2, rc.z", p = i ? ["a.xxyy", "a.zzww"] : ["a.xxzz", "a.yyww"], f = a ? ["b.xzxz", "b.ywyw"] : ["b.xyxy", "b.zwzw"], m = "", g = "";
o && (c ? m = `vec4 activation(vec4 a) {
vec4 b = getPreluActivationWeightsAtOutCoords();
` + o + `
}` : m = `vec4 activation(vec4 x) {
` + o + `
}`, g = "result = activation(result);");
var y = s ? "result += getBiasAtOutCoords();" : "";
s && this.variableNames.push("bias"), c && this.variableNames.push("preluActivationWeights");
var w = "rc.x", b = "rc.x";
t[0] < e[0] ? w = "int(min(float(rc.x), " + (t[0] - 1) + ".))" : e[0] < t[0] && (b = "int(min(float(rc.x), " + (e[0] - 1) + ".))"), this.userCode = `
` + m + `
const float sharedDimension = ` + u + `.0;
vec4 dot2x2ARowBCol(ivec3 rc) {
vec4 result = vec4(0);
for (int i = 0; i < ` + u + `; i++) {
int batchA = ` + w + `;
int batchB = ` + b + `;
vec4 a = getMatrixA(batchA, ` + h + `);
vec4 b = getMatrixB(batchB, ` + d + `);
// These swizzled products need to be separately added.
// See: https://github.com/tensorflow/tfjs/issues/1735
result += (` + p[0] + " * " + f[0] + `);
result += (` + p[1] + " * " + f[1] + `);
}
return result;
}
void main() {
ivec3 rc = getOutputCoords();
vec4 result = dot2x2ARowBCol(rc);
` + y + `
` + g + `
setOutput(result);
}
`;
}
return n;
}();
var MB = function() {
function n(t, e, r) {
this.variableNames = ["probs"], this.outputShape = [t, r], this.userCode = `
uniform float seed;
void main() {
ivec2 coords = getOutputCoords();
int batch = coords[0];
float r = random(seed);
float cdf = 0.0;
for (int i = 0; i < ` + (e - 1) + `; i++) {
cdf += getProbs(batch, i);
if (r < cdf) {
setOutput(float(i));
return;
}
}
// If no other event happened, last event happened.
setOutput(float(` + (e - 1) + `));
}
`;
}
return n.prototype.getCustomSetupFunc = function(t) {
var e = this;
return function(r, i) {
e.seedLoc == null && (e.seedLoc = r.getUniformLocation(i, "seed")), r.gl.uniform1f(e.seedLoc, t);
};
}, n;
}();
var HB = function() {
function n(t, e, r, i) {
this.variableNames = ["indices"], this.outputShape = [t, e], this.userCode = `
void main() {
ivec2 coords = getOutputCoords();
int index = round(getIndices(coords.x));
setOutput(mix(float(` + i + "), float(" + r + `),
float(index == coords.y)));
}
`;
}
return n;
}();
var YB = function() {
function n(t) {
this.variableNames = ["A"], this.packedInputs = false, this.packedOutput = true, this.outputShape = t;
var e = t.length;
if (e === 0)
this.userCode = `
void main() {
setOutput(vec4(getA(), 0., 0., 0.));
}
`;
else {
var r = Ut("rc", e), i = Ze(e), a = VB(e, t, r), s = GB(e, t[t.length - 1], t[t.length - 2], r), o = qB(t, r);
this.userCode = `
void main() {
` + i + ` rc = getOutputCoords();
if(` + a + `) {
setOutput(vec4(0));
} else {
` + s + `
setOutput(vec4(` + o + `));
}
}
`;
}
}
return n;
}();
function KB(n, t) {
for (var e = [], r = 0; r <= 1; r++)
for (var i = 0; i <= 1; i++) {
for (var a = (r === 0 ? "r" : "rp1") + ", " + (i === 0 ? "c" : "cp1"), s = 2; s < n; s++)
a = t[t.length - 1 - s] + "," + a;
e.push(a);
}
return e;
}
function VB(n, t, e) {
if (n === 1)
return "rc > " + t[0];
for (var r = "", i = n - 2; i < n; i++)
r += e[i] + " >= " + t[i], i < n - 1 && (r += "||");
return r;
}
function GB(n, t, e, r) {
if (n === 1)
return "";
var i = r.slice(-2);
return `
int r = ` + i[0] + `;
int c = ` + i[1] + `;
int rp1 = r + 1;
int cp1 = c + 1;
bool cEdge = cp1 >= ` + t + `;
bool rEdge = rp1 >= ` + e + `;
`;
}
function qB(n, t) {
var e = n.length, r = KB(e, t);
return e === 1 ? `getA(rc),
rc + 1 >= ` + n[0] + ` ? 0. : getA(rc + 1),
0, 0` : "getA(" + r[0] + `),
cEdge ? 0. : getA(` + r[1] + `),
rEdge ? 0. : getA(` + r[2] + `),
rEdge || cEdge ? 0. : getA(` + r[3] + ")";
}
var jB = function() {
function n(t, e, r) {
this.variableNames = ["x"], this.outputShape = e.map(function(l, u) {
return l[0] + t[u] + l[1];
});
var i = t.length, a = Ze(i), s = e.map(function(l) {
return l[0];
}).join(","), o = e.map(function(l, u) {
return l[0] + t[u];
}).join(","), c = ["coords[0]", "coords[1]", "coords[2]", "coords[3]"].slice(0, i);
if (i === 1) {
this.userCode = `
int start = ` + s + `;
int end = ` + o + `;
void main() {
int outC = getOutputCoords();
if (outC < start || outC >= end) {
setOutput(float(` + r + `));
} else {
setOutput(getX(outC - start));
}
}
`;
return;
}
this.userCode = `
` + a + " start = " + a + "(" + s + `);
` + a + " end = " + a + "(" + o + `);
void main() {
` + a + ` outC = getOutputCoords();
if (any(lessThan(outC, start)) || any(greaterThanEqual(outC, end))) {
setOutput(float(` + r + `));
} else {
` + a + ` coords = outC - start;
setOutput(getX(` + c + `));
}
}
`;
}
return n;
}();
var $B = function() {
function n(t, e, r) {
this.variableNames = ["x"], this.packedInputs = true, this.packedOutput = true, this.outputShape = e.map(function(y, w) {
return y[0] + t[w] + y[1];
});
for (var i = t.length, a = Ze(i), s = e.map(function(y) {
return y[0];
}).join(","), o = e.map(function(y, w) {
return y[0] + t[w];
}).join(","), c = Ut("rc", i), l = Ut("source", i), u = c[i - 1] + " < " + this.outputShape[i - 1], h = i === 1 ? "source" : "vec2(" + l.slice(-2).join() + ")", d = [a + " rc = outputLoc;", c[i - 1] + ` += 1;
if(` + u + `) {
`, i === 1 ? "" : `}
rc = outputLoc;
` + c[i - 2] + ` += 1;
if(` + c[i - 2] + " < " + this.outputShape[i - 2] + ") {", i === 1 ? "" : " " + c[i - 1] + ` += 1;
if(` + u + ") {"], p = i === 1 ? "rc < start || rc >= end" : "any(lessThan(rc, start)) || any(greaterThanEqual(rc, end))", f = "", m = 0, g = i === 1 ? 2 : 4; m < g; m++)
f += `
` + d[m] + `
if (` + p + `) {
result[` + m + "] = float(" + r + `);
} else {
` + a + ` source = rc - start;
result[` + m + "] = getChannel(getX(" + l.join() + "), " + h + `);
}
`;
f += i === 1 ? "} " : "}}", this.userCode = `
const ` + a + " start = " + a + "(" + s + `);
const ` + a + " end = " + a + "(" + o + `);
void main() {
` + a + ` outputLoc = getOutputCoords();
vec4 result = vec4(0.);
` + f + `
setOutput(result);
}
`;
}
return n;
}();
var us = function() {
function n(t, e, r, i, a) {
if (i === void 0 && (i = false), a === void 0 && (a = false), this.variableNames = ["x"], e === "avg" && r)
throw new Error("Cannot compute positions for average pool.");
var s = t.filterWidth, o = t.strideHeight, c = t.strideWidth, l = t.dilationHeight, u = t.dilationWidth, h = t.effectiveFilterHeight, d = t.effectiveFilterWidth, p = t.padInfo.top, f = t.padInfo.left;
this.outputShape = t.outShape;
var m = e === "avg", g = "((batch * " + t.inHeight + " + xR) * " + t.inWidth + " + xC) * " + t.inChannels + " + d", y = "(xR * " + t.inWidth + " + xC) * " + t.inChannels + " + d", w = "0.0";
if (m || (w = "-1.0 / 1e-20"), r) {
var b = ">=";
this.userCode = `
const ivec2 strides = ivec2(` + o + ", " + c + `);
const ivec2 pads = ivec2(` + p + ", " + f + `);
void main() {
ivec4 coords = getOutputCoords();
int batch = coords[0];
int d = coords[3];
ivec2 xRCCorner = coords.yz * strides - pads;
int xRCorner = xRCCorner.x;
int xCCorner = xRCCorner.y;
// max/min x(?, ?, d) to get y(yR, yC, d).
// ? = to be determined
float minMaxValue = 0.0;
float minMaxValueFound = 0.0;
int minMaxPosition = 0;
float avgValue = 0.0;
for (int wR = 0; wR < ` + h + `;
wR += ` + l + `) {
int xR = xRCorner + wR;
if (xR < 0 || xR >= ` + t.inHeight + `) {
continue;
}
for (int wC = 0; wC < ` + d + `;
wC += ` + u + `) {
int xC = xCCorner + wC;
if (xC < 0 || xC >= ` + t.inWidth + `) {
continue;
}
float value = getX(batch, xR, xC, d);
// If a min / max value has already been found, use it. If not,
// use the current value.
float currMinMaxValue = mix(
value, minMaxValue, minMaxValueFound);
if (value ` + b + ` currMinMaxValue) {
minMaxValue = value;
minMaxValueFound = 1.0;
minMaxPosition = ` + (i ? a ? g : y : "wR * " + d + " + wC") + `;
}
}
}
setOutput(float(minMaxPosition));
}
`;
return;
}
var x = "max", L = e + "(" + e + "(" + e + "(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";
e === "avg" && (L = "avgValue / count");
var N = Math.floor(s / 4) * 4, I = s % 4, C = `
if (` + m + `) {
avgValue += dot(values, ones);
} else {
minMaxValue = ` + x + `(values, minMaxValue);
}
`;
this.userCode = `
const ivec2 strides = ivec2(` + o + ", " + c + `);
const ivec2 pads = ivec2(` + p + ", " + f + `);
const float initializationValue = ` + w + `;
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
float count = 0.0;
float getValue(int batch, int xR, int xC, int d) {
if (xC < 0 || xC >= ` + t.inWidth + `) {
return initializationValue;
}
count += 1.0;
return getX(batch, xR, xC, d);
}
void main() {
ivec4 coords = getOutputCoords();
int batch = coords[0];
int d = coords[3];
ivec2 xRCCorner = coords.yz * strides - pads;
int xRCorner = xRCCorner.x;
int xCCorner = xRCCorner.y;
// max/min x(?, ?, d) to get y(yR, yC, d).
// ? = to be determined
vec4 minMaxValue = vec4(` + w + `);
float avgValue = 0.0;
count = 0.0;
for (int wR = 0; wR < ` + h + `;
wR += ` + l + `) {
int xR = xRCorner + wR;
if (xR < 0 || xR >= ` + t.inHeight + `) {
continue;
}
for (int wC = 0; wC < ` + N + `; wC += 4) {
int xC = xCCorner + wC * ` + u + `;
vec4 values = vec4(
getValue(batch, xR, xC, d),
getValue(batch, xR, xC + ` + u + `, d),
getValue(batch, xR, xC + 2 * ` + u + `, d),
getValue(batch, xR, xC + 3 * ` + u + `, d)
);
` + C + `
}
int xC = xCCorner + ` + N + `;
if (` + (I === 1) + `) {
vec4 values = vec4(
getValue(batch, xR, xC, d),
initializationValue,
initializationValue,
initializationValue
);
` + C + `
} else if (` + (I === 2) + `) {
vec4 values = vec4(
getValue(batch, xR, xC, d),
getValue(batch, xR, xC + ` + u + `, d),
initializationValue,
initializationValue
);
` + C + `
} else if (` + (I === 3) + `) {
vec4 values = vec4(
getValue(batch, xR, xC, d),
getValue(batch, xR, xC + ` + u + `, d),
getValue(batch, xR, xC + 2 * ` + u + `, d),
initializationValue
);
` + C + `
}
}
setOutput(` + L + `);
}
`;
}
return n;
}(), np = function() {
function n(t, e, r, i, a) {
if (i === void 0 && (i = false), a === void 0 && (a = false), this.variableNames = ["x"], e === "avg" && r)
throw new Error("Cannot compute positions for average pool.");
var s = t.filterWidth, o = t.strideDepth, c = t.strideHeight, l = t.strideWidth, u = t.dilationDepth, h = t.dilationHeight, d = t.dilationWidth, p = t.effectiveFilterDepth, f = t.effectiveFilterHeight, m = t.effectiveFilterWidth, g = t.padInfo.front, y = t.padInfo.top, w = t.padInfo.left;
this.outputShape = t.outShape;
var b = e === "avg", x = "0.0";
if (b || (x = "-1.0 / 1e-20"), r) {
var L = ">=";
this.userCode = `
const ivec3 strides =
ivec3(` + o + ", " + c + ", " + l + `);
const ivec3 pads = ivec3(` + g + ", " + y + ", " + w + `);
void main() {
ivec5 coords = getOutputCoords();
int batch = coords.x;
int ch = coords.u;
ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;
int xDCorner = xCorner.x;
int xRCorner = xCorner.y;
int xCCorner = xCorner.z;
// max/min x(?, ?, ?, ch) to get y(yD, yR, yC, ch).
// ? = to be determined
float minMaxValue = 0.0;
float minMaxValueFound = 0.0;
int minMaxPosition = 0;
for (int wD = 0; wD < ` + p + `;
wD += ` + u + `) {
int xD = xDCorner + wD;
if (xD < 0 || xD >= ` + t.inDepth + `) {
continue;
}
for (int wR = 0; wR < ` + f + `;
wR += ` + h + `) {
int xR = xRCorner + wR;
if (xR < 0 || xR >= ` + t.inHeight + `) {
continue;
}
for (int wC = 0; wC < ` + m + `;
wC += ` + d + `) {
int xC = xCCorner + wC;
if (xC < 0 || xC >= ` + t.inWidth + `) {
continue;
}
float value = getX(batch, xD, xR, xC, ch);
// If a min / max value has already been found, use it. If not,
// use the current value.
float currMinMaxValue = mix(
value, minMaxValue, minMaxValueFound);
if (value ` + L + ` currMinMaxValue) {
minMaxValue = value;
minMaxValueFound = 1.0;
minMaxPosition = ` + (i ? a ? "(((batch * " + t.inDepth + " + xD) * " + t.inHeight + " + xR) * " + t.inWidth + " + xC) * " + t.inChannels + " + ch" : "((xD * " + t.inHeight + " + xR) * " + t.inWidth + " + xC) * " + t.inChannels + " + ch" : "wD * " + f + " * " + m + ` +
wR * ` + m + " + wC") + `;
}
}
}
}
setOutput(float(minMaxPosition));
}
`;
return;
}
var N = "max", I = e + "(" + e + "(" + e + "(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";
e === "avg" && (I = "avgValue / count");
var C = Math.floor(s / 4) * 4, O = s % 4, D = `
if (` + b + `) {
avgValue += dot(values, ones);
} else {
minMaxValue = ` + N + `(values, minMaxValue);
}
`;
this.userCode = `
const ivec3 strides =
ivec3(` + o + ", " + c + ", " + l + `);
const ivec3 pads = ivec3(` + g + ", " + y + ", " + w + `);
const float initializationValue = ` + x + `;
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
float count = 0.0;
float getValue(int batch, int xD, int xR, int xC, int ch) {
if (xC < 0 || xC >= ` + t.inWidth + `) {
return initializationValue;
}
count += 1.0;
return getX(batch, xD, xR, xC, ch);
}
void main() {
ivec5 coords = getOutputCoords();
int batch = coords.x;
int ch = coords.u;
ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;
int xDCorner = xCorner.x;
int xRCorner = xCorner.y;
int xCCorner = xCorner.z;
// max/min x(?, ?, ?, d) to get y(yD, yR, yC, ch).
// ? = to be determined
vec4 minMaxValue = vec4(` + x + `);
float avgValue = 0.0;
count = 0.0;
for (int wD = 0; wD < ` + p + `;
wD += ` + u + `) {
int xD = xDCorner + wD;
if (xD < 0 || xD >= ` + t.inDepth + `) {
continue;
}
for (int wR = 0; wR < ` + f + `;
wR += ` + h + `) {
int xR = xRCorner + wR;
if (xR < 0 || xR >= ` + t.inHeight + `) {
continue;
}
for (int wC = 0; wC < ` + C + `; wC += 4) {
int xC = xCCorner + wC * ` + d + `;
vec4 values = vec4(
getValue(batch, xD, xR, xC, ch),
getValue(batch, xD, xR, xC + ` + d + `, ch),
getValue(batch, xD, xR, xC + 2 * ` + d + `, ch),
getValue(batch, xD, xR, xC + 3 * ` + d + `, ch)
);
` + D + `
}
int xC = xCCorner + ` + C + `;
if (` + (O === 1) + `) {
vec4 values = vec4(
getValue(batch, xD, xR, xC, ch),
initializationValue,
initializationValue,
initializationValue
);
` + D + `
} else if (` + (O === 2) + `) {
vec4 values = vec4(
getValue(batch, xD, xR, xC, ch),
getValue(batch, xD, xR, xC + ` + d + `, ch),
initializationValue,
initializationValue
);
` + D + `
} else if (` + (O === 3) + `) {
vec4 values = vec4(
getValue(batch, xD, xR, xC, ch),
getValue(batch, xD, xR, xC + ` + d + `, ch),
getValue(batch, xD, xR, xC + 2 * ` + d + `, ch),
initializationValue
);
` + D + `
}
}
setOutput(` + I + `);
}
}
`;
}
return n;
}();
var Gb = function() {
function n(t, e) {
this.variableNames = ["x"];
var r = t.windowSize, i = t.batchSize, a = t.inSize, s = t.outSize;
this.outputShape = [i, s];
var o = "0.0", c = "";
e === "prod" ? o = "1.0" : e === "min" ? (o = "1.0 / 1e-20", c = "min") : e === "max" && (o = "-1.0 / 1e-20", c = "max");
var l = e + "(" + e + "(" + e + "(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";
e === "sum" ? l = "sumValue" : e === "prod" ? l = "prodValue" : e === "all" ? l = "allValue" : e === "any" && (l = "anyValue");
var u = Math.floor(r / 4) * 4, h = r % 4, d = `
if (` + (e === "sum") + `) {
sumValue += dot(values, ones);
} else if (` + (e === "prod") + `) {
vec2 tmp = vec2(values[0], values[1]) * vec2(values[2], values[3]);
prodValue *= tmp[0] * tmp[1];
} else {
minMaxValue = ` + c + `(values, minMaxValue);
}
`, p = "vec4";
e === "all" ? (o = "1.0", d = `
bool reducedAllValue = all(values);
float floatedReducedAllValue = float(reducedAllValue);
allValue = float(allValue >= 1.0 && floatedReducedAllValue >= 1.0);
`, p = "bvec4") : e === "any" && (o = "0.0", d = `
bool reducedAnyValue = any(values);
float floatedReducedAnyValue = float(reducedAnyValue);
anyValue = float(anyValue >= 1.0 || floatedReducedAnyValue >= 1.0);
`, p = "bvec4");
var f = "";
a % r > 0 && (f = `
if (inIdx < 0 || inIdx >= ` + a + `) {
return initializationValue;
}
`), this.userCode = `
const float initializationValue = ` + o + `;
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
float getValue(int batch, int inIdx) {
` + f + `
return getX(batch, inIdx);
}
void main() {
ivec2 coords = getOutputCoords();
int batch = coords[0];
int outIdx = coords[1];
int inOffset = outIdx * ` + r + `;
vec4 minMaxValue = vec4(` + o + `);
float prodValue = 1.0;
float sumValue = 0.0;
float allValue = 1.0;
float anyValue = 0.0;
for (int i = 0; i < ` + u + `; i += 4) {
int inIdx = inOffset + i;
` + p + " values = " + p + `(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
getValue(batch, inIdx + 2),
getValue(batch, inIdx + 3)
);
` + d + `
}
int inIdx = inOffset + ` + u + `;
if (` + (h === 1) + `) {
` + p + " values = " + p + `(
getValue(batch, inIdx),
initializationValue,
initializationValue,
initializationValue
);
` + d + `
} else if (` + (h === 2) + `) {
` + p + " values = " + p + `(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
initializationValue,
initializationValue
);
` + d + `
} else if (` + (h === 3) + `) {
` + p + " values = " + p + `(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
getValue(batch, inIdx + 2),
initializationValue
);
` + d + `
}
setOutput(` + l + `);
}
`;
}
return n;
}();
var qb = function() {
function n(t, e) {
this.variableNames = ["A"], this.packedInputs = true, this.packedOutput = true, this.outputShape = t;
for (var r = "", i = 0; i < 4; i++) {
var a = "thisRC = rc;";
i % 2 === 1 && (a += "thisRC.z += 1;"), i > 1 && (a += "thisRC.y += 1;"), r += `
` + a + `
` + (i > 0 ? "if(thisRC.y < rows && thisRC.z < cols){" : "") + `
int flatIndex = getFlatIndex(thisRC);
ivec3 inputRC = inputCoordsFromReshapedOutCoords(flatIndex);
vec2 inputRCInnerDims = vec2(float(inputRC.y),float(inputRC.z));
result[` + i + `] =
getChannel(getA(inputRC.x, inputRC.y, inputRC.z), inputRCInnerDims);
` + (i > 0 ? "}" : "") + `
`;
}
this.userCode = `
` + XB(e) + `
` + $d(t) + `
void main() {
ivec3 rc = getOutputCoords();
vec4 result = vec4(0.);
ivec3 thisRC;
int rows = ` + t[1] + `;
int cols = ` + t[2] + `;
` + r + `
setOutput(result);
}
`;
}
return n;
}();
function XB(n) {
var t = gi(["r", "c", "d"], n);
return `
ivec3 inputCoordsFromReshapedOutCoords(int index) {
` + t + `
return ivec3(r, c, d);
}
`;
}
var JB = function() {
function n(t, e, r) {
this.variableNames = ["dy"], this.outputShape = [], this.outputShape = e.shape;
var i = e.shape, a = i[1], s = i[2], o = t.shape, c = o[1], l = o[2], u = [r && c > 1 ? a - 1 : a, r && l > 1 ? s - 1 : s], h = [r && c > 1 ? c - 1 : c, r && l > 1 ? l - 1 : l], d = u[0] / h[0], p = u[1] / h[1], f = 1 / d, m = 1 / p, g = Math.ceil(f) * 2 + 2, y = Math.ceil(m) * 2 + 2;
this.userCode = `
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int d = coords[3];
int r = coords[1];
int c = coords[2];
float accumulator = 0.0;
const float heightScale = float(` + d + `);
const float widthScale = float(` + p + `);
const float invHeightScale = float(` + f + `);
const float invWidthScale = float(` + m + `);
const int winHeight = int(` + g + `);
const int winWidth = int(` + y + `);
// Compute bounds for where in dy we will look
float startRLerp = floor(float(r) * invHeightScale);
int startDyR = int(startRLerp - float(winHeight / 2));
float startCLerp = floor(float(c) * invWidthScale);
int startDyC = int(startCLerp - float(winWidth / 2));
// Loop over dy
for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {
int dyR = dyROffset + startDyR;
// Guard against the window exceeding the bounds of dy
if (dyR < 0 || dyR >= ` + c + `) {
continue;
}
for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {
int dyC = dyCOffset + startDyC;
// Guard against the window exceeding the bounds of dy
if (dyC < 0 || dyC >= ` + l + `) {
continue;
}
float dxR = float(dyR) * heightScale;
int topDxRIndex = int(floor(dxR));
int bottomDxRIndex = int(min(ceil(dxR), ` + (a - 1) + `.0));
float dxRLerp = dxR - float(topDxRIndex);
float inverseDxRLerp = 1.0 - dxRLerp;
float dxC = float(dyC) * widthScale;
int leftDxCIndex = int(floor(dxC));
int rightDxCIndex = int(min(ceil(dxC), ` + (s - 1) + `.0));
float dxCLerp = dxC - float(leftDxCIndex);
float inverseDxCLerp = 1.0 - dxCLerp;
if (r == topDxRIndex && c == leftDxCIndex) {
// topLeft
accumulator +=
getDy(b, dyR, dyC, d) * inverseDxRLerp * inverseDxCLerp;
}
if (r == topDxRIndex && c == rightDxCIndex) {
// topRight
accumulator += getDy(b, dyR, dyC, d) * inverseDxRLerp * dxCLerp;
}
if (r == bottomDxRIndex && c == leftDxCIndex) {
// bottomLeft
accumulator += getDy(b, dyR, dyC, d) * dxRLerp * inverseDxCLerp;
}
if (r == bottomDxRIndex && c == rightDxCIndex) {
// bottomRight
accumulator += getDy(b, dyR, dyC, d) * dxRLerp * dxCLerp;
}
}
}
// End loop over dy
setOutput(accumulator);
}
`;
}
return n;
}();
var ZB = function() {
function n(t, e, r, i) {
this.variableNames = ["A"], this.outputShape = [];
var a = t[0], s = t[1], o = t[2], c = t[3];
this.outputShape = [a, e, r, c];
var l = [i && e > 1 ? s - 1 : s, i && r > 1 ? o - 1 : o], u = [i && e > 1 ? e - 1 : e, i && r > 1 ? r - 1 : r];
this.userCode = `
const vec2 effectiveInputOverOutputRatioRC = vec2(
` + l[0] / u[0] + `,
` + l[1] / u[1] + `);
const vec2 inputShapeRC = vec2(` + s + ".0, " + o + `.0);
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int d = coords[3];
ivec2 yRC = coords.yz;
// Fractional source index.
vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;
// Compute the four integer indices.
ivec2 sourceFloorRC = ivec2(sourceFracIndexRC);
ivec2 sourceCeilRC = ivec2(
min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));
float topLeft = getA(b, sourceFloorRC.x, sourceFloorRC.y, d);
float bottomLeft = getA(b, sourceCeilRC.x, sourceFloorRC.y, d);
float topRight = getA(b, sourceFloorRC.x, sourceCeilRC.y, d);
float bottomRight = getA(b, sourceCeilRC.x, sourceCeilRC.y, d);
vec2 fracRC = sourceFracIndexRC - vec2(sourceFloorRC);
float top = topLeft + (topRight - topLeft) * fracRC.y;
float bottom = bottomLeft + (bottomRight - bottomLeft) * fracRC.y;
float newValue = top + (bottom - top) * fracRC.x;
setOutput(newValue);
}
`;
}
return n;
}();
var QB = function() {
function n(t, e, r, i) {
this.variableNames = ["A"], this.packedInputs = true, this.packedOutput = true, this.outputShape = [];
var a = t[0], s = t[1], o = t[2], c = t[3];
this.outputShape = [a, e, r, c];
var l = [i && e > 1 ? s - 1 : s, i && r > 1 ? o - 1 : o], u = [i && e > 1 ? e - 1 : e, i && r > 1 ? r - 1 : r];
this.userCode = `
const vec3 effectiveInputOverOutputRatioRC = vec3(
` + l[0] / u[0] + `,
` + l[1] / u[1] + `,
` + l[1] / u[1] + `);
const vec3 inputShapeRC = vec3(` + s + ".0, " + o + `.0,
` + o + `.0);
float getAValue(int b, int r, int c, int d) {
return getChannel(getA(b, r, c, d), vec2(c, d));
}
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int d = coords[3];
// Calculate values for next column in yRC.z.
ivec3 yRC = coords.yzz + ivec3(0, 0, 1);
// Fractional source index.
vec3 sourceFracIndexRC = vec3(yRC) * effectiveInputOverOutputRatioRC;
// Compute the four integer indices.
ivec3 sourceFloorRC = ivec3(sourceFracIndexRC);
ivec3 sourceCeilRC = ivec3(
min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));
// Should we calculate next column and row elements in 2x2 packed cell.
bool hasNextCol = d < ` + (c - 1) + `;
bool hasNextRow = coords.z < ` + (r - 1) + `;
// In parallel, construct four corners for all four components in
// packed 2x2 cell.
vec4 topLeft = vec4(
getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d),
hasNextCol ? getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d + 1)
: 0.0,
hasNextRow ? getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d)
: 0.0,
(hasNextRow && hasNextCol) ?
getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d + 1) : 0.0);
vec4 bottomLeft = vec4(
getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d),
hasNextCol ? getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d + 1)
: 0.0,
hasNextRow ? getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d)
: 0.0,
(hasNextRow && hasNextCol) ?
getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d + 1) : 0.0);
vec4 topRight = vec4(
getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d),
hasNextCol ? getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d + 1)
: 0.0,
hasNextRow ? getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d)
: 0.0,
(hasNextRow && hasNextCol) ?
getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d + 1) : 0.0);
vec4 bottomRight = vec4(
getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d),
hasNextCol ? getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d + 1)
: 0.0,
hasNextRow ? getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d)
: 0.0,
(hasNextRow && hasNextCol) ?
getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d + 1) : 0.0);
vec3 fracRC = sourceFracIndexRC - vec3(sourceFloorRC);
vec4 top = mix(topLeft, topRight, fracRC.yyzz);
vec4 bottom = mix(bottomLeft, bottomRight, fracRC.yyzz);
vec4 newValue = mix(top, bottom, fracRC.x);
setOutput(newValue);
}
`;
}
return n;
}();
var ez = function() {
function n(t, e, r) {
this.variableNames = ["dy"], this.outputShape = [], this.outputShape = e.shape;
var i = e.shape, a = i[1], s = i[2], o = t.shape, c = o[1], l = o[2], u = [r && c > 1 ? a - 1 : a, r && l > 1 ? s - 1 : s], h = [r && c > 1 ? c - 1 : c, r && l > 1 ? l - 1 : l], d = u[0] / h[0], p = u[1] / h[1], f = 1 / d, m = 1 / p, g = Math.ceil(f) * 2 + 2, y = Math.ceil(m) * 2 + 2;
this.userCode = `
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int d = coords[3];
int r = coords[1];
int c = coords[2];
float accumulator = 0.0;
const float heightScale = float(` + d + `);
const float widthScale = float(` + p + `);
const float invHeightScale = float(` + f + `);
const float invWidthScale = float(` + m + `);
const int winHeight = int(` + g + `);
const int winWidth = int(` + y + `);
// Compute bounds for where in dy we will look
float startRLerp = floor(float(r) * invHeightScale);
int startDyR = int(floor(startRLerp - float(winHeight / 2)));
float startCLerp = floor(float(c) * invWidthScale);
int startDyC = int(floor(startCLerp - float(winWidth / 2)));
// Loop over dy
for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {
int dyR = dyROffset + startDyR;
// Guard against the window exceeding the bounds of dy
if (dyR < 0 || dyR >= ` + c + `) {
continue;
}
for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {
int dyC = dyCOffset + startDyC;
// Guard against the window exceeding the bounds of dy
if (dyC < 0 || dyC >= ` + l + `) {
continue;
}
float sourceFracRow =
float(` + u[0] + `) *
(float(dyR) / float(` + h[0] + `));
float sourceFracCol =
float(` + u[1] + `) *
(float(dyC) / float(` + h[1] + `));
int sourceNearestRow = int(min(
float(int(` + a + `) - 1),
` + r + ` ? float(round(sourceFracRow)) :
float(floor(sourceFracRow))));
int sourceNearestCol = int(min(
float(int(` + s + `) - 1),
` + r + ` ? float(round(sourceFracCol)) :
float(floor(sourceFracCol))));
if (r == sourceNearestRow && c == sourceNearestCol) {
accumulator += getDy(b, dyR, dyC, d);
}
}
}
// End loop over dy
setOutput(accumulator);
}
`;
}
return n;
}();
var tz = function() {
function n(t, e, r, i) {
this.variableNames = ["A"], this.outputShape = [];
var a = t[0], s = t[1], o = t[2], c = t[3];
this.outputShape = [a, e, r, c];
var l = [i && e > 1 ? s - 1 : s, i && r > 1 ? o - 1 : o], u = [i && e > 1 ? e - 1 : e, i && r > 1 ? r - 1 : r], h = i ? "0.5" : "0.0";
this.userCode = `
const vec2 effectiveInputOverOutputRatioRC = vec2(
` + l[0] / u[0] + `,
` + l[1] / u[1] + `);
const vec2 inputShapeRC = vec2(` + s + ".0, " + o + `.0);
void main() {
ivec4 coords = getOutputCoords();
int b = coords[0];
int d = coords[3];
ivec2 yRC = coords.yz;
// Fractional source index.
vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;
// Compute the coordinators of nearest neighbor point.
ivec2 sourceNearestRC = ivec2(
min(inputShapeRC - 1.0, floor(sourceFracIndexRC + ` + h + `)));
float newValue = getA(b, sourceNearestRC.x, sourceNearestRC.y, d);
setOutput(newValue);
}
`;
}
return n;
}();
var nz = function() {
function n(t, e) {
this.variableNames = ["x"];
var r = t.length;
if (r > 4)
throw new Error("WebGL backend: Reverse of rank-" + r + " tensor is not yet supported");
if (this.outputShape = t, r === 1) {
this.userCode = `
void main() {
int coord = getOutputCoords();
setOutput(getX(` + t[0] + ` - coord - 1));
}
`;
return;
}
var i = function(o) {
return e.indexOf(o) !== -1 && t[o] !== 1 ? t[o] + " - coords[" + o + "] - 1" : "coords[" + o + "]";
}, a = t.map(function(o, c) {
return i(c);
}).join(","), s = Ze(r);
this.userCode = `
void main() {
` + s + ` coords = getOutputCoords();
setOutput(getX(` + a + `));
}
`;
}
return n;
}();
var rz = function() {
function n(t, e) {
this.variableNames = ["x"], this.packedInputs = true, this.packedOutput = true;
var r = t.length;
if (r > 4)
throw new Error("WebGL backend: Reverse of rank-" + r + " tensor is not yet supported");
this.outputShape = t;
var i = Ut("rc", r), a = i[r - 1] + " + 1 < " + this.outputShape[r - 1], s = i[r - 2] + " + 1 < " + this.outputShape[r - 2], o = Ze(r);
r === 1 ? this.userCode = `
void main(){
int rc = getOutputCoords();
vec4 result = vec4(0.);
result.r = getChannel(getX(` + t[0] + ` - rc - 1),
` + t[0] + ` - rc - 1);
if(` + a + `){
result.g = getChannel(getX(` + t[0] + ` - (rc + 1) - 1),
` + t[0] + ` - (rc + 1) - 1);
}
setOutput(result);
}
` : this.userCode = `
void main() {
` + o + ` rc = getOutputCoords();
vec4 result = vec4(0.);
result.r = ` + c(i.slice()) + `;
if(` + a + `){
result.g = ` + l(i.slice()) + `;
}
if(` + s + `) {
result.b = ` + u(i.slice()) + `;
if(` + a + `) {
result.a = ` + h(i.slice()) + `;
}
}
setOutput(result);
}
`;
function c(f) {
return d(f);
}
function l(f) {
return f[r - 1] = "(" + f[r - 1] + " + 1)", d(f);
}
function u(f) {
return f[r - 2] = "(" + f[r - 2] + " + 1)", d(f);
}
function h(f) {
return f[r - 1] = "(" + f[r - 1] + " + 1)", f[r - 2] = "(" + f[r - 2] + " + 1)", d(f);
}
function d(f) {
var m = t.map(function(w, b) {
return p(b, f);
}), g = m.join(","), y = m.slice(-2).join(",");
return "getChannel(getX(" + g + "), vec2(" + y + "))";
}
function p(f, m) {
return e.indexOf(f) !== -1 && t[f] !== 1 ? t[f] + " - " + m[f] + " - 1" : "" + m[f];
}
}
return n;
}();
var Yb = function() {
function n(t, e, r, i, a, s, o) {
this.variableNames = ["updates", "indices", "defaultValue"], this.outputShape = s;
var c = Ze(a.length), l = Ze(s.length), u = "";
r === 1 ? u = "i" : r === 2 && (u = "i, j");
var h = "getIndices(" + u + ")", d = "";
i === 1 ? d = "i" : i === 2 && (d = "i, coords[1]");
var p = "getUpdates(" + d + ")", f = e > 1 ? "strides[j]" : "strides";
this.userCode = `
` + c + " strides = " + c + "(" + a + `);
void main() {
` + l + ` coords = getOutputCoords();
float sum = 0.0;
bool found = false;
for (int i = 0; i < ` + t + `; i++) {
int flattenedIndex = 0;
for (int j = 0; j < ` + e + `; j++) {
int index = round(` + h + `);
flattenedIndex += index * ` + f + `;
}
if (flattenedIndex == coords[0]) {
sum += ` + p + `;
found = true;
}
}
setOutput(mix(getDefaultValue(), sum, float(found)));
}
`;
}
return n;
}();
var iz = function() {
function n(t, e) {
this.variableNames = ["x", "segmentIds"];
var r = t.windowSize, i = t.batchSize, a = t.inSize, s = t.numSegments, o = s * Math.ceil(a / r);
this.outputShape = [i, o];
var c = "0.0", l = "sumValue", u = Math.floor(r / 4) * 4, h = r % 4, d = `
sumValue += dot(values, segFilter);
`, p = "";
a % r > 0 && (p = `
if (inIdx < 0 || inIdx >= ` + a + `) {
return initializationValue;
}
`);
var f = "";
a % r > 0 && (f = `
if (inIdx < 0 || inIdx >= ` + a + `) {
return -1.0;
}
`), this.userCode = `
const float initializationValue = ` + c + `;
float getValue(int batch, int inIdx) {
` + p + `
return getX(batch, inIdx);
}
float getSegmentIdAtIndex(int inIdx) {
` + f + `
return getSegmentIds(inIdx);
}
void main() {
ivec2 coords = getOutputCoords();
int batch = coords[0];
int outIdx = coords[1];
int inOffset = int(floor(float(outIdx) / float(
` + s + ")) * float(" + r + `));
int currentSeg = int(mod(float(outIdx), float(` + s + `)));
float sumValue = 0.0;
for (int i = 0; i < ` + u + `; i += 4) {
int inIdx = inOffset + i;
vec4 values = vec4(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
getValue(batch, inIdx + 2),
getValue(batch, inIdx + 3)
);
vec4 segFilter = vec4(
int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,
int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,
int(getSegmentIdAtIndex(inIdx + 3)) == currentSeg ? 1 : 0
);
` + d + `
}
int inIdx = inOffset + ` + u + `;
if (` + (h === 1) + `) {
vec4 values = vec4(
getValue(batch, inIdx),
initializationValue,
initializationValue,
initializationValue
);
int inIdxSeg = int(getSegmentIdAtIndex(inIdx));
vec4 segFilter = vec4(
int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
0,
0,
0
);
` + d + `
} else if (` + (h === 2) + `) {
vec4 values = vec4(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
initializationValue,
initializationValue
);
vec4 segFilter = vec4(
int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,
0,
0
);
` + d + `
} else if (` + (h === 3) + `) {
vec4 values = vec4(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
getValue(batch, inIdx + 2),
initializationValue
);
vec4 segFilter = vec4(
int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,
int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,
0
);
` + d + `
}
setOutput(` + l + `);
}
`;
}
return n;
}();
var az = function() {
function n(t, e, r) {
this.variableNames = ["c", "a", "b"], this.outputShape = e;
var i, a;
if (r > 4)
throw Error("Where for rank " + r + " is not yet supported");
if (r === 1)
a = "resRC", i = "resRC";
else {
for (var s = ["resRC.x", "resRC.y", "resRC.z", "resRC.w"], o = [], c = [], l = 0; l < e.length; l++)
c.push("" + s[l]), l < t && o.push("" + s[l]);
i = o.join(), a = c.join();
}
var u = Ze(r);
this.userCode = `
void main() {
` + u + ` resRC = getOutputCoords();
float cVal = getC(` + i + `);
if (cVal >= 1.0) {
setOutput(getA(` + a + `));
} else {
setOutput(getB(` + a + `));
}
}
`;
}
return n;
}();
var oz = function() {
function n(t) {
this.variableNames = ["source"], this.outputShape = t, this.rank = t.length;
var e = Ze(this.rank), r = "uniform int start[" + this.rank + "];", i = sz(this.rank), a, s = t.map(function(o, c) {
return "sourceLoc." + rp[c] + " = start[" + c + "] + coords." + rp[c] + ";";
});
a = `
` + e + ` sourceLoc;
` + e + ` coords = getOutputCoords();
` + s.join(`
`) + `
`, this.userCode = `
` + r + `
void main() {
` + a + `
setOutput(getSource(` + i + `));
}
`;
}
return n.prototype.getCustomSetupFunc = function(t) {
var e = this;
if (t.length !== this.rank)
throw Error("The rank (" + this.rank + ") of the program must match the " + ("length of start (" + t.length + ")"));
return function(r, i) {
if (e.startLoc == null && (e.startLoc = r.getUniformLocationNoThrow(i, "start"), e.startLoc == null))
return;
r.gl.uniform1iv(e.startLoc, t);
};
}, n;
}(), rp = ["x", "y", "z", "w", "u", "v"];
function sz(n) {
if (n === 1)
return "sourceLoc";
if (n <= 6)
return rp.slice(0, n).map(function(t) {
return "sourceLoc." + t;
}).join(",");
throw Error("Slicing for rank " + n + " is not yet supported");
}
var cz = function() {
function n(t) {
this.variableNames = ["source"], this.packedInputs = true, this.packedOutput = true, this.outputShape = t, this.rank = t.length;
var e = Ze(this.rank), r = Ut("coords", this.rank), i = Ut("sourceLoc", this.rank), a = this.rank === 1 ? "sourceLoc" : "vec2(" + i.slice(-2).join() + ")", s = "getChannel(getSource(" + i.join() + "), " + a + ")", o = `
result.x = ` + s + `;
if (++` + r[this.rank - 1] + " < " + t[this.rank - 1] + `) {
++` + i[this.rank - 1] + `;
result.y = ` + s + `;
--` + i[this.rank - 1] + `;
}
`, c = this.rank === 1 ? "" : `
--` + r[this.rank - 1] + `;
if (++` + r[this.rank - 2] + " < " + t[this.rank - 2] + `) {
++` + i[this.rank - 2] + `;
result.z = ` + s + `;
if (++` + r[this.rank - 1] + " < " + t[this.rank - 1] + `) {
++` + i[this.rank - 1] + `;
result.w = ` + s + `;
}
}
`, l = this.rank <= 4 ? `sourceLoc = coords +
` + e + "(" + t.map(function(u, h) {
return "start[" + h + "]";
}).join() + ");" : t.map(function(u, h) {
return i[h] + " = " + r[h] + " + start[" + h + "];";
}).join(`
`);
this.userCode = `
uniform int start[` + this.rank + `];
void main() {
` + e + ` coords = getOutputCoords();
` + e + ` sourceLoc;
` + l + `
vec4 result = vec4(0.);
` + o + `
` + c + `
setOutput(result);
}
`;
}
return n.prototype.getCustomSetupFunc = function(t) {
var e = this;
if (t.length !== this.rank)
throw Error("The rank (" + this.rank + ") of the program must match the " + ("length of start (" + t.length + ")"));
return function(r, i) {
if (e.startLoc == null && (e.startLoc = r.getUniformLocationNoThrow(i, "start"), e.startLoc == null))
return;
r.gl.uniform1iv(e.startLoc, t);
};
}, n;
}();
var lz = function() {
function n(t, e, r) {
this.variableNames = ["x"], this.outputShape = r;
var i = r.length, a = Ze(r.length), s = Ze(r.length), o = "";
if (i === 1)
o = "coords * strides + begin";
else {
var c = 0;
o = r.map(function(l, u) {
return c++, r.length === 1 ? "coords * strides[" + u + "] + begin[" + u + "]" : "coords[" + (c - 1) + "] * strides[" + u + "] + begin[" + u + "]";
}).join(",");
}
this.userCode = `
` + a + " begin = " + a + "(" + t + `);
` + a + " strides = " + a + "(" + e + `);
void main() {
` + s + ` coords = getOutputCoords();
setOutput(getX(` + o + `));
}
`;
}
return n;
}();
var uz = function() {
function n(t) {
this.gpgpu = t, this.numUsedTextures = 0, this.numFreeTextures = 0, this._numBytesAllocated = 0, this._numBytesFree = 0, this.freeTextures = {}, this.logEnabled = false, this.usedTextures = {};
}
return n.prototype.acquireTexture = function(t, e, r) {
var i = jb(e, r), a = $b(t, i, r);
a in this.freeTextures || (this.freeTextures[a] = []), a in this.usedTextures || (this.usedTextures[a] = []);
var s = Kb(t, i, this.gpgpu.gl, this.gpgpu.textureConfig, r);
if (this.freeTextures[a].length > 0) {
this.numFreeTextures--, this.numUsedTextures++, this._numBytesFree -= s, this.log();
var o = this.freeTextures[a].shift();
return this.usedTextures[a].push(o), o;
}
var c;
return i === Dt.PACKED_2X2_FLOAT32 ? c = this.gpgpu.createPackedMatrixTexture(t[0], t[1]) : i === Dt.PACKED_2X2_FLOAT16 ? c = this.gpgpu.createFloat16PackedMatrixTexture(t[0], t[1]) : i === Dt.UNPACKED_FLOAT32 ? c = this.gpgpu.createFloat32MatrixTexture(t[0], t[1]) : i === Dt.UNPACKED_FLOAT16 ? c = this.gpgpu.createFloat16MatrixTexture(t[0], t[1]) : i === Dt.PACKED_4X1_UNSIGNED_BYTE && (c = this.gpgpu.createUnsignedBytesMatrixTexture(t[0], t[1])), this.usedTextures[a].push(c), this.numUsedTextures++, this._numBytesAllocated += s, this.log(), c;
}, n.prototype.releaseTexture = function(t, e, r, i) {
if (this.freeTextures == null)
return;
var a = jb(r, i), s = $b(e, a, i);
s in this.freeTextures || (this.freeTextures[s] = []);
var o = Kb(e, a, this.gpgpu.gl, this.gpgpu.textureConfig, i), c = _.env().get("WEBGL_DELETE_TEXTURE_THRESHOLD");
c !== -1 && this._numBytesAllocated > c ? (this.gpgpu.deleteMatrixTexture(t), this._numBytesAllocated -= o) : (this.freeTextures[s].push(t), this.numFreeTextures++, this._numBytesFree += o), this.numUsedTextures--;
var l = this.usedTextures[s], u = l.indexOf(t);
if (u < 0)
throw new Error("Cannot release a texture that was never provided by this texture manager");
l.splice(u, 1), this.log();
}, n.prototype.log = function() {
if (!this.logEnabled)
return;
var t = this.numFreeTextures + this.numUsedTextures;
console.log("Free/Used", this.numFreeTextures + " / " + this.numUsedTextures, "(" + t + ")");
var e = this._numBytesFree / this._numBytesAllocated;
console.log("Bytes allocated: " + this._numBytesAllocated), console.log("Bytes unused: " + this._numBytesFree + " (" + Math.round(100 * e) + "%)");
}, Object.defineProperty(n.prototype, "numBytesAllocated", {get: function() {
return this._numBytesAllocated;
}, enumerable: true, configurable: true}), Object.defineProperty(n.prototype, "numBytesFree", {get: function() {
return this._numBytesFree;
}, enumerable: true, configurable: true}), n.prototype.getNumUsedTextures = function() {
return this.numUsedTextures;
}, n.prototype.getNumFreeTextures = function() {
return this.numFreeTextures;
}, n.prototype.dispose = function() {
var t = this;
if (this.freeTextures == null)
return;
for (var e in this.freeTextures)
this.freeTextures[e].forEach(function(r) {
t.gpgpu.deleteMatrixTexture(r);
});
for (var e in this.usedTextures)
this.usedTextures[e].forEach(function(i) {
t.gpgpu.deleteMatrixTexture(i);
});
this.freeTextures = null, this.usedTextures = null, this.numUsedTextures = 0, this.numFreeTextures = 0, this._numBytesAllocated = 0, this._numBytesFree = 0;
}, n;
}();
function hz(n, t) {
var e = n;
if (t === e.R32F)
return 4;
if (t === e.R16F)
return 2;
if (t === e.RGBA32F)
return 16;
if (t === n.RGBA)
return 16;
if (t === e.RGBA16F)
return 8;
throw new Error("Unknown internal format " + t);
}
function Kb(n, t, e, r, i) {
var a = dz(t, r), s;
if (i) {
var o = ta(n[0], n[1]), c = o[0], l = o[1];
s = c * l;
} else {
var u = is(n[0], n[1]), h = u[0], d = u[1];
s = h * d;
}
var p = hz(e, a);
return s * p;
}
function dz(n, t) {
switch (n) {
case Dt.PACKED_2X2_FLOAT32:
return Qd(t);
case Dt.PACKED_2X2_FLOAT16:
return ep(t);
case Dt.UNPACKED_FLOAT32:
return Xd(t);
case Dt.UNPACKED_FLOAT16:
return Jd(t);
case Dt.PACKED_4X1_UNSIGNED_BYTE:
return Zd(t);
default:
throw new Error("Unknown physical texture type " + n);
}
}
function pz(n) {
return _.env().getBool("WEBGL_RENDER_FLOAT32_ENABLED") ? n ? Dt.PACKED_2X2_FLOAT32 : Dt.UNPACKED_FLOAT32 : n ? Dt.PACKED_2X2_FLOAT16 : Dt.UNPACKED_FLOAT16;
}
function jb(n, t) {
if (n === cn.UPLOAD)
return Dt.PACKED_2X2_FLOAT32;
if (n === cn.RENDER || n == null)
return pz(t);
if (n === cn.DOWNLOAD || n === cn.PIXELS)
return Dt.PACKED_4X1_UNSIGNED_BYTE;
throw new Error("Unknown logical texture type " + n);
}
function $b(n, t, e) {
return n[0] + "_" + n[1] + "_" + t + "_" + e;
}
var mz = function() {
function n(t, e) {
this.variableNames = ["A"];
for (var r = new Array(t.length), i = 0; i < r.length; i++)
r[i] = t[i] * e[i];
this.outputShape = r, this.rank = r.length;
var a = Ze(this.rank), s = fz(t);
this.userCode = `
void main() {
` + a + ` resRC = getOutputCoords();
setOutput(getA(` + s + `));
}
`;
}
return n;
}();
function fz(n) {
var t = n.length;
if (t > 5)
throw Error("Tile for rank " + t + " is not yet supported");
if (t === 1)
return "imod(resRC, " + n[0] + ")";
for (var e = ["resRC.x", "resRC.y", "resRC.z", "resRC.w", "resRC.u"], r = [], i = 0; i < n.length; i++)
r.push("imod(" + e[i] + ", " + n[i] + ")");
return r.join();
}
var De = function() {
function n(t, e) {
this.variableNames = ["A"], this.outputShape = t, this.userCode = `
float unaryOperation(float x) {
` + e + `
}
void main() {
float x = getAAtOutCoords();
float y = unaryOperation(x);
setOutput(y);
}
`;
}
return n;
}(), ir = "if (isnan(x)) return x;", gz = "return x;", Xb = "return abs(x);", Jb = ir + `
return (x < 0.0) ? 0.0 : x;
`, Zb = ir + `
return (x < 0.0) ? 0.0 : min(6.0, x);
`, Qb = "return (x >= 0.0) ? x : (exp(x) - 1.0);", yz = `
// Stable and Attracting Fixed Point (0, 1) for Normalized Weights.
// see: https://arxiv.org/abs/1706.02515
float scaleAlpha = ` + _.backend_util.SELU_SCALEALPHA + `;
float scale = ` + _.backend_util.SELU_SCALE + `;
return (x >= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);
`;
function vz(n) {
return n === void 0 && (n = 0), ir + (`
return x > 0.0 ? 1.0 : float(` + n + `);
`);
}
var e2 = "return -x;", t2 = "return ceil(x);", n2 = "return floor(x);", wz = `
if (isnan(x)) { return 0.0; }
return sign(x);
`, bz = "return float(isnan(x));", xz = "return float(isinf(x));", Lz = "return float(!isnan(x) && !isinf(x));", Sz = `
// OpenGL ES does not support round function.
// The algorithm is based on banker's rounding.
float base = floor(x);
if ((x - base) < 0.5) {
return floor(x);
} else if ((x - base) > 0.5) {
return ceil(x);
} else {
if (mod(base, 2.0) == 0.0) {
return base;
} else {
return base + 1.0;
}
}
`, r2 = "return exp(x);", i2 = "return exp(x) - 1.0;", Iz = `if (x < 0.0) return NAN;
return log(x);`, Az = "return log(1.0 + x);", Tz = "return sqrt(x);", Nz = "return inversesqrt(x);", _z = "return 1.0 / (1.0 + exp(-1.0 * x));", Cz = `
float epsilon = 1.1920928955078125e-7;
float threshold = log(epsilon) + 2.0;
bool too_large = x > -threshold;
bool too_small = x < threshold;
float result;
float exp_x = exp(x);
if (too_large){
result = x;
}
else if (too_small){
result = exp_x;
}
else{
result = log(exp_x + 1.0);
}
return result;
`, Rz = ir + `
if (abs(x) > 1.) {
return NAN;
}
return asin(x);
`, Oz = ir + `
if (abs(x) > 1.) {
return NAN;
}
return acos(x);
`, Ez = ir + `
return atan(x);
`, Dz = `
float e2x = exp(x);
return (e2x - 1.0 / e2x) / 2.0;
`, kz = `
float e2x = exp(-x);
return (e2x + 1.0 / e2x) / 2.0;
`, Fz = `
float e2x = exp(-2.0 * abs(x));
return sign(x) * (1.0 - e2x) / (1.0 + e2x);
`, Wz = ir + "return log(x + sqrt(x * x + 1.0));", Uz = ir + `
if (x < 1.0) return NAN;
return log(x + sqrt(x * x - 1.0));`, Bz = ir + `
if ((x < -1.0) || (x > 1.0)) return NAN;
return (log(1.0 + x) - log(1.0 - x)) / 2.0;`, zz = `
// Error function is calculated approximately with elementary function.
// See "Handbook of Mathematical Functions with Formulas,
// Graphs, and Mathematical Tables", Abramowitz and Stegun.
float p = ` + _.backend_util.ERF_P + `;
float a1 = ` + _.backend_util.ERF_A1 + `;
float a2 = ` + _.backend_util.ERF_A2 + `;
float a3 = ` + _.backend_util.ERF_A3 + `;
float a4 = ` + _.backend_util.ERF_A4 + `;
float a5 = ` + _.backend_util.ERF_A5 + `;
float sign = sign(x);
x = abs(x);
float t = 1.0 / (1.0 + p * x);
return sign * (1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x));
`, Pz = "return 1.0 / x;", Mz = "return float(!(x >= 1.0));", jo = "return x;";
var Hz = "return x;", Vz = `
vec4 result = log(x);
vec4 isNaN = vec4(lessThan(x, vec4(0.0)));
result.r = isNaN.r == 1.0 ? NAN : result.r;
result.g = isNaN.g == 1.0 ? NAN : result.g;
result.b = isNaN.b == 1.0 ? NAN : result.b;
result.a = isNaN.a == 1.0 ? NAN : result.a;
return result;
`, a2 = `
vec4 result = x * vec4(greaterThanEqual(x, vec4(0.0)));
bvec4 isNaN = isnan(x);
result.r = isNaN.r ? x.r : result.r;
result.g = isNaN.g ? x.g : result.g;
result.b = isNaN.b ? x.b : result.b;
result.a = isNaN.a ? x.a : result.a;
return result;
`, s2 = `
vec4 result = min(x, vec4(6.)) * vec4(greaterThanEqual(x, vec4(0.0)));
bvec4 isNaN = isnan(x);
result.r = isNaN.r ? x.r : result.r;
result.g = isNaN.g ? x.g : result.g;
result.b = isNaN.b ? x.b : result.b;
result.a = isNaN.a ? x.a : result.a;
return result;
`, o2 = `
vec4 result;
result.r = (x.r >= 0.0) ? x.r : (exp(x.r) - 1.0);
result.g = (x.g >= 0.0) ? x.g : (exp(x.g) - 1.0);
result.b = (x.b >= 0.0) ? x.b : (exp(x.b) - 1.0);
result.a = (x.a >= 0.0) ? x.a : (exp(x.a) - 1.0);
return result;
`, hs = function() {
function n(t, e) {
this.variableNames = ["A"], this.packedInputs = true, this.packedOutput = true, this.outputShape = t, this.userCode = `
vec4 unaryOperation(vec4 x) {
` + e + `
}
void main() {
vec4 x = getAAtOutCoords();
vec4 y = unaryOperation(x);
setOutput(y);
}
`;
}
return n;
}();
var Gz = function() {
function n(t) {
this.variableNames = ["A"], this.packedInputs = true, this.packedOutput = false, this.outputShape = t;
var e = t.length, r = Ut("rc", e), i = Ze(e), a = $W(e, r), s = r.slice(-2), o = e <= 1 ? "rc" : "vec2(" + s.join(",") + ")";
this.userCode = `
void main() {
` + i + ` rc = getOutputCoords();
vec4 packedInput = getA(` + a + `);
setOutput(getChannel(packedInput, ` + o + `));
}
`;
}
return n;
}();
var c2 = _.backend_util.segment_util, qz = _.kernel_impls.split, Yz = _.kernel_impls.tile, Kz = _.kernel_impls.topkImpl, jz = _.kernel_impls.whereImpl, $z = 1e-7, Xz = 1e-4, $o = {};
function Jz(n) {
return n in $o || ($o[n] = {}), $o[n];
}
function Xo(n, t) {
if (t === void 0 && (t = false), n === "linear")
return t ? Hz : gz;
if (n === "relu")
return t ? a2 : Jb;
if (n === "elu")
return t ? o2 : Qb;
if (n === "relu6")
return t ? s2 : Zb;
if (n === "prelu")
return t ? wb : vb;
throw new Error("Activation " + n + " has not been implemented for the WebGL backend.");
}
var Zz = 128, Qz = 600;
function eP() {
return _.env().global.screen == null ? 1024 : _.env().global.screen.height * _.env().global.screen.width * window.devicePixelRatio * Qz / 1024 / 1024;
}
var l2 = 1e3, u2 = function(n) {
nW(t, n);
function t(e) {
var r = n.call(this) || this;
if (r.pendingRead = new WeakMap(), r.pendingDisposal = new WeakSet(), r.dataRefCount = new WeakMap(), r.numBytesInGPU = 0, r.uploadWaitMs = 0, r.downloadWaitMs = 0, r.warnedAboutMemory = false, r.warnedAboutCPUBackend = false, r.pendingDeletes = 0, r.disposed = false, !_.env().getBool("HAS_WEBGL"))
throw new Error("WebGL is not supported on this device");
if (e == null) {
var i = zn(_.env().getNumber("WEBGL_VERSION"));
r.binaryCache = Jz(_.env().getNumber("WEBGL_VERSION")), r.gpgpu = new Hb(i), r.canvas = i.canvas, r.gpgpuCreatedLocally = true;
} else
r.gpgpu = e, r.binaryCache = {}, r.gpgpuCreatedLocally = false, r.canvas = e.gl.canvas;
return r.textureManager = new uz(r.gpgpu), r.numMBBeforeWarning = eP(), r.texData = new _.DataStorage(r, _.engine()), r;
}
return t.prototype.numDataIds = function() {
return this.texData.numDataIds() + (this.cpuBackend ? this.cpuBackend.numDataIds() : 0) - this.pendingDeletes;
}, t.prototype.write = function(e, r, i) {
if ((_.env().getBool("WEBGL_CHECK_NUMERICAL_PROBLEMS") || _.env().getBool("DEBUG")) && this.checkNumericalProblems(e), i === "complex64" && e != null)
throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");
var a = {};
return this.texData.set(a, {shape: r, dtype: i, values: e, usage: cn.UPLOAD, refCount: 1, complexParentRefCount: 0}), a;
}, t.prototype.incRef = function(e) {
var r = this.texData.get(e);
r.refCount++;
}, t.prototype.decRef = function(e) {
if (this.texData.has(e)) {
var r = this.texData.get(e);
r.refCount--;
}
}, t.prototype.move = function(e, r, i, a) {
if (_.env().getBool("DEBUG") && this.checkNumericalProblems(r), a === "complex64")
throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");
this.texData.set(e, {shape: i, dtype: a, values: r, usage: cn.UPLOAD, refCount: 1, complexParentRefCount: 0});
}, t.prototype.disposeIntermediateTensorInfo = function(e) {
var r = e.dataId;
if (this.texData.has(r)) {
var i = this.texData.get(r);
i.refCount--, i.refCount < 1 && this.disposeData(r);
}
}, t.prototype.readSync = function(e) {
var r = this.texData.get(e), i = r.values, a = r.dtype, s = r.complexTensorInfos, o = r.slice, c = r.shape, l = r.isPacked;
if (o != null) {
var u = void 0;
l ? u = new hs(c, jo) : u = new De(c, jo);
var h = this.runWebGLProgram(u, [{dataId: e, shape: c, dtype: a}], a), d = this.readSync(h.dataId);
return this.disposeIntermediateTensorInfo(h), d;
}
if (i != null)
return this.convertAndCacheOnCPU(e);
if (a === "string")
return i;
var p = this.activeTimers != null, f;
p && (f = _.util.now());
var m;
if (a === "complex64") {
var g = this.readSync(s.real.dataId), y = this.readSync(s.imag.dataId);
m = _.backend_util.mergeRealAndImagArrays(g, y);
} else
m = this.getValuesFromTexture(e);
return p && (this.downloadWaitMs += _.util.now() - f), this.convertAndCacheOnCPU(e, m);
}, t.prototype.read = function(e) {
return zo(this, void 0, void 0, function() {
var r, i, a, s, o, c, l, u, h, d, p, f, m, g, y, w, b, x, L, N, I, C;
return Po(this, function(O) {
switch (O.label) {
case 0:
if (this.pendingRead.has(e))
return r = this.pendingRead.get(e), [2, new Promise(function(D) {
return r.push(D);
})];
if (i = this.texData.get(e), a = i.values, s = i.shape, o = i.slice, c = i.dtype, l = i.complexTensorInfos, u = i.isPacked, o != null)
return h = void 0, u ? h = new hs(s, jo) : h = new De(s, jo), d = this.runWebGLProgram(h, [{dataId: e, shape: s, dtype: c}], c), p = this.read(d.dataId), this.disposeIntermediateTensorInfo(d), [2, p];
if (a != null)
return [2, this.convertAndCacheOnCPU(e)];
if (!_.env().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED") && _.env().getNumber("WEBGL_VERSION") === 2)
throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported.");
return f = null, c !== "complex64" && _.env().get("WEBGL_BUFFER_SUPPORTED") && (m = this.decode(e), g = this.texData.get(m.dataId), f = (C = this.gpgpu).createBufferFromTexture.apply(C, [g.texture].concat(as(s)))), this.pendingRead.set(e, []), c !== "complex64" ? [4, this.gpgpu.createAndWaitForFence()] : [3, 2];
case 1:
O.sent(), O.label = 2;
case 2:
return c === "complex64" ? [4, Promise.all([this.read(l.real.dataId), this.read(l.imag.dataId)])] : [3, 4];
case 3:
return w = O.sent(), b = w[0], x = w[1], y = _.backend_util.mergeRealAndImagArrays(b, x), [3, 5];
case 4:
f == null ? y = this.getValuesFromTexture(e) : (L = _.util.sizeFromShape(s), y = this.gpgpu.downloadFloat32MatrixFromBuffer(f, L)), O.label = 5;
case 5:
return m != null && this.disposeIntermediateTensorInfo(m), N = this.convertAndCacheOnCPU(e, y), I = this.pendingRead.get(e), this.pendingRead.delete(e), I.forEach(function(D) {
return D(N);
}), this.pendingDisposal.has(e) && (this.pendingDisposal.delete(e), this.disposeData(e), this.pendingDeletes--), [2, N];
}
});
});
}, t.prototype.checkNumericalProblems = function(e) {
if (e == null)
return;
for (var r = 0; r < e.length; r++) {
var i = e[r];
if (!Vw(i))
throw _.env().getBool("WEBGL_RENDER_FLOAT32_CAPABLE") ? Error("The value " + i + " cannot be represented with your current settings. Consider enabling float32 rendering: 'tf.env().set('WEBGL_RENDER_FLOAT32_ENABLED', true);'") : Error("The value " + i + " cannot be represented on this device.");
}
}, t.prototype.getValuesFromTexture = function(e) {
var r, i = this.texData.get(e), a = i.shape, s = i.dtype, o = i.isPacked, c = _.util.sizeFromShape(a);
if (_.env().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")) {
var l = this.decode(e), u = this.texData.get(l.dataId), h = (r = this.gpgpu).downloadMatrixFromPackedTexture.apply(r, [u.texture].concat(as(a))).subarray(0, c);
return this.disposeIntermediateTensorInfo(l), h;
}
var d = _.env().getBool("WEBGL_PACK") && o === true, p = d ? Vo(a) : a, f = d ? new SB(p) : new LB(p), m = this.runWebGLProgram(f, [{shape: p, dtype: s, dataId: e}], "float32"), g = this.texData.get(m.dataId), y = this.gpgpu.downloadByteEncodedFloatMatrixFromOutputTexture(g.texture, g.texShape[0], g.texShape[1]).subarray(0, c);
return this.disposeIntermediateTensorInfo(m), y;
}, t.prototype.time = function(e) {
return zo(this, void 0, void 0, function() {
var r, i, a, s, o, c, l;
return Po(this, function(u) {
switch (u.label) {
case 0:
return r = this.activeTimers, i = [], a = false, this.programTimersStack == null ? (this.programTimersStack = i, a = true) : this.activeTimers.push(i), this.activeTimers = i, e(), s = _.util.flatten(this.activeTimers.map(function(h) {
return h.query;
})).filter(function(h) {
return h != null;
}), o = _.util.flatten(this.activeTimers.map(function(h) {
return h.name;
})).filter(function(h) {
return h != null;
}), this.activeTimers = r, a && (this.programTimersStack = null), c = {uploadWaitMs: this.uploadWaitMs, downloadWaitMs: this.downloadWaitMs, kernelMs: null, wallMs: null}, _.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE") > 0 ? [4, Promise.all(s)] : [3, 2];
case 1:
return l = u.sent(), c.kernelMs = _.util.sum(l), c.getExtraProfileInfo = function() {
return l.map(function(h, d) {
return {name: o[d], ms: h};
}).map(function(h) {
return h.name + ": " + h.ms;
}).join(", ");
}, [3, 3];
case 2:
c.kernelMs = {error: "WebGL query timers are not supported in this environment."}, u.label = 3;
case 3:
return this.uploadWaitMs = 0, this.downloadWaitMs = 0, [2, c];
}
});
});
}, t.prototype.memory = function() {
return {unreliable: false, numBytesInGPU: this.numBytesInGPU, numBytesInGPUAllocated: this.textureManager.numBytesAllocated, numBytesInGPUFree: this.textureManager.numBytesFree};
}, t.prototype.startTimer = function() {
return _.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE") > 0 ? this.gpgpu.beginQuery() : {startMs: _.util.now(), endMs: null};
}, t.prototype.endTimer = function(e) {
return _.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE") > 0 ? (this.gpgpu.endQuery(), e) : (e.endMs = _.util.now(), e);
}, t.prototype.getQueryTime = function(e) {
return zo(this, void 0, void 0, function() {
var r;
return Po(this, function(i) {
return _.env().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE") > 0 ? [2, this.gpgpu.waitForQueryAndGetTime(e)] : (r = e, [2, r.endMs - r.startMs]);
});
});
}, t.prototype.disposeData = function(e) {
if (this.pendingDisposal.has(e))
return;
if (this.pendingRead.has(e)) {
this.pendingDisposal.add(e), this.pendingDeletes++;
return;
}
if (!this.texData.has(e))
return;
if (this.texData.get(e).complexParentRefCount > 0) {
this.texData.get(e).refCount--;
return;
}
this.releaseGPUData(e);
var r = this.texData.get(e).complexTensorInfos;
r != null && (this.texData.get(r.real.dataId).complexParentRefCount--, this.disposeIntermediateTensorInfo(r.real), this.texData.get(r.imag.dataId).complexParentRefCount--, this.disposeIntermediateTensorInfo(r.imag)), this.texData.delete(e);
}, t.prototype.releaseGPUData = function(e) {
var r = this.texData.get(e), i = r.texture, a = r.dtype, s = r.texShape, o = r.usage, c = r.isPacked, l = r.slice, u = l && l.origDataId || e, h = this.dataRefCount.get(u);
h > 1 ? this.dataRefCount.set(u, h - 1) : (this.dataRefCount.delete(u), i != null && (this.numBytesInGPU -= this.computeBytes(s, a), this.textureManager.releaseTexture(i, s, o, c)));
var d = this.texData.get(e);
d.texture = null, d.texShape = null, d.isPacked = false, d.slice = null;
}, t.prototype.getTexture = function(e) {
return this.uploadToGPU(e), this.texData.get(e).texture;
}, t.prototype.getDataInfo = function(e) {
return this.texData.get(e);
}, t.prototype.getCPUBackend = function() {
return _.env().getBool("WEBGL_CPU_FORWARD") ? (this.cpuBackend == null && (this.cpuBackend = _.engine().findBackend("cpu")), this.cpuBackend) : null;
}, t.prototype.shouldExecuteOnCPU = function(e, r) {
var i = this;
r === void 0 && (r = Zz);
var a = this.getCPUBackend();
return !this.warnedAboutCPUBackend && a == null && (console.warn("Your application contains ops that are small enough to be executed on the CPU backend, however the CPU backend cannot be found. Consider importing the CPU backend (@tensorflow/tfjs-backend-cpu) for better performance."), this.warnedAboutCPUBackend = true), a != null && e.every(function(s) {
return i.texData.get(s.dataId).texture == null && _.util.sizeFromShape(s.shape) < r;
});
}, t.prototype.getGPGPUContext = function() {
return this.gpgpu;
}, t.prototype.slice = function(e, r, i) {
if (this.shouldExecuteOnCPU([e])) {
var a = VW(this.texData.get(e.dataId).values, r, i, e.shape, e.dtype);
return this.makeOutput(i, e.dtype, a);
}
if (_.util.sizeFromShape(i) === 0)
return _.tensor([], i, e.dtype);
var s = this.texData.get(e.dataId).isPacked, o = _.slice_util.isSliceContinous(e.shape, r, i);
if (s || !o) {
var c = _.env().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new cz(i) : new oz(i), l = c.getCustomSetupFunc(r);
return this.compileAndRun(c, [e], null, l);
}
return this.uploadToGPU(e.dataId), this.shallowSlice(e, r, i);
}, t.prototype.shallowSlice = function(e, r, i) {
var a = this.texData.get(e.dataId), s = this.makeOutput(i, e.dtype), o = this.texData.get(s.dataId);
Object.assign(o, a), o.shape = i, o.dtype = e.dtype;
var c = _.slice_util.computeFlatOffset(r, e.strides);
a.slice && (c += a.slice.flatOffset), o.slice = {flatOffset: c, origDataId: a.slice && a.slice.origDataId || e.dataId};
var l = this.dataRefCount.get(o.slice.origDataId) || 1;
return this.dataRefCount.set(o.slice.origDataId, l + 1), s;
}, t.prototype.stridedSlice = function(e, r, i, a) {
var s = this, o = this.tryRunOnCpuOrThrow([e], function() {
return s.cpuBackend.stridedSlice(e, r, i, a);
});
if (o)
return o;
var c = _.slice_util.computeOutShape(r, i, a);
if (c.some(function(u) {
return u === 0;
}))
return _.tensor([], c);
var l = new lz(r, a, c);
return this.compileAndRun(l, [e]);
}, t.prototype.reverse = function(e, r) {
var i = _.env().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new rz(e.shape, r) : new nz(e.shape, r);
return this.compileAndRun(i, [e]);
}, t.prototype.neg = function(e) {
var r = this, i = this.tryRunOnCpuOrThrow([e], function() {
return r.cpuBackend.neg(e);
});
if (i)
return i;
if (_.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))
return this.packedUnaryOp(e, e2, e.dtype);
var a = new De(e.shape, e2);
return this.compileAndRun(a, [e]);
}, t.prototype.batchMatMul = function(e, r, i, a) {
var s = i ? e.shape[2] : e.shape[1], o = a ? r.shape[1] : r.shape[2], c = i ? e.shape[1] : e.shape[2], l = Math.max(e.shape[0], r.shape[0]);
if ((s === 1 || o === 1) && c > l2) {
i && (e = _.transpose(e, [0, 2, 1])), a && (r = _.transpose(r, [0, 2, 1]));
var u = o === 1 ? e : e.as3D(l, c, 1), h = o === 1 ? 2 : 1, d = o === 1 ? r.as3D(l, 1, c) : r, p = _.mul(u, d);
return p.sum(h, true);
}
var f = _.upcastType(e.dtype, r.dtype), m = new tp(e.shape, r.shape, [l, s, o], i, a);
return this.compileAndRun(m, [e, r], f);
}, t.prototype.fusedBatchMatMul = function(e) {
var r = e.a, i = e.b, a = e.transposeA, s = e.transposeB, o = e.bias, c = e.activation, l = e.preluActivationWeights, u = a ? r.shape[2] : r.shape[1], h = s ? i.shape[1] : i.shape[2], d = Math.max(r.shape[0], i.shape[0]), p = _.upcastType(r.dtype, i.dtype), f = o != null, m = l != null, g = c ? Xo(c, true) : null, y = new tp(r.shape, i.shape, [d, u, h], a, s, f, g, m), w = [r, i];
return o && w.push(o), l && w.push(l), this.compileAndRun(y, w, p);
}, t.prototype.localResponseNormalization4D = function(e, r, i, a, s) {
var o = _.env().getBool("WEBGL_PACK_NORMALIZATION") ? new BB(e.shape, r, i, a, s) : new WB(e.shape, r, i, a, s);
return this.compileAndRun(o, [e]);
}, t.prototype.LRNGrad = function(e, r, i, a, s, o, c) {
var l = new UB(r.shape, a, s, o, c);
return this.compileAndRun(l, [r, i, e]);
}, t.prototype.tile = function(e, r) {
if (e.dtype === "string") {
var i = this.readSync(e.dataId), a = i.map(function(c) {
return _.util.decodeString(c);
}), s = _.buffer(e.shape, e.dtype, a);
return Yz(s, r);
}
var o = new mz(e.shape, r);
return this.compileAndRun(o, [e]);
}, t.prototype.pad = function(e, r, i) {
var a = _.env().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new $B(e.shape, r, i) : new jB(e.shape, r, i);
return this.compileAndRun(a, [e]);
}, t.prototype.gather = function(e, r, i) {
var a = this, s = this.tryRunOnCpuOrThrow([e, r], function() {
return a.cpuBackend.gather(e, r, i);
});
if (s)
return s;
var o = new _B(e.shape, r.size, i);
return this.compileAndRun(o, [e, r]);
}, t.prototype.batchToSpaceND = function(e, r, i) {
_.util.assert(e.rank <= 4, function() {
return "batchToSpaceND for rank > 4 with a WebGL backend not implemented yet";
});
var a = r.reduce(function(h, d) {
return h * d;
}), s = _.backend_util.getReshaped(e.shape, r, a), o = _.backend_util.getPermuted(s.length, r.length), c = _.backend_util.getReshapedPermuted(e.shape, r, a), l = _.backend_util.getSliceBeginCoords(i, r.length), u = _.backend_util.getSliceSize(c, i, r.length);
return _.transpose(e.reshape(s), o).reshape(c).slice(l, u);
}, t.prototype.spaceToBatchND = function(e, r, i) {
_.util.assert(e.rank <= 4, function() {
return "spaceToBatchND for rank > 4 with a WebGL backend not implemented yet";
});
var a = r.reduce(function(p, f) {
return p * f;
}), s = [[0, 0]];
s.push.apply(s, i);
for (var o = 1 + r.length; o < e.shape.length; ++o)
s.push([0, 0]);
var c = e.pad(s), l = _.backend_util.getReshaped(c.shape, r, a, false), u = _.backend_util.getPermuted(l.length, r.length, false), h = _.backend_util.getReshapedPermuted(c.shape, r, a, false), d = _.transpose(c.reshape(l), u);
return _.reshape(d, h);
}, t.prototype.reduce = function(e, r, i) {
var a = e.shape[0], s = e.shape[1], o = _.backend_util.computeOptimalWindowSize(s), c = Math.ceil(s / o), l = {windowSize: o, inSize: s, batchSize: a, outSize: c}, u = new Gb(l, r), h = this.compileAndRun(u, [e], i);
return h.shape[1] === 1 ? h : this.reduce(h, r, i);
}, t.prototype.argReduce = function(e, r, i) {
i === void 0 && (i = null);
var a = e.shape[0], s = e.shape[1];
i != null && (a = i.shape[0], s = i.shape[1]);
var o = _.backend_util.computeOptimalWindowSize(s), c = {windowSize: o, inSize: s, batchSize: a, outSize: Math.ceil(s / o)}, l = new jW(c, r, i == null), u = [e];
i != null && u.push(i);
var h = this.compileAndRun(l, u, "int32");
return h.shape[1] === 1 ? h : this.argReduce(e, r, h);
}, t.prototype.argReducePacked = function(e, r, i) {
i === void 0 && (i = null);
var a = i != null ? i.shape : e.shape, s = a[a.length - 1], o = _.backend_util.computeOptimalWindowSize(s), c = new EU(a, o, r, i == null), l = i == null ? [e] : [e, i], u = this.compileAndRun(c, l, "int32");
return u.rank === e.rank ? this.argReducePacked(e, r, u) : u;
}, t.prototype.sum = function(e, r) {
_.backend_util.assertAxesAreInnerMostDims("sum", r, e.rank);
var i = _.backend_util.computeOutAndReduceShapes(e.shape, r), a = i[0], s = i[1], o = _.util.sizeFromShape(s), c = e.as2D(-1, o), l = _.sumOutType(e.dtype);
return this.reduce(c, "sum", l).reshape(a);
}, t.prototype.prod = function(e, r) {
var i = this, a = this.tryRunOnCpuOrThrow([e], function() {
return i.cpuBackend.prod(e, r);
});
if (a)
return a;
var s = _.backend_util.computeOutAndReduceShapes(e.shape, r), o = s[0], c = s[1], l = _.util.sizeFromShape(c), u = e.as2D(-1, l), h = _.sumOutType(e.dtype);
return this.reduce(u, "prod", h).reshape(o);
}, t.prototype.unsortedSegmentSum = function(e, r, i) {
var a = 0, s = _.backend_util.getAxesPermutation([a], e.rank), o = e;
s != null && (o = _.transpose(e, s), a = _.backend_util.getInnerMostAxes(1, e.rank)[0]);
var c = c2.computeOutShape(o.shape, a, i), l = _.util.sizeFromShape([o.shape[a]]), u = o.as2D(-1, l), h = _.sumOutType(e.dtype), d = this.segOpCompute(u, "unsortedSegmentSum", r, h, i).reshape(c);
return s != null && (d = _.transpose(d, _.backend_util.getUndoAxesPermutation(s))), d;
}, t.prototype.segOpCompute = function(e, r, i, a, s) {
var o = e.shape[0], c = e.shape[1], l = c2.segOpComputeOptimalWindowSize(c, s), u = {windowSize: l, inSize: c, batchSize: o, numSegments: s}, h = new iz(u, r), d = this.compileAndRun(h, [e, i], a);
return d.shape[1] === s ? d : (i = _.range(0, s).tile([c / l]), this.segOpCompute(d, r, i, a, s));
}, t.prototype.argMinMaxReduce = function(e, r, i) {
var a = [r];
if (_.backend_util.assertAxesAreInnerMostDims("arg" + i.charAt(0).toUpperCase() + i.slice(1), a, e.rank), !_.env().getBool("WEBGL_PACK_REDUCE") || e.rank <= 2) {
var s = _.backend_util.computeOutAndReduceShapes(e.shape, a), o = s[0], c = s[1], l = _.util.sizeFromShape(c), u = e.as2D(-1, l);
return this.argReduce(u, i).reshape(o);
}
return this.argReducePacked(e, i);
}, t.prototype.argMin = function(e, r) {
return this.argMinMaxReduce(e, r, "min");
}, t.prototype.argMax = function(e, r) {
return this.argMinMaxReduce(e, r, "max");
}, t.prototype.cumsum = function(e, r, i, a) {
if (r !== e.rank - 1)
throw new Error("WebGL cumsum shader expects an inner-most axis=" + (e.rank - 1) + " " + ("but got axis=" + r));
for (var s = e.shape[r], o = e, c = 0; c <= Math.ceil(Math.log2(s)) - 1; c++) {
var l = new Ab(e.shape, false, a), u = l.getCustomSetupFunc(c), h = o;
o = this.compileAndRun(l, [o], o.dtype, u), h.dispose();
}
if (i) {
var l = new Ab(e.shape, i, a), h = o;
o = this.compileAndRun(l, [o]), h.dispose();
}
return o;
}, t.prototype.equal = function(e, r) {
if (_.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))
return this.packedBinaryOp(e, r, JU, "bool");
var i = new Wt(UU, e.shape, r.shape);
return this.compileAndRun(i, [e, r], "bool");
}, t.prototype.less = function(e, r) {
var i = this, a = this.tryRunOnCpuOrThrow([e, r], function() {
return i.cpuBackend.less(e, r);
});
if (a)
return a;
if (_.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))
return this.packedBinaryOp(e, r, ZU, "bool");
var s = new Wt(BU, e.shape, r.shape);
return this.compileAndRun(s, [e, r], "bool");
}, t.prototype.lessEqual = function(e, r) {
if (_.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))
return this.packedBinaryOp(e, r, QU, "bool");
var i = new Wt(zU, e.shape, r.shape);
return this.compileAndRun(i, [e, r], "bool");
}, t.prototype.greater = function(e, r) {
var i = this, a = this.tryRunOnCpuOrThrow([e, r], function() {
return i.cpuBackend.greater(e, r);
});
if (a)
return a;
if (_.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))
return this.packedBinaryOp(e, r, eB, "bool");
var s = new Wt(PU, e.shape, r.shape);
return this.compileAndRun(s, [e, r], "bool");
}, t.prototype.greaterEqual = function(e, r) {
if (_.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))
return this.packedBinaryOp(e, r, tB, "bool");
var i = new Wt(MU, e.shape, r.shape);
return this.compileAndRun(i, [e, r], "bool");
}, t.prototype.logicalNot = function(e) {
var r = new De(e.shape, Mz);
return this.compileAndRun(r, [e]);
}, t.prototype.logicalAnd = function(e, r) {
if (_.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))
return this.packedBinaryOp(e, r, nB, "bool");
var i = new Wt(HU, e.shape, r.shape);
return this.compileAndRun(i, [e, r], "bool");
}, t.prototype.logicalOr = function(e, r) {
if (_.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))
return this.packedBinaryOp(e, r, rB, "bool");
var i = new Wt(VU, e.shape, r.shape);
return this.compileAndRun(i, [e, r], "bool");
}, t.prototype.select = function(e, r, i) {
var a = new az(e.rank, r.shape, r.rank);
return this.compileAndRun(a, [e, r, i], _.upcastType(r.dtype, i.dtype));
}, t.prototype.where = function(e) {
_.backend_util.warn("tf.where() in webgl locks the UI thread. Call tf.whereAsync() instead");
var r = e.dataSync();
return jz(e.shape, r);
}, t.prototype.topk = function(e, r, i) {
var a = e.dataSync();
return Kz(a, e.shape, e.dtype, r, i);
}, t.prototype.min = function(e, r) {
_.backend_util.assertAxesAreInnerMostDims("min", r, e.rank);
var i = _.backend_util.computeOutAndReduceShapes(e.shape, r), a = i[0], s = i[1], o = _.util.sizeFromShape(s), c = e.as2D(-1, o);
return this.reduce(c, "min", c.dtype).reshape(a);
}, t.prototype.minimum = function(e, r) {
var i = this, a = this.tryRunOnCpuOrThrow([e, r], function() {
return i.cpuBackend.minimum(e, r);
});
if (a)
return a;
var s = _.env().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new rr(aB, e.shape, r.shape) : new Wt(qU, e.shape, r.shape);
return this.compileAndRun(s, [e, r]);
}, t.prototype.mod = function(e, r) {
var i = _.env().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new rr(sB, e.shape, r.shape) : new Wt(YU, e.shape, r.shape);
return this.compileAndRun(i, [e, r]);
}, t.prototype.maximum = function(e, r) {
var i = this, a = this.tryRunOnCpuOrThrow([e, r], function() {
return i.cpuBackend.maximum(e, r);
});
if (a)
return a;
var s = _.env().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new rr(iB, e.shape, r.shape) : new Wt(GU, e.shape, r.shape);
return this.compileAndRun(s, [e, r]);
}, t.prototype.all = function(e, r) {
_.backend_util.assertAxesAreInnerMostDims("all", r, e.rank);
var i = _.backend_util.computeOutAndReduceShapes(e.shape, r), a = i[0], s = i[1], o = _.util.sizeFromShape(s), c = e.as2D(-1, o);
return this.reduce(c, "all", c.dtype).reshape(a);
}, t.prototype.any = function(e, r) {
_.backend_util.assertAxesAreInnerMostDims("any", r, e.rank);
var i = _.backend_util.computeOutAndReduceShapes(e.shape, r), a = i[0], s = i[1], o = _.util.sizeFromShape(s), c = e.as2D(-1, o);
return this.reduce(c, "any", c.dtype).reshape(a);
}, t.prototype.floorDiv = function(e, r) {
var i = FU, a = "int32";
if (_.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"))
return this.packedBinaryOp(e, r, jU, a);
var s = new Wt(i, e.shape, r.shape);
return this.compileAndRun(s, [e, r], a);
}, t.prototype.packedUnaryOp = function(e, r, i) {
var a = new hs(e.shape, r);
return this.compileAndRun(a, [e], i);
}, t.prototype.packedBinaryOp = function(e, r, i, a, s) {
s === void 0 && (s = false);
var o = new rr(i, e.shape, r.shape, s);
return this.compileAndRun(o, [e, r], a);
}, t.prototype.makeComplexComponentTensorInfo = function(e, r) {
return {dataId: r.dataId, dtype: r.dtype, shape: e.shape};
}, t.prototype.addN = function(e) {
if (e.length === 1)
return e[0];
if (e.length > _.env().get("WEBGL_MAX_TEXTURES_IN_SHADER")) {
var r = Math.floor(e.length / 2), i = this.addN(e.slice(0, r)), a = this.addN(e.slice(r));
return this.addN([i, a]);
}
var s = e.map(function(u) {
return u.dtype;
}).reduce(function(u, h) {
return _.upcastType(u, h);
}), o = e.map(function(u) {
return u.shape;
}), c = _.env().getBool("WEBGL_PACK"), l = c ? new KW(e[0].shape, o) : new YW(e[0].shape, o);
return this.compileAndRun(l, e, s);
}, t.prototype.pow = function(e, r) {
var i = _.env().getBool("WEBGL_PACK_BINARY_OPERATIONS"), a = i ? new rr($U, e.shape, r.shape) : new Wt(WU, e.shape, r.shape), s = _.upcastType(e.dtype, r.dtype);
return this.compileAndRun(a, [e, r], s);
}, t.prototype.ceil = function(e) {
if (this.shouldExecuteOnCPU([e])) {
var r = FW(this.texData.get(e.dataId).values, e.dtype);
return this.makeOutput(e.shape, e.dtype, r);
}
if (_.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))
return this.packedUnaryOp(e, t2, e.dtype);
var i = new De(e.shape, t2);
return this.compileAndRun(i, [e]);
}, t.prototype.floor = function(e) {
if (this.shouldExecuteOnCPU([e])) {
var r = BW(this.texData.get(e.dataId).values, e.dtype);
return this.makeOutput(e.shape, e.dtype, r);
}
if (_.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))
return this.packedUnaryOp(e, n2, e.dtype);
var i = new De(e.shape, n2);
return this.compileAndRun(i, [e]);
}, t.prototype.sign = function(e) {
var r = new De(e.shape, wz);
return this.compileAndRun(r, [e]);
}, t.prototype.isNaN = function(e) {
var r = new De(e.shape, bz);
return this.compileAndRun(r, [e], "bool");
}, t.prototype.isInf = function(e) {
var r = new De(e.shape, xz);
return this.compileAndRun(r, [e], "bool");
}, t.prototype.isFinite = function(e) {
var r = new De(e.shape, Lz);
return this.compileAndRun(r, [e], "bool");
}, t.prototype.round = function(e) {
var r = new De(e.shape, Sz);
return this.compileAndRun(r, [e]);
}, t.prototype.exp = function(e) {
if (this.shouldExecuteOnCPU([e])) {
var r = WW(this.texData.get(e.dataId).values, e.dtype);
return this.makeOutput(e.shape, e.dtype, r);
}
if (_.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))
return this.packedUnaryOp(e, r2, e.dtype);
var i = new De(e.shape, r2);
return this.compileAndRun(i, [e]);
}, t.prototype.expm1 = function(e) {
if (this.shouldExecuteOnCPU([e])) {
var r = UW(this.texData.get(e.dataId).values, e.dtype);
return this.makeOutput(e.shape, e.dtype, r);
}
if (_.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))
return this.packedUnaryOp(e, i2, e.dtype);
var i = new De(e.shape, i2);
return this.compileAndRun(i, [e]);
}, t.prototype.softmax = function(e, r) {
var i = _.util.parseAxisParam([r], e.shape), a = _.max(e, i), s = _.backend_util.expandShapeToKeepDim(a.shape, i), o = _.sub(e, a.reshape(s)), c = this.exp(o), l = this.sum(c, i).reshape(s);
return _.div(c, l);
}, t.prototype.log = function(e) {
if (this.shouldExecuteOnCPU([e])) {
var r = zW(this.texData.get(e.dataId).values, e.dtype);
return this.makeOutput(e.shape, e.dtype, r);
}
if (_.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))
return this.packedUnaryOp(e, Vz, e.dtype);
var i = new De(e.shape, Iz);
return this.compileAndRun(i, [e]);
}, t.prototype.log1p = function(e) {
var r = new De(e.shape, Az);
return this.compileAndRun(r, [e]);
}, t.prototype.sqrt = function(e) {
var r = new De(e.shape, Tz);
return this.compileAndRun(r, [e]);
}, t.prototype.rsqrt = function(e) {
if (this.shouldExecuteOnCPU([e])) {
var r = HW(this.texData.get(e.dataId).values, e.dtype);
return this.makeOutput(e.shape, e.dtype, r);
}
var i = new De(e.shape, Nz);
return this.compileAndRun(i, [e]);
}, t.prototype.reciprocal = function(e) {
var r = new De(e.shape, Pz);
return this.compileAndRun(r, [e]);
}, t.prototype.relu = function(e) {
var r;
return _.env().getBool("WEBGL_PACK") ? r = new hs(e.shape, a2) : r = new De(e.shape, Jb), this.compileAndRun(r, [e]);
}, t.prototype.relu6 = function(e) {
var r;
return _.env().getBool("WEBGL_PACK") ? r = new hs(e.shape, s2) : r = new De(e.shape, Zb), this.compileAndRun(r, [e]);
}, t.prototype.prelu = function(e, r) {
var i = _.env().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new rr(wb, e.shape, r.shape) : new Wt(vb, e.shape, r.shape);
return this.compileAndRun(i, [e, r]);
}, t.prototype.elu = function(e) {
if (_.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))
return this.packedUnaryOp(e, o2, e.dtype);
var r = new De(e.shape, Qb);
return this.compileAndRun(r, [e]);
}, t.prototype.eluDer = function(e, r) {
var i = _.env().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new rr(XU, e.shape, r.shape) : new Wt(KU, e.shape, r.shape);
return this.compileAndRun(i, [e, r]);
}, t.prototype.selu = function(e) {
var r = new De(e.shape, yz);
return this.compileAndRun(r, [e]);
}, t.prototype.clip = function(e, r, i) {
var a;
_.env().getBool("WEBGL_PACK_CLIP") ? a = new cB(e.shape) : a = new oB(e.shape);
var s = a.getCustomSetupFunc(r, i);
return this.compileAndRun(a, [e], null, s);
}, t.prototype.abs = function(e) {
if (this.shouldExecuteOnCPU([e]) && e.dtype !== "complex64") {
var r = DW(this.texData.get(e.dataId).values);
return this.makeOutput(e.shape, e.dtype, r);
}
if (_.env().getBool("WEBGL_PACK_UNARY_OPERATIONS"))
return this.packedUnaryOp(e, Xb, e.dtype);
var i = new De(e.shape, Xb);
return this.compileAndRun(i, [e]);
}, t.prototype.complexAbs = function(e) {
var r = this.texData.get(e.dataId), i = new lB(e.shape), a = [this.makeComplexComponentTensorInfo(e, r.complexTensorInfos.real), this.makeComplexComponentTensorInfo(e, r.complexTensorInfos.imag)];
return this.compileAndRun(i, a);
}, t.prototype.sigmoid = function(e) {
var r = new De(e.shape, _z);
return this.compileAndRun(r, [e]);
}, t.prototype.softplus = function(e) {
var r = new De(e.shape, Cz);
return this.compileAndRun(r, [e]);
}, t.prototype.asin = function(e) {
var r = new De(e.shape, Rz);
return this.compileAndRun(r, [e]);
}, t.prototype.acos = function(e) {
var r = new De(e.shape, Oz);
return this.compileAndRun(r, [e]);
}, t.prototype.atan = function(e) {
var r = new De(e.shape, Ez);
return this.compileAndRun(r, [e]);
}, t.prototype.sinh = function(e) {
var r = new De(e.shape, Dz);
return this.compileAndRun(r, [e]);
}, t.prototype.cosh = function(e) {
var r = new De(e.shape, kz);
return this.compileAndRun(r, [e]);
}, t.prototype.tanh = function(e) {
var r = new De(e.shape, Fz);
return this.compileAndRun(r, [e]);
}, t.prototype.asinh = function(e) {
var r = new De(e.shape, Wz);
return this.compileAndRun(r, [e]);
}, t.prototype.acosh = function(e) {
var r = new De(e.shape, Uz);
return this.compileAndRun(r, [e]);
}, t.prototype.atanh = function(e) {
var r = new De(e.shape, Bz);
return this.compileAndRun(r, [e]);
}, t.prototype.erf = function(e) {
var r = new De(e.shape, zz);
return this.compileAndRun(r, [e]);
}, t.prototype.step = function(e, r) {
var i = new De(e.shape, vz(r));
return this.compileAndRun(i, [e]);
}, t.prototype.conv2dByMatMul = function(e, r, i, a, s, o) {
var c = e.shape, l = this.texData.get(e.dataId), u = i.inChannels, h = c[0] * c[1] * c[2], d = i.outChannels, p = i.dataFormat === "channelsLast", f = false, m = false, g = (h === 1 || d === 1) && u > l2, y = c[2] % 2 !== 0 && !!l.isPacked;
if (g || !_.env().getBool("WEBGL_LAZILY_UNPACK") || !_.env().getBool("WEBGL_PACK_BINARY_OPERATIONS") || !y) {
var w = p ? c[0] * c[1] * c[2] : c[0] * c[2] * c[3], b = _.reshape(e, [1, w, i.inChannels]), x = _.reshape(r, [1, i.inChannels, i.outChannels]), L = this.fusedBatchMatMul({a: b, b: x, transposeA: f, transposeB: m, bias: a, activation: s, preluActivationWeights: o});
return _.reshape(L, i.outShape);
}
var N = p ? c[0] * c[1] * (c[2] + 1) : c[0] * c[2] * (c[3] + 1), I = {dataId: e.dataId, shape: [1, N, i.inChannels], dtype: e.dtype}, C = l.shape;
l.shape = l.shape.slice(), l.shape[l.shape.length - 2]++, _.util.assert(cs(l.shape, I.shape), function() {
return "packed reshape " + l.shape + " to " + I.shape + " isn't free";
});
var O = _.reshape(r, [1, i.inChannels, i.outChannels]), D = this.fusedBatchMatMul({a: I, b: O, transposeA: f, transposeB: m, bias: a, activation: s, preluActivationWeights: o}), F = this.texData.get(D.dataId);
return _.util.assert(F.isPacked, function() {
return "batchMatMul result is expected to be packed";
}), l.shape = C, F.shape = i.outShape, _.engine().makeTensorFromDataId(D.dataId, i.outShape, D.dtype);
}, t.prototype.conv2dWithIm2Row = function(e, r, i, a, s, o) {
var c = i.filterWidth, l = i.filterHeight, u = i.inChannels, h = i.outWidth, d = i.outHeight, p = i.dataFormat, f = p === "channelsLast", m = c * l * u, g = d * h, y = [m, g], w = true, b = false, x = e.squeeze([0]), L = r.reshape([1, m, -1]), N = new FB(y, x.shape, i), I = this.compileAndRun(N, [x]).reshape([1, y[0], y[1]]), C = a != null, O = o != null, D = s ? Xo(s, true) : null, F = new tp(I.shape, L.shape, [1, g, i.outChannels], w, b, C, D, O), k = [I, L];
a && k.push(a), O && k.push(o);
var B = this.compileAndRun(F, k);
return f ? B.reshape([1, d, h, i.outChannels]) : B.reshape([1, i.outChannels, d, h]);
}, t.prototype.fusedConv2d = function(e) {
var r = e.input, i = e.filter, a = e.convInfo, s = e.bias, o = e.activation, c = e.preluActivationWeights;
if (a.filterHeight === 1 && a.filterWidth === 1 && a.dilationHeight === 1 && a.dilationWidth === 1 && a.strideHeight === 1 && a.strideWidth === 1 && (a.padInfo.type === "SAME" || a.padInfo.type === "VALID"))
return this.conv2dByMatMul(r, i, a, s, o, c);
if (_.env().getBool("WEBGL_CONV_IM2COL") && r.shape[0] === 1)
return this.conv2dWithIm2Row(r, i, a, s, o, c);
var l = s != null, u = c != null, h = o ? Xo(o, false) : null, d = new bb(a, l, h, u), p = [r, i];
return s && p.push(s), c && p.push(c), this.compileAndRun(d, p);
}, t.prototype.conv2d = function(e, r, i) {
if (i.filterHeight === 1 && i.filterWidth === 1 && i.dilationHeight === 1 && i.dilationWidth === 1 && i.strideHeight === 1 && i.strideWidth === 1 && (i.padInfo.type === "SAME" || i.padInfo.type === "VALID"))
return this.conv2dByMatMul(e, r, i);
if (_.env().getBool("WEBGL_CONV_IM2COL") && e.shape[0] === 1)
return this.conv2dWithIm2Row(e, r, i);
var a = new bb(i);
return this.compileAndRun(a, [e, r]);
}, t.prototype.conv2dDerInput = function(e, r, i) {
var a = new hB(i);
return this.compileAndRun(a, [e, r]);
}, t.prototype.conv2dDerFilter = function(e, r, i) {
var a = new uB(i);
return this.compileAndRun(a, [e, r]);
}, t.prototype.fusedDepthwiseConv2D = function(e) {
var r = e.input, i = e.filter, a = e.convInfo, s = e.bias, o = e.activation, c = e.preluActivationWeights, l = _.env().getBool("WEBGL_PACK_DEPTHWISECONV") && a.strideWidth <= 2 && a.outChannels / a.inChannels === 1, u = o ? Xo(o, l) : null, h = [r, i], d = s != null, p = c != null;
d && h.push(s), p && h.push(c);
var f;
return l ? (f = new Lb(a, d, u, p), this.compileAndRun(f, h)) : (f = new xb(a, d, u, p), this.compileAndRun(f, h));
}, t.prototype.depthwiseConv2D = function(e, r, i) {
var a;
return _.env().getBool("WEBGL_PACK_DEPTHWISECONV") && i.strideWidth <= 2 && i.outChannels / i.inChannels === 1 ? (a = new Lb(i), this.compileAndRun(a, [e, r])) : (a = new xb(i), this.compileAndRun(a, [e, r]));
}, t.prototype.depthwiseConv2DDerInput = function(e, r, i) {
var a = new mB(i);
return this.compileAndRun(a, [e, r]);
}, t.prototype.depthwiseConv2DDerFilter = function(e, r, i) {
var a = new fB(i);
return this.compileAndRun(a, [e, r]);
}, t.prototype.conv3d = function(e, r, i) {
var a = new gB(i);
return this.compileAndRun(a, [e, r]);
}, t.prototype.conv3dDerInput = function(e, r, i) {
var a = new pB(i);
return this.compileAndRun(a, [e, r]);
}, t.prototype.conv3dDerFilter = function(e, r, i) {
var a = new dB(i);
return this.compileAndRun(a, [e, r]);
}, t.prototype.unstack = function(e, r) {
for (var i = e.shape[r], a = new Array(e.rank - 1), s = 0, o = 0; o < e.rank; o++)
o !== r && (a[s++] = e.shape[o]);
var c = new Array(e.rank).fill(0), l = e.shape.slice();
l[r] = 1;
for (var u = new Array(i), o = 0; o < u.length; o++)
c[r] = o, u[o] = this.slice(e, c, l).reshape(a);
return u;
}, t.prototype.avgPool3d = function(e, r) {
var i = new np(r, "avg", false);
return this.compileAndRun(i, [e], "float32");
}, t.prototype.avgPool3dBackprop = function(e, r, i) {
var a = new kU(i);
return this.compileAndRun(a, [e], r.dtype);
}, t.prototype.maxPool3d = function(e, r) {
var i = new np(r, "max", false);
return this.compileAndRun(i, [e], "float32");
}, t.prototype.maxPool3dBackprop = function(e, r, i, a) {
var s = true, o = new np(a, "max", s), c = this.compileAndRun(o, [r]), l = new PB(a), u = this.compileAndRun(l, [e, c], r.dtype);
return c.dispose(), u;
}, t.prototype.resizeBilinear = function(e, r, i, a) {
var s = _.env().getBool("WEBGL_PACK_IMAGE_OPERATIONS") ? new QB(e.shape, r, i, a) : new ZB(e.shape, r, i, a);
return this.compileAndRun(s, [e], "float32");
}, t.prototype.resizeBilinearBackprop = function(e, r, i) {
var a = new JB(e, r, i);
return this.compileAndRun(a, [e]);
}, t.prototype.resizeNearestNeighbor = function(e, r, i, a) {
var s = new tz(e.shape, r, i, a);
return this.compileAndRun(s, [e]);
}, t.prototype.resizeNearestNeighborBackprop = function(e, r, i) {
var a = new ez(e, r, i);
return this.compileAndRun(a, [e]);
}, t.prototype.multinomial = function(e, r, i, a) {
var s = r ? e : _.softmax(e), o = s.shape[0], c = s.shape[1], l = new MB(o, c, i), u = l.getCustomSetupFunc(a);
return this.compileAndRun(l, [s], "int32", u);
}, t.prototype.oneHot = function(e, r, i, a) {
var s = new HB(e.size, r, i, a);
return this.compileAndRun(s, [e]);
}, t.prototype.diag = function(e) {
var r = new xB(e.size);
return this.compileAndRun(r, [e]);
}, t.prototype.cropAndResize = function(e, r, i, a, s, o) {
var c = new yB(e.shape, r.shape, a, s, o);
return this.compileAndRun(c, [e, r, i], "float32");
}, t.prototype.depthToSpace = function(e, r, i) {
_.util.assert(r > 1, function() {
return "blockSize should be > 1 for depthToSpace, but was: " + r;
});
var a = e.shape[0], s = i === "NHWC" ? e.shape[1] : e.shape[2], o = i === "NHWC" ? e.shape[2] : e.shape[3], c = i === "NHWC" ? e.shape[3] : e.shape[1], l = s * r, u = o * r, h = c / (r * r), d = i === "NHWC" ? [a, l, u, h] : [a, h, l, u], p = new bB(d, r, i);
return this.compileAndRun(p, [e]);
}, t.prototype.split = function(e, r, i) {
return qz(e, r, i);
}, t.prototype.scatterND = function(e, r, i) {
var a = _.backend_util.calculateShapes(r, e, i), s = a.sliceRank, o = a.numUpdates, c = a.sliceSize, l = a.strides, u = a.outputSize, h = [u / c, c], d = e.reshape([o, s]), p = r.reshape([o, c]);
if (u === 0)
return _.backend_util.reshapeTensor(_.tensor([]), i);
var f = _.scalar(0), m = new Yb(o, s, d.rank, p.rank, l, h), g = this.compileAndRun(m, [p, d, f]);
return g.reshape(i);
}, t.prototype.sparseToDense = function(e, r, i, a) {
var s = _.backend_util.calculateShapes(r, e, i), o = s.sliceRank, c = s.numUpdates, l = s.strides, u = s.outputSize, h = false, d = new Yb(c, o, e.rank, r.rank, l, [u, 1], h), p = this.compileAndRun(d, [r, e, a]);
return p.reshape(i);
}, t.prototype.gatherND = function(e, r) {
var i = r.shape, a = i[i.length - 1], s = _.backend_util.prepareAndValidate(e, r), o = s[0], c = s[1], l = s[2], u = s[3], h = r.reshape([c, a]), d = e.reshape([e.size / l, l]), p = new CB(a, u, [c, l]), f = this.compileAndRun(p, [d, h]);
return f.reshape(o);
}, t.prototype.fill = function(e, r, i) {
if (i = i || _.util.inferDtype(r), i === "string") {
var a = _.util.getArrayFromDType(i, _.util.sizeFromShape(e));
return a.fill(r), _.engine().makeTensor(a, e, i, this);
} else {
var s = new TB(e, r), o = s.getCustomSetupFunc(r);
return this.compileAndRun(s, [], i, o);
}
}, t.prototype.onesLike = function(e) {
if (e.dtype === "string")
throw new Error("onesLike is not supported under string dtype");
return this.fill(e.shape, 1, e.dtype);
}, t.prototype.zerosLike = function(e) {
return this.fill(e.shape, e.dtype === "string" ? "" : 0, e.dtype);
}, t.prototype.linspace = function(e, r, i) {
return _.backend_util.linspaceImpl(e, r, i);
}, t.prototype.makeTensorInfo = function(e, r, i) {
var a = this.write(i, e, r);
return this.texData.get(a).usage = null, {dataId: a, shape: e, dtype: r};
}, t.prototype.makeOutput = function(e, r, i) {
var a = this.makeTensorInfo(e, r, i).dataId;
return _.engine().makeTensorFromDataId(a, e, r, this);
}, t.prototype.unpackTensor = function(e) {
var r = new Gz(e.shape);
return this.runWebGLProgram(r, [e], e.dtype);
}, t.prototype.packTensor = function(e) {
var r = new YB(e.shape), i = true;
return this.runWebGLProgram(r, [e], e.dtype, null, i);
}, t.prototype.packedReshape = function(e, r) {
var i = [fi(e.shape)].concat(mi(e.shape)), a = {dtype: e.dtype, shape: i, dataId: e.dataId}, s = [fi(r)].concat(mi(r)), o = new qb(s, i), c = true, l = this.runWebGLProgram(o, [a], e.dtype, null, c);
return {dataId: l.dataId, shape: r, dtype: l.dtype};
}, t.prototype.decode = function(e) {
var r = this.texData.get(e), i = r.isPacked, a = r.shape, s = r.dtype, o = Vo(a), c;
i ? c = new wB(o) : c = new vB(o);
var l = true, u = this.runWebGLProgram(c, [{shape: o, dtype: s, dataId: e}], s, null, l);
return {dtype: s, shape: a, dataId: u.dataId};
}, t.prototype.runWebGLProgram = function(e, r, i, a, s) {
var o = this;
s === void 0 && (s = false);
var c = this.makeTensorInfo(e.outputShape, i), l = this.texData.get(c.dataId);
if (e.packedOutput && (l.isPacked = true), e.outPackingScheme === rs.DENSE) {
var u = as(e.outputShape);
l.texShape = u.map(function(b) {
return b * 2;
});
}
if (e.outTexUsage != null && (l.usage = e.outTexUsage), _.util.sizeFromShape(c.shape) === 0)
return l.values = _.util.getTypedArrayFromDType(c.dtype, 0), c;
var h = [], d = r.map(function(b) {
if (b.dtype === "complex64")
throw new Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts.");
var x = o.texData.get(b.dataId);
if (x.texture == null) {
if (!e.packedInputs && _.util.sizeFromShape(b.shape) <= _.env().getNumber("WEBGL_SIZE_UPLOAD_UNIFORM"))
return {shape: b.shape, texData: null, isUniform: true, uniformValues: x.values};
e.packedInputs && (x.isPacked = true, x.shape = b.shape);
} else if (!!x.isPacked !== !!e.packedInputs)
b = x.isPacked ? o.unpackTensor(b) : o.packTensor(b), h.push(b), x = o.texData.get(b.dataId);
else if (x.isPacked && !cs(x.shape, b.shape)) {
var L = b, N = b.shape;
b.shape = x.shape, b = o.packedReshape(b, N), h.push(b), x = o.texData.get(b.dataId), L.shape = N;
}
return o.uploadToGPU(b.dataId), {shape: b.shape, texData: x, isUniform: false};
});
this.uploadToGPU(c.dataId);
var p = {shape: c.shape, texData: l, isUniform: false}, f = kB(e, d, p), m = this.getAndSaveBinary(f, function() {
return EB(o.gpgpu, e, d, p);
}), g = this.activeTimers != null, y;
if (g && (y = this.startTimer()), DB(this.gpgpu, m, d, p, a), h.forEach(function(b) {
return o.disposeIntermediateTensorInfo(b);
}), g && (y = this.endTimer(y), this.activeTimers.push({name: e.constructor.name, query: this.getQueryTime(y)})), !_.env().getBool("WEBGL_LAZILY_UNPACK") && l.isPacked && s === false) {
var w = this.unpackTensor(c);
return this.disposeIntermediateTensorInfo(c), w;
}
return c;
}, t.prototype.compileAndRun = function(e, r, i, a, s) {
s === void 0 && (s = false), i = i || r[0].dtype;
var o = this.runWebGLProgram(e, r, i, a, s);
return _.engine().makeTensorFromDataId(o.dataId, o.shape, o.dtype);
}, t.prototype.getAndSaveBinary = function(e, r) {
return e in this.binaryCache || (this.binaryCache[e] = r()), this.binaryCache[e];
}, t.prototype.getTextureManager = function() {
return this.textureManager;
}, t.prototype.dispose = function() {
var e = this;
if (this.disposed)
return;
if (!_.env().getBool("IS_TEST")) {
var r = Object.keys(this.binaryCache);
r.forEach(function(i) {
e.gpgpu.deleteProgram(e.binaryCache[i].webGLProgram), delete e.binaryCache[i];
});
}
this.textureManager.dispose(), this.canvas != null && typeof HTMLCanvasElement != "undefined" && this.canvas instanceof HTMLCanvasElement ? this.canvas.remove() : this.canvas = null, this.gpgpuCreatedLocally && (this.gpgpu.program = null, this.gpgpu.dispose()), this.disposed = true;
}, t.prototype.floatPrecision = function() {
var e = this;
return this.floatPrecisionValue == null && (this.floatPrecisionValue = _.tidy(function() {
if (!_.env().get("WEBGL_RENDER_FLOAT32_ENABLED")) {
var r = _.env().getBool("DEBUG");
_.env().set("DEBUG", false);
var i = e.abs(_.scalar(1e-8)).dataSync()[0];
if (_.env().set("DEBUG", r), i > 0)
return 32;
}
return 16;
})), this.floatPrecisionValue;
}, t.prototype.epsilon = function() {
return this.floatPrecision() === 32 ? $z : Xz;
}, t.prototype.uploadToGPU = function(e) {
var r, i = this.texData.get(e), a = i.shape, s = i.dtype, o = i.values, c = i.texture, l = i.usage, u = i.isPacked;
if (c != null)
return;
var h = this.activeTimers != null, d;
h && (d = _.util.now());
var p = i.texShape;
if (p == null && (p = ab(a, u), i.texShape = p), o != null) {
var f = Vo(a), m = void 0, g = p[1], y = p[0], w = o instanceof Uint8Array;
u ? (r = ta(p[0], p[1]), g = r[0], y = r[1], m = new AB(f, [y, g], w)) : m = new IB(f, [y, g], w);
var b = this.makeTensorInfo([y, g], s);
w ? this.texData.get(b.dataId).usage = cn.PIXELS : this.texData.get(b.dataId).usage = cn.UPLOAD, this.gpgpu.uploadDenseMatrixToTexture(this.getTexture(b.dataId), g, y, o);
var x = true, L = this.runWebGLProgram(m, [b], s, null, x), N = this.texData.get(L.dataId);
i.texture = N.texture, i.texShape = N.texShape, i.isPacked = N.isPacked, i.usage = N.usage, this.disposeIntermediateTensorInfo(b), this.texData.delete(L.dataId), i.values = null, h && (this.uploadWaitMs += _.util.now() - d);
} else {
var I = this.acquireTexture(p, l, s, u);
i.texture = I;
}
}, t.prototype.convertAndCacheOnCPU = function(e, r) {
var i = this.texData.get(e), a = i.dtype;
return this.releaseGPUData(e), r != null && (i.values = tP(r, a)), i.values;
}, t.prototype.acquireTexture = function(e, r, i, a) {
if (this.numBytesInGPU += this.computeBytes(e, i), !this.warnedAboutMemory && this.numBytesInGPU > this.numMBBeforeWarning * 1024 * 1024) {
var s = (this.numBytesInGPU / 1024 / 1024).toFixed(2);
this.warnedAboutMemory = true, console.warn("High memory usage in GPU: " + s + " MB, most likely due to a memory leak");
}
return this.textureManager.acquireTexture(e, r, a);
}, t.prototype.computeBytes = function(e, r) {
return e[0] * e[1] * _.util.bytesPerElement(r);
}, t.prototype.tryRunOnCpuOrThrow = function(e, r) {
if (this.shouldExecuteOnCPU(e))
try {
return r();
} catch (i) {
if (_.env().getBool("IS_TEST"))
throw new Error("CPU forwarding failed");
}
return null;
}, t;
}(_.KernelBackend);
function tP(n, t) {
if (t === "float32" || t === "complex64")
return n;
if (t === "int32" || t === "bool") {
for (var e = t === "int32" ? new Int32Array(n.length) : new Uint8Array(n.length), r = 0; r < e.length; ++r)
e[r] = Math.round(n[r]);
return e;
} else
throw new Error("Unknown dtype " + t);
}
var nP = "2.7.0";
function h2() {
_.env().set("WEBGL_FORCE_F16_TEXTURES", true);
}
_.device_util.isBrowser() && _.registerBackend("webgl", function() {
return new u2();
}, 2);
var rP = {forceHalfFloat: h2};
function ar(n) {
var t = n.inputs, e = n.backend, r = t.x;
return e.incRef(r.dataId), {dataId: r.dataId, shape: r.shape, dtype: r.dtype};
}
var iP = {kernelName: _.Identity, backendName: "webgl", kernelFunc: ar};
function ca(n) {
var t = n.inputs, e = n.backend, r = t.real, i = t.imag, a = e.makeTensorInfo(r.shape, "complex64"), s = e.texData.get(a.dataId), o = ar({inputs: {x: r}, backend: e}), c = e.texData.get(o.dataId);
c.complexParentRefCount++;
var l = ar({inputs: {x: i}, backend: e}), u = e.texData.get(l.dataId);
return u.complexParentRefCount++, s.complexTensorInfos = {real: o, imag: l}, a;
}
var aP = {kernelName: _.Complex, backendName: "webgl", kernelFunc: ca};
var d2 = "if (isnan(x)) return x;", sP = `
if (isnan(a)) return a;
if (isnan(b)) return b;
`, oP = `
result.r = isNaN.r > 0. ? NAN : result.r;
result.g = isNaN.g > 0. ? NAN : result.g;
result.b = isNaN.b > 0. ? NAN : result.b;
result.a = isNaN.a > 0. ? NAN : result.a;
`;
function Jo(n) {
return function(t) {
var e = t.inputs, r = t.backend, i = e.x, a = r, s = new De(i.shape, n);
return a.runWebGLProgram(s, [i], i.dtype);
};
}
function la(n) {
var t = n.opSnippet, e = n.packedOpSnippet, r = n.checkOutOfBounds, i = r === void 0 ? false : r, a = n.supportsComplex, s = a === void 0 ? false : a, o = n.cpuKernelImpl, c = n.dtype;
return function(l) {
var u = l.inputs, h = l.backend, d = u, p = d.a, f = d.b, m = h;
if (s && p.dtype === "complex64") {
var g = m.texData.get(p.dataId), y = m.texData.get(f.dataId), w = [[g.complexTensorInfos.real, y.complexTensorInfos.real], [g.complexTensorInfos.imag, y.complexTensorInfos.imag]].map(function(V) {
var P = V[0], G = V[1], j = {dataId: P.dataId, dtype: P.dtype, shape: p.shape}, q = {dataId: G.dataId, dtype: G.dtype, shape: f.shape}, H = new Wt(t, p.shape, f.shape);
return m.runWebGLProgram(H, [j, q], _.upcastType(P.dtype, G.dtype));
}), b = w[0], x = w[1], L = ca({inputs: {real: b, imag: x}, backend: m});
return m.disposeIntermediateTensorInfo(b), m.disposeIntermediateTensorInfo(x), L;
}
var N = c || _.upcastType(p.dtype, f.dtype);
if (m.shouldExecuteOnCPU([p, f]) && o != null) {
var g = m.texData.get(p.dataId), y = m.texData.get(f.dataId), I = o(p.shape, f.shape, g.values, y.values, N), C = I[0], O = I[1], D = m.makeTensorInfo(O, N), F = m.texData.get(D.dataId);
return F.values = C, D;
}
var k = _.env().getBool("WEBGL_PACK_BINARY_OPERATIONS") && e != null, B;
return k ? B = new rr(e, p.shape, f.shape, i) : B = new Wt(t, p.shape, f.shape), m.runWebGLProgram(B, [p, f], N);
};
}
var p2 = "return a + b;", cP = la({opSnippet: p2, packedOpSnippet: p2, supportsComplex: true, cpuKernelImpl: kW}), lP = {kernelName: _.Add, backendName: "webgl", kernelFunc: cP};
var uP = sP + `
return atan(a, b);
`, hP = `
vec4 result = atan(a, b);
vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));
` + oP + `
return result;
`, dP = la({opSnippet: uP, packedOpSnippet: hP}), pP = {kernelName: _.Atan2, backendName: "webgl", kernelFunc: dP};
function fP(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x;
na(i, "avgPool");
var a = r.filterSize, s = r.strides, o = r.pad, c = r.dimRoundingMode, l = 1;
_.util.assert(_.backend_util.eitherStridesOrDilationsAreOne(s, l), function() {
return "Error in avgPool: Either strides or dilations must be 1. " + ("Got strides " + s + " and dilations '" + l + "'");
});
var u = _.backend_util.computePool2DInfo(i.shape, a, s, l, o, c);
if (u.filterWidth === 1 && u.filterHeight === 1 && _.util.arraysEqual(u.inShape, u.outShape))
return ar({inputs: {x: i}, backend: e});
var h = new us(u, "avg", false);
return e.runWebGLProgram(h, [i], "float32");
}
var mP = {kernelName: _.AvgPool, backendName: "webgl", kernelFunc: fP};
function gP(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.dy, a = t.input, s = a;
na([i, a], "avgPoolBackprop");
var o = r.filterSize, c = r.strides, l = r.pad, u = _.backend_util.computePool2DInfo(s.shape, o, c, 1, l), h = new DU(u);
return e.runWebGLProgram(h, [i], s.dtype);
}
var yP = {kernelName: _.AvgPoolBackprop, backendName: "webgl", kernelFunc: gP};
var vP = function() {
function n(t, e, r, i, a, s) {
this.outputShape = [], this.variableNames = ["x", "mean", "variance"], _.backend_util.assertAndGetBroadcastShape(t, e), _.backend_util.assertAndGetBroadcastShape(t, r);
var o = "0.0";
i != null && (_.backend_util.assertAndGetBroadcastShape(t, i), this.variableNames.push("offset"), o = "getOffsetAtOutCoords()");
var c = "1.0";
a != null && (_.backend_util.assertAndGetBroadcastShape(t, a), this.variableNames.push("scale"), c = "getScaleAtOutCoords()"), this.outputShape = t, this.userCode = `
void main() {
float x = getXAtOutCoords();
float mean = getMeanAtOutCoords();
float variance = getVarianceAtOutCoords();
float offset = ` + o + `;
float scale = ` + c + `;
float inv = scale * inversesqrt(variance + float(` + s + `));
setOutput(dot(vec3(x, -mean, offset), vec3(inv, inv, 1)));
}
`;
}
return n;
}();
var wP = function() {
function n(t, e, r, i, a, s) {
this.packedInputs = true, this.packedOutput = true, this.variableNames = ["x", "mean", "variance"], _.backend_util.assertAndGetBroadcastShape(t, e), _.backend_util.assertAndGetBroadcastShape(t, r);
var o = "vec4(0.0)";
i != null && (_.backend_util.assertAndGetBroadcastShape(t, i), this.variableNames.push("offset"), o = "getOffsetAtOutCoords()");
var c = "vec4(1.0)";
a != null && (_.backend_util.assertAndGetBroadcastShape(t, a), this.variableNames.push("scale"), c = "getScaleAtOutCoords()"), this.outputShape = t, this.userCode = `
void main() {
vec4 offset = ` + o + `;
vec4 scale = ` + c + `;
vec4 x = getXAtOutCoords();
vec4 mean = getMeanAtOutCoords();
vec4 variance = getVarianceAtOutCoords();
vec4 inv = scale * inversesqrt(variance + vec4(` + s + `));
setOutput((x - mean) * inv + offset);
}
`;
}
return n;
}();
var bP = function(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = t.mean, s = t.variance, o = t.offset, c = t.scale;
_.util.assert(a.shape.length === s.shape.length, function() {
return "Batch normalization gradient requires mean and variance to have equal ranks.";
}), _.util.assert(o == null || a.shape.length === o.shape.length, function() {
return "Batch normalization gradient requires mean and offset to have equal ranks.";
}), _.util.assert(c == null || a.shape.length === c.shape.length, function() {
return "Batch normalization gradient requires mean and scale to have equal ranks.";
});
var l = r.varianceEpsilon;
l == null && (l = 1e-3);
var u = [i, a, s], h = null;
o != null && (h = o.shape, u.push(o));
var d = null;
c != null && (d = c.shape, u.push(c));
var p = _.env().getBool("WEBGL_PACK_NORMALIZATION") ? new wP(i.shape, a.shape, s.shape, h, d, l) : new vP(i.shape, a.shape, s.shape, h, d, l), f = e.runWebGLProgram(p, u, u[0].dtype);
return f;
}, xP = {kernelName: _.FusedBatchNorm, backendName: "webgl", kernelFunc: bP};
var LP = "return float(a != b);", f2 = la({opSnippet: LP, dtype: "bool"}), SP = {kernelName: _.NotEqual, backendName: "webgl", kernelFunc: f2};
function ip(n) {
var t = n.inputs, e = n.backend, r = t.input, i = e.texData.get(r.dataId);
return ar({inputs: {x: i.complexTensorInfos.real}, backend: e});
}
var IP = {kernelName: _.Real, backendName: "webgl", kernelFunc: ip};
var AP = "return float(int(x));";
function TP(n, t) {
var e = new De(n.shape, AP), r = t.runWebGLProgram(e, [n], "int32");
return {dataId: r.dataId, shape: r.shape, dtype: r.dtype};
}
function ap(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = r.dtype;
if (a === "complex64") {
if (i.dtype === "complex64")
return ar({inputs: {x: i}, backend: e});
var s = _.zeros(i.shape), o = ap({inputs: {x: i}, backend: e, attrs: {dtype: "float32"}}), c = ca({inputs: {real: o, imag: s}, backend: e});
return s.dispose(), e.disposeIntermediateTensorInfo(o), c;
}
if (i.dtype === "complex64") {
var l = ip({inputs: {input: i}, backend: e}), c = ap({inputs: {x: l}, backend: e, attrs: {dtype: a}});
return e.disposeIntermediateTensorInfo(l), c;
}
if (!_.util.hasEncodingLoss(i.dtype, a)) {
var c = ar({inputs: {x: i}, backend: e});
return {dataId: c.dataId, shape: c.shape, dtype: a};
}
if (a === "int32")
return TP(i, e);
if (a === "bool") {
var u = e.makeTensorInfo([], "bool", _.util.getTypedArrayFromDType("bool", 1)), h = {a: i, b: u}, c = f2({inputs: h, backend: e});
return e.disposeIntermediateTensorInfo(u), c;
}
throw new Error("Error in Cast: failed to cast " + i.dtype + " to " + a);
}
var NP = {kernelName: _.Cast, backendName: "webgl", kernelFunc: ap};
var _P = function() {
function n(t) {
this.outputShape = [], this.outputShape = _.backend_util.computeOutShape(t, 1), this.variableNames = t.map(function(c, l) {
return "T" + l;
});
var e = new Array(t.length - 1);
e[0] = t[0][1];
for (var r = 1; r < e.length; r++)
e[r] = e[r - 1] + t[r][1];
for (var i = ["if (yC < " + e[0] + ") setOutput(getT0(yR, yC));"], r = 1; r < e.length; r++) {
var a = e[r - 1];
i.push("else if (yC < " + e[r] + ") " + ("setOutput(getT" + r + "(yR, yC-" + a + "));"));
}
var s = e.length, o = e[e.length - 1];
i.push("else setOutput(getT" + s + "(yR, yC-" + o + "));"), this.userCode = `
void main() {
ivec2 coords = getOutputCoords();
int yR = coords.x;
int yC = coords.y;
` + i.join(`
`) + `
}
`;
}
return n;
}();
var CP = function() {
function n(t, e) {
this.packedInputs = true, this.packedOutput = true, this.outputShape = [], this.outputShape = _.backend_util.computeOutShape(t, e);
var r = this.outputShape, i = r.length, a = Ze(i), s = Ut("coords", i), o = ["x", "y", "z", "w", "u", "v"].slice(0, i);
this.variableNames = t.map(function(y, w) {
return "T" + w;
});
var c = new Array(t.length - 1);
c[0] = t[0][e];
for (var l = 1; l < c.length; l++)
c[l] = c[l - 1] + t[l][e];
for (var u = o[e], h = o.slice(-2), d = o.join(), p = "if (" + u + " < " + c[0] + `) {
return getChannel(
getT0(` + d + "), vec2(" + h.join() + `));
}`, l = 1; l < c.length; l++) {
var f = c[l - 1];
p += `
if (` + u + " < " + c[l] + " && " + u + " >= " + c[l - 1] + `) {
return getChannel(
getT` + l + "(" + Zo(o, u, f) + `),
vec2(` + Zo(h, u, f) + `));
}`;
}
var m = c.length, g = c[c.length - 1];
p += `
return getChannel(
getT` + m + "(" + Zo(o, u, g) + `),
vec2(` + Zo(h, u, g) + "));", this.userCode = `
float getValue(` + o.map(function(y) {
return "int " + y;
}) + `) {
` + p + `
}
void main() {
` + a + ` coords = getOutputCoords();
vec4 result = vec4(getValue(` + s + `), 0., 0., 0.);
` + s[i - 1] + " = " + s[i - 1] + ` + 1;
if (` + s[i - 1] + " < " + r[i - 1] + `) {
result.g = getValue(` + s + `);
}
` + s[i - 2] + " = " + s[i - 2] + ` + 1;
if (` + s[i - 2] + " < " + r[i - 2] + `) {
result.a = getValue(` + s + `);
}
` + s[i - 1] + " = " + s[i - 1] + ` - 1;
if (` + s[i - 2] + " < " + r[i - 2] + ` &&
` + s[i - 1] + " < " + r[i - 1] + `) {
result.b = getValue(` + s + `);
}
setOutput(result);
}
`;
}
return n;
}();
function Zo(n, t, e) {
var r = n.indexOf(t), i = n.map(function(a, s) {
return s === r ? a + " - " + e : a;
});
return i.join();
}
function m2(n) {
var t = n.inputs, e = n.backend, r = t.input, i = e.texData.get(r.dataId);
return ar({inputs: {x: i.complexTensorInfos.imag}, backend: e});
}
var RP = {kernelName: _.Imag, backendName: "webgl", kernelFunc: m2};
function OP(n, t, e) {
var r = [fi(n.shape)].concat(mi(n.shape)), i = {dtype: n.dtype, shape: r, dataId: n.dataId}, a = [fi(t)].concat(mi(t)), s = new qb(a, r), o = true, c = e.runWebGLProgram(s, [i], n.dtype, null, o);
return {dataId: c.dataId, shape: t, dtype: c.dtype};
}
function sr(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = r.shape, s = e, o = _.util.sizeFromShape(i.shape), c = _.util.inferFromImplicitShape(a, o), l = _.util.sizeFromShape(c);
_.util.assert(o === l, function() {
return "The new shape (" + c + ") has " + l + " elements and the old " + ("shape (" + i.shape + ") has " + o + " elements. The new shape and old ") + "shape must have the same number of elements.";
});
var u = s.texData.get(i.dataId);
return u.isPacked && !cs(i.shape, c) && !(u.texture !== null && cs(u.shape, c)) ? OP(i, c, s) : (s.incRef(i.dataId), {dataId: i.dataId, shape: c, dtype: i.dtype});
}
var EP = {kernelName: _.Reshape, backendName: "webgl", kernelFunc: sr};
function ua(n, t, e) {
var r = n[0].dtype;
if (r === "complex64") {
var i = n.map(function(b) {
return ip({inputs: {input: b}, backend: e});
}), a = n.map(function(b) {
return m2({inputs: {input: b}, backend: e});
}), s = ua(i, t, e), o = ua(a, t, e), c = ca({inputs: {real: s, imag: o}, backend: e});
return i.forEach(function(b) {
return e.disposeIntermediateTensorInfo(b);
}), a.forEach(function(b) {
return e.disposeIntermediateTensorInfo(b);
}), e.disposeIntermediateTensorInfo(s), e.disposeIntermediateTensorInfo(o), c;
}
if (n.length > _.env().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER")) {
var l = Math.floor(n.length / 2), u = ua(n.slice(0, l), t, e), h = ua(n.slice(l), t, e), d = ua([u, h], t, e);
return e.disposeIntermediateTensorInfo(u), e.disposeIntermediateTensorInfo(h), d;
}
if (_.env().getBool("WEBGL_PACK_ARRAY_OPERATIONS") && n[0].shape.length > 1) {
var p = new CP(n.map(function(b) {
return b.shape;
}), t);
return e.runWebGLProgram(p, n, r);
}
var f = _.backend_util.computeOutShape(n.map(function(b) {
return b.shape;
}), t), m = n.map(function(b) {
return sr({inputs: {x: b}, attrs: {shape: [-1, _.util.sizeFromShape(b.shape.slice(t))]}, backend: e});
}), g = new _P(m.map(function(b) {
return b.shape;
})), y = e.runWebGLProgram(g, m, r);
m.forEach(function(b) {
return e.disposeIntermediateTensorInfo(b);
});
var w = sr({inputs: {x: y}, attrs: {shape: f}, backend: e});
return e.disposeIntermediateTensorInfo(y), w;
}
function DP(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = r.axis, a = _.util.parseAxisParam(i, t[0].shape)[0], s = _.backend_util.computeOutShape(t.map(function(l) {
return l.shape;
}), a);
if (_.util.sizeFromShape(s) === 0)
return e.makeTensorInfo(s, t[0].dtype, []);
var o = t.filter(function(l) {
return _.util.sizeFromShape(l.shape) > 0;
});
if (o.length === 1)
return o[0];
var c = o.map(function(l) {
return l.shape;
});
return _.backend_util.assertParamsConsistent(c, a), ua(o, a, e);
}
var kP = {kernelName: _.Concat, backendName: "webgl", kernelFunc: DP};
var FP = d2 + `
return cos(x);
`, WP = Jo(FP), UP = {kernelName: _.Cos, backendName: "webgl", kernelFunc: WP};
var BP = `
if (a == b) {
return 1.0;
};
return a / b;`, zP = `
// vec4 one = vec4(equal(a, b));
// return one + (vec4(1.0) - one) * a / b;
vec4 result = a / b;
if(a.x == b.x) {
result.x = 1.;
}
if(a.y == b.y) {
result.y = 1.;
}
if(a.z == b.z) {
result.z = 1.;
}
if(a.w == b.w) {
result.w = 1.;
}
return result;
`, PP = la({opSnippet: BP, packedOpSnippet: zP, checkOutOfBounds: true}), MP = {kernelName: _.Div, backendName: "webgl", kernelFunc: PP};
var g2 = function() {
function n(t, e, r) {
this.variableNames = ["real", "imag"];
var i = e[1];
this.outputShape = e;
var a = r ? "2.0 * " + Math.PI : "-2.0 * " + Math.PI, s = r ? i + ".0" : "1.0", o;
if (t === "real")
o = "return real * expR - imag * expI;";
else if (t === "imag")
o = "return real * expI + imag * expR;";
else
throw new Error('FFT component must be either "real" or "imag", got ' + t + ".");
this.userCode = `
const float exponentMultiplier = ` + a + `;
float unaryOpComplex(float real, float expR, float imag, float expI) {
` + o + `
}
float mulMatDFT(int batch, int index) {
float indexRatio = float(index) / float(` + i + `);
float exponentMultiplierTimesIndexRatio =
exponentMultiplier * indexRatio;
float result = 0.0;
for (int i = 0; i < ` + i + `; i++) {
// x = (-2|2 * PI / N) * index * i;
float x = exponentMultiplierTimesIndexRatio * float(i);
float expR = cos(x);
float expI = sin(x);
float real = getReal(batch, i);
float imag = getImag(batch, i);
result +=
unaryOpComplex(real, expR, imag, expI) / ` + s + `;
}
return result;
}
void main() {
ivec2 coords = getOutputCoords();
setOutput(mulMatDFT(coords[0], coords[1]));
}
`;
}
return n;
}();
function y2(n, t, e) {
var r = e.texData.get(n.dataId), i = _.util.sizeFromShape(n.shape), a = n.shape[n.shape.length - 1], s = i / a, o = sr({inputs: {x: n}, backend: e, attrs: {shape: [s, a]}}), c = o.shape, l = new g2("real", c, t), u = new g2("imag", c, t), h = [{dataId: r.complexTensorInfos.real.dataId, dtype: r.complexTensorInfos.real.dtype, shape: c}, {dataId: r.complexTensorInfos.imag.dataId, dtype: r.complexTensorInfos.imag.dtype, shape: c}], d = e.runWebGLProgram(l, h, "float32"), p = e.runWebGLProgram(u, h, "float32"), f = ca({inputs: {real: d, imag: p}, backend: e});
e.disposeIntermediateTensorInfo(d), e.disposeIntermediateTensorInfo(p);
var m = sr({inputs: {x: f}, backend: e, attrs: {shape: n.shape}});
return e.disposeIntermediateTensorInfo(m), m;
}
function HP(n) {
var t = n.inputs, e = n.backend, r = t.input;
return y2(r, false, e);
}
var VP = {kernelName: _.FFT, backendName: "webgl", kernelFunc: HP};
var GP = function() {
function n(t) {
this.variableNames = ["Image"], this.outputShape = [];
var e = t[2];
this.outputShape = t, this.userCode = `
void main() {
ivec4 coords = getOutputCoords();
int x = coords[2];
int coordX = ` + e + ` - x;
float outputValue;
if(coordX >= 0 && coordX < ` + e + `) {
outputValue = getImage(coords[0], coords[1], coordX, coords[3]);
} else {
outputValue = getImage(coords[0], coords[1], coords[2], coords[3]);
}
setOutput(outputValue);
}
`;
}
return n;
}();
var qP = {kernelName: _.FlipLeftRight, backendName: "webgl", kernelFunc: function(n) {
var t = n.inputs, e = n.backend, r = t.image, i = e, a = new GP(r.shape), s = i.runWebGLProgram(a, [r], r.dtype);
return s;
}};
var YP = function() {
function n(t) {
this.variableNames = ["A"];
var e = Bt(), r = t[0], i = t[1];
this.outputShape = t, this.userCode = `
void main() {
ivec3 coords = getOutputCoords();
int texR = coords[0];
int texC = coords[1];
int depth = coords[2];
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(` + i + ".0, " + r + `.0);
vec4 values = ` + e.texture2D + `(A, uv);
float value;
if (depth == 0) {
value = values.r;
} else if (depth == 1) {
value = values.g;
} else if (depth == 2) {
value = values.b;
} else if (depth == 3) {
value = values.a;
}
setOutput(floor(value * 255.0 + 0.5));
}
`;
}
return n;
}();
var KP = function() {
function n(t) {
this.variableNames = ["A"], this.packedInputs = false, this.packedOutput = true;
var e = Bt(), r = t[0], i = t[1];
this.outputShape = t, this.userCode = `
void main() {
ivec3 coords = getOutputCoords();
int texR = coords[0];
int texC = coords[1];
int depth = coords[2];
vec4 result = vec4(0.);
for(int row=0; row<=1; row++) {
for(int col=0; col<=1; col++) {
texC = coords[1] + row;
depth = coords[2] + col;
vec2 uv = (vec2(texC, texR) + halfCR) /
vec2(` + i + ".0, " + r + `.0);
vec4 values = ` + e.texture2D + `(A, uv);
float value;
if (depth == 0) {
value = values.r;
} else if (depth == 1) {
value = values.g;
} else if (depth == 2) {
value = values.b;
} else if (depth == 3) {
value = values.a;
}
result[row * 2 + col] = floor(value * 255.0 + 0.5);
}
}
` + e.output + ` = result;
}
`;
}
return n;
}();
var $P = {kernelName: _.FromPixels, backendName: "webgl", kernelFunc: jP}, ha;
function jP(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.pixels, a = r.numChannels, s = typeof HTMLVideoElement != "undefined" && i instanceof HTMLVideoElement, o = typeof HTMLImageElement != "undefined" && i instanceof HTMLImageElement, c = s ? [i.videoWidth, i.videoHeight] : [i.width, i.height], l = c[0], u = c[1], h = [u, l], d = [u, l, a];
(o || s) && (ha == null && (ha = document.createElement("canvas").getContext("2d")), ha.canvas.width = l, ha.canvas.height = u, ha.drawImage(i, 0, 0, l, u), i = ha.canvas);
var p = e.makeTensorInfo(h, "int32");
e.texData.get(p.dataId).usage = cn.PIXELS, e.gpgpu.uploadPixelDataToTexture(e.getTexture(p.dataId), i);
var f = _.env().getBool("WEBGL_PACK") ? new KP(d) : new YP(d), m = e.runWebGLProgram(f, [p], "int32");
return e.disposeData(p.dataId), m;
}
function XP(n) {
var t = n.inputs, e = n.backend, r = t.input;
return y2(r, true, e);
}
var JP = {kernelName: _.IFFT, backendName: "webgl", kernelFunc: XP};
var v2 = function() {
function n(t, e) {
this.variableNames = ["x"];
var r = t.windowSize, i = t.batchSize, a = t.inSize, s = t.outSize;
this.outputShape = [i, s];
var o = Math.floor(r / 4) * 4, c = r % 4, l = "sumValue += dot(values, ones);";
if (e != null) {
var u = 1 / e;
l = "sumValue += dot(values * " + (_.util.isInt(u) ? u.toPrecision(2) : u) + ", ones);";
}
var h = "";
a % r > 0 && (h = `
if (inIdx < 0 || inIdx >= ` + a + `) {
return 0.0;
}
`), this.userCode = `
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
float getValue(int batch, int inIdx) {
` + h + `
return getX(batch, inIdx);
}
void main() {
ivec2 coords = getOutputCoords();
int batch = coords[0];
int outIdx = coords[1];
int inOffset = outIdx * ` + r + `;
float sumValue = 0.0;
for (int i = 0; i < ` + o + `; i += 4) {
int inIdx = inOffset + i;
vec4 values = vec4(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
getValue(batch, inIdx + 2),
getValue(batch, inIdx + 3)
);
` + l + `
}
int inIdx = inOffset + ` + o + `;
if (` + (c === 1) + `) {
vec4 values = vec4(getValue(batch, inIdx), 0.0, 0.0, 0.0);
` + l + `
} else if (` + (c === 2) + `) {
vec4 values = vec4(
getValue(batch, inIdx),
getValue(batch, inIdx + 1), 0.0, 0.0);
` + l + `
} else if (` + (c === 3) + `) {
vec4 values = vec4(
getValue(batch, inIdx),
getValue(batch, inIdx + 1),
getValue(batch, inIdx + 2), 0.0);
` + l + `
}
setOutput(sumValue);
}
`;
}
return n;
}();
function ZP(n) {
for (var t = []; t.length === 0 || t[t.length - 1].outSize !== 1; ) {
var e = t.length ? t[t.length - 1].outSize : n[1], r = _.backend_util.computeOptimalWindowSize(e);
t.push({inSize: e, windowSize: r, outSize: Math.ceil(e / r)});
}
return t;
}
function w2(n, t, e, r) {
for (var i = ZP(n.shape), a = n, s = 0; s < i.length; s++) {
var o = i[s], c = o.inSize, l = o.windowSize, u = o.outSize, h = void 0, d = void 0;
e === "mean" ? h = s === 0 ? new v2({windowSize: l, inSize: c, batchSize: n.shape[0], outSize: u}, c) : new v2({windowSize: l, inSize: c, batchSize: n.shape[0], outSize: u}) : h = new Gb({windowSize: l, inSize: c, batchSize: n.shape[0], outSize: u}, e), d = a, a = r.runWebGLProgram(h, [a], t), d.dataId !== n.dataId && r.disposeIntermediateTensorInfo(d);
}
return a;
}
function QP(n, t, e, r) {
var i = _.util.sizeFromShape(t), a = _.util.sizeFromShape(n.shape), s = a / i, o = sr({inputs: {x: n}, attrs: {shape: [s, i]}, backend: r}), c = w2(o, n.dtype, "max", r), l = sr({inputs: {x: c}, attrs: {shape: e}, backend: r});
return r.disposeIntermediateTensorInfo(o), r.disposeIntermediateTensorInfo(c), l;
}
var tM = function() {
function n(t, e) {
this.variableNames = ["A"];
for (var r = new Array(t.length), i = 0; i < r.length; i++)
r[i] = t[e[i]];
this.outputShape = r, this.rank = r.length;
var a = Ze(this.rank), s = eM(e);
this.userCode = `
void main() {
` + a + ` resRC = getOutputCoords();
setOutput(getA(` + s + `));
}
`;
}
return n;
}();
function eM(n) {
var t = n.length;
if (t > 6)
throw Error("Transpose for rank " + t + " is not yet supported");
for (var e = ["resRC.x", "resRC.y", "resRC.z", "resRC.w", "resRC.u", "resRC.v"], r = new Array(t), i = 0; i < n.length; i++)
r[n[i]] = e[i];
return r.join();
}
var nM = function() {
function n(t, e) {
this.variableNames = ["A"], this.packedInputs = true, this.packedOutput = true;
for (var r = new Array(t.length), i = 0; i < r.length; i++)
r[i] = t[e[i]];
if (this.outputShape = r, this.rank = r.length, this.rank > 6)
throw Error("Packed transpose for rank " + this.rank + " is not yet supported.");
for (var a = Ze(this.rank), s = db("rc", this.rank), o = new Array(this.rank), i = 0; i < e.length; i++)
o[e[i]] = s[i];
var c = "vec2(" + o.slice(-2).join() + ")", l = "++" + s[this.rank - 1] + " < " + r[this.rank - 1], u = "getChannel(getA(" + o.join() + "), " + c + ")";
this.userCode = `
void main() {
` + a + ` rc = getOutputCoords();
vec4 result = vec4(0.);
result[0] = ` + u + `;
if(` + l + `) {
result[1] = ` + u + `;
}
--` + s[this.rank - 1] + `;
if(++` + s[this.rank - 2] + " < " + r[this.rank - 2] + `) {
result[2] = ` + u + `;
if(` + l + `) {
result[3] = ` + u + `;
}
}
setOutput(result);
}
`;
}
return n;
}();
function sp(n, t, e) {
var r = _.env().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new nM(n.shape, t) : new tM(n.shape, t);
return e.runWebGLProgram(r, [n], n.dtype);
}
var rM = {kernelName: _.Max, backendName: "webgl", kernelFunc: function(n) {
var t = n.inputs, e = n.attrs, r = n.backend, i = t.x, a = e, s = a.reductionIndices, o = a.keepDims, c = r, l = i.shape.length, u = _.util.parseAxisParam(s, i.shape), h = u, d = _.backend_util.getAxesPermutation(h, l), p = d != null, f = c.shouldExecuteOnCPU([i]), m = i;
if (p) {
if (f) {
for (var g = c.texData.get(m.dataId), y = g.values, w = new Array(l), b = 0; b < w.length; b++)
w[b] = i.shape[d[b]];
var x = jd(y, i.shape, i.dtype, d, w);
m = c.makeTensorInfo(w, i.dtype);
var L = c.texData.get(m.dataId);
L.values = x;
} else
m = sp(i, d, c);
h = _.backend_util.getInnerMostAxes(h.length, l);
}
_.backend_util.assertAxesAreInnerMostDims("max", h, l);
var N = _.backend_util.computeOutAndReduceShapes(m.shape, h), I = N[0], C = N[1], O = I;
o && (O = _.backend_util.expandShapeToKeepDim(I, u));
var D;
if (f) {
var g = c.texData.get(m.dataId), y = g.values, F = PW(y, _.util.sizeFromShape(C), O, i.dtype);
D = c.makeTensorInfo(O, i.dtype);
var k = c.texData.get(D.dataId);
k.values = F;
} else
D = QP(m, C, O, c);
return p && c.disposeIntermediateTensorInfo(m), D;
}};
function iM(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x;
na(i, "maxPool");
var a = r.filterSize, s = r.strides, o = r.pad, c = r.dimRoundingMode, l = 1;
_.util.assert(_.backend_util.eitherStridesOrDilationsAreOne(s, l), function() {
return "Error in maxPool: Either strides or dilations must be 1. " + ("Got strides " + s + " and dilations '" + l + "'");
});
var u = _.backend_util.computePool2DInfo(i.shape, a, s, l, o, c);
if (u.filterWidth === 1 && u.filterHeight === 1 && _.util.arraysEqual(u.inShape, u.outShape))
return ar({inputs: {x: i}, backend: e});
var h = new us(u, "max", false);
return e.runWebGLProgram(h, [i], i.dtype);
}
var aM = {kernelName: _.MaxPool, backendName: "webgl", kernelFunc: iM};
function sM(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.dy, a = t.input, s = t.output, o = a;
na([a, s], "maxPoolBackprop");
var c = r.filterSize, l = r.strides, u = r.pad, h = r.dimRoundingMode, d = _.backend_util.computePool2DInfo(o.shape, c, l, 1, u, h), p = true, f = new us(d, "max", p), m = e.runWebGLProgram(f, [o], o.dtype), g = new zB(d), y = e.runWebGLProgram(g, [i, m], o.dtype);
return e.disposeIntermediateTensorInfo(m), y;
}
var oM = {kernelName: _.MaxPoolBackprop, backendName: "webgl", kernelFunc: sM};
function cM(n, t, e, r) {
var i = new us(e, "max", false), a = r.runWebGLProgram(i, [n], "float32");
i = new us(e, "max", true, true, t);
var s = r.runWebGLProgram(i, [n], "float32");
return [a, s];
}
var lM = {kernelName: _.MaxPoolWithArgmax, backendName: "webgl", kernelFunc: function(n) {
var t = n.inputs, e = n.attrs, r = n.backend, i = t.x, a = e, s = a.filterSize, o = a.strides, c = a.pad, l = a.includeBatchInIndex, u = r;
_.util.assert(i.shape.length === 4, function() {
return "Error in maxPool: input must be rank 4 but got rank " + i.shape.length + ".";
});
var h = [1, 1];
_.util.assert(_.backend_util.eitherStridesOrDilationsAreOne(o, h), function() {
return "Error in maxPool: Either strides or dilations must be 1. " + ("Got strides " + o + " and dilations '" + h + "'");
});
var d = _.backend_util.computePool2DInfo(i.shape, s, o, h, c), p = cM(i, l, d, u), f = p[0], m = p[1];
return [f, m];
}};
function uM(n, t, e, r) {
var i = _.util.sizeFromShape(t), a = _.util.sizeFromShape(n.shape), s = a / i, o = sr({inputs: {x: n}, attrs: {shape: [s, i]}, backend: r}), c = w2(o, "float32", "mean", r), l = sr({inputs: {x: c}, attrs: {shape: e}, backend: r});
return r.disposeIntermediateTensorInfo(o), r.disposeIntermediateTensorInfo(c), l;
}
var hM = {kernelName: _.Mean, backendName: "webgl", kernelFunc: function(n) {
var t = n.inputs, e = n.attrs, r = n.backend, i = t.x, a = e, s = a.keepDims, o = a.axis, c = r, l = i.shape.length, u = _.util.parseAxisParam(o, i.shape), h = u, d = _.backend_util.getAxesPermutation(h, l), p = d != null, f = c.shouldExecuteOnCPU([i]), m = [], g = i;
if (p) {
if (f) {
for (var y = c.texData.get(g.dataId), w = y.values, b = new Array(l), x = 0; x < b.length; x++)
b[x] = i.shape[d[x]];
var L = jd(w, i.shape, i.dtype, d, b);
g = c.makeTensorInfo(b, i.dtype);
var N = c.texData.get(g.dataId);
N.values = L;
} else
g = sp(i, d, c);
m.push(g), h = _.backend_util.getInnerMostAxes(h.length, l);
}
_.backend_util.assertAxesAreInnerMostDims("sum", h, l);
var I = _.backend_util.computeOutAndReduceShapes(g.shape, h), C = I[0], O = I[1], D = C;
s && (D = _.backend_util.expandShapeToKeepDim(C, u));
for (var F = uM(g, O, D, c), k = 0, B = m; k < B.length; k++) {
var x = B[k];
c.disposeIntermediateTensorInfo(x);
}
return F;
}};
var dM = function() {
function n(t, e, r) {
this.variableNames = ["x"], this.outputShape = e.map(function(u, h) {
return u[0] + t[h] + u[1];
});
var i = t.length, a = Ze(i), s = e.map(function(u) {
return u[0];
}).join(","), o = e.map(function(u, h) {
return u[0] + t[h];
}).join(","), c = ["coords[0]", "coords[1]", "coords[2]", "coords[3]"].slice(0, i), l = r === "reflect" ? 0 : 1;
if (i === 1) {
this.userCode = `
int start = ` + s + `;
int end = ` + o + `;
void main() {
int outC = getOutputCoords();
if (outC < start) {
outC = start * 2 - outC - ` + l + `;
} else if(outC >= end) {
outC = (end - 1) * 2 - outC + ` + l + `;
}
setOutput(getX(outC - start));
}
`;
return;
}
this.userCode = `
` + a + " start = " + a + "(" + s + `);
` + a + " end = " + a + "(" + o + `);
void main() {
` + a + ` outC = getOutputCoords();
for (int i = 0; i < ` + i + `; i++) {
if (outC[i] < start[i]) {
outC[i] = start[i] * 2 - outC[i] - ` + l + `;
} else if(outC[i] >= end[i]) {
outC[i] = (end[i] - 1) * 2 - outC[i] + ` + l + `;
}
}
` + a + ` coords = outC - start;
setOutput(getX(` + c + `));
}
`;
}
return n;
}();
var pM = function() {
function n(t, e, r) {
this.variableNames = ["x"], this.packedInputs = true, this.packedOutput = true, this.outputShape = e.map(function(m, g) {
return m[0] + t[g] + m[1];
});
var i = t.length, a = Ze(i), s = e.map(function(m) {
return m[0];
}).join(","), o = e.map(function(m, g) {
return m[0] + t[g];
}).join(","), c = Ut("rc", i), l = Ut("source", i), u = c[i - 1] + " < " + this.outputShape[i - 1], h = i === 1 ? "source" : "vec2(" + l.slice(-2).join() + ")", d = r === "reflect" ? 0 : 1, p = "";
if (i === 1) {
var f = `
` + a + ` source = rc;
if (source < start) {
source = start * 2 - source - ` + d + `;
} else if (source >= end) {
source = (end - 1) * 2 - source + ` + d + `;
}
source -= start;
`;
p = `
` + a + ` rc = outputLoc;
` + f + `
result[0] = getChannel(getX(` + l.join() + "), " + h + `);
` + c[i - 1] + ` += 1;
if(` + u + `) {
` + f + `
result[1] = getChannel(getX(` + l.join() + "), " + h + `);
}
`;
} else {
var f = `
` + a + ` source = rc;
` + a + " lt = " + a + `(lessThan(source, start));
` + a + " gte = " + a + `(greaterThanEqual(source, end));
` + a + ` orig = 1 - (lt + gte);
source = orig * source +
lt * (start * 2 - source - ` + d + `) +
gte * ((end - 1) * 2 - source + ` + d + `);
source -= start;
`;
p = `
` + a + ` rc = outputLoc;
` + f + `
result[0] = getChannel(getX(` + l.join() + "), " + h + `);
` + c[i - 1] + ` += 1;
if(` + u + `) {
` + f + `
result[1] = getChannel(getX(` + l.join() + "), " + h + `);
}
rc = outputLoc;
` + c[i - 2] + ` += 1;
if(` + c[i - 2] + " < " + this.outputShape[i - 2] + `) {
` + f + `
result[2] = getChannel(getX(` + l.join() + "), " + h + `);
` + c[i - 1] + ` += 1;
if(` + u + `) {
` + f + `
result[3] = getChannel(getX(` + l.join() + "), " + h + `);
}
}
`;
}
this.userCode = `
const ` + a + " start = " + a + "(" + s + `);
const ` + a + " end = " + a + "(" + o + `);
void main() {
` + a + ` outputLoc = getOutputCoords();
vec4 result = vec4(0.);
` + p + `
setOutput(result);
}
`;
}
return n;
}();
var fM = function(n) {
var t = n.inputs, e = n.backend, r = n.attrs, i = t.x, a = r.paddings, s = r.mode, o = _.env().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new pM(i.shape, a, s) : new dM(i.shape, a, s), c = e.runWebGLProgram(o, [i], i.dtype);
return c;
}, mM = {kernelName: _.MirrorPad, backendName: "webgl", kernelFunc: fM};
var b2 = {REAL: "return areal * breal - aimag * bimag;", IMAG: "return areal * bimag + aimag * breal;"}, x2 = function() {
function n(t, e, r) {
this.variableNames = ["AReal", "AImag", "BReal", "BImag"], this.outputShape = _.backend_util.assertAndGetBroadcastShape(e, r), this.userCode = `
float binaryOpComplex(
float areal, float aimag, float breal, float bimag) {
` + t + `
}
void main() {
float areal = getARealAtOutCoords();
float aimag = getAImagAtOutCoords();
float breal = getBRealAtOutCoords();
float bimag = getBImagAtOutCoords();
setOutput(binaryOpComplex(areal, aimag, breal, bimag));
}
`;
}
return n;
}();
var L2 = "return a * b;";
function gM(n) {
var t = n.inputs, e = n.backend, r = t.a, i = t.b, a = _.backend_util.upcastType(r.dtype, i.dtype);
if (r.dtype === "complex64") {
var s = e.texData.get(r.dataId), o = e.texData.get(i.dataId), c = new x2(b2.REAL, r.shape, i.shape), l = new x2(b2.IMAG, r.shape, i.shape), u = [{dataId: s.complexTensorInfos.real.dataId, dtype: s.complexTensorInfos.real.dtype, shape: r.shape}, {dataId: s.complexTensorInfos.imag.dataId, dtype: s.complexTensorInfos.imag.dtype, shape: r.shape}, {dataId: o.complexTensorInfos.real.dataId, dtype: o.complexTensorInfos.real.dtype, shape: i.shape}, {dataId: o.complexTensorInfos.imag.dataId, dtype: o.complexTensorInfos.imag.dtype, shape: i.shape}], h = e.runWebGLProgram(c, u, "float32"), d = e.runWebGLProgram(l, u, "float32"), p = ca({inputs: {real: h, imag: d}, backend: e});
return e.disposeIntermediateTensorInfo(h), e.disposeIntermediateTensorInfo(d), p;
}
if (e.shouldExecuteOnCPU([r, i])) {
var s = e.texData.get(r.dataId), o = e.texData.get(i.dataId), f = MW(r.shape, i.shape, s.values, o.values, a), m = f[0], g = f[1], y = e.makeTensorInfo(g, a), w = e.texData.get(y.dataId);
return w.values = m, y;
}
var b;
return _.env().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? b = new rr(L2, r.shape, i.shape) : b = new Wt(L2, r.shape, i.shape), e.runWebGLProgram(b, [r, i], a);
}
var yM = {kernelName: _.Multiply, backendName: "webgl", kernelFunc: gM};
var vM = {kernelName: _.NonMaxSuppressionV3, backendName: "webgl", kernelFunc: function(n) {
var t = n.inputs, e = n.backend, r = n.attrs;
_.backend_util.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");
var i = t, a = i.boxes, s = i.scores, o = r, c = o.maxOutputSize, l = o.iouThreshold, u = o.scoreThreshold, h = e, d = h.readSync(a.dataId), p = h.readSync(s.dataId), f = c, m = l, g = u;
return _.kernel_impls.nonMaxSuppressionV3Impl(d, p, f, m, g);
}};
var wM = _.kernel_impls.nonMaxSuppressionV4Impl, bM = {kernelName: _.NonMaxSuppressionV4, backendName: "webgl", kernelFunc: function(n) {
var t = n.inputs, e = n.backend, r = n.attrs;
_.backend_util.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");
var i = t, a = i.boxes, s = i.scores, o = r, c = o.maxOutputSize, l = o.iouThreshold, u = o.scoreThreshold, h = o.padToMaxOutputSize, d = e, p = d.readSync(a.dataId), f = d.readSync(s.dataId), m = wM(p, f, c, l, u, h), g = m.selectedIndices, y = m.validOutputs;
return [g, y];
}};
var xM = _.kernel_impls.nonMaxSuppressionV5Impl, LM = {kernelName: _.NonMaxSuppressionV5, backendName: "webgl", kernelFunc: function(n) {
var t = n.inputs, e = n.backend, r = n.attrs;
_.backend_util.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");
var i = t, a = i.boxes, s = i.scores, o = r, c = o.maxOutputSize, l = o.iouThreshold, u = o.scoreThreshold, h = o.softNmsSigma, d = e, p = d.readSync(a.dataId), f = d.readSync(s.dataId), m = c, g = l, y = u, w = h, b = xM(p, f, m, g, y, w), x = b.selectedIndices, L = b.selectedScores;
return [x, L];
}};
var SM = function() {
function n(t, e, r, i) {
this.variableNames = ["Image"], this.outputShape = [];
var a = t[1], s = t[2], o = Math.sin(e).toFixed(3), c = Math.cos(e).toFixed(3);
this.outputShape = t;
var l = _.backend_util.getImageCenter(i, a, s), u = l[0], h = l[1], d = u.toFixed(3), p = h.toFixed(3), f = "";
typeof r == "number" ? f = "float outputValue = " + r.toFixed(2) + ";" : f = `
vec3 fill = vec3(` + r.join(",") + `);
float outputValue = fill[coords[3]];`, this.userCode = `
void main() {
ivec4 coords = getOutputCoords();
int x = coords[2];
int y = coords[1];
float coordXFloat = (float(x) - ` + d + ") * " + c + " - (float(y) - " + p + ") * " + o + `;
float coordYFloat = (float(x) - ` + d + ") * " + o + " + (float(y) - " + p + ") * " + c + `;
int coordX = int(round(coordXFloat + ` + d + `));
int coordY = int(round(coordYFloat + ` + p + `));
` + f + `
if(coordX >= 0 && coordX < ` + s + " && coordY >= 0 && coordY < " + a + `) {
outputValue = getImage(coords[0], coordY, coordX, coords[3]);
}
setOutput(outputValue);
}
`;
}
return n;
}();
var IM = {kernelName: _.RotateWithOffset, backendName: "webgl", kernelFunc: function(n) {
var t = n.inputs, e = n.attrs, r = n.backend, i = t.image, a = e, s = a.radians, o = a.fillValue, c = a.center, l = r, u = new SM(i.shape, s, o, c), h = l.runWebGLProgram(u, [i], i.dtype);
return h;
}};
var AM = d2 + `
return sin(x);
`, TM = Jo(AM), NM = {kernelName: _.Sin, backendName: "webgl", kernelFunc: TM};
var _M = "return x * x;", CM = Jo(_M), RM = {kernelName: _.Square, backendName: "webgl", kernelFunc: CM};
var S2 = "return (a - b) * (a - b);", OM = la({opSnippet: S2, packedOpSnippet: S2}), EM = {kernelName: _.SquaredDifference, backendName: "webgl", kernelFunc: OM};
var I2 = "return a - b;", DM = la({opSnippet: I2, packedOpSnippet: I2, supportsComplex: true, cpuKernelImpl: GW}), kM = {kernelName: _.Sub, backendName: "webgl", kernelFunc: DM};
var FM = "return tan(x);", WM = Jo(FM), UM = {kernelName: _.Tan, backendName: "webgl", kernelFunc: WM};
var BM = {kernelName: _.Transpose, backendName: "webgl", kernelFunc: function(n) {
for (var t = n.inputs, e = n.attrs, r = n.backend, i = t.x, a = e.perm, s = r, o = i.shape.length, c = new Array(o), l = 0; l < c.length; l++)
c[l] = i.shape[a[l]];
var u;
if (s.shouldExecuteOnCPU([i])) {
var h = s.texData.get(i.dataId), d = h.values, p = jd(d, i.shape, i.dtype, a, c);
u = s.makeTensorInfo(c, i.dtype);
var f = s.texData.get(u.dataId);
f.values = p;
} else
u = sp(i, a, s);
return u;
}};
function zM(n) {
var t = n.inputs, e = n.attrs, r = n.backend, i = e.axis, a = t.x;
na(a, "unique"), console.warn("WARNING: ", "UI might be locked temporarily as data is being downloaded");
var s = r.readSync(a.dataId), o = qW(s, i, a.shape, a.dtype), c = o.outputValues, l = o.outputShape, u = o.indices;
return [r.makeTensorInfo(l, a.dtype, c), r.makeTensorInfo([u.length], "int32", u)];
}
var PM = {kernelName: _.Unique, backendName: "webgl", kernelFunc: zM};
var MM = [lP, pP, mP, yP, xP, NP, aP, kP, UP, MP, VP, qP, $P, iP, JP, RP, rM, aM, oM, lM, hM, mM, yM, vM, bM, LM, SP, IP, EP, IM, NM, RM, kM, EM, UM, BM, PM];
for (var op = 0, A2 = MM; op < A2.length; op++) {
var HM = A2[op];
_.registerKernel(HM);
}
Bn.GPGPUContext = Hb;
Bn.MathBackendWebGL = u2;
Bn.forceHalfFloat = h2;
Bn.gpgpu_util = RB;
Bn.setWebGLContext = Mw;
Bn.version_webgl = nP;
Bn.webgl = rP;
Bn.webgl_util = vW;
});
var zt = we((vi) => {
"use strict";
Object.defineProperty(vi, "__esModule", {value: true});
var cp = ei(), lp = l1(), up = I1(), N2 = q1(), VM = Pw(), GM = T2();
var qM = "2.7.0";
var YM = {"tfjs-core": cp.version_core, "tfjs-backend-cpu": VM.version_cpu, "tfjs-backend-webgl": GM.version_webgl, "tfjs-data": N2.version_data, "tfjs-layers": lp.version_layers, "tfjs-converter": up.version_converter, tfjs: qM};
Object.keys(cp).forEach(function(n) {
n !== "default" && Object.defineProperty(vi, n, {enumerable: true, get: function() {
return cp[n];
}});
});
Object.keys(lp).forEach(function(n) {
n !== "default" && Object.defineProperty(vi, n, {enumerable: true, get: function() {
return lp[n];
}});
});
Object.keys(up).forEach(function(n) {
n !== "default" && Object.defineProperty(vi, n, {enumerable: true, get: function() {
return up[n];
}});
});
vi.data = N2;
vi.version = YM;
});
var D2 = we((Qo) => {
const Ve = zt(), _2 = 6;
function KM(n) {
const t = {strides: [n / 16, n / 8], anchors: [2, 6]}, e = [];
for (let r = 0; r < t.strides.length; r++) {
const i = t.strides[r], a = Math.floor((n + i - 1) / i), s = Math.floor((n + i - 1) / i), o = t.anchors[r];
for (let c = 0; c < a; c++) {
const l = i * (c + 0.5);
for (let u = 0; u < s; u++) {
const h = i * (u + 0.5);
for (let d = 0; d < o; d++)
e.push([h, l]);
}
}
}
return e;
}
const C2 = (n) => {
n.startEndTensor.dispose(), n.startPoint.dispose(), n.endPoint.dispose();
}, R2 = (n) => ({startEndTensor: n, startPoint: Ve.slice(n, [0, 0], [-1, 2]), endPoint: Ve.slice(n, [0, 2], [-1, 2])}), O2 = (n, t) => {
const e = Ve.mul(n.startPoint, t), r = Ve.mul(n.endPoint, t), i = Ve.concat2d([e, r], 1);
return R2(i);
};
function jM(n, t, e) {
const r = Ve.slice(n, [0, 1], [-1, 2]), i = Ve.add(r, t), a = Ve.slice(n, [0, 3], [-1, 2]), s = Ve.div(a, e), o = Ve.div(i, e), c = Ve.div(s, 2), l = Ve.sub(o, c), u = Ve.add(o, c), h = Ve.mul(l, e), d = Ve.mul(u, e), p = 1;
return Ve.concat2d([h, d], p);
}
function $M(n, t) {
return Ve.tidy(() => {
const e = n.box ? n.box : n;
return O2(e, t).startEndTensor.squeeze();
});
}
class E2 {
constructor(n, t) {
this.blazeFaceModel = n, this.width = t.detector.inputSize, this.height = t.detector.inputSize, this.maxFaces = t.detector.maxFaces, this.anchorsData = KM(t.detector.inputSize), this.anchors = Ve.tensor2d(this.anchorsData), this.inputSize = Ve.tensor1d([this.width, this.height]), this.iouThreshold = t.detector.iouThreshold, this.scaleFaces = 0.8, this.scoreThreshold = t.detector.scoreThreshold;
}
async getBoundingBoxes(n) {
if (!n || n.isDisposedInternal || n.shape.length !== 4 || n.shape[1] < 1 || n.shape[2] < 1)
return null;
const [t, e, r] = Ve.tidy(() => {
const l = n.resizeBilinear([this.width, this.height]), u = Ve.mul(Ve.sub(l.div(255), 0.5), 2), h = this.blazeFaceModel.predict(u);
let d;
if (Array.isArray(h)) {
const g = h.sort((x, L) => x.size - L.size), y = Ve.concat([g[0], g[2]], 2), w = Ve.concat([g[1], g[3]], 2), b = Ve.concat([w, y], 1);
d = b.squeeze(0);
} else
d = h.squeeze();
const p = jM(d, this.anchors, this.inputSize), f = Ve.slice(d, [0, 0], [-1, 1]), m = Ve.sigmoid(f).squeeze();
return [d, p, m];
}), i = await Ve.image.nonMaxSuppressionAsync(e, r, this.maxFaces, this.iouThreshold, this.scoreThreshold), a = i.arraySync();
i.dispose();
const s = a.map((l) => Ve.slice(e, [l, 0], [1, -1])), o = s.map((l) => {
const u = l.arraySync();
return l.dispose(), u;
}), c = [];
for (let l = 0; l < o.length; l++) {
const u = o[l], h = R2(u), d = a[l], p = this.anchorsData[d], f = Ve.slice(t, [d, _2 - 1], [1, -1]), m = f.squeeze(), g = m.reshape([_2, -1]), y = Ve.slice(r, [d], [1]), w = {box: h, landmarks: g, probability: y, anchor: p};
c.push(w), f.dispose(), m.dispose();
}
return t.dispose(), e.dispose(), r.dispose(), t.dispose(), {boxes: c, scaleFactor: [n.shape[2] / this.width, n.shape[1] / this.height]};
}
async estimateFaces(n) {
const {boxes: t, scaleFactor: e} = await this.getBoundingBoxes(n), r = [];
for (const i of t) {
const a = i.landmarks.arraySync(), s = $M(i, e), o = O2.arraySync(), c = i.probability.arraySync(), l = i.anchor, [u, h] = e, d = a.map((f) => [(f[0] + l[0]) * u, (f[1] + l[1]) * h]), p = {topLeft: o.slice(0, 2), bottomRight: o.slice(2), landmarks: d, probability: c};
C2(i.box), i.landmarks.dispose(), i.probability.dispose(), s.dispose(), r.push(p);
}
return r;
}
}
async function XM(n) {
const t = await Ve.loadGraphModel(n.detector.modelPath, {fromTFHub: n.detector.modelPath.includes("tfhub.dev")}), e = new E2(t, n);
return e;
}
Qo.load = XM;
Qo.BlazeFaceModel = E2;
Qo.disposeBox = C2;
});
var dp = we((hp) => {
hp.MESH_ANNOTATIONS = {silhouette: [10, 338, 297, 332, 284, 251, 389, 356, 454, 323, 361, 288, 397, 365, 379, 378, 400, 377, 152, 148, 176, 149, 150, 136, 172, 58, 132, 93, 234, 127, 162, 21, 54, 103, 67, 109], lipsUpperOuter: [61, 185, 40, 39, 37, 0, 267, 269, 270, 409, 291], lipsLowerOuter: [146, 91, 181, 84, 17, 314, 405, 321, 375, 291], lipsUpperInner: [78, 191, 80, 81, 82, 13, 312, 311, 310, 415, 308], lipsLowerInner: [78, 95, 88, 178, 87, 14, 317, 402, 318, 324, 308], rightEyeUpper0: [246, 161, 160, 159, 158, 157, 173], rightEyeLower0: [33, 7, 163, 144, 145, 153, 154, 155, 133], rightEyeUpper1: [247, 30, 29, 27, 28, 56, 190], rightEyeLower1: [130, 25, 110, 24, 23, 22, 26, 112, 243], rightEyeUpper2: [113, 225, 224, 223, 222, 221, 189], rightEyeLower2: [226, 31, 228, 229, 230, 231, 232, 233, 244], rightEyeLower3: [143, 111, 117, 118, 119, 120, 121, 128, 245], rightEyebrowUpper: [156, 70, 63, 105, 66, 107, 55, 193], rightEyebrowLower: [35, 124, 46, 53, 52, 65], rightEyeIris: [473, 474, 475, 476, 477], leftEyeUpper0: [466, 388, 387, 386, 385, 384, 398], leftEyeLower0: [263, 249, 390, 373, 374, 380, 381, 382, 362], leftEyeUpper1: [467, 260, 259, 257, 258, 286, 414], leftEyeLower1: [359, 255, 339, 254, 253, 252, 256, 341, 463], leftEyeUpper2: [342, 445, 444, 443, 442, 441, 413], leftEyeLower2: [446, 261, 448, 449, 450, 451, 452, 453, 464], leftEyeLower3: [372, 340, 346, 347, 348, 349, 350, 357, 465], leftEyebrowUpper: [383, 300, 293, 334, 296, 336, 285, 417], leftEyebrowLower: [265, 353, 276, 283, 282, 295], leftEyeIris: [468, 469, 470, 471, 472], midwayBetweenEyes: [168], noseTip: [1], noseBottom: [2], noseRightCorner: [98], noseLeftCorner: [327], rightCheek: [205], leftCheek: [425]};
hp.MESH_TO_IRIS_INDICES_MAP = [{key: "EyeUpper0", indices: [9, 10, 11, 12, 13, 14, 15]}, {key: "EyeUpper1", indices: [25, 26, 27, 28, 29, 30, 31]}, {key: "EyeUpper2", indices: [41, 42, 43, 44, 45, 46, 47]}, {key: "EyeLower0", indices: [0, 1, 2, 3, 4, 5, 6, 7, 8]}, {key: "EyeLower1", indices: [16, 17, 18, 19, 20, 21, 22, 23, 24]}, {key: "EyeLower2", indices: [32, 33, 34, 35, 36, 37, 38, 39, 40]}, {key: "EyeLower3", indices: [54, 55, 56, 57, 58, 59, 60, 61, 62]}, {key: "EyebrowUpper", indices: [63, 64, 65, 66, 67, 68, 69, 70]}, {key: "EyebrowLower", indices: [48, 49, 50, 51, 52, 53]}];
});
var k2 = we((wi) => {
const JM = zt();
function ZM(n, t) {
const e = [n.startPoint[0] * t[0], n.startPoint[1] * t[1]], r = [n.endPoint[0] * t[0], n.endPoint[1] * t[1]];
return {startPoint: e, endPoint: r};
}
wi.scaleBoxCoordinates = ZM;
function pp(n) {
return [Math.abs(n.endPoint[0] - n.startPoint[0]), Math.abs(n.endPoint[1] - n.startPoint[1])];
}
wi.getBoxSize = pp;
function fp(n) {
return [n.startPoint[0] + (n.endPoint[0] - n.startPoint[0]) / 2, n.startPoint[1] + (n.endPoint[1] - n.startPoint[1]) / 2];
}
wi.getBoxCenter = fp;
function QM(n, t, e) {
const r = t.shape[1], i = t.shape[2], a = [[n.startPoint[1] / r, n.startPoint[0] / i, n.endPoint[1] / r, n.endPoint[0] / i]];
return JM.image.cropAndResize(t, a, [0], e);
}
wi.cutBoxFromImageAndResize = QM;
function eH(n, t = 1.5) {
const e = fp(n), r = pp(n), i = [t * r[0] / 2, t * r[1] / 2], a = [e[0] - i[0], e[1] - i[1]], s = [e[0] + i[0], e[1] + i[1]];
return {startPoint: a, endPoint: s, landmarks: n.landmarks};
}
wi.enlargeBox = eH;
function tH(n) {
const t = fp(n), e = pp(n), r = Math.max(...e), i = r / 2, a = [t[0] - i, t[1] - i], s = [t[0] + i, t[1] + i];
return {startPoint: a, endPoint: s, landmarks: n.landmarks};
}
wi.squarifyBox = tH;
});
var z2 = we((Tn) => {
Tn.IDENTITY_MATRIX = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
function F2(n) {
return n - 2 * Math.PI * Math.floor((n + Math.PI) / (2 * Math.PI));
}
Tn.normalizeRadians = F2;
function nH(n, t) {
const e = Math.PI / 2 - Math.atan2(-(t[1] - n[1]), t[0] - n[0]);
return F2(e);
}
Tn.computeRotation = nH;
function rH(n) {
return n * 180 / Math.PI;
}
Tn.radToDegrees = rH;
function W2(n, t) {
return [[1, 0, n], [0, 1, t], [0, 0, 1]];
}
function da(n, t) {
let e = 0;
for (let r = 0; r < n.length; r++)
e += n[r] * t[r];
return e;
}
Tn.dot = da;
function U2(n, t) {
const e = [];
for (let r = 0; r < n.length; r++)
e.push(n[r][t]);
return e;
}
Tn.getColumnFrom2DArr = U2;
function B2(n, t) {
const e = [], r = n.length;
for (let i = 0; i < r; i++) {
e.push([]);
for (let a = 0; a < r; a++)
e[i].push(da(n[i], U2(t, a)));
}
return e;
}
function iH(n, t) {
const e = Math.cos(n), r = Math.sin(n), i = [[e, -r, 0], [r, e, 0], [0, 0, 1]], a = W2(t[0], t[1]), s = B2(a, i), o = W2(-t[0], -t[1]);
return B2(s, o);
}
Tn.buildRotationMatrix = iH;
function aH(n) {
const t = [[n[0][0], n[1][0]], [n[0][1], n[1][1]]], e = [n[0][2], n[1][2]], r = [-da(t[0], e), -da(t[1], e)];
return [t[0].concat(r[0]), t[1].concat(r[1]), [0, 0, 1]];
}
Tn.invertTransformMatrix = aH;
function sH(n, t) {
return [da(n, t[0]), da(n, t[1])];
}
Tn.rotatePoint = sH;
function oH(n, t) {
return Math.sqrt((n[0] - t[0]) ** 2 + (n[1] - t[1]) ** 2);
}
Tn.xyDistanceBetweenPoints = oH;
});
var M2 = we((P2) => {
const or = zt(), Pn = k2(), Dr = dp(), kr = z2(), cH = 468, lH = 0.25, uH = 13, hH = [uH, Dr.MESH_ANNOTATIONS.midwayBetweenEyes[0]], dH = 3, pH = 2, fH = [dH, pH], mp = Dr.MESH_ANNOTATIONS.leftEyeLower0, gp = [mp[0], mp[mp.length - 1]], yp = Dr.MESH_ANNOTATIONS.rightEyeLower0, vp = [yp[0], yp[yp.length - 1]], mH = 3, gH = 4, yH = 71, wp = 76;
function ec(n, t, e, r) {
for (let i = 0; i < Dr.MESH_TO_IRIS_INDICES_MAP.length; i++) {
const {key: a, indices: s} = Dr.MESH_TO_IRIS_INDICES_MAP[i], o = Dr.MESH_ANNOTATIONS[`${e}${a}`], c = r == null;
if (c || r.includes(a))
for (let l = 0; l < s.length; l++) {
const u = s[l];
n[o[l]] = [t[u][0], t[u][1], (t[u][2] + n[o[l]][2]) / 2];
}
}
}
class vH {
constructor(n, t, e, r) {
this.regionsOfInterest = [], this.runsWithoutFaceDetector = 0, this.boundingBoxDetector = n, this.meshDetector = t, this.irisModel = e, this.meshWidth = r.mesh.inputSize, this.meshHeight = r.mesh.inputSize, this.irisSize = r.iris.inputSize, this.irisEnlarge = r.iris.enlargeFactor;
}
transformRawCoords(n, t, e, r) {
const i = Pn.getBoxSize({startPoint: t.startPoint, endPoint: t.endPoint}), a = [i[0] / this.meshWidth, i[1] / this.meshHeight], s = n.map((d) => [a[0] * (d[0] - this.meshWidth / 2), a[1] * (d[1] - this.meshHeight / 2), d[2]]), o = kr.buildRotationMatrix(e, [0, 0]), c = s.map((d) => [...kr.rotatePoint(d, o), d[2]]), l = kr.invertTransformMatrix(r), u = [...Pn.getBoxCenter({startPoint: t.startPoint, endPoint: t.endPoint}), 1], h = [kr.dot(u, l[0]), kr.dot(u, l[1])];
return c.map((d) => [d[0] + h[0], d[1] + h[1], d[2]]);
}
getLeftToRightEyeDepthDifference(n) {
const t = n[gp[0]][2], e = n[vp[0]][2];
return t - e;
}
getEyeBox(n, t, e, r, i = false) {
const a = Pn.squarifyBox(Pn.enlargeBox(this.calculateLandmarksBoundingBox([n[e], n[r]]), this.irisEnlarge)), s = Pn.getBoxSize(a);
let o = or.image.cropAndResize(t, [[a.startPoint[1] / this.meshHeight, a.startPoint[0] / this.meshWidth, a.endPoint[1] / this.meshHeight, a.endPoint[0] / this.meshWidth]], [0], [this.irisSize, this.irisSize]);
return i && (o = or.image.flipLeftRight(o)), {box: a, boxSize: s, crop: o};
}
getEyeCoords(n, t, e, r = false) {
const i = [];
for (let a = 0; a < wp; a++) {
const s = n[a * 3], o = n[a * 3 + 1], c = n[a * 3 + 2];
i.push([(r ? 1 - s / this.irisSize : s / this.irisSize) * e[0] + t.startPoint[0], o / this.irisSize * e[1] + t.startPoint[1], c]);
}
return {rawCoords: i, iris: i.slice(yH)};
}
getAdjustedIrisCoords(n, t, e) {
const r = n[Dr.MESH_ANNOTATIONS[`${e}EyeUpper0`][mH]][2], i = n[Dr.MESH_ANNOTATIONS[`${e}EyeLower0`][gH]][2], a = (r + i) / 2;
return t.map((s, o) => {
let c = a;
return o === 2 ? c = r : o === 4 && (c = i), [s[0], s[1], c];
});
}
async predict(n, t) {
if (this.skipFrames = t.detector.skipFrames, this.maxFaces = t.detector.maxFaces, this.runsWithoutFaceDetector++, this.shouldUpdateRegionsOfInterest()) {
const r = await this.boundingBoxDetector.getBoundingBoxes(n);
if (!r || !r.boxes || r.boxes.length === 0)
return this.regionsOfInterest = [], null;
const i = r.boxes.map((a) => {
const s = a.box.startPoint.squeeze(), o = a.box.endPoint.squeeze(), c = {startPoint: s.arraySync(), endPoint: o.arraySync()};
s.dispose(), o.dispose();
const l = Pn.scaleBoxCoordinates(c, r.scaleFactor), u = Pn.enlargeBox(l), h = a.landmarks.arraySync();
return a.box.startPoint.dispose(), a.box.endPoint.dispose(), a.landmarks.dispose(), a.probability.dispose(), {...u, landmarks: h};
});
this.updateRegionsOfInterest(i), this.runsWithoutFaceDetector = 0;
}
const e = or.tidy(() => this.regionsOfInterest.map((r, i) => {
let a = 0;
const s = r.landmarks.length >= cH;
let [o, c] = hH;
s === false && ([o, c] = fH), a = kr.computeRotation(r.landmarks[o], r.landmarks[c]);
const l = Pn.getBoxCenter({startPoint: r.startPoint, endPoint: r.endPoint}), u = [l[0] / n.shape[2], l[1] / n.shape[1]];
let h = n, d = kr.IDENTITY_MATRIX;
a !== 0 && (h = or.image.rotateWithOffset(n, a, 0, u), d = kr.buildRotationMatrix(-a, l));
const p = {startPoint: r.startPoint, endPoint: r.endPoint}, f = Pn.cutBoxFromImageAndResize(p, h, [this.meshHeight, this.meshWidth]).div(255), [, m, g] = this.meshDetector.predict(f), y = or.reshape(g, [-1, 3]);
let w = y.arraySync();
if (t.iris.enabled) {
const {box: I, boxSize: C, crop: O} = this.getEyeBox(w, f, gp[0], gp[1], true), {box: D, boxSize: F, crop: k} = this.getEyeBox(w, f, vp[0], vp[1]), B = this.irisModel.predict(or.concat([O, k])), V = B.dataSync();
B.dispose();
const P = V.slice(0, wp * 3), {rawCoords: G, iris: j} = this.getEyeCoords(P, I, C, true), q = V.slice(wp * 3), {rawCoords: H, iris: J} = this.getEyeCoords(q, D, F), $ = this.getLeftToRightEyeDepthDifference(w);
Math.abs($) < 30 ? (ec(w, G, "left"), ec(w, H, "right")) : $ < 1 ? ec(w, G, "left", ["EyeUpper0", "EyeLower0"]) : ec(w, H, "right", ["EyeUpper0", "EyeLower0"]);
const ee = this.getAdjustedIrisCoords(w, j, "left"), te = this.getAdjustedIrisCoords(w, J, "right");
w = w.concat(ee).concat(te);
}
const b = this.transformRawCoords(w, r, a, d);
or.dispose(w);
const x = Pn.enlargeBox(this.calculateLandmarksBoundingBox(b)), L = m.squeeze();
if (or.dispose(m), t.mesh.enabled) {
const I = or.tensor2d(b);
this.regionsOfInterest[i] = {...x, landmarks: I.arraySync()};
const C = {coords: I, box: x, confidence: L, image: f};
return C;
}
const N = {coords: null, box: x, confidence: L, image: f};
return N;
}));
return e;
}
updateRegionsOfInterest(n) {
for (let t = 0; t < n.length; t++) {
const e = n[t], r = this.regionsOfInterest[t];
let i = 0;
if (r && r.startPoint) {
const [a, s] = e.startPoint, [o, c] = e.endPoint, [l, u] = r.startPoint, [h, d] = r.endPoint, p = Math.max(a, l), f = Math.max(s, u), m = Math.min(o, h), g = Math.min(c, d), y = (m - p) * (g - f), w = (o - a) * (c - s), b = (h - l) * (d - s);
i = y / (w + b - y);
}
i < lH && (this.regionsOfInterest[t] = e);
}
this.regionsOfInterest = this.regionsOfInterest.slice(0, n.length);
}
clearRegionOfInterest(n) {
this.regionsOfInterest[n] != null && (this.regionsOfInterest = [...this.regionsOfInterest.slice(0, n), ...this.regionsOfInterest.slice(n + 1)]);
}
shouldUpdateRegionsOfInterest() {
return this.regionsOfInterest.length === 0 ? true : this.regionsOfInterest.length !== this.maxFaces && this.runsWithoutFaceDetector >= this.skipFrames;
}
calculateLandmarksBoundingBox(n) {
const t = n.map((a) => a[0]), e = n.map((a) => a[1]), r = [Math.min(...t), Math.min(...e)], i = [Math.max(...t), Math.max(...e)];
return {startPoint: r, endPoint: i, landmarks: n};
}
}
P2.Pipeline = vH;
});
var V2 = we((H2) => {
H2.UV_COORDS = [[0.499976992607117, 0.652534008026123], [0.500025987625122, 0.547487020492554], [0.499974012374878, 0.602371990680695], [0.482113003730774, 0.471979022026062], [0.500150978565216, 0.527155995368958], [0.499909996986389, 0.498252987861633], [0.499523013830185, 0.40106201171875], [0.289712011814117, 0.380764007568359], [0.499954998493195, 0.312398016452789], [0.499987006187439, 0.269918978214264], [0.500023007392883, 0.107050001621246], [0.500023007392883, 0.666234016418457], [0.5000159740448, 0.679224014282227], [0.500023007392883, 0.692348003387451], [0.499976992607117, 0.695277988910675], [0.499976992607117, 0.70593398809433], [0.499976992607117, 0.719385027885437], [0.499976992607117, 0.737019002437592], [0.499967992305756, 0.781370997428894], [0.499816000461578, 0.562981009483337], [0.473773002624512, 0.573909997940063], [0.104906998574734, 0.254140973091125], [0.365929991006851, 0.409575998783112], [0.338757991790771, 0.41302502155304], [0.311120003461838, 0.409460008144379], [0.274657994508743, 0.389131009578705], [0.393361985683441, 0.403706014156342], [0.345234006643295, 0.344011008739471], [0.370094001293182, 0.346076011657715], [0.319321990013123, 0.347265005111694], [0.297903001308441, 0.353591024875641], [0.24779200553894, 0.410809993743896], [0.396889001131058, 0.842755019664764], [0.280097991228104, 0.375599980354309], [0.106310002505779, 0.399955987930298], [0.2099249958992, 0.391353011131287], [0.355807989835739, 0.534406006336212], [0.471751004457474, 0.65040397644043], [0.474155008792877, 0.680191993713379], [0.439785003662109, 0.657229006290436], [0.414617002010345, 0.66654098033905], [0.450374007225037, 0.680860996246338], [0.428770989179611, 0.682690978050232], [0.374971002340317, 0.727805018424988], [0.486716985702515, 0.547628998756409], [0.485300987958908, 0.527395009994507], [0.257764995098114, 0.314490020275116], [0.401223003864288, 0.455172002315521], [0.429818987846375, 0.548614978790283], [0.421351999044418, 0.533740997314453], [0.276895999908447, 0.532056987285614], [0.483370006084442, 0.499586999416351], [0.33721199631691, 0.282882988452911], [0.296391993761063, 0.293242990970612], [0.169294998049736, 0.193813979625702], [0.447580009698868, 0.302609980106354], [0.392390012741089, 0.353887975215912], [0.354490011930466, 0.696784019470215], [0.067304998636246, 0.730105042457581], [0.442739009857178, 0.572826027870178], [0.457098007202148, 0.584792017936707], [0.381974011659622, 0.694710969924927], [0.392388999462128, 0.694203019142151], [0.277076005935669, 0.271932005882263], [0.422551989555359, 0.563233017921448], [0.385919004678726, 0.281364023685455], [0.383103013038635, 0.255840003490448], [0.331431001424789, 0.119714021682739], [0.229923993349075, 0.232002973556519], [0.364500999450684, 0.189113974571228], [0.229622006416321, 0.299540996551514], [0.173287004232407, 0.278747975826263], [0.472878992557526, 0.666198015213013], [0.446828007698059, 0.668527007102966], [0.422762006521225, 0.673889994621277], [0.445307999849319, 0.580065965652466], [0.388103008270264, 0.693961024284363], [0.403039008378983, 0.706539988517761], [0.403629004955292, 0.693953037261963], [0.460041999816895, 0.557139039039612], [0.431158006191254, 0.692366003990173], [0.452181994915009, 0.692366003990173], [0.475387006998062, 0.692366003990173], [0.465828001499176, 0.779190003871918], [0.472328990697861, 0.736225962638855], [0.473087012767792, 0.717857003211975], [0.473122000694275, 0.704625964164734], [0.473033010959625, 0.695277988910675], [0.427942007780075, 0.695277988910675], [0.426479011774063, 0.703539967536926], [0.423162013292313, 0.711845993995667], [0.4183090031147, 0.720062971115112], [0.390094995498657, 0.639572978019714], [0.013953999616206, 0.560034036636353], [0.499913990497589, 0.58014702796936], [0.413199990987778, 0.69539999961853], [0.409626007080078, 0.701822996139526], [0.468080013990402, 0.601534962654114], [0.422728985548019, 0.585985004901886], [0.463079988956451, 0.593783974647522], [0.37211999297142, 0.47341400384903], [0.334562003612518, 0.496073007583618], [0.411671012639999, 0.546965003013611], [0.242175996303558, 0.14767599105835], [0.290776997804642, 0.201445996761322], [0.327338010072708, 0.256527006626129], [0.399509996175766, 0.748921036720276], [0.441727995872498, 0.261676013469696], [0.429764986038208, 0.187834024429321], [0.412198007106781, 0.108901023864746], [0.288955003023148, 0.398952007293701], [0.218936994671822, 0.435410976409912], [0.41278201341629, 0.398970007896423], [0.257135003805161, 0.355440020561218], [0.427684992551804, 0.437960982322693], [0.448339998722076, 0.536936044692993], [0.178560003638268, 0.45755398273468], [0.247308000922203, 0.457193970680237], [0.286267012357712, 0.467674970626831], [0.332827985286713, 0.460712015628815], [0.368755996227264, 0.447206974029541], [0.398963987827301, 0.432654976844788], [0.476410001516342, 0.405806005001068], [0.189241006970406, 0.523923993110657], [0.228962004184723, 0.348950982093811], [0.490725994110107, 0.562400996685028], [0.404670000076294, 0.485132992267609], [0.019469000399113, 0.401564002037048], [0.426243007183075, 0.420431017875671], [0.396993011236191, 0.548797011375427], [0.266469985246658, 0.376977026462555], [0.439121007919312, 0.51895797252655], [0.032313998788595, 0.644356966018677], [0.419054001569748, 0.387154996395111], [0.462783008813858, 0.505746960639954], [0.238978996872902, 0.779744982719421], [0.198220998048782, 0.831938028335571], [0.107550002634525, 0.540755033493042], [0.183610007166862, 0.740257024765015], [0.134409993886948, 0.333683013916016], [0.385764002799988, 0.883153975009918], [0.490967005491257, 0.579378008842468], [0.382384985685349, 0.508572995662689], [0.174399003386497, 0.397670984268188], [0.318785011768341, 0.39623498916626], [0.343364000320435, 0.400596976280212], [0.396100014448166, 0.710216999053955], [0.187885001301765, 0.588537991046906], [0.430987000465393, 0.944064974784851], [0.318993002176285, 0.898285031318665], [0.266247987747192, 0.869701027870178], [0.500023007392883, 0.190576016902924], [0.499976992607117, 0.954452991485596], [0.366169989109039, 0.398822009563446], [0.393207013607025, 0.39553701877594], [0.410373002290726, 0.391080021858215], [0.194993004202843, 0.342101991176605], [0.388664990663528, 0.362284004688263], [0.365961998701096, 0.355970978736877], [0.343364000320435, 0.355356991291046], [0.318785011768341, 0.35834002494812], [0.301414996385574, 0.363156020641327], [0.058132998645306, 0.319076001644135], [0.301414996385574, 0.387449026107788], [0.499987989664078, 0.618434011936188], [0.415838003158569, 0.624195992946625], [0.445681989192963, 0.566076993942261], [0.465844005346298, 0.620640993118286], [0.49992299079895, 0.351523995399475], [0.288718998432159, 0.819945991039276], [0.335278987884521, 0.852819979190826], [0.440512001514435, 0.902418971061707], [0.128294005990028, 0.791940987110138], [0.408771991729736, 0.373893976211548], [0.455606997013092, 0.451801002025604], [0.499877005815506, 0.908990025520325], [0.375436991453171, 0.924192011356354], [0.11421000212431, 0.615022003650665], [0.448662012815475, 0.695277988910675], [0.4480200111866, 0.704632043838501], [0.447111994028091, 0.715808033943176], [0.444831997156143, 0.730794012546539], [0.430011987686157, 0.766808986663818], [0.406787008047104, 0.685672998428345], [0.400738000869751, 0.681069016456604], [0.392399996519089, 0.677703022956848], [0.367855995893478, 0.663918972015381], [0.247923001646996, 0.601333022117615], [0.452769994735718, 0.420849978923798], [0.43639200925827, 0.359887003898621], [0.416164010763168, 0.368713974952698], [0.413385987281799, 0.692366003990173], [0.228018000721931, 0.683571994304657], [0.468268007040024, 0.352671027183533], [0.411361992359161, 0.804327011108398], [0.499989002943039, 0.469825029373169], [0.479153990745544, 0.442654013633728], [0.499974012374878, 0.439637005329132], [0.432112008333206, 0.493588984012604], [0.499886006116867, 0.866917014122009], [0.49991300702095, 0.821729004383087], [0.456548988819122, 0.819200992584229], [0.344549000263214, 0.745438992977142], [0.37890899181366, 0.574010014533997], [0.374292999505997, 0.780184984207153], [0.319687992334366, 0.570737957954407], [0.357154995203018, 0.604269981384277], [0.295284003019333, 0.621580958366394], [0.447750002145767, 0.862477004528046], [0.410986006259918, 0.508723020553589], [0.31395098567009, 0.775308012962341], [0.354128003120422, 0.812552988529205], [0.324548006057739, 0.703992962837219], [0.189096003770828, 0.646299958229065], [0.279776990413666, 0.71465802192688], [0.1338230073452, 0.682700991630554], [0.336768001317978, 0.644733011722565], [0.429883986711502, 0.466521978378296], [0.455527991056442, 0.548622965812683], [0.437114000320435, 0.558896005153656], [0.467287987470627, 0.529924988746643], [0.414712011814117, 0.335219979286194], [0.37704598903656, 0.322777986526489], [0.344107985496521, 0.320150971412659], [0.312875986099243, 0.32233202457428], [0.283526003360748, 0.333190023899078], [0.241245999932289, 0.382785975933075], [0.102986000478268, 0.468762993812561], [0.267612010240555, 0.424560010433197], [0.297879010438919, 0.433175981044769], [0.333433985710144, 0.433878004550934], [0.366427004337311, 0.426115989685059], [0.396012008190155, 0.416696012020111], [0.420121014118195, 0.41022801399231], [0.007561000064015, 0.480777025222778], [0.432949006557465, 0.569517970085144], [0.458638995885849, 0.479089021682739], [0.473466008901596, 0.545744001865387], [0.476087987422943, 0.563830018043518], [0.468472003936768, 0.555056989192963], [0.433990985155106, 0.582361996173859], [0.483518004417419, 0.562983989715576], [0.482482999563217, 0.57784903049469], [0.42645001411438, 0.389798998832703], [0.438998997211456, 0.39649498462677], [0.450067013502121, 0.400434017181396], [0.289712011814117, 0.368252992630005], [0.276670008897781, 0.363372981548309], [0.517862021923065, 0.471948027610779], [0.710287988185883, 0.380764007568359], [0.526226997375488, 0.573909997940063], [0.895093023777008, 0.254140973091125], [0.634069979190826, 0.409575998783112], [0.661242008209229, 0.41302502155304], [0.688880026340485, 0.409460008144379], [0.725341975688934, 0.389131009578705], [0.606630027294159, 0.40370500087738], [0.654766023159027, 0.344011008739471], [0.629905998706818, 0.346076011657715], [0.680678009986877, 0.347265005111694], [0.702096998691559, 0.353591024875641], [0.75221198797226, 0.410804986953735], [0.602918028831482, 0.842862963676453], [0.719901978969574, 0.375599980354309], [0.893692970275879, 0.399959981441498], [0.790081977844238, 0.391354024410248], [0.643998026847839, 0.534487962722778], [0.528249025344849, 0.65040397644043], [0.525849997997284, 0.680191040039062], [0.560214996337891, 0.657229006290436], [0.585384011268616, 0.66654098033905], [0.549625992774963, 0.680860996246338], [0.57122802734375, 0.682691991329193], [0.624852001667023, 0.72809898853302], [0.513050019741058, 0.547281980514526], [0.51509702205658, 0.527251958847046], [0.742246985435486, 0.314507007598877], [0.598631024360657, 0.454979002475739], [0.570338010787964, 0.548575043678284], [0.578631997108459, 0.533622980117798], [0.723087012767792, 0.532054007053375], [0.516445994377136, 0.499638974666595], [0.662801027297974, 0.282917976379395], [0.70362401008606, 0.293271005153656], [0.830704987049103, 0.193813979625702], [0.552385985851288, 0.302568018436432], [0.607609987258911, 0.353887975215912], [0.645429015159607, 0.696707010269165], [0.932694971561432, 0.730105042457581], [0.557260990142822, 0.572826027870178], [0.542901992797852, 0.584792017936707], [0.6180260181427, 0.694710969924927], [0.607590973377228, 0.694203019142151], [0.722943007946014, 0.271963000297546], [0.577413976192474, 0.563166975975037], [0.614082992076874, 0.281386971473694], [0.616907000541687, 0.255886018276215], [0.668509006500244, 0.119913995265961], [0.770092010498047, 0.232020974159241], [0.635536015033722, 0.189248979091644], [0.77039098739624, 0.299556016921997], [0.826722025871277, 0.278755009174347], [0.527121007442474, 0.666198015213013], [0.553171992301941, 0.668527007102966], [0.577238023281097, 0.673889994621277], [0.554691970348358, 0.580065965652466], [0.611896991729736, 0.693961024284363], [0.59696102142334, 0.706539988517761], [0.596370995044708, 0.693953037261963], [0.539958000183105, 0.557139039039612], [0.568841993808746, 0.692366003990173], [0.547818005084991, 0.692366003990173], [0.52461302280426, 0.692366003990173], [0.534089982509613, 0.779141008853912], [0.527670979499817, 0.736225962638855], [0.526912987232208, 0.717857003211975], [0.526877999305725, 0.704625964164734], [0.526966989040375, 0.695277988910675], [0.572058022022247, 0.695277988910675], [0.573521018028259, 0.703539967536926], [0.57683801651001, 0.711845993995667], [0.581691026687622, 0.720062971115112], [0.609944999217987, 0.639909982681274], [0.986046016216278, 0.560034036636353], [0.5867999792099, 0.69539999961853], [0.590372025966644, 0.701822996139526], [0.531915009021759, 0.601536989212036], [0.577268004417419, 0.585934996604919], [0.536915004253387, 0.593786001205444], [0.627542972564697, 0.473352015018463], [0.665585994720459, 0.495950996875763], [0.588353991508484, 0.546862006187439], [0.757824003696442, 0.14767599105835], [0.709249973297119, 0.201507985591888], [0.672684013843536, 0.256581008434296], [0.600408971309662, 0.74900496006012], [0.55826598405838, 0.261672019958496], [0.570303976535797, 0.187870979309082], [0.588165998458862, 0.109044015407562], [0.711045026779175, 0.398952007293701], [0.781069993972778, 0.435405015945435], [0.587247014045715, 0.398931980133057], [0.742869973182678, 0.355445981025696], [0.572156012058258, 0.437651991844177], [0.55186802148819, 0.536570012569427], [0.821442008018494, 0.457556009292603], [0.752701997756958, 0.457181990146637], [0.71375697851181, 0.467626988887787], [0.66711300611496, 0.460672974586487], [0.631101012229919, 0.447153985500336], [0.6008620262146, 0.432473003864288], [0.523481011390686, 0.405627012252808], [0.810747981071472, 0.523926019668579], [0.771045982837677, 0.348959028720856], [0.509127020835876, 0.562718033790588], [0.595292985439301, 0.485023975372314], [0.980530977249146, 0.401564002037048], [0.573499977588654, 0.420000016689301], [0.602994978427887, 0.548687994480133], [0.733529984951019, 0.376977026462555], [0.560611009597778, 0.519016981124878], [0.967685997486115, 0.644356966018677], [0.580985009670258, 0.387160003185272], [0.537728011608124, 0.505385041236877], [0.760966002941132, 0.779752969741821], [0.801778972148895, 0.831938028335571], [0.892440974712372, 0.54076099395752], [0.816350996494293, 0.740260004997253], [0.865594983100891, 0.333687007427216], [0.614073991775513, 0.883246004581451], [0.508952975273132, 0.579437971115112], [0.617941975593567, 0.508316040039062], [0.825608015060425, 0.397674977779388], [0.681214988231659, 0.39623498916626], [0.656635999679565, 0.400596976280212], [0.603900015354156, 0.710216999053955], [0.81208598613739, 0.588539004325867], [0.56801301240921, 0.944564998149872], [0.681007981300354, 0.898285031318665], [0.733752012252808, 0.869701027870178], [0.633830010890961, 0.398822009563446], [0.606792986392975, 0.39553701877594], [0.589659988880157, 0.391062021255493], [0.805015981197357, 0.342108011245728], [0.611334979534149, 0.362284004688263], [0.634037971496582, 0.355970978736877], [0.656635999679565, 0.355356991291046], [0.681214988231659, 0.35834002494812], [0.698584973812103, 0.363156020641327], [0.941866993904114, 0.319076001644135], [0.698584973812103, 0.387449026107788], [0.584177017211914, 0.624107003211975], [0.554318010807037, 0.566076993942261], [0.534153997898102, 0.62064003944397], [0.711217999458313, 0.819975018501282], [0.664629995822906, 0.852871000766754], [0.559099972248077, 0.902631998062134], [0.871706008911133, 0.791940987110138], [0.591234028339386, 0.373893976211548], [0.544341027736664, 0.451583981513977], [0.624562978744507, 0.924192011356354], [0.88577002286911, 0.615028977394104], [0.551338016986847, 0.695277988910675], [0.551980018615723, 0.704632043838501], [0.552887976169586, 0.715808033943176], [0.555167973041534, 0.730794012546539], [0.569944024085999, 0.767035007476807], [0.593203008174896, 0.685675978660583], [0.599261999130249, 0.681069016456604], [0.607599973678589, 0.677703022956848], [0.631937980651855, 0.663500010967255], [0.752032995223999, 0.601315021514893], [0.547226011753082, 0.420395016670227], [0.563543975353241, 0.359827995300293], [0.583841025829315, 0.368713974952698], [0.586614012718201, 0.692366003990173], [0.771915018558502, 0.683578014373779], [0.531597018241882, 0.352482974529266], [0.588370978832245, 0.804440975189209], [0.52079701423645, 0.442565023899078], [0.567984998226166, 0.493479013442993], [0.543282985687256, 0.819254994392395], [0.655317008495331, 0.745514988899231], [0.621008992195129, 0.574018001556396], [0.625559985637665, 0.78031200170517], [0.680198013782501, 0.570719003677368], [0.64276397228241, 0.604337990283966], [0.704662978649139, 0.621529996395111], [0.552012026309967, 0.862591981887817], [0.589071989059448, 0.508637011051178], [0.685944974422455, 0.775357007980347], [0.645735025405884, 0.812640011310577], [0.675342977046967, 0.703978002071381], [0.810858011245728, 0.646304965019226], [0.72012197971344, 0.714666962623596], [0.866151988506317, 0.682704985141754], [0.663187026977539, 0.644596993923187], [0.570082008838654, 0.466325998306274], [0.544561982154846, 0.548375964164734], [0.562758982181549, 0.558784961700439], [0.531987011432648, 0.530140042304993], [0.585271000862122, 0.335177004337311], [0.622952997684479, 0.32277899980545], [0.655896008014679, 0.320163011550903], [0.687132000923157, 0.322345972061157], [0.716481983661652, 0.333200991153717], [0.758756995201111, 0.382786989212036], [0.897013008594513, 0.468769013881683], [0.732392013072968, 0.424547016620636], [0.70211398601532, 0.433162987232208], [0.66652500629425, 0.433866024017334], [0.633504986763, 0.426087975502014], [0.603875994682312, 0.416586995124817], [0.579657971858978, 0.409945011138916], [0.992439985275269, 0.480777025222778], [0.567192018032074, 0.569419980049133], [0.54136598110199, 0.478899002075195], [0.526564002037048, 0.546118021011353], [0.523913025856018, 0.563830018043518], [0.531529009342194, 0.555056989192963], [0.566035985946655, 0.582329034805298], [0.51631098985672, 0.563053965568542], [0.5174720287323, 0.577877044677734], [0.573594987392426, 0.389806985855103], [0.560697972774506, 0.395331978797913], [0.549755990505219, 0.399751007556915], [0.710287988185883, 0.368252992630005], [0.723330020904541, 0.363372981548309]];
});
var G2 = we((wH) => {
vs(wH, {default: () => bH});
var bH = [127, 34, 139, 11, 0, 37, 232, 231, 120, 72, 37, 39, 128, 121, 47, 232, 121, 128, 104, 69, 67, 175, 171, 148, 157, 154, 155, 118, 50, 101, 73, 39, 40, 9, 151, 108, 48, 115, 131, 194, 204, 211, 74, 40, 185, 80, 42, 183, 40, 92, 186, 230, 229, 118, 202, 212, 214, 83, 18, 17, 76, 61, 146, 160, 29, 30, 56, 157, 173, 106, 204, 194, 135, 214, 192, 203, 165, 98, 21, 71, 68, 51, 45, 4, 144, 24, 23, 77, 146, 91, 205, 50, 187, 201, 200, 18, 91, 106, 182, 90, 91, 181, 85, 84, 17, 206, 203, 36, 148, 171, 140, 92, 40, 39, 193, 189, 244, 159, 158, 28, 247, 246, 161, 236, 3, 196, 54, 68, 104, 193, 168, 8, 117, 228, 31, 189, 193, 55, 98, 97, 99, 126, 47, 100, 166, 79, 218, 155, 154, 26, 209, 49, 131, 135, 136, 150, 47, 126, 217, 223, 52, 53, 45, 51, 134, 211, 170, 140, 67, 69, 108, 43, 106, 91, 230, 119, 120, 226, 130, 247, 63, 53, 52, 238, 20, 242, 46, 70, 156, 78, 62, 96, 46, 53, 63, 143, 34, 227, 173, 155, 133, 123, 117, 111, 44, 125, 19, 236, 134, 51, 216, 206, 205, 154, 153, 22, 39, 37, 167, 200, 201, 208, 36, 142, 100, 57, 212, 202, 20, 60, 99, 28, 158, 157, 35, 226, 113, 160, 159, 27, 204, 202, 210, 113, 225, 46, 43, 202, 204, 62, 76, 77, 137, 123, 116, 41, 38, 72, 203, 129, 142, 64, 98, 240, 49, 102, 64, 41, 73, 74, 212, 216, 207, 42, 74, 184, 169, 170, 211, 170, 149, 176, 105, 66, 69, 122, 6, 168, 123, 147, 187, 96, 77, 90, 65, 55, 107, 89, 90, 180, 101, 100, 120, 63, 105, 104, 93, 137, 227, 15, 86, 85, 129, 102, 49, 14, 87, 86, 55, 8, 9, 100, 47, 121, 145, 23, 22, 88, 89, 179, 6, 122, 196, 88, 95, 96, 138, 172, 136, 215, 58, 172, 115, 48, 219, 42, 80, 81, 195, 3, 51, 43, 146, 61, 171, 175, 199, 81, 82, 38, 53, 46, 225, 144, 163, 110, 246, 33, 7, 52, 65, 66, 229, 228, 117, 34, 127, 234, 107, 108, 69, 109, 108, 151, 48, 64, 235, 62, 78, 191, 129, 209, 126, 111, 35, 143, 163, 161, 246, 117, 123, 50, 222, 65, 52, 19, 125, 141, 221, 55, 65, 3, 195, 197, 25, 7, 33, 220, 237, 44, 70, 71, 139, 122, 193, 245, 247, 130, 33, 71, 21, 162, 153, 158, 159, 170, 169, 150, 188, 174, 196, 216, 186, 92, 144, 160, 161, 2, 97, 167, 141, 125, 241, 164, 167, 37, 72, 38, 12, 145, 159, 160, 38, 82, 13, 63, 68, 71, 226, 35, 111, 158, 153, 154, 101, 50, 205, 206, 92, 165, 209, 198, 217, 165, 167, 97, 220, 115, 218, 133, 112, 243, 239, 238, 241, 214, 135, 169, 190, 173, 133, 171, 208, 32, 125, 44, 237, 86, 87, 178, 85, 86, 179, 84, 85, 180, 83, 84, 181, 201, 83, 182, 137, 93, 132, 76, 62, 183, 61, 76, 184, 57, 61, 185, 212, 57, 186, 214, 207, 187, 34, 143, 156, 79, 239, 237, 123, 137, 177, 44, 1, 4, 201, 194, 32, 64, 102, 129, 213, 215, 138, 59, 166, 219, 242, 99, 97, 2, 94, 141, 75, 59, 235, 24, 110, 228, 25, 130, 226, 23, 24, 229, 22, 23, 230, 26, 22, 231, 112, 26, 232, 189, 190, 243, 221, 56, 190, 28, 56, 221, 27, 28, 222, 29, 27, 223, 30, 29, 224, 247, 30, 225, 238, 79, 20, 166, 59, 75, 60, 75, 240, 147, 177, 215, 20, 79, 166, 187, 147, 213, 112, 233, 244, 233, 128, 245, 128, 114, 188, 114, 217, 174, 131, 115, 220, 217, 198, 236, 198, 131, 134, 177, 132, 58, 143, 35, 124, 110, 163, 7, 228, 110, 25, 356, 389, 368, 11, 302, 267, 452, 350, 349, 302, 303, 269, 357, 343, 277, 452, 453, 357, 333, 332, 297, 175, 152, 377, 384, 398, 382, 347, 348, 330, 303, 304, 270, 9, 336, 337, 278, 279, 360, 418, 262, 431, 304, 408, 409, 310, 415, 407, 270, 409, 410, 450, 348, 347, 422, 430, 434, 313, 314, 17, 306, 307, 375, 387, 388, 260, 286, 414, 398, 335, 406, 418, 364, 367, 416, 423, 358, 327, 251, 284, 298, 281, 5, 4, 373, 374, 253, 307, 320, 321, 425, 427, 411, 421, 313, 18, 321, 405, 406, 320, 404, 405, 315, 16, 17, 426, 425, 266, 377, 400, 369, 322, 391, 269, 417, 465, 464, 386, 257, 258, 466, 260, 388, 456, 399, 419, 284, 332, 333, 417, 285, 8, 346, 340, 261, 413, 441, 285, 327, 460, 328, 355, 371, 329, 392, 439, 438, 382, 341, 256, 429, 420, 360, 364, 394, 379, 277, 343, 437, 443, 444, 283, 275, 440, 363, 431, 262, 369, 297, 338, 337, 273, 375, 321, 450, 451, 349, 446, 342, 467, 293, 334, 282, 458, 461, 462, 276, 353, 383, 308, 324, 325, 276, 300, 293, 372, 345, 447, 382, 398, 362, 352, 345, 340, 274, 1, 19, 456, 248, 281, 436, 427, 425, 381, 256, 252, 269, 391, 393, 200, 199, 428, 266, 330, 329, 287, 273, 422, 250, 462, 328, 258, 286, 384, 265, 353, 342, 387, 259, 257, 424, 431, 430, 342, 353, 276, 273, 335, 424, 292, 325, 307, 366, 447, 345, 271, 303, 302, 423, 266, 371, 294, 455, 460, 279, 278, 294, 271, 272, 304, 432, 434, 427, 272, 407, 408, 394, 430, 431, 395, 369, 400, 334, 333, 299, 351, 417, 168, 352, 280, 411, 325, 319, 320, 295, 296, 336, 319, 403, 404, 330, 348, 349, 293, 298, 333, 323, 454, 447, 15, 16, 315, 358, 429, 279, 14, 15, 316, 285, 336, 9, 329, 349, 350, 374, 380, 252, 318, 402, 403, 6, 197, 419, 318, 319, 325, 367, 364, 365, 435, 367, 397, 344, 438, 439, 272, 271, 311, 195, 5, 281, 273, 287, 291, 396, 428, 199, 311, 271, 268, 283, 444, 445, 373, 254, 339, 263, 466, 249, 282, 334, 296, 449, 347, 346, 264, 447, 454, 336, 296, 299, 338, 10, 151, 278, 439, 455, 292, 407, 415, 358, 371, 355, 340, 345, 372, 390, 249, 466, 346, 347, 280, 442, 443, 282, 19, 94, 370, 441, 442, 295, 248, 419, 197, 263, 255, 359, 440, 275, 274, 300, 383, 368, 351, 412, 465, 263, 467, 466, 301, 368, 389, 380, 374, 386, 395, 378, 379, 412, 351, 419, 436, 426, 322, 373, 390, 388, 2, 164, 393, 370, 462, 461, 164, 0, 267, 302, 11, 12, 374, 373, 387, 268, 12, 13, 293, 300, 301, 446, 261, 340, 385, 384, 381, 330, 266, 425, 426, 423, 391, 429, 355, 437, 391, 327, 326, 440, 457, 438, 341, 382, 362, 459, 457, 461, 434, 430, 394, 414, 463, 362, 396, 369, 262, 354, 461, 457, 316, 403, 402, 315, 404, 403, 314, 405, 404, 313, 406, 405, 421, 418, 406, 366, 401, 361, 306, 408, 407, 291, 409, 408, 287, 410, 409, 432, 436, 410, 434, 416, 411, 264, 368, 383, 309, 438, 457, 352, 376, 401, 274, 275, 4, 421, 428, 262, 294, 327, 358, 433, 416, 367, 289, 455, 439, 462, 370, 326, 2, 326, 370, 305, 460, 455, 254, 449, 448, 255, 261, 446, 253, 450, 449, 252, 451, 450, 256, 452, 451, 341, 453, 452, 413, 464, 463, 441, 413, 414, 258, 442, 441, 257, 443, 442, 259, 444, 443, 260, 445, 444, 467, 342, 445, 459, 458, 250, 289, 392, 290, 290, 328, 460, 376, 433, 435, 250, 290, 392, 411, 416, 433, 341, 463, 464, 453, 464, 465, 357, 465, 412, 343, 412, 399, 360, 363, 440, 437, 399, 456, 420, 456, 363, 401, 435, 288, 372, 383, 353, 339, 255, 249, 448, 261, 255, 133, 243, 190, 133, 155, 112, 33, 246, 247, 33, 130, 25, 398, 384, 286, 362, 398, 414, 362, 463, 341, 263, 359, 467, 263, 249, 255, 466, 467, 260, 75, 60, 166, 238, 239, 79, 162, 127, 139, 72, 11, 37, 121, 232, 120, 73, 72, 39, 114, 128, 47, 233, 232, 128, 103, 104, 67, 152, 175, 148, 173, 157, 155, 119, 118, 101, 74, 73, 40, 107, 9, 108, 49, 48, 131, 32, 194, 211, 184, 74, 185, 191, 80, 183, 185, 40, 186, 119, 230, 118, 210, 202, 214, 84, 83, 17, 77, 76, 146, 161, 160, 30, 190, 56, 173, 182, 106, 194, 138, 135, 192, 129, 203, 98, 54, 21, 68, 5, 51, 4, 145, 144, 23, 90, 77, 91, 207, 205, 187, 83, 201, 18, 181, 91, 182, 180, 90, 181, 16, 85, 17, 205, 206, 36, 176, 148, 140, 165, 92, 39, 245, 193, 244, 27, 159, 28, 30, 247, 161, 174, 236, 196, 103, 54, 104, 55, 193, 8, 111, 117, 31, 221, 189, 55, 240, 98, 99, 142, 126, 100, 219, 166, 218, 112, 155, 26, 198, 209, 131, 169, 135, 150, 114, 47, 217, 224, 223, 53, 220, 45, 134, 32, 211, 140, 109, 67, 108, 146, 43, 91, 231, 230, 120, 113, 226, 247, 105, 63, 52, 241, 238, 242, 124, 46, 156, 95, 78, 96, 70, 46, 63, 116, 143, 227, 116, 123, 111, 1, 44, 19, 3, 236, 51, 207, 216, 205, 26, 154, 22, 165, 39, 167, 199, 200, 208, 101, 36, 100, 43, 57, 202, 242, 20, 99, 56, 28, 157, 124, 35, 113, 29, 160, 27, 211, 204, 210, 124, 113, 46, 106, 43, 204, 96, 62, 77, 227, 137, 116, 73, 41, 72, 36, 203, 142, 235, 64, 240, 48, 49, 64, 42, 41, 74, 214, 212, 207, 183, 42, 184, 210, 169, 211, 140, 170, 176, 104, 105, 69, 193, 122, 168, 50, 123, 187, 89, 96, 90, 66, 65, 107, 179, 89, 180, 119, 101, 120, 68, 63, 104, 234, 93, 227, 16, 15, 85, 209, 129, 49, 15, 14, 86, 107, 55, 9, 120, 100, 121, 153, 145, 22, 178, 88, 179, 197, 6, 196, 89, 88, 96, 135, 138, 136, 138, 215, 172, 218, 115, 219, 41, 42, 81, 5, 195, 51, 57, 43, 61, 208, 171, 199, 41, 81, 38, 224, 53, 225, 24, 144, 110, 105, 52, 66, 118, 229, 117, 227, 34, 234, 66, 107, 69, 10, 109, 151, 219, 48, 235, 183, 62, 191, 142, 129, 126, 116, 111, 143, 7, 163, 246, 118, 117, 50, 223, 222, 52, 94, 19, 141, 222, 221, 65, 196, 3, 197, 45, 220, 44, 156, 70, 139, 188, 122, 245, 139, 71, 162, 145, 153, 159, 149, 170, 150, 122, 188, 196, 206, 216, 92, 163, 144, 161, 164, 2, 167, 242, 141, 241, 0, 164, 37, 11, 72, 12, 144, 145, 160, 12, 38, 13, 70, 63, 71, 31, 226, 111, 157, 158, 154, 36, 101, 205, 203, 206, 165, 126, 209, 217, 98, 165, 97, 237, 220, 218, 237, 239, 241, 210, 214, 169, 140, 171, 32, 241, 125, 237, 179, 86, 178, 180, 85, 179, 181, 84, 180, 182, 83, 181, 194, 201, 182, 177, 137, 132, 184, 76, 183, 185, 61, 184, 186, 57, 185, 216, 212, 186, 192, 214, 187, 139, 34, 156, 218, 79, 237, 147, 123, 177, 45, 44, 4, 208, 201, 32, 98, 64, 129, 192, 213, 138, 235, 59, 219, 141, 242, 97, 97, 2, 141, 240, 75, 235, 229, 24, 228, 31, 25, 226, 230, 23, 229, 231, 22, 230, 232, 26, 231, 233, 112, 232, 244, 189, 243, 189, 221, 190, 222, 28, 221, 223, 27, 222, 224, 29, 223, 225, 30, 224, 113, 247, 225, 99, 60, 240, 213, 147, 215, 60, 20, 166, 192, 187, 213, 243, 112, 244, 244, 233, 245, 245, 128, 188, 188, 114, 174, 134, 131, 220, 174, 217, 236, 236, 198, 134, 215, 177, 58, 156, 143, 124, 25, 110, 7, 31, 228, 25, 264, 356, 368, 0, 11, 267, 451, 452, 349, 267, 302, 269, 350, 357, 277, 350, 452, 357, 299, 333, 297, 396, 175, 377, 381, 384, 382, 280, 347, 330, 269, 303, 270, 151, 9, 337, 344, 278, 360, 424, 418, 431, 270, 304, 409, 272, 310, 407, 322, 270, 410, 449, 450, 347, 432, 422, 434, 18, 313, 17, 291, 306, 375, 259, 387, 260, 424, 335, 418, 434, 364, 416, 391, 423, 327, 301, 251, 298, 275, 281, 4, 254, 373, 253, 375, 307, 321, 280, 425, 411, 200, 421, 18, 335, 321, 406, 321, 320, 405, 314, 315, 17, 423, 426, 266, 396, 377, 369, 270, 322, 269, 413, 417, 464, 385, 386, 258, 248, 456, 419, 298, 284, 333, 168, 417, 8, 448, 346, 261, 417, 413, 285, 326, 327, 328, 277, 355, 329, 309, 392, 438, 381, 382, 256, 279, 429, 360, 365, 364, 379, 355, 277, 437, 282, 443, 283, 281, 275, 363, 395, 431, 369, 299, 297, 337, 335, 273, 321, 348, 450, 349, 359, 446, 467, 283, 293, 282, 250, 458, 462, 300, 276, 383, 292, 308, 325, 283, 276, 293, 264, 372, 447, 346, 352, 340, 354, 274, 19, 363, 456, 281, 426, 436, 425, 380, 381, 252, 267, 269, 393, 421, 200, 428, 371, 266, 329, 432, 287, 422, 290, 250, 328, 385, 258, 384, 446, 265, 342, 386, 387, 257, 422, 424, 430, 445, 342, 276, 422, 273, 424, 306, 292, 307, 352, 366, 345, 268, 271, 302, 358, 423, 371, 327, 294, 460, 331, 279, 294, 303, 271, 304, 436, 432, 427, 304, 272, 408, 395, 394, 431, 378, 395, 400, 296, 334, 299, 6, 351, 168, 376, 352, 411, 307, 325, 320, 285, 295, 336, 320, 319, 404, 329, 330, 349, 334, 293, 333, 366, 323, 447, 316, 15, 315, 331, 358, 279, 317, 14, 316, 8, 285, 9, 277, 329, 350, 253, 374, 252, 319, 318, 403, 351, 6, 419, 324, 318, 325, 397, 367, 365, 288, 435, 397, 278, 344, 439, 310, 272, 311, 248, 195, 281, 375, 273, 291, 175, 396, 199, 312, 311, 268, 276, 283, 445, 390, 373, 339, 295, 282, 296, 448, 449, 346, 356, 264, 454, 337, 336, 299, 337, 338, 151, 294, 278, 455, 308, 292, 415, 429, 358, 355, 265, 340, 372, 388, 390, 466, 352, 346, 280, 295, 442, 282, 354, 19, 370, 285, 441, 295, 195, 248, 197, 457, 440, 274, 301, 300, 368, 417, 351, 465, 251, 301, 389, 385, 380, 386, 394, 395, 379, 399, 412, 419, 410, 436, 322, 387, 373, 388, 326, 2, 393, 354, 370, 461, 393, 164, 267, 268, 302, 12, 386, 374, 387, 312, 268, 13, 298, 293, 301, 265, 446, 340, 380, 385, 381, 280, 330, 425, 322, 426, 391, 420, 429, 437, 393, 391, 326, 344, 440, 438, 458, 459, 461, 364, 434, 394, 428, 396, 262, 274, 354, 457, 317, 316, 402, 316, 315, 403, 315, 314, 404, 314, 313, 405, 313, 421, 406, 323, 366, 361, 292, 306, 407, 306, 291, 408, 291, 287, 409, 287, 432, 410, 427, 434, 411, 372, 264, 383, 459, 309, 457, 366, 352, 401, 1, 274, 4, 418, 421, 262, 331, 294, 358, 435, 433, 367, 392, 289, 439, 328, 462, 326, 94, 2, 370, 289, 305, 455, 339, 254, 448, 359, 255, 446, 254, 253, 449, 253, 252, 450, 252, 256, 451, 256, 341, 452, 414, 413, 463, 286, 441, 414, 286, 258, 441, 258, 257, 442, 257, 259, 443, 259, 260, 444, 260, 467, 445, 309, 459, 250, 305, 289, 290, 305, 290, 460, 401, 376, 435, 309, 250, 392, 376, 411, 433, 453, 341, 464, 357, 453, 465, 343, 357, 412, 437, 343, 399, 344, 360, 440, 420, 437, 456, 360, 420, 363, 361, 401, 288, 265, 372, 353, 390, 339, 249, 339, 448, 255];
});
var K2 = we((ds) => {
const bp = zt(), xH = D2(), q2 = dp(), LH = M2(), SH = V2(), IH = G2().default;
class Y2 {
constructor(n, t, e, r) {
this.pipeline = new LH.Pipeline(n, t, e, r), r && (this.config = r);
}
async estimateFaces(n, t) {
t && (this.config = t);
const e = await this.pipeline.predict(n, t), r = [];
for (const i of e || []) {
if (i.isDisposedInternal)
continue;
const a = i.confidence.arraySync();
if (a >= this.config.detector.minConfidence) {
const s = i.coords ? i.coords.arraySync() : null, o = {};
if (s && s.length > 0)
for (const c in q2.MESH_ANNOTATIONS)
(this.config.iris.enabled || c.includes("Iris") === false) && (o[c] = q2.MESH_ANNOTATIONS[c].map((l) => s[l]));
r.push({confidence: a || 0, box: i.box ? [i.box.startPoint[0], i.box.startPoint[1], i.box.endPoint[0] - i.box.startPoint[0], i.box.endPoint[1] - i.box.startPoint[1]] : 0, mesh: s, annotations: o, image: i.image ? bp.clone(i.image) : null});
}
i.confidence && i.confidence.dispose(), i.coords && i.coords.dispose(), i.image && i.image.dispose();
}
return r;
}
}
async function AH(n) {
const t = await Promise.all([xH.load(n), bp.loadGraphModel(n.mesh.modelPath, {fromTFHub: n.mesh.modelPath.includes("tfhub.dev")}), bp.loadGraphModel(n.iris.modelPath, {fromTFHub: n.iris.modelPath.includes("tfhub.dev")})]), e = new Y2(t[0], t[1], t[2], n);
return e;
}
ds.load = AH;
ds.MediaPipeFaceMesh = Y2;
ds.uv_coords = SH;
ds.triangulation = IH;
});
var tc = we((xp) => {
const j2 = {};
function TH(n, t) {
if (!t || !t.kernels)
return;
const e = 5, r = t.kernels.filter((o) => o.kernelTimeMs > 0).reduce((o, c) => o += c.kernelTimeMs, 0), i = t.kernels.map((o, c) => (o.id = c, o)).filter((o) => o.kernelTimeMs > 0).sort((o, c) => c.kernelTimeMs - o.kernelTimeMs), a = t.kernels.map((o, c) => (o.id = c, o)).filter((o) => o.totalBytesSnapshot > 0).sort((o, c) => c.totalBytesSnapshot - o.totalBytesSnapshot);
i.length > e && (i.length = e), a.length > e && (a.length = e);
const s = {newBytes: t.newBytes, newTensors: t.newTensors, peakBytes: t.peakBytes, numKernelOps: t.kernels.length, timeKernelOps: r, slowestKernelOps: i, largestKernelOps: a};
j2[n] = s;
}
xp.run = TH;
xp.data = j2;
});
var J2 = we((nc) => {
const Mn = zt(), $2 = tc(), Hn = {};
let X2 = {age: 0, gender: ""}, Lp = Number.MAX_SAFE_INTEGER;
async function NH(n) {
return Hn.age || (Hn.age = await Mn.loadGraphModel(n.face.age.modelPath)), Hn.age;
}
async function _H(n) {
return Hn.gender || (Hn.gender = await Mn.loadGraphModel(n.face.gender.modelPath)), Hn.gender;
}
async function CH(n, t) {
if (Lp < t.face.age.skipFrames)
return Lp += 1, X2;
Lp = 0;
const e = Mn.image.resizeBilinear(n, [t.face.age.inputSize, t.face.age.inputSize], false), r = Mn.mul(e, [255]);
Mn.dispose(e);
const i = [];
let a, s;
const o = {};
if (!t.profile || t.async)
t.face.age.enabled && i.push(a = Hn.age.predict(r)), t.face.gender.enabled && i.push(s = Hn.gender.predict(r)), await Promise.all(i);
else {
const c = t.face.age.enabled ? await Mn.profile(() => Hn.age.predict(r)) : {};
a = c.result.clone(), c.result.dispose(), $2.run("age", c);
const l = t.face.gender.enabled ? await Mn.profile(() => Hn.gender.predict(r)) : {};
s = l.result.clone(), l.result.dispose(), $2.run("gender", l);
}
if (a) {
const c = a.dataSync();
o.age = Math.trunc(10 * c[0]) / 10, Mn.dispose(a);
}
if (s) {
const c = s.dataSync(), l = Math.trunc(Math.abs(1.9 * 100 * (c[0] - 0.5))) / 100;
l > t.face.gender.minConfidence && (o.gender = c[0] <= 0.5 ? "female" : "male", o.confidence = l), Mn.dispose(s);
}
return Mn.dispose(r), X2 = o, o;
}
nc.predict = CH;
nc.loadAge = NH;
nc.loadGender = _H;
});
var ex = we((Sp) => {
const Vn = zt(), RH = tc(), OH = ["angry", "discust", "fear", "happy", "sad", "surpise", "neutral"], ps = {};
let Z2 = [], Ip = Number.MAX_SAFE_INTEGER;
const Q2 = 1.5;
async function EH(n) {
return ps.emotion || (ps.emotion = await Vn.loadGraphModel(n.face.emotion.modelPath)), ps.emotion;
}
async function DH(n, t) {
if (Ip < t.face.emotion.skipFrames)
return Ip += 1, Z2;
Ip = 0;
const e = Vn.image.resizeBilinear(n, [t.face.emotion.inputSize, t.face.emotion.inputSize], false), [r, i, a] = Vn.split(e, 3, 3);
e.dispose();
const s = Vn.mul(r, [0.2989]), o = Vn.mul(i, [0.587]), c = Vn.mul(a, [0.114]);
r.dispose(), i.dispose(), a.dispose();
const l = Vn.addN([s, o, c]);
s.dispose(), o.dispose(), c.dispose();
const u = [];
if (t.face.emotion.enabled) {
let h;
if (t.profile) {
const d = await Vn.profile(() => ps.emotion.predict(l));
h = d.result.dataSync(), d.result.dispose(), RH.run("emotion", d);
} else {
const d = await ps.emotion.predict(l);
h = d.dataSync(), Vn.dispose(d);
}
for (let d = 0; d < h.length; d++)
Q2 * h[d] > t.face.emotion.minConfidence && u.push({score: Math.min(0.99, Math.trunc(100 * Q2 * h[d]) / 100), emotion: OH[d]});
u.sort((d, p) => p.score - d.score);
}
return Vn.dispose(l), Z2 = u, u;
}
Sp.predict = DH;
Sp.load = EH;
});
var nx = we((tx) => {
const kH = zt();
class FH {
constructor(n, t) {
this.model = n, this.outputStride = t;
}
predict(n) {
return kH.tidy(() => {
const t = this.preprocessInput(n.toFloat()), e = t.expandDims(0), r = this.model.predict(e), i = r.map((s) => s.squeeze([0])), a = this.nameOutputResults(i);
return {heatmapScores: a.heatmap.sigmoid(), offsets: a.offsets, displacementFwd: a.displacementFwd, displacementBwd: a.displacementBwd};
});
}
dispose() {
this.model.dispose();
}
}
tx.BaseModel = FH;
});
var Ap = we((rx) => {
const ix = zt(), WH = nx();
class UH extends WH.BaseModel {
preprocessInput(n) {
return ix.tidy(() => ix.div(n, 127.5).sub(1));
}
nameOutputResults(n) {
const [t, e, r, i] = n;
return {offsets: t, heatmap: e, displacementFwd: r, displacementBwd: i};
}
}
rx.MobileNet = UH;
});
var sx = we((ax) => {
function Tp(n) {
return Math.floor(n / 2);
}
class BH {
constructor(n, t) {
this.priorityQueue = new Array(n), this.numberOfElements = -1, this.getElementValue = t;
}
enqueue(n) {
this.priorityQueue[++this.numberOfElements] = n, this.swim(this.numberOfElements);
}
dequeue() {
const n = this.priorityQueue[0];
return this.exchange(0, this.numberOfElements--), this.sink(0), this.priorityQueue[this.numberOfElements + 1] = null, n;
}
empty() {
return this.numberOfElements === -1;
}
size() {
return this.numberOfElements + 1;
}
all() {
return this.priorityQueue.slice(0, this.numberOfElements + 1);
}
max() {
return this.priorityQueue[0];
}
swim(n) {
for (; n > 0 && this.less(Tp(n), n); )
this.exchange(n, Tp(n)), n = Tp(n);
}
sink(n) {
for (; 2 * n <= this.numberOfElements; ) {
let t = 2 * n;
if (t < this.numberOfElements && this.less(t, t + 1) && t++, !this.less(n, t))
break;
this.exchange(n, t), n = t;
}
}
getValueAt(n) {
return this.getElementValue(this.priorityQueue[n]);
}
less(n, t) {
return this.getValueAt(n) < this.getValueAt(t);
}
exchange(n, t) {
const e = this.priorityQueue[n];
this.priorityQueue[n] = this.priorityQueue[t], this.priorityQueue[t] = e;
}
}
ax.MaxHeap = BH;
});
var cx = we((ox) => {
const zH = sx();
function PH(n, t, e, r, i, a) {
const [s, o] = a.shape;
let c = true;
const l = Math.max(e - i, 0), u = Math.min(e + i + 1, s);
for (let h = l; h < u; ++h) {
const d = Math.max(r - i, 0), p = Math.min(r + i + 1, o);
for (let f = d; f < p; ++f)
if (a.get(h, f, n) > t) {
c = false;
break;
}
if (!c)
break;
}
return c;
}
function MH(n, t, e) {
const [r, i, a] = e.shape, s = new zH.MaxHeap(r * i * a, ({score: o}) => o);
for (let o = 0; o < r; ++o)
for (let c = 0; c < i; ++c)
for (let l = 0; l < a; ++l) {
const u = e.get(o, c, l);
if (u < n)
continue;
PH(l, u, o, c, t, e) && s.enqueue({score: u, part: {heatmapY: o, heatmapX: c, id: l}});
}
return s;
}
ox.buildPartWithScoreQueue = MH;
});
var fs = we((Nn) => {
Nn.partNames = ["nose", "leftEye", "rightEye", "leftEar", "rightEar", "leftShoulder", "rightShoulder", "leftElbow", "rightElbow", "leftWrist", "rightWrist", "leftHip", "rightHip", "leftKnee", "rightKnee", "leftAnkle", "rightAnkle"];
Nn.NUM_KEYPOINTS = Nn.partNames.length;
Nn.partIds = Nn.partNames.reduce((n, t, e) => (n[t] = e, n), {});
const HH = [["leftHip", "leftShoulder"], ["leftElbow", "leftShoulder"], ["leftElbow", "leftWrist"], ["leftHip", "leftKnee"], ["leftKnee", "leftAnkle"], ["rightHip", "rightShoulder"], ["rightElbow", "rightShoulder"], ["rightElbow", "rightWrist"], ["rightHip", "rightKnee"], ["rightKnee", "rightAnkle"], ["leftShoulder", "rightShoulder"], ["leftHip", "rightHip"]];
Nn.poseChain = [["nose", "leftEye"], ["leftEye", "leftEar"], ["nose", "rightEye"], ["rightEye", "rightEar"], ["nose", "leftShoulder"], ["leftShoulder", "leftElbow"], ["leftElbow", "leftWrist"], ["leftShoulder", "leftHip"], ["leftHip", "leftKnee"], ["leftKnee", "leftAnkle"], ["nose", "rightShoulder"], ["rightShoulder", "rightElbow"], ["rightElbow", "rightWrist"], ["rightShoulder", "rightHip"], ["rightHip", "rightKnee"], ["rightKnee", "rightAnkle"]];
Nn.connectedPartIndices = HH.map(([n, t]) => [Nn.partIds[n], Nn.partIds[t]]);
Nn.partChannels = ["left_face", "right_face", "right_upper_leg_front", "right_lower_leg_back", "right_upper_leg_back", "left_lower_leg_front", "left_upper_leg_front", "left_upper_leg_back", "left_lower_leg_back", "right_feet", "right_lower_leg_front", "left_feet", "torso_front", "torso_back", "right_upper_arm_front", "right_upper_arm_back", "right_lower_arm_back", "left_lower_arm_front", "left_upper_arm_front", "left_upper_arm_back", "left_lower_arm_back", "right_hand", "right_lower_arm_front", "left_hand"];
});
var _p = we((Fr) => {
const VH = fs();
function lx(n, t, e, r) {
return {y: r.get(n, t, e), x: r.get(n, t, e + VH.NUM_KEYPOINTS)};
}
Fr.getOffsetPoint = lx;
function GH(n, t, e) {
const {heatmapY: r, heatmapX: i, id: a} = n, {y: s, x: o} = lx(r, i, a, e);
return {x: n.heatmapX * t + o, y: n.heatmapY * t + s};
}
Fr.getImageCoords = GH;
function qH(n, t) {
const e = new Array(t);
for (let r = 0; r < t; r++)
e[r] = n;
return e;
}
Fr.fillArray = qH;
function Np(n, t, e) {
return n < t ? t : n > e ? e : n;
}
Fr.clamp = Np;
function YH(n, t, e, r) {
const i = e - n, a = r - t;
return i * i + a * a;
}
Fr.squaredDistance = YH;
function KH(n, t) {
return {x: n.x + t.x, y: n.y + t.y};
}
Fr.addVectors = KH;
function jH(n, t, e) {
return {y: Np(n.y, t, e), x: Np(n.x, t, e)};
}
Fr.clampVector = jH;
});
var fx = we((ux) => {
const ms = fs(), pa = _p(), hx = ms.poseChain.map(([n, t]) => [ms.partIds[n], ms.partIds[t]]), Cp = hx.map(([, n]) => n), dx = hx.map(([n]) => n);
function $H(n, t, e) {
const r = e.shape[2] / 2;
return {y: e.get(t.y, t.x, n), x: e.get(t.y, t.x, r + n)};
}
function Rp(n, t, e, r) {
return {y: pa.clamp(Math.round(n.y / t), 0, e - 1), x: pa.clamp(Math.round(n.x / t), 0, r - 1)};
}
function px(n, t, e, r, i, a, s, o = 2) {
const [c, l] = r.shape, u = Rp(t.position, a, c, l), h = $H(n, u, s), d = pa.addVectors(t.position, h);
let p = d;
for (let g = 0; g < o; g++) {
const y = Rp(p, a, c, l), w = pa.getOffsetPoint(y.y, y.x, e, i);
p = pa.addVectors({x: y.x * a, y: y.y * a}, {x: w.x, y: w.y});
}
const f = Rp(p, a, c, l), m = r.get(f.y, f.x, e);
return {position: p, part: ms.partNames[e], score: m};
}
function XH(n, t, e, r, i, a) {
const s = t.shape[2], o = Cp.length, c = new Array(s), {part: l, score: u} = n, h = pa.getImageCoords(l, r, e);
c[l.id] = {score: u, part: ms.partNames[l.id], position: h};
for (let d = o - 1; d >= 0; --d) {
const p = Cp[d], f = dx[d];
c[p] && !c[f] && (c[f] = px(d, c[p], f, t, e, r, a));
}
for (let d = 0; d < o; ++d) {
const p = dx[d], f = Cp[d];
c[p] && !c[f] && (c[f] = px(d, c[p], f, t, e, r, i));
}
return c;
}
ux.decodePose = XH;
});
var Op = we((mx) => {
const JH = cx(), ZH = fx(), gx = _p();
function yx(n, t, {x: e, y: r}, i) {
return n.some(({keypoints: a}) => {
const s = a[i].position;
return gx.squaredDistance(r, e, s.y, s.x) <= t;
});
}
function QH(n, t, e) {
const r = e.reduce((i, {position: a, score: s}, o) => (yx(n, t, a, o) || (i += s), i), 0);
return r / e.length;
}
const eV = 1;
function tV(n, t, e, r, i, a, s = 0.5, o = 20) {
const c = [], l = JH.buildPartWithScoreQueue(s, eV, n), u = o * o;
for (; c.length < a && !l.empty(); ) {
const h = l.dequeue(), d = gx.getImageCoords(h.part, i, t);
if (yx(c, u, d, h.part.id))
continue;
const p = ZH.decodePose(h, n, t, i, e, r), f = QH(c, u, p);
c.push({keypoints: p, score: f});
}
return c;
}
mx.decodeMultiplePoses = tV;
});
var Ep = we((Wr) => {
const nV = fs();
function rV(n, t, e) {
return n < e || t < e;
}
function iV(n, t) {
return nV.connectedPartIndices.reduce((e, [r, i]) => (rV(n[r].score, n[i].score, t) || e.push([n[r], n[i]]), e), []);
}
Wr.getAdjacentKeyPoints = iV;
const {NEGATIVE_INFINITY: vx, POSITIVE_INFINITY: wx} = Number;
function bx(n) {
return n.reduce(({maxX: t, maxY: e, minX: r, minY: i}, {position: {x: a, y: s}}) => ({maxX: Math.max(t, a), maxY: Math.max(e, s), minX: Math.min(r, a), minY: Math.min(i, s)}), {maxX: vx, maxY: vx, minX: wx, minY: wx});
}
Wr.getBoundingBox = bx;
function aV(n) {
const {minX: t, minY: e, maxX: r, maxY: i} = bx(n);
return [{x: t, y: e}, {x: r, y: e}, {x: r, y: i}, {x: t, y: i}];
}
Wr.getBoundingBoxPoints = aV;
async function sV(n) {
return Promise.all(n.map((t) => t.buffer()));
}
Wr.toTensorBuffers3D = sV;
function xx(n, t, e) {
return {score: n.score, keypoints: n.keypoints.map(({score: r, part: i, position: a}) => ({score: r, part: i, position: {x: a.x * e, y: a.y * t}}))};
}
Wr.scalePose = xx;
function oV(n, [t, e]) {
const r = n.squeeze(0), i = r.resizeBilinear([t, e]);
return r.dispose(), i;
}
Wr.resizeTo = oV;
function cV(n, [t, e], [r, i]) {
const a = n.map((s) => xx(s, t / r, e / i));
return a;
}
Wr.scaleAndFlipPoses = cV;
});
var Sx = we((Dp) => {
const lV = zt(), uV = Ap(), hV = Op(), kp = Ep();
class Lx {
constructor(n) {
this.baseModel = n;
}
async estimatePoses(n, t) {
const e = t.outputStride, r = n.shape[1], i = n.shape[2], a = kp.resizeTo(n, [t.inputResolution, t.inputResolution]), {heatmapScores: s, offsets: o, displacementFwd: c, displacementBwd: l} = this.baseModel.predict(a), u = await kp.toTensorBuffers3D([s, o, c, l]), h = u[0], d = u[1], p = u[2], f = u[3], m = await hV.decodeMultiplePoses(h, d, p, f, e, t.maxDetections, t.scoreThreshold, t.nmsRadius), g = kp.scaleAndFlipPoses(m, [r, i], [t.inputResolution, t.inputResolution]);
return s.dispose(), o.dispose(), c.dispose(), l.dispose(), a.dispose(), g;
}
dispose() {
this.baseModel.dispose();
}
}
Dp.PoseNet = Lx;
async function dV(n) {
const t = await lV.loadGraphModel(n.modelPath), e = new uV.MobileNet(t, n.outputStride);
return new Lx(e);
}
async function pV(n) {
return dV(n);
}
Dp.load = pV;
});
var Ax = we((nn) => {
const fV = Ap(), Ix = Sx(), mV = Op(), rc = fs(), gs = Ep();
nn.load = Ix.load;
nn.PoseNet = Ix.PoseNet;
nn.MobileNet = fV.MobileNet;
nn.decodeMultiplePoses = mV.decodeMultiplePoses;
nn.partChannels = rc.partChannels;
nn.partIds = rc.partIds;
nn.partNames = rc.partNames;
nn.poseChain = rc.poseChain;
nn.getAdjacentKeyPoints = gs.getAdjacentKeyPoints;
nn.getBoundingBox = gs.getBoundingBox;
nn.getBoundingBoxPoints = gs.getBoundingBoxPoints;
nn.scaleAndFlipPoses = gs.scaleAndFlipPoses;
nn.scalePose = gs.scalePose;
});
var Up = we((gV) => {
vs(gV, {cutBoxFromImageAndResize: () => vV, enlargeBox: () => bV, getBoxCenter: () => Wp, getBoxSize: () => Fp, scaleBoxCoordinates: () => wV, shiftBox: () => LV, squarifyBox: () => xV});
const yV = zt();
function Fp(n) {
return [Math.abs(n.endPoint[0] - n.startPoint[0]), Math.abs(n.endPoint[1] - n.startPoint[1])];
}
function Wp(n) {
return [n.startPoint[0] + (n.endPoint[0] - n.startPoint[0]) / 2, n.startPoint[1] + (n.endPoint[1] - n.startPoint[1]) / 2];
}
function vV(n, t, e) {
const r = t.shape[1], i = t.shape[2], a = [[n.startPoint[1] / r, n.startPoint[0] / i, n.endPoint[1] / r, n.endPoint[0] / i]];
return yV.image.cropAndResize(t, a, [0], e);
}
function wV(n, t) {
const e = [n.startPoint[0] * t[0], n.startPoint[1] * t[1]], r = [n.endPoint[0] * t[0], n.endPoint[1] * t[1]], i = n.palmLandmarks.map((a) => {
const s = [a[0] * t[0], a[1] * t[1]];
return s;
});
return {startPoint: e, endPoint: r, palmLandmarks: i};
}
function bV(n, t = 1.5) {
const e = Wp(n), r = Fp(n), i = [t * r[0] / 2, t * r[1] / 2], a = [e[0] - i[0], e[1] - i[1]], s = [e[0] + i[0], e[1] + i[1]];
return {startPoint: a, endPoint: s, palmLandmarks: n.palmLandmarks};
}
function xV(n) {
const t = Wp(n), e = Fp(n), r = Math.max(...e), i = r / 2, a = [t[0] - i, t[1] - i], s = [t[0] + i, t[1] + i];
return {startPoint: a, endPoint: s, palmLandmarks: n.palmLandmarks};
}
function LV(n, t) {
const e = [n.endPoint[0] - n.startPoint[0], n.endPoint[1] - n.startPoint[1]], r = [e[0] * t[0], e[1] * t[1]], i = [n.startPoint[0] + r[0], n.startPoint[1] + r[1]], a = [n.endPoint[0] + r[0], n.endPoint[1] + r[1]];
return {startPoint: i, endPoint: a, palmLandmarks: n.palmLandmarks};
}
});
var Nx = we((Tx) => {
const et = zt(), SV = Up();
class IV {
constructor(n, t, e) {
this.model = n, this.anchors = e.map((r) => [r.x_center, r.y_center]), this.anchorsTensor = et.tensor2d(this.anchors), this.inputSizeTensor = et.tensor1d([t, t]), this.doubleInputSizeTensor = et.tensor1d([t * 2, t * 2]);
}
normalizeBoxes(n) {
return et.tidy(() => {
const t = et.slice(n, [0, 0], [-1, 2]), e = et.slice(n, [0, 2], [-1, 2]), r = et.add(et.div(t, this.inputSizeTensor), this.anchorsTensor), i = et.div(e, this.doubleInputSizeTensor), a = et.mul(et.sub(r, i), this.inputSizeTensor), s = et.mul(et.add(r, i), this.inputSizeTensor);
return et.concat2d([a, s], 1);
});
}
normalizeLandmarks(n, t) {
return et.tidy(() => {
const e = et.add(et.div(n.reshape([-1, 7, 2]), this.inputSizeTensor), this.anchors[t]);
return et.mul(e, this.inputSizeTensor);
});
}
async getBoundingBoxes(n, t) {
const e = this.model.predict(n), r = e.squeeze(), i = et.tidy(() => et.sigmoid(et.slice(r, [0, 0], [-1, 1])).squeeze()), a = et.slice(r, [0, 1], [-1, 4]), s = this.normalizeBoxes(a), o = et.image.nonMaxSuppression(s, i, t.maxHands, t.iouThreshold, 0.95), c = o.arraySync(), l = [e, o, r, s, a, i];
if (c.length === 0)
return l.forEach((h) => h.dispose()), null;
const u = [];
for (const h of c) {
const d = et.slice(s, [h, 0], [1, -1]), p = et.slice(r, [h, 5], [1, 14]), f = et.tidy(() => this.normalizeLandmarks(p, h).reshape([-1, 2]));
p.dispose(), u.push({boxes: d, palmLandmarks: f});
}
return l.forEach((h) => h.dispose()), u;
}
async estimateHandBounds(n, t) {
const e = n.shape[1], r = n.shape[2], i = et.tidy(() => n.resizeBilinear([t.inputSize, t.inputSize]).div(127.5).sub(1)), a = await this.getBoundingBoxes(i, t);
if (i.dispose(), !a || a.length === 0)
return null;
const s = [];
for (const o of a) {
const c = o.boxes.dataSync(), l = c.slice(0, 2), u = c.slice(2, 4), h = o.palmLandmarks.arraySync();
o.boxes.dispose(), o.palmLandmarks.dispose(), s.push(SV.scaleBoxCoordinates({startPoint: l, endPoint: u, palmLandmarks: h}, [r / t.inputSize, e / t.inputSize]));
}
return s;
}
}
Tx.HandDetector = IV;
});
var Ex = we((AV) => {
vs(AV, {buildRotationMatrix: () => NV, computeRotation: () => TV, dot: () => fa, getColumnFrom2DArr: () => Rx, invertTransformMatrix: () => _V, normalizeRadians: () => _x, rotatePoint: () => CV});
function _x(n) {
return n - 2 * Math.PI * Math.floor((n + Math.PI) / (2 * Math.PI));
}
function TV(n, t) {
const e = Math.PI / 2 - Math.atan2(-(t[1] - n[1]), t[0] - n[0]);
return _x(e);
}
const Cx = (n, t) => [[1, 0, n], [0, 1, t], [0, 0, 1]];
function fa(n, t) {
let e = 0;
for (let r = 0; r < n.length; r++)
e += n[r] * t[r];
return e;
}
function Rx(n, t) {
const e = [];
for (let r = 0; r < n.length; r++)
e.push(n[r][t]);
return e;
}
function Ox(n, t) {
const e = [], r = n.length;
for (let i = 0; i < r; i++) {
e.push([]);
for (let a = 0; a < r; a++)
e[i].push(fa(n[i], Rx(t, a)));
}
return e;
}
function NV(n, t) {
const e = Math.cos(n), r = Math.sin(n), i = [[e, -r, 0], [r, e, 0], [0, 0, 1]], a = Cx(t[0], t[1]), s = Ox(a, i), o = Cx(-t[0], -t[1]);
return Ox(s, o);
}
function _V(n) {
const t = [[n[0][0], n[1][0]], [n[0][1], n[1][1]]], e = [n[0][2], n[1][2]], r = [-fa(t[0], e), -fa(t[1], e)];
return [t[0].concat(r[0]), t[1].concat(r[1]), [0, 0, 1]];
}
function CV(n, t) {
return [fa(n, t[0]), fa(n, t[1])];
}
});
var Wx = we((Dx) => {
const kx = zt(), Gn = Up(), Ur = Ex(), RV = 0.8, OV = [0, -0.4], EV = 3, DV = [0, -0.1], kV = 1.65, Fx = [0, 5, 9, 13, 17, 1, 2], FV = 0, WV = 2;
class UV {
constructor(n, t, e) {
this.boundingBoxDetector = n, this.meshDetector = t, this.inputSize = e, this.regionsOfInterest = [], this.runsWithoutHandDetector = 0, this.skipFrames = 0, this.detectedHands = 0;
}
getBoxForPalmLandmarks(n, t) {
const e = n.map((i) => {
const a = [...i, 1];
return Ur.rotatePoint(a, t);
}), r = this.calculateLandmarksBoundingBox(e);
return Gn.enlargeBox(Gn.squarifyBox(Gn.shiftBox(r, OV)), EV);
}
getBoxForHandLandmarks(n) {
const t = this.calculateLandmarksBoundingBox(n), e = Gn.enlargeBox(Gn.squarifyBox(Gn.shiftBox(t, DV)), kV), r = [];
for (let i = 0; i < Fx.length; i++)
r.push(n[Fx[i]].slice(0, 2));
return e.palmLandmarks = r, e;
}
transformRawCoords(n, t, e, r) {
const i = Gn.getBoxSize(t), a = [i[0] / this.inputSize, i[1] / this.inputSize], s = n.map((d) => [a[0] * (d[0] - this.inputSize / 2), a[1] * (d[1] - this.inputSize / 2), d[2]]), o = Ur.buildRotationMatrix(e, [0, 0]), c = s.map((d) => {
const p = Ur.rotatePoint(d, o);
return [...p, d[2]];
}), l = Ur.invertTransformMatrix(r), u = [...Gn.getBoxCenter(t), 1], h = [Ur.dot(u, l[0]), Ur.dot(u, l[1])];
return c.map((d) => [d[0] + h[0], d[1] + h[1], d[2]]);
}
async estimateHands(n, t) {
this.skipFrames = t.skipFrames;
let e = this.detectedHands === 0 || this.detectedHands !== this.regionsOfInterest.length, r;
if ((e || this.runsWithoutHandDetector > this.skipFrames) && (r = await this.boundingBoxDetector.estimateHandBounds(n, t)), t.maxHands > 1 && r && r.length > 0 && r.length !== this.detectedHands && (e = true), e) {
if (this.regionsOfInterest = [], !r || r.length === 0)
return n.dispose(), this.detectedHands = 0, null;
for (const a of r)
this.regionsOfInterest.push(a);
this.runsWithoutHandDetector = 0;
} else
this.runsWithoutHandDetector++;
const i = [];
for (const a in this.regionsOfInterest) {
const s = this.regionsOfInterest[a];
if (!s)
continue;
const o = Ur.computeRotation(s.palmLandmarks[FV], s.palmLandmarks[WV]), c = Gn.getBoxCenter(s), l = [c[0] / n.shape[2], c[1] / n.shape[1]], u = kx.image.rotateWithOffset(n, o, 0, l), h = Ur.buildRotationMatrix(-o, c), d = e ? this.getBoxForPalmLandmarks(s.palmLandmarks, h) : s, p = Gn.cutBoxFromImageAndResize(d, u, [this.inputSize, this.inputSize]), f = p.div(255);
p.dispose(), u.dispose();
const m = this.meshDetector.predict(f), [g, y] = m;
f.dispose();
const w = g.dataSync()[0];
if (g.dispose(), w >= t.minConfidence) {
const b = kx.reshape(y, [-1, 3]), x = b.arraySync();
y.dispose(), b.dispose();
const L = this.transformRawCoords(x, d, o, h), N = this.getBoxForHandLandmarks(L);
this.updateRegionsOfInterest(N, a);
const I = {landmarks: L, handInViewConfidence: w, boundingBox: {topLeft: N.startPoint, bottomRight: N.endPoint}};
i.push(I);
}
y.dispose();
}
return this.detectedHands = i.length, i;
}
calculateLandmarksBoundingBox(n) {
const t = n.map((a) => a[0]), e = n.map((a) => a[1]), r = [Math.min(...t), Math.min(...e)], i = [Math.max(...t), Math.max(...e)];
return {startPoint: r, endPoint: i};
}
updateRegionsOfInterest(n, t) {
const e = this.regionsOfInterest[t];
let r = 0;
if (e != null && e.startPoint != null) {
const [i, a] = n.startPoint, [s, o] = n.endPoint, [c, l] = e.startPoint, [u, h] = e.endPoint, d = Math.max(i, c), p = Math.max(a, l), f = Math.min(s, u), m = Math.min(o, h), g = (f - d) * (m - p), y = (s - i) * (o - a), w = (u - c) * (h - a);
r = g / (y + w - g);
}
this.regionsOfInterest[t] = r > RV ? e : n;
}
}
Dx.HandPipeline = UV;
});
var Bx = we((Ux) => {
Ux.anchors = [{w: 1, h: 1, x_center: 0.015625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.015625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.046875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.078125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.109375}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.140625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.171875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.203125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.234375}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.265625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.296875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.328125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.359375}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.390625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.421875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.453125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.484375}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.515625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.546875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.578125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.609375}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.640625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.671875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.703125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.734375}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.765625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.796875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.828125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.859375}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.890625}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.921875}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.953125}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.015625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.046875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.078125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.109375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.140625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.171875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.203125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.234375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.265625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.296875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.328125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.359375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.390625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.421875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.453125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.484375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.515625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.546875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.578125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.609375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.640625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.671875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.703125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.734375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.765625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.796875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.828125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.859375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.890625, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.921875, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.953125, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.984375, y_center: 0.984375}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.03125}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.09375}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.15625}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.21875}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.28125}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.34375}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.40625}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.46875}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.53125}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.59375}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.65625}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.71875}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.78125}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.84375}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.90625}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.03125, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.09375, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.15625, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.21875, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.28125, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.34375, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.40625, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.46875, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.53125, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.59375, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.65625, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.71875, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.78125, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.84375, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.90625, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.96875, y_center: 0.96875}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.0625}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.1875}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.3125}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.4375}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.5625}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.6875}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.8125}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.0625, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.1875, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.3125, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.4375, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.5625, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.6875, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.8125, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.9375}, {w: 1, h: 1, x_center: 0.9375, y_center: 0.9375}];
});
var Mx = we((Bp) => {
const zx = zt(), BV = Nx(), zV = Wx(), PV = Bx(), zp = {thumb: [1, 2, 3, 4], indexFinger: [5, 6, 7, 8], middleFinger: [9, 10, 11, 12], ringFinger: [13, 14, 15, 16], pinky: [17, 18, 19, 20], palmBase: [0]};
class Px {
constructor(n) {
this.pipeline = n;
}
static getAnnotations() {
return zp;
}
async estimateHands(n, t) {
const e = await this.pipeline.estimateHands(n, t);
if (!e)
return [];
const r = [];
for (const i of e) {
const a = {};
if (i.landmarks)
for (const s of Object.keys(zp))
a[s] = zp[s].map((o) => i.landmarks[o]);
r.push({confidence: i.handInViewConfidence, box: i.boundingBox ? [i.boundingBox.topLeft[0], i.boundingBox.topLeft[1], i.boundingBox.bottomRight[0] - i.boundingBox.topLeft[0], i.boundingBox.bottomRight[1] - i.boundingBox.topLeft[1]] : 0, landmarks: i.landmarks, annotations: a});
}
return r;
}
}
Bp.HandPose = Px;
async function MV(n) {
const [t, e] = await Promise.all([zx.loadGraphModel(n.detector.modelPath, {fromTFHub: n.detector.modelPath.includes("tfhub.dev")}), zx.loadGraphModel(n.skeleton.modelPath, {fromTFHub: n.skeleton.modelPath.includes("tfhub.dev")})]), r = new BV.HandDetector(t, n.inputSize, PV.anchors), i = new zV.HandPipeline(r, e, n.inputSize), a = new Px(i);
return a;
}
Bp.load = MV;
});
var Hx = we((ic) => {
ic.body = (n) => {
if (!n)
return [];
const t = [];
for (const e of n) {
const r = e.keypoints.find((c) => c.part === "leftWrist"), i = e.keypoints.find((c) => c.part === "rightWrist"), a = e.keypoints.find((c) => c.part === "nose");
a && r && i && r.position.y < a.position.y && i.position.y < a.position.y ? t.push("i give up") : a && r && r.position.y < a.position.y ? t.push("raise left hand") : a && i && i.position.y < a.position.y && t.push("raise right hand");
const s = e.keypoints.find((c) => c.part === "leftShoulder"), o = e.keypoints.find((c) => c.part === "rightShoulder");
s && o && t.push(`leaning ${s.position.y > o.position.y ? "left" : "right"}`);
}
return t;
};
ic.face = (n) => {
if (!n)
return [];
const t = [];
for (const e of n)
e.annotations.rightCheek && e.annotations.leftCheek && e.annotations.rightCheek.length > 0 && e.annotations.leftCheek.length > 0 && t.push(`facing ${e.annotations.rightCheek[0][2] > 0 || e.annotations.leftCheek[0][2] < 0 ? "right" : "left"}`);
return t;
};
ic.hand = (n) => {
if (!n)
return [];
const t = [];
for (const e of n) {
const r = [];
for (const [i, a] of Object.entries(e.annotations))
i !== "palmBase" && r.push({name: i.toLowerCase(), position: a[0]});
if (r && r.length > 0) {
const i = r.reduce((s, o) => s.position[2] < o.position[2] ? s : o), a = r.reduce((s, o) => s.position[1] < o.position[1] ? s : o);
t.push(`${i.name} forward ${a.name} up`);
}
}
return t;
};
});
var Gx = we((Vx) => {
const HV = function(n, t, e) {
const r = function(o, c, l) {
const u = new RegExp("\\b" + c + " \\w+ (\\w+)", "ig");
o.replace(u, (h, d) => (l[d] = 0, h));
}, i = function(o, c) {
const l = n.createShader(c);
if (n.shaderSource(l, o), n.compileShader(l), !n.getShaderParameter(l, n.COMPILE_STATUS))
throw new Error("Filter: GL compile failed", n.getShaderInfoLog(l));
return l;
};
this.uniform = {}, this.attribute = {};
const a = i(t, n.VERTEX_SHADER), s = i(e, n.FRAGMENT_SHADER);
if (this.id = n.createProgram(), n.attachShader(this.id, a), n.attachShader(this.id, s), n.linkProgram(this.id), !n.getProgramParameter(this.id, n.LINK_STATUS))
throw new Error("Filter: GL link failed", n.getProgramInfoLog(this.id));
n.useProgram(this.id), r(t, "attribute", this.attribute);
for (const o in this.attribute)
this.attribute[o] = n.getAttribLocation(this.id, o);
r(t, "uniform", this.uniform), r(e, "uniform", this.uniform);
for (const o in this.uniform)
this.uniform[o] = n.getUniformLocation(this.id, o);
}, VV = function(n) {
n || (n = {});
let t = 0, e = null, r = false, i = -1, a = [null, null], s = [], o = -1, c = -1, l = null, u = null;
const h = n.canvas || document.createElement("canvas"), d = {}, p = h.getContext("webgl");
if (!p)
throw new Error("Filter: getContext() failed");
this.addFilter = function(N) {
const I = Array.prototype.slice.call(arguments, 1), C = L[N];
s.push({func: C, args: I});
}, this.reset = function() {
s = [];
}, this.apply = function(N) {
if (f(N.width, N.height), t = 0, e || (e = p.createTexture()), p.bindTexture(p.TEXTURE_2D, e), p.texParameteri(p.TEXTURE_2D, p.TEXTURE_WRAP_S, p.CLAMP_TO_EDGE), p.texParameteri(p.TEXTURE_2D, p.TEXTURE_WRAP_T, p.CLAMP_TO_EDGE), p.texParameteri(p.TEXTURE_2D, p.TEXTURE_MIN_FILTER, p.NEAREST), p.texParameteri(p.TEXTURE_2D, p.TEXTURE_MAG_FILTER, p.NEAREST), p.texImage2D(p.TEXTURE_2D, 0, p.RGBA, p.RGBA, p.UNSIGNED_BYTE, N), s.length === 0)
return y(), h;
for (let I = 0; I < s.length; I++) {
r = I === s.length - 1;
const C = s[I];
C.func.apply(this, C.args || []);
}
return h;
};
const f = function(N, I) {
if (N === o && I === c)
return;
if (h.width = N, o = N, h.height = I, c = I, !l) {
const C = new Float32Array([-1, -1, 0, 1, 1, -1, 1, 1, -1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 1, 1, 1, 1, 1, 0]);
l = p.createBuffer(), p.bindBuffer(p.ARRAY_BUFFER, l), p.bufferData(p.ARRAY_BUFFER, C, p.STATIC_DRAW), p.pixelStorei(p.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
}
p.viewport(0, 0, o, c), a = [null, null];
}, m = function(N) {
return a[N] = a[N] || g(o, c), a[N];
}, g = function(N, I) {
const C = p.createFramebuffer();
p.bindFramebuffer(p.FRAMEBUFFER, C);
const O = p.createRenderbuffer();
p.bindRenderbuffer(p.RENDERBUFFER, O);
const D = p.createTexture();
return p.bindTexture(p.TEXTURE_2D, D), p.texImage2D(p.TEXTURE_2D, 0, p.RGBA, N, I, 0, p.RGBA, p.UNSIGNED_BYTE, null), p.texParameteri(p.TEXTURE_2D, p.TEXTURE_MAG_FILTER, p.LINEAR), p.texParameteri(p.TEXTURE_2D, p.TEXTURE_MIN_FILTER, p.LINEAR), p.texParameteri(p.TEXTURE_2D, p.TEXTURE_WRAP_S, p.CLAMP_TO_EDGE), p.texParameteri(p.TEXTURE_2D, p.TEXTURE_WRAP_T, p.CLAMP_TO_EDGE), p.framebufferTexture2D(p.FRAMEBUFFER, p.COLOR_ATTACHMENT0, p.TEXTURE_2D, D, 0), p.bindTexture(p.TEXTURE_2D, null), p.bindFramebuffer(p.FRAMEBUFFER, null), {fbo: C, texture: D};
}, y = function(N) {
let I = null, C = null, O = false;
t === 0 ? I = e : I = m(i).texture, t++, r && !(N & b.INTERMEDIATE) ? (C = null, O = t % 2 === 0) : (i = (i + 1) % 2, C = m(i).fbo), p.bindTexture(p.TEXTURE_2D, I), p.bindFramebuffer(p.FRAMEBUFFER, C), p.uniform1f(u.uniform.flipY, O ? -1 : 1), p.drawArrays(p.TRIANGLES, 0, 6);
}, w = function(N) {
if (d[N])
return u = d[N], p.useProgram(u.id), u;
u = new HV(p, x.VERTEX_IDENTITY, N);
const I = Float32Array.BYTES_PER_ELEMENT, C = 4 * I;
return p.enableVertexAttribArray(u.attribute.pos), p.vertexAttribPointer(u.attribute.pos, 2, p.FLOAT, false, C, 0 * I), p.enableVertexAttribArray(u.attribute.uv), p.vertexAttribPointer(u.attribute.uv, 2, p.FLOAT, false, C, 2 * I), d[N] = u, u;
};
let b = {INTERMEDIATE: 1}, x = {};
x.VERTEX_IDENTITY = ["precision highp float;", "attribute vec2 pos;", "attribute vec2 uv;", "varying vec2 vUv;", "uniform float flipY;", "void main(void) {", "vUv = uv;", "gl_Position = vec4(pos.x, pos.y*flipY, 0.0, 1.);", "}"].join(`
`), x.FRAGMENT_IDENTITY = ["precision highp float;", "varying vec2 vUv;", "uniform sampler2D texture;", "void main(void) {", "gl_FragColor = texture2D(texture, vUv);", "}"].join(`
`);
let L = {};
L.colorMatrix = function(N) {
const I = new Float32Array(N);
I[4] /= 255, I[9] /= 255, I[14] /= 255, I[19] /= 255;
const C = I[18] === 1 && I[3] === 0 && I[8] === 0 && I[13] === 0 && I[15] === 0 && I[16] === 0 && I[17] === 0 && I[19] === 0 ? L.colorMatrix.SHADER.WITHOUT_ALPHA : L.colorMatrix.SHADER.WITH_ALPHA, O = w(C);
p.uniform1fv(O.uniform.m, I), y();
}, L.colorMatrix.SHADER = {}, L.colorMatrix.SHADER.WITH_ALPHA = ["precision highp float;", "varying vec2 vUv;", "uniform sampler2D texture;", "uniform float m[20];", "void main(void) {", "vec4 c = texture2D(texture, vUv);", "gl_FragColor.r = m[0] * c.r + m[1] * c.g + m[2] * c.b + m[3] * c.a + m[4];", "gl_FragColor.g = m[5] * c.r + m[6] * c.g + m[7] * c.b + m[8] * c.a + m[9];", "gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[13] * c.a + m[14];", "gl_FragColor.a = m[15] * c.r + m[16] * c.g + m[17] * c.b + m[18] * c.a + m[19];", "}"].join(`
`), L.colorMatrix.SHADER.WITHOUT_ALPHA = ["precision highp float;", "varying vec2 vUv;", "uniform sampler2D texture;", "uniform float m[20];", "void main(void) {", "vec4 c = texture2D(texture, vUv);", "gl_FragColor.r = m[0] * c.r + m[1] * c.g + m[2] * c.b + m[4];", "gl_FragColor.g = m[5] * c.r + m[6] * c.g + m[7] * c.b + m[9];", "gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[14];", "gl_FragColor.a = c.a;", "}"].join(`
`), L.brightness = function(N) {
const I = (N || 0) + 1;
L.colorMatrix([I, 0, 0, 0, 0, 0, I, 0, 0, 0, 0, 0, I, 0, 0, 0, 0, 0, 1, 0]);
}, L.saturation = function(N) {
const I = (N || 0) * 2 / 3 + 1, C = (I - 1) * -0.5;
L.colorMatrix([I, C, C, 0, 0, C, I, C, 0, 0, C, C, I, 0, 0, 0, 0, 0, 1, 0]);
}, L.desaturate = function() {
L.saturation(-1);
}, L.contrast = function(N) {
const I = (N || 0) + 1, C = -128 * (I - 1);
L.colorMatrix([I, 0, 0, 0, C, 0, I, 0, 0, C, 0, 0, I, 0, C, 0, 0, 0, 1, 0]);
}, L.negative = function() {
L.contrast(-2);
}, L.hue = function(N) {
N = (N || 0) / 180 * Math.PI;
const I = Math.cos(N), C = Math.sin(N), O = 0.213, D = 0.715, F = 0.072;
L.colorMatrix([O + I * (1 - O) + C * -O, D + I * -D + C * -D, F + I * -F + C * (1 - F), 0, 0, O + I * -O + C * 0.143, D + I * (1 - D) + C * 0.14, F + I * -F + C * -0.283, 0, 0, O + I * -O + C * -(1 - O), D + I * -D + C * D, F + I * (1 - F) + C * F, 0, 0, 0, 0, 0, 1, 0]);
}, L.desaturateLuminance = function() {
L.colorMatrix([0.2764723, 0.929708, 0.0938197, 0, -37.1, 0.2764723, 0.929708, 0.0938197, 0, -37.1, 0.2764723, 0.929708, 0.0938197, 0, -37.1, 0, 0, 0, 1, 0]);
}, L.sepia = function() {
L.colorMatrix([0.393, 0.7689999, 0.18899999, 0, 0, 0.349, 0.6859999, 0.16799999, 0, 0, 0.272, 0.5339999, 0.13099999, 0, 0, 0, 0, 0, 1, 0]);
}, L.brownie = function() {
L.colorMatrix([0.5997023498159715, 0.34553243048391263, -0.2708298674538042, 0, 47.43192855600873, -0.037703249837783157, 0.8609577587992641, 0.15059552388459913, 0, -36.96841498319127, 0.24113635128153335, -0.07441037908422492, 0.44972182064877153, 0, -7.562075277591283, 0, 0, 0, 1, 0]);
}, L.vintagePinhole = function() {
L.colorMatrix([0.6279345635605994, 0.3202183420819367, -0.03965408211312453, 0, 9.651285835294123, 0.02578397704808868, 0.6441188644374771, 0.03259127616149294, 0, 7.462829176470591, 0.0466055556782719, -0.0851232987247891, 0.5241648018700465, 0, 5.159190588235296, 0, 0, 0, 1, 0]);
}, L.kodachrome = function() {
L.colorMatrix([1.1285582396593525, -0.3967382283601348, -0.03992559172921793, 0, 63.72958762196502, -0.16404339962244616, 1.0835251566291304, -0.05498805115633132, 0, 24.732407896706203, -0.16786010706155763, -0.5603416277695248, 1.6014850761964943, 0, 35.62982807460946, 0, 0, 0, 1, 0]);
}, L.technicolor = function() {
L.colorMatrix([1.9125277891456083, -0.8545344976951645, -0.09155508482755585, 0, 11.793603434377337, -0.3087833385928097, 1.7658908555458428, -0.10601743074722245, 0, -70.35205161461398, -0.231103377548616, -0.7501899197440212, 1.847597816108189, 0, 30.950940869491138, 0, 0, 0, 1, 0]);
}, L.polaroid = function() {
L.colorMatrix([1.438, -0.062, -0.062, 0, 0, -0.122, 1.378, -0.122, 0, 0, -0.016, -0.016, 1.483, 0, 0, 0, 0, 0, 1, 0]);
}, L.shiftToBGR = function() {
L.colorMatrix([0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0]);
}, L.convolution = function(N) {
const I = new Float32Array(N), C = 1 / o, O = 1 / c, D = w(L.convolution.SHADER);
p.uniform1fv(D.uniform.m, I), p.uniform2f(D.uniform.px, C, O), y();
}, L.convolution.SHADER = ["precision highp float;", "varying vec2 vUv;", "uniform sampler2D texture;", "uniform vec2 px;", "uniform float m[9];", "void main(void) {", "vec4 c11 = texture2D(texture, vUv - px);", "vec4 c12 = texture2D(texture, vec2(vUv.x, vUv.y - px.y));", "vec4 c13 = texture2D(texture, vec2(vUv.x + px.x, vUv.y - px.y));", "vec4 c21 = texture2D(texture, vec2(vUv.x - px.x, vUv.y) );", "vec4 c22 = texture2D(texture, vUv);", "vec4 c23 = texture2D(texture, vec2(vUv.x + px.x, vUv.y) );", "vec4 c31 = texture2D(texture, vec2(vUv.x - px.x, vUv.y + px.y) );", "vec4 c32 = texture2D(texture, vec2(vUv.x, vUv.y + px.y) );", "vec4 c33 = texture2D(texture, vUv + px );", "gl_FragColor = ", "c11 * m[0] + c12 * m[1] + c22 * m[2] +", "c21 * m[3] + c22 * m[4] + c23 * m[5] +", "c31 * m[6] + c32 * m[7] + c33 * m[8];", "gl_FragColor.a = c22.a;", "}"].join(`
`), L.detectEdges = function() {
L.convolution.call(this, [0, 1, 0, 1, -4, 1, 0, 1, 0]);
}, L.sobelX = function() {
L.convolution.call(this, [-1, 0, 1, -2, 0, 2, -1, 0, 1]);
}, L.sobelY = function() {
L.convolution.call(this, [-1, -2, -1, 0, 0, 0, 1, 2, 1]);
}, L.sharpen = function(N) {
const I = N || 1;
L.convolution.call(this, [0, -1 * I, 0, -1 * I, 1 + 4 * I, -1 * I, 0, -1 * I, 0]);
}, L.emboss = function(N) {
const I = N || 1;
L.convolution.call(this, [-2 * I, -1 * I, 0, -1 * I, 1, 1 * I, 0, 1 * I, 2 * I]);
}, L.blur = function(N) {
const I = N / 7 / o, C = N / 7 / c, O = w(L.blur.SHADER);
p.uniform2f(O.uniform.px, 0, C), y(b.INTERMEDIATE), p.uniform2f(O.uniform.px, I, 0), y();
}, L.blur.SHADER = ["precision highp float;", "varying vec2 vUv;", "uniform sampler2D texture;", "uniform vec2 px;", "void main(void) {", "gl_FragColor = vec4(0.0);", "gl_FragColor += texture2D(texture, vUv + vec2(-7.0*px.x, -7.0*px.y))*0.0044299121055113265;", "gl_FragColor += texture2D(texture, vUv + vec2(-6.0*px.x, -6.0*px.y))*0.00895781211794;", "gl_FragColor += texture2D(texture, vUv + vec2(-5.0*px.x, -5.0*px.y))*0.0215963866053;", "gl_FragColor += texture2D(texture, vUv + vec2(-4.0*px.x, -4.0*px.y))*0.0443683338718;", "gl_FragColor += texture2D(texture, vUv + vec2(-3.0*px.x, -3.0*px.y))*0.0776744219933;", "gl_FragColor += texture2D(texture, vUv + vec2(-2.0*px.x, -2.0*px.y))*0.115876621105;", "gl_FragColor += texture2D(texture, vUv + vec2(-1.0*px.x, -1.0*px.y))*0.147308056121;", "gl_FragColor += texture2D(texture, vUv )*0.159576912161;", "gl_FragColor += texture2D(texture, vUv + vec2( 1.0*px.x, 1.0*px.y))*0.147308056121;", "gl_FragColor += texture2D(texture, vUv + vec2( 2.0*px.x, 2.0*px.y))*0.115876621105;", "gl_FragColor += texture2D(texture, vUv + vec2( 3.0*px.x, 3.0*px.y))*0.0776744219933;", "gl_FragColor += texture2D(texture, vUv + vec2( 4.0*px.x, 4.0*px.y))*0.0443683338718;", "gl_FragColor += texture2D(texture, vUv + vec2( 5.0*px.x, 5.0*px.y))*0.0215963866053;", "gl_FragColor += texture2D(texture, vUv + vec2( 6.0*px.x, 6.0*px.y))*0.00895781211794;", "gl_FragColor += texture2D(texture, vUv + vec2( 7.0*px.x, 7.0*px.y))*0.0044299121055113265;", "}"].join(`
`), L.pixelate = function(N) {
const I = N / o, C = N / c, O = w(L.pixelate.SHADER);
p.uniform2f(O.uniform.size, I, C), y();
}, L.pixelate.SHADER = ["precision highp float;", "varying vec2 vUv;", "uniform vec2 size;", "uniform sampler2D texture;", "vec2 pixelate(vec2 coord, vec2 size) {", "return floor( coord / size ) * size;", "}", "void main(void) {", "gl_FragColor = vec4(0.0);", "vec2 coord = pixelate(vUv, size);", "gl_FragColor += texture2D(texture, coord);", "}"].join(`
`);
};
Vx.Canvas = VV;
});
var Yx = we((qx) => {
const ys = zt(), GV = Gx();
let yt = null, Yt = null;
function qV(n, t) {
let e;
if (n instanceof ys.Tensor)
e = ys.clone(n);
else {
const r = n.naturalWidth || n.videoWidth || n.width || n.shape && n.shape[1] > 0, i = n.naturalHeight || n.videoHeight || n.height || n.shape && n.shape[2] > 0;
let a = r, s = i;
t.filter.width > 0 ? a = t.filter.width : t.filter.height > 0 && (a = r * (t.filter.height / i)), t.filter.height > 0 ? s = t.filter.height : t.filter.width > 0 && (s = i * (t.filter.width / r)), (!yt || yt.width !== a || yt.height !== s) && (yt = typeof OffscreenCanvas != "undefined" ? new OffscreenCanvas(a, s) : document.createElement("canvas"), yt.width !== a && (yt.width = a), yt.height !== s && (yt.height = s));
const o = yt.getContext("2d");
n instanceof ImageData ? o.putImageData(n, 0, 0) : o.drawImage(n, 0, 0, r, i, 0, 0, yt.width, yt.height), t.filter.enabled && ((!this.fx || !Yt || yt.width !== Yt.width || yt.height !== Yt.height) && (Yt = typeof OffscreenCanvas != "undefined" ? new OffscreenCanvas(yt.width, yt.height) : document.createElement("canvas"), Yt.width !== yt.width && (Yt.width = yt.width), Yt.height !== yt.height && (Yt.height = yt.height), this.fx = ys.ENV.flags.IS_BROWSER && typeof document != "undefined" ? new GV.Canvas({canvas: Yt}) : null), this.fx.reset(), this.fx.addFilter("brightness", t.filter.brightness), t.filter.contrast !== 0 && this.fx.addFilter("contrast", t.filter.contrast), t.filter.sharpness !== 0 && this.fx.addFilter("sharpen", t.filter.sharpness), t.filter.blur !== 0 && this.fx.addFilter("blur", t.filter.blur), t.filter.saturation !== 0 && this.fx.addFilter("saturation", t.filter.saturation), t.filter.hue !== 0 && this.fx.addFilter("hue", t.filter.hue), t.filter.negative && this.fx.addFilter("negative"), t.filter.sepia && this.fx.addFilter("sepia"), t.filter.vintage && this.fx.addFilter("brownie"), t.filter.sepia && this.fx.addFilter("sepia"), t.filter.kodachrome && this.fx.addFilter("kodachrome"), t.filter.technicolor && this.fx.addFilter("technicolor"), t.filter.polaroid && this.fx.addFilter("polaroid"), t.filter.pixelate !== 0 && this.fx.addFilter("pixelate", t.filter.pixelate), this.fx.apply(yt)), Yt || (Yt = yt);
let c;
if (t.backend === "webgl" || Yt instanceof ImageData)
c = ys.browser.fromPixels(Yt);
else {
const u = typeof OffscreenCanvas != "undefined" ? new OffscreenCanvas(a, s) : document.createElement("canvas");
u.width = a, u.height = s;
const h = u.getContext("2d");
h.drawImage(Yt, 0, 0);
const d = h.getImageData(0, 0, a, s);
c = ys.browser.fromPixels(d);
}
const l = c.toFloat();
e = l.expandDims(0), c.dispose(), l.dispose();
}
return {tensor: e, canvas: t.filter.return ? Yt : null};
}
qx.process = qV;
});
var Kx = we((YV) => {
vs(YV, {default: () => KV});
var KV = {backend: "webgl", console: true, async: false, profile: false, deallocate: false, scoped: false, videoOptimized: true, filter: {enabled: true, width: 0, height: 0, return: true, brightness: 0, contrast: 0, sharpness: 0, blur: 0, saturation: 0, hue: 0, negative: false, sepia: false, vintage: false, kodachrome: false, technicolor: false, polaroid: false, pixelate: 0}, gesture: {enabled: true}, face: {enabled: true, detector: {modelPath: "../models/blazeface-back.json", inputSize: 256, maxFaces: 10, skipFrames: 10, minConfidence: 0.5, iouThreshold: 0.3, scoreThreshold: 0.5}, mesh: {enabled: true, modelPath: "../models/facemesh.json", inputSize: 192}, iris: {enabled: true, modelPath: "../models/iris.json", enlargeFactor: 2.3, inputSize: 64}, age: {enabled: true, modelPath: "../models/ssrnet-age-imdb.json", inputSize: 64, skipFrames: 10}, gender: {enabled: true, minConfidence: 0.8, modelPath: "../models/ssrnet-gender-imdb.json"}, emotion: {enabled: true, inputSize: 64, minConfidence: 0.5, skipFrames: 10, modelPath: "../models/emotion.json"}}, body: {enabled: true, modelPath: "../models/posenet.json", inputResolution: 257, outputStride: 16, maxDetections: 10, scoreThreshold: 0.5, nmsRadius: 20}, hand: {enabled: true, inputSize: 256, skipFrames: 10, minConfidence: 0.5, iouThreshold: 0.3, scoreThreshold: 0.5, enlargeFactor: 1.65, maxHands: 10, detector: {modelPath: "../models/handdetect.json"}, skeleton: {modelPath: "../models/handskeleton.json"}}};
});
var $x = we((JG, jx) => {
jx.exports = {name: "@vladmandic/human", version: "0.7.1", description: "human: 3D Face Detection, Body Pose, Hand & Finger Tracking, Iris Tracking, Age & Gender Prediction, Emotion Prediction & Gesture Recognition", sideEffects: false, main: "dist/human.node.js", module: "dist/human.esm.js", browser: "dist/human.esm.js", author: "Vladimir Mandic <mandic00@live.com>", bugs: {url: "https://github.com/vladmandic/human/issues"}, homepage: "https://github.com/vladmandic/human#readme", license: "MIT", engines: {node: ">=14.0.0"}, repository: {type: "git", url: "git+https://github.com/vladmandic/human.git"}, dependencies: {}, peerDependencies: {}, devDependencies: {"@tensorflow/tfjs": "^2.7.0", "@tensorflow/tfjs-node": "^2.7.0", "@vladmandic/pilogger": "^0.2.7", dayjs: "^1.9.4", esbuild: "^0.7.22", eslint: "^7.12.1", "eslint-config-airbnb-base": "^14.2.0", "eslint-plugin-import": "^2.22.1", "eslint-plugin-json": "^2.1.2", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^4.2.1", rimraf: "^3.0.2", seedrandom: "^3.0.5", "simple-git": "^2.21.0"}, scripts: {start: "node --trace-warnings --unhandled-rejections=strict --trace-uncaught --no-deprecation src/node.js", lint: "eslint src/*.js demo/*.js", "build-iife": "esbuild --bundle --minify --platform=browser --sourcemap --target=esnext --format=iife --external:fs --global-name=Human --metafile=dist/human.json --outfile=dist/human.js src/human.js", "build-esm-bundle": "esbuild --bundle --minify --platform=browser --sourcemap --target=esnext --format=esm --external:fs --metafile=dist/human.esm.json --outfile=dist/human.esm.js src/human.js", "build-esm-nobundle": "esbuild --bundle --minify --platform=browser --sourcemap --target=esnext --format=esm --external:@tensorflow --external:fs --metafile=dist/human.esm-nobundle.json --outfile=dist/human.esm-nobundle.js src/human.js", "build-node": "esbuild --bundle --minify --platform=node --sourcemap --target=esnext --format=cjs --metafile=dist/human.node.json --outfile=dist/human.node.js src/human.js", "build-node-nobundle": "esbuild --bundle --minify --platform=node --sourcemap --target=esnext --format=cjs --external:@tensorflow --metafile=dist/human.node.json --outfile=dist/human.node-nobundle.js src/human.js", "build-demo": "esbuild --bundle --platform=browser --sourcemap --target=es2018 --format=esm --external:fs --metafile=dist/demo-browser-index.json --outfile=dist/demo-browser-index.js demo/browser.js", build: "rimraf dist/* && npm run build-iife && npm run build-esm-bundle && npm run build-esm-nobundle && npm run build-node && npm run build-node-nobundle && npm run build-demo && ls -l dist/", update: "npm update --depth 20 --force && npm dedupe && npm prune && npm audit", changelog: "node changelog.js"}, keywords: ["tensorflowjs", "face-detection", "face-geometry", "body-tracking", "hand-tracking", "iris-tracking", "age-estimation", "emotion-detection", "gender-prediction", "gesture-recognition"]};
});
const Kt = zt();
const Xx = K2();
const ac = J2();
const Pp = ex();
const Jx = Ax();
const Zx = Mx();
const Mp = Hx();
const jV = Yx();
const $V = tc();
const sc = Kx().default;
const XV = $x();
const JV = {face: {detector: {skipFrames: 0}, age: {skipFrames: 0}, emotion: {skipFrames: 0}}, hand: {skipFrames: 0}};
const At = () => typeof performance != "undefined" ? performance.now() : parseInt(Number(process.hrtime.bigint()) / 1e3 / 1e3);
function oc(...n) {
const t = (e) => e && typeof e == "object";
return n.reduce((e, r) => (Object.keys(r || {}).forEach((i) => {
const a = e[i], s = r[i];
Array.isArray(a) && Array.isArray(s) ? e[i] = a.concat(...s) : t(a) && t(s) ? e[i] = oc(a, s) : e[i] = s;
}), e), {});
}
class ZV {
constructor() {
this.tf = Kt, this.version = XV.version, this.defaults = sc, this.config = sc, this.fx = null, this.state = "idle", this.numTensors = 0, this.analyzeMemoryLeaks = false, this.checkSanity = false, this.firstRun = true, this.models = {facemesh: null, posenet: null, handpose: null, iris: null, age: null, gender: null, emotion: null}, this.facemesh = Xx, this.ssrnet = ac, this.emotion = Pp, this.posenet = Jx, this.handpose = Zx;
}
log(...n) {
n && this.config.console && console.log("Human:", ...n);
}
profile() {
return this.config.profile ? $V.data : {};
}
analyze(...n) {
if (!this.analyzeMemoryLeaks)
return;
const t = Kt.engine().state.numTensors, e = this.numTensors;
this.numTensors = t;
const r = t - e;
r !== 0 && this.log(...n, r);
}
sanity(n) {
if (!this.checkSanity)
return null;
if (!n)
return "input is not defined";
if (Kt.ENV.flags.IS_NODE && !(n instanceof Kt.Tensor))
return "input must be a tensor";
try {
Kt.getBackend();
} catch (e) {
return "backend not loaded";
}
return null;
}
async load(n) {
n && (this.config = oc(sc, n)), this.firstRun && (this.checkBackend(true), this.log(`version: ${this.version} TensorFlow/JS version: ${Kt.version_core}`), this.log("configuration:", this.config), this.log("flags:", Kt.ENV.flags), this.firstRun = false), this.config.face.enabled && !this.models.facemesh && (this.log("load model: face"), this.models.facemesh = await Xx.load(this.config.face)), this.config.body.enabled && !this.models.posenet && (this.log("load model: body"), this.models.posenet = await Jx.load(this.config.body)), this.config.hand.enabled && !this.models.handpose && (this.log("load model: hand"), this.models.handpose = await Zx.load(this.config.hand)), this.config.face.enabled && this.config.face.age.enabled && !this.models.age && (this.log("load model: age"), this.models.age = await ac.loadAge(this.config)), this.config.face.enabled && this.config.face.gender.enabled && !this.models.gender && (this.log("load model: gender"), this.models.gender = await ac.loadGender(this.config)), this.config.face.enabled && this.config.face.emotion.enabled && !this.models.emotion && (this.log("load model: emotion"), this.models.emotion = await Pp.load(this.config));
}
async checkBackend(n) {
(n || Kt.getBackend() !== this.config.backend) && (this.state = "backend", this.log("setting backend:", this.config.backend), await Kt.setBackend(this.config.backend), Kt.enableProdMode(), this.config.deallocate && this.config.backend === "webgl" && (this.log("Changing WebGL: WEBGL_DELETE_TEXTURE_THRESHOLD:", this.config.deallocate), Kt.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD", this.config.deallocate ? 0 : -1)), Kt.ENV.set("WEBGL_PACK_DEPTHWISECONV", true), await Kt.ready());
}
async detect(n, t = {}) {
this.state = "config";
const e = {};
let r;
this.config = oc(sc, t), this.config.videoOptimized || (this.config = oc(this.config, JV)), this.state = "check";
const i = this.sanity(n);
return i ? (this.log(i, n), {error: i}) : new Promise(async (a) => {
let s, o, c, l;
const u = At();
r = At(), await this.checkBackend(), e.backend = Math.trunc(At() - r), r = At(), this.state = "load", await this.load(), e.load = Math.trunc(At() - r), this.config.scoped && Kt.engine().startScope(), this.analyze("Start Detect:"), r = At();
const h = jV.process(n, this.config);
e.image = Math.trunc(At() - r);
const d = [];
if (this.config.face.enabled) {
this.state = "run:face", r = At(), this.analyze("Start FaceMesh:");
const f = await this.models.facemesh.estimateFaces(h.tensor, this.config.face);
e.face = Math.trunc(At() - r);
for (const m of f) {
if (!m.image || m.image.isDisposedInternal) {
this.log("Face object is disposed:", m.image);
continue;
}
this.state = "run:agegender", r = At(), c = this.config.face.age.enabled || this.config.face.gender.enabled ? await ac.predict(m.image, this.config) : {}, e.agegender = Math.trunc(At() - r), this.state = "run:emotion", r = At(), l = this.config.face.emotion.enabled ? await Pp.predict(m.image, this.config) : {}, e.emotion = Math.trunc(At() - r), m.image.dispose();
const g = m.annotations.leftEyeIris && m.annotations.rightEyeIris ? Math.max(m.annotations.leftEyeIris[3][0] - m.annotations.leftEyeIris[1][0], m.annotations.rightEyeIris[3][0] - m.annotations.rightEyeIris[1][0]) : 0;
d.push({confidence: m.confidence, box: m.box, mesh: m.mesh, annotations: m.annotations, age: c.age, gender: c.gender, agConfidence: c.confidence, emotion: l, iris: g !== 0 ? Math.trunc(100 * 11.7 / g) / 100 : 0}), this.analyze("End FaceMesh:");
}
}
this.config.async ? s = this.config.body.enabled ? this.models.posenet.estimatePoses(h.tensor, this.config.body) : [] : (this.state = "run:body", r = At(), this.analyze("Start PoseNet"), s = this.config.body.enabled ? await this.models.posenet.estimatePoses(h.tensor, this.config.body) : [], this.analyze("End PoseNet:"), e.body = Math.trunc(At() - r)), this.config.async ? o = this.config.hand.enabled ? this.models.handpose.estimateHands(h.tensor, this.config.hand) : [] : (this.state = "run:hand", r = At(), this.analyze("Start HandPose:"), o = this.config.hand.enabled ? await this.models.handpose.estimateHands(h.tensor, this.config.hand) : [], this.analyze("End HandPose:"), e.hand = Math.trunc(At() - r)), this.config.async && ([s, o] = await Promise.all([s, o])), h.tensor.dispose(), this.state = "idle", this.config.scoped && Kt.engine().endScope(), this.analyze("End Scope:");
let p = [];
this.config.gesture.enabled && (r = At(), p = {body: Mp.body(s), hand: Mp.hand(o), face: Mp.face(d)}, e.gesture = Math.trunc(At() - r)), e.total = Math.trunc(At() - u), a({face: d, body: s, hand: o, gesture: p, performance: e, canvas: h.canvas});
});
}
}
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/**
* @license
* Copyright 2017 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
/**
* @license
* Copyright 2018 Google LLC
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
* =============================================================================
*/
/**
* @license
* Copyright 2018 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* =============================================================================
*/
/**
* @license
* Copyright 2018 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
/**
* @license
* Copyright 2019 Google LLC
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
* =============================================================================
*/
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* =============================================================================
*/
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
/**
* @license
* Copyright 2020 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
/**
* @license
* Copyright 2020 Google LLC
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
* =============================================================================
*/
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
/**
* @license
* Copyright 2018 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
/** @license See the LICENSE file. */
// demo/draw.js
async function drawGesture(result, canvas, ui2) {
if (!result)
return;
const ctx = canvas.getContext("2d");
ctx.font = ui2.baseFont;
ctx.fillStyle = ui2.baseLabel;
let i = 1;
for (const [key, val] of Object.entries(result)) {
if (val.length > 0) {
const label = `${key}: ${val.join(", ")}`;
ctx.fillText(label, 6, i * (ui2.baseLineHeight + 24));
i += 1;
}
}
}
async function drawFace(result, canvas, ui2, triangulation) {
if (!result)
return;
const ctx = canvas.getContext("2d");
for (const face of result) {
ctx.font = ui2.baseFont;
ctx.strokeStyle = ui2.baseColor;
ctx.fillStyle = ui2.baseColor;
ctx.lineWidth = ui2.baseLineWidth;
ctx.beginPath();
if (ui2.drawBoxes) {
ctx.rect(face.box[0], face.box[1], face.box[2], face.box[3]);
}
const labels = [];
if (face.agConfidence)
labels.push(`${Math.trunc(100 * face.agConfidence)}% ${face.gender || ""}`);
if (face.age)
labels.push(`age: ${face.age || ""}`);
if (face.iris)
labels.push(`iris: ${face.iris}`);
if (face.emotion && face.emotion[0])
labels.push(`${Math.trunc(100 * face.emotion[0].score)}% ${face.emotion[0].emotion}`);
ctx.fillStyle = ui2.baseLabel;
for (const i in labels)
ctx.fillText(labels[i], face.box[0] + 8, face.box[1] + 24 + (i + 1) * ui2.baseLineHeight);
ctx.stroke();
ctx.lineWidth = 1;
if (face.mesh) {
if (ui2.drawPoints) {
for (const point of face.mesh) {
ctx.fillStyle = ui2.useDepth ? `rgba(${127.5 + 2 * point[2]}, ${127.5 - 2 * point[2]}, 255, 0.5)` : ui2.baseColor;
ctx.beginPath();
ctx.arc(point[0], point[1], 2, 0, 2 * Math.PI);
ctx.fill();
}
}
if (ui2.drawPolygons) {
for (let i = 0; i < triangulation.length / 3; i++) {
const points = [
triangulation[i * 3 + 0],
triangulation[i * 3 + 1],
triangulation[i * 3 + 2]
].map((index) => face.mesh[index]);
const path = new Path2D();
path.moveTo(points[0][0], points[0][1]);
for (const point of points) {
path.lineTo(point[0], point[1]);
}
path.closePath();
ctx.strokeStyle = ui2.useDepth ? `rgba(${127.5 + 2 * points[0][2]}, ${127.5 - 2 * points[0][2]}, 255, 0.3)` : ui2.baseColor;
ctx.stroke(path);
if (ui2.fillPolygons) {
ctx.fillStyle = ui2.useDepth ? `rgba(${127.5 + 2 * points[0][2]}, ${127.5 - 2 * points[0][2]}, 255, 0.3)` : ui2.baseColor;
ctx.fill(path);
}
}
}
}
}
}
async function drawBody(result, canvas, ui2) {
if (!result)
return;
const ctx = canvas.getContext("2d");
ctx.lineJoin = "round";
for (const pose of result) {
ctx.fillStyle = ui2.baseColor;
ctx.strokeStyle = ui2.baseColor;
ctx.font = ui2.baseFont;
ctx.lineWidth = ui2.baseLineWidth;
if (ui2.drawPoints) {
for (const point of pose.keypoints) {
ctx.beginPath();
ctx.arc(point.position.x, point.position.y, 2, 0, 2 * Math.PI);
ctx.fill();
}
}
if (ui2.drawPolygons) {
const path = new Path2D();
let part;
part = pose.keypoints.find((a) => a.part === "leftShoulder");
path.moveTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "rightShoulder");
path.lineTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "rightHip");
path.lineTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "leftHip");
path.lineTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "leftShoulder");
path.lineTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "leftHip");
path.moveTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "leftKnee");
path.lineTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "leftAnkle");
path.lineTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "rightHip");
path.moveTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "rightKnee");
path.lineTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "rightAnkle");
path.lineTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "rightShoulder");
path.moveTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "leftShoulder");
path.lineTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "leftElbow");
path.lineTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "leftWrist");
path.lineTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "leftShoulder");
path.moveTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "rightShoulder");
path.lineTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "rightElbow");
path.lineTo(part.position.x, part.position.y);
part = pose.keypoints.find((a) => a.part === "rightWrist");
path.lineTo(part.position.x, part.position.y);
ctx.stroke(path);
}
}
}
async function drawHand(result, canvas, ui2) {
if (!result)
return;
const ctx = canvas.getContext("2d");
ctx.lineJoin = "round";
for (const hand of result) {
ctx.font = ui2.baseFont;
ctx.lineWidth = ui2.baseLineWidth;
if (ui2.drawBoxes) {
ctx.lineWidth = ui2.baseLineWidth;
ctx.beginPath();
ctx.strokeStyle = ui2.baseColor;
ctx.fillStyle = ui2.baseColor;
ctx.rect(hand.box[0], hand.box[1], hand.box[2], hand.box[3]);
ctx.fillStyle = ui2.baseLabel;
ctx.fillText("hand", hand.box[0] + 2, hand.box[1] + 22, hand.box[2]);
ctx.stroke();
}
if (ui2.drawPoints) {
if (hand.landmarks && hand.landmarks.length > 0) {
for (const point of hand.landmarks) {
ctx.fillStyle = ui2.useDepth ? `rgba(${127.5 + 2 * point[2]}, ${127.5 - 2 * point[2]}, 255, 0.5)` : ui2.baseColor;
ctx.beginPath();
ctx.arc(point[0], point[1], 2, 0, 2 * Math.PI);
ctx.fill();
}
}
}
if (ui2.drawPolygons) {
const addPart = (part) => {
if (!part)
return;
for (let i = 0; i < part.length; i++) {
ctx.lineWidth = ui2.baseLineWidth;
ctx.beginPath();
ctx.strokeStyle = ui2.useDepth ? `rgba(${127.5 + 2 * part[i][2]}, ${127.5 - 2 * part[i][2]}, 255, 0.5)` : ui2.baseColor;
ctx.moveTo(part[i > 0 ? i - 1 : 0][0], part[i > 0 ? i - 1 : 0][1]);
ctx.lineTo(part[i][0], part[i][1]);
ctx.stroke();
}
};
addPart(hand.annotations.indexFinger);
addPart(hand.annotations.middleFinger);
addPart(hand.annotations.ringFinger);
addPart(hand.annotations.pinky);
addPart(hand.annotations.thumb);
}
}
}
const draw = {
face: drawFace,
body: drawBody,
hand: drawHand,
gesture: drawGesture
};
var draw_default = draw;
// demo/menu.js
let instance = 0;
let CSScreated = false;
let theme = {
background: "darkslategray",
hover: "lightgray",
itemBackground: "black",
itemColor: "white",
buttonBackground: "lightblue",
buttonHover: "lightgreen",
checkboxOn: "lightgreen",
checkboxOff: "lightcoral",
rangeBackground: "lightblue",
rangeLabel: "white",
chartColor: "lightblue"
};
function createCSS() {
if (CSScreated)
return;
const css = `
.menu { position: fixed; top: 0rem; right: 0; width: fit-content; padding: 0 0.8rem 0 0.8rem; line-height: 1.8rem; z-index: 10; max-height: calc(100% - 4rem);
box-shadow: 0 0 8px dimgrey; background: ${theme.background}; border-radius: 1rem; border-color: black; border-style: solid; border-width: thin; }
.menu:hover { box-shadow: 0 0 8px ${theme.hover}; }
.menu-container { display: block; max-height: 100vh; }
.menu-container-fadeout { max-height: 0; overflow: hidden; transition: max-height, 0.5s ease; }
.menu-container-fadein { max-height: 100vh; overflow: hidden; transition: max-height, 0.5s ease; }
.menu-item { display: flex; white-space: nowrap; padding: 0.2rem; width: max-content; cursor: default; }
.menu-title { text-align: right; cursor: pointer; }
.menu-hr { margin: 0.2rem; border: 1px solid rgba(0, 0, 0, 0.5) }
.menu-label { padding: 0; }
.menu-list { margin-right: 0.8rem; }
select:focus { outline: none; }
.menu-list-item { background: ${theme.itemBackground}; color: ${theme.itemColor}; border: none; padding: 0.2rem; font-family: inherit; font-variant: inherit; border-radius: 1rem; }
.menu-chart-title { padding: 0; font-size: 0.8rem; font-weight: 800; align-items: center}
.menu-chart-canvas { background: transparent; margin: 0.2rem 0 0.2rem 0.6rem; }
.menu-button { border: 0; background: ${theme.buttonBackground}; width: -webkit-fill-available; padding: 8px; margin: 8px 0 8px 0; cursor: pointer; box-shadow: 4px 4px 4px 0 dimgrey; border-radius: 1rem; justify-content: center; }
.menu-button:hover { background: ${theme.buttonHover}; box-shadow: 4px 4px 4px 0 black; }
.menu-button:focus { outline: none; }
.menu-checkbox { width: 2.8rem; height: 1rem; background: ${theme.itemBackground}; margin: 0.5rem 0.8rem 0 0; position: relative; border-radius: 1rem; }
.menu-checkbox:after { content: 'OFF'; color: ${theme.checkboxOff}; position: absolute; right: 0.2rem; top: -0.4rem; font-weight: 800; font-size: 0.5rem; }
.menu-checkbox:before { content: 'ON'; color: ${theme.checkboxOn}; position: absolute; left: 0.3rem; top: -0.4rem; font-weight: 800; font-size: 0.5rem; }
.menu-checkbox-label { width: 1.3rem; height: 0.8rem; cursor: pointer; position: absolute; top: 0.1rem; left: 0.1rem; z-index: 1; background: ${theme.checkboxOff}; border-radius: 1rem; transition: left 0.6s ease; }
input[type=checkbox] { visibility: hidden; }
input[type=checkbox]:checked + label { left: 1.4rem; background: ${theme.checkboxOn}; }
.menu-range { margin: 0 0.8rem 0 0; width: 5rem; background: transparent; color: ${theme.rangeBackground}; }
.menu-range:before { content: attr(value); color: ${theme.rangeLabel}; margin: 0 0.4rem 0 0; font-weight: 800; font-size: 0.6rem; position: relative; top: 0.3rem; }
input[type=range] { -webkit-appearance: none; }
input[type=range]::-webkit-slider-runnable-track { width: 100%; height: 1rem; cursor: pointer; background: ${theme.itemBackground}; border-radius: 1rem; border: 1px; }
input[type=range]::-webkit-slider-thumb { border: 1px solid #000000; margin-top: 0.05rem; height: 0.9rem; width: 1.5rem; border-radius: 1rem; background: ${theme.rangeBackground}; cursor: pointer; -webkit-appearance: none; }
`;
const el = document.createElement("style");
el.innerHTML = css;
document.getElementsByTagName("head")[0].appendChild(el);
CSScreated = true;
}
class Menu {
constructor(parent, title, position, userTheme) {
if (userTheme)
theme = {...theme, ...userTheme};
createCSS();
this.createMenu(parent, title, position);
this.id = 0;
this.instance = instance;
instance++;
this._maxFPS = 0;
this.hidden = 0;
}
createMenu(parent, title = "", position = {top: null, left: null, bottom: null, right: null}) {
this.menu = document.createElement("div");
this.menu.id = `menu-${instance}`;
this.menu.className = "menu";
if (position) {
if (position.top)
this.menu.style.top = position.top;
if (position.bottom)
this.menu.style.bottom = position.bottom;
if (position.left)
this.menu.style.left = position.left;
if (position.right)
this.menu.style.right = position.right;
}
this.container = document.createElement("div");
this.container.id = `menu-container-${instance}`;
this.container.className = "menu-container menu-container-fadein";
if (title !== "") {
const elTitle = document.createElement("div");
elTitle.className = "menu-title";
elTitle.id = `menu-title-${instance}`;
elTitle.innerHTML = title;
this.menu.appendChild(elTitle);
elTitle.addEventListener("click", () => {
this.container.classList.toggle("menu-container-fadeout");
this.container.classList.toggle("menu-container-fadein");
this.menu.style.borderStyle = this.container.classList.contains("menu-container-fadeout") ? "none" : "solid";
});
}
this.menu.appendChild(this.container);
if (typeof parent === "object")
parent.appendChild(this.menu);
else
document.getElementById(parent).appendChild(this.menu);
}
get newID() {
this.id++;
return `menu-${this.instance}-${this.id}`;
}
get ID() {
return `menu-${this.instance}-${this.id}`;
}
get width() {
return this.menu.offsetWidth;
}
get height() {
return this.menu.offsetHeight;
}
hide() {
if (this.container.classList.contains("menu-container-fadein")) {
this.container.classList.toggle("menu-container-fadeout");
this.container.classList.toggle("menu-container-fadein");
}
}
visible() {
return this.container.classList.contains("menu-container-fadein");
}
toggle(evt) {
this.container.classList.toggle("menu-container-fadeout");
this.container.classList.toggle("menu-container-fadein");
if (this.container.classList.contains("menu-container-fadein") && evt) {
const x = evt.x || (evt.touches && evt.touches[0] ? evt.touches[0].pageX : null);
const y = evt.y || (evt.touches && evt.touches[0] ? evt.touches[0].pageY : null);
if (x)
this.menu.style.left = `${x - 105}px`;
if (y)
this.menu.style.top = "5.5rem";
if (this.menu.offsetLeft < 0)
this.menu.style.left = 0;
if (this.menu.offsetLeft + this.menu.offsetWidth > window.innerWidth) {
this.menu.style.left = null;
this.menu.style.right = 0;
}
this.menu.style.borderStyle = "solid";
} else {
this.menu.style.borderStyle = "none";
}
}
addTitle(title) {
const el = document.createElement("div");
el.className = "menu-title";
el.id = this.newID;
el.innerHTML = title;
this.menu.appendChild(el);
el.addEventListener("click", () => {
this.hidden = !this.hidden;
const all = document.getElementsByClassName("menu");
for (const item of all) {
item.style.display = this.hidden ? "none" : "block";
}
});
return el;
}
addLabel(title) {
const el = document.createElement("div");
el.className = "menu-item menu-label";
el.id = this.newID;
el.innerHTML = title;
this.container.appendChild(el);
return el;
}
addBool(title, object, variable, callback) {
const el = document.createElement("div");
el.className = "menu-item";
el.innerHTML = `<div class="menu-checkbox"><input class="menu-checkbox" type="checkbox" id="${this.newID}" ${object[variable] ? "checked" : ""}/><label class="menu-checkbox-label" for="${this.ID}"></label></div>${title}`;
this.container.appendChild(el);
el.addEventListener("change", (evt) => {
object[variable] = evt.target.checked;
if (callback)
callback(evt.target.checked);
});
return el;
}
async addList(title, items, selected, callback) {
const el = document.createElement("div");
el.className = "menu-item";
let options = "";
for (const item of items) {
const def = item === selected ? "selected" : "";
options += `<option value="${item}" ${def}>${item}</option>`;
}
el.innerHTML = `<div class="menu-list"><select name="${this.ID}" class="menu-list-item">${options}</select><label for="${this.ID}"></label></div>${title}`;
el.style.fontFamily = document.body.style.fontFamily;
el.style.fontSize = document.body.style.fontSize;
el.style.fontVariant = document.body.style.fontVariant;
this.container.appendChild(el);
el.addEventListener("change", (evt) => {
if (callback)
callback(items[evt.target.selectedIndex]);
});
return el;
}
addRange(title, object, variable, min, max, step, callback) {
const el = document.createElement("div");
el.className = "menu-item";
el.innerHTML = `<input class="menu-range" type="range" id="${this.newID}" min="${min}" max="${max}" step="${step}" value="${object[variable]}">${title}`;
this.container.appendChild(el);
el.addEventListener("change", (evt) => {
object[variable] = evt.target.value;
evt.target.setAttribute("value", evt.target.value);
if (callback)
callback(evt.target.value);
});
return el;
}
addHTML(html) {
const el = document.createElement("div");
el.className = "menu-item";
el.id = this.newID;
if (html)
el.innerHTML = html;
this.container.appendChild(el);
return el;
}
addButton(titleOn, titleOff, callback) {
const el = document.createElement("button");
el.className = "menu-item menu-button";
el.style.fontFamily = document.body.style.fontFamily;
el.style.fontSize = document.body.style.fontSize;
el.style.fontVariant = document.body.style.fontVariant;
el.type = "button";
el.id = this.newID;
el.innerText = titleOn;
this.container.appendChild(el);
el.addEventListener("click", () => {
if (el.innerText === titleOn)
el.innerText = titleOff;
else
el.innerText = titleOn;
if (callback)
callback(el.innerText !== titleOn);
});
return el;
}
addValue(title, val, suffix = "") {
const el = document.createElement("div");
el.className = "menu-item";
el.id = `menu-val-${title}`;
el.innerText = `${title}: ${val}${suffix}`;
this.container.appendChild(el);
return el;
}
updateValue(title, val, suffix = "") {
const el = document.getElementById(`menu-val-${title}`);
if (el)
el.innerText = `${title}: ${val}${suffix}`;
else
this.addValue(title, val);
}
addChart(title, id, width = 200, height = 40, color) {
if (color)
theme.chartColor = color;
const el = document.createElement("div");
el.className = "menu-item menu-chart-title";
el.id = this.newID;
el.innerHTML = `<font color=${theme.chartColor}>${title}</font><canvas id="menu-canvas-${id}" class="menu-chart-canvas" width="${width}px" height="${height}px"></canvas>`;
this.container.appendChild(el);
return el;
}
async updateChart(id, values) {
if (!values || values.length === 0)
return;
const canvas = document.getElementById(`menu-canvas-${id}`);
if (!canvas)
return;
const ctx = canvas.getContext("2d");
ctx.fillStyle = theme.background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
const width = canvas.width / values.length;
const max = 1 + Math.max(...values);
const height = canvas.height / max;
for (const i in values) {
const gradient = ctx.createLinearGradient(0, (max - values[i]) * height, 0, 0);
gradient.addColorStop(0.1, theme.chartColor);
gradient.addColorStop(0.4, theme.background);
ctx.fillStyle = gradient;
ctx.fillRect(i * width, 0, width - 4, canvas.height);
ctx.fillStyle = theme.background;
ctx.font = `${width / 1.5}px "Segoe UI"`;
ctx.fillText(Math.round(values[i]), i * width + 1, canvas.height - 1, width - 1);
}
}
}
var menu_default = Menu;
// demo/browser.js
const human = new ZV();
const ui = {
baseColor: "rgba(173, 216, 230, 0.3)",
baseBackground: "rgba(50, 50, 50, 1)",
baseLabel: "rgba(173, 216, 230, 0.9)",
baseFontProto: 'small-caps {size} "Segoe UI"',
baseLineWidth: 16,
baseLineHeightProto: 2,
columns: 2,
busy: false,
facing: true,
useWorker: false,
worker: "worker.js",
samples: ["../assets/sample6.jpg", "../assets/sample1.jpg", "../assets/sample4.jpg", "../assets/sample5.jpg", "../assets/sample3.jpg", "../assets/sample2.jpg"],
drawBoxes: true,
drawPoints: false,
drawPolygons: true,
fillPolygons: true,
useDepth: true,
console: true,
maxFrames: 10,
modelsPreload: true,
modelsWarmup: true
};
const config = {
backend: "webgl",
profile: false,
deallocate: false,
wasm: {path: "../assets"},
filter: {
enabled: true,
width: 0,
height: 0,
brightness: 0,
contrast: 0,
sharpness: 0,
blur: 0,
saturation: 0,
hue: 0,
negative: false,
sepia: false,
vintage: false,
kodachrome: false,
technicolor: false,
polaroid: false,
pixelate: 0
},
videoOptimized: true,
face: {
enabled: true,
detector: {maxFaces: 10, skipFrames: 10, minConfidence: 0.5, iouThreshold: 0.3, scoreThreshold: 0.5},
mesh: {enabled: true},
iris: {enabled: true},
age: {enabled: true, skipFrames: 10},
gender: {enabled: true},
emotion: {enabled: true, minConfidence: 0.5, useGrayscale: true}
},
body: {enabled: true, maxDetections: 10, scoreThreshold: 0.5, nmsRadius: 20},
hand: {enabled: true, skipFrames: 10, minConfidence: 0.5, iouThreshold: 0.3, scoreThreshold: 0.5},
gesture: {enabled: true}
};
let menu2;
let menuFX;
let worker;
let timeStamp;
let camera = {};
const fps = [];
function str(...msg) {
if (!Array.isArray(msg))
return msg;
let line = "";
for (const entry of msg) {
if (typeof entry === "object")
line += JSON.stringify(entry).replace(/{|}|"|\[|\]/g, "").replace(/,/g, ", ");
else
line += entry;
}
return line;
}
const log = (...msg) => {
if (ui.console)
console.log(...msg);
};
const status = (msg) => {
document.getElementById("status").innerText = msg;
};
function drawResults(input, result, canvas) {
fps.push(1e3 / (performance.now() - timeStamp));
if (fps.length > ui.maxFrames)
fps.shift();
requestAnimationFrame(() => runHumanDetect(input, canvas));
menu2.updateChart("FPS", fps);
const ctx = canvas.getContext("2d");
ctx.fillStyle = ui.baseBackground;
ctx.fillRect(0, 0, canvas.width, canvas.height);
if (result.canvas) {
if (result.canvas.width !== canvas.width)
canvas.width = result.canvas.width;
if (result.canvas.height !== canvas.height)
canvas.height = result.canvas.height;
ctx.drawImage(result.canvas, 0, 0, result.canvas.width, result.canvas.height, 0, 0, result.canvas.width, result.canvas.height);
} else {
ctx.drawImage(input, 0, 0, input.width, input.height, 0, 0, canvas.width, canvas.height);
}
draw_default.face(result.face, canvas, ui, human.facemesh.triangulation);
draw_default.body(result.body, canvas, ui);
draw_default.hand(result.hand, canvas, ui);
draw_default.gesture(result.gesture, canvas, ui);
const engine = human.tf.engine();
const gpu = engine.backendInstance ? `gpu: ${(engine.backendInstance.numBytesInGPU ? engine.backendInstance.numBytesInGPU : 0).toLocaleString()} bytes` : "";
const memory = `system: ${engine.state.numBytes.toLocaleString()} bytes ${gpu} | tensors: ${engine.state.numTensors.toLocaleString()}`;
const processing = result.canvas ? `processing: ${result.canvas.width} x ${result.canvas.height}` : "";
const avg = Math.trunc(10 * fps.reduce((a, b) => a + b) / fps.length) / 10;
document.getElementById("log").innerText = `
video: ${camera.name} | facing: ${camera.facing} | resolution: ${camera.width} x ${camera.height} ${processing}
backend: ${human.tf.getBackend()} | ${memory} | object size: ${str(result).length.toLocaleString()} bytes
performance: ${str(result.performance)} FPS:${avg}
`;
}
async function setupCamera() {
if (ui.busy)
return null;
ui.busy = true;
const video = document.getElementById("video");
const canvas = document.getElementById("canvas");
const output = document.getElementById("log");
const live = video.srcObject ? video.srcObject.getVideoTracks()[0].readyState === "live" && video.readyState > 2 && !video.paused : false;
let msg = "";
status("starting camera");
if (!navigator.mediaDevices) {
msg = "camera access not supported";
output.innerText += `
${msg}`;
log(msg);
status(msg);
return null;
}
let stream;
try {
stream = await navigator.mediaDevices.getUserMedia({
audio: false,
video: {
facingMode: ui.facing ? "user" : "environment",
width: window.innerWidth,
height: window.innerHeight,
resizeMode: "none",
contrast: 75
}
});
} catch (err) {
output.innerText += "\nCamera permission denied";
status("camera permission denied");
log(err);
}
if (stream)
video.srcObject = stream;
else
return null;
const track = stream.getVideoTracks()[0];
const settings = track.getSettings();
log("camera settings:", settings);
log("camera track:", track);
camera = {name: track.label, width: settings.width, height: settings.height, facing: settings.facingMode === "user" ? "front" : "back"};
return new Promise((resolve) => {
video.onloadeddata = async () => {
video.width = video.videoWidth;
video.height = video.videoHeight;
canvas.width = video.width;
canvas.height = video.height;
if (live)
video.play();
ui.busy = false;
resolve(video);
};
});
}
function webWorker(input, image, canvas) {
if (!worker) {
log("Creating worker thread");
worker = new Worker(ui.worker, {type: "module"});
worker.addEventListener("message", (msg) => drawResults(input, msg.data, canvas));
}
worker.postMessage({image: image.data.buffer, width: canvas.width, height: canvas.height, config}, [image.data.buffer]);
}
function runHumanDetect(input, canvas) {
timeStamp = performance.now();
if (input.srcObject) {
const live = input.srcObject.getVideoTracks()[0].readyState === "live" && input.readyState > 2 && !input.paused;
if (!live) {
if (!input.paused) {
log(`Video not ready: state: ${input.srcObject.getVideoTracks()[0].readyState} stream state: ${input.readyState}`);
setTimeout(() => runHumanDetect(input, canvas), 500);
}
return;
}
if (ui.useWorker) {
const offscreen = new OffscreenCanvas(canvas.width, canvas.height);
const ctx = offscreen.getContext("2d");
ctx.drawImage(input, 0, 0, input.width, input.height, 0, 0, canvas.width, canvas.height);
const data = ctx.getImageData(0, 0, canvas.width, canvas.height);
webWorker(input, data, canvas);
} else {
human.detect(input, config).then((result) => {
if (result.error)
log(result.error);
else
drawResults(input, result, canvas);
if (config.profile)
log("Profile data:", human.profile());
});
}
}
}
async function processImage(input) {
timeStamp = performance.now();
return new Promise((resolve) => {
const image = new Image();
image.onload = async () => {
log("Processing image:", image.src);
const canvas = document.getElementById("canvas");
image.width = image.naturalWidth;
image.height = image.naturalHeight;
canvas.width = config.filter.width && config.filter.width > 0 ? config.filter.width : image.naturalWidth;
canvas.height = config.filter.height && config.filter.height > 0 ? config.filter.height : image.naturalHeight;
const result = await human.detect(image, config);
drawResults(image, result, canvas);
const thumb = document.createElement("canvas");
thumb.className = "thumbnail";
thumb.width = window.innerWidth / (ui.columns + 0.1);
thumb.height = canvas.height / (window.innerWidth / thumb.width);
const ctx = thumb.getContext("2d");
ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height, 0, 0, thumb.width, thumb.height);
document.getElementById("samples-container").appendChild(thumb);
image.src = "";
resolve(true);
};
image.src = input;
});
}
async function detectVideo() {
config.videoOptimized = true;
document.getElementById("samples-container").style.display = "none";
document.getElementById("canvas").style.display = "block";
const video = document.getElementById("video");
const canvas = document.getElementById("canvas");
ui.baseFont = ui.baseFontProto.replace(/{size}/, "1.3rem");
ui.baseLineHeight = ui.baseLineHeightProto;
if (video.srcObject !== null && !video.paused) {
document.getElementById("play").style.display = "block";
status("paused");
video.pause();
} else {
await setupCamera();
document.getElementById("play").style.display = "none";
status("");
video.play();
}
runHumanDetect(video, canvas);
}
async function detectSampleImages() {
document.getElementById("play").style.display = "none";
config.videoOptimized = false;
ui.baseFont = ui.baseFontProto.replace(/{size}/, `${1.3 * ui.columns}rem`);
ui.baseLineHeight = ui.baseLineHeightProto * ui.columns;
document.getElementById("canvas").style.display = "none";
document.getElementById("samples-container").style.display = "block";
log("Running detection of sample images");
status("processing images");
document.getElementById("samples-container").innerHTML = "";
for (const sample of ui.samples)
await processImage(sample);
status("");
}
function setupMenu() {
menu2 = new menu_default(document.body, "...", {top: "1rem", right: "1rem"});
const btn = menu2.addButton("Start Video", "Pause Video", () => detectVideo());
menu2.addButton("Process Images", "Process Images", () => detectSampleImages());
document.getElementById("play").addEventListener("click", () => btn.click());
menu2.addHTML('<hr style="min-width: 200px; border-style: inset; border-color: dimgray">');
menu2.addList("Backend", ["cpu", "webgl", "wasm", "webgpu"], config.backend, (val) => config.backend = val);
menu2.addBool("Enable Profiler", config, "profile");
menu2.addBool("Memory Shield", config, "deallocate");
menu2.addBool("Use Web Worker", ui, "useWorker");
menu2.addHTML('<hr style="min-width: 200px; border-style: inset; border-color: dimgray">');
menu2.addLabel("Enabled Models");
menu2.addBool("Face Detect", config.face, "enabled");
menu2.addBool("Face Mesh", config.face.mesh, "enabled");
menu2.addBool("Face Iris", config.face.iris, "enabled");
menu2.addBool("Face Age", config.face.age, "enabled");
menu2.addBool("Face Gender", config.face.gender, "enabled");
menu2.addBool("Face Emotion", config.face.emotion, "enabled");
menu2.addBool("Body Pose", config.body, "enabled");
menu2.addBool("Hand Pose", config.hand, "enabled");
menu2.addBool("Gesture Analysis", config.gesture, "enabled");
menu2.addHTML('<hr style="min-width: 200px; border-style: inset; border-color: dimgray">');
menu2.addLabel("Model Parameters");
menu2.addRange("Max Objects", config.face.detector, "maxFaces", 1, 50, 1, (val) => {
config.face.detector.maxFaces = parseInt(val);
config.body.maxDetections = parseInt(val);
config.hand.maxHands = parseInt(val);
});
menu2.addRange("Skip Frames", config.face.detector, "skipFrames", 0, 50, 1, (val) => {
config.face.detector.skipFrames = parseInt(val);
config.face.emotion.skipFrames = parseInt(val);
config.face.age.skipFrames = parseInt(val);
config.hand.skipFrames = parseInt(val);
});
menu2.addRange("Min Confidence", config.face.detector, "minConfidence", 0, 1, 0.05, (val) => {
config.face.detector.minConfidence = parseFloat(val);
config.face.emotion.minConfidence = parseFloat(val);
config.hand.minConfidence = parseFloat(val);
});
menu2.addRange("Score Threshold", config.face.detector, "scoreThreshold", 0.1, 1, 0.05, (val) => {
config.face.detector.scoreThreshold = parseFloat(val);
config.hand.scoreThreshold = parseFloat(val);
config.body.scoreThreshold = parseFloat(val);
});
menu2.addRange("IOU Threshold", config.face.detector, "iouThreshold", 0.1, 1, 0.05, (val) => {
config.face.detector.iouThreshold = parseFloat(val);
config.hand.iouThreshold = parseFloat(val);
});
menu2.addHTML('<hr style="min-width: 200px; border-style: inset; border-color: dimgray">');
menu2.addChart("FPS", "FPS");
menuFX = new menu_default(document.body, "...", {top: "1rem", right: "18rem"});
menuFX.addLabel("UI Options");
menuFX.addBool("Camera Front/Back", ui, "facing", () => setupCamera());
menuFX.addBool("Use 3D Depth", ui, "useDepth");
menuFX.addBool("Draw Boxes", ui, "drawBoxes");
menuFX.addBool("Draw Points", ui, "drawPoints");
menuFX.addBool("Draw Polygons", ui, "drawPolygons");
menuFX.addBool("Fill Polygons", ui, "fillPolygons");
menuFX.addHTML('<hr style="min-width: 200px; border-style: inset; border-color: dimgray">');
menuFX.addLabel("Image Processing");
menuFX.addBool("Enabled", config.filter, "enabled");
menuFX.addRange("Image width", config.filter, "width", 0, 3840, 10, (val) => config.filter.width = parseInt(val));
menuFX.addRange("Image height", config.filter, "height", 0, 2160, 10, (val) => config.filter.height = parseInt(val));
menuFX.addRange("Brightness", config.filter, "brightness", -1, 1, 0.05, (val) => config.filter.brightness = parseFloat(val));
menuFX.addRange("Contrast", config.filter, "contrast", -1, 1, 0.05, (val) => config.filter.contrast = parseFloat(val));
menuFX.addRange("Sharpness", config.filter, "sharpness", 0, 1, 0.05, (val) => config.filter.sharpness = parseFloat(val));
menuFX.addRange("Blur", config.filter, "blur", 0, 20, 1, (val) => config.filter.blur = parseInt(val));
menuFX.addRange("Saturation", config.filter, "saturation", -1, 1, 0.05, (val) => config.filter.saturation = parseFloat(val));
menuFX.addRange("Hue", config.filter, "hue", 0, 360, 5, (val) => config.filter.hue = parseInt(val));
menuFX.addRange("Pixelate", config.filter, "pixelate", 0, 32, 1, (val) => config.filter.pixelate = parseInt(val));
menuFX.addBool("Negative", config.filter, "negative");
menuFX.addBool("Sepia", config.filter, "sepia");
menuFX.addBool("Vintage", config.filter, "vintage");
menuFX.addBool("Kodachrome", config.filter, "kodachrome");
menuFX.addBool("Technicolor", config.filter, "technicolor");
menuFX.addBool("Polaroid", config.filter, "polaroid");
}
async function main() {
log("Human: demo starting ...");
setupMenu();
document.getElementById("log").innerText = `Human: version ${human.version} TensorFlow/JS: version ${human.tf.version_core}`;
if (ui.modelsPreload) {
status("loading");
await human.load();
}
if (ui.modelsWarmup) {
status("initializing");
const warmup = new ImageData(50, 50);
await human.detect(warmup);
}
status("human: ready");
document.getElementById("loader").style.display = "none";
document.getElementById("play").style.display = "block";
}
window.onload = main;
window.onresize = setupCamera;
//# sourceMappingURL=demo-browser-index.js.map