@tensorflow-models/coco-ssd
Version:
Object detection model (coco-ssd) in TensorFlow.js
23 lines (22 loc) • 1.1 MB
JavaScript
// @tensorflow/tfjs Copyright 2019 Google
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.tf = global.tf || {})));
}(this, (function (exports) { 'use strict';
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/var extendStatics=function(e,t){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t;}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);})(e,t);};function __extends(e,t){function n(){this.constructor=e;}extendStatics(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n());}var __assign=function(){return(__assign=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e;}).apply(this,arguments);};function __awaiter(e,t,n,r){return new(n||(n=Promise))(function(o,a){function i(e){try{u(r.next(e));}catch(e){a(e);}}function s(e){try{u(r.throw(e));}catch(e){a(e);}}function u(e){e.done?o(e.value):new n(function(t){t(e.value);}).then(i,s);}u((r=r.apply(e,t||[])).next());});}function __generator(e,t){var n,r,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1];},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this;}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===a[0]||2===a[0])){i=0;continue;}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break;}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break;}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break;}o[2]&&i.ops.pop(),i.trys.pop();continue;}a=t.call(e,i);}catch(e){a=[6,e],r=0;}finally{n=o=0;}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0};}([a,s]);};}}var contexts={},WEBGL_ATTRIBUTES={alpha:!1,antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,depth:!1,stencil:!1,failIfMajorPerformanceCaveat:!0};function getWebGLContext(e){e in contexts||(document.createElement("canvas").addEventListener("webglcontextlost",function(t){t.preventDefault(),delete contexts[e];},!1),contexts[e]=getWebGLRenderingContext(e));var t=contexts[e];return t.isContextLost()?(delete contexts[e],getWebGLContext(e)):(t.disable(t.DEPTH_TEST),t.disable(t.STENCIL_TEST),t.disable(t.BLEND),t.disable(t.DITHER),t.disable(t.POLYGON_OFFSET_FILL),t.disable(t.SAMPLE_COVERAGE),t.enable(t.SCISSOR_TEST),t.enable(t.CULL_FACE),t.cullFace(t.BACK),contexts[e]);}function getWebGLRenderingContext(e){if(1!==e&&2!==e)throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");var t=document.createElement("canvas");return 1===e?t.getContext("webgl",WEBGL_ATTRIBUTES)||t.getContext("experimental-webgl",WEBGL_ATTRIBUTES):t.getContext("webgl2",WEBGL_ATTRIBUTES);}function isMobile(){var e=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(e)||/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(e.substr(0,4));}function shuffle(e){for(var t=e.length,n=0,r=0;t>0;)r=Math.random()*t|0,n=e[--t],e[t]=e[r],e[r]=n;}function clamp(e,t,n){return Math.max(e,Math.min(t,n));}function nearestLargerEven(e){return e%2==0?e:e+1;}function sum(e){for(var t=0,n=0;n<e.length;n++)t+=e[n];return t;}function randUniform(e,t){var n=Math.random();return t*n+(1-n)*e;}function distSquared(e,t){for(var n=0,r=0;r<e.length;r++){var o=Number(e[r])-Number(t[r]);n+=o*o;}return n;}function assert(e,t){if(!e)throw new Error("string"==typeof t?t:t());}function assertShapesMatch(e,t,n){void 0===n&&(n=""),assert(arraysEqual(e,t),n+" Shapes "+e+" and "+t+" must match");}function assertNonNull(e){assert(null!=e,"The input to the tensor constructor must be a non-null value.");}function flatten(e,t){if(void 0===t&&(t=[]),Array.isArray(e)||isTypedArray(e))for(var n=0;n<e.length;++n)flatten(e[n],t);else t.push(e);return t;}function sizeFromShape(e){if(0===e.length)return 1;for(var t=e[0],n=1;n<e.length;n++)t*=e[n];return t;}function isScalarShape(e){return 0===e.length;}function arraysEqual(e,t){if(e===t)return!0;if(null==e||null==t)return!1;if(e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0;}function isInt(e){return e%1==0;}function tanh(e){if(null!=Math.tanh)return Math.tanh(e);if(e===1/0)return 1;if(e===-1/0)return-1;var t=Math.exp(2*e);return(t-1)/(t+1);}function sizeToSquarishShape(e){var t=Math.ceil(Math.sqrt(e));return[t,Math.ceil(e/t)];}function createShuffledIndices(e){for(var t=new Uint32Array(e),n=0;n<e;++n)t[n]=n;return shuffle(t),t;}function rightPad(e,t){return t<=e.length?e:e+" ".repeat(t-e.length);}function repeatedTry(e,t,n){return void 0===t&&(t=function(e){return 0;}),new Promise(function(r,o){var a=0,i=function(){if(e())r();else{var s=t(++a);null!=n&&a>=n?o():setTimeout(i,s);}};i();});}function inferFromImplicitShape(e,t){for(var n=1,r=-1,o=0;o<e.length;++o)if(e[o]>=0)n*=e[o];else if(-1===e[o]){if(-1!==r)throw Error("Shapes can only have 1 implicit size. Found -1 at dim "+r+" and dim "+o);r=o;}else if(e[o]<0)throw Error("Shapes can not be < 0. Found "+e[o]+" at dim "+o);if(-1===r){if(t>0&&t!==n)throw Error("Size("+t+") must match the product of shape "+e);return e;}if(0===n)throw Error("Cannot infer the missing size in ["+e+"] when there are 0 elements");if(t%n!=0)throw Error("The implicit shape can't be a fractional number. Got "+t+" / "+n);var a=e.slice();return a[r]=t/n,a;}function parseAxisParam(e,t){var n=t.length;return assert((e=null==e?t.map(function(e,t){return t;}):[].concat(e)).every(function(e){return e>=-n&&e<n;}),"All values in axis param must be in range [-"+n+", "+n+") but got axis "+e),assert(e.every(function(e){return isInt(e);}),"All values in axis param must be integers but got axis "+e),e.map(function(e){return e<0?n+e:e;});}function squeezeShape(e,t){for(var n=[],r=[],o=null==t?null:parseAxisParam(t,e).sort(),a=0,i=0;i<e.length;++i){if(null!=o){if(o[a]===i&&1!==e[i])throw new Error("Can't squeeze axis "+i+" since its dim '"+e[i]+"' is not 1");(null==o[a]||o[a]>i)&&1===e[i]&&(n.push(e[i]),r.push(i)),o[a]<=i&&a++;}1!==e[i]&&(n.push(e[i]),r.push(i));}return{newShape:n,keptDims:r};}function getTypedArrayFromDType(e,t){var n=null;if(null==e||"float32"===e)n=new Float32Array(t);else if("int32"===e)n=new Int32Array(t);else{if("bool"!==e)throw new Error("Unknown data type "+e);n=new Uint8Array(t);}return n;}function getArrayFromDType(e,t){var n=null;if(null==e||"float32"===e)n=new Float32Array(t);else if("int32"===e)n=new Int32Array(t);else if("bool"===e)n=new Uint8Array(t);else{if("string"!==e)throw new Error("Unknown data type "+e);n=new Array(t);}return n;}function checkComputationForErrors(e,t,n){if("float32"===t)for(var r=0;r<e.length;r++){var o=e[r];if(isNaN(o)||!isFinite(o))throw Error("The result of the '"+n+"' is "+o+".");}}function checkConversionForErrors(e,t){for(var n=0;n<e.length;n++){var r=e[n];if(isNaN(r)||!isFinite(r))throw Error("A tensor of type "+t+" being uploaded contains "+r+".");}}function hasEncodingLoss(e,t){return"complex64"!==t&&("float32"!==t||"complex64"===e)&&("int32"!==t||"float32"===e||"complex64"===e)&&("bool"!==t||"bool"!==e);}function isTypedArray(e){return e instanceof Float32Array||e instanceof Int32Array||e instanceof Uint8Array;}function bytesPerElement(e){if("float32"===e||"int32"===e)return 4;if("complex64"===e)return 8;if("bool"===e)return 1;throw new Error("Unknown dtype "+e);}function bytesFromStringArray(e){if(null==e)return 0;var t=0;return e.forEach(function(e){return t+=2*e.length;}),t;}function isString(e){return"string"==typeof e||e instanceof String;}function isBoolean(e){return"boolean"==typeof e;}function isNumber(e){return"number"==typeof e;}function inferDtype(e){return Array.isArray(e)?inferDtype(e[0]):e instanceof Float32Array?"float32":e instanceof Int32Array||e instanceof Uint8Array?"int32":isNumber(e)?"float32":isString(e)?"string":isBoolean(e)?"bool":"float32";}function isFunction(e){return!!(e&&e.constructor&&e.call&&e.apply);}function nearestDivisor(e,t){for(var n=t;n<e;++n)if(e%n==0)return n;return e;}function computeStrides(e){var t=e.length;if(t<2)return[];var n=new Array(t-1);n[t-2]=e[t-1];for(var r=t-3;r>=0;--r)n[r]=n[r+1]*e[r+1];return n;}function toTypedArray(e,t,n){if("string"===t)throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(e)&&(e=flatten(e)),n&&checkConversionForErrors(e,t),noConversionNeeded(e,t))return e;if(null==t||"float32"===t||"complex64"===t)return new Float32Array(e);if("int32"===t)return new Int32Array(e);if("bool"===t){for(var r=new Uint8Array(e.length),o=0;o<r.length;++o)0!==Math.round(e[o])&&(r[o]=1);return r;}throw new Error("Unknown data type "+t);}function createNestedArray(e,t,n){var r=new Array();if(1===t.length)for(var o=t[0],a=0;a<o;a++)r[a]=n[e+a];else{o=t[0];var i=t.slice(1),s=i.reduce(function(e,t){return e*t;});for(a=0;a<o;a++)r[a]=createNestedArray(e+a*s,i,n);}return r;}function toNestedArray(e,t){if(0===e.length)return t[0];var n=e.reduce(function(e,t){return e*t;});if(0===n)return[];if(n!==t.length)throw new Error("["+e+"] does not match the input size.");return createNestedArray(0,e,t);}function noConversionNeeded(e,t){return e instanceof Float32Array&&"float32"===t||e instanceof Int32Array&&"int32"===t||e instanceof Uint8Array&&"bool"===t;}function makeOnesTypedArray(e,t){for(var n=makeZerosTypedArray(e,t),r=0;r<n.length;r++)n[r]=1;return n;}function makeZerosTypedArray(e,t){if(null==t||"float32"===t||"complex64"===t)return new Float32Array(e);if("int32"===t)return new Int32Array(e);if("bool"===t)return new Uint8Array(e);throw new Error("Unknown data type "+t);}function now(){if("undefined"!=typeof performance)return performance.now();if("undefined"!=typeof process){var e=process.hrtime();return 1e3*e[0]+e[1]/1e6;}throw new Error("Cannot measure time in this environment. You should run tf.js in the browser or in Node.js");}function monitorPromisesProgress(e,t,n,r){!function(e){assert(null!=e&&Array.isArray(e)&&e.length>0,"promises must be a none empty array");}(e),function(e,t){assert(e>=0&&e<=1,"Progress fraction must be in range [0, 1], but got startFraction "+e),assert(t>=0&&t<=1,"Progress fraction must be in range [0, 1], but got endFraction "+t),assert(t>=e,"startFraction must be no more than endFraction, but got startFraction "+e+" and endFraction "+t);}(n=null==n?0:n,r=null==r?1:r);var o=0;return Promise.all(e.map(function(a){return a.then(function(a){var i=n+ ++o/e.length*(r-n);return t(i),a;}),a;}));}var util=Object.freeze({shuffle:shuffle,clamp:clamp,nearestLargerEven:nearestLargerEven,sum:sum,randUniform:randUniform,distSquared:distSquared,assert:assert,assertShapesMatch:assertShapesMatch,assertNonNull:assertNonNull,flatten:flatten,sizeFromShape:sizeFromShape,isScalarShape:isScalarShape,arraysEqual:arraysEqual,isInt:isInt,tanh:tanh,sizeToSquarishShape:sizeToSquarishShape,createShuffledIndices:createShuffledIndices,rightPad:rightPad,repeatedTry:repeatedTry,inferFromImplicitShape:inferFromImplicitShape,parseAxisParam:parseAxisParam,squeezeShape:squeezeShape,getTypedArrayFromDType:getTypedArrayFromDType,getArrayFromDType:getArrayFromDType,checkComputationForErrors:checkComputationForErrors,checkConversionForErrors:checkConversionForErrors,hasEncodingLoss:hasEncodingLoss,isTypedArray:isTypedArray,bytesPerElement:bytesPerElement,bytesFromStringArray:bytesFromStringArray,isString:isString,isBoolean:isBoolean,isNumber:isNumber,inferDtype:inferDtype,isFunction:isFunction,nearestDivisor:nearestDivisor,computeStrides:computeStrides,toTypedArray:toTypedArray,toNestedArray:toNestedArray,makeOnesTypedArray:makeOnesTypedArray,makeZerosTypedArray:makeZerosTypedArray,now:now,monitorPromisesProgress:monitorPromisesProgress}),Profiler=function(){function e(e,t){this.backendTimer=e,this.logger=t,null==t&&(this.logger=new Logger());}return e.prototype.profileKernel=function(e,t){var n,r=this,o=this.backendTimer.time(function(){n=t();});return(Array.isArray(n)?n:[n]).forEach(function(t){var n=t.dataSync();checkComputationForErrors(n,t.dtype,e),o.then(function(o){var a="";null!=o.getExtraProfileInfo&&(a=o.getExtraProfileInfo()),r.logger.logKernelProfile(e,t,n,o.kernelMs,a);});}),n;},e;}(),Logger=function(){function e(){}return e.prototype.logKernelProfile=function(e,t,n,r,o){var a=rightPad(r+"ms",9),i=rightPad(e,25),s=t.rank,u=t.size,l=rightPad(t.shape.toString(),14);console.log("%c"+i+"\t%c"+a+"\t%c"+s+"D "+l+"\t%c"+u+"\t%c"+o,"font-weight:bold","color:red","color:blue","color: orange","color: green");},e;}(),FORMAT_LIMIT_NUM_VALS=20,FORMAT_NUM_FIRST_LAST_VALS=3,FORMAT_NUM_SIG_DIGITS=7;function tensorToString(e,t,n,r){var o=computeStrides(t),a=computeMaxSizePerColumn(e,t,n,o),i=t.length,s=subTensorToString(e,t,n,o,a),u=["Tensor"];return r&&(u.push(" dtype: "+n),u.push(" rank: "+i),u.push(" shape: ["+t+"]"),u.push(" values:")),u.push(s.map(function(e){return" "+e;}).join("\n")),u.join("\n");}function computeMaxSizePerColumn(e,t,n,r){var o=sizeFromShape(t),a=r[r.length-1],i=new Array(a).fill(0),s=t.length,u="complex64"===n?createComplexTuples(e):e;if(s>1)for(var l=0;l<o/a;l++)for(var c=l*a,p=0;p<a;p++)i[p]=Math.max(i[p],valToString(u[c+p],0).length);return i;}function valToString(e,t){return rightPad(Array.isArray(e)?parseFloat(e[0].toFixed(FORMAT_NUM_SIG_DIGITS))+" + "+parseFloat(e[1].toFixed(FORMAT_NUM_SIG_DIGITS))+"j":isString(e)?"'"+e+"'":parseFloat(e.toFixed(FORMAT_NUM_SIG_DIGITS)).toString(),t);}function subTensorToString(e,t,n,r,o,a){void 0===a&&(a=!0);var i="complex64"===n?2:1,s=t[0],u=t.length;if(0===u)return"complex64"===n?[valToString(createComplexTuples(e)[0],0)]:[e[0].toString()];if(1===u){if(s>FORMAT_LIMIT_NUM_VALS){var l=FORMAT_NUM_FIRST_LAST_VALS*i,c=Array.from(e.slice(0,l)),p=Array.from(e.slice(s-FORMAT_NUM_FIRST_LAST_VALS*i,s));return"complex64"===n&&(c=createComplexTuples(c),p=createComplexTuples(p)),["["+c.map(function(e,t){return valToString(e,o[t]);}).join(", ")+", ..., "+p.map(function(e,t){return valToString(e,o[s-FORMAT_NUM_FIRST_LAST_VALS+t]);}).join(", ")+"]"];}return["["+("complex64"===n?createComplexTuples(e):Array.from(e)).map(function(e,t){return valToString(e,o[t]);}).join(", ")+"]"];}var d=t.slice(1),h=r.slice(1),f=r[0]*i,m=[];if(s>FORMAT_LIMIT_NUM_VALS){for(var g=0;g<FORMAT_NUM_FIRST_LAST_VALS;g++){var v=(y=g*f)+f;m.push.apply(m,subTensorToString(e.slice(y,v),d,n,h,o,!1));}m.push("...");for(g=s-FORMAT_NUM_FIRST_LAST_VALS;g<s;g++){v=(y=g*f)+f;m.push.apply(m,subTensorToString(e.slice(y,v),d,n,h,o,g===s-1));}}else for(g=0;g<s;g++){var y;v=(y=g*f)+f;m.push.apply(m,subTensorToString(e.slice(y,v),d,n,h,o,g===s-1));}var x=2===u?",":"";m[0]="["+m[0]+x;for(g=1;g<m.length-1;g++)m[g]=" "+m[g]+x;var T=",\n";for(g=2;g<u;g++)T+="\n";return m[m.length-1]=" "+m[m.length-1]+"]"+(a?"":T),m;}function createComplexTuples(e){for(var t=[],n=0;n<e.length;n+=2)t.push([e[n],e[n+1]]);return t;}var TensorBuffer=function(){function e(e,t,n){if(this.dtype=t,this.shape=e.slice(),this.size=sizeFromShape(e),null!=n){var r=n.length;assert(r===this.size,"Length of values '"+r+"' does not match the size inferred by the shape '"+this.size+"'.");}if("complex64"===t)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=n||getArrayFromDType(t,sizeFromShape(this.shape)),this.strides=computeStrides(e);}return e.prototype.set=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];0===t.length&&(t=[0]),assert(t.length===this.rank,"The number of provided coordinates ("+t.length+") must match the rank ("+this.rank+")");var r=this.locToIndex(t);this.values[r]=e;},e.prototype.get=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];0===e.length&&(e=[0]);for(var n=e[e.length-1],r=0;r<e.length-1;++r)n+=this.strides[r]*e[r];return this.values[n];},e.prototype.locToIndex=function(e){if(0===this.rank)return 0;if(1===this.rank)return e[0];for(var t=e[e.length-1],n=0;n<e.length-1;++n)t+=this.strides[n]*e[n];return t;},e.prototype.indexToLoc=function(e){if(0===this.rank)return[];if(1===this.rank)return[e];for(var t=new Array(this.shape.length),n=0;n<t.length-1;++n)t[n]=Math.floor(e/this.strides[n]),e-=t[n]*this.strides[n];return t[t.length-1]=e,t;},Object.defineProperty(e.prototype,"rank",{get:function(){return this.shape.length;},enumerable:!0,configurable:!0}),e.prototype.toTensor=function(){return Tensor.make(this.shape,{values:this.values},this.dtype);},e;}(),trackerFn=null,opHandler=null,deprecationWarningFn=null;function setTensorTracker(e){trackerFn=e;}function setOpHandler(e){opHandler=e;}function setDeprecationWarningFn(e){deprecationWarningFn=e;}var Tensor=function(){function e(e,t,n,r){this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=t||"float32",this.size=sizeFromShape(e),this.strides=computeStrides(e),this.dataId=null!=r?r:{},this.id=trackerFn().nextTensorId(),this.rankType=this.rank<5?this.rank.toString():"higher",trackerFn().registerTensor(this),null!=n&&trackerFn().write(this.dataId,n);}return e.make=function(t,n,r){return new e(t,r,n.values,n.dataId);},e.prototype.flatten=function(){return this.throwIfDisposed(),this.as1D();},e.prototype.asScalar=function(){return this.throwIfDisposed(),assert(1===this.size,"The array must have only 1 element."),this.reshape([]);},e.prototype.as1D=function(){return this.throwIfDisposed(),this.reshape([this.size]);},e.prototype.as2D=function(e,t){return this.throwIfDisposed(),this.reshape([e,t]);},e.prototype.as3D=function(e,t,n){return this.throwIfDisposed(),this.reshape([e,t,n]);},e.prototype.as4D=function(e,t,n,r){return this.throwIfDisposed(),this.reshape([e,t,n,r]);},e.prototype.as5D=function(e,t,n,r,o){return this.throwIfDisposed(),this.reshape([e,t,n,r,o]);},e.prototype.asType=function(e){return this.throwIfDisposed(),opHandler.cast(this,e);},Object.defineProperty(e.prototype,"rank",{get:function(){return this.shape.length;},enumerable:!0,configurable:!0}),e.prototype.get=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];deprecationWarningFn("Tensor.get() is deprecated. Use Tensor.array() and native array indexing instead."),assert(e.length===this.rank,"Number of coordinates in get() must match the rank of the tensor"),assert("complex64"!==this.dtype,"Tensor.get() is not supported for complex64 tensors yet."),this.throwIfDisposed(),0===e.length&&(e=[0]);for(var n=e[e.length-1],r=0;r<e.length-1;++r)n+=this.strides[r]*e[r];return this.dataSync()[n];},e.prototype.buffer=function(){return deprecationWarningFn("Tensor.buffer() is renamed to Tensor.bufferSync() in TensorFlow.js 1.0 and Tensor.buffer() will become an async function."),opHandler.buffer(this.shape,this.dtype,this.dataSync());},e.prototype.bufferSync=function(){return opHandler.buffer(this.shape,this.dtype,this.dataSync());},e.prototype.array=function(){return __awaiter(this,void 0,void 0,function(){var e,t;return __generator(this,function(n){switch(n.label){case 0:return e=toNestedArray,t=[this.shape],[4,this.data()];case 1:return[2,e.apply(void 0,t.concat([n.sent()]))];}});});},e.prototype.arraySync=function(){return toNestedArray(this.shape,this.dataSync());},e.prototype.data=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){return this.throwIfDisposed(),[2,trackerFn().read(this.dataId)];});});},e.prototype.dataSync=function(){return this.throwIfDisposed(),trackerFn().readSync(this.dataId);},e.prototype.dispose=function(){this.isDisposed||(trackerFn().disposeTensor(this),this.isDisposedInternal=!0);},Object.defineProperty(e.prototype,"isDisposed",{get:function(){return this.isDisposedInternal;},enumerable:!0,configurable:!0}),e.prototype.throwIfDisposed=function(){if(this.isDisposed)throw new Error("Tensor is disposed.");},e.prototype.toFloat=function(){return this.asType("float32");},e.prototype.toInt=function(){return this.asType("int32");},e.prototype.toBool=function(){return this.asType("bool");},e.prototype.print=function(e){return void 0===e&&(e=!1),opHandler.print(this,e);},e.prototype.reshape=function(e){return this.throwIfDisposed(),opHandler.reshape(this,e);},e.prototype.reshapeAs=function(e){return this.throwIfDisposed(),this.reshape(e.shape);},e.prototype.expandDims=function(e){return void 0===e&&(e=0),opHandler.expandDims(this,e);},e.prototype.cumsum=function(e,t,n){return void 0===e&&(e=0),void 0===t&&(t=!1),void 0===n&&(n=!1),opHandler.cumsum(this,e,t,n);},e.prototype.squeeze=function(e){return this.throwIfDisposed(),opHandler.squeeze(this,e);},e.prototype.clone=function(){return this.throwIfDisposed(),opHandler.clone(this);},e.prototype.oneHot=function(e,t,n){return this.throwIfDisposed(),opHandler.oneHot(this,e,t,n);},e.prototype.toString=function(e){return void 0===e&&(e=!1),tensorToString(this.dataSync(),this.shape,this.dtype,e);},e.prototype.tile=function(e){return this.throwIfDisposed(),opHandler.tile(this,e);},e.prototype.gather=function(e,t){return void 0===t&&(t=0),this.throwIfDisposed(),opHandler.gather(this,e,t);},e.prototype.matMul=function(e,t,n){return void 0===t&&(t=!1),void 0===n&&(n=!1),this.throwIfDisposed(),opHandler.matMul(this,e,t,n);},e.prototype.dot=function(e){return this.throwIfDisposed(),opHandler.dot(this,e);},e.prototype.norm=function(e,t,n){return void 0===e&&(e="euclidean"),void 0===t&&(t=null),void 0===n&&(n=!1),this.throwIfDisposed(),opHandler.norm(this,e,t,n);},e.prototype.slice=function(e,t){return this.throwIfDisposed(),opHandler.slice(this,e,t);},e.prototype.reverse=function(e){return this.throwIfDisposed(),opHandler.reverse(this,e);},e.prototype.concat=function(t,n){return void 0===n&&(n=0),this.throwIfDisposed(),t instanceof e&&(t=[t]),opHandler.concat([this].concat(t),n);},e.prototype.split=function(e,t){return void 0===t&&(t=0),this.throwIfDisposed(),opHandler.split(this,e,t);},e.prototype.stack=function(e,t){return void 0===t&&(t=0),opHandler.stack([this,e],t);},e.prototype.unstack=function(e){return void 0===e&&(e=0),opHandler.unstack(this,e);},e.prototype.pad=function(e,t){return void 0===t&&(t=0),opHandler.pad(this,e,t);},e.prototype.batchNormalization=function(e,t,n,r,o){return void 0===n&&(n=.001),deprecationWarningFn("tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon"),this.batchNorm(e,t,o,r,n);},e.prototype.batchNorm=function(e,t,n,r,o){return void 0===o&&(o=.001),this.throwIfDisposed(),opHandler.batchNorm(this,e,t,n,r,o);},e.prototype.all=function(e,t){return void 0===e&&(e=null),void 0===t&&(t=!1),this.throwIfDisposed(),opHandler.all(this,e,t);},e.prototype.any=function(e,t){return void 0===e&&(e=null),void 0===t&&(t=!1),this.throwIfDisposed(),opHandler.any(this,e,t);},e.prototype.logSumExp=function(e,t){return void 0===e&&(e=null),void 0===t&&(t=!1),this.throwIfDisposed(),opHandler.logSumExp(this,e,t);},e.prototype.sum=function(e,t){return void 0===e&&(e=null),void 0===t&&(t=!1),this.throwIfDisposed(),opHandler.sum(this,e,t);},e.prototype.prod=function(e,t){return void 0===e&&(e=null),void 0===t&&(t=!1),this.throwIfDisposed(),opHandler.prod(this,e,t);},e.prototype.mean=function(e,t){return void 0===e&&(e=null),void 0===t&&(t=!1),this.throwIfDisposed(),opHandler.mean(this,e,t);},e.prototype.min=function(e,t){return void 0===e&&(e=null),void 0===t&&(t=!1),this.throwIfDisposed(),opHandler.min(this,e,t);},e.prototype.max=function(e,t){return void 0===e&&(e=null),void 0===t&&(t=!1),this.throwIfDisposed(),opHandler.max(this,e,t);},e.prototype.argMin=function(e){return void 0===e&&(e=null),this.throwIfDisposed(),opHandler.argMin(this,e);},e.prototype.argMax=function(e){return void 0===e&&(e=null),this.throwIfDisposed(),opHandler.argMax(this,e);},e.prototype.cast=function(e){return this.throwIfDisposed(),opHandler.cast(this,e);},e.prototype.add=function(e){return this.throwIfDisposed(),opHandler.add(this,e);},e.prototype.addStrict=function(e){return this.throwIfDisposed(),opHandler.addStrict(this,e);},e.prototype.atan2=function(e){return this.throwIfDisposed(),opHandler.atan2(this,e);},e.prototype.sub=function(e){return this.throwIfDisposed(),opHandler.sub(this,e);},e.prototype.subStrict=function(e){return this.throwIfDisposed(),opHandler.subStrict(this,e);},e.prototype.pow=function(e){return this.throwIfDisposed(),opHandler.pow(this,e);},e.prototype.powStrict=function(e){return this.throwIfDisposed(),opHandler.powStrict(this,e);},e.prototype.mul=function(e){return this.throwIfDisposed(),opHandler.mul(this,e);},e.prototype.mulStrict=function(e){return this.throwIfDisposed(),opHandler.mulStrict(this,e);},e.prototype.div=function(e){return this.throwIfDisposed(),opHandler.div(this,e);},e.prototype.floorDiv=function(e){return this.throwIfDisposed(),opHandler.floorDiv(this,e);},e.prototype.divStrict=function(e){return this.throwIfDisposed(),opHandler.divStrict(this,e);},e.prototype.minimum=function(e){return this.throwIfDisposed(),opHandler.minimum(this,e);},e.prototype.minimumStrict=function(e){return this.throwIfDisposed(),opHandler.minimumStrict(this,e);},e.prototype.maximum=function(e){return this.throwIfDisposed(),opHandler.maximum(this,e);},e.prototype.maximumStrict=function(e){return this.throwIfDisposed(),opHandler.maximumStrict(this,e);},e.prototype.mod=function(e){return this.throwIfDisposed(),opHandler.mod(this,e);},e.prototype.modStrict=function(e){return this.throwIfDisposed(),opHandler.modStrict(this,e);},e.prototype.squaredDifference=function(e){return this.throwIfDisposed(),opHandler.squaredDifference(this,e);},e.prototype.squaredDifferenceStrict=function(e){return this.throwIfDisposed(),opHandler.squaredDifferenceStrict(this,e);},e.prototype.transpose=function(e){return this.throwIfDisposed(),opHandler.transpose(this,e);},e.prototype.notEqual=function(e){return this.throwIfDisposed(),opHandler.notEqual(this,e);},e.prototype.notEqualStrict=function(e){return this.throwIfDisposed(),opHandler.notEqualStrict(this,e);},e.prototype.less=function(e){return this.throwIfDisposed(),opHandler.less(this,e);},e.prototype.lessStrict=function(e){return this.throwIfDisposed(),opHandler.lessStrict(this,e);},e.prototype.equal=function(e){return this.throwIfDisposed(),opHandler.equal(this,e);},e.prototype.equalStrict=function(e){return this.throwIfDisposed(),opHandler.equalStrict(this,e);},e.prototype.lessEqual=function(e){return this.throwIfDisposed(),opHandler.lessEqual(this,e);},e.prototype.lessEqualStrict=function(e){return this.throwIfDisposed(),opHandler.lessEqualStrict(this,e);},e.prototype.greater=function(e){return this.throwIfDisposed(),opHandler.greater(this,e);},e.prototype.greaterStrict=function(e){return this.throwIfDisposed(),opHandler.greaterStrict(this,e);},e.prototype.greaterEqual=function(e){return this.throwIfDisposed(),opHandler.greaterEqual(this,e);},e.prototype.greaterEqualStrict=function(e){return this.throwIfDisposed(),opHandler.greaterEqualStrict(this,e);},e.prototype.logicalAnd=function(e){return this.throwIfDisposed(),opHandler.logicalAnd(this,e);},e.prototype.logicalOr=function(e){return this.throwIfDisposed(),opHandler.logicalOr(this,e);},e.prototype.logicalNot=function(){return this.throwIfDisposed(),opHandler.logicalNot(this);},e.prototype.logicalXor=function(e){return this.throwIfDisposed(),opHandler.logicalXor(this,e);},e.prototype.where=function(e,t){return this.throwIfDisposed(),opHandler.where(e,this,t);},e.prototype.neg=function(){return this.throwIfDisposed(),opHandler.neg(this);},e.prototype.ceil=function(){return this.throwIfDisposed(),opHandler.ceil(this);},e.prototype.floor=function(){return this.throwIfDisposed(),opHandler.floor(this);},e.prototype.sign=function(){return this.throwIfDisposed(),opHandler.sign(this);},e.prototype.exp=function(){return this.throwIfDisposed(),opHandler.exp(this);},e.prototype.expm1=function(){return this.throwIfDisposed(),opHandler.expm1(this);},e.prototype.log=function(){return this.throwIfDisposed(),opHandler.log(this);},e.prototype.log1p=function(){return this.throwIfDisposed(),opHandler.log1p(this);},e.prototype.sqrt=function(){return this.throwIfDisposed(),opHandler.sqrt(this);},e.prototype.rsqrt=function(){return this.throwIfDisposed(),opHandler.rsqrt(this);},e.prototype.square=function(){return this.throwIfDisposed(),opHandler.square(this);},e.prototype.reciprocal=function(){return this.throwIfDisposed(),opHandler.reciprocal(this);},e.prototype.abs=function(){return this.throwIfDisposed(),opHandler.abs(this);},e.prototype.clipByValue=function(e,t){return this.throwIfDisposed(),opHandler.clipByValue(this,e,t);},e.prototype.relu=function(){return this.throwIfDisposed(),opHandler.relu(this);},e.prototype.elu=function(){return this.throwIfDisposed(),opHandler.elu(this);},e.prototype.selu=function(){return this.throwIfDisposed(),opHandler.selu(this);},e.prototype.leakyRelu=function(e){return void 0===e&&(e=.2),this.throwIfDisposed(),opHandler.leakyRelu(this,e);},e.prototype.prelu=function(e){return this.throwIfDisposed(),opHandler.prelu(this,e);},e.prototype.sigmoid=function(){return this.throwIfDisposed(),opHandler.sigmoid(this);},e.prototype.logSigmoid=function(){return this.throwIfDisposed(),opHandler.logSigmoid(this);},e.prototype.softplus=function(){return this.throwIfDisposed(),opHandler.softplus(this);},e.prototype.zerosLike=function(){return this.throwIfDisposed(),opHandler.zerosLike(this);},e.prototype.onesLike=function(){return this.throwIfDisposed(),opHandler.onesLike(this);},e.prototype.sin=function(){return this.throwIfDisposed(),opHandler.sin(this);},e.prototype.cos=function(){return this.throwIfDisposed(),opHandler.cos(this);},e.prototype.tan=function(){return this.throwIfDisposed(),opHandler.tan(this);},e.prototype.asin=function(){return this.throwIfDisposed(),opHandler.asin(this);},e.prototype.acos=function(){return this.throwIfDisposed(),opHandler.acos(this);},e.prototype.atan=function(){return this.throwIfDisposed(),opHandler.atan(this);},e.prototype.sinh=function(){return this.throwIfDisposed(),opHandler.sinh(this);},e.prototype.cosh=function(){return this.throwIfDisposed(),opHandler.cosh(this);},e.prototype.tanh=function(){return this.throwIfDisposed(),opHandler.tanh(this);},e.prototype.asinh=function(){return this.throwIfDisposed(),opHandler.asinh(this);},e.prototype.acosh=function(){return this.throwIfDisposed(),opHandler.acosh(this);},e.prototype.atanh=function(){return this.throwIfDisposed(),opHandler.atanh(this);},e.prototype.erf=function(){return this.throwIfDisposed(),opHandler.erf(this);},e.prototype.round=function(){return this.throwIfDisposed(),opHandler.round(this);},e.prototype.step=function(e){return void 0===e&&(e=0),this.throwIfDisposed(),opHandler.step(this,e);},e.prototype.softmax=function(e){return void 0===e&&(e=-1),this.throwIfDisposed(),opHandler.softmax(this,e);},e.prototype.logSoftmax=function(e){return void 0===e&&(e=-1),this.throwIfDisposed(),opHandler.logSoftmax(this,e);},e.prototype.resizeBilinear=function(e,t){return void 0===t&&(t=!1),this.throwIfDisposed(),opHandler.image.resizeBilinear(this,e,t);},e.prototype.resizeNearestNeighbor=function(e,t){return void 0===t&&(t=!1),this.throwIfDisposed(),opHandler.image.resizeNearestNeighbor(this,e,t);},e.prototype.conv1d=function(e,t,n,r,o,a){return void 0===r&&(r="NWC"),void 0===o&&(o=1),this.throwIfDisposed(),opHandler.conv1d(this,e,t,n,r,o,a);},e.prototype.conv2d=function(e,t,n,r,o,a){return void 0===r&&(r="NHWC"),void 0===o&&(o=[1,1]),this.throwIfDisposed(),opHandler.conv2d(this,e,t,n,r,o,a);},e.prototype.conv2dTranspose=function(e,t,n,r,o){return this.throwIfDisposed(),opHandler.conv2dTranspose(this,e,t,n,r,o);},e.prototype.depthwiseConv2D=function(e,t,n,r,o,a){return void 0===r&&(r="NHWC"),void 0===o&&(o=[1,1]),this.throwIfDisposed(),opHandler.depthwiseConv2d(this,e,t,n,r,o,a);},e.prototype.separableConv2d=function(e,t,n,r,o,a){return void 0===o&&(o=[1,1]),void 0===a&&(a="NHWC"),this.throwIfDisposed(),opHandler.separableConv2d(this,e,t,n,r,o,a);},e.prototype.avgPool=function(e,t,n,r){return this.throwIfDisposed(),opHandler.avgPool(this,e,t,n,r);},e.prototype.maxPool=function(e,t,n,r){return this.throwIfDisposed(),opHandler.maxPool(this,e,t,n,r);},e.prototype.localResponseNormalization=function(e,t,n,r){return void 0===e&&(e=5),void 0===t&&(t=1),void 0===n&&(n=1),void 0===r&&(r=.5),opHandler.localResponseNormalization(this,e,t,n,r);},e.prototype.pool=function(e,t,n,r,o){return this.throwIfDisposed(),opHandler.pool(this,e,t,n,r,o);},e.prototype.variable=function(e,t,n){return void 0===e&&(e=!0),this.throwIfDisposed(),Variable.variable(this,e,t,n);},e.prototype.unsortedSegmentSum=function(e,t){return this.throwIfDisposed(),opHandler.unsortedSegmentSum(this,e,t);},e.prototype.batchToSpaceND=function(e,t){return this.throwIfDisposed(),opHandler.batchToSpaceND(this,e,t);},e.prototype.spaceToBatchND=function(e,t){return this.throwIfDisposed(),opHandler.spaceToBatchND(this,e,t);},e.prototype.topk=function(e,t){return void 0===e&&(e=1),void 0===t&&(t=!0),this.throwIfDisposed(),opHandler.topk(this,e,t);},e.prototype.stridedSlice=function(e,t,n,r,o,a,i,s){return void 0===r&&(r=0),void 0===o&&(o=0),void 0===a&&(a=0),void 0===i&&(i=0),void 0===s&&(s=0),this.throwIfDisposed(),opHandler.stridedSlice(this,e,t,n,r,o,a,i,s);},e.prototype.depthToSpace=function(e,t){return this.throwIfDisposed(),opHandler.depthToSpace(this,e,t);},e.prototype.fft=function(){return this.throwIfDisposed(),opHandler.spectral.fft(this);},e.prototype.ifft=function(){return this.throwIfDisposed(),opHandler.spectral.ifft(this);},e.prototype.rfft=function(){return this.throwIfDisposed(),opHandler.spectral.rfft(this);},e.prototype.irfft=function(){return this.throwIfDisposed(),opHandler.spectral.irfft(this);},e;}();Object.defineProperty(Tensor,Symbol.hasInstance,{value:function(e){return!!e&&null!=e.dataId&&null!=e.shape&&null!=e.dtype;}});var Variable=function(e){function t(t,n,r){void 0===n&&(n=!0);var o=e.call(this,t.shape,t.dtype,null,t.dataId)||this;o.trainable=n,o.name=r,null==o.name&&(o.name=trackerFn().nextVariableId().toString());try{trackerFn().registerVariable(o);}catch(e){throw trackerFn().disposeTensor(o),e;}return o;}return __extends(t,e),t.variable=function(e,n,r,o){return void 0===n&&(n=!0),null!=o&&o!==e.dtype&&(e=e.asType(o)),new t(e,n,r);},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(!arraysEqual(e.shape,this.shape))throw new Error("shape of the new value ("+e.shape+") and previous value ("+this.shape+") must match");trackerFn().disposeTensor(this),this.dataId=e.dataId,trackerFn().registerTensor(this);},t;}(Tensor);Object.defineProperty(Variable,Symbol.hasInstance,{value:function(e){return e instanceof Tensor&&null!=e.assign&&e.assign instanceof Function;}});var UpcastInt32AndMap,UpcastBoolAndMap,UpcastFloat32AndMap,UpcastComplex64AndMap,variable=Variable.variable;function getFilteredNodesXToY(e,t,n){for(var r={},o={},a=0;a<t.length;a++)r[t[a].id]=!0;for(a=0;a<e.length;a++){var i=(f=e[a]).inputs;for(var s in i){for(var u=i[s],l=!1,c=0;c<t.length;c++)if(r[u.id]){f.outputs.forEach(function(e){return r[e.id]=!0;}),l=!0,o[f.id]=!0;break;}if(l)break;}}var p={};p[n.id]=!0;var d={};for(a=e.length-1;a>=0;a--)for(i=(f=e[a]).inputs,c=0;c<f.outputs.length;c++)if(p[f.outputs[c].id]){for(var s in i)p[i[s].id]=!0,d[f.id]=!0;break;}var h=[];for(a=0;a<e.length;a++){var f;if(o[(f=e[a]).id]&&d[f.id]){var m={};for(var s in f.inputs){var g=f.inputs[s];r[g.id]&&(m[s]=g);}var v=Object.assign({},f);v.inputs=m,v.outputs=f.outputs,h.push(v);}}return h;}function backpropagateGradients(e,t){for(var n=function(n){var r=t[n],o=[];if(r.outputs.forEach(function(t){var n=e[t.id];if(null!=n)o.push(n);else{var r=Tensor.make(t.shape,{values:makeZerosTypedArray(t.size,t.dtype)},t.dtype);o.push(r);}}),null==r.gradient)throw new Error("Cannot compute gradient: gradient function not found for "+r.name+".");var a=r.gradient(1===r.outputs.length?o[0]:o);for(var i in r.inputs){if(!(i in a))throw new Error("Cannot backprop through input "+i+". Available gradients found: "+Object.keys(a)+".");var s=a[i]();if("float32"!==s.dtype)throw new Error("Error in gradient for op "+r.name+". The gradient of input "+i+" must have 'float32' dtype, but has '"+s.dtype+"'");var u=r.inputs[i];if(!arraysEqual(s.shape,u.shape))throw new Error("Error in gradient for op "+r.name+". The gradient of input '"+i+"' has shape '"+s.shape+"', which does not match the shape of the input '"+u.shape+"'");if(null==e[u.id])e[u.id]=s;else{var l=e[u.id];e[u.id]=l.add(s),l.dispose();}}},r=t.length-1;r>=0;r--)n(r);}!function(e){e.R0="R0",e.R1="R1",e.R2="R2",e.R3="R3",e.R4="R4",e.R5="R5",e.R6="R6";}(exports.Rank||(exports.Rank={})),function(e){e.float32="float32",e.int32="int32",e.bool="int32",e.complex64="complex64";}(UpcastInt32AndMap||(UpcastInt32AndMap={})),function(e){e.float32="float32",e.int32="int32",e.bool="bool",e.complex64="complex64";}(UpcastBoolAndMap||(UpcastBoolAndMap={})),function(e){e.float32="float32",e.int32="float32",e.bool="float32",e.complex64="complex64";}(UpcastFloat32AndMap||(UpcastFloat32AndMap={})),function(e){e.float32="complex64",e.int32="complex64",e.bool="complex64",e.complex64="complex64";}(UpcastComplex64AndMap||(UpcastComplex64AndMap={}));var upcastTypeMap={float32:UpcastFloat32AndMap,int32:UpcastInt32AndMap,bool:UpcastBoolAndMap,complex64:UpcastComplex64AndMap};function upcastType(e,t){if("string"===e||"string"===t){if("string"===e&&"string"===t)return"string";throw new Error("Can not upcast "+e+" with "+t);}return upcastTypeMap[e][t];}function sumOutType(e){return upcastType(e,"int32");}function makeTypesMatch(e,t){if(e.dtype===t.dtype)return[e,t];var n=upcastType(e.dtype,t.dtype);return[e.cast(n),t.cast(n)];}function assertTypesMatch(e,t){assert(e.dtype===t.dtype,"The dtypes of the first("+e.dtype+") and second("+t.dtype+") input must match");}function isTensorInList(e,t){for(var n=0;n<t.length;n++)if(t[n].id===e.id)return!0;return!1;}function getTensorsInContainer(e){var t=[];return walkTensorContainer(e,t,new Set()),t;}function walkTensorContainer(e,t,n){if(null!=e)if(e instanceof Tensor)t.push(e);else if(isIterable(e)){var r=e;for(var o in r){var a=r[o];n.has(a)||(n.add(a),walkTensorContainer(a,t,n));}}}function isIterable(e){return Array.isArray(e)||"object"==typeof e;}var Type,Engine=function(){function e(e,t,n){this.backend=e,this.safeMode=t,this.debugMode=n,this.registeredVariables={},this.nextTapeNodeId=0,this.numBytes=0,this.numTensors=0,this.numStringTensors=0,this.numDataBuffers=0,this.profiling=!1,this.gradientScopeCount=0,this.customGradientDepth=0,this.scopeStack=[],this.keepTensors=new Set(),this.tensorInfo=new WeakMap(),this.profiler=new Profiler(e),this.activeProfile={newBytes:0,newTensors:0,peakBytes:0,kernels:[],result:null};}return e.prototype.moveData=function(e){this.write(e,this.readSync(e));},e.prototype.tidy=function(e,t,n){var r=this;void 0===n&&(n=!1);var o,a=null;if(null==t){if("function"!=typeof e)throw new Error("Please provide a function to tidy()");t=e;}else{if("string"!=typeof e&&!(e instanceof String))throw new Error("When calling with two arguments, the first argument to tidy() must be a string");if("function"!=typeof t)throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");a=e;}return this.scopedRun(function(){return r.startScope(a,n);},function(){return r.endScope(o,n);},function(){return(o=t())instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),o;});},e.prototype.scopedRun=function(e,t,n){e();try{var r=n();return t(),r;}catch(e){throw t(),e;}},e.prototype.nextTensorId=function(){return e.nextTensorId++;},e.prototype.nextVariableId=function(){return e.nextVariableId++;},e.prototype.runKernel=function(e,t,n){var r,o=this,a=[],i=function(e){return a.push(e),e;},s=null!=this.activeScope?this.activeScope.name:"",u=this.numBytes,l=this.numTensors;if(this.scopedRun(function(){return o.customGradientDepth++;},function(){return o.customGradientDepth--;},function(){r=o.debugMode()?o.profiler.profileKernel(s,function(){return e(o.backend,i);}):e(o.backend,i);}),this.shouldRecord()){var c={id:this.nextTapeNodeId++,name:s,inputs:t,outputs:Array.isArray(r)?r:[r]};null!=n&&(c.gradient=function(e){return n(e,a);}),this.activeTape.push(c);}return this.profiling&&this.activeProfile.kernels.push({name:s,bytesAdded:this.numBytes-u,totalBytesSnapshot:this.numBytes,tensorsAdded:this.numTensors-l,totalTensorsSnapshot:this.numTensors,inputShapes:Object.keys(t).map(function(e){return t[e].shape;}),outputShape:Array.isArray(r)?r.map(function(e){return e.shape;}):r.shape}),r;},e.prototype.registerTensor=function(e){var t=this.tensorInfo.has(e.dataId)?this.tensorInfo.get(e.dataId).refCount:0;if(this.numTensors++,"string"===e.dtype&&this.numStringTensors++,0===t){this.numDataBuffers++;var n=0;"complex64"!==e.dtype&&"string"!==e.dtype&&(n=sizeFromShape(e.shape)*bytesPerElement(e.dtype)),this.tensorInfo.set(e.dataId,{backend:this.backend,dtype:e.dtype,shape:e.shape,bytes:n,refCount:0}),this.numBytes+=n,this.backend.register(e.dataId,e.shape,e.dtype);}this.tensorInfo.get(e.dataId).refCount++,e instanceof Variable||this.track(e);},e.prototype.registerVariable=function(e){if(null!=this.registeredVariables[e.name])throw new Error("Variable with name "+e.name+" was already registered");this.registeredVariables[e.name]=e;},e.prototype.disposeTensor=function(e){if(this.tensorInfo.has(e.dataId)){this.keepTensors.has(e.id)&&this.keepTensors.delete(e.id),this.numTensors--,"string"===e.dtype&&this.numStringTensors--;var t=this.tensorInfo.get(e.dataId);t.refCount<=1?("complex64"!==e.dtype&&(this.numBytes-=t.bytes),this.numDataBuffers--,t.backend.disposeData(e.dataId),this.tensorInfo.delete(e.dataId)):this.tensorInfo.get(e.dataId).refCount--;}},e.prototype.disposeVariables=function(){for(var e in this.registeredVariables){var t=this.registeredVariables[e];this.disposeTensor(t),delete this.registeredVariables[e];}},e.prototype.memory=function(){var e=this.backend.memory();return e.numTensors=this.numTensors,e.numDataBuffers=this.numDataBuffers,e.numBytes=this.numBytes,this.numStringTensors>0&&(e.unreliable=!0,null==e.reasons&&(e.reasons=[]),e.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")),e;},e.prototype.profile=function(e){return __awaiter(this,void 0,void 0,function(){var t,n;return __generator(this,function(r){return this.profiling=!0,t=this.numBytes,n=this.numTensors,this.activeProfile.kernels=[],this.activeProfile.result=e(),this.profiling=!1,this.activeProfile.peakBytes=Math.max.apply(Math,this.activeProfile.kernels.map(function(e){return e.totalBytesSnapshot;})),this.activeProfile.newBytes=this.numBytes-t,this.activeProfile.newTensors=this.numTensors-n,[2,this.activeProfile];});});},e.prototype.shouldRecord=function(){return null!=this.activeTape&&0===this.customGradientDepth;},e.prototype.addTapeNode=function(e,t,n){var r={};e.forEach(function(e,t){r[t]=e;});var o={id:this.nextTapeNodeId++,name:this.activeScope.name,inputs:r,outputs:[t],gradient:function(e){var t={};return n(e).forEach(function(e,n){t[n]=function(){return e;};}),t;}};this.activeTape.push(o);},e.prototype.keep=function(e){if(1===this.scopeStack.length&&this.safeMode)throw new Error("Safe mode is ON. Enclose all tensor operations inside tf.tidy(): tf.tidy(() => {...}) to avoid memory leaks.");return this.keepTensors.add(e.id),e;},e.prototype.startScope=function(e,t){void 0===t&&(t=!1),t&&0===this.gradientScopeCount&&(this.activeTape=[]),t&&this.gradientScopeCount++;var n={track:[],name:"unnamed scope"};e&&(n.name=e),this.scopeStack.push(n),this.activeScope=n;},e.prototype.endScope=function(e,t){var n=this;void 0===t&&(t=!1),t&&(this.gradientScopeCount--,0===this.gradientScopeCount&&(this.activeTape=null));var r=new Set(this.keepTensors),o=getTensorsInContainer(e);o.forEach(function(e){return r.add(e.id);});for(var a=0;a<this.activeScope.track.length;a++){var i=this.activeScope.track[a];r.has(i.id)||(null!=this.activeTape?o.push(i):i.dispose());}var s=this.scopeStack.pop();this.activeScope=0===this.scopeStack.length?null:this.scopeStack[this.scopeStack.length-1],o.forEach(function(e){!n.keepTensors.has(e.id)&&isTensorInList(e,s.track)&&n.track(e);});},e.prototype.gradients=function(e,t,n,r){var o=this;if(void 0===r&&(r=!1),assert(t.length>0,"gradients() received an empty list of xs."),null!=n&&"float32"!==n.dtype)throw new Error("dy must have 'float32' dtype, but has '"+n.dtype+"'");return this.tidy("gradients",function(){var a=e();assert(a instanceof Tensor,"The result y returned by f() must be a tensor.");var i=getFilteredNodesXToY(o.activeTape,t,a);if(!r&&0===i.length&&t.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.");var s={};return s[a.id]=null==n?ones(a.shape):n,backpropagateGradients(s,i),{value:a,grads:t.map(function(e){return s[e.id];})};},!0);},e.prototype.customGrad=function(e){var t=this;return assert(isFunction(e),"The f passed in customGrad(f) must be a function."),function(){for(var n,r,o=[],a=0;a<arguments.length;a++)o[a]=arguments[a];if(assert(o.every(function(e){return e instanceof Tensor;}),"The args passed in customGrad(f)(x1, x2,...) must all be tensors"),t.scopedRun(function(){return t.customGradientDepth++;},function(){return t.customGradientDepth--;},function(){r=t.tidy(e.name,function(){var t=e.apply(void 0,o),r=t.value,a=t.gradFunc;return assert(r instanceof Tensor,"The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"),assert(isFunction(a),"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."),n=a,r;},!0);}),t.shouldRecord()){t.addTapeNode(o,r,function(e){var t=n(e),r=Array.isArray(t)?t:[t];return assert(r.length===o.length,"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(...)."),assert(r.every(function(e){return e instanceof Tensor;}),"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors."),r;});}return r;};},e.prototype.write=function(e,t){var n=this.tensorInfo.get(e);if("string"===n.dtype){var r=bytesFromStringArray(t);this.numBytes+=r-n.bytes,n.bytes=r;}this.backend!==n.backend&&(n.backend.disposeData(e),n.backend=this.backend,this.backend.register(e,n.shape,n.dtype)),this.backend.write(e,t);},e.prototype.readSync=function(e){return this.tensorInfo.get(e).backend.readSync(e);},e.prototype.read=function(e){return this.tensorInfo.get(e).backend.read(e);},e.prototype.fromPixels=function(e,t){return this.backend.fromPixels(e,t);},e.prototype.time=function(e){return __awaiter(this,void 0,void 0,f