From 7f2f3c4b94d79b9be0ee2e9ff268c75e0748fde2 Mon Sep 17 00:00:00 2001 From: Marco Tulio Soares Date: Thu, 5 Sep 2024 18:06:23 -0300 Subject: [PATCH 1/7] arquivos detector facial --- riso_facial-service/Face-Detection-JavaScript | 1 + 1 file changed, 1 insertion(+) create mode 160000 riso_facial-service/Face-Detection-JavaScript diff --git a/riso_facial-service/Face-Detection-JavaScript b/riso_facial-service/Face-Detection-JavaScript new file mode 160000 index 00000000..646525e2 --- /dev/null +++ b/riso_facial-service/Face-Detection-JavaScript @@ -0,0 +1 @@ +Subproject commit 646525e20bea82ce838ae6047076dfd095a65ad5 From 99682f54cf5c9607c11d3b3644c484a3f2112bac Mon Sep 17 00:00:00 2001 From: DanielRogs Date: Thu, 5 Sep 2024 19:25:08 -0300 Subject: [PATCH 2/7] fix: resolvendo bug de arquivos de reconhecimento facial MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: JÉSUS GABRIEL --- riso_facial-service/Face-Detection-JavaScript | 1 - riso_facial-service/face-api.min.js | 1 + riso_facial-service/index.html | 29 ++++++++++ .../models/face_expression_model-shard1 | Bin 0 -> 329468 bytes ...ace_expression_model-weights_manifest.json | 1 + .../models/face_landmark_68_model-shard1 | Bin 0 -> 356840 bytes ...ce_landmark_68_model-weights_manifest.json | 1 + .../models/face_landmark_68_tiny_model-shard1 | Bin 0 -> 77224 bytes ...ndmark_68_tiny_model-weights_manifest.json | 1 + .../models/face_recognition_model-shard1 | Bin 0 -> 4194304 bytes .../models/face_recognition_model-shard2 | 6 ++ ...ce_recognition_model-weights_manifest.json | 1 + .../models/tiny_face_detector_model-shard1 | Bin 0 -> 193321 bytes ..._face_detector_model-weights_manifest.json | 1 + riso_facial-service/script.js | 52 ++++++++++++++++++ 15 files changed, 93 insertions(+), 1 deletion(-) delete mode 160000 riso_facial-service/Face-Detection-JavaScript create mode 100644 riso_facial-service/face-api.min.js create mode 100644 riso_facial-service/index.html create mode 100644 riso_facial-service/models/face_expression_model-shard1 create mode 100644 riso_facial-service/models/face_expression_model-weights_manifest.json create mode 100644 riso_facial-service/models/face_landmark_68_model-shard1 create mode 100644 riso_facial-service/models/face_landmark_68_model-weights_manifest.json create mode 100644 riso_facial-service/models/face_landmark_68_tiny_model-shard1 create mode 100644 riso_facial-service/models/face_landmark_68_tiny_model-weights_manifest.json create mode 100644 riso_facial-service/models/face_recognition_model-shard1 create mode 100644 riso_facial-service/models/face_recognition_model-shard2 create mode 100644 riso_facial-service/models/face_recognition_model-weights_manifest.json create mode 100644 riso_facial-service/models/tiny_face_detector_model-shard1 create mode 100644 riso_facial-service/models/tiny_face_detector_model-weights_manifest.json create mode 100644 riso_facial-service/script.js diff --git a/riso_facial-service/Face-Detection-JavaScript b/riso_facial-service/Face-Detection-JavaScript deleted file mode 160000 index 646525e2..00000000 --- a/riso_facial-service/Face-Detection-JavaScript +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 646525e20bea82ce838ae6047076dfd095a65ad5 diff --git a/riso_facial-service/face-api.min.js b/riso_facial-service/face-api.min.js new file mode 100644 index 00000000..e5ac83ba --- /dev/null +++ b/riso_facial-service/face-api.min.js @@ -0,0 +1 @@ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).faceapi=t.faceapi||{})}(this,function(c){"use strict";var r=function(t,e){return(r=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,e)};function a(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var O=function(){return(O=Object.assign||function(t){for(var e,n=1,r=arguments.length;na[0]&&e[1]a[0]&&e[1]a)&&1===t[a]&&(n.push(t[a]),r.push(a)),o[i]<=a&&i++}1!==t[a]&&(n.push(t[a]),r.push(a))}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 M(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 F(t,e,n){if("float32"===e)for(var r=0;r=this.shape[n]){var a="Requested out of range element at "+t+". Buffer shape="+this.shape;throw new Error(a)}n++}for(var s=t[t.length-1],u=0;u {...}) to avoid memory leaks.");return t.kept=!0,t},t.prototype.startTape=function(){0===this.gradientDepth&&(this.activeTape=[]),this.gradientDepth++},t.prototype.endTape=function(){this.gradientDepth--},t.prototype.startScope=function(t){var e={track:[],name:"unnamed scope",id:this.nextScopeId++};t&&(e.name=t),this.scopeStack.push(e),this.activeScope=e},t.prototype.endScope=function(t){for(var e=this,n=Dt(t),r=new Set(n.map(function(t){return t.id})),o=0;o {op();...}); to avoid memory leaks.");return null!=this.activeScope&&(t.scopeId=this.activeScope.id,this.activeScope.track.push(t)),t},t.nextTensorId=0,t.nextVariableId=0,t}();(Ot=Mt||(Mt={}))[Ot.NUMBER=0]="NUMBER",Ot[Ot.BOOLEAN=1]="BOOLEAN",Ot[Ot.STRING=2]="STRING";var Lt,Bt,Wt=[{name:"DEBUG",type:Mt.BOOLEAN},{name:"IS_BROWSER",type:Mt.BOOLEAN},{name:"WEBGL_LAZILY_UNPACK",type:Mt.BOOLEAN},{name:"WEBGL_CPU_FORWARD",type:Mt.BOOLEAN},{name:"WEBGL_PACK",type:Mt.BOOLEAN},{name:"WEBGL_PACK_BATCHNORMALIZATION",type:Mt.BOOLEAN},{name:"WEBGL_PACK_CLIP",type:Mt.BOOLEAN},{name:"WEBGL_PACK_DEPTHWISECONV",type:Mt.BOOLEAN},{name:"WEBGL_PACK_BINARY_OPERATIONS",type:Mt.BOOLEAN},{name:"WEBGL_PACK_ARRAY_OPERATIONS",type:Mt.BOOLEAN},{name:"WEBGL_PACK_IMAGE_OPERATIONS",type:Mt.BOOLEAN},{name:"WEBGL_PACK_REDUCE",type:Mt.BOOLEAN},{name:"WEBGL_CONV_IM2COL",type:Mt.BOOLEAN},{name:"WEBGL_MAX_TEXTURE_SIZE",type:Mt.NUMBER},{name:"WEBGL_NUM_MB_BEFORE_PAGING",type:Mt.NUMBER},{name:"WEBGL_MAX_TEXTURES_IN_SHADER",type:Mt.NUMBER},{name:"WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION",type:Mt.NUMBER},{name:"WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE",type:Mt.BOOLEAN},{name:"WEBGL_VERSION",type:Mt.NUMBER},{name:"WEBGL_RENDER_FLOAT32_ENABLED",type:Mt.BOOLEAN},{name:"WEBGL_DOWNLOAD_FLOAT_ENABLED",type:Mt.BOOLEAN},{name:"WEBGL_FENCE_API_ENABLED",type:Mt.BOOLEAN},{name:"WEBGL_SIZE_UPLOAD_UNIFORM",type:Mt.NUMBER},{name:"BACKEND",type:Mt.STRING},{name:"EPSILON",type:Mt.NUMBER},{name:"PROD",type:Mt.BOOLEAN},{name:"TENSORLIKE_CHECK_SHAPE_CONSISTENCY",type:Mt.BOOLEAN},{name:"DEPRECATION_WARNINGS_ENABLED",type:Mt.BOOLEAN}];function zt(t){try{if(null!=l(t))return!0}catch(t){return!1}return!1}var Ut="tfjsflags";function Gt(){var e={};if("undefined"==typeof window||void 0===window.location||void 0===window.location.search)return e;var t,a,n=(t=window.location.search,a={},t.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,function(t){for(var e=[],n=1;nt.rank)throw new Error("index innermost dimension length must be <= tensor rank; saw: "+e.shape[e.rank-1]+" vs. "+t.rank);if(0===t.size)throw new Error("Requested more than 0 entries, but input is empty. Input shape: "+t.shape+".");for(var n=e.shape,r=n[n.length-1],o=1,i=0;i=l[e]:o<=l[e]);o+=r)n+=1;return n}),[c,f,h]}function De(t,e,n,r,o){var i=e[o],a=n[o]||1;(t&1<o}).sort(function(t,e){return e.score-t.score}),a=[],s=0;s=r){h=!0;break}if(!h&&(a.push(l),a.length>=n))break}return He(a,"int32")}function hn(t,e,n){var r=t.subarray(4*e,4*e+4),o=t.subarray(4*n,4*n+4),i=Math.min(r[0],r[2]),a=Math.min(r[1],r[3]),s=Math.max(r[0],r[2]),u=Math.max(r[1],r[3]),c=Math.min(o[0],o[2]),l=Math.min(o[1],o[3]),h=Math.max(o[0],o[2]),p=Math.max(o[1],o[3]),f=(s-i)*(u-a),d=(h-c)*(p-l);if(f<=0||d<=0)return 0;var v=Math.max(i,c),m=Math.max(a,l),g=Math.min(s,h),y=Math.min(u,p),x=Math.max(g-v,0)*Math.max(y-m,0);return x/(f+d-x)}function pn(n,t,r){var o=new Array(n.rank).fill(0),i=n.shape.slice();return t.map(function(t){i[r]=t;var e=n.slice(o,i);return o[r]+=t,e})}function fn(t,e,n,r,o){for(var i=e[e.length-1],a=[t.length/i,i],s=a[0],u=a[1],c=A(n,s*r),l=A("int32",s*r),h=0;h":"<",u=n?"inOffset + i;":"round(getBestIndicesA(batch, inOffset + i));";this.userCode="\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * "+r+";\n\n int bestIndex = inOffset;\n float bestValue = getA(batch, bestIndex);\n\n for (int i = 0; i < "+r+"; i++) {\n int inIdx = "+u+";\n float candidate = getA(batch, inIdx);\n if (candidate "+s+" bestValue) {\n bestValue = candidate;\n bestIndex = inIdx;\n }\n }\n setOutput(float(bestIndex));\n }\n "};function vn(e,t){return["x","y","z","w","u","v"].slice(0,t).map(function(t){return e+"."+t})}function mn(t,e){return 1===e?[t]:vn(t,e)}function gn(t,e){for(var n=t.length,r=[],o=0;o= "+t.outHeight+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < "+u+";\n wC+= "+a+") {\n float dyC = float(dyCCorner + wC) / "+o+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n\n dotProd += dyValue * avgMultiplier;\n }\n }\n setOutput(dotProd);\n }\n "},Ln=function(t,e,n,r,o,i){this.outputShape=[],this.variableNames=["x","mean","variance"],xn(t,e),xn(t,n);var a="0.0";null!=r&&(xn(t,r),this.variableNames.push("offset"),a="getOffsetAtOutCoords()");var s="1.0";null!=o&&(xn(t,o),this.variableNames.push("scale"),s="getScaleAtOutCoords()"),this.outputShape=t,this.userCode="\n void main() {\n float x = getXAtOutCoords();\n float mean = getMeanAtOutCoords();\n float variance = getVarianceAtOutCoords();\n float offset = "+a+";\n float scale = "+s+";\n float inv = scale * inversesqrt(variance + float("+i+"));\n setOutput(dot(vec3(x, -mean, offset), vec3(inv, inv, 1)));\n }\n "},Bn=function(t,e,n,r,o,i){this.usesPackedTextures=!0,this.variableNames=["x","mean","variance"],xn(t,e),xn(t,n);var a="vec4(0.0)";null!=r&&(xn(t,r),this.variableNames.push("offset"),a="getOffsetAtOutCoords()");var s="vec4(1.0)";null!=o&&(xn(t,o),this.variableNames.push("scale"),s="getScaleAtOutCoords()"),this.outputShape=t,this.userCode="\n void main() {\n vec4 offset = "+a+";\n vec4 scale = "+s+";\n\n vec4 x = getXAtOutCoords();\n vec4 mean = getMeanAtOutCoords();\n vec4 variance = getVarianceAtOutCoords();\n\n vec4 inv = scale * inversesqrt(variance + vec4("+i+"));\n\n setOutput((x - mean) * inv + offset);\n }\n "},Wn="return areal * breal - aimag * bimag;",zn="return areal * bimag + aimag * breal;",Un=function(t,e,n){this.variableNames=["AReal","AImag","BReal","BImag"],this.outputShape=xn(e,n),this.userCode="\n float binaryOpComplex(\n float areal, float aimag, float breal, float bimag) {\n "+t+"\n }\n\n void main() {\n float areal = getARealAtOutCoords();\n float aimag = getAImagAtOutCoords();\n float breal = getBRealAtOutCoords();\n float bimag = getBImagAtOutCoords();\n setOutput(binaryOpComplex(areal, aimag, breal, bimag));\n }\n "},Gn="return a + b;",Vn="return a - b;",Hn="return a * b;",qn="return (a - b) * (a - b);",jn=function(t,e,n){this.variableNames=["A","B"],this.outputShape=xn(e,n),this.userCode="\n float binaryOperation(float a, float b) {\n "+t+"\n }\n\n void main() {\n float a = getAAtOutCoords();\n float b = getBAtOutCoords();\n setOutput(binaryOperation(a, b));\n }\n "},$n=function(t,e,n){this.variableNames=["A","B"],this.supportsBroadcasting=!0,this.usesPackedTextures=!0,this.outputShape=xn(e,n),this.userCode="\n vec4 binaryOperation(vec4 a, vec4 b) {\n "+t+"\n }\n\n void main() {\n vec4 a = getAAtOutCoords();\n vec4 b = getBAtOutCoords();\n setOutput(binaryOperation(a, b));\n }\n "},Kn=function(){function t(t){this.variableNames=["A"],this.outputShape=t,this.userCode="\n uniform float min;\n uniform float max;\n\n void main() {\n float value = getAAtOutCoords();\n if (isnan(value)) {\n setOutput(value);\n return;\n }\n\n setOutput(clamp(value, min, max));\n }\n "}return t.prototype.getCustomSetupFunc=function(n,r){var o=this;return function(t,e){null==o.minLoc&&(o.minLoc=t.getUniformLocationNoThrow(e,"min"),o.maxLoc=t.getUniformLocationNoThrow(e,"max")),t.gl.uniform1f(o.minLoc,n),t.gl.uniform1f(o.maxLoc,r)}},t}(),Xn=function(){function t(t){this.variableNames=["A"],this.usesPackedTextures=!0,this.outputShape=t,this.userCode="\n uniform float min;\n uniform float max;\n\n void main() {\n vec4 value = getAAtOutCoords();\n\n if (any(isnan(value))) {\n setOutput(value);\n return;\n }\n\n setOutput(clamp(value, vec4(min), vec4(max)));\n }\n "}return t.prototype.getCustomSetupFunc=function(n,r){var o=this;return function(t,e){null==o.minLoc&&(o.minLoc=t.getUniformLocationNoThrow(e,"min"),o.maxLoc=t.getUniformLocationNoThrow(e,"max")),t.gl.uniform1f(o.minLoc,n),t.gl.uniform1f(o.maxLoc,r)}},t}(),Yn=function(t){this.variableNames=["real","imag"],this.outputShape=t,this.userCode="\n void main() {\n float re = abs(getRealAtOutCoords());\n float im = abs(getImagAtOutCoords());\n float mx = max(re, im);\n\n // sadly the length function in glsl is not underflow-safe\n // (at least not on Intel GPUs). So the safe solution is\n // to ensure underflow-safety in all cases.\n setOutput(\n mx == 0.0 ? 0.0 : mx * length(vec2(1, min(re, im)/mx))\n );\n }\n "},Qn=function(t){this.outputShape=[],this.outputShape=Re(t,1),this.variableNames=t.map(function(t,e){return"T"+e});var e=new Array(t.length-1);e[0]=t[0][1];for(var n=1;n= "+t.inHeight+") {\n continue;\n }\n\n for (int yC = 0; yC < "+t.outWidth+"; yC++) {\n int xC = wC + yC * "+n+" - "+o+";\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n float dyValue = getDy(b, yR, yC, d2);\n float xValue = getX(b, xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n }\n setOutput(dotProd);\n }\n "},tr=function(t){this.variableNames=["dy","W"],this.outputShape=t.inShape;var e=t.filterHeight,n=t.filterWidth,r=t.strideHeight,o=t.strideWidth,i=e-1-t.padInfo.top,a=n-1-t.padInfo.left;this.userCode="\n const ivec2 pads = ivec2("+i+", "+a+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d1 = coords[3];\n\n ivec2 dyCorner = coords.yz - pads;\n int dyRCorner = dyCorner.x;\n int dyCCorner = dyCorner.y;\n\n // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < "+e+"; wR++) {\n float dyR = float(dyRCorner + wR) / "+r+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = "+e+" - 1 - wR;\n\n for (int wC = 0; wC < "+n+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+o+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = "+n+" - 1 - wC;\n\n for (int d2 = 0; d2 < "+t.outChannels+"; d2++) {\n float xValue = getDy(batch, idyR, idyC, d2);\n float wValue = getW(wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n }\n }\n }\n setOutput(dotProd);\n }\n "},er=function(t){this.variableNames=["x","dy"],this.outputShape=t.filterShape;var e=t.strideDepth,n=t.strideHeight,r=t.strideWidth,o=t.padInfo.front,i=t.padInfo.top,a=t.padInfo.left;this.userCode="\n void main() {\n ivec5 coords = getOutputCoords();\n int wF = coords.x;\n int wR = coords.y;\n int wC = coords.z;\n int d1 = coords.w;\n int d2 = coords.u;\n\n float dotProd = 0.0;\n\n for (int b = 0; b < "+t.batchSize+"; b++) {\n for (int yF = 0; yF < "+t.outDepth+"; yF++) {\n int xF = wF + yF * "+e+" - "+o+";\n\n if (xF < 0 || xF >= "+t.inDepth+") {\n continue;\n }\n\n for (int yR = 0; yR < "+t.outHeight+"; yR++) {\n int xR = wR + yR * "+n+" - "+i+";\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int yC = 0; yC < "+t.outWidth+"; yC++) {\n int xC = wC + yC * "+r+" - "+a+";\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n float dyValue = getDy(b, yF, yR, yC, d2);\n float xValue = getX(b, xF, xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n }\n }\n setOutput(dotProd);\n }\n "},nr=function(t){this.variableNames=["dy","W"],this.outputShape=t.inShape;var e=t.filterDepth,n=t.filterHeight,r=t.filterWidth,o=t.strideDepth,i=t.strideHeight,a=t.strideWidth,s=e-1-t.padInfo.front,u=n-1-t.padInfo.top,c=r-1-t.padInfo.left;this.userCode="\n const ivec3 pads = ivec3("+s+", "+u+", "+c+");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int d1 = coords.u;\n\n\n ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;\n int dyFCorner = dyCorner.x;\n int dyRCorner = dyCorner.y;\n int dyCCorner = dyCorner.z;\n\n float dotProd = 0.0;\n for (int wF = 0; wF < "+e+"; wF++) {\n float dyF = float(dyFCorner + wF) / "+o+".0;\n\n if (dyF < 0.0 || dyF >= "+t.outDepth+".0 || fract(dyF) > 0.0) {\n continue;\n }\n int idyF = int(dyF);\n\n int wFPerm = "+e+" - 1 - wF;\n\n for (int wR = 0; wR < "+n+"; wR++) {\n float dyR = float(dyRCorner + wR) / "+i+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 ||\n fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = "+n+" - 1 - wR;\n\n for (int wC = 0; wC < "+r+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+a+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = "+r+" - 1 - wC;\n\n for (int d2 = 0; d2 < "+t.outChannels+"; d2++) {\n float xValue = getDy(batch, idyF, idyR, idyC, d2);\n float wValue = getW(wFPerm, wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n }\n }\n }\n }\n setOutput(dotProd);\n }\n "},rr=function(t){this.variableNames=["x","dy"],this.outputShape=t.filterShape;var e=t.strideHeight,n=t.strideWidth,r=t.padInfo.top,o=t.padInfo.left,i=t.outChannels/t.inChannels;this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int wR = coords.x;\n int wC = coords.y;\n int d1 = coords.z;\n int dm = coords.w;\n int d2 = d1 * "+i+" + dm;\n\n float dotProd = 0.0;\n\n // TODO: Vec4 over the batch size\n for (int b = 0; b < "+t.batchSize+"; b++) {\n for (int yR = 0; yR < "+t.outHeight+"; yR++) {\n int xR = wR + yR * "+e+" - "+r+";\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int yC = 0; yC < "+t.outWidth+"; yC++) {\n int xC = wC + yC * "+n+" - "+o+";\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n float dyValue = getDy(b, yR, yC, d2);\n float xValue = getX(b, xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n }\n setOutput(dotProd);\n }\n "},or=function(t){this.variableNames=["dy","W"],this.outputShape=t.inShape;var e=t.filterHeight,n=t.filterWidth,r=t.strideHeight,o=t.strideWidth,i=e-1-t.padInfo.top,a=n-1-t.padInfo.left,s=t.outChannels/t.inChannels;this.userCode="\n const ivec2 pads = ivec2("+i+", "+a+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d1 = coords[3];\n ivec2 dyCorner = coords.yz - pads;\n int dyRCorner = dyCorner.x;\n int dyCCorner = dyCorner.y;\n\n float dotProd = 0.0;\n\n for (int wR = 0; wR < "+e+"; wR++) {\n float dyR = float(dyRCorner + wR) / "+r+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = "+e+" - 1 - wR;\n\n for (int wC = 0; wC < "+n+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+o+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = "+n+" - 1 - wC;\n\n // TODO: Vec4 over the channelMul\n for (int dm = 0; dm < "+s+"; dm++) {\n int d2 = d1 * "+s+" + dm;\n float xValue = getDy(batch, idyR, idyC, d2);\n float wValue = getW(wRPerm, wCPerm, d1, dm);\n dotProd += xValue * wValue;\n }\n }\n }\n setOutput(dotProd);\n }\n "},ir=function(t){this.variableNames=["x","W"],this.outputShape=t.outShape;var e=t.padInfo.top,n=t.padInfo.left,r=t.strideHeight,o=t.strideWidth,i=t.dilationHeight,a=t.dilationWidth,s=t.filterHeight,u=t.filterWidth,c=4*Math.floor(t.inChannels/4),l=t.inChannels%4;this.userCode="\n const ivec2 strides = ivec2("+r+", "+o+");\n const ivec2 pads = ivec2("+e+", "+n+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d2 = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < "+s+"; wR++) {\n int xR = xRCorner + wR * "+i+";\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+u+"; wC++) {\n int xC = xCCorner + wC * "+a+";\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n for (int d1 = 0; d1 < "+c+"; d1 += 4) {\n vec4 xValues = vec4(\n getX(batch, xR, xC, d1),\n getX(batch, xR, xC, d1 + 1),\n getX(batch, xR, xC, d1 + 2),\n getX(batch, xR, xC, d1 + 3)\n );\n vec4 wValues = vec4(\n getW(wR, wC, d1, d2),\n getW(wR, wC, d1 + 1, d2),\n getW(wR, wC, d1 + 2, d2),\n getW(wR, wC, d1 + 3, d2)\n );\n\n dotProd += dot(xValues, wValues);\n }\n\n if ("+(1===l)+") {\n dotProd +=\n getX(batch, xR, xC, "+c+") *\n getW(wR, wC, "+c+", d2);\n } else if ("+(2===l)+") {\n vec2 xValues = vec2(\n getX(batch, xR, xC, "+c+"),\n getX(batch, xR, xC, "+c+" + 1)\n );\n vec2 wValues = vec2(\n getW(wR, wC, "+c+", d2),\n getW(wR, wC, "+c+" + 1, d2)\n );\n dotProd += dot(xValues, wValues);\n } else if ("+(3===l)+") {\n vec3 xValues = vec3(\n getX(batch, xR, xC, "+c+"),\n getX(batch, xR, xC, "+c+" + 1),\n getX(batch, xR, xC, "+c+" + 2)\n );\n vec3 wValues = vec3(\n getW(wR, wC, "+c+", d2),\n getW(wR, wC, "+c+" + 1, d2),\n getW(wR, wC, "+c+" + 2, d2)\n );\n dotProd += dot(xValues, wValues);\n }\n }\n }\n setOutput(dotProd);\n }\n "},ar=function(t){this.variableNames=["x","W"],this.outputShape=t.outShape;var e=t.padInfo.front,n=t.padInfo.top,r=t.padInfo.left,o=t.strideDepth,i=t.strideHeight,a=t.strideWidth,s=t.dilationDepth,u=t.dilationHeight,c=t.dilationWidth,l=t.filterDepth,h=t.filterHeight,p=t.filterWidth,f=4*Math.floor(t.inChannels/4),d=t.inChannels%4;this.userCode="\n const ivec3 strides = ivec3("+o+", "+i+", "+a+");\n const ivec3 pads = ivec3("+e+", "+n+", "+r+");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int d2 = coords.u;\n\n ivec3 xFRCCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;\n int xFCorner = xFRCCorner.x;\n int xRCorner = xFRCCorner.y;\n int xCCorner = xFRCCorner.z;\n\n // Convolve x(?, ?, ?, d1) with w(:, :, :, d1, d2) to get\n // y(yF, yR, yC, d2). ? = to be determined. : = across all\n // values in that axis.\n float dotProd = 0.0;\n for (int wF = 0; wF < "+l+"; wF++) {\n int xF = xFCorner + wF * "+s+";\n\n if (xF < 0 || xF >= "+t.inDepth+") {\n continue;\n }\n\n for (int wR = 0; wR < "+h+"; wR++) {\n int xR = xRCorner + wR * "+u+";\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+p+"; wC++) {\n int xC = xCCorner + wC * "+c+";\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n for (int d1 = 0; d1 < "+f+"; d1 += 4) {\n vec4 xValues = vec4(\n getX(batch, xF, xR, xC, d1),\n getX(batch, xF, xR, xC, d1 + 1),\n getX(batch, xF, xR, xC, d1 + 2),\n getX(batch, xF, xR, xC, d1 + 3)\n );\n vec4 wValues = vec4(\n getW(wF, wR, wC, d1, d2),\n getW(wF, wR, wC, d1 + 1, d2),\n getW(wF, wR, wC, d1 + 2, d2),\n getW(wF, wR, wC, d1 + 3, d2)\n );\n\n dotProd += dot(xValues, wValues);\n }\n\n if ("+(1===d)+") {\n dotProd +=\n getX(batch, xF, xR, xC, "+f+") *\n getW(wF, wR, wC, "+f+", d2);\n } else if ("+(2===d)+") {\n vec2 xValues = vec2(\n getX(batch, xF, xR, xC, "+f+"),\n getX(batch, xF, xR, xC, "+f+" + 1)\n );\n vec2 wValues = vec2(\n getW(wF, wR, wC, "+f+", d2),\n getW(wF, wR, wC, "+f+" + 1, d2)\n );\n dotProd += dot(xValues, wValues);\n } else if ("+(3===d)+") {\n vec3 xValues = vec3(\n getX(batch, xF, xR, xC, "+f+"),\n getX(batch, xF, xR, xC, "+f+" + 1),\n getX(batch, xF, xR, xC, "+f+" + 2)\n );\n vec3 wValues = vec3(\n getW(wF, wR, wC, "+f+", d2),\n getW(wF, wR, wC, "+f+" + 1, d2),\n getW(wF, wR, wC, "+f+" + 2, d2)\n );\n dotProd += dot(xValues, wValues);\n }\n }\n }\n }\n setOutput(dotProd);\n }\n "},sr=function(t){this.variableNames=["x","W"],this.outputShape=t.outShape;var e=t.inHeight,n=t.inWidth,r=t.padInfo.top,o=t.padInfo.left,i=t.strideHeight,a=t.strideWidth,s=t.dilationHeight,u=t.dilationWidth,c=t.filterHeight,l=t.filterWidth,h=t.outChannels/t.inChannels;this.userCode="\n const ivec2 strides = ivec2("+i+", "+a+");\n const ivec2 pads = ivec2("+r+", "+o+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords.x;\n ivec2 xRCCorner = coords.yz * strides - pads;\n int d2 = coords.w;\n int d1 = d2 / "+h+";\n int q = d2 - d1 * "+h+";\n\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n // TODO(dsmilkov): Flatten the two for loops and vec4 the operations.\n for (int wR = 0; wR < "+c+"; wR++) {\n int xR = xRCorner + wR * "+s+";\n\n if (xR < 0 || xR >= "+e+") {\n continue;\n }\n\n for (int wC = 0; wC < "+l+"; wC++) {\n int xC = xCCorner + wC * "+u+";\n\n if (xC < 0 || xC >= "+n+") {\n continue;\n }\n\n float xVal = getX(batch, xR, xC, d1);\n float wVal = getW(wR, wC, d1, q);\n dotProd += xVal * wVal;\n }\n }\n setOutput(dotProd);\n }\n "},ur=function(t){this.variableNames=["x","W"],this.usesPackedTextures=!0,this.outputShape=t.outShape;for(var e=t.inHeight,n=t.inWidth,r=t.padInfo.top,o=t.padInfo.left,i=t.strideHeight,a=t.strideWidth,s=t.dilationHeight,u=t.dilationWidth,c=t.filterHeight,l=t.filterWidth,h=l,p="int xR; int xC; int xCOffset;",f=0;f= 0 && xR < "+e+" && xCOffset >= 0 && xCOffset < "+n+") {\n xTexelR"+f+"C"+d+" = getX(batch, xR, xCOffset, d1);\n } else {\n xTexelR"+f+"C"+d+" = vec4(0.);\n }\n\n xCOffset = xC + 1 - 2;\n if(xR >= 0 && xR < "+e+" && xCOffset >= 0 && xCOffset < "+n+") {\n vec4 previous = getX(batch, xR, xCOffset, d1);\n xR"+f+"C"+d+" = vec4(previous.zw, xTexelR"+f+"C"+d+".xy);\n } else {\n xR"+f+"C"+d+" = vec4(0, 0, xTexelR"+f+"C"+d+".xy);\n }\n ":"\n if(xR >= 0 && xR < "+e+" && xC >= 0 && xC < "+n+") {\n xTexelR"+f+"C"+d+" = getX(batch, xR, xC, d1);\n } else {\n xTexelR"+f+"C"+d+" = vec4(0.);\n }\n\n xR"+f+"C"+d+" = xTexelR"+f+"C"+d+";\n ",d+1= 0 && xR < "+e+" &&\n xCOffset >= 0 && xCOffset < "+n+") {\n xTexelR"+f+"C"+(d+2)+" = getX(batch, xR, xCOffset, d1);\n }\n ",1= 0 && xR < "+e+" &&\n xCOffset >= 0 && xCOffset < "+n+") {\n xTexelR"+f+"C"+d+" = getX(batch, xR, xCOffset, d1);\n } else {\n xTexelR"+f+"C"+d+" = vec4(0.);\n }\n "),p+="\n xR"+f+"C"+(d+1)+" = vec4(\n xTexelR"+f+"C"+d+".zw, xTexelR"+f+"C"+(d+2)+".xy);\n "):p+="\n xCOffset = xC + "+m+";\n\n if(xR >= 0 && xR < "+e+" &&\n xCOffset >= 0 && xCOffset < "+n+") {\n xTexelR"+f+"C"+(d+2)+" = getX(batch, xR, xCOffset, d1);\n }\n\n xR"+f+"C"+(d+1)+" = xTexelR"+f+"C"+(d+2)+";\n "}}else d= 0 && xR < "+e+") {\n ",o%2==1?(p+="\n xCOffset = xC + 1 - "+a+";\n if(xCOffset >= 0 && xCOffset < "+n+") {\n xTexelR"+f+"C"+d+" = getX(batch, xR, xCOffset, d1);\n } else {\n xTexelR"+f+"C"+d+" = vec4(0.);\n }\n\n if(xC + 1 >= 0 && xC + 1 < "+n+") {\n xTexelR"+f+"C"+(d+2)+" = getX(batch, xR, xC + 1, d1);\n } else {\n xTexelR"+f+"C"+(d+2)+" = vec4(0.);\n }\n\n xR"+f+"C"+d+" = vec4(\n xTexelR"+f+"C"+d+".zw, xTexelR"+f+"C"+(d+2)+".zw);\n ",d+1= 0 && xCOffset < "+n+") {\n final = getX(batch, xR, xCOffset, d1);\n }\n xR"+f+"C"+(d+1)+" = vec4(xTexelR"+f+"C"+(d+2)+".xy, final.xy);\n ")):(p+="\n if(xC >= 0 && xC < "+n+") {\n xTexelR"+f+"C"+d+" = getX(batch, xR, xC, d1);\n } else {\n xTexelR"+f+"C"+d+" = vec4(0.);\n }\n\n xCOffset = xC + "+a+";\n if(xCOffset >= 0 && xCOffset < "+n+") {\n xTexelR"+f+"C"+(d+2)+" = getX(batch, xR, xCOffset, d1);\n } else {\n xTexelR"+f+"C"+(d+2)+" = vec4(0.);\n }\n\n xR"+f+"C"+d+" = vec4(\n xTexelR"+f+"C"+d+".xy, xTexelR"+f+"C"+(d+2)+".xy);\n ",d+1= "+i+") {\n return;\n }\n\n float height_scale = "+y+";\n float width_scale = "+E+";\n\n float in_y = "+x+";\n if( in_y < 0.0 || in_y > "+d+" ) {\n setOutput(float("+o+"));\n return;\n }\n float in_x = "+C+";\n if( in_x < 0.0 || in_x > "+v+" ) {\n setOutput(float("+o+"));\n return;\n }\n\n vec2 sourceFracIndexCR = vec2(in_x,in_y);\n if("+p+" == 1) {\n // Compute the four integer indices.\n ivec2 sourceFloorCR = ivec2(sourceFracIndexCR);\n ivec2 sourceCeilCR = ivec2(ceil(sourceFracIndexCR));\n\n float topLeft = getImage(b, sourceFloorCR.y, sourceFloorCR.x, d);\n float bottomLeft = getImage(b, sourceCeilCR.y, sourceFloorCR.x, d);\n float topRight = getImage(b, sourceFloorCR.y, sourceCeilCR.x, d);\n float bottomRight = getImage(b, sourceCeilCR.y, sourceCeilCR.x, d);\n\n vec2 fracCR = sourceFracIndexCR - vec2(sourceFloorCR);\n\n float top = topLeft + (topRight - topLeft) * fracCR.x;\n float bottom = bottomLeft + (bottomRight - bottomLeft) * fracCR.x;\n float newValue = top + (bottom - top) * fracCR.y;\n setOutput(newValue);\n } else {\n // Compute the coordinators of nearest neighbor point.\n ivec2 sourceNearestCR = ivec2(floor(\n sourceFracIndexCR + vec2(0.5,0.5)));\n float newValue = getImage(b, sourceNearestCR.y, sourceNearestCR.x, d);\n setOutput(newValue);\n }\n }\n "},lr=function(t,e,n){this.variableNames=["x"];var r=(this.outputShape=t).length,o=t[t.length-1],i=n?"<":">";this.userCode="\n int getIndex(int i) {\n "+(n?"return "+o+" -i - 1;":"return i;")+"\n }\n\n void main() {\n "+Dn(r)+" coords = getOutputCoords();\n int end = "+hr(r,"coords")+";\n float val = 0.0;\n for (int i = "+o+" - 1; i >= 0; i -= 1) {\n int idx = getIndex(i);\n if (idx "+i+" end) {\n continue;\n }\n if (idx == end && "+e+") {\n continue;\n }\n "+hr(r,"coords")+" = idx;\n val += getX("+function(t,e){if(1===t)return""+e;if(2===t)return e+".x, "+e+".y";if(3===t)return e+".x, "+e+".y, "+e+".z";if(4===t)return e+".x, "+e+".y, "+e+".z, "+e+".w";throw Error("Cumulative sum for rank "+t+" is not yet supported")}(r,"coords")+");\n }\n setOutput(val);\n }\n "};function hr(t,e){if(1===t)return""+e;if(2===t)return e+".y";if(3===t)return e+".z";if(4===t)return e+".w";throw Error("Cumulative sum for rank "+t+" is not yet supported")}var pr=function(){function t(t,e,n){this.variableNames=["x"],this.outputShape=[],this.outputShape=t,this.blockSize=e,this.dataFormat=n,this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int h = "+this.getHeightCoordString()+";\n int w = "+this.getWidthCoordString()+";\n int d = "+this.getDepthCoordString()+";\n\n int in_h = h / "+e+";\n int offset_h = imod(h, "+e+");\n int in_w = w / "+e+";\n int offset_w = imod(w, "+e+");\n int offset_d = (offset_h * "+e+" + offset_w) *\n "+this.getOutputDepthSize()+";\n int in_d = d + offset_d;\n\n float result = "+this.getInputSamplingString()+";\n setOutput(result);\n }\n "}return t.prototype.getHeightCoordString=function(){return"NHWC"===this.dataFormat?"coords[1]":"coords[2]"},t.prototype.getWidthCoordString=function(){return"NHWC"===this.dataFormat?"coords[2]":"coords[3]"},t.prototype.getDepthCoordString=function(){return"NHWC"===this.dataFormat?"coords[3]":"coords[1]"},t.prototype.getOutputDepthSize=function(){return"NHWC"===this.dataFormat?this.outputShape[3]:this.outputShape[1]},t.prototype.getInputSamplingString=function(){return"NHWC"===this.dataFormat?"getX(b, in_h, in_w, in_d)":"getX(b, in_d, in_h, in_w)"},t}(),fr=function(t){this.variableNames=["A"];var e=wn();this.outputShape=t,this.userCode="\n const float FLOAT_MAX = 1.70141184e38;\n const float FLOAT_MIN = 1.17549435e-38;\n\n lowp vec4 encode_float(highp float v) {\n if (isnan(v)) {\n return vec4(255, 255, 255, 255);\n }\n\n highp float av = abs(v);\n\n if(av < FLOAT_MIN) {\n return vec4(0.0, 0.0, 0.0, 0.0);\n } else if(v > FLOAT_MAX) {\n return vec4(0.0, 0.0, 128.0, 127.0) / 255.0;\n } else if(v < -FLOAT_MAX) {\n return vec4(0.0, 0.0, 128.0, 255.0) / 255.0;\n }\n\n highp vec4 c = vec4(0,0,0,0);\n\n highp float e = floor(log2(av));\n highp float m = exp2(fract(log2(av))) - 1.0;\n\n c[2] = floor(128.0 * m);\n m -= c[2] / 128.0;\n c[1] = floor(32768.0 * m);\n m -= c[1] / 32768.0;\n c[0] = floor(8388608.0 * m);\n\n highp float ebias = e + 127.0;\n c[3] = floor(ebias / 2.0);\n ebias -= c[3] * 2.0;\n c[2] += floor(ebias) * 128.0;\n\n c[3] += 128.0 * step(0.0, -v);\n\n return c / 255.0;\n }\n\n void main() {\n float x = getAAtOutCoords();\n "+e.output+" = encode_float(x);\n }\n "},dr="return real * expR - imag * expI;",vr="return real * expI + imag * expR;",mr=function(t,e,n){this.variableNames=["real","imag"];var r=e[1];this.outputShape=e;var o=n?"2.0 * "+Math.PI:"-2.0 * "+Math.PI,i=n?r+".0":"1.0";this.userCode="\n const float exponentMultiplier = "+o+";\n\n float unaryOpComplex(float real, float expR, float imag, float expI) {\n "+t+"\n }\n\n float mulMatDFT(int batch, int index) {\n float indexRatio = float(index) / float("+r+");\n float exponentMultiplierTimesIndexRatio =\n exponentMultiplier * indexRatio;\n\n float result = 0.0;\n\n for (int i = 0; i < "+r+"; i++) {\n // x = (-2|2 * PI / N) * index * i;\n float x = exponentMultiplierTimesIndexRatio * float(i);\n float expR = cos(x);\n float expI = sin(x);\n float real = getReal(batch, i);\n float imag = getImag(batch, i);\n\n result +=\n unaryOpComplex(real, expR, imag, expI) / "+i+";\n }\n\n return result;\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n setOutput(mulMatDFT(coords[0], coords[1]));\n }\n "},gr=function(){function t(t,e){this.outputShape=[],this.variableNames=["x"],this.outputShape=t,this.userCode="\n uniform float value;\n void main() {\n // Input can be obtained from uniform value.\n setOutput(value);\n }\n "}return t.prototype.getCustomSetupFunc=function(n){var r=this;return function(t,e){null==r.valueLoc&&(r.valueLoc=t.getUniformLocationNoThrow(e,"value")),t.gl.uniform1f(r.valueLoc,n)}},t}(),yr=function(t){this.variableNames=["A"];var e=wn(),n=t[0],r=t[1];this.outputShape=t,this.userCode="\n void main() {\n ivec3 coords = getOutputCoords();\n int texR = coords[0];\n int texC = coords[1];\n int depth = coords[2];\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2("+r+".0, "+n+".0);\n\n vec4 values = "+e.texture2D+"(A, uv);\n float value;\n if (depth == 0) {\n value = values.r;\n } else if (depth == 1) {\n value = values.g;\n } else if (depth == 2) {\n value = values.b;\n } else if (depth == 3) {\n value = values.a;\n }\n\n setOutput(floor(value * 255.0 + 0.5));\n }\n "},xr=function(t,e,n){this.variableNames=["A","indices"];var r=t.slice();r[n]=e,this.outputShape=r,this.rank=r.length;var o=Dn(this.rank),i=function(t,e){var n=t.length;if(4= "+r);for(var o=0,i=0;i= "+i);for(var a=r%2==1,s=n%2==1,u=Math.floor(r/2),c=Math.floor(n/2),l=Math.ceil(r/2),h=l*Math.ceil(n/2),p=_(n)*_(r),f=0;f=n.length-2?_(n[e]):n[e]})).length&&(n=[2,n[0]])),2!==n.length){var o=I(n);n=o.newShape}var i=B(n);if(n.length<=1&&i<=r)return[1,i];if(2===n.length&&n[0]<=r&&n[1]<=r)return n;if(3===n.length&&n[0]*n[1]<=r&&n[2]<=r)return[n[0]*n[1],n[2]];if(3===n.length&&n[0]<=r&&n[1]*n[2]<=r)return[n[0],n[1]*n[2]];if(4===n.length&&n[0]*n[1]*n[2]<=r&&n[3]<=r)return[n[0]*n[1]*n[2],n[3]];if(4===n.length&&n[0]<=r&&n[1]*n[2]*n[3]<=r)return[n[0],n[1]*n[2]*n[3]];if(t){var a=oo(n),s=2,u=2;return n.length&&(s=(e=io(n))[0],u=e[1]),b(i=a*(s/2)*(u/2)).map(function(t){return 2*t})}return b(i)}function so(t){return t%2==0}function uo(t,e){if(E(t=t.slice(-2),e=e.slice(-2)))return!0;if(!t.length||!e.length)return!0;if(0===t[0]||0===t[1]||0===e[0]||0===e[1])return!0;if(t.length!==e.length){var n=t.slice(-1)[0],r=e.slice(-1)[0];if(n===r)return!0;if(so(n)&&so(r)&&(1===t[0]||1===e[0]))return!0}return t[1]===e[1]&&so(t[0])&&so(e[0])}var co=Object.freeze({callAndCheck:Ar,canBeRepresented:Dr,getWebGLErrorMessage:Mr,getExtensionOrThrow:Or,createVertexShader:Pr,createFragmentShader:Fr,createProgram:Br,linkProgram:Wr,validateProgram:zr,createStaticVertexBuffer:Ur,createStaticIndexBuffer:Gr,getNumChannels:Vr,createTexture:Hr,validateTextureSize:qr,createFramebuffer:jr,bindVertexBufferToProgramAttribute:$r,bindTextureUnit:Kr,unbindTextureUnit:function(t,e,n){ro(t,n),Ar(t,e,function(){return t.activeTexture(t.TEXTURE0+n)}),Ar(t,e,function(){return t.bindTexture(t.TEXTURE_2D,null)})},getProgramUniformLocationOrThrow:Xr,getProgramUniformLocation:Yr,bindTextureToProgramUniformSampler:Qr,bindCanvasToFramebuffer:function(t,e){Ar(t,e,function(){return t.bindFramebuffer(t.FRAMEBUFFER,null)}),Ar(t,e,function(){return t.viewport(0,0,t.canvas.width,t.canvas.height)}),Ar(t,e,function(){return t.scissor(0,0,t.canvas.width,t.canvas.height)})},bindColorTextureToFramebuffer:Jr,unbindColorTextureFromFramebuffer:Zr,validateFramebuffer:to,getFramebufferErrorMessage:eo,getBatchDim:oo,getRowsCols:io,getTextureShapeFromLogicalShape:ao,isReshapeFree:uo});function lo(t,e){var n=wn();return Pr(t,e,n.version+"\n precision highp float;\n "+n.attribute+" vec3 clipSpacePos;\n "+n.attribute+" vec2 uv;\n "+n.varyingVs+" vec2 resultUV;\n\n void main() {\n gl_Position = vec4(clipSpacePos, 1);\n resultUV = uv;\n }")}function ho(t,e){return Ur(t,e,new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,-1,0,1,0]))}function po(t,e){return Gr(t,e,new Uint16Array([0,1,2,2,1,3]))}function fo(t,e){var n,r,o,i,a,s,u,c,l=t;return c=2===Zt.get("WEBGL_VERSION")?(n=l.R32F,r=l.R16F,o=l.RGBA16F,i=l.RGBA32F,a=l.RED,s=4,u=1,l.HALF_FLOAT):(n=t.RGBA,r=t.RGBA,o=t.RGBA,i=l.RGBA,a=t.RGBA,u=s=4,null!=e?e.HALF_FLOAT_OES:null),{internalFormatFloat:n,internalFormatHalfFloat:r,internalFormatPackedHalfFloat:o,internalFormatPackedFloat:i,textureFormatFloat:a,downloadTextureFormat:t.RGBA,downloadUnpackNumChannels:s,defaultNumChannels:u,textureTypeHalfFloat:c}}function vo(t,e,n,r,o,i,a){qr(n,r);var s=Hr(t,e),u=t.TEXTURE_2D;return Ar(t,e,function(){return t.bindTexture(u,s)}),Ar(t,e,function(){return t.texParameteri(u,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)}),Ar(t,e,function(){return t.texParameteri(u,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)}),Ar(t,e,function(){return t.texParameteri(u,t.TEXTURE_MIN_FILTER,t.NEAREST)}),Ar(t,e,function(){return t.texParameteri(u,t.TEXTURE_MAG_FILTER,t.NEAREST)}),Ar(t,e,function(){return t.texImage2D(u,0,o,n,r,0,i,a,null)}),Ar(t,e,function(){return t.bindTexture(t.TEXTURE_2D,null)}),s}function mo(t,e,n,r,o){var i=Sr(n,r);return vo(t,e,i[0],i[1],o.internalFormatFloat,o.textureFormatFloat,t.FLOAT)}function go(t,e,n,r,o){var i=Sr(n,r);return vo(t,e,i[0],i[1],o.internalFormatHalfFloat,o.textureFormatFloat,o.textureTypeHalfFloat)}function yo(t,e,n,r,o){var i=Sr(n,r);return vo(t,e,i[0],i[1],t.RGBA,t.RGBA,t.UNSIGNED_BYTE)}function xo(t,e,n,r,o){var i=kr(n,r);return vo(t,e,i[0],i[1],o.internalFormatPackedFloat,t.RGBA,t.FLOAT)}function wo(t,e,n,r,o){var i=kr(n,r);return vo(t,e,i[0],i[1],o.internalFormatPackedHalfFloat,t.RGBA,o.textureTypeHalfFloat)}function bo(t,e,n,r){return Ar(t,e,function(){return t.bindBuffer(t.ARRAY_BUFFER,r)}),$r(t,e,n,"clipSpacePos",r,3,20,0)&&$r(t,e,n,"uv",r,2,20,12)}function Eo(t,e,n,r){Ar(t,e,function(){return t.bindTexture(t.TEXTURE_2D,n)}),Ar(t,e,function(){return t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,r)}),Ar(t,e,function(){return t.bindTexture(t.TEXTURE_2D,null)})}function Co(t,e,n,r,o,i,a){qr(r,o),Ar(t,e,function(){return t.bindTexture(t.TEXTURE_2D,n)}),Ar(t,e,function(){return t.texSubImage2D(t.TEXTURE_2D,0,0,0,r,o,a,t.FLOAT,i)}),Ar(t,e,function(){return t.bindTexture(t.TEXTURE_2D,null)})}function _o(t,e,n,r,o,i,a,s){var u,c=Sr(r,o),l=c[0],h=c[1],p=r*o;1===s.defaultNumChannels&&p===i.length?u=i:function(t,e,n){var r=Rr(t.length,n);if(e.length= "+r);for(var o=0,i=0;i= "+t[1]+" || pos >= "+t[0]+") continue;\n\n int offsetY = int(blockIndex / ("+u+")) * "+a+" - "+p+";\n int d0 = offsetY + "+l+" * (pos / "+f+");\n\n if(d0 >= "+e[0]+" || d0 < 0) continue;\n\n int offsetX = int(mod(float(blockIndex), "+u+".) * "+i+". - "+h+".);\n int d1 = offsetX + "+c+" * (int(mod(float(pos), "+f+".) / "+o+".));\n\n if(d1 >= "+e[1]+" || d1 < 0) continue;\n\n vec2 innerDims = vec2(d1, int(mod(float(pos), "+o+".)));\n result[row * 2 + col] = getChannel(getA(d0, int(innerDims.x),\n int(innerDims.y)), innerDims);\n }\n }\n\n "+d.output+" = result;\n }\n "},Fo=function(t,e,n,r,o){this.variableNames=["x"],this.outputShape=[];var i,a=e,s=t[3]-1;this.outputShape=t;var u="float("+n+") + float("+r+") * sum";i=.5===o?"inversesqrt("+u+")":1===o?"1.0/("+u+")":"exp(log("+u+") * float(-"+o+"));",this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n int d = coords[3];\n float x = getX(b, r, c, d);\n float sum = 0.0;\n for (int j = -"+a+"; j <= "+a+"; j++) {\n int idx = d + j;\n if (idx >= 0 && idx <= "+s+") {\n float z = getX(b, r, c, idx);\n sum += z * z;\n }\n }\n float val = x * "+i+";\n setOutput(val);\n }\n "},Lo=function(t,e,n,r,o){this.variableNames=["inputImage","outputImage","dy"],this.outputShape=[],this.outputShape=t,this.depth=t[3],this.depthRadius=e,this.bias=n,this.alpha=r,this.beta=o,this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n\n float result = 0.0;\n for (int d = 0; d < "+this.depth+"; ++d) {\n int depthBegin = int(max(0.0, float(d - "+e+")));\n int depthEnd = int(min(float("+this.depth+"),\n float(d + "+e+" + 1)));\n\n const int MIN_DEPTH_BEGIN = 0;\n const int MAX_DEPTH_END = "+this.depth+";\n\n float norm = 0.0;\n for (int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k) {\n if (k < depthBegin){\n continue;\n }\n else if (k >= depthBegin && k < depthEnd) {\n norm += getInputImage(b, r, c, k) * getInputImage(b, r, c, k);\n }\n else {\n break;\n }\n }\n\n norm = float("+r+") * norm + float("+n+");\n\n for(int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k){\n if (k < depthBegin){\n continue;\n }\n else if (k >= depthBegin && k < depthEnd){\n float dyi = -2.0 * float("+r+")\n * float("+o+")\n * getInputImage(b ,r ,c, k) * getOutputImage(b, r, c, d)\n / norm;\n if (k == d) {\n dyi += pow(norm, -1.0 * "+o+");\n }\n if (k == coords[3]) {\n dyi *= getDy(b, r, c, d);\n result += dyi;\n }\n }\n else {\n break;\n }\n }\n }\n setOutput(result);\n }\n "},Bo=function(t){this.variableNames=["dy","maxPos"],this.outputShape=t.inShape;var e=t.strideHeight,n=t.strideWidth,r=t.dilationHeight,o=t.effectiveFilterHeight,i=t.effectiveFilterWidth,a=o-1-t.padInfo.top,s=i-1-t.padInfo.left,u=o*i-1;this.userCode="\n const ivec2 pads = ivec2("+a+", "+s+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < "+o+";\n wR += "+r+") {\n float dyR = float(dyRCorner + wR) / "+e+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < "+i+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+n+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n int maxPosValue = "+u+" - int(getMaxPos(b, idyR, idyC, d));\n\n // Get the current value, check it against the value from the\n // position matrix.\n int curPosValue = wR * "+i+" + wC;\n float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\n\n dotProd += dyValue * mask;\n }\n }\n setOutput(dotProd);\n }\n "},Wo=function(t,e,n,r,o,i){void 0===n&&(n=!1),void 0===r&&(r=!1),void 0===o&&(o=!1),void 0===i&&(i=null),this.variableNames=["matrixA","matrixB"],this.usesPackedTextures=!0,this.outputShape=e;var a=n?t[1]:t[2],s=Math.ceil(a/2),u=n?"i * 2, rc.y":"rc.y, i * 2",c=r?"rc.z, i * 2":"i * 2, rc.z",l=n?["a.xxyy","a.zzww"]:["a.xxzz","a.yyww"],h=r?["b.xzxz","b.ywyw"]:["b.xyxy","b.zwzw"],p="",f="";i&&(p="vec4 activation(vec4 x) {\n "+i+"\n }",f="result = activation(result);");var d=o?"result += getBiasAtOutCoords();":"";o&&this.variableNames.push("bias"),this.userCode="\n "+p+"\n\n const float sharedDimension = "+s+".0;\n\n vec4 dot2x2ARowBCol(ivec3 rc) {\n vec4 result = vec4(0);\n for (int i = 0; i < "+s+"; i++) {\n vec4 a = getMatrixA(rc.x, "+u+");\n vec4 b = getMatrixB(rc.x, "+c+");\n\n result += ("+l[0]+" * "+h[0]+") + ("+l[1]+" * "+h[1]+");\n }\n return result;\n }\n\n void main() {\n ivec3 rc = getOutputCoords();\n vec4 result = dot2x2ARowBCol(rc);\n\n "+d+"\n\n "+f+"\n\n setOutput(result);\n }\n "},zo=function(){function t(t,e,n){this.variableNames=["probs"],this.outputShape=[t,n],this.userCode="\n uniform float seed;\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n\n float r = random(seed);\n float cdf = 0.0;\n\n for (int i = 0; i < "+(e-1)+"; i++) {\n cdf += getProbs(batch, i);\n\n if (r < cdf) {\n setOutput(float(i));\n return;\n }\n }\n\n // If no other event happened, last event happened.\n setOutput(float("+(e-1)+"));\n }\n "}return t.prototype.getCustomSetupFunc=function(n){var r=this;return function(t,e){null==r.seedLoc&&(r.seedLoc=t.getUniformLocation(e,"seed")),t.gl.uniform1f(r.seedLoc,n)}},t}(),Uo=function(t,e,n,r){this.variableNames=["indices"],this.outputShape=[t,e],this.userCode="\n void main() {\n ivec2 coords = getOutputCoords();\n int index = round(getIndices(coords.x));\n setOutput(mix(float("+r+"), float("+n+"),\n float(index == coords.y)));\n }\n "},Go=function(t){this.variableNames=["A"],this.isPackShader=!0;var e,n,r,o,i=(this.outputShape=t).length;if(0===i)this.userCode="\n void main() {\n setOutput(vec4(getA(), 0., 0., 0.));\n }\n ";else{var a=mn("rc",i),s=Dn(i),u=function(t,e,n){if(1===t)return"rc > "+e[0];for(var r="",o=t-2;o= "+e[o],o= "+e+";\n bool rEdge = rp1 >= "+n+";\n "}(i,t[t.length-1],t[t.length-2],a),l=(n=a,r=(e=t).length,o=function(t,e){for(var n=[],r=0;r<=1;r++)for(var o=0;o<=1;o++){for(var i=(0===r?"r":"rp1")+", "+(0===o?"c":"cp1"),a=2;a= "+e[0]+" ? 0. : getA(rc + 1),\n 0, 0":"getA("+o[0]+"),\n cEdge ? 0. : getA("+o[1]+"),\n rEdge ? 0. : getA("+o[2]+"),\n rEdge || cEdge ? 0. : getA("+o[3]+")");this.userCode="\n void main() {\n "+s+" rc = getOutputCoords();\n\n if("+u+") {\n setOutput(vec4(0));\n } else {\n "+c+"\n\n setOutput(vec4("+l+"));\n }\n }\n "}};var Vo=function(n,t,e){this.variableNames=["x"],this.outputShape=t.map(function(t,e){return t[0]+n[e]+t[1]});var r=n.length,o=Dn(r),i=t.map(function(t){return t[0]}).join(","),a=t.map(function(t,e){return t[0]+n[e]}).join(","),s=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,r);this.userCode=1!==r?"\n "+o+" start = "+o+"("+i+");\n "+o+" end = "+o+"("+a+");\n\n void main() {\n "+o+" outC = getOutputCoords();\n if (any(lessThan(outC, start)) || any(greaterThanEqual(outC, end))) {\n setOutput(float("+e+"));\n } else {\n "+o+" coords = outC - start;\n setOutput(getX("+s+"));\n }\n }\n ":"\n int start = "+i+";\n int end = "+a+";\n\n void main() {\n int outC = getOutputCoords();\n if (outC < start || outC >= end) {\n setOutput(float("+e+"));\n } else {\n setOutput(getX(outC - start));\n }\n }\n "},Ho=function(n,t,e){this.variableNames=["x"],this.usesPackedTextures=!0,this.outputShape=t.map(function(t,e){return t[0]+n[e]+t[1]});for(var r=n.length,o=Dn(r),i=t.map(function(t){return t[0]}).join(","),a=t.map(function(t,e){return t[0]+n[e]}).join(","),s=mn("rc",r),u=mn("source",r),c=s[r-1]+" < "+this.outputShape[r-1],l=1===r?"source":"vec2("+u.slice(-2).join()+")",h=[o+" rc = outputLoc;",s[r-1]+" += 1;\n if("+c+") {\n ",1===r?"":"}\n rc = outputLoc;\n "+s[r-2]+" += 1;\n if("+s[r-2]+" < "+this.outputShape[r-2]+") {",1===r?"":" "+s[r-1]+" += 1;\n if("+c+") {"],p=1===r?"rc < start || rc >= end":"any(lessThan(rc, start)) || any(greaterThanEqual(rc, end))",f="",d=0,v=1===r?2:4;d= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+c+";\n wC += "+s+") {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n float value = getX(batch, xR, xC, d);\n\n // If a min / max value has already been found, use it. If not,\n // use the current value.\n float currMinMaxValue = mix(\n value, minMaxValue, minMaxValueFound);\n if (value >= currMinMaxValue) {\n minMaxValue = value;\n minMaxValueFound = 1.0;\n minMaxPosition = wR * "+c+" + wC;\n }\n }\n }\n setOutput(float(minMaxPosition));\n }\n ";else{var d=e+"("+e+"("+e+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";"avg"===e&&(d="avgValue / count");var v=4*Math.floor(r/4),m=r%4,g="\n if ("+p+") {\n avgValue += dot(values, ones);\n } else {\n minMaxValue = max(values, minMaxValue);\n }\n ";this.userCode="\n const ivec2 strides = ivec2("+o+", "+i+");\n const ivec2 pads = ivec2("+l+", "+h+");\n const float initializationValue = "+f+";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float count = 0.0;\n\n float getValue(int batch, int xR, int xC, int d) {\n if (xC < 0 || xC >= "+t.inWidth+") {\n return initializationValue;\n }\n count += 1.0;\n return getX(batch, xR, xC, d);\n }\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n vec4 minMaxValue = vec4("+f+");\n float avgValue = 0.0;\n count = 0.0;\n\n for (int wR = 0; wR < "+u+";\n wR += "+a+") {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+v+"; wC += 4) {\n int xC = xCCorner + wC * "+s+";\n\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + "+s+", d),\n getValue(batch, xR, xC + 2 * "+s+", d),\n getValue(batch, xR, xC + 3 * "+s+", d)\n );\n\n "+g+"\n }\n\n int xC = xCCorner + "+v+";\n if ("+(1===m)+") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n "+g+"\n } else if ("+(2===m)+") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + "+s+", d),\n initializationValue,\n initializationValue\n );\n\n "+g+"\n } else if ("+(3===m)+") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + "+s+", d),\n getValue(batch, xR, xC + 2 * "+s+", d),\n initializationValue\n );\n\n "+g+"\n }\n }\n setOutput("+d+");\n }\n "}},jo=function(t,e){this.variableNames=["x"];var n=t.windowSize,r=t.batchSize,o=t.inSize,i=Math.ceil(o/n);this.outputShape=[r,i];var a="0.0",s="";"prod"===e?a="1.0":"min"===e?(a="1.0 / 1e-20",s="min"):"max"===e&&(a="-1.0 / 1e-20",s="max");var u=e+"("+e+"("+e+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";"sum"===e?u="sumValue":"prod"===e?u="prodValue":"all"===e?u="allValue":"any"===e&&(u="anyValue");var c=4*Math.floor(n/4),l=n%4,h="\n if ("+("sum"===e)+") {\n sumValue += dot(values, ones);\n } else if ("+("prod"===e)+") {\n vec2 tmp = vec2(values[0], values[1]) * vec2(values[2], values[3]);\n prodValue *= tmp[0] * tmp[1];\n } else {\n minMaxValue = "+s+"(values, minMaxValue);\n }\n ",p="vec4";"all"===e?(a="1.0",h="\n bool reducedAllValue = all(values);\n float floatedReducedAllValue = float(reducedAllValue);\n allValue = float(allValue >= 1.0 && floatedReducedAllValue >= 1.0);\n ",p="bvec4"):"any"===e&&(a="0.0",h="\n bool reducedAnyValue = any(values);\n float floatedReducedAnyValue = float(reducedAnyValue);\n anyValue = float(anyValue >= 1.0 || floatedReducedAnyValue >= 1.0);\n ",p="bvec4");var f="";0= "+o+") {\n return initializationValue;\n }\n "),this.userCode="\n const float initializationValue = "+a+";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float getValue(int batch, int inIdx) {\n "+f+"\n return getX(batch, inIdx);\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * "+n+";\n\n vec4 minMaxValue = vec4("+a+");\n float prodValue = 1.0;\n float sumValue = 0.0;\n float allValue = 1.0;\n float anyValue = 0.0;\n\n for (int i = 0; i < "+c+"; i += 4) {\n int inIdx = inOffset + i;\n "+p+" values = "+p+"(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n getValue(batch, inIdx + 3)\n );\n\n "+h+"\n }\n\n int inIdx = inOffset + "+c+";\n if ("+(1===l)+") {\n "+p+" values = "+p+"(\n getValue(batch, inIdx),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n "+h+"\n } else if ("+(2===l)+") {\n "+p+" values = "+p+"(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n initializationValue,\n initializationValue\n );\n\n "+h+"\n } else if ("+(3===l)+") {\n "+p+" values = "+p+"(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n initializationValue\n );\n\n "+h+"\n }\n setOutput("+u+");\n }\n "},$o=function(t,e){this.variableNames=["A"],this.usesPackedTextures=!0,this.outputShape=t;for(var n="",r=0;r<4;r++){var o="thisRC = rc;";r%2==1&&(o+="thisRC.z += 1;"),1= "+s+") {\n continue;\n }\n\n for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {\n int dyC = dyCOffset + startDyC;\n\n // Guard against the window exceeding the bounds of dy\n if (dyC < 0 || dyC >= "+u+") {\n continue;\n }\n\n float dxR = float(dyR) * heightScale;\n int topDxRIndex = int(floor(dxR));\n int bottomDxRIndex = int(min(ceil(dxR), "+(o-1)+".0));\n float dxRLerp = dxR - float(topDxRIndex);\n float inverseDxRLerp = 1.0 - dxRLerp;\n\n float dxC = float(dyC) * widthScale;\n int leftDxCIndex = int(floor(dxC));\n int rightDxCIndex = int(min(ceil(dxC), "+(i-1)+".0));\n float dxCLerp = dxC - float(leftDxCIndex);\n float inverseDxCLerp = 1.0 - dxCLerp;\n\n if (r == topDxRIndex && c == leftDxCIndex) {\n // topLeft\n accumulator +=\n getDy(b, dyR, dyC, d) * inverseDxRLerp * inverseDxCLerp;\n }\n\n if (r == topDxRIndex && c == rightDxCIndex) {\n // topRight\n accumulator += getDy(b, dyR, dyC, d) * inverseDxRLerp * dxCLerp;\n }\n\n if (r == bottomDxRIndex && c == leftDxCIndex) {\n // bottomLeft\n accumulator += getDy(b, dyR, dyC, d) * dxRLerp * inverseDxCLerp;\n }\n\n if (r == bottomDxRIndex && c == rightDxCIndex) {\n // bottomRight\n accumulator += getDy(b, dyR, dyC, d) * dxRLerp * dxCLerp;\n }\n }\n }\n // End loop over dy\n\n setOutput(accumulator);\n }\n "},Xo=function(t,e,n,r){this.variableNames=["A"],this.outputShape=[];var o=t[0],i=t[1],a=t[2],s=t[3];this.outputShape=[o,e,n,s];var u=[r&&1= "+s+") {\n continue;\n }\n\n for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {\n int dyC = dyCOffset + startDyC;\n\n // Guard against the window exceeding the bounds of dy\n if (dyC < 0 || dyC >= "+u+") {\n continue;\n }\n\n float sourceFracRow =\n float("+c[0]+") *\n (float(dyR) / float("+l[0]+"));\n\n float sourceFracCol =\n float("+c[1]+") *\n (float(dyC) / float("+l[1]+"));\n\n int sourceNearestRow = int(min(\n float(int("+o+") - 1),\n "+n+" ? float(round(sourceFracRow)) :\n float(floor(sourceFracRow))));\n\n int sourceNearestCol = int(min(\n float(int("+i+") - 1),\n "+n+" ? float(round(sourceFracCol)) :\n float(floor(sourceFracCol))));\n\n if (r == sourceNearestRow && c == sourceNearestCol) {\n accumulator += getDy(b, dyR, dyC, d);\n }\n }\n }\n // End loop over dy\n\n setOutput(accumulator);\n }\n "},Jo=function(t,e,n,r){this.variableNames=["A"],this.outputShape=[];var o=t[0],i=t[1],a=t[2],s=t[3];this.outputShape=[o,e,n,s];var u=[r&&1= 1.0) {\n setOutput(getA("+o+"));\n } else {\n setOutput(getB("+o+"));\n }\n }\n "},oi=function(){function t(t){this.variableNames=["source"],this.outputShape=t,this.rank=t.length;var e,n=Dn(this.rank),r="uniform int start["+this.rank+"];",o=function(t){if(1===t)return"sourceLoc";if(t<=6)return ii.slice(0,t).map(function(t){return"sourceLoc."+t}).join(",");throw Error("Slicing for rank "+t+" is not yet supported")}(this.rank);e="\n "+n+" sourceLoc;\n "+n+" coords = getOutputCoords();\n "+t.map(function(t,e){return"sourceLoc."+ii[e]+" = start["+e+"] + coords."+ii[e]+";"}).join("\n")+"\n ",this.userCode="\n "+r+"\n void main() {\n "+e+"\n setOutput(getSource("+o+"));\n }\n "}return t.prototype.getCustomSetupFunc=function(n){var r=this;if(n.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the length of start ("+n.length+")");return function(t,e){null==r.startLoc&&(r.startLoc=t.getUniformLocationNoThrow(e,"start"),null==r.startLoc)||t.gl.uniform1iv(r.startLoc,n)}},t}(),ii=["x","y","z","w","u","v"];var ai=function(){function t(t){this.variableNames=["source"],this.usesPackedTextures=!0,this.outputShape=t,this.rank=t.length;var e=Dn(this.rank),n=mn("coords",this.rank),r=mn("sourceLoc",this.rank),o=1===this.rank?"sourceLoc":"vec2("+r.slice(-2).join()+")",i="getChannel(getSource("+r.join()+"), "+o+")",a="\n result.x = "+i+";\n if (++"+n[this.rank-1]+" < "+t[this.rank-1]+") {\n ++"+r[this.rank-1]+";\n result.y = "+i+";\n --"+r[this.rank-1]+";\n }\n ",s=1===this.rank?"":"\n --"+n[this.rank-1]+";\n if (++"+n[this.rank-2]+" < "+t[this.rank-2]+") {\n ++"+r[this.rank-2]+";\n result.z = "+i+";\n if (++"+n[this.rank-1]+" < "+t[this.rank-1]+") {\n ++"+r[this.rank-1]+";\n result.w = "+i+";\n }\n }\n ",u=this.rank<=4?"sourceLoc = coords +\n "+e+"("+t.map(function(t,e){return"start["+e+"]"}).join()+");":t.map(function(t,e){return r[e]+" = "+n[e]+" + start["+e+"];"}).join("\n");this.userCode="\n uniform int start["+this.rank+"];\n void main() {\n "+e+" coords = getOutputCoords();\n "+e+" sourceLoc;\n "+u+" \n vec4 result = vec4(0.);\n "+a+"\n "+s+"\n setOutput(result);\n }\n "}return t.prototype.getCustomSetupFunc=function(n){var r=this;if(n.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the length of start ("+n.length+")");return function(t,e){null==r.startLoc&&(r.startLoc=t.getUniformLocationNoThrow(e,"start"),null==r.startLoc)||t.gl.uniform1iv(r.startLoc,n)}},t}(),si=function(t,e,n,r){this.variableNames=["x"];var o=n.filter(function(t,e){return-1===r.indexOf(e)});this.outputShape=o;var i=n.length,a=Dn(n.length),s=Dn(o.length),u="";if(1===i)u="coords * strides + begin";else{var c=0;u=n.map(function(t,e){return-1===r.indexOf(e)?(c++,1===o.length?"coords * strides["+e+"] + begin["+e+"]":"coords["+(c-1)+"] * strides["+e+"] + begin["+e+"]"):"begin["+e+"]"}).join(",")}this.userCode="\n "+a+" begin = "+a+"("+t+");\n "+a+" strides = "+a+"("+e+");\n\n void main() {\n "+s+" coords = getOutputCoords();\n setOutput(getX("+u+"));\n }\n "},ui=function(){function t(t){this.gpgpu=t,this.numUsedTextures=0,this.numFreeTextures=0,this.freeTextures={},this.logEnabled=!1,this.usedTextures={}}return t.prototype.acquireTexture=function(t,e,n){var r,o=ci(e,n),i=li(t,o,n);if(i in this.freeTextures||(this.freeTextures[i]=[]),i in this.usedTextures||(this.usedTextures[i]=[]),0>>0,r=(n*=r)>>>0,r+=4294967296*(n-=r)}return 2.3283064365386963e-10*(r>>>0)});e.next=function(){var t=2091639*e.s0+2.3283064365386963e-10*e.c;return e.s0=e.s1,e.s1=e.s2,e.s2=t-(e.c=0|t)},e.c=1,e.s0=n(" "),e.s1=n(" "),e.s2=n(" "),e.s0-=n(t),e.s0<0&&(e.s0+=1),e.s1-=n(t),e.s1<0&&(e.s1+=1),e.s2-=n(t),e.s2<0&&(e.s2+=1),n=null}(t),r=e&&e.state,o=n.next;return o.int32=function(){return 4294967296*n.next()|0},o.double=function(){return o()+11102230246251565e-32*(2097152*o()|0)},o.quick=o,r&&("object"==typeof r&&i(r,n),o.state=function(){return i(n,{})}),o}e&&e.exports?e.exports=r:this.alea=r}(0,t)}),Di=Ti(function(t){!function(t,e,n){function i(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e}function r(t,e){var n=new function(t){var e=this,n="";e.x=0,e.y=0,e.z=0,e.w=0,e.next=function(){var t=e.x^e.x<<11;return e.x=e.y,e.y=e.z,e.z=e.w,e.w^=e.w>>>19^t^t>>>8},t===(0|t)?e.x=t:n+=t;for(var r=0;r>>0)/4294967296};return o.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},o.int32=n.next,o.quick=o,r&&("object"==typeof r&&i(r,n),o.state=function(){return i(n,{})}),o}e&&e.exports?e.exports=r:this.xor128=r}(0,t)}),Mi=Ti(function(t){!function(t,e,n){function i(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e.v=t.v,e.d=t.d,e}function r(t,e){var n=new function(t){var e=this,n="";e.next=function(){var t=e.x^e.x>>>2;return e.x=e.y,e.y=e.z,e.z=e.w,e.w=e.v,(e.d=e.d+362437|0)+(e.v=e.v^e.v<<4^t^t<<1)|0},e.x=0,e.y=0,e.z=0,e.w=0,t===((e.v=0)|t)?e.x=t:n+=t;for(var r=0;r>>4),e.next()}(t),r=e&&e.state,o=function(){return(n.next()>>>0)/4294967296};return o.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},o.int32=n.next,o.quick=o,r&&("object"==typeof r&&i(r,n),o.state=function(){return i(n,{})}),o}e&&e.exports?e.exports=r:this.xorwow=r}(0,t)}),Oi=Ti(function(t){!function(t,e,n){function i(t,e){return e.x=t.x.slice(),e.i=t.i,e}function r(t,e){null==t&&(t=+new Date);var n=new function(t){var o=this;o.next=function(){var t,e,n=o.x,r=o.i;return t=n[r],e=(t^=t>>>7)^t<<24,e^=(t=n[r+1&7])^t>>>10,e^=(t=n[r+3&7])^t>>>3,e^=(t=n[r+4&7])^t<<7,t=n[r+7&7],e^=(t^=t<<13)^t<<9,n[r]=e,o.i=r+1&7,e},function(t,e){var n,r=[];if(e===(0|e))r[0]=e;else for(e=""+e,n=0;n>>0)/4294967296};return o.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},o.int32=n.next,o.quick=o,r&&(r.x&&i(r,n),o.state=function(){return i(n,{})}),o}e&&e.exports?e.exports=r:this.xorshift7=r}(0,t)}),Pi=Ti(function(t){!function(t,e,n){function i(t,e){return e.i=t.i,e.w=t.w,e.X=t.X.slice(),e}function r(t,e){null==t&&(t=+new Date);var n=new function(t){var i=this;i.next=function(){var t,e,n=i.w,r=i.X,o=i.i;return i.w=n=n+1640531527|0,e=r[o+34&127],t=r[o=o+1&127],e^=e<<13,t^=t<<17,e^=e>>>15,t^=t>>>12,e=r[o]=e^t,i.i=o,e+(n^n>>>16)|0},function(t,e){var n,r,o,i,a,s=[],u=128;for(e===(0|e)?(r=e,e=null):(e+="\0",r=0,u=Math.max(u,e.length)),o=0,i=-32;i>>15,r^=r<<4,r^=r>>>13,0<=i&&(a=a+1640531527|0,o=0==(n=s[127&i]^=r+a)?o+1:0);for(128<=o&&(s[127&(e&&e.length||0)]=-1),o=127,i=512;0>>15,n^=n>>>12,s[o]=r^n;t.w=a,t.X=s,t.i=o}(i,t)}(t),r=e&&e.state,o=function(){return(n.next()>>>0)/4294967296};return o.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},o.int32=n.next,o.quick=o,r&&(r.X&&i(r,n),o.state=function(){return i(n,{})}),o}e&&e.exports?e.exports=r:this.xor4096=r}(0,t)}),Fi=Ti(function(t){!function(t,e,n){function i(t,e){return e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e}function r(t,e){var n=new function(t){var o=this,e="";o.next=function(){var t=o.b,e=o.c,n=o.d,r=o.a;return t=t<<25^t>>>7^e,e=e-n|0,n=n<<24^n>>>8^r,r=r-t|0,o.b=t=t<<20^t>>>12^e,o.c=e=e-n|0,o.d=n<<16^e>>>16^r,o.a=r-t|0},o.a=0,o.b=0,o.c=-1640531527,o.d=1367130551,t===Math.floor(t)?(o.a=t/4294967296|0,o.b=0|t):e+=t;for(var n=0;n>>0)/4294967296};return o.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},o.int32=n.next,o.quick=o,r&&("object"==typeof r&&i(r,n),o.state=function(){return i(n,{})}),o}e&&e.exports?e.exports=r:this.tychei=r}(0,t)}),Li=Ti(function(e){!function(s,u){var c,l=this,h=256,p=6,f="random",d=u.pow(h,p),v=u.pow(2,52),m=2*v,g=h-1;function t(t,e,n){var r=[],o=x(function t(e,n){var r,o=[],i=typeof e;if(n&&"object"==i)for(r in e)try{o.push(t(e[r],n-1))}catch(t){}return o.length?o:"string"==i?e:e+"\0"}((e=1==e?{entropy:!0}:e||{}).entropy?[t,w(s)]:null==t?function(){try{var t;return c&&(t=c.randomBytes)?t=t(h):(t=new Uint8Array(h),(l.crypto||l.msCrypto).getRandomValues(t)),w(t)}catch(t){var e=l.navigator,n=e&&e.plugins;return[+new Date,l,n,l.screen,w(s)]}}():t,3),r),i=new function(t){var e,n=t.length,a=this,r=0,o=a.i=a.j=0,i=a.S=[];for(n||(t=[n++]);r>>=1;return(t+n)/e};return a.int32=function(){return 0|i.g(4)},a.quick=function(){return i.g(4)/4294967296},a.double=a,x(w(i.S),s),(e.pass||n||function(t,e,n,r){return r&&(r.S&&y(r,i),t.state=function(){return y(i,{})}),n?(u[f]=t,e):t})(a,o,"global"in e?e.global:this==u,e.state)}function y(t,e){return e.i=t.i,e.j=t.j,e.S=t.S.slice(),e}function x(t,e){for(var n,r=t+"",o=0;o=this.lower},t}();function zi(t,e,n){return void 0===e&&(e="float32"),e=e||"float32",tt(t),new lt(t,e,n)}function Ui(t,e){void 0===e&&(e=!1),console.log(t.toString(e))}var Gi=Fe({batchToSpaceND_:function(t,e,n){var r=re(t,"x","batchToSpaceND"),o=e.reduce(function(t,e){return t*e});return D(r.rank>=1+e.length,function(){return"input rank is "+r.rank+" but should be > than blockShape.length "+e.length}),D(n.length===e.length,function(){return"crops.length is "+n.length+" but should be equal to blockShape.length "+e.length}),D(r.shape[0]%o==0,function(){return"input tensor batch is "+r.shape[0]+" but is not divisible by the product of the elements of blockShape "+e.join(" * ")+" === "+o}),Zt.engine.runKernel(function(t){return t.batchToSpaceND(r,e,n)},{$x:r},function(t){return{$x:function(){return t.spaceToBatchND(e,n)}}})}}),Vi=Fe({cast_:function(t,e){var n=re(t,"x","cast");return Zt.engine.runKernel(function(t){return t.cast(n,e)},{$x:n},function(t){return{$x:function(){return t.clone()}}})}}),Hi=Fe({clone_:function(t){var e=re(t,"x","clone",null);return Zt.engine.runKernel(function(t){return dt.make(e.shape,{dataId:e.dataId},e.dtype)},{$x:e},function(t){return{$x:function(){return t.toFloat()}}})}}),qi=Fe({cumsum_:function(t,e,n,r){void 0===e&&(e=0),void 0===n&&(n=!1),void 0===r&&(r=!1);var o=re(t,"x","cumsum"),i=Ce([e|=0],o.rank),a=o;null!=i&&(a=o.transpose(i));var s=Se(1,o.rank)[0],u=Zt.engine.runKernel(function(t){return t.cumsum(a,s,n,r)},{permutedX:a},function(t){return{permutedX:function(){return t.cumsum(e,n,!r)}}});return null!=i&&(u=u.transpose(i)),u}}),ji=Fe({depthToSpace_:function(t,e,n){void 0===n&&(n="NHWC");var r=re(t,"x","depthToSpace"),o="NHWC"===n?r.shape[1]:r.shape[2],i="NHWC"===n?r.shape[2]:r.shape[3],a="NHWC"===n?r.shape[3]:r.shape[1];return D(0<=o*e,function(){return"Negative dimension size caused by overflow when multiplying\n "+o+" and "+e+" for depthToSpace with input shape\n "+r.shape}),D(0<=i*e,function(){return"Negative dimension size caused by overflow when multiplying\n "+i+" and "+e+" for depthToSpace with input shape\n "+r.shape}),D(a%(e*e)==0,function(){return"Dimension size must be evenly divisible by "+e*e+" but is "+a+" for depthToSpace with input shape "+r.shape}),Zt.engine.runKernel(function(t){return t.depthToSpace(r,e,n)},{$x:r})}}),$i=Fe({expandDims_:function(t,e){void 0===e&&(e=0);var n=re(t,"x","expandDims");D(e<=n.rank,function(){return"Axis must be <= rank of the tensor"});var r=n.shape.slice();return e<0&&(D(-(n.rank+1)<=e,function(){return"Axis must be in the interval ["+-(n.rank+1)+", "+n.rank+"]"}),e=n.rank+e+1),r.splice(e,0,1),ia(n,r)}}),Ki=Fe({eye_:function(t,e,n,r){void 0===r&&(r="float32"),null==e&&(e=t);for(var o=zi([t,e],r),i=t<=e?t:e,a=0;a=2, but it is "+e);var o=re(t,"indices","oneHot","int32"),i=o.shape.concat([e]);return o=o.flatten(),Zt.engine.runKernel(function(t){return t.oneHot(o,e,n,r)},{$indices:o},function(t){return{$indices:function(){return Qe(o.shape,"float32")}}}).reshape(i)}}),Qi=Fe({pad_:function(t,e,n){void 0===n&&(n=0);var r=re(t,"x","pad");if(0===r.rank)throw new Error("pad(scalar) is not defined. Pass non-scalar to pad");var o=e.map(function(t){return t[0]});return Zt.engine.runKernel(function(t){return t.pad(r,e,n)},{$x:r},function(t){return{$x:function(){return t.slice(o,r.shape)}}})}}),Ji=Fe({pad1d_:function(t,e,n){return void 0===n&&(n=0),D(2===e.length,function(){return"Invalid number of paddings. Must be length of 2."}),Qi(t,[e],n)}}),Zi=Fe({pad2d_:function(t,e,n){return void 0===n&&(n=0),D(2===e.length&&2===e[0].length&&2===e[1].length,function(){return"Invalid number of paddings. Must be length of 2 each."}),Qi(t,e,n)}}),ta=Fe({pad3d_:function(t,e,n){return void 0===n&&(n=0),D(3===e.length&&2===e[0].length&&2===e[1].length&&2===e[2].length,function(){return"Invalid number of paddings. Must be length of 2 each."}),Qi(t,e,n)}}),ea=Fe({pad4d_:function(t,e,n){return void 0===n&&(n=0),D(4===e.length&&2===e[0].length&&2===e[1].length&&2===e[2].length&&2===e[3].length,function(){return"Invalid number of paddings. Must be length of 2 each."}),Qi(t,e,n)}}),na=Fe({rand_:function(t,e,n){var r=B(t),o=null;if(null==n||"float32"===n)o=new Float32Array(r);else if("int32"===n)o=new Int32Array(r);else{if("bool"!==n)throw new Error("Unknown data type "+n);o=new Uint8Array(r)}for(var i=0;i=1+r.length,function(){return"input rank "+e.rank+" should be > than [blockShape] "+r.length}),D(o.length===r.length,function(){return"paddings.shape[0] "+o.length+" must be equal to [blockShape] "+r.length}),D(e.shape.reduce(function(t,e,n){return 0=-n.shape.length&&eZt.get("WEBGL_MAX_TEXTURES_IN_SHADER")){var n=Math.floor(t.length/2),r=this.concat(t.slice(0,n),e),o=this.concat(t.slice(n),e);return this.concat([r,o],e)}if(Zt.get("WEBGL_PACK_ARRAY_OPERATIONS")&&1 4 with a WebGL backend not implemented yet"});var r=e.reduce(function(t,e){return t*e}),o=de(t.shape,e,r),i=ve(o.length,e.length),a=me(t.shape,e,r),s=ge(n,e.length),u=ye(a,n,e.length);return t.reshape(o).transpose(i).reshape(a).slice(s,u)},t.prototype.spaceToBatchND=function(t,e,n){D(t.rank<=4,function(){return"spaceToBatchND for rank > 4 with a WebGL backend not implemented yet"});var r=e.reduce(function(t,e){return t*e}),o=[[0,0]];o.push.apply(o,n);for(var i=1+e.length;i b);",t.shape,e.shape),r=this.makeOutputArray(n.outputShape,"bool");return this.compileAndRun(n,[t,e],r)},t.prototype.greaterEqual=function(t,e){if(Zt.get("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(greaterThanEqual(a, b));\n","bool");var n=new jn("return float(a >= b);",t.shape,e.shape),r=this.makeOutputArray(n.outputShape,"bool");return this.compileAndRun(n,[t,e],r)},t.prototype.logicalNot=function(t){var e=new mi(t.shape,"return float(!(x >= 1.0));");return this.compileAndRun(e,[t])},t.prototype.logicalAnd=function(t,e){if(Zt.get("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(\n vec4(greaterThanEqual(a, vec4(1.0))) *\n vec4(greaterThanEqual(b, vec4(1.0))));\n","bool");var n=new jn("return float(a >= 1.0 && b >= 1.0);",t.shape,e.shape),r=this.makeOutputArray(n.outputShape,"bool");return this.compileAndRun(n,[t,e],r)},t.prototype.logicalOr=function(t,e){if(Zt.get("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return min(\n vec4(greaterThanEqual(a, vec4(1.0))) +\n vec4(greaterThanEqual(b, vec4(1.0))),\n vec4(1.0));\n","bool");var n=new jn("return float(a >= 1.0 || b >= 1.0);",t.shape,e.shape),r=this.makeOutputArray(n.outputShape,"bool");return this.compileAndRun(n,[t,e],r)},t.prototype.select=function(t,e,n){var r=new ri(t.rank,e.shape,e.rank),o=this.makeOutputArray(r.outputShape,kt(e.dtype,n.dtype));return this.compileAndRun(r,[t,e,n],o)},t.prototype.where=function(t){fe("tf.where() in webgl locks the UI thread. Call tf.whereAsync() instead");var e=t.dataSync();return fa(t.shape,e)},t.prototype.topk=function(t,e,n){return fn(t.dataSync(),t.shape,t.dtype,e)},t.prototype.min=function(t,e){Ee("min",e,t.rank);var n=we(t.shape,e),r=n[0],o=B(n[1]),i=t.as2D(-1,o);return this.reduce(i,"min",i.dtype).reshape(r)},t.prototype.minimum=function(t,e){if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.minimum(t,e);var n=Zt.get("WEBGL_PACK_BINARY_OPERATIONS")?new $n("\n vec4 result = vec4(min(a, b));\n vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n",t.shape,e.shape):new jn("\n if (isnan(a)) return a;\n if (isnan(b)) return b;\n\n return min(a, b);\n",t.shape,e.shape);return this.compileAndRun(n,[t,e])},t.prototype.mod=function(t,e){var n=Zt.get("WEBGL_PACK_BINARY_OPERATIONS")?new $n("\n vec4 result = mod(a, b);\n vec4 isNaN = vec4(equal(b, vec4(0.0)));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n",t.shape,e.shape):new jn("if (b == 0.0) return NAN;\n return mod(a, b);",t.shape,e.shape);return this.compileAndRun(n,[t,e])},t.prototype.max=function(t,e){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.max(t,e);Ee("max",e,t.rank);var n=we(t.shape,e),r=n[0],o=B(n[1]),i=t.as2D(-1,o);return this.reduce(i,"max",i.dtype).reshape(r)},t.prototype.maximum=function(t,e){if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.maximum(t,e);var n=Zt.get("WEBGL_PACK_BINARY_OPERATIONS")?new $n("\n vec4 result = vec4(max(a, b));\n vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n",t.shape,e.shape):new jn("\n if (isnan(a)) return a;\n if (isnan(b)) return b;\n\n return max(a, b);\n",t.shape,e.shape);return this.compileAndRun(n,[t,e])},t.prototype.all=function(t,e){Ee("all",e,t.rank);var n=we(t.shape,e),r=n[0],o=B(n[1]),i=t.as2D(-1,o);return this.reduce(i,"all",i.dtype).reshape(r)},t.prototype.any=function(t,e){Ee("any",e,t.rank);var n=we(t.shape,e),r=n[0],o=B(n[1]),i=t.as2D(-1,o);return this.reduce(i,"any",i.dtype).reshape(r)},t.prototype.squaredDifference=function(t,e){var n=Zt.get("WEBGL_PACK_BINARY_OPERATIONS")?new $n(qn,t.shape,e.shape):new jn(qn,t.shape,e.shape);return this.compileAndRun(n,[t,e])},t.prototype.realDivide=function(t,e){var n=new jn("if (a == b) return 1.0;\n return a / b;",t.shape,e.shape),r=this.makeOutputArray(n.outputShape,"float32");return this.compileAndRun(n,[t,e],r)},t.prototype.floorDiv=function(t,e){if(Zt.get("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n vec4 resultSign = sign(a) * sign(b);\n ivec4 ia = round(a);\n ivec4 ib = round(b);\n ivec4 result = ia / ib;\n ivec4 amodb = ia - ib * result;\n\n // Vectorize INT_DIV\n // if (resultSign < 0.0 && amodb != 0) result -= 1;\n // return float(result);\n return vec4(result -\n ivec4(lessThan(resultSign, vec4(0.0))) * ivec4(notEqual(amodb, ivec4(0))));\n","int32");var n=new jn("\n float resultSign = sign(a) * sign(b);\n int ia = round(a);\n int ib = round(b);\n int result = ia / ib;\n int amodb = ia - ib * result;\n\n if (resultSign < 0.0 && amodb != 0) {\n result -= 1;\n }\n return float(result);\n",t.shape,e.shape),r=this.makeOutputArray(n.outputShape,"int32");return this.compileAndRun(n,[t,e],r)},t.prototype.add=function(t,e){if("complex64"===t.dtype&&"complex64"===e.dtype)return this.complexSeparableBinaryOp(t,e,Gn);if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.add(t,e);var n=kt(t.dtype,e.dtype);if(Zt.get("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,Gn,n);var r=new jn(Gn,t.shape,e.shape),o=this.makeOutputArray(r.outputShape,n);return this.compileAndRun(r,[t,e],o)},t.prototype.packedBinaryOp=function(t,e,n,r){var o=new $n(n,t.shape,e.shape),i=this.makePackedTensor(o.outputShape,r);return this.compileAndRun(o,[t,e],i)},t.prototype.complexSeparableBinaryOp=function(s,u,c){var l=this,t=this.texData.get(s.dataId),e=this.texData.get(u.dataId),n=[[t.complexTensors.real,e.complexTensors.real],[t.complexTensors.imag,e.complexTensors.imag]].map(function(t){var e=t[0],n=t[1],r=l.makeComplexComponentTensorHandle(s,e),o=l.makeComplexComponentTensorHandle(u,n),i=new jn(c,s.shape,u.shape),a=l.makeOutputArray(i.outputShape,kt(e.dtype,n.dtype));return l.compileAndRun(i,[r,o],a)}),r=n[0],o=n[1],i=this.complex(r,o);return r.dispose(),o.dispose(),i},t.prototype.makeComplexComponentTensorHandle=function(t,e){return{dataId:e.dataId,dtype:e.dtype,shape:t.shape}},t.prototype.addN=function(t){for(var e=t[0],n=1;n 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n",t.shape,e.shape):new jn("\nif(a < 0.0 && floor(b) < b){\n return NAN;\n}\nreturn (round(mod(b, 2.0)) != 1) ?\n pow(abs(a), b) : sign(a) * pow(abs(a), b);\n",t.shape,e.shape),o=kt(t.dtype,e.dtype),i=n?this.makePackedTensor(r.outputShape,o):this.makeOutputArray(r.outputShape,o);return this.compileAndRun(r,[t,e],i)},t.prototype.ceil=function(t){var e=new mi(t.shape,"return ceil(x);");return this.compileAndRun(e,[t])},t.prototype.floor=function(t){var e=new mi(t.shape,"return floor(x);");return this.compileAndRun(e,[t])},t.prototype.sign=function(t){var e=new mi(t.shape,"\n if (isnan(x)) { return 0.0; }\n return sign(x);\n");return this.compileAndRun(e,[t])},t.prototype.isNaN=function(t){var e=new mi(t.shape,"return float(isnan(x));"),n=this.makeOutputArray(e.outputShape,"bool");return this.compileAndRun(e,[t],n)},t.prototype.isInf=function(t){var e=new mi(t.shape,"return float(isinf(x));"),n=this.makeOutputArray(e.outputShape,"bool");return this.compileAndRun(e,[t],n)},t.prototype.isFinite=function(t){var e=new mi(t.shape,"return float(!isnan(x) && !isinf(x));"),n=this.makeOutputArray(e.outputShape,"bool");return this.compileAndRun(e,[t],n)},t.prototype.round=function(t){var e=new mi(t.shape,"\n // OpenGL ES does not support round function.\n // The algorithm is based on banker's rounding.\n float base = floor(x);\n if ((x - base) < 0.5) {\n return floor(x);\n } else if ((x - base) > 0.5) {\n return ceil(x);\n } else {\n if (mod(base, 2.0) == 0.0) {\n return base;\n } else {\n return base + 1.0;\n }\n }\n");return this.compileAndRun(e,[t])},t.prototype.exp=function(t){var e;return e=Zt.get("WEBGL_PACK")?new Ei(t.shape,xi):new mi(t.shape,xi),this.compileAndRun(e,[t])},t.prototype.expm1=function(t){var e=new mi(t.shape,"return exp(x) - 1.0;");return this.compileAndRun(e,[t])},t.prototype.log=function(t){var e;return e=Zt.get("WEBGL_PACK")?new Ei(t.shape,"\n vec4 result = log(x);\n vec4 isNaN = vec4(lessThan(x, vec4(0.0)));\n result.r = isNaN.r == 1.0 ? NAN : result.r;\n result.g = isNaN.g == 1.0 ? NAN : result.g;\n result.b = isNaN.b == 1.0 ? NAN : result.b;\n result.a = isNaN.a == 1.0 ? NAN : result.a;\n\n return result;\n"):new mi(t.shape,"if (x < 0.0) return NAN;\n return log(x);"),this.compileAndRun(e,[t])},t.prototype.log1p=function(t){var e=new mi(t.shape,"return log(1.0 + x);");return this.compileAndRun(e,[t])},t.prototype.sqrt=function(t){var e=new mi(t.shape,"return sqrt(x);");return this.compileAndRun(e,[t])},t.prototype.rsqrt=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.rsqrt(t);var e=new mi(t.shape,"return inversesqrt(x);");return this.compileAndRun(e,[t])},t.prototype.square=function(t){var e=new mi(t.shape,"return x * x;");return this.compileAndRun(e,[t])},t.prototype.reciprocal=function(t){var e=new mi(t.shape,"return 1.0 / x;");return this.compileAndRun(e,[t])},t.prototype.relu=function(t){var e;return e=Zt.get("WEBGL_PACK")?new Ei(t.shape,bi):new mi(t.shape,yi),this.compileAndRun(e,[t])},t.prototype.prelu=function(t,e){var n=Zt.get("WEBGL_PACK_BINARY_OPERATIONS")?new $n("\n vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));\n return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);\n",t.shape,e.shape):new jn("return (a < 0.) ? b * a : a;",t.shape,e.shape);return this.compileAndRun(n,[t,e])},t.prototype.elu=function(t){var e=new mi(t.shape,"return (x >= 0.0) ? x : (exp(x) - 1.0);");return this.compileAndRun(e,[t])},t.prototype.eluDer=function(t,e){var n=Zt.get("WEBGL_PACK_BINARY_OPERATIONS")?new $n("\n vec4 bGTEZero = vec4(greaterThanEqual(b, vec4(0.)));\n return (bGTEZero * a) + ((vec4(1.0) - bGTEZero) * (a * (b + vec4(1.0))));\n",t.shape,e.shape):new jn("return (b >= 1.0) ? a : a * (b + 1.0);",t.shape,e.shape);return this.compileAndRun(n,[t,e])},t.prototype.selu=function(t){var e=new mi(t.shape,"\n // Stable and Attracting Fixed Point (0, 1) for Normalized Weights.\n // see: https://arxiv.org/abs/1706.02515\n float scaleAlpha = 1.7580993408473768;\n float scale = 1.0507009873554805;\n return (x >= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);\n");return this.compileAndRun(e,[t])},t.prototype.int=function(t){var e=new mi(t.shape,"return float(int(x));"),n=this.makeOutputArray(e.outputShape,"int32");return this.compileAndRun(e,[t],n)},t.prototype.clip=function(t,e,n){var r,o=(r=Zt.get("WEBGL_PACK_CLIP")?new Xn(t.shape):new Kn(t.shape)).getCustomSetupFunc(e,n);return this.compileAndRun(r,[t],null,o)},t.prototype.abs=function(t){var e=new mi(t.shape,"return abs(x);");return this.compileAndRun(e,[t])},t.prototype.complexAbs=function(t){var e=this.texData.get(t.dataId),n=new Yn(t.shape),r=[this.makeComplexComponentTensorHandle(t,e.complexTensors.real),this.makeComplexComponentTensorHandle(t,e.complexTensors.imag)];return this.compileAndRun(n,r)},t.prototype.sigmoid=function(t){var e=new mi(t.shape,"return 1.0 / (1.0 + exp(-1.0 * x));");return this.compileAndRun(e,[t])},t.prototype.softplus=function(t){var e=new mi(t.shape,"\n float epsilon = 1.1920928955078125e-7;\n float threshold = log(epsilon) + 2.0;\n\n bool too_large = x > -threshold;\n bool too_small = x < threshold;\n\n float result;\n float exp_x = exp(x);\n\n if (too_large){\n result = x;\n }\n else if (too_small){\n result = exp_x;\n }\n else{\n result = log(exp_x + 1.0);\n }\n return result;\n");return this.compileAndRun(e,[t])},t.prototype.sin=function(t){var e=new mi(t.shape,"if (isnan(x)) return x;\n return sin(x);\n");return this.compileAndRun(e,[t])},t.prototype.cos=function(t){var e=new mi(t.shape,"if (isnan(x)) return x;\n return cos(x);\n");return this.compileAndRun(e,[t])},t.prototype.tan=function(t){var e=new mi(t.shape,"return tan(x);");return this.compileAndRun(e,[t])},t.prototype.asin=function(t){var e=new mi(t.shape,"return asin(x);");return this.compileAndRun(e,[t])},t.prototype.acos=function(t){var e=new mi(t.shape,"return acos(x);");return this.compileAndRun(e,[t])},t.prototype.atan=function(t){var e=new mi(t.shape,"if (isnan(x)) return x;\n return atan(x);\n");return this.compileAndRun(e,[t])},t.prototype.atan2=function(t,e){var n=Zt.get("WEBGL_PACK_BINARY_OPERATIONS")?new $n("\n vec4 result = atan(a, b);\n vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n",t.shape,e.shape):new jn("\n if (isnan(a)) return a;\n if (isnan(b)) return b;\n\n return atan(a, b);\n",t.shape,e.shape);return this.compileAndRun(n,[t,e])},t.prototype.sinh=function(t){var e=new mi(t.shape,"\n float e2x = exp(x);\n return (e2x - 1.0 / e2x) / 2.0;\n");return this.compileAndRun(e,[t])},t.prototype.cosh=function(t){var e=new mi(t.shape,"\n float e2x = exp(-x);\n return (e2x + 1.0 / e2x) / 2.0;\n");return this.compileAndRun(e,[t])},t.prototype.tanh=function(t){var e=new mi(t.shape,"\n float e2x = exp(-2.0 * abs(x));\n return sign(x) * (1.0 - e2x) / (1.0 + e2x);\n");return this.compileAndRun(e,[t])},t.prototype.asinh=function(t){var e=new mi(t.shape,"return log(x + sqrt(x * x + 1.0));");return this.compileAndRun(e,[t])},t.prototype.acosh=function(t){var e=new mi(t.shape,"if (isnan(x)) return x;\n if (x < 1.0) return NAN;\n return log(x + sqrt(x * x - 1.0));");return this.compileAndRun(e,[t])},t.prototype.atanh=function(t){var e=new mi(t.shape,"if (isnan(x)) return x;\n if ((x < -1.0) || (x > 1.0)) return NAN;\n return (log(1.0 + x) - log(1.0 - x)) / 2.0;");return this.compileAndRun(e,[t])},t.prototype.erf=function(t){var e=new mi(t.shape,'\n // Error function is calculated approximately with elementary function.\n // See "Handbook of Mathematical Functions with Formulas,\n // Graphs, and Mathematical Tables", Abramowitz and Stegun.\n float p = 0.3275911;\n float a1 = 0.254829592;\n float a2 = -0.284496736;\n float a3 = 1.421413741;\n float a4 = -1.453152027;\n float a5 = 1.061405429;\n\n float t = 1.0 / (1.0 + p * x);\n return 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x);\n');return this.compileAndRun(e,[t])},t.prototype.step=function(t,e){var n,r=new mi(t.shape,(void 0===(n=e)&&(n=0),gi+"\n return x > 0.0 ? 1.0 : float("+n+");\n "));return this.compileAndRun(r,[t])},t.prototype.conv2dByMatMul=function(t,e,n){var r=t.shape,o=this.texData.get(t.dataId),i=n.inChannels,a=r[0]*r[1]*r[2],s=n.outChannels,u=(1===a||1===s)&&1e3 1 for depthToSpace, but was: "+e});var r=t.shape[0],o="NHWC"===n?t.shape[1]:t.shape[2],i="NHWC"===n?t.shape[2]:t.shape[3],a="NHWC"===n?t.shape[3]:t.shape[1],s=o*e,u=i*e,c=a/(e*e),l=new pr("NHWC"===n?[r,s,u,c]:[r,c,s,u],e,n);return this.compileAndRun(l,[t])},t.prototype.split=function(t,e,n){return pn(t,e,n)},t.prototype.scatterND=function(t,e,n){var r=Te(0,t,n),o=r.sliceRank,i=r.numUpdates,a=r.sliceSize,s=r.strides,u=r.outputSize,c=[u/a,a],l=t.reshape([i,o]),h=e.reshape([i,a]);if(0===u)return sn(Ge([]),n);var p=Ve(0),f=new ei(i,o,l.rank,h.rank,s,c);return this.compileAndRun(f,[h,l,p]).reshape(n)},t.prototype.sparseToDense=function(t,e,n,r){var o=Te(0,t,n),i=o.sliceRank,a=o.numUpdates,s=o.strides,u=o.outputSize,c=new ei(a,i,t.rank,e.rank,s,[u,1],!1);return this.compileAndRun(c,[e,t,r]).reshape(n)},t.prototype.fft=function(t){return this.fftImpl(t,!1)},t.prototype.ifft=function(t){return this.fftImpl(t,!0)},t.prototype.fftImpl=function(t,e){var n=this.texData.get(t.dataId),r=new mr(dr,t.shape,e),o=new mr(vr,t.shape,e),i=[this.makeComplexComponentTensorHandle(t,n.complexTensors.real),this.makeComplexComponentTensorHandle(t,n.complexTensors.imag)],a=this.compileAndRun(r,i),s=this.compileAndRun(o,i),u=this.complex(a,s).as2D(t.shape[0],t.shape[1]);return a.dispose(),s.dispose(),u},t.prototype.gatherND=function(t,e){var n=e.shape,r=n[n.length-1],o=Ne(t,e),i=o[0],a=o[1],s=o[2],u=o[3],c=e.reshape([a,r]),l=t.reshape([t.size/s,s]),h=new _r(r,u,[a,s]);return this.compileAndRun(h,[l,c]).reshape(i)},t.prototype.fill=function(t,e,n){if("string"===(n=n||q(e))){var r=M(n,B(t));return r.fill(e),dt.make(t,{values:r},n)}var o=new gr(t,e),i=o.getCustomSetupFunc(e),a=this.makeOutputArray(t,n);return this.compileAndRun(o,[],a,i)},t.prototype.onesLike=function(t){if("string"===t.dtype)throw new Error("onesLike is not supported under string dtype");return this.fill(t.shape,1,t.dtype)},t.prototype.zerosLike=function(t){return this.fill(t.shape,"string"===t.dtype?"":0,t.dtype)},t.prototype.makeOutputArray=function(t,e){return dt.make(t,{},e,this)},t.prototype.makePackedTensor=function(t,e){var n=dt.make(t,{},e,this);return this.texData.get(n.dataId).isPacked=!0,n},t.prototype.unpackTensor=function(t){var e=new Ci(t.shape);return this.compileAndRun(e,[t],dt.make(e.outputShape,{},t.dtype,this))},t.prototype.packTensor=function(t){var e=new Go(t.shape);return this.compileAndRun(e,[t],this.makePackedTensor(t.shape,t.dtype))},t.prototype.packedReshape=function(t,e){var n=t.reshape([oo(t.shape)].concat(io(t.shape))),r=[oo(e)].concat(io(e)),o=new $o(r,n.shape);return this.compileAndRun(o,[n]).reshape(e)},t.prototype.compileAndRun=function(o,t,e,n,r){var i=this;if(void 0===r&&(r=!0),null==e&&(e=o.usesPackedTextures?this.makePackedTensor(o.outputShape,t[0].dtype):this.makeOutputArray(o.outputShape,t[0].dtype)),0===e.size)return this.texData.get(e.dataId).values=A(e.dtype,0),e;var a=t.map(function(t){if("complex64"===t.dtype)throw new Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts.");var e=i.texData.get(t.dataId);if(null==e.texture){if(!o.usesPackedTextures&&B(t.shape)<=Zt.get("WEBGL_SIZE_UPLOAD_UNIFORM"))return{shape:t.shape,texData:null,isUniform:!0,uniformValues:i.readSync(t.dataId)};o.usesPackedTextures&&(e.isPacked=!0,e.shape=t.shape)}else if(!!e.isPacked!=!!o.usesPackedTextures)t=e.isPacked?i.unpackTensor(t):i.packTensor(t),e=i.texData.get(t.dataId);else if(e.isPacked&&!uo(e.shape,t.shape)){var n=t,r=t.shape;t.shape=e.shape,t=i.packedReshape(t,r),e=i.texData.get(t.dataId),n.shape=r}return i.uploadToGPU(t.dataId),{shape:t.shape,texData:e,isUniform:!1}});this.uploadToGPU(e.dataId);var s,u={shape:e.shape,texData:this.texData.get(e.dataId),isUniform:!1},c=function(t,e,n){var r="";e.concat(n).forEach(function(t){var e=null!=t.texData&&null!=t.texData.slice&&0p)for(var f=this.numBytesInGPU-p;0= 2, but got rank "+t.rank);if(2===t.rank)return Ic(t,o);var e=t.shape.slice(0,t.shape.length-2).reduce(function(t,e){return t*e}),i=[],a=[];return ha(t.reshape([e,t.shape[t.shape.length-2],t.shape[t.shape.length-1]]),0).forEach(function(t){var e=Ic(t,o),n=e[0],r=e[1];i.push(n),a.push(r)}),[ua(i,0).reshape(t.shape),ua(a,0).reshape(t.shape)]}}),Dc=Object.freeze({gramSchmidt:Tc,qr:Ac});function Mc(t,e,n,r,o){null==r&&(r=.5),null==o&&(o=Number.NEGATIVE_INFINITY);var i=t.shape[0];return n=Math.min(n,i),D(0<=r&&r<=1,function(){return"iouThreshold must be in [0, 1], but was '"+r+"'"}),D(2===t.rank,function(){return"boxes must be a 2D tensor, but was of rank '"+t.rank+"'"}),D(4===t.shape[1],function(){return"boxes must have 4 columns, but 2nd dimension was "+t.shape[1]}),D(1===e.rank,function(){return"scores must be a 1D tensor"}),D(e.shape[0]===i,function(){return"scores has incompatible shape with boxes. Expected "+i+", but was "+e.shape[0]}),{maxOutputSize:n,iouThreshold:r,scoreThreshold:o}}var Oc=Fe({resizeBilinear_:function(t,e,r){void 0===r&&(r=!1);var n=re(t,"images","resizeBilinear");D(3===n.rank||4===n.rank,function(){return"Error in resizeBilinear: x must be rank 3 or 4, but got rank "+n.rank+"."}),D(2===e.length,function(){return"Error in resizeBilinear: new shape must 2D, but got shape "+e+"."});var o=n,i=!1;3===n.rank&&(i=!0,o=n.as4D(1,n.shape[0],n.shape[1],n.shape[2]));var a=e[0],s=e[1],u=Zt.engine.runKernel(function(t,e){return e([o]),t.resizeBilinear(o,a,s,r)},{batchImages:o},function(e,n){return{batchImages:function(){return Zt.engine.runKernel(function(t){return t.resizeBilinearBackprop(e,n[0],r)},{})}}});return i?u.as3D(u.shape[1],u.shape[2],u.shape[3]):u}}),Pc=Fe({resizeNearestNeighbor_:function(t,e,r){void 0===r&&(r=!1);var n=re(t,"images","resizeNearestNeighbor");D(3===n.rank||4===n.rank,function(){return"Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank "+n.rank+"."}),D(2===e.length,function(){return"Error in resizeNearestNeighbor: new shape must 2D, but got shape "+e+"."}),D("float32"===n.dtype||"int32"===n.dtype,function(){return"`images` must have `int32` or `float32` as dtype"});var o=n,i=!1;3===n.rank&&(i=!0,o=n.as4D(1,n.shape[0],n.shape[1],n.shape[2]));var a=e[0],s=e[1],u=Zt.engine.runKernel(function(t,e){return e([o]),t.resizeNearestNeighbor(o,a,s,r)},{batchImages:o},function(e,n){return{batchImages:function(){return Zt.engine.runKernel(function(t){return t.resizeNearestNeighborBackprop(e,n[0],r)},{})}}});return i?u.as3D(u.shape[1],u.shape[2],u.shape[3]):u}}),Fc=Fe({nonMaxSuppression_:function(t,e,n,r,o){void 0===r&&(r=.5),void 0===o&&(o=Number.NEGATIVE_INFINITY);var i=re(t,"boxes","nonMaxSuppression"),a=re(e,"scores","nonMaxSuppression"),s=Mc(i,a,n,r,o);return n=s.maxOutputSize,r=s.iouThreshold,o=s.scoreThreshold,Zt.engine.runKernel(function(t){return t.nonMaxSuppression(i,a,n,r,o)},{$boxes:i})}}),Lc=function(s,u,c,l,h){return void 0===l&&(l=.5),void 0===h&&(h=Number.NEGATIVE_INFINITY),m(this,void 0,void 0,function(){var e,n,r,o,i,a;return R(this,function(t){switch(t.label){case 0:return e=re(s,"boxes","nonMaxSuppressionAsync"),n=re(u,"scores","nonMaxSuppressionAsync"),r=Mc(e,n,c,l,h),c=r.maxOutputSize,l=r.iouThreshold,h=r.scoreThreshold,[4,e.data()];case 1:return o=t.sent(),[4,n.data()];case 2:return i=t.sent(),a=ln(o,i,c,l,h),e!==s&&e.dispose(),n!==u&&n.dispose(),[2,a]}})})},Bc=Fe({cropAndResize_:function(t,e,n,r,o,i){var a=re(t,"image","cropAndResize","float32"),s=re(e,"boxes","cropAndResize","float32"),u=re(n,"boxInd","cropAndResize","int32");o=o||"bilinear",i=i||0;var c=s.shape[0];return D(4===a.rank,function(){return"Error in cropAndResize: image must be rank 4,but got rank "+a.rank+"."}),D(2===s.rank&&4===s.shape[1],function(){return"Error in cropAndResize: boxes must be have size ["+c+",4] but had shape "+s.shape+"."}),D(1===u.rank&&u.shape[0]===c,function(){return"Error in cropAndResize: boxInd must be have size ["+c+"] but had shape "+s.shape+"."}),D(2===r.length,function(){return"Error in cropAndResize: cropSize must be of length 2, but got length "+r.length+"."}),D(1<=r[0]&&1<=r[1],function(){return"cropSize must be atleast [1,1], but was "+r}),D("bilinear"===o||"nearest"===o,function(){return"method must be bilinear or nearest, but was "+o}),Zt.engine.runKernel(function(t,e){return t.cropAndResize(a,s,u,r,o,i)},{$image:a,$boxes:s})}}),Wc=Object.freeze({resizeBilinear:Oc,resizeNearestNeighbor:Pc,nonMaxSuppression:Fc,nonMaxSuppressionAsync:Lc,cropAndResize:Bc});var zc=Fe({matMul_:function(t,e,s,u,c,l){var n;void 0===s&&(s=!1),void 0===u&&(u=!1),void 0===l&&(l="linear");var r=re(t,"a","fused matMul"),o=re(e,"b","fused matMul");n=Tt(r,o),r=n[0],o=n[1];var i=s?r.shape[r.rank-2]:r.shape[r.rank-1],a=u?o.shape[o.rank-1]:o.shape[o.rank-2],h=s?r.shape[r.rank-1]:r.shape[r.rank-2],p=u?o.shape[o.rank-2]:o.shape[o.rank-1],f=r.shape.slice(0,-2),d=o.shape.slice(0,-2),v=B(f),m=B(d);D(2<=r.rank&&2<=o.rank&&r.rank===o.rank,function(){return"Error in fused matMul: inputs must have the same rank of at least 2, got ranks "+r.rank+" and "+o.rank+"."}),D(E(f,d),function(){return"Error in fused matMul: outer dimensions ("+f+") and ("+d+") of Tensors with shapes "+r.shape+" and "+o.shape+" must match."}),D(i===a,function(){return"Error in fused matMul: inner shapes ("+i+") and ("+a+") of Tensors with shapes "+r.shape+" and "+o.shape+" and transposeA="+s+" and transposeB="+u+" must match."});var g,y=r.shape.slice(0,-2).concat([h,p]),x=s?r.as3D(v,i,h):r.as3D(v,h,i),w=u?o.as3D(m,p,a):o.as3D(m,a,p);null!=c&&xn(y,(g=Tt(g=re(c,"bias","fused matMul"),r)[0]).shape);var b={$a:x,$b:w};return null!=c&&(b.$bias=g),Zt.engine.runKernel(function(t,e){var n=t.fusedBatchMatMul(x,w,s,u,g,l);return e([x,w,n]),n},b,function(t,e){var n,r=e[0],o=e[1],i=e[2];if(null==l||"linear"===l)n=t;else{if("relu"!==l)throw new Error("Gradient for activation "+l+" has not been implemented yet.");n=t.mul(i.step())}var a={};return null!=c&&(a={$bias:function(){var t=n,e=yn(g.shape,n.shape);return 0-e,s=r[o]=n.inHeight))for(var b=x*e.strides[0],E=d+w*t.strides[1],C=0;C=n.inWidth))for(var k=b+R*e.strides[1],I=E+N*n.inChannels,T=k,A=0;A=n.inDepth))for(var _=E*e.strides[0],S=g+C*t.strides[1],R=0;R=n.inHeight))for(var A=_+I*e.strides[1],D=S+T*t.strides[2],M=0;M=n.inWidth))for(var B=A+F*e.strides[2],W=D+L*n.inChannels,z=B,U=0;U=n.inHeight))for(var E=w*e.strides[0],C=v+b*t.strides[1],_=0;_=n.inWidth))for(var I=E+N*e.strides[1],T=C+k*n.inChannels,A=S,D=I,M=0;M=r.outHeight||Math.floor(_)!==_))for(var S=0;S=r.outWidth||Math.floor(R)!==R)){var N=c*l-1-d.get(m,_,R,g)===C*l+S?1:0;0!==N&&(E+=v.get(m,_,R,g)*N)}}}f.set(E,m,y,x,g)}return f.toTensor()},t.prototype.avgPoolBackprop=function(t,e,n){this.assertNotComplex([t,e],"avgPoolBackprop");for(var r=n.strideHeight,o=n.strideWidth,i=n.filterHeight,a=n.filterWidth,s=n.dilationHeight,u=n.dilationWidth,c=n.effectiveFilterHeight,l=n.effectiveFilterWidth,h=l-1-n.padInfo.left,p=c-1-n.padInfo.top,f=zi(e.shape,"float32"),d=1/(i*a),v=t.bufferSync(),m=0;m=n.outHeight||Math.floor(_)!==_))for(var S=0;S=n.outWidth||Math.floor(R)!==R||(E+=v.get(m,_,R,g))}}f.set(E*d,m,y,x,g)}return f.toTensor()},t.prototype.cast=function(t,e){return an(t,e,this)},t.prototype.reshape=function(t,e){return sn(t,e)},t.prototype.avgPool=function(t,e){return this.assertNotComplex(t,"avgPool"),this.pool(t,e,"avg").toFloat()},t.prototype.resizeBilinear=function(t,e,n,r){this.assertNotComplex(t,"resizeBilinear");for(var o=t.shape,i=o[0],a=o[1],s=o[2],u=o[3],c=t.dataSync(),l=new Float32Array(B([i,e,n,u])),h=[r&&1 1 for depthToSpace, but was: "+e});for(var r=t.shape[0],o=t.shape[1],i=t.shape[2],a=t.shape[3],s=o*e,u=i*e,c=a/(e*e),l=t.dataSync(),h=new Float32Array(r*s*u*c),p=0,f=0;f=t.size/s)throw new Error("Invalid indices: "+f+" does not index into "+t.shape);for(var g=0;gn)}var jl=Object.freeze({WEBGL_ENVS:{HAS_WEBGL:!0},PACKED_ENVS:{WEBGL_PACK:!0},NODE_ENVS:{IS_NODE:!0},CHROME_ENVS:{IS_CHROME:!0},BROWSER_ENVS:{IS_BROWSER:!0},CPU_ENVS:{HAS_WEBGL:!1},ALL_ENVS:{},expectArraysClose:Vl,expectPromiseToFail:function(t,e){t().then(function(){return e.fail()},function(){return e()})},expectArraysEqual:function(t,e){var n="string"==typeof e||"number"==typeof e||"boolean"==typeof e?[e]:e;return t instanceof dt&&"string"===t.dtype||e instanceof dt&&"string"===e.dtype||Array.isArray(t)&&V(t[0])||Array.isArray(e)&&V(e[0])?Hl(t,n,function(t,e){return t==e}):Vl(t,e,0)},expectNumbersClose:function(t,e,n){if(null==n&&(n=Zt.get("TEST_EPSILON")),!ql(t,e,n))throw new Error("Numbers differ: actual === "+t+", expected === "+e)},expectValuesInRange:function(t,e,n){var r;r=t instanceof dt?t.dataSync():t;for(var o=0;on)throw new Error("Value out of range:"+r[o]+" low: "+e+", high: "+n)},expectArrayBuffersEqual:function(t,e){expect(new Float32Array(t)).toEqual(new Float32Array(e))}}),$l=Object.freeze({gpgpu_util:Do,webgl_util:co,MathBackendWebGL:va,GPGPUContext:Mo}),Kl=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.minimize=function(t,e,n){void 0===e&&(e=!1);var r=this.computeGradients(t,n),o=r.value,i=r.grads;return this.applyGradients(i),Object.keys(i).forEach(function(t){return i[t].dispose()}),e?o:(o.dispose(),null)},e.prototype.computeGradients=function(t,e){return ie(t,e)},e.prototype.dispose=function(){},e}(Wl);Object.defineProperty(Kl,Symbol.hasInstance,{value:function(t){return null!=t.minimize&&null!=t.computeGradients&&null!=t.applyGradients}});var Xl=function(o){function t(t,e,n){void 0===n&&(n=null);var r=o.call(this)||this;return r.learningRate=t,r.rho=e,r.epsilon=n,r.accumulatedGrads={},r.accumulatedUpdates={},r.c=ce(Ve(-t)),r.rhoScalar=ce(Ve(e)),r.oneMinusRho=ce(Ve(1-e)),null===n&&(n=Zt.get("EPSILON")),r.epsilonScalar=ce(Ve(n)),r}return s(t,o),t.prototype.applyGradients=function(t){var c=this,e=function(o){var i=Zt.engine.registeredVariables[o];null==n.accumulatedGrads[o]&&ue(function(){c.accumulatedGrads[o]=nn(i).variable(!1)}),null==n.accumulatedUpdates[o]&&ue(function(){c.accumulatedUpdates[o]=nn(i).variable(!1)});var a=t[o],s=n.accumulatedGrads[o],u=n.accumulatedUpdates[o];ue(function(){var t=c.rhoScalar.mul(s).add(c.oneMinusRho.mul(a.square())),e=u.add(c.epsilonScalar).sqrt().div(s.add(c.epsilonScalar).sqrt()).mul(a),n=c.rhoScalar.mul(u).add(c.oneMinusRho.mul(e.square()));c.accumulatedGrads[o].assign(t),c.accumulatedUpdates[o].assign(n);var r=c.c.mul(e).add(i);i.assign(r)})},n=this;for(var r in t)e(r)},t.prototype.dispose=function(){var e=this;this.c.dispose(),this.epsilonScalar.dispose(),this.rhoScalar.dispose(),this.oneMinusRho.dispose(),null!=this.accumulatedUpdates&&(Object.keys(this.accumulatedUpdates).forEach(function(t){return e.accumulatedUpdates[t].dispose()}),Object.keys(this.accumulatedGrads).forEach(function(t){return e.accumulatedGrads[t].dispose()}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,rho:this.rho,epsilon:this.epsilon}},t.fromConfig=function(t,e){return new t(e.learningRate,e.rho,e.epsilon)},t.className="AdadeltaOptimizer",t}(Kl);Ul(Xl);var Yl=function(r){function t(t,e){void 0===e&&(e=.1);var n=r.call(this)||this;return n.learningRate=t,n.initialAccumulatorValue=e,n.accumulatedGrads={},n.c=ce(Ve(-t)),n.epsilon=ce(Ve(Zt.get("EPSILON"))),n}return s(t,r),t.prototype.applyGradients=function(t){var a=this,e=function(n){var r=Zt.engine.registeredVariables[n];null==s.accumulatedGrads[n]&&ue(function(){a.accumulatedGrads[n]=Je(r.shape,a.initialAccumulatorValue).variable(!1)});var o=t[n],i=s.accumulatedGrads[n];ue(function(){var t=i.add(o.square());a.accumulatedGrads[n].assign(t);var e=a.c.mul(o.div(t.add(a.epsilon).sqrt())).add(r);r.assign(e)})},s=this;for(var n in t)e(n)},t.prototype.dispose=function(){var e=this;this.epsilon.dispose(),this.c.dispose(),null!=this.accumulatedGrads&&Object.keys(this.accumulatedGrads).forEach(function(t){return e.accumulatedGrads[t].dispose()})},t.prototype.getConfig=function(){return{learningRate:this.learningRate,initialAccumulatorValue:this.initialAccumulatorValue}},t.fromConfig=function(t,e){return new t(e.learningRate,e.initialAccumulatorValue)},t.className="AdagradOptimizer",t}(Kl);Ul(Yl);var Ql=function(i){function t(t,e,n,r){void 0===r&&(r=null);var o=i.call(this)||this;return o.learningRate=t,o.beta1=e,o.beta2=n,o.epsilon=r,o.accumulatedFirstMoment={},o.accumulatedSecondMoment={},o.c=ce(Ve(-t)),o.beta1Scalar=ce(Ve(e)),o.beta2Scalar=ce(Ve(n)),ue(function(){o.accBeta1=Ve(e).variable(),o.accBeta2=Ve(n).variable()}),o.oneMinusBeta1=ce(Ve(1-e)),o.oneMinusBeta2=ce(Ve(1-n)),o.one=ce(Ve(1)),null===r&&(r=Zt.get("EPSILON")),o.epsScalar=ce(Ve(r)),o}return s(t,i),t.prototype.applyGradients=function(f){var d=this;ue(function(){var t=d.one.sub(d.accBeta1),e=d.one.sub(d.accBeta2);for(var n in f){var r=Zt.engine.registeredVariables[n];if(null==d.accumulatedFirstMoment[n]){var o=!1;d.accumulatedFirstMoment[n]=nn(r).variable(o)}null==d.accumulatedSecondMoment[n]&&(o=!1,d.accumulatedSecondMoment[n]=nn(r).variable(o));var i=f[n],a=d.accumulatedFirstMoment[n],s=d.accumulatedSecondMoment[n],u=d.beta1Scalar.mul(a).add(d.oneMinusBeta1.mul(i)),c=d.beta2Scalar.mul(s).add(d.oneMinusBeta2.mul(i.square())),l=u.div(t),h=c.div(e);d.accumulatedFirstMoment[n].assign(u),d.accumulatedSecondMoment[n].assign(c);var p=d.c.mul(l.div(d.epsScalar.add(h.sqrt()))).add(r);r.assign(p)}d.accBeta1.assign(d.accBeta1.mul(d.beta1Scalar)),d.accBeta2.assign(d.accBeta2.mul(d.beta2Scalar))})},t.prototype.dispose=function(){var e=this;this.c.dispose(),this.epsScalar.dispose(),this.beta1Scalar.dispose(),this.beta2Scalar.dispose(),this.accBeta1.dispose(),this.accBeta2.dispose(),this.oneMinusBeta1.dispose(),this.oneMinusBeta2.dispose(),this.one.dispose(),null!=this.accumulatedFirstMoment&&Object.keys(this.accumulatedFirstMoment).forEach(function(t){return e.accumulatedFirstMoment[t].dispose()}),null!=this.accumulatedSecondMoment&&Object.keys(this.accumulatedSecondMoment).forEach(function(t){return e.accumulatedSecondMoment[t].dispose()})},t.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon}},t.fromConfig=function(t,e){return new t(e.learningRate,e.beta1,e.beta2,e.epsilon)},t.className="AdamOptimizer",t}(Kl);Ul(Ql);var Jl=function(a){function t(t,e,n,r,o){void 0===r&&(r=null),void 0===o&&(o=0);var i=a.call(this)||this;return i.learningRate=t,i.beta1=e,i.beta2=n,i.epsilon=r,i.decay=o,i.accumulatedFirstMoment={},i.accumulatedWeightedInfNorm={},i.c=ce(Ve(-t)),i.beta1Scalar=ce(Ve(e)),i.beta2Scalar=ce(Ve(n)),i.decayScalar=ce(Ve(o)),ue(function(){i.iteration=Ve(0).variable(),i.accBeta1=Ve(e).variable()}),i.oneMinusBeta1=ce(Ve(1-e)),i.one=ce(Ve(1)),null===r&&(r=Zt.get("EPSILON")),i.epsScalar=ce(Ve(r)),i}return s(t,a),t.prototype.applyGradients=function(f){var d=this;ue(function(){var t=d.one.sub(d.accBeta1),e=d.c.div(d.one.add(d.decayScalar.mul(d.iteration)));for(var n in f){var r=Zt.engine.registeredVariables[n];if(null==d.accumulatedFirstMoment[n]){var o=!1;d.accumulatedFirstMoment[n]=nn(r).variable(o)}null==d.accumulatedWeightedInfNorm[n]&&(o=!1,d.accumulatedWeightedInfNorm[n]=nn(r).variable(o));var i=f[n],a=d.accumulatedFirstMoment[n],s=d.accumulatedWeightedInfNorm[n],u=d.beta1Scalar.mul(a).add(d.oneMinusBeta1.mul(i)),c=d.beta2Scalar.mul(s),l=i.abs(),h=c.maximum(l);d.accumulatedFirstMoment[n].assign(u),d.accumulatedWeightedInfNorm[n].assign(h);var p=e.div(t).mul(u.div(d.epsScalar.add(h))).add(r);r.assign(p)}d.iteration.assign(d.iteration.add(d.one)),d.accBeta1.assign(d.accBeta1.mul(d.beta1Scalar))})},t.prototype.dispose=function(){var e=this;this.c.dispose(),this.epsScalar.dispose(),this.accBeta1.dispose(),this.beta1Scalar.dispose(),this.beta2Scalar.dispose(),this.oneMinusBeta1.dispose(),this.decayScalar.dispose(),this.iteration.dispose(),this.one.dispose(),null!=this.accumulatedFirstMoment&&Object.keys(this.accumulatedFirstMoment).forEach(function(t){return e.accumulatedFirstMoment[t].dispose()}),null!=this.accumulatedWeightedInfNorm&&Object.keys(this.accumulatedWeightedInfNorm).forEach(function(t){return e.accumulatedWeightedInfNorm[t].dispose()})},t.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon,decay:this.decay}},t.fromConfig=function(t,e){return new t(e.learningRate,e.beta1,e.beta2,e.epsilon,e.decay)},t.className="AdamaxOptimizer",t}(Kl);Ul(Jl);var Zl=function(n){function t(t){var e=n.call(this)||this;return e.learningRate=t,e.setLearningRate(t),e}return s(t,n),t.prototype.applyGradients=function(r){var o=this;Object.keys(r).forEach(function(t){var e=r[t],n=Zt.engine.registeredVariables[t];ue(function(){var t=o.c.mul(e).add(n);n.assign(t)})})},t.prototype.setLearningRate=function(t){this.learningRate=t,null!=this.c&&this.c.dispose(),this.c=ce(Ve(-t))},t.prototype.dispose=function(){this.c.dispose()},t.prototype.getConfig=function(){return{learningRate:this.learningRate}},t.fromConfig=function(t,e){return new t(e.learningRate)},t.className="SGDOptimizer",t}(Kl);Ul(Zl);var th=function(o){function t(t,e,n){void 0===n&&(n=!1);var r=o.call(this,t)||this;return r.learningRate=t,r.momentum=e,r.useNesterov=n,r.m=Ve(r.momentum),r.accumulations={},r}return s(t,o),t.prototype.applyGradients=function(t){var a=this,e=function(n){var r=Zt.engine.registeredVariables[n];null==s.accumulations[n]&&ue(function(){a.accumulations[n]=nn(r).variable(!1)});var o=s.accumulations[n],i=t[n];ue(function(){var t,e=a.m.mul(o).add(i);t=a.useNesterov?a.c.mul(i.add(e.mul(a.m))).add(r):a.c.mul(e).add(r),a.accumulations[n].assign(e),r.assign(t)})},s=this;for(var n in t)e(n)},t.prototype.dispose=function(){if(o.prototype.dispose.call(this),this.m.dispose(),null!=this.accumulations)for(var t in this.accumulations)this.accumulations[t].dispose()},t.prototype.setMomentum=function(t){this.momentum=t},t.prototype.getConfig=function(){return{learningRate:this.learningRate,momentum:this.momentum,useNesterov:this.useNesterov}},t.fromConfig=function(t,e){return new t(e.learningRate,e.momentum,e.useNesterov)},t.className="MomentumOptimizer",t}(Zl);Ul(th);var eh=function(a){function t(t,e,n,r,o){void 0===e&&(e=.9),void 0===n&&(n=0),void 0===r&&(r=null),void 0===o&&(o=!1);var i=a.call(this)||this;return i.learningRate=t,i.decay=e,i.momentum=n,i.epsilon=r,i.accumulatedMeanSquares={},i.accumulatedMeanGrads={},i.accumulatedMoments={},i.c=ce(Ve(t)),i.decayScalar=ce(Ve(e)),i.momentumScalar=ce(Ve(n)),i.oneMinusDecay=ce(Ve(1-e)),i.centered=o,null===r&&(r=Zt.get("EPSILON")),i.epsilonScalar=ce(Ve(r)),i}return s(t,a),t.prototype.applyGradients=function(t){var h=this,e=function(i){var a=Zt.engine.registeredVariables[i];null==n.accumulatedMeanSquares[i]&&ue(function(){h.accumulatedMeanSquares[i]=nn(a).variable(!1)}),null==n.accumulatedMeanGrads[i]&&n.centered&&ue(function(){h.accumulatedMeanGrads[i]=nn(a).variable(!1)}),null==n.accumulatedMoments[i]&&ue(function(){h.accumulatedMoments[i]=nn(a).variable(!1)});var s=n.accumulatedMeanSquares[i],u=n.accumulatedMeanGrads[i],c=n.accumulatedMoments[i],l=t[i];ue(function(){var t=h.decayScalar.mul(s).add(h.oneMinusDecay.mul(l.square()));if(h.centered){var e=h.decayScalar.mul(u).add(h.oneMinusDecay.mul(l)),n=h.momentumScalar.mul(c).add(h.c.mul(l).div(t.sub(e.square().add(h.epsilonScalar)).sqrt()));h.accumulatedMeanSquares[i].assign(t),h.accumulatedMeanGrads[i].assign(e),h.accumulatedMoments[i].assign(n);var r=a.sub(n);a.assign(r)}else{var o=h.decayScalar.mul(s).add(h.oneMinusDecay.mul(l.square()));n=h.momentumScalar.mul(c).add(h.c.mul(l).div(o.add(h.epsilonScalar).sqrt())),h.accumulatedMeanSquares[i].assign(o),h.accumulatedMoments[i].assign(n),r=a.sub(n),a.assign(r)}})},n=this;for(var r in t)e(r)},t.prototype.dispose=function(){var e=this;this.c.dispose(),this.epsilonScalar.dispose(),this.decayScalar.dispose(),this.momentumScalar.dispose(),this.oneMinusDecay.dispose(),null!=this.accumulatedMeanSquares&&Object.keys(this.accumulatedMeanSquares).forEach(function(t){return e.accumulatedMeanSquares[t].dispose()}),null!=this.accumulatedMeanGrads&&this.centered&&Object.keys(this.accumulatedMeanGrads).forEach(function(t){return e.accumulatedMeanGrads[t].dispose()}),null!=this.accumulatedMoments&&Object.keys(this.accumulatedMoments).forEach(function(t){return e.accumulatedMoments[t].dispose()})},t.prototype.getConfig=function(){return{learningRate:this.learningRate,decay:this.decay,momentum:this.momentum,epsilon:this.epsilon,centered:this.centered}},t.fromConfig=function(t,e){return new t(e.learningRate,e.decay,e.momentum,e.epsilon,e.centered)},t.className="RMSPropOptimizer",t}(Kl);Ul(eh);var nh=function(){function t(){}return t.sgd=function(t){return new Zl(t)},t.momentum=function(t,e,n){return void 0===n&&(n=!1),new th(t,e,n)},t.rmsprop=function(t,e,n,r,o){return void 0===e&&(e=.9),void 0===n&&(n=0),void 0===r&&(r=null),void 0===o&&(o=!1),new eh(t,e,n,r,o)},t.adam=function(t,e,n,r){return void 0===t&&(t=.001),void 0===e&&(e=.9),void 0===n&&(n=.999),void 0===r&&(r=null),new Ql(t,e,n,r)},t.adadelta=function(t,e,n){return void 0===t&&(t=.001),void 0===e&&(e=.95),void 0===n&&(n=null),new Xl(t,e,n)},t.adamax=function(t,e,n,r,o){return void 0===t&&(t=.002),void 0===e&&(e=.9),void 0===n&&(n=.999),void 0===r&&(r=null),void 0===o&&(o=0),new Jl(t,e,n,r,o)},t.adagrad=function(t,e){return void 0===e&&(e=.1),new Yl(t,e)},t}(),rh={sgd:nh.sgd,momentum:nh.momentum,adadelta:nh.adadelta,adagrad:nh.adagrad,rmsprop:nh.rmsprop,adamax:nh.adamax,adam:nh.adam},oh=jt.setBackend,ih=jt.getBackend,ah=jt.disposeVariables,sh=jt.memory;pt=Gc;var uh=Object.freeze({setBackend:oh,getBackend:ih,disposeVariables:ah,memory:sh,version_core:"1.0.3",nextFrame:function(){return new Promise(function(t){return Hc(function(){return t()})})},enableProdMode:Kt,enableDebugMode:Xt,disableDeprecationWarnings:Yt,deprecationWarn:Qt,browser:Bl,environment:te,io:Ol,math:Fl,serialization:Gl,test_util:jl,util:t,webgl:$l,tensor_util:Pt,AdadeltaOptimizer:Xl,AdagradOptimizer:Yl,AdamOptimizer:Ql,AdamaxOptimizer:Jl,MomentumOptimizer:th,Optimizer:Kl,RMSPropOptimizer:eh,SGDOptimizer:Zl,Tensor:dt,TensorBuffer:lt,variable:Rt,Variable:vt,get Rank(){return mt},get Reduction(){return mc},ENV:Zt,Environment:jt,KernelBackend:on,DataStorage:rn,image:Wc,linalg:Dc,losses:kc,spectral:dc,fused:Uc,op:Fe,batchNormalization2d:os,batchNormalization3d:is,batchNormalization4d:as,batchNormalization:ss,batchNorm:us,batchNorm2d:cs,batchNorm3d:ls,batchNorm4d:hs,complex:We,real:ze,imag:Ue,concat:_i,concat1d:Si,concat2d:Ri,concat3d:Ni,concat4d:ki,split:Ii,conv1d:_s,conv2d:Ss,conv3d:Rs,conv2dDerFilter:Ns,depthwiseConv2d:ks,separableConv2d:Is,conv2dTranspose:Ts,matMul:As,dot:Ds,outerProduct:Ms,reverse:Os,reverse1d:Ps,reverse2d:Fs,reverse3d:Ls,reverse4d:Bs,maxPool:Us,avgPool:Gs,pool:Vs,slice:Hs,slice1d:qs,slice2d:js,slice3d:$s,slice4d:Ks,abs:ga,acos:ya,acosh:xa,asin:wa,asinh:ba,atan:Ea,atanh:Ca,ceil:_a,clipByValue:Sa,cos:Ra,cosh:Na,erf:ka,exp:Ia,expm1:Ta,floor:Aa,log:Da,log1p:Ma,logSigmoid:Oa,neg:Pa,reciprocal:Fa,round:La,rsqrt:Ba,sigmoid:Wa,sign:za,isNaN:Ua,isInf:Ga,isFinite:Va,sin:Ha,sinh:qa,softplus:ja,sqrt:$a,square:Ka,step:Xa,tan:Ya,tanh:Qa,all:Ys,any:Qs,argMax:Js,argMin:Zs,logSumExp:tu,max:eu,mean:nu,min:ru,moments:ou,sum:iu,prod:au,equal:su,equalStrict:uu,greater:cu,greaterEqual:lu,greaterEqualStrict:hu,greaterStrict:pu,less:fu,lessEqual:du,lessEqualStrict:vu,lessStrict:mu,notEqual:gu,notEqualStrict:yu,add:xu,addN:wu,addStrict:bu,atan2:Eu,div:Cu,divStrict:_u,floorDiv:Su,maximum:Ru,maximumStrict:Nu,minimum:ku,minimumStrict:Iu,mod:Tu,modStrict:Au,mul:Du,mulStrict:Mu,pow:Ou,powStrict:Pu,squaredDifference:Fu,squaredDifferenceStrict:Lu,sub:Bu,subStrict:Wu,elu:ju,leakyRelu:$u,prelu:Ku,relu:Xu,selu:Yu,logicalAnd:zu,logicalNot:Uu,logicalOr:Gu,logicalXor:Vu,where:Hu,whereAsync:qu,buffer:zi,print:Ui,batchToSpaceND:Gi,cast:Vi,clone:Hi,cumsum:qi,depthToSpace:ji,expandDims:$i,eye:Ki,multinomial:Xi,oneHot:Yi,pad:Qi,pad1d:Ji,pad2d:Zi,pad3d:ta,pad4d:ea,rand:na,randomNormal:ra,randomUniform:oa,reshape:ia,spaceToBatchND:aa,squeeze:sa,stack:ua,tile:ca,truncatedNormal:la,unstack:ha,setdiff1dAsync:pa,fill:Je,linspace:Ze,ones:Ye,range:tn,scalar:Ve,tensor:Ge,tensor1d:He,tensor2d:qe,tensor3d:je,tensor4d:$e,tensor5d:Ke,tensor6d:Xe,zeros:Qe,onesLike:en,zerosLike:nn,transpose:Qu,softmax:Le,logSoftmax:Be,localResponseNormalization:Ju,norm:Zu,gather:nc,unsortedSegmentSum:rc,basicLSTMCell:oc,multiRNNCell:ic,movingAverage:ac,stridedSlice:sc,topk:uc,scatterND:cc,fft:lc,ifft:hc,rfft:pc,irfft:fc,sparseToDense:vc,gatherND:yc,train:rh,tidy:ue,keep:ce,dispose:le,time:he,profile:pe,customGrad:ae,grad:function(i){return D(j(i),function(){return"The f passed in grad(f) must be a function"}),function(t,e){var r=re(t,"x","tf.grad",null),o=null!=e?re(e,"dy","tf.grad"):null;return Zt.engine.tidy(function(){var t=Zt.engine.gradients(function(){return i(r)},[r],o),e=t.value,n=t.grads;return null!=o&&g(e.shape,o.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),se(n),n[0]})}},grads:function(i){return D(j(i),function(){return"The f passed in grads(f) must be a function"}),function(t,e){D(Array.isArray(t),function(){return"The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s"});var r=oe(t,"args","tf.grads",null),o=null!=e?re(e,"dy","tf.grads"):null;return Zt.engine.tidy(function(){var t=Zt.engine.gradients(function(){return i.apply(void 0,r)},r,o),e=t.value,n=t.grads;return null!=o&&g(e.shape,o.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),se(n),n})}},valueAndGrad:function(i){return D(j(i),function(){return"The f passed in valueAndGrad(f) must be a function"}),function(t,e){D(t instanceof dt,function(){return"The x passed in valueAndGrad(f)(x) must be a tensor"}),D(null==e||e instanceof dt,function(){return"The dy passed in valueAndGrad(f)(x, dy) must be a tensor"});var n=Zt.engine.gradients(function(){return i(t)},[t],e),r=n.grads,o=n.value;return se(r),{grad:r[0],value:o}}},valueAndGrads:function(r){return D(j(r),function(){return"The f passed in valueAndGrads(f) must be a function"}),function(t,e){D(Array.isArray(t)&&t.every(function(t){return t instanceof dt}),function(){return"The args passed in valueAndGrads(f)(args) must be array of tensors"}),D(null==e||e instanceof dt,function(){return"The dy passed in valueAndGrads(f)(args, dy) must be a tensor"});var n=Zt.engine.gradients(function(){return r.apply(void 0,t)},t,e);return null!=e&&g(n.value.shape,e.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),se(n.grads),n}},variableGrads:ie}),ch=function(){function t(t,e){if(!Eh(t)||!Eh(e))throw new Error("Dimensions.constructor - expected width and height to be valid numbers, instead have "+JSON.stringify({width:t,height:e}));this._width=t,this._height=e}return Object.defineProperty(t.prototype,"width",{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},enumerable:!0,configurable:!0}),t.prototype.reverse=function(){return new t(1/this.width,1/this.height)},t}(),lh=function(){function e(t,e){this._x=t,this._y=e}return Object.defineProperty(e.prototype,"x",{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"y",{get:function(){return this._y},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return new e(this.x+t.x,this.y+t.y)},e.prototype.sub=function(t){return new e(this.x-t.x,this.y-t.y)},e.prototype.mul=function(t){return new e(this.x*t.x,this.y*t.y)},e.prototype.div=function(t){return new e(this.x/t.x,this.y/t.y)},e.prototype.abs=function(){return new e(Math.abs(this.x),Math.abs(this.y))},e.prototype.magnitude=function(){return Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2))},e.prototype.floor=function(){return new e(Math.floor(this.x),Math.floor(this.y))},e}();function hh(t,e){return t instanceof dt&&t.shape.length===e}function ph(t){return hh(t,2)}function fh(t){return hh(t,3)}function dh(t){return hh(t,4)}function vh(t){return t%1!=0}function mh(t){return t%2==0}function gh(t,e){void 0===e&&(e=2);var n=Math.pow(10,e);return Math.floor(t*n)/n}function yh(t){return t&&t.width&&t.height}function xh(t,e){var n=t.width,r=t.height,o=e/Math.max(r,n);return new ch(Math.round(n*o),Math.round(r*o))}function wh(t){return t.reduce(function(t,e){return t.add(e)},new lh(0,0)).div(new lh(t.length,t.length))}function bh(t,n,r){return Array(t).fill(0).map(function(t,e){return n+e*r})}function Eh(t){return!!t&&t!==1/0&&t!==-1/0&&!isNaN(t)||0===t}function Ch(t){return Eh(t)&&0<=t&&t<=1}var _h,Sh=function(){function l(t,e){void 0===e&&(e=!0);var n=t||{},r=[n.left,n.top,n.right,n.bottom].every(Eh),o=[n.x,n.y,n.width,n.height].every(Eh);if(!o&&!r)throw new Error("Box.constructor - expected box to be IBoundingBox | IRect, instead have "+JSON.stringify(n));var i=o?[n.x,n.y,n.width,n.height]:[n.left,n.top,n.right-n.left,n.bottom-n.top],a=i[0],s=i[1],u=i[2],c=i[3];l.assertIsValidBox({x:a,y:s,width:u,height:c},"Box.constructor",e),this._x=a,this._y=s,this._width=u,this._height=c}return l.isRect=function(t){return!!t&&[t.x,t.y,t.width,t.height].every(Eh)},l.assertIsValidBox=function(t,e,n){if(void 0===n&&(n=!1),!l.isRect(t))throw new Error(e+" - invalid box: "+JSON.stringify(t)+", expected object with properties x, y, width, height");if(!n&&(t.width<0||t.height<0))throw new Error(e+" - width ("+t.width+") and height ("+t.height+") must be positive numbers")},Object.defineProperty(l.prototype,"x",{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"y",{get:function(){return this._y},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"width",{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"height",{get:function(){return this._height},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"area",{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"topLeft",{get:function(){return new lh(this.left,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"topRight",{get:function(){return new lh(this.right,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"bottomLeft",{get:function(){return new lh(this.left,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"bottomRight",{get:function(){return new lh(this.right,this.bottom)},enumerable:!0,configurable:!0}),l.prototype.round=function(){var t=[this.x,this.y,this.width,this.height].map(function(t){return Math.round(t)});return new l({x:t[0],y:t[1],width:t[2],height:t[3]})},l.prototype.floor=function(){var t=[this.x,this.y,this.width,this.height].map(function(t){return Math.floor(t)});return new l({x:t[0],y:t[1],width:t[2],height:t[3]})},l.prototype.toSquare=function(){var t=this.x,e=this.y,n=this.width,r=this.height,o=Math.abs(n-r);return ne.classScore?t:e})]}})})},r.DEFAULT_FILTER_SIZES=[3,16,32,64,128,256,512,1024,1024],r}(xp),Pp=Object.freeze({convLayer:Kh,disposeUnusedWeightTensors:Xh,extractConvParamsFactory:Yh,extractFCParamsFactory:Qh,extractSeparableConvParamsFactory:Zh,loadSeparableConvParamsFactory:tp,extractWeightEntryFactory:ep,extractWeightsFactory:np,getModelUris:rp,SeparableConvParams:Jh,TinyYolov2:Op,get TinyYolov2SizeType(){return _p},TinyYolov2Options:Mp,validateConfig:Np});function Fp(i,a,t){if(void 0===t&&(t=!1),i.beginPath(),a.slice(1).forEach(function(t,e){var n=t.x,r=t.y,o=a[e];i.moveTo(o.x,o.y),i.lineTo(n,r)}),t){var e=a[a.length-1],n=a[0];if(!e||!n)return;i.moveTo(e.x,e.y),i.lineTo(n.x,n.y)}i.stroke()}var Lp=function(r){function o(t,e,n){return r.call(this,t,t,"",e,n)||this}return a(o,r),o.prototype.forSize=function(t,e){var n=r.prototype.forSize.call(this,t,e);return new o(n.score,n.relativeBox,n.imageDims)},o}(kh);function Bp(t){return t.detection instanceof Lp}function Wp(t,e){var n={detection:e};return Object.assign({},t,n)}function zp(e,n,r){return ue(function(){var t=Is(e,n.depthwise_filter,n.pointwise_filter,r,"same");return t=xu(t,n.bias)})}function Up(r,o,i){return void 0===i&&(i=!1),ue(function(){var t=Xu(i?xu(Ss(r,o.conv0.filters,[2,2],"same"),o.conv0.bias):zp(r,o.conv0,[2,2])),e=zp(t,o.conv1,[1,1]),n=zp(Xu(xu(t,e)),o.conv2,[1,1]);return Xu(xu(t,xu(e,n)))})}function Gp(o,i,a,s){return void 0===a&&(a=!1),void 0===s&&(s=!0),ue(function(){var t=Xu(a?xu(Ss(o,i.conv0.filters,s?[2,2]:[1,1],"same"),i.conv0.bias):zp(o,i.conv0,s?[2,2]:[1,1])),e=zp(t,i.conv1,[1,1]),n=zp(Xu(xu(t,e)),i.conv2,[1,1]),r=zp(Xu(xu(t,xu(e,n))),i.conv3,[1,1]);return Xu(xu(t,xu(e,xu(n,r))))})}function Vp(t,e){var o=Yh(t,e),i=Zh(t,e);function a(t,e,n,r){return void 0===r&&(r=!1),{conv0:r?o(t,e,3,n+"/conv0"):i(t,e,n+"/conv0"),conv1:i(e,e,n+"/conv1"),conv2:i(e,e,n+"/conv2")}}return{extractDenseBlock3Params:a,extractDenseBlock4Params:function(t,e,n,r){void 0===r&&(r=!1);var o=a(t,e,n,r);return{conv0:o.conv0,conv1:o.conv1,conv2:o.conv2,conv3:i(e,e,n+"/conv3")}}}}function Hp(e){return function(t){return{filters:e(t+"/filters",4),bias:e(t+"/bias",1)}}}function qp(t,e){var n=ep(t,e),r=Hp(n),o=tp(n);return{extractDenseBlock3Params:function(t,e){return void 0===e&&(e=!1),{conv0:e?r(t+"/conv0"):o(t+"/conv0"),conv1:o(t+"/conv1"),conv2:o(t+"/conv2")}},extractDenseBlock4Params:function(t,e){return void 0===e&&(e=!1),{conv0:e?r(t+"/conv0"):o(t+"/conv0"),conv1:o(t+"/conv1"),conv2:o(t+"/conv2"),conv3:o(t+"/conv3")}}}}var jp=function(t){function e(){return t.call(this,"FaceFeatureExtractor")||this}return a(e,t),e.prototype.forwardInput=function(e){var n=this.params;if(!n)throw new Error("FaceFeatureExtractor - load model before inference");return ue(function(){var t=Gp(Ep(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(Ve(255)),n.dense0,!0);return t=Gp(t=Gp(t=Gp(t,n.dense1),n.dense2),n.dense3),t=Gs(t,[7,7],[2,2],"valid")})},e.prototype.forward=function(n){return p(this,void 0,void 0,function(){var e;return P(this,function(t){switch(t.label){case 0:return e=this.forwardInput,[4,yp(n)];case 1:return[2,e.apply(this,[t.sent()])]}})})},e.prototype.getDefaultModelName=function(){return"face_feature_extractor_model"},e.prototype.extractParamsFromWeigthMap=function(t){return r=qp(e=t,n=[]).extractDenseBlock4Params,o={dense0:r("dense0",!0),dense1:r("dense1"),dense2:r("dense2"),dense3:r("dense3")},Xh(e,n),{params:o,paramMappings:n};var e,n,r,o},e.prototype.extractParams=function(t){return function(t){var e=[],n=np(t),r=n.extractWeights,o=n.getRemainingWeights,i=Vp(r,e).extractDenseBlock4Params,a=i(3,32,"dense0",!0),s=i(32,64,"dense1"),u=i(64,128,"dense2"),c=i(128,256,"dense3");if(0!==o().length)throw new Error("weights remaing after extract: "+o().length);return{paramMappings:e,params:{dense0:a,dense1:s,dense2:u,dense3:c}}}(t)},e}(xp);function $p(t,e){return ue(function(){return xu(As(t,e.weights),e.bias)})}function Kp(e){var n={},r={};return Object.keys(e).forEach(function(t){(t.startsWith("fc")?r:n)[t]=e[t]}),{featureExtractorMap:n,classifierMap:r}}var Xp=function(r){function t(t,e){var n=r.call(this,t)||this;return n._faceFeatureExtractor=e,n}return a(t,r),Object.defineProperty(t.prototype,"faceFeatureExtractor",{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),t.prototype.runNet=function(e){var n=this,r=this.params;if(!r)throw new Error(this._name+" - load model before inference");return ue(function(){var t=e instanceof gp?n.faceFeatureExtractor.forwardInput(e):e;return $p(t.as2D(t.shape[0],-1),r.fc)})},t.prototype.dispose=function(t){void 0===t&&(t=!0),this.faceFeatureExtractor.dispose(t),r.prototype.dispose.call(this,t)},t.prototype.loadClassifierParams=function(t){var e=this.extractClassifierParams(t),n=e.params,r=e.paramMappings;this._params=n,this._paramMappings=r},t.prototype.extractClassifierParams=function(t){return function(t,e,n){var r=[],o=np(t),i=o.extractWeights,a=o.getRemainingWeights,s=Qh(i,r)(e,n,"fc");if(0!==a().length)throw new Error("weights remaing after extract: "+a().length);return{paramMappings:r,params:{fc:s}}}(t,this.getClassifierChannelsIn(),this.getClassifierChannelsOut())},t.prototype.extractParamsFromWeigthMap=function(t){var e,n,r,o,i,a=Kp(t),s=a.featureExtractorMap,u=a.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(s),o=ep(e=u,r=[]),i={fc:(n="fc",{weights:o(n+"/weights",2),bias:o(n+"/bias",1)})},Xh(e,r),{params:i,paramMappings:r}},t.prototype.extractParams=function(t){var e=this.getClassifierChannelsIn(),n=this.getClassifierChannelsOut(),r=n*e+n,o=t.slice(0,t.length-r),i=t.slice(t.length-r);return this.faceFeatureExtractor.extractWeights(o),this.extractClassifierParams(i)},t}(xp),Yp=["neutral","happy","sad","angry","fearful","disgusted","surprised"],Qp=function(){function t(n){var r=this;if(7!==n.length)throw new Error("FaceExpressions.constructor - expected probabilities.length to be 7, have: "+n.length);Yp.forEach(function(t,e){r[t]=n[e]})}return t.prototype.asSortedArray=function(){var e=this;return Yp.map(function(t){return{expression:t,probability:e[t]}}).sort(function(t,e){return e.probability-t.probability})},t}(),Jp=function(e){function t(t){return void 0===t&&(t=new jp),e.call(this,"FaceExpressionNet",t)||this}return a(t,e),t.prototype.forwardInput=function(t){var e=this;return ue(function(){return Le(e.runNet(t))})},t.prototype.forward=function(n){return p(this,void 0,void 0,function(){var e;return P(this,function(t){switch(t.label){case 0:return e=this.forwardInput,[4,yp(n)];case 1:return[2,e.apply(this,[t.sent()])]}})})},t.prototype.predictExpressions=function(a){return p(this,void 0,void 0,function(){var e,n,r,o,i=this;return P(this,function(t){switch(t.label){case 0:return[4,yp(a)];case 1:return e=t.sent(),[4,this.forwardInput(e)];case 2:return n=t.sent(),[4,Promise.all(ha(n).map(function(n){return p(i,void 0,void 0,function(){var e;return P(this,function(t){switch(t.label){case 0:return[4,n.data()];case 1:return e=t.sent(),n.dispose(),[2,e]}})})}))];case 3:return r=t.sent(),n.dispose(),o=r.map(function(t){return new Qp(t)}),[2,e.isBatchInput?o:o[0]]}})})},t.prototype.getDefaultModelName=function(){return"face_expression_model"},t.prototype.getClassifierChannelsIn=function(){return 256},t.prototype.getClassifierChannelsOut=function(){return 7},t}(Xp);function Zp(t){return t.expressions instanceof Qp}function tf(t,e){var n={expressions:e};return Object.assign({},t,n)}var ef=function(){function t(t,e,n){void 0===n&&(n=new lh(0,0));var r=e.width,o=e.height;this._imgDims=new ch(r,o),this._shift=n,this._positions=t.map(function(t){return t.mul(new lh(r,o)).add(n)})}return Object.defineProperty(t.prototype,"shift",{get:function(){return new lh(this._shift.x,this._shift.y)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"imageWidth",{get:function(){return this._imgDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"imageHeight",{get:function(){return this._imgDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"positions",{get:function(){return this._positions},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"relativePositions",{get:function(){var e=this;return this._positions.map(function(t){return t.sub(e._shift).div(new lh(e.imageWidth,e.imageHeight))})},enumerable:!0,configurable:!0}),t.prototype.forSize=function(t,e){return new this.constructor(this.relativePositions,{width:t,height:e})},t.prototype.shiftBy=function(t,e){return new this.constructor(this.relativePositions,this._imgDims,new lh(t,e))},t.prototype.shiftByPoint=function(t){return this.shiftBy(t.x,t.y)},t.prototype.align=function(t,e){if(void 0===e&&(e={}),t){var n=t instanceof Lp?t.box.floor():new Sh(t);return this.shiftBy(n.x,n.y).align(null,e)}var r=Object.assign({},{useDlibAlignment:!1,minBoxPadding:.2},e),o=r.useDlibAlignment,i=r.minBoxPadding;return o?this.alignDlib():this.alignMinBbox(i)},t.prototype.alignDlib=function(){var t=this.getRefPointsForAlignment(),e=t[0],n=t[1],r=t[2],o=function(t){return r.sub(t).magnitude()},i=(o(e)+o(n))/2,a=Math.floor(i/.45),s=wh(t),u=Math.floor(Math.max(0,s.x-.5*a)),c=Math.floor(Math.max(0,s.y-.43*a));return new Th(u,c,Math.min(a,this.imageWidth+u),Math.min(a,this.imageHeight+c))},t.prototype.alignMinBbox=function(t){var e,n,r,o,i,a,s,u=(e=this.positions,n=e.map(function(t){return t.x}),r=e.map(function(t){return t.y}),o=n.reduce(function(t,e){return e or array thereof");var n=e.asSortedArray().filter(function(t){return t.probability>i}),r=Bp(t)?t.detection.box.bottomLeft:a||new lh(0,0);new Hh(n.map(function(t){return t.expression+" ("+gh(t.probability)+")"}),r).draw(o)})},DrawFaceLandmarksOptions:af,DrawFaceLandmarks:sf,drawFaceLandmarks:function(n,t){(Array.isArray(t)?t:[t]).forEach(function(t){var e=t instanceof ef?t:rf(t)?t.landmarks:void 0;if(!e)throw new Error("drawFaceLandmarks - expected faceExpressions to be FaceLandmarks | WithFaceLandmarks> or array thereof");new sf(e).draw(n)})}});function cf(t,e){var n,r,o,i,a=[],s=np(t),u=s.extractWeights,c=s.getRemainingWeights,l=(o=Yh(n=u,r=a),i=Zh(n,r),{extractConvParams:o,extractSeparableConvParams:i,extractReductionBlockParams:function(t,e,n){return{separable_conv0:i(t,e,n+"/separable_conv0"),separable_conv1:i(e,e,n+"/separable_conv1"),expansion_conv:o(t,e,1,n+"/expansion_conv")}},extractMainBlockParams:function(t,e){return{separable_conv0:i(t,t,e+"/separable_conv0"),separable_conv1:i(t,t,e+"/separable_conv1"),separable_conv2:i(t,t,e+"/separable_conv2")}}}),h=l.extractSeparableConvParams,p=l.extractReductionBlockParams,f=l.extractMainBlockParams,d={conv_in:(0,l.extractConvParams)(3,32,3,"entry_flow/conv_in"),reduction_block_0:p(32,64,"entry_flow/reduction_block_0"),reduction_block_1:p(64,128,"entry_flow/reduction_block_1")},v={};bh(e,0,1).forEach(function(t){v["main_block_"+t]=f(128,"middle_flow/main_block_"+t)});var m={reduction_block:p(128,256,"exit_flow/reduction_block"),separable_conv:h(256,512,"exit_flow/separable_conv")};if(0!==c().length)throw new Error("weights remaing after extract: "+c().length);return{paramMappings:a,params:{entry_flow:d,middle_flow:v,exit_flow:m}}}function lf(t,e){var n,r,o,i=[],a=(n=ep(t,i),r=Hp(n),o=tp(n),{extractConvParams:r,extractSeparableConvParams:o,extractReductionBlockParams:function(t){return{separable_conv0:o(t+"/separable_conv0"),separable_conv1:o(t+"/separable_conv1"),expansion_conv:r(t+"/expansion_conv")}},extractMainBlockParams:function(t){return{separable_conv0:o(t+"/separable_conv0"),separable_conv1:o(t+"/separable_conv1"),separable_conv2:o(t+"/separable_conv2")}}}),s=a.extractSeparableConvParams,u=a.extractReductionBlockParams,c=a.extractMainBlockParams,l={conv_in:(0,a.extractConvParams)("entry_flow/conv_in"),reduction_block_0:u("entry_flow/reduction_block_0"),reduction_block_1:u("entry_flow/reduction_block_1")},h={};bh(e,0,1).forEach(function(t){h["main_block_"+t]=c("middle_flow/main_block_"+t)});var p={reduction_block:u("exit_flow/reduction_block"),separable_conv:s("exit_flow/separable_conv")};return Xh(t,i),{params:{entry_flow:l,middle_flow:h,exit_flow:p},paramMappings:i}}function hf(t,e,n){return xu(Ss(t,e.filters,n,"same"),e.bias)}function pf(t,e,n){void 0===n&&(n=!0);var r=n?Xu(t):t;return r=zp(r,e.separable_conv0,[1,1]),r=zp(Xu(r),e.separable_conv1,[1,1]),r=Us(r,[3,3],[2,2],"same"),r=xu(r,hf(t,e.expansion_conv,[2,2]))}var ff,df=function(n){function t(t){var e=n.call(this,"TinyXception")||this;return e._numMainBlocks=t,e}return a(t,n),t.prototype.forwardInput=function(e){var n=this,i=this.params;if(!i)throw new Error("TinyXception - load model before inference");return ue(function(){var t=Ep(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(Ve(256)),o=Xu(hf(t,i.entry_flow.conv_in,[2,2]));return o=pf(o=pf(o,i.entry_flow.reduction_block_0,!1),i.entry_flow.reduction_block_1),bh(n._numMainBlocks,0,1).forEach(function(t){var e,n,r;e=o,n=i.middle_flow["main_block_"+t],r=zp(Xu(e),n.separable_conv0,[1,1]),r=zp(Xu(r),n.separable_conv1,[1,1]),r=zp(Xu(r),n.separable_conv2,[1,1]),o=r=xu(r,e)}),o=pf(o,i.exit_flow.reduction_block),o=Xu(zp(o,i.exit_flow.separable_conv,[1,1]))})},t.prototype.forward=function(n){return p(this,void 0,void 0,function(){var e;return P(this,function(t){switch(t.label){case 0:return e=this.forwardInput,[4,yp(n)];case 1:return[2,e.apply(this,[t.sent()])]}})})},t.prototype.getDefaultModelName=function(){return"tiny_xception_model"},t.prototype.extractParamsFromWeigthMap=function(t){return lf(t,this._numMainBlocks)},t.prototype.extractParams=function(t){return cf(t,this._numMainBlocks)},t}(xp);(ff=c.Gender||(c.Gender={})).FEMALE="female",ff.MALE="male";var vf=function(n){function t(t){void 0===t&&(t=new df(2));var e=n.call(this,"AgeGenderNet")||this;return e._faceFeatureExtractor=t,e}return a(t,n),Object.defineProperty(t.prototype,"faceFeatureExtractor",{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),t.prototype.runNet=function(n){var r=this,o=this.params;if(!o)throw new Error(this._name+" - load model before inference");return ue(function(){var t=n instanceof gp?r.faceFeatureExtractor.forwardInput(n):n,e=Gs(t,[7,7],[2,2],"valid").as2D(t.shape[0],-1);return{age:$p(e,o.fc.age).as1D(),gender:$p(e,o.fc.gender)}})},t.prototype.forwardInput=function(r){var o=this;return ue(function(){var t=o.runNet(r),e=t.age,n=t.gender;return{age:e,gender:Le(n)}})},t.prototype.forward=function(n){return p(this,void 0,void 0,function(){var e;return P(this,function(t){switch(t.label){case 0:return e=this.forwardInput,[4,yp(n)];case 1:return[2,e.apply(this,[t.sent()])]}})})},t.prototype.predictAgeAndGender=function(s){return p(this,void 0,void 0,function(){var e,n,r,o,i,a,u=this;return P(this,function(t){switch(t.label){case 0:return[4,yp(s)];case 1:return e=t.sent(),[4,this.forwardInput(e)];case 2:return n=t.sent(),r=ha(n.age),o=ha(n.gender),i=r.map(function(t,e){return{ageTensor:t,genderTensor:o[e]}}),[4,Promise.all(i.map(function(t){var a=t.ageTensor,s=t.genderTensor;return p(u,void 0,void 0,function(){var e,n,r,o,i;return P(this,function(t){switch(t.label){case 0:return[4,a.data()];case 1:return e=t.sent()[0],[4,s.data()];case 2:return n=t.sent()[0],o=(r=.5 1 not supported");return(o=r.getInput(0))instanceof e?(i=o,[3,4]):[3,2];case 2:return[4,pp(o)];case 3:i=t.sent(),t.label=4;case 4:n=i,t.label=5;case 5:return a=Gh(n),[2,u.map(function(t){return t instanceof Lp?t.forSize(n.width,n.height).box.floor():t}).map(function(t){return t.clipAtImageBorders(n.width,n.height)}).map(function(t){var e=t.x,n=t.y,r=t.width,o=t.height,i=up({width:r,height:o});return Gh(i).putImageData(a.getImageData(e,n,r,o),0,0),i})]}})})}function wf(u,e){return p(this,void 0,void 0,function(){return P(this,function(t){if(!fh(u)&&!dh(u))throw new Error("extractFaceTensors - expected image tensor to be 3D or 4D");if(dh(u)&&1 1 not supported");return[2,ue(function(){var t=u.shape.slice(dh(u)?1:0),i=t[0],a=t[1],s=t[2];return e.map(function(t){return t instanceof Lp?t.forSize(a,i).box:t}).map(function(t){return t.clipAtImageBorders(a,i)}).map(function(t){var e=t.x,n=t.y,r=t.width,o=t.height;return $s(u.as3D(i,a,s),[n,e,0],[o,r,s])})})]})})}var bf=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.postProcess=function(t,o,e){var i=e.map(function(t){var e=t.width,n=t.height,r=o/Math.max(n,e);return{width:e*r,height:n*r}}),a=i.length;return ue(function(){var n=function(t,e){return ua([Je([68],t),Je([68],e)],1).as2D(1,136).as1D()},r=function(t,e){var n=i[t],r=n.width,o=n.height;return e(r,o)?Math.abs(r-o)/2:0};return t.mul(Je([a,136],o)).sub(ua(Array.from(Array(a),function(t,e){return n(r(e,function(t,e){return t 0");if("number"!=typeof this._scaleFactor||this._scaleFactor<=0||1<=this._scaleFactor)throw new Error(this._name+" - expected scaleFactor to be a number between 0 and 1");if("number"!=typeof this._maxNumScales||this._maxNumScales<0)throw new Error(this._name+" - expected maxNumScales to be a number > 0");if(!Array.isArray(this._scoreThresholds)||3!==this._scoreThresholds.length||this._scoreThresholds.some(function(t){return"number"!=typeof t}))throw new Error(this._name+" - expected scoreThresholds to be an array of numbers of length 3");if(this._scaleSteps&&(!Array.isArray(this._scaleSteps)||this._scaleSteps.some(function(t){return"number"!=typeof t})))throw new Error(this._name+" - expected scaleSteps to be an array of numbers")}return Object.defineProperty(t.prototype,"minFaceSize",{get:function(){return this._minFaceSize},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scaleFactor",{get:function(){return this._scaleFactor},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxNumScales",{get:function(){return this._maxNumScales},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scoreThresholds",{get:function(){return this._scoreThresholds},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scaleSteps",{get:function(){return this._scaleSteps},enumerable:!0,configurable:!0}),t}();function Ff(l,h){function i(t,e,n,r,o){var i=$e(l(t*e*n*n),[n,n,t,e]),a=He(l(e));return h.push({paramPath:r+"/filters"},{paramPath:r+"/"+(o?"batch_norm_offset":"bias")}),{filters:i,bias:a}}function p(t,e,n,r){var o=i(t,e,n,r,!0);return{filters:o.filters,batch_norm_offset:o.bias}}function t(t,e,n){var r,o,i,a,s,u,c;return{depthwise_conv:(o=n+"/depthwise_conv",i=$e(l(9*(r=t)),[3,3,r,1]),a=He(l(r)),s=He(l(r)),u=He(l(r)),c=He(l(r)),h.push({paramPath:o+"/filters"},{paramPath:o+"/batch_norm_scale"},{paramPath:o+"/batch_norm_offset"},{paramPath:o+"/batch_norm_mean"},{paramPath:o+"/batch_norm_variance"}),{filters:i,batch_norm_scale:a,batch_norm_offset:s,batch_norm_mean:u,batch_norm_variance:c}),pointwise_conv:p(t,e,1,n+"/pointwise_conv")}}return{extractMobilenetV1Params:function(){return{conv_0:p(3,32,3,"mobilenetv1/conv_0"),conv_1:t(32,64,"mobilenetv1/conv_1"),conv_2:t(64,128,"mobilenetv1/conv_2"),conv_3:t(128,128,"mobilenetv1/conv_3"),conv_4:t(128,256,"mobilenetv1/conv_4"),conv_5:t(256,256,"mobilenetv1/conv_5"),conv_6:t(256,512,"mobilenetv1/conv_6"),conv_7:t(512,512,"mobilenetv1/conv_7"),conv_8:t(512,512,"mobilenetv1/conv_8"),conv_9:t(512,512,"mobilenetv1/conv_9"),conv_10:t(512,512,"mobilenetv1/conv_10"),conv_11:t(512,512,"mobilenetv1/conv_11"),conv_12:t(512,1024,"mobilenetv1/conv_12"),conv_13:t(1024,1024,"mobilenetv1/conv_13")}},extractPredictionLayerParams:function(){return{conv_0:p(1024,256,1,"prediction_layer/conv_0"),conv_1:p(256,512,3,"prediction_layer/conv_1"),conv_2:p(512,128,1,"prediction_layer/conv_2"),conv_3:p(128,256,3,"prediction_layer/conv_3"),conv_4:p(256,128,1,"prediction_layer/conv_4"),conv_5:p(128,256,3,"prediction_layer/conv_5"),conv_6:p(256,64,1,"prediction_layer/conv_6"),conv_7:p(64,128,3,"prediction_layer/conv_7"),box_predictor_0:{box_encoding_predictor:i(512,12,1,"prediction_layer/box_predictor_0/box_encoding_predictor"),class_predictor:i(512,9,1,"prediction_layer/box_predictor_0/class_predictor")},box_predictor_1:{box_encoding_predictor:i(1024,24,1,"prediction_layer/box_predictor_1/box_encoding_predictor"),class_predictor:i(1024,18,1,"prediction_layer/box_predictor_1/class_predictor")},box_predictor_2:{box_encoding_predictor:i(512,24,1,"prediction_layer/box_predictor_2/box_encoding_predictor"),class_predictor:i(512,18,1,"prediction_layer/box_predictor_2/class_predictor")},box_predictor_3:{box_encoding_predictor:i(256,24,1,"prediction_layer/box_predictor_3/box_encoding_predictor"),class_predictor:i(256,18,1,"prediction_layer/box_predictor_3/class_predictor")},box_predictor_4:{box_encoding_predictor:i(256,24,1,"prediction_layer/box_predictor_4/box_encoding_predictor"),class_predictor:i(256,18,1,"prediction_layer/box_predictor_4/class_predictor")},box_predictor_5:{box_encoding_predictor:i(128,24,1,"prediction_layer/box_predictor_5/box_encoding_predictor"),class_predictor:i(128,18,1,"prediction_layer/box_predictor_5/class_predictor")}}}}}function Lf(t){var e=[],n=function(t,e){var i=ep(t,e);function a(t,e,n){return{filters:i(t+"/Conv2d_"+e+"_pointwise/weights",4,n+"/filters"),batch_norm_offset:i(t+"/Conv2d_"+e+"_pointwise/convolution_bn_offset",1,n+"/batch_norm_offset")}}function n(t){var e="mobilenetv1/conv_"+t,n="MobilenetV1/Conv2d_"+t+"_depthwise",r=e+"/depthwise_conv",o=e+"/pointwise_conv";return{depthwise_conv:{filters:i(n+"/depthwise_weights",4,r+"/filters"),batch_norm_scale:i(n+"/BatchNorm/gamma",1,r+"/batch_norm_scale"),batch_norm_offset:i(n+"/BatchNorm/beta",1,r+"/batch_norm_offset"),batch_norm_mean:i(n+"/BatchNorm/moving_mean",1,r+"/batch_norm_mean"),batch_norm_variance:i(n+"/BatchNorm/moving_variance",1,r+"/batch_norm_variance")},pointwise_conv:a("MobilenetV1",t,o)}}function r(t,e){return{filters:i(t+"/weights",4,e+"/filters"),bias:i(t+"/biases",1,e+"/bias")}}function o(t){return{box_encoding_predictor:r("Prediction/BoxPredictor_"+t+"/BoxEncodingPredictor","prediction_layer/box_predictor_"+t+"/box_encoding_predictor"),class_predictor:r("Prediction/BoxPredictor_"+t+"/ClassPredictor","prediction_layer/box_predictor_"+t+"/class_predictor")}}return{extractMobilenetV1Params:function(){return{conv_0:a("MobilenetV1",0,"mobilenetv1/conv_0"),conv_1:n(1),conv_2:n(2),conv_3:n(3),conv_4:n(4),conv_5:n(5),conv_6:n(6),conv_7:n(7),conv_8:n(8),conv_9:n(9),conv_10:n(10),conv_11:n(11),conv_12:n(12),conv_13:n(13)}},extractPredictionLayerParams:function(){return{conv_0:a("Prediction",0,"prediction_layer/conv_0"),conv_1:a("Prediction",1,"prediction_layer/conv_1"),conv_2:a("Prediction",2,"prediction_layer/conv_2"),conv_3:a("Prediction",3,"prediction_layer/conv_3"),conv_4:a("Prediction",4,"prediction_layer/conv_4"),conv_5:a("Prediction",5,"prediction_layer/conv_5"),conv_6:a("Prediction",6,"prediction_layer/conv_6"),conv_7:a("Prediction",7,"prediction_layer/conv_7"),box_predictor_0:o(0),box_predictor_1:o(1),box_predictor_2:o(2),box_predictor_3:o(3),box_predictor_4:o(4),box_predictor_5:o(5)}}}}(t,e),r=n.extractMobilenetV1Params,o=n.extractPredictionLayerParams,i=t["Output/extra_dim"];if(e.push({originalPath:"Output/extra_dim",paramPath:"output_layer/extra_dim"}),!fh(i))throw new Error("expected weightMap['Output/extra_dim'] to be a Tensor3D, instead have "+i);var a={mobilenetv1:r(),prediction_layer:o(),output_layer:{extra_dim:i}};return Xh(t,e),{params:a,paramMappings:e}}function Bf(e,n,r){return ue(function(){var t=Ss(e,n.filters,r,"same");return t=xu(t,n.batch_norm_offset),Sa(t,0,6)})}var Wf=.0010000000474974513;function zf(t,e){return ue(function(){var u=null,c=Bf(t,e.conv_0,[2,2]);if([e.conv_1,e.conv_2,e.conv_3,e.conv_4,e.conv_5,e.conv_6,e.conv_7,e.conv_8,e.conv_9,e.conv_10,e.conv_11,e.conv_12,e.conv_13].forEach(function(t,e){var n,r,o,i,a=e+1,s=(n=a,[2,4,6,12].some(function(t){return t===n})?[2,2]:[1,1]);r=c,o=t.depthwise_conv,i=s,c=Bf(c=ue(function(){var t=ks(r,o.filters,i,"same");return t=us(t,o.batch_norm_mean,o.batch_norm_variance,o.batch_norm_offset,o.batch_norm_scale,Wf),Sa(t,0,6)}),t.pointwise_conv,[1,1]),11===a&&(u=c)}),null===u)throw new Error("mobileNetV1 - output of conv layer 11 is null");return{out:c,conv11:u}})}function Uf(t,e,n){var r=t.arraySync(),o=Math.min(r[e][0],r[e][2]),i=Math.min(r[e][1],r[e][3]),a=Math.max(r[e][0],r[e][2]),s=Math.max(r[e][1],r[e][3]),u=Math.min(r[n][0],r[n][2]),c=Math.min(r[n][1],r[n][3]),l=Math.max(r[n][0],r[n][2]),h=Math.max(r[n][1],r[n][3]),p=(a-o)*(s-i),f=(l-u)*(h-c);if(p<=0||f<=0)return 0;var d=Math.max(o,u),v=Math.max(i,c),m=Math.min(a,l),g=Math.min(s,h),y=Math.max(m-d,0)*Math.max(g-v,0);return y/(p+f-y)}function Gf(t,e){var n,r,o=(n=ha(Qu(t,[1,0])),{sizes:r=[Bu(n[2],n[0]),Bu(n[3],n[1])],centers:[xu(n[0],Cu(r[0],Ve(2))),xu(n[1],Cu(r[1],Ve(2)))]}),i=o.sizes,a=o.centers,s=ha(Qu(e,[1,0])),u=Cu(Du(Ia(Cu(s[2],Ve(5))),i[0]),Ve(2)),c=xu(Du(Cu(s[0],Ve(10)),i[0]),a[0]),l=Cu(Du(Ia(Cu(s[3],Ve(5))),i[1]),Ve(2)),h=xu(Du(Cu(s[1],Ve(10)),i[1]),a[1]);return Qu(ua([Bu(c,u),Bu(h,l),xu(c,u),xu(h,l)]),[1,0])}function Vf(e,n){return ue(function(){var t=e.shape[0];return{boxPredictionEncoding:ia(Kh(e,n.box_encoding_predictor),[t,-1,1,4]),classPrediction:ia(Kh(e,n.class_predictor),[t,-1,3])}})}var Hf=function(){function t(t){var e=void 0===t?{}:t,n=e.minConfidence,r=e.maxResults;if(this._name="SsdMobilenetv1Options",this._minConfidence=n||.5,this._maxResults=r||100,"number"!=typeof this._minConfidence||this._minConfidence<=0||1<=this._minConfidence)throw new Error(this._name+" - expected minConfidence to be a number between 0 and 1");if("number"!=typeof this._maxResults)throw new Error(this._name+" - expected maxResults to be a number")}return Object.defineProperty(t.prototype,"minConfidence",{get:function(){return this._minConfidence},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxResults",{get:function(){return this._maxResults},enumerable:!0,configurable:!0}),t}(),qf=function(t){function e(){return t.call(this,"SsdMobilenetv1")||this}return a(e,t),e.prototype.forwardInput=function(u){var c=this.params;if(!c)throw new Error("SsdMobilenetv1 - load model before inference");return ue(function(){var l,h,p,o,i,a,t=u.toBatchTensor(512,!1).toFloat(),e=zf(Bu(Du(t,Ve(.007843137718737125)),Ve(1)),c.mobilenetv1),n=(l=e.out,h=e.conv11,p=c.prediction_layer,ue(function(){var t=Bf(Bf(l,p.conv_0,[1,1]),p.conv_1,[2,2]),e=Bf(Bf(t,p.conv_2,[1,1]),p.conv_3,[2,2]),n=Bf(Bf(e,p.conv_4,[1,1]),p.conv_5,[2,2]),r=Bf(Bf(n,p.conv_6,[1,1]),p.conv_7,[2,2]),o=Vf(h,p.box_predictor_0),i=Vf(l,p.box_predictor_1),a=Vf(t,p.box_predictor_2),s=Vf(e,p.box_predictor_3),u=Vf(n,p.box_predictor_4),c=Vf(r,p.box_predictor_5);return{boxPredictions:_i([o.boxPredictionEncoding,i.boxPredictionEncoding,a.boxPredictionEncoding,s.boxPredictionEncoding,u.boxPredictionEncoding,c.boxPredictionEncoding],1),classPredictions:_i([o.classPrediction,i.classPrediction,a.classPrediction,s.classPrediction,u.classPrediction,c.classPrediction],1)}})),r=n.boxPredictions,s=n.classPredictions;return o=r,i=s,a=c.output_layer,ue(function(){var t=o.shape[0],e=Gf(ia(ca(a.extra_dim,[t,1,1]),[-1,4]),ia(o,[-1,4]));e=ia(e,[t,e.shape[0]/t,4]);var n=Wa(Hs(i,[0,0,1],[-1,-1,-1])),r=Hs(n,[0,0,0],[-1,-1,1]);return r=ia(r,[t,r.shape[1]]),{boxes:ha(e),scores:ha(r)}})})},e.prototype.forward=function(n){return p(this,void 0,void 0,function(){var e;return P(this,function(t){switch(t.label){case 0:return e=this.forwardInput,[4,yp(n)];case 1:return[2,e.apply(this,[t.sent()])]}})})},e.prototype.locateFaces=function(T,A){return void 0===A&&(A={}),p(this,void 0,void 0,function(){var l,h,p,f,d,v,m,g,y,x,w,b,E,C,_,S,R,N,k,I;return P(this,function(t){switch(t.label){case 0:return l=new Hf(A),h=l.maxResults,p=l.minConfidence,[4,yp(T)];case 1:for(f=t.sent(),d=this.forwardInput(f),v=d.boxes,m=d.scores,g=v[0],y=m[0],x=1;xa}).sort(function(t,e){return e.score-t.score}),c=[],u.forEach(function(t){if(!(c.length>=s)){for(var e=t.score,n=c.length-1;0<=n;--n){var r=Uf(o,t.boxIndex,c[n]);if(0!==r&&(t.score*=r<=i?1:0,t.score<=a))break}e===t.score&&c.push(t.boxIndex)}}),C=c,_=f.getReshapedInputDimensions(0),S=f.inputSize,R=S/_.width,N=S/_.height,k=g.arraySync(),I=C.map(function(t){var e=[Math.max(0,k[t][0]),Math.min(1,k[t][2])].map(function(t){return t*N}),n=e[0],r=e[1],o=[Math.max(0,k[t][1]),Math.min(1,k[t][3])].map(function(t){return t*R}),i=o[0],a=o[1];return new Lp(w[t],new Th(i,n,a-i,r-n),{height:f.getInputHeight(0),width:f.getInputWidth(0)})}),g.dispose(),y.dispose(),[2,I]}var o,e,n,i,a,r,s,u,c})})},e.prototype.getDefaultModelName=function(){return"ssd_mobilenetv1_model"},e.prototype.extractParamsFromWeigthMap=function(t){return Lf(t)},e.prototype.extractParams=function(t){return function(t){var e=[],n=np(t),r=n.extractWeights,o=n.getRemainingWeights,i=Ff(r,e),a=i.extractMobilenetV1Params,s=i.extractPredictionLayerParams,u=a(),c=s(),l={extra_dim:je(r(20472),[1,5118,4])};if(e.push({paramPath:"output_layer/extra_dim"}),0!==o().length)throw new Error("weights remaing after extract: "+o().length);return{params:{mobilenetv1:u,prediction_layer:c,output_layer:l},paramMappings:e}}(t)},e}(xp);function jf(t){var e=new qf;return e.extractWeights(t),e}var $f=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e}(qf),Kf=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._name="TinyFaceDetectorOptions",t}return a(t,e),t}(Mp),Xf=function(){function t(){}return t.prototype.then=function(n){return p(this,void 0,void 0,function(){var e;return P(this,function(t){switch(t.label){case 0:return e=n,[4,this.run()];case 1:return[2,e.apply(void 0,[t.sent()])]}})})},t.prototype.run=function(){return p(this,void 0,void 0,function(){return P(this,function(t){throw new Error("ComposableTask - run is not implemented")})})},t}();function Yf(a,s,u,c,l){return void 0===l&&(l=function(t){return t.alignedRect}),p(this,void 0,void 0,function(){var e,n,r,o,i;return P(this,function(t){switch(t.label){case 0:return e=a.map(function(t){return rf(t)?l(t):t.detection}),(r=c)?[3,5]:s instanceof dt?[4,wf(s,e)]:[3,2];case 1:return o=t.sent(),[3,4];case 2:return[4,xf(s,e)];case 3:o=t.sent(),t.label=4;case 4:r=o,t.label=5;case 5:return[4,u(n=r)];case 6:return i=t.sent(),n.forEach(function(t){return t instanceof dt&&t.dispose()}),[2,i]}})})}function Qf(e,r,o,i,a){return p(this,void 0,void 0,function(){var n=this;return P(this,function(t){return[2,Yf([e],r,function(e){return p(n,void 0,void 0,function(){return P(this,function(t){return[2,o(e[0])]})})},i,a)]})})}var Jf=2,Zf=12;function td(t){var e=np(t),n=e.extractWeights,r=e.getRemainingWeights,o=[],i=function(r,o){var u=Yh(r,o),c=Qh(r,o);function l(t,e){var n=He(r(t));return o.push({paramPath:e}),n}function h(t,e,n){return void 0===n&&(n=!1),{conv1:u(t[0],t[1],3,e+"/conv1"),prelu1_alpha:l(t[1],e+"/prelu1_alpha"),conv2:u(t[1],t[2],3,e+"/conv2"),prelu2_alpha:l(t[2],e+"/prelu2_alpha"),conv3:u(t[2],t[3],n?2:3,e+"/conv3"),prelu3_alpha:l(t[3],e+"/prelu3_alpha")}}return{extractPNetParams:function(){var t=h([3,10,16,32],"pnet"),e=u(32,2,1,"pnet/conv4_1"),n=u(32,4,1,"pnet/conv4_2");return O({},t,{conv4_1:e,conv4_2:n})},extractRNetParams:function(){var t=h([3,28,48,64],"rnet",!0),e=c(576,128,"rnet/fc1"),n=l(128,"rnet/prelu4_alpha"),r=c(128,2,"rnet/fc2_1"),o=c(128,4,"rnet/fc2_2");return O({},t,{fc1:e,prelu4_alpha:n,fc2_1:r,fc2_2:o})},extractONetParams:function(){var t=h([3,32,64,64],"onet"),e=u(64,128,2,"onet/conv4"),n=l(128,"onet/prelu4_alpha"),r=c(1152,256,"onet/fc1"),o=l(256,"onet/prelu5_alpha"),i=c(256,2,"onet/fc2_1"),a=c(256,4,"onet/fc2_2"),s=c(256,10,"onet/fc2_3");return O({},t,{conv4:e,prelu4_alpha:n,fc1:r,prelu5_alpha:o,fc2_1:i,fc2_2:a,fc2_3:s})}}}(n,o),a=i.extractPNetParams,s=i.extractRNetParams,u=i.extractONetParams,c=a(),l=s(),h=u();if(0!==r().length)throw new Error("weights remaing after extract: "+r().length);return{params:{pnet:c,rnet:l,onet:h},paramMappings:o}}function ed(t){var e=[],n=function(t,e){var n=ep(t,e);function u(t){return{filters:n(t+"/weights",4,t+"/filters"),bias:n(t+"/bias",1)}}function c(t){return{weights:n(t+"/weights",2),bias:n(t+"/bias",1)}}function l(t){return n(t,1)}function h(t){return{conv1:u(t+"/conv1"),prelu1_alpha:l(t+"/prelu1_alpha"),conv2:u(t+"/conv2"),prelu2_alpha:l(t+"/prelu2_alpha"),conv3:u(t+"/conv3"),prelu3_alpha:l(t+"/prelu3_alpha")}}return{extractPNetParams:function(){var t=h("pnet"),e=u("pnet/conv4_1"),n=u("pnet/conv4_2");return O({},t,{conv4_1:e,conv4_2:n})},extractRNetParams:function(){var t=h("rnet"),e=c("rnet/fc1"),n=l("rnet/prelu4_alpha"),r=c("rnet/fc2_1"),o=c("rnet/fc2_2");return O({},t,{fc1:e,prelu4_alpha:n,fc2_1:r,fc2_2:o})},extractONetParams:function(){var t=h("onet"),e=u("onet/conv4"),n=l("onet/prelu4_alpha"),r=c("onet/fc1"),o=l("onet/prelu5_alpha"),i=c("onet/fc2_1"),a=c("onet/fc2_2"),s=c("onet/fc2_3");return O({},t,{conv4:e,prelu4_alpha:n,fc1:r,prelu5_alpha:o,fc2_1:i,fc2_2:a,fc2_3:s})}}}(t,e),r=n.extractPNetParams,o=n.extractRNetParams,i=n.extractONetParams,a=r(),s=o(),u=i();return Xh(t,e),{params:{pnet:a,rnet:s,onet:u},paramMappings:e}}function nd(t,e){var n=e[0],r=e[1];return{height:Math.floor(n*t),width:Math.floor(r*t)}}var rd=function(o){function t(t,e,n,r){return o.call(this,{left:t,top:e,right:n,bottom:r},!0)||this}return a(t,o),t}(Sh);function od(t){return ue(function(){return Du(Bu(t,Ve(127.5)),Ve(.0078125))})}function id(t,e){return ue(function(){return xu(Xu(t),Du(e,Pa(Xu(Pa(t)))))})}function ad(e,n,r){return void 0===r&&(r=!1),ue(function(){var t=Kh(e,n.conv1,"valid");return t=id(t,n.prelu1_alpha),t=id(t=Kh(t=Us(t,r?[2,2]:[3,3],[2,2],"same"),n.conv2,"valid"),n.prelu2_alpha),t=id(t=Kh(t=r?t:Us(t,[3,3],[2,2],"valid"),n.conv3,"valid"),n.prelu3_alpha)})}function sd(h,t,u,p,c){c.stage1=[];var e=t.map(function(l){return ue(function(){var o,i,r,a,t={scale:l},e=(o=h,i=l,ue(function(){var t=nd(i,o.shape.slice(1)),e=t.height,n=t.width,r=od(Wc.resizeBilinear(o,[e,n]));return Qu(r,[0,2,1,3])})),n=Date.now(),s=(r=e,a=p,ue(function(){var t=ad(r,a,!0),e=Kh(t,a.conv4_1,"valid"),n=$i(eu(e,3),3);return{prob:Le(Bu(e,n),3),regions:Kh(t,a.conv4_2,"valid")}})),u=s.prob,c=s.regions;return t.pnet=Date.now()-n,{scoresTensor:ha(ha(u,3)[1])[0],regionsTensor:ha(c)[0],scale:l,statsForScale:t}})}).map(function(t){var e=t.scoresTensor,n=t.regionsTensor,r=t.scale,o=t.statsForScale,i=function(t,o,i,e){for(var n=[],a=t.arraySync(),r=0;r=e&&n.push(new lh(s,r));return n.map(function(t){var e=new Rh(Math.round((t.y*Jf+1)/i),Math.round((t.x*Jf+1)/i),Math.round((t.y*Jf+Zf)/i),Math.round((t.x*Jf+Zf)/i)),n=a[t.y][t.x],r=o.arraySync();return{cell:e,score:n,region:new rd(r[t.y][t.x][0],r[t.y][t.x][1],r[t.y][t.x][2],r[t.y][t.x][3])}})}(e,n,r,u);if(e.dispose(),n.dispose(),!i.length)return c.stage1.push(o),[];var a=Date.now(),s=bp(i.map(function(t){return t.cell}),i.map(function(t){return t.score}),.5);return o.nms=Date.now()-a,o.numBoxes=s.length,c.stage1.push(o),s.map(function(t){return i[t]})}).reduce(function(t,e){return t.concat(e)},[]),n=[],r=[];if(0g}).map(function(t){return t.idx}),c=u.map(function(t){return m[t]}),l=u.map(function(t){return i[t]}),h=[],p=[],0y}).map(function(t){return t.idx}),c=u.map(function(t){var e=i[t].regions.arraySync();return new rd(e[0][0],e[0][1],e[0][2],e[0][3])}),l=u.map(function(t,e){return g[t].calibrate(c[e])}),h=u.map(function(t){return o[t]}),p=[],f=[],d=[],0Zf}).slice(0,f),r.scales=m,r.pyramid=m.map(function(t){return nd(t,[u,c])}),g=Date.now(),[4,sd(i,m,d[0],e.pnet,r)];case 1:return y=t.sent(),r.total_stage1=Date.now()-g,y.boxes.length?(r.stage2_numInputBoxes=y.boxes.length,g=Date.now(),[4,cd(n,y.boxes,d[1],e.rnet,r)]):[2,a({results:[],stats:r})];case 2:return x=t.sent(),r.total_stage2=Date.now()-g,x.boxes.length?(r.stage3_numInputBoxes=x.boxes.length,g=Date.now(),[4,ld(n,x.boxes,d[2],e.onet,r)]):[2,a({results:[],stats:r})];case 3:return w=t.sent(),r.total_stage3=Date.now()-g,b=w.boxes.map(function(e,t){return of(Wp({},new Lp(w.scores[t],new Th(e.left/c,e.top/u,e.width/c,e.height/u),{height:u,width:c})),new mf(w.points[t].map(function(t){return t.sub(new lh(e.left,e.top)).div(new lh(e.width,e.height))}),{width:e.width,height:e.height}))}),[2,a({results:b,stats:r})]}})})},e.prototype.forward=function(n,r){return void 0===r&&(r={}),p(this,void 0,void 0,function(){var e;return P(this,function(t){switch(t.label){case 0:return e=this.forwardInput,[4,yp(n)];case 1:return[4,e.apply(this,[t.sent(),r])];case 2:return[2,t.sent().results]}})})},e.prototype.forwardWithStats=function(n,r){return void 0===r&&(r={}),p(this,void 0,void 0,function(){var e;return P(this,function(t){switch(t.label){case 0:return e=this.forwardInput,[4,yp(n)];case 1:return[2,e.apply(this,[t.sent(),r])]}})})},e.prototype.getDefaultModelName=function(){return"mtcnn_model"},e.prototype.extractParamsFromWeigthMap=function(t){return ed(t)},e.prototype.extractParams=function(t){return td(t)},e}(xp),pd=[new lh(1.603231,2.094468),new lh(6.041143,7.080126),new lh(2.882459,3.518061),new lh(4.266906,5.178857),new lh(9.041765,10.66308)],fd=[117.001,114.697,97.404],dd=function(e){function t(){var t={withSeparableConvs:!0,iouThreshold:.4,classes:["face"],anchors:pd,meanRgb:fd,isFirstLayerConv2d:!0,filterSizes:[3,16,32,64,128,256,512]};return e.call(this,t)||this}return a(t,e),Object.defineProperty(t.prototype,"anchors",{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),t.prototype.locateFaces=function(e,n){return p(this,void 0,void 0,function(){return P(this,function(t){switch(t.label){case 0:return[4,this.detect(e,n)];case 1:return[2,t.sent().map(function(t){return new Lp(t.score,t.relativeBox,{width:t.imageWidth,height:t.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return"tiny_face_detector_model"},t.prototype.extractParamsFromWeigthMap=function(t){return e.prototype.extractParamsFromWeigthMap.call(this,t)},t}(Op),vd=[new lh(.738768,.874946),new lh(2.42204,2.65704),new lh(4.30971,7.04493),new lh(10.246,4.59428),new lh(12.6868,11.8741)],md=[new lh(1.603231,2.094468),new lh(6.041143,7.080126),new lh(2.882459,3.518061),new lh(4.266906,5.178857),new lh(9.041765,10.66308)],gd=[117.001,114.697,97.404],yd=function(n){function t(t){void 0===t&&(t=!0);var e=Object.assign({},{withSeparableConvs:t,iouThreshold:.4,classes:["face"]},t?{anchors:md,meanRgb:gd}:{anchors:vd,withClassScores:!0});return n.call(this,e)||this}return a(t,n),Object.defineProperty(t.prototype,"withSeparableConvs",{get:function(){return this.config.withSeparableConvs},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"anchors",{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),t.prototype.locateFaces=function(e,n){return p(this,void 0,void 0,function(){return P(this,function(t){switch(t.label){case 0:return[4,this.detect(e,n)];case 1:return[2,t.sent().map(function(t){return new Lp(t.score,t.relativeBox,{width:t.imageWidth,height:t.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return this.withSeparableConvs?"tiny_yolov2_separable_conv_model":"tiny_yolov2_model"},t.prototype.extractParamsFromWeigthMap=function(t){return n.prototype.extractParamsFromWeigthMap.call(this,t)},t}(Op);var xd={ssdMobilenetv1:new qf,tinyFaceDetector:new dd,tinyYolov2:new yd,mtcnn:new hd,faceLandmark68Net:new Ef,faceLandmark68TinyNet:new _f,faceRecognitionNet:new Mf,faceExpressionNet:new Jp,ageGenderNet:new vf},wd=function(t,e){return xd.ssdMobilenetv1.locateFaces(t,e)},bd=function(t){return xd.faceLandmark68Net.detectLandmarks(t)},Ed=function(t){return xd.ssdMobilenetv1.load(t)},Cd=Ed,_d=wd,Sd=bd;function Rd(t,e){var n={age:e};return Object.assign({},t,n)}function Nd(t,e,n){var r={gender:e,genderProbability:n};return Object.assign({},t,r)}var kd=function(o){function t(t,e,n){var r=o.call(this)||this;return r.parentTask=t,r.input=e,r.extractedFaces=n,r}return a(t,o),t}(Xf),Id=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.run=function(){return p(this,void 0,void 0,function(){var e,n,r=this;return P(this,function(t){switch(t.label){case 0:return[4,this.parentTask];case 1:return[4,Yf(e=t.sent(),this.input,function(e){return p(r,void 0,void 0,function(){return P(this,function(t){switch(t.label){case 0:return[4,Promise.all(e.map(function(t){return xd.faceExpressionNet.predictExpressions(t)}))];case 1:return[2,t.sent()]}})})},this.extractedFaces)];case 2:return n=t.sent(),[2,e.map(function(t,e){return tf(t,n[e])})]}})})},e.prototype.withAgeAndGender=function(){return new Od(this,this.input)},e}(kd),Td=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.run=function(){return p(this,void 0,void 0,function(){var e,n;return P(this,function(t){switch(t.label){case 0:return[4,this.parentTask];case 1:return(e=t.sent())?[4,Qf(e,this.input,function(t){return xd.faceExpressionNet.predictExpressions(t)},this.extractedFaces)]:[2];case 2:return n=t.sent(),[2,tf(e,n)]}})})},e.prototype.withAgeAndGender=function(){return new Pd(this,this.input)},e}(kd),Ad=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.withAgeAndGender=function(){return new Fd(this,this.input)},e.prototype.withFaceDescriptors=function(){return new Wd(this,this.input)},e}(Id),Dd=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.withAgeAndGender=function(){return new Ld(this,this.input)},e.prototype.withFaceDescriptor=function(){return new zd(this,this.input)},e}(Td),Md=function(o){function t(t,e,n){var r=o.call(this)||this;return r.parentTask=t,r.input=e,r.extractedFaces=n,r}return a(t,o),t}(Xf),Od=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.run=function(){return p(this,void 0,void 0,function(){var e,o,n=this;return P(this,function(t){switch(t.label){case 0:return[4,this.parentTask];case 1:return[4,Yf(e=t.sent(),this.input,function(e){return p(n,void 0,void 0,function(){return P(this,function(t){switch(t.label){case 0:return[4,Promise.all(e.map(function(t){return xd.ageGenderNet.predictAgeAndGender(t)}))];case 1:return[2,t.sent()]}})})},this.extractedFaces)];case 2:return o=t.sent(),[2,e.map(function(t,e){var n=o[e],r=n.age;return Rd(Nd(t,n.gender,n.genderProbability),r)})]}})})},e.prototype.withFaceExpressions=function(){return new Id(this,this.input)},e}(Md),Pd=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.run=function(){return p(this,void 0,void 0,function(){var e,n,r,o,i;return P(this,function(t){switch(t.label){case 0:return[4,this.parentTask];case 1:return(e=t.sent())?[4,Qf(e,this.input,function(t){return xd.ageGenderNet.predictAgeAndGender(t)},this.extractedFaces)]:[2];case 2:return n=t.sent(),r=n.age,o=n.gender,i=n.genderProbability,[2,Rd(Nd(e,o,i),r)]}})})},e.prototype.withFaceExpressions=function(){return new Td(this,this.input)},e}(Md),Fd=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.withFaceExpressions=function(){return new Ad(this,this.input)},e.prototype.withFaceDescriptors=function(){return new Wd(this,this.input)},e}(Od),Ld=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.withFaceExpressions=function(){return new Dd(this,this.input)},e.prototype.withFaceDescriptor=function(){return new zd(this,this.input)},e}(Pd),Bd=function(r){function t(t,e){var n=r.call(this)||this;return n.parentTask=t,n.input=e,n}return a(t,r),t}(Xf),Wd=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.run=function(){return p(this,void 0,void 0,function(){var n;return P(this,function(t){switch(t.label){case 0:return[4,this.parentTask];case 1:return[4,Yf(n=t.sent(),this.input,function(t){return Promise.all(t.map(function(t){return xd.faceRecognitionNet.computeFaceDescriptor(t)}))},null,function(t){return t.landmarks.align(null,{useDlibAlignment:!0})})];case 2:return[2,t.sent().map(function(t,e){return Of(n[e],t)})]}})})},e.prototype.withFaceExpressions=function(){return new Ad(this,this.input)},e.prototype.withAgeAndGender=function(){return new Fd(this,this.input)},e}(Bd),zd=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.run=function(){return p(this,void 0,void 0,function(){var e,n;return P(this,function(t){switch(t.label){case 0:return[4,this.parentTask];case 1:return(e=t.sent())?[4,Qf(e,this.input,function(t){return xd.faceRecognitionNet.computeFaceDescriptor(t)},null,function(t){return t.landmarks.align(null,{useDlibAlignment:!0})})]:[2];case 2:return n=t.sent(),[2,Of(e,n)]}})})},e.prototype.withFaceExpressions=function(){return new Dd(this,this.input)},e.prototype.withAgeAndGender=function(){return new Ld(this,this.input)},e}(Bd),Ud=function(o){function t(t,e,n){var r=o.call(this)||this;return r.parentTask=t,r.input=e,r.useTinyLandmarkNet=n,r}return a(t,o),Object.defineProperty(t.prototype,"landmarkNet",{get:function(){return this.useTinyLandmarkNet?xd.faceLandmark68TinyNet:xd.faceLandmark68Net},enumerable:!0,configurable:!0}),t}(Xf),Gd=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.run=function(){return p(this,void 0,void 0,function(){var e,n,r,o,i,a=this;return P(this,function(t){switch(t.label){case 0:return[4,this.parentTask];case 1:return e=t.sent(),n=e.map(function(t){return t.detection}),this.input instanceof dt?[4,wf(this.input,n)]:[3,3];case 2:return o=t.sent(),[3,5];case 3:return[4,xf(this.input,n)];case 4:o=t.sent(),t.label=5;case 5:return r=o,[4,Promise.all(r.map(function(t){return a.landmarkNet.detectLandmarks(t)}))];case 6:return i=t.sent(),r.forEach(function(t){return t instanceof dt&&t.dispose()}),[2,e.map(function(t,e){return of(t,i[e])})]}})})},e.prototype.withFaceExpressions=function(){return new Ad(this,this.input)},e.prototype.withAgeAndGender=function(){return new Fd(this,this.input)},e.prototype.withFaceDescriptors=function(){return new Wd(this,this.input)},e}(Ud),Vd=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.run=function(){return p(this,void 0,void 0,function(){var e,n,r,o,i;return P(this,function(t){switch(t.label){case 0:return[4,this.parentTask];case 1:return(e=t.sent())?(n=e.detection,this.input instanceof dt?[4,wf(this.input,[n])]:[3,3]):[2];case 2:return o=t.sent(),[3,5];case 3:return[4,xf(this.input,[n])];case 4:o=t.sent(),t.label=5;case 5:return r=o,[4,this.landmarkNet.detectLandmarks(r[0])];case 6:return i=t.sent(),r.forEach(function(t){return t instanceof dt&&t.dispose()}),[2,of(e,i)]}})})},e.prototype.withFaceExpressions=function(){return new Dd(this,this.input)},e.prototype.withAgeAndGender=function(){return new Ld(this,this.input)},e.prototype.withFaceDescriptor=function(){return new zd(this,this.input)},e}(Ud),Hd=function(r){function t(t,e){void 0===e&&(e=new Hf);var n=r.call(this)||this;return n.input=t,n.options=e,n}return a(t,r),t}(Xf),qd=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.run=function(){return p(this,void 0,void 0,function(){var e,n,r,o;return P(this,function(t){switch(t.label){case 0:return n=(e=this).input,(r=e.options)instanceof Pf?[4,xd.mtcnn.forward(n,r)]:[3,2];case 1:return[2,t.sent().map(function(t){return t.detection})];case 2:if(!(o=r instanceof Kf?function(t){return xd.tinyFaceDetector.locateFaces(t,r)}:r instanceof Hf?function(t){return xd.ssdMobilenetv1.locateFaces(t,r)}:r instanceof Mp?function(t){return xd.tinyYolov2.locateFaces(t,r)}:null))throw new Error("detectFaces - expected options to be instance of TinyFaceDetectorOptions | SsdMobilenetv1Options | MtcnnOptions | TinyYolov2Options");return[2,o(n)]}})})},e.prototype.runAndExtendWithFaceDetections=function(){var t=this;return new Promise(function(n){return p(t,void 0,void 0,function(){var e;return P(this,function(t){switch(t.label){case 0:return[4,this.run()];case 1:return e=t.sent(),[2,n(e.map(function(t){return Wp({},t)}))]}})})})},e.prototype.withFaceLandmarks=function(t){return void 0===t&&(t=!1),new Gd(this.runAndExtendWithFaceDetections(),this.input,t)},e.prototype.withFaceExpressions=function(){return new Id(this.runAndExtendWithFaceDetections(),this.input)},e.prototype.withAgeAndGender=function(){return new Od(this.runAndExtendWithFaceDetections(),this.input)},e}(Hd),jd=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.run=function(){return p(this,void 0,void 0,function(){var e,n;return P(this,function(t){switch(t.label){case 0:return[4,new qd(this.input,this.options)];case 1:return e=t.sent(),n=e[0],e.forEach(function(t){t.score>n.score&&(n=t)}),[2,n]}})})},e.prototype.runAndExtendWithFaceDetection=function(){var t=this;return new Promise(function(n){return p(t,void 0,void 0,function(){var e;return P(this,function(t){switch(t.label){case 0:return[4,this.run()];case 1:return e=t.sent(),[2,n(e?Wp({},e):void 0)]}})})})},e.prototype.withFaceLandmarks=function(t){return void 0===t&&(t=!1),new Vd(this.runAndExtendWithFaceDetection(),this.input,t)},e.prototype.withFaceExpressions=function(){return new Td(this.runAndExtendWithFaceDetection(),this.input)},e.prototype.withAgeAndGender=function(){return new Pd(this.runAndExtendWithFaceDetection(),this.input)},e}(Hd);function $d(t,e){return void 0===e&&(e=new Hf),new qd(t,e)}function Kd(e,n){return p(this,void 0,void 0,function(){return P(this,function(t){switch(t.label){case 0:return[4,$d(e,new Hf(n?{minConfidence:n}:{})).withFaceLandmarks().withFaceDescriptors()];case 1:return[2,t.sent()]}})})}var Xd=Kd;function Yd(t,e){if(t.length!==e.length)throw new Error("euclideanDistance: arr1.length !== arr2.length");var n=Array.from(t),r=Array.from(e);return Math.sqrt(n.map(function(t,e){return t-r[e]}).reduce(function(t,e){return t+Math.pow(e,2)},0))}var Qd=function(){function t(t,e){void 0===e&&(e=.6),this._distanceThreshold=e;var n=Array.isArray(t)?t:[t];if(!n.length)throw new Error("FaceRecognizer.constructor - expected atleast one input");var r=1,o=function(){return"person "+r++};this._labeledDescriptors=n.map(function(t){if(t instanceof yf)return t;if(t instanceof Float32Array)return new yf(o(),[t]);if(t.descriptor&&t.descriptor instanceof Float32Array)return new yf(o(),[t.descriptor]);throw new Error("FaceRecognizer.constructor - expected inputs to be of type LabeledFaceDescriptors | WithFaceDescriptor | Float32Array | Array | Float32Array>")})}return Object.defineProperty(t.prototype,"labeledDescriptors",{get:function(){return this._labeledDescriptors},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"distanceThreshold",{get:function(){return this._distanceThreshold},enumerable:!0,configurable:!0}),t.prototype.computeMeanDistance=function(e,t){return t.map(function(t){return Yd(t,e)}).reduce(function(t,e){return t+e},0)/(t.length||1)},t.prototype.matchDescriptor=function(r){var o=this;return this.labeledDescriptors.map(function(t){var e=t.descriptors,n=t.label;return new gf(n,o.computeMeanDistance(r,e))}).reduce(function(t,e){return t.distance + + + + + + Document + + + + + + + + \ No newline at end of file diff --git a/riso_facial-service/models/face_expression_model-shard1 b/riso_facial-service/models/face_expression_model-shard1 new file mode 100644 index 0000000000000000000000000000000000000000..619cdf6d46e8757999a250616782ddb3e25c6504 GIT binary patch literal 329468 zcmWib>ac-V#-)lQ=iDOBTY*~FJt#-AIn9E*rRgrByGMtjNBKTw;IX#EBCpj&Jfr51+U5V%q0_&iS45{T;LRXyY8L zR`!pQ=oxV=a;w7|_8VkVt_RHrmj1q5SI}=3r`Q6Ir*U#HqjbYTRLOio`m)Q~0Q<1S z>0kUgo(i40)vxvKzho?MaK_brBim(AnfkUugt6_tPiR(qn~c))PjZ2W$3km~%;CZ% zMyaN2zpkm7dq!V+*7w&vh7+I`$tAxwdjCQh&0X`8tK{$t6l`6!BN6X+tuScn?DYt*9} zw(zI+*4hi-HR~Y4H2b437gG`a{@$f__(T&WDaYfE(~qzPQQ6qCJg)S;`u?}iM#a39 zbY^XQtj}4UlmfQW1#p{6)8BCt7WnR4r+rRxYIC7vEt(~+St>K2Umy7lc;m$>Aj)?59g@*ILGHYa^%~yCe5mpVuYMCxAZbKd_!ergl&CjrM6h%;n0c?}Fb6+Z?v_ zP$kb4O?!U{bz7yI)F60n$yLnI;iLt-8WmUJ!p^A!7mdN^ZTvP^&%&aYKdu%7UG&k@ zd;ar*b`3vm8k`0qrfAR2k9={u|Kag{SlqYh{qi`7`=+iESTfV=(^-h(MC4OLT`+4f zRz74#nhLT5ht>s!CDVZvsx@Eca82(l5~_nSO6Avqs|QTk%a1MLq&ue%^iPW~4C;JF zyZKkOpjt8Tzf(ui%*dAMFJDkVwphPgUm$cQ49uqCzr7yBz4)btx%+{+IabeL1m2q+ zY2sP;4PW!Z1 zVUznkApkCU|FFmL$Uk+TNdITYs&n-` z-#F9#aO}Oqna}1s^)sxaKmE;zovYj5==tK|HxF~CVqG6xyVLpU6aRI%xbaE%mupWQ zu?9Cgob=_+7hnF{&Ts#2qa*$4ogI1$q-UTf4D+lh^`)SzYtRq6&(o|}vG1aKq-&BQbC4HV@(Lr}t?vP- za@QZ|(%YxXHS@dYxA! zxrxU?g`MGzd;Pqbv94h!hh|7rnZpvbZ7=&UvPXHDzZ8&$IO>g-w^oe|FGH zno^y*B=J+u2*od6I6Wx;EB)*XC-h*CMa?>DJl-E0Q1V}N36sK?$FvC_IvE4vID-c5)A;^eNYmk8t%zgT z;cKMNR!Hh)+nU2C()z6>1*vu9T$0B+LAN36zP3E-loAuJ7KZn^vv)nRZsqIpfNLk& zu8M>8x})Is$a07S9Zjm$Ax3b+zGWKN*jR~Fqdn|2z}+~gWb*N#PyTpCOk@}fDiX7~ z8xg|?ffsDkm0Ns!L}vA+8)Zt@|RhRy~Z*vY7^{%35BN8 zR*%NzkXp?i<3j4IOen{8w&=c;B^;}__RBR%35C%+$(dUUe{x9iJ+)wxf8v}29cu44SY>+fcZ-pQ6>^*iLz&cJe&(VjRp!>_AydBD@aCJLfJTt4iPhGc)WTVU0vukWoC`@ZS3bbV zb`(Ji<%3LYkzUsEW0lpQGi*zm(+QvpzZ0--UR{fDHf+VvSw+a(S;3=uf+9M~tzefC z9y2^lmwS9`S8}L%pEUdV!tl@jIRJ{&-n?7I{XeSh3Bt7U`abCYb(uhZdaxBx)M?rr zJ3|d9Th+w_Mp^1pK}&}cSXlE_gStRKlZZN@sLK-YxqZb@z!f*8(?*XwEA@&E=ZGFXArW8!wrTf{@Tm|4AfH*nR9%?07kn3)vXj(aP%o!t4gY4;+J zkOk!mW9ed{fxBQ5*A%~vR6gBpL?xls@4m~;2AH1a75Z1ZqaVE5#Zp{36#lRFLG7Qf zb;ie|oqrEK-uXoI%_BMb#^Fz1_^|WF-9PL8-@pHMNB6`FhcvIM^Cv_7Jx_nGJNR^a z@UYMLt3&QTZ+8BHxY?N+_|f6vt-tA{#i~w=96emp{l1I%{~AZ&f_1palYt_OG!C%Z15Gh;r5Z9HPbWee-&+9+5s=VSN7i;5J7 zdg*A%t-HAB-d1X)r1|7**E&YUUVnS*g|fTM&}~Wt%(uNpntz+|i{Rh(*F{`UXx2A4 z^0cIP>+$Y^{}9#PFU7AI9ht>9V2S=0kZAV3d(H`w+Px`30#;EpLF5vPEpr@de>fZ& zd%~C{y{xvmT04ZjfBTm=ptI8tEo^@j);Yg7wt26nI!VLac0CH3Y>Sh&g7bF z)5bf6RbgtTe0=<#X-95tYc^is*n_T-wO4*_7K(L*At5fZ`s-Yg0oEzHp7$aCplNAX zALVo5p-Ii>;@&q0T&h&e_{`Edr$IA4Es}^3fxZEV8EUeN)jubTn!+q>RE%{m0f_6g zM8pw~!FsRR#Xi|5T=DQj(&_VpSN12KwOqC#C*V1+PaI33rwS4RVfS1Zq4z%aj1;8} zYKGN)=0^-P$K^|`kpULg)3-1;8AZ3K}qB+nTvUc4+KYkEg zqF2wRFU~?!SZFZ*oJ2w`CG|LHiqAl8h0AAV!|a^;bg`R6yR2c5xgyiRm`ydtv1fXUU^3`h+n?)Eavc!5zV21(|aCts;x0Z&!JD%3dX7SrP=g|qs3Qb zz52wk!D82?xb;!7di)tKBCLBkMhggMge@^3D6rS&8Ja2Ga@g(%atb$a?a*Xmvy8R? zi28}FnIsCbWfA%tO8ZMe`y}h+3>qJZYCs+$w3&LRugHI6G3kUM(bJ!xp?Eb9sFxu_ zk>n;3Ge9bjqq@342=|w?c_;L|UJZsTmgb2h)*VVj20{r$V175~v~TdlRtv@N zcw?;E|WZhOgtw1jPaY40_)6F91ceSDa?q~U~gQ$h}xpKp2U zgz?Oz;K1sj4t4R)>Ml;YB*0+O4O$s0*vh5JW_Lf9z&AnCe0ZsQ4TS#;e)=_@=i$JE zy6<@uJU6Pd`CJYeCK!0JiNy83H;zOAXmlM8jnF2=tiGi5OqhsT`}J(Quo79h*SkpX z!hMvg1)rH;#a|FJ1cU6jiA0&gSm7vJ#y^r<_=j|Bk2$#zTioL!ueEj7@*fCj?%zHo=zjUu2Zw+BM_=#x!pObO zZy2TS$6gk9K4sPpk+;9viTw1<&cFN+KD_ewT=!eu!ESqC@bCxcp6H(V#&3)Pd?uB6gWt#|XKzRr4@@7f_;RcK+0`O=oL-IKy)Ema7^DnbjdmsU={>Gs zb9u{uts$FxFE5Y>ay)OJ>6~$5S>LWbFY*=|BI++4Z>pEyB0G)K+LbBg5dpv5*h@8> zAd!6lSL*wG=|evGk&-jigvi(ZE!pYm#rN}CUd5B< z9Y#8u_L;lJBUhx#4YZs6KeB&rH^J|gaLPAADMRd7eqGimq!&KQ^CbybGvU2fEjzu%sT}+(U)?=6 zIqO*B{yMogm0h%=>xE#(?)W@*=lFs;X5G z--@|v7_n3%V!MiVz&PhUNR2nklVP$8L^ecK_>FpGx8R*^iMDQj==ALG@2!_V+)Avk zW_Rbk+J&RLp{0TcPe?2~@wZi1ga46Qh$|AgL?r#1<0sgYT zJ(*0;E#^1pR+eGUo@VK7->CvdYQeV(o=6faqQi}4-D2RDX-{)oYPqRmDfw%wt&YVz=RlTXP{g#S znj;K5yQ);kZAzQmg-!WC#X~W7z`1(+A)nesx8NRXpaK&gh8*-yrz7f{-o4=BN?2D@ z-&$c8Wm)ss($!3Bc{iA!h9erj-=0m$lYh|{4>AB(#6aK%Pq~dH+jTRTA*y#pg%$8$D@U=oWILCPtb+k} z13lNQ6tdcQ$eyW_sw@?~6??zZ)G7{U!?&`g*{UVx(=@8rYX4j)znX<=iTz9X-J9h9 zv7g5fizz+LkgOBvn*j^XT}1Wc6UhEZ0xp(nM74UW%P^mEk)n~SLGFg;<7t}17KoMt z*OC3_1~cqPrf~m#yjI>R4a^}$Z^g10zv@n$8sjUsgZYj7nB!7c0=A@9>Gp1Gj65csDJ~IuQ~NqSfpuwh6|P6B zT8S+j4+t3VFPJwCrbrM=#j}^M1+;FnHwEmo13$D1e^cxk(sd5{-v3sI|K9gI^ryeu z^Xc#Mhu^w$t>=%#pZ1*l<~KU3H}FpN50^XtZ@k#^AG=@a^cUPcmwxQ+{H%@lJp9&S z=bkg!b87REPX6OYNAcvp9{l2=V&}_oO%J(P>E^YW-PHB3UA*$0*5RK$c)IiQi~n@E z82atu{8Nt}UjOQF4-Re`ow`Ca6M4sJ2rZROW(>yMNzlQc?P6VOBW&`pBrs zGZ+tl@H}V&G`9qN;FYKM4O}&gD@^)&+ok(berSnO&;Qe45krzo1L|Qm)%%hLBi3~d zgCX{sRW-@J#uzlI6DPV!YMW7cux3HZl5rrCG+Toxneu)dntSeQ(|wk2YEpDfvv0IRnwM zQ(ES{Bv(rt!>=soS$m)12Ya;x(+NWI%6BhO$G+7{JZb!!=k^b3SKhT!e7ukDlHc7W zZcLNpV#Y%z)j;=$cSd^-Pp;oiDAz*$CdQ7Y|IZ(_a4u^FUcum)UBxo1v@jPph3OC@ zK&i)FRFYEVM}bLZ#{DPK@VTU}Pj3wc9St7z0uV?}Osl<@0F#GiFOJ$kUK=!vr@O8Y zI|;AL773kXO-9Fjs8}z@hS5s!g&Bb*Z`DgP)VN5Qw&Rl+q@h95Q(-ETU{zT@gMcHT zTgg7{Or|hm^yFn@95pGbojzl8%{((1Q8AeTsxl+Chq!=qMUGGL2LN@qnFPBpfPRqy zI35R);4bsLKQpdAXHmI?f@!nD?z*DjO0j7VW~TAeh{VQ5Y*x)yQJM?kTAQ=mjbeaQoIN2jsTq0$#2ubFGk4Pb7m67F%9+a? zn#zVOLJ~@k-k|qGqm&-8xSbO?rS#~;zG@17Za^o=`7~xWPk)(0%?ku#k5D~fl8jo; zOmS@zkfszOI+j=DCc7@#C?UWdQ+h;6iJ3VXjKOY=OFJVPcytIpKh9*%i7oa?wf=&6 z!-7n){Pbms&d!;5(`TP_2qv#+E(y(2rbjw~%>+Q)h%L22A?1G}KBra>{9bNIa-%kO zSgZ|X0p*MbR&ggq96wv_uKSIOIU|yc*zm68|f`s~NrK7U@s*C=a^ zG(yUlwftOFsqGJJPv%0;P4sem)pz9^G*j^zF%Wtqr6=TXW!2#Q&m$(ilcLUr#dI>1 zHA@h4ObwYo@c>qcZ_#?V=cQJG^k38iQMto;F(RI?68JO1o3Be#7>I=^T$Ii{BmWU| z$)J0dslH+wHH=JY_zs4a;hdM-zw#`EnvFg?htI>9s8wJPfN+~2Q~*n?2988##d%|! zNQ78AF1&Q)GMq`0CULrQOZ;^Uiy<-i9Y(WLCbO$_LLuRWs1bojD;v8S@F@3=vH