UNPKG

@webwriter/neural-network

Version:

Deep learning visualization for feed-forward networks with custom datasets, training and prediction.

1,418 lines (1,413 loc) 9.81 MB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name); var __typeError = (msg) => { throw TypeError(msg); }; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __esm = (fn3, res) => function __init() { return fn3 && (res = (0, fn3[__getOwnPropNames(fn3)[0]])(fn3 = 0)), res; }; var __commonJS = (cb, mod4) => function __require() { return mod4 || (0, cb[__getOwnPropNames(cb)[0]])((mod4 = { exports: {} }).exports, mod4), mod4.exports; }; var __export = (target, all5) => { for (var name in all5) __defProp(target, name, { get: all5[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __reExport = (target, mod4, secondTarget) => (__copyProps(target, mod4, "default"), secondTarget && __copyProps(secondTarget, mod4, "default")); var __toESM = (mod4, isNodeMode, target) => (target = mod4 != null ? __create(__getProtoOf(mod4)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod4 || !mod4.__esModule ? __defProp(target, "default", { value: mod4, enumerable: true }) : target, mod4 )); var __toCommonJS = (mod4) => __copyProps(__defProp({}, "__esModule", { value: true }), mod4); var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)]; var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"]; var __expectFn = (fn3) => fn3 !== void 0 && typeof fn3 !== "function" ? __typeError("Function expected") : fn3; var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn3) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn3 || null)) }); var __decoratorMetadata = (array4, target) => __defNormalProp(target, __knownSymbol("metadata"), array4[3]); var __runInitializers = (array4, flags, self2, value) => { for (var i12 = 0, fns = array4[flags >> 1], n13 = fns && fns.length; i12 < n13; i12++) flags & 1 ? fns[i12].call(self2) : value = fns[i12].call(self2, value); return value; }; var __decorateElement = (array4, flags, name, decorators, target, extra) => { var fn3, it2, done, ctx, access, k4 = flags & 7, s8 = !!(flags & 8), p7 = !!(flags & 16); var j4 = k4 > 3 ? array4.length + 1 : k4 ? s8 ? 1 : 2 : 0, key = __decoratorStrings[k4 + 5]; var initializers = k4 > 3 && (array4[j4 - 1] = []), extraInitializers = array4[j4] || (array4[j4] = []); var desc = k4 && (!p7 && !s8 && (target = target.prototype), k4 < 5 && (k4 > 3 || !p7) && __getOwnPropDesc(k4 < 4 ? target : { get [name]() { return __privateGet(this, extra); }, set [name](x5) { return __privateSet(this, extra, x5); } }, name)); k4 ? p7 && k4 < 4 && __name(extra, (k4 > 2 ? "set " : k4 > 1 ? "get " : "") + name) : __name(target, name); for (var i12 = decorators.length - 1; i12 >= 0; i12--) { ctx = __decoratorContext(k4, name, done = {}, array4[3], extraInitializers); if (k4) { ctx.static = s8, ctx.private = p7, access = ctx.access = { has: p7 ? (x5) => __privateIn(target, x5) : (x5) => name in x5 }; if (k4 ^ 3) access.get = p7 ? (x5) => (k4 ^ 1 ? __privateGet : __privateMethod)(x5, target, k4 ^ 4 ? extra : desc.get) : (x5) => x5[name]; if (k4 > 2) access.set = p7 ? (x5, y6) => __privateSet(x5, target, y6, k4 ^ 4 ? extra : desc.set) : (x5, y6) => x5[name] = y6; } it2 = (0, decorators[i12])(k4 ? k4 < 4 ? p7 ? extra : desc[key] : k4 > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1; if (k4 ^ 4 || it2 === void 0) __expectFn(it2) && (k4 > 4 ? initializers.unshift(it2) : k4 ? p7 ? extra = it2 : desc[key] = it2 : target = it2); else if (typeof it2 !== "object" || it2 === null) __typeError("Object expected"); else __expectFn(fn3 = it2.get) && (desc.get = fn3), __expectFn(fn3 = it2.set) && (desc.set = fn3), __expectFn(fn3 = it2.init) && initializers.unshift(fn3); } return k4 || __decoratorMetadata(array4, target), desc && __defProp(target, name, desc), p7 ? k4 ^ 4 ? extra : desc : target; }; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj); var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method); // (disabled):node_modules/node-fetch/browser.js var require_browser = __commonJS({ "(disabled):node_modules/node-fetch/browser.js"() { } }); // (disabled):util var require_util = __commonJS({ "(disabled):util"() { } }); // (disabled):crypto var require_crypto = __commonJS({ "(disabled):crypto"() { } }); // node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js var require_tf_core_node = __commonJS({ "node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js"(exports) { "use strict"; function _mergeNamespaces(n13, m5) { m5.forEach(function(e17) { e17 && typeof e17 !== "string" && !Array.isArray(e17) && Object.keys(e17).forEach(function(k4) { if (k4 !== "default" && !(k4 in n13)) { var d5 = Object.getOwnPropertyDescriptor(e17, k4); Object.defineProperty(n13, k4, d5.get ? d5 : { enumerable: true, get: function() { return e17[k4]; } }); } }); }); return n13; } var extendStatics = function(d5, b5) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d6, b6) { d6.__proto__ = b6; } || function(d6, b6) { for (var p7 in b6) if (Object.prototype.hasOwnProperty.call(b6, p7)) d6[p7] = b6[p7]; }; return extendStatics(d5, b5); }; function __extends(d5, b5) { if (typeof b5 !== "function" && b5 !== null) throw new TypeError("Class extends value " + String(b5) + " is not a constructor or null"); extendStatics(d5, b5); function __() { this.constructor = d5; } d5.prototype = b5 === null ? Object.create(b5) : (__.prototype = b5.prototype, new __()); } function __awaiter(thisArg, _arguments, P4, generator2) { function adopt(value) { return value instanceof P4 ? value : new P4(function(resolve2) { resolve2(value); }); } return new (P4 || (P4 = Promise))(function(resolve2, reject2) { function fulfilled(value) { try { step7(generator2.next(value)); } catch (e17) { reject2(e17); } } function rejected(value) { try { step7(generator2["throw"](value)); } catch (e17) { reject2(e17); } } function step7(result) { result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected); } step7((generator2 = generator2.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _4 = { label: 0, sent: function() { if (t9[0] & 1) throw t9[1]; return t9[1]; }, trys: [], ops: [] }, f8, y6, t9, g4; return g4 = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g4[Symbol.iterator] = function() { return this; }), g4; function verb(n13) { return function(v4) { return step7([n13, v4]); }; } function step7(op3) { if (f8) throw new TypeError("Generator is already executing."); while (_4) try { if (f8 = 1, y6 && (t9 = op3[0] & 2 ? y6["return"] : op3[0] ? y6["throw"] || ((t9 = y6["return"]) && t9.call(y6), 0) : y6.next) && !(t9 = t9.call(y6, op3[1])).done) return t9; if (y6 = 0, t9) op3 = [op3[0] & 2, t9.value]; switch (op3[0]) { case 0: case 1: t9 = op3; break; case 4: _4.label++; return { value: op3[1], done: false }; case 5: _4.label++; y6 = op3[1]; op3 = [0]; continue; case 7: op3 = _4.ops.pop(); _4.trys.pop(); continue; default: if (!(t9 = _4.trys, t9 = t9.length > 0 && t9[t9.length - 1]) && (op3[0] === 6 || op3[0] === 2)) { _4 = 0; continue; } if (op3[0] === 3 && (!t9 || op3[1] > t9[0] && op3[1] < t9[3])) { _4.label = op3[1]; break; } if (op3[0] === 6 && _4.label < t9[1]) { _4.label = t9[1]; t9 = op3; break; } if (t9 && _4.label < t9[2]) { _4.label = t9[2]; _4.ops.push(op3); break; } if (t9[2]) _4.ops.pop(); _4.trys.pop(); continue; } op3 = body.call(thisArg, _4); } catch (e17) { op3 = [6, e17]; y6 = 0; } finally { f8 = t9 = 0; } if (op3[0] & 5) throw op3[1]; return { value: op3[0] ? op3[1] : void 0, done: true }; } } function __values(o16) { var s8 = typeof Symbol === "function" && Symbol.iterator, m5 = s8 && o16[s8], i12 = 0; if (m5) return m5.call(o16); if (o16 && typeof o16.length === "number") return { next: function() { if (o16 && i12 >= o16.length) o16 = void 0; return { value: o16 && o16[i12++], done: !o16 }; } }; throw new TypeError(s8 ? "Object is not iterable." : "Symbol.iterator is not defined."); } function __read(o16, n13) { var m5 = typeof Symbol === "function" && o16[Symbol.iterator]; if (!m5) return o16; var i12 = m5.call(o16), r14, ar = [], e17; try { while ((n13 === void 0 || n13-- > 0) && !(r14 = i12.next()).done) ar.push(r14.value); } catch (error3) { e17 = { error: error3 }; } finally { try { if (r14 && !r14.done && (m5 = i12["return"])) m5.call(i12); } finally { if (e17) throw e17.error; } } return ar; } function __spreadArray(to, from, pack3) { if (pack3 || arguments.length === 2) for (var i12 = 0, l7 = from.length, ar; i12 < l7; i12++) { if (ar || !(i12 in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i12); ar[i12] = from[i12]; } } return to.concat(ar || Array.prototype.slice.call(from)); } var EPSILON_FLOAT323 = 1e-7; var EPSILON_FLOAT163 = 1e-4; var DataStorage3 = ( /** @class */ function() { function DataStorage4(backend4, dataMover) { this.backend = backend4; this.dataMover = dataMover; this.data = /* @__PURE__ */ new WeakMap(); this.dataIdsCount = 0; } DataStorage4.prototype.get = function(dataId) { if (!this.data.has(dataId)) { this.dataMover.moveData(this.backend, dataId); } return this.data.get(dataId); }; DataStorage4.prototype.set = function(dataId, value) { this.dataIdsCount++; this.data.set(dataId, value); }; DataStorage4.prototype.has = function(dataId) { return this.data.has(dataId); }; DataStorage4.prototype.delete = function(dataId) { this.dataIdsCount--; return this.data.delete(dataId); }; DataStorage4.prototype.numDataIds = function() { return this.dataIdsCount; }; return DataStorage4; }() ); var KernelBackend4 = ( /** @class */ function() { function KernelBackend5() { } KernelBackend5.prototype.refCount = function(dataId) { return notYetImplemented2("refCount"); }; KernelBackend5.prototype.incRef = function(dataId) { return notYetImplemented2("incRef"); }; KernelBackend5.prototype.timerAvailable = function() { return true; }; KernelBackend5.prototype.time = function(f8) { return notYetImplemented2("time"); }; KernelBackend5.prototype.read = function(dataId) { return notYetImplemented2("read"); }; KernelBackend5.prototype.readSync = function(dataId) { return notYetImplemented2("readSync"); }; KernelBackend5.prototype.readToGPU = function(dataId, options2) { return notYetImplemented2("readToGPU"); }; KernelBackend5.prototype.numDataIds = function() { return notYetImplemented2("numDataIds"); }; KernelBackend5.prototype.disposeData = function(dataId, force) { return notYetImplemented2("disposeData"); }; KernelBackend5.prototype.write = function(values, shape, dtype) { return notYetImplemented2("write"); }; KernelBackend5.prototype.move = function(dataId, values, shape, dtype, refCount) { return notYetImplemented2("move"); }; KernelBackend5.prototype.createTensorFromGPUData = function(values, shape, dtype) { return notYetImplemented2("createTensorFromGPUData"); }; KernelBackend5.prototype.memory = function() { return notYetImplemented2("memory"); }; KernelBackend5.prototype.floatPrecision = function() { return notYetImplemented2("floatPrecision"); }; KernelBackend5.prototype.epsilon = function() { return this.floatPrecision() === 32 ? EPSILON_FLOAT323 : EPSILON_FLOAT163; }; KernelBackend5.prototype.dispose = function() { return notYetImplemented2("dispose"); }; return KernelBackend5; }() ); function notYetImplemented2(kernelName) { throw new Error("'".concat(kernelName, "' not yet implemented or not found in the registry. ") + "This kernel may not be supported by the tfjs backend you have chosen"); } function shuffle(array4) { var counter = array4.length; var index = 0; while (counter > 0) { index = Math.random() * counter | 0; counter--; swap(array4, counter, index); } } function shuffleCombo(array4, array22) { if (array4.length !== array22.length) { throw new Error("Array sizes must match to be shuffled together " + "First array length was ".concat(array4.length) + "Second array length was ".concat(array22.length)); } var counter = array4.length; var index = 0; while (counter > 0) { index = Math.random() * counter | 0; counter--; swap(array4, counter, index); swap(array22, counter, index); } } function clamp3(min11, x5, max14) { return Math.max(min11, Math.min(x5, max14)); } function nearestLargerEven(val) { return val % 2 === 0 ? val : val + 1; } function swap(object3, left, right) { var temp = object3[left]; object3[left] = object3[right]; object3[right] = temp; } function sum$1(arr) { var sum11 = 0; for (var i12 = 0; i12 < arr.length; i12++) { sum11 += arr[i12]; } return sum11; } function randUniform(a8, b5) { var r14 = Math.random(); return b5 * r14 + (1 - r14) * a8; } function distSquared(a8, b5) { var result = 0; for (var i12 = 0; i12 < a8.length; i12++) { var diff2 = Number(a8[i12]) - Number(b5[i12]); result += diff2 * diff2; } return result; } function assert3(expr, msg) { if (!expr) { throw new Error(typeof msg === "string" ? msg : msg()); } } function assertShapesMatch2(shapeA, shapeB, errorMessagePrefix) { if (errorMessagePrefix === void 0) { errorMessagePrefix = ""; } assert3(arraysEqual2(shapeA, shapeB), function() { return errorMessagePrefix + " Shapes ".concat(shapeA, " and ").concat(shapeB, " must match"); }); } function assertNonNull2(a8) { assert3(a8 != null, function() { return "The input to the tensor constructor must be a non-null value."; }); } function sizeFromShape2(shape) { if (shape.length === 0) { return 1; } var size5 = shape[0]; for (var i12 = 1; i12 < shape.length; i12++) { size5 *= shape[i12]; } return size5; } function isScalarShape(shape) { return shape.length === 0; } function arraysEqualWithNull2(n1, n22) { if (n1 === n22) { return true; } if (n1 == null || n22 == null) { return false; } if (n1.length !== n22.length) { return false; } for (var i12 = 0; i12 < n1.length; i12++) { if (n1[i12] !== null && n22[i12] !== null && n1[i12] !== n22[i12]) { return false; } } return true; } function arraysEqual2(n1, n22) { if (n1 === n22) { return true; } if (n1 == null || n22 == null) { return false; } if (n1.length !== n22.length) { return false; } for (var i12 = 0; i12 < n1.length; i12++) { if (n1[i12] !== n22[i12]) { return false; } } return true; } function isInt2(a8) { return a8 % 1 === 0; } function tanh$1(x5) { if (Math.tanh != null) { return Math.tanh(x5); } if (x5 === Infinity) { return 1; } else if (x5 === -Infinity) { return -1; } else { var e2x = Math.exp(2 * x5); return (e2x - 1) / (e2x + 1); } } function sizeToSquarishShape(size5) { var width2 = Math.ceil(Math.sqrt(size5)); return [width2, Math.ceil(size5 / width2)]; } function createShuffledIndices(n13) { var shuffledIndices = new Uint32Array(n13); for (var i12 = 0; i12 < n13; ++i12) { shuffledIndices[i12] = i12; } shuffle(shuffledIndices); return shuffledIndices; } function rightPad2(a8, size5) { if (size5 <= a8.length) { return a8; } return a8 + " ".repeat(size5 - a8.length); } function repeatedTry(checkFn, delayFn, maxCounter, scheduleFn) { if (delayFn === void 0) { delayFn = function(counter) { return 0; }; } return new Promise(function(resolve2, reject2) { var tryCount = 0; var tryFn = function() { if (checkFn()) { resolve2(); return; } tryCount++; var nextBackoff = delayFn(tryCount); if (maxCounter != null && tryCount >= maxCounter) { reject2(); return; } if (scheduleFn != null) { scheduleFn(tryFn, nextBackoff); } else { setTimeout(tryFn, nextBackoff); } }; tryFn(); }); } function inferFromImplicitShape(shape, size5) { var shapeProd = 1; var implicitIdx = -1; for (var i12 = 0; i12 < shape.length; ++i12) { if (shape[i12] >= 0) { shapeProd *= shape[i12]; } else if (shape[i12] === -1) { if (implicitIdx !== -1) { throw Error("Shapes can only have 1 implicit size. " + "Found -1 at dim ".concat(implicitIdx, " and dim ").concat(i12)); } implicitIdx = i12; } else if (shape[i12] < 0) { throw Error("Shapes can not be < 0. Found ".concat(shape[i12], " at dim ").concat(i12)); } } if (implicitIdx === -1) { if (size5 > 0 && size5 !== shapeProd) { throw Error("Size(".concat(size5, ") must match the product of shape ").concat(shape)); } return shape; } if (shapeProd === 0) { throw Error("Cannot infer the missing size in [".concat(shape, "] when ") + "there are 0 elements"); } if (size5 % shapeProd !== 0) { throw Error("The implicit shape can't be a fractional number. " + "Got ".concat(size5, " / ").concat(shapeProd)); } var newShape = shape.slice(); newShape[implicitIdx] = size5 / shapeProd; return newShape; } function parseAxisParam2(axis, shape) { var rank = shape.length; axis = axis == null ? shape.map(function(s8, i12) { return i12; }) : [].concat(axis); assert3(axis.every(function(ax) { return ax >= -rank && ax < rank; }), function() { return "All values in axis param must be in range [-".concat(rank, ", ").concat(rank, ") but ") + "got axis ".concat(axis); }); assert3(axis.every(function(ax) { return isInt2(ax); }), function() { return "All values in axis param must be integers but " + "got axis ".concat(axis); }); return axis.map(function(a8) { return a8 < 0 ? rank + a8 : a8; }); } function squeezeShape2(shape, axis) { var newShape = []; var keptDims = []; var isEmptyArray = axis != null && Array.isArray(axis) && axis.length === 0; var axes = axis == null || isEmptyArray ? null : parseAxisParam2(axis, shape).sort(); var j4 = 0; for (var i12 = 0; i12 < shape.length; ++i12) { if (axes != null) { if (axes[j4] === i12 && shape[i12] !== 1) { throw new Error("Can't squeeze axis ".concat(i12, " since its dim '").concat(shape[i12], "' is not 1")); } if ((axes[j4] == null || axes[j4] > i12) && shape[i12] === 1) { newShape.push(shape[i12]); keptDims.push(i12); } if (axes[j4] <= i12) { j4++; } } if (shape[i12] !== 1) { newShape.push(shape[i12]); keptDims.push(i12); } } return { newShape, keptDims }; } function getTypedArrayFromDType2(dtype, size5) { return getArrayFromDType2(dtype, size5); } function getArrayFromDType2(dtype, size5) { var values = null; if (dtype == null || dtype === "float32") { values = new Float32Array(size5); } else if (dtype === "int32") { values = new Int32Array(size5); } else if (dtype === "bool") { values = new Uint8Array(size5); } else if (dtype === "string") { values = new Array(size5); } else { throw new Error("Unknown data type ".concat(dtype)); } return values; } function checkConversionForErrors2(vals, dtype) { for (var i12 = 0; i12 < vals.length; i12++) { var num = vals[i12]; if (isNaN(num) || !isFinite(num)) { throw Error("A tensor of type ".concat(dtype, " being uploaded contains ").concat(num, ".")); } } } function isValidDtype2(dtype) { return dtype === "bool" || dtype === "complex64" || dtype === "float32" || dtype === "int32" || dtype === "string"; } function hasEncodingLoss(oldType, newType) { if (newType === "complex64") { return false; } if (newType === "float32" && oldType !== "complex64") { return false; } if (newType === "int32" && oldType !== "float32" && oldType !== "complex64") { return false; } if (newType === "bool" && oldType === "bool") { return false; } return true; } function bytesPerElement2(dtype) { if (dtype === "float32" || dtype === "int32") { return 4; } else if (dtype === "complex64") { return 8; } else if (dtype === "bool") { return 1; } else { throw new Error("Unknown dtype ".concat(dtype)); } } function bytesFromStringArray2(arr) { if (arr == null) { return 0; } var bytes = 0; arr.forEach(function(x5) { return bytes += x5.length; }); return bytes; } function isString2(value) { return typeof value === "string" || value instanceof String; } function isBoolean2(value) { return typeof value === "boolean"; } function isNumber2(value) { return typeof value === "number"; } function inferDtype2(values) { if (Array.isArray(values)) { return inferDtype2(values[0]); } if (values instanceof Float32Array) { return "float32"; } else if (values instanceof Int32Array || values instanceof Uint8Array || values instanceof Uint8ClampedArray) { return "int32"; } else if (isNumber2(values)) { return "float32"; } else if (isString2(values)) { return "string"; } else if (isBoolean2(values)) { return "bool"; } return "float32"; } function isFunction2(f8) { return !!(f8 && f8.constructor && f8.call && f8.apply); } function nearestDivisor2(size5, start) { for (var i12 = start; i12 < size5; ++i12) { if (size5 % i12 === 0) { return i12; } } return size5; } function computeStrides2(shape) { var rank = shape.length; if (rank < 2) { return []; } var strides = new Array(rank - 1); strides[rank - 2] = shape[rank - 1]; for (var i12 = rank - 3; i12 >= 0; --i12) { strides[i12] = strides[i12 + 1] * shape[i12 + 1]; } return strides; } function createNestedArray2(offset3, shape, a8, isComplex) { if (isComplex === void 0) { isComplex = false; } var ret = new Array(); if (shape.length === 1) { var d5 = shape[0] * (isComplex ? 2 : 1); for (var i12 = 0; i12 < d5; i12++) { ret[i12] = a8[offset3 + i12]; } } else { var d5 = shape[0]; var rest = shape.slice(1); var len = rest.reduce(function(acc, c10) { return acc * c10; }) * (isComplex ? 2 : 1); for (var i12 = 0; i12 < d5; i12++) { ret[i12] = createNestedArray2(offset3 + i12 * len, rest, a8, isComplex); } } return ret; } function toNestedArray2(shape, a8, isComplex) { if (isComplex === void 0) { isComplex = false; } if (shape.length === 0) { return a8[0]; } var size5 = shape.reduce(function(acc, c10) { return acc * c10; }) * (isComplex ? 2 : 1); if (size5 === 0) { return []; } if (size5 !== a8.length) { throw new Error("[".concat(shape, "] does not match the input size ").concat(a8.length).concat(isComplex ? " for a complex tensor" : "", ".")); } return createNestedArray2(0, shape, a8, isComplex); } function convertBackendValuesAndArrayBuffer(data4, dtype) { if (Array.isArray(data4)) { return data4; } if (dtype === "float32") { return data4 instanceof Float32Array ? data4 : new Float32Array(data4); } else if (dtype === "int32") { return data4 instanceof Int32Array ? data4 : new Int32Array(data4); } else if (dtype === "bool" || dtype === "string") { return Uint8Array.from(new Int32Array(data4)); } else { throw new Error("Unknown dtype ".concat(dtype)); } } function makeOnesTypedArray2(size5, dtype) { var array4 = makeZerosTypedArray2(size5, dtype); for (var i12 = 0; i12 < array4.length; i12++) { array4[i12] = 1; } return array4; } function makeZerosTypedArray2(size5, dtype) { if (dtype == null || dtype === "float32" || dtype === "complex64") { return new Float32Array(size5); } else if (dtype === "int32") { return new Int32Array(size5); } else if (dtype === "bool") { return new Uint8Array(size5); } else { throw new Error("Unknown data type ".concat(dtype)); } } function makeZerosNestedTypedArray(shape, dtype) { var size5 = shape.reduce(function(prev, curr) { return prev * curr; }, 1); if (dtype == null || dtype === "float32") { return toNestedArray2(shape, new Float32Array(size5)); } else if (dtype === "int32") { return toNestedArray2(shape, new Int32Array(size5)); } else if (dtype === "bool") { return toNestedArray2(shape, new Uint8Array(size5)); } else { throw new Error("Unknown data type ".concat(dtype)); } } function assertNonNegativeIntegerDimensions2(shape) { shape.forEach(function(dimSize) { assert3(Number.isInteger(dimSize) && dimSize >= 0, function() { return "Tensor must have a shape comprised of positive integers but got " + "shape [".concat(shape, "]."); }); }); } function locToIndex(locs, rank, strides) { if (rank === 0) { return 0; } else if (rank === 1) { return locs[0]; } var index = locs[locs.length - 1]; for (var i12 = 0; i12 < locs.length - 1; ++i12) { index += strides[i12] * locs[i12]; } return index; } function indexToLoc(index, rank, strides) { if (rank === 0) { return []; } else if (rank === 1) { return [index]; } var locs = new Array(rank); for (var i12 = 0; i12 < locs.length - 1; ++i12) { locs[i12] = Math.floor(index / strides[i12]); index -= locs[i12] * strides[i12]; } locs[locs.length - 1] = index; return locs; } function isPromise2(object3) { return object3 && object3.then && typeof object3.then === "function"; } var TENSORFLOWJS_FLAGS_PREFIX2 = "tfjsflags"; var Environment2 = ( /** @class */ function() { function Environment3(global2) { this.global = global2; this.flags = {}; this.flagRegistry = {}; this.urlFlags = {}; this.getQueryParams = getQueryParams2; this.populateURLFlags(); } Environment3.prototype.setPlatform = function(platformName, platform2) { if (this.platform != null) { if (!(env55().getBool("IS_TEST") || env55().getBool("PROD"))) { console.warn("Platform ".concat(this.platformName, " has already been set. ") + "Overwriting the platform with ".concat(platformName, ".")); } } this.platformName = platformName; this.platform = platform2; }; Environment3.prototype.registerFlag = function(flagName, evaluationFn, setHook) { this.flagRegistry[flagName] = { evaluationFn, setHook }; if (this.urlFlags[flagName] != null) { var flagValue = this.urlFlags[flagName]; if (!(env55().getBool("IS_TEST") || env55().getBool("PROD"))) { console.warn("Setting feature override from URL ".concat(flagName, ": ").concat(flagValue, ".")); } this.set(flagName, flagValue); } }; Environment3.prototype.getAsync = function(flagName) { return __awaiter(this, void 0, void 0, function() { var _a60, _b; return __generator(this, function(_c) { switch (_c.label) { case 0: if (flagName in this.flags) { return [2, this.flags[flagName]]; } _a60 = this.flags; _b = flagName; return [4, this.evaluateFlag(flagName)]; case 1: _a60[_b] = _c.sent(); return [2, this.flags[flagName]]; } }); }); }; Environment3.prototype.get = function(flagName) { if (flagName in this.flags) { return this.flags[flagName]; } var flagValue = this.evaluateFlag(flagName); if (isPromise2(flagValue)) { throw new Error("Flag ".concat(flagName, " cannot be synchronously evaluated. ") + "Please use getAsync() instead."); } this.flags[flagName] = flagValue; return this.flags[flagName]; }; Environment3.prototype.getNumber = function(flagName) { return this.get(flagName); }; Environment3.prototype.getBool = function(flagName) { return this.get(flagName); }; Environment3.prototype.getString = function(flagName) { return this.get(flagName); }; Environment3.prototype.getFlags = function() { return this.flags; }; Object.defineProperty(Environment3.prototype, "features", { // For backwards compatibility. get: function() { return this.flags; }, enumerable: false, configurable: true }); Environment3.prototype.set = function(flagName, value) { if (this.flagRegistry[flagName] == null) { throw new Error("Cannot set flag ".concat(flagName, " as it has not been registered.")); } this.flags[flagName] = value; if (this.flagRegistry[flagName].setHook != null) { this.flagRegistry[flagName].setHook(value); } }; Environment3.prototype.evaluateFlag = function(flagName) { if (this.flagRegistry[flagName] == null) { throw new Error("Cannot evaluate flag '".concat(flagName, "': no evaluation function found.")); } return this.flagRegistry[flagName].evaluationFn(); }; Environment3.prototype.setFlags = function(flags) { this.flags = Object.assign({}, flags); }; Environment3.prototype.reset = function() { this.flags = {}; this.urlFlags = {}; this.populateURLFlags(); }; Environment3.prototype.populateURLFlags = function() { var _this = this; if (typeof this.global === "undefined" || typeof this.global.location === "undefined" || typeof this.global.location.search === "undefined") { return; } var urlParams = this.getQueryParams(this.global.location.search); if (TENSORFLOWJS_FLAGS_PREFIX2 in urlParams) { var keyValues = urlParams[TENSORFLOWJS_FLAGS_PREFIX2].split(","); keyValues.forEach(function(keyValue) { var _a60 = __read(keyValue.split(":"), 2), key = _a60[0], value = _a60[1]; _this.urlFlags[key] = parseValue2(key, value); }); } }; return Environment3; }() ); function getQueryParams2(queryString) { var params = {}; queryString.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, function(s8) { var t9 = []; for (var _i = 1; _i < arguments.length; _i++) { t9[_i - 1] = arguments[_i]; } decodeParam2(params, t9[0], t9[1]); return t9.join("="); }); return params; } function decodeParam2(params, name, value) { params[decodeURIComponent(name)] = decodeURIComponent(value || ""); } function parseValue2(flagName, value) { var lowerCaseValue = value.toLowerCase(); if (lowerCaseValue === "true" || lowerCaseValue === "false") { return lowerCaseValue === "true"; } else if ("".concat(+lowerCaseValue) === lowerCaseValue) { return +lowerCaseValue; } else { return value; } } function env55() { return exports.ENV; } exports.ENV = null; function setEnvironmentGlobal2(environment) { exports.ENV = environment; } var globalNameSpace2; function getGlobalNamespace2() { if (globalNameSpace2 == null) { var ns = void 0; if (typeof window !== "undefined") { ns = window; } else if (typeof global !== "undefined") { ns = global; } else if (typeof process !== "undefined") { ns = process; } else if (typeof self !== "undefined") { ns = self; } else { throw new Error("Could not find a global object"); } globalNameSpace2 = ns; } return globalNameSpace2; } function getGlobalMap2() { var ns = getGlobalNamespace2(); if (ns._tfGlobals == null) { ns._tfGlobals = /* @__PURE__ */ new Map(); } return ns._tfGlobals; } function getGlobal2(key, init) { var globalMap = getGlobalMap2(); if (globalMap.has(key)) { return globalMap.get(key); } else { var singleton = init(); globalMap.set(key, singleton); return globalMap.get(key); } } var Abs4 = "Abs"; var Acos4 = "Acos"; var Acosh4 = "Acosh"; var Add5 = "Add"; var AddN4 = "AddN"; var All4 = "All"; var Any4 = "Any"; var ArgMax4 = "ArgMax"; var ArgMin4 = "ArgMin"; var Asin4 = "Asin"; var Asinh4 = "Asinh"; var Atan5 = "Atan"; var Atanh4 = "Atanh"; var Atan24 = "Atan2"; var AvgPool4 = "AvgPool"; var AvgPoolGrad4 = "AvgPoolGrad"; var AvgPool3D4 = "AvgPool3D"; var AvgPool3DGrad4 = "AvgPool3DGrad"; var BatchMatMul4 = "BatchMatMul"; var BatchToSpaceND4 = "BatchToSpaceND"; var Bincount4 = "Bincount"; var BitwiseAnd4 = "BitwiseAnd"; var BroadcastTo2 = "BroadcastTo"; var BroadcastArgs4 = "BroadcastArgs"; var Cast4 = "Cast"; var Ceil4 = "Ceil"; var ClipByValue4 = "ClipByValue"; var Complex4 = "Complex"; var ComplexAbs4 = "ComplexAbs"; var Concat4 = "Concat"; var Conv2D5 = "Conv2D"; var Conv2DBackpropFilter4 = "Conv2DBackpropFilter"; var Conv2DBackpropInput4 = "Conv2DBackpropInput"; var Conv3D5 = "Conv3D"; var Conv3DBackpropFilterV24 = "Conv3DBackpropFilterV2"; var Conv3DBackpropInputV24 = "Conv3DBackpropInputV2"; var Cos4 = "Cos"; var Cosh4 = "Cosh"; var Cumprod4 = "Cumprod"; var Cumsum4 = "Cumsum"; var CropAndResize4 = "CropAndResize"; var DenseBincount4 = "DenseBincount"; var DepthToSpace4 = "DepthToSpace"; var DepthwiseConv2dNative4 = "DepthwiseConv2dNative"; var DepthwiseConv2dNativeBackpropFilter4 = "DepthwiseConv2dNativeBackpropFilter"; var DepthwiseConv2dNativeBackpropInput4 = "DepthwiseConv2dNativeBackpropInput"; var Diag4 = "Diag"; var Dilation2D4 = "Dilation2D"; var Dilation2DBackpropInput3 = "Dilation2DBackpropInput"; var Dilation2DBackpropFilter3 = "Dilation2DBackpropFilter"; var Draw2 = "Draw"; var RealDiv4 = "RealDiv"; var Einsum4 = "Einsum"; var Elu5 = "Elu"; var EluGrad4 = "EluGrad"; var Erf4 = "Erf"; var Equal4 = "Equal"; var Exp4 = "Exp"; var ExpandDims4 = "ExpandDims"; var Expm14 = "Expm1"; var FFT4 = "FFT"; var Fill4 = "Fill"; var FlipLeftRight4 = "FlipLeftRight"; var Floor4 = "Floor"; var FloorDiv4 = "FloorDiv"; var FusedBatchNorm4 = "FusedBatchNorm"; var GatherV24 = "GatherV2"; var GatherNd4 = "GatherNd"; var Greater4 = "Greater"; var GreaterEqual4 = "GreaterEqual"; var Identity5 = "Identity"; var IFFT4 = "IFFT"; var Imag4 = "Imag"; var IsFinite4 = "IsFinite"; var IsInf4 = "IsInf"; var IsNan4 = "IsNan"; var LeakyRelu4 = "LeakyRelu"; var Less4 = "Less"; var LessEqual4 = "LessEqual"; var LinSpace4 = "LinSpace"; var Log4 = "Log"; var Log1p4 = "Log1p"; var LogicalAnd4 = "LogicalAnd"; var LogicalNot4 = "LogicalNot"; var LogicalOr4 = "LogicalOr"; var LogicalXor = "LogicalXor"; var LogSoftmax3 = "LogSoftmax"; var LowerBound = "LowerBound"; var LRN4 = "LRN"; var LRNGrad4 = "LRNGrad"; var MatrixBandPart = "MatrixBandPart"; var Max4 = "Max"; var Maximum5 = "Maximum"; var MaxPool4 = "MaxPool"; var MaxPoolGrad4 = "MaxPoolGrad"; var MaxPool3D4 = "MaxPool3D"; var MaxPool3DGrad4 = "MaxPool3DGrad"; var MaxPoolWithArgmax4 = "MaxPoolWithArgmax"; var Mean4 = "Mean"; var Min4 = "Min"; var Minimum5 = "Minimum"; var MirrorPad4 = "MirrorPad"; var Mod4 = "Mod"; var Multinomial4 = "Multinomial"; var Multiply5 = "Multiply"; var Neg4 = "Neg"; var NotEqual4 = "NotEqual"; var NonMaxSuppressionV34 = "NonMaxSuppressionV3"; var NonMaxSuppressionV44 = "NonMaxSuppressionV4"; var NonMaxSuppressionV54 = "NonMaxSuppressionV5"; var OnesLike4 = "OnesLike"; var OneHot4 = "OneHot"; var Pack4 = "Pack"; var PadV24 = "PadV2"; var Pool = "Pool"; var Pow4 = "Pow"; var Prelu4 = "Prelu"; var Prod4 = "Prod"; var RaggedGather4 = "RaggedGather"; var RaggedRange4 = "RaggedRange"; var RaggedTensorToTensor4 = "RaggedTensorToTensor"; var Range4 = "Range"; var Real4 = "Real"; var Reciprocal4 = "Reciprocal"; var Relu5 = "Relu"; var Reshape5 = "Reshape"; var ResizeNearestNeighbor4 = "ResizeNearestNeighbor"; var ResizeNearestNeighborGrad4 = "ResizeNearestNeighborGrad"; var ResizeBilinear4 = "ResizeBilinear"; var ResizeBilinearGrad4 = "ResizeBilinearGrad"; var Relu65 = "Relu6"; var Reverse4 = "Reverse"; var Round4 = "Round"; var Rsqrt4 = "Rsqrt"; var ScatterNd4 = "ScatterNd"; var TensorScatterUpdate4 = "TensorScatterUpdate"; var SearchSorted4 = "SearchSorted"; var Select4 = "Select"; var Selu5 = "Selu"; var Slice4 = "Slice"; var Sin4 = "Sin"; var Sinh4 = "Sinh"; var Sign4 = "Sign"; var Sigmoid5 = "Sigmoid"; var Softplus5 = "Softplus"; var Sqrt4 = "Sqrt"; var Sum4 = "Sum"; var SpaceToBatchND4 = "SpaceToBatchND"; var SplitV4 = "SplitV"; var Softmax6 = "Softmax"; var SparseFillEmptyRows4 = "SparseFillEmptyRows"; var SparseReshape4 = "SparseReshape"; var SparseSegmentMean4 = "SparseSegmentMean"; var SparseSegmentSum4 = "SparseSegmentSum"; var SparseToDense4 = "SparseToDense"; var SquaredDifference4 = "SquaredDifference"; var Square4 = "Square"; var StaticRegexReplace4 = "StaticRegexReplace"; var StridedSlice4 = "StridedSlice"; var StringNGrams4 = "StringNGrams"; var StringSplit4 = "StringSplit"; var StringToHashBucketFast4 = "StringToHashBucketFast"; var Sub4 = "Sub"; var Tan4 = "Tan"; var Tanh5 = "Tanh"; var Tile4 = "Tile"; var TopK4 = "TopK"; var Transform4 = "Transform"; var Transpose4 = "Transpose"; var Unique4 = "Unique"; var Unpack4 = "Unpack"; var UnsortedSegmentSum4 = "UnsortedSegmentSum"; var UpperBound = "UpperBound"; var ZerosLike4 = "ZerosLike"; var Step4 = "Step"; var FromPixels2 = "FromPixels"; var RotateWithOffset4 = "RotateWithOffset"; var _FusedMatMul4 = "_FusedMatMul"; var FusedConv2D4 = "FusedConv2D"; var FusedDepthwiseConv2D4 = "FusedDepthwiseConv2D"; function warn4() { var msg = []; for (var _i = 0; _i < arguments.length; _i++) { msg[_i] = arguments[_i]; } if (!(env55().getBool("IS_TEST") || env55().getBool("PROD"))) { console.warn.apply(console, __spreadArray([], __read(msg), false)); } } function log$1() { var msg = []; for (var _i = 0; _i < arguments.length; _i++) { msg[_i] = arguments[_i]; } if (!(env55().getBool("IS_TEST") || env55().getBool("PROD"))) { console.log.apply(console, __spreadArray([], __read(msg), false)); } } var kernelRegistry2 = getGlobal2("kernelRegistry", function() { return /* @__PURE__ */ new Map(); }); var gradRegistry2 = getGlobal2("gradRegistry", function() { return /* @__PURE__ */ new Map(); }); function getKernel2(kernelName, backendName) { var key = makeKey2(kernelName, backendName); return kernelRegistry2.get(key); } function getGradient2(kernelName) { return gradRegistry2.get(kernelName); } function getKernelsForBackend2(backendName) { var it2 = kernelRegistry2.entries(); var result = []; while (true) { var _a60 = it2.next(), done = _a60.done, value = _a60.value; if (done) { break; } var _b = __read(value, 2), key = _b[0], config = _b[1]; var _c = __read(key.split("_"), 1), backend4 = _c[0]; if (backend4 === backendName) { result.push(config); } } return result; } function registerKernel3(config) { var kernelName = config.kernelName, backendName = config.backendName; var key = makeKey2(kernelName, backendName); if (kernelRegistry2.has(key)) { warn4("The kernel '".concat(kernelName, "' for backend ") + "'".concat(backendName, "' is already registered")); } kernelRegistry2.set(key, config); } function registerGradient2(config) { var kernelName = config.kernelName; if (gradRegistry2.has(kernelName)) { if (env55().getBool("DEBUG")) { warn4("Overriding the gradient for '".concat(kernelName, "'")); } } gradRegistry2.set(kernelName, config); } function unregisterKernel(kernelName, backendName) { var key = makeKey2(kernelName, backendName); if (!kernelRegistry2.has(key)) { throw new Error("The kernel '".concat(kernelName, "' for backend ") + "'".concat(backendName, "' is not registered")); } kernelRegistry2.delete(key); } function unregisterGradient(kernelName) { if (!gradRegistry2.has(kernelName)) { throw new Error("The gradient '".concat(kernelName, "' for backend is not registered")); } gradRegistry2.delete(kernelName); } function copyRegisteredKernels(registeredBackendName, newBackendName) { var kernels = getKernelsForBackend2(registeredBackendName); kernels.forEach(function(kernelConfig) { var newKernelConfig = Object.assign({}, kernelConfig, { backendName: newBackendName }); registerKernel3(newKernelConfig); }); } function makeKey2(kernelName, backendName) { return "".concat(backendName, "_").concat(kernelName); } function isTypedArrayBrowser2(a8) { return a8 instanceof Float32Array || a8 instanceof Int32Array || a8 instanceof Uint8Array || a8 instanceof Uint8ClampedArray; } var commonjsGlobal2 = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {}; function getDefaultExportFromCjs2(x5) { return x5 && x5.__esModule && Object.prototype.hasOwnProperty.call(x5, "default") ? x5["default"] : x5; } var long = Long$1; var wasm = null; try { wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([ 0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117,