UNPKG

@tensorflow-models/coco-ssd

Version:

Object detection model (coco-ssd) in TensorFlow.js

17 lines 461 kB
/** * @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. * ============================================================================= */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.tf=t.tf||{})}(this,function(t){"use strict";var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,n)};function n(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r=function(){return(r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function o(t,e,n,r){return new(n||(n=Promise))(function(o,a){function i(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(i,s)}u((r=r.apply(t,e||[])).next())})}function a(t,e){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=e.call(t,i)}catch(t){a=[6,t],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 i={},s={alpha:!1,antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,depth:!1,stencil:!1,failIfMajorPerformanceCaveat:!0};function u(t){t in i||(i[t]=function(t){if(1!==t&&2!==t)throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");var e=document.createElement("canvas");if(e.addEventListener("webglcontextlost",function(e){e.preventDefault(),delete i[t]},!1),1===t)return e.getContext("webgl",s)||e.getContext("experimental-webgl",s);return e.getContext("webgl2",s)}(t));var e=i[t];return e.isContextLost()?(delete i[t],u(t)):(e.disable(e.DEPTH_TEST),e.disable(e.STENCIL_TEST),e.disable(e.BLEND),e.disable(e.DITHER),e.disable(e.POLYGON_OFFSET_FILL),e.disable(e.SAMPLE_COVERAGE),e.enable(e.SCISSOR_TEST),e.enable(e.CULL_FACE),e.cullFace(e.BACK),i[t])}function l(t){for(var e=t.length,n=0,r=0;e>0;)r=Math.random()*e|0,n=t[--e],t[e]=t[r],t[r]=n}function c(t,e,n){return Math.max(t,Math.min(e,n))}function h(t){return t%2==0?t:t+1}function p(t){for(var e=0,n=0;n<t.length;n++)e+=t[n];return e}function f(t,e){var n=Math.random();return e*n+(1-n)*t}function d(t,e){if(!t)throw new Error("string"==typeof e?e:e())}function m(t,e,n){void 0===n&&(n=""),d(x(t,e),n+" Shapes "+t+" and "+e+" must match")}function v(t){d(null!=t,"The input to the tensor constructor must be a non-null value.")}function g(t,e){if(void 0===e&&(e=[]),null==e&&(e=[]),Array.isArray(t)||_(t))for(var n=0;n<t.length;++n)g(t[n],e);else e.push(t);return e}function y(t){if(0===t.length)return 1;for(var e=t[0],n=1;n<t.length;n++)e*=t[n];return e}function x(t,e){if(t===e)return!0;if(null==t||null==e)return!1;if(t.length!==e.length)return!1;for(var n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function w(t){return t%1==0}function b(t){if(null!=Math.tanh)return Math.tanh(t);if(t===1/0)return 1;if(t===-1/0)return-1;var e=Math.exp(2*t);return(e-1)/(e+1)}function E(t){var e=Math.ceil(Math.sqrt(t));return[e,Math.ceil(t/e)]}function C(t,e){return e<=t.length?t:t+" ".repeat(e-t.length)}function R(t,e,n){return void 0===e&&(e=function(t){return 0}),new Promise(function(r,o){var a=0,i=function(){if(t())r();else{var s=e(++a);null!=n&&a>=n?o():setTimeout(i,s)}};i()})}function S(t,e){for(var n=1,r=-1,o=0;o<t.length;++o)if(t[o]>=0)n*=t[o];else if(-1===t[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(t[o]<0)throw Error("Shapes can not be < 0. Found "+t[o]+" at dim "+o);if(-1===r){if(e>0&&e!==n)throw Error("Size("+e+") must match the product of shape "+t);return t}if(0===n)throw Error("Cannot infer the missing size in ["+t+"] when there are 0 elements");if(e%n!=0)throw Error("The implicit shape can't be a fractional number. Got "+e+" / "+n);var a=t.slice();return a[r]=e/n,a}function N(t,e){var n=e.length;return d((t=null==t?e.map(function(t,e){return e}):[].concat(t)).every(function(t){return t>=-n&&t<n}),"All values in axis param must be in range [-"+n+", "+n+") but got axis "+t),d(t.every(function(t){return w(t)}),"All values in axis param must be integers but got axis "+t),t.map(function(t){return t<0?n+t:t})}function k(t,e){for(var n=[],r=[],o=null==e?null:N(e,t).sort(),a=0,i=0;i<t.length;++i){if(null!=o){if(o[a]===i&&1!==t[i])throw new Error("Can't squeeze axis "+i+" since its dim '"+t[i]+"' is not 1");(null==o[a]||o[a]>i)&&1===t[i]&&(n.push(t[i]),r.push(i)),o[a]<=i&&a++}1!==t[i]&&(n.push(t[i]),r.push(i))}return{newShape:n,keptDims:r}}function A(t,e){var n=null;if(null==t||"float32"===t)n=new Float32Array(e);else if("int32"===t)n=new Int32Array(e);else{if("bool"!==t)throw new Error("Unknown data type "+t);n=new Uint8Array(e)}return n}function I(t,e){var n=null;if(null==t||"float32"===t)n=new Float32Array(e);else if("int32"===t)n=new Int32Array(e);else if("bool"===t)n=new Uint8Array(e);else{if("string"!==t)throw new Error("Unknown data type "+t);n=new Array(e)}return n}function T(t,e,n){if("float32"===e)for(var r=0;r<t.length;r++){var o=t[r];if(isNaN(o)||!isFinite(o))throw Error("The result of the '"+n+"' is "+o+".")}}function D(t,e){for(var n=0;n<t.length;n++){var r=t[n];if(isNaN(r)||!isFinite(r))throw Error("A tensor of type "+e+" being uploaded contains "+r+".")}}function O(t,e){return"complex64"!==e&&(("float32"!==e||"complex64"===t)&&(("int32"!==e||"float32"===t||"complex64"===t)&&("bool"!==e||"bool"!==t)))}function _(t){return t instanceof Float32Array||t instanceof Int32Array||t instanceof Uint8Array}function M(t){if("float32"===t||"int32"===t)return 4;if("complex64"===t)return 8;if("bool"===t)return 1;throw new Error("Unknown dtype "+t)}function F(t){if(null==t)return 0;var e=0;return t.forEach(function(t){return e+=2*t.length}),e}function B(t){return"string"==typeof t||t instanceof String}function P(t){return"boolean"==typeof t}function L(t){return"number"==typeof t}function W(t){return Array.isArray(t)?W(t[0]):t instanceof Float32Array?"float32":t instanceof Int32Array||t instanceof Uint8Array?"int32":L(t)?"float32":B(t)?"string":P(t)?"bool":"float32"}function U(t){return!!(t&&t.constructor&&t.call&&t.apply)}function z(t,e){for(var n=e;n<t;++n)if(t%n==0)return n;return t}function V(t){var e=t.length;if(e<2)return[];var n=new Array(e-1);n[e-2]=t[e-1];for(var r=e-3;r>=0;--r)n[r]=n[r+1]*t[r+1];return n}function G(t,e,n){if("string"===e)throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(t)&&(t=g(t)),n&&D(t,e),function(t,e){return t instanceof Float32Array&&"float32"===e||t instanceof Int32Array&&"int32"===e||t instanceof Uint8Array&&"bool"===e}(t,e))return t;if(null==e||"float32"===e||"complex64"===e)return new Float32Array(t);if("int32"===e)return new Int32Array(t);if("bool"===e){for(var r=new Uint8Array(t.length),o=0;o<r.length;++o)0!==Math.round(t[o])&&(r[o]=1);return r}throw new Error("Unknown data type "+e)}function q(t,e){if(0===t.length)return e[0];var n=t.reduce(function(t,e){return t*e});if(0===n)return[];if(n!==e.length)throw new Error("["+t+"] does not match the input size.");return function t(e,n,r){var o=new Array;if(1===n.length)for(var a=n[0],i=0;i<a;i++)o[i]=r[e+i];else{a=n[0];var s=n.slice(1),u=s.reduce(function(t,e){return t*e});for(i=0;i<a;i++)o[i]=t(e+i*u,s,r)}return o}(0,t,e)}function H(t,e){for(var n=$(t,e),r=0;r<n.length;r++)n[r]=1;return n}function $(t,e){if(null==e||"float32"===e||"complex64"===e)return new Float32Array(t);if("int32"===e)return new Int32Array(t);if("bool"===e)return new Uint8Array(t);throw new Error("Unknown data type "+e)}function K(){if("undefined"!=typeof performance)return performance.now();if("undefined"!=typeof process){var t=process.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")}function j(t,e,n,r){!function(t){d(null!=t&&Array.isArray(t)&&t.length>0,"promises must be a none empty array")}(t),function(t,e){d(t>=0&&t<=1,"Progress fraction must be in range [0, 1], but got startFraction "+t),d(e>=0&&e<=1,"Progress fraction must be in range [0, 1], but got endFraction "+e),d(e>=t,"startFraction must be no more than endFraction, but got startFraction "+t+" and endFraction "+e)}(n=null==n?0:n,r=null==r?1:r);var o=0;return Promise.all(t.map(function(a){return a.then(function(a){var i=n+ ++o/t.length*(r-n);return e(i),a}),a}))}function X(t){t.forEach(function(e){d(Number.isInteger(e)&&e>=0,"Tensor must have a shape comprised of positive integers but got shape ["+t+"].")})}var Y=Object.freeze({shuffle:l,clamp:c,nearestLargerEven:h,sum:p,randUniform:f,distSquared:function(t,e){for(var n=0,r=0;r<t.length;r++){var o=Number(t[r])-Number(e[r]);n+=o*o}return n},assert:d,assertShapesMatch:m,assertNonNull:v,flatten:g,sizeFromShape:y,isScalarShape:function(t){return 0===t.length},arraysEqual:x,isInt:w,tanh:b,sizeToSquarishShape:E,createShuffledIndices:function(t){for(var e=new Uint32Array(t),n=0;n<t;++n)e[n]=n;return l(e),e},rightPad:C,repeatedTry:R,inferFromImplicitShape:S,parseAxisParam:N,squeezeShape:k,getTypedArrayFromDType:A,getArrayFromDType:I,checkComputationForErrors:T,checkConversionForErrors:D,hasEncodingLoss:O,isTypedArray:_,bytesPerElement:M,bytesFromStringArray:F,isString:B,isBoolean:P,isNumber:L,inferDtype:W,isFunction:U,nearestDivisor:z,computeStrides:V,toTypedArray:G,toNestedArray:q,makeOnesTypedArray:H,makeZerosTypedArray:$,now:K,monitorPromisesProgress:j,assertNonNegativeIntegerDimensions:X}),Q=function(){function t(t,e){this.backendTimer=t,this.logger=e,null==e&&(this.logger=new J)}return t.prototype.profileKernel=function(t,e){var n,r=this,o=this.backendTimer.time(function(){n=e()});return(Array.isArray(n)?n:[n]).forEach(function(e){var n=e.dataSync();T(n,e.dtype,t),o.then(function(o){var a="";null!=o.getExtraProfileInfo&&(a=o.getExtraProfileInfo()),r.logger.logKernelProfile(t,e,n,o.kernelMs,a)})}),n},t}(),J=function(){function t(){}return t.prototype.logKernelProfile=function(t,e,n,r,o){var a=C(r+"ms",9),i=C(t,25),s=e.rank,u=e.size,l=C(e.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")},t}(),Z=20,tt=3,et=7;function nt(t,e,n,r){var o=V(e),a=function(t,e,n,r){var o=y(e),a=r[r.length-1],i=new Array(a).fill(0),s=e.length,u="complex64"===n?ot(t):t;if(s>1)for(var l=0;l<o/a;l++)for(var c=l*a,h=0;h<a;h++)i[h]=Math.max(i[h],rt(u[c+h],0).length);return i}(t,e,n,o),i=e.length,s=function t(e,n,r,o,a,i){void 0===i&&(i=!0);var s="complex64"===r?2:1;var u=n[0];var l=n.length;if(0===l){if("complex64"===r){var c=ot(e);return[rt(c[0],0)]}return[e[0].toString()]}if(1===l){if(u>Z){var h=tt*s,p=Array.from(e.slice(0,h)),f=Array.from(e.slice(u-tt*s,u));return"complex64"===r&&(p=ot(p),f=ot(f)),["["+p.map(function(t,e){return rt(t,a[e])}).join(", ")+", ..., "+f.map(function(t,e){return rt(t,a[u-tt+e])}).join(", ")+"]"]}var d="complex64"===r?ot(e):Array.from(e);return["["+d.map(function(t,e){return rt(t,a[e])}).join(", ")+"]"]}var m=n.slice(1);var v=o.slice(1);var g=o[0]*s;var y=[];if(u>Z){for(var x=0;x<tt;x++){var w=x*g,b=w+g;y.push.apply(y,t(e.slice(w,b),m,r,v,a,!1))}y.push("...");for(var x=u-tt;x<u;x++){var w=x*g,b=w+g;y.push.apply(y,t(e.slice(w,b),m,r,v,a,x===u-1))}}else for(var x=0;x<u;x++){var w=x*g,b=w+g;y.push.apply(y,t(e.slice(w,b),m,r,v,a,x===u-1))}var E=2===l?",":"";y[0]="["+y[0]+E;for(var x=1;x<y.length-1;x++)y[x]=" "+y[x]+E;var C=",\n";for(var x=2;x<l;x++)C+="\n";y[y.length-1]=" "+y[y.length-1]+"]"+(i?"":C);return y}(t,e,n,o,a),u=["Tensor"];return r&&(u.push(" dtype: "+n),u.push(" rank: "+i),u.push(" shape: ["+e+"]"),u.push(" values:")),u.push(s.map(function(t){return" "+t}).join("\n")),u.join("\n")}function rt(t,e){return C(Array.isArray(t)?parseFloat(t[0].toFixed(et))+" + "+parseFloat(t[1].toFixed(et))+"j":B(t)?"'"+t+"'":parseFloat(t.toFixed(et)).toString(),e)}function ot(t){for(var e=[],n=0;n<t.length;n+=2)e.push([t[n],t[n+1]]);return e}var at=function(){function t(t,e,n){if(this.dtype=e,this.shape=t.slice(),this.size=y(t),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"===e)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(e,y(this.shape)),this.strides=V(t)}return t.prototype.set=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];0===e.length&&(e=[0]),d(e.length===this.rank,"The number of provided coordinates ("+e.length+") must match the rank ("+this.rank+")");var r=this.locToIndex(e);this.values[r]=t},t.prototype.get=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];0===t.length&&(t=[0]);for(var n=t[t.length-1],r=0;r<t.length-1;++r)n+=this.strides[r]*t[r];return this.values[n]},t.prototype.locToIndex=function(t){if(0===this.rank)return 0;if(1===this.rank)return t[0];for(var e=t[t.length-1],n=0;n<t.length-1;++n)e+=this.strides[n]*t[n];return e},t.prototype.indexToLoc=function(t){if(0===this.rank)return[];if(1===this.rank)return[t];for(var e=new Array(this.shape.length),n=0;n<e.length-1;++n)e[n]=Math.floor(t/this.strides[n]),t-=e[n]*this.strides[n];return e[e.length-1]=t,e},Object.defineProperty(t.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),t.prototype.toTensor=function(){return lt.make(this.shape,{values:this.values},this.dtype)},t}(),it=null,st=null,ut=null;var lt=function(){function t(t,e,n,r,o){this.isDisposedInternal=!1,this.shape=t.slice(),this.dtype=e||"float32",this.size=y(t),this.strides=V(t),this.dataId=null!=r?r:{},this.id=it().nextTensorId(),this.rankType=this.rank<5?this.rank.toString():"higher",it().registerTensor(this,o),null!=n&&it().write(this.dataId,n)}return t.make=function(e,n,r,o){return new t(e,r,n.values,n.dataId,o)},t.prototype.flatten=function(){return this.throwIfDisposed(),this.as1D()},t.prototype.asScalar=function(){return this.throwIfDisposed(),d(1===this.size,"The array must have only 1 element."),this.reshape([])},t.prototype.as1D=function(){return this.throwIfDisposed(),this.reshape([this.size])},t.prototype.as2D=function(t,e){return this.throwIfDisposed(),this.reshape([t,e])},t.prototype.as3D=function(t,e,n){return this.throwIfDisposed(),this.reshape([t,e,n])},t.prototype.as4D=function(t,e,n,r){return this.throwIfDisposed(),this.reshape([t,e,n,r])},t.prototype.as5D=function(t,e,n,r,o){return this.throwIfDisposed(),this.reshape([t,e,n,r,o])},t.prototype.asType=function(t){return this.throwIfDisposed(),st.cast(this,t)},Object.defineProperty(t.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),t.prototype.buffer=function(){return o(this,void 0,void 0,function(){var t;return a(this,function(e){switch(e.label){case 0:return[4,this.data()];case 1:return t=e.sent(),[2,st.buffer(this.shape,this.dtype,t)]}})})},t.prototype.bufferSync=function(){return st.buffer(this.shape,this.dtype,this.dataSync())},t.prototype.array=function(){return o(this,void 0,void 0,function(){var t;return a(this,function(e){switch(e.label){case 0:return[4,this.data()];case 1:return t=e.sent(),[2,q(this.shape,t)]}})})},t.prototype.arraySync=function(){return q(this.shape,this.dataSync())},t.prototype.data=function(){return o(this,void 0,void 0,function(){return a(this,function(t){return this.throwIfDisposed(),[2,it().read(this.dataId)]})})},t.prototype.dataSync=function(){return this.throwIfDisposed(),it().readSync(this.dataId)},t.prototype.dispose=function(){this.isDisposed||(it().disposeTensor(this),this.isDisposedInternal=!0)},Object.defineProperty(t.prototype,"isDisposed",{get:function(){return this.isDisposedInternal},enumerable:!0,configurable:!0}),t.prototype.throwIfDisposed=function(){if(this.isDisposed)throw new Error("Tensor is disposed.")},t.prototype.toFloat=function(){return this.asType("float32")},t.prototype.toInt=function(){return this.asType("int32")},t.prototype.toBool=function(){return this.asType("bool")},t.prototype.print=function(t){return void 0===t&&(t=!1),st.print(this,t)},t.prototype.reshape=function(t){return this.throwIfDisposed(),st.reshape(this,t)},t.prototype.reshapeAs=function(t){return this.throwIfDisposed(),this.reshape(t.shape)},t.prototype.expandDims=function(t){return void 0===t&&(t=0),st.expandDims(this,t)},t.prototype.cumsum=function(t,e,n){return void 0===t&&(t=0),void 0===e&&(e=!1),void 0===n&&(n=!1),st.cumsum(this,t,e,n)},t.prototype.squeeze=function(t){return this.throwIfDisposed(),st.squeeze(this,t)},t.prototype.clone=function(){return this.throwIfDisposed(),st.clone(this)},t.prototype.oneHot=function(t,e,n){return this.throwIfDisposed(),st.oneHot(this,t,e,n)},t.prototype.toString=function(t){return void 0===t&&(t=!1),nt(this.dataSync(),this.shape,this.dtype,t)},t.prototype.tile=function(t){return this.throwIfDisposed(),st.tile(this,t)},t.prototype.gather=function(t,e){return void 0===e&&(e=0),this.throwIfDisposed(),st.gather(this,t,e)},t.prototype.matMul=function(t,e,n){return void 0===e&&(e=!1),void 0===n&&(n=!1),this.throwIfDisposed(),st.matMul(this,t,e,n)},t.prototype.dot=function(t){return this.throwIfDisposed(),st.dot(this,t)},t.prototype.norm=function(t,e,n){return void 0===t&&(t="euclidean"),void 0===e&&(e=null),void 0===n&&(n=!1),this.throwIfDisposed(),st.norm(this,t,e,n)},t.prototype.slice=function(t,e){return this.throwIfDisposed(),st.slice(this,t,e)},t.prototype.reverse=function(t){return this.throwIfDisposed(),st.reverse(this,t)},t.prototype.concat=function(e,n){return void 0===n&&(n=0),this.throwIfDisposed(),e instanceof t&&(e=[e]),st.concat([this].concat(e),n)},t.prototype.split=function(t,e){return void 0===e&&(e=0),this.throwIfDisposed(),st.split(this,t,e)},t.prototype.stack=function(t,e){return void 0===e&&(e=0),st.stack([this,t],e)},t.prototype.unstack=function(t){return void 0===t&&(t=0),st.unstack(this,t)},t.prototype.pad=function(t,e){return void 0===e&&(e=0),st.pad(this,t,e)},t.prototype.batchNormalization=function(t,e,n,r,o){return void 0===n&&(n=.001),ut("tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon"),this.batchNorm(t,e,o,r,n)},t.prototype.batchNorm=function(t,e,n,r,o){return void 0===o&&(o=.001),this.throwIfDisposed(),st.batchNorm(this,t,e,n,r,o)},t.prototype.all=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),st.all(this,t,e)},t.prototype.any=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),st.any(this,t,e)},t.prototype.logSumExp=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),st.logSumExp(this,t,e)},t.prototype.sum=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),st.sum(this,t,e)},t.prototype.prod=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),st.prod(this,t,e)},t.prototype.mean=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),st.mean(this,t,e)},t.prototype.min=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),st.min(this,t,e)},t.prototype.max=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),st.max(this,t,e)},t.prototype.argMin=function(t){return void 0===t&&(t=null),this.throwIfDisposed(),st.argMin(this,t)},t.prototype.argMax=function(t){return void 0===t&&(t=null),this.throwIfDisposed(),st.argMax(this,t)},t.prototype.cast=function(t){return this.throwIfDisposed(),st.cast(this,t)},t.prototype.add=function(t){return this.throwIfDisposed(),st.add(this,t)},t.prototype.addStrict=function(t){return this.throwIfDisposed(),st.addStrict(this,t)},t.prototype.atan2=function(t){return this.throwIfDisposed(),st.atan2(this,t)},t.prototype.sub=function(t){return this.throwIfDisposed(),st.sub(this,t)},t.prototype.subStrict=function(t){return this.throwIfDisposed(),st.subStrict(this,t)},t.prototype.pow=function(t){return this.throwIfDisposed(),st.pow(this,t)},t.prototype.powStrict=function(t){return this.throwIfDisposed(),st.powStrict(this,t)},t.prototype.mul=function(t){return this.throwIfDisposed(),st.mul(this,t)},t.prototype.mulStrict=function(t){return this.throwIfDisposed(),st.mulStrict(this,t)},t.prototype.div=function(t){return this.throwIfDisposed(),st.div(this,t)},t.prototype.floorDiv=function(t){return this.throwIfDisposed(),st.floorDiv(this,t)},t.prototype.divStrict=function(t){return this.throwIfDisposed(),st.divStrict(this,t)},t.prototype.minimum=function(t){return this.throwIfDisposed(),st.minimum(this,t)},t.prototype.minimumStrict=function(t){return this.throwIfDisposed(),st.minimumStrict(this,t)},t.prototype.maximum=function(t){return this.throwIfDisposed(),st.maximum(this,t)},t.prototype.maximumStrict=function(t){return this.throwIfDisposed(),st.maximumStrict(this,t)},t.prototype.mod=function(t){return this.throwIfDisposed(),st.mod(this,t)},t.prototype.modStrict=function(t){return this.throwIfDisposed(),st.modStrict(this,t)},t.prototype.squaredDifference=function(t){return this.throwIfDisposed(),st.squaredDifference(this,t)},t.prototype.squaredDifferenceStrict=function(t){return this.throwIfDisposed(),st.squaredDifferenceStrict(this,t)},t.prototype.transpose=function(t){return this.throwIfDisposed(),st.transpose(this,t)},t.prototype.notEqual=function(t){return this.throwIfDisposed(),st.notEqual(this,t)},t.prototype.notEqualStrict=function(t){return this.throwIfDisposed(),st.notEqualStrict(this,t)},t.prototype.less=function(t){return this.throwIfDisposed(),st.less(this,t)},t.prototype.lessStrict=function(t){return this.throwIfDisposed(),st.lessStrict(this,t)},t.prototype.equal=function(t){return this.throwIfDisposed(),st.equal(this,t)},t.prototype.equalStrict=function(t){return this.throwIfDisposed(),st.equalStrict(this,t)},t.prototype.lessEqual=function(t){return this.throwIfDisposed(),st.lessEqual(this,t)},t.prototype.lessEqualStrict=function(t){return this.throwIfDisposed(),st.lessEqualStrict(this,t)},t.prototype.greater=function(t){return this.throwIfDisposed(),st.greater(this,t)},t.prototype.greaterStrict=function(t){return this.throwIfDisposed(),st.greaterStrict(this,t)},t.prototype.greaterEqual=function(t){return this.throwIfDisposed(),st.greaterEqual(this,t)},t.prototype.greaterEqualStrict=function(t){return this.throwIfDisposed(),st.greaterEqualStrict(this,t)},t.prototype.logicalAnd=function(t){return this.throwIfDisposed(),st.logicalAnd(this,t)},t.prototype.logicalOr=function(t){return this.throwIfDisposed(),st.logicalOr(this,t)},t.prototype.logicalNot=function(){return this.throwIfDisposed(),st.logicalNot(this)},t.prototype.logicalXor=function(t){return this.throwIfDisposed(),st.logicalXor(this,t)},t.prototype.where=function(t,e){return this.throwIfDisposed(),st.where(t,this,e)},t.prototype.neg=function(){return this.throwIfDisposed(),st.neg(this)},t.prototype.ceil=function(){return this.throwIfDisposed(),st.ceil(this)},t.prototype.floor=function(){return this.throwIfDisposed(),st.floor(this)},t.prototype.sign=function(){return this.throwIfDisposed(),st.sign(this)},t.prototype.exp=function(){return this.throwIfDisposed(),st.exp(this)},t.prototype.expm1=function(){return this.throwIfDisposed(),st.expm1(this)},t.prototype.log=function(){return this.throwIfDisposed(),st.log(this)},t.prototype.log1p=function(){return this.throwIfDisposed(),st.log1p(this)},t.prototype.sqrt=function(){return this.throwIfDisposed(),st.sqrt(this)},t.prototype.rsqrt=function(){return this.throwIfDisposed(),st.rsqrt(this)},t.prototype.square=function(){return this.throwIfDisposed(),st.square(this)},t.prototype.reciprocal=function(){return this.throwIfDisposed(),st.reciprocal(this)},t.prototype.abs=function(){return this.throwIfDisposed(),st.abs(this)},t.prototype.clipByValue=function(t,e){return this.throwIfDisposed(),st.clipByValue(this,t,e)},t.prototype.relu=function(){return this.throwIfDisposed(),st.relu(this)},t.prototype.elu=function(){return this.throwIfDisposed(),st.elu(this)},t.prototype.selu=function(){return this.throwIfDisposed(),st.selu(this)},t.prototype.leakyRelu=function(t){return void 0===t&&(t=.2),this.throwIfDisposed(),st.leakyRelu(this,t)},t.prototype.prelu=function(t){return this.throwIfDisposed(),st.prelu(this,t)},t.prototype.sigmoid=function(){return this.throwIfDisposed(),st.sigmoid(this)},t.prototype.logSigmoid=function(){return this.throwIfDisposed(),st.logSigmoid(this)},t.prototype.softplus=function(){return this.throwIfDisposed(),st.softplus(this)},t.prototype.zerosLike=function(){return this.throwIfDisposed(),st.zerosLike(this)},t.prototype.onesLike=function(){return this.throwIfDisposed(),st.onesLike(this)},t.prototype.sin=function(){return this.throwIfDisposed(),st.sin(this)},t.prototype.cos=function(){return this.throwIfDisposed(),st.cos(this)},t.prototype.tan=function(){return this.throwIfDisposed(),st.tan(this)},t.prototype.asin=function(){return this.throwIfDisposed(),st.asin(this)},t.prototype.acos=function(){return this.throwIfDisposed(),st.acos(this)},t.prototype.atan=function(){return this.throwIfDisposed(),st.atan(this)},t.prototype.sinh=function(){return this.throwIfDisposed(),st.sinh(this)},t.prototype.cosh=function(){return this.throwIfDisposed(),st.cosh(this)},t.prototype.tanh=function(){return this.throwIfDisposed(),st.tanh(this)},t.prototype.asinh=function(){return this.throwIfDisposed(),st.asinh(this)},t.prototype.acosh=function(){return this.throwIfDisposed(),st.acosh(this)},t.prototype.atanh=function(){return this.throwIfDisposed(),st.atanh(this)},t.prototype.erf=function(){return this.throwIfDisposed(),st.erf(this)},t.prototype.round=function(){return this.throwIfDisposed(),st.round(this)},t.prototype.step=function(t){return void 0===t&&(t=0),this.throwIfDisposed(),st.step(this,t)},t.prototype.softmax=function(t){return void 0===t&&(t=-1),this.throwIfDisposed(),st.softmax(this,t)},t.prototype.logSoftmax=function(t){return void 0===t&&(t=-1),this.throwIfDisposed(),st.logSoftmax(this,t)},t.prototype.resizeBilinear=function(t,e){return void 0===e&&(e=!1),this.throwIfDisposed(),st.image.resizeBilinear(this,t,e)},t.prototype.resizeNearestNeighbor=function(t,e){return void 0===e&&(e=!1),this.throwIfDisposed(),st.image.resizeNearestNeighbor(this,t,e)},t.prototype.conv1d=function(t,e,n,r,o,a){return void 0===r&&(r="NWC"),void 0===o&&(o=1),this.throwIfDisposed(),st.conv1d(this,t,e,n,r,o,a)},t.prototype.conv2d=function(t,e,n,r,o,a){return void 0===r&&(r="NHWC"),void 0===o&&(o=[1,1]),this.throwIfDisposed(),st.conv2d(this,t,e,n,r,o,a)},t.prototype.conv2dTranspose=function(t,e,n,r,o){return this.throwIfDisposed(),st.conv2dTranspose(this,t,e,n,r,o)},t.prototype.depthwiseConv2D=function(t,e,n,r,o,a){return void 0===r&&(r="NHWC"),void 0===o&&(o=[1,1]),this.throwIfDisposed(),st.depthwiseConv2d(this,t,e,n,r,o,a)},t.prototype.separableConv2d=function(t,e,n,r,o,a){return void 0===o&&(o=[1,1]),void 0===a&&(a="NHWC"),this.throwIfDisposed(),st.separableConv2d(this,t,e,n,r,o,a)},t.prototype.avgPool=function(t,e,n,r){return this.throwIfDisposed(),st.avgPool(this,t,e,n,r)},t.prototype.maxPool=function(t,e,n,r){return this.throwIfDisposed(),st.maxPool(this,t,e,n,r)},t.prototype.localResponseNormalization=function(t,e,n,r){return void 0===t&&(t=5),void 0===e&&(e=1),void 0===n&&(n=1),void 0===r&&(r=.5),st.localResponseNormalization(this,t,e,n,r)},t.prototype.pool=function(t,e,n,r,o){return this.throwIfDisposed(),st.pool(this,t,e,n,r,o)},t.prototype.variable=function(t,e,n){return void 0===t&&(t=!0),this.throwIfDisposed(),ct.variable(this,t,e,n)},t.prototype.unsortedSegmentSum=function(t,e){return this.throwIfDisposed(),st.unsortedSegmentSum(this,t,e)},t.prototype.batchToSpaceND=function(t,e){return this.throwIfDisposed(),st.batchToSpaceND(this,t,e)},t.prototype.spaceToBatchND=function(t,e){return this.throwIfDisposed(),st.spaceToBatchND(this,t,e)},t.prototype.topk=function(t,e){return void 0===t&&(t=1),void 0===e&&(e=!0),this.throwIfDisposed(),st.topk(this,t,e)},t.prototype.stridedSlice=function(t,e,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(),st.stridedSlice(this,t,e,n,r,o,a,i,s)},t.prototype.depthToSpace=function(t,e){return this.throwIfDisposed(),st.depthToSpace(this,t,e)},t.prototype.fft=function(){return this.throwIfDisposed(),st.spectral.fft(this)},t.prototype.ifft=function(){return this.throwIfDisposed(),st.spectral.ifft(this)},t.prototype.rfft=function(){return this.throwIfDisposed(),st.spectral.rfft(this)},t.prototype.irfft=function(){return this.throwIfDisposed(),st.spectral.irfft(this)},t}();Object.defineProperty(lt,Symbol.hasInstance,{value:function(t){return!!t&&null!=t.dataId&&null!=t.shape&&null!=t.dtype}});var ct=function(t){function e(e,n,r){void 0===n&&(n=!0);var o=t.call(this,e.shape,e.dtype,null,e.dataId)||this;o.trainable=n,o.name=r,null==o.name&&(o.name=it().nextVariableId().toString());try{it().registerVariable(o)}catch(t){throw it().disposeTensor(o),t}return o}return n(e,t),e.variable=function(t,n,r,o){return void 0===n&&(n=!0),null!=o&&o!==t.dtype&&(t=t.asType(o)),new e(t,n,r)},e.prototype.assign=function(t){if(t.dtype!==this.dtype)throw new Error("dtype of the new value ("+t.dtype+") and previous value ("+this.dtype+") must match");if(!x(t.shape,this.shape))throw new Error("shape of the new value ("+t.shape+") and previous value ("+this.shape+") must match");it().disposeTensor(this),this.dataId=t.dataId,it().registerTensor(this)},e}(lt);Object.defineProperty(ct,Symbol.hasInstance,{value:function(t){return t instanceof lt&&null!=t.assign&&t.assign instanceof Function}});var ht,pt,ft,dt,mt,vt=ct.variable;(ht=t.Rank||(t.Rank={})).R0="R0",ht.R1="R1",ht.R2="R2",ht.R3="R3",ht.R4="R4",ht.R5="R5",ht.R6="R6",function(t){t.float32="float32",t.int32="int32",t.bool="int32",t.complex64="complex64"}(pt||(pt={})),function(t){t.float32="float32",t.int32="int32",t.bool="bool",t.complex64="complex64"}(ft||(ft={})),function(t){t.float32="float32",t.int32="float32",t.bool="float32",t.complex64="complex64"}(dt||(dt={})),function(t){t.float32="complex64",t.int32="complex64",t.bool="complex64",t.complex64="complex64"}(mt||(mt={}));var gt={float32:dt,int32:pt,bool:ft,complex64:mt};function yt(t,e){if("string"===t||"string"===e){if("string"===t&&"string"===e)return"string";throw new Error("Can not upcast "+t+" with "+e)}return gt[t][e]}function xt(t){return yt(t,"int32")}function wt(t,e){if(t.dtype===e.dtype)return[t,e];var n=yt(t.dtype,e.dtype);return[t.cast(n),e.cast(n)]}function bt(t){var e=[];return function t(e,n,r){if(null==e)return;if(e instanceof lt)return void n.push(e);if(o=e,!Array.isArray(o)&&"object"!=typeof o)return;var o;var a=e;for(var i in a){var s=a[i];r.has(s)||(r.add(s),t(s,n,r))}}(t,e,new Set),e}var Et,Ct=function(){function t(t,e,n){this.backend=t,this.safeMode=e,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 Q(t),this.activeProfile={newBytes:0,newTensors:0,peakBytes:0,kernels:[],result:null}}return t.prototype.moveData=function(t){this.write(t,this.readSync(t))},t.prototype.tidy=function(t,e,n){var r=this;void 0===n&&(n=!1);var o,a=null;if(null==e){if("function"!=typeof t)throw new Error("Please provide a function to tidy()");e=t}else{if("string"!=typeof t&&!(t instanceof String))throw new Error("When calling with two arguments, the first argument to tidy() must be a string");if("function"!=typeof e)throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");a=t}return this.scopedRun(function(){return r.startScope(a,n)},function(){return r.endScope(o,n)},function(){return(o=e())instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),o})},t.prototype.scopedRun=function(t,e,n){t();try{var r=n();return e(),r}catch(t){throw e(),t}},t.prototype.nextTensorId=function(){return t.nextTensorId++},t.prototype.nextVariableId=function(){return t.nextVariableId++},t.prototype.runKernel=function(t,e,n){var r,o=this,a=[],i=function(t){return a.push(t),t},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 t(o.backend,i)}):t(o.backend,i)}),this.shouldRecord()){var c={id:this.nextTapeNodeId++,name:s,inputs:e,outputs:Array.isArray(r)?r:[r]};null!=n&&(c.gradient=function(t){return n(t,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(e).map(function(t){return e[t].shape}),outputShape:Array.isArray(r)?r.map(function(t){return t.shape}):r.shape}),r},t.prototype.registerTensor=function(t,e){var n=this.tensorInfo.has(t.dataId)?this.tensorInfo.get(t.dataId).refCount:0;if(this.numTensors++,"string"===t.dtype&&this.numStringTensors++,0===n){this.numDataBuffers++;var r=0;"complex64"!==t.dtype&&"string"!==t.dtype&&(r=y(t.shape)*M(t.dtype)),this.tensorInfo.set(t.dataId,{backend:null!=e?e:this.backend,dtype:t.dtype,shape:t.shape,bytes:r,refCount:0}),this.numBytes+=r,null!=e?e.register(t.dataId,t.shape,t.dtype):this.backend.register(t.dataId,t.shape,t.dtype)}this.tensorInfo.get(t.dataId).refCount++,t instanceof ct||this.track(t)},t.prototype.registerVariable=function(t){if(null!=this.registeredVariables[t.name])throw new Error("Variable with name "+t.name+" was already registered");this.registeredVariables[t.name]=t},t.prototype.disposeTensor=function(t){if(this.tensorInfo.has(t.dataId)){this.keepTensors.has(t.id)&&this.keepTensors.delete(t.id),this.numTensors--,"string"===t.dtype&&this.numStringTensors--;var e=this.tensorInfo.get(t.dataId);e.refCount<=1?("complex64"!==t.dtype&&(this.numBytes-=e.bytes),this.numDataBuffers--,e.backend.disposeData(t.dataId),this.tensorInfo.delete(t.dataId)):this.tensorInfo.get(t.dataId).refCount--}},t.prototype.disposeVariables=function(){for(var t in this.registeredVariables){var e=this.registeredVariables[t];this.disposeTensor(e),delete this.registeredVariables[t]}},t.prototype.memory=function(){var t=this.backend.memory();return t.numTensors=this.numTensors,t.numDataBuffers=this.numDataBuffers,t.numBytes=this.numBytes,this.numStringTensors>0&&(t.unreliable=!0,null==t.reasons&&(t.reasons=[]),t.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")),t},t.prototype.profile=function(t){return o(this,void 0,void 0,function(){var e,n;return a(this,function(r){return this.profiling=!0,e=this.numBytes,n=this.numTensors,this.activeProfile.kernels=[],this.activeProfile.result=t(),this.profiling=!1,this.activeProfile.peakBytes=Math.max.apply(Math,this.activeProfile.kernels.map(function(t){return t.totalBytesSnapshot})),this.activeProfile.newBytes=this.numBytes-e,this.activeProfile.newTensors=this.numTensors-n,[2,this.activeProfile]})})},t.prototype.shouldRecord=function(){return null!=this.activeTape&&0===this.customGradientDepth},t.prototype.addTapeNode=function(t,e,n){var r={};t.forEach(function(t,e){r[e]=t});var o={id:this.nextTapeNodeId++,name:this.activeScope.name,inputs:r,outputs:[e],gradient:function(t){var e={};return n(t).forEach(function(t,n){e[n]=function(){return t}}),e}};this.activeTape.push(o)},t.prototype.keep=function(t){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(t.id),t},t.prototype.startScope=function(t,e){void 0===e&&(e=!1),e&&0===this.gradientScopeCount&&(this.activeTape=[]),e&&this.gradientScopeCount++;var n={track:[],name:"unnamed scope"};t&&(n.name=t),this.scopeStack.push(n),this.activeScope=n},t.prototype.endScope=function(t,e){var n=this;void 0===e&&(e=!1),e&&(this.gradientScopeCount--,0===this.gradientScopeCount&&(this.activeTape=null));var r=new Set(this.keepTensors),o=bt(t);o.forEach(function(t){return r.add(t.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(t){!n.keepTensors.has(t.id)&&function(t,e){for(var n=0;n<e.length;n++)if(e[n].id===t.id)return!0;return!1}(t,s.track)&&n.track(t)})},t.prototype.gradients=function(t,e,n,r){var o=this;if(void 0===r&&(r=!1),d(e.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=t();d(a instanceof lt,"The result y returned by f() must be a tensor.");var i=function(t,e,n){for(var r={},o={},a=0;a<e.length;a++)r[e[a].id]=!0;for(a=0;a<t.length;a++){var i=(d=t[a]).inputs;for(var s in i){for(var u=i[s],l=!1,c=0;c<e.length;c++)if(r[u.id]){d.outputs.forEach(function(t){return r[t.id]=!0}),l=!0,o[d.id]=!0;break}if(l)break}}var h={};h[n.id]=!0;var p={};for(a=t.length-1;a>=0;a--)for(i=(d=t[a]).inputs,c=0;c<d.outputs.length;c++)if(h[d.outputs[c].id]){for(var s in i)h[i[s].id]=!0,p[d.id]=!0;break}var f=[];for(a=0;a<t.length;a++){var d;if(o[(d=t[a]).id]&&p[d.id]){var m={};for(var s in d.inputs){var v=d.inputs[s];r[v.id]&&(m[s]=v)}var g=Object.assign({},d);g.inputs=m,g.outputs=d.outputs,f.push(g)}}return f}(o.activeTape,e,a);if(!r&&0===i.length&&e.length>0)throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that the f you passed encloses all operations that lead from x to y.");var s,u,l={};return l[a.id]=null==n?(s=a.shape,u=H(y(s),"float32"),lt.make(s,{values:u})):n,function(t,e){for(var n=function(n){var r=e[n],o=[];if(r.outputs.forEach(function(e){var n=t[e.id];if(null!=n)o.push(n);else{var r=lt.make(e.shape,{values:$(e.size,e.dtype)},e.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(!x(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==t[u.id])t[u.id]=s;else{var l=t[u.id];t[u.id]=l.add(s),l.dispose()}}},r=e.length-1;r>=0;r--)n(r)}(l,i),{value:a,grads:e.map(function(t){return l[t.id]})}},!0)},t.prototype.customGrad=function(t){var e=this;return d(U(t),"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(d(o.every(function(t){return t instanceof lt}),"The args passed in customGrad(f)(x1, x2,...) must all be tensors"),e.scopedRun(function(){return e.customGradientDepth++},function(){return e.customGradientDepth--},function(){r=e.tidy(t.name,function(){var e=t.apply(void 0,o),r=e.value,a=e.gradFunc;return d(r instanceof lt,"The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"),d(U(a),"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."),n=a,r},!0)}),e.shouldRecord()){e.addTapeNode(o,r,function(t){var e=n(t),r=Array.isArray(e)?e:[e];return d(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(...)."),d(r.every(function(t){return t instanceof lt}),"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}},t.prototype.write=function(t,e){var n=this.tensorInfo.get(t);if("string"===n.dtype){var r=F(e);this.numBytes+=r-n.bytes,n.bytes=r}this.backend!==n.backend&&(n.backend.disposeData(t),n.backend=this.backend,this.backend.register(t,n.shape,n.dtype)),this.backend.write(t,e)},t.prototype.readSync=function(t){return this.tensorInfo.get(t).backend.readSync(t)},t.prototype.read=function(t){return this.tensorInfo.get(t).backend.read(t)},t.prototype.fromPixels=function(t,e){return this.backend.fromPixels(t,e)},t.prototype.time=function(t){return o(this,void 0,void 0,function(){var e,n;return a(this,function(r){switch(r.label){case 0:return e=K(),[4,this.backend.time(t)];case 1:return(n=r.sent()).wallMs=K()-e,[2,n]}})})},t.prototype.track=function(t){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 null!=this.activeScope&&this.activeScope.track.push(t),t},t.nextTensorId=0,t.nextVariableId=0,t}();!function(t){t[t.NUMBER=0]="NUMBER",t[t.BOOLEAN=1]="BOOLEAN",t[t.STRING=2]="STRING"}(Et||(Et={}));var Rt,St,Nt=[{name:"DEBUG",type:Et.BOOLEAN},{name:"IS_BROWSER",type:Et.BOOLEAN},{name:"WEBGL_LAZILY_UNPACK",type:Et.BOOLEAN},{name:"WEBGL_CPU_FORWARD",type:Et.BOOLEAN},{name:"WEBGL_PACK",type:Et.BOOLEAN},{name:"WEBGL_PACK_BATCHNORMALIZATION",type:Et.BOOLEAN},{name:"WEBGL_PACK_CLIP",type:Et.BOOLEAN},{name:"WEBGL_PACK_DEPTHWISECONV",type:Et.BOOLEAN},{name:"WEBGL_PACK_BINARY_OPERATIONS",type:Et.BOOLEAN},{name:"WEBGL_PACK_ARRAY_OPERATIONS",type:Et.BOOLEAN},{name:"WEBGL_PACK_IMAGE_OPERATIONS",type:Et.BOOLEAN},{name:"WEBGL_CONV_IM2COL",type:Et.BOOLEAN},{name:"WEBGL_MAX_TEXTURE_SIZE",type:Et.NUMBER},{name:"WEBGL_NUM_MB_BEFORE_PAGING",type:Et.NUMBER},{name:"WEBGL_MAX_TEXTURES_IN_SHADER",type:Et.NUMBER},{name:"WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION",type:Et.NUMBER},{name:"WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE",type:Et.BOOLEAN},{name:"WEBGL_VERSION",type:Et.NUMBER},{name:"WEBGL_RENDER_FLOAT32_ENABLED",type:Et.BOOLEAN},{name:"WEBGL_DOWNLOAD_FLOAT_ENABLED",type:Et.BOOLEAN},{name:"WEBGL_FENCE_API_ENABLED",type:Et.BOOLEAN},{name:"WEBGL_SIZE_UPLOAD_UNIFORM",type:Et.NUMBER},{name:"BACKEND",type:Et.STRING},{name:"EPSILON",type:Et.NUMBER},{name:"PROD",type:Et.BOOLEAN},{name:"TENSORLIKE_CHECK_SHAPE_CONSISTENCY",type:Et.BOOLEAN},{name:"DEPRECATION_WARNINGS_ENABLED",type:Et.BOOLEAN}];function kt(t){try{if(null!=u(t))return!0}catch(t){return!1}return!1}var At="tfjsflags";function It(){var t={};if("undefined"==typeof window||void 0===window.location||void 0===window.location.search)return t;var e,n,r=(e=window.location.search,n={},e.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return function(t,e,n){t[decodeURIComponent(e)]=decodeURIComponent(n||"")}(n,e[0],e[1]),e.join("=")}),n);if(At in r){var o={};r[At].split(",").forEach(function(t){var e=t.split(":"),n=e[0],r=e[1];o[n]=r}),Nt.forEach(function(e){e.name in o&&(console.log("Setting feature override from URL "+e.name+": "+o[e.name]),e.type===Et.NUMBER?t[e.name]=+o[e.name]:e.type===Et.BOOLEAN?t[e.name]="true"===o[e.name]:e.type===Et.STRING?t[e.name]=o[e.name]:console.warn("Unknown URL param: "+e.name+"."))})}return t}function Tt(t,e){return null!=t.getExtension(e)}function Dt(t,e){var n=t.createFramebuffer(),r=t.createTexture();t.bindTexture(t.TEXTURE_2D,r);var o=2===e?t.RGBA32F:t.RGBA;t.texImage2D(t.TEXTURE_2D,0,o,1,1,0,t.RGBA,t.FLOAT,null),t.bindFramebuffer(t.FRAMEBUFFER,n),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r,0);var a=t.checkFramebufferStatus(t.FRAMEBUFFER)===t.FRAMEBUFFER_COMPLETE;return t.bindTexture(t.TEXTURE_2D,null),t.bindFramebuffer(t.FRAMEBUFFER,null),t.deleteTexture(r),t.deleteFramebuffer(n),a}var Ot=600;var _t,Mt=function(){function t(t){this.features={},this.registry={},null!=t&&(this.features=t),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(t,e){if(void 0===e&&(e=!1),!(t in zt.registry))throw new Error("Backend name '"+t+"' not found in registry");zt.engine.backend=zt.findBackend(t),zt.backendName=t},t.getBackend=function(){return zt.initEngine(),zt.backendName},t.disposeVariables=function(){zt.engine.disposeVariables()},t.memory=function(){return zt.engine.memory()},t.profile=function(t){return zt.engine.profile(t)},t.tidy=function(t,e){return zt.engine.tidy(t,e)},t.dispose=function(t){bt(t).forEach(function(t){return t.dispose()})},t.keep=function(t){return zt.engine.keep(t)},t.time=function(t){return zt.engine.time(t)},t.prototype.get=function(t){return t in this.features?this.features[t]:(this.features[t]=this.evaluateFeature(t),this.features[t])},t.prototype.getFeatures=function(){return this.features},t.prototype.set=function(t,e){this.features[t]=e},t.prototype.getBestBackendName=function(){var t=this;if(0===Object.keys(this.registry).length)throw new Error("No backend found in registry.");return Object.keys(this.registry).map(function(e){return{name:e,entry:t.registry[e]}}).sort(function(t,e){return e.entry.priority-t.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"undefined"!=typeof process&&void 0!==process.versions&&void 0!==process.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("WEBGL_CPU_FORWARD"===t)return!0;if("WEBGL_PACK"===t)return 0!==this.get("WEBGL_VERSION");if("WEBGL_PACK_BATCHNORMALIZATION"===t)return this.get("WEBGL_PACK");if("WEBGL_PACK_CLIP"===t)return this.get("WEBGL_PACK");if("WEBGL_PACK_DEPTHWISECONV"===t)return this.get("WEBGL_PACK");if("WEBGL_PACK_BINARY_OPERATIONS"===t)return this.get("WEBGL_PACK");if("WEBGL_PACK_ARRAY_OPERATIONS"===t)return this.get("WEBGL_PACK");if("WEBGL_PACK_IMAGE_OPERATIONS"===t)return this.get("WEBGL_PACK");if("WEBGL_LAZILY_UNPACK"===t)return this.get("WEBGL_PACK");if("WEBGL_CONV_IM2COL"===t)return this.get("WEBGL_PACK");if("WEBGL_NUM_MB_BEFORE_PAGING"===t)return this.get("PROD")||!this.get("IS_BROWSER")?Number.POSITIVE_INFINITY:window.screen.height*window.screen.width*window.devicePixelRatio*Ot/1024;if("WEBGL_MAX_TEXTURE_SIZE"===t)return function(t){if(null==Rt){var e=u(t);Rt=e.getParameter(e.MAX_TEXTURE_SIZE)}return Rt}(this.get("WEBGL_VERSION"));if("WEBGL_MAX_TEXTURES_IN_SHADER"===t)return function(t){if(null==St){var e=u(t);St=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS)}return Math.min(16,St)}(this.get("WEBGL_VERSION"));if("IS_TEST"===t)return!1;if("BACKEND"===t)return this.getBestBackendName();if("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"===t){var e=this.get("WEBGL_VERSION");return 0===e?0:function(t){if(0===t)return 0;var e=u(t);return Tt(e,"EXT_disjoint_timer_query_webgl2")&&2===t?2:Tt(e,"EXT_disjoint_timer_query")?1:0}(e)}if("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE"===t)return this.get("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0&&(n=navigator.userAgent||navigator.vendor||window.opera,!(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(n)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez(