// dist/human.esm.js var rf = Object.defineProperty; var dL = (n) => rf(n, "__esModule", {value: true}); var we = (n, t) => () => (t || (t = {exports: {}}, n(t.exports, t)), t.exports); var As = (n, t) => { dL(n); for (var e in t) rf(n, e, {get: t[e], enumerable: true}); }; var af = we(() => { }); var sf = we(() => { }); var Ts = we(() => { }); var Qr = we((A) => { "use strict"; Object.defineProperty(A, "__esModule", {value: true}); var gc = function(n, t) { return gc = 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]); }, gc(n, t); }; function qn(n, t) { gc(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 pL = 1e-7, fL = 1e-4, mL = 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; }(), of = 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 ? pL : fL; }, 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 cf(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 gL(n) { return n % 2 === 0 ? n : n + 1; } function yL(n) { for (var t = 0, e = 0; e < n.length; e++) t += n[e]; return t; } function vL(n, t) { var e = Math.random(); return t * e + (1 - e) * n; } function wL(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(fn(n, t), function() { return e + (" Shapes " + n + " and " + t + " must match"); }); } function Ur(n) { E(n != null, function() { return "The input to the tensor constructor must be a non-null value."; }); } function Br(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) Br(n[r], t, e); else t.push(n); return t; } function pt(n) { if (n.length === 0) return 1; for (var t = n[0], e = 1; e < n.length; e++) t *= n[e]; return t; } function bL(n) { return n.length === 0; } function fn(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 xL(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 LL(n) { var t = Math.ceil(Math.sqrt(n)); return [t, Math.ceil(n / t)]; } function SL(n) { for (var t = new Uint32Array(n), e = 0; e < n; ++e) t[e] = e; return cf(t), t; } function ya(n, t) { return t <= n.length ? n : n + " ".repeat(t - n.length); } function IL(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 lf(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 uf(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 Ns(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 hf(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 df(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 pf(n) { return n === "bool" || n === "complex64" || n === "float32" || n === "int32" || n === "string"; } function ff(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 mf(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 gf(n) { if (n == null) return 0; var t = 0; return n.forEach(function(e) { return t += e.length; }), t; } function or(n) { return typeof n == "string" || n instanceof String; } function yf(n) { return typeof n == "boolean"; } function vf(n) { return typeof n == "number"; } function _s(n) { return Array.isArray(n) ? _s(n[0]) : n instanceof Float32Array ? "float32" : n instanceof Int32Array || n instanceof Uint8Array ? "int32" : vf(n) ? "float32" : or(n) ? "string" : yf(n) ? "bool" : "float32"; } function cr(n) { return !!(n && n.constructor && n.call && n.apply); } function Cs(n, t) { for (var e = t; e < n; ++e) if (n % e === 0) return e; return n; } function bi(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 wf(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] = wf(n + a * o, s, e); return r; } function xi(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 wf(0, n, t); } function yc(n, t) { for (var e = Li(n, t), r = 0; r < e.length; r++) e[r] = 1; return e; } function Li(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 AL(n, t) { var e = n.reduce(function(r, i) { return r * i; }, 1); if (t == null || t === "float32") return xi(n, new Float32Array(e)); if (t === "int32") return xi(n, new Int32Array(e)); if (t === "bool") return xi(n, new Uint8Array(e)); throw new Error("Unknown data type " + t); } function vc(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 TL(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 NL(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 wc(n) { return n && n.then && typeof n.then == "function"; } var bf = "tfjsflags", xf = 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 (wc(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 = _L(this.global.location.search); if (bf in e) { var r = e[bf].split(","); r.forEach(function(i) { var a = i.split(":"), s = a[0], o = a[1]; t.urlFlags[s] = CL(s, o); }); } }, n; }(); function _L(n) { var t = {}; return n.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, function(e) { for (var r = [], i = 1; i < arguments.length; i++) r[i - 1] = arguments[i]; return RL(t, r[0], r[1]), r.join("="); }), t; } function RL(n, t, e) { n[decodeURIComponent(t)] = decodeURIComponent(e || ""); } function CL(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 Ge() { return A.ENV; } A.ENV = null; function OL(n) { A.ENV = n; } var bc; function Lf() { if (bc == 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"); bc = n; } return bc; } function EL() { var n = Lf(); return n._tfGlobals == null && (n._tfGlobals = new Map()), n._tfGlobals; } function Sf(n, t) { var e = EL(); if (e.has(n)) return e.get(n); var r = t(); return e.set(n, r), e.get(n); } var xc = "Abs", Lc = "Acos", Sc = "Acosh", Rs = "Add", Ic = "AddN", If = "All", Af = "Any", Ac = "ArgMax", Tc = "ArgMin", Nc = "Asin", _c = "Asinh", Cc = "Atan", Rc = "Atanh", Oc = "Atan2", Ec = "AvgPool", Tf = "AvgPoolBackprop", Dc = "AvgPool3D", Nf = "AvgPool3DBackprop", kc = "BatchMatMul", Fc = "BatchToSpaceND", Wc = "BroadcastTo", Os = "Cast", Uc = "Ceil", Bc = "ClipByValue", _f = "Complex", zc = "Concat", Pc = "Conv2D", Cf = "Conv2DBackpropFilter", Mc = "Conv2DBackpropInput", Hc = "Conv3D", Rf = "Conv3DBackpropFilterV2", Of = "Conv3DBackpropInputV2", Vc = "Cos", Gc = "Cosh", qc = "Cumsum", Ef = "CropAndResize", Df = "DepthToSpace", Yc = "DepthwiseConv2dNative", kf = "DepthwiseConv2dNativeBackpropFilter", Ff = "DepthwiseConv2dNativeBackpropInput", Wf = "Diag", Kc = "Dilation2D", Uf = "Dilation2DBackpropInput", Bf = "Dilation2DBackpropFilter", jc = "Div", $c = "Elu", zf = "EluGrad", Xc = "Erf", Pf = "Equal", Jc = "Exp", Zc = "Expm1", Mf = "FFT", Hf = "Fill", Vf = "FlipLeftRight", Qc = "Floor", el = "FloorDiv", tl = "FusedBatchNorm", nl = "GatherV2", Gf = "GatherNd", qf = "Greater", rl = "GreaterEqual", il = "Identity", Yf = "IFFT", Kf = "Imag", al = "IsFinite", sl = "IsInf", ol = "IsNan", jf = "Less", $f = "LessEqual", Xf = "LinSpace", cl = "Log", ll = "Log1p", Jf = "LogicalAnd", Zf = "LogicalNot", Qf = "LogicalOr", ul = "LogSoftmax", hl = "LRN", em = "LRNBackprop", dl = "Max", pl = "Maximum", fl = "MaxPool", tm = "MaxPoolBackprop", ml = "MaxPool3D", nm = "MaxPool3DBackprop", rm = "MaxPoolWithArgmax", im = "Mean", gl = "Min", yl = "Minimum", vl = "MirrorPad", wl = "Mod", bl = "Multiply", xl = "Negate", am = "NotEqual", sm = "NonMaxSuppressionV3", om = "NonMaxSuppressionV4", cm = "NonMaxSuppressionV5", Ll = "OnesLike", Sl = "OneHot", Il = "PadV2", DL = "Pool", Al = "Pow", Tl = "Prelu", lm = "Prod", um = "Range", hm = "Real", Nl = "Reciprocal", _l = "Relu", Cl = "Reshape", Rl = "ResizeNearestNeighbor", dm = "ResizeNearestNeighborGrad", Ol = "ResizeBilinear", pm = "ResizeBilinearGrad", El = "Relu6", Dl = "Reverse", kl = "Round", Fl = "Rsqrt", fm = "ScatterNd", Wl = "SelectV2", Ul = "Selu", Bl = "Slice", zl = "Sin", Pl = "Sinh", Ml = "Sign", Hl = "Sigmoid", Vl = "Softplus", Gl = "Sqrt", ql = "Sum", Yl = "SpaceToBatchND", Kl = "SplitV", jl = "Softmax", $l = "SquaredDifference", mm = "Square", Xl = "Sub", gm = "SparseToDense", ym = "StridedSlice", Jl = "Tan", Zl = "Tanh", Ql = "Tile", vm = "TopK", eu = "Transpose", wm = "Unique", tu = "Unpack", nu = "UnsortedSegmentSum", ru = "ZerosLike", iu = "Step", au = "FromPixels", bm = "RotateWithOffset", su = "_FusedMatMul", ou = "FusedConv2D", cu = "FusedDepthwiseConv2D"; var Si = Sf("kernelRegistry", function() { return new Map(); }), va = Sf("gradRegistry", function() { return new Map(); }); function uu(n, t) { var e = lu(n, t); return Si.get(e); } function hu(n) { return va.get(n); } function Es(n) { for (var t = Si.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 xm(n) { var t = n.kernelName, e = n.backendName, r = lu(t, e); Si.has(r) && console.warn("The kernel '" + t + "' for backend " + ("'" + e + "' is already registered")), Si.set(r, n); } function Lm(n) { var t = n.kernelName; va.has(t) && (Ge().getBool("DEBUG") && console.warn("Overriding the gradient for '" + t + "'")), va.set(t, n); } function kL(n, t) { var e = lu(n, t); if (!Si.has(e)) throw new Error("The kernel '" + n + "' for backend " + ("'" + t + "' is not registered")); Si.delete(e); } function FL(n) { if (!va.has(n)) throw new Error("The gradient '" + n + "' for backend is not registered"); va.delete(n); } function WL(n, t) { var e = Es(n); e.forEach(function(r) { var i = Object.assign({}, r, {backendName: t}); xm(i); }); } function lu(n, t) { return t + "_" + n; } function UL(n, t) { return t === "string" ? du(n) : Ds([n], t); } function BL(n, t) { return n instanceof Float32Array && t === "float32" || n instanceof Int32Array && t === "int32" || n instanceof Uint8Array && t === "bool"; } function Ds(n, t) { if (t === "string") throw new Error("Cannot convert a string[] to a TypedArray"); if (Array.isArray(n) && (n = Br(n)), Ge().getBool("DEBUG") && df(n, t), BL(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 pu() { return Ge().platform.now(); } function zL(n, t) { return Ge().platform.fetch(n, t); } function du(n, t) { return t === void 0 && (t = "utf-8"), t = t || "utf-8", Ge().platform.encode(n, t); } function fu(n, t) { return t === void 0 && (t = "utf-8"), t = t || "utf-8", Ge().platform.decode(n, t); } var PL = {__proto__: null, createScalarValue: UL, toTypedArray: Ds, now: pu, fetch: zL, encodeString: du, decodeString: fu, shuffle: cf, clamp: ga, nearestLargerEven: gL, sum: yL, randUniform: vL, distSquared: wL, assert: E, assertShapesMatch: Pe, assertNonNull: Ur, flatten: Br, sizeFromShape: pt, isScalarShape: bL, arraysEqual: fn, isInt: ot, tanh: xL, sizeToSquarishShape: LL, createShuffledIndices: SL, rightPad: ya, repeatedTry: IL, inferFromImplicitShape: lf, parseAxisParam: rt, squeezeShape: uf, getTypedArrayFromDType: Ns, getArrayFromDType: hf, checkConversionForErrors: df, isValidDtype: pf, hasEncodingLoss: ff, isTypedArray: Ft, bytesPerElement: mf, bytesFromStringArray: gf, isString: or, isBoolean: yf, isNumber: vf, inferDtype: _s, isFunction: cr, nearestDivisor: Cs, computeStrides: bi, toNestedArray: xi, makeOnesTypedArray: yc, makeZerosTypedArray: Li, makeZerosNestedTypedArray: AL, assertNonNegativeIntegerDimensions: vc, locToIndex: TL, indexToLoc: NL, isPromise: wc}; var VL = function() { function n(t, e) { this.backendTimer = t, this.logger = e, e == null && (this.logger = new HL()); } 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) { ML(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 ML(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 HL = 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 GL(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 qL(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 (!fn(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 Sm = 20, wa = 3, mu = 7; function KL(n, t, e, r) { var i = bi(t), a = YL(n, t, e, i), s = t.length, o = ks(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 YL(n, t, e, r) { var i = pt(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(mu)) + " + " + (parseFloat(n[1].toFixed(mu)) + "j") : or(n) ? r = "'" + n + "'" : e === "bool" ? r = Im(n) : r = parseFloat(n.toFixed(mu)).toString(), ya(r, t); } function Im(n) { return n === 0 ? "false" : "true"; } function ks(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" ? [Im(n[0])] : [n[0].toString()]; } if (c === 1) { if (o > Sm) { 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 > Sm) { for (var w = 0; w < wa; w++) { var b = w * g, L = b + g; y.push.apply(y, ks(n.slice(b, L), f, e, m, i, false)); } y.push("..."); for (var w = o - wa; w < o; w++) { var b = w * g, L = b + g; y.push.apply(y, ks(n.slice(b, L), f, e, m, i, w === o - 1)); } } else for (var w = 0; w < o; w++) { var b = w * g, L = b + g; y.push.apply(y, ks(n.slice(b, L), f, e, m, i, w === o - 1)); } var x = c === 2 ? "," : ""; y[0] = "[" + y[0] + x; for (var w = 1; w < y.length - 1; w++) y[w] = " " + y[w] + x; 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 Fs = function() { function n(t, e, r) { var i = this; if (this.dtype = e, this.shape = t.slice(), this.size = pt(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 || hf(e, this.size), this.strides = bi(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 Rn().makeTensor(this.values, this.shape, this.dtype); }, n; }(), Rn = null, Ii = null; function jL(n) { Rn = n; } function $L(n) { Ii = 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 = pt(t), this.strides = bi(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, Ii.buffer(this.shape, this.dtype, t)]; } }); }); }, n.prototype.bufferSync = function() { return Ii.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, xi(this.shape, t)]; } }); }); }, n.prototype.arraySync = function() { return xi(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 = Rn().read(this.dataId), this.dtype === "string" ? [4, t] : [3, 2]; case 1: e = r.sent(); try { return [2, e.map(function(i) { return fu(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 = Rn().readSync(this.dataId); if (this.dtype === "string") try { return t.map(function(e) { return fu(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, Rn().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; Rn().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), Ii.print(this, t); }, n.prototype.clone = function() { return this.throwIfDisposed(), Ii.clone(this); }, n.prototype.toString = function(t) { t === void 0 && (t = false); var e = this.dataSync(); return KL(e, this.shape, this.dtype, t); }, n.prototype.cast = function(t) { return this.throwIfDisposed(), Ii.cast(this, t); }, n.prototype.variable = function(t, e, r) { return t === void 0 && (t = true), this.throwIfDisposed(), Rn().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) { qn(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 (!fn(e.shape, this.shape)) throw new Error("shape of the new value (" + e.shape + ") and " + ("previous value (" + this.shape + ") must match")); Rn().disposeTensor(this), this.dataId = e.dataId, Rn().incRef(this, null); }, t.prototype.dispose = function() { Rn().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 gu; (function(n) { n.float32 = "float32", n.int32 = "int32", n.bool = "int32", n.complex64 = "complex64"; })(gu || (gu = {})); var yu; (function(n) { n.float32 = "float32", n.int32 = "int32", n.bool = "bool", n.complex64 = "complex64"; })(yu || (yu = {})); var vu; (function(n) { n.float32 = "float32", n.int32 = "float32", n.bool = "float32", n.complex64 = "complex64"; })(vu || (vu = {})); var wu; (function(n) { n.float32 = "complex64", n.int32 = "complex64", n.bool = "complex64", n.complex64 = "complex64"; })(wu || (wu = {})); var XL = {float32: vu, int32: gu, bool: yu, complex64: wu}; function Ws(n, t) { if (n === "string" || t === "string") { if (n === "string" && t === "string") return "string"; throw new Error("Can not upcast " + n + " with " + t); } return XL[n][t]; } function JL(n) { return Ws(n, "int32"); } function ct(n, t) { if (n.dtype === t.dtype) return [n, t]; var e = Ws(n.dtype, t.dtype); return [n.cast(e), t.cast(e)]; } function Am(n, t) { E(n.dtype === t.dtype, function() { return "The dtypes of the first(" + n.dtype + ") and" + (" second(" + t.dtype + ") input must match"); }); } function ZL(n, t) { return t.some(function(e) { return e.id === n.id; }); } function bu(n) { var t = [], e = new Set(); return Tm(n, t, e), t; } function Tm(n, t, e) { if (n == null) return; if (n instanceof K) { t.push(n); return; } if (!QL(n)) return; var r = n; for (var i in r) { var a = r[i]; e.has(a) || (e.add(a), Tm(a, t, e)); } } function QL(n) { return Array.isArray(n) || typeof n == "object"; } var eS = {__proto__: null, makeTypesMatch: ct, assertTypesMatch: Am, isTensorInList: ZL, getTensorsInContainer: bu}; var Nm = 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; }(), rS = function() { function n(t) { this.ENV = t, this.registry = {}, this.registryFactory = {}, this.pendingBackendInitId = 0, this.state = new Nm(); } 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 VL(this.backendInstance), [2, true]; } }); }); }, n.prototype.setupRegisteredKernels = function() { var t = this, e = Es(this.backendName); e.forEach(function(r) { r.setupFunc != null && r.setupFunc(t.backendInstance); }); }, n.prototype.disposeRegisteredKernels = function(t) { var e = this, r = Es(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 of) && 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, Os, 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 = uu(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 L = Array.isArray(g) ? g : [g]; c.shouldCheckForMemLeaks() && c.checkKernelForMemLeak(i, b, L); var x = L.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, x); if (N == null) { o == null && (o = []); var I = x.filter(function(C, O) { return o[O]; }); N = (s || []).slice().concat(I); } u = c.saveTensorsForBackwardMode(N); } return x; }; else { var y = function(b) { if (!h) return; u = b.map(function(L) { return c.keep(c.clone(L)); }); }; f = function() { var b = c.backend.numDataIds(); g = c.tidy(function() { return t(c.backend, y); }); var L = Array.isArray(g) ? g : [g]; return c.shouldCheckForMemLeaks() && c.checkKernelForMemLeak(i, b, L), L; }; } 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 = hu(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" && or(t[0]) && (a = t.map(function(u) { return du(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 = gf(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 * mf(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 = hu(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 = Li(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 = bu(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 = GL(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 ? tS(s.shape) : r, qL(c, o, function(u) { return a.tidy(u); }, nS); 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(cr(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(cr(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 = pu(), [4, this.backend.time(t)]; case 1: return r = i.sent(), r.wallMs = pu() - 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 Nm(); 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 tS(n) { var t = yc(pt(n), "float32"); return z.makeTensor(t, n, "float32"); } function _m() { var n = Lf(); if (n._tfengine == null) { var t = new xf(n); n._tfengine = new rS(t); } return OL(n._tfengine.ENV), jL(function() { return n._tfengine; }), n._tfengine; } var z = _m(); function nS(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, Rs); } function iS() { return typeof navigator != "undefined" && navigator != null; } function aS() { if (iS()) { 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 Cm() { return typeof window != "undefined" && window.document != null || typeof WorkerGlobalScope != "undefined"; } var sS = {__proto__: null, isMobile: aS, isBrowser: Cm}; var Yn = Ge(); Yn.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."); }); Yn.registerFlag("IS_BROWSER", function() { return Cm(); }); Yn.registerFlag("IS_NODE", function() { return typeof process != "undefined" && typeof process.versions != "undefined" && typeof process.versions.node != "undefined"; }); Yn.registerFlag("IS_CHROME", function() { return typeof navigator != "undefined" && navigator != null && navigator.userAgent != null && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor); }); Yn.registerFlag("PROD", function() { return false; }); Yn.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY", function() { return Yn.getBool("DEBUG"); }); Yn.registerFlag("DEPRECATION_WARNINGS_ENABLED", function() { return true; }); Yn.registerFlag("IS_TEST", function() { return false; }); function On(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) && Ge().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY") && Rm(n, r, []), r; } function Rm(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) Rm(n[i], r, e.concat(i)); } function Om(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 Om(r, n.dtype, t, e), n; var i = _s(n); if (i !== "string" && ["bool", "int32", "float32"].indexOf(r) >= 0 && (i = r), Om(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 = On(n, i); !Ft(n) && !Array.isArray(n) && (n = [n]); var o = true, c = i !== "string" ? Ds(n, i) : Br(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 Em = "__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 + Em; 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 wc(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 oS(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, _f); } var lr = U({complex_: oS}); function ur(n, t, e, r) { if (r == null && (r = _s(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) { vc(t); var i = pt(t), a = pt(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 !== pt(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" ? Ds(n, r) : Br(n, [], true), z.makeTensor(n, t, r); } function hr(n, t, e) { var r = On(n, e); return ur(n, t, r, e); } var xu = {float32: 4, float16: 2, int32: 4, uint16: 2, uint8: 1, bool: 1, complex64: 8}; var Us = 4; function lS(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, L, x, 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) + Us * g.length, w = new Uint8Array(y), b = 0, L = 0; L < g.length; L++) x = g[L], N = new Uint8Array(new Uint32Array([x.length]).buffer), w.set(N, b), b += Us, w.set(x, b), b += x.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: cS(o), specs: e}]; } }); }); } function Dm(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 = pt(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 = xu[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 = uS()), 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 = pt(o.shape); d = []; for (var y = 0; y < b; y++) { var L = new Uint32Array(n.slice(i, i + Us))[0]; i += Us; var x = new Uint8Array(n.slice(i, i + L)); d.push(x), i += L; } } else { var N = xu[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 = hr(I, u, "float32"), D = hr(C, u, "float32"); e[c] = lr(O, D), O.dispose(), D.dispose(); } else throw new Error("Unsupported dtype in weight '" + c + "': " + l); i += h * N; } l !== "complex64" && (e[c] = hr(d, u, l)); } return e; } function cS(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 Lu = typeof Buffer != "undefined" && (typeof Blob == "undefined" || typeof atob == "undefined" || typeof btoa == "undefined"); function km(n) { return Lu ? Buffer.byteLength(n) : new Blob([n]).size; } function hS(n) { if (Lu) 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 dS(n) { if (Lu) { 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 Su(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 Fm(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 : km(JSON.stringify(n.modelTopology)), weightSpecsBytes: n.weightSpecs == null ? 0 : km(JSON.stringify(n.weightSpecs)), weightDataBytes: n.weightData == null ? 0 : n.weightData.byteLength}; } function pS() { 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 fS() { 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 mS() { for (var n = new Uint32Array(64), t = 0; t < 64; t++) n[t] = 1024; return n[0] = n[32] = 0, n; } function uS() { var n = pS(), t = fS(), e = mS(); 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; }(), gS = function(n) { return rn.registerSaveRouter(n); }, yS = function(n) { return rn.registerLoadRouter(n); }, vS = function(n) { return rn.getSaveHandlers(n); }, wS = function(n, t) { return rn.getLoadHandlers(n, t); }; var Iu = "tensorflowjs", Au = 1, zr = "models_store", dr = "model_info_store"; function Wm() { if (!Ge().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 Tu(n) { var t = n.result; t.createObjectStore(zr, {keyPath: "modelPath"}), t.createObjectStore(dr, {keyPath: "modelPath"}); } var Ai = function() { function n(t) { if (this.indexedDB = Wm(), 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(Iu, Au); s.onupgradeneeded = function() { return Tu(s); }, s.onsuccess = function() { var o = s.result; if (e == null) { var c = o.transaction(zr, "readonly"), l = c.objectStore(zr), 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(dr, "readwrite"), p = d.objectStore(dr), f = p.put({modelPath: r.modelPath, modelArtifactsInfo: h}), m; f.onsuccess = function() { m = o.transaction(zr, "readwrite"); var g = m.objectStore(zr), y = g.put({modelPath: r.modelPath, modelArtifacts: e, modelArtifactsInfo: h}); y.onsuccess = function() { return i({modelArtifactsInfo: h}); }, y.onerror = function(w) { p = d.objectStore(dr); var b = p.delete(r.modelPath); b.onsuccess = function() { return o.close(), a(y.error); }, b.onerror = function(L) { 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; }(), Um = function(n) { return Ge().getBool("IS_BROWSER") && (!Array.isArray(n) && n.startsWith(Ai.URL_SCHEME)) ? bS(n.slice(Ai.URL_SCHEME.length)) : null; }; rn.registerSaveRouter(Um); rn.registerLoadRouter(Um); function bS(n) { return new Ai(n); } function xS(n) { return n.startsWith(Ai.URL_SCHEME) ? n.slice(Ai.URL_SCHEME.length) : n; } var LS = function() { function n() { this.indexedDB = Wm(); } 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(Iu, Au); a.onupgradeneeded = function() { return Tu(a); }, a.onsuccess = function() { var s = a.result, o = s.transaction(dr, "readonly"), c = o.objectStore(dr), 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 = xS(t), [2, new Promise(function(i, a) { var s = e.indexedDB.open(Iu, Au); s.onupgradeneeded = function() { return Tu(s); }, s.onsuccess = function() { var o = s.result, c = o.transaction(dr, "readwrite"), l = c.objectStore(dr), 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(zr, "readwrite"); var f = h.objectStore(zr), 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 Kn = "/", Ti = "tensorflowjs_models", Bm = "info", SS = "model_topology", IS = "weight_specs", AS = "weight_data", TS = "model_metadata"; function zm(n) { return {info: [Ti, n, Bm].join(Kn), topology: [Ti, n, SS].join(Kn), weightSpecs: [Ti, n, IS].join(Kn), weightData: [Ti, n, AS].join(Kn), modelMetadata: [Ti, n, TS].join(Kn)}; } function NS(n) { var t = n.split(Kn); if (t.length < 3) throw new Error("Invalid key format: " + n); return t.slice(1, t.length - 1).join(Kn); } function _S(n) { return n.startsWith(Ni.URL_SCHEME) ? n.slice(Ni.URL_SCHEME.length) : n; } var Ni = function() { function n(t) { if (!Ge().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 = zm(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, hS(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 = dS(o), [2, e]; }); }); }, n.URL_SCHEME = "localstorage://", n; }(), Pm = function(n) { return Ge().getBool("IS_BROWSER") && (!Array.isArray(n) && n.startsWith(Ni.URL_SCHEME)) ? CS(n.slice(Ni.URL_SCHEME.length)) : null; }; rn.registerSaveRouter(Pm); rn.registerLoadRouter(Pm); function CS(n) { return new Ni(n); } var RS = function() { function n() { E(Ge().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 = Ti + Kn, r = Kn + Bm, i = 0; i < this.LS.length; ++i) a = this.LS.key(i), a.startsWith(e) && a.endsWith(r) && (s = NS(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 = _S(t), e = zm(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 _i = "://", pr = 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(_i) && (t = t.slice(0, t.indexOf(_i))), 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 Bs(n) { if (n.indexOf(_i) === -1) throw new Error("The url string provided does not contain a scheme. Supported schemes are: " + ("" + pr.getSchemes().join(","))); return {scheme: n.split(_i)[0], path: n.split(_i)[1]}; } function Mm(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 = Bs(n).scheme, c = Bs(n).path, l = o === Bs(n).scheme, [4, i.load()]; case 1: return u = d.sent(), e && l ? [4, pr.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, pr.getManager(o).removeModel(c)] : [3, 6]; case 5: d.sent(), d.label = 6; case 6: return [2, h.modelArtifactsInfo]; } }); }); } function OS() { 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 = pr.getSchemes(), t = {}, e = 0, r = n, c.label = 1; case 1: return e < r.length ? (i = r[e], [4, pr.getManager(i).listModels()]) : [3, 4]; case 2: a = c.sent(); for (s in a) o = i + _i + s, t[o] = a[s]; c.label = 3; case 3: return e++, [3, 1]; case 4: return [2, t]; } }); }); } function ES(n) { return pe(this, void 0, void 0, function() { var t, e; return fe(this, function(r) { return t = Bs(n), e = pr.getManager(t.scheme), [2, e.removeModel(t.path)]; }); }); } function DS(n, t) { return pe(this, void 0, void 0, function() { var e; return fe(this, function(r) { return e = false, [2, Mm(n, t, e)]; }); }); } function kS(n, t) { return pe(this, void 0, void 0, function() { var e; return fe(this, function(r) { return e = true, [2, Mm(n, t, e)]; }); }); } var FS = 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 (Ge().get("IS_BROWSER")) { Ge().setPlatform("browser", new FS()); try { pr.registerManager(Ni.URL_SCHEME, new RS()); } catch (n) { } try { pr.registerManager(Ai.URL_SCHEME, new LS()); } catch (n) { } } var WS = {importFetch: function() { return af(); }}, Nu, US = function() { function n() { this.util = sf(), this.textEncoder = new this.util.TextEncoder(); } return n.prototype.fetch = function(t, e) { return Ge().global.fetch != null ? Ge().global.fetch(t, e) : (Nu == null && (Nu = WS.importFetch()), Nu(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; }(); Ge().get("IS_NODE") && Ge().setPlatform("node", new US()); function En(n, t, e) { return t === void 0 && (t = "float32"), t = t || "float32", vc(n), new Fs(n, t, e); } function BS(n, t) { var e = R(n, "x", "cast"); if (!pf(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, Os, i); } var he = U({cast_: BS}); function zS(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, il); } var Pr = U({clone_: zS}); function Hm(n, t) { t === void 0 && (t = false), console.log(n.toString(t)); } _m(); var PS = {buffer: En, cast: he, clone: Pr, print: Hm}; $L(PS); var MS = "model", HS = ".json", VS = ".weights.bin"; function Vm(n) { return new Promise(function(t) { return setTimeout(t); }).then(n); } var _u = function() { function n(t) { if (!Ge().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 = MS), this.modelTopologyFileName = t + HS, this.weightDataFileName = t + VS; } 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, Vm(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, Vm(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; }(), GS = 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 L = b.target.result, x = f.indexOf(y); m[x] = L, m.indexOf(null) === -1 && a({modelTopology: u, weightSpecs: p, weightData: Su(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 Fm(l.name); }), a = {}, s = 0, o = t; s < o.length; s++) { var c = o[s]; c.paths.forEach(function(l) { var u = Fm(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; }(), YS = function(n) { return Ge().getBool("IS_BROWSER") && (!Array.isArray(n) && n.startsWith(_u.URL_SCHEME)) ? qS(n.slice(_u.URL_SCHEME.length)) : null; }; rn.registerSaveRouter(YS); function qS(n) { return n === void 0 && (n = "model"), new _u(n); } function KS(n) { return new GS(n); } function Gm(n, t, e, r) { s(n), e = e == null ? 0 : e, r = r == null ? 1 : r, 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 qm(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 ? Ge().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, Gm(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, Gm(c, t.onProgress, l, u)]; case 7: d = p.sent(), p.label = 8; case 8: return h = d, [2, h]; } }); }); } function jS(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 qm(o, {requestInit: r}); }, a = Ym(i), [2, a(n, t, e)]; }); }); } function Ym(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 L = "quantization" in b ? b.quantization.dtype : b.dtype, x = xu[L] * pt(b.shape), N = function() { a[y] = true, s[y] == null && (s[y] = []), s[y].push({manifestEntry: b, groupOffset: w, sizeBytes: x}); }; i != null ? i.forEach(function(I, C) { I === b.name && (N(), o[C] = true); }) : N(), c.push(b.name), w += x; }); }), !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 L = new ArrayBuffer(w), x = new Uint8Array(L), N = 0, I = 0; I < y; I++) { var C = new Uint8Array(d[f + I]); x.set(C, N), N += C.byteLength; } var O = s[g]; O.forEach(function(D) { var F = L.slice(D.groupOffset, D.groupOffset + D.sizeBytes), k = Dm(F, [D.manifestEntry]); for (var B in k) p[B] = k[B]; }), f += y; }), [2, p]; } }); }); }; } var $S = "application/octet-stream", XS = "application/json", Km = 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 = Ge().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: XS}), "model.json"), t.weightData != null && e.body.append("model.weights.bin", new Blob([t.weightData], {type: $S}), "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, L, x, N; return fe(this, function(I) { switch (I.label) { case 0: for (e = Array.isArray(this.path) ? this.path[1] : this.path, r = JS(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 ? (L = (b = h.push).apply, x = [h], [4, Promise.all(d)]) : [3, 2]; case 1: L.apply(b, x.concat([I.sent()])), I.label = 2; case 2: return [4, qm(h, {requestInit: this.requestInit, fetchFunc: this.fetch, onProgress: this.onProgress})]; case 3: return N = I.sent(), [2, [o, Su(N)]]; } }); }); }, n.URL_SCHEME_REGEX = /^https?:\/\//, n; }(); function JS(n) { var t = n.lastIndexOf("/"), e = n.lastIndexOf("?"), r = n.substring(0, t), i = e > t ? n.substring(e) : ""; return [r + "/", i]; } function Cu(n) { return n.match(Km.URL_SCHEME_REGEX) != null; } var jm = 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 Cu(r); }) : e = Cu(n), e ? Ru(n, t) : null; }; rn.registerSaveRouter(jm); rn.registerLoadRouter(jm); function Ru(n, t) { return new Km(n, t); } function ZS(n, t) { return Ru(n, t); } var Ou = 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; }(), QS = 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 eI(n, t, e, r) { if (arguments.length === 1) { var i = n.modelTopology != null || n.weightSpecs != null; return i ? new Ou(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 Ou({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 Ou({modelTopology: n, weightSpecs: t, weightData: e, trainingConfig: r}); } function tI(n) { return new QS(n); } var nI = {__proto__: null, browserFiles: KS, browserHTTPRequest: ZS, concatenateArrayBuffers: Su, decodeWeights: Dm, encodeWeights: lS, fromMemory: eI, getLoadHandlers: wS, getModelArtifactsInfoForJSON: Ia, getSaveHandlers: vS, http: Ru, isHTTPScheme: Cu, loadWeights: jS, registerLoadRouter: yS, registerSaveRouter: gS, weightsLoaderFactory: Ym, withSaveHandler: tI, copyModel: DS, listModels: OS, moveModel: kS, removeModel: ES}; function rI(n, t) { var e = R(n, "x", "reshape", null), r = {x: e}, i = {shape: t}, a = function(s, o) { return t = lf(t, e.size), E(e.size === pt(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, Cl, i); } var Y = U({reshape_: rI}); function iI(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 = pt(g), b = pt(y), L = w === b || w === 1 || b === 1; E(a.rank >= 2 && s.rank >= 2 && L, 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 x = w > b ? g : y, N = x.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, kc, l); } var Ue = U({matMul_: iI}); function aI(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, Sl, c); } var zs = U({oneHot_: aI}); function sI(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, eu, i); } var Tt = U({transpose_: sI}); function oI(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 = zs(he(r, "int32"), e), s = zs(he(i, "int32"), e), o = Tt(a), c = Ue(o, s); return he(c, "int32"); } var cI = U({confusionMatrix_: oI}); var lI = {__proto__: null, confusionMatrix: cI}; function $m(n, t, e) { if (Ur(n), t != null && t.length !== 3) throw new Error("tensor3d() requires shape to have three numbers"); var r = On(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 ur(n, t, r, e); } var Ci; function uI(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