// dist/human.esm.js var Hp = Object.defineProperty; var eL = (n) => Hp(n, "__esModule", {value: true}); var we = (n, t) => () => (t || (t = {exports: {}}, n(t.exports, t)), t.exports); var vs = (n, t) => { eL(n); for (var e in t) Hp(n, e, {get: t[e], enumerable: true}); }; var Vp = we(() => { }); var Gp = we(() => { }); var ws = we(() => { }); var ei = we((A) => { "use strict"; Object.defineProperty(A, "__esModule", {value: true}); var uc = function(n, t) { return uc = Object.setPrototypeOf || {__proto__: []} instanceof Array && function(e, r) { e.__proto__ = r; } || function(e, r) { for (var i in r) r.hasOwnProperty(i) && (e[i] = r[i]); }, uc(n, t); }; function Yn(n, t) { uc(n, t); function e() { this.constructor = n; } n.prototype = t === null ? Object.create(t) : (e.prototype = t.prototype, new e()); } function pe(n, t, e, r) { return new (e || (e = Promise))(function(i, a) { function s(l) { try { c(r.next(l)); } catch (u) { a(u); } } function o(l) { try { c(r.throw(l)); } catch (u) { a(u); } } function c(l) { l.done ? i(l.value) : new e(function(u) { u(l.value); }).then(s, o); } c((r = r.apply(n, t || [])).next()); }); } function fe(n, t) { var e = {label: 0, sent: function() { if (a[0] & 1) throw a[1]; return a[1]; }, trys: [], ops: []}, r, i, a, s; return s = {next: o(0), throw: o(1), return: o(2)}, typeof Symbol == "function" && (s[Symbol.iterator] = function() { return this; }), s; function o(l) { return function(u) { return c([l, u]); }; } function c(l) { if (r) throw new TypeError("Generator is already executing."); for (; e; ) try { if (r = 1, i && (a = l[0] & 2 ? i.return : l[0] ? i.throw || ((a = i.return) && a.call(i), 0) : i.next) && !(a = a.call(i, l[1])).done) return a; (i = 0, a) && (l = [l[0] & 2, a.value]); switch (l[0]) { case 0: case 1: a = l; break; case 4: return e.label++, {value: l[1], done: false}; case 5: e.label++, i = l[1], l = [0]; continue; case 7: l = e.ops.pop(), e.trys.pop(); continue; default: if (!(a = e.trys, a = a.length > 0 && a[a.length - 1]) && (l[0] === 6 || l[0] === 2)) { e = 0; continue; } if (l[0] === 3 && (!a || l[1] > a[0] && l[1] < a[3])) { e.label = l[1]; break; } if (l[0] === 6 && e.label < a[1]) { e.label = a[1], a = l; break; } if (a && e.label < a[2]) { e.label = a[2], e.ops.push(l); break; } a[2] && e.ops.pop(), e.trys.pop(); continue; } l = t.call(n, e); } catch (u) { l = [6, u], i = 0; } finally { r = a = 0; } if (l[0] & 5) throw l[1]; return {value: l[0] ? l[1] : void 0, done: true}; } } var tL = 1e-7, nL = 1e-4, rL = function() { function n(t, e) { this.backend = t, this.dataMover = e, this.data = new WeakMap(), this.dataIdsCount = 0; } return n.prototype.get = function(t) { return this.data.has(t) || this.dataMover.moveData(this.backend, t), this.data.get(t); }, n.prototype.set = function(t, e) { this.dataIdsCount++, this.data.set(t, e); }, n.prototype.has = function(t) { return this.data.has(t); }, n.prototype.delete = function(t) { return this.dataIdsCount--, this.data.delete(t); }, n.prototype.numDataIds = function() { return this.dataIdsCount; }, n; }(), qp = function() { function n() { } return n.prototype.time = function(t) { return X("time"); }, n.prototype.read = function(t) { return X("read"); }, n.prototype.readSync = function(t) { return X("readSync"); }, n.prototype.numDataIds = function() { return X("numDataIds"); }, n.prototype.disposeData = function(t) { return X("disposeData"); }, n.prototype.write = function(t, e, r) { return X("write"); }, n.prototype.move = function(t, e, r, i) { return X("move"); }, n.prototype.memory = function() { return X("memory"); }, n.prototype.floatPrecision = function() { return X("floatPrecision"); }, n.prototype.epsilon = function() { return this.floatPrecision() === 32 ? tL : nL; }, n.prototype.batchMatMul = function(t, e, r, i) { return X("batchMatMul"); }, n.prototype.fusedBatchMatMul = function(t) { var e = t.a, r = t.b, i = t.transposeA, a = t.transposeB, s = t.bias, o = t.activation, c = t.preluActivationWeights; return X("fusedBatchMatMul"); }, n.prototype.slice = function(t, e, r) { return X("slice"); }, n.prototype.stridedSlice = function(t, e, r, i) { return X("stridedSlice"); }, n.prototype.unstack = function(t, e) { return X("unstack"); }, n.prototype.reverse = function(t, e) { return X("reverse"); }, n.prototype.concat = function(t, e) { return X("concat"); }, n.prototype.neg = function(t) { return X("neg"); }, n.prototype.add = function(t, e) { return X("add"); }, n.prototype.addN = function(t) { return X("addN"); }, n.prototype.subtract = function(t, e) { return X("subtract"); }, n.prototype.multiply = function(t, e) { return X("multiply"); }, n.prototype.realDivide = function(t, e) { return X("realDivide"); }, n.prototype.floorDiv = function(t, e) { return X("floorDiv"); }, n.prototype.sum = function(t, e) { return X("sum"); }, n.prototype.prod = function(t, e) { return X("prod"); }, n.prototype.unsortedSegmentSum = function(t, e, r) { return X("unsortedSegmentSum"); }, n.prototype.argMin = function(t, e) { return X("argMin"); }, n.prototype.argMax = function(t, e) { return X("argMax"); }, n.prototype.equal = function(t, e) { return X("equal"); }, n.prototype.notEqual = function(t, e) { return X("notEqual"); }, n.prototype.less = function(t, e) { return X("less"); }, n.prototype.lessEqual = function(t, e) { return X("lessEqual"); }, n.prototype.greater = function(t, e) { return X("greater"); }, n.prototype.greaterEqual = function(t, e) { return X("greaterEqual"); }, n.prototype.logicalNot = function(t) { return X("logicalNot"); }, n.prototype.logicalAnd = function(t, e) { return X("logicalAnd"); }, n.prototype.logicalOr = function(t, e) { return X("logicalOr"); }, n.prototype.where = function(t) { return X("where"); }, n.prototype.select = function(t, e, r) { return X("select"); }, n.prototype.topk = function(t, e, r) { return X("topk"); }, n.prototype.min = function(t, e) { return X("min"); }, n.prototype.minimum = function(t, e) { return X("minimum"); }, n.prototype.mod = function(t, e) { return X("mod"); }, n.prototype.max = function(t, e) { return X("max"); }, n.prototype.maximum = function(t, e) { return X("maximum"); }, n.prototype.all = function(t, e) { return X("all"); }, n.prototype.any = function(t, e) { return X("any"); }, n.prototype.squaredDifference = function(t, e) { return X("squaredDifference"); }, n.prototype.ceil = function(t) { return X("ceil"); }, n.prototype.floor = function(t) { return X("floor"); }, n.prototype.round = function(t) { return X("round"); }, n.prototype.sign = function(t) { return X("sign"); }, n.prototype.isNaN = function(t) { return X("isNaN"); }, n.prototype.isInf = function(t) { return X("isInf"); }, n.prototype.isFinite = function(t) { return X("isFinite"); }, n.prototype.pow = function(t, e) { return X("pow"); }, n.prototype.exp = function(t) { return X("exp"); }, n.prototype.expm1 = function(t) { return X("expm1"); }, n.prototype.softmax = function(t, e) { return X("softmax"); }, n.prototype.log = function(t) { return X("log"); }, n.prototype.log1p = function(t) { return X("log1p"); }, n.prototype.sqrt = function(t) { return X("sqrt"); }, n.prototype.rsqrt = function(t) { return X("rsqrt"); }, n.prototype.square = function(t) { return X("square"); }, n.prototype.reciprocal = function(t) { return X("reciprocal"); }, n.prototype.relu = function(t) { return X("relu"); }, n.prototype.relu6 = function(t) { return X("relu6"); }, n.prototype.prelu = function(t, e) { return X("prelu"); }, n.prototype.elu = function(t) { return X("elu"); }, n.prototype.eluDer = function(t, e) { return X("eluDer"); }, n.prototype.selu = function(t) { return X("selu"); }, n.prototype.int = function(t) { return X("int"); }, n.prototype.clip = function(t, e, r) { return X("clip"); }, n.prototype.abs = function(t) { return X("abs"); }, n.prototype.complexAbs = function(t) { return X("complexAbs"); }, n.prototype.sigmoid = function(t) { return X("sigmoid"); }, n.prototype.softplus = function(t) { return X("softplus"); }, n.prototype.sin = function(t) { return X("sin"); }, n.prototype.cos = function(t) { return X("cos"); }, n.prototype.tan = function(t) { return X("tan"); }, n.prototype.asin = function(t) { return X("asin"); }, n.prototype.acos = function(t) { return X("acos"); }, n.prototype.atan = function(t) { return X("atan"); }, n.prototype.atan2 = function(t, e) { return X("atan2"); }, n.prototype.sinh = function(t) { return X("sinh"); }, n.prototype.cosh = function(t) { return X("cosh"); }, n.prototype.tanh = function(t) { return X("tanh"); }, n.prototype.asinh = function(t) { return X("asinh"); }, n.prototype.acosh = function(t) { return X("acosh"); }, n.prototype.atanh = function(t) { return X("atanh"); }, n.prototype.erf = function(t) { return X("erf"); }, n.prototype.step = function(t, e) { return X("step"); }, n.prototype.fusedConv2d = function(t) { var e = t.input, r = t.filter, i = t.convInfo, a = t.bias, s = t.activation, o = t.preluActivationWeights; return X("fusedConv2d"); }, n.prototype.conv2d = function(t, e, r) { return X("conv2d"); }, n.prototype.conv2dDerInput = function(t, e, r) { return X("conv2dDerInput"); }, n.prototype.conv2dDerFilter = function(t, e, r) { return X("conv2dDerFilter"); }, n.prototype.fusedDepthwiseConv2D = function(t) { var e = t.input, r = t.filter, i = t.convInfo, a = t.bias, s = t.activation, o = t.preluActivationWeights; return X("fusedDepthwiseConv2D"); }, n.prototype.depthwiseConv2D = function(t, e, r) { return X("depthwiseConv2D"); }, n.prototype.depthwiseConv2DDerInput = function(t, e, r) { return X("depthwiseConv2DDerInput"); }, n.prototype.depthwiseConv2DDerFilter = function(t, e, r) { return X("depthwiseConv2DDerFilter"); }, n.prototype.conv3d = function(t, e, r) { return X("conv3d"); }, n.prototype.conv3dDerInput = function(t, e, r) { return X("conv3dDerInput"); }, n.prototype.conv3dDerFilter = function(t, e, r) { return X("conv3dDerFilter"); }, n.prototype.maxPool = function(t, e) { return X("maxPool"); }, n.prototype.maxPoolBackprop = function(t, e, r, i) { return X("maxPoolBackprop"); }, n.prototype.avgPool = function(t, e) { return X("avgPool"); }, n.prototype.avgPoolBackprop = function(t, e, r) { return X("avgPoolBackprop"); }, n.prototype.avgPool3d = function(t, e) { return X("avgPool3d"); }, n.prototype.avgPool3dBackprop = function(t, e, r) { return X("avgPool3dBackprop"); }, n.prototype.maxPool3d = function(t, e) { return X("maxPool3d"); }, n.prototype.maxPool3dBackprop = function(t, e, r, i) { return X("maxPool3dBackprop"); }, n.prototype.reshape = function(t, e) { return X("reshape"); }, n.prototype.cast = function(t, e) { return X("cast"); }, n.prototype.tile = function(t, e) { return X("tile"); }, n.prototype.pad = function(t, e, r) { return X("pad"); }, n.prototype.transpose = function(t, e) { return X("transpose"); }, n.prototype.gather = function(t, e, r) { return X("gather"); }, n.prototype.gatherND = function(t, e) { return X("gatherND"); }, n.prototype.scatterND = function(t, e, r) { return X("scatterND"); }, n.prototype.batchToSpaceND = function(t, e, r) { return X("batchToSpaceND"); }, n.prototype.spaceToBatchND = function(t, e, r) { return X("spaceToBatchND"); }, n.prototype.resizeBilinear = function(t, e, r, i) { return X("resizeBilinear"); }, n.prototype.resizeBilinearBackprop = function(t, e, r) { return X("resizeBilinearBackprop"); }, n.prototype.resizeNearestNeighbor = function(t, e, r, i) { return X("resizeNearestNeighbor"); }, n.prototype.resizeNearestNeighborBackprop = function(t, e, r) { return X("resizeNearestNeighborBackprop"); }, n.prototype.batchNorm = function(t, e, r, i, a, s) { return X("batchNorm"); }, n.prototype.localResponseNormalization4D = function(t, e, r, i, a) { return X("localResponseNormalization4D"); }, n.prototype.LRNGrad = function(t, e, r, i, a, s, o) { return X("LRNGrad"); }, n.prototype.multinomial = function(t, e, r, i) { return X("multinomial"); }, n.prototype.oneHot = function(t, e, r, i) { return X("oneHot"); }, n.prototype.cumsum = function(t, e, r, i) { return X("cumsum"); }, n.prototype.nonMaxSuppression = function(t, e, r, i, a) { return X("nonMaxSuppression"); }, n.prototype.fft = function(t) { return X("fft"); }, n.prototype.ifft = function(t) { return X("ifft"); }, n.prototype.complex = function(t, e) { return X("complex"); }, n.prototype.real = function(t) { return X("real"); }, n.prototype.imag = function(t) { return X("imag"); }, n.prototype.cropAndResize = function(t, e, r, i, a, s) { return X("cropAndResize"); }, n.prototype.depthToSpace = function(t, e, r) { return X("depthToSpace"); }, n.prototype.split = function(t, e, r) { return X("split"); }, n.prototype.sparseToDense = function(t, e, r, i) { return X("sparseToDense"); }, n.prototype.diag = function(t) { return X("diag"); }, n.prototype.fill = function(t, e, r) { return X("fill"); }, n.prototype.onesLike = function(t) { return X("onesLike"); }, n.prototype.zerosLike = function(t) { return X("zerosLike"); }, n.prototype.linspace = function(t, e, r) { return X("linspace"); }, n.prototype.dispose = function() { return X("dispose"); }, n; }(); function X(n) { throw new Error("'" + n + "' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen"); } function Yp(n) { for (var t = n.length, e = 0, r = 0; t > 0; ) r = Math.random() * t | 0, t--, e = n[t], n[t] = n[r], n[r] = e; } function ga(n, t, e) { return Math.max(n, Math.min(t, e)); } function iL(n) { return n % 2 === 0 ? n : n + 1; } function aL(n) { for (var t = 0, e = 0; e < n.length; e++) t += n[e]; return t; } function sL(n, t) { var e = Math.random(); return t * e + (1 - e) * n; } function oL(n, t) { for (var e = 0, r = 0; r < n.length; r++) { var i = Number(n[r]) - Number(t[r]); e += i * i; } return e; } function E(n, t) { if (!n) throw new Error(typeof t == "string" ? t : t()); } function Pe(n, t, e) { e === void 0 && (e = ""), E(pn(n, t), function() { return e + (" Shapes " + n + " and " + t + " must match"); }); } function Br(n) { E(n != null, function() { return "The input to the tensor constructor must be a non-null value."; }); } function zr(n, t, e) { if (t === void 0 && (t = []), e === void 0 && (e = false), t == null && (t = []), Array.isArray(n) || Ft(n) && !e) for (var r = 0; r < n.length; ++r) zr(n[r], t, e); else t.push(n); return t; } function dt(n) { if (n.length === 0) return 1; for (var t = n[0], e = 1; e < n.length; e++) t *= n[e]; return t; } function cL(n) { return n.length === 0; } function pn(n, t) { if (n === t) return true; if (n == null || t == null) return false; if (n.length !== t.length) return false; for (var e = 0; e < n.length; e++) if (n[e] !== t[e]) return false; return true; } function ot(n) { return n % 1 === 0; } function lL(n) { if (Math.tanh != null) return Math.tanh(n); if (n === Infinity) return 1; if (n === -Infinity) return -1; var t = Math.exp(2 * n); return (t - 1) / (t + 1); } function uL(n) { var t = Math.ceil(Math.sqrt(n)); return [t, Math.ceil(n / t)]; } function hL(n) { for (var t = new Uint32Array(n), e = 0; e < n; ++e) t[e] = e; return Yp(t), t; } function ya(n, t) { return t <= n.length ? n : n + " ".repeat(t - n.length); } function dL(n, t, e) { return t === void 0 && (t = function(r) { return 0; }), new Promise(function(r, i) { var a = 0, s = function() { if (n()) { r(); return; } a++; var o = t(a); if (e != null && a >= e) { i(); return; } setTimeout(s, o); }; s(); }); } function Kp(n, t) { for (var e = 1, r = -1, i = 0; i < n.length; ++i) if (n[i] >= 0) e *= n[i]; else if (n[i] === -1) { if (r !== -1) throw Error("Shapes can only have 1 implicit size. " + ("Found -1 at dim " + r + " and dim " + i)); r = i; } else if (n[i] < 0) throw Error("Shapes can not be < 0. Found " + n[i] + " at dim " + i); if (r === -1) { if (t > 0 && t !== e) throw Error("Size(" + t + ") must match the product of shape " + n); return n; } if (e === 0) throw Error("Cannot infer the missing size in [" + n + "] when there are 0 elements"); if (t % e !== 0) throw Error("The implicit shape can't be a fractional number. " + ("Got " + t + " / " + e)); var a = n.slice(); return a[r] = t / e, a; } function rt(n, t) { var e = t.length; return n = n == null ? t.map(function(r, i) { return i; }) : [].concat(n), E(n.every(function(r) { return r >= -e && r < e; }), function() { return "All values in axis param must be in range [-" + e + ", " + e + ") but " + ("got axis " + n); }), E(n.every(function(r) { return ot(r); }), function() { return "All values in axis param must be integers but " + ("got axis " + n); }), n.map(function(r) { return r < 0 ? e + r : r; }); } function jp(n, t) { for (var e = [], r = [], i = t != null && Array.isArray(t) && t.length === 0, a = t == null || i ? null : rt(t, n).sort(), s = 0, o = 0; o < n.length; ++o) { if (a != null) { if (a[s] === o && n[o] !== 1) throw new Error("Can't squeeze axis " + o + " since its dim '" + n[o] + "' is not 1"); (a[s] == null || a[s] > o) && n[o] === 1 && (e.push(n[o]), r.push(o)), a[s] <= o && s++; } n[o] !== 1 && (e.push(n[o]), r.push(o)); } return {newShape: e, keptDims: r}; } function bs(n, t) { var e = null; if (n == null || n === "float32") e = new Float32Array(t); else if (n === "int32") e = new Int32Array(t); else if (n === "bool") e = new Uint8Array(t); else throw new Error("Unknown data type " + n); return e; } function $p(n, t) { var e = null; if (n == null || n === "float32") e = new Float32Array(t); else if (n === "int32") e = new Int32Array(t); else if (n === "bool") e = new Uint8Array(t); else if (n === "string") e = new Array(t); else throw new Error("Unknown data type " + n); return e; } function Xp(n, t) { for (var e = 0; e < n.length; e++) { var r = n[e]; if (isNaN(r) || !isFinite(r)) throw Error("A tensor of type " + t + " being uploaded contains " + r + "."); } } function Jp(n) { return n === "bool" || n === "complex64" || n === "float32" || n === "int32" || n === "string"; } function Zp(n, t) { return t === "complex64" || (t === "float32" && n !== "complex64" || t === "int32" && n !== "float32" && n !== "complex64") ? false : !(t === "bool" && n === "bool"); } function Ft(n) { return n instanceof Float32Array || n instanceof Int32Array || n instanceof Uint8Array; } function Qp(n) { if (n === "float32" || n === "int32") return 4; if (n === "complex64") return 8; if (n === "bool") return 1; throw new Error("Unknown dtype " + n); } function ef(n) { if (n == null) return 0; var t = 0; return n.forEach(function(e) { return t += e.length; }), t; } function lr(n) { return typeof n == "string" || n instanceof String; } function tf(n) { return typeof n == "boolean"; } function nf(n) { return typeof n == "number"; } function xs(n) { return Array.isArray(n) ? xs(n[0]) : n instanceof Float32Array ? "float32" : n instanceof Int32Array || n instanceof Uint8Array ? "int32" : nf(n) ? "float32" : lr(n) ? "string" : tf(n) ? "bool" : "float32"; } function ur(n) { return !!(n && n.constructor && n.call && n.apply); } function Ls(n, t) { for (var e = t; e < n; ++e) if (n % e === 0) return e; return n; } function xi(n) { var t = n.length; if (t < 2) return []; var e = new Array(t - 1); e[t - 2] = n[t - 1]; for (var r = t - 3; r >= 0; --r) e[r] = e[r + 1] * n[r + 1]; return e; } function rf(n, t, e) { var r = new Array(); if (t.length === 1) for (var i = t[0], a = 0; a < i; a++) r[a] = e[n + a]; else for (var i = t[0], s = t.slice(1), o = s.reduce(function(l, u) { return l * u; }), a = 0; a < i; a++) r[a] = rf(n + a * o, s, e); return r; } function Li(n, t) { if (n.length === 0) return t[0]; var e = n.reduce(function(r, i) { return r * i; }); if (e === 0) return []; if (e !== t.length) throw new Error("[" + n + "] does not match the input size " + t.length + "."); return rf(0, n, t); } function hc(n, t) { for (var e = Si(n, t), r = 0; r < e.length; r++) e[r] = 1; return e; } function Si(n, t) { if (t == null || t === "float32" || t === "complex64") return new Float32Array(n); if (t === "int32") return new Int32Array(n); if (t === "bool") return new Uint8Array(n); throw new Error("Unknown data type " + t); } function pL(n, t) { var e = n.reduce(function(r, i) { return r * i; }, 1); if (t == null || t === "float32") return Li(n, new Float32Array(e)); if (t === "int32") return Li(n, new Int32Array(e)); if (t === "bool") return Li(n, new Uint8Array(e)); throw new Error("Unknown data type " + t); } function dc(n) { n.forEach(function(t) { E(Number.isInteger(t) && t >= 0, function() { return "Tensor must have a shape comprised of positive integers but got " + ("shape [" + n + "]."); }); }); } function fL(n, t, e) { if (t === 0) return 0; if (t === 1) return n[0]; for (var r = n[n.length - 1], i = 0; i < n.length - 1; ++i) r += e[i] * n[i]; return r; } function mL(n, t, e) { if (t === 0) return []; if (t === 1) return [n]; for (var r = new Array(t), i = 0; i < r.length - 1; ++i) r[i] = Math.floor(n / e[i]), n -= r[i] * e[i]; return r[r.length - 1] = n, r; } function pc(n) { return n && n.then && typeof n.then == "function"; } var af = "tfjsflags", sf = function() { function n(t) { this.global = t, this.flags = {}, this.flagRegistry = {}, this.urlFlags = {}, this.populateURLFlags(); } return n.prototype.setPlatform = function(t, e) { this.platform != null && console.warn("Platform " + this.platformName + " has already been set. " + ("Overwriting the platform with " + e + ".")), this.platformName = t, this.platform = e; }, n.prototype.registerFlag = function(t, e, r) { if (this.flagRegistry[t] = {evaluationFn: e, setHook: r}, this.urlFlags[t] != null) { var i = this.urlFlags[t]; console.warn("Setting feature override from URL " + t + ": " + i + "."), this.set(t, i); } }, n.prototype.getAsync = function(t) { return pe(this, void 0, void 0, function() { var e, r; return fe(this, function(i) { switch (i.label) { case 0: return t in this.flags ? [2, this.flags[t]] : (e = this.flags, r = t, [4, this.evaluateFlag(t)]); case 1: return e[r] = i.sent(), [2, this.flags[t]]; } }); }); }, n.prototype.get = function(t) { if (t in this.flags) return this.flags[t]; var e = this.evaluateFlag(t); if (pc(e)) throw new Error("Flag " + t + " cannot be synchronously evaluated. Please use getAsync() instead."); return this.flags[t] = e, this.flags[t]; }, n.prototype.getNumber = function(t) { return this.get(t); }, n.prototype.getBool = function(t) { return this.get(t); }, n.prototype.getFlags = function() { return this.flags; }, Object.defineProperty(n.prototype, "features", {get: function() { return this.flags; }, enumerable: true, configurable: true}), n.prototype.set = function(t, e) { if (this.flagRegistry[t] == null) throw new Error("Cannot set flag " + t + " as it has not been registered."); this.flags[t] = e, this.flagRegistry[t].setHook != null && this.flagRegistry[t].setHook(e); }, n.prototype.evaluateFlag = function(t) { if (this.flagRegistry[t] == null) throw new Error("Cannot evaluate flag '" + t + "': no evaluation function found."); return this.flagRegistry[t].evaluationFn(); }, n.prototype.setFlags = function(t) { this.flags = Object.assign({}, t); }, n.prototype.reset = function() { this.flags = {}, this.urlFlags = {}, this.populateURLFlags(); }, n.prototype.populateURLFlags = function() { var t = this; if (typeof this.global == "undefined" || typeof this.global.location == "undefined" || typeof this.global.location.search == "undefined") return; var e = gL(this.global.location.search); if (af in e) { var r = e[af].split(","); r.forEach(function(i) { var a = i.split(":"), s = a[0], o = a[1]; t.urlFlags[s] = yL(s, o); }); } }, n; }(); function gL(n) { var t = {}; return n.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, function(e) { for (var r = [], i = 1; i < arguments.length; i++) r[i - 1] = arguments[i]; return vL(t, r[0], r[1]), r.join("="); }), t; } function vL(n, t, e) { n[decodeURIComponent(t)] = decodeURIComponent(e || ""); } function yL(n, t) { if (t = t.toLowerCase(), t === "true" || t === "false") return t === "true"; if ("" + +t === t) return +t; throw new Error("Could not parse value flag value " + t + " for flag " + n + "."); } function qe() { return A.ENV; } A.ENV = null; function wL(n) { A.ENV = n; } var fc; function of() { if (fc == null) { var n = void 0; if (typeof window != "undefined") n = window; else if (typeof global != "undefined") n = global; else if (typeof process != "undefined") n = process; else if (typeof self != "undefined") n = self; else throw new Error("Could not find a global object"); fc = n; } return fc; } function bL() { var n = of(); return n._tfGlobals == null && (n._tfGlobals = new Map()), n._tfGlobals; } function cf(n, t) { var e = bL(); if (e.has(n)) return e.get(n); var r = t(); return e.set(n, r), e.get(n); } var mc = "Abs", gc = "Acos", yc = "Acosh", Ss = "Add", vc = "AddN", lf = "All", uf = "Any", wc = "ArgMax", bc = "ArgMin", xc = "Asin", Lc = "Asinh", Sc = "Atan", Ic = "Atanh", Ac = "Atan2", Tc = "AvgPool", hf = "AvgPoolBackprop", Nc = "AvgPool3D", df = "AvgPool3DBackprop", _c = "BatchMatMul", Cc = "BatchToSpaceND", Rc = "BroadcastTo", Is = "Cast", Oc = "Ceil", Ec = "ClipByValue", pf = "Complex", Dc = "Concat", kc = "Conv2D", ff = "Conv2DBackpropFilter", Fc = "Conv2DBackpropInput", Wc = "Conv3D", mf = "Conv3DBackpropFilterV2", gf = "Conv3DBackpropInputV2", Uc = "Cos", Bc = "Cosh", zc = "Cumsum", yf = "CropAndResize", vf = "DepthToSpace", Pc = "DepthwiseConv2dNative", wf = "DepthwiseConv2dNativeBackpropFilter", bf = "DepthwiseConv2dNativeBackpropInput", xf = "Diag", Mc = "Dilation2D", Lf = "Dilation2DBackpropInput", Sf = "Dilation2DBackpropFilter", Hc = "Div", Vc = "Elu", If = "EluGrad", Gc = "Erf", Af = "Equal", qc = "Exp", Yc = "Expm1", Tf = "FFT", Nf = "Fill", _f = "FlipLeftRight", Kc = "Floor", jc = "FloorDiv", $c = "FusedBatchNorm", Xc = "GatherV2", Cf = "GatherNd", Rf = "Greater", Jc = "GreaterEqual", Zc = "Identity", Of = "IFFT", Ef = "Imag", Qc = "IsFinite", el = "IsInf", tl = "IsNan", Df = "Less", kf = "LessEqual", Ff = "LinSpace", nl = "Log", rl = "Log1p", Wf = "LogicalAnd", Uf = "LogicalNot", Bf = "LogicalOr", il = "LogSoftmax", al = "LRN", zf = "LRNBackprop", sl = "Max", ol = "Maximum", cl = "MaxPool", Pf = "MaxPoolBackprop", ll = "MaxPool3D", Mf = "MaxPool3DBackprop", Hf = "MaxPoolWithArgmax", Vf = "Mean", ul = "Min", hl = "Minimum", dl = "MirrorPad", pl = "Mod", fl = "Multiply", ml = "Negate", Gf = "NotEqual", qf = "NonMaxSuppressionV3", Yf = "NonMaxSuppressionV4", Kf = "NonMaxSuppressionV5", gl = "OnesLike", yl = "OneHot", vl = "PadV2", xL = "Pool", wl = "Pow", bl = "Prelu", jf = "Prod", $f = "Range", Xf = "Real", xl = "Reciprocal", Ll = "Relu", Sl = "Reshape", Il = "ResizeNearestNeighbor", Jf = "ResizeNearestNeighborGrad", Al = "ResizeBilinear", Zf = "ResizeBilinearGrad", Tl = "Relu6", Nl = "Reverse", _l = "Round", Cl = "Rsqrt", Qf = "ScatterNd", Rl = "SelectV2", Ol = "Selu", El = "Slice", Dl = "Sin", kl = "Sinh", Fl = "Sign", Wl = "Sigmoid", Ul = "Softplus", Bl = "Sqrt", zl = "Sum", Pl = "SpaceToBatchND", Ml = "SplitV", Hl = "Softmax", Vl = "SquaredDifference", em = "Square", Gl = "Sub", tm = "SparseToDense", nm = "StridedSlice", ql = "Tan", Yl = "Tanh", Kl = "Tile", rm = "TopK", jl = "Transpose", im = "Unique", $l = "Unpack", Xl = "UnsortedSegmentSum", Jl = "ZerosLike", Zl = "Step", Ql = "FromPixels", am = "RotateWithOffset", eu = "_FusedMatMul", tu = "FusedConv2D", nu = "FusedDepthwiseConv2D"; var Ii = cf("kernelRegistry", function() { return new Map(); }), va = cf("gradRegistry", function() { return new Map(); }); function iu(n, t) { var e = ru(n, t); return Ii.get(e); } function au(n) { return va.get(n); } function As(n) { for (var t = Ii.entries(), e = []; ; ) { var r = t.next(), i = r.done, a = r.value; if (i) break; var s = a[0], o = a[1], c = s.split("_")[0]; c === n && e.push(o); } return e; } function sm(n) { var t = n.kernelName, e = n.backendName, r = ru(t, e); Ii.has(r) && console.warn("The kernel '" + t + "' for backend " + ("'" + e + "' is already registered")), Ii.set(r, n); } function om(n) { var t = n.kernelName; va.has(t) && (qe().getBool("DEBUG") && console.warn("Overriding the gradient for '" + t + "'")), va.set(t, n); } function LL(n, t) { var e = ru(n, t); if (!Ii.has(e)) throw new Error("The kernel '" + n + "' for backend " + ("'" + t + "' is not registered")); Ii.delete(e); } function SL(n) { if (!va.has(n)) throw new Error("The gradient '" + n + "' for backend is not registered"); va.delete(n); } function IL(n, t) { var e = As(n); e.forEach(function(r) { var i = Object.assign({}, r, {backendName: t}); sm(i); }); } function ru(n, t) { return t + "_" + n; } function AL(n, t) { return t === "string" ? su(n) : Ts([n], t); } function TL(n, t) { return n instanceof Float32Array && t === "float32" || n instanceof Int32Array && t === "int32" || n instanceof Uint8Array && t === "bool"; } function Ts(n, t) { if (t === "string") throw new Error("Cannot convert a string[] to a TypedArray"); if (Array.isArray(n) && (n = zr(n)), qe().getBool("DEBUG") && Xp(n, t), TL(n, t)) return n; if (t == null || t === "float32" || t === "complex64") return new Float32Array(n); if (t === "int32") return new Int32Array(n); if (t === "bool") { for (var e = new Uint8Array(n.length), r = 0; r < e.length; ++r) Math.round(n[r]) !== 0 && (e[r] = 1); return e; } else throw new Error("Unknown data type " + t); } function ou() { return qe().platform.now(); } function NL(n, t) { return qe().platform.fetch(n, t); } function su(n, t) { return t === void 0 && (t = "utf-8"), t = t || "utf-8", qe().platform.encode(n, t); } function cu(n, t) { return t === void 0 && (t = "utf-8"), t = t || "utf-8", qe().platform.decode(n, t); } var _L = {__proto__: null, createScalarValue: AL, toTypedArray: Ts, now: ou, fetch: NL, encodeString: su, decodeString: cu, shuffle: Yp, clamp: ga, nearestLargerEven: iL, sum: aL, randUniform: sL, distSquared: oL, assert: E, assertShapesMatch: Pe, assertNonNull: Br, flatten: zr, sizeFromShape: dt, isScalarShape: cL, arraysEqual: pn, isInt: ot, tanh: lL, sizeToSquarishShape: uL, createShuffledIndices: hL, rightPad: ya, repeatedTry: dL, inferFromImplicitShape: Kp, parseAxisParam: rt, squeezeShape: jp, getTypedArrayFromDType: bs, getArrayFromDType: $p, checkConversionForErrors: Xp, isValidDtype: Jp, hasEncodingLoss: Zp, isTypedArray: Ft, bytesPerElement: Qp, bytesFromStringArray: ef, isString: lr, isBoolean: tf, isNumber: nf, inferDtype: xs, isFunction: ur, nearestDivisor: Ls, computeStrides: xi, toNestedArray: Li, makeOnesTypedArray: hc, makeZerosTypedArray: Si, makeZerosNestedTypedArray: pL, assertNonNegativeIntegerDimensions: dc, locToIndex: fL, indexToLoc: mL, isPromise: pc}; var OL = function() { function n(t, e) { this.backendTimer = t, this.logger = e, e == null && (this.logger = new RL()); } return n.prototype.profileKernel = function(t, e, r) { for (var i, a = function() { i = r(); }, s = this.backendTimer.time(a), o = function(u) { var h = i[u]; h.data().then(function(d) { CL(d, h.dtype, t); }); }, c = 0; c < i.length; c++) o(c); var l = {kernelName: t, outputs: i, inputs: e, timeMs: s.then(function(u) { return u.kernelMs; }), extraInfo: s.then(function(u) { return u.getExtraProfileInfo != null ? u.getExtraProfileInfo() : ""; })}; return l; }, n.prototype.logKernelProfile = function(t) { var e = this, r = t.kernelName, i = t.outputs, a = t.timeMs, s = t.inputs, o = t.extraInfo; i.forEach(function(c) { Promise.all([c.data(), a, o]).then(function(l) { e.logger.logKernelProfile(r, c, l[0], l[1], s, l[2]); }); }); }, n; }(); function CL(n, t, e) { if (t !== "float32") return false; for (var r = 0; r < n.length; r++) { var i = n[r]; if (isNaN(i) || !isFinite(i)) return console.warn("Found " + i + " in the result of '" + e + "'"), true; } return false; } var RL = function() { function n() { } return n.prototype.logKernelProfile = function(t, e, r, i, a, s) { var o = typeof i == "number" ? ya(i + "ms", 9) : i.error, c = ya(t, 25), l = e.rank, u = e.size, h = ya(e.shape.toString(), 14), d = ""; for (var p in a) { var f = a[p]; if (f != null) { var m = f.shape || e.shape, g = m.length; d += p + ": " + g + "D " + (g > 0 ? m : "") + " "; } } console.log("%c" + c + " %c" + o + " %c" + l + "D " + h + " %c" + u + " %c" + d + " %c" + s, "font-weight:bold", "color:red", "color:blue", "color: orange", "color: green", "color: steelblue"); }, n; }(); function EL(n, t, e) { for (var r = {}, i = {}, a = 0; a < t.length; a++) r[t[a].id] = true; for (var a = 0; a < n.length; a++) { var s = n[a], o = s.inputs; for (var c in o) { for (var l = o[c], u = false, h = 0; h < t.length; h++) if (r[l.id]) { s.outputs.forEach(function(b) { return r[b.id] = true; }), u = true, i[s.id] = true; break; } if (u) break; } } var d = {}; d[e.id] = true; for (var p = {}, a = n.length - 1; a >= 0; a--) for (var s = n[a], o = s.inputs, h = 0; h < s.outputs.length; h++) if (d[s.outputs[h].id]) { for (var c in o) d[o[c].id] = true, p[s.id] = true; break; } for (var f = [], a = 0; a < n.length; a++) { var s = n[a]; if (i[s.id] && p[s.id]) { var m = {}; for (var c in s.inputs) { var g = s.inputs[c]; r[g.id] && (m[c] = g); } var y = Object.assign({}, s); y.inputs = m, y.outputs = s.outputs, f.push(y); } } return f; } function DL(n, t, e, r) { for (var i = function(s) { var o = t[s], c = []; if (o.outputs.forEach(function(d) { var p = n[d.id]; p != null ? c.push(p) : c.push(null); }), o.gradient == null) throw new Error("Cannot compute gradient: gradient function not found " + ("for " + o.kernelName + ".")); var l = o.gradient(c), u = function(d) { if (!(d in l)) throw new Error("Cannot backprop through input " + d + ". " + ("Available gradients found: " + Object.keys(l) + ".")); var p = e(function() { return l[d](); }); if (p.dtype !== "float32") throw new Error("Error in gradient for op " + o.kernelName + ". The gradient of input " + (d + " must have 'float32' dtype, but has '" + p.dtype + "'")); var f = o.inputs[d]; if (!pn(p.shape, f.shape)) throw new Error("Error in gradient for op " + o.kernelName + ". The gradient of input " + ("'" + d + "' has shape '" + p.shape + "', which does not match ") + ("the shape of the input '" + f.shape + "'")); if (n[f.id] == null) n[f.id] = p; else { var m = n[f.id]; n[f.id] = r(m, p), m.dispose(); } }; for (var h in o.inputs) u(h); }, a = t.length - 1; a >= 0; a--) i(a); } var cm = 20, wa = 3, lu = 7; function FL(n, t, e, r) { var i = xi(t), a = kL(n, t, e, i), s = t.length, o = Ns(n, t, e, i, a), c = ["Tensor"]; return r && (c.push(" dtype: " + e), c.push(" rank: " + s), c.push(" shape: [" + t + "]"), c.push(" values:")), c.push(o.map(function(l) { return " " + l; }).join(` `)), c.join(` `); } function kL(n, t, e, r) { var i = dt(t), a = r[r.length - 1], s = new Array(a).fill(0), o = t.length, c = e === "complex64" ? xa(n) : n; if (o > 1) for (var l = 0; l < i / a; l++) for (var u = l * a, h = 0; h < a; h++) s[h] = Math.max(s[h], ba(c[u + h], 0, e).length); return s; } function ba(n, t, e) { var r; return Array.isArray(n) ? r = parseFloat(n[0].toFixed(lu)) + " + " + (parseFloat(n[1].toFixed(lu)) + "j") : lr(n) ? r = "'" + n + "'" : e === "bool" ? r = lm(n) : r = parseFloat(n.toFixed(lu)).toString(), ya(r, t); } function lm(n) { return n === 0 ? "false" : "true"; } function Ns(n, t, e, r, i, a) { a === void 0 && (a = true); var s = e === "complex64" ? 2 : 1, o = t[0], c = t.length; if (c === 0) { if (e === "complex64") { var l = xa(n); return [ba(l[0], 0, e)]; } return e === "bool" ? [lm(n[0])] : [n[0].toString()]; } if (c === 1) { if (o > cm) { var u = wa * s, h = Array.from(n.slice(0, u)), d = Array.from(n.slice((o - wa) * s, o * s)); return e === "complex64" && (h = xa(h), d = xa(d)), ["[" + h.map(function(I, C) { return ba(I, i[C], e); }).join(", ") + ", ..., " + d.map(function(I, C) { return ba(I, i[o - wa + C], e); }).join(", ") + "]"]; } var p = e === "complex64" ? xa(n) : Array.from(n); return ["[" + p.map(function(I, C) { return ba(I, i[C], e); }).join(", ") + "]"]; } var f = t.slice(1), m = r.slice(1), g = r[0] * s, y = []; if (o > cm) { for (var w = 0; w < wa; w++) { var b = w * g, x = b + g; y.push.apply(y, Ns(n.slice(b, x), f, e, m, i, false)); } y.push("..."); for (var w = o - wa; w < o; w++) { var b = w * g, x = b + g; y.push.apply(y, Ns(n.slice(b, x), f, e, m, i, w === o - 1)); } } else for (var w = 0; w < o; w++) { var b = w * g, x = b + g; y.push.apply(y, Ns(n.slice(b, x), f, e, m, i, w === o - 1)); } var L = c === 2 ? "," : ""; y[0] = "[" + y[0] + L; for (var w = 1; w < y.length - 1; w++) y[w] = " " + y[w] + L; for (var N = `, `, w = 2; w < c; w++) N += ` `; return y[y.length - 1] = " " + y[y.length - 1] + "]" + (a ? "" : N), y; } function xa(n) { for (var t = [], e = 0; e < n.length; e += 2) t.push([n[e], n[e + 1]]); return t; } var _s = function() { function n(t, e, r) { var i = this; if (this.dtype = e, this.shape = t.slice(), this.size = dt(t), r != null) { var a = r.length; E(a === this.size, function() { return "Length of values '" + a + "' does not match the size " + ("inferred by the shape '" + i.size + "'."); }); } if (e === "complex64") throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag)."); this.values = r || $p(e, this.size), this.strides = xi(t); } return n.prototype.set = function(t) { for (var e = this, r = [], i = 1; i < arguments.length; i++) r[i - 1] = arguments[i]; r.length === 0 && (r = [0]), E(r.length === this.rank, function() { return "The number of provided coordinates (" + r.length + ") must " + ("match the rank (" + e.rank + ")"); }); var a = this.locToIndex(r); this.values[a] = t; }, n.prototype.get = function() { for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e]; t.length === 0 && (t = [0]); for (var r = 0, i = 0, a = t; i < a.length; i++) { var s = a[i]; if (s < 0 || s >= this.shape[r]) { var o = "Requested out of range element at " + t + ". " + (" Buffer shape=" + this.shape); throw new Error(o); } r++; } for (var c = t[t.length - 1], l = 0; l < t.length - 1; ++l) c += this.strides[l] * t[l]; return this.values[c]; }, n.prototype.locToIndex = function(t) { if (this.rank === 0) return 0; if (this.rank === 1) return t[0]; for (var e = t[t.length - 1], r = 0; r < t.length - 1; ++r) e += this.strides[r] * t[r]; return e; }, n.prototype.indexToLoc = function(t) { if (this.rank === 0) return []; if (this.rank === 1) return [t]; for (var e = new Array(this.shape.length), r = 0; r < e.length - 1; ++r) e[r] = Math.floor(t / this.strides[r]), t -= e[r] * this.strides[r]; return e[e.length - 1] = t, e; }, Object.defineProperty(n.prototype, "rank", {get: function() { return this.shape.length; }, enumerable: true, configurable: true}), n.prototype.toTensor = function() { return _n().makeTensor(this.values, this.shape, this.dtype); }, n; }(), _n = null, Ai = null; function WL(n) { _n = n; } function UL(n) { Ai = n; } var K = function() { function n(t, e, r, i) { this.kept = false, this.isDisposedInternal = false, this.shape = t.slice(), this.dtype = e || "float32", this.size = dt(t), this.strides = xi(t), this.dataId = r, this.id = i, this.rankType = this.rank < 5 ? this.rank.toString() : "higher"; } return Object.defineProperty(n.prototype, "rank", {get: function() { return this.shape.length; }, enumerable: true, configurable: true}), n.prototype.buffer = function() { return pe(this, void 0, void 0, function() { var t; return fe(this, function(e) { switch (e.label) { case 0: return [4, this.data()]; case 1: return t = e.sent(), [2, Ai.buffer(this.shape, this.dtype, t)]; } }); }); }, n.prototype.bufferSync = function() { return Ai.buffer(this.shape, this.dtype, this.dataSync()); }, n.prototype.array = function() { return pe(this, void 0, void 0, function() { var t; return fe(this, function(e) { switch (e.label) { case 0: return [4, this.data()]; case 1: return t = e.sent(), [2, Li(this.shape, t)]; } }); }); }, n.prototype.arraySync = function() { return Li(this.shape, this.dataSync()); }, n.prototype.data = function() { return pe(this, void 0, void 0, function() { var t, e; return fe(this, function(r) { switch (r.label) { case 0: return this.throwIfDisposed(), t = _n().read(this.dataId), this.dtype === "string" ? [4, t] : [3, 2]; case 1: e = r.sent(); try { return [2, e.map(function(i) { return cu(i); })]; } catch (i) { throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes()."); } r.label = 2; case 2: return [2, t]; } }); }); }, n.prototype.dataSync = function() { this.throwIfDisposed(); var t = _n().readSync(this.dataId); if (this.dtype === "string") try { return t.map(function(e) { return cu(e); }); } catch (e) { throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes()."); } return t; }, n.prototype.bytes = function() { return pe(this, void 0, void 0, function() { var t; return fe(this, function(e) { switch (e.label) { case 0: return this.throwIfDisposed(), [4, _n().read(this.dataId)]; case 1: return t = e.sent(), this.dtype === "string" ? [2, t] : [2, new Uint8Array(t.buffer)]; } }); }); }, n.prototype.dispose = function() { if (this.isDisposed) return; _n().disposeTensor(this), this.isDisposedInternal = true; }, Object.defineProperty(n.prototype, "isDisposed", {get: function() { return this.isDisposedInternal; }, enumerable: true, configurable: true}), n.prototype.throwIfDisposed = function() { if (this.isDisposed) throw new Error("Tensor is disposed."); }, n.prototype.print = function(t) { return t === void 0 && (t = false), Ai.print(this, t); }, n.prototype.clone = function() { return this.throwIfDisposed(), Ai.clone(this); }, n.prototype.toString = function(t) { t === void 0 && (t = false); var e = this.dataSync(); return FL(e, this.shape, this.dtype, t); }, n.prototype.cast = function(t) { return this.throwIfDisposed(), Ai.cast(this, t); }, n.prototype.variable = function(t, e, r) { return t === void 0 && (t = true), this.throwIfDisposed(), _n().makeVariable(this, t, e, r); }, n; }(); Object.defineProperty(K, Symbol.hasInstance, {value: function(n) { return !!n && n.data != null && n.dataSync != null && n.throwIfDisposed != null; }}); var La = function(n) { Yn(t, n); function t(e, r, i, a) { var s = n.call(this, e.shape, e.dtype, e.dataId, a) || this; return s.trainable = r, s.name = i, s; } return t.prototype.assign = function(e) { if (e.dtype !== this.dtype) throw new Error("dtype of the new value (" + e.dtype + ") and " + ("previous value (" + this.dtype + ") must match")); if (!pn(e.shape, this.shape)) throw new Error("shape of the new value (" + e.shape + ") and " + ("previous value (" + this.shape + ") must match")); _n().disposeTensor(this), this.dataId = e.dataId, _n().incRef(this, null); }, t.prototype.dispose = function() { _n().disposeVariable(this), this.isDisposedInternal = true; }, t; }(K); Object.defineProperty(La, Symbol.hasInstance, {value: function(n) { return n instanceof K && n.assign != null && n.assign instanceof Function; }}); (function(n) { n.R0 = "R0", n.R1 = "R1", n.R2 = "R2", n.R3 = "R3", n.R4 = "R4", n.R5 = "R5", n.R6 = "R6"; })(A.Rank || (A.Rank = {})); var uu; (function(n) { n.float32 = "float32", n.int32 = "int32", n.bool = "int32", n.complex64 = "complex64"; })(uu || (uu = {})); var hu; (function(n) { n.float32 = "float32", n.int32 = "int32", n.bool = "bool", n.complex64 = "complex64"; })(hu || (hu = {})); var du; (function(n) { n.float32 = "float32", n.int32 = "float32", n.bool = "float32", n.complex64 = "complex64"; })(du || (du = {})); var pu; (function(n) { n.float32 = "complex64", n.int32 = "complex64", n.bool = "complex64", n.complex64 = "complex64"; })(pu || (pu = {})); var BL = {float32: du, int32: uu, bool: hu, complex64: pu}; function Cs(n, t) { if (n === "string" || t === "string") { if (n === "string" && t === "string") return "string"; throw new Error("Can not upcast " + n + " with " + t); } return BL[n][t]; } function zL(n) { return Cs(n, "int32"); } function ct(n, t) { if (n.dtype === t.dtype) return [n, t]; var e = Cs(n.dtype, t.dtype); return [n.cast(e), t.cast(e)]; } function um(n, t) { E(n.dtype === t.dtype, function() { return "The dtypes of the first(" + n.dtype + ") and" + (" second(" + t.dtype + ") input must match"); }); } function PL(n, t) { return t.some(function(e) { return e.id === n.id; }); } function fu(n) { var t = [], e = new Set(); return hm(n, t, e), t; } function hm(n, t, e) { if (n == null) return; if (n instanceof K) { t.push(n); return; } if (!ML(n)) return; var r = n; for (var i in r) { var a = r[i]; e.has(a) || (e.add(a), hm(a, t, e)); } } function ML(n) { return Array.isArray(n) || typeof n == "object"; } var HL = {__proto__: null, makeTypesMatch: ct, assertTypesMatch: um, isTensorInList: PL, getTensorsInContainer: fu}; var dm = function() { function n() { this.registeredVariables = {}, this.nextTapeNodeId = 0, this.numBytes = 0, this.numTensors = 0, this.numStringTensors = 0, this.numDataBuffers = 0, this.gradientDepth = 0, this.kernelDepth = 0, this.scopeStack = [], this.numDataMovesStack = [], this.nextScopeId = 0, this.tensorInfo = new WeakMap(), this.profiling = false, this.activeProfile = {newBytes: 0, newTensors: 0, peakBytes: 0, kernels: [], result: null}; } return n.prototype.dispose = function() { for (var t in this.registeredVariables) this.registeredVariables[t].dispose(); }, n; }(), qL = function() { function n(t) { this.ENV = t, this.registry = {}, this.registryFactory = {}, this.pendingBackendInitId = 0, this.state = new dm(); } return n.prototype.ready = function() { return pe(this, void 0, void 0, function() { var t, e, r, i; return fe(this, function(a) { switch (a.label) { case 0: if (this.pendingBackendInit != null) return [2, this.pendingBackendInit.then(function() { })]; if (this.backendInstance != null) return [2]; t = this.getSortedBackends(), e = 0, a.label = 1; case 1: return e < t.length ? (r = t[e], [4, this.initializeBackend(r).success]) : [3, 5]; case 2: return i = a.sent(), i ? [4, this.setBackend(r)] : [3, 4]; case 3: return a.sent(), [2]; case 4: return e++, [3, 1]; case 5: throw new Error("Could not initialize any backends, all backend initializations failed."); } }); }); }, Object.defineProperty(n.prototype, "backend", {get: function() { if (this.pendingBackendInit != null) throw new Error("Backend '" + this.backendName + "' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods"); if (this.backendInstance == null) { var t = this.initializeBackendsAndReturnBest(), e = t.name, r = t.asyncInit; if (r) throw new Error("The highest priority backend '" + e + "' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods"); this.setBackend(e); } return this.backendInstance; }, enumerable: true, configurable: true}), n.prototype.backendNames = function() { return Object.keys(this.registryFactory); }, n.prototype.findBackend = function(t) { if (!(t in this.registry)) if (t in this.registryFactory) { var e = this.initializeBackend(t).asyncInit; if (e) return null; } else return null; return this.registry[t]; }, n.prototype.findBackendFactory = function(t) { return t in this.registryFactory ? this.registryFactory[t].factory : null; }, n.prototype.registerBackend = function(t, e, r) { return r === void 0 && (r = 1), t in this.registryFactory ? (console.warn(t + " backend was already registered. Reusing existing backend factory."), false) : (this.registryFactory[t] = {factory: e, priority: r}, true); }, n.prototype.setBackend = function(t) { return pe(this, void 0, void 0, function() { var e, r, i, a, s; return fe(this, function(o) { switch (o.label) { case 0: if (this.registryFactory[t] == null) throw new Error("Backend name '" + t + "' not found in registry"); return this.backendName = t, this.registry[t] == null ? (this.backendInstance = null, e = this.initializeBackend(t), r = e.success, i = e.asyncInit, i ? [4, r] : [3, 2]) : [3, 4]; case 1: return s = o.sent(), [3, 3]; case 2: s = r, o.label = 3; case 3: if (a = s, !a) return [2, false]; o.label = 4; case 4: return this.backendInstance = this.registry[t], this.setupRegisteredKernels(), this.profiler = new OL(this.backendInstance), [2, true]; } }); }); }, n.prototype.setupRegisteredKernels = function() { var t = this, e = As(this.backendName); e.forEach(function(r) { r.setupFunc != null && r.setupFunc(t.backendInstance); }); }, n.prototype.disposeRegisteredKernels = function(t) { var e = this, r = As(t); r.forEach(function(i) { i.disposeFunc != null && i.disposeFunc(e.registry[t]); }); }, n.prototype.initializeBackend = function(t) { var e = this, r = this.registryFactory[t]; if (r == null) throw new Error("Cannot initialize backend " + t + ", no registration found."); try { var i = r.factory(); if (i && !(i instanceof qp) && typeof i.then == "function") { var a = ++this.pendingBackendInitId, s = i.then(function(o) { return a < e.pendingBackendInitId ? false : (e.registry[t] = o, e.pendingBackendInit = null, true); }).catch(function(o) { return a < e.pendingBackendInitId || (e.pendingBackendInit = null, console.warn("Initialization of backend " + t + " failed"), console.warn(o.stack || o.message)), false; }); return this.pendingBackendInit = s, {success: s, asyncInit: true}; } else return this.registry[t] = i, {success: true, asyncInit: false}; } catch (o) { return console.warn("Initialization of backend " + t + " failed"), console.warn(o.stack || o.message), {success: false, asyncInit: false}; } }, n.prototype.removeBackend = function(t) { if (!(t in this.registryFactory)) throw new Error(t + " backend not found in registry"); this.backendName === t && this.pendingBackendInit != null && this.pendingBackendInitId++, t in this.registry && (this.disposeRegisteredKernels(t), this.registry[t].dispose(), delete this.registry[t]), delete this.registryFactory[t], this.backendName === t && (this.pendingBackendInit = null, this.backendName = null, this.backendInstance = null); }, n.prototype.getSortedBackends = function() { var t = this; if (Object.keys(this.registryFactory).length === 0) throw new Error("No backend found in registry."); return Object.keys(this.registryFactory).sort(function(e, r) { return t.registryFactory[r].priority - t.registryFactory[e].priority; }); }, n.prototype.initializeBackendsAndReturnBest = function() { for (var t = this.getSortedBackends(), e = 0; e < t.length; e++) { var r = t[e], i = this.initializeBackend(r), a = i.success, s = i.asyncInit; if (s || a) return {name: r, asyncInit: s}; } throw new Error("Could not initialize any backends, all backend initializations failed."); }, n.prototype.moveData = function(t, e) { var r = this.state.tensorInfo.get(e), i = r.backend, a = this.readSync(e); i.disposeData(e), r.backend = t, t.move(e, a, r.shape, r.dtype), this.shouldCheckForMemLeaks() && this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1]++; }, n.prototype.tidy = function(t, e) { var r = this, i = null; if (e == null) { if (typeof t != "function") throw new Error("Please provide a function to tidy()"); e = t; } else { if (typeof t != "string" && !(t instanceof String)) throw new Error("When calling with two arguments, the first argument to tidy() must be a string"); if (typeof e != "function") throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function"); i = t; } var a; return this.scopedRun(function() { return r.startScope(i); }, function() { return r.endScope(a); }, function() { return a = e(), a instanceof Promise && console.error("Cannot return a Promise inside of tidy."), a; }); }, n.prototype.scopedRun = function(t, e, r) { t(); try { var i = r(); return e(), i; } catch (a) { throw e(), a; } }, n.prototype.nextTensorId = function() { return n.nextTensorId++; }, n.prototype.nextVariableId = function() { return n.nextVariableId++; }, n.prototype.clone = function(t) { var e = this.makeTensorFromDataId(t.dataId, t.shape, t.dtype), r = {x: t}, i = function(s) { return {x: function() { var o = "float32", c = {x: s}, l = {dtype: o}; return z.runKernelFunc(function(u) { return u.cast(s, o); }, c, null, Is, l); }}; }, a = []; return this.addTapeNode(this.state.activeScope.name, r, [e], i, a, {}), e; }, n.prototype.runKernel = function(t, e, r, i, a) { var s = null, o = null; return this.runKernelFunc(s, e, o, t, r, i, a); }, n.prototype.shouldCheckForMemLeaks = function() { return this.ENV.getBool("IS_TEST"); }, n.prototype.checkKernelForMemLeak = function(t, e, r) { var i = this.backend.numDataIds(), a = 0; r.forEach(function(c) { a += c.dtype === "complex64" ? 3 : 1; }); var s = this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1], o = i - e - a - s; if (o > 0) throw new Error("Backend '" + this.backendName + "' has an internal memory leak " + ("(" + o + " data ids) after running '" + t + "'")); }, n.prototype.runKernelFunc = function(t, e, r, i, a, s, o) { var c = this, l, u = [], h = this.isTapeOn(); i == null && (i = this.state.activeScope != null ? this.state.activeScope.name : ""); var d = this.state.numBytes, p = this.state.numTensors; this.shouldCheckForMemLeaks() && this.state.numDataMovesStack.push(0); var f, m = iu(i, this.backendName), g; if (m != null) f = function() { var b = c.backend.numDataIds(); g = m.kernelFunc({inputs: e, attrs: a, backend: c.backend}); var x = Array.isArray(g) ? g : [g]; c.shouldCheckForMemLeaks() && c.checkKernelForMemLeak(i, b, x); var L = x.map(function(C) { var O = C.dataId, D = C.shape, F = C.dtype; return c.makeTensorFromDataId(O, D, F); }); if (h) { var N = c.getTensorsForGradient(i, e, L); if (N == null) { o == null && (o = []); var I = L.filter(function(C, O) { return o[O]; }); N = (s || []).slice().concat(I); } u = c.saveTensorsForBackwardMode(N); } return L; }; else { var y = function(b) { if (!h) return; u = b.map(function(x) { return c.keep(c.clone(x)); }); }; f = function() { var b = c.backend.numDataIds(); g = c.tidy(function() { return t(c.backend, y); }); var x = Array.isArray(g) ? g : [g]; return c.shouldCheckForMemLeaks() && c.checkKernelForMemLeak(i, b, x), x; }; } var w; return this.scopedRun(function() { return c.state.kernelDepth++; }, function() { return c.state.kernelDepth--; }, function() { !c.ENV.getBool("DEBUG") && !c.state.profiling ? l = f() : (w = c.profiler.profileKernel(i, e, function() { return f(); }), c.ENV.getBool("DEBUG") && c.profiler.logKernelProfile(w), l = w.outputs); }), h && this.addTapeNode(i, e, l, r, u, a), this.state.profiling && this.state.activeProfile.kernels.push({name: i, bytesAdded: this.state.numBytes - d, totalBytesSnapshot: this.state.numBytes, tensorsAdded: this.state.numTensors - p, totalTensorsSnapshot: this.state.numTensors, inputShapes: Object.keys(e).map(function(b) { return e[b] != null ? e[b].shape : null; }), outputShapes: l.map(function(b) { return b.shape; }), kernelTimeMs: w.timeMs, extraInfo: w.extraInfo}), Array.isArray(g) ? l : l[0]; }, n.prototype.saveTensorsForBackwardMode = function(t) { var e = this, r = t.map(function(i) { return e.keep(e.clone(i)); }); return r; }, n.prototype.getTensorsForGradient = function(t, e, r) { var i = au(t); if (i != null) { var a = i.inputsToSave || [], s = i.outputsToSave || [], o = void 0; i.saveAllInputs ? (E(Array.isArray(e), function() { return "saveAllInputs is true, expected inputs to be an array."; }), o = Object.keys(e).map(function(l) { return e[l]; })) : o = a.map(function(l) { return e[l]; }); var c = r.filter(function(l, u) { return s[u]; }); return o.concat(c); } return null; }, n.prototype.makeTensor = function(t, e, r, i) { if (t == null) throw new Error("Values passed to engine.makeTensor() are null"); r = r || "float32", i = i || this.backend; var a = t; r === "string" && lr(t[0]) && (a = t.map(function(u) { return su(u); })); var s = i.write(a, e, r), o = new K(e, r, s, this.nextTensorId()); if (this.incRef(o, i), r === "string") { var c = this.state.tensorInfo.get(s), l = ef(a); this.state.numBytes += l - c.bytes, c.bytes = l; } return o; }, n.prototype.makeTensorFromDataId = function(t, e, r, i) { r = r || "float32"; var a = new K(e, r, t, this.nextTensorId()); return this.incRef(a, i), a; }, n.prototype.makeVariable = function(t, e, r, i) { e === void 0 && (e = true), r = r || this.nextVariableId().toString(), i != null && i !== t.dtype && (t = t.cast(i)); var a = new La(t, e, r, this.nextTensorId()); if (this.state.registeredVariables[a.name] != null) throw new Error("Variable with name " + a.name + " was already registered"); return this.state.registeredVariables[a.name] = a, this.incRef(a, this.backend), a; }, n.prototype.incRef = function(t, e) { var r = this.state.tensorInfo.has(t.dataId) ? this.state.tensorInfo.get(t.dataId).refCount : 0; if (this.state.numTensors++, t.dtype === "string" && this.state.numStringTensors++, r === 0) { this.state.numDataBuffers++; var i = 0; t.dtype !== "complex64" && t.dtype !== "string" && (i = t.size * Qp(t.dtype)), this.state.tensorInfo.set(t.dataId, {backend: e || this.backend, dtype: t.dtype, shape: t.shape, bytes: i, refCount: 0}), this.state.numBytes += i; } this.state.tensorInfo.get(t.dataId).refCount++, t instanceof La || this.track(t); }, n.prototype.disposeTensor = function(t) { if (!this.state.tensorInfo.has(t.dataId)) return; this.state.numTensors--, t.dtype === "string" && this.state.numStringTensors--; var e = this.state.tensorInfo.get(t.dataId), r = e.refCount; r <= 1 ? (t.dtype !== "complex64" && (this.state.numBytes -= e.bytes), this.state.numDataBuffers--, e.backend.disposeData(t.dataId), this.state.tensorInfo.delete(t.dataId)) : this.state.tensorInfo.get(t.dataId).refCount--; }, n.prototype.disposeVariables = function() { for (var t in this.state.registeredVariables) { var e = this.state.registeredVariables[t]; this.disposeVariable(e); } }, n.prototype.disposeVariable = function(t) { this.disposeTensor(t), this.state.registeredVariables[t.name] != null && delete this.state.registeredVariables[t.name]; }, n.prototype.memory = function() { var t = this.backend.memory(); return t.numTensors = this.state.numTensors, t.numDataBuffers = this.state.numDataBuffers, t.numBytes = this.state.numBytes, this.state.numStringTensors > 0 && (t.unreliable = true, t.reasons == null && (t.reasons = []), t.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")), t; }, n.prototype.profile = function(t) { return pe(this, void 0, void 0, function() { var e, r, i, a, s, o, c, l; return fe(this, function(u) { switch (u.label) { case 0: return this.state.profiling = true, e = this.state.numBytes, r = this.state.numTensors, this.state.activeProfile.kernels = [], i = this.state.activeProfile, [4, t()]; case 1: i.result = u.sent(), this.state.profiling = false, this.state.activeProfile.peakBytes = Math.max.apply(Math, this.state.activeProfile.kernels.map(function(h) { return h.totalBytesSnapshot; })), this.state.activeProfile.newBytes = this.state.numBytes - e, this.state.activeProfile.newTensors = this.state.numTensors - r, a = 0, s = this.state.activeProfile.kernels, u.label = 2; case 2: return a < s.length ? (o = s[a], c = o, [4, o.kernelTimeMs]) : [3, 6]; case 3: return c.kernelTimeMs = u.sent(), l = o, [4, o.extraInfo]; case 4: l.extraInfo = u.sent(), u.label = 5; case 5: return a++, [3, 2]; case 6: return [2, this.state.activeProfile]; } }); }); }, n.prototype.isTapeOn = function() { return this.state.gradientDepth > 0 && this.state.kernelDepth === 0; }, n.prototype.addTapeNode = function(t, e, r, i, a, s) { var o = this, c = {id: this.state.nextTapeNodeId++, kernelName: t, inputs: e, outputs: r, saved: a}, l = au(t); l != null && (i = l.gradFunc), i != null && (c.gradient = function(u) { return u = u.map(function(h, d) { if (h == null) { var p = r[d], f = Si(p.size, p.dtype); return o.makeTensor(f, p.shape, p.dtype); } return h; }), i(u.length > 1 ? u : u[0], a, s); }), this.state.activeTape.push(c); }, n.prototype.keep = function(t) { return t.kept = true, t; }, n.prototype.startTape = function() { this.state.gradientDepth === 0 && (this.state.activeTape = []), this.state.gradientDepth++; }, n.prototype.endTape = function() { this.state.gradientDepth--; }, n.prototype.startScope = function(t) { var e = {track: [], name: "unnamed scope", id: this.state.nextScopeId++}; t && (e.name = t), this.state.scopeStack.push(e), this.state.activeScope = e; }, n.prototype.endScope = function(t) { for (var e = this, r = fu(t), i = new Set(r.map(function(c) { return c.id; })), a = 0; a < this.state.activeScope.track.length; a++) { var s = this.state.activeScope.track[a]; !s.kept && !i.has(s.id) && s.dispose(); } var o = this.state.scopeStack.pop(); this.state.activeScope = this.state.scopeStack.length === 0 ? null : this.state.scopeStack[this.state.scopeStack.length - 1], r.forEach(function(c) { !c.kept && c.scopeId === o.id && e.track(c); }); }, n.prototype.gradients = function(t, e, r, i) { var a = this; if (i === void 0 && (i = false), E(e.length > 0, function() { return "gradients() received an empty list of xs."; }), r != null && r.dtype !== "float32") throw new Error("dy must have 'float32' dtype, but has '" + r.dtype + "'"); var s = this.scopedRun(function() { return a.startTape(); }, function() { return a.endTape(); }, function() { return a.tidy("forward", t); }); E(s instanceof K, function() { return "The result y returned by f() must be a tensor."; }); var o = EL(this.state.activeTape, e, s); if (!i && o.length === 0 && e.length > 0) throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that the f you passed encloses all operations that lead from x to y."); return this.tidy("backward", function() { var c = {}; c[s.id] = r ?? VL(s.shape), DL(c, o, function(u) { return a.tidy(u); }, GL); var l = e.map(function(u) { return c[u.id]; }); return a.state.gradientDepth === 0 && (a.state.activeTape.forEach(function(u) { for (var h = 0, d = u.saved; h < d.length; h++) { var p = d[h]; p.dispose(); } }), a.state.activeTape = null), {value: s, grads: l}; }); }, n.prototype.customGrad = function(t) { var e = this; return E(ur(t), function() { return "The f passed in customGrad(f) must be a function."; }), function() { for (var r = [], i = 0; i < arguments.length; i++) r[i] = arguments[i]; E(r.every(function(o) { return o instanceof K; }), function() { return "The args passed in customGrad(f)(x1, x2,...) must all be tensors"; }); var a, s = {}; return r.forEach(function(o, c) { s[c] = o; }), e.runKernelFunc(function(o, c) { return a = t.apply(void 0, r.concat([c])), E(a.value instanceof K, function() { return "The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"; }), E(ur(a.gradFunc), function() { return "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."; }), a.value; }, s, function(o, c) { var l = a.gradFunc(o, c), u = Array.isArray(l) ? l : [l]; E(u.length === r.length, function() { return "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns the same number of tensors as inputs passed to f(...)."; }), E(u.every(function(d) { return d instanceof K; }), function() { return "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors."; }); var h = {}; return u.forEach(function(d, p) { h[p] = function() { return d; }; }), h; }); }; }, n.prototype.readSync = function(t) { var e = this.state.tensorInfo.get(t); return e.backend.readSync(t); }, n.prototype.read = function(t) { var e = this.state.tensorInfo.get(t); return e.backend.read(t); }, n.prototype.time = function(t) { return pe(this, void 0, void 0, function() { var e, r; return fe(this, function(i) { switch (i.label) { case 0: return e = ou(), [4, this.backend.time(t)]; case 1: return r = i.sent(), r.wallMs = ou() - e, [2, r]; } }); }); }, n.prototype.track = function(t) { return this.state.activeScope != null && (t.scopeId = this.state.activeScope.id, this.state.activeScope.track.push(t)), t; }, Object.defineProperty(n.prototype, "registeredVariables", {get: function() { return this.state.registeredVariables; }, enumerable: true, configurable: true}), n.prototype.reset = function() { this.pendingBackendInitId++, this.state.dispose(), this.ENV.reset(), this.state = new dm(); for (var t in this.registry) this.disposeRegisteredKernels(t), this.registry[t].dispose(), delete this.registry[t]; this.backendName = null, this.backendInstance = null, this.pendingBackendInit = null; }, n.nextTensorId = 0, n.nextVariableId = 0, n; }(); function VL(n) { var t = hc(dt(n), "float32"); return z.makeTensor(t, n, "float32"); } function pm() { var n = of(); if (n._tfengine == null) { var t = new sf(n); n._tfengine = new qL(t); } return wL(n._tfengine.ENV), WL(function() { return n._tfengine; }), n._tfengine; } var z = pm(); function GL(n, t) { var e = {a: n, b: t}; return z.runKernelFunc(function(r, i) { var a = r.add(n, t); return i([n, t]), a; }, e, null, Ss); } function YL() { return typeof navigator != "undefined" && navigator != null; } function KL() { if (YL()) { var n = navigator.userAgent || navigator.vendor || window.opera; return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(n) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(n.substr(0, 4)); } return false; } function fm() { return typeof window != "undefined" && window.document != null || typeof WorkerGlobalScope != "undefined"; } var jL = {__proto__: null, isMobile: KL, isBrowser: fm}; var Kn = qe(); Kn.registerFlag("DEBUG", function() { return false; }, function(n) { n && console.warn("Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance."); }); Kn.registerFlag("IS_BROWSER", function() { return fm(); }); Kn.registerFlag("IS_NODE", function() { return typeof process != "undefined" && typeof process.versions != "undefined" && typeof process.versions.node != "undefined"; }); Kn.registerFlag("IS_CHROME", function() { return typeof navigator != "undefined" && navigator != null && navigator.userAgent != null && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor); }); Kn.registerFlag("PROD", function() { return false; }); Kn.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY", function() { return Kn.getBool("DEBUG"); }); Kn.registerFlag("DEPRECATION_WARNINGS_ENABLED", function() { return true; }); Kn.registerFlag("IS_TEST", function() { return false; }); function Cn(n, t) { var e = n; if (Ft(n)) return t === "string" ? [] : [n.length]; if (!Array.isArray(n)) return []; for (var r = []; Array.isArray(e) || Ft(e) && t !== "string"; ) r.push(e.length), e = e[0]; return Array.isArray(n) && qe().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY") && mm(n, r, []), r; } function mm(n, t, e) { if (e = e || [], !Array.isArray(n) && !Ft(n)) { E(t.length === 0, function() { return "Element arr[" + e.join("][") + "] is a primitive, " + ("but should be an array/TypedArray of " + t[0] + " elements"); }); return; } E(t.length > 0, function() { return "Element arr[" + e.join("][") + "] should be a primitive, " + ("but is an array of " + n.length + " elements"); }), E(n.length === t[0], function() { return "Element arr[" + e.join("][") + "] should have " + t[0] + " " + ("elements, but has " + n.length + " elements"); }); for (var r = t.slice(1), i = 0; i < n.length; ++i) mm(n[i], r, e.concat(i)); } function gm(n, t, e, r) { if (n == null) return; if (n !== "numeric" && n !== t || n === "numeric" && t === "string") throw new Error("Argument '" + e + "' passed to '" + r + "' must " + ("be " + n + " tensor, but got " + t + " tensor")); } function R(n, t, e, r) { if (r === void 0 && (r = "numeric"), n instanceof K) return gm(r, n.dtype, t, e), n; var i = xs(n); if (i !== "string" && ["bool", "int32", "float32"].indexOf(r) >= 0 && (i = r), gm(r, i, t, e), n == null || !Ft(n) && !Array.isArray(n) && typeof n != "number" && typeof n != "boolean" && typeof n != "string") { var a = n == null ? "null" : n.constructor.name; throw new Error("Argument '" + t + "' passed to '" + e + "' must be a " + ("Tensor or TensorLike, but got '" + a + "'")); } var s = Cn(n, i); !Ft(n) && !Array.isArray(n) && (n = [n]); var o = true, c = i !== "string" ? Ts(n, i) : zr(n, [], o); return z.makeTensor(c, s, i); } function Sa(n, t, e, r) { if (r === void 0 && (r = "numeric"), !Array.isArray(n)) throw new Error("Argument " + t + " passed to " + e + " must be a `Tensor[]` or `TensorLike[]`"); var i = n; return i.map(function(a, s) { return R(a, t + "[" + s + "]", e); }, r); } var ym = "__op"; function U(n) { var t = Object.keys(n); if (t.length !== 1) throw new Error("Please provide an object with a single key (operation name) mapping to a function. Got an object with " + (t.length + " keys.")); var e = t[0], r = n[e]; e.endsWith("_") && (e = e.substring(0, e.length - 1)), e = e + ym; var i = function() { for (var a = [], s = 0; s < arguments.length; s++) a[s] = arguments[s]; z.startScope(e); try { var o = r.apply(void 0, a); return pc(o) && console.error("Cannot return a Promise inside of tidy."), z.endScope(o), o; } catch (c) { throw z.endScope(null), c; } }; return Object.defineProperty(i, "name", {value: e, configurable: true}), i; } function $L(n, t) { var e = R(n, "real", "complex"), r = R(t, "imag", "complex"); Pe(e.shape, r.shape, "real and imag shapes, " + e.shape + " and " + r.shape + ", must match in call to tf.complex()."); var i = function(s) { return s.complex(e, r); }, a = {real: e, imag: r}; return z.runKernelFunc(i, a, null, pf); } var hr = U({complex_: $L}); function dr(n, t, e, r) { if (r == null && (r = xs(n)), r === "complex64") throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag)."); if (!Ft(n) && !Array.isArray(n) && typeof n != "number" && typeof n != "boolean" && typeof n != "string") throw new Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray"); if (t != null) { dc(t); var i = dt(t), a = dt(e); E(i === a, function() { return "Based on the provided shape, [" + t + "], the tensor should have " + (i + " values but has " + a); }); for (var s = 0; s < e.length; ++s) { var o = e[s], c = s === e.length - 1 ? o !== dt(t.slice(s)) : true; E(e[s] === t[s] || !c, function() { return "Error creating a new Tensor. Inferred shape " + ("(" + e + ") does not match the provided ") + ("shape (" + t + "). "); }); } } return !Ft(n) && !Array.isArray(n) && (n = [n]), t = t || e, n = r !== "string" ? Ts(n, r) : zr(n, [], true), z.makeTensor(n, t, r); } function pr(n, t, e) { var r = Cn(n, e); return dr(n, t, r, e); } var mu = {float32: 4, float16: 2, int32: 4, uint16: 2, uint8: 1, bool: 1, complex64: 8}; var Rs = 4; function JL(n, t) { return pe(this, void 0, void 0, function() { var e, r, i, a, s, o, c = this; return fe(this, function(l) { switch (l.label) { case 0: for (e = [], r = [], i = Array.isArray(n) ? n.map(function(u) { return u.name; }) : Object.keys(n), a = function(u) { var h = i[u], d = Array.isArray(n) ? n[u].tensor : n[h]; if (d.dtype !== "float32" && d.dtype !== "int32" && d.dtype !== "bool" && d.dtype !== "string" && d.dtype !== "complex64") throw new Error("Unsupported dtype in weight '" + h + "': " + d.dtype); var p = {name: h, shape: d.shape, dtype: d.dtype}; if (d.dtype === "string") { var f = new Promise(function(m) { return pe(c, void 0, void 0, function() { var g, y, w, b, x, L, N; return fe(this, function(I) { switch (I.label) { case 0: return [4, d.bytes()]; case 1: for (g = I.sent(), y = g.reduce(function(C, O) { return C + O.length; }, 0) + Rs * g.length, w = new Uint8Array(y), b = 0, x = 0; x < g.length; x++) L = g[x], N = new Uint8Array(new Uint32Array([L.length]).buffer), w.set(N, b), b += Rs, w.set(L, b), b += L.length; return m(w), [2]; } }); }); }); r.push(f); } else r.push(d.data()); t != null && (p.group = t), e.push(p); }, s = 0; s < i.length; ++s) a(s); return [4, Promise.all(r)]; case 1: return o = l.sent(), [2, {data: XL(o), specs: e}]; } }); }); } function vm(n, t) { for (var e = {}, r, i = 0, a = 0, s = t; a < s.length; a++) { var o = s[a], c = o.name, l = o.dtype, u = o.shape, h = dt(u), d = void 0; if ("quantization" in o) { var p = o.quantization; if (p.dtype === "uint8" || p.dtype === "uint16") { if (!("min" in p && "scale" in p)) throw new Error("Weight " + o.name + " with quantization " + p.dtype + " doesn't have corresponding metadata min and scale."); } else if (p.dtype === "float16") { if (l !== "float32") throw new Error("Weight " + o.name + " is quantized with " + p.dtype + " " + ("which only supports weights of type float32 not " + l + ".")); } else throw new Error("Weight " + o.name + " has unknown " + ("quantization dtype " + p.dtype + ". ") + "Supported quantization dtypes are: 'uint8', 'uint16', and 'float16'."); var f = mu[p.dtype], m = n.slice(i, i + h * f), g = p.dtype === "uint8" ? new Uint8Array(m) : new Uint16Array(m); if (l === "float32") if (p.dtype === "uint8" || p.dtype === "uint16") { d = new Float32Array(g.length); for (var y = 0; y < g.length; y++) { var w = g[y]; d[y] = w * p.scale + p.min; } } else if (p.dtype === "float16") r === void 0 && (r = ZL()), d = r(g); else throw new Error("Unsupported quantization type " + p.dtype + " for weight type float32."); else if (l === "int32") { if (p.dtype !== "uint8" && p.dtype !== "uint16") throw new Error("Unsupported quantization type " + p.dtype + " for weight type int32."); d = new Int32Array(g.length); for (var y = 0; y < g.length; y++) { var w = g[y]; d[y] = Math.round(w * p.scale + p.min); } } else throw new Error("Unsupported dtype in weight '" + c + "': " + l); i += h * f; } else if (l === "string") { var b = dt(o.shape); d = []; for (var y = 0; y < b; y++) { var x = new Uint32Array(n.slice(i, i + Rs))[0]; i += Rs; var L = new Uint8Array(n.slice(i, i + x)); d.push(L), i += x; } } else { var N = mu[l], m = n.slice(i, i + h * N); if (l === "float32") d = new Float32Array(m); else if (l === "int32") d = new Int32Array(m); else if (l === "bool") d = new Uint8Array(m); else if (l === "complex64") { d = new Float32Array(m); for (var I = new Float32Array(d.length / 2), C = new Float32Array(d.length / 2), y = 0; y < I.length; y++) I[y] = d[y * 2], C[y] = d[y * 2 + 1]; var O = pr(I, u, "float32"), D = pr(C, u, "float32"); e[c] = hr(O, D), O.dispose(), D.dispose(); } else throw new Error("Unsupported dtype in weight '" + c + "': " + l); i += h * N; } l !== "complex64" && (e[c] = pr(d, u, l)); } return e; } function XL(n) { if (n === null) throw new Error("Invalid input value: " + JSON.stringify(n)); var t = 0, e = []; n.forEach(function(a) { if (t += a.byteLength, e.push(a.byteLength === a.buffer.byteLength ? a : new a.constructor(a)), !(a instanceof Float32Array || a instanceof Int32Array || a instanceof Uint8Array)) throw new Error("Unsupported TypedArray subtype: " + a.constructor.name); }); var r = new Uint8Array(t), i = 0; return e.forEach(function(a) { r.set(new Uint8Array(a.buffer), i), i += a.byteLength; }), r.buffer; } var gu = typeof Buffer != "undefined" && (typeof Blob == "undefined" || typeof atob == "undefined" || typeof btoa == "undefined"); function wm(n) { return gu ? Buffer.byteLength(n) : new Blob([n]).size; } function QL(n) { if (gu) return Buffer.from(n).toString("base64"); for (var t = new Uint8Array(n), e = "", r = 0, i = t.length; r < i; r++) e += String.fromCharCode(t[r]); return btoa(e); } function eS(n) { if (gu) { var t = Buffer.from(n, "base64"); return t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength); } for (var e = atob(n), r = new Uint8Array(e.length), i = 0; i < e.length; ++i) r.set([e.charCodeAt(i)], i); return r.buffer; } function yu(n) { if (n.length === 1) return n[0]; var t = 0; n.forEach(function(i) { t += i.byteLength; }); var e = new Uint8Array(t), r = 0; return n.forEach(function(i) { e.set(new Uint8Array(i), r), r += i.byteLength; }), e.buffer; } function bm(n) { var t = "/"; for (n = n.trim(); n.endsWith(t); ) n = n.slice(0, n.length - 1); var e = n.split(t); return e[e.length - 1]; } function Ia(n) { if (n.modelTopology instanceof ArrayBuffer) throw new Error("Expected JSON model topology, received ArrayBuffer."); return {dateSaved: new Date(), modelTopologyType: "JSON", modelTopologyBytes: n.modelTopology == null ? 0 : wm(JSON.stringify(n.modelTopology)), weightSpecsBytes: n.weightSpecs == null ? 0 : wm(JSON.stringify(n.weightSpecs)), weightDataBytes: n.weightData == null ? 0 : n.weightData.byteLength}; } function tS() { var n = function(r) { for (var i = r << 13, a = 0; (i & 8388608) === 0; ) a -= 8388608, i <<= 1; return i &= ~8388608, a += 947912704, i | a; }, t = new Uint32Array(2048); t[0] = 0; for (var e = 1; e < 1024; e++) t[e] = n(e); for (var e = 1024; e < 2048; e++) t[e] = 939524096 + (e - 1024 << 13); return t; } function nS() { var n = new Uint32Array(64); n[0] = 0, n[31] = 1199570944, n[32] = 2147483648, n[63] = 3347054592; for (var t = 1; t < 31; t++) n[t] = t << 23; for (var t = 33; t < 63; t++) n[t] = 2147483648 + (t - 32 << 23); return n; } function rS() { for (var n = new Uint32Array(64), t = 0; t < 64; t++) n[t] = 1024; return n[0] = n[32] = 0, n; } function ZL() { var n = tS(), t = nS(), e = rS(); return function(r) { for (var i = new ArrayBuffer(4 * r.length), a = new Uint32Array(i), s = 0; s < r.length; s++) { var o = r[s], c = n[e[o >> 10] + (o & 1023)] + t[o >> 10]; a[s] = c; } return new Float32Array(i); }; } var rn = function() { function n() { this.saveRouters = [], this.loadRouters = []; } return n.getInstance = function() { return n.instance == null && (n.instance = new n()), n.instance; }, n.registerSaveRouter = function(t) { n.getInstance().saveRouters.push(t); }, n.registerLoadRouter = function(t) { n.getInstance().loadRouters.push(t); }, n.getSaveHandlers = function(t) { return n.getHandlers(t, "save"); }, n.getLoadHandlers = function(t, e) { return n.getHandlers(t, "load", e); }, n.getHandlers = function(t, e, r) { var i = [], a = e === "load" ? n.getInstance().loadRouters : n.getInstance().saveRouters; return a.forEach(function(s) { var o = s(t, r); o !== null && i.push(o); }), i; }, n; }(), iS = function(n) { return rn.registerSaveRouter(n); }, aS = function(n) { return rn.registerLoadRouter(n); }, sS = function(n) { return rn.getSaveHandlers(n); }, oS = function(n, t) { return rn.getLoadHandlers(n, t); }; var vu = "tensorflowjs", wu = 1, Pr = "models_store", fr = "model_info_store"; function xm() { if (!qe().getBool("IS_BROWSER")) throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser."); var n = typeof window == "undefined" ? self : window, t = n.indexedDB || n.mozIndexedDB || n.webkitIndexedDB || n.msIndexedDB || n.shimIndexedDB; if (t == null) throw new Error("The current browser does not appear to support IndexedDB."); return t; } function bu(n) { var t = n.result; t.createObjectStore(Pr, {keyPath: "modelPath"}), t.createObjectStore(fr, {keyPath: "modelPath"}); } var Ti = function() { function n(t) { if (this.indexedDB = xm(), t == null || !t) throw new Error("For IndexedDB, modelPath must not be null, undefined or empty."); this.modelPath = t; } return n.prototype.save = function(t) { return pe(this, void 0, void 0, function() { return fe(this, function(e) { if (t.modelTopology instanceof ArrayBuffer) throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet."); return [2, this.databaseAction(this.modelPath, t)]; }); }); }, n.prototype.load = function() { return pe(this, void 0, void 0, function() { return fe(this, function(t) { return [2, this.databaseAction(this.modelPath)]; }); }); }, n.prototype.databaseAction = function(t, e) { var r = this; return new Promise(function(i, a) { var s = r.indexedDB.open(vu, wu); s.onupgradeneeded = function() { return bu(s); }, s.onsuccess = function() { var o = s.result; if (e == null) { var c = o.transaction(Pr, "readonly"), l = c.objectStore(Pr), u = l.get(r.modelPath); u.onsuccess = function() { if (u.result == null) return o.close(), a(new Error("Cannot find model with path '" + r.modelPath + "' in IndexedDB.")); i(u.result.modelArtifacts); }, u.onerror = function(g) { return o.close(), a(u.error); }, c.oncomplete = function() { return o.close(); }; } else { var h = Ia(e), d = o.transaction(fr, "readwrite"), p = d.objectStore(fr), f = p.put({modelPath: r.modelPath, modelArtifactsInfo: h}), m; f.onsuccess = function() { m = o.transaction(Pr, "readwrite"); var g = m.objectStore(Pr), y = g.put({modelPath: r.modelPath, modelArtifacts: e, modelArtifactsInfo: h}); y.onsuccess = function() { return i({modelArtifactsInfo: h}); }, y.onerror = function(w) { p = d.objectStore(fr); var b = p.delete(r.modelPath); b.onsuccess = function() { return o.close(), a(y.error); }, b.onerror = function(x) { return o.close(), a(y.error); }; }; }, f.onerror = function(g) { return o.close(), a(f.error); }, d.oncomplete = function() { m == null ? o.close() : m.oncomplete = function() { return o.close(); }; }; } }, s.onerror = function(o) { return a(s.error); }; }); }, n.URL_SCHEME = "indexeddb://", n; }(), Lm = function(n) { return qe().getBool("IS_BROWSER") && (!Array.isArray(n) && n.startsWith(Ti.URL_SCHEME)) ? cS(n.slice(Ti.URL_SCHEME.length)) : null; }; rn.registerSaveRouter(Lm); rn.registerLoadRouter(Lm); function cS(n) { return new Ti(n); } function lS(n) { return n.startsWith(Ti.URL_SCHEME) ? n.slice(Ti.URL_SCHEME.length) : n; } var uS = function() { function n() { this.indexedDB = xm(); } return n.prototype.listModels = function() { return pe(this, void 0, void 0, function() { var t = this; return fe(this, function(e) { return [2, new Promise(function(r, i) { var a = t.indexedDB.open(vu, wu); a.onupgradeneeded = function() { return bu(a); }, a.onsuccess = function() { var s = a.result, o = s.transaction(fr, "readonly"), c = o.objectStore(fr), l = c.getAll(); l.onsuccess = function() { for (var u = {}, h = 0, d = l.result; h < d.length; h++) { var p = d[h]; u[p.modelPath] = p.modelArtifactsInfo; } r(u); }, l.onerror = function(u) { return s.close(), i(l.error); }, o.oncomplete = function() { return s.close(); }; }, a.onerror = function(s) { return i(a.error); }; })]; }); }); }, n.prototype.removeModel = function(t) { return pe(this, void 0, void 0, function() { var e = this; return fe(this, function(r) { return t = lS(t), [2, new Promise(function(i, a) { var s = e.indexedDB.open(vu, wu); s.onupgradeneeded = function() { return bu(s); }, s.onsuccess = function() { var o = s.result, c = o.transaction(fr, "readwrite"), l = c.objectStore(fr), u = l.get(t), h; u.onsuccess = function() { if (u.result == null) return o.close(), a(new Error("Cannot find model with path '" + t + "' in IndexedDB.")); var d = l.delete(t), p = function() { h = o.transaction(Pr, "readwrite"); var f = h.objectStore(Pr), m = f.delete(t); m.onsuccess = function() { return i(u.result.modelArtifactsInfo); }, m.onerror = function(g) { return a(u.error); }; }; d.onsuccess = p, d.onerror = function(f) { return p(), o.close(), a(u.error); }; }, u.onerror = function(d) { return o.close(), a(u.error); }, c.oncomplete = function() { h == null ? o.close() : h.oncomplete = function() { return o.close(); }; }; }, s.onerror = function(o) { return a(s.error); }; })]; }); }); }, n; }(); var jn = "/", Ni = "tensorflowjs_models", Sm = "info", hS = "model_topology", dS = "weight_specs", pS = "weight_data", fS = "model_metadata"; function Im(n) { return {info: [Ni, n, Sm].join(jn), topology: [Ni, n, hS].join(jn), weightSpecs: [Ni, n, dS].join(jn), weightData: [Ni, n, pS].join(jn), modelMetadata: [Ni, n, fS].join(jn)}; } function mS(n) { var t = n.split(jn); if (t.length < 3) throw new Error("Invalid key format: " + n); return t.slice(1, t.length - 1).join(jn); } function gS(n) { return n.startsWith(_i.URL_SCHEME) ? n.slice(_i.URL_SCHEME.length) : n; } var _i = function() { function n(t) { if (!qe().getBool("IS_BROWSER") || typeof window == "undefined" || typeof window.localStorage == "undefined") throw new Error("The current environment does not support local storage."); if (this.LS = window.localStorage, t == null || !t) throw new Error("For local storage, modelPath must not be null, undefined or empty."); this.modelPath = t, this.keys = Im(this.modelPath); } return n.prototype.save = function(t) { return pe(this, void 0, void 0, function() { var e, r, i; return fe(this, function(a) { if (t.modelTopology instanceof ArrayBuffer) throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet."); e = JSON.stringify(t.modelTopology), r = JSON.stringify(t.weightSpecs), i = Ia(t); try { return this.LS.setItem(this.keys.info, JSON.stringify(i)), this.LS.setItem(this.keys.topology, e), this.LS.setItem(this.keys.weightSpecs, r), this.LS.setItem(this.keys.weightData, QL(t.weightData)), this.LS.setItem(this.keys.modelMetadata, JSON.stringify({format: t.format, generatedBy: t.generatedBy, convertedBy: t.convertedBy, userDefinedMetadata: t.userDefinedMetadata})), [2, {modelArtifactsInfo: i}]; } catch (s) { throw this.LS.removeItem(this.keys.info), this.LS.removeItem(this.keys.topology), this.LS.removeItem(this.keys.weightSpecs), this.LS.removeItem(this.keys.weightData), this.LS.removeItem(this.keys.modelMetadata), new Error("Failed to save model '" + this.modelPath + "' to local storage: size quota being exceeded is a possible cause of this failure: " + ("modelTopologyBytes=" + i.modelTopologyBytes + ", ") + ("weightSpecsBytes=" + i.weightSpecsBytes + ", ") + ("weightDataBytes=" + i.weightDataBytes + ".")); } return [2]; }); }); }, n.prototype.load = function() { return pe(this, void 0, void 0, function() { var t, e, r, i, a, s, o; return fe(this, function(c) { if (t = JSON.parse(this.LS.getItem(this.keys.info)), t == null) throw new Error("In local storage, there is no model with name '" + this.modelPath + "'"); if (t.modelTopologyType !== "JSON") throw new Error("BrowserLocalStorage does not support loading non-JSON model topology yet."); if (e = {}, r = JSON.parse(this.LS.getItem(this.keys.topology)), r == null) throw new Error("In local storage, the topology of model '" + this.modelPath + "' is missing."); if (e.modelTopology = r, i = JSON.parse(this.LS.getItem(this.keys.weightSpecs)), i == null) throw new Error("In local storage, the weight specs of model '" + this.modelPath + "' are missing."); if (e.weightSpecs = i, a = this.LS.getItem(this.keys.modelMetadata), a != null && (s = JSON.parse(a), e.format = s.format, e.generatedBy = s.generatedBy, e.convertedBy = s.convertedBy, e.userDefinedMetadata = s.userDefinedMetadata), o = this.LS.getItem(this.keys.weightData), o == null) throw new Error("In local storage, the binary weight values of model " + ("'" + this.modelPath + "' are missing.")); return e.weightData = eS(o), [2, e]; }); }); }, n.URL_SCHEME = "localstorage://", n; }(), Am = function(n) { return qe().getBool("IS_BROWSER") && (!Array.isArray(n) && n.startsWith(_i.URL_SCHEME)) ? yS(n.slice(_i.URL_SCHEME.length)) : null; }; rn.registerSaveRouter(Am); rn.registerLoadRouter(Am); function yS(n) { return new _i(n); } var vS = function() { function n() { E(qe().getBool("IS_BROWSER"), function() { return "Current environment is not a web browser"; }), E(typeof window == "undefined" || typeof window.localStorage != "undefined", function() { return "Current browser does not appear to support localStorage"; }), this.LS = window.localStorage; } return n.prototype.listModels = function() { return pe(this, void 0, void 0, function() { var t, e, r, i, a, s; return fe(this, function(o) { for (t = {}, e = Ni + jn, r = jn + Sm, i = 0; i < this.LS.length; ++i) a = this.LS.key(i), a.startsWith(e) && a.endsWith(r) && (s = mS(a), t[s] = JSON.parse(this.LS.getItem(a))); return [2, t]; }); }); }, n.prototype.removeModel = function(t) { return pe(this, void 0, void 0, function() { var e, r; return fe(this, function(i) { if (t = gS(t), e = Im(t), this.LS.getItem(e.info) == null) throw new Error("Cannot find model at path '" + t + "'"); return r = JSON.parse(this.LS.getItem(e.info)), this.LS.removeItem(e.info), this.LS.removeItem(e.topology), this.LS.removeItem(e.weightSpecs), this.LS.removeItem(e.weightData), [2, r]; }); }); }, n; }(); var Ci = "://", mr = function() { function n() { this.managers = {}; } return n.getInstance = function() { return n.instance == null && (n.instance = new n()), n.instance; }, n.registerManager = function(t, e) { E(t != null, function() { return "scheme must not be undefined or null."; }), t.endsWith(Ci) && (t = t.slice(0, t.indexOf(Ci))), E(t.length > 0, function() { return "scheme must not be an empty string."; }); var r = n.getInstance(); E(r.managers[t] == null, function() { return "A model store manager is already registered for scheme '" + t + "'."; }), r.managers[t] = e; }, n.getManager = function(t) { var e = this.getInstance().managers[t]; if (e == null) throw new Error("Cannot find model manager for scheme '" + t + "'"); return e; }, n.getSchemes = function() { return Object.keys(this.getInstance().managers); }, n; }(); function Os(n) { if (n.indexOf(Ci) === -1) throw new Error("The url string provided does not contain a scheme. Supported schemes are: " + ("" + mr.getSchemes().join(","))); return {scheme: n.split(Ci)[0], path: n.split(Ci)[1]}; } function Tm(n, t, e) { return e === void 0 && (e = false), pe(this, void 0, void 0, function() { var r, i, a, s, o, c, l, u, h; return fe(this, function(d) { switch (d.label) { case 0: return E(n !== t, function() { return "Old path and new path are the same: '" + n + "'"; }), r = rn.getLoadHandlers(n), E(r.length > 0, function() { return "Copying failed because no load handler is found for source URL " + n + "."; }), E(r.length < 2, function() { return "Copying failed because more than one (" + r.length + ") " + ("load handlers for source URL " + n + "."); }), i = r[0], a = rn.getSaveHandlers(t), E(a.length > 0, function() { return "Copying failed because no save handler is found for destination " + ("URL " + t + "."); }), E(a.length < 2, function() { return "Copying failed because more than one (" + r.length + ") " + ("save handlers for destination URL " + t + "."); }), s = a[0], o = Os(n).scheme, c = Os(n).path, l = o === Os(n).scheme, [4, i.load()]; case 1: return u = d.sent(), e && l ? [4, mr.getManager(o).removeModel(c)] : [3, 3]; case 2: d.sent(), d.label = 3; case 3: return [4, s.save(u)]; case 4: return h = d.sent(), e && !l ? [4, mr.getManager(o).removeModel(c)] : [3, 6]; case 5: d.sent(), d.label = 6; case 6: return [2, h.modelArtifactsInfo]; } }); }); } function wS() { return pe(this, void 0, void 0, function() { var n, t, e, r, i, a, s, o; return fe(this, function(c) { switch (c.label) { case 0: n = mr.getSchemes(), t = {}, e = 0, r = n, c.label = 1; case 1: return e < r.length ? (i = r[e], [4, mr.getManager(i).listModels()]) : [3, 4]; case 2: a = c.sent(); for (s in a) o = i + Ci + s, t[o] = a[s]; c.label = 3; case 3: return e++, [3, 1]; case 4: return [2, t]; } }); }); } function bS(n) { return pe(this, void 0, void 0, function() { var t, e; return fe(this, function(r) { return t = Os(n), e = mr.getManager(t.scheme), [2, e.removeModel(t.path)]; }); }); } function xS(n, t) { return pe(this, void 0, void 0, function() { var e; return fe(this, function(r) { return e = false, [2, Tm(n, t, e)]; }); }); } function LS(n, t) { return pe(this, void 0, void 0, function() { var e; return fe(this, function(r) { return e = true, [2, Tm(n, t, e)]; }); }); } var SS = function() { function n() { } return n.prototype.fetch = function(t, e) { return fetch(t, e); }, n.prototype.now = function() { return performance.now(); }, n.prototype.encode = function(t, e) { if (e !== "utf-8" && e !== "utf8") throw new Error("Browser's encoder only supports utf-8, but got " + e); return this.textEncoder == null && (this.textEncoder = new TextEncoder()), this.textEncoder.encode(t); }, n.prototype.decode = function(t, e) { return new TextDecoder(e).decode(t); }, n; }(); if (qe().get("IS_BROWSER")) { qe().setPlatform("browser", new SS()); try { mr.registerManager(_i.URL_SCHEME, new vS()); } catch (n) { } try { mr.registerManager(Ti.URL_SCHEME, new uS()); } catch (n) { } } var IS = {importFetch: function() { return Vp(); }}, xu, AS = function() { function n() { this.util = Gp(), this.textEncoder = new this.util.TextEncoder(); } return n.prototype.fetch = function(t, e) { return qe().global.fetch != null ? qe().global.fetch(t, e) : (xu == null && (xu = IS.importFetch()), xu(t, e)); }, n.prototype.now = function() { var t = process.hrtime(); return t[0] * 1e3 + t[1] / 1e6; }, n.prototype.encode = function(t, e) { if (e !== "utf-8" && e !== "utf8") throw new Error("Node built-in encoder only supports utf-8, but got " + e); return this.textEncoder.encode(t); }, n.prototype.decode = function(t, e) { return t.length === 0 ? "" : new this.util.TextDecoder(e).decode(t); }, n; }(); qe().get("IS_NODE") && qe().setPlatform("node", new AS()); function Rn(n, t, e) { return t === void 0 && (t = "float32"), t = t || "float32", dc(n), new _s(n, t, e); } function TS(n, t) { var e = R(n, "x", "cast"); if (!Jp(t)) throw new Error("Failed to cast to unknown dtype " + t); if (t === "string" && e.dtype !== "string" || t !== "string" && e.dtype === "string") throw new Error("Only strings can be casted to strings"); var r = {x: e}, i = {dtype: t}; return z.runKernelFunc(function(a) { return a.cast(e, t); }, r, null, Is, i); } var he = U({cast_: TS}); function NS(n) { var t = R(n, "x", "clone", null), e = function() { return z.makeTensorFromDataId(t.dataId, t.shape, t.dtype); }, r = {x: t}; return z.runKernelFunc(e, r, null, Zc); } var Mr = U({clone_: NS}); function Nm(n, t) { t === void 0 && (t = false), console.log(n.toString(t)); } pm(); var _S = {buffer: Rn, cast: he, clone: Mr, print: Nm}; UL(_S); var CS = "model", RS = ".json", OS = ".weights.bin"; function _m(n) { return new Promise(function(t) { return setTimeout(t); }).then(n); } var Lu = function() { function n(t) { if (!qe().getBool("IS_BROWSER")) throw new Error("browserDownloads() cannot proceed because the current environment is not a browser."); t.startsWith(n.URL_SCHEME) && (t = t.slice(n.URL_SCHEME.length)), (t == null || t.length === 0) && (t = CS), this.modelTopologyFileName = t + RS, this.weightDataFileName = t + OS; } return n.prototype.save = function(t) { return pe(this, void 0, void 0, function() { var e, r, i, a, s, o; return fe(this, function(c) { switch (c.label) { case 0: if (typeof document == "undefined") throw new Error("Browser downloads are not supported in this environment since `document` is not present"); if (e = window.URL.createObjectURL(new Blob([t.weightData], {type: "application/octet-stream"})), !(t.modelTopology instanceof ArrayBuffer)) return [3, 1]; throw new Error("BrowserDownloads.save() does not support saving model topology in binary formats yet."); case 1: return r = [{paths: ["./" + this.weightDataFileName], weights: t.weightSpecs}], i = {modelTopology: t.modelTopology, format: t.format, generatedBy: t.generatedBy, convertedBy: t.convertedBy, weightsManifest: r}, a = window.URL.createObjectURL(new Blob([JSON.stringify(i)], {type: "application/json"})), s = this.jsonAnchor == null ? document.createElement("a") : this.jsonAnchor, s.download = this.modelTopologyFileName, s.href = a, [4, _m(function() { return s.dispatchEvent(new MouseEvent("click")); })]; case 2: return c.sent(), t.weightData != null ? (o = this.weightDataAnchor == null ? document.createElement("a") : this.weightDataAnchor, o.download = this.weightDataFileName, o.href = e, [4, _m(function() { return o.dispatchEvent(new MouseEvent("click")); })]) : [3, 4]; case 3: c.sent(), c.label = 4; case 4: return [2, {modelArtifactsInfo: Ia(t)}]; } }); }); }, n.URL_SCHEME = "downloads://", n; }(), ES = function() { function n(t) { if (t == null || t.length < 1) throw new Error("When calling browserFiles, at least 1 file is required, " + ("but received " + t)); this.files = t; } return n.prototype.load = function() { return pe(this, void 0, void 0, function() { var t, e, r = this; return fe(this, function(i) { return t = this.files[0], e = this.files.slice(1), [2, new Promise(function(a, s) { var o = new FileReader(); o.onload = function(c) { var l = JSON.parse(c.target.result), u = l.modelTopology; if (u == null) { s(new Error("modelTopology field is missing from file " + t.name)); return; } e.length === 0 && a({modelTopology: u}); var h = l.weightsManifest; if (h == null) { s(new Error("weightManifest field is missing from file " + t.name)); return; } var d; try { d = r.checkManifestAndWeightFiles(h, e); } catch (g) { s(g); return; } var p = [], f = [], m = []; h.forEach(function(g) { g.paths.forEach(function(y) { f.push(y), m.push(null); }), p.push.apply(p, g.weights); }), h.forEach(function(g) { g.paths.forEach(function(y) { var w = new FileReader(); w.onload = function(b) { var x = b.target.result, L = f.indexOf(y); m[L] = x, m.indexOf(null) === -1 && a({modelTopology: u, weightSpecs: p, weightData: yu(m), format: l.format, generatedBy: l.generatedBy, convertedBy: l.convertedBy, userDefinedMetadata: l.userDefinedMetadata}); }, w.onerror = function(b) { return s("Failed to weights data from file of path '" + y + "'."); }, w.readAsArrayBuffer(d[y]); }); }); }, o.onerror = function(c) { return s("Failed to read model topology and weights manifest JSON " + ("from file '" + t.name + "'. BrowserFiles supports loading ") + "Keras-style tf.Model artifacts only."); }, o.readAsText(t); })]; }); }); }, n.prototype.checkManifestAndWeightFiles = function(t, e) { for (var r = [], i = e.map(function(l) { return bm(l.name); }), a = {}, s = 0, o = t; s < o.length; s++) { var c = o[s]; c.paths.forEach(function(l) { var u = bm(l); if (r.indexOf(u) !== -1) throw new Error("Duplicate file basename found in weights manifest: " + ("'" + u + "'")); if (r.push(u), i.indexOf(u) === -1) throw new Error("Weight file with basename '" + u + "' is not provided."); a[l] = e[i.indexOf(u)]; }); } if (r.length !== e.length) throw new Error("Mismatch in the number of files in weights manifest " + ("(" + r.length + ") and the number of weight files provided ") + ("(" + e.length + ").")); return a; }, n; }(), kS = function(n) { return qe().getBool("IS_BROWSER") && (!Array.isArray(n) && n.startsWith(Lu.URL_SCHEME)) ? DS(n.slice(Lu.URL_SCHEME.length)) : null; }; rn.registerSaveRouter(kS); function DS(n) { return n === void 0 && (n = "model"), new Lu(n); } function FS(n) { return new ES(n); } function Cm(n, t, e, r) { s(n), e = e ?? 0, r = r ?? 1, o(e, r); var i = 0, a = function(c) { return c.then(function(l) { var u = e + ++i / n.length * (r - e); return t(u), l; }), c; }; function s(c) { E(c != null && Array.isArray(c) && c.length > 0, function() { return "promises must be a none empty array"; }); } function o(c, l) { E(c >= 0 && c <= 1, function() { return "Progress fraction must be in range [0, 1], but " + ("got startFraction " + c); }), E(l >= 0 && l <= 1, function() { return "Progress fraction must be in range [0, 1], but " + ("got endFraction " + l); }), E(l >= c, function() { return "startFraction must be no more than endFraction, but " + ("got startFraction " + c + " and endFraction ") + ("" + l); }); } return Promise.all(n.map(a)); } function Rm(n, t) { return pe(this, void 0, void 0, function() { var e, r, i, a, s, o, c, l, u, h, d; return fe(this, function(p) { switch (p.label) { case 0: return t == null && (t = {}), e = t.fetchFunc == null ? qe().platform.fetch : t.fetchFunc, r = n.map(function(f) { return e(f, t.requestInit, {isBinary: true}); }), i = 0, a = 0.5, t.onProgress == null ? [4, Promise.all(r)] : [3, 2]; case 1: return o = p.sent(), [3, 4]; case 2: return [4, Cm(r, t.onProgress, i, a)]; case 3: o = p.sent(), p.label = 4; case 4: return s = o, c = s.map(function(f) { return f.arrayBuffer(); }), l = 0.5, u = 1, t.onProgress == null ? [4, Promise.all(c)] : [3, 6]; case 5: return d = p.sent(), [3, 8]; case 6: return [4, Cm(c, t.onProgress, l, u)]; case 7: d = p.sent(), p.label = 8; case 8: return h = d, [2, h]; } }); }); } function WS(n, t, e, r) { return t === void 0 && (t = ""), pe(this, void 0, void 0, function() { var i, a; return fe(this, function(s) { return i = function(o) { return Rm(o, {requestInit: r}); }, a = Om(i), [2, a(n, t, e)]; }); }); } function Om(n) { var t = this; return function(e, r, i) { return r === void 0 && (r = ""), pe(t, void 0, void 0, function() { var a, s, o, c, l, u, h, d, p, f; return fe(this, function(m) { switch (m.label) { case 0: if (a = e.map(function() { return false; }), s = {}, o = i != null ? i.map(function() { return false; }) : [], c = [], e.forEach(function(g, y) { var w = 0; g.weights.forEach(function(b) { var x = "quantization" in b ? b.quantization.dtype : b.dtype, L = mu[x] * dt(b.shape), N = function() { a[y] = true, s[y] == null && (s[y] = []), s[y].push({manifestEntry: b, groupOffset: w, sizeBytes: L}); }; i != null ? i.forEach(function(I, C) { I === b.name && (N(), o[C] = true); }) : N(), c.push(b.name), w += L; }); }), !o.every(function(g) { return g; })) throw l = i.filter(function(g, y) { return !o[y]; }), new Error("Could not find weights in manifest with names: " + (l.join(", ") + `. `) + "Manifest JSON has weights with names: " + (c.join(", ") + ".")); return u = a.reduce(function(g, y, w) { return y && g.push(w), g; }, []), h = [], u.forEach(function(g) { e[g].paths.forEach(function(y) { var w = r + (r.endsWith("/") ? "" : "/") + y; h.push(w); }); }), [4, n(h)]; case 1: return d = m.sent(), p = {}, f = 0, u.forEach(function(g) { for (var y = e[g].paths.length, w = 0, b = 0; b < y; b++) w += d[f + b].byteLength; for (var x = new ArrayBuffer(w), L = new Uint8Array(x), N = 0, I = 0; I < y; I++) { var C = new Uint8Array(d[f + I]); L.set(C, N), N += C.byteLength; } var O = s[g]; O.forEach(function(D) { var F = x.slice(D.groupOffset, D.groupOffset + D.sizeBytes), k = vm(F, [D.manifestEntry]); for (var B in k) p[B] = k[B]; }), f += y; }), [2, p]; } }); }); }; } var US = "application/octet-stream", BS = "application/json", Em = function() { function n(t, e) { if (this.DEFAULT_METHOD = "POST", e == null && (e = {}), this.weightPathPrefix = e.weightPathPrefix, this.onProgress = e.onProgress, this.weightUrlConverter = e.weightUrlConverter, e.fetchFunc != null ? (E(typeof e.fetchFunc == "function", function() { return "Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"; }), this.fetch = e.fetchFunc) : this.fetch = qe().platform.fetch, E(t != null && t.length > 0, function() { return "URL path for http must not be null, undefined or empty."; }), Array.isArray(t) && E(t.length === 2, function() { return "URL paths for http must have a length of 2, " + ("(actual length is " + t.length + ")."); }), this.path = t, e.requestInit != null && e.requestInit.body != null) throw new Error("requestInit is expected to have no pre-existing body, but has one."); this.requestInit = e.requestInit || {}; } return n.prototype.save = function(t) { return pe(this, void 0, void 0, function() { var e, r, i, a; return fe(this, function(s) { switch (s.label) { case 0: if (t.modelTopology instanceof ArrayBuffer) throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet."); return e = Object.assign({method: this.DEFAULT_METHOD}, this.requestInit), e.body = new FormData(), r = [{paths: ["./model.weights.bin"], weights: t.weightSpecs}], i = {modelTopology: t.modelTopology, format: t.format, generatedBy: t.generatedBy, convertedBy: t.convertedBy, userDefinedMetadata: t.userDefinedMetadata, weightsManifest: r}, e.body.append("model.json", new Blob([JSON.stringify(i)], {type: BS}), "model.json"), t.weightData != null && e.body.append("model.weights.bin", new Blob([t.weightData], {type: US}), "model.weights.bin"), [4, this.fetch(this.path, e)]; case 1: if (a = s.sent(), a.ok) return [2, {modelArtifactsInfo: Ia(t), responses: [a]}]; throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status " + (a.status + ".")); } }); }); }, n.prototype.load = function() { return pe(this, void 0, void 0, function() { var t, e, r, i, a, s, o, c, l, u, h, d, p, f, m; return fe(this, function(g) { switch (g.label) { case 0: return [4, this.fetch(this.path, this.requestInit)]; case 1: if (t = g.sent(), !t.ok) throw new Error("Request to " + this.path + " failed with status code " + (t.status + ". Please verify this URL points to ") + "the model JSON of the model to load."); g.label = 2; case 2: return g.trys.push([2, 4, , 5]), [4, t.json()]; case 3: return e = g.sent(), [3, 5]; case 4: throw r = g.sent(), i = "Failed to parse model JSON of response from " + this.path + ".", this.path.endsWith(".pb") ? i += " Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository." : i += " Please make sure the server is serving valid JSON for this request.", new Error(i); case 5: if (a = e.modelTopology, s = e.weightsManifest, o = e.generatedBy, c = e.convertedBy, l = e.format, u = e.userDefinedMetadata, a == null && s == null) throw new Error("The JSON from HTTP path " + this.path + " contains neither model topology or manifest for weights."); return s != null ? [4, this.loadWeights(s)] : [3, 7]; case 6: p = g.sent(), h = p[0], d = p[1], g.label = 7; case 7: return f = {modelTopology: a, weightSpecs: h, weightData: d, userDefinedMetadata: u, generatedBy: o, convertedBy: c, format: l}, m = e.modelInitializer, m && (f.modelInitializer = m), [2, f]; } }); }); }, n.prototype.loadWeights = function(t) { return pe(this, void 0, void 0, function() { var e, r, i, a, s, o, c, l, u, h, d, p, f, m, g, y, w, b, x, L, N; return fe(this, function(I) { switch (I.label) { case 0: for (e = Array.isArray(this.path) ? this.path[1] : this.path, r = zS(e), i = r[0], a = r[1], s = this.weightPathPrefix || i, o = [], c = 0, l = t; c < l.length; c++) u = l[c], o.push.apply(o, u.weights); for (h = [], d = [], p = 0, f = t; p < f.length; p++) for (m = f[p], g = 0, y = m.paths; g < y.length; g++) w = y[g], this.weightUrlConverter != null ? d.push(this.weightUrlConverter(w)) : h.push(s + w + a); return this.weightUrlConverter ? (x = (b = h.push).apply, L = [h], [4, Promise.all(d)]) : [3, 2]; case 1: x.apply(b, L.concat([I.sent()])), I.label = 2; case 2: return [4, Rm(h, {requestInit: this.requestInit, fetchFunc: this.fetch, onProgress: this.onProgress})]; case 3: return N = I.sent(), [2, [o, yu(N)]]; } }); }); }, n.URL_SCHEME_REGEX = /^https?:\/\//, n; }(); function zS(n) { var t = n.lastIndexOf("/"), e = n.lastIndexOf("?"), r = n.substring(0, t), i = e > t ? n.substring(e) : ""; return [r + "/", i]; } function Su(n) { return n.match(Em.URL_SCHEME_REGEX) != null; } var Dm = function(n, t) { if (typeof fetch == "undefined" && (t == null || t.fetchFunc == null)) return null; var e = true; return Array.isArray(n) ? e = n.every(function(r) { return Su(r); }) : e = Su(n), e ? Iu(n, t) : null; }; rn.registerSaveRouter(Dm); rn.registerLoadRouter(Dm); function Iu(n, t) { return new Em(n, t); } function PS(n, t) { return Iu(n, t); } var Au = function() { function n(t) { this.modelArtifacts = t; } return n.prototype.load = function() { return pe(this, void 0, void 0, function() { return fe(this, function(t) { return [2, this.modelArtifacts]; }); }); }, n; }(), MS = function() { function n(t) { this.saveHandler = t; } return n.prototype.save = function(t) { return pe(this, void 0, void 0, function() { return fe(this, function(e) { return [2, this.saveHandler(t)]; }); }); }, n; }(); function HS(n, t, e, r) { if (arguments.length === 1) { var i = n.modelTopology != null || n.weightSpecs != null; return i ? new Au(n) : (console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."), new Au({modelTopology: n})); } else return console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."), new Au({modelTopology: n, weightSpecs: t, weightData: e, trainingConfig: r}); } function VS(n) { return new MS(n); } var GS = {__proto__: null, browserFiles: FS, browserHTTPRequest: PS, concatenateArrayBuffers: yu, decodeWeights: vm, encodeWeights: JL, fromMemory: HS, getLoadHandlers: oS, getModelArtifactsInfoForJSON: Ia, getSaveHandlers: sS, http: Iu, isHTTPScheme: Su, loadWeights: WS, registerLoadRouter: aS, registerSaveRouter: iS, weightsLoaderFactory: Om, withSaveHandler: VS, copyModel: xS, listModels: wS, moveModel: LS, removeModel: bS}; function qS(n, t) { var e = R(n, "x", "reshape", null), r = {x: e}, i = {shape: t}, a = function(s, o) { return t = Kp(t, e.size), E(e.size === dt(t), function() { return "new shape and old shape must have the same number of elements."; }), o([e]), s.reshape(e, t); }; return z.runKernelFunc(a, r, null, Sl, i); } var Y = U({reshape_: qS}); function YS(n, t, e, r) { var i; e === void 0 && (e = false), r === void 0 && (r = false); var a = R(n, "a", "matMul"), s = R(t, "b", "matMul"); i = ct(a, s), a = i[0], s = i[1]; var o = function(u, h) { h([a, s]); var d = e ? a.shape[a.rank - 2] : a.shape[a.rank - 1], p = r ? s.shape[s.rank - 1] : s.shape[s.rank - 2], f = e ? a.shape[a.rank - 1] : a.shape[a.rank - 2], m = r ? s.shape[s.rank - 2] : s.shape[s.rank - 1], g = a.shape.slice(0, -2), y = s.shape.slice(0, -2), w = dt(g), b = dt(y), x = w === b || w === 1 || b === 1; E(a.rank >= 2 && s.rank >= 2 && x, function() { return "Error in matMul: the input batch dimensions must either be the same or at least one input batch dimension must be 1. Got input " + ("batch dimensions of (" + g + ") and (" + y + ")."); }), E(d === p, function() { return "Error in matMul: inner shapes (" + d + ") and (" + (p + ") of Tensors with shapes " + a.shape + " and ") + (s.shape + " and transposeA=" + e) + (" and transposeB=" + r + " must match."); }); var L = w > b ? g : y, N = L.concat([f, m]), I = e ? Y(a, [w, d, f]) : Y(a, [w, f, d]), C = r ? Y(s, [b, m, p]) : Y(s, [b, p, m]), O = u.batchMatMul(I, C, e, r); return Y(O, N); }, c = {a, b: s}, l = {transposeA: e, transposeB: r}; return z.runKernelFunc(o, c, null, _c, l); } var Ue = U({matMul_: YS}); function KS(n, t, e, r) { if (e === void 0 && (e = 1), r === void 0 && (r = 0), t < 2) throw new Error("Error in oneHot: depth must be >=2, but it is " + t); var i = R(n, "indices", "oneHot", "int32"), a = i.shape.concat([t]), s = function(l, u) { return u([i]), Y(l.oneHot(Y(i, [i.size]), t, e, r), a); }, o = {indices: i}, c = {depth: t, onValue: e, offValue: r}; return z.runKernelFunc(s, o, null, yl, c); } var Es = U({oneHot_: KS}); function jS(n, t) { var e = R(n, "x", "transpose"); if (t == null && (t = e.shape.map(function(a, s) { return s; }).reverse()), E(e.rank === t.length, function() { return "Error in transpose: rank of input " + e.rank + " " + ("must match length of perm " + t + "."); }), t.forEach(function(a) { E(a >= 0 && a < e.rank, function() { return "All entries in 'perm' must be between 0 and " + (e.rank - 1) + (" but got " + t); }); }), e.rank <= 1) return e.clone(); var r = {x: e}, i = {perm: t}; return z.runKernelFunc(function(a) { return a.transpose(e, t); }, r, null, jl, i); } var Tt = U({transpose_: jS}); function $S(n, t, e) { var r = R(n, "labels", "confusionMatrix"), i = R(t, "predictions", "confusionMatrix"); E(e == null || e > 0 && Number.isInteger(e), function() { return "If provided, numClasses must be a positive integer, " + ("but got " + e); }), E(r.rank === 1, function() { return "Expected the rank of labels to be 1, but got " + r.rank; }), E(i.rank === 1, function() { return "Expected the rank of predictions to be 1, " + ("but got " + i.rank); }), E(r.shape[0] === i.shape[0], function() { return "Mismatch in the number of examples: " + (r.shape[0] + " vs. " + i.shape[0] + ". ") + "Labels and predictions should have the same number of elements."; }), E(e > 0 && Number.isInteger(e), function() { return "numClasses is required to be a positive integer, but got " + ("" + e); }); var a = Es(he(r, "int32"), e), s = Es(he(i, "int32"), e), o = Tt(a), c = Ue(o, s); return he(c, "int32"); } var XS = U({confusionMatrix_: $S}); var JS = {__proto__: null, confusionMatrix: XS}; function km(n, t, e) { if (Br(n), t != null && t.length !== 3) throw new Error("tensor3d() requires shape to have three numbers"); var r = Cn(n, e); if (r.length !== 3 && r.length !== 1) throw new Error("tensor3d() requires values to be number[][][] or flat/TypedArray"); if (r.length === 1 && t == null) throw new Error("tensor3d() requires shape to be provided when `values` are a flat array"); return dr(n, t, r, e); } var Ri; function ZS(n, t) { if (t === void 0 && (t = 3), t > 4) throw new Error("Cannot construct Tensor with more than 4 channels from pixels."); if (n == null) throw new Error("pixels passed to tf.browser.fromPixels() can not be null"); var e = false, r = false, i = false, a = false, s = false; if (n.data instanceof Uint8Array) e = true; else if (typeof ImageData != "undefined" && n instanceof ImageData) r = true; else if (typeof HTMLVideoElement != "undefined" && n instanceof HTMLVideoElement) i = true; else if (typeof HTMLImageElement != "undefined" && n instanceof HTMLImageElement) a = true; else if (n.getContext != null) s = true; else throw new Error("pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData in browser, or OffscreenCanvas, ImageData in webworker or {data: Uint32Array, width: number, height: number}, " + ("but was " + n.constructor.name)); if (i) { var o = 2; if (i && n.readyState < o) throw new Error("The video element has not loaded data yet. Please wait for `loadeddata` event on the