diff --git a/assets/index-Dg6Vu77P.js b/assets/index-TuQ91GCH.js similarity index 99% rename from assets/index-Dg6Vu77P.js rename to assets/index-TuQ91GCH.js index fca0ca2..d178fd4 100644 --- a/assets/index-Dg6Vu77P.js +++ b/assets/index-TuQ91GCH.js @@ -3864,4 +3864,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -***************************************************************************** */var wf=function(e,t){return wf=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var o in r)r.hasOwnProperty(o)&&(n[o]=r[o])},wf(e,t)};function ue(e,t){wf(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}var mt=function(){return mt=Object.assign||function(t){for(var n,r=1,o=arguments.length;r0&&i[i.length-1])&&(l[0]===6||l[0]===2)){n=0;continue}if(l[0]===3&&(!i||l[1]>i[0]&&l[1]n&&(u=-f+n+r,f=n),d>t&&(s=-d+t+o,d=t),l<1&&(s=2-l,l=1),c<1&&(s=2-c,c=1),{dy:a,edy:s,dx:i,edx:u,y:c,ey:d,x:l,ex:f,w:r,h:o}},e.prototype.calibrate=function(t){return new e({left:this.left+t.left*this.width,top:this.top+t.top*this.height,right:this.right+t.right*this.width,bottom:this.bottom+t.bottom*this.height}).toSquare().round()},e}(),Xs=function(e){ue(t,e);function t(n,r,o,i,a){return a===void 0&&(a=!1),e.call(this,{left:n,top:r,right:o,bottom:i},a)||this}return t}(zn),Ry=function(){function e(t,n,r,o,i){this._imageDims=new so(i.width,i.height),this._score=t,this._classScore=n,this._className=r,this._box=new zn(o).rescale(this._imageDims)}return Object.defineProperty(e.prototype,"score",{get:function(){return this._score},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"classScore",{get:function(){return this._classScore},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"className",{get:function(){return this._className},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"box",{get:function(){return this._box},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"imageDims",{get:function(){return this._imageDims},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"imageWidth",{get:function(){return this.imageDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"imageHeight",{get:function(){return this.imageDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"relativeBox",{get:function(){return new zn(this._box).rescale(this.imageDims.reverse())},enumerable:!0,configurable:!0}),e.prototype.forSize=function(t,n){return new e(this.score,this.classScore,this.className,this.relativeBox,{width:t,height:n})},e}(),Kt=function(e){ue(t,e);function t(n,r,o){return e.call(this,n,n,"",r,o)||this}return t.prototype.forSize=function(n,r){var o=e.prototype.forSize.call(this,n,r),i=o.score,a=o.relativeBox,u=o.imageDims;return new t(i,a,u)},t}(Ry);function Dk(e,t,n){n===void 0&&(n=!0);var r=Math.max(0,Math.min(e.right,t.right)-Math.max(e.left,t.left)),o=Math.max(0,Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top)),i=r*o;return n?i/(e.area+t.area-i):i/Math.min(e.area,t.area)}function Tk(e){var t=e.map(function(u){return u.x}),n=e.map(function(u){return u.y}),r=t.reduce(function(u,s){return s0;)a();return i}function Ba(e,t){return X(function(){var n=t[0],r=t[1],o=t[2],i=Ln(Qi(e.shape.slice(0,3),[1]),n),a=Ln(Qi(e.shape.slice(0,3),[1]),r),u=Ln(Qi(e.shape.slice(0,3),[1]),o),s=Ye([i,a,u],3);return Ze(e,s)})}function Nk(e,t){return t===void 0&&(t=!1),X(function(){var n=e.shape.slice(1),r=n[0],o=n[1];if(r===o)return e;var i=Math.abs(r-o),a=Math.round(i*(t?.5:1)),u=r>o?2:1,s=function(h){var p=e.shape.slice();return p[u]=h,Ln(p,0)},l=s(a),c=i-l.shape[u],f=t&&c?s(c):null,d=[f,e,l].filter(function(h){return!!h}).map(function(h){return h.toFloat()});return Ye(d,u)})}function nc(e){return 1/(1+Math.exp(-e))}var Xd=function(e){ue(t,e);function t(n,r,o,i,a){return a===void 0&&(a=!1),e.call(this,{x:n,y:r,width:o,height:i},a)||this}return t}(zn),Ak=.5,Pk=.43,Fk=.45,yi=function(){function e(t,n,r){r===void 0&&(r=new we(0,0));var o=n.width,i=n.height;this._imgDims=new so(o,i),this._shift=r,this._positions=t.map(function(a){return a.mul(new we(o,i)).add(r)})}return Object.defineProperty(e.prototype,"shift",{get:function(){return new we(this._shift.x,this._shift.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"imageWidth",{get:function(){return this._imgDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"imageHeight",{get:function(){return this._imgDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"positions",{get:function(){return this._positions},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"relativePositions",{get:function(){var t=this;return this._positions.map(function(n){return n.sub(t._shift).div(new we(t.imageWidth,t.imageHeight))})},enumerable:!0,configurable:!0}),e.prototype.forSize=function(t,n){return new this.constructor(this.relativePositions,{width:t,height:n})},e.prototype.shiftBy=function(t,n){return new this.constructor(this.relativePositions,this._imgDims,new we(t,n))},e.prototype.shiftByPoint=function(t){return this.shiftBy(t.x,t.y)},e.prototype.align=function(t,n){if(n===void 0&&(n={}),t){var r=t instanceof Kt?t.box.floor():new zn(t);return this.shiftBy(r.x,r.y).align(null,n)}var o=Object.assign({},{useDlibAlignment:!1,minBoxPadding:.2},n),i=o.useDlibAlignment,a=o.minBoxPadding;return i?this.alignDlib():this.alignMinBbox(a)},e.prototype.alignDlib=function(){var t=this.getRefPointsForAlignment(),n=t[0],r=t[1],o=t[2],i=function(f){return o.sub(f).magnitude()},a=(i(n)+i(r))/2,u=Math.floor(a/Fk),s=Kd(t),l=Math.floor(Math.max(0,s.x-Ak*u)),c=Math.floor(Math.max(0,s.y-Pk*u));return new Xd(l,c,Math.min(u,this.imageWidth+l),Math.min(u,this.imageHeight+c))},e.prototype.alignMinBbox=function(t){var n=Tk(this.positions);return n.pad(n.width*t,n.height*t)},e.prototype.getRefPointsForAlignment=function(){throw new Error("getRefPointsForAlignment not implemented by base class")},e}(),Mk=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.getRefPointsForAlignment=function(){var n=this.positions;return[n[0],n[1],Kd([n[3],n[4]])]},t}(yi),Iy=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.getJawOutline=function(){return this.positions.slice(0,17)},t.prototype.getLeftEyeBrow=function(){return this.positions.slice(17,22)},t.prototype.getRightEyeBrow=function(){return this.positions.slice(22,27)},t.prototype.getNose=function(){return this.positions.slice(27,36)},t.prototype.getLeftEye=function(){return this.positions.slice(36,42)},t.prototype.getRightEye=function(){return this.positions.slice(42,48)},t.prototype.getMouth=function(){return this.positions.slice(48,68)},t.prototype.getRefPointsForAlignment=function(){return[this.getLeftEye(),this.getRightEye(),this.getMouth()].map(Kd)},t}(yi),Rv=function(){function e(t,n){this._label=t,this._distance=n}return Object.defineProperty(e.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"distance",{get:function(){return this._distance},enumerable:!0,configurable:!0}),e.prototype.toString=function(t){return t===void 0&&(t=!0),""+this.label+(t?" ("+qd(this.distance)+")":"")},e}(),Iv=function(e){ue(t,e);function t(n,r){var o=e.call(this,n)||this;return o._label=r,o}return t.assertIsValidLabeledBox=function(n,r){if(zn.assertIsValidBox(n,r),!lo(n.label))throw new Error(r+" - expected property label ("+n.label+") to be a number")},Object.defineProperty(t.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),t}(zn),fu=function(){function e(t,n){if(typeof t!="string")throw new Error("LabeledFaceDescriptors - constructor expected label to be a string");if(!Array.isArray(n)||n.some(function(r){return!(r instanceof Float32Array)}))throw new Error("LabeledFaceDescriptors - constructor expected descriptors to be an array of Float32Array");this._label=t,this._descriptors=n}return Object.defineProperty(e.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"descriptors",{get:function(){return this._descriptors},enumerable:!0,configurable:!0}),e.prototype.toJSON=function(){return{label:this.label,descriptors:this.descriptors.map(function(t){return Array.from(t)})}},e.fromJSON=function(t){var n=t.descriptors.map(function(r){return new Float32Array(r)});return new e(t.label,n)},e}();(function(e){ue(t,e);function t(n,r,o,i){var a=e.call(this,n,r)||this;return a._score=o,a._classScore=i,a}return t.assertIsValidPredictedBox=function(n,r){if(Iv.assertIsValidLabeledBox(n,r),!kv(n.score)||!kv(n.classScore))throw new Error(r+" - expected properties score ("+n.score+") and ("+n.classScore+") to be a number between [0, 1]")},Object.defineProperty(t.prototype,"score",{get:function(){return this._score},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"classScore",{get:function(){return this._classScore},enumerable:!0,configurable:!0}),t})(Iv);function Ca(e){return e.detection instanceof Kt}function _a(e,t){var n={detection:t};return Object.assign({},e,n)}function Dy(){var e=window.fetch||function(){throw new Error("fetch - missing fetch implementation for browser environment")},t=function(){throw new Error("readFile - filesystem not available for browser environment")};return{Canvas:HTMLCanvasElement,CanvasRenderingContext2D,Image:HTMLImageElement,ImageData,Video:HTMLVideoElement,createCanvasElement:function(){return document.createElement("canvas")},createImageElement:function(){return document.createElement("img")},fetch:e,readFile:t}}function Ty(e){var t="";if(!e)try{e=require("fs")}catch(r){t=r.toString()}var n=e?function(r){return new Promise(function(o,i){e.readFile(r,function(a,u){return a?i(a):o(u)})})}:function(){throw new Error("readFile - failed to require fs in nodejs environment with error: "+t)};return{readFile:n}}function Ny(){var e=global.Canvas||global.HTMLCanvasElement,t=global.Image||global.HTMLImageElement,n=function(){if(e)return new e;throw new Error("createCanvasElement - missing Canvas implementation for nodejs environment")},r=function(){if(t)return new t;throw new Error("createImageElement - missing Image implementation for nodejs environment")},o=global.fetch||function(){throw new Error("fetch - missing fetch implementation for nodejs environment")},i=Ty();return mt({Canvas:e||function(){function a(){}return a}(),CanvasRenderingContext2D:global.CanvasRenderingContext2D||function(){function a(){}return a}(),Image:t||function(){function a(){}return a}(),ImageData:global.ImageData||function(){function a(){}return a}(),Video:global.HTMLVideoElement||function(){function a(){}return a}(),createCanvasElement:n,createImageElement:r,fetch:o},i)}function Ay(){return typeof window=="object"&&typeof document<"u"&&typeof HTMLImageElement<"u"&&typeof HTMLCanvasElement<"u"&&typeof HTMLVideoElement<"u"&&typeof ImageData<"u"&&typeof CanvasRenderingContext2D<"u"}function Py(){return typeof global=="object"&&typeof require=="function"&&typeof d1<"u"&&typeof process<"u"&&!!process.version}var qe;function Ok(){if(!qe)throw new Error("getEnv - environment is not defined, check isNodejs() and isBrowser()");return qe}function bf(e){qe=e}function Yd(){Ay()&&bf(Dy()),Py()&&bf(Ny())}function Bk(e){if(qe||Yd(),!qe)throw new Error("monkeyPatch - environment is not defined, check isNodejs() and isBrowser()");var t=e.Canvas,n=t===void 0?qe.Canvas:t,r=e.Image,o=r===void 0?qe.Image:r;qe.Canvas=n,qe.Image=o,qe.createCanvasElement=e.createCanvasElement||function(){return new n},qe.createImageElement=e.createImageElement||function(){return new o},qe.ImageData=e.ImageData||qe.ImageData,qe.Video=e.Video||qe.Video,qe.fetch=e.fetch||qe.fetch,qe.readFile=e.readFile||qe.readFile}var Ct={getEnv:Ok,setEnv:bf,initialize:Yd,createBrowserEnv:Dy,createFileSystem:Ty,createNodejsEnv:Ny,monkeyPatch:Bk,isBrowser:Ay,isNodejs:Py};Yd();function Qd(e){return!Ct.isNodejs()&&typeof e=="string"?document.getElementById(e):e}function Un(e){var t=Ct.getEnv(),n=t.Canvas,r=t.CanvasRenderingContext2D;if(e instanceof r)return e;var o=Qd(e);if(!(o instanceof n))throw new Error("resolveContext2d - expected canvas to be of instance of Canvas");var i=o.getContext("2d");if(!i)throw new Error("resolveContext2d - canvas 2d context is null");return i}var kr;(function(e){e.TOP_LEFT="TOP_LEFT",e.TOP_RIGHT="TOP_RIGHT",e.BOTTOM_LEFT="BOTTOM_LEFT",e.BOTTOM_RIGHT="BOTTOM_RIGHT"})(kr||(kr={}));var Fy=function(){function e(t){t===void 0&&(t={});var n=t.anchorPosition,r=t.backgroundColor,o=t.fontColor,i=t.fontSize,a=t.fontStyle,u=t.padding;this.anchorPosition=n||kr.TOP_LEFT,this.backgroundColor=r||"rgba(0, 0, 0, 0.5)",this.fontColor=o||"rgba(255, 255, 255, 1)",this.fontSize=i||14,this.fontStyle=a||"Georgia",this.padding=u||4}return e}(),My=function(){function e(t,n,r){r===void 0&&(r={}),this.text=typeof t=="string"?[t]:t instanceof e?t.text:t,this.anchor=n,this.options=new Fy(r)}return e.prototype.measureWidth=function(t){var n=this.options.padding;return this.text.map(function(r){return t.measureText(r).width}).reduce(function(r,o){return r=3}function Uk(e){return new Promise(function(t,n){if(e instanceof Ct.getEnv().Canvas||Oy(e))return t();function r(i){i.currentTarget&&(i.currentTarget.removeEventListener("load",r),i.currentTarget.removeEventListener("error",o),t(i))}function o(i){i.currentTarget&&(i.currentTarget.removeEventListener("load",r),i.currentTarget.removeEventListener("error",o),n(i))}e.addEventListener("load",r),e.addEventListener("error",o)})}function Jd(e){var t=Ct.getEnv(),n=t.Image,r=t.Video;return e instanceof n?new so(e.naturalWidth,e.naturalHeight):e instanceof r?new so(e.videoWidth,e.videoHeight):new so(e.width,e.height)}function Ys(e){var t=e.width,n=e.height,r=Ct.getEnv().createCanvasElement,o=r();return o.width=t,o.height=n,o}function Zd(e,t){var n=Ct.getEnv().ImageData;if(!(e instanceof n)&&!Oy(e))throw new Error("createCanvasFromMedia - media has not finished loading yet");var r=t||Jd(e),o=r.width,i=r.height,a=Ys({width:o,height:i});return e instanceof n?Un(a).putImageData(e,0,0):Un(a).drawImage(e,0,0,o,i),a}function Vk(e,t){return te(this,void 0,void 0,function(){var n,r,o,i,a,u;return ne(this,function(s){switch(s.label){case 0:return n=t||Ct.getEnv().createCanvasElement(),r=e.shape.slice(Br(e)?1:0),o=r[0],i=r[1],a=r[2],u=X(function(){return e.as3D(o,i,a).toInt()}),[4,Gd.toPixels(u,n)];case 1:return s.sent(),u.dispose(),[2,n]}})})}function Dv(e){var t=Ct.getEnv(),n=t.Image,r=t.Canvas,o=t.Video;return e instanceof n||e instanceof r||e instanceof o}function $k(e,t,n){n===void 0&&(n=!1);var r=Ct.getEnv(),o=r.Image,i=r.Canvas;if(!(e instanceof o||e instanceof i))throw new Error("imageToSquare - expected arg0 to be HTMLImageElement | HTMLCanvasElement");var a=Jd(e),u=t/Math.max(a.height,a.width),s=u*a.width,l=u*a.height,c=Ys({width:t,height:t}),f=e instanceof i?e:Zd(e),d=Math.abs(s-l)/2,h=n&&s1||this._treatAsBatchInput},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"batchSize",{get:function(){return this._batchSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"inputDimensions",{get:function(){return this._inputDimensions},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"inputSize",{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"reshapedInputDimensions",{get:function(){var t=this;return wa(this.batchSize,0,1).map(function(n,r){return t.getReshapedInputDimensions(r)})},enumerable:!0,configurable:!0}),e.prototype.getInput=function(t){return this.canvases[t]||this.imageTensors[t]},e.prototype.getInputDimensions=function(t){return this._inputDimensions[t]},e.prototype.getInputHeight=function(t){return this._inputDimensions[t][0]},e.prototype.getInputWidth=function(t){return this._inputDimensions[t][1]},e.prototype.getReshapedInputDimensions=function(t){if(typeof this.inputSize!="number")throw new Error("getReshapedInputDimensions - inputSize not set, toBatchTensor has not been called yet");var n=this.getInputWidth(t),r=this.getInputHeight(t);return Ik({width:n,height:r},this.inputSize)},e.prototype.toBatchTensor=function(t,n){var r=this;return n===void 0&&(n=!0),this._inputSize=t,X(function(){var o=wa(r.batchSize,0,1).map(function(a){var u=r.getInput(a);if(u instanceof Fe){var s=Br(u)?u:u.expandDims();return s=Nk(s,n),(s.shape[1]!==t||s.shape[2]!==t)&&(s=zd.resizeBilinear(s,[t,t])),s.as3D(t,t,3)}if(u instanceof Ct.getEnv().Canvas)return Gd.fromPixels($k(u,t,n));throw new Error("toBatchTensor - at batchIdx "+a+", expected input to be instanceof tf.Tensor or instanceof HTMLCanvasElement, instead have "+u)}),i=Gt(o.map(function(a){return a.toFloat()})).as4D(r.batchSize,t,t,3);return i})},e}();function it(e){return te(this,void 0,void 0,function(){var t,n,r;return ne(this,function(o){switch(o.label){case 0:if(e instanceof xs)return[2,e];if(t=Array.isArray(e)?e:[e],!t.length)throw new Error("toNetInput - empty array passed as input");return n=function(i){return Array.isArray(e)?" at input index "+i+":":""},r=t.map(Qd),r.forEach(function(i,a){if(!Dv(i)&&!Ks(i)&&!Br(i))throw typeof t[a]=="string"?new Error("toNetInput -"+n(a)+" string passed, but could not resolve HTMLElement for element id "+t[a]):new Error("toNetInput -"+n(a)+" expected media to be of type HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | tf.Tensor3D, or to be an element id");if(Br(i)){var u=i.shape[0];if(u!==1)throw new Error("toNetInput -"+n(a)+" tf.Tensor4D with batchSize "+u+" passed, but not supported in input array")}}),[4,Promise.all(r.map(function(i){return Dv(i)&&Uk(i)}))];case 1:return o.sent(),[2,new xs(r,Array.isArray(e))]}})})}function eh(e,t){return te(this,void 0,void 0,function(){var n,r,o,i,a,u,s;return ne(this,function(l){switch(l.label){case 0:return n=Ct.getEnv().Canvas,r=e,e instanceof n?[3,5]:[4,it(e)];case 1:if(o=l.sent(),o.batchSize>1)throw new Error("extractFaces - batchSize > 1 not supported");return i=o.getInput(0),i instanceof n?(a=i,[3,4]):[3,2];case 2:return[4,Vk(i)];case 3:a=l.sent(),l.label=4;case 4:r=a,l.label=5;case 5:return u=Un(r),s=t.map(function(c){return c instanceof Kt?c.forSize(r.width,r.height).box.floor():c}).map(function(c){return c.clipAtImageBorders(r.width,r.height)}),[2,s.map(function(c){var f=c.x,d=c.y,h=c.width,p=c.height,m=Ys({width:h,height:p});return Un(m).putImageData(u.getImageData(f,d,h,p),0,0),m})]}})})}function th(e,t){return te(this,void 0,void 0,function(){return ne(this,function(n){if(!Ks(e)&&!Br(e))throw new Error("extractFaceTensors - expected image tensor to be 3D or 4D");if(Br(e)&&e.shape[0]>1)throw new Error("extractFaceTensors - batchSize > 1 not supported");return[2,X(function(){var r=e.shape.slice(Br(e)?1:0),o=r[0],i=r[1],a=r[2],u=t.map(function(l){return l instanceof Kt?l.forSize(i,o).box:l}).map(function(l){return l.clipAtImageBorders(i,o)}),s=u.map(function(l){var c=l.x,f=l.y,d=l.width,h=l.height;return sy(e.as3D(o,i,a),[f,c,0],[h,d,a])});return s})]})})}function Hk(e,t){return te(this,void 0,void 0,function(){var n,r;return ne(this,function(o){switch(o.label){case 0:return n=Ct.getEnv().fetch,[4,n(e,t)];case 1:if(r=o.sent(),!(r.status<400))throw new Error("failed to fetch: ("+r.status+") "+r.statusText+", from url: "+r.url);return[2,r]}})})}function jk(e){return te(this,void 0,void 0,function(){return ne(this,function(t){switch(t.label){case 0:return[4,Hk(e)];case 1:return[2,t.sent().json()]}})})}function By(e,t){var n=t+"-weights_manifest.json";if(!e)return{modelBaseUri:"",manifestUri:n};if(e==="/")return{modelBaseUri:"/",manifestUri:"/"+n};var r=e.startsWith("http://")?"http://":e.startsWith("https://")?"https://":"";e=e.replace(r,"");var o=e.split("/").filter(function(u){return u}),i=e.endsWith(".json")?o[o.length-1]:n,a=r+(e.endsWith(".json")?o.slice(0,o.length-1):o).join("/");return a=e.startsWith("/")?"/"+a:a,{modelBaseUri:a,manifestUri:a==="/"?"/"+i:a+"/"+i}}function Gk(e,t){return te(this,void 0,void 0,function(){var n,r,o,i;return ne(this,function(a){switch(a.label){case 0:return n=By(e,t),r=n.manifestUri,o=n.modelBaseUri,[4,jk(r)];case 1:return i=a.sent(),[2,Sy.loadWeights(i,o)]}})})}function qk(e,t,n){n===void 0&&(n=!1);var r=n?Jd(t):t,o=r.width,i=r.height;return e.width=o,e.height=i,{width:o,height:i}}var fr=function(){function e(t){this._name=t,this._params=void 0,this._paramMappings=[]}return Object.defineProperty(e.prototype,"params",{get:function(){return this._params},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"paramMappings",{get:function(){return this._paramMappings},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isLoaded",{get:function(){return!!this.params},enumerable:!0,configurable:!0}),e.prototype.getParamFromPath=function(t){var n=this.traversePropertyPath(t),r=n.obj,o=n.objProp;return r[o]},e.prototype.reassignParamFromPath=function(t,n){var r=this.traversePropertyPath(t),o=r.obj,i=r.objProp;o[i].dispose(),o[i]=n},e.prototype.getParamList=function(){var t=this;return this._paramMappings.map(function(n){var r=n.paramPath;return{path:r,tensor:t.getParamFromPath(r)}})},e.prototype.getTrainableParams=function(){return this.getParamList().filter(function(t){return t.tensor instanceof vi})},e.prototype.getFrozenParams=function(){return this.getParamList().filter(function(t){return!(t.tensor instanceof vi)})},e.prototype.variable=function(){var t=this;this.getFrozenParams().forEach(function(n){var r=n.path,o=n.tensor;t.reassignParamFromPath(r,o.variable())})},e.prototype.freeze=function(){var t=this;this.getTrainableParams().forEach(function(n){var r=n.path,o=n.tensor,i=lt(o.dataSync());o.dispose(),t.reassignParamFromPath(r,i)})},e.prototype.dispose=function(t){t===void 0&&(t=!0),this.getParamList().forEach(function(n){if(t&&n.tensor.isDisposed)throw new Error("param tensor has already been disposed for path "+n.path);n.tensor.dispose()}),this._params=void 0},e.prototype.serializeParams=function(){return new Float32Array(this.getParamList().map(function(t){var n=t.tensor;return Array.from(n.dataSync())}).reduce(function(t,n){return t.concat(n)}))},e.prototype.load=function(t){return te(this,void 0,void 0,function(){return ne(this,function(n){switch(n.label){case 0:return t instanceof Float32Array?(this.extractWeights(t),[2]):[4,this.loadFromUri(t)];case 1:return n.sent(),[2]}})})},e.prototype.loadFromUri=function(t){return te(this,void 0,void 0,function(){var n;return ne(this,function(r){switch(r.label){case 0:if(t&&typeof t!="string")throw new Error(this._name+".loadFromUri - expected model uri");return[4,Gk(t,this.getDefaultModelName())];case 1:return n=r.sent(),this.loadFromWeightMap(n),[2]}})})},e.prototype.loadFromDisk=function(t){return te(this,void 0,void 0,function(){var n,r,o,i,a,u,s,l,c,f;return ne(this,function(d){switch(d.label){case 0:if(t&&typeof t!="string")throw new Error(this._name+".loadFromDisk - expected model file path");return n=Ct.getEnv().readFile,r=By(t,this.getDefaultModelName()),o=r.manifestUri,i=r.modelBaseUri,a=function(h){return Promise.all(h.map(function(p){return n(p).then(function(m){return m.buffer})}))},u=Sy.weightsLoaderFactory(a),c=(l=JSON).parse,[4,n(o)];case 1:return s=c.apply(l,[d.sent().toString()]),[4,u(s,i)];case 2:return f=d.sent(),this.loadFromWeightMap(f),[2]}})})},e.prototype.loadFromWeightMap=function(t){var n=this.extractParamsFromWeigthMap(t),r=n.paramMappings,o=n.params;this._paramMappings=r,this._params=o},e.prototype.extractWeights=function(t){var n=this.extractParams(t),r=n.paramMappings,o=n.params;this._paramMappings=r,this._params=o},e.prototype.traversePropertyPath=function(t){if(!this.params)throw new Error("traversePropertyPath - model has no loaded params");var n=t.split("/").reduce(function(i,a){if(!i.nextObj.hasOwnProperty(a))throw new Error("traversePropertyPath - object does not have property "+a+", for path "+t);return{obj:i.nextObj,objProp:a,nextObj:i.nextObj[a]}},{nextObj:this.params}),r=n.obj,o=n.objProp;if(!r||!o||!(r[o]instanceof Fe))throw new Error("traversePropertyPath - parameter is not a tensor, for path "+t);return{obj:r,objProp:o}},e}();function Ht(e,t,n){return X(function(){var r=Md(e,t.depthwise_filter,t.pointwise_filter,n,"same");return r=de(r,t.bias),r})}function rc(e,t,n){return n===void 0&&(n=!1),X(function(){var r=Me(n?de(un(e,t.conv0.filters,[2,2],"same"),t.conv0.bias):Ht(e,t.conv0,[2,2])),o=Ht(r,t.conv1,[1,1]),i=Me(de(r,o)),a=Ht(i,t.conv2,[1,1]);return Me(de(r,de(o,a)))})}function du(e,t,n,r){return n===void 0&&(n=!1),r===void 0&&(r=!0),X(function(){var o=Me(n?de(un(e,t.conv0.filters,r?[2,2]:[1,1],"same"),t.conv0.bias):Ht(e,t.conv0,r?[2,2]:[1,1])),i=Ht(o,t.conv1,[1,1]),a=Me(de(o,i)),u=Ht(a,t.conv2,[1,1]),s=Me(de(o,de(i,u))),l=Ht(s,t.conv3,[1,1]);return Me(de(o,de(i,de(u,l))))})}function yn(e,t,n,r){return n===void 0&&(n="same"),r===void 0&&(r=!1),X(function(){var o=de(un(e,t.filters,[1,1],n),t.bias);return r?Me(o):o})}function dr(e,t){Object.keys(e).forEach(function(n){t.some(function(r){return r.originalPath===n})||e[n].dispose()})}function Qs(e,t){return function(n,r,o,i){var a=It(e(n*r*o*o),[o,o,n,r]),u=Ge(e(r));return t.push({paramPath:i+"/filters"},{paramPath:i+"/bias"}),{filters:a,bias:u}}}function nh(e,t){return function(n,r,o){var i=Mr(e(n*r),[n,r]),a=Ge(e(r));return t.push({paramPath:o+"/weights"},{paramPath:o+"/bias"}),{weights:i,bias:a}}}var Ly=function(){function e(t,n,r){this.depthwise_filter=t,this.pointwise_filter=n,this.bias=r}return e}();function rh(e,t){return function(n,r,o){var i=It(e(9*n),[3,3,n,1]),a=It(e(n*r),[1,1,n,r]),u=Ge(e(r));return t.push({paramPath:o+"/depthwise_filter"},{paramPath:o+"/pointwise_filter"},{paramPath:o+"/bias"}),new Ly(i,a,u)}}function oh(e){return function(t){var n=e(t+"/depthwise_filter",4),r=e(t+"/pointwise_filter",4),o=e(t+"/bias",1);return new Ly(n,r,o)}}function Gr(e,t){return function(n,r,o){var i=e[n];if(!qs(i,r))throw new Error("expected weightMap["+n+"] to be a Tensor"+r+"D, instead have "+i);return t.push({originalPath:n,paramPath:o||n}),i}}function hr(e){var t=e;function n(o){var i=t.slice(0,o);return t=t.slice(o),i}function r(){return t}return{extractWeights:n,getRemainingWeights:r}}function Wy(e,t){var n=Qs(e,t),r=rh(e,t);function o(a,u,s,l){l===void 0&&(l=!1);var c=l?n(a,u,3,s+"/conv0"):r(a,u,s+"/conv0"),f=r(u,u,s+"/conv1"),d=r(u,u,s+"/conv2");return{conv0:c,conv1:f,conv2:d}}function i(a,u,s,l){l===void 0&&(l=!1);var c=o(a,u,s,l),f=c.conv0,d=c.conv1,h=c.conv2,p=r(u,u,s+"/conv3");return{conv0:f,conv1:d,conv2:h,conv3:p}}return{extractDenseBlock3Params:o,extractDenseBlock4Params:i}}function Kk(e){var t=[],n=hr(e),r=n.extractWeights,o=n.getRemainingWeights,i=Wy(r,t).extractDenseBlock4Params,a=i(3,32,"dense0",!0),u=i(32,64,"dense1"),s=i(64,128,"dense2"),l=i(128,256,"dense3");if(o().length!==0)throw new Error("weights remaing after extract: "+o().length);return{paramMappings:t,params:{dense0:a,dense1:u,dense2:s,dense3:l}}}function zy(e){return function(t){var n=e(t+"/filters",4),r=e(t+"/bias",1);return{filters:n,bias:r}}}function Uy(e,t){var n=Gr(e,t),r=zy(n),o=oh(n);function i(u,s){s===void 0&&(s=!1);var l=s?r(u+"/conv0"):o(u+"/conv0"),c=o(u+"/conv1"),f=o(u+"/conv2");return{conv0:l,conv1:c,conv2:f}}function a(u,s){s===void 0&&(s=!1);var l=s?r(u+"/conv0"):o(u+"/conv0"),c=o(u+"/conv1"),f=o(u+"/conv2"),d=o(u+"/conv3");return{conv0:l,conv1:c,conv2:f,conv3:d}}return{extractDenseBlock3Params:i,extractDenseBlock4Params:a}}function Xk(e){var t=[],n=Uy(e,t).extractDenseBlock4Params,r={dense0:n("dense0",!0),dense1:n("dense1"),dense2:n("dense2"),dense3:n("dense3")};return dr(e,t),{params:r,paramMappings:t}}var Vy=function(e){ue(t,e);function t(){return e.call(this,"FaceFeatureExtractor")||this}return t.prototype.forwardInput=function(n){var r=this.params;if(!r)throw new Error("FaceFeatureExtractor - load model before inference");return X(function(){var o=n.toBatchTensor(112,!0),i=[122.782,117.001,104.298],a=Ba(o,i).div(K(255)),u=du(a,r.dense0,!0);return u=du(u,r.dense1),u=du(u,r.dense2),u=du(u,r.dense3),u=Ma(u,[7,7],[2,2],"valid"),u})},t.prototype.forward=function(n){return te(this,void 0,void 0,function(){var r;return ne(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,it(n)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.getDefaultModelName=function(){return"face_feature_extractor_model"},t.prototype.extractParamsFromWeigthMap=function(n){return Xk(n)},t.prototype.extractParams=function(n){return Kk(n)},t}(fr);function Pn(e,t){return X(function(){return de(Hs(e,t.weights),t.bias)})}function Yk(e,t,n){var r=[],o=hr(e),i=o.extractWeights,a=o.getRemainingWeights,u=nh(i,r),s=u(t,n,"fc");if(a().length!==0)throw new Error("weights remaing after extract: "+a().length);return{paramMappings:r,params:{fc:s}}}function Qk(e){var t=[],n=Gr(e,t);function r(i){var a=n(i+"/weights",2),u=n(i+"/bias",1);return{weights:a,bias:u}}var o={fc:r("fc")};return dr(e,t),{params:o,paramMappings:t}}function $y(e){var t={},n={};return Object.keys(e).forEach(function(r){var o=r.startsWith("fc")?n:t;o[r]=e[r]}),{featureExtractorMap:t,classifierMap:n}}var Hy=function(e){ue(t,e);function t(n,r){var o=e.call(this,n)||this;return o._faceFeatureExtractor=r,o}return 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 X(function(){var i=n instanceof xs?r.faceFeatureExtractor.forwardInput(n):n;return Pn(i.as2D(i.shape[0],-1),o.fc)})},t.prototype.dispose=function(n){n===void 0&&(n=!0),this.faceFeatureExtractor.dispose(n),e.prototype.dispose.call(this,n)},t.prototype.loadClassifierParams=function(n){var r=this.extractClassifierParams(n),o=r.params,i=r.paramMappings;this._params=o,this._paramMappings=i},t.prototype.extractClassifierParams=function(n){return Yk(n,this.getClassifierChannelsIn(),this.getClassifierChannelsOut())},t.prototype.extractParamsFromWeigthMap=function(n){var r=$y(n),o=r.featureExtractorMap,i=r.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(o),Qk(i)},t.prototype.extractParams=function(n){var r=this.getClassifierChannelsIn(),o=this.getClassifierChannelsOut(),i=o*r+o,a=n.slice(0,n.length-i),u=n.slice(n.length-i);return this.faceFeatureExtractor.extractWeights(a),this.extractClassifierParams(u)},t}(fr),Tv=["neutral","happy","sad","angry","fearful","disgusted","surprised"],ih=function(){function e(t){var n=this;if(t.length!==7)throw new Error("FaceExpressions.constructor - expected probabilities.length to be 7, have: "+t.length);Tv.forEach(function(r,o){n[r]=t[o]})}return e.prototype.asSortedArray=function(){var t=this;return Tv.map(function(n){return{expression:n,probability:t[n]}}).sort(function(n,r){return r.probability-n.probability})},e}(),Jk=function(e){ue(t,e);function t(n){return n===void 0&&(n=new Vy),e.call(this,"FaceExpressionNet",n)||this}return t.prototype.forwardInput=function(n){var r=this;return X(function(){return lr(r.runNet(n))})},t.prototype.forward=function(n){return te(this,void 0,void 0,function(){var r;return ne(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,it(n)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.predictExpressions=function(n){return te(this,void 0,void 0,function(){var r,o,i,a,u=this;return ne(this,function(s){switch(s.label){case 0:return[4,it(n)];case 1:return r=s.sent(),[4,this.forwardInput(r)];case 2:return o=s.sent(),[4,Promise.all(Qe(o).map(function(l){return te(u,void 0,void 0,function(){var c;return ne(this,function(f){switch(f.label){case 0:return[4,l.data()];case 1:return c=f.sent(),l.dispose(),[2,c]}})})}))];case 3:return i=s.sent(),o.dispose(),a=i.map(function(l){return new ih(l)}),[2,r.isBatchInput?a:a[0]]}})})},t.prototype.getDefaultModelName=function(){return"face_expression_model"},t.prototype.getClassifierChannelsIn=function(){return 256},t.prototype.getClassifierChannelsOut=function(){return 7},t}(Hy);function Zk(e){return e.expressions instanceof ih}function jy(e,t){var n={expressions:t};return Object.assign({},e,n)}function eR(e,t,n,r){n===void 0&&(n=.1);var o=Array.isArray(t)?t:[t];o.forEach(function(i){var a=i instanceof ih?i:Zk(i)?i.expressions:void 0;if(!a)throw new Error("drawFaceExpressions - expected faceExpressions to be FaceExpressions | WithFaceExpressions<{}> or array thereof");var u=a.asSortedArray(),s=u.filter(function(f){return f.probability>n}),l=Ca(i)?i.detection.box.bottomLeft:r||new we(0,0),c=new My(s.map(function(f){return f.expression+" ("+qd(f.probability)+")"}),l);c.draw(e)})}function ah(e){return Ca(e)&&e.landmarks instanceof yi&&e.unshiftedLandmarks instanceof yi&&e.alignedRect instanceof Kt}function Js(e,t){var n=e.detection.box,r=t.shiftBy(n.x,n.y),o=r.align(),i=e.detection.imageDims,a=new Kt(e.detection.score,o.rescale(i.reverse()),i),u={landmarks:r,unshiftedLandmarks:t,alignedRect:a};return Object.assign({},e,u)}var tR=function(){function e(t){t===void 0&&(t={});var n=t.drawLines,r=n===void 0?!0:n,o=t.drawPoints,i=o===void 0?!0:o,a=t.lineWidth,u=t.lineColor,s=t.pointSize,l=t.pointColor;this.drawLines=r,this.drawPoints=i,this.lineWidth=a||1,this.pointSize=s||2,this.lineColor=u||"rgba(0, 255, 255, 1)",this.pointColor=l||"rgba(255, 0, 255, 1)"}return e}(),nR=function(){function e(t,n){n===void 0&&(n={}),this.faceLandmarks=t,this.options=new tR(n)}return e.prototype.draw=function(t){var n=Un(t),r=this.options,o=r.drawLines,i=r.drawPoints,a=r.lineWidth,u=r.lineColor,s=r.pointSize,l=r.pointColor;if(o&&this.faceLandmarks instanceof Iy&&(n.strokeStyle=u,n.lineWidth=a,Xr(n,this.faceLandmarks.getJawOutline()),Xr(n,this.faceLandmarks.getLeftEyeBrow()),Xr(n,this.faceLandmarks.getRightEyeBrow()),Xr(n,this.faceLandmarks.getNose()),Xr(n,this.faceLandmarks.getLeftEye(),!0),Xr(n,this.faceLandmarks.getRightEye(),!0),Xr(n,this.faceLandmarks.getMouth(),!0)),i){n.strokeStyle=l,n.fillStyle=l;var c=function(f){n.beginPath(),n.arc(f.x,f.y,s,0,2*Math.PI),n.fill()};this.faceLandmarks.positions.forEach(c)}},e}();function rR(e,t){var n=Array.isArray(t)?t:[t];n.forEach(function(r){var o=r instanceof yi?r:ah(r)?r.landmarks:void 0;if(!o)throw new Error("drawFaceLandmarks - expected faceExpressions to be FaceLandmarks | WithFaceLandmarks> or array thereof");new nR(o).draw(e)})}function oR(e,t){var n=Qs(e,t),r=rh(e,t);function o(a,u,s){var l=r(a,u,s+"/separable_conv0"),c=r(u,u,s+"/separable_conv1"),f=n(a,u,1,s+"/expansion_conv");return{separable_conv0:l,separable_conv1:c,expansion_conv:f}}function i(a,u){var s=r(a,a,u+"/separable_conv0"),l=r(a,a,u+"/separable_conv1"),c=r(a,a,u+"/separable_conv2");return{separable_conv0:s,separable_conv1:l,separable_conv2:c}}return{extractConvParams:n,extractSeparableConvParams:r,extractReductionBlockParams:o,extractMainBlockParams:i}}function iR(e,t){var n=[],r=hr(e),o=r.extractWeights,i=r.getRemainingWeights,a=oR(o,n),u=a.extractConvParams,s=a.extractSeparableConvParams,l=a.extractReductionBlockParams,c=a.extractMainBlockParams,f=u(3,32,3,"entry_flow/conv_in"),d=l(32,64,"entry_flow/reduction_block_0"),h=l(64,128,"entry_flow/reduction_block_1"),p={conv_in:f,reduction_block_0:d,reduction_block_1:h},m={};wa(t,0,1).forEach(function(x){m["main_block_"+x]=c(128,"middle_flow/main_block_"+x)});var g=l(128,256,"exit_flow/reduction_block"),v=s(256,512,"exit_flow/separable_conv"),y={reduction_block:g,separable_conv:v};if(i().length!==0)throw new Error("weights remaing after extract: "+i().length);return{paramMappings:n,params:{entry_flow:p,middle_flow:m,exit_flow:y}}}function aR(e,t){var n=Gr(e,t),r=zy(n),o=oh(n);function i(u){var s=o(u+"/separable_conv0"),l=o(u+"/separable_conv1"),c=r(u+"/expansion_conv");return{separable_conv0:s,separable_conv1:l,expansion_conv:c}}function a(u){var s=o(u+"/separable_conv0"),l=o(u+"/separable_conv1"),c=o(u+"/separable_conv2");return{separable_conv0:s,separable_conv1:l,separable_conv2:c}}return{extractConvParams:r,extractSeparableConvParams:o,extractReductionBlockParams:i,extractMainBlockParams:a}}function uR(e,t){var n=[],r=aR(e,n),o=r.extractConvParams,i=r.extractSeparableConvParams,a=r.extractReductionBlockParams,u=r.extractMainBlockParams,s=o("entry_flow/conv_in"),l=a("entry_flow/reduction_block_0"),c=a("entry_flow/reduction_block_1"),f={conv_in:s,reduction_block_0:l,reduction_block_1:c},d={};wa(t,0,1).forEach(function(g){d["main_block_"+g]=u("middle_flow/main_block_"+g)});var h=a("exit_flow/reduction_block"),p=i("exit_flow/separable_conv"),m={reduction_block:h,separable_conv:p};return dr(e,n),{params:{entry_flow:f,middle_flow:d,exit_flow:m},paramMappings:n}}function Gy(e,t,n){return de(un(e,t.filters,n,"same"),t.bias)}function oc(e,t,n){n===void 0&&(n=!0);var r=n?Me(e):e;return r=Ht(r,t.separable_conv0,[1,1]),r=Ht(Me(r),t.separable_conv1,[1,1]),r=tt(r,[3,3],[2,2],"same"),r=de(r,Gy(e,t.expansion_conv,[2,2])),r}function sR(e,t){var n=Ht(Me(e),t.separable_conv0,[1,1]);return n=Ht(Me(n),t.separable_conv1,[1,1]),n=Ht(Me(n),t.separable_conv2,[1,1]),n=de(n,e),n}var lR=function(e){ue(t,e);function t(n){var r=e.call(this,"TinyXception")||this;return r._numMainBlocks=n,r}return t.prototype.forwardInput=function(n){var r=this,o=this.params;if(!o)throw new Error("TinyXception - load model before inference");return X(function(){var i=n.toBatchTensor(112,!0),a=[122.782,117.001,104.298],u=Ba(i,a).div(K(256)),s=Me(Gy(u,o.entry_flow.conv_in,[2,2]));return s=oc(s,o.entry_flow.reduction_block_0,!1),s=oc(s,o.entry_flow.reduction_block_1),wa(r._numMainBlocks,0,1).forEach(function(l){s=sR(s,o.middle_flow["main_block_"+l])}),s=oc(s,o.exit_flow.reduction_block),s=Me(Ht(s,o.exit_flow.separable_conv,[1,1])),s})},t.prototype.forward=function(n){return te(this,void 0,void 0,function(){var r;return ne(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,it(n)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.getDefaultModelName=function(){return"tiny_xception_model"},t.prototype.extractParamsFromWeigthMap=function(n){return uR(n,this._numMainBlocks)},t.prototype.extractParams=function(n){return iR(n,this._numMainBlocks)},t}(fr);function cR(e){var t=[],n=hr(e),r=n.extractWeights,o=n.getRemainingWeights,i=nh(r,t),a=i(512,1,"fc/age"),u=i(512,2,"fc/gender");if(o().length!==0)throw new Error("weights remaing after extract: "+o().length);return{paramMappings:t,params:{fc:{age:a,gender:u}}}}function fR(e){var t=[],n=Gr(e,t);function r(i){var a=n(i+"/weights",2),u=n(i+"/bias",1);return{weights:a,bias:u}}var o={fc:{age:r("fc/age"),gender:r("fc/gender")}};return dr(e,t),{params:o,paramMappings:t}}var ws;(function(e){e.FEMALE="female",e.MALE="male"})(ws||(ws={}));var dR=function(e){ue(t,e);function t(n){n===void 0&&(n=new lR(2));var r=e.call(this,"AgeGenderNet")||this;return r._faceFeatureExtractor=n,r}return 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 X(function(){var i=n instanceof xs?r.faceFeatureExtractor.forwardInput(n):n,a=Ma(i,[7,7],[2,2],"valid").as2D(i.shape[0],-1),u=Pn(a,o.fc.age).as1D(),s=Pn(a,o.fc.gender);return{age:u,gender:s}})},t.prototype.forwardInput=function(n){var r=this;return X(function(){var o=r.runNet(n),i=o.age,a=o.gender;return{age:i,gender:lr(a)}})},t.prototype.forward=function(n){return te(this,void 0,void 0,function(){var r;return ne(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,it(n)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.predictAgeAndGender=function(n){return te(this,void 0,void 0,function(){var r,o,i,a,u,s,l=this;return ne(this,function(c){switch(c.label){case 0:return[4,it(n)];case 1:return r=c.sent(),[4,this.forwardInput(r)];case 2:return o=c.sent(),i=Qe(o.age),a=Qe(o.gender),u=i.map(function(f,d){return{ageTensor:f,genderTensor:a[d]}}),[4,Promise.all(u.map(function(f){var d=f.ageTensor,h=f.genderTensor;return te(l,void 0,void 0,function(){var p,m,g,v,y;return ne(this,function(x){switch(x.label){case 0:return[4,d.data()];case 1:return p=x.sent()[0],[4,h.data()];case 2:return m=x.sent()[0],g=m>.5,v=g?ws.MALE:ws.FEMALE,y=g?m:1-m,d.dispose(),h.dispose(),[2,{age:p,gender:v,genderProbability:y}]}})})}))];case 3:return s=c.sent(),o.age.dispose(),o.gender.dispose(),[2,r.isBatchInput?s:s[0]]}})})},t.prototype.getDefaultModelName=function(){return"age_gender_model"},t.prototype.dispose=function(n){n===void 0&&(n=!0),this.faceFeatureExtractor.dispose(n),e.prototype.dispose.call(this,n)},t.prototype.loadClassifierParams=function(n){var r=this.extractClassifierParams(n),o=r.params,i=r.paramMappings;this._params=o,this._paramMappings=i},t.prototype.extractClassifierParams=function(n){return cR(n)},t.prototype.extractParamsFromWeigthMap=function(n){var r=$y(n),o=r.featureExtractorMap,i=r.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(o),fR(i)},t.prototype.extractParams=function(n){var r=1539,o=n.slice(0,n.length-r),i=n.slice(n.length-r);return this.faceFeatureExtractor.extractWeights(o),this.extractClassifierParams(i)},t}(fr),qy=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.postProcess=function(n,r,o){var i=o.map(function(u){var s=u.width,l=u.height,c=r/Math.max(l,s);return{width:s*c,height:l*c}}),a=i.length;return X(function(){var u=function(d,h){return Gt([Ln([68],d),Ln([68],h)],1).as2D(1,136).as1D()},s=function(d,h){var p=i[d],m=p.width,g=p.height;return h(m,g)?Math.abs(m-g)/2:0},l=function(d){return s(d,function(h,p){return h 0");if(typeof this._scaleFactor!="number"||this._scaleFactor<=0||this._scaleFactor>=1)throw new Error(this._name+" - expected scaleFactor to be a number between 0 and 1");if(typeof this._maxNumScales!="number"||this._maxNumScales<0)throw new Error(this._name+" - expected maxNumScales to be a number > 0");if(!Array.isArray(this._scoreThresholds)||this._scoreThresholds.length!==3||this._scoreThresholds.some(function(s){return typeof s!="number"}))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(s){return typeof s!="number"})))throw new Error(this._name+" - expected scaleSteps to be an array of numbers")}return Object.defineProperty(e.prototype,"minFaceSize",{get:function(){return this._minFaceSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scaleFactor",{get:function(){return this._scaleFactor},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maxNumScales",{get:function(){return this._maxNumScales},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scoreThresholds",{get:function(){return this._scoreThresholds},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scaleSteps",{get:function(){return this._scaleSteps},enumerable:!0,configurable:!0}),e}();function ER(e,t){function n(s,l){var c=It(e(9*s),[3,3,s,1]),f=Ge(e(s)),d=Ge(e(s)),h=Ge(e(s)),p=Ge(e(s));return t.push({paramPath:l+"/filters"},{paramPath:l+"/batch_norm_scale"},{paramPath:l+"/batch_norm_offset"},{paramPath:l+"/batch_norm_mean"},{paramPath:l+"/batch_norm_variance"}),{filters:c,batch_norm_scale:f,batch_norm_offset:d,batch_norm_mean:h,batch_norm_variance:p}}function r(s,l,c,f,d){var h=It(e(s*l*c*c),[c,c,s,l]),p=Ge(e(l));return t.push({paramPath:f+"/filters"},{paramPath:f+"/"+(d?"batch_norm_offset":"bias")}),{filters:h,bias:p}}function o(s,l,c,f){var d=r(s,l,c,f,!0),h=d.filters,p=d.bias;return{filters:h,batch_norm_offset:p}}function i(s,l,c){var f=n(s,c+"/depthwise_conv"),d=o(s,l,1,c+"/pointwise_conv");return{depthwise_conv:f,pointwise_conv:d}}function a(){var s=o(3,32,3,"mobilenetv1/conv_0"),l=i(32,64,"mobilenetv1/conv_1"),c=i(64,128,"mobilenetv1/conv_2"),f=i(128,128,"mobilenetv1/conv_3"),d=i(128,256,"mobilenetv1/conv_4"),h=i(256,256,"mobilenetv1/conv_5"),p=i(256,512,"mobilenetv1/conv_6"),m=i(512,512,"mobilenetv1/conv_7"),g=i(512,512,"mobilenetv1/conv_8"),v=i(512,512,"mobilenetv1/conv_9"),y=i(512,512,"mobilenetv1/conv_10"),x=i(512,512,"mobilenetv1/conv_11"),w=i(512,1024,"mobilenetv1/conv_12"),b=i(1024,1024,"mobilenetv1/conv_13");return{conv_0:s,conv_1:l,conv_2:c,conv_3:f,conv_4:d,conv_5:h,conv_6:p,conv_7:m,conv_8:g,conv_9:v,conv_10:y,conv_11:x,conv_12:w,conv_13:b}}function u(){var s=o(1024,256,1,"prediction_layer/conv_0"),l=o(256,512,3,"prediction_layer/conv_1"),c=o(512,128,1,"prediction_layer/conv_2"),f=o(128,256,3,"prediction_layer/conv_3"),d=o(256,128,1,"prediction_layer/conv_4"),h=o(128,256,3,"prediction_layer/conv_5"),p=o(256,64,1,"prediction_layer/conv_6"),m=o(64,128,3,"prediction_layer/conv_7"),g=r(512,12,1,"prediction_layer/box_predictor_0/box_encoding_predictor"),v=r(512,9,1,"prediction_layer/box_predictor_0/class_predictor"),y=r(1024,24,1,"prediction_layer/box_predictor_1/box_encoding_predictor"),x=r(1024,18,1,"prediction_layer/box_predictor_1/class_predictor"),w=r(512,24,1,"prediction_layer/box_predictor_2/box_encoding_predictor"),b=r(512,18,1,"prediction_layer/box_predictor_2/class_predictor"),C=r(256,24,1,"prediction_layer/box_predictor_3/box_encoding_predictor"),_=r(256,18,1,"prediction_layer/box_predictor_3/class_predictor"),E=r(256,24,1,"prediction_layer/box_predictor_4/box_encoding_predictor"),R=r(256,18,1,"prediction_layer/box_predictor_4/class_predictor"),k=r(128,24,1,"prediction_layer/box_predictor_5/box_encoding_predictor"),T=r(128,18,1,"prediction_layer/box_predictor_5/class_predictor"),N={box_encoding_predictor:g,class_predictor:v},W={box_encoding_predictor:y,class_predictor:x},L={box_encoding_predictor:w,class_predictor:b},U={box_encoding_predictor:C,class_predictor:_},$={box_encoding_predictor:E,class_predictor:R},V={box_encoding_predictor:k,class_predictor:T};return{conv_0:s,conv_1:l,conv_2:c,conv_3:f,conv_4:d,conv_5:h,conv_6:p,conv_7:m,box_predictor_0:N,box_predictor_1:W,box_predictor_2:L,box_predictor_3:U,box_predictor_4:$,box_predictor_5:V}}return{extractMobilenetV1Params:a,extractPredictionLayerParams:u}}function SR(e){var t=[],n=hr(e),r=n.extractWeights,o=n.getRemainingWeights,i=ER(r,t),a=i.extractMobilenetV1Params,u=i.extractPredictionLayerParams,s=a(),l=u(),c=wd(r(5118*4),[1,5118,4]),f={extra_dim:c};if(t.push({paramPath:"output_layer/extra_dim"}),o().length!==0)throw new Error("weights remaing after extract: "+o().length);return{params:{mobilenetv1:s,prediction_layer:l,output_layer:f},paramMappings:t}}function kR(e,t){var n=Gr(e,t);function r(l,c,f){var d=n(l+"/Conv2d_"+c+"_pointwise/weights",4,f+"/filters"),h=n(l+"/Conv2d_"+c+"_pointwise/convolution_bn_offset",1,f+"/batch_norm_offset");return{filters:d,batch_norm_offset:h}}function o(l){var c="mobilenetv1/conv_"+l,f="MobilenetV1/Conv2d_"+l+"_depthwise",d=c+"/depthwise_conv",h=c+"/pointwise_conv",p=n(f+"/depthwise_weights",4,d+"/filters"),m=n(f+"/BatchNorm/gamma",1,d+"/batch_norm_scale"),g=n(f+"/BatchNorm/beta",1,d+"/batch_norm_offset"),v=n(f+"/BatchNorm/moving_mean",1,d+"/batch_norm_mean"),y=n(f+"/BatchNorm/moving_variance",1,d+"/batch_norm_variance");return{depthwise_conv:{filters:p,batch_norm_scale:m,batch_norm_offset:g,batch_norm_mean:v,batch_norm_variance:y},pointwise_conv:r("MobilenetV1",l,h)}}function i(){return{conv_0:r("MobilenetV1",0,"mobilenetv1/conv_0"),conv_1:o(1),conv_2:o(2),conv_3:o(3),conv_4:o(4),conv_5:o(5),conv_6:o(6),conv_7:o(7),conv_8:o(8),conv_9:o(9),conv_10:o(10),conv_11:o(11),conv_12:o(12),conv_13:o(13)}}function a(l,c){var f=n(l+"/weights",4,c+"/filters"),d=n(l+"/biases",1,c+"/bias");return{filters:f,bias:d}}function u(l){var c=a("Prediction/BoxPredictor_"+l+"/BoxEncodingPredictor","prediction_layer/box_predictor_"+l+"/box_encoding_predictor"),f=a("Prediction/BoxPredictor_"+l+"/ClassPredictor","prediction_layer/box_predictor_"+l+"/class_predictor");return{box_encoding_predictor:c,class_predictor:f}}function s(){return{conv_0:r("Prediction",0,"prediction_layer/conv_0"),conv_1:r("Prediction",1,"prediction_layer/conv_1"),conv_2:r("Prediction",2,"prediction_layer/conv_2"),conv_3:r("Prediction",3,"prediction_layer/conv_3"),conv_4:r("Prediction",4,"prediction_layer/conv_4"),conv_5:r("Prediction",5,"prediction_layer/conv_5"),conv_6:r("Prediction",6,"prediction_layer/conv_6"),conv_7:r("Prediction",7,"prediction_layer/conv_7"),box_predictor_0:u(0),box_predictor_1:u(1),box_predictor_2:u(2),box_predictor_3:u(3),box_predictor_4:u(4),box_predictor_5:u(5)}}return{extractMobilenetV1Params:i,extractPredictionLayerParams:s}}function RR(e){var t=[],n=kR(e,t),r=n.extractMobilenetV1Params,o=n.extractPredictionLayerParams,i=e["Output/extra_dim"];if(t.push({originalPath:"Output/extra_dim",paramPath:"output_layer/extra_dim"}),!Ks(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 dr(e,t),{params:a,paramMappings:t}}function In(e,t,n){return X(function(){var r=un(e,t.filters,n,"same");return r=de(r,t.batch_norm_offset),Nd(r,0,6)})}var IR=.0010000000474974513;function DR(e,t,n){return X(function(){var r=$s(e,t.filters,n,"same");return r=q0(r,t.batch_norm_mean,t.batch_norm_variance,t.batch_norm_offset,t.batch_norm_scale,IR),Nd(r,0,6)})}function TR(e){return[2,4,6,12].some(function(t){return t===e})?[2,2]:[1,1]}function NR(e,t){return X(function(){var n=null,r=In(e,t.conv_0,[2,2]),o=[t.conv_1,t.conv_2,t.conv_3,t.conv_4,t.conv_5,t.conv_6,t.conv_7,t.conv_8,t.conv_9,t.conv_10,t.conv_11,t.conv_12,t.conv_13];if(o.forEach(function(i,a){var u=a+1,s=TR(u);r=DR(r,i.depthwise_conv,s),r=In(r,i.pointwise_conv,[1,1]),u===11&&(n=r)}),n===null)throw new Error("mobileNetV1 - output of conv layer 11 is null");return{out:r,conv11:n}})}function AR(e,t,n,r,o){var i=e.shape[0],a=Math.min(n,i),u=t.map(function(c,f){return{score:c,boxIndex:f}}).filter(function(c){return c.score>o}).sort(function(c,f){return f.score-c.score}),s=function(c){return c<=r?1:0},l=[];return u.forEach(function(c){if(!(l.length>=a)){for(var f=c.score,d=l.length-1;d>=0;--d){var h=PR(e,c.boxIndex,l[d]);if(h!==0&&(c.score*=s(h),c.score<=o))break}f===c.score&&l.push(c.boxIndex)}}),l}function PR(e,t,n){var r=e.arraySync(),o=Math.min(r[t][0],r[t][2]),i=Math.min(r[t][1],r[t][3]),a=Math.max(r[t][0],r[t][2]),u=Math.max(r[t][1],r[t][3]),s=Math.min(r[n][0],r[n][2]),l=Math.min(r[n][1],r[n][3]),c=Math.max(r[n][0],r[n][2]),f=Math.max(r[n][1],r[n][3]),d=(a-o)*(u-i),h=(c-s)*(f-l);if(d<=0||h<=0)return 0;var p=Math.max(o,s),m=Math.max(i,l),g=Math.min(a,c),v=Math.min(u,f),y=Math.max(g-p,0)*Math.max(v-m,0);return y/(d+h-y)}function FR(e){var t=Qe(zr(e,[1,0])),n=[Ze(t[2],t[0]),Ze(t[3],t[1])],r=[de(t[0],pn(n[0],K(2))),de(t[1],pn(n[1],K(2)))];return{sizes:n,centers:r}}function MR(e,t){var n=FR(e),r=n.sizes,o=n.centers,i=Qe(zr(t,[1,0])),a=pn(xt(pf(pn(i[2],K(5))),r[0]),K(2)),u=de(xt(pn(i[0],K(10)),r[0]),o[0]),s=pn(xt(pf(pn(i[3],K(5))),r[1]),K(2)),l=de(xt(pn(i[1],K(10)),r[1]),o[1]);return zr(Gt([Ze(u,a),Ze(l,s),de(u,a),de(l,s)]),[1,0])}function OR(e,t,n){return X(function(){var r=e.shape[0],o=MR(vn(ti(n.extra_dim,[r,1,1]),[-1,4]),vn(e,[-1,4]));o=vn(o,[r,o.shape[0]/r,4]);var i=$0(Wn(t,[0,0,1],[-1,-1,-1])),a=Wn(i,[0,0,0],[-1,-1,1]);a=vn(a,[r,a.shape[1]]);var u=Qe(o),s=Qe(a);return{boxes:u,scores:s}})}function No(e,t){return X(function(){var n=e.shape[0],r=vn(yn(e,t.box_encoding_predictor),[n,-1,1,4]),o=vn(yn(e,t.class_predictor),[n,-1,3]);return{boxPredictionEncoding:r,classPrediction:o}})}function BR(e,t,n){return X(function(){var r=In(e,n.conv_0,[1,1]),o=In(r,n.conv_1,[2,2]),i=In(o,n.conv_2,[1,1]),a=In(i,n.conv_3,[2,2]),u=In(a,n.conv_4,[1,1]),s=In(u,n.conv_5,[2,2]),l=In(s,n.conv_6,[1,1]),c=In(l,n.conv_7,[2,2]),f=No(t,n.box_predictor_0),d=No(e,n.box_predictor_1),h=No(o,n.box_predictor_2),p=No(a,n.box_predictor_3),m=No(s,n.box_predictor_4),g=No(c,n.box_predictor_5),v=Ye([f.boxPredictionEncoding,d.boxPredictionEncoding,h.boxPredictionEncoding,p.boxPredictionEncoding,m.boxPredictionEncoding,g.boxPredictionEncoding],1),y=Ye([f.classPrediction,d.classPrediction,h.classPrediction,p.classPrediction,m.classPrediction,g.classPrediction],1);return{boxPredictions:v,classPredictions:y}})}var Zs=function(){function e(t){var n=t===void 0?{}:t,r=n.minConfidence,o=n.maxResults;if(this._name="SsdMobilenetv1Options",this._minConfidence=r||.5,this._maxResults=o||100,typeof this._minConfidence!="number"||this._minConfidence<=0||this._minConfidence>=1)throw new Error(this._name+" - expected minConfidence to be a number between 0 and 1");if(typeof this._maxResults!="number")throw new Error(this._name+" - expected maxResults to be a number")}return Object.defineProperty(e.prototype,"minConfidence",{get:function(){return this._minConfidence},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maxResults",{get:function(){return this._maxResults},enumerable:!0,configurable:!0}),e}(),t1=function(e){ue(t,e);function t(){return e.call(this,"SsdMobilenetv1")||this}return t.prototype.forwardInput=function(n){var r=this.params;if(!r)throw new Error("SsdMobilenetv1 - load model before inference");return X(function(){var o=n.toBatchTensor(512,!1).toFloat(),i=Ze(xt(o,K(.007843137718737125)),K(1)),a=NR(i,r.mobilenetv1),u=BR(a.out,a.conv11,r.prediction_layer),s=u.boxPredictions,l=u.classPredictions;return OR(s,l,r.output_layer)})},t.prototype.forward=function(n){return te(this,void 0,void 0,function(){var r;return ne(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,it(n)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.locateFaces=function(n,r){return r===void 0&&(r={}),te(this,void 0,void 0,function(){var o,i,a,u,s,l,c,f,d,h,p,m,g,v,y,x,w,b,C,_,E;return ne(this,function(R){switch(R.label){case 0:return o=new Zs(r),i=o.maxResults,a=o.minConfidence,[4,it(n)];case 1:for(u=R.sent(),s=this.forwardInput(u),l=s.boxes,c=s.scores,f=l[0],d=c[0],h=1;h1)throw new Error("config.iouThreshold has to be a number between [0, 1], have: "+e.iouThreshold);if(!Array.isArray(e.classes)||!e.classes.length||!e.classes.every(function(t){return typeof t=="string"}))throw new Error("config.classes has to be an array class names: string[], have: "+JSON.stringify(e.classes));if(!Array.isArray(e.anchors)||!e.anchors.length||!e.anchors.map(function(t){return t||{}}).every(function(t){return pu(t.x)&&pu(t.y)}))throw new Error("config.anchors has to be an array of { x: number, y: number }, have: "+JSON.stringify(e.anchors));if(e.meanRgb&&(!Array.isArray(e.meanRgb)||e.meanRgb.length!==3||!e.meanRgb.every(pu)))throw new Error("config.meanRgb has to be an array of shape [number, number, number], have: "+JSON.stringify(e.meanRgb))}function sh(e){return X(function(){var t=xt(e,K(.10000000149011612));return de(Me(Ze(e,t)),t)})}function mr(e,t){return X(function(){var n=wo(e,[[0,0],[1,1],[1,1],[0,0]]);return n=un(n,t.conv.filters,[1,1],"valid"),n=Ze(n,t.bn.sub),n=xt(n,t.bn.truediv),n=de(n,t.conv.bias),sh(n)})}function gr(e,t){return X(function(){var n=wo(e,[[0,0],[1,1],[1,1],[0,0]]);return n=Md(n,t.depthwise_filter,t.pointwise_filter,[1,1],"valid"),n=de(n,t.bias),sh(n)})}function jR(e,t){var n=Qs(e,t);function r(a,u){var s=Ge(e(a)),l=Ge(e(a));return t.push({paramPath:u+"/sub"},{paramPath:u+"/truediv"}),{sub:s,truediv:l}}function o(a,u,s){var l=n(a,u,3,s+"/conv"),c=r(u,s+"/bn");return{conv:l,bn:c}}var i=rh(e,t);return{extractConvParams:n,extractConvWithBatchNormParams:o,extractSeparableConvParams:i}}function GR(e,t,n,r){var o=hr(e),i=o.extractWeights,a=o.getRemainingWeights,u=[],s=jR(i,u),l=s.extractConvParams,c=s.extractConvWithBatchNormParams,f=s.extractSeparableConvParams,d;if(t.withSeparableConvs){var h=r[0],p=r[1],m=r[2],g=r[3],v=r[4],y=r[5],x=r[6],w=r[7],b=r[8],C=t.isFirstLayerConv2d?l(h,p,3,"conv0"):f(h,p,"conv0"),_=f(p,m,"conv1"),E=f(m,g,"conv2"),R=f(g,v,"conv3"),k=f(v,y,"conv4"),T=f(y,x,"conv5"),N=w?f(x,w,"conv6"):void 0,W=b?f(w,b,"conv7"):void 0,L=l(b||w||x,5*n,1,"conv8");d={conv0:C,conv1:_,conv2:E,conv3:R,conv4:k,conv5:T,conv6:N,conv7:W,conv8:L}}else{var h=r[0],p=r[1],m=r[2],g=r[3],v=r[4],y=r[5],x=r[6],w=r[7],b=r[8],C=c(h,p,"conv0"),_=c(p,m,"conv1"),E=c(m,g,"conv2"),R=c(g,v,"conv3"),k=c(v,y,"conv4"),T=c(y,x,"conv5"),N=c(x,w,"conv6"),W=c(w,b,"conv7"),L=l(b,5*n,1,"conv8");d={conv0:C,conv1:_,conv2:E,conv3:R,conv4:k,conv5:T,conv6:N,conv7:W,conv8:L}}if(a().length!==0)throw new Error("weights remaing after extract: "+a().length);return{params:d,paramMappings:u}}function qR(e,t){var n=Gr(e,t);function r(u){var s=n(u+"/sub",1),l=n(u+"/truediv",1);return{sub:s,truediv:l}}function o(u){var s=n(u+"/filters",4),l=n(u+"/bias",1);return{filters:s,bias:l}}function i(u){var s=o(u+"/conv"),l=r(u+"/bn");return{conv:s,bn:l}}var a=oh(n);return{extractConvParams:o,extractConvWithBatchNormParams:i,extractSeparableConvParams:a}}function KR(e,t){var n=[],r=qR(e,n),o=r.extractConvParams,i=r.extractConvWithBatchNormParams,a=r.extractSeparableConvParams,u;if(t.withSeparableConvs){var s=t.filterSizes&&t.filterSizes.length||9;u={conv0:t.isFirstLayerConv2d?o("conv0"):a("conv0"),conv1:a("conv1"),conv2:a("conv2"),conv3:a("conv3"),conv4:a("conv4"),conv5:a("conv5"),conv6:s>7?a("conv6"):void 0,conv7:s>8?a("conv7"):void 0,conv8:o("conv8")}}else u={conv0:i("conv0"),conv1:i("conv1"),conv2:i("conv2"),conv3:i("conv3"),conv4:i("conv4"),conv5:i("conv5"),conv6:i("conv6"),conv7:i("conv7"),conv8:o("conv8")};return dr(e,n),{params:u,paramMappings:n}}var Nv;(function(e){e[e.XS=224]="XS",e[e.SM=320]="SM",e[e.MD=416]="MD",e[e.LG=608]="LG"})(Nv||(Nv={}));var lh=function(){function e(t){var n=t===void 0?{}:t,r=n.inputSize,o=n.scoreThreshold;if(this._name="TinyYolov2Options",this._inputSize=r||416,this._scoreThreshold=o||.5,typeof this._inputSize!="number"||this._inputSize%32!==0)throw new Error(this._name+" - expected inputSize to be a number divisible by 32");if(typeof this._scoreThreshold!="number"||this._scoreThreshold<=0||this._scoreThreshold>=1)throw new Error(this._name+" - expected scoreThreshold to be a number between 0 and 1")}return Object.defineProperty(e.prototype,"inputSize",{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scoreThreshold",{get:function(){return this._scoreThreshold},enumerable:!0,configurable:!0}),e}(),n1=function(e){ue(t,e);function t(n){var r=e.call(this,"TinyYolov2")||this;return HR(n),r._config=n,r}return Object.defineProperty(t.prototype,"config",{get:function(){return this._config},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"withClassScores",{get:function(){return this.config.withClassScores||this.config.classes.length>1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"boxEncodingSize",{get:function(){return 5+(this.withClassScores?this.config.classes.length:0)},enumerable:!0,configurable:!0}),t.prototype.runTinyYolov2=function(n,r){var o=mr(n,r.conv0);return o=tt(o,[2,2],[2,2],"same"),o=mr(o,r.conv1),o=tt(o,[2,2],[2,2],"same"),o=mr(o,r.conv2),o=tt(o,[2,2],[2,2],"same"),o=mr(o,r.conv3),o=tt(o,[2,2],[2,2],"same"),o=mr(o,r.conv4),o=tt(o,[2,2],[2,2],"same"),o=mr(o,r.conv5),o=tt(o,[2,2],[1,1],"same"),o=mr(o,r.conv6),o=mr(o,r.conv7),yn(o,r.conv8,"valid",!1)},t.prototype.runMobilenet=function(n,r){var o=this.config.isFirstLayerConv2d?sh(yn(n,r.conv0,"valid",!1)):gr(n,r.conv0);return o=tt(o,[2,2],[2,2],"same"),o=gr(o,r.conv1),o=tt(o,[2,2],[2,2],"same"),o=gr(o,r.conv2),o=tt(o,[2,2],[2,2],"same"),o=gr(o,r.conv3),o=tt(o,[2,2],[2,2],"same"),o=gr(o,r.conv4),o=tt(o,[2,2],[2,2],"same"),o=gr(o,r.conv5),o=tt(o,[2,2],[1,1],"same"),o=r.conv6?gr(o,r.conv6):o,o=r.conv7?gr(o,r.conv7):o,yn(o,r.conv8,"valid",!1)},t.prototype.forwardInput=function(n,r){var o=this,i=this.params;if(!i)throw new Error("TinyYolov2 - load model before inference");return X(function(){var a=n.toBatchTensor(r,!1).toFloat();return a=o.config.meanRgb?Ba(a,o.config.meanRgb):a,a=a.div(K(256)),o.config.withSeparableConvs?o.runMobilenet(a,i):o.runTinyYolov2(a,i)})},t.prototype.forward=function(n,r){return te(this,void 0,void 0,function(){var o;return ne(this,function(i){switch(i.label){case 0:return o=this.forwardInput,[4,it(n)];case 1:return[4,o.apply(this,[i.sent(),r])];case 2:return[2,i.sent()]}})})},t.prototype.detect=function(n,r){return r===void 0&&(r={}),te(this,void 0,void 0,function(){var o,i,a,u,s,l,c,f,d,h,p,m,g,v,y=this;return ne(this,function(x){switch(x.label){case 0:return o=new lh(r),i=o.inputSize,a=o.scoreThreshold,[4,it(n)];case 1:return u=x.sent(),[4,this.forwardInput(u,i)];case 2:return s=x.sent(),l=X(function(){return Qe(s)[0].expandDims()}),c={width:u.getInputWidth(0),height:u.getInputHeight(0)},[4,this.extractBoxes(l,u.getReshapedInputDimensions(0),a)];case 3:return f=x.sent(),s.dispose(),l.dispose(),d=f.map(function(w){return w.box}),h=f.map(function(w){return w.score}),p=f.map(function(w){return w.classScore}),m=f.map(function(w){return y.config.classes[w.label]}),g=ba(d.map(function(w){return w.rescale(i)}),h,this.config.iouThreshold,!0),v=g.map(function(w){return new Ry(h[w],p[w],m[w],d[w],c)}),[2,v]}})})},t.prototype.getDefaultModelName=function(){return""},t.prototype.extractParamsFromWeigthMap=function(n){return KR(n,this.config)},t.prototype.extractParams=function(n){var r=this.config.filterSizes||t.DEFAULT_FILTER_SIZES,o=r?r.length:void 0;if(o!==7&&o!==8&&o!==9)throw new Error("TinyYolov2 - expected 7 | 8 | 9 convolutional filters, but found "+o+" filterSizes in config");return GR(n,this.config,this.boxEncodingSize,r)},t.prototype.extractBoxes=function(n,r,o){return te(this,void 0,void 0,function(){var i,a,u,s,l,c,f,d,h,p,m,g,v,y,x,w,b,C,_,E,R,k,T,N,W,L,U,$,V,P=this;return ne(this,function(M){switch(M.label){case 0:return i=r.width,a=r.height,u=Math.max(i,a),s=u/i,l=u/a,c=n.shape[1],f=this.config.anchors.length,d=X(function(){var B=n.reshape([c,c,f,P.boxEncodingSize]),G=B.slice([0,0,0,0],[c,c,f,4]),q=B.slice([0,0,0,4],[c,c,f,1]),re=P.withClassScores?lr(B.slice([0,0,0,5],[c,c,f,P.config.classes.length]),3):K(0);return[G,q,re]}),h=d[0],p=d[1],m=d[2],g=[],[4,p.array()];case 1:return v=M.sent(),[4,h.array()];case 2:y=M.sent(),x=0,M.label=3;case 3:if(!(xo?(_=(w+nc(y[x][w][b][0]))/c*s,E=(x+nc(y[x][w][b][1]))/c*l,R=Math.exp(y[x][w][b][2])*this.config.anchors[b].x/c*s,k=Math.exp(y[x][w][b][3])*this.config.anchors[b].y/c*l,T=_-R/2,N=E-k/2,W={row:x,col:w,anchor:b},this.withClassScores?[4,this.extractPredictedClass(m,W)]:[3,7]):[3,9]):[3,10];case 6:return V=M.sent(),[3,8];case 7:V={classScore:1,label:0},M.label=8;case 8:L=V,U=L.classScore,$=L.label,g.push(mt({box:new Xs(T,N,T+R,N+k),score:C,classScore:C*U,label:$},W)),M.label=9;case 9:return b++,[3,5];case 10:return w++,[3,4];case 11:return x++,[3,3];case 12:return h.dispose(),p.dispose(),m.dispose(),[2,g]}})})},t.prototype.extractPredictedClass=function(n,r){return te(this,void 0,void 0,function(){var o,i,a,u;return ne(this,function(s){switch(s.label){case 0:return o=r.row,i=r.col,a=r.anchor,[4,n.array()];case 1:return u=s.sent(),[2,Array(this.config.classes.length).fill(0).map(function(l,c){return u[o][i][a][c]}).map(function(l,c){return{classScore:l,label:c}}).reduce(function(l,c){return l.classScore>c.classScore?l:c})]}})})},t.DEFAULT_FILTER_SIZES=[3,16,32,64,128,256,512,1024,1024],t}(fr),XR=function(e){ue(t,e);function t(n){n===void 0&&(n=!0);var r=this,o=Object.assign({},{withSeparableConvs:n,iouThreshold:LR,classes:["face"]},n?{anchors:zR,meanRgb:UR}:{anchors:WR,withClassScores:!0});return r=e.call(this,o)||this,r}return 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(n,r){return te(this,void 0,void 0,function(){var o;return ne(this,function(i){switch(i.label){case 0:return[4,this.detect(n,r)];case 1:return o=i.sent(),[2,o.map(function(a){return new Kt(a.score,a.relativeBox,{width:a.imageWidth,height:a.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return this.withSeparableConvs?$R:VR},t.prototype.extractParamsFromWeigthMap=function(n){return e.prototype.extractParamsFromWeigthMap.call(this,n)},t}(n1),r1=function(e){ue(t,e);function t(){var n=e!==null&&e.apply(this,arguments)||this;return n._name="TinyFaceDetectorOptions",n}return t}(lh),La=function(){function e(){}return e.prototype.then=function(t){return te(this,void 0,void 0,function(){var n;return ne(this,function(r){switch(r.label){case 0:return n=t,[4,this.run()];case 1:return[2,n.apply(void 0,[r.sent()])]}})})},e.prototype.run=function(){return te(this,void 0,void 0,function(){return ne(this,function(t){throw new Error("ComposableTask - run is not implemented")})})},e}();function el(e,t,n,r,o){return o===void 0&&(o=function(i){var a=i.alignedRect;return a}),te(this,void 0,void 0,function(){var i,a,u,s,l;return ne(this,function(c){switch(c.label){case 0:return i=e.map(function(f){return ah(f)?o(f):f.detection}),u=r,u?[3,5]:t instanceof Fe?[4,th(t,i)]:[3,2];case 1:return s=c.sent(),[3,4];case 2:return[4,eh(t,i)];case 3:s=c.sent(),c.label=4;case 4:u=s,c.label=5;case 5:return a=u,[4,n(a)];case 6:return l=c.sent(),a.forEach(function(f){return f instanceof Fe&&f.dispose()}),[2,l]}})})}function ch(e,t,n,r,o){return te(this,void 0,void 0,function(){var i=this;return ne(this,function(a){return[2,el([e],t,function(u){return te(i,void 0,void 0,function(){return ne(this,function(s){return[2,n(u[0])]})})},r,o)]})})}function YR(e){return X(function(){return Gt(Qe(e,3).reverse(),3)})}var vu=2,bs=12;function QR(e,t){var n=Qs(e,t),r=nh(e,t);function o(l,c){var f=Ge(e(l));return t.push({paramPath:c}),f}function i(l,c,f){f===void 0&&(f=!1);var d=n(l[0],l[1],3,c+"/conv1"),h=o(l[1],c+"/prelu1_alpha"),p=n(l[1],l[2],3,c+"/conv2"),m=o(l[2],c+"/prelu2_alpha"),g=n(l[2],l[3],f?2:3,c+"/conv3"),v=o(l[3],c+"/prelu3_alpha");return{conv1:d,prelu1_alpha:h,conv2:p,prelu2_alpha:m,conv3:g,prelu3_alpha:v}}function a(){var l=i([3,10,16,32],"pnet"),c=n(32,2,1,"pnet/conv4_1"),f=n(32,4,1,"pnet/conv4_2");return mt(mt({},l),{conv4_1:c,conv4_2:f})}function u(){var l=i([3,28,48,64],"rnet",!0),c=r(576,128,"rnet/fc1"),f=o(128,"rnet/prelu4_alpha"),d=r(128,2,"rnet/fc2_1"),h=r(128,4,"rnet/fc2_2");return mt(mt({},l),{fc1:c,prelu4_alpha:f,fc2_1:d,fc2_2:h})}function s(){var l=i([3,32,64,64],"onet"),c=n(64,128,2,"onet/conv4"),f=o(128,"onet/prelu4_alpha"),d=r(1152,256,"onet/fc1"),h=o(256,"onet/prelu5_alpha"),p=r(256,2,"onet/fc2_1"),m=r(256,4,"onet/fc2_2"),g=r(256,10,"onet/fc2_3");return mt(mt({},l),{conv4:c,prelu4_alpha:f,fc1:d,prelu5_alpha:h,fc2_1:p,fc2_2:m,fc2_3:g})}return{extractPNetParams:a,extractRNetParams:u,extractONetParams:s}}function JR(e){var t=hr(e),n=t.extractWeights,r=t.getRemainingWeights,o=[],i=QR(n,o),a=i.extractPNetParams,u=i.extractRNetParams,s=i.extractONetParams,l=a(),c=u(),f=s();if(r().length!==0)throw new Error("weights remaing after extract: "+r().length);return{params:{pnet:l,rnet:c,onet:f},paramMappings:o}}function ZR(e,t){var n=Gr(e,t);function r(c){var f=n(c+"/weights",4,c+"/filters"),d=n(c+"/bias",1);return{filters:f,bias:d}}function o(c){var f=n(c+"/weights",2),d=n(c+"/bias",1);return{weights:f,bias:d}}function i(c){return n(c,1)}function a(c){var f=r(c+"/conv1"),d=i(c+"/prelu1_alpha"),h=r(c+"/conv2"),p=i(c+"/prelu2_alpha"),m=r(c+"/conv3"),g=i(c+"/prelu3_alpha");return{conv1:f,prelu1_alpha:d,conv2:h,prelu2_alpha:p,conv3:m,prelu3_alpha:g}}function u(){var c=a("pnet"),f=r("pnet/conv4_1"),d=r("pnet/conv4_2");return mt(mt({},c),{conv4_1:f,conv4_2:d})}function s(){var c=a("rnet"),f=o("rnet/fc1"),d=i("rnet/prelu4_alpha"),h=o("rnet/fc2_1"),p=o("rnet/fc2_2");return mt(mt({},c),{fc1:f,prelu4_alpha:d,fc2_1:h,fc2_2:p})}function l(){var c=a("onet"),f=r("onet/conv4"),d=i("onet/prelu4_alpha"),h=o("onet/fc1"),p=i("onet/prelu5_alpha"),m=o("onet/fc2_1"),g=o("onet/fc2_2"),v=o("onet/fc2_3");return mt(mt({},c),{conv4:f,prelu4_alpha:d,fc1:h,prelu5_alpha:p,fc2_1:m,fc2_2:g,fc2_3:v})}return{extractPNetParams:u,extractRNetParams:s,extractONetParams:l}}function eI(e){var t=[],n=ZR(e,t),r=n.extractPNetParams,o=n.extractRNetParams,i=n.extractONetParams,a=r(),u=o(),s=i();return dr(e,t),{params:{pnet:a,rnet:u,onet:s},paramMappings:t}}function Cf(e,t){var n=t[0],r=t[1];return{height:Math.floor(n*e),width:Math.floor(r*e)}}function tI(e,t,n){for(var r=n[0],o=n[1],i=bs/e,a=[],u=Math.min(r,o)*i,s=0;u>=12;)a.push(i*Math.pow(t,s)),u=u*t,s+=1;return a}var fh=function(e){ue(t,e);function t(n,r,o,i){return e.call(this,{left:n,top:r,right:o,bottom:i},!0)||this}return t}(zn);function o1(e){return X(function(){return xt(Ze(e,K(127.5)),K(.0078125))})}function ai(e,t){return X(function(){return de(Me(e),xt(t,vs(Me(vs(e)))))})}function dh(e,t,n){return n===void 0&&(n=!1),X(function(){var r=yn(e,t.conv1,"valid");return r=ai(r,t.prelu1_alpha),r=tt(r,n?[2,2]:[3,3],[2,2],"same"),r=yn(r,t.conv2,"valid"),r=ai(r,t.prelu2_alpha),r=n?r:tt(r,[3,3],[2,2],"valid"),r=yn(r,t.conv3,"valid"),r=ai(r,t.prelu3_alpha),r})}function nI(e,t){return X(function(){var n=dh(e,t,!0),r=yn(n,t.conv4_1,"valid"),o=Zt(js(r,3),3),i=lr(Ze(r,o),3),a=yn(n,t.conv4_2,"valid");return{prob:i,regions:a}})}function rI(e,t){return X(function(){var n=Cf(t,e.shape.slice(1)),r=n.height,o=n.width,i=zd.resizeBilinear(e,[r,o]),a=o1(i);return zr(a,[0,2,1,3])})}function oI(e,t,n,r){for(var o=[],i=e.arraySync(),a=0;a=r&&o.push(new we(u,a));var s=o.map(function(l){var c=new Xs(Math.round((l.y*vu+1)/n),Math.round((l.x*vu+1)/n),Math.round((l.y*vu+bs)/n),Math.round((l.x*vu+bs)/n)),f=i[l.y][l.x],d=t.arraySync(),h=new fh(d[l.y][l.x][0],d[l.y][l.x][1],d[l.y][l.x][2],d[l.y][l.x][3]);return{cell:c,score:f,region:h}});return s}function iI(e,t,n,r,o){o.stage1=[];var i=t.map(function(d){return X(function(){var h={scale:d},p=rI(e,d),m=Date.now(),g=nI(p,r),v=g.prob,y=g.regions;h.pnet=Date.now()-m;var x=Qe(Qe(v,3)[1])[0],w=Qe(y)[0];return{scoresTensor:x,regionsTensor:w,scale:d,statsForScale:h}})}),a=i.map(function(d){var h=d.scoresTensor,p=d.regionsTensor,m=d.scale,g=d.statsForScale,v=oI(h,p,m,n);if(h.dispose(),p.dispose(),!v.length)return o.stage1.push(g),[];var y=Date.now(),x=ba(v.map(function(w){return w.cell}),v.map(function(w){return w.score}),.5);return g.nms=Date.now()-y,g.numBoxes=x.length,o.stage1.push(g),x.map(function(w){return v[w]})}),u=a.reduce(function(d,h){return d.concat(h)},[]),s=[],l=[];if(u.length>0){var c=Date.now(),f=ba(u.map(function(d){return d.cell}),u.map(function(d){return d.score}),.7);o.stage1_nms=Date.now()-c,l=f.map(function(d){return u[d].score}),s=f.map(function(d){return u[d]}).map(function(d){var h=d.cell,p=d.region;return new Xs(h.left+p.left*h.width,h.top+p.top*h.height,h.right+p.right*h.width,h.bottom+p.bottom*h.height).toSquare().round()})}return{boxes:s,scores:l}}function i1(e,t,n){var r=n.width,o=n.height;return te(this,void 0,void 0,function(){var i,a,u,s=this;return ne(this,function(l){switch(l.label){case 0:return i=Un(e),[4,Promise.all(t.map(function(c){return te(s,void 0,void 0,function(){var f,d,h,p,m,g,v,y;return ne(this,function(x){return f=c.padAtBorders(e.height,e.width),d=f.y,h=f.ey,p=f.x,m=f.ex,g=p-1,v=d-1,y=i.getImageData(g,v,m-g,h-v),[2,Ct.isNodejs()?Zd(y):createImageBitmap(y)]})})}))];case 1:return a=l.sent(),u=[],a.forEach(function(c){var f=Ys({width:r,height:o}),d=Un(f);d.drawImage(c,0,0,r,o);for(var h=d.getImageData(0,0,r,o).data,p=[],m=0;m1?Ye(u.map(function(w){return w.scores})):u[0].scores,f=(c=Array).from,[4,s.data()];case 2:return l=f.apply(c,[x.sent()]),s.dispose(),d=l.map(function(w,b){return{score:w,idx:b}}).filter(function(w){return w.score>n}).map(function(w){var b=w.idx;return b}),h=d.map(function(w){return t[w]}),p=d.map(function(w){return l[w]}),m=[],g=[],h.length>0&&(i=Date.now(),v=ba(h,p,.7),o.stage2_nms=Date.now()-i,y=v.map(function(w){var b=u[d[w]].regions.arraySync();return new fh(b[0][0],b[0][1],b[0][2],b[0][3])}),g=v.map(function(w){return p[w]}),m=v.map(function(w,b){return h[w].calibrate(y[b])})),u.forEach(function(w){w.regions.dispose(),w.scores.dispose()}),[2,{boxes:m,scores:g}]}})})}function sI(e,t){return X(function(){var n=dh(e,t);n=tt(n,[2,2],[2,2],"same"),n=yn(n,t.conv4,"valid"),n=ai(n,t.prelu4_alpha);var r=vn(n,[n.shape[0],t.fc1.weights.shape[0]]),o=Pn(r,t.fc1),i=ai(o,t.prelu5_alpha),a=Pn(i,t.fc2_1),u=Zt(js(a,1),1),s=lr(Ze(a,u),1),l=Pn(i,t.fc2_2),c=Pn(i,t.fc2_3),f=Qe(s,1)[1];return{scores:f,regions:l,points:c}})}function lI(e,t,n,r,o){return te(this,void 0,void 0,function(){var i,a,u,s,l,c,f,d,h,p,m,g,v,y,x;return ne(this,function(w){switch(w.label){case 0:return i=Date.now(),[4,i1(e,t,{width:48,height:48})];case 1:return a=w.sent(),o.stage3_extractImagePatches=Date.now()-i,i=Date.now(),u=a.map(function(b){var C=sI(b,r);return b.dispose(),C}),o.stage3_onet=Date.now()-i,s=u.length>1?Ye(u.map(function(b){return b.scores})):u[0].scores,f=(c=Array).from,[4,s.data()];case 2:return l=f.apply(c,[w.sent()]),s.dispose(),d=l.map(function(b,C){return{score:b,idx:C}}).filter(function(b){return b.score>n}).map(function(b){var C=b.idx;return C}),h=d.map(function(b){var C=u[b].regions.arraySync();return new fh(C[0][0],C[0][1],C[0][2],C[0][3])}),p=d.map(function(b,C){return t[b].calibrate(h[C])}),m=d.map(function(b){return l[b]}),g=[],v=[],y=[],p.length>0&&(i=Date.now(),x=ba(p,m,.7,!1),o.stage3_nms=Date.now()-i,g=x.map(function(b){return p[b]}),v=x.map(function(b){return m[b]}),y=x.map(function(b,C){return Array(5).fill(0).map(function(_,E){var R=u[b].points.arraySync();return new we(R[0][E]*(g[C].width+1)+g[C].left,R[0][E+5]*(g[C].height+1)+g[C].top)})})),u.forEach(function(b){b.regions.dispose(),b.scores.dispose(),b.points.dispose()}),[2,{boxes:g,scores:v,points:y}]}})})}var cI=function(e){ue(t,e);function t(){return e.call(this,"Mtcnn")||this}return t.prototype.load=function(n){return te(this,void 0,void 0,function(){return ne(this,function(r){return console.warn("mtcnn is deprecated and will be removed soon"),[2,e.prototype.load.call(this,n)]})})},t.prototype.loadFromDisk=function(n){return te(this,void 0,void 0,function(){return ne(this,function(r){return console.warn("mtcnn is deprecated and will be removed soon"),[2,e.prototype.loadFromDisk.call(this,n)]})})},t.prototype.forwardInput=function(n,r){return r===void 0&&(r={}),te(this,void 0,void 0,function(){var o,i,a,u,s,l,c,f,d,h,p,m,g,v,y,x,w,b,C,_,E;return ne(this,function(R){switch(R.label){case 0:if(o=this.params,!o)throw new Error("Mtcnn - load model before inference");if(i=n.canvases[0],!i)throw new Error("Mtcnn - inputCanvas is not defined, note that passing tensors into Mtcnn.forwardInput is not supported yet.");return a={},u=Date.now(),s=X(function(){return YR(Zt(Gd.fromPixels(i)).toFloat())}),l=function(k){return s.dispose(),a.total=Date.now()-u,k},c=s.shape.slice(1),f=c[0],d=c[1],h=new e1(r),p=h.minFaceSize,m=h.scaleFactor,g=h.maxNumScales,v=h.scoreThresholds,y=h.scaleSteps,x=(y||tI(p,m,[f,d])).filter(function(k){var T=Cf(k,[f,d]);return Math.min(T.width,T.height)>bs}).slice(0,g),a.scales=x,a.pyramid=x.map(function(k){return Cf(k,[f,d])}),w=Date.now(),[4,iI(s,x,v[0],o.pnet,a)];case 1:return b=R.sent(),a.total_stage1=Date.now()-w,b.boxes.length?(a.stage2_numInputBoxes=b.boxes.length,w=Date.now(),[4,uI(i,b.boxes,v[1],o.rnet,a)]):[2,l({results:[],stats:a})];case 2:return C=R.sent(),a.total_stage2=Date.now()-w,C.boxes.length?(a.stage3_numInputBoxes=C.boxes.length,w=Date.now(),[4,lI(i,C.boxes,v[2],o.onet,a)]):[2,l({results:[],stats:a})];case 3:return _=R.sent(),a.total_stage3=Date.now()-w,E=_.boxes.map(function(k,T){return Js(_a({},new Kt(_.scores[T],new Xd(k.left/d,k.top/f,k.width/d,k.height/f),{height:f,width:d})),new Mk(_.points[T].map(function(N){return N.sub(new we(k.left,k.top)).div(new we(k.width,k.height))}),{width:k.width,height:k.height}))}),[2,l({results:E,stats:a})]}})})},t.prototype.forward=function(n,r){return r===void 0&&(r={}),te(this,void 0,void 0,function(){var o;return ne(this,function(i){switch(i.label){case 0:return o=this.forwardInput,[4,it(n)];case 1:return[4,o.apply(this,[i.sent(),r])];case 2:return[2,i.sent().results]}})})},t.prototype.forwardWithStats=function(n,r){return r===void 0&&(r={}),te(this,void 0,void 0,function(){var o;return ne(this,function(i){switch(i.label){case 0:return o=this.forwardInput,[4,it(n)];case 1:return[2,o.apply(this,[i.sent(),r])]}})})},t.prototype.getDefaultModelName=function(){return"mtcnn_model"},t.prototype.extractParamsFromWeigthMap=function(n){return eI(n)},t.prototype.extractParams=function(n){return JR(n)},t}(fr),fI=.4,dI=[new we(1.603231,2.094468),new we(6.041143,7.080126),new we(2.882459,3.518061),new we(4.266906,5.178857),new we(9.041765,10.66308)],hI=[117.001,114.697,97.404],pI=function(e){ue(t,e);function t(){var n=this,r={withSeparableConvs:!0,iouThreshold:fI,classes:["face"],anchors:dI,meanRgb:hI,isFirstLayerConv2d:!0,filterSizes:[3,16,32,64,128,256,512]};return n=e.call(this,r)||this,n}return Object.defineProperty(t.prototype,"anchors",{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),t.prototype.locateFaces=function(n,r){return te(this,void 0,void 0,function(){var o;return ne(this,function(i){switch(i.label){case 0:return[4,this.detect(n,r)];case 1:return o=i.sent(),[2,o.map(function(a){return new Kt(a.score,a.relativeBox,{width:a.imageWidth,height:a.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return"tiny_face_detector_model"},t.prototype.extractParamsFromWeigthMap=function(n){return e.prototype.extractParamsFromWeigthMap.call(this,n)},t}(n1),wt={ssdMobilenetv1:new t1,tinyFaceDetector:new pI,tinyYolov2:new XR,mtcnn:new cI,faceLandmark68Net:new Ky,faceLandmark68TinyNet:new mR,faceRecognitionNet:new _R,faceExpressionNet:new Jk,ageGenderNet:new dR},a1=function(e){ue(t,e);function t(n,r,o){var i=e.call(this)||this;return i.parentTask=n,i.input=r,i.extractedFaces=o,i}return t}(La),hh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r,o=this;return ne(this,function(i){switch(i.label){case 0:return[4,this.parentTask];case 1:return n=i.sent(),[4,el(n,this.input,function(a){return te(o,void 0,void 0,function(){return ne(this,function(u){switch(u.label){case 0:return[4,Promise.all(a.map(function(s){return wt.faceExpressionNet.predictExpressions(s)}))];case 1:return[2,u.sent()]}})})},this.extractedFaces)];case 2:return r=i.sent(),[2,n.map(function(a,u){return jy(a,r[u])})]}})})},t.prototype.withAgeAndGender=function(){return new gh(this,this.input)},t}(a1),ph=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r;return ne(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return n=o.sent(),n?[4,ch(n,this.input,function(i){return wt.faceExpressionNet.predictExpressions(i)},this.extractedFaces)]:[2];case 2:return r=o.sent(),[2,jy(n,r)]}})})},t.prototype.withAgeAndGender=function(){return new yh(this,this.input)},t}(a1),vh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new xh(this,this.input)},t.prototype.withFaceDescriptors=function(){return new bh(this,this.input)},t}(hh),mh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new wh(this,this.input)},t.prototype.withFaceDescriptor=function(){return new Ch(this,this.input)},t}(ph),u1=function(e){ue(t,e);function t(n,r,o){var i=e.call(this)||this;return i.parentTask=n,i.input=r,i.extractedFaces=o,i}return t}(La),gh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r,o=this;return ne(this,function(i){switch(i.label){case 0:return[4,this.parentTask];case 1:return n=i.sent(),[4,el(n,this.input,function(a){return te(o,void 0,void 0,function(){return ne(this,function(u){switch(u.label){case 0:return[4,Promise.all(a.map(function(s){return wt.ageGenderNet.predictAgeAndGender(s)}))];case 1:return[2,u.sent()]}})})},this.extractedFaces)];case 2:return r=i.sent(),[2,n.map(function(a,u){var s=r[u],l=s.age,c=s.gender,f=s.genderProbability;return Jy(Zy(a,c,f),l)})]}})})},t.prototype.withFaceExpressions=function(){return new hh(this,this.input)},t}(u1),yh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r,o,i,a;return ne(this,function(u){switch(u.label){case 0:return[4,this.parentTask];case 1:return n=u.sent(),n?[4,ch(n,this.input,function(s){return wt.ageGenderNet.predictAgeAndGender(s)},this.extractedFaces)]:[2];case 2:return r=u.sent(),o=r.age,i=r.gender,a=r.genderProbability,[2,Jy(Zy(n,i,a),o)]}})})},t.prototype.withFaceExpressions=function(){return new ph(this,this.input)},t}(u1),xh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new vh(this,this.input)},t.prototype.withFaceDescriptors=function(){return new bh(this,this.input)},t}(gh),wh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new mh(this,this.input)},t.prototype.withFaceDescriptor=function(){return new Ch(this,this.input)},t}(yh),s1=function(e){ue(t,e);function t(n,r){var o=e.call(this)||this;return o.parentTask=n,o.input=r,o}return t}(La),bh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r;return ne(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return n=o.sent(),[4,el(n,this.input,function(i){return Promise.all(i.map(function(a){return wt.faceRecognitionNet.computeFaceDescriptor(a)}))},null,function(i){return i.landmarks.align(null,{useDlibAlignment:!0})})];case 2:return r=o.sent(),[2,r.map(function(i,a){return Qy(n[a],i)})]}})})},t.prototype.withFaceExpressions=function(){return new vh(this,this.input)},t.prototype.withAgeAndGender=function(){return new xh(this,this.input)},t}(s1),Ch=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r;return ne(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return n=o.sent(),n?[4,ch(n,this.input,function(i){return wt.faceRecognitionNet.computeFaceDescriptor(i)},null,function(i){return i.landmarks.align(null,{useDlibAlignment:!0})})]:[2];case 2:return r=o.sent(),[2,Qy(n,r)]}})})},t.prototype.withFaceExpressions=function(){return new mh(this,this.input)},t.prototype.withAgeAndGender=function(){return new wh(this,this.input)},t}(s1),l1=function(e){ue(t,e);function t(n,r,o){var i=e.call(this)||this;return i.parentTask=n,i.input=r,i.useTinyLandmarkNet=o,i}return Object.defineProperty(t.prototype,"landmarkNet",{get:function(){return this.useTinyLandmarkNet?wt.faceLandmark68TinyNet:wt.faceLandmark68Net},enumerable:!0,configurable:!0}),t}(La),vI=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r,o,i,a,u=this;return ne(this,function(s){switch(s.label){case 0:return[4,this.parentTask];case 1:return n=s.sent(),r=n.map(function(l){return l.detection}),this.input instanceof Fe?[4,th(this.input,r)]:[3,3];case 2:return i=s.sent(),[3,5];case 3:return[4,eh(this.input,r)];case 4:i=s.sent(),s.label=5;case 5:return o=i,[4,Promise.all(o.map(function(l){return u.landmarkNet.detectLandmarks(l)}))];case 6:return a=s.sent(),o.forEach(function(l){return l instanceof Fe&&l.dispose()}),[2,n.map(function(l,c){return Js(l,a[c])})]}})})},t.prototype.withFaceExpressions=function(){return new vh(this,this.input)},t.prototype.withAgeAndGender=function(){return new xh(this,this.input)},t.prototype.withFaceDescriptors=function(){return new bh(this,this.input)},t}(l1),mI=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r,o,i,a;return ne(this,function(u){switch(u.label){case 0:return[4,this.parentTask];case 1:return n=u.sent(),n?(r=n.detection,this.input instanceof Fe?[4,th(this.input,[r])]:[3,3]):[2];case 2:return i=u.sent(),[3,5];case 3:return[4,eh(this.input,[r])];case 4:i=u.sent(),u.label=5;case 5:return o=i,[4,this.landmarkNet.detectLandmarks(o[0])];case 6:return a=u.sent(),o.forEach(function(s){return s instanceof Fe&&s.dispose()}),[2,Js(n,a)]}})})},t.prototype.withFaceExpressions=function(){return new mh(this,this.input)},t.prototype.withAgeAndGender=function(){return new wh(this,this.input)},t.prototype.withFaceDescriptor=function(){return new Ch(this,this.input)},t}(l1),c1=function(e){ue(t,e);function t(n,r){r===void 0&&(r=new Zs);var o=e.call(this)||this;return o.input=n,o.options=r,o}return t}(La),gI=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r,o,i;return ne(this,function(a){switch(a.label){case 0:return n=this,r=n.input,o=n.options,o instanceof e1?[4,wt.mtcnn.forward(r,o)]:[3,2];case 1:return[2,a.sent().map(function(u){return u.detection})];case 2:if(i=o instanceof r1?function(u){return wt.tinyFaceDetector.locateFaces(u,o)}:o instanceof Zs?function(u){return wt.ssdMobilenetv1.locateFaces(u,o)}:o instanceof lh?function(u){return wt.tinyYolov2.locateFaces(u,o)}:null,!i)throw new Error("detectFaces - expected options to be instance of TinyFaceDetectorOptions | SsdMobilenetv1Options | MtcnnOptions | TinyYolov2Options");return[2,i(r)]}})})},t.prototype.runAndExtendWithFaceDetections=function(){var n=this;return new Promise(function(r){return te(n,void 0,void 0,function(){var o;return ne(this,function(i){switch(i.label){case 0:return[4,this.run()];case 1:return o=i.sent(),[2,r(o.map(function(a){return _a({},a)}))]}})})})},t.prototype.withFaceLandmarks=function(n){return n===void 0&&(n=!1),new vI(this.runAndExtendWithFaceDetections(),this.input,n)},t.prototype.withFaceExpressions=function(){return new hh(this.runAndExtendWithFaceDetections(),this.input)},t.prototype.withAgeAndGender=function(){return new gh(this.runAndExtendWithFaceDetections(),this.input)},t}(c1),yI=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r;return ne(this,function(o){switch(o.label){case 0:return[4,new gI(this.input,this.options)];case 1:return n=o.sent(),r=n[0],n.forEach(function(i){i.score>r.score&&(r=i)}),[2,r]}})})},t.prototype.runAndExtendWithFaceDetection=function(){var n=this;return new Promise(function(r){return te(n,void 0,void 0,function(){var o;return ne(this,function(i){switch(i.label){case 0:return[4,this.run()];case 1:return o=i.sent(),[2,r(o?_a({},o):void 0)]}})})})},t.prototype.withFaceLandmarks=function(n){return n===void 0&&(n=!1),new mI(this.runAndExtendWithFaceDetection(),this.input,n)},t.prototype.withFaceExpressions=function(){return new ph(this.runAndExtendWithFaceDetection(),this.input)},t.prototype.withAgeAndGender=function(){return new yh(this.runAndExtendWithFaceDetection(),this.input)},t}(c1);function xI(e,t){return t===void 0&&(t=new Zs),new yI(e,t)}function wI(e,t){if(e.length!==t.length)throw new Error("euclideanDistance: arr1.length !== arr2.length");var n=Array.from(e),r=Array.from(t);return Math.sqrt(n.map(function(o,i){return o-r[i]}).reduce(function(o,i){return o+Math.pow(i,2)},0))}(function(){function e(t,n){n===void 0&&(n=.6),this._distanceThreshold=n;var r=Array.isArray(t)?t:[t];if(!r.length)throw new Error("FaceRecognizer.constructor - expected atleast one input");var o=1,i=function(){return"person "+o++};this._labeledDescriptors=r.map(function(a){if(a instanceof fu)return a;if(a instanceof Float32Array)return new fu(i(),[a]);if(a.descriptor&&a.descriptor instanceof Float32Array)return new fu(i(),[a.descriptor]);throw new Error("FaceRecognizer.constructor - expected inputs to be of type LabeledFaceDescriptors | WithFaceDescriptor | Float32Array | Array | Float32Array>")})}return Object.defineProperty(e.prototype,"labeledDescriptors",{get:function(){return this._labeledDescriptors},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"distanceThreshold",{get:function(){return this._distanceThreshold},enumerable:!0,configurable:!0}),e.prototype.computeMeanDistance=function(t,n){return n.map(function(r){return wI(r,t)}).reduce(function(r,o){return r+o},0)/(n.length||1)},e.prototype.matchDescriptor=function(t){var n=this;return this.labeledDescriptors.map(function(r){var o=r.descriptors,i=r.label;return new Rv(i,n.computeMeanDistance(t,o))}).reduce(function(r,o){return r.distance{ln[t]=!ln[t]});qr(this,"loadModels",async()=>{await Promise.all([wt.tinyFaceDetector.loadFromUri(mu),wt.faceLandmark68Net.loadFromUri(mu),wt.faceRecognitionNet.loadFromUri(mu),wt.faceExpressionNet.loadFromUri(mu)])});qr(this,"play",()=>{const{video:t,canvas:n}=this.elements;!t||!n||(qk(n,this.display.size),setInterval(async()=>{const r=await xI(t,new r1).withFaceLandmarks().withFaceExpressions();if(!r)return;const o=n.getContext("2d"),i=f1(r,this.display.size);if(!o||!i)return{};o.clearRect(0,0,n.width,n.height),ln!=null&&ln.detectionBox&&zk(n,i),ln!=null&&ln.faceLandmark&&rR(n,i),ln!=null&&ln.expressions&&eR(n,i)},100))});qr(this,"init",async()=>{try{const{video:t,canvas:n}=this.elements;if(!t||!n)return;await this.loadModels(),this.play()}catch(t){console.log("### error",t)}});if(!t||!n)throw new Error("configuração inválida");this.elements=t,this.display=n}}const ic={width:600,height:600,facingMode:"user"};function CI(){const[e,t]=Jn.useState([]),n=Jn.useRef(null),r=Jn.useRef(null),o=Jn.useRef(null),i=a=>t(u=>{const s=[...u];return s.includes(a)?s.filter(l=>l!==a):[...u,a]});return Jn.useEffect(()=>{var a;o.current=new bI({elements:{video:((a=n.current)==null?void 0:a.video)??null,canvas:r.current},display:{size:{...ic}}}),o.current.init().then()},[]),cn.jsxs("div",{className:"container",children:[cn.jsxs("div",{className:"display-wrapper",children:[cn.jsx(qw,{id:"webcam",ref:n,autoPlay:!0,audio:!1,screenshotFormat:"image/jpeg",videoConstraints:ic}),cn.jsx("canvas",{ref:r,id:"overlay",className:e.join(" "),style:{...ic}})]}),cn.jsxs("div",{className:"options-wrapper",children:[cn.jsx("button",{onClick:()=>i("show-background"),children:"Mostrar background do canvas"}),cn.jsx("button",{onClick:()=>{var a;return(a=o.current)==null?void 0:a.switchShowConfigByKey("detectionBox")},children:"Mostrar caixa de detecção"}),cn.jsx("button",{onClick:()=>{var a;return(a=o.current)==null?void 0:a.switchShowConfigByKey("faceLandmark")},children:"Mostrar linhas do rosto"}),cn.jsx("button",{onClick:()=>{var a;return(a=o.current)==null?void 0:a.switchShowConfigByKey("expressions")},children:"Mostrar expressões"})]})]})}ac.createRoot(document.getElementById("root")).render(cn.jsx(M1.StrictMode,{children:cn.jsx(CI,{})}))});export default _I(); +***************************************************************************** */var wf=function(e,t){return wf=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var o in r)r.hasOwnProperty(o)&&(n[o]=r[o])},wf(e,t)};function ue(e,t){wf(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}var mt=function(){return mt=Object.assign||function(t){for(var n,r=1,o=arguments.length;r0&&i[i.length-1])&&(l[0]===6||l[0]===2)){n=0;continue}if(l[0]===3&&(!i||l[1]>i[0]&&l[1]n&&(u=-f+n+r,f=n),d>t&&(s=-d+t+o,d=t),l<1&&(s=2-l,l=1),c<1&&(s=2-c,c=1),{dy:a,edy:s,dx:i,edx:u,y:c,ey:d,x:l,ex:f,w:r,h:o}},e.prototype.calibrate=function(t){return new e({left:this.left+t.left*this.width,top:this.top+t.top*this.height,right:this.right+t.right*this.width,bottom:this.bottom+t.bottom*this.height}).toSquare().round()},e}(),Xs=function(e){ue(t,e);function t(n,r,o,i,a){return a===void 0&&(a=!1),e.call(this,{left:n,top:r,right:o,bottom:i},a)||this}return t}(zn),Ry=function(){function e(t,n,r,o,i){this._imageDims=new so(i.width,i.height),this._score=t,this._classScore=n,this._className=r,this._box=new zn(o).rescale(this._imageDims)}return Object.defineProperty(e.prototype,"score",{get:function(){return this._score},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"classScore",{get:function(){return this._classScore},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"className",{get:function(){return this._className},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"box",{get:function(){return this._box},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"imageDims",{get:function(){return this._imageDims},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"imageWidth",{get:function(){return this.imageDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"imageHeight",{get:function(){return this.imageDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"relativeBox",{get:function(){return new zn(this._box).rescale(this.imageDims.reverse())},enumerable:!0,configurable:!0}),e.prototype.forSize=function(t,n){return new e(this.score,this.classScore,this.className,this.relativeBox,{width:t,height:n})},e}(),Kt=function(e){ue(t,e);function t(n,r,o){return e.call(this,n,n,"",r,o)||this}return t.prototype.forSize=function(n,r){var o=e.prototype.forSize.call(this,n,r),i=o.score,a=o.relativeBox,u=o.imageDims;return new t(i,a,u)},t}(Ry);function Dk(e,t,n){n===void 0&&(n=!0);var r=Math.max(0,Math.min(e.right,t.right)-Math.max(e.left,t.left)),o=Math.max(0,Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top)),i=r*o;return n?i/(e.area+t.area-i):i/Math.min(e.area,t.area)}function Tk(e){var t=e.map(function(u){return u.x}),n=e.map(function(u){return u.y}),r=t.reduce(function(u,s){return s0;)a();return i}function Ba(e,t){return X(function(){var n=t[0],r=t[1],o=t[2],i=Ln(Qi(e.shape.slice(0,3),[1]),n),a=Ln(Qi(e.shape.slice(0,3),[1]),r),u=Ln(Qi(e.shape.slice(0,3),[1]),o),s=Ye([i,a,u],3);return Ze(e,s)})}function Nk(e,t){return t===void 0&&(t=!1),X(function(){var n=e.shape.slice(1),r=n[0],o=n[1];if(r===o)return e;var i=Math.abs(r-o),a=Math.round(i*(t?.5:1)),u=r>o?2:1,s=function(h){var p=e.shape.slice();return p[u]=h,Ln(p,0)},l=s(a),c=i-l.shape[u],f=t&&c?s(c):null,d=[f,e,l].filter(function(h){return!!h}).map(function(h){return h.toFloat()});return Ye(d,u)})}function nc(e){return 1/(1+Math.exp(-e))}var Xd=function(e){ue(t,e);function t(n,r,o,i,a){return a===void 0&&(a=!1),e.call(this,{x:n,y:r,width:o,height:i},a)||this}return t}(zn),Ak=.5,Pk=.43,Fk=.45,yi=function(){function e(t,n,r){r===void 0&&(r=new we(0,0));var o=n.width,i=n.height;this._imgDims=new so(o,i),this._shift=r,this._positions=t.map(function(a){return a.mul(new we(o,i)).add(r)})}return Object.defineProperty(e.prototype,"shift",{get:function(){return new we(this._shift.x,this._shift.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"imageWidth",{get:function(){return this._imgDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"imageHeight",{get:function(){return this._imgDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"positions",{get:function(){return this._positions},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"relativePositions",{get:function(){var t=this;return this._positions.map(function(n){return n.sub(t._shift).div(new we(t.imageWidth,t.imageHeight))})},enumerable:!0,configurable:!0}),e.prototype.forSize=function(t,n){return new this.constructor(this.relativePositions,{width:t,height:n})},e.prototype.shiftBy=function(t,n){return new this.constructor(this.relativePositions,this._imgDims,new we(t,n))},e.prototype.shiftByPoint=function(t){return this.shiftBy(t.x,t.y)},e.prototype.align=function(t,n){if(n===void 0&&(n={}),t){var r=t instanceof Kt?t.box.floor():new zn(t);return this.shiftBy(r.x,r.y).align(null,n)}var o=Object.assign({},{useDlibAlignment:!1,minBoxPadding:.2},n),i=o.useDlibAlignment,a=o.minBoxPadding;return i?this.alignDlib():this.alignMinBbox(a)},e.prototype.alignDlib=function(){var t=this.getRefPointsForAlignment(),n=t[0],r=t[1],o=t[2],i=function(f){return o.sub(f).magnitude()},a=(i(n)+i(r))/2,u=Math.floor(a/Fk),s=Kd(t),l=Math.floor(Math.max(0,s.x-Ak*u)),c=Math.floor(Math.max(0,s.y-Pk*u));return new Xd(l,c,Math.min(u,this.imageWidth+l),Math.min(u,this.imageHeight+c))},e.prototype.alignMinBbox=function(t){var n=Tk(this.positions);return n.pad(n.width*t,n.height*t)},e.prototype.getRefPointsForAlignment=function(){throw new Error("getRefPointsForAlignment not implemented by base class")},e}(),Mk=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.getRefPointsForAlignment=function(){var n=this.positions;return[n[0],n[1],Kd([n[3],n[4]])]},t}(yi),Iy=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.getJawOutline=function(){return this.positions.slice(0,17)},t.prototype.getLeftEyeBrow=function(){return this.positions.slice(17,22)},t.prototype.getRightEyeBrow=function(){return this.positions.slice(22,27)},t.prototype.getNose=function(){return this.positions.slice(27,36)},t.prototype.getLeftEye=function(){return this.positions.slice(36,42)},t.prototype.getRightEye=function(){return this.positions.slice(42,48)},t.prototype.getMouth=function(){return this.positions.slice(48,68)},t.prototype.getRefPointsForAlignment=function(){return[this.getLeftEye(),this.getRightEye(),this.getMouth()].map(Kd)},t}(yi),Rv=function(){function e(t,n){this._label=t,this._distance=n}return Object.defineProperty(e.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"distance",{get:function(){return this._distance},enumerable:!0,configurable:!0}),e.prototype.toString=function(t){return t===void 0&&(t=!0),""+this.label+(t?" ("+qd(this.distance)+")":"")},e}(),Iv=function(e){ue(t,e);function t(n,r){var o=e.call(this,n)||this;return o._label=r,o}return t.assertIsValidLabeledBox=function(n,r){if(zn.assertIsValidBox(n,r),!lo(n.label))throw new Error(r+" - expected property label ("+n.label+") to be a number")},Object.defineProperty(t.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),t}(zn),fu=function(){function e(t,n){if(typeof t!="string")throw new Error("LabeledFaceDescriptors - constructor expected label to be a string");if(!Array.isArray(n)||n.some(function(r){return!(r instanceof Float32Array)}))throw new Error("LabeledFaceDescriptors - constructor expected descriptors to be an array of Float32Array");this._label=t,this._descriptors=n}return Object.defineProperty(e.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"descriptors",{get:function(){return this._descriptors},enumerable:!0,configurable:!0}),e.prototype.toJSON=function(){return{label:this.label,descriptors:this.descriptors.map(function(t){return Array.from(t)})}},e.fromJSON=function(t){var n=t.descriptors.map(function(r){return new Float32Array(r)});return new e(t.label,n)},e}();(function(e){ue(t,e);function t(n,r,o,i){var a=e.call(this,n,r)||this;return a._score=o,a._classScore=i,a}return t.assertIsValidPredictedBox=function(n,r){if(Iv.assertIsValidLabeledBox(n,r),!kv(n.score)||!kv(n.classScore))throw new Error(r+" - expected properties score ("+n.score+") and ("+n.classScore+") to be a number between [0, 1]")},Object.defineProperty(t.prototype,"score",{get:function(){return this._score},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"classScore",{get:function(){return this._classScore},enumerable:!0,configurable:!0}),t})(Iv);function Ca(e){return e.detection instanceof Kt}function _a(e,t){var n={detection:t};return Object.assign({},e,n)}function Dy(){var e=window.fetch||function(){throw new Error("fetch - missing fetch implementation for browser environment")},t=function(){throw new Error("readFile - filesystem not available for browser environment")};return{Canvas:HTMLCanvasElement,CanvasRenderingContext2D,Image:HTMLImageElement,ImageData,Video:HTMLVideoElement,createCanvasElement:function(){return document.createElement("canvas")},createImageElement:function(){return document.createElement("img")},fetch:e,readFile:t}}function Ty(e){var t="";if(!e)try{e=require("fs")}catch(r){t=r.toString()}var n=e?function(r){return new Promise(function(o,i){e.readFile(r,function(a,u){return a?i(a):o(u)})})}:function(){throw new Error("readFile - failed to require fs in nodejs environment with error: "+t)};return{readFile:n}}function Ny(){var e=global.Canvas||global.HTMLCanvasElement,t=global.Image||global.HTMLImageElement,n=function(){if(e)return new e;throw new Error("createCanvasElement - missing Canvas implementation for nodejs environment")},r=function(){if(t)return new t;throw new Error("createImageElement - missing Image implementation for nodejs environment")},o=global.fetch||function(){throw new Error("fetch - missing fetch implementation for nodejs environment")},i=Ty();return mt({Canvas:e||function(){function a(){}return a}(),CanvasRenderingContext2D:global.CanvasRenderingContext2D||function(){function a(){}return a}(),Image:t||function(){function a(){}return a}(),ImageData:global.ImageData||function(){function a(){}return a}(),Video:global.HTMLVideoElement||function(){function a(){}return a}(),createCanvasElement:n,createImageElement:r,fetch:o},i)}function Ay(){return typeof window=="object"&&typeof document<"u"&&typeof HTMLImageElement<"u"&&typeof HTMLCanvasElement<"u"&&typeof HTMLVideoElement<"u"&&typeof ImageData<"u"&&typeof CanvasRenderingContext2D<"u"}function Py(){return typeof global=="object"&&typeof require=="function"&&typeof d1<"u"&&typeof process<"u"&&!!process.version}var qe;function Ok(){if(!qe)throw new Error("getEnv - environment is not defined, check isNodejs() and isBrowser()");return qe}function bf(e){qe=e}function Yd(){Ay()&&bf(Dy()),Py()&&bf(Ny())}function Bk(e){if(qe||Yd(),!qe)throw new Error("monkeyPatch - environment is not defined, check isNodejs() and isBrowser()");var t=e.Canvas,n=t===void 0?qe.Canvas:t,r=e.Image,o=r===void 0?qe.Image:r;qe.Canvas=n,qe.Image=o,qe.createCanvasElement=e.createCanvasElement||function(){return new n},qe.createImageElement=e.createImageElement||function(){return new o},qe.ImageData=e.ImageData||qe.ImageData,qe.Video=e.Video||qe.Video,qe.fetch=e.fetch||qe.fetch,qe.readFile=e.readFile||qe.readFile}var Ct={getEnv:Ok,setEnv:bf,initialize:Yd,createBrowserEnv:Dy,createFileSystem:Ty,createNodejsEnv:Ny,monkeyPatch:Bk,isBrowser:Ay,isNodejs:Py};Yd();function Qd(e){return!Ct.isNodejs()&&typeof e=="string"?document.getElementById(e):e}function Un(e){var t=Ct.getEnv(),n=t.Canvas,r=t.CanvasRenderingContext2D;if(e instanceof r)return e;var o=Qd(e);if(!(o instanceof n))throw new Error("resolveContext2d - expected canvas to be of instance of Canvas");var i=o.getContext("2d");if(!i)throw new Error("resolveContext2d - canvas 2d context is null");return i}var kr;(function(e){e.TOP_LEFT="TOP_LEFT",e.TOP_RIGHT="TOP_RIGHT",e.BOTTOM_LEFT="BOTTOM_LEFT",e.BOTTOM_RIGHT="BOTTOM_RIGHT"})(kr||(kr={}));var Fy=function(){function e(t){t===void 0&&(t={});var n=t.anchorPosition,r=t.backgroundColor,o=t.fontColor,i=t.fontSize,a=t.fontStyle,u=t.padding;this.anchorPosition=n||kr.TOP_LEFT,this.backgroundColor=r||"rgba(0, 0, 0, 0.5)",this.fontColor=o||"rgba(255, 255, 255, 1)",this.fontSize=i||14,this.fontStyle=a||"Georgia",this.padding=u||4}return e}(),My=function(){function e(t,n,r){r===void 0&&(r={}),this.text=typeof t=="string"?[t]:t instanceof e?t.text:t,this.anchor=n,this.options=new Fy(r)}return e.prototype.measureWidth=function(t){var n=this.options.padding;return this.text.map(function(r){return t.measureText(r).width}).reduce(function(r,o){return r=3}function Uk(e){return new Promise(function(t,n){if(e instanceof Ct.getEnv().Canvas||Oy(e))return t();function r(i){i.currentTarget&&(i.currentTarget.removeEventListener("load",r),i.currentTarget.removeEventListener("error",o),t(i))}function o(i){i.currentTarget&&(i.currentTarget.removeEventListener("load",r),i.currentTarget.removeEventListener("error",o),n(i))}e.addEventListener("load",r),e.addEventListener("error",o)})}function Jd(e){var t=Ct.getEnv(),n=t.Image,r=t.Video;return e instanceof n?new so(e.naturalWidth,e.naturalHeight):e instanceof r?new so(e.videoWidth,e.videoHeight):new so(e.width,e.height)}function Ys(e){var t=e.width,n=e.height,r=Ct.getEnv().createCanvasElement,o=r();return o.width=t,o.height=n,o}function Zd(e,t){var n=Ct.getEnv().ImageData;if(!(e instanceof n)&&!Oy(e))throw new Error("createCanvasFromMedia - media has not finished loading yet");var r=t||Jd(e),o=r.width,i=r.height,a=Ys({width:o,height:i});return e instanceof n?Un(a).putImageData(e,0,0):Un(a).drawImage(e,0,0,o,i),a}function Vk(e,t){return te(this,void 0,void 0,function(){var n,r,o,i,a,u;return ne(this,function(s){switch(s.label){case 0:return n=t||Ct.getEnv().createCanvasElement(),r=e.shape.slice(Br(e)?1:0),o=r[0],i=r[1],a=r[2],u=X(function(){return e.as3D(o,i,a).toInt()}),[4,Gd.toPixels(u,n)];case 1:return s.sent(),u.dispose(),[2,n]}})})}function Dv(e){var t=Ct.getEnv(),n=t.Image,r=t.Canvas,o=t.Video;return e instanceof n||e instanceof r||e instanceof o}function $k(e,t,n){n===void 0&&(n=!1);var r=Ct.getEnv(),o=r.Image,i=r.Canvas;if(!(e instanceof o||e instanceof i))throw new Error("imageToSquare - expected arg0 to be HTMLImageElement | HTMLCanvasElement");var a=Jd(e),u=t/Math.max(a.height,a.width),s=u*a.width,l=u*a.height,c=Ys({width:t,height:t}),f=e instanceof i?e:Zd(e),d=Math.abs(s-l)/2,h=n&&s1||this._treatAsBatchInput},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"batchSize",{get:function(){return this._batchSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"inputDimensions",{get:function(){return this._inputDimensions},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"inputSize",{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"reshapedInputDimensions",{get:function(){var t=this;return wa(this.batchSize,0,1).map(function(n,r){return t.getReshapedInputDimensions(r)})},enumerable:!0,configurable:!0}),e.prototype.getInput=function(t){return this.canvases[t]||this.imageTensors[t]},e.prototype.getInputDimensions=function(t){return this._inputDimensions[t]},e.prototype.getInputHeight=function(t){return this._inputDimensions[t][0]},e.prototype.getInputWidth=function(t){return this._inputDimensions[t][1]},e.prototype.getReshapedInputDimensions=function(t){if(typeof this.inputSize!="number")throw new Error("getReshapedInputDimensions - inputSize not set, toBatchTensor has not been called yet");var n=this.getInputWidth(t),r=this.getInputHeight(t);return Ik({width:n,height:r},this.inputSize)},e.prototype.toBatchTensor=function(t,n){var r=this;return n===void 0&&(n=!0),this._inputSize=t,X(function(){var o=wa(r.batchSize,0,1).map(function(a){var u=r.getInput(a);if(u instanceof Fe){var s=Br(u)?u:u.expandDims();return s=Nk(s,n),(s.shape[1]!==t||s.shape[2]!==t)&&(s=zd.resizeBilinear(s,[t,t])),s.as3D(t,t,3)}if(u instanceof Ct.getEnv().Canvas)return Gd.fromPixels($k(u,t,n));throw new Error("toBatchTensor - at batchIdx "+a+", expected input to be instanceof tf.Tensor or instanceof HTMLCanvasElement, instead have "+u)}),i=Gt(o.map(function(a){return a.toFloat()})).as4D(r.batchSize,t,t,3);return i})},e}();function it(e){return te(this,void 0,void 0,function(){var t,n,r;return ne(this,function(o){switch(o.label){case 0:if(e instanceof xs)return[2,e];if(t=Array.isArray(e)?e:[e],!t.length)throw new Error("toNetInput - empty array passed as input");return n=function(i){return Array.isArray(e)?" at input index "+i+":":""},r=t.map(Qd),r.forEach(function(i,a){if(!Dv(i)&&!Ks(i)&&!Br(i))throw typeof t[a]=="string"?new Error("toNetInput -"+n(a)+" string passed, but could not resolve HTMLElement for element id "+t[a]):new Error("toNetInput -"+n(a)+" expected media to be of type HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | tf.Tensor3D, or to be an element id");if(Br(i)){var u=i.shape[0];if(u!==1)throw new Error("toNetInput -"+n(a)+" tf.Tensor4D with batchSize "+u+" passed, but not supported in input array")}}),[4,Promise.all(r.map(function(i){return Dv(i)&&Uk(i)}))];case 1:return o.sent(),[2,new xs(r,Array.isArray(e))]}})})}function eh(e,t){return te(this,void 0,void 0,function(){var n,r,o,i,a,u,s;return ne(this,function(l){switch(l.label){case 0:return n=Ct.getEnv().Canvas,r=e,e instanceof n?[3,5]:[4,it(e)];case 1:if(o=l.sent(),o.batchSize>1)throw new Error("extractFaces - batchSize > 1 not supported");return i=o.getInput(0),i instanceof n?(a=i,[3,4]):[3,2];case 2:return[4,Vk(i)];case 3:a=l.sent(),l.label=4;case 4:r=a,l.label=5;case 5:return u=Un(r),s=t.map(function(c){return c instanceof Kt?c.forSize(r.width,r.height).box.floor():c}).map(function(c){return c.clipAtImageBorders(r.width,r.height)}),[2,s.map(function(c){var f=c.x,d=c.y,h=c.width,p=c.height,m=Ys({width:h,height:p});return Un(m).putImageData(u.getImageData(f,d,h,p),0,0),m})]}})})}function th(e,t){return te(this,void 0,void 0,function(){return ne(this,function(n){if(!Ks(e)&&!Br(e))throw new Error("extractFaceTensors - expected image tensor to be 3D or 4D");if(Br(e)&&e.shape[0]>1)throw new Error("extractFaceTensors - batchSize > 1 not supported");return[2,X(function(){var r=e.shape.slice(Br(e)?1:0),o=r[0],i=r[1],a=r[2],u=t.map(function(l){return l instanceof Kt?l.forSize(i,o).box:l}).map(function(l){return l.clipAtImageBorders(i,o)}),s=u.map(function(l){var c=l.x,f=l.y,d=l.width,h=l.height;return sy(e.as3D(o,i,a),[f,c,0],[h,d,a])});return s})]})})}function Hk(e,t){return te(this,void 0,void 0,function(){var n,r;return ne(this,function(o){switch(o.label){case 0:return n=Ct.getEnv().fetch,[4,n(e,t)];case 1:if(r=o.sent(),!(r.status<400))throw new Error("failed to fetch: ("+r.status+") "+r.statusText+", from url: "+r.url);return[2,r]}})})}function jk(e){return te(this,void 0,void 0,function(){return ne(this,function(t){switch(t.label){case 0:return[4,Hk(e)];case 1:return[2,t.sent().json()]}})})}function By(e,t){var n=t+"-weights_manifest.json";if(!e)return{modelBaseUri:"",manifestUri:n};if(e==="/")return{modelBaseUri:"/",manifestUri:"/"+n};var r=e.startsWith("http://")?"http://":e.startsWith("https://")?"https://":"";e=e.replace(r,"");var o=e.split("/").filter(function(u){return u}),i=e.endsWith(".json")?o[o.length-1]:n,a=r+(e.endsWith(".json")?o.slice(0,o.length-1):o).join("/");return a=e.startsWith("/")?"/"+a:a,{modelBaseUri:a,manifestUri:a==="/"?"/"+i:a+"/"+i}}function Gk(e,t){return te(this,void 0,void 0,function(){var n,r,o,i;return ne(this,function(a){switch(a.label){case 0:return n=By(e,t),r=n.manifestUri,o=n.modelBaseUri,[4,jk(r)];case 1:return i=a.sent(),[2,Sy.loadWeights(i,o)]}})})}function qk(e,t,n){n===void 0&&(n=!1);var r=n?Jd(t):t,o=r.width,i=r.height;return e.width=o,e.height=i,{width:o,height:i}}var fr=function(){function e(t){this._name=t,this._params=void 0,this._paramMappings=[]}return Object.defineProperty(e.prototype,"params",{get:function(){return this._params},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"paramMappings",{get:function(){return this._paramMappings},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isLoaded",{get:function(){return!!this.params},enumerable:!0,configurable:!0}),e.prototype.getParamFromPath=function(t){var n=this.traversePropertyPath(t),r=n.obj,o=n.objProp;return r[o]},e.prototype.reassignParamFromPath=function(t,n){var r=this.traversePropertyPath(t),o=r.obj,i=r.objProp;o[i].dispose(),o[i]=n},e.prototype.getParamList=function(){var t=this;return this._paramMappings.map(function(n){var r=n.paramPath;return{path:r,tensor:t.getParamFromPath(r)}})},e.prototype.getTrainableParams=function(){return this.getParamList().filter(function(t){return t.tensor instanceof vi})},e.prototype.getFrozenParams=function(){return this.getParamList().filter(function(t){return!(t.tensor instanceof vi)})},e.prototype.variable=function(){var t=this;this.getFrozenParams().forEach(function(n){var r=n.path,o=n.tensor;t.reassignParamFromPath(r,o.variable())})},e.prototype.freeze=function(){var t=this;this.getTrainableParams().forEach(function(n){var r=n.path,o=n.tensor,i=lt(o.dataSync());o.dispose(),t.reassignParamFromPath(r,i)})},e.prototype.dispose=function(t){t===void 0&&(t=!0),this.getParamList().forEach(function(n){if(t&&n.tensor.isDisposed)throw new Error("param tensor has already been disposed for path "+n.path);n.tensor.dispose()}),this._params=void 0},e.prototype.serializeParams=function(){return new Float32Array(this.getParamList().map(function(t){var n=t.tensor;return Array.from(n.dataSync())}).reduce(function(t,n){return t.concat(n)}))},e.prototype.load=function(t){return te(this,void 0,void 0,function(){return ne(this,function(n){switch(n.label){case 0:return t instanceof Float32Array?(this.extractWeights(t),[2]):[4,this.loadFromUri(t)];case 1:return n.sent(),[2]}})})},e.prototype.loadFromUri=function(t){return te(this,void 0,void 0,function(){var n;return ne(this,function(r){switch(r.label){case 0:if(t&&typeof t!="string")throw new Error(this._name+".loadFromUri - expected model uri");return[4,Gk(t,this.getDefaultModelName())];case 1:return n=r.sent(),this.loadFromWeightMap(n),[2]}})})},e.prototype.loadFromDisk=function(t){return te(this,void 0,void 0,function(){var n,r,o,i,a,u,s,l,c,f;return ne(this,function(d){switch(d.label){case 0:if(t&&typeof t!="string")throw new Error(this._name+".loadFromDisk - expected model file path");return n=Ct.getEnv().readFile,r=By(t,this.getDefaultModelName()),o=r.manifestUri,i=r.modelBaseUri,a=function(h){return Promise.all(h.map(function(p){return n(p).then(function(m){return m.buffer})}))},u=Sy.weightsLoaderFactory(a),c=(l=JSON).parse,[4,n(o)];case 1:return s=c.apply(l,[d.sent().toString()]),[4,u(s,i)];case 2:return f=d.sent(),this.loadFromWeightMap(f),[2]}})})},e.prototype.loadFromWeightMap=function(t){var n=this.extractParamsFromWeigthMap(t),r=n.paramMappings,o=n.params;this._paramMappings=r,this._params=o},e.prototype.extractWeights=function(t){var n=this.extractParams(t),r=n.paramMappings,o=n.params;this._paramMappings=r,this._params=o},e.prototype.traversePropertyPath=function(t){if(!this.params)throw new Error("traversePropertyPath - model has no loaded params");var n=t.split("/").reduce(function(i,a){if(!i.nextObj.hasOwnProperty(a))throw new Error("traversePropertyPath - object does not have property "+a+", for path "+t);return{obj:i.nextObj,objProp:a,nextObj:i.nextObj[a]}},{nextObj:this.params}),r=n.obj,o=n.objProp;if(!r||!o||!(r[o]instanceof Fe))throw new Error("traversePropertyPath - parameter is not a tensor, for path "+t);return{obj:r,objProp:o}},e}();function Ht(e,t,n){return X(function(){var r=Md(e,t.depthwise_filter,t.pointwise_filter,n,"same");return r=de(r,t.bias),r})}function rc(e,t,n){return n===void 0&&(n=!1),X(function(){var r=Me(n?de(un(e,t.conv0.filters,[2,2],"same"),t.conv0.bias):Ht(e,t.conv0,[2,2])),o=Ht(r,t.conv1,[1,1]),i=Me(de(r,o)),a=Ht(i,t.conv2,[1,1]);return Me(de(r,de(o,a)))})}function du(e,t,n,r){return n===void 0&&(n=!1),r===void 0&&(r=!0),X(function(){var o=Me(n?de(un(e,t.conv0.filters,r?[2,2]:[1,1],"same"),t.conv0.bias):Ht(e,t.conv0,r?[2,2]:[1,1])),i=Ht(o,t.conv1,[1,1]),a=Me(de(o,i)),u=Ht(a,t.conv2,[1,1]),s=Me(de(o,de(i,u))),l=Ht(s,t.conv3,[1,1]);return Me(de(o,de(i,de(u,l))))})}function yn(e,t,n,r){return n===void 0&&(n="same"),r===void 0&&(r=!1),X(function(){var o=de(un(e,t.filters,[1,1],n),t.bias);return r?Me(o):o})}function dr(e,t){Object.keys(e).forEach(function(n){t.some(function(r){return r.originalPath===n})||e[n].dispose()})}function Qs(e,t){return function(n,r,o,i){var a=It(e(n*r*o*o),[o,o,n,r]),u=Ge(e(r));return t.push({paramPath:i+"/filters"},{paramPath:i+"/bias"}),{filters:a,bias:u}}}function nh(e,t){return function(n,r,o){var i=Mr(e(n*r),[n,r]),a=Ge(e(r));return t.push({paramPath:o+"/weights"},{paramPath:o+"/bias"}),{weights:i,bias:a}}}var Ly=function(){function e(t,n,r){this.depthwise_filter=t,this.pointwise_filter=n,this.bias=r}return e}();function rh(e,t){return function(n,r,o){var i=It(e(9*n),[3,3,n,1]),a=It(e(n*r),[1,1,n,r]),u=Ge(e(r));return t.push({paramPath:o+"/depthwise_filter"},{paramPath:o+"/pointwise_filter"},{paramPath:o+"/bias"}),new Ly(i,a,u)}}function oh(e){return function(t){var n=e(t+"/depthwise_filter",4),r=e(t+"/pointwise_filter",4),o=e(t+"/bias",1);return new Ly(n,r,o)}}function Gr(e,t){return function(n,r,o){var i=e[n];if(!qs(i,r))throw new Error("expected weightMap["+n+"] to be a Tensor"+r+"D, instead have "+i);return t.push({originalPath:n,paramPath:o||n}),i}}function hr(e){var t=e;function n(o){var i=t.slice(0,o);return t=t.slice(o),i}function r(){return t}return{extractWeights:n,getRemainingWeights:r}}function Wy(e,t){var n=Qs(e,t),r=rh(e,t);function o(a,u,s,l){l===void 0&&(l=!1);var c=l?n(a,u,3,s+"/conv0"):r(a,u,s+"/conv0"),f=r(u,u,s+"/conv1"),d=r(u,u,s+"/conv2");return{conv0:c,conv1:f,conv2:d}}function i(a,u,s,l){l===void 0&&(l=!1);var c=o(a,u,s,l),f=c.conv0,d=c.conv1,h=c.conv2,p=r(u,u,s+"/conv3");return{conv0:f,conv1:d,conv2:h,conv3:p}}return{extractDenseBlock3Params:o,extractDenseBlock4Params:i}}function Kk(e){var t=[],n=hr(e),r=n.extractWeights,o=n.getRemainingWeights,i=Wy(r,t).extractDenseBlock4Params,a=i(3,32,"dense0",!0),u=i(32,64,"dense1"),s=i(64,128,"dense2"),l=i(128,256,"dense3");if(o().length!==0)throw new Error("weights remaing after extract: "+o().length);return{paramMappings:t,params:{dense0:a,dense1:u,dense2:s,dense3:l}}}function zy(e){return function(t){var n=e(t+"/filters",4),r=e(t+"/bias",1);return{filters:n,bias:r}}}function Uy(e,t){var n=Gr(e,t),r=zy(n),o=oh(n);function i(u,s){s===void 0&&(s=!1);var l=s?r(u+"/conv0"):o(u+"/conv0"),c=o(u+"/conv1"),f=o(u+"/conv2");return{conv0:l,conv1:c,conv2:f}}function a(u,s){s===void 0&&(s=!1);var l=s?r(u+"/conv0"):o(u+"/conv0"),c=o(u+"/conv1"),f=o(u+"/conv2"),d=o(u+"/conv3");return{conv0:l,conv1:c,conv2:f,conv3:d}}return{extractDenseBlock3Params:i,extractDenseBlock4Params:a}}function Xk(e){var t=[],n=Uy(e,t).extractDenseBlock4Params,r={dense0:n("dense0",!0),dense1:n("dense1"),dense2:n("dense2"),dense3:n("dense3")};return dr(e,t),{params:r,paramMappings:t}}var Vy=function(e){ue(t,e);function t(){return e.call(this,"FaceFeatureExtractor")||this}return t.prototype.forwardInput=function(n){var r=this.params;if(!r)throw new Error("FaceFeatureExtractor - load model before inference");return X(function(){var o=n.toBatchTensor(112,!0),i=[122.782,117.001,104.298],a=Ba(o,i).div(K(255)),u=du(a,r.dense0,!0);return u=du(u,r.dense1),u=du(u,r.dense2),u=du(u,r.dense3),u=Ma(u,[7,7],[2,2],"valid"),u})},t.prototype.forward=function(n){return te(this,void 0,void 0,function(){var r;return ne(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,it(n)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.getDefaultModelName=function(){return"face_feature_extractor_model"},t.prototype.extractParamsFromWeigthMap=function(n){return Xk(n)},t.prototype.extractParams=function(n){return Kk(n)},t}(fr);function Pn(e,t){return X(function(){return de(Hs(e,t.weights),t.bias)})}function Yk(e,t,n){var r=[],o=hr(e),i=o.extractWeights,a=o.getRemainingWeights,u=nh(i,r),s=u(t,n,"fc");if(a().length!==0)throw new Error("weights remaing after extract: "+a().length);return{paramMappings:r,params:{fc:s}}}function Qk(e){var t=[],n=Gr(e,t);function r(i){var a=n(i+"/weights",2),u=n(i+"/bias",1);return{weights:a,bias:u}}var o={fc:r("fc")};return dr(e,t),{params:o,paramMappings:t}}function $y(e){var t={},n={};return Object.keys(e).forEach(function(r){var o=r.startsWith("fc")?n:t;o[r]=e[r]}),{featureExtractorMap:t,classifierMap:n}}var Hy=function(e){ue(t,e);function t(n,r){var o=e.call(this,n)||this;return o._faceFeatureExtractor=r,o}return 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 X(function(){var i=n instanceof xs?r.faceFeatureExtractor.forwardInput(n):n;return Pn(i.as2D(i.shape[0],-1),o.fc)})},t.prototype.dispose=function(n){n===void 0&&(n=!0),this.faceFeatureExtractor.dispose(n),e.prototype.dispose.call(this,n)},t.prototype.loadClassifierParams=function(n){var r=this.extractClassifierParams(n),o=r.params,i=r.paramMappings;this._params=o,this._paramMappings=i},t.prototype.extractClassifierParams=function(n){return Yk(n,this.getClassifierChannelsIn(),this.getClassifierChannelsOut())},t.prototype.extractParamsFromWeigthMap=function(n){var r=$y(n),o=r.featureExtractorMap,i=r.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(o),Qk(i)},t.prototype.extractParams=function(n){var r=this.getClassifierChannelsIn(),o=this.getClassifierChannelsOut(),i=o*r+o,a=n.slice(0,n.length-i),u=n.slice(n.length-i);return this.faceFeatureExtractor.extractWeights(a),this.extractClassifierParams(u)},t}(fr),Tv=["neutral","happy","sad","angry","fearful","disgusted","surprised"],ih=function(){function e(t){var n=this;if(t.length!==7)throw new Error("FaceExpressions.constructor - expected probabilities.length to be 7, have: "+t.length);Tv.forEach(function(r,o){n[r]=t[o]})}return e.prototype.asSortedArray=function(){var t=this;return Tv.map(function(n){return{expression:n,probability:t[n]}}).sort(function(n,r){return r.probability-n.probability})},e}(),Jk=function(e){ue(t,e);function t(n){return n===void 0&&(n=new Vy),e.call(this,"FaceExpressionNet",n)||this}return t.prototype.forwardInput=function(n){var r=this;return X(function(){return lr(r.runNet(n))})},t.prototype.forward=function(n){return te(this,void 0,void 0,function(){var r;return ne(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,it(n)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.predictExpressions=function(n){return te(this,void 0,void 0,function(){var r,o,i,a,u=this;return ne(this,function(s){switch(s.label){case 0:return[4,it(n)];case 1:return r=s.sent(),[4,this.forwardInput(r)];case 2:return o=s.sent(),[4,Promise.all(Qe(o).map(function(l){return te(u,void 0,void 0,function(){var c;return ne(this,function(f){switch(f.label){case 0:return[4,l.data()];case 1:return c=f.sent(),l.dispose(),[2,c]}})})}))];case 3:return i=s.sent(),o.dispose(),a=i.map(function(l){return new ih(l)}),[2,r.isBatchInput?a:a[0]]}})})},t.prototype.getDefaultModelName=function(){return"face_expression_model"},t.prototype.getClassifierChannelsIn=function(){return 256},t.prototype.getClassifierChannelsOut=function(){return 7},t}(Hy);function Zk(e){return e.expressions instanceof ih}function jy(e,t){var n={expressions:t};return Object.assign({},e,n)}function eR(e,t,n,r){n===void 0&&(n=.1);var o=Array.isArray(t)?t:[t];o.forEach(function(i){var a=i instanceof ih?i:Zk(i)?i.expressions:void 0;if(!a)throw new Error("drawFaceExpressions - expected faceExpressions to be FaceExpressions | WithFaceExpressions<{}> or array thereof");var u=a.asSortedArray(),s=u.filter(function(f){return f.probability>n}),l=Ca(i)?i.detection.box.bottomLeft:r||new we(0,0),c=new My(s.map(function(f){return f.expression+" ("+qd(f.probability)+")"}),l);c.draw(e)})}function ah(e){return Ca(e)&&e.landmarks instanceof yi&&e.unshiftedLandmarks instanceof yi&&e.alignedRect instanceof Kt}function Js(e,t){var n=e.detection.box,r=t.shiftBy(n.x,n.y),o=r.align(),i=e.detection.imageDims,a=new Kt(e.detection.score,o.rescale(i.reverse()),i),u={landmarks:r,unshiftedLandmarks:t,alignedRect:a};return Object.assign({},e,u)}var tR=function(){function e(t){t===void 0&&(t={});var n=t.drawLines,r=n===void 0?!0:n,o=t.drawPoints,i=o===void 0?!0:o,a=t.lineWidth,u=t.lineColor,s=t.pointSize,l=t.pointColor;this.drawLines=r,this.drawPoints=i,this.lineWidth=a||1,this.pointSize=s||2,this.lineColor=u||"rgba(0, 255, 255, 1)",this.pointColor=l||"rgba(255, 0, 255, 1)"}return e}(),nR=function(){function e(t,n){n===void 0&&(n={}),this.faceLandmarks=t,this.options=new tR(n)}return e.prototype.draw=function(t){var n=Un(t),r=this.options,o=r.drawLines,i=r.drawPoints,a=r.lineWidth,u=r.lineColor,s=r.pointSize,l=r.pointColor;if(o&&this.faceLandmarks instanceof Iy&&(n.strokeStyle=u,n.lineWidth=a,Xr(n,this.faceLandmarks.getJawOutline()),Xr(n,this.faceLandmarks.getLeftEyeBrow()),Xr(n,this.faceLandmarks.getRightEyeBrow()),Xr(n,this.faceLandmarks.getNose()),Xr(n,this.faceLandmarks.getLeftEye(),!0),Xr(n,this.faceLandmarks.getRightEye(),!0),Xr(n,this.faceLandmarks.getMouth(),!0)),i){n.strokeStyle=l,n.fillStyle=l;var c=function(f){n.beginPath(),n.arc(f.x,f.y,s,0,2*Math.PI),n.fill()};this.faceLandmarks.positions.forEach(c)}},e}();function rR(e,t){var n=Array.isArray(t)?t:[t];n.forEach(function(r){var o=r instanceof yi?r:ah(r)?r.landmarks:void 0;if(!o)throw new Error("drawFaceLandmarks - expected faceExpressions to be FaceLandmarks | WithFaceLandmarks> or array thereof");new nR(o).draw(e)})}function oR(e,t){var n=Qs(e,t),r=rh(e,t);function o(a,u,s){var l=r(a,u,s+"/separable_conv0"),c=r(u,u,s+"/separable_conv1"),f=n(a,u,1,s+"/expansion_conv");return{separable_conv0:l,separable_conv1:c,expansion_conv:f}}function i(a,u){var s=r(a,a,u+"/separable_conv0"),l=r(a,a,u+"/separable_conv1"),c=r(a,a,u+"/separable_conv2");return{separable_conv0:s,separable_conv1:l,separable_conv2:c}}return{extractConvParams:n,extractSeparableConvParams:r,extractReductionBlockParams:o,extractMainBlockParams:i}}function iR(e,t){var n=[],r=hr(e),o=r.extractWeights,i=r.getRemainingWeights,a=oR(o,n),u=a.extractConvParams,s=a.extractSeparableConvParams,l=a.extractReductionBlockParams,c=a.extractMainBlockParams,f=u(3,32,3,"entry_flow/conv_in"),d=l(32,64,"entry_flow/reduction_block_0"),h=l(64,128,"entry_flow/reduction_block_1"),p={conv_in:f,reduction_block_0:d,reduction_block_1:h},m={};wa(t,0,1).forEach(function(x){m["main_block_"+x]=c(128,"middle_flow/main_block_"+x)});var g=l(128,256,"exit_flow/reduction_block"),v=s(256,512,"exit_flow/separable_conv"),y={reduction_block:g,separable_conv:v};if(i().length!==0)throw new Error("weights remaing after extract: "+i().length);return{paramMappings:n,params:{entry_flow:p,middle_flow:m,exit_flow:y}}}function aR(e,t){var n=Gr(e,t),r=zy(n),o=oh(n);function i(u){var s=o(u+"/separable_conv0"),l=o(u+"/separable_conv1"),c=r(u+"/expansion_conv");return{separable_conv0:s,separable_conv1:l,expansion_conv:c}}function a(u){var s=o(u+"/separable_conv0"),l=o(u+"/separable_conv1"),c=o(u+"/separable_conv2");return{separable_conv0:s,separable_conv1:l,separable_conv2:c}}return{extractConvParams:r,extractSeparableConvParams:o,extractReductionBlockParams:i,extractMainBlockParams:a}}function uR(e,t){var n=[],r=aR(e,n),o=r.extractConvParams,i=r.extractSeparableConvParams,a=r.extractReductionBlockParams,u=r.extractMainBlockParams,s=o("entry_flow/conv_in"),l=a("entry_flow/reduction_block_0"),c=a("entry_flow/reduction_block_1"),f={conv_in:s,reduction_block_0:l,reduction_block_1:c},d={};wa(t,0,1).forEach(function(g){d["main_block_"+g]=u("middle_flow/main_block_"+g)});var h=a("exit_flow/reduction_block"),p=i("exit_flow/separable_conv"),m={reduction_block:h,separable_conv:p};return dr(e,n),{params:{entry_flow:f,middle_flow:d,exit_flow:m},paramMappings:n}}function Gy(e,t,n){return de(un(e,t.filters,n,"same"),t.bias)}function oc(e,t,n){n===void 0&&(n=!0);var r=n?Me(e):e;return r=Ht(r,t.separable_conv0,[1,1]),r=Ht(Me(r),t.separable_conv1,[1,1]),r=tt(r,[3,3],[2,2],"same"),r=de(r,Gy(e,t.expansion_conv,[2,2])),r}function sR(e,t){var n=Ht(Me(e),t.separable_conv0,[1,1]);return n=Ht(Me(n),t.separable_conv1,[1,1]),n=Ht(Me(n),t.separable_conv2,[1,1]),n=de(n,e),n}var lR=function(e){ue(t,e);function t(n){var r=e.call(this,"TinyXception")||this;return r._numMainBlocks=n,r}return t.prototype.forwardInput=function(n){var r=this,o=this.params;if(!o)throw new Error("TinyXception - load model before inference");return X(function(){var i=n.toBatchTensor(112,!0),a=[122.782,117.001,104.298],u=Ba(i,a).div(K(256)),s=Me(Gy(u,o.entry_flow.conv_in,[2,2]));return s=oc(s,o.entry_flow.reduction_block_0,!1),s=oc(s,o.entry_flow.reduction_block_1),wa(r._numMainBlocks,0,1).forEach(function(l){s=sR(s,o.middle_flow["main_block_"+l])}),s=oc(s,o.exit_flow.reduction_block),s=Me(Ht(s,o.exit_flow.separable_conv,[1,1])),s})},t.prototype.forward=function(n){return te(this,void 0,void 0,function(){var r;return ne(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,it(n)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.getDefaultModelName=function(){return"tiny_xception_model"},t.prototype.extractParamsFromWeigthMap=function(n){return uR(n,this._numMainBlocks)},t.prototype.extractParams=function(n){return iR(n,this._numMainBlocks)},t}(fr);function cR(e){var t=[],n=hr(e),r=n.extractWeights,o=n.getRemainingWeights,i=nh(r,t),a=i(512,1,"fc/age"),u=i(512,2,"fc/gender");if(o().length!==0)throw new Error("weights remaing after extract: "+o().length);return{paramMappings:t,params:{fc:{age:a,gender:u}}}}function fR(e){var t=[],n=Gr(e,t);function r(i){var a=n(i+"/weights",2),u=n(i+"/bias",1);return{weights:a,bias:u}}var o={fc:{age:r("fc/age"),gender:r("fc/gender")}};return dr(e,t),{params:o,paramMappings:t}}var ws;(function(e){e.FEMALE="female",e.MALE="male"})(ws||(ws={}));var dR=function(e){ue(t,e);function t(n){n===void 0&&(n=new lR(2));var r=e.call(this,"AgeGenderNet")||this;return r._faceFeatureExtractor=n,r}return 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 X(function(){var i=n instanceof xs?r.faceFeatureExtractor.forwardInput(n):n,a=Ma(i,[7,7],[2,2],"valid").as2D(i.shape[0],-1),u=Pn(a,o.fc.age).as1D(),s=Pn(a,o.fc.gender);return{age:u,gender:s}})},t.prototype.forwardInput=function(n){var r=this;return X(function(){var o=r.runNet(n),i=o.age,a=o.gender;return{age:i,gender:lr(a)}})},t.prototype.forward=function(n){return te(this,void 0,void 0,function(){var r;return ne(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,it(n)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.predictAgeAndGender=function(n){return te(this,void 0,void 0,function(){var r,o,i,a,u,s,l=this;return ne(this,function(c){switch(c.label){case 0:return[4,it(n)];case 1:return r=c.sent(),[4,this.forwardInput(r)];case 2:return o=c.sent(),i=Qe(o.age),a=Qe(o.gender),u=i.map(function(f,d){return{ageTensor:f,genderTensor:a[d]}}),[4,Promise.all(u.map(function(f){var d=f.ageTensor,h=f.genderTensor;return te(l,void 0,void 0,function(){var p,m,g,v,y;return ne(this,function(x){switch(x.label){case 0:return[4,d.data()];case 1:return p=x.sent()[0],[4,h.data()];case 2:return m=x.sent()[0],g=m>.5,v=g?ws.MALE:ws.FEMALE,y=g?m:1-m,d.dispose(),h.dispose(),[2,{age:p,gender:v,genderProbability:y}]}})})}))];case 3:return s=c.sent(),o.age.dispose(),o.gender.dispose(),[2,r.isBatchInput?s:s[0]]}})})},t.prototype.getDefaultModelName=function(){return"age_gender_model"},t.prototype.dispose=function(n){n===void 0&&(n=!0),this.faceFeatureExtractor.dispose(n),e.prototype.dispose.call(this,n)},t.prototype.loadClassifierParams=function(n){var r=this.extractClassifierParams(n),o=r.params,i=r.paramMappings;this._params=o,this._paramMappings=i},t.prototype.extractClassifierParams=function(n){return cR(n)},t.prototype.extractParamsFromWeigthMap=function(n){var r=$y(n),o=r.featureExtractorMap,i=r.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(o),fR(i)},t.prototype.extractParams=function(n){var r=1539,o=n.slice(0,n.length-r),i=n.slice(n.length-r);return this.faceFeatureExtractor.extractWeights(o),this.extractClassifierParams(i)},t}(fr),qy=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.postProcess=function(n,r,o){var i=o.map(function(u){var s=u.width,l=u.height,c=r/Math.max(l,s);return{width:s*c,height:l*c}}),a=i.length;return X(function(){var u=function(d,h){return Gt([Ln([68],d),Ln([68],h)],1).as2D(1,136).as1D()},s=function(d,h){var p=i[d],m=p.width,g=p.height;return h(m,g)?Math.abs(m-g)/2:0},l=function(d){return s(d,function(h,p){return h 0");if(typeof this._scaleFactor!="number"||this._scaleFactor<=0||this._scaleFactor>=1)throw new Error(this._name+" - expected scaleFactor to be a number between 0 and 1");if(typeof this._maxNumScales!="number"||this._maxNumScales<0)throw new Error(this._name+" - expected maxNumScales to be a number > 0");if(!Array.isArray(this._scoreThresholds)||this._scoreThresholds.length!==3||this._scoreThresholds.some(function(s){return typeof s!="number"}))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(s){return typeof s!="number"})))throw new Error(this._name+" - expected scaleSteps to be an array of numbers")}return Object.defineProperty(e.prototype,"minFaceSize",{get:function(){return this._minFaceSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scaleFactor",{get:function(){return this._scaleFactor},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maxNumScales",{get:function(){return this._maxNumScales},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scoreThresholds",{get:function(){return this._scoreThresholds},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scaleSteps",{get:function(){return this._scaleSteps},enumerable:!0,configurable:!0}),e}();function ER(e,t){function n(s,l){var c=It(e(9*s),[3,3,s,1]),f=Ge(e(s)),d=Ge(e(s)),h=Ge(e(s)),p=Ge(e(s));return t.push({paramPath:l+"/filters"},{paramPath:l+"/batch_norm_scale"},{paramPath:l+"/batch_norm_offset"},{paramPath:l+"/batch_norm_mean"},{paramPath:l+"/batch_norm_variance"}),{filters:c,batch_norm_scale:f,batch_norm_offset:d,batch_norm_mean:h,batch_norm_variance:p}}function r(s,l,c,f,d){var h=It(e(s*l*c*c),[c,c,s,l]),p=Ge(e(l));return t.push({paramPath:f+"/filters"},{paramPath:f+"/"+(d?"batch_norm_offset":"bias")}),{filters:h,bias:p}}function o(s,l,c,f){var d=r(s,l,c,f,!0),h=d.filters,p=d.bias;return{filters:h,batch_norm_offset:p}}function i(s,l,c){var f=n(s,c+"/depthwise_conv"),d=o(s,l,1,c+"/pointwise_conv");return{depthwise_conv:f,pointwise_conv:d}}function a(){var s=o(3,32,3,"mobilenetv1/conv_0"),l=i(32,64,"mobilenetv1/conv_1"),c=i(64,128,"mobilenetv1/conv_2"),f=i(128,128,"mobilenetv1/conv_3"),d=i(128,256,"mobilenetv1/conv_4"),h=i(256,256,"mobilenetv1/conv_5"),p=i(256,512,"mobilenetv1/conv_6"),m=i(512,512,"mobilenetv1/conv_7"),g=i(512,512,"mobilenetv1/conv_8"),v=i(512,512,"mobilenetv1/conv_9"),y=i(512,512,"mobilenetv1/conv_10"),x=i(512,512,"mobilenetv1/conv_11"),w=i(512,1024,"mobilenetv1/conv_12"),b=i(1024,1024,"mobilenetv1/conv_13");return{conv_0:s,conv_1:l,conv_2:c,conv_3:f,conv_4:d,conv_5:h,conv_6:p,conv_7:m,conv_8:g,conv_9:v,conv_10:y,conv_11:x,conv_12:w,conv_13:b}}function u(){var s=o(1024,256,1,"prediction_layer/conv_0"),l=o(256,512,3,"prediction_layer/conv_1"),c=o(512,128,1,"prediction_layer/conv_2"),f=o(128,256,3,"prediction_layer/conv_3"),d=o(256,128,1,"prediction_layer/conv_4"),h=o(128,256,3,"prediction_layer/conv_5"),p=o(256,64,1,"prediction_layer/conv_6"),m=o(64,128,3,"prediction_layer/conv_7"),g=r(512,12,1,"prediction_layer/box_predictor_0/box_encoding_predictor"),v=r(512,9,1,"prediction_layer/box_predictor_0/class_predictor"),y=r(1024,24,1,"prediction_layer/box_predictor_1/box_encoding_predictor"),x=r(1024,18,1,"prediction_layer/box_predictor_1/class_predictor"),w=r(512,24,1,"prediction_layer/box_predictor_2/box_encoding_predictor"),b=r(512,18,1,"prediction_layer/box_predictor_2/class_predictor"),C=r(256,24,1,"prediction_layer/box_predictor_3/box_encoding_predictor"),_=r(256,18,1,"prediction_layer/box_predictor_3/class_predictor"),E=r(256,24,1,"prediction_layer/box_predictor_4/box_encoding_predictor"),R=r(256,18,1,"prediction_layer/box_predictor_4/class_predictor"),k=r(128,24,1,"prediction_layer/box_predictor_5/box_encoding_predictor"),T=r(128,18,1,"prediction_layer/box_predictor_5/class_predictor"),N={box_encoding_predictor:g,class_predictor:v},W={box_encoding_predictor:y,class_predictor:x},L={box_encoding_predictor:w,class_predictor:b},U={box_encoding_predictor:C,class_predictor:_},$={box_encoding_predictor:E,class_predictor:R},V={box_encoding_predictor:k,class_predictor:T};return{conv_0:s,conv_1:l,conv_2:c,conv_3:f,conv_4:d,conv_5:h,conv_6:p,conv_7:m,box_predictor_0:N,box_predictor_1:W,box_predictor_2:L,box_predictor_3:U,box_predictor_4:$,box_predictor_5:V}}return{extractMobilenetV1Params:a,extractPredictionLayerParams:u}}function SR(e){var t=[],n=hr(e),r=n.extractWeights,o=n.getRemainingWeights,i=ER(r,t),a=i.extractMobilenetV1Params,u=i.extractPredictionLayerParams,s=a(),l=u(),c=wd(r(5118*4),[1,5118,4]),f={extra_dim:c};if(t.push({paramPath:"output_layer/extra_dim"}),o().length!==0)throw new Error("weights remaing after extract: "+o().length);return{params:{mobilenetv1:s,prediction_layer:l,output_layer:f},paramMappings:t}}function kR(e,t){var n=Gr(e,t);function r(l,c,f){var d=n(l+"/Conv2d_"+c+"_pointwise/weights",4,f+"/filters"),h=n(l+"/Conv2d_"+c+"_pointwise/convolution_bn_offset",1,f+"/batch_norm_offset");return{filters:d,batch_norm_offset:h}}function o(l){var c="mobilenetv1/conv_"+l,f="MobilenetV1/Conv2d_"+l+"_depthwise",d=c+"/depthwise_conv",h=c+"/pointwise_conv",p=n(f+"/depthwise_weights",4,d+"/filters"),m=n(f+"/BatchNorm/gamma",1,d+"/batch_norm_scale"),g=n(f+"/BatchNorm/beta",1,d+"/batch_norm_offset"),v=n(f+"/BatchNorm/moving_mean",1,d+"/batch_norm_mean"),y=n(f+"/BatchNorm/moving_variance",1,d+"/batch_norm_variance");return{depthwise_conv:{filters:p,batch_norm_scale:m,batch_norm_offset:g,batch_norm_mean:v,batch_norm_variance:y},pointwise_conv:r("MobilenetV1",l,h)}}function i(){return{conv_0:r("MobilenetV1",0,"mobilenetv1/conv_0"),conv_1:o(1),conv_2:o(2),conv_3:o(3),conv_4:o(4),conv_5:o(5),conv_6:o(6),conv_7:o(7),conv_8:o(8),conv_9:o(9),conv_10:o(10),conv_11:o(11),conv_12:o(12),conv_13:o(13)}}function a(l,c){var f=n(l+"/weights",4,c+"/filters"),d=n(l+"/biases",1,c+"/bias");return{filters:f,bias:d}}function u(l){var c=a("Prediction/BoxPredictor_"+l+"/BoxEncodingPredictor","prediction_layer/box_predictor_"+l+"/box_encoding_predictor"),f=a("Prediction/BoxPredictor_"+l+"/ClassPredictor","prediction_layer/box_predictor_"+l+"/class_predictor");return{box_encoding_predictor:c,class_predictor:f}}function s(){return{conv_0:r("Prediction",0,"prediction_layer/conv_0"),conv_1:r("Prediction",1,"prediction_layer/conv_1"),conv_2:r("Prediction",2,"prediction_layer/conv_2"),conv_3:r("Prediction",3,"prediction_layer/conv_3"),conv_4:r("Prediction",4,"prediction_layer/conv_4"),conv_5:r("Prediction",5,"prediction_layer/conv_5"),conv_6:r("Prediction",6,"prediction_layer/conv_6"),conv_7:r("Prediction",7,"prediction_layer/conv_7"),box_predictor_0:u(0),box_predictor_1:u(1),box_predictor_2:u(2),box_predictor_3:u(3),box_predictor_4:u(4),box_predictor_5:u(5)}}return{extractMobilenetV1Params:i,extractPredictionLayerParams:s}}function RR(e){var t=[],n=kR(e,t),r=n.extractMobilenetV1Params,o=n.extractPredictionLayerParams,i=e["Output/extra_dim"];if(t.push({originalPath:"Output/extra_dim",paramPath:"output_layer/extra_dim"}),!Ks(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 dr(e,t),{params:a,paramMappings:t}}function In(e,t,n){return X(function(){var r=un(e,t.filters,n,"same");return r=de(r,t.batch_norm_offset),Nd(r,0,6)})}var IR=.0010000000474974513;function DR(e,t,n){return X(function(){var r=$s(e,t.filters,n,"same");return r=q0(r,t.batch_norm_mean,t.batch_norm_variance,t.batch_norm_offset,t.batch_norm_scale,IR),Nd(r,0,6)})}function TR(e){return[2,4,6,12].some(function(t){return t===e})?[2,2]:[1,1]}function NR(e,t){return X(function(){var n=null,r=In(e,t.conv_0,[2,2]),o=[t.conv_1,t.conv_2,t.conv_3,t.conv_4,t.conv_5,t.conv_6,t.conv_7,t.conv_8,t.conv_9,t.conv_10,t.conv_11,t.conv_12,t.conv_13];if(o.forEach(function(i,a){var u=a+1,s=TR(u);r=DR(r,i.depthwise_conv,s),r=In(r,i.pointwise_conv,[1,1]),u===11&&(n=r)}),n===null)throw new Error("mobileNetV1 - output of conv layer 11 is null");return{out:r,conv11:n}})}function AR(e,t,n,r,o){var i=e.shape[0],a=Math.min(n,i),u=t.map(function(c,f){return{score:c,boxIndex:f}}).filter(function(c){return c.score>o}).sort(function(c,f){return f.score-c.score}),s=function(c){return c<=r?1:0},l=[];return u.forEach(function(c){if(!(l.length>=a)){for(var f=c.score,d=l.length-1;d>=0;--d){var h=PR(e,c.boxIndex,l[d]);if(h!==0&&(c.score*=s(h),c.score<=o))break}f===c.score&&l.push(c.boxIndex)}}),l}function PR(e,t,n){var r=e.arraySync(),o=Math.min(r[t][0],r[t][2]),i=Math.min(r[t][1],r[t][3]),a=Math.max(r[t][0],r[t][2]),u=Math.max(r[t][1],r[t][3]),s=Math.min(r[n][0],r[n][2]),l=Math.min(r[n][1],r[n][3]),c=Math.max(r[n][0],r[n][2]),f=Math.max(r[n][1],r[n][3]),d=(a-o)*(u-i),h=(c-s)*(f-l);if(d<=0||h<=0)return 0;var p=Math.max(o,s),m=Math.max(i,l),g=Math.min(a,c),v=Math.min(u,f),y=Math.max(g-p,0)*Math.max(v-m,0);return y/(d+h-y)}function FR(e){var t=Qe(zr(e,[1,0])),n=[Ze(t[2],t[0]),Ze(t[3],t[1])],r=[de(t[0],pn(n[0],K(2))),de(t[1],pn(n[1],K(2)))];return{sizes:n,centers:r}}function MR(e,t){var n=FR(e),r=n.sizes,o=n.centers,i=Qe(zr(t,[1,0])),a=pn(xt(pf(pn(i[2],K(5))),r[0]),K(2)),u=de(xt(pn(i[0],K(10)),r[0]),o[0]),s=pn(xt(pf(pn(i[3],K(5))),r[1]),K(2)),l=de(xt(pn(i[1],K(10)),r[1]),o[1]);return zr(Gt([Ze(u,a),Ze(l,s),de(u,a),de(l,s)]),[1,0])}function OR(e,t,n){return X(function(){var r=e.shape[0],o=MR(vn(ti(n.extra_dim,[r,1,1]),[-1,4]),vn(e,[-1,4]));o=vn(o,[r,o.shape[0]/r,4]);var i=$0(Wn(t,[0,0,1],[-1,-1,-1])),a=Wn(i,[0,0,0],[-1,-1,1]);a=vn(a,[r,a.shape[1]]);var u=Qe(o),s=Qe(a);return{boxes:u,scores:s}})}function No(e,t){return X(function(){var n=e.shape[0],r=vn(yn(e,t.box_encoding_predictor),[n,-1,1,4]),o=vn(yn(e,t.class_predictor),[n,-1,3]);return{boxPredictionEncoding:r,classPrediction:o}})}function BR(e,t,n){return X(function(){var r=In(e,n.conv_0,[1,1]),o=In(r,n.conv_1,[2,2]),i=In(o,n.conv_2,[1,1]),a=In(i,n.conv_3,[2,2]),u=In(a,n.conv_4,[1,1]),s=In(u,n.conv_5,[2,2]),l=In(s,n.conv_6,[1,1]),c=In(l,n.conv_7,[2,2]),f=No(t,n.box_predictor_0),d=No(e,n.box_predictor_1),h=No(o,n.box_predictor_2),p=No(a,n.box_predictor_3),m=No(s,n.box_predictor_4),g=No(c,n.box_predictor_5),v=Ye([f.boxPredictionEncoding,d.boxPredictionEncoding,h.boxPredictionEncoding,p.boxPredictionEncoding,m.boxPredictionEncoding,g.boxPredictionEncoding],1),y=Ye([f.classPrediction,d.classPrediction,h.classPrediction,p.classPrediction,m.classPrediction,g.classPrediction],1);return{boxPredictions:v,classPredictions:y}})}var Zs=function(){function e(t){var n=t===void 0?{}:t,r=n.minConfidence,o=n.maxResults;if(this._name="SsdMobilenetv1Options",this._minConfidence=r||.5,this._maxResults=o||100,typeof this._minConfidence!="number"||this._minConfidence<=0||this._minConfidence>=1)throw new Error(this._name+" - expected minConfidence to be a number between 0 and 1");if(typeof this._maxResults!="number")throw new Error(this._name+" - expected maxResults to be a number")}return Object.defineProperty(e.prototype,"minConfidence",{get:function(){return this._minConfidence},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maxResults",{get:function(){return this._maxResults},enumerable:!0,configurable:!0}),e}(),t1=function(e){ue(t,e);function t(){return e.call(this,"SsdMobilenetv1")||this}return t.prototype.forwardInput=function(n){var r=this.params;if(!r)throw new Error("SsdMobilenetv1 - load model before inference");return X(function(){var o=n.toBatchTensor(512,!1).toFloat(),i=Ze(xt(o,K(.007843137718737125)),K(1)),a=NR(i,r.mobilenetv1),u=BR(a.out,a.conv11,r.prediction_layer),s=u.boxPredictions,l=u.classPredictions;return OR(s,l,r.output_layer)})},t.prototype.forward=function(n){return te(this,void 0,void 0,function(){var r;return ne(this,function(o){switch(o.label){case 0:return r=this.forwardInput,[4,it(n)];case 1:return[2,r.apply(this,[o.sent()])]}})})},t.prototype.locateFaces=function(n,r){return r===void 0&&(r={}),te(this,void 0,void 0,function(){var o,i,a,u,s,l,c,f,d,h,p,m,g,v,y,x,w,b,C,_,E;return ne(this,function(R){switch(R.label){case 0:return o=new Zs(r),i=o.maxResults,a=o.minConfidence,[4,it(n)];case 1:for(u=R.sent(),s=this.forwardInput(u),l=s.boxes,c=s.scores,f=l[0],d=c[0],h=1;h1)throw new Error("config.iouThreshold has to be a number between [0, 1], have: "+e.iouThreshold);if(!Array.isArray(e.classes)||!e.classes.length||!e.classes.every(function(t){return typeof t=="string"}))throw new Error("config.classes has to be an array class names: string[], have: "+JSON.stringify(e.classes));if(!Array.isArray(e.anchors)||!e.anchors.length||!e.anchors.map(function(t){return t||{}}).every(function(t){return pu(t.x)&&pu(t.y)}))throw new Error("config.anchors has to be an array of { x: number, y: number }, have: "+JSON.stringify(e.anchors));if(e.meanRgb&&(!Array.isArray(e.meanRgb)||e.meanRgb.length!==3||!e.meanRgb.every(pu)))throw new Error("config.meanRgb has to be an array of shape [number, number, number], have: "+JSON.stringify(e.meanRgb))}function sh(e){return X(function(){var t=xt(e,K(.10000000149011612));return de(Me(Ze(e,t)),t)})}function mr(e,t){return X(function(){var n=wo(e,[[0,0],[1,1],[1,1],[0,0]]);return n=un(n,t.conv.filters,[1,1],"valid"),n=Ze(n,t.bn.sub),n=xt(n,t.bn.truediv),n=de(n,t.conv.bias),sh(n)})}function gr(e,t){return X(function(){var n=wo(e,[[0,0],[1,1],[1,1],[0,0]]);return n=Md(n,t.depthwise_filter,t.pointwise_filter,[1,1],"valid"),n=de(n,t.bias),sh(n)})}function jR(e,t){var n=Qs(e,t);function r(a,u){var s=Ge(e(a)),l=Ge(e(a));return t.push({paramPath:u+"/sub"},{paramPath:u+"/truediv"}),{sub:s,truediv:l}}function o(a,u,s){var l=n(a,u,3,s+"/conv"),c=r(u,s+"/bn");return{conv:l,bn:c}}var i=rh(e,t);return{extractConvParams:n,extractConvWithBatchNormParams:o,extractSeparableConvParams:i}}function GR(e,t,n,r){var o=hr(e),i=o.extractWeights,a=o.getRemainingWeights,u=[],s=jR(i,u),l=s.extractConvParams,c=s.extractConvWithBatchNormParams,f=s.extractSeparableConvParams,d;if(t.withSeparableConvs){var h=r[0],p=r[1],m=r[2],g=r[3],v=r[4],y=r[5],x=r[6],w=r[7],b=r[8],C=t.isFirstLayerConv2d?l(h,p,3,"conv0"):f(h,p,"conv0"),_=f(p,m,"conv1"),E=f(m,g,"conv2"),R=f(g,v,"conv3"),k=f(v,y,"conv4"),T=f(y,x,"conv5"),N=w?f(x,w,"conv6"):void 0,W=b?f(w,b,"conv7"):void 0,L=l(b||w||x,5*n,1,"conv8");d={conv0:C,conv1:_,conv2:E,conv3:R,conv4:k,conv5:T,conv6:N,conv7:W,conv8:L}}else{var h=r[0],p=r[1],m=r[2],g=r[3],v=r[4],y=r[5],x=r[6],w=r[7],b=r[8],C=c(h,p,"conv0"),_=c(p,m,"conv1"),E=c(m,g,"conv2"),R=c(g,v,"conv3"),k=c(v,y,"conv4"),T=c(y,x,"conv5"),N=c(x,w,"conv6"),W=c(w,b,"conv7"),L=l(b,5*n,1,"conv8");d={conv0:C,conv1:_,conv2:E,conv3:R,conv4:k,conv5:T,conv6:N,conv7:W,conv8:L}}if(a().length!==0)throw new Error("weights remaing after extract: "+a().length);return{params:d,paramMappings:u}}function qR(e,t){var n=Gr(e,t);function r(u){var s=n(u+"/sub",1),l=n(u+"/truediv",1);return{sub:s,truediv:l}}function o(u){var s=n(u+"/filters",4),l=n(u+"/bias",1);return{filters:s,bias:l}}function i(u){var s=o(u+"/conv"),l=r(u+"/bn");return{conv:s,bn:l}}var a=oh(n);return{extractConvParams:o,extractConvWithBatchNormParams:i,extractSeparableConvParams:a}}function KR(e,t){var n=[],r=qR(e,n),o=r.extractConvParams,i=r.extractConvWithBatchNormParams,a=r.extractSeparableConvParams,u;if(t.withSeparableConvs){var s=t.filterSizes&&t.filterSizes.length||9;u={conv0:t.isFirstLayerConv2d?o("conv0"):a("conv0"),conv1:a("conv1"),conv2:a("conv2"),conv3:a("conv3"),conv4:a("conv4"),conv5:a("conv5"),conv6:s>7?a("conv6"):void 0,conv7:s>8?a("conv7"):void 0,conv8:o("conv8")}}else u={conv0:i("conv0"),conv1:i("conv1"),conv2:i("conv2"),conv3:i("conv3"),conv4:i("conv4"),conv5:i("conv5"),conv6:i("conv6"),conv7:i("conv7"),conv8:o("conv8")};return dr(e,n),{params:u,paramMappings:n}}var Nv;(function(e){e[e.XS=224]="XS",e[e.SM=320]="SM",e[e.MD=416]="MD",e[e.LG=608]="LG"})(Nv||(Nv={}));var lh=function(){function e(t){var n=t===void 0?{}:t,r=n.inputSize,o=n.scoreThreshold;if(this._name="TinyYolov2Options",this._inputSize=r||416,this._scoreThreshold=o||.5,typeof this._inputSize!="number"||this._inputSize%32!==0)throw new Error(this._name+" - expected inputSize to be a number divisible by 32");if(typeof this._scoreThreshold!="number"||this._scoreThreshold<=0||this._scoreThreshold>=1)throw new Error(this._name+" - expected scoreThreshold to be a number between 0 and 1")}return Object.defineProperty(e.prototype,"inputSize",{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scoreThreshold",{get:function(){return this._scoreThreshold},enumerable:!0,configurable:!0}),e}(),n1=function(e){ue(t,e);function t(n){var r=e.call(this,"TinyYolov2")||this;return HR(n),r._config=n,r}return Object.defineProperty(t.prototype,"config",{get:function(){return this._config},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"withClassScores",{get:function(){return this.config.withClassScores||this.config.classes.length>1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"boxEncodingSize",{get:function(){return 5+(this.withClassScores?this.config.classes.length:0)},enumerable:!0,configurable:!0}),t.prototype.runTinyYolov2=function(n,r){var o=mr(n,r.conv0);return o=tt(o,[2,2],[2,2],"same"),o=mr(o,r.conv1),o=tt(o,[2,2],[2,2],"same"),o=mr(o,r.conv2),o=tt(o,[2,2],[2,2],"same"),o=mr(o,r.conv3),o=tt(o,[2,2],[2,2],"same"),o=mr(o,r.conv4),o=tt(o,[2,2],[2,2],"same"),o=mr(o,r.conv5),o=tt(o,[2,2],[1,1],"same"),o=mr(o,r.conv6),o=mr(o,r.conv7),yn(o,r.conv8,"valid",!1)},t.prototype.runMobilenet=function(n,r){var o=this.config.isFirstLayerConv2d?sh(yn(n,r.conv0,"valid",!1)):gr(n,r.conv0);return o=tt(o,[2,2],[2,2],"same"),o=gr(o,r.conv1),o=tt(o,[2,2],[2,2],"same"),o=gr(o,r.conv2),o=tt(o,[2,2],[2,2],"same"),o=gr(o,r.conv3),o=tt(o,[2,2],[2,2],"same"),o=gr(o,r.conv4),o=tt(o,[2,2],[2,2],"same"),o=gr(o,r.conv5),o=tt(o,[2,2],[1,1],"same"),o=r.conv6?gr(o,r.conv6):o,o=r.conv7?gr(o,r.conv7):o,yn(o,r.conv8,"valid",!1)},t.prototype.forwardInput=function(n,r){var o=this,i=this.params;if(!i)throw new Error("TinyYolov2 - load model before inference");return X(function(){var a=n.toBatchTensor(r,!1).toFloat();return a=o.config.meanRgb?Ba(a,o.config.meanRgb):a,a=a.div(K(256)),o.config.withSeparableConvs?o.runMobilenet(a,i):o.runTinyYolov2(a,i)})},t.prototype.forward=function(n,r){return te(this,void 0,void 0,function(){var o;return ne(this,function(i){switch(i.label){case 0:return o=this.forwardInput,[4,it(n)];case 1:return[4,o.apply(this,[i.sent(),r])];case 2:return[2,i.sent()]}})})},t.prototype.detect=function(n,r){return r===void 0&&(r={}),te(this,void 0,void 0,function(){var o,i,a,u,s,l,c,f,d,h,p,m,g,v,y=this;return ne(this,function(x){switch(x.label){case 0:return o=new lh(r),i=o.inputSize,a=o.scoreThreshold,[4,it(n)];case 1:return u=x.sent(),[4,this.forwardInput(u,i)];case 2:return s=x.sent(),l=X(function(){return Qe(s)[0].expandDims()}),c={width:u.getInputWidth(0),height:u.getInputHeight(0)},[4,this.extractBoxes(l,u.getReshapedInputDimensions(0),a)];case 3:return f=x.sent(),s.dispose(),l.dispose(),d=f.map(function(w){return w.box}),h=f.map(function(w){return w.score}),p=f.map(function(w){return w.classScore}),m=f.map(function(w){return y.config.classes[w.label]}),g=ba(d.map(function(w){return w.rescale(i)}),h,this.config.iouThreshold,!0),v=g.map(function(w){return new Ry(h[w],p[w],m[w],d[w],c)}),[2,v]}})})},t.prototype.getDefaultModelName=function(){return""},t.prototype.extractParamsFromWeigthMap=function(n){return KR(n,this.config)},t.prototype.extractParams=function(n){var r=this.config.filterSizes||t.DEFAULT_FILTER_SIZES,o=r?r.length:void 0;if(o!==7&&o!==8&&o!==9)throw new Error("TinyYolov2 - expected 7 | 8 | 9 convolutional filters, but found "+o+" filterSizes in config");return GR(n,this.config,this.boxEncodingSize,r)},t.prototype.extractBoxes=function(n,r,o){return te(this,void 0,void 0,function(){var i,a,u,s,l,c,f,d,h,p,m,g,v,y,x,w,b,C,_,E,R,k,T,N,W,L,U,$,V,P=this;return ne(this,function(M){switch(M.label){case 0:return i=r.width,a=r.height,u=Math.max(i,a),s=u/i,l=u/a,c=n.shape[1],f=this.config.anchors.length,d=X(function(){var B=n.reshape([c,c,f,P.boxEncodingSize]),G=B.slice([0,0,0,0],[c,c,f,4]),q=B.slice([0,0,0,4],[c,c,f,1]),re=P.withClassScores?lr(B.slice([0,0,0,5],[c,c,f,P.config.classes.length]),3):K(0);return[G,q,re]}),h=d[0],p=d[1],m=d[2],g=[],[4,p.array()];case 1:return v=M.sent(),[4,h.array()];case 2:y=M.sent(),x=0,M.label=3;case 3:if(!(xo?(_=(w+nc(y[x][w][b][0]))/c*s,E=(x+nc(y[x][w][b][1]))/c*l,R=Math.exp(y[x][w][b][2])*this.config.anchors[b].x/c*s,k=Math.exp(y[x][w][b][3])*this.config.anchors[b].y/c*l,T=_-R/2,N=E-k/2,W={row:x,col:w,anchor:b},this.withClassScores?[4,this.extractPredictedClass(m,W)]:[3,7]):[3,9]):[3,10];case 6:return V=M.sent(),[3,8];case 7:V={classScore:1,label:0},M.label=8;case 8:L=V,U=L.classScore,$=L.label,g.push(mt({box:new Xs(T,N,T+R,N+k),score:C,classScore:C*U,label:$},W)),M.label=9;case 9:return b++,[3,5];case 10:return w++,[3,4];case 11:return x++,[3,3];case 12:return h.dispose(),p.dispose(),m.dispose(),[2,g]}})})},t.prototype.extractPredictedClass=function(n,r){return te(this,void 0,void 0,function(){var o,i,a,u;return ne(this,function(s){switch(s.label){case 0:return o=r.row,i=r.col,a=r.anchor,[4,n.array()];case 1:return u=s.sent(),[2,Array(this.config.classes.length).fill(0).map(function(l,c){return u[o][i][a][c]}).map(function(l,c){return{classScore:l,label:c}}).reduce(function(l,c){return l.classScore>c.classScore?l:c})]}})})},t.DEFAULT_FILTER_SIZES=[3,16,32,64,128,256,512,1024,1024],t}(fr),XR=function(e){ue(t,e);function t(n){n===void 0&&(n=!0);var r=this,o=Object.assign({},{withSeparableConvs:n,iouThreshold:LR,classes:["face"]},n?{anchors:zR,meanRgb:UR}:{anchors:WR,withClassScores:!0});return r=e.call(this,o)||this,r}return 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(n,r){return te(this,void 0,void 0,function(){var o;return ne(this,function(i){switch(i.label){case 0:return[4,this.detect(n,r)];case 1:return o=i.sent(),[2,o.map(function(a){return new Kt(a.score,a.relativeBox,{width:a.imageWidth,height:a.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return this.withSeparableConvs?$R:VR},t.prototype.extractParamsFromWeigthMap=function(n){return e.prototype.extractParamsFromWeigthMap.call(this,n)},t}(n1),r1=function(e){ue(t,e);function t(){var n=e!==null&&e.apply(this,arguments)||this;return n._name="TinyFaceDetectorOptions",n}return t}(lh),La=function(){function e(){}return e.prototype.then=function(t){return te(this,void 0,void 0,function(){var n;return ne(this,function(r){switch(r.label){case 0:return n=t,[4,this.run()];case 1:return[2,n.apply(void 0,[r.sent()])]}})})},e.prototype.run=function(){return te(this,void 0,void 0,function(){return ne(this,function(t){throw new Error("ComposableTask - run is not implemented")})})},e}();function el(e,t,n,r,o){return o===void 0&&(o=function(i){var a=i.alignedRect;return a}),te(this,void 0,void 0,function(){var i,a,u,s,l;return ne(this,function(c){switch(c.label){case 0:return i=e.map(function(f){return ah(f)?o(f):f.detection}),u=r,u?[3,5]:t instanceof Fe?[4,th(t,i)]:[3,2];case 1:return s=c.sent(),[3,4];case 2:return[4,eh(t,i)];case 3:s=c.sent(),c.label=4;case 4:u=s,c.label=5;case 5:return a=u,[4,n(a)];case 6:return l=c.sent(),a.forEach(function(f){return f instanceof Fe&&f.dispose()}),[2,l]}})})}function ch(e,t,n,r,o){return te(this,void 0,void 0,function(){var i=this;return ne(this,function(a){return[2,el([e],t,function(u){return te(i,void 0,void 0,function(){return ne(this,function(s){return[2,n(u[0])]})})},r,o)]})})}function YR(e){return X(function(){return Gt(Qe(e,3).reverse(),3)})}var vu=2,bs=12;function QR(e,t){var n=Qs(e,t),r=nh(e,t);function o(l,c){var f=Ge(e(l));return t.push({paramPath:c}),f}function i(l,c,f){f===void 0&&(f=!1);var d=n(l[0],l[1],3,c+"/conv1"),h=o(l[1],c+"/prelu1_alpha"),p=n(l[1],l[2],3,c+"/conv2"),m=o(l[2],c+"/prelu2_alpha"),g=n(l[2],l[3],f?2:3,c+"/conv3"),v=o(l[3],c+"/prelu3_alpha");return{conv1:d,prelu1_alpha:h,conv2:p,prelu2_alpha:m,conv3:g,prelu3_alpha:v}}function a(){var l=i([3,10,16,32],"pnet"),c=n(32,2,1,"pnet/conv4_1"),f=n(32,4,1,"pnet/conv4_2");return mt(mt({},l),{conv4_1:c,conv4_2:f})}function u(){var l=i([3,28,48,64],"rnet",!0),c=r(576,128,"rnet/fc1"),f=o(128,"rnet/prelu4_alpha"),d=r(128,2,"rnet/fc2_1"),h=r(128,4,"rnet/fc2_2");return mt(mt({},l),{fc1:c,prelu4_alpha:f,fc2_1:d,fc2_2:h})}function s(){var l=i([3,32,64,64],"onet"),c=n(64,128,2,"onet/conv4"),f=o(128,"onet/prelu4_alpha"),d=r(1152,256,"onet/fc1"),h=o(256,"onet/prelu5_alpha"),p=r(256,2,"onet/fc2_1"),m=r(256,4,"onet/fc2_2"),g=r(256,10,"onet/fc2_3");return mt(mt({},l),{conv4:c,prelu4_alpha:f,fc1:d,prelu5_alpha:h,fc2_1:p,fc2_2:m,fc2_3:g})}return{extractPNetParams:a,extractRNetParams:u,extractONetParams:s}}function JR(e){var t=hr(e),n=t.extractWeights,r=t.getRemainingWeights,o=[],i=QR(n,o),a=i.extractPNetParams,u=i.extractRNetParams,s=i.extractONetParams,l=a(),c=u(),f=s();if(r().length!==0)throw new Error("weights remaing after extract: "+r().length);return{params:{pnet:l,rnet:c,onet:f},paramMappings:o}}function ZR(e,t){var n=Gr(e,t);function r(c){var f=n(c+"/weights",4,c+"/filters"),d=n(c+"/bias",1);return{filters:f,bias:d}}function o(c){var f=n(c+"/weights",2),d=n(c+"/bias",1);return{weights:f,bias:d}}function i(c){return n(c,1)}function a(c){var f=r(c+"/conv1"),d=i(c+"/prelu1_alpha"),h=r(c+"/conv2"),p=i(c+"/prelu2_alpha"),m=r(c+"/conv3"),g=i(c+"/prelu3_alpha");return{conv1:f,prelu1_alpha:d,conv2:h,prelu2_alpha:p,conv3:m,prelu3_alpha:g}}function u(){var c=a("pnet"),f=r("pnet/conv4_1"),d=r("pnet/conv4_2");return mt(mt({},c),{conv4_1:f,conv4_2:d})}function s(){var c=a("rnet"),f=o("rnet/fc1"),d=i("rnet/prelu4_alpha"),h=o("rnet/fc2_1"),p=o("rnet/fc2_2");return mt(mt({},c),{fc1:f,prelu4_alpha:d,fc2_1:h,fc2_2:p})}function l(){var c=a("onet"),f=r("onet/conv4"),d=i("onet/prelu4_alpha"),h=o("onet/fc1"),p=i("onet/prelu5_alpha"),m=o("onet/fc2_1"),g=o("onet/fc2_2"),v=o("onet/fc2_3");return mt(mt({},c),{conv4:f,prelu4_alpha:d,fc1:h,prelu5_alpha:p,fc2_1:m,fc2_2:g,fc2_3:v})}return{extractPNetParams:u,extractRNetParams:s,extractONetParams:l}}function eI(e){var t=[],n=ZR(e,t),r=n.extractPNetParams,o=n.extractRNetParams,i=n.extractONetParams,a=r(),u=o(),s=i();return dr(e,t),{params:{pnet:a,rnet:u,onet:s},paramMappings:t}}function Cf(e,t){var n=t[0],r=t[1];return{height:Math.floor(n*e),width:Math.floor(r*e)}}function tI(e,t,n){for(var r=n[0],o=n[1],i=bs/e,a=[],u=Math.min(r,o)*i,s=0;u>=12;)a.push(i*Math.pow(t,s)),u=u*t,s+=1;return a}var fh=function(e){ue(t,e);function t(n,r,o,i){return e.call(this,{left:n,top:r,right:o,bottom:i},!0)||this}return t}(zn);function o1(e){return X(function(){return xt(Ze(e,K(127.5)),K(.0078125))})}function ai(e,t){return X(function(){return de(Me(e),xt(t,vs(Me(vs(e)))))})}function dh(e,t,n){return n===void 0&&(n=!1),X(function(){var r=yn(e,t.conv1,"valid");return r=ai(r,t.prelu1_alpha),r=tt(r,n?[2,2]:[3,3],[2,2],"same"),r=yn(r,t.conv2,"valid"),r=ai(r,t.prelu2_alpha),r=n?r:tt(r,[3,3],[2,2],"valid"),r=yn(r,t.conv3,"valid"),r=ai(r,t.prelu3_alpha),r})}function nI(e,t){return X(function(){var n=dh(e,t,!0),r=yn(n,t.conv4_1,"valid"),o=Zt(js(r,3),3),i=lr(Ze(r,o),3),a=yn(n,t.conv4_2,"valid");return{prob:i,regions:a}})}function rI(e,t){return X(function(){var n=Cf(t,e.shape.slice(1)),r=n.height,o=n.width,i=zd.resizeBilinear(e,[r,o]),a=o1(i);return zr(a,[0,2,1,3])})}function oI(e,t,n,r){for(var o=[],i=e.arraySync(),a=0;a=r&&o.push(new we(u,a));var s=o.map(function(l){var c=new Xs(Math.round((l.y*vu+1)/n),Math.round((l.x*vu+1)/n),Math.round((l.y*vu+bs)/n),Math.round((l.x*vu+bs)/n)),f=i[l.y][l.x],d=t.arraySync(),h=new fh(d[l.y][l.x][0],d[l.y][l.x][1],d[l.y][l.x][2],d[l.y][l.x][3]);return{cell:c,score:f,region:h}});return s}function iI(e,t,n,r,o){o.stage1=[];var i=t.map(function(d){return X(function(){var h={scale:d},p=rI(e,d),m=Date.now(),g=nI(p,r),v=g.prob,y=g.regions;h.pnet=Date.now()-m;var x=Qe(Qe(v,3)[1])[0],w=Qe(y)[0];return{scoresTensor:x,regionsTensor:w,scale:d,statsForScale:h}})}),a=i.map(function(d){var h=d.scoresTensor,p=d.regionsTensor,m=d.scale,g=d.statsForScale,v=oI(h,p,m,n);if(h.dispose(),p.dispose(),!v.length)return o.stage1.push(g),[];var y=Date.now(),x=ba(v.map(function(w){return w.cell}),v.map(function(w){return w.score}),.5);return g.nms=Date.now()-y,g.numBoxes=x.length,o.stage1.push(g),x.map(function(w){return v[w]})}),u=a.reduce(function(d,h){return d.concat(h)},[]),s=[],l=[];if(u.length>0){var c=Date.now(),f=ba(u.map(function(d){return d.cell}),u.map(function(d){return d.score}),.7);o.stage1_nms=Date.now()-c,l=f.map(function(d){return u[d].score}),s=f.map(function(d){return u[d]}).map(function(d){var h=d.cell,p=d.region;return new Xs(h.left+p.left*h.width,h.top+p.top*h.height,h.right+p.right*h.width,h.bottom+p.bottom*h.height).toSquare().round()})}return{boxes:s,scores:l}}function i1(e,t,n){var r=n.width,o=n.height;return te(this,void 0,void 0,function(){var i,a,u,s=this;return ne(this,function(l){switch(l.label){case 0:return i=Un(e),[4,Promise.all(t.map(function(c){return te(s,void 0,void 0,function(){var f,d,h,p,m,g,v,y;return ne(this,function(x){return f=c.padAtBorders(e.height,e.width),d=f.y,h=f.ey,p=f.x,m=f.ex,g=p-1,v=d-1,y=i.getImageData(g,v,m-g,h-v),[2,Ct.isNodejs()?Zd(y):createImageBitmap(y)]})})}))];case 1:return a=l.sent(),u=[],a.forEach(function(c){var f=Ys({width:r,height:o}),d=Un(f);d.drawImage(c,0,0,r,o);for(var h=d.getImageData(0,0,r,o).data,p=[],m=0;m1?Ye(u.map(function(w){return w.scores})):u[0].scores,f=(c=Array).from,[4,s.data()];case 2:return l=f.apply(c,[x.sent()]),s.dispose(),d=l.map(function(w,b){return{score:w,idx:b}}).filter(function(w){return w.score>n}).map(function(w){var b=w.idx;return b}),h=d.map(function(w){return t[w]}),p=d.map(function(w){return l[w]}),m=[],g=[],h.length>0&&(i=Date.now(),v=ba(h,p,.7),o.stage2_nms=Date.now()-i,y=v.map(function(w){var b=u[d[w]].regions.arraySync();return new fh(b[0][0],b[0][1],b[0][2],b[0][3])}),g=v.map(function(w){return p[w]}),m=v.map(function(w,b){return h[w].calibrate(y[b])})),u.forEach(function(w){w.regions.dispose(),w.scores.dispose()}),[2,{boxes:m,scores:g}]}})})}function sI(e,t){return X(function(){var n=dh(e,t);n=tt(n,[2,2],[2,2],"same"),n=yn(n,t.conv4,"valid"),n=ai(n,t.prelu4_alpha);var r=vn(n,[n.shape[0],t.fc1.weights.shape[0]]),o=Pn(r,t.fc1),i=ai(o,t.prelu5_alpha),a=Pn(i,t.fc2_1),u=Zt(js(a,1),1),s=lr(Ze(a,u),1),l=Pn(i,t.fc2_2),c=Pn(i,t.fc2_3),f=Qe(s,1)[1];return{scores:f,regions:l,points:c}})}function lI(e,t,n,r,o){return te(this,void 0,void 0,function(){var i,a,u,s,l,c,f,d,h,p,m,g,v,y,x;return ne(this,function(w){switch(w.label){case 0:return i=Date.now(),[4,i1(e,t,{width:48,height:48})];case 1:return a=w.sent(),o.stage3_extractImagePatches=Date.now()-i,i=Date.now(),u=a.map(function(b){var C=sI(b,r);return b.dispose(),C}),o.stage3_onet=Date.now()-i,s=u.length>1?Ye(u.map(function(b){return b.scores})):u[0].scores,f=(c=Array).from,[4,s.data()];case 2:return l=f.apply(c,[w.sent()]),s.dispose(),d=l.map(function(b,C){return{score:b,idx:C}}).filter(function(b){return b.score>n}).map(function(b){var C=b.idx;return C}),h=d.map(function(b){var C=u[b].regions.arraySync();return new fh(C[0][0],C[0][1],C[0][2],C[0][3])}),p=d.map(function(b,C){return t[b].calibrate(h[C])}),m=d.map(function(b){return l[b]}),g=[],v=[],y=[],p.length>0&&(i=Date.now(),x=ba(p,m,.7,!1),o.stage3_nms=Date.now()-i,g=x.map(function(b){return p[b]}),v=x.map(function(b){return m[b]}),y=x.map(function(b,C){return Array(5).fill(0).map(function(_,E){var R=u[b].points.arraySync();return new we(R[0][E]*(g[C].width+1)+g[C].left,R[0][E+5]*(g[C].height+1)+g[C].top)})})),u.forEach(function(b){b.regions.dispose(),b.scores.dispose(),b.points.dispose()}),[2,{boxes:g,scores:v,points:y}]}})})}var cI=function(e){ue(t,e);function t(){return e.call(this,"Mtcnn")||this}return t.prototype.load=function(n){return te(this,void 0,void 0,function(){return ne(this,function(r){return console.warn("mtcnn is deprecated and will be removed soon"),[2,e.prototype.load.call(this,n)]})})},t.prototype.loadFromDisk=function(n){return te(this,void 0,void 0,function(){return ne(this,function(r){return console.warn("mtcnn is deprecated and will be removed soon"),[2,e.prototype.loadFromDisk.call(this,n)]})})},t.prototype.forwardInput=function(n,r){return r===void 0&&(r={}),te(this,void 0,void 0,function(){var o,i,a,u,s,l,c,f,d,h,p,m,g,v,y,x,w,b,C,_,E;return ne(this,function(R){switch(R.label){case 0:if(o=this.params,!o)throw new Error("Mtcnn - load model before inference");if(i=n.canvases[0],!i)throw new Error("Mtcnn - inputCanvas is not defined, note that passing tensors into Mtcnn.forwardInput is not supported yet.");return a={},u=Date.now(),s=X(function(){return YR(Zt(Gd.fromPixels(i)).toFloat())}),l=function(k){return s.dispose(),a.total=Date.now()-u,k},c=s.shape.slice(1),f=c[0],d=c[1],h=new e1(r),p=h.minFaceSize,m=h.scaleFactor,g=h.maxNumScales,v=h.scoreThresholds,y=h.scaleSteps,x=(y||tI(p,m,[f,d])).filter(function(k){var T=Cf(k,[f,d]);return Math.min(T.width,T.height)>bs}).slice(0,g),a.scales=x,a.pyramid=x.map(function(k){return Cf(k,[f,d])}),w=Date.now(),[4,iI(s,x,v[0],o.pnet,a)];case 1:return b=R.sent(),a.total_stage1=Date.now()-w,b.boxes.length?(a.stage2_numInputBoxes=b.boxes.length,w=Date.now(),[4,uI(i,b.boxes,v[1],o.rnet,a)]):[2,l({results:[],stats:a})];case 2:return C=R.sent(),a.total_stage2=Date.now()-w,C.boxes.length?(a.stage3_numInputBoxes=C.boxes.length,w=Date.now(),[4,lI(i,C.boxes,v[2],o.onet,a)]):[2,l({results:[],stats:a})];case 3:return _=R.sent(),a.total_stage3=Date.now()-w,E=_.boxes.map(function(k,T){return Js(_a({},new Kt(_.scores[T],new Xd(k.left/d,k.top/f,k.width/d,k.height/f),{height:f,width:d})),new Mk(_.points[T].map(function(N){return N.sub(new we(k.left,k.top)).div(new we(k.width,k.height))}),{width:k.width,height:k.height}))}),[2,l({results:E,stats:a})]}})})},t.prototype.forward=function(n,r){return r===void 0&&(r={}),te(this,void 0,void 0,function(){var o;return ne(this,function(i){switch(i.label){case 0:return o=this.forwardInput,[4,it(n)];case 1:return[4,o.apply(this,[i.sent(),r])];case 2:return[2,i.sent().results]}})})},t.prototype.forwardWithStats=function(n,r){return r===void 0&&(r={}),te(this,void 0,void 0,function(){var o;return ne(this,function(i){switch(i.label){case 0:return o=this.forwardInput,[4,it(n)];case 1:return[2,o.apply(this,[i.sent(),r])]}})})},t.prototype.getDefaultModelName=function(){return"mtcnn_model"},t.prototype.extractParamsFromWeigthMap=function(n){return eI(n)},t.prototype.extractParams=function(n){return JR(n)},t}(fr),fI=.4,dI=[new we(1.603231,2.094468),new we(6.041143,7.080126),new we(2.882459,3.518061),new we(4.266906,5.178857),new we(9.041765,10.66308)],hI=[117.001,114.697,97.404],pI=function(e){ue(t,e);function t(){var n=this,r={withSeparableConvs:!0,iouThreshold:fI,classes:["face"],anchors:dI,meanRgb:hI,isFirstLayerConv2d:!0,filterSizes:[3,16,32,64,128,256,512]};return n=e.call(this,r)||this,n}return Object.defineProperty(t.prototype,"anchors",{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),t.prototype.locateFaces=function(n,r){return te(this,void 0,void 0,function(){var o;return ne(this,function(i){switch(i.label){case 0:return[4,this.detect(n,r)];case 1:return o=i.sent(),[2,o.map(function(a){return new Kt(a.score,a.relativeBox,{width:a.imageWidth,height:a.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return"tiny_face_detector_model"},t.prototype.extractParamsFromWeigthMap=function(n){return e.prototype.extractParamsFromWeigthMap.call(this,n)},t}(n1),wt={ssdMobilenetv1:new t1,tinyFaceDetector:new pI,tinyYolov2:new XR,mtcnn:new cI,faceLandmark68Net:new Ky,faceLandmark68TinyNet:new mR,faceRecognitionNet:new _R,faceExpressionNet:new Jk,ageGenderNet:new dR},a1=function(e){ue(t,e);function t(n,r,o){var i=e.call(this)||this;return i.parentTask=n,i.input=r,i.extractedFaces=o,i}return t}(La),hh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r,o=this;return ne(this,function(i){switch(i.label){case 0:return[4,this.parentTask];case 1:return n=i.sent(),[4,el(n,this.input,function(a){return te(o,void 0,void 0,function(){return ne(this,function(u){switch(u.label){case 0:return[4,Promise.all(a.map(function(s){return wt.faceExpressionNet.predictExpressions(s)}))];case 1:return[2,u.sent()]}})})},this.extractedFaces)];case 2:return r=i.sent(),[2,n.map(function(a,u){return jy(a,r[u])})]}})})},t.prototype.withAgeAndGender=function(){return new gh(this,this.input)},t}(a1),ph=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r;return ne(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return n=o.sent(),n?[4,ch(n,this.input,function(i){return wt.faceExpressionNet.predictExpressions(i)},this.extractedFaces)]:[2];case 2:return r=o.sent(),[2,jy(n,r)]}})})},t.prototype.withAgeAndGender=function(){return new yh(this,this.input)},t}(a1),vh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new xh(this,this.input)},t.prototype.withFaceDescriptors=function(){return new bh(this,this.input)},t}(hh),mh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new wh(this,this.input)},t.prototype.withFaceDescriptor=function(){return new Ch(this,this.input)},t}(ph),u1=function(e){ue(t,e);function t(n,r,o){var i=e.call(this)||this;return i.parentTask=n,i.input=r,i.extractedFaces=o,i}return t}(La),gh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r,o=this;return ne(this,function(i){switch(i.label){case 0:return[4,this.parentTask];case 1:return n=i.sent(),[4,el(n,this.input,function(a){return te(o,void 0,void 0,function(){return ne(this,function(u){switch(u.label){case 0:return[4,Promise.all(a.map(function(s){return wt.ageGenderNet.predictAgeAndGender(s)}))];case 1:return[2,u.sent()]}})})},this.extractedFaces)];case 2:return r=i.sent(),[2,n.map(function(a,u){var s=r[u],l=s.age,c=s.gender,f=s.genderProbability;return Jy(Zy(a,c,f),l)})]}})})},t.prototype.withFaceExpressions=function(){return new hh(this,this.input)},t}(u1),yh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r,o,i,a;return ne(this,function(u){switch(u.label){case 0:return[4,this.parentTask];case 1:return n=u.sent(),n?[4,ch(n,this.input,function(s){return wt.ageGenderNet.predictAgeAndGender(s)},this.extractedFaces)]:[2];case 2:return r=u.sent(),o=r.age,i=r.gender,a=r.genderProbability,[2,Jy(Zy(n,i,a),o)]}})})},t.prototype.withFaceExpressions=function(){return new ph(this,this.input)},t}(u1),xh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new vh(this,this.input)},t.prototype.withFaceDescriptors=function(){return new bh(this,this.input)},t}(gh),wh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new mh(this,this.input)},t.prototype.withFaceDescriptor=function(){return new Ch(this,this.input)},t}(yh),s1=function(e){ue(t,e);function t(n,r){var o=e.call(this)||this;return o.parentTask=n,o.input=r,o}return t}(La),bh=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r;return ne(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return n=o.sent(),[4,el(n,this.input,function(i){return Promise.all(i.map(function(a){return wt.faceRecognitionNet.computeFaceDescriptor(a)}))},null,function(i){return i.landmarks.align(null,{useDlibAlignment:!0})})];case 2:return r=o.sent(),[2,r.map(function(i,a){return Qy(n[a],i)})]}})})},t.prototype.withFaceExpressions=function(){return new vh(this,this.input)},t.prototype.withAgeAndGender=function(){return new xh(this,this.input)},t}(s1),Ch=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r;return ne(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return n=o.sent(),n?[4,ch(n,this.input,function(i){return wt.faceRecognitionNet.computeFaceDescriptor(i)},null,function(i){return i.landmarks.align(null,{useDlibAlignment:!0})})]:[2];case 2:return r=o.sent(),[2,Qy(n,r)]}})})},t.prototype.withFaceExpressions=function(){return new mh(this,this.input)},t.prototype.withAgeAndGender=function(){return new wh(this,this.input)},t}(s1),l1=function(e){ue(t,e);function t(n,r,o){var i=e.call(this)||this;return i.parentTask=n,i.input=r,i.useTinyLandmarkNet=o,i}return Object.defineProperty(t.prototype,"landmarkNet",{get:function(){return this.useTinyLandmarkNet?wt.faceLandmark68TinyNet:wt.faceLandmark68Net},enumerable:!0,configurable:!0}),t}(La),vI=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r,o,i,a,u=this;return ne(this,function(s){switch(s.label){case 0:return[4,this.parentTask];case 1:return n=s.sent(),r=n.map(function(l){return l.detection}),this.input instanceof Fe?[4,th(this.input,r)]:[3,3];case 2:return i=s.sent(),[3,5];case 3:return[4,eh(this.input,r)];case 4:i=s.sent(),s.label=5;case 5:return o=i,[4,Promise.all(o.map(function(l){return u.landmarkNet.detectLandmarks(l)}))];case 6:return a=s.sent(),o.forEach(function(l){return l instanceof Fe&&l.dispose()}),[2,n.map(function(l,c){return Js(l,a[c])})]}})})},t.prototype.withFaceExpressions=function(){return new vh(this,this.input)},t.prototype.withAgeAndGender=function(){return new xh(this,this.input)},t.prototype.withFaceDescriptors=function(){return new bh(this,this.input)},t}(l1),mI=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r,o,i,a;return ne(this,function(u){switch(u.label){case 0:return[4,this.parentTask];case 1:return n=u.sent(),n?(r=n.detection,this.input instanceof Fe?[4,th(this.input,[r])]:[3,3]):[2];case 2:return i=u.sent(),[3,5];case 3:return[4,eh(this.input,[r])];case 4:i=u.sent(),u.label=5;case 5:return o=i,[4,this.landmarkNet.detectLandmarks(o[0])];case 6:return a=u.sent(),o.forEach(function(s){return s instanceof Fe&&s.dispose()}),[2,Js(n,a)]}})})},t.prototype.withFaceExpressions=function(){return new mh(this,this.input)},t.prototype.withAgeAndGender=function(){return new wh(this,this.input)},t.prototype.withFaceDescriptor=function(){return new Ch(this,this.input)},t}(l1),c1=function(e){ue(t,e);function t(n,r){r===void 0&&(r=new Zs);var o=e.call(this)||this;return o.input=n,o.options=r,o}return t}(La),gI=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r,o,i;return ne(this,function(a){switch(a.label){case 0:return n=this,r=n.input,o=n.options,o instanceof e1?[4,wt.mtcnn.forward(r,o)]:[3,2];case 1:return[2,a.sent().map(function(u){return u.detection})];case 2:if(i=o instanceof r1?function(u){return wt.tinyFaceDetector.locateFaces(u,o)}:o instanceof Zs?function(u){return wt.ssdMobilenetv1.locateFaces(u,o)}:o instanceof lh?function(u){return wt.tinyYolov2.locateFaces(u,o)}:null,!i)throw new Error("detectFaces - expected options to be instance of TinyFaceDetectorOptions | SsdMobilenetv1Options | MtcnnOptions | TinyYolov2Options");return[2,i(r)]}})})},t.prototype.runAndExtendWithFaceDetections=function(){var n=this;return new Promise(function(r){return te(n,void 0,void 0,function(){var o;return ne(this,function(i){switch(i.label){case 0:return[4,this.run()];case 1:return o=i.sent(),[2,r(o.map(function(a){return _a({},a)}))]}})})})},t.prototype.withFaceLandmarks=function(n){return n===void 0&&(n=!1),new vI(this.runAndExtendWithFaceDetections(),this.input,n)},t.prototype.withFaceExpressions=function(){return new hh(this.runAndExtendWithFaceDetections(),this.input)},t.prototype.withAgeAndGender=function(){return new gh(this.runAndExtendWithFaceDetections(),this.input)},t}(c1),yI=function(e){ue(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return te(this,void 0,void 0,function(){var n,r;return ne(this,function(o){switch(o.label){case 0:return[4,new gI(this.input,this.options)];case 1:return n=o.sent(),r=n[0],n.forEach(function(i){i.score>r.score&&(r=i)}),[2,r]}})})},t.prototype.runAndExtendWithFaceDetection=function(){var n=this;return new Promise(function(r){return te(n,void 0,void 0,function(){var o;return ne(this,function(i){switch(i.label){case 0:return[4,this.run()];case 1:return o=i.sent(),[2,r(o?_a({},o):void 0)]}})})})},t.prototype.withFaceLandmarks=function(n){return n===void 0&&(n=!1),new mI(this.runAndExtendWithFaceDetection(),this.input,n)},t.prototype.withFaceExpressions=function(){return new ph(this.runAndExtendWithFaceDetection(),this.input)},t.prototype.withAgeAndGender=function(){return new yh(this.runAndExtendWithFaceDetection(),this.input)},t}(c1);function xI(e,t){return t===void 0&&(t=new Zs),new yI(e,t)}function wI(e,t){if(e.length!==t.length)throw new Error("euclideanDistance: arr1.length !== arr2.length");var n=Array.from(e),r=Array.from(t);return Math.sqrt(n.map(function(o,i){return o-r[i]}).reduce(function(o,i){return o+Math.pow(i,2)},0))}(function(){function e(t,n){n===void 0&&(n=.6),this._distanceThreshold=n;var r=Array.isArray(t)?t:[t];if(!r.length)throw new Error("FaceRecognizer.constructor - expected atleast one input");var o=1,i=function(){return"person "+o++};this._labeledDescriptors=r.map(function(a){if(a instanceof fu)return a;if(a instanceof Float32Array)return new fu(i(),[a]);if(a.descriptor&&a.descriptor instanceof Float32Array)return new fu(i(),[a.descriptor]);throw new Error("FaceRecognizer.constructor - expected inputs to be of type LabeledFaceDescriptors | WithFaceDescriptor | Float32Array | Array | Float32Array>")})}return Object.defineProperty(e.prototype,"labeledDescriptors",{get:function(){return this._labeledDescriptors},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"distanceThreshold",{get:function(){return this._distanceThreshold},enumerable:!0,configurable:!0}),e.prototype.computeMeanDistance=function(t,n){return n.map(function(r){return wI(r,t)}).reduce(function(r,o){return r+o},0)/(n.length||1)},e.prototype.matchDescriptor=function(t){var n=this;return this.labeledDescriptors.map(function(r){var o=r.descriptors,i=r.label;return new Rv(i,n.computeMeanDistance(t,o))}).reduce(function(r,o){return r.distance{ln[t]=!ln[t]});qr(this,"loadModels",async()=>{await Promise.all([wt.tinyFaceDetector.loadFromUri(mu),wt.faceLandmark68Net.loadFromUri(mu),wt.faceRecognitionNet.loadFromUri(mu),wt.faceExpressionNet.loadFromUri(mu)])});qr(this,"play",()=>{const{video:t,canvas:n}=this.elements;!t||!n||(qk(n,this.display.size),setInterval(async()=>{const r=await xI(t,new r1).withFaceLandmarks().withFaceExpressions();if(!r)return;const o=n.getContext("2d"),i=f1(r,this.display.size);if(!o||!i)return{};o.clearRect(0,0,n.width,n.height),ln!=null&&ln.detectionBox&&zk(n,i),ln!=null&&ln.faceLandmark&&rR(n,i),ln!=null&&ln.expressions&&eR(n,i)},100))});qr(this,"init",async()=>{try{const{video:t,canvas:n}=this.elements;if(!t||!n)return;await this.loadModels(),this.play()}catch(t){console.log("### error",t)}});if(!t||!n)throw new Error("configuração inválida");this.elements=t,this.display=n}}const ic={width:600,height:600,facingMode:"user"};function CI(){const[e,t]=Jn.useState([]),n=Jn.useRef(null),r=Jn.useRef(null),o=Jn.useRef(null),i=a=>t(u=>{const s=[...u];return s.includes(a)?s.filter(l=>l!==a):[...u,a]});return Jn.useEffect(()=>{var a;o.current=new bI({elements:{video:((a=n.current)==null?void 0:a.video)??null,canvas:r.current},display:{size:{...ic}}}),o.current.init().then()},[]),cn.jsxs("div",{className:"container",children:[cn.jsxs("div",{className:"display-wrapper",children:[cn.jsx(qw,{id:"webcam",ref:n,autoPlay:!0,audio:!1,screenshotFormat:"image/jpeg",videoConstraints:ic}),cn.jsx("canvas",{ref:r,id:"overlay",className:e.join(" "),style:{...ic}})]}),cn.jsxs("div",{className:"options-wrapper",children:[cn.jsx("button",{onClick:()=>i("show-background"),children:"Mostrar background do canvas"}),cn.jsx("button",{onClick:()=>{var a;return(a=o.current)==null?void 0:a.switchShowConfigByKey("detectionBox")},children:"Mostrar caixa de detecção"}),cn.jsx("button",{onClick:()=>{var a;return(a=o.current)==null?void 0:a.switchShowConfigByKey("faceLandmark")},children:"Mostrar linhas do rosto"}),cn.jsx("button",{onClick:()=>{var a;return(a=o.current)==null?void 0:a.switchShowConfigByKey("expressions")},children:"Mostrar expressões"})]})]})}ac.createRoot(document.getElementById("root")).render(cn.jsx(M1.StrictMode,{children:cn.jsx(CI,{})}))});export default _I(); diff --git a/index.html b/index.html index cf284cc..05ed3fa 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@ content="html, css, javaScript, react, reactjs, typescript, react-webcam, face-api.js, faceapi"> Reconhecimento facial - +