image-dataset
Version:
Tool to build image dataset: collect, classify, review
1,567 lines (1,562 loc) • 4.26 MB
JavaScript
"use strict";
(() => {
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 __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __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 || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
// (disabled):node_modules/.pnpm/node-fetch@2.6.13/node_modules/node-fetch/browser.js
var require_browser = __commonJS({
"(disabled):node_modules/.pnpm/node-fetch@2.6.13/node_modules/node-fetch/browser.js"() {
}
});
// (disabled):util
var require_util = __commonJS({
"(disabled):util"() {
}
});
// (disabled):crypto
var require_crypto = __commonJS({
"(disabled):crypto"() {
}
});
// node_modules/.pnpm/@tensorflow+tfjs-core@4.22.0/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js
var require_tf_core_node = __commonJS({
"node_modules/.pnpm/@tensorflow+tfjs-core@4.22.0/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js"(exports) {
"use strict";
function _mergeNamespaces(n, m) {
m.forEach(function(e) {
e && typeof e !== "string" && !Array.isArray(e) && Object.keys(e).forEach(function(k) {
if (k !== "default" && !(k in n)) {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function() {
return e[k];
}
});
}
});
});
return n;
}
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
d2.__proto__ = b2;
} || function(d2, b2) {
for (var p in b2)
if (Object.prototype.hasOwnProperty.call(b2, p))
d2[p] = b2[p];
};
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function(resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function(resolve, reject) {
function fulfilled(value) {
try {
step2(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step2(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step2(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step2((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() {
if (t[0] & 1)
throw t[1];
return t[1];
}, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
return this;
}), g;
function verb(n) {
return function(v) {
return step2([n, v]);
};
}
function step2(op2) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op2[0] & 2 ? y["return"] : op2[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op2[1])).done)
return t;
if (y = 0, t)
op2 = [op2[0] & 2, t.value];
switch (op2[0]) {
case 0:
case 1:
t = op2;
break;
case 4:
_.label++;
return { value: op2[1], done: false };
case 5:
_.label++;
y = op2[1];
op2 = [0];
continue;
case 7:
op2 = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op2[0] === 6 || op2[0] === 2)) {
_ = 0;
continue;
}
if (op2[0] === 3 && (!t || op2[1] > t[0] && op2[1] < t[3])) {
_.label = op2[1];
break;
}
if (op2[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op2;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op2);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op2 = body.call(thisArg, _);
} catch (e) {
op2 = [6, e];
y = 0;
} finally {
f = t = 0;
}
if (op2[0] & 5)
throw op2[1];
return { value: op2[0] ? op2[1] : void 0, done: true };
}
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function() {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
} catch (error) {
e = { error };
} finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
} finally {
if (e)
throw e.error;
}
}
return ar;
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2)
for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar)
ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
var EPSILON_FLOAT32 = 1e-7;
var EPSILON_FLOAT16 = 1e-4;
var DataStorage = (
/** @class */
function() {
function DataStorage2(backend2, dataMover) {
this.backend = backend2;
this.dataMover = dataMover;
this.data = /* @__PURE__ */ new WeakMap();
this.dataIdsCount = 0;
}
DataStorage2.prototype.get = function(dataId) {
if (!this.data.has(dataId)) {
this.dataMover.moveData(this.backend, dataId);
}
return this.data.get(dataId);
};
DataStorage2.prototype.set = function(dataId, value) {
this.dataIdsCount++;
this.data.set(dataId, value);
};
DataStorage2.prototype.has = function(dataId) {
return this.data.has(dataId);
};
DataStorage2.prototype.delete = function(dataId) {
this.dataIdsCount--;
return this.data.delete(dataId);
};
DataStorage2.prototype.numDataIds = function() {
return this.dataIdsCount;
};
return DataStorage2;
}()
);
var KernelBackend = (
/** @class */
function() {
function KernelBackend2() {
}
KernelBackend2.prototype.refCount = function(dataId) {
return notYetImplemented("refCount");
};
KernelBackend2.prototype.incRef = function(dataId) {
return notYetImplemented("incRef");
};
KernelBackend2.prototype.timerAvailable = function() {
return true;
};
KernelBackend2.prototype.time = function(f) {
return notYetImplemented("time");
};
KernelBackend2.prototype.read = function(dataId) {
return notYetImplemented("read");
};
KernelBackend2.prototype.readSync = function(dataId) {
return notYetImplemented("readSync");
};
KernelBackend2.prototype.readToGPU = function(dataId, options) {
return notYetImplemented("readToGPU");
};
KernelBackend2.prototype.numDataIds = function() {
return notYetImplemented("numDataIds");
};
KernelBackend2.prototype.disposeData = function(dataId, force) {
return notYetImplemented("disposeData");
};
KernelBackend2.prototype.write = function(values, shape, dtype) {
return notYetImplemented("write");
};
KernelBackend2.prototype.move = function(dataId, values, shape, dtype, refCount) {
return notYetImplemented("move");
};
KernelBackend2.prototype.createTensorFromGPUData = function(values, shape, dtype) {
return notYetImplemented("createTensorFromGPUData");
};
KernelBackend2.prototype.memory = function() {
return notYetImplemented("memory");
};
KernelBackend2.prototype.floatPrecision = function() {
return notYetImplemented("floatPrecision");
};
KernelBackend2.prototype.epsilon = function() {
return this.floatPrecision() === 32 ? EPSILON_FLOAT32 : EPSILON_FLOAT16;
};
KernelBackend2.prototype.dispose = function() {
return notYetImplemented("dispose");
};
return KernelBackend2;
}()
);
function notYetImplemented(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(array) {
var counter = array.length;
var index = 0;
while (counter > 0) {
index = Math.random() * counter | 0;
counter--;
swap(array, counter, index);
}
}
function shuffleCombo(array, array2) {
if (array.length !== array2.length) {
throw new Error("Array sizes must match to be shuffled together " + "First array length was ".concat(array.length) + "Second array length was ".concat(array2.length));
}
var counter = array.length;
var index = 0;
while (counter > 0) {
index = Math.random() * counter | 0;
counter--;
swap(array, counter, index);
swap(array2, counter, index);
}
}
function clamp(min2, x, max2) {
return Math.max(min2, Math.min(x, max2));
}
function nearestLargerEven(val) {
return val % 2 === 0 ? val : val + 1;
}
function swap(object, left, right) {
var temp = object[left];
object[left] = object[right];
object[right] = temp;
}
function sum$1(arr) {
var sum2 = 0;
for (var i = 0; i < arr.length; i++) {
sum2 += arr[i];
}
return sum2;
}
function randUniform(a, b) {
var r = Math.random();
return b * r + (1 - r) * a;
}
function distSquared(a, b) {
var result = 0;
for (var i = 0; i < a.length; i++) {
var diff = Number(a[i]) - Number(b[i]);
result += diff * diff;
}
return result;
}
function assert(expr, msg) {
if (!expr) {
throw new Error(typeof msg === "string" ? msg : msg());
}
}
function assertShapesMatch(shapeA, shapeB, errorMessagePrefix) {
if (errorMessagePrefix === void 0) {
errorMessagePrefix = "";
}
assert(arraysEqual(shapeA, shapeB), function() {
return errorMessagePrefix + " Shapes ".concat(shapeA, " and ").concat(shapeB, " must match");
});
}
function assertNonNull(a) {
assert(a != null, function() {
return "The input to the tensor constructor must be a non-null value.";
});
}
function sizeFromShape(shape) {
if (shape.length === 0) {
return 1;
}
var size = shape[0];
for (var i = 1; i < shape.length; i++) {
size *= shape[i];
}
return size;
}
function isScalarShape(shape) {
return shape.length === 0;
}
function arraysEqualWithNull(n1, n2) {
if (n1 === n2) {
return true;
}
if (n1 == null || n2 == null) {
return false;
}
if (n1.length !== n2.length) {
return false;
}
for (var i = 0; i < n1.length; i++) {
if (n1[i] !== null && n2[i] !== null && n1[i] !== n2[i]) {
return false;
}
}
return true;
}
function arraysEqual(n1, n2) {
if (n1 === n2) {
return true;
}
if (n1 == null || n2 == null) {
return false;
}
if (n1.length !== n2.length) {
return false;
}
for (var i = 0; i < n1.length; i++) {
if (n1[i] !== n2[i]) {
return false;
}
}
return true;
}
function isInt(a) {
return a % 1 === 0;
}
function tanh$1(x) {
if (Math.tanh != null) {
return Math.tanh(x);
}
if (x === Infinity) {
return 1;
} else if (x === -Infinity) {
return -1;
} else {
var e2x = Math.exp(2 * x);
return (e2x - 1) / (e2x + 1);
}
}
function sizeToSquarishShape(size) {
var width = Math.ceil(Math.sqrt(size));
return [width, Math.ceil(size / width)];
}
function createShuffledIndices(n) {
var shuffledIndices = new Uint32Array(n);
for (var i = 0; i < n; ++i) {
shuffledIndices[i] = i;
}
shuffle(shuffledIndices);
return shuffledIndices;
}
function rightPad(a, size) {
if (size <= a.length) {
return a;
}
return a + " ".repeat(size - a.length);
}
function repeatedTry(checkFn, delayFn, maxCounter, scheduleFn) {
if (delayFn === void 0) {
delayFn = function(counter) {
return 0;
};
}
return new Promise(function(resolve, reject) {
var tryCount = 0;
var tryFn = function() {
if (checkFn()) {
resolve();
return;
}
tryCount++;
var nextBackoff = delayFn(tryCount);
if (maxCounter != null && tryCount >= maxCounter) {
reject();
return;
}
if (scheduleFn != null) {
scheduleFn(tryFn, nextBackoff);
} else {
setTimeout(tryFn, nextBackoff);
}
};
tryFn();
});
}
function inferFromImplicitShape(shape, size) {
var shapeProd = 1;
var implicitIdx = -1;
for (var i = 0; i < shape.length; ++i) {
if (shape[i] >= 0) {
shapeProd *= shape[i];
} else if (shape[i] === -1) {
if (implicitIdx !== -1) {
throw Error("Shapes can only have 1 implicit size. " + "Found -1 at dim ".concat(implicitIdx, " and dim ").concat(i));
}
implicitIdx = i;
} else if (shape[i] < 0) {
throw Error("Shapes can not be < 0. Found ".concat(shape[i], " at dim ").concat(i));
}
}
if (implicitIdx === -1) {
if (size > 0 && size !== shapeProd) {
throw Error("Size(".concat(size, ") 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 (size % shapeProd !== 0) {
throw Error("The implicit shape can't be a fractional number. " + "Got ".concat(size, " / ").concat(shapeProd));
}
var newShape = shape.slice();
newShape[implicitIdx] = size / shapeProd;
return newShape;
}
function parseAxisParam(axis, shape) {
var rank = shape.length;
axis = axis == null ? shape.map(function(s, i) {
return i;
}) : [].concat(axis);
assert(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);
});
assert(axis.every(function(ax) {
return isInt(ax);
}), function() {
return "All values in axis param must be integers but " + "got axis ".concat(axis);
});
return axis.map(function(a) {
return a < 0 ? rank + a : a;
});
}
function squeezeShape(shape, axis) {
var newShape = [];
var keptDims = [];
var isEmptyArray = axis != null && Array.isArray(axis) && axis.length === 0;
var axes = axis == null || isEmptyArray ? null : parseAxisParam(axis, shape).sort();
var j = 0;
for (var i = 0; i < shape.length; ++i) {
if (axes != null) {
if (axes[j] === i && shape[i] !== 1) {
throw new Error("Can't squeeze axis ".concat(i, " since its dim '").concat(shape[i], "' is not 1"));
}
if ((axes[j] == null || axes[j] > i) && shape[i] === 1) {
newShape.push(shape[i]);
keptDims.push(i);
}
if (axes[j] <= i) {
j++;
}
}
if (shape[i] !== 1) {
newShape.push(shape[i]);
keptDims.push(i);
}
}
return { newShape, keptDims };
}
function getTypedArrayFromDType(dtype, size) {
return getArrayFromDType(dtype, size);
}
function getArrayFromDType(dtype, size) {
var values = null;
if (dtype == null || dtype === "float32") {
values = new Float32Array(size);
} else if (dtype === "int32") {
values = new Int32Array(size);
} else if (dtype === "bool") {
values = new Uint8Array(size);
} else if (dtype === "string") {
values = new Array(size);
} else {
throw new Error("Unknown data type ".concat(dtype));
}
return values;
}
function checkConversionForErrors(vals, dtype) {
for (var i = 0; i < vals.length; i++) {
var num = vals[i];
if (isNaN(num) || !isFinite(num)) {
throw Error("A tensor of type ".concat(dtype, " being uploaded contains ").concat(num, "."));
}
}
}
function isValidDtype(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 bytesPerElement(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 bytesFromStringArray(arr) {
if (arr == null) {
return 0;
}
var bytes = 0;
arr.forEach(function(x) {
return bytes += x.length;
});
return bytes;
}
function isString(value) {
return typeof value === "string" || value instanceof String;
}
function isBoolean(value) {
return typeof value === "boolean";
}
function isNumber(value) {
return typeof value === "number";
}
function inferDtype(values) {
if (Array.isArray(values)) {
return inferDtype(values[0]);
}
if (values instanceof Float32Array) {
return "float32";
} else if (values instanceof Int32Array || values instanceof Uint8Array || values instanceof Uint8ClampedArray) {
return "int32";
} else if (isNumber(values)) {
return "float32";
} else if (isString(values)) {
return "string";
} else if (isBoolean(values)) {
return "bool";
}
return "float32";
}
function isFunction(f) {
return !!(f && f.constructor && f.call && f.apply);
}
function nearestDivisor(size, start) {
for (var i = start; i < size; ++i) {
if (size % i === 0) {
return i;
}
}
return size;
}
function computeStrides(shape) {
var rank = shape.length;
if (rank < 2) {
return [];
}
var strides = new Array(rank - 1);
strides[rank - 2] = shape[rank - 1];
for (var i = rank - 3; i >= 0; --i) {
strides[i] = strides[i + 1] * shape[i + 1];
}
return strides;
}
function createNestedArray(offset, shape, a, isComplex) {
if (isComplex === void 0) {
isComplex = false;
}
var ret = new Array();
if (shape.length === 1) {
var d = shape[0] * (isComplex ? 2 : 1);
for (var i = 0; i < d; i++) {
ret[i] = a[offset + i];
}
} else {
var d = shape[0];
var rest = shape.slice(1);
var len = rest.reduce(function(acc, c) {
return acc * c;
}) * (isComplex ? 2 : 1);
for (var i = 0; i < d; i++) {
ret[i] = createNestedArray(offset + i * len, rest, a, isComplex);
}
}
return ret;
}
function toNestedArray(shape, a, isComplex) {
if (isComplex === void 0) {
isComplex = false;
}
if (shape.length === 0) {
return a[0];
}
var size = shape.reduce(function(acc, c) {
return acc * c;
}) * (isComplex ? 2 : 1);
if (size === 0) {
return [];
}
if (size !== a.length) {
throw new Error("[".concat(shape, "] does not match the input size ").concat(a.length).concat(isComplex ? " for a complex tensor" : "", "."));
}
return createNestedArray(0, shape, a, isComplex);
}
function convertBackendValuesAndArrayBuffer(data, dtype) {
if (Array.isArray(data)) {
return data;
}
if (dtype === "float32") {
return data instanceof Float32Array ? data : new Float32Array(data);
} else if (dtype === "int32") {
return data instanceof Int32Array ? data : new Int32Array(data);
} else if (dtype === "bool" || dtype === "string") {
return Uint8Array.from(new Int32Array(data));
} else {
throw new Error("Unknown dtype ".concat(dtype));
}
}
function makeOnesTypedArray(size, dtype) {
var array = makeZerosTypedArray(size, dtype);
for (var i = 0; i < array.length; i++) {
array[i] = 1;
}
return array;
}
function makeZerosTypedArray(size, dtype) {
if (dtype == null || dtype === "float32" || dtype === "complex64") {
return new Float32Array(size);
} else if (dtype === "int32") {
return new Int32Array(size);
} else if (dtype === "bool") {
return new Uint8Array(size);
} else {
throw new Error("Unknown data type ".concat(dtype));
}
}
function makeZerosNestedTypedArray(shape, dtype) {
var size = shape.reduce(function(prev, curr) {
return prev * curr;
}, 1);
if (dtype == null || dtype === "float32") {
return toNestedArray(shape, new Float32Array(size));
} else if (dtype === "int32") {
return toNestedArray(shape, new Int32Array(size));
} else if (dtype === "bool") {
return toNestedArray(shape, new Uint8Array(size));
} else {
throw new Error("Unknown data type ".concat(dtype));
}
}
function assertNonNegativeIntegerDimensions(shape) {
shape.forEach(function(dimSize) {
assert(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 i = 0; i < locs.length - 1; ++i) {
index += strides[i] * locs[i];
}
return index;
}
function indexToLoc(index, rank, strides) {
if (rank === 0) {
return [];
} else if (rank === 1) {
return [index];
}
var locs = new Array(rank);
for (var i = 0; i < locs.length - 1; ++i) {
locs[i] = Math.floor(index / strides[i]);
index -= locs[i] * strides[i];
}
locs[locs.length - 1] = index;
return locs;
}
function isPromise(object) {
return object && object.then && typeof object.then === "function";
}
var TENSORFLOWJS_FLAGS_PREFIX = "tfjsflags";
var Environment = (
/** @class */
function() {
function Environment2(global2) {
this.global = global2;
this.flags = {};
this.flagRegistry = {};
this.urlFlags = {};
this.getQueryParams = getQueryParams;
this.populateURLFlags();
}
Environment2.prototype.setPlatform = function(platformName, platform) {
if (this.platform != null) {
if (!(env().getBool("IS_TEST") || env().getBool("PROD"))) {
console.warn("Platform ".concat(this.platformName, " has already been set. ") + "Overwriting the platform with ".concat(platformName, "."));
}
}
this.platformName = platformName;
this.platform = platform;
};
Environment2.prototype.registerFlag = function(flagName, evaluationFn, setHook) {
this.flagRegistry[flagName] = { evaluationFn, setHook };
if (this.urlFlags[flagName] != null) {
var flagValue = this.urlFlags[flagName];
if (!(env().getBool("IS_TEST") || env().getBool("PROD"))) {
console.warn("Setting feature override from URL ".concat(flagName, ": ").concat(flagValue, "."));
}
this.set(flagName, flagValue);
}
};
Environment2.prototype.getAsync = function(flagName) {
return __awaiter(this, void 0, void 0, function() {
var _a, _b;
return __generator(this, function(_c) {
switch (_c.label) {
case 0:
if (flagName in this.flags) {
return [2, this.flags[flagName]];
}
_a = this.flags;
_b = flagName;
return [4, this.evaluateFlag(flagName)];
case 1:
_a[_b] = _c.sent();
return [2, this.flags[flagName]];
}
});
});
};
Environment2.prototype.get = function(flagName) {
if (flagName in this.flags) {
return this.flags[flagName];
}
var flagValue = this.evaluateFlag(flagName);
if (isPromise(flagValue)) {
throw new Error("Flag ".concat(flagName, " cannot be synchronously evaluated. ") + "Please use getAsync() instead.");
}
this.flags[flagName] = flagValue;
return this.flags[flagName];
};
Environment2.prototype.getNumber = function(flagName) {
return this.get(flagName);
};
Environment2.prototype.getBool = function(flagName) {
return this.get(flagName);
};
Environment2.prototype.getString = function(flagName) {
return this.get(flagName);
};
Environment2.prototype.getFlags = function() {
return this.flags;
};
Object.defineProperty(Environment2.prototype, "features", {
// For backwards compatibility.
get: function() {
return this.flags;
},
enumerable: false,
configurable: true
});
Environment2.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);
}
};
Environment2.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();
};
Environment2.prototype.setFlags = function(flags) {
this.flags = Object.assign({}, flags);
};
Environment2.prototype.reset = function() {
this.flags = {};
this.urlFlags = {};
this.populateURLFlags();
};
Environment2.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_PREFIX in urlParams) {
var keyValues = urlParams[TENSORFLOWJS_FLAGS_PREFIX].split(",");
keyValues.forEach(function(keyValue) {
var _a = __read(keyValue.split(":"), 2), key = _a[0], value = _a[1];
_this.urlFlags[key] = parseValue(key, value);
});
}
};
return Environment2;
}()
);
function getQueryParams(queryString) {
var params = {};
queryString.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, function(s) {
var t = [];
for (var _i = 1; _i < arguments.length; _i++) {
t[_i - 1] = arguments[_i];
}
decodeParam(params, t[0], t[1]);
return t.join("=");
});
return params;
}
function decodeParam(params, name, value) {
params[decodeURIComponent(name)] = decodeURIComponent(value || "");
}
function parseValue(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 env() {
return exports.ENV;
}
exports.ENV = null;
function setEnvironmentGlobal(environment) {
exports.ENV = environment;
}
var globalNameSpace;
function getGlobalNamespace() {
if (globalNameSpace == 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");
}
globalNameSpace = ns;
}
return globalNameSpace;
}
function getGlobalMap() {
var ns = getGlobalNamespace();
if (ns._tfGlobals == null) {
ns._tfGlobals = /* @__PURE__ */ new Map();
}
return ns._tfGlobals;
}
function getGlobal(key, init) {
var globalMap = getGlobalMap();
if (globalMap.has(key)) {
return globalMap.get(key);
} else {
var singleton = init();
globalMap.set(key, singleton);
return globalMap.get(key);
}
}
var Abs = "Abs";
var Acos = "Acos";
var Acosh = "Acosh";
var Add = "Add";
var AddN = "AddN";
var All = "All";
var Any = "Any";
var ArgMax = "ArgMax";
var ArgMin = "ArgMin";
var Asin = "Asin";
var Asinh = "Asinh";
var Atan = "Atan";
var Atanh = "Atanh";
var Atan2 = "Atan2";
var AvgPool = "AvgPool";
var AvgPoolGrad = "AvgPoolGrad";
var AvgPool3D = "AvgPool3D";
var AvgPool3DGrad = "AvgPool3DGrad";
var BatchMatMul = "BatchMatMul";
var BatchToSpaceND = "BatchToSpaceND";
var Bincount = "Bincount";
var BitwiseAnd = "BitwiseAnd";
var BroadcastTo = "BroadcastTo";
var BroadcastArgs = "BroadcastArgs";
var Cast = "Cast";
var Ceil = "Ceil";
var ClipByValue = "ClipByValue";
var Complex = "Complex";
var ComplexAbs = "ComplexAbs";
var Concat = "Concat";
var Conv2D = "Conv2D";
var Conv2DBackpropFilter = "Conv2DBackpropFilter";
var Conv2DBackpropInput = "Conv2DBackpropInput";
var Conv3D = "Conv3D";
var Conv3DBackpropFilterV2 = "Conv3DBackpropFilterV2";
var Conv3DBackpropInputV2 = "Conv3DBackpropInputV2";
var Cos = "Cos";
var Cosh = "Cosh";
var Cumprod = "Cumprod";
var Cumsum = "Cumsum";
var CropAndResize = "CropAndResize";
var DenseBincount = "DenseBincount";
var DepthToSpace = "DepthToSpace";
var DepthwiseConv2dNative = "DepthwiseConv2dNative";
var DepthwiseConv2dNativeBackpropFilter = "DepthwiseConv2dNativeBackpropFilter";
var DepthwiseConv2dNativeBackpropInput = "DepthwiseConv2dNativeBackpropInput";
var Diag = "Diag";
var Dilation2D = "Dilation2D";
var Dilation2DBackpropInput = "Dilation2DBackpropInput";
var Dilation2DBackpropFilter = "Dilation2DBackpropFilter";
var Draw = "Draw";
var RealDiv = "RealDiv";
var Einsum = "Einsum";
var Elu = "Elu";
var EluGrad = "EluGrad";
var Erf = "Erf";
var Equal = "Equal";
var Exp = "Exp";
var ExpandDims = "ExpandDims";
var Expm1 = "Expm1";
var FFT = "FFT";
var Fill = "Fill";
var FlipLeftRight = "FlipLeftRight";
var Floor = "Floor";
var FloorDiv = "FloorDiv";
var FusedBatchNorm = "FusedBatchNorm";
var GatherV2 = "GatherV2";
var GatherNd = "GatherNd";
var Greater = "Greater";
var GreaterEqual = "GreaterEqual";
var Identity = "Identity";
var IFFT = "IFFT";
var Imag = "Imag";
var IsFinite = "IsFinite";
var IsInf = "IsInf";
var IsNan = "IsNan";
var LeakyRelu = "LeakyRelu";
var Less = "Less";
var LessEqual = "LessEqual";
var LinSpace = "LinSpace";
var Log = "Log";
var Log1p = "Log1p";
var LogicalAnd = "LogicalAnd";
var LogicalNot = "LogicalNot";
var LogicalOr = "LogicalOr";
var LogicalXor = "LogicalXor";
var LogSoftmax = "LogSoftmax";
var LowerBound = "LowerBound";
var LRN = "LRN";
var LRNGrad = "LRNGrad";
var MatrixBandPart = "MatrixBandPart";
var Max = "Max";
var Maximum = "Maximum";
var MaxPool = "MaxPool";
var MaxPoolGrad = "MaxPoolGrad";
var MaxPool3D = "MaxPool3D";
var MaxPool3DGrad = "MaxPool3DGrad";
var MaxPoolWithArgmax = "MaxPoolWithArgmax";
var Mean = "Mean";
var Min = "Min";
var Minimum = "Minimum";
var MirrorPad = "MirrorPad";
var Mod = "Mod";
var Multinomial = "Multinomial";
var Multiply = "Multiply";
var Neg = "Neg";
var NotEqual = "NotEqual";
var NonMaxSuppressionV3 = "NonMaxSuppressionV3";
var NonMaxSuppressionV4 = "NonMaxSuppressionV4";
var NonMaxSuppressionV5 = "NonMaxSuppressionV5";
var OnesLike = "OnesLike";
var OneHot = "OneHot";
var Pack = "Pack";
var PadV2 = "PadV2";
var Pool = "Pool";
var Pow = "Pow";
var Prelu = "Prelu";
var Prod = "Prod";
var RaggedGather = "RaggedGather";
var RaggedRange = "RaggedRange";
var RaggedTensorToTensor = "RaggedTensorToTensor";
var Range = "Range";
var Real = "Real";
var Reciprocal = "Reciprocal";
var Relu = "Relu";
var Reshape = "Reshape";
var ResizeNearestNeighbor = "ResizeNearestNeighbor";
var ResizeNearestNeighborGrad = "ResizeNearestNeighborGrad";
var ResizeBilinear = "ResizeBilinear";
var ResizeBilinearGrad = "ResizeBilinearGrad";
var Relu6 = "Relu6";
var Reverse = "Reverse";
var Round = "Round";
var Rsqrt = "Rsqrt";
var ScatterNd = "ScatterNd";
var TensorScatterUpdate = "TensorScatterUpdate";
var SearchSorted = "SearchSorted";
var Select = "Select";
var Selu = "Selu";
var Slice = "Slice";
var Sin = "Sin";
var Sinh = "Sinh";
var Sign = "Sign";
var Sigmoid = "Sigmoid";
var Softplus = "Softplus";
var Sqrt = "Sqrt";
var Sum = "Sum";
var SpaceToBatchND = "SpaceToBatchND";
var SplitV = "SplitV";
var Softmax = "Softmax";
var SparseFillEmptyRows = "SparseFillEmptyRows";
var SparseReshape = "SparseReshape";
var SparseSegmentMean = "SparseSegmentMean";
var SparseSegmentSum = "SparseSegmentSum";
var SparseToDense = "SparseToDense";
var SquaredDifference = "SquaredDifference";
var Square = "Square";
var StaticRegexReplace = "StaticRegexReplace";
var StridedSlice = "StridedSlice";
var StringNGrams = "StringNGrams";
var StringSplit = "StringSplit";
var StringToHashBucketFast = "StringToHashBucketFast";
var Sub = "Sub";
var Tan = "Tan";
var Tanh = "Tanh";
var Tile = "Tile";
var TopK = "TopK";
var Transform = "Transform";
var Transpose = "Transpose";
var Unique = "Unique";
var Unpack = "Unpack";
var UnsortedSegmentSum = "UnsortedSegmentSum";
var UpperBound = "UpperBound";
var ZerosLike = "ZerosLike";
var Step = "Step";
var FromPixels = "FromPixels";
var RotateWithOffset = "RotateWithOffset";
var _FusedMatMul = "_FusedMatMul";
var FusedConv2D = "FusedConv2D";
var FusedDepthwiseConv2D = "FusedDepthwiseConv2D";
function warn() {
var msg = [];
for (var _i = 0; _i < arguments.length; _i++) {
msg[_i] = arguments[_i];
}
if (!(env().getBool("IS_TEST") || env().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 (!(env().getBool("IS_TEST") || env().getBool("PROD"))) {
console.log.apply(console, __spreadArray([], __read(msg), false));
}
}
var kernelRegistry = getGlobal("kernelRegistry", function() {
return /* @__PURE__ */ new Map();
});
var gradRegistry = getGlobal("gradRegistry", function() {
return /* @__PURE__ */ new Map();
});
function getKernel(kernelName, backendName) {
var key = makeKey(kernelName, backendName);
return kernelRegistry.get(key);
}
function getGradient(kernelName) {
return gradRegistry.get(kernelName);
}
function getKernelsForBackend(backendName) {
var it = kernelRegistry.entries();
var result = [];
while (true) {
var _a = it.next(), done = _a.done, value = _a.value;
if (done) {
break;
}
var _b = __read(value, 2), key = _b[0], config = _b[1];
var _c = __read(key.split("_"), 1), backend2 = _c[0];
if (backend2 === backendName) {
result.push(config);
}
}
return result;
}
function registerKernel(config) {
var kernelName = config.kernelName, backendName = config.backendName;
var key = makeKey(kernelName, backendName);
if (kernelRegistry.has(key)) {
warn("The kernel '".concat(kernelName, "' for backend ") + "'".concat(backendName, "' is already registered"));
}
kernelRegistry.set(key, config);
}
function registerGradient(config) {
var kernelName = config.kernelName;
if (gradRegistry.has(kernelName)) {
if (env().getBool("DEBUG")) {
warn("Overriding the gradient for '".concat(kernelName, "'"));
}
}
gradRegistry.set(kernelName, config);
}
function unregisterKernel(kernelName, backendName) {
var key = makeKey(kernelName, backendName);
if (!kernelRegistry.has(key)) {
throw new Error("The kernel '".concat(kernelName, "' for backend ") + "'".concat(backendName, "' is not registered"));
}
kernelRegistry.delete(key);
}
function unregisterGradient(kernelName) {
if (!gradRegistry.has(kernelName)) {
throw new Error("The gradient '".concat(kernelName, "' for backend is not registered"));
}
gradRegistry.delete(kernelName);
}
function copyRegisteredKernels(registeredBackendName, newBackendName) {
var kernels = getKernelsForBackend(registeredBackendName);
kernels.forEach(function(kernelConfig) {
var newKernelConfig = Object.assign({}, kernelConfig, { backendName: newBackendName });
registerKernel(newKernelConfig);
});
}
function makeKey(kernelName, backendName) {
return "".concat(backendName, "_").concat(kernelName);
}
function isTypedArrayBrowser(a) {
return a instanceof Float32Array || a instanceof Int32Array || a instanceof Uint8Array || a instanceof Uint8ClampedArray;
}
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
function getDefaultExportFromCjs(x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
}
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,
0,
5,
8,
103,
101,
116,
95,
104,
105,
103,
104,
0,
0,
10,
191,
1,
6,
4,
0,
35,
0,
11,
36,
1,
1,
126,
32,
0,
173,
32,
1,
173,
66,
32,
134,
132,
32,
2,
173,
32,
3,
173,
66,
32,
134,
132,
126,
34,
4,
66,
32,
135,
167,
36,
0,
32,
4,
167,
11,
36,
1,
1,
126,
32,
0,
173,
32,
1,
173,
66,
32,
134,
132,
32,
2,
173,
32,
3,
173,
66,
32,
134,
132,
127,
34,
4,
66,
32,
135,
167,
36,
0,
32,
4,
167,
11,
36,
1,
1,
126,
32,
0,
173,
32,
1,
173,
66,
32,
134,
132,
32,
2,
173,
32,
3,
173,
66,
32,
134,
132,
128,
34,
4,
66,
32,
135,
167,
36,
0,
32,
4,
167,
11,
36,
1,
1,
126,
32,
0,
173,
32,
1,
173,
66,
32,
134,
132,
32,
2,
173,
32,
3,
173,
66,
32,
134,
132,
129,
34,
4,
66,
32,
135,
167,
36,
0,
32,
4,
167,
11,
36,
1,
1,
126,
32,
0,
173,
32,
1,
173,
66,
32,
134,
132,
32,
2,
173,
32,
3,
173,
66,
32,
134,
132,
130,
34,
4,
66,
32,
135,
167,
36,