UNPKG

ml5

Version:

A friendly machine learning library for the web.

18 lines 1.99 MB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ml5=t():e.ml5=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var a=t[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=675)}([function(e,t,n){"use strict";(function(e,r,a,i){n.d(t,"Fc",function(){return vu}),n.d(t,"Ya",function(){return bu}),n.d(t,"Ga",function(){return wu}),n.d(t,"Gb",function(){return xu}),n.d(t,"Dd",function(){return ou}),n.d(t,"Tb",function(){return is}),n.d(t,"La",function(){return ge}),n.d(t,"hb",function(){return Zs}),n.d(t,"Ec",function(){return nu}),n.d(t,"nd",function(){return iu}),n.d(t,"yd",function(){return V}),n.d(t,"Ed",function(){return su}),n.d(t,"a",function(){return lu}),n.d(t,"b",function(){return cu}),n.d(t,"c",function(){return fu}),n.d(t,"d",function(){return pu}),n.d(t,"g",function(){return du}),n.d(t,"h",function(){return uu}),n.d(t,"i",function(){return mu}),n.d(t,"l",function(){return hu}),n.d(t,"m",function(){return Q}),n.d(t,"n",function(){return X}),n.d(t,"Bd",function(){return te}),n.d(t,"o",function(){return ee}),n.d(t,"j",function(){return gt}),n.d(t,"k",function(){return Co}),n.d(t,"e",function(){return me}),n.d(t,"f",function(){return de}),n.d(t,"gb",function(){return ts}),n.d(t,"ob",function(){return Yo}),n.d(t,"zb",function(){return Go}),n.d(t,"ac",function(){return Je}),n.d(t,"H",function(){return qa}),n.d(t,"I",function(){return $a}),n.d(t,"J",function(){return Ga}),n.d(t,"G",function(){return Ha}),n.d(t,"Q",function(){return Qe}),n.d(t,"qc",function(){return et}),n.d(t,"fb",function(){return tt}),n.d(t,"R",function(){return vr}),n.d(t,"S",function(){return br}),n.d(t,"T",function(){return wr}),n.d(t,"U",function(){return xr}),n.d(t,"V",function(){return _r}),n.d(t,"Sc",function(){return Sr}),n.d(t,"W",function(){return ii}),n.d(t,"X",function(){return oi}),n.d(t,"Ea",function(){return si}),n.d(t,"Dc",function(){return ui}),n.d(t,"Y",function(){return li}),n.d(t,"Ab",function(){return Qa}),n.d(t,"Ja",function(){return ei}),n.d(t,"bc",function(){return ti}),n.d(t,"uc",function(){return ci}),n.d(t,"vc",function(){return fi}),n.d(t,"wc",function(){return pi}),n.d(t,"xc",function(){return hi}),n.d(t,"yc",function(){return di}),n.d(t,"Cb",function(){return mi}),n.d(t,"E",function(){return gi}),n.d(t,"Kc",function(){return yi}),n.d(t,"Lc",function(){return vi}),n.d(t,"Mc",function(){return bi}),n.d(t,"Nc",function(){return wi}),n.d(t,"Oc",function(){return xi}),n.d(t,"p",function(){return fa}),n.d(t,"q",function(){return pa}),n.d(t,"r",function(){return ha}),n.d(t,"z",function(){return da}),n.d(t,"A",function(){return ma}),n.d(t,"B",function(){return ga}),n.d(t,"D",function(){return ya}),n.d(t,"N",function(){return va}),n.d(t,"O",function(){return ba}),n.d(t,"Z",function(){return wa}),n.d(t,"Aa",function(){return xa}),n.d(t,"Oa",function(){return _a}),n.d(t,"Pa",function(){return Sa}),n.d(t,"Ra",function(){return Ea}),n.d(t,"Ua",function(){return Na}),n.d(t,"rb",function(){return Oa}),n.d(t,"sb",function(){return ka}),n.d(t,"tb",function(){return Ia}),n.d(t,"Sb",function(){return Ca}),n.d(t,"rc",function(){return Aa}),n.d(t,"zc",function(){return Pa}),n.d(t,"Ac",function(){return Ta}),n.d(t,"Gc",function(){return Ma}),n.d(t,"Hc",function(){return Ra}),n.d(t,"Ic",function(){return Da}),n.d(t,"Jc",function(){return ja}),n.d(t,"Qc",function(){return La}),n.d(t,"Tc",function(){return za}),n.d(t,"Uc",function(){return Ba}),n.d(t,"Zc",function(){return Fa}),n.d(t,"ed",function(){return Va}),n.d(t,"fd",function(){return Ua}),n.d(t,"v",function(){return Si}),n.d(t,"w",function(){return Ei}),n.d(t,"x",function(){return Ni}),n.d(t,"y",function(){return Oi}),n.d(t,"ub",function(){return ki}),n.d(t,"Bb",function(){return Ii}),n.d(t,"Fb",function(){return Ci}),n.d(t,"Hb",function(){return Ai}),n.d(t,"Mb",function(){return Pi}),n.d(t,"dd",function(){return Ti}),n.d(t,"Ma",function(){return Mi}),n.d(t,"Na",function(){return Ri}),n.d(t,"bb",function(){return Di}),n.d(t,"cb",function(){return ji}),n.d(t,"db",function(){return Li}),n.d(t,"eb",function(){return zi}),n.d(t,"kb",function(){return Bi}),n.d(t,"lb",function(){return Fi}),n.d(t,"mb",function(){return Vi}),n.d(t,"nb",function(){return Ui}),n.d(t,"Vb",function(){return Wi}),n.d(t,"Wb",function(){return qi}),n.d(t,"s",function(){return $i}),n.d(t,"t",function(){return Gi}),n.d(t,"u",function(){return Hi}),n.d(t,"C",function(){return Ki}),n.d(t,"Ha",function(){return Xi}),n.d(t,"Ia",function(){return Yi}),n.d(t,"Va",function(){return Ji}),n.d(t,"Db",function(){return Zi}),n.d(t,"Eb",function(){return Qi}),n.d(t,"Ib",function(){return eo}),n.d(t,"Jb",function(){return to}),n.d(t,"Kb",function(){return no}),n.d(t,"Lb",function(){return ro}),n.d(t,"Ob",function(){return ao}),n.d(t,"Pb",function(){return io}),n.d(t,"hc",function(){return oo}),n.d(t,"ic",function(){return so}),n.d(t,"Vc",function(){return uo}),n.d(t,"Wc",function(){return lo}),n.d(t,"bd",function(){return co}),n.d(t,"cd",function(){return fo}),n.d(t,"Ka",function(){return bo}),n.d(t,"jb",function(){return wo}),n.d(t,"jc",function(){return xo}),n.d(t,"sc",function(){return _o}),n.d(t,"Cc",function(){return So}),n.d(t,"vb",function(){return po}),n.d(t,"wb",function(){return ho}),n.d(t,"xb",function(){return mo}),n.d(t,"yb",function(){return go}),n.d(t,"Fd",function(){return yo}),n.d(t,"Gd",function(){return vo}),n.d(t,"L",function(){return Dr}),n.d(t,"rd",function(){return Rr}),n.d(t,"kc",function(){return jr}),n.d(t,"K",function(){return Lr}),n.d(t,"M",function(){return zr}),n.d(t,"P",function(){return Br}),n.d(t,"Ba",function(){return Fr}),n.d(t,"Da",function(){return Vr}),n.d(t,"Qa",function(){return Ur}),n.d(t,"Sa",function(){return Wr}),n.d(t,"Wa",function(){return qr}),n.d(t,"Rb",function(){return $r}),n.d(t,"Xb",function(){return Gr}),n.d(t,"cc",function(){return Hr}),n.d(t,"dc",function(){return Kr}),n.d(t,"ec",function(){return Xr}),n.d(t,"fc",function(){return Yr}),n.d(t,"gc",function(){return Jr}),n.d(t,"mc",function(){return Zr}),n.d(t,"nc",function(){return Qr}),n.d(t,"oc",function(){return ea}),n.d(t,"tc",function(){return ta}),n.d(t,"Rc",function(){return na}),n.d(t,"Xc",function(){return ra}),n.d(t,"Yc",function(){return aa}),n.d(t,"pd",function(){return ia}),n.d(t,"vd",function(){return oa}),n.d(t,"xd",function(){return sa}),n.d(t,"Ta",function(){return pt}),n.d(t,"pb",function(){return ht}),n.d(t,"Yb",function(){return ct}),n.d(t,"pc",function(){return dt}),n.d(t,"Bc",function(){return rt}),n.d(t,"gd",function(){return nt}),n.d(t,"hd",function(){return at}),n.d(t,"id",function(){return it}),n.d(t,"jd",function(){return ot}),n.d(t,"kd",function(){return st}),n.d(t,"ld",function(){return ut}),n.d(t,"md",function(){return lt}),n.d(t,"Hd",function(){return ft}),n.d(t,"Zb",function(){return xt}),n.d(t,"Id",function(){return _t}),n.d(t,"ud",function(){return Eo}),n.d(t,"Pc",function(){return Ze}),n.d(t,"qb",function(){return No}),n.d(t,"Ub",function(){return Oo}),n.d(t,"Xa",function(){return Ao}),n.d(t,"wd",function(){return Po}),n.d(t,"F",function(){return To}),n.d(t,"Qb",function(){return Mo}),n.d(t,"Nb",function(){return Ro}),n.d(t,"ad",function(){return Do}),n.d(t,"sd",function(){return jo}),n.d(t,"td",function(){return yu}),n.d(t,"od",function(){return Ee}),n.d(t,"ib",function(){return Ne}),n.d(t,"Fa",function(){return Oe}),n.d(t,"qd",function(){return ke}),n.d(t,"lc",function(){return Ie}),n.d(t,"Ca",function(){return _e}),n.d(t,"Za",function(){return ye}),n.d(t,"ab",function(){return ve}),n.d(t,"zd",function(){return be}),n.d(t,"Ad",function(){return we}),n.d(t,"Cd",function(){return xe}); /** * @license * Copyright 2018 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 o=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])};function s(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var u=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e};function l(e,t,n,r){return new(n||(n=Promise))(function(a,i){function o(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){e.done?a(e.value):new n(function(t){t(e.value)}).then(o,s)}u((r=r.apply(e,t||[])).next())})}function c(e,t){var n,r,a,i,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(a=2&i[0]?r.return:i[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,i[1])).done)return a;switch(r=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,r=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!(a=(a=o.trys).length>0&&a[a.length-1])&&(6===i[0]||2===i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]<a[3])){o.label=i[1];break}if(6===i[0]&&o.label<a[1]){o.label=a[1],a=i;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(i);break}a[2]&&o.ops.pop(),o.trys.pop();continue}i=t.call(e,o)}catch(e){i=[6,e],r=0}finally{n=a=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function f(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 p(e,t,n){return Math.max(e,Math.min(t,n))}function h(e,t){var n=Math.random();return t*n+(1-n)*e}function d(e,t){if(!e)throw new Error("string"==typeof t?t:t())}function m(e,t,n){void 0===n&&(n=""),d(w(e,t),n+" Shapes "+e+" and "+t+" must match")}function g(e){d(null!=e,"The input to the tensor constructor must be a non-null value.")}function y(e,t){if(void 0===t&&(t=[]),Array.isArray(e))for(var n=0;n<e.length;++n)y(e[n],t);else t.push(e);return t}function v(e){var t=e;if(T(e))return[e.length];if(!Array.isArray(e))return[];for(var n=[];t instanceof Array;)n.push(t.length),t=t[0];return e instanceof Array&&function e(t,n,r){if(r=r||[],t instanceof Array){d(n.length>0,function(){return"Element arr["+r.join("][")+"] should be a primitive, but is an array of "+t.length+" elements"}),d(t.length===n[0],function(){return"Element arr["+r.join("][")+"] should have "+n[0]+" elements, but has "+t.length+" elements"});for(var a=n.slice(1),i=0;i<t.length;++i)e(t[i],a,r.concat(i))}else d(0===n.length,function(){return"Element arr["+r.join("][")+"] is a primitive, but should be an array of "+n[0]+" elements"})}(e,n,[]),n}function b(e){if(0===e.length)return 1;for(var t=e[0],n=1;n<e.length;n++)t*=e[n];return t}function w(e,t){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 x(e){return e%1==0}function _(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 S(e){for(var t=Math.floor(Math.sqrt(e));t>1;--t)if(e%t==0)return[t,e/t];return[1,e]}function E(e,t){return t<=e.length?e:e+" ".repeat(t-e.length)}function N(e,t,n){return void 0===t&&(t=function(e){return 0}),new Promise(function(r,a){var i=0,o=function(){if(e())r();else{var s=t(++i);null!=n&&i>=n?a():setTimeout(o,s)}};o()})}function O(e,t){for(var n=1,r=-1,a=0;a<e.length;++a)if(e[a]>=0)n*=e[a];else if(-1===e[a]){if(-1!==r)throw Error("Shapes can only have 1 implicit size. Found -1 at dim "+r+" and dim "+a);r=a}else if(e[a]<0)throw Error("Shapes can not be < 0. Found "+e[a]+" at dim "+a);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 i=e.slice();return i[r]=t/n,i}function k(e,t){for(var n=[],r=[],a=0,i=0;i<e.length;++i){if(null!=t){if(t[a]===i&&1!==e[i])throw new Error("Can't squeeze axis "+i+" since its dim '"+e[i]+"' is not 1");(null==t[a]||t[a]>i)&&1===e[i]&&(n.push(e[i]),r.push(i)),t[a]<=i&&a++}1!==e[i]&&(n.push(e[i]),r.push(i))}return{newShape:n,keptDims:r}}function I(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 C(e,t,n){if("float32"===t)for(var r=0;r<e.length;r++)if(isNaN(e[r]))throw Error("The result of the '"+n+"' has NaNs.")}function A(e,t){if("float32"!==t)for(var n=0;n<e.length;n++)if(isNaN(e[n]))throw Error("NaN is not a valid value for dtype: '"+t+"'.")}function P(e,t){return!("complex64"===t||"float32"===t&&"complex64"!==e||"int32"===t&&"float32"!==e&&"complex64"!==e||"bool"===t&&"bool"===e)}function T(e){return e instanceof Float32Array||e instanceof Int32Array||e instanceof Uint8Array}function M(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 R(e){return!!(e&&e.constructor&&e.call&&e.apply)}function D(e,t){for(var n=t;n<e;++n)if(e%n==0)return n;return e}function j(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 L(e,t,n){return function(e,t){return e instanceof Float32Array&&"float32"===t||e instanceof Int32Array&&"int32"===t||e instanceof Uint8Array&&"bool"===t}(e,t)?e:(Array.isArray(e)&&(e=y(e)),function(e,t,n){if(null==t||"float32"===t||"complex64"===t)return new Float32Array(e);if("int32"===t)return n&&A(e,t),new Int32Array(e);if("bool"===t){for(var r=new Uint8Array(e.length),a=0;a<r.length;++a)0!==Math.round(e[a])&&(r[a]=1);return r}throw new Error("Unknown data type "+t)}(e,t,n))}function z(e,t){for(var n=B(e,t),r=0;r<n.length;r++)n[r]=1;return n}function B(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 F(){if("undefined"!=typeof performance)return performance.now();if(void 0!==e){var t=e.hrtime();return 1e3*t[0]+t[1]/1e6}throw new Error("Cannot measure time in this environment. You should run tf.js in the browser or in Node.js")}var V=Object.freeze({shuffle:f,clamp:p,randUniform:h,distSquared:function(e,t){for(var n=0,r=0;r<e.length;r++){var a=Number(e[r])-Number(t[r]);n+=a*a}return n},assert:d,assertShapesMatch:m,assertNonNull:g,flatten:y,inferShape:v,sizeFromShape:b,isScalarShape:function(e){return 0===e.length},arraysEqual:w,isInt:x,tanh:_,sizeToSquarishShape:S,createShuffledIndices:function(e){for(var t=new Uint32Array(e),n=0;n<e;++n)t[n]=n;return f(t),t},rightPad:E,repeatedTry:N,inferFromImplicitShape:O,squeezeShape:k,getTypedArrayFromDType:I,checkComputationForNaN:C,checkConversionForNaN:A,hasEncodingLoss:P,isTypedArray:T,bytesPerElement:M,isFunction:R,nearestDivisor:D,computeStrides:j,toTypedArray:L,makeOnesTypedArray:z,makeZerosTypedArray:B,now:F}),U=function(){function e(e,t){this.backendTimer=e,this.logger=t,null==t&&(this.logger=new W)}return e.prototype.profileKernel=function(e,t){var n,r=this,a=this.backendTimer.time(function(){n=t()});return(Array.isArray(n)?n:[n]).forEach(function(t){var n=t.dataSync();C(n,t.dtype,e),a.then(function(a){r.logger.logKernelProfile(e,t,n,a.kernelMs)})}),n},e}(),W=function(){function e(){}return e.prototype.logKernelProfile=function(e,t,n,r){var a=E(r+"ms",9),i=E(e,25),o=t.rank,s=t.size,u=E(t.shape.toString(),14);console.log("%c"+i+"\t%c"+a+"\t%c"+o+"D "+u+"\t%c"+s,"font-weight:bold","color:red","color:blue","color: orange")},e}(),q=20,$=3,G=7;function H(e,t){return E(Array.isArray(e)?parseFloat(e[0].toFixed(G))+" + "+parseFloat(e[1].toFixed(G))+"j":parseFloat(e.toFixed(G)).toString(),t)}function K(e){for(var t=[],n=0;n<e.length;n+=2)t.push([e[n],e[n+1]]);return t}var X=function(){function e(e,t,n){if(this.dtype=t,this.shape=e.slice(),this.size=b(e),null!=n){var r=n.length;d(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||I(t,b(this.shape)),this.strides=j(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]),d(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 Q.make(this.shape,{values:this.values},this.dtype)},e}(),Y=null,J=null;function Z(e){Y=e}var Q=function(){function e(t,n,r,a){this.isDisposedInternal=!1,this.shape=t.slice(),this.dtype=n||"float32",this.size=b(t),null!=r&&d(this.size===r.length,"Based on the provided shape, ["+t+"], and dtype "+this.dtype+", the tensor should have "+this.size+" values but has "+r.length),this.strides=j(t),this.dataId=null!=a?a:{},this.id=e.nextId++,this.rankType=this.rank<5?this.rank.toString():"higher",Y().registerTensor(this),null!=r&&Y().write(this.dataId,r)}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(),d(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.asType=function(e){return this.throwIfDisposed(),J.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];d(e.length===this.rank,"Number of coordinates in get() must match the rank of the tensor"),d("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 J.buffer(this.shape,this.dtype,this.dataSync())},e.prototype.data=function(){return l(this,void 0,void 0,function(){return c(this,function(e){return this.throwIfDisposed(),[2,Y().read(this.dataId)]})})},e.prototype.dataSync=function(){return this.throwIfDisposed(),Y().readSync(this.dataId)},e.prototype.dispose=function(){this.isDisposed||(Y().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),J.print(this,e)},e.prototype.reshape=function(e){return this.throwIfDisposed(),J.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),J.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),J.cumsum(this,e,t,n)},e.prototype.squeeze=function(e){return this.throwIfDisposed(),J.squeeze(this,e)},e.prototype.clone=function(){return this.throwIfDisposed(),J.clone(this)},e.prototype.toString=function(e){return void 0===e&&(e=!1),function(e,t,n,r){var a=j(t),i=function(e,t,n,r){var a=b(t),i=r[r.length-1],o=new Array(i).fill(0),s=t.length,u="complex64"===n?K(e):e;if(s>1)for(var l=0;l<a/i;l++)for(var c=l*i,f=0;f<i;f++)o[f]=Math.max(o[f],H(u[c+f],0).length);return o}(e,t,n,a),o=t.length,s=function e(t,n,r,a,i,o){void 0===o&&(o=!0);var s="complex64"===r?2:1,u=n[0],l=n.length;if(0===l)return"complex64"===r?[H(K(t)[0],0)]:[t[0].toString()];if(1===l){if(u>q){var c=$*s,f=Array.from(t.subarray(0,c)),p=Array.from(t.subarray(u-$*s,u));return"complex64"===r&&(f=K(f),p=K(p)),["["+f.map(function(e,t){return H(e,i[t])}).join(", ")+", ..., "+p.map(function(e,t){return H(e,i[u-$+t])}).join(", ")+"]"]}return["["+("complex64"===r?K(t):Array.from(t)).map(function(e,t){return H(e,i[t])}).join(", ")+"]"]}var h=n.slice(1),d=a.slice(1),m=a[0]*s,g=[];if(u>q){for(var y=0;y<$;y++){var v=(b=y*m)+m;g.push.apply(g,e(t.subarray(b,v),h,r,d,i,!1))}for(g.push("..."),y=u-$;y<u;y++)v=(b=y*m)+m,g.push.apply(g,e(t.subarray(b,v),h,r,d,i,y===u-1))}else for(y=0;y<u;y++){var b;v=(b=y*m)+m,g.push.apply(g,e(t.subarray(b,v),h,r,d,i,y===u-1))}var w=2===l?",":"";for(g[0]="["+g[0]+w,y=1;y<g.length-1;y++)g[y]=" "+g[y]+w;var x=",\n";for(y=2;y<l;y++)x+="\n";return g[g.length-1]=" "+g[g.length-1]+"]"+(o?"":x),g}(e,t,n,a,i),u=["Tensor"];return r&&(u.push(" dtype: "+n),u.push(" rank: "+o),u.push(" shape: ["+t+"]"),u.push(" values:")),u.push(s.map(function(e){return" "+e}).join("\n")),u.join("\n")}(this.dataSync(),this.shape,this.dtype,e)},e.prototype.tile=function(e){return this.throwIfDisposed(),J.tile(this,e)},e.prototype.gather=function(e,t){return void 0===t&&(t=0),this.throwIfDisposed(),J.gather(this,e,t)},e.prototype.matMul=function(e,t,n){return void 0===t&&(t=!1),void 0===n&&(n=!1),this.throwIfDisposed(),J.matMul(this,e,t,n)},e.prototype.dot=function(e){return this.throwIfDisposed(),J.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(),J.norm(this,e,t,n)},e.prototype.slice=function(e,t){return this.throwIfDisposed(),J.slice(this,e,t)},e.prototype.reverse=function(e){return this.throwIfDisposed(),J.reverse(this,e)},e.prototype.concat=function(e,t){return void 0===t&&(t=0),this.throwIfDisposed(),J.concat([this,e],t)},e.prototype.split=function(e,t){return void 0===t&&(t=0),this.throwIfDisposed(),J.split(this,e,t)},e.prototype.stack=function(e,t){return void 0===t&&(t=0),J.stack([this,e],t)},e.prototype.unstack=function(e,t){return void 0===t&&(t=0),J.unstack(this,t)},e.prototype.pad=function(e,t){return void 0===t&&(t=0),J.pad(this,e,t)},e.prototype.batchNormalization=function(e,t,n,r,a){return void 0===n&&(n=.001),this.throwIfDisposed(),J.batchNormalization(this,e,t,n,r,a)},e.prototype.all=function(e,t){return void 0===e&&(e=null),void 0===t&&(t=!1),this.throwIfDisposed(),J.all(this,e,t)},e.prototype.any=function(e,t){return void 0===e&&(e=null),void 0===t&&(t=!1),this.throwIfDisposed(),J.any(this,e,t)},e.prototype.logSumExp=function(e,t){return void 0===e&&(e=null),void 0===t&&(t=!1),this.throwIfDisposed(),J.logSumExp(this,e,t)},e.prototype.sum=function(e,t){return void 0===e&&(e=null),void 0===t&&(t=!1),this.throwIfDisposed(),J.sum(this,e,t)},e.prototype.mean=function(e,t){return void 0===e&&(e=null),void 0===t&&(t=!1),this.throwIfDisposed(),J.mean(this,e,t)},e.prototype.min=function(e,t){return void 0===e&&(e=null),void 0===t&&(t=!1),this.throwIfDisposed(),J.min(this,e,t)},e.prototype.max=function(e,t){return void 0===e&&(e=null),void 0===t&&(t=!1),this.throwIfDisposed(),J.max(this,e,t)},e.prototype.argMin=function(e){return void 0===e&&(e=null),this.throwIfDisposed(),J.argMin(this,e)},e.prototype.argMax=function(e){return void 0===e&&(e=null),this.throwIfDisposed(),J.argMax(this,e)},e.prototype.cast=function(e){return this.throwIfDisposed(),J.cast(this,e)},e.prototype.add=function(e){return this.throwIfDisposed(),J.add(this,e)},e.prototype.addStrict=function(e){return this.throwIfDisposed(),J.addStrict(this,e)},e.prototype.atan2=function(e){return this.throwIfDisposed(),J.atan2(this,e)},e.prototype.sub=function(e){return this.throwIfDisposed(),J.sub(this,e)},e.prototype.subStrict=function(e){return this.throwIfDisposed(),J.subStrict(this,e)},e.prototype.pow=function(e){return this.throwIfDisposed(),J.pow(this,e)},e.prototype.powStrict=function(e){return this.throwIfDisposed(),J.powStrict(this,e)},e.prototype.mul=function(e){return this.throwIfDisposed(),J.mul(this,e)},e.prototype.mulStrict=function(e){return this.throwIfDisposed(),J.mulStrict(this,e)},e.prototype.div=function(e){return this.throwIfDisposed(),J.div(this,e)},e.prototype.floorDiv=function(e){return this.throwIfDisposed(),J.floorDiv(this,e)},e.prototype.divStrict=function(e){return this.throwIfDisposed(),J.divStrict(this,e)},e.prototype.minimum=function(e){return this.throwIfDisposed(),J.minimum(this,e)},e.prototype.minimumStrict=function(e){return this.throwIfDisposed(),J.minimumStrict(this,e)},e.prototype.maximum=function(e){return this.throwIfDisposed(),J.maximum(this,e)},e.prototype.maximumStrict=function(e){return this.throwIfDisposed(),J.maximumStrict(this,e)},e.prototype.mod=function(e){return this.throwIfDisposed(),J.mod(this,e)},e.prototype.modStrict=function(e){return this.throwIfDisposed(),J.modStrict(this,e)},e.prototype.squaredDifference=function(e){return this.throwIfDisposed(),J.squaredDifference(this,e)},e.prototype.squaredDifferenceStrict=function(e){return this.throwIfDisposed(),J.squaredDifferenceStrict(this,e)},e.prototype.transpose=function(e){return this.throwIfDisposed(),J.transpose(this,e)},e.prototype.notEqual=function(e){return this.throwIfDisposed(),J.notEqual(this,e)},e.prototype.notEqualStrict=function(e){return this.throwIfDisposed(),J.notEqualStrict(this,e)},e.prototype.less=function(e){return this.throwIfDisposed(),J.less(this,e)},e.prototype.lessStrict=function(e){return this.throwIfDisposed(),J.lessStrict(this,e)},e.prototype.equal=function(e){return this.throwIfDisposed(),J.equal(this,e)},e.prototype.equalStrict=function(e){return this.throwIfDisposed(),J.equalStrict(this,e)},e.prototype.lessEqual=function(e){return this.throwIfDisposed(),J.lessEqual(this,e)},e.prototype.lessEqualStrict=function(e){return this.throwIfDisposed(),J.lessEqualStrict(this,e)},e.prototype.greater=function(e){return this.throwIfDisposed(),J.greater(this,e)},e.prototype.greaterStrict=function(e){return this.throwIfDisposed(),J.greaterStrict(this,e)},e.prototype.greaterEqual=function(e){return this.throwIfDisposed(),J.greaterEqual(this,e)},e.prototype.greaterEqualStrict=function(e){return this.throwIfDisposed(),J.greaterEqualStrict(this,e)},e.prototype.logicalAnd=function(e){return this.throwIfDisposed(),J.logicalAnd(this,e)},e.prototype.logicalOr=function(e){return this.throwIfDisposed(),J.logicalOr(this,e)},e.prototype.logicalNot=function(){return this.throwIfDisposed(),J.logicalNot(this)},e.prototype.logicalXor=function(e){return this.throwIfDisposed(),J.logicalXor(this,e)},e.prototype.where=function(e,t){return this.throwIfDisposed(),J.where(e,this,t)},e.prototype.neg=function(){return this.throwIfDisposed(),J.neg(this)},e.prototype.ceil=function(){return this.throwIfDisposed(),J.ceil(this)},e.prototype.floor=function(){return this.throwIfDisposed(),J.floor(this)},e.prototype.sign=function(){return this.throwIfDisposed(),J.sign(this)},e.prototype.exp=function(){return this.throwIfDisposed(),J.exp(this)},e.prototype.expm1=function(){return this.throwIfDisposed(),J.expm1(this)},e.prototype.log=function(){return this.throwIfDisposed(),J.log(this)},e.prototype.log1p=function(){return this.throwIfDisposed(),J.log1p(this)},e.prototype.sqrt=function(){return this.throwIfDisposed(),J.sqrt(this)},e.prototype.rsqrt=function(){return this.throwIfDisposed(),J.rsqrt(this)},e.prototype.square=function(){return this.throwIfDisposed(),J.square(this)},e.prototype.reciprocal=function(){return this.throwIfDisposed(),J.reciprocal(this)},e.prototype.abs=function(){return this.throwIfDisposed(),J.abs(this)},e.prototype.clipByValue=function(e,t){return this.throwIfDisposed(),J.clipByValue(this,e,t)},e.prototype.relu=function(){return this.throwIfDisposed(),J.relu(this)},e.prototype.elu=function(){return this.throwIfDisposed(),J.elu(this)},e.prototype.selu=function(){return this.throwIfDisposed(),J.selu(this)},e.prototype.leakyRelu=function(e){return void 0===e&&(e=.2),this.throwIfDisposed(),J.leakyRelu(this,e)},e.prototype.prelu=function(e){return this.throwIfDisposed(),J.prelu(this,e)},e.prototype.sigmoid=function(){return this.throwIfDisposed(),J.sigmoid(this)},e.prototype.logSigmoid=function(){return this.throwIfDisposed(),J.logSigmoid(this)},e.prototype.softplus=function(){return this.throwIfDisposed(),J.softplus(this)},e.prototype.zerosLike=function(){return this.throwIfDisposed(),J.zerosLike(this)},e.prototype.onesLike=function(){return this.throwIfDisposed(),J.onesLike(this)},e.prototype.sin=function(){return this.throwIfDisposed(),J.sin(this)},e.prototype.cos=function(){return this.throwIfDisposed(),J.cos(this)},e.prototype.tan=function(){return this.throwIfDisposed(),J.tan(this)},e.prototype.asin=function(){return this.throwIfDisposed(),J.asin(this)},e.prototype.acos=function(){return this.throwIfDisposed(),J.acos(this)},e.prototype.atan=function(){return this.throwIfDisposed(),J.atan(this)},e.prototype.sinh=function(){return this.throwIfDisposed(),J.sinh(this)},e.prototype.cosh=function(){return this.throwIfDisposed(),J.cosh(this)},e.prototype.tanh=function(){return this.throwIfDisposed(),J.tanh(this)},e.prototype.asinh=function(){return this.throwIfDisposed(),J.asinh(this)},e.prototype.acosh=function(){return this.throwIfDisposed(),J.acosh(this)},e.prototype.atanh=function(){return this.throwIfDisposed(),J.atanh(this)},e.prototype.erf=function(){return this.throwIfDisposed(),J.erf(this)},e.prototype.round=function(){return this.throwIfDisposed(),J.round(this)},e.prototype.step=function(e){return void 0===e&&(e=0),this.throwIfDisposed(),J.step(this,e)},e.prototype.softmax=function(e){return void 0===e&&(e=-1),this.throwIfDisposed(),J.softmax(this,e)},e.prototype.resizeBilinear=function(e,t){return void 0===t&&(t=!1),this.throwIfDisposed(),J.image.resizeBilinear(this,e,t)},e.prototype.resizeNearestNeighbor=function(e,t){return void 0===t&&(t=!1),this.throwIfDisposed(),J.image.resizeNearestNeighbor(this,e,t)},e.prototype.conv1d=function(e,t,n,r,a,i){return void 0===r&&(r="NWC"),void 0===a&&(a=1),this.throwIfDisposed(),J.conv1d(this,e,t,n,r,a,i)},e.prototype.conv2d=function(e,t,n,r,a,i){return void 0===r&&(r="NHWC"),void 0===a&&(a=[1,1]),this.throwIfDisposed(),J.conv2d(this,e,t,n,r,a,i)},e.prototype.conv2dTranspose=function(e,t,n,r,a){return this.throwIfDisposed(),J.conv2dTranspose(this,e,t,n,r,a)},e.prototype.depthwiseConv2D=function(e,t,n,r,a,i){return void 0===r&&(r="NHWC"),void 0===a&&(a=[1,1]),this.throwIfDisposed(),J.depthwiseConv2d(this,e,t,n,r,a,i)},e.prototype.separableConv2d=function(e,t,n,r,a,i){return void 0===a&&(a=[1,1]),void 0===i&&(i="NHWC"),this.throwIfDisposed(),J.separableConv2d(this,e,t,n,r,a,i)},e.prototype.avgPool=function(e,t,n,r){return this.throwIfDisposed(),J.avgPool(this,e,t,n,r)},e.prototype.maxPool=function(e,t,n,r){return this.throwIfDisposed(),J.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),J.localResponseNormalization(this,e,t,n,r)},e.prototype.variable=function(e,t,n){return void 0===e&&(e=!0),this.throwIfDisposed(),ee.variable(this,e,t,n)},e.prototype.unsortedSegmentSum=function(e,t){return this.throwIfDisposed(),J.unsortedSegmentSum(this,e,t)},e.prototype.batchToSpaceND=function(e,t){return this.throwIfDisposed(),J.batchToSpaceND(this,e,t)},e.prototype.spaceToBatchND=function(e,t){return this.throwIfDisposed(),J.spaceToBatchND(this,e,t)},e.prototype.topk=function(e,t){return void 0===e&&(e=1),void 0===t&&(t=!0),this.throwIfDisposed(),J.topk(this,e,t)},e.prototype.stridedSlice=function(e,t,n,r,a){return void 0===r&&(r=0),void 0===a&&(a=0),this.throwIfDisposed(),J.stridedSlice(this,e,t,n,r,a)},e.prototype.depthToSpace=function(e,t){return this.throwIfDisposed(),J.depthToSpace(this,e,t)},e.nextId=0,e}();Object.defineProperty(Q,Symbol.hasInstance,{value:function(e){return!!e&&null!=e.shape&&null!=e.dtype}});var ee=function(e){function t(n,r,a){void 0===r&&(r=!0);var i=e.call(this,n.shape,n.dtype,null,n.dataId)||this;i.trainable=r,i.name=a,null==i.name&&(i.name=t.nextVarId.toString(),t.nextVarId++);try{Y().registerVariable(i)}catch(e){throw Y().disposeTensor(i),e}return i}return s(t,e),t.variable=function(e,n,r,a){return void 0===n&&(n=!0),null!=a&&a!==e.dtype&&(e=e.asType(a)),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(!w(e.shape,this.shape))throw new Error("shape of the new value ("+e.shape+") and previous value ("+this.shape+") must match");Y().disposeTensor(this),this.dataId=e.dataId,Y().registerTensor(this)},t.nextVarId=0,t}(Q);Object.defineProperty(ee,Symbol.hasInstance,{value:function(e){return e instanceof Q&&null!=e.assign&&e.assign instanceof Function}});var te=ee.variable;function ne(e,t){d(e.dtype===t.dtype,"The dtypes of the first("+e.dtype+") and second("+t.dtype+") input must match")}function re(e){var t=[];return function e(t,n,r){if(null!=t)if(t instanceof Q)n.push(t);else if(function(e){return Array.isArray(e)||"object"==typeof e}(t)){var a=t;for(var i in a){var o=a[i];r.has(o)||(r.add(o),e(o,n,r))}}}(e,t,new Set),t}var ae,ie=function(){function e(e,t,n){this.backend=e,this.safeMode=t,this.debugMode=n,this.registeredVariables={},this.refCounter=new WeakMap,this.nextTapeNodeId=0,this.numBytes=0,this.numTensors=0,this.numDataBuffers=0,this.profiling=!1,this.gradientScopeCount=0,this.customGradientDepth=0,this.keepTensors=new Set,this.activeScope={track:[],name:"default scope"},this.scopeStack=[this.activeScope],this.profiler=new U(e),this.activeProfile={newBytes:0,newTensors:0,peakBytes:0,kernels:[],result:null}}return e.prototype.tidy=function(e,t,n){var r=this;void 0===n&&(n=!1);var a,i=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");i=e}return this.scopedRun(function(){return r.startScope(i,n)},function(){return r.endScope(a,n)},function(){return(a=t())instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),a})},e.prototype.scopedRun=function(e,t,n){e();try{var r=n();return t(),r}catch(e){throw t(),e}},e.prototype.runKernel=function(e,t,n){var r,a=this,i=[],o=function(e){return i.push(e),e},s=this.activeScope.name,u=this.numBytes,l=this.numTensors;if(this.scopedRun(function(){return a.customGradientDepth++},function(){return a.customGradientDepth--},function(){r=a.debugMode()?a.profiler.profileKernel(s,function(){return e(a.backend,o)}):e(a.backend,o)}),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,i)}),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.refCounter.has(e.dataId)?this.refCounter.get(e.dataId):0;this.numTensors++,0===t&&(this.numDataBuffers++,"complex64"!==e.dtype&&(this.numBytes+=b(e.shape)*M(e.dtype)),this.backend.register(e.dataId,e.shape,e.dtype)),this.refCounter.set(e.dataId,t+1),e instanceof ee||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.refCounter.has(e.dataId)){this.keepTensors.has(e.id)&&this.keepTensors.delete(e.id),this.numTensors--;var t=this.refCounter.get(e.dataId);t<=1?(this.refCounter.delete(e.dataId),this.backend.disposeData(e.dataId),this.numDataBuffers--,"complex64"!==e.dtype&&(this.numBytes-=b(e.shape)*M(e.dtype))):this.refCounter.set(e.dataId,t-1)}},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,e},e.prototype.profile=function(e){return l(this,void 0,void 0,function(){var t,n;return c(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 a={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(a)},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),a=re(e);a.forEach(function(e){return r.add(e.id)});for(var i=0;i<this.activeScope.track.length;i++){var o=this.activeScope.track[i];r.has(o.id)||(null!=this.activeTape?a.push(o):o.dispose())}var s=this.scopeStack.pop();this.activeScope=0===this.scopeStack.length?{track:[],name:"default scope"}:this.scopeStack[this.scopeStack.length-1],a.forEach(function(e){!n.keepTensors.has(e.id)&&function(e,t){for(var n=0;n<t.length;n++)if(t[n].id===e.id)return!0;return!1}(e,s.track)&&n.track(e)})},e.prototype.gradients=function(e,t,n,r){var a=this;return void 0===r&&(r=!1),d(t.length>0,"gradients() received an empty list of xs."),this.tidy("gradients",function(){var i=e();d(i instanceof Q,"The result y returned by f() must be a tensor.");var o=function(e,t,n){for(var r={},a={},i=0;i<t.length;i++)r[t[i].id]=!0;for(i=0;i<e.length;i++){var o=(d=e[i]).inputs;for(var s in o){for(var u=o[s],l=!1,c=0;c<t.length;c++)if(r[u.id]){d.outputs.forEach(function(e){return r[e.id]=!0}),l=!0,a[d.id]=!0;break}if(l)break}}var f={};f[n.id]=!0;var p={};for(i=e.length-1;i>=0;i--)for(o=(d=e[i]).inputs,c=0;c<d.outputs.length;c++)if(f[d.outputs[c].id]){for(var s in o)f[o[s].id]=!0,p[d.id]=!0;break}var h=[];for(i=0;i<e.length;i++){var d;if(a[(d=e[i]).id]&&p[d.id]){var m={};for(var s in d.inputs){var g=d.inputs[s];r[g.id]&&(m[s]=g)}var y=Object.assign({},d);y.inputs=m,y.outputs=d.outputs,h.push(y)}}return h}(a.activeTape,t,i);if(!r&&0===o.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[i.id]=null==n?function(e){var t=z(b(e),"float32");return Q.make(e,{values:t})}(i.shape):n,function(e,t){for(var n=function(n){var r=t[n],a=[];if(r.outputs.forEach(function(t){var n=e[t.id];if(null!=n)a.push(n);else{var r=Q.make(t.shape,{values:B(t.size,t.dtype)},t.dtype);a.push(r)}}),null==r.gradient)throw new Error("Cannot compute gradient: gradient function not found for "+r.name+".");var i=r.gradient(1===r.outputs.length?a[0]:a);for(var o in r.inputs){if(!(o in i))throw new Error("Cannot backprop through input "+o+". Available gradients found: "+Object.keys(i)+".");var s=i[o](),u=r.inputs[o];if(!w(s.shape,u.shape))throw new Error("Error in gradient for op "+r.name+". The gradient of input '"+o+"' 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)}(s,o),{value:i,grads:t.map(function(e){return s[e.id]})}},!0)},e.prototype.customGrad=function(e){var t=this;return d(R(e),"The f passed in customGrad(f) must be a function."),function(){for(var n,r,a=[],i=0;i<arguments.length;i++)a[i]=arguments[i];return d(a.every(function(e){return e instanceof Q}),"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,a),r=t.value,i=t.gradFunc;return d(r instanceof Q,"The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"),d(R(i),"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."),n=i,r},!0)}),t.shouldRecord()&&t.addTapeNode(a,r,function(e){var t=n(e),r=Array.isArray(t)?t:[t];return d(r.length===a.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(...)."),d(r.every(function(e){return e instanceof Q}),"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}),r}},e.prototype.write=function(e,t){this.backend.write(e,t)},e.prototype.readSync=function(e){return this.backend.readSync(e)},e.prototype.read=function(e){return this.backend.read(e)},e.prototype.fromPixels=function(e,t){return this.backend.fromPixels(e,t)},e.prototype.time=function(e){return l(this,void 0,void 0,function(){var t,n;return c(this,function(r){switch(r.label){case 0:return t=F(),[4,this.backend.time(e)];case 1:return(n=r.sent()).wallMs=F()-t,[2,n]}})})},e.prototype.track=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(() => {op();...}); to avoid memory leaks.");return this.activeScope.track.push(e),e},e}();!function(e){e[e.NUMBER=0]="NUMBER",e[e.BOOLEAN=1]="BOOLEAN",e[e.STRING=2]="STRING"}(ae||(ae={}));var oe=[{name:"DEBUG",type:ae.BOOLEAN},{name:"IS_BROWSER",type:ae.BOOLEAN},{name:"WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION",type:ae.NUMBER},{name:"WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE",type:ae.BOOLEAN},{name:"WEBGL_VERSION",type:ae.NUMBER},{name:"WEBGL_RENDER_FLOAT32_ENABLED",type:ae.BOOLEAN},{name:"WEBGL_DOWNLOAD_FLOAT_ENABLED",type:ae.BOOLEAN},{name:"WEBGL_FENCE_API_ENABLED",type:ae.BOOLEAN},{name:"BACKEND",type:ae.STRING},{name:"EPSILON",type:ae.NUMBER}];function se(e,t){var n;try{n=fe(e,t)}catch(e){return!1}return null!=n&&(pe(n),!0)}var ue="tfjsflags";function le(){var e={};if("undefined"==typeof window||void 0===window.location)return e;var t=function(e){var t={};return window.location.search.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return function(e,t,n){e[decodeURIComponent(t)]=decodeURIComponent(n||"")}(t,n[0],n[1]),n.join("=")}),t}();if(ue in t){var n={};t[ue].split(",").forEach(function(e){var t=e.split(":"),r=t[0],a=t[1];n[r]=a}),oe.forEach(function(t){t.name in n&&(console.log("Setting feature override from URL "+t.name+": "+n[t.name]),t.type===ae.NUMBER?e[t.name]=+n[t.name]:t.type===ae.BOOLEAN?e[t.name]="true"===n[t.name]:t.type===ae.STRING?e[t.name]=n[t.name]:console.warn("Unknown URL param: "+t.name+"."))})}return e}function ce(e,t){return null!=e.getExtension(t)}function fe(e,t){if(0===e||!t)throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");var n=document.createElement("canvas");return 1===e?n.getContext("webgl")||n.getContext("experimental-webgl"):n.getContext("webgl2")}function pe(e){if(null!=e){var t=e.getExtension("WEBGL_lose_context");if(null==t)throw new Error("Extension WEBGL_lose_context not supported on this browser.");t.loseContext()}}function he(e,t){var n=e.createFramebuffer(),r=e.createTexture();e.bindTexture(e.TEXTURE_2D,r);var a=2===t?e.RGBA32F:e.RGBA;e.texImage2D(e.TEXTURE_2D,0,a,1,1,0,e.RGBA,e.FLOAT,null),e.bindFramebuffer(e.FRAMEBUFFER,n),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,r,0);var i=e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE;return e.bindTexture(e.TEXTURE_2D,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteTexture(r),e.deleteFramebuffer(n),i}var de=function(){function t(e){this.features={},this.engines={},this.registry={},null!=e&&(this.features=e),this.get("DEBUG")&&console.warn("Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.")}return t.setBackend=function(e,t){if(void 0===t&&(t=!1),!(e in me.registry))throw new Error("Backend name '"+e+"' not found in registry");me.initBackend(e,t)},t.getBackend=function(){return me.initDefaultBackend(),me.backendName},t.disposeVariables=function(){me.engine.disposeVariables()},t.memory=function(){return me.engine.memory()},t.profile=function(e){return me.engine.profile(e)},t.tidy=function(e,t,n){return void 0===n&&(n=!1),me.engine.tidy(e,t,n)},t.dispose=function(e){re(e).forEach(function(e){return e.dispose()})},t.keep=function(e){return me.engine.keep(e)},t.time=function(e){return me.engine.time(e)},t.prototype.get=function(e){return e in this.features?this.features[e]:(this.features[e]=this.evaluateFeature(e),this.features[e])},t.prototype.getFeatures=function(){return this.features},t.prototype.set=function(e,t){this.features[e]=t},t.prototype.getBestBackendName=function(){var e=this;if(0===Object.keys(this.registry).length)throw new Error("No backend found in registry.");return Object.keys(this.registry).map(function(t){return{name:t,entry:e.registry[t]}}).sort(function(e,t){return t.entry.priority-e.entry.priority})[0].name},t.prototype.evaluateFeature=function(t){if("DEBUG"===t)return!1;if("IS_BROWSER"===t)return"undefined"!=typeof window;if("IS_NODE"===t)return void 0!==e&&void 0!==e.versions.node;if("IS_CHROME"===t)return"undefined"!=typeof navigator&&null!=navigator&&null!=navigator.userAgent&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);if("IS_TEST"===t)return!1;if("BACKEND"===t)return this.getBestBackendName();if("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"===t){var n=this.get("WEBGL_VERSION");return 0===n?0:n>0?0:function(e,t){if(0===e)return 0;var n,r=fe(e,t);return n=ce(r,"EXT_disjoint_timer_query_webgl2")&&2===e?2:ce(r,"EXT_disjoint_timer_query")?1:0,null!=r&&pe(r),n}(n,this.get("IS_BROWSER"))}if("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE"===t)return this.get("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0&&!function(){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