alphavalid-sdk 0.0.6 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3801,4 +3801,4 @@ Manifest JSON has weights with names: `+s.join(`, `)+`.`);return l=t.reduce((fun
3801
3801
  Actual: `+c+`.
3802
3802
  Expected: `+l+`.`);for(var u=0;u<l.length;++u){var d=c[u],f=l[u];if(!n(d,f))throw Error(`Arrays differ: actual[`+u+`] = `+d+`, expected[`+u+`] = `+f+`.
3803
3803
  Actual: `+c+`.
3804
- Expected: `+l+`.`)}}function qf(e,t,n){return!isFinite(e)&&!isFinite(t)||!(isNaN(e)||isNaN(t)||Math.abs(e-t)>n)}Object.freeze({TEST_EPSILON_FLOAT16:Wf,expectArraysClose:function(e,t,n){return n??=Gf(),Kf(e,t,(function(e,t){return qf(e,t,n)}))},testEpsilon:Gf,expectPromiseToFail:function(e,t){e().then((function(){return t.fail()}),(function(){return t()}))},expectArraysEqual:function(e,t){var n=typeof t==`string`||typeof t==`number`||typeof t==`boolean`?[t]:t;return de(e)||de(e[0])||de(t)||de(t[0])?Kf(e,n,(function(e,t){return e==t})):Kf(e,t,(function(e,t){return qf(e,t,0)}))},expectNumbersClose:function(e,t,n){if(n??=Gf(),!qf(e,t,n))throw Error(`Numbers differ: actual === `+e+`, expected === `+t)},expectValuesInRange:function(e,t,n){for(var r=0;r<e.length;r++)if(e[r]<t||e[r]>n)throw Error(`Value out of range:`+e[r]+` low: `+t+`, high: `+n)},expectArrayBuffersEqual:function(e,t){expect(new Float32Array(e)).toEqual(new Float32Array(t))}}),Object.freeze({gpgpu_util:_o,webgl_util:on,forceHalfFloat:function(){p().set(`WEBGL_FORCE_F16_TEXTURES`,!0)},MathBackendWebGL:Ps,setWebGLContext:lt,GPGPUContext:vo});var Jf=function(e){function t(){return e!==null&&e.apply(this,arguments)||this}return c(t,e),t.prototype.minimize=function(e,t,n){t===void 0&&(t=!1);var r=this.computeGradients(e,n),i=r.value,a=r.grads;if(n!=null){var o=n.map((function(e){return{name:e.name,tensor:a[e.name]}}));this.applyGradients(o)}else this.applyGradients(a);return cn(a),t?i:(i.dispose(),null)},Object.defineProperty(t.prototype,`iterations`,{get:function(){return this.iterations_??=0,this.iterations_},enumerable:!0,configurable:!0}),t.prototype.incrementIterations=function(){this.iterations_=this.iterations+1},t.prototype.computeGradients=function(e,t){return $r(e,t)},t.prototype.dispose=function(){this.iterations_!=null&&cn(this.iterations_)},t.prototype.saveIterations=function(){return l(this,void 0,void 0,(function(){return u(this,(function(e){return this.iterations_??=0,[2,{name:`iter`,tensor:G(this.iterations_,`int32`)}]}))}))},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){return u(this,(function(e){throw Error(`getWeights() is not implemented for this optimizer yet.`)}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){return u(this,(function(e){throw Error(`setWeights() is not implemented for this optimizer class `+this.getClassName())}))}))},t.prototype.extractIterations=function(e){return l(this,void 0,void 0,(function(){var t;return u(this,(function(n){switch(n.label){case 0:return t=this,[4,e[0].tensor.data()];case 1:return t.iterations_=n.sent()[0],[2,e.slice(1)]}}))}))},t}(Bf);Object.defineProperty(Jf,Symbol.hasInstance,{value:function(e){return e.minimize!=null&&e.computeGradients!=null&&e.applyGradients!=null}});var Yf=function(e){function t(t,n,r){r===void 0&&(r=null);var i=e.call(this)||this;return i.learningRate=t,i.rho=n,i.epsilon=r,i.accumulatedGrads=[],i.accumulatedUpdates=[],r??(i.epsilon=z.backend.epsilon()),i}return c(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=z.registeredVariables[n];t.accumulatedGrads[r]??(t.accumulatedGrads[r]={originalName:n+`/accum_grad`,variable:H((function(){return Hn(i).variable(!1)}))}),t.accumulatedUpdates[r]??(t.accumulatedUpdates[r]={originalName:n+`/accum_var`,variable:H((function(){return Hn(i).variable(!1)}))});var a=Array.isArray(e)?e[r].tensor:e[n];if(a!=null){var o=t.accumulatedGrads[r].variable,s=t.accumulatedUpdates[r].variable;H((function(){var e=o.mul(t.rho).add(a.square().mul(1-t.rho)),n=s.add(t.epsilon).sqrt().div(o.add(t.epsilon).sqrt()).mul(a),r=s.mul(t.rho).add(n.square().mul(1-t.rho));o.assign(e),s.assign(r);var c=n.mul(-t.learningRate).add(i);i.assign(c)}))}})),this.incrementIterations()},t.prototype.dispose=function(){this.accumulatedUpdates!=null&&(cn(this.accumulatedGrads.map((function(e){return e.variable}))),cn(this.accumulatedUpdates.map((function(e){return e.variable}))))},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return e=this.accumulatedGrads.concat(this.accumulatedUpdates),[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(e.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){var t;return u(this,(function(n){switch(n.label){case 0:return[4,this.extractIterations(e)];case 1:return e=n.sent(),t=e.length/2,this.accumulatedGrads=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.accumulatedUpdates=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,rho:this.rho,epsilon:this.epsilon}},t.fromConfig=function(e,t){return new e(t.learningRate,t.rho,t.epsilon)},t.className=`Adadelta`,t}(Jf);Hf(Yf);var Xf=function(e){function t(t,n){n===void 0&&(n=.1);var r=e.call(this)||this;return r.learningRate=t,r.initialAccumulatorValue=n,r.accumulatedGrads=[],r}return c(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=z.registeredVariables[n];t.accumulatedGrads[r]??(t.accumulatedGrads[r]={originalName:n+`/accumulator`,variable:H((function(){return Rn(i.shape,t.initialAccumulatorValue).variable(!1)}))});var a=Array.isArray(e)?e[r].tensor:e[n];if(a!=null){var o=t.accumulatedGrads[r].variable;H((function(){var e=o.add(a.square());o.assign(e);var n=a.div(e.add(z.backend.epsilon()).sqrt()).mul(-t.learningRate).add(i);i.assign(n)}))}})),this.incrementIterations()},t.prototype.dispose=function(){this.accumulatedGrads!=null&&cn(this.accumulatedGrads.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(this.accumulatedGrads.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){return u(this,(function(t){switch(t.label){case 0:return[4,this.extractIterations(e)];case 1:return e=t.sent(),this.accumulatedGrads=e.map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,initialAccumulatorValue:this.initialAccumulatorValue}},t.fromConfig=function(e,t){return new e(t.learningRate,t.initialAccumulatorValue)},t.className=`Adagrad`,t}(Jf);Hf(Xf);var Zf=function(e){function t(t,n,r,i){i===void 0&&(i=null);var a=e.call(this)||this;return a.learningRate=t,a.beta1=n,a.beta2=r,a.epsilon=i,a.accumulatedFirstMoment=[],a.accumulatedSecondMoment=[],H((function(){a.accBeta1=G(n).variable(),a.accBeta2=G(r).variable()})),i??(a.epsilon=z.backend.epsilon()),a}return c(t,e),t.prototype.applyGradients=function(e){var t=this,n=Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e);H((function(){var r=rl(1,t.accBeta1),i=rl(1,t.accBeta2);n.forEach((function(n,a){var o=z.registeredVariables[n];t.accumulatedFirstMoment[a]??(t.accumulatedFirstMoment[a]={originalName:n+`/m`,variable:H((function(){return Hn(o).variable(!1)}))}),t.accumulatedSecondMoment[a]??(t.accumulatedSecondMoment[a]={originalName:n+`/v`,variable:H((function(){return Hn(o).variable(!1)}))});var s=Array.isArray(e)?e[a].tensor:e[n];if(s!=null){var c=t.accumulatedFirstMoment[a].variable,l=t.accumulatedSecondMoment[a].variable,u=c.mul(t.beta1).add(s.mul(1-t.beta1)),d=l.mul(t.beta2).add(s.square().mul(1-t.beta2)),f=u.div(r),p=d.div(i);c.assign(u),l.assign(d);var m=f.div(p.sqrt().add(t.epsilon)).mul(-t.learningRate).add(o);o.assign(m)}})),t.accBeta1.assign(t.accBeta1.mul(t.beta1)),t.accBeta2.assign(t.accBeta2.mul(t.beta2))})),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.accBeta2.dispose(),this.accumulatedFirstMoment!=null&&cn(this.accumulatedFirstMoment.map((function(e){return e.variable}))),this.accumulatedSecondMoment!=null&&cn(this.accumulatedSecondMoment.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return e=this.accumulatedFirstMoment.concat(this.accumulatedSecondMoment),[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(e.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){var t,n=this;return u(this,(function(r){switch(r.label){case 0:return[4,this.extractIterations(e)];case 1:return e=r.sent(),H((function(){n.accBeta1.assign(el(n.beta1,n.iterations_+1)),n.accBeta2.assign(el(n.beta2,n.iterations_+1))})),t=e.length/2,this.accumulatedFirstMoment=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.accumulatedSecondMoment=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon}},t.fromConfig=function(e,t){return new e(t.learningRate,t.beta1,t.beta2,t.epsilon)},t.className=`Adam`,t}(Jf);Hf(Zf);var Qf=function(e){function t(t,n,r,i,a){i===void 0&&(i=null),a===void 0&&(a=0);var o=e.call(this)||this;return o.learningRate=t,o.beta1=n,o.beta2=r,o.epsilon=i,o.decay=a,o.accumulatedFirstMoment=[],o.accumulatedWeightedInfNorm=[],H((function(){o.iteration=G(0).variable(),o.accBeta1=G(n).variable()})),i??(o.epsilon=z.backend.epsilon()),o}return c(t,e),t.prototype.applyGradients=function(e){var t=this,n=Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e);H((function(){var r=rl(1,t.accBeta1),i=Hc(-t.learningRate,t.iteration.mul(t.decay).add(1));n.forEach((function(n,a){var o=z.registeredVariables[n];t.accumulatedFirstMoment[a]??(t.accumulatedFirstMoment[a]={originalName:n+`/m`,variable:Hn(o).variable(!1)}),t.accumulatedWeightedInfNorm[a]??(t.accumulatedWeightedInfNorm[a]={originalName:n+`/v`,variable:Hn(o).variable(!1)});var s=Array.isArray(e)?e[a].tensor:e[n];if(s!=null){var c=t.accumulatedFirstMoment[a].variable,l=t.accumulatedWeightedInfNorm[a].variable,u=c.mul(t.beta1).add(s.mul(1-t.beta1)),d=l.mul(t.beta2),f=s.abs(),p=d.maximum(f);c.assign(u),l.assign(p);var m=i.div(r).mul(u.div(p.add(t.epsilon))).add(o);o.assign(m)}})),t.iteration.assign(t.iteration.add(1)),t.accBeta1.assign(t.accBeta1.mul(t.beta1))})),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.iteration.dispose(),this.accumulatedFirstMoment!=null&&cn(this.accumulatedFirstMoment.map((function(e){return e.variable}))),this.accumulatedWeightedInfNorm!=null&&cn(this.accumulatedWeightedInfNorm.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){return u(this,(function(e){throw Error(`getWeights() is not implemented for Adamax yet.`)}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){return u(this,(function(e){throw Error(`setWeights() is not implemented for Adamax yet.`)}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon,decay:this.decay}},t.fromConfig=function(e,t){return new e(t.learningRate,t.beta1,t.beta2,t.epsilon,t.decay)},t.className=`Adamax`,t}(Jf);Hf(Qf);var $f=function(e){function t(t){var n=e.call(this)||this;return n.learningRate=t,n.setLearningRate(t),n}return c(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=Array.isArray(e)?e[r].tensor:e[n];if(i!=null){var a=z.registeredVariables[n];H((function(){var e=t.c.mul(i).add(a);a.assign(e)}))}})),this.incrementIterations()},t.prototype.setLearningRate=function(e){this.learningRate=e,this.c!=null&&this.c.dispose(),this.c=ln(G(-e))},t.prototype.dispose=function(){this.c.dispose()},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()]]}}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){return u(this,(function(t){switch(t.label){case 0:return[4,this.extractIterations(e)];case 1:if((e=t.sent()).length!==0)throw Error(`SGD optimizer does not have settable weights.`);return[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate}},t.fromConfig=function(e,t){return new e(t.learningRate)},t.className=`SGD`,t}(Jf);Hf($f);var ep=function(e){function t(t,n,r){r===void 0&&(r=!1);var i=e.call(this,t)||this;return i.learningRate=t,i.momentum=n,i.useNesterov=r,i.accumulations=[],i.m=G(i.momentum),i}return c(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=z.registeredVariables[n];t.accumulations[r]??(t.accumulations[r]={originalName:n+`/momentum`,variable:H((function(){return Hn(i).variable(!1)}))});var a=t.accumulations[r].variable,o=Array.isArray(e)?e[r].tensor:e[n];o!=null&&H((function(){var e,n=t.m.mul(a).add(o);e=t.useNesterov?t.c.mul(o.add(n.mul(t.m))).add(i):t.c.mul(n).add(i),a.assign(n),i.assign(e)}))})),this.incrementIterations()},t.prototype.dispose=function(){this.m.dispose(),this.accumulations!=null&&cn(this.accumulations.map((function(e){return e.variable})))},t.prototype.setMomentum=function(e){this.momentum=e},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(this.accumulations.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){return u(this,(function(t){switch(t.label){case 0:return[4,this.extractIterations(e)];case 1:return e=t.sent(),this.accumulations=e.map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,momentum:this.momentum,useNesterov:this.useNesterov}},t.fromConfig=function(e,t){return new e(t.learningRate,t.momentum,t.useNesterov)},t.className=`Momentum`,t}($f);Hf(ep);var tp=function(e){function t(t,n,r,i,a){n===void 0&&(n=.9),r===void 0&&(r=0),i===void 0&&(i=null),a===void 0&&(a=!1);var o=e.call(this)||this;if(o.learningRate=t,o.decay=n,o.momentum=r,o.epsilon=i,o.accumulatedMeanSquares=[],o.accumulatedMoments=[],o.accumulatedMeanGrads=[],o.centered=a,i??(o.epsilon=z.backend.epsilon()),t==null)throw Error(`learningRate for RMSPropOptimizer must be defined.`);return o}return c(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=z.registeredVariables[n];t.accumulatedMeanSquares[r]??(t.accumulatedMeanSquares[r]={originalName:n+`/rms`,variable:H((function(){return Hn(i).variable(!1)}))}),t.accumulatedMoments[r]??(t.accumulatedMoments[r]={originalName:n+`/momentum`,variable:H((function(){return Hn(i).variable(!1)}))}),t.accumulatedMeanGrads[r]==null&&t.centered&&(t.accumulatedMeanGrads[r]={originalName:n+`/mg`,variable:H((function(){return Hn(i).variable(!1)}))});var a=Array.isArray(e)?e[r].tensor:e[n];if(a!=null){var o=t.accumulatedMeanSquares[r].variable,s=t.accumulatedMoments[r].variable;H((function(){var e=o.mul(t.decay).add(a.square().mul(1-t.decay));if(t.centered){var n=t.accumulatedMeanGrads[r].variable,c=n.mul(t.decay).add(a.mul(1-t.decay)),l=s.mul(t.momentum).add(a.mul(t.learningRate).div(e.sub(c.square().add(t.epsilon)).sqrt()));o.assign(e),n.assign(c),s.assign(l);var u=i.sub(l);i.assign(u)}else{var d=o.mul(t.decay).add(a.square().mul(1-t.decay));l=s.mul(t.momentum).add(a.mul(t.learningRate).div(d.add(t.epsilon).sqrt())),o.assign(d),s.assign(l),u=i.sub(l),i.assign(u)}}))}})),this.incrementIterations()},t.prototype.dispose=function(){this.accumulatedMeanSquares!=null&&cn(this.accumulatedMeanSquares.map((function(e){return e.variable}))),this.accumulatedMeanGrads!=null&&this.centered&&cn(this.accumulatedMeanGrads.map((function(e){return e.variable}))),this.accumulatedMoments!=null&&cn(this.accumulatedMoments.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return e=this.accumulatedMeanSquares.concat(this.accumulatedMoments),this.centered&&e.push.apply(e,this.accumulatedMeanGrads),[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(e.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){var t;return u(this,(function(n){switch(n.label){case 0:return[4,this.extractIterations(e)];case 1:return e=n.sent(),t=this.centered?e.length/3:e.length/2,this.accumulatedMeanSquares=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.accumulatedMoments=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.centered&&(this.accumulatedMeanGrads=e.slice(2*t,3*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}}))),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,decay:this.decay,momentum:this.momentum,epsilon:this.epsilon,centered:this.centered}},t.fromConfig=function(e,t){return new e(t.learningRate,t.decay,t.momentum,t.epsilon,t.centered)},t.className=`RMSProp`,t}(Jf);Hf(tp);var np=function(){function e(){}return e.sgd=function(e){return new $f(e)},e.momentum=function(e,t,n){return n===void 0&&(n=!1),new ep(e,t,n)},e.rmsprop=function(e,t,n,r,i){return t===void 0&&(t=.9),n===void 0&&(n=0),r===void 0&&(r=null),i===void 0&&(i=!1),new tp(e,t,n,r,i)},e.adam=function(e,t,n,r){return e===void 0&&(e=.001),t===void 0&&(t=.9),n===void 0&&(n=.999),r===void 0&&(r=null),new Zf(e,t,n,r)},e.adadelta=function(e,t,n){return e===void 0&&(e=.001),t===void 0&&(t=.95),n===void 0&&(n=null),new Yf(e,t,n)},e.adamax=function(e,t,n,r,i){return e===void 0&&(e=.002),t===void 0&&(t=.9),n===void 0&&(n=.999),r===void 0&&(r=null),i===void 0&&(i=0),new Qf(e,t,n,r,i)},e.adagrad=function(e,t){return t===void 0&&(t=.1),new Xf(e,t)},e}();np.sgd,np.momentum,np.adadelta,np.adagrad,np.rmsprop,np.adamax,np.adam,Be.prototype.squaredDifference=function(e){return Ls(this,e)},R=wd;function rp(e,t,n){if(n===void 0&&(n=!1),e.beginPath(),t.slice(1).forEach(function(n,r){var i=n.x,a=n.y,o=t[r];e.moveTo(o.x,o.y),e.lineTo(i,a)}),n){var r=t[t.length-1],i=t[0];if(!r||!i)return;e.moveTo(r.x,r.y),e.lineTo(i.x,i.y)}e.stroke()}var ip=function(e,t){return ip=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])},ip(e,t)};function Z(e,t){ip(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}var ap=function(){return ap=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},ap.apply(this,arguments)};function Q(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})}function $(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(o){if(r)throw TypeError(`Generator is already executing.`);for(;n;)try{if(r=1,i&&(a=o[0]&2?i.return:o[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,o[1])).done)return a;switch(i=0,a&&(o=[o[0]&2,a.value]),o[0]){case 0:case 1:a=o;break;case 4:return n.label++,{value:o[1],done:!1};case 5:n.label++,i=o[1],o=[0];continue;case 7:o=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(o[0]===6||o[0]===2)){n=0;continue}if(o[0]===3&&(!a||o[1]>a[0]&&o[1]<a[3])){n.label=o[1];break}if(o[0]===6&&n.label<a[1]){n.label=a[1],a=o;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(o);break}a[2]&&n.ops.pop(),n.trys.pop();continue}o=t.call(e,n)}catch(e){o=[6,e],i=0}finally{r=a=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}}function op(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var r=Array(e),i=0,t=0;t<n;t++)for(var a=arguments[t],o=0,s=a.length;o<s;o++,i++)r[i]=a[o];return r}var sp=function(){function e(e,t){if(!yp(e)||!yp(t))throw Error(`Dimensions.constructor - expected width and height to be valid numbers, instead have `+JSON.stringify({width:e,height:t}));this._width=e,this._height=t}return Object.defineProperty(e.prototype,`width`,{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`height`,{get:function(){return this._height},enumerable:!0,configurable:!0}),e.prototype.reverse=function(){return new e(1/this.width,1/this.height)},e}();function cp(e,t){return e instanceof Be&&e.shape.length===t}function lp(e){return cp(e,2)}function up(e){return cp(e,3)}function dp(e){return cp(e,4)}function fp(e){return e%1!=0}function pp(e){return e%2==0}function mp(e,t){t===void 0&&(t=2);var n=10**t;return Math.floor(e*n)/n}function hp(e){return e&&e.width&&e.height}function gp(e,t){var n=e.width,r=e.height,i=t/Math.max(r,n);return new sp(Math.round(n*i),Math.round(r*i))}function _p(e){return e.reduce(function(e,t){return e.add(t)},new xp(0,0)).div(new xp(e.length,e.length))}function vp(e,t,n){return Array(e).fill(0).map(function(e,r){return t+r*n})}function yp(e){return!!e&&e!==1/0&&e!==-1/0&&!isNaN(e)||e===0}function bp(e){return yp(e)&&0<=e&&e<=1}var xp=function(){function e(e,t){this._x=e,this._y=t}return Object.defineProperty(e.prototype,`x`,{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`y`,{get:function(){return this._y},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return new e(this.x+t.x,this.y+t.y)},e.prototype.sub=function(t){return new e(this.x-t.x,this.y-t.y)},e.prototype.mul=function(t){return new e(this.x*t.x,this.y*t.y)},e.prototype.div=function(t){return new e(this.x/t.x,this.y/t.y)},e.prototype.abs=function(){return new e(Math.abs(this.x),Math.abs(this.y))},e.prototype.magnitude=function(){return Math.sqrt(this.x**2+this.y**2)},e.prototype.floor=function(){return new e(Math.floor(this.x),Math.floor(this.y))},e}(),Sp=function(){function e(t,n){n===void 0&&(n=!0);var r=t||{},i=[r.left,r.top,r.right,r.bottom].every(yp),a=[r.x,r.y,r.width,r.height].every(yp);if(!a&&!i)throw Error(`Box.constructor - expected box to be IBoundingBox | IRect, instead have `+JSON.stringify(r));var o=a?[r.x,r.y,r.width,r.height]:[r.left,r.top,r.right-r.left,r.bottom-r.top],s=o[0],c=o[1],l=o[2],u=o[3];e.assertIsValidBox({x:s,y:c,width:l,height:u},`Box.constructor`,n),this._x=s,this._y=c,this._width=l,this._height=u}return e.isRect=function(e){return!!e&&[e.x,e.y,e.width,e.height].every(yp)},e.assertIsValidBox=function(t,n,r){if(r===void 0&&(r=!1),!e.isRect(t))throw Error(n+` - invalid box: `+JSON.stringify(t)+`, expected object with properties x, y, width, height`);if(!r&&(t.width<0||t.height<0))throw Error(n+` - width (`+t.width+`) and height (`+t.height+`) must be positive numbers`)},Object.defineProperty(e.prototype,`x`,{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`y`,{get:function(){return this._y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`width`,{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`height`,{get:function(){return this._height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`left`,{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`top`,{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`right`,{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottom`,{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`area`,{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`topLeft`,{get:function(){return new xp(this.left,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`topRight`,{get:function(){return new xp(this.right,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottomLeft`,{get:function(){return new xp(this.left,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottomRight`,{get:function(){return new xp(this.right,this.bottom)},enumerable:!0,configurable:!0}),e.prototype.round=function(){var t=[this.x,this.y,this.width,this.height].map(function(e){return Math.round(e)}),n=t[0],r=t[1],i=t[2],a=t[3];return new e({x:n,y:r,width:i,height:a})},e.prototype.floor=function(){var t=[this.x,this.y,this.width,this.height].map(function(e){return Math.floor(e)}),n=t[0],r=t[1],i=t[2],a=t[3];return new e({x:n,y:r,width:i,height:a})},e.prototype.toSquare=function(){var t=this,n=t.x,r=t.y,i=t.width,a=t.height,o=Math.abs(i-a);return i<a&&(n-=o/2,i+=o),a<i&&(r-=o/2,a+=o),new e({x:n,y:r,width:i,height:a})},e.prototype.rescale=function(t){var n=hp(t)?t.width:t,r=hp(t)?t.height:t;return new e({x:this.x*n,y:this.y*r,width:this.width*n,height:this.height*r})},e.prototype.pad=function(t,n){var r=[this.x-t/2,this.y-n/2,this.width+t,this.height+n],i=r[0],a=r[1],o=r[2],s=r[3];return new e({x:i,y:a,width:o,height:s})},e.prototype.clipAtImageBorders=function(t,n){var r=this,i=r.x,a=r.y,o=r.right,s=r.bottom,c=Math.max(i,0),l=Math.max(a,0),u=o-c,d=s-l;return new e({x:c,y:l,width:Math.min(u,t-c),height:Math.min(d,n-l)}).floor()},e.prototype.shift=function(t,n){var r=this,i=r.width,a=r.height;return new e({x:this.x+t,y:this.y+n,width:i,height:a})},e.prototype.padAtBorders=function(e,t){var n=this.width+1,r=this.height+1,i=1,a=1,o=n,s=r,c=this.left,l=this.top,u=this.right,d=this.bottom;return u>t&&(o=-u+t+n,u=t),d>e&&(s=-d+e+r,d=e),c<1&&(s=2-c,c=1),l<1&&(s=2-l,l=1),{dy:a,edy:s,dx:i,edx:o,y:l,ey:d,x:c,ex:u,w:n,h:r}},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}(),Cp=function(e){Z(t,e);function t(t,n,r,i,a){return a===void 0&&(a=!1),e.call(this,{left:t,top:n,right:r,bottom:i},a)||this}return t}(Sp),wp=function(){function e(e,t,n,r,i){this._imageDims=new sp(i.width,i.height),this._score=e,this._classScore=t,this._className=n,this._box=new Sp(r).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 Sp(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}(),Tp=function(e){Z(t,e);function t(t,n,r){return e.call(this,t,t,``,n,r)||this}return t.prototype.forSize=function(n,r){var i=e.prototype.forSize.call(this,n,r),a=i.score,o=i.relativeBox,s=i.imageDims;return new t(a,o,s)},t}(wp);function Ep(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))*Math.max(0,Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top));return n?r/(e.area+t.area-r):r/Math.min(e.area,t.area)}function Dp(e){var t=e.map(function(e){return e.x}),n=e.map(function(e){return e.y});return new Cp(t.reduce(function(e,t){return t<e?t:e},1/0),n.reduce(function(e,t){return t<e?t:e},1/0),t.reduce(function(e,t){return e<t?t:e},0),n.reduce(function(e,t){return e<t?t:e},0))}function Op(e,t,n,r){r===void 0&&(r=!0);for(var i=t.map(function(e,t){return{score:e,boxIndex:t}}).sort(function(e,t){return e.score-t.score}).map(function(e){return e.boxIndex}),a=[],o=function(){var t=i.pop();a.push(t);for(var o=i,s=[],c=0;c<o.length;c++){var l=o[c],u=e[t],d=e[l];s.push(Ep(u,d,r))}i=i.filter(function(e,t){return s[t]<=n})};i.length>0;)o();return a}function kp(e,t){return H(function(){var n=t[0],r=t[1],i=t[2];return rl(e,Un([Rn(op(e.shape.slice(0,3),[1]),n),Rn(op(e.shape.slice(0,3),[1]),r),Rn(op(e.shape.slice(0,3),[1]),i)],3))})}function Ap(e,t){return t===void 0&&(t=!1),H(function(){var n=e.shape.slice(1),r=n[0],i=n[1];if(r===i)return e;var a=Math.abs(r-i),o=Math.round(a*(t?.5:1)),s=r>i?2:1,c=function(t){var n=e.shape.slice();return n[s]=t,Rn(n,0)},l=c(o),u=a-l.shape[s];return Un([t&&u?c(u):null,e,l].filter(function(e){return!!e}).map(function(e){return e.toFloat()}),s)})}function jp(e){return 1/(1+Math.exp(-e))}var Mp=function(e){Z(t,e);function t(t,n,r,i,a){return a===void 0&&(a=!1),e.call(this,{x:t,y:n,width:r,height:i},a)||this}return t}(Sp),Np=.5,Pp=.43,Fp=.45,Ip=function(){function e(e,t,n){n===void 0&&(n=new xp(0,0));var r=t.width,i=t.height;this._imgDims=new sp(r,i),this._shift=n,this._positions=e.map(function(e){return e.mul(new xp(r,i)).add(n)})}return Object.defineProperty(e.prototype,`shift`,{get:function(){return new xp(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 e=this;return this._positions.map(function(t){return t.sub(e._shift).div(new xp(e.imageWidth,e.imageHeight))})},enumerable:!0,configurable:!0}),e.prototype.forSize=function(e,t){return new this.constructor(this.relativePositions,{width:e,height:t})},e.prototype.shiftBy=function(e,t){return new this.constructor(this.relativePositions,this._imgDims,new xp(e,t))},e.prototype.shiftByPoint=function(e){return this.shiftBy(e.x,e.y)},e.prototype.align=function(e,t){if(t===void 0&&(t={}),e){var n=e instanceof Tp?e.box.floor():new Sp(e);return this.shiftBy(n.x,n.y).align(null,t)}var r=Object.assign({},{useDlibAlignment:!1,minBoxPadding:.2},t),i=r.useDlibAlignment,a=r.minBoxPadding;return i?this.alignDlib():this.alignMinBbox(a)},e.prototype.alignDlib=function(){var e=this.getRefPointsForAlignment(),t=e[0],n=e[1],r=e[2],i=function(e){return r.sub(e).magnitude()},a=(i(t)+i(n))/2,o=Math.floor(a/Fp),s=_p(e),c=Math.floor(Math.max(0,s.x-Np*o)),l=Math.floor(Math.max(0,s.y-Pp*o));return new Mp(c,l,Math.min(o,this.imageWidth+c),Math.min(o,this.imageHeight+l))},e.prototype.alignMinBbox=function(e){var t=Dp(this.positions);return t.pad(t.width*e,t.height*e)},e.prototype.getRefPointsForAlignment=function(){throw Error(`getRefPointsForAlignment not implemented by base class`)},e}(),Lp=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.getRefPointsForAlignment=function(){var e=this.positions;return[e[0],e[1],_p([e[3],e[4]])]},t}(Ip),Rp=function(e){Z(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(_p)},t}(Ip),zp=function(){function e(e,t){this._label=e,this._distance=t}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(e){return e===void 0&&(e=!0),``+this.label+(e?` (`+mp(this.distance)+`)`:``)},e}(),Bp=function(e){Z(t,e);function t(t,n){var r=e.call(this,t)||this;return r._label=n,r}return t.assertIsValidLabeledBox=function(e,t){if(Sp.assertIsValidBox(e,t),!yp(e.label))throw Error(t+` - expected property label (`+e.label+`) to be a number`)},Object.defineProperty(t.prototype,`label`,{get:function(){return this._label},enumerable:!0,configurable:!0}),t}(Sp),Vp=function(){function e(e,t){if(typeof e!=`string`)throw Error(`LabeledFaceDescriptors - constructor expected label to be a string`);if(!Array.isArray(t)||t.some(function(e){return!(e instanceof Float32Array)}))throw Error(`LabeledFaceDescriptors - constructor expected descriptors to be an array of Float32Array`);this._label=e,this._descriptors=t}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(e){return Array.from(e)})}},e.fromJSON=function(t){var n=t.descriptors.map(function(e){return new Float32Array(e)});return new e(t.label,n)},e}();(function(e){Z(t,e);function t(t,n,r,i){var a=e.call(this,t,n)||this;return a._score=r,a._classScore=i,a}return t.assertIsValidPredictedBox=function(e,t){if(Bp.assertIsValidLabeledBox(e,t),!bp(e.score)||!bp(e.classScore))throw Error(t+` - expected properties score (`+e.score+`) and (`+e.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})(Bp);function Hp(e){return e.detection instanceof Tp}function Up(e,t){return Object.assign({},e,{detection:t})}function Wp(){var e=window.fetch||function(){throw Error(`fetch - missing fetch implementation 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:function(){throw Error(`readFile - filesystem not available for browser environment`)}}}function Gp(e){var t=``;if(!e)try{e=o()}catch(e){t=e.toString()}return{readFile:e?function(t){return new Promise(function(n,r){e.readFile(t,function(e,t){return e?r(e):n(t)})})}:function(){throw Error(`readFile - failed to require fs in nodejs environment with error: `+t)}}}function Kp(){var e=global.Canvas||global.HTMLCanvasElement,t=global.Image||global.HTMLImageElement,n=function(){if(e)return new e;throw Error(`createCanvasElement - missing Canvas implementation for nodejs environment`)},r=function(){if(t)return new t;throw Error(`createImageElement - missing Image implementation for nodejs environment`)},i=global.fetch||function(){throw Error(`fetch - missing fetch implementation for nodejs environment`)},a=Gp();return ap({Canvas:e||function(){function e(){}return e}(),CanvasRenderingContext2D:global.CanvasRenderingContext2D||function(){function e(){}return e}(),Image:t||function(){function e(){}return e}(),ImageData:global.ImageData||function(){function e(){}return e}(),Video:global.HTMLVideoElement||function(){function e(){}return e}(),createCanvasElement:n,createImageElement:r,fetch:i},a)}function qp(){return typeof window==`object`&&typeof document<`u`&&typeof HTMLImageElement<`u`&&typeof HTMLCanvasElement<`u`&&typeof HTMLVideoElement<`u`&&typeof ImageData<`u`&&typeof CanvasRenderingContext2D<`u`}function Jp(){return typeof global==`object`&&typeof require==`function`&&typeof module<`u`&&typeof process<`u`&&!!process.version}var Yp;function Xp(){if(!Yp)throw Error(`getEnv - environment is not defined, check isNodejs() and isBrowser()`);return Yp}function Zp(e){Yp=e}function Qp(){qp()&&Zp(Wp()),Jp()&&Zp(Kp())}function $p(e){if(Yp||Qp(),!Yp)throw Error(`monkeyPatch - environment is not defined, check isNodejs() and isBrowser()`);var t=e.Canvas,n=t===void 0?Yp.Canvas:t,r=e.Image,i=r===void 0?Yp.Image:r;Yp.Canvas=n,Yp.Image=i,Yp.createCanvasElement=e.createCanvasElement||(function(){return new n}),Yp.createImageElement=e.createImageElement||(function(){return new i}),Yp.ImageData=e.ImageData||Yp.ImageData,Yp.Video=e.Video||Yp.Video,Yp.fetch=e.fetch||Yp.fetch,Yp.readFile=e.readFile||Yp.readFile}var em={getEnv:Xp,setEnv:Zp,initialize:Qp,createBrowserEnv:Wp,createFileSystem:Gp,createNodejsEnv:Kp,monkeyPatch:$p,isBrowser:qp,isNodejs:Jp};Qp();function tm(e){return!em.isNodejs()&&typeof e==`string`?document.getElementById(e):e}function nm(e){var t=em.getEnv(),n=t.Canvas;if(e instanceof t.CanvasRenderingContext2D)return e;var r=tm(e);if(!(r instanceof n))throw Error(`resolveContext2d - expected canvas to be of instance of Canvas`);var i=r.getContext(`2d`);if(!i)throw Error(`resolveContext2d - canvas 2d context is null`);return i}var rm;(function(e){e.TOP_LEFT=`TOP_LEFT`,e.TOP_RIGHT=`TOP_RIGHT`,e.BOTTOM_LEFT=`BOTTOM_LEFT`,e.BOTTOM_RIGHT=`BOTTOM_RIGHT`})(rm||={});var im=function(){function e(e){e===void 0&&(e={});var t=e.anchorPosition,n=e.backgroundColor,r=e.fontColor,i=e.fontSize,a=e.fontStyle,o=e.padding;this.anchorPosition=t||rm.TOP_LEFT,this.backgroundColor=n||`rgba(0, 0, 0, 0.5)`,this.fontColor=r||`rgba(255, 255, 255, 1)`,this.fontSize=i||14,this.fontStyle=a||`Georgia`,this.padding=o||4}return e}(),am=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 im(r)}return e.prototype.measureWidth=function(e){var t=this.options.padding;return this.text.map(function(t){return e.measureText(t).width}).reduce(function(e,t){return e<t?t:e},0)+2*t},e.prototype.measureHeight=function(){var e=this.options,t=e.fontSize,n=e.padding;return this.text.length*t+2*n},e.prototype.getUpperLeft=function(e,t){var n=this.options.anchorPosition,r=n===rm.BOTTOM_RIGHT||n===rm.TOP_RIGHT,i=n===rm.BOTTOM_LEFT||n===rm.BOTTOM_RIGHT,a=this.measureWidth(e),o=this.measureHeight(),s=r?this.anchor.x-a:this.anchor.x,c=i?this.anchor.y-o:this.anchor.y;if(t){var l=t.width,u=t.height;return{x:Math.max(Math.min(s,l-a),0),y:Math.max(Math.min(c,u-o),0)}}return{x:s,y:c}},e.prototype.draw=function(e){var t=tm(e),n=nm(t),r=this.options,i=r.backgroundColor,a=r.fontColor,o=r.fontSize,s=r.fontStyle,c=r.padding;n.font=o+`px `+s;var l=this.measureWidth(n),u=this.measureHeight();n.fillStyle=i;var d=this.getUpperLeft(n,t);n.fillRect(d.x,d.y,l,u),n.fillStyle=a,this.text.forEach(function(e,t){var r=c+d.x,i=c+d.y+(t+1)*o;n.fillText(e,r,i)})},e}(),om=function(){function e(e){e===void 0&&(e={});var t=e.boxColor,n=e.lineWidth,r=e.label,i=e.drawLabelOptions;this.boxColor=t||`rgba(0, 0, 255, 1)`,this.lineWidth=n||2,this.label=r;var a={anchorPosition:rm.BOTTOM_LEFT,backgroundColor:this.boxColor};this.drawLabelOptions=new im(Object.assign({},a,i))}return e}();(function(){function e(e,t){t===void 0&&(t={}),this.box=new Sp(e),this.options=new om(t)}return e.prototype.draw=function(e){var t=nm(e),n=this.options,r=n.boxColor,i=n.lineWidth,a=this.box,o=a.x,s=a.y,c=a.width,l=a.height;t.strokeStyle=r,t.lineWidth=i,t.strokeRect(o,s,c,l);var u=this.options.label;u&&new am([u],{x:o-i/2,y:s},this.options.drawLabelOptions).draw(e)},e})();function sm(e){var t=em.getEnv(),n=t.Image,r=t.Video;return e instanceof n&&e.complete||e instanceof r&&e.readyState>=3}function cm(e){return new Promise(function(t,n){if(e instanceof em.getEnv().Canvas||sm(e))return t();function r(e){e.currentTarget&&(e.currentTarget.removeEventListener(`load`,r),e.currentTarget.removeEventListener(`error`,i),t(e))}function i(e){e.currentTarget&&(e.currentTarget.removeEventListener(`load`,r),e.currentTarget.removeEventListener(`error`,i),n(e))}e.addEventListener(`load`,r),e.addEventListener(`error`,i)})}function lm(e){var t=em.getEnv(),n=t.Image,r=t.Video;return e instanceof n?new sp(e.naturalWidth,e.naturalHeight):e instanceof r?new sp(e.videoWidth,e.videoHeight):new sp(e.width,e.height)}function um(e){var t=e.width,n=e.height,r=em.getEnv().createCanvasElement,i=r();return i.width=t,i.height=n,i}function dm(e,t){var n=em.getEnv().ImageData;if(!(e instanceof n)&&!sm(e))throw Error(`createCanvasFromMedia - media has not finished loading yet`);var r=t||lm(e),i=r.width,a=r.height,o=um({width:i,height:a});return e instanceof n?nm(o).putImageData(e,0,0):nm(o).drawImage(e,0,0,i,a),o}function fm(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a,o,s;return $(this,function(c){switch(c.label){case 0:return n=t||em.getEnv().createCanvasElement(),r=e.shape.slice(dp(e)?1:0),i=r[0],a=r[1],o=r[2],s=H(function(){return e.as3D(i,a,o).toInt()}),[4,zf.toPixels(s,n)];case 1:return c.sent(),s.dispose(),[2,n]}})})}function pm(e){var t=em.getEnv(),n=t.Image,r=t.Canvas,i=t.Video;return e instanceof n||e instanceof r||e instanceof i}function mm(e,t,n){n===void 0&&(n=!1);var r=em.getEnv(),i=r.Image,a=r.Canvas;if(!(e instanceof i||e instanceof a))throw Error(`imageToSquare - expected arg0 to be HTMLImageElement | HTMLCanvasElement`);var o=lm(e),s=t/Math.max(o.height,o.width),c=s*o.width,l=s*o.height,u=um({width:t,height:t}),d=e instanceof a?e:dm(e),f=Math.abs(c-l)/2,p=n&&c<l?f:0,m=n&&l<c?f:0;return nm(u).drawImage(d,p,m,c,l),u}var hm=function(){function e(e,t){var n=this;if(t===void 0&&(t=!1),this._imageTensors=[],this._canvases=[],this._treatAsBatchInput=!1,this._inputDimensions=[],!Array.isArray(e))throw Error(`NetInput.constructor - expected inputs to be an Array of TResolvedNetInput or to be instanceof tf.Tensor4D, instead have `+e);this._treatAsBatchInput=t,this._batchSize=e.length,e.forEach(function(e,t){if(up(e)){n._imageTensors[t]=e,n._inputDimensions[t]=e.shape;return}if(dp(e)){var r=e.shape[0];if(r!==1)throw Error(`NetInput - tf.Tensor4D with batchSize `+r+` passed, but not supported in input array`);n._imageTensors[t]=e,n._inputDimensions[t]=e.shape.slice(1);return}var i=e instanceof em.getEnv().Canvas?e:dm(e);n._canvases[t]=i,n._inputDimensions[t]=[i.height,i.width,3]})}return Object.defineProperty(e.prototype,`imageTensors`,{get:function(){return this._imageTensors},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`canvases`,{get:function(){return this._canvases},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`isBatchInput`,{get:function(){return this.batchSize>1||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 e=this;return vp(this.batchSize,0,1).map(function(t,n){return e.getReshapedInputDimensions(n)})},enumerable:!0,configurable:!0}),e.prototype.getInput=function(e){return this.canvases[e]||this.imageTensors[e]},e.prototype.getInputDimensions=function(e){return this._inputDimensions[e]},e.prototype.getInputHeight=function(e){return this._inputDimensions[e][0]},e.prototype.getInputWidth=function(e){return this._inputDimensions[e][1]},e.prototype.getReshapedInputDimensions=function(e){if(typeof this.inputSize!=`number`)throw Error(`getReshapedInputDimensions - inputSize not set, toBatchTensor has not been called yet`);return gp({width:this.getInputWidth(e),height:this.getInputHeight(e)},this.inputSize)},e.prototype.toBatchTensor=function(e,t){var n=this;return t===void 0&&(t=!0),this._inputSize=e,H(function(){return Ar(vp(n.batchSize,0,1).map(function(r){var i=n.getInput(r);if(i instanceof Be){var a=dp(i)?i:i.expandDims();return a=Ap(a,t),(a.shape[1]!==e||a.shape[2]!==e)&&(a=hd.resizeBilinear(a,[e,e])),a.as3D(e,e,3)}if(i instanceof em.getEnv().Canvas)return zf.fromPixels(mm(i,e,t));throw Error(`toBatchTensor - at batchIdx `+r+`, expected input to be instanceof tf.Tensor or instanceof HTMLCanvasElement, instead have `+i)}).map(function(e){return e.toFloat()})).as4D(n.batchSize,e,e,3)})},e}();function gm(e){return Q(this,void 0,void 0,function(){var t,n,r;return $(this,function(i){switch(i.label){case 0:if(e instanceof hm)return[2,e];if(t=Array.isArray(e)?e:[e],!t.length)throw Error(`toNetInput - empty array passed as input`);return n=function(t){return Array.isArray(e)?` at input index `+t+`:`:``},r=t.map(tm),r.forEach(function(e,r){if(!pm(e)&&!up(e)&&!dp(e))throw typeof t[r]==`string`?Error(`toNetInput -`+n(r)+` string passed, but could not resolve HTMLElement for element id `+t[r]):Error(`toNetInput -`+n(r)+` expected media to be of type HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | tf.Tensor3D, or to be an element id`);if(dp(e)){var i=e.shape[0];if(i!==1)throw Error(`toNetInput -`+n(r)+` tf.Tensor4D with batchSize `+i+` passed, but not supported in input array`)}}),[4,Promise.all(r.map(function(e){return pm(e)&&cm(e)}))];case 1:return i.sent(),[2,new hm(r,Array.isArray(e))]}})})}function _m(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c;return $(this,function(l){switch(l.label){case 0:return n=em.getEnv().Canvas,r=e,e instanceof n?[3,5]:[4,gm(e)];case 1:if(i=l.sent(),i.batchSize>1)throw Error(`extractFaces - batchSize > 1 not supported`);return a=i.getInput(0),a instanceof n?(o=a,[3,4]):[3,2];case 2:return[4,fm(a)];case 3:o=l.sent(),l.label=4;case 4:r=o,l.label=5;case 5:return s=nm(r),c=t.map(function(e){return e instanceof Tp?e.forSize(r.width,r.height).box.floor():e}).map(function(e){return e.clipAtImageBorders(r.width,r.height)}),[2,c.map(function(e){var t=e.x,n=e.y,r=e.width,i=e.height,a=um({width:r,height:i});return nm(a).putImageData(s.getImageData(t,n,r,i),0,0),a})]}})})}function vm(e,t){return Q(this,void 0,void 0,function(){return $(this,function(n){if(!up(e)&&!dp(e))throw Error(`extractFaceTensors - expected image tensor to be 3D or 4D`);if(dp(e)&&e.shape[0]>1)throw Error(`extractFaceTensors - batchSize > 1 not supported`);return[2,H(function(){var n=e.shape.slice(dp(e)?1:0),r=n[0],i=n[1],a=n[2];return t.map(function(e){return e instanceof Tp?e.forSize(i,r).box:e}).map(function(e){return e.clipAtImageBorders(i,r)}).map(function(t){var n=t.x,o=t.y,s=t.width,c=t.height;return eu(e.as3D(r,i,a),[o,n,0],[c,s,a])})})]})})}function ym(e,t){return Q(this,void 0,void 0,function(){var n,r;return $(this,function(i){switch(i.label){case 0:return n=em.getEnv().fetch,[4,n(e,t)];case 1:if(r=i.sent(),!(r.status<400))throw Error(`failed to fetch: (`+r.status+`) `+r.statusText+`, from url: `+r.url);return[2,r]}})})}function bm(e){return Q(this,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,ym(e)];case 1:return[2,t.sent().json()]}})})}function xm(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 i=e.split(`/`).filter(function(e){return e}),a=e.endsWith(`.json`)?i[i.length-1]:n,o=r+(e.endsWith(`.json`)?i.slice(0,i.length-1):i).join(`/`);return o=e.startsWith(`/`)?`/`+o:o,{modelBaseUri:o,manifestUri:o===`/`?`/`+a:o+`/`+a}}function Sm(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a;return $(this,function(o){switch(o.label){case 0:return n=xm(e,t),r=n.manifestUri,i=n.modelBaseUri,[4,bm(r)];case 1:return a=o.sent(),[2,Ff.loadWeights(a,i)]}})})}var Cm=function(){function e(e){this._name=e,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(e){var t=this.traversePropertyPath(e);return t.obj[t.objProp]},e.prototype.reassignParamFromPath=function(e,t){var n=this.traversePropertyPath(e),r=n.obj,i=n.objProp;r[i].dispose(),r[i]=t},e.prototype.getParamList=function(){var e=this;return this._paramMappings.map(function(t){var n=t.paramPath;return{path:n,tensor:e.getParamFromPath(n)}})},e.prototype.getTrainableParams=function(){return this.getParamList().filter(function(e){return e.tensor instanceof Ke})},e.prototype.getFrozenParams=function(){return this.getParamList().filter(function(e){return!(e.tensor instanceof Ke)})},e.prototype.variable=function(){var e=this;this.getFrozenParams().forEach(function(t){var n=t.path,r=t.tensor;e.reassignParamFromPath(n,r.variable())})},e.prototype.freeze=function(){var e=this;this.getTrainableParams().forEach(function(t){var n=t.path,r=t.tensor,i=Dn(r.dataSync());r.dispose(),e.reassignParamFromPath(n,i)})},e.prototype.dispose=function(e){e===void 0&&(e=!0),this.getParamList().forEach(function(t){if(e&&t.tensor.isDisposed)throw Error(`param tensor has already been disposed for path `+t.path);t.tensor.dispose()}),this._params=void 0},e.prototype.serializeParams=function(){return new Float32Array(this.getParamList().map(function(e){var t=e.tensor;return Array.from(t.dataSync())}).reduce(function(e,t){return e.concat(t)}))},e.prototype.load=function(e){return Q(this,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return e instanceof Float32Array?(this.extractWeights(e),[2]):[4,this.loadFromUri(e)];case 1:return t.sent(),[2]}})})},e.prototype.loadFromUri=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:if(e&&typeof e!=`string`)throw Error(this._name+`.loadFromUri - expected model uri`);return[4,Sm(e,this.getDefaultModelName())];case 1:return t=n.sent(),this.loadFromWeightMap(t),[2]}})})},e.prototype.loadFromDisk=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i,a,o,s,c,l,u;return $(this,function(d){switch(d.label){case 0:if(e&&typeof e!=`string`)throw Error(this._name+`.loadFromDisk - expected model file path`);return t=em.getEnv().readFile,n=xm(e,this.getDefaultModelName()),r=n.manifestUri,i=n.modelBaseUri,a=function(e){return Promise.all(e.map(function(e){return t(e).then(function(e){return e.buffer})}))},o=Ff.weightsLoaderFactory(a),l=(c=JSON).parse,[4,t(r)];case 1:return s=l.apply(c,[d.sent().toString()]),[4,o(s,i)];case 2:return u=d.sent(),this.loadFromWeightMap(u),[2]}})})},e.prototype.loadFromWeightMap=function(e){var t=this.extractParamsFromWeigthMap(e),n=t.paramMappings,r=t.params;this._paramMappings=n,this._params=r},e.prototype.extractWeights=function(e){var t=this.extractParams(e),n=t.paramMappings,r=t.params;this._paramMappings=n,this._params=r},e.prototype.traversePropertyPath=function(e){if(!this.params)throw Error(`traversePropertyPath - model has no loaded params`);var t=e.split(`/`).reduce(function(t,n){if(!t.nextObj.hasOwnProperty(n))throw Error(`traversePropertyPath - object does not have property `+n+`, for path `+e);return{obj:t.nextObj,objProp:n,nextObj:t.nextObj[n]}},{nextObj:this.params}),n=t.obj,r=t.objProp;if(!n||!r||!(n[r]instanceof Be))throw Error(`traversePropertyPath - parameter is not a tensor, for path `+e);return{obj:n,objProp:r}},e}();function wm(e,t,n){return H(function(){var r=Nl(e,t.depthwise_filter,t.pointwise_filter,n,`same`);return r=Rc(r,t.bias),r})}function Tm(e,t,n){return n===void 0&&(n=!1),H(function(){var r=_u(n?Rc(El(e,t.conv0.filters,[2,2],`same`),t.conv0.bias):wm(e,t.conv0,[2,2])),i=wm(r,t.conv1,[1,1]);return _u(Rc(r,Rc(i,wm(_u(Rc(r,i)),t.conv2,[1,1]))))})}function Em(e,t,n,r){return n===void 0&&(n=!1),r===void 0&&(r=!0),H(function(){var i=_u(n?Rc(El(e,t.conv0.filters,r?[2,2]:[1,1],`same`),t.conv0.bias):wm(e,t.conv0,r?[2,2]:[1,1])),a=wm(i,t.conv1,[1,1]),o=wm(_u(Rc(i,a)),t.conv2,[1,1]);return _u(Rc(i,Rc(a,Rc(o,wm(_u(Rc(i,Rc(a,o))),t.conv3,[1,1])))))})}function Dm(e,t,n,r){return n===void 0&&(n=`same`),r===void 0&&(r=!1),H(function(){var i=Rc(El(e,t.filters,[1,1],n),t.bias);return r?_u(i):i})}function Om(e,t){Object.keys(e).forEach(function(n){t.some(function(e){return e.originalPath===n})||e[n].dispose()})}function km(e,t){return function(n,r,i,a){var o=Mn(e(n*r*i*i),[i,i,n,r]),s=kn(e(r));return t.push({paramPath:a+`/filters`},{paramPath:a+`/bias`}),{filters:o,bias:s}}}function Am(e,t){return function(n,r,i){var a=An(e(n*r),[n,r]),o=kn(e(r));return t.push({paramPath:i+`/weights`},{paramPath:i+`/bias`}),{weights:a,bias:o}}}var jm=function(){function e(e,t,n){this.depthwise_filter=e,this.pointwise_filter=t,this.bias=n}return e}();function Mm(e,t){return function(n,r,i){var a=Mn(e(9*n),[3,3,n,1]),o=Mn(e(n*r),[1,1,n,r]),s=kn(e(r));return t.push({paramPath:i+`/depthwise_filter`},{paramPath:i+`/pointwise_filter`},{paramPath:i+`/bias`}),new jm(a,o,s)}}function Nm(e){return function(t){return new jm(e(t+`/depthwise_filter`,4),e(t+`/pointwise_filter`,4),e(t+`/bias`,1))}}function Pm(e,t){return function(n,r,i){var a=e[n];if(!cp(a,r))throw Error(`expected weightMap[`+n+`] to be a Tensor`+r+`D, instead have `+a);return t.push({originalPath:n,paramPath:i||n}),a}}function Fm(e){var t=e;function n(e){var n=t.slice(0,e);return t=t.slice(e),n}function r(){return t}return{extractWeights:n,getRemainingWeights:r}}function Im(e,t){var n=km(e,t),r=Mm(e,t);function i(e,t,i,a){return a===void 0&&(a=!1),{conv0:a?n(e,t,3,i+`/conv0`):r(e,t,i+`/conv0`),conv1:r(t,t,i+`/conv1`),conv2:r(t,t,i+`/conv2`)}}function a(e,t,n,a){a===void 0&&(a=!1);var o=i(e,t,n,a);return{conv0:o.conv0,conv1:o.conv1,conv2:o.conv2,conv3:r(t,t,n+`/conv3`)}}return{extractDenseBlock3Params:i,extractDenseBlock4Params:a}}function Lm(e){var t=[],n=Fm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Im(r,t).extractDenseBlock4Params,o=a(3,32,`dense0`,!0),s=a(32,64,`dense1`),c=a(64,128,`dense2`),l=a(128,256,`dense3`);if(i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{paramMappings:t,params:{dense0:o,dense1:s,dense2:c,dense3:l}}}function Rm(e){return function(t){return{filters:e(t+`/filters`,4),bias:e(t+`/bias`,1)}}}function zm(e,t){var n=Pm(e,t),r=Rm(n),i=Nm(n);function a(e,t){return t===void 0&&(t=!1),{conv0:t?r(e+`/conv0`):i(e+`/conv0`),conv1:i(e+`/conv1`),conv2:i(e+`/conv2`)}}function o(e,t){return t===void 0&&(t=!1),{conv0:t?r(e+`/conv0`):i(e+`/conv0`),conv1:i(e+`/conv1`),conv2:i(e+`/conv2`),conv3:i(e+`/conv3`)}}return{extractDenseBlock3Params:a,extractDenseBlock4Params:o}}function Bm(e){var t=[],n=zm(e,t).extractDenseBlock4Params,r={dense0:n(`dense0`,!0),dense1:n(`dense1`),dense2:n(`dense2`),dense3:n(`dense3`)};return Om(e,t),{params:r,paramMappings:t}}var Vm=function(e){Z(t,e);function t(){return e.call(this,`FaceFeatureExtractor`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`FaceFeatureExtractor - load model before inference`);return H(function(){var n=Em(kp(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(G(255)),t.dense0,!0);return n=Em(n,t.dense1),n=Em(n,t.dense2),n=Em(n,t.dense3),n=ql(n,[7,7],[2,2],`valid`),n})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.getDefaultModelName=function(){return`face_feature_extractor_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Bm(e)},t.prototype.extractParams=function(e){return Lm(e)},t}(Cm);function Hm(e,t){return H(function(){return Rc(Il(e,t.weights),t.bias)})}function Um(e,t,n){var r=[],i=Fm(e),a=i.extractWeights,o=i.getRemainingWeights,s=Am(a,r)(t,n,`fc`);if(o().length!==0)throw Error(`weights remaing after extract: `+o().length);return{paramMappings:r,params:{fc:s}}}function Wm(e){var t=[],n=Pm(e,t);function r(e){return{weights:n(e+`/weights`,2),bias:n(e+`/bias`,1)}}var i={fc:r(`fc`)};return Om(e,t),{params:i,paramMappings:t}}function Gm(e){var t={},n={};return Object.keys(e).forEach(function(r){var i=r.startsWith(`fc`)?n:t;i[r]=e[r]}),{featureExtractorMap:t,classifierMap:n}}var Km=function(e){Z(t,e);function t(t,n){var r=e.call(this,t)||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(e){var t=this,n=this.params;if(!n)throw Error(this._name+` - load model before inference`);return H(function(){var r=e instanceof hm?t.faceFeatureExtractor.forwardInput(e):e;return Hm(r.as2D(r.shape[0],-1),n.fc)})},t.prototype.dispose=function(t){t===void 0&&(t=!0),this.faceFeatureExtractor.dispose(t),e.prototype.dispose.call(this,t)},t.prototype.loadClassifierParams=function(e){var t=this.extractClassifierParams(e),n=t.params,r=t.paramMappings;this._params=n,this._paramMappings=r},t.prototype.extractClassifierParams=function(e){return Um(e,this.getClassifierChannelsIn(),this.getClassifierChannelsOut())},t.prototype.extractParamsFromWeigthMap=function(e){var t=Gm(e),n=t.featureExtractorMap,r=t.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(n),Wm(r)},t.prototype.extractParams=function(e){var t=this.getClassifierChannelsIn(),n=this.getClassifierChannelsOut(),r=n*t+n,i=e.slice(0,e.length-r),a=e.slice(e.length-r);return this.faceFeatureExtractor.extractWeights(i),this.extractClassifierParams(a)},t}(Cm),qm=[`neutral`,`happy`,`sad`,`angry`,`fearful`,`disgusted`,`surprised`],Jm=function(){function e(e){var t=this;if(e.length!==7)throw Error(`FaceExpressions.constructor - expected probabilities.length to be 7, have: `+e.length);qm.forEach(function(n,r){t[n]=e[r]})}return e.prototype.asSortedArray=function(){var e=this;return qm.map(function(t){return{expression:t,probability:e[t]}}).sort(function(e,t){return t.probability-e.probability})},e}(),Ym=function(e){Z(t,e);function t(t){return t===void 0&&(t=new Vm),e.call(this,`FaceExpressionNet`,t)||this}return t.prototype.forwardInput=function(e){var t=this;return H(function(){return ti(t.runNet(e))})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.predictExpressions=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i,a=this;return $(this,function(o){switch(o.label){case 0:return[4,gm(e)];case 1:return t=o.sent(),[4,this.forwardInput(t)];case 2:return n=o.sent(),[4,Promise.all(Nr(n).map(function(e){return Q(a,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return[4,e.data()];case 1:return t=n.sent(),e.dispose(),[2,t]}})})}))];case 3:return r=o.sent(),n.dispose(),i=r.map(function(e){return new Jm(e)}),[2,t.isBatchInput?i:i[0]]}})})},t.prototype.getDefaultModelName=function(){return`face_expression_model`},t.prototype.getClassifierChannelsIn=function(){return 256},t.prototype.getClassifierChannelsOut=function(){return 7},t}(Km);function Xm(e,t){return Object.assign({},e,{expressions:t})}function Zm(e){return Hp(e)&&e.landmarks instanceof Ip&&e.unshiftedLandmarks instanceof Ip&&e.alignedRect instanceof Tp}function Qm(e,t){var n=e.detection.box,r=t.shiftBy(n.x,n.y),i=r.align(),a=e.detection.imageDims,o={landmarks:r,unshiftedLandmarks:t,alignedRect:new Tp(e.detection.score,i.rescale(a.reverse()),a)};return Object.assign({},e,o)}var $m=function(){function e(e){e===void 0&&(e={});var t=e.drawLines,n=t===void 0?!0:t,r=e.drawPoints,i=r===void 0?!0:r,a=e.lineWidth,o=e.lineColor,s=e.pointSize,c=e.pointColor;this.drawLines=n,this.drawPoints=i,this.lineWidth=a||1,this.pointSize=s||2,this.lineColor=o||`rgba(0, 255, 255, 1)`,this.pointColor=c||`rgba(255, 0, 255, 1)`}return e}();(function(){function e(e,t){t===void 0&&(t={}),this.faceLandmarks=e,this.options=new $m(t)}return e.prototype.draw=function(e){var t=nm(e),n=this.options,r=n.drawLines,i=n.drawPoints,a=n.lineWidth,o=n.lineColor,s=n.pointSize,c=n.pointColor;r&&this.faceLandmarks instanceof Rp&&(t.strokeStyle=o,t.lineWidth=a,rp(t,this.faceLandmarks.getJawOutline()),rp(t,this.faceLandmarks.getLeftEyeBrow()),rp(t,this.faceLandmarks.getRightEyeBrow()),rp(t,this.faceLandmarks.getNose()),rp(t,this.faceLandmarks.getLeftEye(),!0),rp(t,this.faceLandmarks.getRightEye(),!0),rp(t,this.faceLandmarks.getMouth(),!0)),i&&(t.strokeStyle=c,t.fillStyle=c,this.faceLandmarks.positions.forEach(function(e){t.beginPath(),t.arc(e.x,e.y,s,0,2*Math.PI),t.fill()}))},e})();function eh(e,t){var n=km(e,t),r=Mm(e,t);function i(e,t,i){return{separable_conv0:r(e,t,i+`/separable_conv0`),separable_conv1:r(t,t,i+`/separable_conv1`),expansion_conv:n(e,t,1,i+`/expansion_conv`)}}function a(e,t){return{separable_conv0:r(e,e,t+`/separable_conv0`),separable_conv1:r(e,e,t+`/separable_conv1`),separable_conv2:r(e,e,t+`/separable_conv2`)}}return{extractConvParams:n,extractSeparableConvParams:r,extractReductionBlockParams:i,extractMainBlockParams:a}}function th(e,t){var n=[],r=Fm(e),i=r.extractWeights,a=r.getRemainingWeights,o=eh(i,n),s=o.extractConvParams,c=o.extractSeparableConvParams,l=o.extractReductionBlockParams,u=o.extractMainBlockParams,d={conv_in:s(3,32,3,`entry_flow/conv_in`),reduction_block_0:l(32,64,`entry_flow/reduction_block_0`),reduction_block_1:l(64,128,`entry_flow/reduction_block_1`)},f={};vp(t,0,1).forEach(function(e){f[`main_block_`+e]=u(128,`middle_flow/main_block_`+e)});var p={reduction_block:l(128,256,`exit_flow/reduction_block`),separable_conv:c(256,512,`exit_flow/separable_conv`)};if(a().length!==0)throw Error(`weights remaing after extract: `+a().length);return{paramMappings:n,params:{entry_flow:d,middle_flow:f,exit_flow:p}}}function nh(e,t){var n=Pm(e,t),r=Rm(n),i=Nm(n);function a(e){return{separable_conv0:i(e+`/separable_conv0`),separable_conv1:i(e+`/separable_conv1`),expansion_conv:r(e+`/expansion_conv`)}}function o(e){return{separable_conv0:i(e+`/separable_conv0`),separable_conv1:i(e+`/separable_conv1`),separable_conv2:i(e+`/separable_conv2`)}}return{extractConvParams:r,extractSeparableConvParams:i,extractReductionBlockParams:a,extractMainBlockParams:o}}function rh(e,t){var n=[],r=nh(e,n),i=r.extractConvParams,a=r.extractSeparableConvParams,o=r.extractReductionBlockParams,s=r.extractMainBlockParams,c={conv_in:i(`entry_flow/conv_in`),reduction_block_0:o(`entry_flow/reduction_block_0`),reduction_block_1:o(`entry_flow/reduction_block_1`)},l={};vp(t,0,1).forEach(function(e){l[`main_block_`+e]=s(`middle_flow/main_block_`+e)});var u={reduction_block:o(`exit_flow/reduction_block`),separable_conv:a(`exit_flow/separable_conv`)};return Om(e,n),{params:{entry_flow:c,middle_flow:l,exit_flow:u},paramMappings:n}}function ih(e,t,n){return Rc(El(e,t.filters,n,`same`),t.bias)}function ah(e,t,n){n===void 0&&(n=!0);var r=n?_u(e):e;return r=wm(r,t.separable_conv0,[1,1]),r=wm(_u(r),t.separable_conv1,[1,1]),r=Kl(r,[3,3],[2,2],`same`),r=Rc(r,ih(e,t.expansion_conv,[2,2])),r}function oh(e,t){var n=wm(_u(e),t.separable_conv0,[1,1]);return n=wm(_u(n),t.separable_conv1,[1,1]),n=wm(_u(n),t.separable_conv2,[1,1]),n=Rc(n,e),n}var sh=function(e){Z(t,e);function t(t){var n=e.call(this,`TinyXception`)||this;return n._numMainBlocks=t,n}return t.prototype.forwardInput=function(e){var t=this,n=this.params;if(!n)throw Error(`TinyXception - load model before inference`);return H(function(){var r=_u(ih(kp(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(G(256)),n.entry_flow.conv_in,[2,2]));return r=ah(r,n.entry_flow.reduction_block_0,!1),r=ah(r,n.entry_flow.reduction_block_1),vp(t._numMainBlocks,0,1).forEach(function(e){r=oh(r,n.middle_flow[`main_block_`+e])}),r=ah(r,n.exit_flow.reduction_block),r=_u(wm(r,n.exit_flow.separable_conv,[1,1])),r})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.getDefaultModelName=function(){return`tiny_xception_model`},t.prototype.extractParamsFromWeigthMap=function(e){return rh(e,this._numMainBlocks)},t.prototype.extractParams=function(e){return th(e,this._numMainBlocks)},t}(Cm);function ch(e){var t=[],n=Fm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Am(r,t),o=a(512,1,`fc/age`),s=a(512,2,`fc/gender`);if(i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{paramMappings:t,params:{fc:{age:o,gender:s}}}}function lh(e){var t=[],n=Pm(e,t);function r(e){return{weights:n(e+`/weights`,2),bias:n(e+`/bias`,1)}}var i={fc:{age:r(`fc/age`),gender:r(`fc/gender`)}};return Om(e,t),{params:i,paramMappings:t}}var uh;(function(e){e.FEMALE=`female`,e.MALE=`male`})(uh||={});var dh=function(e){Z(t,e);function t(t){t===void 0&&(t=new sh(2));var n=e.call(this,`AgeGenderNet`)||this;return n._faceFeatureExtractor=t,n}return Object.defineProperty(t.prototype,`faceFeatureExtractor`,{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),t.prototype.runNet=function(e){var t=this,n=this.params;if(!n)throw Error(this._name+` - load model before inference`);return H(function(){var r=e instanceof hm?t.faceFeatureExtractor.forwardInput(e):e,i=ql(r,[7,7],[2,2],`valid`).as2D(r.shape[0],-1);return{age:Hm(i,n.fc.age).as1D(),gender:Hm(i,n.fc.gender)}})},t.prototype.forwardInput=function(e){var t=this;return H(function(){var n=t.runNet(e),r=n.age,i=n.gender;return{age:r,gender:ti(i)}})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.predictAgeAndGender=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i,a,o,s=this;return $(this,function(c){switch(c.label){case 0:return[4,gm(e)];case 1:return t=c.sent(),[4,this.forwardInput(t)];case 2:return n=c.sent(),r=Nr(n.age),i=Nr(n.gender),a=r.map(function(e,t){return{ageTensor:e,genderTensor:i[t]}}),[4,Promise.all(a.map(function(e){var t=e.ageTensor,n=e.genderTensor;return Q(s,void 0,void 0,function(){var e,r,i,a,o;return $(this,function(s){switch(s.label){case 0:return[4,t.data()];case 1:return e=s.sent()[0],[4,n.data()];case 2:return r=s.sent()[0],i=r>.5,a=i?uh.MALE:uh.FEMALE,o=i?r:1-r,t.dispose(),n.dispose(),[2,{age:e,gender:a,genderProbability:o}]}})})}))];case 3:return o=c.sent(),n.age.dispose(),n.gender.dispose(),[2,t.isBatchInput?o:o[0]]}})})},t.prototype.getDefaultModelName=function(){return`age_gender_model`},t.prototype.dispose=function(t){t===void 0&&(t=!0),this.faceFeatureExtractor.dispose(t),e.prototype.dispose.call(this,t)},t.prototype.loadClassifierParams=function(e){var t=this.extractClassifierParams(e),n=t.params,r=t.paramMappings;this._params=n,this._paramMappings=r},t.prototype.extractClassifierParams=function(e){return ch(e)},t.prototype.extractParamsFromWeigthMap=function(e){var t=Gm(e),n=t.featureExtractorMap,r=t.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(n),lh(r)},t.prototype.extractParams=function(e){var t=1539,n=e.slice(0,e.length-t),r=e.slice(e.length-t);return this.faceFeatureExtractor.extractWeights(n),this.extractClassifierParams(r)},t}(Cm),fh=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.postProcess=function(e,t,n){var r=n.map(function(e){var n=e.width,r=e.height,i=t/Math.max(r,n);return{width:n*i,height:r*i}}),i=r.length;return H(function(){var n=function(e,t){return Ar([Rn([68],e),Rn([68],t)],1).as2D(1,136).as1D()},a=function(e,t){var n=r[e],i=n.width,a=n.height;return t(i,a)?Math.abs(i-a)/2:0},o=function(e){return a(e,function(e,t){return e<t})},s=function(e){return a(e,function(e,t){return t<e})};return e.mul(Rn([i,136],t)).sub(Ar(Array.from(Array(i),function(e,t){return n(o(t),s(t))}))).div(Ar(Array.from(Array(i),function(e,t){return n(r[t].width,r[t].height)})))})},t.prototype.forwardInput=function(e){var t=this;return H(function(){var n=t.runNet(e);return t.postProcess(n,e.inputSize,e.inputDimensions.map(function(e){return{height:e[0],width:e[1]}}))})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.detectLandmarks=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i=this;return $(this,function(a){switch(a.label){case 0:return[4,gm(e)];case 1:return t=a.sent(),n=H(function(){return Nr(i.forwardInput(t))}),[4,Promise.all(n.map(function(e,n){return Q(i,void 0,void 0,function(){var r,i,a,o,s;return $(this,function(c){switch(c.label){case 0:return a=(i=Array).from,[4,e.data()];case 1:return r=a.apply(i,[c.sent()]),o=r.filter(function(e,t){return pp(t)}),s=r.filter(function(e,t){return!pp(t)}),[2,new Rp(Array(68).fill(0).map(function(e,t){return new xp(o[t],s[t])}),{height:t.getInputHeight(n),width:t.getInputWidth(n)})]}})})}))];case 2:return r=a.sent(),n.forEach(function(e){return e.dispose()}),[2,t.isBatchInput?r:r[0]]}})})},t.prototype.getClassifierChannelsOut=function(){return 136},t}(Km),ph=function(e){Z(t,e);function t(t){return t===void 0&&(t=new Vm),e.call(this,`FaceLandmark68Net`,t)||this}return t.prototype.getDefaultModelName=function(){return`face_landmark_68_model`},t.prototype.getClassifierChannelsIn=function(){return 256},t}(fh);function mh(e){var t=[],n=zm(e,t).extractDenseBlock3Params,r={dense0:n(`dense0`,!0),dense1:n(`dense1`),dense2:n(`dense2`)};return Om(e,t),{params:r,paramMappings:t}}function hh(e){var t=[],n=Fm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Im(r,t).extractDenseBlock3Params,o=a(3,32,`dense0`,!0),s=a(32,64,`dense1`),c=a(64,128,`dense2`);if(i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{paramMappings:t,params:{dense0:o,dense1:s,dense2:c}}}var gh=function(e){Z(t,e);function t(){return e.call(this,`TinyFaceFeatureExtractor`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`TinyFaceFeatureExtractor - load model before inference`);return H(function(){var n=Tm(kp(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(G(255)),t.dense0,!0);return n=Tm(n,t.dense1),n=Tm(n,t.dense2),n=ql(n,[14,14],[2,2],`valid`),n})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.getDefaultModelName=function(){return`face_feature_extractor_tiny_model`},t.prototype.extractParamsFromWeigthMap=function(e){return mh(e)},t.prototype.extractParams=function(e){return hh(e)},t}(Cm),_h=function(e){Z(t,e);function t(t){return t===void 0&&(t=new gh),e.call(this,`FaceLandmark68TinyNet`,t)||this}return t.prototype.getDefaultModelName=function(){return`face_landmark_68_tiny_model`},t.prototype.getClassifierChannelsIn=function(){return 128},t}(fh);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t})(ph);function vh(e,t){return Rc(Qc(e,t.weights),t.biases)}function yh(e,t,n,r,i){i===void 0&&(i=`same`);var a=t.conv,o=a.filters,s=a.bias,c=El(e,o,n,i);return c=Rc(c,s),c=vh(c,t.scale),r?_u(c):c}function bh(e,t){return yh(e,t,[1,1],!0)}function xh(e,t){return yh(e,t,[1,1],!1)}function Sh(e,t){return yh(e,t,[2,2],!0,`valid`)}function Ch(e,t){function n(t,n,r){var i=e(t),a=i.length/(n*r*r);if(fp(a))throw Error(`depth has to be an integer: `+a+`, weights.length: `+i.length+`, numFilters: `+n+`, filterSize: `+r);return H(function(){return bu(Mn(i,[n,a,r,r]),[2,3,1,0])})}function r(r,i,a,o){var s=n(r,i,a),c=kn(e(i));return t.push({paramPath:o+`/filters`},{paramPath:o+`/bias`}),{filters:s,bias:c}}function i(n,r){var i=kn(e(n)),a=kn(e(n));return t.push({paramPath:r+`/weights`},{paramPath:r+`/biases`}),{weights:i,biases:a}}function a(e,t,n,a){return{conv:r(e,t,n,a+`/conv`),scale:i(t,a+`/scale`)}}function o(e,t,n,r,i){return i===void 0&&(i=!1),{conv1:a((i?.5:1)*e,t,n,r+`/conv1`),conv2:a(e,t,n,r+`/conv2`)}}return{extractConvLayerParams:a,extractResidualLayerParams:o}}function wh(e){var t=Fm(e),n=t.extractWeights,r=t.getRemainingWeights,i=[],a=Ch(n,i),o=a.extractConvLayerParams,s=a.extractResidualLayerParams,c=o(4704,32,7,`conv32_down`),l=s(9216,32,3,`conv32_1`),u=s(9216,32,3,`conv32_2`),d=s(9216,32,3,`conv32_3`),f=s(36864,64,3,`conv64_down`,!0),p=s(36864,64,3,`conv64_1`),m=s(36864,64,3,`conv64_2`),h=s(36864,64,3,`conv64_3`),g=s(147456,128,3,`conv128_down`,!0),_=s(147456,128,3,`conv128_1`),v=s(147456,128,3,`conv128_2`),y=s(589824,256,3,`conv256_down`,!0),b=s(589824,256,3,`conv256_1`),x=s(589824,256,3,`conv256_2`),S=s(589824,256,3,`conv256_down_out`),C=H(function(){return bu(An(n(256*128),[128,256]),[1,0])});if(i.push({paramPath:`fc`}),r().length!==0)throw Error(`weights remaing after extract: `+r().length);return{params:{conv32_down:c,conv32_1:l,conv32_2:u,conv32_3:d,conv64_down:f,conv64_1:p,conv64_2:m,conv64_3:h,conv128_down:g,conv128_1:_,conv128_2:v,conv256_down:y,conv256_1:b,conv256_2:x,conv256_down_out:S,fc:C},paramMappings:i}}function Th(e,t){var n=Pm(e,t);function r(e){return{weights:n(e+`/scale/weights`,1),biases:n(e+`/scale/biases`,1)}}function i(e){var t=n(e+`/conv/filters`,4),i=n(e+`/conv/bias`,1),a=r(e);return{conv:{filters:t,bias:i},scale:a}}function a(e){return{conv1:i(e+`/conv1`),conv2:i(e+`/conv2`)}}return{extractConvLayerParams:i,extractResidualLayerParams:a}}function Eh(e){var t=[],n=Th(e,t),r=n.extractConvLayerParams,i=n.extractResidualLayerParams,a=r(`conv32_down`),o=i(`conv32_1`),s=i(`conv32_2`),c=i(`conv32_3`),l=i(`conv64_down`),u=i(`conv64_1`),d=i(`conv64_2`),f=i(`conv64_3`),p=i(`conv128_down`),m=i(`conv128_1`),h=i(`conv128_2`),g=i(`conv256_down`),_=i(`conv256_1`),v=i(`conv256_2`),y=i(`conv256_down_out`),b=e.fc;if(t.push({originalPath:`fc`,paramPath:`fc`}),!lp(b))throw Error(`expected weightMap[fc] to be a Tensor2D, instead have `+b);var x={conv32_down:a,conv32_1:o,conv32_2:s,conv32_3:c,conv64_down:l,conv64_1:u,conv64_2:d,conv64_3:f,conv128_down:p,conv128_1:m,conv128_2:h,conv256_down:g,conv256_1:_,conv256_2:v,conv256_down_out:y,fc:b};return Om(e,t),{params:x,paramMappings:t}}function Dh(e,t){var n=bh(e,t.conv1);return n=xh(n,t.conv2),n=Rc(n,e),n=_u(n),n}function Oh(e,t){var n=Sh(e,t.conv1);n=xh(n,t.conv2);var r=ql(e,2,2,`valid`),i=Ln(r.shape),a=r.shape[3]!==n.shape[3];if(r.shape[1]!==n.shape[1]||r.shape[2]!==n.shape[2]){var o=op(n.shape);o[1]=1;var s=Ln(o);n=Un([n,s],1);var c=op(n.shape);c[2]=1;var l=Ln(c);n=Un([n,l],2)}return r=a?Un([r,i],3):r,n=Rc(r,n),n=_u(n),n}var kh=function(e){Z(t,e);function t(){return e.call(this,`FaceRecognitionNet`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`FaceRecognitionNet - load model before inference`);return H(function(){var n=Sh(kp(e.toBatchTensor(150,!0).toFloat(),[122.782,117.001,104.298]).div(G(256)),t.conv32_down);return n=Kl(n,3,2,`valid`),n=Dh(n,t.conv32_1),n=Dh(n,t.conv32_2),n=Dh(n,t.conv32_3),n=Oh(n,t.conv64_down),n=Dh(n,t.conv64_1),n=Dh(n,t.conv64_2),n=Dh(n,t.conv64_3),n=Oh(n,t.conv128_down),n=Dh(n,t.conv128_1),n=Dh(n,t.conv128_2),n=Oh(n,t.conv256_down),n=Dh(n,t.conv256_1),n=Dh(n,t.conv256_2),n=Oh(n,t.conv256_down_out),Il(n.mean([1,2]),t.fc)})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.computeFaceDescriptor=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i=this;return $(this,function(a){switch(a.label){case 0:return[4,gm(e)];case 1:return t=a.sent(),n=H(function(){return Nr(i.forwardInput(t))}),[4,Promise.all(n.map(function(e){return e.data()}))];case 2:return r=a.sent(),n.forEach(function(e){return e.dispose()}),[2,t.isBatchInput?r:r[0]]}})})},t.prototype.getDefaultModelName=function(){return`face_recognition_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Eh(e)},t.prototype.extractParams=function(e){return wh(e)},t}(Cm);function Ah(e,t){return Object.assign({},e,{descriptor:t})}function jh(e,t){return Object.assign({},e,{age:t})}function Mh(e,t,n){return Object.assign({},e,{gender:t,genderProbability:n})}var Nh=function(){function e(e){var t=e===void 0?{}:e,n=t.minFaceSize,r=t.scaleFactor,i=t.maxNumScales,a=t.scoreThresholds,o=t.scaleSteps;if(this._name=`MtcnnOptions`,this._minFaceSize=n||20,this._scaleFactor=r||.709,this._maxNumScales=i||10,this._scoreThresholds=a||[.6,.7,.7],this._scaleSteps=o,typeof this._minFaceSize!=`number`||this._minFaceSize<0)throw Error(this._name+` - expected minFaceSize to be a number > 0`);if(typeof this._scaleFactor!=`number`||this._scaleFactor<=0||this._scaleFactor>=1)throw Error(this._name+` - expected scaleFactor to be a number between 0 and 1`);if(typeof this._maxNumScales!=`number`||this._maxNumScales<0)throw Error(this._name+` - expected maxNumScales to be a number > 0`);if(!Array.isArray(this._scoreThresholds)||this._scoreThresholds.length!==3||this._scoreThresholds.some(function(e){return typeof e!=`number`}))throw 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(e){return typeof e!=`number`})))throw 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 Ph(e,t){function n(n,r){var i=Mn(e(9*n),[3,3,n,1]),a=kn(e(n)),o=kn(e(n)),s=kn(e(n)),c=kn(e(n));return t.push({paramPath:r+`/filters`},{paramPath:r+`/batch_norm_scale`},{paramPath:r+`/batch_norm_offset`},{paramPath:r+`/batch_norm_mean`},{paramPath:r+`/batch_norm_variance`}),{filters:i,batch_norm_scale:a,batch_norm_offset:o,batch_norm_mean:s,batch_norm_variance:c}}function r(n,r,i,a,o){var s=Mn(e(n*r*i*i),[i,i,n,r]),c=kn(e(r));return t.push({paramPath:a+`/filters`},{paramPath:a+`/`+(o?`batch_norm_offset`:`bias`)}),{filters:s,bias:c}}function i(e,t,n,i){var a=r(e,t,n,i,!0);return{filters:a.filters,batch_norm_offset:a.bias}}function a(e,t,r){return{depthwise_conv:n(e,r+`/depthwise_conv`),pointwise_conv:i(e,t,1,r+`/pointwise_conv`)}}function o(){return{conv_0:i(3,32,3,`mobilenetv1/conv_0`),conv_1:a(32,64,`mobilenetv1/conv_1`),conv_2:a(64,128,`mobilenetv1/conv_2`),conv_3:a(128,128,`mobilenetv1/conv_3`),conv_4:a(128,256,`mobilenetv1/conv_4`),conv_5:a(256,256,`mobilenetv1/conv_5`),conv_6:a(256,512,`mobilenetv1/conv_6`),conv_7:a(512,512,`mobilenetv1/conv_7`),conv_8:a(512,512,`mobilenetv1/conv_8`),conv_9:a(512,512,`mobilenetv1/conv_9`),conv_10:a(512,512,`mobilenetv1/conv_10`),conv_11:a(512,512,`mobilenetv1/conv_11`),conv_12:a(512,1024,`mobilenetv1/conv_12`),conv_13:a(1024,1024,`mobilenetv1/conv_13`)}}function s(){var e=i(1024,256,1,`prediction_layer/conv_0`),t=i(256,512,3,`prediction_layer/conv_1`),n=i(512,128,1,`prediction_layer/conv_2`),a=i(128,256,3,`prediction_layer/conv_3`),o=i(256,128,1,`prediction_layer/conv_4`),s=i(128,256,3,`prediction_layer/conv_5`),c=i(256,64,1,`prediction_layer/conv_6`),l=i(64,128,3,`prediction_layer/conv_7`),u=r(512,12,1,`prediction_layer/box_predictor_0/box_encoding_predictor`),d=r(512,9,1,`prediction_layer/box_predictor_0/class_predictor`),f=r(1024,24,1,`prediction_layer/box_predictor_1/box_encoding_predictor`),p=r(1024,18,1,`prediction_layer/box_predictor_1/class_predictor`),m=r(512,24,1,`prediction_layer/box_predictor_2/box_encoding_predictor`),h=r(512,18,1,`prediction_layer/box_predictor_2/class_predictor`),g=r(256,24,1,`prediction_layer/box_predictor_3/box_encoding_predictor`),_=r(256,18,1,`prediction_layer/box_predictor_3/class_predictor`),v=r(256,24,1,`prediction_layer/box_predictor_4/box_encoding_predictor`),y=r(256,18,1,`prediction_layer/box_predictor_4/class_predictor`),b=r(128,24,1,`prediction_layer/box_predictor_5/box_encoding_predictor`),x=r(128,18,1,`prediction_layer/box_predictor_5/class_predictor`);return{conv_0:e,conv_1:t,conv_2:n,conv_3:a,conv_4:o,conv_5:s,conv_6:c,conv_7:l,box_predictor_0:{box_encoding_predictor:u,class_predictor:d},box_predictor_1:{box_encoding_predictor:f,class_predictor:p},box_predictor_2:{box_encoding_predictor:m,class_predictor:h},box_predictor_3:{box_encoding_predictor:g,class_predictor:_},box_predictor_4:{box_encoding_predictor:v,class_predictor:y},box_predictor_5:{box_encoding_predictor:b,class_predictor:x}}}return{extractMobilenetV1Params:o,extractPredictionLayerParams:s}}function Fh(e){var t=[],n=Fm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Ph(r,t),o=a.extractMobilenetV1Params,s=a.extractPredictionLayerParams,c=o(),l=s(),u={extra_dim:jn(r(5118*4),[1,5118,4])};if(t.push({paramPath:`output_layer/extra_dim`}),i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{params:{mobilenetv1:c,prediction_layer:l,output_layer:u},paramMappings:t}}function Ih(e,t){var n=Pm(e,t);function r(e,t,r){return{filters:n(e+`/Conv2d_`+t+`_pointwise/weights`,4,r+`/filters`),batch_norm_offset:n(e+`/Conv2d_`+t+`_pointwise/convolution_bn_offset`,1,r+`/batch_norm_offset`)}}function i(e){var t=`mobilenetv1/conv_`+e,i=`MobilenetV1/Conv2d_`+e+`_depthwise`,a=t+`/depthwise_conv`,o=t+`/pointwise_conv`;return{depthwise_conv:{filters:n(i+`/depthwise_weights`,4,a+`/filters`),batch_norm_scale:n(i+`/BatchNorm/gamma`,1,a+`/batch_norm_scale`),batch_norm_offset:n(i+`/BatchNorm/beta`,1,a+`/batch_norm_offset`),batch_norm_mean:n(i+`/BatchNorm/moving_mean`,1,a+`/batch_norm_mean`),batch_norm_variance:n(i+`/BatchNorm/moving_variance`,1,a+`/batch_norm_variance`)},pointwise_conv:r(`MobilenetV1`,e,o)}}function a(){return{conv_0:r(`MobilenetV1`,0,`mobilenetv1/conv_0`),conv_1:i(1),conv_2:i(2),conv_3:i(3),conv_4:i(4),conv_5:i(5),conv_6:i(6),conv_7:i(7),conv_8:i(8),conv_9:i(9),conv_10:i(10),conv_11:i(11),conv_12:i(12),conv_13:i(13)}}function o(e,t){return{filters:n(e+`/weights`,4,t+`/filters`),bias:n(e+`/biases`,1,t+`/bias`)}}function s(e){return{box_encoding_predictor:o(`Prediction/BoxPredictor_`+e+`/BoxEncodingPredictor`,`prediction_layer/box_predictor_`+e+`/box_encoding_predictor`),class_predictor:o(`Prediction/BoxPredictor_`+e+`/ClassPredictor`,`prediction_layer/box_predictor_`+e+`/class_predictor`)}}function c(){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:s(0),box_predictor_1:s(1),box_predictor_2:s(2),box_predictor_3:s(3),box_predictor_4:s(4),box_predictor_5:s(5)}}return{extractMobilenetV1Params:a,extractPredictionLayerParams:c}}function Lh(e){var t=[],n=Ih(e,t),r=n.extractMobilenetV1Params,i=n.extractPredictionLayerParams,a=e[`Output/extra_dim`];if(t.push({originalPath:`Output/extra_dim`,paramPath:`output_layer/extra_dim`}),!up(a))throw Error(`expected weightMap['Output/extra_dim'] to be a Tensor3D, instead have `+a);var o={mobilenetv1:r(),prediction_layer:i(),output_layer:{extra_dim:a}};return Om(e,t),{params:o,paramMappings:t}}function Rh(e,t,n){return H(function(){var r=El(e,t.filters,n,`same`);return r=Rc(r,t.batch_norm_offset),Ks(r,0,6)})}var zh=.0010000000474974513;function Bh(e,t,n){return H(function(){var r=Al(e,t.filters,n,`same`);return r=Oc(r,t.batch_norm_mean,t.batch_norm_variance,t.batch_norm_offset,t.batch_norm_scale,zh),Ks(r,0,6)})}function Vh(e){return[2,4,6,12].some(function(t){return t===e})?[2,2]:[1,1]}function Hh(e,t){return H(function(){var n=null,r=Rh(e,t.conv_0,[2,2]);if([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].forEach(function(e,t){var i=t+1,a=Vh(i);r=Bh(r,e.depthwise_conv,a),r=Rh(r,e.pointwise_conv,[1,1]),i===11&&(n=r)}),n===null)throw Error(`mobileNetV1 - output of conv layer 11 is null`);return{out:r,conv11:n}})}function Uh(e,t,n,r,i){var a=e.shape[0],o=Math.min(n,a),s=t.map(function(e,t){return{score:e,boxIndex:t}}).filter(function(e){return e.score>i}).sort(function(e,t){return t.score-e.score}),c=function(e){return e<=r?1:0},l=[];return s.forEach(function(t){if(!(l.length>=o)){for(var n=t.score,r=l.length-1;r>=0;--r){var a=Wh(e,t.boxIndex,l[r]);if(a!==0&&(t.score*=c(a),t.score<=i))break}n===t.score&&l.push(t.boxIndex)}}),l}function Wh(e,t,n){var r=e.arraySync(),i=Math.min(r[t][0],r[t][2]),a=Math.min(r[t][1],r[t][3]),o=Math.max(r[t][0],r[t][2]),s=Math.max(r[t][1],r[t][3]),c=Math.min(r[n][0],r[n][2]),l=Math.min(r[n][1],r[n][3]),u=Math.max(r[n][0],r[n][2]),d=Math.max(r[n][1],r[n][3]),f=(o-i)*(s-a),p=(u-c)*(d-l);if(f<=0||p<=0)return 0;var m=Math.max(i,c),h=Math.max(a,l),g=Math.min(o,u),_=Math.min(s,d),v=Math.max(g-m,0)*Math.max(_-h,0);return v/(f+p-v)}function Gh(e){var t=Nr(bu(e,[1,0])),n=[rl(t[2],t[0]),rl(t[3],t[1])];return{sizes:n,centers:[Rc(t[0],Hc(n[0],G(2))),Rc(t[1],Hc(n[1],G(2)))]}}function Kh(e,t){var n=Gh(e),r=n.sizes,i=n.centers,a=Nr(bu(t,[1,0])),o=Hc(Qc(Xs(Hc(a[2],G(5))),r[0]),G(2)),s=Rc(Qc(Hc(a[0],G(10)),r[0]),i[0]),c=Hc(Qc(Xs(Hc(a[3],G(5))),r[1]),G(2)),l=Rc(Qc(Hc(a[1],G(10)),r[1]),i[1]);return bu(Ar([rl(s,o),rl(l,c),Rc(s,o),Rc(l,c)]),[1,0])}function qh(e,t,n){return H(function(){var r=e.shape[0],i=Kh(Dr(jr(n.extra_dim,[r,1,1]),[-1,4]),Dr(e,[-1,4]));i=Dr(i,[r,i.shape[0]/r,4]);var a=Zl(oc(Zl(t,[0,0,1],[-1,-1,-1])),[0,0,0],[-1,-1,1]);return a=Dr(a,[r,a.shape[1]]),{boxes:Nr(i),scores:Nr(a)}})}function Jh(e,t){return H(function(){var n=e.shape[0];return{boxPredictionEncoding:Dr(Dm(e,t.box_encoding_predictor),[n,-1,1,4]),classPrediction:Dr(Dm(e,t.class_predictor),[n,-1,3])}})}function Yh(e,t,n){return H(function(){var r=Rh(Rh(e,n.conv_0,[1,1]),n.conv_1,[2,2]),i=Rh(Rh(r,n.conv_2,[1,1]),n.conv_3,[2,2]),a=Rh(Rh(i,n.conv_4,[1,1]),n.conv_5,[2,2]),o=Rh(Rh(a,n.conv_6,[1,1]),n.conv_7,[2,2]),s=Jh(t,n.box_predictor_0),c=Jh(e,n.box_predictor_1),l=Jh(r,n.box_predictor_2),u=Jh(i,n.box_predictor_3),d=Jh(a,n.box_predictor_4),f=Jh(o,n.box_predictor_5);return{boxPredictions:Un([s.boxPredictionEncoding,c.boxPredictionEncoding,l.boxPredictionEncoding,u.boxPredictionEncoding,d.boxPredictionEncoding,f.boxPredictionEncoding],1),classPredictions:Un([s.classPrediction,c.classPrediction,l.classPrediction,u.classPrediction,d.classPrediction,f.classPrediction],1)}})}var Xh=function(){function e(e){var t=e===void 0?{}:e,n=t.minConfidence,r=t.maxResults;if(this._name=`SsdMobilenetv1Options`,this._minConfidence=n||.5,this._maxResults=r||100,typeof this._minConfidence!=`number`||this._minConfidence<=0||this._minConfidence>=1)throw Error(this._name+` - expected minConfidence to be a number between 0 and 1`);if(typeof this._maxResults!=`number`)throw 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}(),Zh=function(e){Z(t,e);function t(){return e.call(this,`SsdMobilenetv1`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`SsdMobilenetv1 - load model before inference`);return H(function(){var n=Hh(rl(Qc(e.toBatchTensor(512,!1).toFloat(),G(.007843137718737125)),G(1)),t.mobilenetv1),r=Yh(n.out,n.conv11,t.prediction_layer),i=r.boxPredictions,a=r.classPredictions;return qh(i,a,t.output_layer)})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.locateFaces=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S;return $(this,function(C){switch(C.label){case 0:return n=new Xh(t),r=n.maxResults,i=n.minConfidence,[4,gm(e)];case 1:for(a=C.sent(),o=this.forwardInput(a),s=o.boxes,c=o.scores,l=s[0],u=c[0],d=1;d<s.length;d++)s[d].dispose(),c[d].dispose();return m=(p=Array).from,[4,u.data()];case 2:return f=m.apply(p,[C.sent()]),h=.5,g=Uh(l,f,r,h,i),_=a.getReshapedInputDimensions(0),v=a.inputSize,y=v/_.width,b=v/_.height,x=l.arraySync(),S=g.map(function(e){var t=[Math.max(0,x[e][0]),Math.min(1,x[e][2])].map(function(e){return e*b}),n=t[0],r=t[1],i=[Math.max(0,x[e][1]),Math.min(1,x[e][3])].map(function(e){return e*y}),o=i[0],s=i[1];return new Tp(f[e],new Mp(o,n,s-o,r-n),{height:a.getInputHeight(0),width:a.getInputWidth(0)})}),l.dispose(),u.dispose(),[2,S]}})})},t.prototype.getDefaultModelName=function(){return`ssd_mobilenetv1_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Lh(e)},t.prototype.extractParams=function(e){return Fh(e)},t}(Cm);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t})(Zh);var Qh=.4,$h=[new xp(.738768,.874946),new xp(2.42204,2.65704),new xp(4.30971,7.04493),new xp(10.246,4.59428),new xp(12.6868,11.8741)],eg=[new xp(1.603231,2.094468),new xp(6.041143,7.080126),new xp(2.882459,3.518061),new xp(4.266906,5.178857),new xp(9.041765,10.66308)],tg=[117.001,114.697,97.404],ng=`tiny_yolov2_model`,rg=`tiny_yolov2_separable_conv_model`,ig=function(e){return typeof e==`number`};function ag(e){if(!e)throw Error(`invalid config: `+e);if(typeof e.withSeparableConvs!=`boolean`)throw Error(`config.withSeparableConvs has to be a boolean, have: `+e.withSeparableConvs);if(!ig(e.iouThreshold)||e.iouThreshold<0||e.iouThreshold>1)throw 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(e){return typeof e==`string`}))throw 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(e){return e||{}}).every(function(e){return ig(e.x)&&ig(e.y)}))throw 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(ig)))throw Error(`config.meanRgb has to be an array of shape [number, number, number], have: `+JSON.stringify(e.meanRgb))}function og(e){return H(function(){var t=Qc(e,G(.10000000149011612));return Rc(_u(rl(e,t)),t)})}function sg(e,t){return H(function(){var n=vr(e,[[0,0],[1,1],[1,1],[0,0]]);return n=El(n,t.conv.filters,[1,1],`valid`),n=rl(n,t.bn.sub),n=Qc(n,t.bn.truediv),n=Rc(n,t.conv.bias),og(n)})}function cg(e,t){return H(function(){var n=vr(e,[[0,0],[1,1],[1,1],[0,0]]);return n=Nl(n,t.depthwise_filter,t.pointwise_filter,[1,1],`valid`),n=Rc(n,t.bias),og(n)})}function lg(e,t){var n=km(e,t);function r(n,r){var i=kn(e(n)),a=kn(e(n));return t.push({paramPath:r+`/sub`},{paramPath:r+`/truediv`}),{sub:i,truediv:a}}function i(e,t,i){return{conv:n(e,t,3,i+`/conv`),bn:r(t,i+`/bn`)}}return{extractConvParams:n,extractConvWithBatchNormParams:i,extractSeparableConvParams:Mm(e,t)}}function ug(e,t,n,r){var i=Fm(e),a=i.extractWeights,o=i.getRemainingWeights,s=[],c=lg(a,s),l=c.extractConvParams,u=c.extractConvWithBatchNormParams,d=c.extractSeparableConvParams,f;if(t.withSeparableConvs){var p=r[0],m=r[1],h=r[2],g=r[3],_=r[4],v=r[5],y=r[6],b=r[7],x=r[8],S=t.isFirstLayerConv2d?l(p,m,3,`conv0`):d(p,m,`conv0`),C=d(m,h,`conv1`),w=d(h,g,`conv2`),T=d(g,_,`conv3`),E=d(_,v,`conv4`),D=d(v,y,`conv5`),O=b?d(y,b,`conv6`):void 0,k=x?d(b,x,`conv7`):void 0,A=l(x||b||y,5*n,1,`conv8`);f={conv0:S,conv1:C,conv2:w,conv3:T,conv4:E,conv5:D,conv6:O,conv7:k,conv8:A}}else{var p=r[0],m=r[1],h=r[2],g=r[3],_=r[4],v=r[5],y=r[6],b=r[7],x=r[8],S=u(p,m,`conv0`),C=u(m,h,`conv1`),w=u(h,g,`conv2`),T=u(g,_,`conv3`),E=u(_,v,`conv4`),D=u(v,y,`conv5`),O=u(y,b,`conv6`),k=u(b,x,`conv7`),A=l(x,5*n,1,`conv8`);f={conv0:S,conv1:C,conv2:w,conv3:T,conv4:E,conv5:D,conv6:O,conv7:k,conv8:A}}if(o().length!==0)throw Error(`weights remaing after extract: `+o().length);return{params:f,paramMappings:s}}function dg(e,t){var n=Pm(e,t);function r(e){return{sub:n(e+`/sub`,1),truediv:n(e+`/truediv`,1)}}function i(e){return{filters:n(e+`/filters`,4),bias:n(e+`/bias`,1)}}function a(e){return{conv:i(e+`/conv`),bn:r(e+`/bn`)}}return{extractConvParams:i,extractConvWithBatchNormParams:a,extractSeparableConvParams:Nm(n)}}function fg(e,t){var n=[],r=dg(e,n),i=r.extractConvParams,a=r.extractConvWithBatchNormParams,o=r.extractSeparableConvParams,s;if(t.withSeparableConvs){var c=t.filterSizes&&t.filterSizes.length||9;s={conv0:t.isFirstLayerConv2d?i(`conv0`):o(`conv0`),conv1:o(`conv1`),conv2:o(`conv2`),conv3:o(`conv3`),conv4:o(`conv4`),conv5:o(`conv5`),conv6:c>7?o(`conv6`):void 0,conv7:c>8?o(`conv7`):void 0,conv8:i(`conv8`)}}else s={conv0:a(`conv0`),conv1:a(`conv1`),conv2:a(`conv2`),conv3:a(`conv3`),conv4:a(`conv4`),conv5:a(`conv5`),conv6:a(`conv6`),conv7:a(`conv7`),conv8:i(`conv8`)};return Om(e,n),{params:s,paramMappings:n}}var pg;(function(e){e[e.XS=224]=`XS`,e[e.SM=320]=`SM`,e[e.MD=416]=`MD`,e[e.LG=608]=`LG`})(pg||={});var mg=function(){function e(e){var t=e===void 0?{}:e,n=t.inputSize,r=t.scoreThreshold;if(this._name=`TinyYolov2Options`,this._inputSize=n||416,this._scoreThreshold=r||.5,typeof this._inputSize!=`number`||this._inputSize%32!=0)throw Error(this._name+` - expected inputSize to be a number divisible by 32`);if(typeof this._scoreThreshold!=`number`||this._scoreThreshold<=0||this._scoreThreshold>=1)throw 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}(),hg=function(e){Z(t,e);function t(t){var n=e.call(this,`TinyYolov2`)||this;return ag(t),n._config=t,n}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(e,t){var n=sg(e,t.conv0);return n=Kl(n,[2,2],[2,2],`same`),n=sg(n,t.conv1),n=Kl(n,[2,2],[2,2],`same`),n=sg(n,t.conv2),n=Kl(n,[2,2],[2,2],`same`),n=sg(n,t.conv3),n=Kl(n,[2,2],[2,2],`same`),n=sg(n,t.conv4),n=Kl(n,[2,2],[2,2],`same`),n=sg(n,t.conv5),n=Kl(n,[2,2],[1,1],`same`),n=sg(n,t.conv6),n=sg(n,t.conv7),Dm(n,t.conv8,`valid`,!1)},t.prototype.runMobilenet=function(e,t){var n=this.config.isFirstLayerConv2d?og(Dm(e,t.conv0,`valid`,!1)):cg(e,t.conv0);return n=Kl(n,[2,2],[2,2],`same`),n=cg(n,t.conv1),n=Kl(n,[2,2],[2,2],`same`),n=cg(n,t.conv2),n=Kl(n,[2,2],[2,2],`same`),n=cg(n,t.conv3),n=Kl(n,[2,2],[2,2],`same`),n=cg(n,t.conv4),n=Kl(n,[2,2],[2,2],`same`),n=cg(n,t.conv5),n=Kl(n,[2,2],[1,1],`same`),n=t.conv6?cg(n,t.conv6):n,n=t.conv7?cg(n,t.conv7):n,Dm(n,t.conv8,`valid`,!1)},t.prototype.forwardInput=function(e,t){var n=this,r=this.params;if(!r)throw Error(`TinyYolov2 - load model before inference`);return H(function(){var i=e.toBatchTensor(t,!1).toFloat();return i=n.config.meanRgb?kp(i,n.config.meanRgb):i,i=i.div(G(256)),n.config.withSeparableConvs?n.runMobilenet(i,r):n.runTinyYolov2(i,r)})},t.prototype.forward=function(e,t){return Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return n=this.forwardInput,[4,gm(e)];case 1:return[4,n.apply(this,[r.sent(),t])];case 2:return[2,r.sent()]}})})},t.prototype.detect=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c,l,u,d,f,p,m,h,g=this;return $(this,function(_){switch(_.label){case 0:return n=new mg(t),r=n.inputSize,i=n.scoreThreshold,[4,gm(e)];case 1:return a=_.sent(),[4,this.forwardInput(a,r)];case 2:return o=_.sent(),s=H(function(){return Nr(o)[0].expandDims()}),c={width:a.getInputWidth(0),height:a.getInputHeight(0)},[4,this.extractBoxes(s,a.getReshapedInputDimensions(0),i)];case 3:return l=_.sent(),o.dispose(),s.dispose(),u=l.map(function(e){return e.box}),d=l.map(function(e){return e.score}),f=l.map(function(e){return e.classScore}),p=l.map(function(e){return g.config.classes[e.label]}),m=Op(u.map(function(e){return e.rescale(r)}),d,this.config.iouThreshold,!0),h=m.map(function(e){return new wp(d[e],f[e],p[e],u[e],c)}),[2,h]}})})},t.prototype.getDefaultModelName=function(){return``},t.prototype.extractParamsFromWeigthMap=function(e){return fg(e,this.config)},t.prototype.extractParams=function(e){var n=this.config.filterSizes||t.DEFAULT_FILTER_SIZES,r=n?n.length:void 0;if(r!==7&&r!==8&&r!==9)throw Error(`TinyYolov2 - expected 7 | 8 | 9 convolutional filters, but found `+r+` filterSizes in config`);return ug(e,this.config,this.boxEncodingSize,n)},t.prototype.extractBoxes=function(e,t,n){return Q(this,void 0,void 0,function(){var r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M=this;return $(this,function(N){switch(N.label){case 0:return r=t.width,i=t.height,a=Math.max(r,i),o=a/r,s=a/i,c=e.shape[1],l=this.config.anchors.length,u=H(function(){var t=e.reshape([c,c,l,M.boxEncodingSize]);return[t.slice([0,0,0,0],[c,c,l,4]),t.slice([0,0,0,4],[c,c,l,1]),M.withClassScores?ti(t.slice([0,0,0,5],[c,c,l,M.config.classes.length]),3):G(0)]}),d=u[0],f=u[1],p=u[2],m=[],[4,f.array()];case 1:return h=N.sent(),[4,d.array()];case 2:g=N.sent(),_=0,N.label=3;case 3:if(!(_<c))return[3,12];v=0,N.label=4;case 4:if(!(v<c))return[3,11];y=0,N.label=5;case 5:return y<l?(b=jp(h[_][v][y][0]),!n||b>n?(x=(v+jp(g[_][v][y][0]))/c*o,S=(_+jp(g[_][v][y][1]))/c*s,C=Math.exp(g[_][v][y][2])*this.config.anchors[y].x/c*o,w=Math.exp(g[_][v][y][3])*this.config.anchors[y].y/c*s,T=x-C/2,E=S-w/2,D={row:_,col:v,anchor:y},this.withClassScores?[4,this.extractPredictedClass(p,D)]:[3,7]):[3,9]):[3,10];case 6:return j=N.sent(),[3,8];case 7:j={classScore:1,label:0},N.label=8;case 8:O=j,k=O.classScore,A=O.label,m.push(ap({box:new Cp(T,E,T+C,E+w),score:b,classScore:b*k,label:A},D)),N.label=9;case 9:return y++,[3,5];case 10:return v++,[3,4];case 11:return _++,[3,3];case 12:return d.dispose(),f.dispose(),p.dispose(),[2,m]}})})},t.prototype.extractPredictedClass=function(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a;return $(this,function(o){switch(o.label){case 0:return n=t.row,r=t.col,i=t.anchor,[4,e.array()];case 1:return a=o.sent(),[2,Array(this.config.classes.length).fill(0).map(function(e,t){return a[n][r][i][t]}).map(function(e,t){return{classScore:e,label:t}}).reduce(function(e,t){return e.classScore>t.classScore?e:t})]}})})},t.DEFAULT_FILTER_SIZES=[3,16,32,64,128,256,512,1024,1024],t}(Cm),gg=function(e){Z(t,e);function t(t){t===void 0&&(t=!0);var n=this,r=Object.assign({},{withSeparableConvs:t,iouThreshold:Qh,classes:[`face`]},t?{anchors:eg,meanRgb:tg}:{anchors:$h,withClassScores:!0});return n=e.call(this,r)||this,n}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(e,t){return Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return[4,this.detect(e,t)];case 1:return n=r.sent(),[2,n.map(function(e){return new Tp(e.score,e.relativeBox,{width:e.imageWidth,height:e.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return this.withSeparableConvs?rg:ng},t.prototype.extractParamsFromWeigthMap=function(t){return e.prototype.extractParamsFromWeigthMap.call(this,t)},t}(hg),_g=function(e){Z(t,e);function t(){var t=e!==null&&e.apply(this,arguments)||this;return t._name=`TinyFaceDetectorOptions`,t}return t}(mg),vg=function(){function e(){}return e.prototype.then=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=e,[4,this.run()];case 1:return[2,t.apply(void 0,[n.sent()])]}})})},e.prototype.run=function(){return Q(this,void 0,void 0,function(){return $(this,function(e){throw Error(`ComposableTask - run is not implemented`)})})},e}();function yg(e,t,n,r,i){return i===void 0&&(i=function(e){return e.alignedRect}),Q(this,void 0,void 0,function(){var a,o,s,c,l;return $(this,function(u){switch(u.label){case 0:return a=e.map(function(e){return Zm(e)?i(e):e.detection}),s=r,s?[3,5]:t instanceof Be?[4,vm(t,a)]:[3,2];case 1:return c=u.sent(),[3,4];case 2:return[4,_m(t,a)];case 3:c=u.sent(),u.label=4;case 4:s=c,u.label=5;case 5:return o=s,[4,n(o)];case 6:return l=u.sent(),o.forEach(function(e){return e instanceof Be&&e.dispose()}),[2,l]}})})}function bg(e,t,n,r,i){return Q(this,void 0,void 0,function(){var a=this;return $(this,function(o){return[2,yg([e],t,function(e){return Q(a,void 0,void 0,function(){return $(this,function(t){return[2,n(e[0])]})})},r,i)]})})}function xg(e){return H(function(){return Ar(Nr(e,3).reverse(),3)})}function Sg(e,t){var n=km(e,t),r=Am(e,t);function i(n,r){var i=kn(e(n));return t.push({paramPath:r}),i}function a(e,t,r){return r===void 0&&(r=!1),{conv1:n(e[0],e[1],3,t+`/conv1`),prelu1_alpha:i(e[1],t+`/prelu1_alpha`),conv2:n(e[1],e[2],3,t+`/conv2`),prelu2_alpha:i(e[2],t+`/prelu2_alpha`),conv3:n(e[2],e[3],r?2:3,t+`/conv3`),prelu3_alpha:i(e[3],t+`/prelu3_alpha`)}}function o(){var e=a([3,10,16,32],`pnet`),t=n(32,2,1,`pnet/conv4_1`),r=n(32,4,1,`pnet/conv4_2`);return ap(ap({},e),{conv4_1:t,conv4_2:r})}function s(){var e=a([3,28,48,64],`rnet`,!0),t=r(576,128,`rnet/fc1`),n=i(128,`rnet/prelu4_alpha`),o=r(128,2,`rnet/fc2_1`),s=r(128,4,`rnet/fc2_2`);return ap(ap({},e),{fc1:t,prelu4_alpha:n,fc2_1:o,fc2_2:s})}function c(){var e=a([3,32,64,64],`onet`),t=n(64,128,2,`onet/conv4`),o=i(128,`onet/prelu4_alpha`),s=r(1152,256,`onet/fc1`),c=i(256,`onet/prelu5_alpha`),l=r(256,2,`onet/fc2_1`),u=r(256,4,`onet/fc2_2`),d=r(256,10,`onet/fc2_3`);return ap(ap({},e),{conv4:t,prelu4_alpha:o,fc1:s,prelu5_alpha:c,fc2_1:l,fc2_2:u,fc2_3:d})}return{extractPNetParams:o,extractRNetParams:s,extractONetParams:c}}function Cg(e){var t=Fm(e),n=t.extractWeights,r=t.getRemainingWeights,i=[],a=Sg(n,i),o=a.extractPNetParams,s=a.extractRNetParams,c=a.extractONetParams,l=o(),u=s(),d=c();if(r().length!==0)throw Error(`weights remaing after extract: `+r().length);return{params:{pnet:l,rnet:u,onet:d},paramMappings:i}}function wg(e,t){var n=Pm(e,t);function r(e){return{filters:n(e+`/weights`,4,e+`/filters`),bias:n(e+`/bias`,1)}}function i(e){return{weights:n(e+`/weights`,2),bias:n(e+`/bias`,1)}}function a(e){return n(e,1)}function o(e){return{conv1:r(e+`/conv1`),prelu1_alpha:a(e+`/prelu1_alpha`),conv2:r(e+`/conv2`),prelu2_alpha:a(e+`/prelu2_alpha`),conv3:r(e+`/conv3`),prelu3_alpha:a(e+`/prelu3_alpha`)}}function s(){var e=o(`pnet`),t=r(`pnet/conv4_1`),n=r(`pnet/conv4_2`);return ap(ap({},e),{conv4_1:t,conv4_2:n})}function c(){var e=o(`rnet`),t=i(`rnet/fc1`),n=a(`rnet/prelu4_alpha`),r=i(`rnet/fc2_1`),s=i(`rnet/fc2_2`);return ap(ap({},e),{fc1:t,prelu4_alpha:n,fc2_1:r,fc2_2:s})}function l(){var e=o(`onet`),t=r(`onet/conv4`),n=a(`onet/prelu4_alpha`),s=i(`onet/fc1`),c=a(`onet/prelu5_alpha`),l=i(`onet/fc2_1`),u=i(`onet/fc2_2`),d=i(`onet/fc2_3`);return ap(ap({},e),{conv4:t,prelu4_alpha:n,fc1:s,prelu5_alpha:c,fc2_1:l,fc2_2:u,fc2_3:d})}return{extractPNetParams:s,extractRNetParams:c,extractONetParams:l}}function Tg(e){var t=[],n=wg(e,t),r=n.extractPNetParams,i=n.extractRNetParams,a=n.extractONetParams,o=r(),s=i(),c=a();return Om(e,t),{params:{pnet:o,rnet:s,onet:c},paramMappings:t}}function Eg(e,t){var n=t[0],r=t[1];return{height:Math.floor(n*e),width:Math.floor(r*e)}}function Dg(e,t,n){for(var r=n[0],i=n[1],a=12/e,o=[],s=Math.min(r,i)*a,c=0;s>=12;)o.push(a*t**+c),s*=t,c+=1;return o}var Og=function(e){Z(t,e);function t(t,n,r,i){return e.call(this,{left:t,top:n,right:r,bottom:i},!0)||this}return t}(Sp);function kg(e){return H(function(){return Qc(rl(e,G(127.5)),G(.0078125))})}function Ag(e,t){return H(function(){return Rc(_u(e),Qc(t,nc(_u(nc(e)))))})}function jg(e,t,n){return n===void 0&&(n=!1),H(function(){var r=Dm(e,t.conv1,`valid`);return r=Ag(r,t.prelu1_alpha),r=Kl(r,n?[2,2]:[3,3],[2,2],`same`),r=Dm(r,t.conv2,`valid`),r=Ag(r,t.prelu2_alpha),r=n?r:Kl(r,[3,3],[2,2],`valid`),r=Dm(r,t.conv3,`valid`),r=Ag(r,t.prelu3_alpha),r})}function Mg(e,t){return H(function(){var n=jg(e,t,!0),r=Dm(n,t.conv4_1,`valid`);return{prob:ti(rl(r,mr(cu(r,3),3)),3),regions:Dm(n,t.conv4_2,`valid`)}})}function Ng(e,t){return H(function(){var n=Eg(t,e.shape.slice(1)),r=n.height,i=n.width;return bu(kg(hd.resizeBilinear(e,[r,i])),[0,2,1,3])})}function Pg(e,t,n,r){for(var i=[],a=e.arraySync(),o=0;o<e.shape[0];o++)for(var s=0;s<e.shape[1];s++)a[o][s]>=r&&i.push(new xp(s,o));return i.map(function(e){var r=new Cp(Math.round((e.y*2+1)/n),Math.round((e.x*2+1)/n),Math.round((e.y*2+12)/n),Math.round((e.x*2+12)/n)),i=a[e.y][e.x],o=t.arraySync();return{cell:r,score:i,region:new Og(o[e.y][e.x][0],o[e.y][e.x][1],o[e.y][e.x][2],o[e.y][e.x][3])}})}function Fg(e,t,n,r,i){i.stage1=[];var a=t.map(function(t){return H(function(){var n={scale:t},i=Ng(e,t),a=Date.now(),o=Mg(i,r),s=o.prob,c=o.regions;return n.pnet=Date.now()-a,{scoresTensor:Nr(Nr(s,3)[1])[0],regionsTensor:Nr(c)[0],scale:t,statsForScale:n}})}).map(function(e){var t=e.scoresTensor,r=e.regionsTensor,a=e.scale,o=e.statsForScale,s=Pg(t,r,a,n);if(t.dispose(),r.dispose(),!s.length)return i.stage1.push(o),[];var c=Date.now(),l=Op(s.map(function(e){return e.cell}),s.map(function(e){return e.score}),.5);return o.nms=Date.now()-c,o.numBoxes=l.length,i.stage1.push(o),l.map(function(e){return s[e]})}).reduce(function(e,t){return e.concat(t)},[]),o=[],s=[];if(a.length>0){var c=Date.now(),l=Op(a.map(function(e){return e.cell}),a.map(function(e){return e.score}),.7);i.stage1_nms=Date.now()-c,s=l.map(function(e){return a[e].score}),o=l.map(function(e){return a[e]}).map(function(e){var t=e.cell,n=e.region;return new Cp(t.left+n.left*t.width,t.top+n.top*t.height,t.right+n.right*t.width,t.bottom+n.bottom*t.height).toSquare().round()})}return{boxes:o,scores:s}}function Ig(e,t,n){var r=n.width,i=n.height;return Q(this,void 0,void 0,function(){var n,a,o,s=this;return $(this,function(c){switch(c.label){case 0:return n=nm(e),[4,Promise.all(t.map(function(t){return Q(s,void 0,void 0,function(){var r,i,a,o,s,c,l,u;return $(this,function(d){return r=t.padAtBorders(e.height,e.width),i=r.y,a=r.ey,o=r.x,s=r.ex,c=o-1,l=i-1,u=n.getImageData(c,l,s-c,a-l),[2,em.isNodejs()?dm(u):createImageBitmap(u)]})})}))];case 1:return a=c.sent(),o=[],a.forEach(function(e){var t=nm(um({width:r,height:i}));t.drawImage(e,0,0,r,i);for(var n=t.getImageData(0,0,r,i).data,a=[],s=0;s<n.length;s+=4)a.push(n[s+2]),a.push(n[s+1]),a.push(n[s]);o.push(a)}),[2,o.map(function(e){return H(function(){return kg(bu(Mn(e,[1,r,i,3]),[0,2,1,3]).toFloat())})})]}})})}function Lg(e,t){return H(function(){var n=jg(e,t),r=Ag(Hm(Dr(n,[n.shape[0],t.fc1.weights.shape[0]]),t.fc1),t.prelu4_alpha),i=Hm(r,t.fc2_1),a=ti(rl(i,mr(cu(i,1),1)),1),o=Hm(r,t.fc2_2);return{scores:Nr(a,1)[1],regions:o}})}function Rg(e,t,n,r,i){return Q(this,void 0,void 0,function(){var a,o,s,c,l,u,d,f,p,m,h,g,_,v;return $(this,function(y){switch(y.label){case 0:return a=Date.now(),[4,Ig(e,t,{width:24,height:24})];case 1:return o=y.sent(),i.stage2_extractImagePatches=Date.now()-a,a=Date.now(),s=o.map(function(e){var t=Lg(e,r);return e.dispose(),t}),i.stage2_rnet=Date.now()-a,c=s.length>1?Un(s.map(function(e){return e.scores})):s[0].scores,d=(u=Array).from,[4,c.data()];case 2:return l=d.apply(u,[y.sent()]),c.dispose(),f=l.map(function(e,t){return{score:e,idx:t}}).filter(function(e){return e.score>n}).map(function(e){return e.idx}),p=f.map(function(e){return t[e]}),m=f.map(function(e){return l[e]}),h=[],g=[],p.length>0&&(a=Date.now(),_=Op(p,m,.7),i.stage2_nms=Date.now()-a,v=_.map(function(e){var t=s[f[e]].regions.arraySync();return new Og(t[0][0],t[0][1],t[0][2],t[0][3])}),g=_.map(function(e){return m[e]}),h=_.map(function(e,t){return p[e].calibrate(v[t])})),s.forEach(function(e){e.regions.dispose(),e.scores.dispose()}),[2,{boxes:h,scores:g}]}})})}function zg(e,t){return H(function(){var n=jg(e,t);n=Kl(n,[2,2],[2,2],`same`),n=Dm(n,t.conv4,`valid`),n=Ag(n,t.prelu4_alpha);var r=Ag(Hm(Dr(n,[n.shape[0],t.fc1.weights.shape[0]]),t.fc1),t.prelu5_alpha),i=Hm(r,t.fc2_1),a=ti(rl(i,mr(cu(i,1),1)),1),o=Hm(r,t.fc2_2),s=Hm(r,t.fc2_3);return{scores:Nr(a,1)[1],regions:o,points:s}})}function Bg(e,t,n,r,i){return Q(this,void 0,void 0,function(){var a,o,s,c,l,u,d,f,p,m,h,g,_,v,y;return $(this,function(b){switch(b.label){case 0:return a=Date.now(),[4,Ig(e,t,{width:48,height:48})];case 1:return o=b.sent(),i.stage3_extractImagePatches=Date.now()-a,a=Date.now(),s=o.map(function(e){var t=zg(e,r);return e.dispose(),t}),i.stage3_onet=Date.now()-a,c=s.length>1?Un(s.map(function(e){return e.scores})):s[0].scores,d=(u=Array).from,[4,c.data()];case 2:return l=d.apply(u,[b.sent()]),c.dispose(),f=l.map(function(e,t){return{score:e,idx:t}}).filter(function(e){return e.score>n}).map(function(e){return e.idx}),p=f.map(function(e){var t=s[e].regions.arraySync();return new Og(t[0][0],t[0][1],t[0][2],t[0][3])}),m=f.map(function(e,n){return t[e].calibrate(p[n])}),h=f.map(function(e){return l[e]}),g=[],_=[],v=[],m.length>0&&(a=Date.now(),y=Op(m,h,.7,!1),i.stage3_nms=Date.now()-a,g=y.map(function(e){return m[e]}),_=y.map(function(e){return h[e]}),v=y.map(function(e,t){return[,,,,,].fill(0).map(function(n,r){var i=s[e].points.arraySync();return new xp(i[0][r]*(g[t].width+1)+g[t].left,i[0][r+5]*(g[t].height+1)+g[t].top)})})),s.forEach(function(e){e.regions.dispose(),e.scores.dispose(),e.points.dispose()}),[2,{boxes:g,scores:_,points:v}]}})})}var Vg=function(e){Z(t,e);function t(){return e.call(this,`Mtcnn`)||this}return t.prototype.load=function(t){return Q(this,void 0,void 0,function(){return $(this,function(n){return console.warn(`mtcnn is deprecated and will be removed soon`),[2,e.prototype.load.call(this,t)]})})},t.prototype.loadFromDisk=function(t){return Q(this,void 0,void 0,function(){return $(this,function(n){return console.warn(`mtcnn is deprecated and will be removed soon`),[2,e.prototype.loadFromDisk.call(this,t)]})})},t.prototype.forwardInput=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S;return $(this,function(C){switch(C.label){case 0:if(n=this.params,!n)throw Error(`Mtcnn - load model before inference`);if(r=e.canvases[0],!r)throw Error(`Mtcnn - inputCanvas is not defined, note that passing tensors into Mtcnn.forwardInput is not supported yet.`);return i={},a=Date.now(),o=H(function(){return xg(mr(zf.fromPixels(r)).toFloat())}),s=function(e){return o.dispose(),i.total=Date.now()-a,e},c=o.shape.slice(1),l=c[0],u=c[1],d=new Nh(t),f=d.minFaceSize,p=d.scaleFactor,m=d.maxNumScales,h=d.scoreThresholds,g=d.scaleSteps,_=(g||Dg(f,p,[l,u])).filter(function(e){var t=Eg(e,[l,u]);return Math.min(t.width,t.height)>12}).slice(0,m),i.scales=_,i.pyramid=_.map(function(e){return Eg(e,[l,u])}),v=Date.now(),[4,Fg(o,_,h[0],n.pnet,i)];case 1:return y=C.sent(),i.total_stage1=Date.now()-v,y.boxes.length?(i.stage2_numInputBoxes=y.boxes.length,v=Date.now(),[4,Rg(r,y.boxes,h[1],n.rnet,i)]):[2,s({results:[],stats:i})];case 2:return b=C.sent(),i.total_stage2=Date.now()-v,b.boxes.length?(i.stage3_numInputBoxes=b.boxes.length,v=Date.now(),[4,Bg(r,b.boxes,h[2],n.onet,i)]):[2,s({results:[],stats:i})];case 3:return x=C.sent(),i.total_stage3=Date.now()-v,S=x.boxes.map(function(e,t){return Qm(Up({},new Tp(x.scores[t],new Mp(e.left/u,e.top/l,e.width/u,e.height/l),{height:l,width:u})),new Lp(x.points[t].map(function(t){return t.sub(new xp(e.left,e.top)).div(new xp(e.width,e.height))}),{width:e.width,height:e.height}))}),[2,s({results:S,stats:i})]}})})},t.prototype.forward=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return n=this.forwardInput,[4,gm(e)];case 1:return[4,n.apply(this,[r.sent(),t])];case 2:return[2,r.sent().results]}})})},t.prototype.forwardWithStats=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return n=this.forwardInput,[4,gm(e)];case 1:return[2,n.apply(this,[r.sent(),t])]}})})},t.prototype.getDefaultModelName=function(){return`mtcnn_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Tg(e)},t.prototype.extractParams=function(e){return Cg(e)},t}(Cm),Hg=.4,Ug=[new xp(1.603231,2.094468),new xp(6.041143,7.080126),new xp(2.882459,3.518061),new xp(4.266906,5.178857),new xp(9.041765,10.66308)],Wg=[117.001,114.697,97.404],Gg=function(e){Z(t,e);function t(){var t=this,n={withSeparableConvs:!0,iouThreshold:Hg,classes:[`face`],anchors:Ug,meanRgb:Wg,isFirstLayerConv2d:!0,filterSizes:[3,16,32,64,128,256,512]};return t=e.call(this,n)||this,t}return Object.defineProperty(t.prototype,`anchors`,{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),t.prototype.locateFaces=function(e,t){return Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return[4,this.detect(e,t)];case 1:return n=r.sent(),[2,n.map(function(e){return new Tp(e.score,e.relativeBox,{width:e.imageWidth,height:e.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return`tiny_face_detector_model`},t.prototype.extractParamsFromWeigthMap=function(t){return e.prototype.extractParamsFromWeigthMap.call(this,t)},t}(hg),Kg={ssdMobilenetv1:new Zh,tinyFaceDetector:new Gg,tinyYolov2:new gg,mtcnn:new Vg,faceLandmark68Net:new ph,faceLandmark68TinyNet:new _h,faceRecognitionNet:new kh,faceExpressionNet:new Ym,ageGenderNet:new dh},qg=function(e){Z(t,e);function t(t,n,r){var i=e.call(this)||this;return i.parentTask=t,i.input=n,i.extractedFaces=r,i}return t}(vg),Jg=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n=this;return $(this,function(r){switch(r.label){case 0:return[4,this.parentTask];case 1:return e=r.sent(),[4,yg(e,this.input,function(e){return Q(n,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,Promise.all(e.map(function(e){return Kg.faceExpressionNet.predictExpressions(e)}))];case 1:return[2,t.sent()]}})})},this.extractedFaces)];case 2:return t=r.sent(),[2,e.map(function(e,n){return Xm(e,t[n])})]}})})},t.prototype.withAgeAndGender=function(){return new $g(this,this.input)},t}(qg),Yg=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,this.parentTask];case 1:return e=n.sent(),e?[4,bg(e,this.input,function(e){return Kg.faceExpressionNet.predictExpressions(e)},this.extractedFaces)]:[2];case 2:return t=n.sent(),[2,Xm(e,t)]}})})},t.prototype.withAgeAndGender=function(){return new e_(this,this.input)},t}(qg),Xg=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new t_(this,this.input)},t.prototype.withFaceDescriptors=function(){return new i_(this,this.input)},t}(Jg),Zg=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new n_(this,this.input)},t.prototype.withFaceDescriptor=function(){return new a_(this,this.input)},t}(Yg),Qg=function(e){Z(t,e);function t(t,n,r){var i=e.call(this)||this;return i.parentTask=t,i.input=n,i.extractedFaces=r,i}return t}(vg),$g=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n=this;return $(this,function(r){switch(r.label){case 0:return[4,this.parentTask];case 1:return e=r.sent(),[4,yg(e,this.input,function(e){return Q(n,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,Promise.all(e.map(function(e){return Kg.ageGenderNet.predictAgeAndGender(e)}))];case 1:return[2,t.sent()]}})})},this.extractedFaces)];case 2:return t=r.sent(),[2,e.map(function(e,n){var r=t[n],i=r.age,a=r.gender,o=r.genderProbability;return jh(Mh(e,a,o),i)})]}})})},t.prototype.withFaceExpressions=function(){return new Jg(this,this.input)},t}(Qg),e_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r,i;return $(this,function(a){switch(a.label){case 0:return[4,this.parentTask];case 1:return e=a.sent(),e?[4,bg(e,this.input,function(e){return Kg.ageGenderNet.predictAgeAndGender(e)},this.extractedFaces)]:[2];case 2:return t=a.sent(),n=t.age,r=t.gender,i=t.genderProbability,[2,jh(Mh(e,r,i),n)]}})})},t.prototype.withFaceExpressions=function(){return new Yg(this,this.input)},t}(Qg),t_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new Xg(this,this.input)},t.prototype.withFaceDescriptors=function(){return new i_(this,this.input)},t}($g),n_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new Zg(this,this.input)},t.prototype.withFaceDescriptor=function(){return new a_(this,this.input)},t}(e_),r_=function(e){Z(t,e);function t(t,n){var r=e.call(this)||this;return r.parentTask=t,r.input=n,r}return t}(vg),i_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,this.parentTask];case 1:return e=n.sent(),[4,yg(e,this.input,function(e){return Promise.all(e.map(function(e){return Kg.faceRecognitionNet.computeFaceDescriptor(e)}))},null,function(e){return e.landmarks.align(null,{useDlibAlignment:!0})})];case 2:return t=n.sent(),[2,t.map(function(t,n){return Ah(e[n],t)})]}})})},t.prototype.withFaceExpressions=function(){return new Xg(this,this.input)},t.prototype.withAgeAndGender=function(){return new t_(this,this.input)},t}(r_),a_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,this.parentTask];case 1:return e=n.sent(),e?[4,bg(e,this.input,function(e){return Kg.faceRecognitionNet.computeFaceDescriptor(e)},null,function(e){return e.landmarks.align(null,{useDlibAlignment:!0})})]:[2];case 2:return t=n.sent(),[2,Ah(e,t)]}})})},t.prototype.withFaceExpressions=function(){return new Zg(this,this.input)},t.prototype.withAgeAndGender=function(){return new n_(this,this.input)},t}(r_),o_=function(e){Z(t,e);function t(t,n,r){var i=e.call(this)||this;return i.parentTask=t,i.input=n,i.useTinyLandmarkNet=r,i}return Object.defineProperty(t.prototype,`landmarkNet`,{get:function(){return this.useTinyLandmarkNet?Kg.faceLandmark68TinyNet:Kg.faceLandmark68Net},enumerable:!0,configurable:!0}),t}(vg),s_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r,i,a=this;return $(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return e=o.sent(),t=e.map(function(e){return e.detection}),this.input instanceof Be?[4,vm(this.input,t)]:[3,3];case 2:return r=o.sent(),[3,5];case 3:return[4,_m(this.input,t)];case 4:r=o.sent(),o.label=5;case 5:return n=r,[4,Promise.all(n.map(function(e){return a.landmarkNet.detectLandmarks(e)}))];case 6:return i=o.sent(),n.forEach(function(e){return e instanceof Be&&e.dispose()}),[2,e.map(function(e,t){return Qm(e,i[t])})]}})})},t.prototype.withFaceExpressions=function(){return new Xg(this,this.input)},t.prototype.withAgeAndGender=function(){return new t_(this,this.input)},t.prototype.withFaceDescriptors=function(){return new i_(this,this.input)},t}(o_),c_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r,i;return $(this,function(a){switch(a.label){case 0:return[4,this.parentTask];case 1:return e=a.sent(),e?(t=e.detection,this.input instanceof Be?[4,vm(this.input,[t])]:[3,3]):[2];case 2:return r=a.sent(),[3,5];case 3:return[4,_m(this.input,[t])];case 4:r=a.sent(),a.label=5;case 5:return n=r,[4,this.landmarkNet.detectLandmarks(n[0])];case 6:return i=a.sent(),n.forEach(function(e){return e instanceof Be&&e.dispose()}),[2,Qm(e,i)]}})})},t.prototype.withFaceExpressions=function(){return new Zg(this,this.input)},t.prototype.withAgeAndGender=function(){return new n_(this,this.input)},t.prototype.withFaceDescriptor=function(){return new a_(this,this.input)},t}(o_),l_=function(e){Z(t,e);function t(t,n){n===void 0&&(n=new Xh);var r=e.call(this)||this;return r.input=t,r.options=n,r}return t}(vg),u_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r;return $(this,function(i){switch(i.label){case 0:return e=this,t=e.input,n=e.options,n instanceof Nh?[4,Kg.mtcnn.forward(t,n)]:[3,2];case 1:return[2,i.sent().map(function(e){return e.detection})];case 2:if(r=n instanceof _g?function(e){return Kg.tinyFaceDetector.locateFaces(e,n)}:n instanceof Xh?function(e){return Kg.ssdMobilenetv1.locateFaces(e,n)}:n instanceof mg?function(e){return Kg.tinyYolov2.locateFaces(e,n)}:null,!r)throw Error(`detectFaces - expected options to be instance of TinyFaceDetectorOptions | SsdMobilenetv1Options | MtcnnOptions | TinyYolov2Options`);return[2,r(t)]}})})},t.prototype.runAndExtendWithFaceDetections=function(){var e=this;return new Promise(function(t){return Q(e,void 0,void 0,function(){var e;return $(this,function(n){switch(n.label){case 0:return[4,this.run()];case 1:return e=n.sent(),[2,t(e.map(function(e){return Up({},e)}))]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new s_(this.runAndExtendWithFaceDetections(),this.input,e)},t.prototype.withFaceExpressions=function(){return new Jg(this.runAndExtendWithFaceDetections(),this.input)},t.prototype.withAgeAndGender=function(){return new $g(this.runAndExtendWithFaceDetections(),this.input)},t}(l_);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,new u_(this.input,this.options)];case 1:return e=n.sent(),t=e[0],e.forEach(function(e){e.score>t.score&&(t=e)}),[2,t]}})})},t.prototype.runAndExtendWithFaceDetection=function(){var e=this;return new Promise(function(t){return Q(e,void 0,void 0,function(){var e;return $(this,function(n){switch(n.label){case 0:return[4,this.run()];case 1:return e=n.sent(),[2,t(e?Up({},e):void 0)]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new c_(this.runAndExtendWithFaceDetection(),this.input,e)},t.prototype.withFaceExpressions=function(){return new Yg(this.runAndExtendWithFaceDetection(),this.input)},t.prototype.withAgeAndGender=function(){return new e_(this.runAndExtendWithFaceDetection(),this.input)},t})(l_);function d_(e,t){return t===void 0&&(t=new Xh),new u_(e,t)}function f_(e,t){if(e.length!==t.length)throw Error(`euclideanDistance: arr1.length !== arr2.length`);var n=Array.from(e),r=Array.from(t);return Math.sqrt(n.map(function(e,t){return e-r[t]}).reduce(function(e,t){return e+t**2},0))}(function(){function e(e,t){t===void 0&&(t=.6),this._distanceThreshold=t;var n=Array.isArray(e)?e:[e];if(!n.length)throw Error(`FaceRecognizer.constructor - expected atleast one input`);var r=1,i=function(){return`person `+ r++};this._labeledDescriptors=n.map(function(e){if(e instanceof Vp)return e;if(e instanceof Float32Array)return new Vp(i(),[e]);if(e.descriptor&&e.descriptor instanceof Float32Array)return new Vp(i(),[e.descriptor]);throw Error(`FaceRecognizer.constructor - expected inputs to be of type LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array | Array<LabeledFaceDescriptors | WithFaceDescriptor<any> | 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(e,t){return t.map(function(t){return f_(t,e)}).reduce(function(e,t){return e+t},0)/(t.length||1)},e.prototype.matchDescriptor=function(e){var t=this;return this.labeledDescriptors.map(function(n){var r=n.descriptors,i=n.label;return new zp(i,t.computeMeanDistance(e,r))}).reduce(function(e,t){return e.distance<t.distance?e:t})},e.prototype.findBestMatch=function(e){var t=this.matchDescriptor(e);return t.distance<this.distanceThreshold?t:new zp(`unknown`,t.distance)},e.prototype.toJSON=function(){return{distanceThreshold:this.distanceThreshold,labeledDescriptors:this.labeledDescriptors.map(function(e){return e.toJSON()})}},e.fromJSON=function(t){return new e(t.labeledDescriptors.map(function(e){return Vp.fromJSON(e)}),t.distanceThreshold)},e})();function p_(){let e=!1;return{load:async t=>{e||=(await Kg.tinyFaceDetector.loadFromUri(t),!0)},detect:async t=>{if(!e)return{faces:0};let n=await d_(t,new _g({inputSize:224,scoreThreshold:.5}));if(!n||n.length===0)return{faces:0};if(n.length>1)return{faces:n.length};let r=n[0].box,i=t.videoWidth||1,a=t.videoHeight||1;return{faces:1,box:{x:r.x/i,y:r.y/a,width:r.width/i,height:r.height/a}}}}}function m_(e){if(e.faces===0)return{message:`Centralize seu rosto`,valid:!1};if(e.faces>1)return{message:`Apenas 1 rosto por vez`,valid:!1};if(!e.box)return{message:`Centralize seu rosto`,valid:!1};let{x:t,y:n,width:r,height:i}=e.box,a=t+r/2,o=n+i/2,s=r*i;return s<.07?{message:`Aproxime o rosto`,valid:!1}:s>.22?{message:`Afaste o rosto`,valid:!1}:Math.abs(a-.5)>.12||Math.abs(o-.5)>.12?{message:`Centralize seu rosto`,valid:!1}:{message:`Pronto para capturar`,valid:!0}}e.AlphaValid=class{_camera=null;_overlay=null;_container=null;_faceDetector=p_();_loopTimer=null;_lastStatusValid=!1;_options=null;async start(e){n(e.container,`options.container`),await this.stop(),this._options={overlay:!0,guideCircleRatio:.72,detectionIntervalMs:200,modelsPath:`/models`,...e},this._container=this._options.container;try{this._options.onFeedback?.(`Inicializando câmera...`),this._camera=await r(this._container),this._options.overlay!==!1&&(this._overlay=a(this._container,this._options.guideCircleRatio)),this._options.onReady?.(),this._options.modelsPath&&await this._faceDetector.load(this._options.modelsPath),this.startDetectionLoop()}catch(e){throw this._options?.onError?.(e),await this.stop(),e}}async stop(){this._loopTimer!=null&&(window.clearTimeout(this._loopTimer),this._loopTimer=null),this._lastStatusValid=!1,this._overlay&&=(this._overlay.dispose(),null),this._camera&&=(this._camera.stop(),null),this._container=null,this._options=null}async capture(){if(!this._camera)throw Error(`Camera not started. Call start() first.`);if(!this._lastStatusValid)throw Error(`Face not valid for capture yet. Wait for feedback "Pronto para capturar".`);return await i(this._camera.video,.9)}startDetectionLoop(){let e=async()=>{let t=this._camera,n=this._options;if(!(!t||!n))try{let e=await this._faceDetector.detect(t.video),r=m_(e);this._lastStatusValid=r.valid,n.onFeedback?.(r.message),this._overlay?.render({message:r.message,box:e.box,valid:r.valid})}catch(e){n.onError?.(e)}finally{this._loopTimer=window.setTimeout(e,n.detectionIntervalMs??200)}};e()}}});
3804
+ Expected: `+l+`.`)}}function qf(e,t,n){return!isFinite(e)&&!isFinite(t)||!(isNaN(e)||isNaN(t)||Math.abs(e-t)>n)}Object.freeze({TEST_EPSILON_FLOAT16:Wf,expectArraysClose:function(e,t,n){return n??=Gf(),Kf(e,t,(function(e,t){return qf(e,t,n)}))},testEpsilon:Gf,expectPromiseToFail:function(e,t){e().then((function(){return t.fail()}),(function(){return t()}))},expectArraysEqual:function(e,t){var n=typeof t==`string`||typeof t==`number`||typeof t==`boolean`?[t]:t;return de(e)||de(e[0])||de(t)||de(t[0])?Kf(e,n,(function(e,t){return e==t})):Kf(e,t,(function(e,t){return qf(e,t,0)}))},expectNumbersClose:function(e,t,n){if(n??=Gf(),!qf(e,t,n))throw Error(`Numbers differ: actual === `+e+`, expected === `+t)},expectValuesInRange:function(e,t,n){for(var r=0;r<e.length;r++)if(e[r]<t||e[r]>n)throw Error(`Value out of range:`+e[r]+` low: `+t+`, high: `+n)},expectArrayBuffersEqual:function(e,t){expect(new Float32Array(e)).toEqual(new Float32Array(t))}}),Object.freeze({gpgpu_util:_o,webgl_util:on,forceHalfFloat:function(){p().set(`WEBGL_FORCE_F16_TEXTURES`,!0)},MathBackendWebGL:Ps,setWebGLContext:lt,GPGPUContext:vo});var Jf=function(e){function t(){return e!==null&&e.apply(this,arguments)||this}return c(t,e),t.prototype.minimize=function(e,t,n){t===void 0&&(t=!1);var r=this.computeGradients(e,n),i=r.value,a=r.grads;if(n!=null){var o=n.map((function(e){return{name:e.name,tensor:a[e.name]}}));this.applyGradients(o)}else this.applyGradients(a);return cn(a),t?i:(i.dispose(),null)},Object.defineProperty(t.prototype,`iterations`,{get:function(){return this.iterations_??=0,this.iterations_},enumerable:!0,configurable:!0}),t.prototype.incrementIterations=function(){this.iterations_=this.iterations+1},t.prototype.computeGradients=function(e,t){return $r(e,t)},t.prototype.dispose=function(){this.iterations_!=null&&cn(this.iterations_)},t.prototype.saveIterations=function(){return l(this,void 0,void 0,(function(){return u(this,(function(e){return this.iterations_??=0,[2,{name:`iter`,tensor:G(this.iterations_,`int32`)}]}))}))},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){return u(this,(function(e){throw Error(`getWeights() is not implemented for this optimizer yet.`)}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){return u(this,(function(e){throw Error(`setWeights() is not implemented for this optimizer class `+this.getClassName())}))}))},t.prototype.extractIterations=function(e){return l(this,void 0,void 0,(function(){var t;return u(this,(function(n){switch(n.label){case 0:return t=this,[4,e[0].tensor.data()];case 1:return t.iterations_=n.sent()[0],[2,e.slice(1)]}}))}))},t}(Bf);Object.defineProperty(Jf,Symbol.hasInstance,{value:function(e){return e.minimize!=null&&e.computeGradients!=null&&e.applyGradients!=null}});var Yf=function(e){function t(t,n,r){r===void 0&&(r=null);var i=e.call(this)||this;return i.learningRate=t,i.rho=n,i.epsilon=r,i.accumulatedGrads=[],i.accumulatedUpdates=[],r??(i.epsilon=z.backend.epsilon()),i}return c(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=z.registeredVariables[n];t.accumulatedGrads[r]??(t.accumulatedGrads[r]={originalName:n+`/accum_grad`,variable:H((function(){return Hn(i).variable(!1)}))}),t.accumulatedUpdates[r]??(t.accumulatedUpdates[r]={originalName:n+`/accum_var`,variable:H((function(){return Hn(i).variable(!1)}))});var a=Array.isArray(e)?e[r].tensor:e[n];if(a!=null){var o=t.accumulatedGrads[r].variable,s=t.accumulatedUpdates[r].variable;H((function(){var e=o.mul(t.rho).add(a.square().mul(1-t.rho)),n=s.add(t.epsilon).sqrt().div(o.add(t.epsilon).sqrt()).mul(a),r=s.mul(t.rho).add(n.square().mul(1-t.rho));o.assign(e),s.assign(r);var c=n.mul(-t.learningRate).add(i);i.assign(c)}))}})),this.incrementIterations()},t.prototype.dispose=function(){this.accumulatedUpdates!=null&&(cn(this.accumulatedGrads.map((function(e){return e.variable}))),cn(this.accumulatedUpdates.map((function(e){return e.variable}))))},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return e=this.accumulatedGrads.concat(this.accumulatedUpdates),[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(e.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){var t;return u(this,(function(n){switch(n.label){case 0:return[4,this.extractIterations(e)];case 1:return e=n.sent(),t=e.length/2,this.accumulatedGrads=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.accumulatedUpdates=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,rho:this.rho,epsilon:this.epsilon}},t.fromConfig=function(e,t){return new e(t.learningRate,t.rho,t.epsilon)},t.className=`Adadelta`,t}(Jf);Hf(Yf);var Xf=function(e){function t(t,n){n===void 0&&(n=.1);var r=e.call(this)||this;return r.learningRate=t,r.initialAccumulatorValue=n,r.accumulatedGrads=[],r}return c(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=z.registeredVariables[n];t.accumulatedGrads[r]??(t.accumulatedGrads[r]={originalName:n+`/accumulator`,variable:H((function(){return Rn(i.shape,t.initialAccumulatorValue).variable(!1)}))});var a=Array.isArray(e)?e[r].tensor:e[n];if(a!=null){var o=t.accumulatedGrads[r].variable;H((function(){var e=o.add(a.square());o.assign(e);var n=a.div(e.add(z.backend.epsilon()).sqrt()).mul(-t.learningRate).add(i);i.assign(n)}))}})),this.incrementIterations()},t.prototype.dispose=function(){this.accumulatedGrads!=null&&cn(this.accumulatedGrads.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(this.accumulatedGrads.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){return u(this,(function(t){switch(t.label){case 0:return[4,this.extractIterations(e)];case 1:return e=t.sent(),this.accumulatedGrads=e.map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,initialAccumulatorValue:this.initialAccumulatorValue}},t.fromConfig=function(e,t){return new e(t.learningRate,t.initialAccumulatorValue)},t.className=`Adagrad`,t}(Jf);Hf(Xf);var Zf=function(e){function t(t,n,r,i){i===void 0&&(i=null);var a=e.call(this)||this;return a.learningRate=t,a.beta1=n,a.beta2=r,a.epsilon=i,a.accumulatedFirstMoment=[],a.accumulatedSecondMoment=[],H((function(){a.accBeta1=G(n).variable(),a.accBeta2=G(r).variable()})),i??(a.epsilon=z.backend.epsilon()),a}return c(t,e),t.prototype.applyGradients=function(e){var t=this,n=Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e);H((function(){var r=rl(1,t.accBeta1),i=rl(1,t.accBeta2);n.forEach((function(n,a){var o=z.registeredVariables[n];t.accumulatedFirstMoment[a]??(t.accumulatedFirstMoment[a]={originalName:n+`/m`,variable:H((function(){return Hn(o).variable(!1)}))}),t.accumulatedSecondMoment[a]??(t.accumulatedSecondMoment[a]={originalName:n+`/v`,variable:H((function(){return Hn(o).variable(!1)}))});var s=Array.isArray(e)?e[a].tensor:e[n];if(s!=null){var c=t.accumulatedFirstMoment[a].variable,l=t.accumulatedSecondMoment[a].variable,u=c.mul(t.beta1).add(s.mul(1-t.beta1)),d=l.mul(t.beta2).add(s.square().mul(1-t.beta2)),f=u.div(r),p=d.div(i);c.assign(u),l.assign(d);var m=f.div(p.sqrt().add(t.epsilon)).mul(-t.learningRate).add(o);o.assign(m)}})),t.accBeta1.assign(t.accBeta1.mul(t.beta1)),t.accBeta2.assign(t.accBeta2.mul(t.beta2))})),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.accBeta2.dispose(),this.accumulatedFirstMoment!=null&&cn(this.accumulatedFirstMoment.map((function(e){return e.variable}))),this.accumulatedSecondMoment!=null&&cn(this.accumulatedSecondMoment.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return e=this.accumulatedFirstMoment.concat(this.accumulatedSecondMoment),[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(e.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){var t,n=this;return u(this,(function(r){switch(r.label){case 0:return[4,this.extractIterations(e)];case 1:return e=r.sent(),H((function(){n.accBeta1.assign(el(n.beta1,n.iterations_+1)),n.accBeta2.assign(el(n.beta2,n.iterations_+1))})),t=e.length/2,this.accumulatedFirstMoment=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.accumulatedSecondMoment=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon}},t.fromConfig=function(e,t){return new e(t.learningRate,t.beta1,t.beta2,t.epsilon)},t.className=`Adam`,t}(Jf);Hf(Zf);var Qf=function(e){function t(t,n,r,i,a){i===void 0&&(i=null),a===void 0&&(a=0);var o=e.call(this)||this;return o.learningRate=t,o.beta1=n,o.beta2=r,o.epsilon=i,o.decay=a,o.accumulatedFirstMoment=[],o.accumulatedWeightedInfNorm=[],H((function(){o.iteration=G(0).variable(),o.accBeta1=G(n).variable()})),i??(o.epsilon=z.backend.epsilon()),o}return c(t,e),t.prototype.applyGradients=function(e){var t=this,n=Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e);H((function(){var r=rl(1,t.accBeta1),i=Hc(-t.learningRate,t.iteration.mul(t.decay).add(1));n.forEach((function(n,a){var o=z.registeredVariables[n];t.accumulatedFirstMoment[a]??(t.accumulatedFirstMoment[a]={originalName:n+`/m`,variable:Hn(o).variable(!1)}),t.accumulatedWeightedInfNorm[a]??(t.accumulatedWeightedInfNorm[a]={originalName:n+`/v`,variable:Hn(o).variable(!1)});var s=Array.isArray(e)?e[a].tensor:e[n];if(s!=null){var c=t.accumulatedFirstMoment[a].variable,l=t.accumulatedWeightedInfNorm[a].variable,u=c.mul(t.beta1).add(s.mul(1-t.beta1)),d=l.mul(t.beta2),f=s.abs(),p=d.maximum(f);c.assign(u),l.assign(p);var m=i.div(r).mul(u.div(p.add(t.epsilon))).add(o);o.assign(m)}})),t.iteration.assign(t.iteration.add(1)),t.accBeta1.assign(t.accBeta1.mul(t.beta1))})),this.incrementIterations()},t.prototype.dispose=function(){this.accBeta1.dispose(),this.iteration.dispose(),this.accumulatedFirstMoment!=null&&cn(this.accumulatedFirstMoment.map((function(e){return e.variable}))),this.accumulatedWeightedInfNorm!=null&&cn(this.accumulatedWeightedInfNorm.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){return u(this,(function(e){throw Error(`getWeights() is not implemented for Adamax yet.`)}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){return u(this,(function(e){throw Error(`setWeights() is not implemented for Adamax yet.`)}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon,decay:this.decay}},t.fromConfig=function(e,t){return new e(t.learningRate,t.beta1,t.beta2,t.epsilon,t.decay)},t.className=`Adamax`,t}(Jf);Hf(Qf);var $f=function(e){function t(t){var n=e.call(this)||this;return n.learningRate=t,n.setLearningRate(t),n}return c(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=Array.isArray(e)?e[r].tensor:e[n];if(i!=null){var a=z.registeredVariables[n];H((function(){var e=t.c.mul(i).add(a);a.assign(e)}))}})),this.incrementIterations()},t.prototype.setLearningRate=function(e){this.learningRate=e,this.c!=null&&this.c.dispose(),this.c=ln(G(-e))},t.prototype.dispose=function(){this.c.dispose()},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()]]}}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){return u(this,(function(t){switch(t.label){case 0:return[4,this.extractIterations(e)];case 1:if((e=t.sent()).length!==0)throw Error(`SGD optimizer does not have settable weights.`);return[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate}},t.fromConfig=function(e,t){return new e(t.learningRate)},t.className=`SGD`,t}(Jf);Hf($f);var ep=function(e){function t(t,n,r){r===void 0&&(r=!1);var i=e.call(this,t)||this;return i.learningRate=t,i.momentum=n,i.useNesterov=r,i.accumulations=[],i.m=G(i.momentum),i}return c(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=z.registeredVariables[n];t.accumulations[r]??(t.accumulations[r]={originalName:n+`/momentum`,variable:H((function(){return Hn(i).variable(!1)}))});var a=t.accumulations[r].variable,o=Array.isArray(e)?e[r].tensor:e[n];o!=null&&H((function(){var e,n=t.m.mul(a).add(o);e=t.useNesterov?t.c.mul(o.add(n.mul(t.m))).add(i):t.c.mul(n).add(i),a.assign(n),i.assign(e)}))})),this.incrementIterations()},t.prototype.dispose=function(){this.m.dispose(),this.accumulations!=null&&cn(this.accumulations.map((function(e){return e.variable})))},t.prototype.setMomentum=function(e){this.momentum=e},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(this.accumulations.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){return u(this,(function(t){switch(t.label){case 0:return[4,this.extractIterations(e)];case 1:return e=t.sent(),this.accumulations=e.map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,momentum:this.momentum,useNesterov:this.useNesterov}},t.fromConfig=function(e,t){return new e(t.learningRate,t.momentum,t.useNesterov)},t.className=`Momentum`,t}($f);Hf(ep);var tp=function(e){function t(t,n,r,i,a){n===void 0&&(n=.9),r===void 0&&(r=0),i===void 0&&(i=null),a===void 0&&(a=!1);var o=e.call(this)||this;if(o.learningRate=t,o.decay=n,o.momentum=r,o.epsilon=i,o.accumulatedMeanSquares=[],o.accumulatedMoments=[],o.accumulatedMeanGrads=[],o.centered=a,i??(o.epsilon=z.backend.epsilon()),t==null)throw Error(`learningRate for RMSPropOptimizer must be defined.`);return o}return c(t,e),t.prototype.applyGradients=function(e){var t=this;(Array.isArray(e)?e.map((function(e){return e.name})):Object.keys(e)).forEach((function(n,r){var i=z.registeredVariables[n];t.accumulatedMeanSquares[r]??(t.accumulatedMeanSquares[r]={originalName:n+`/rms`,variable:H((function(){return Hn(i).variable(!1)}))}),t.accumulatedMoments[r]??(t.accumulatedMoments[r]={originalName:n+`/momentum`,variable:H((function(){return Hn(i).variable(!1)}))}),t.accumulatedMeanGrads[r]==null&&t.centered&&(t.accumulatedMeanGrads[r]={originalName:n+`/mg`,variable:H((function(){return Hn(i).variable(!1)}))});var a=Array.isArray(e)?e[r].tensor:e[n];if(a!=null){var o=t.accumulatedMeanSquares[r].variable,s=t.accumulatedMoments[r].variable;H((function(){var e=o.mul(t.decay).add(a.square().mul(1-t.decay));if(t.centered){var n=t.accumulatedMeanGrads[r].variable,c=n.mul(t.decay).add(a.mul(1-t.decay)),l=s.mul(t.momentum).add(a.mul(t.learningRate).div(e.sub(c.square().add(t.epsilon)).sqrt()));o.assign(e),n.assign(c),s.assign(l);var u=i.sub(l);i.assign(u)}else{var d=o.mul(t.decay).add(a.square().mul(1-t.decay));l=s.mul(t.momentum).add(a.mul(t.learningRate).div(d.add(t.epsilon).sqrt())),o.assign(d),s.assign(l),u=i.sub(l),i.assign(u)}}))}})),this.incrementIterations()},t.prototype.dispose=function(){this.accumulatedMeanSquares!=null&&cn(this.accumulatedMeanSquares.map((function(e){return e.variable}))),this.accumulatedMeanGrads!=null&&this.centered&&cn(this.accumulatedMeanGrads.map((function(e){return e.variable}))),this.accumulatedMoments!=null&&cn(this.accumulatedMoments.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return l(this,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return e=this.accumulatedMeanSquares.concat(this.accumulatedMoments),this.centered&&e.push.apply(e,this.accumulatedMeanGrads),[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(e.map((function(e){return{name:e.originalName,tensor:e.variable}})))]}}))}))},t.prototype.setWeights=function(e){return l(this,void 0,void 0,(function(){var t;return u(this,(function(n){switch(n.label){case 0:return[4,this.extractIterations(e)];case 1:return e=n.sent(),t=this.centered?e.length/3:e.length/2,this.accumulatedMeanSquares=e.slice(0,t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.accumulatedMoments=e.slice(t,2*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}})),this.centered&&(this.accumulatedMeanGrads=e.slice(2*t,3*t).map((function(e){return{originalName:e.name,variable:e.tensor.variable(!1)}}))),[2]}}))}))},t.prototype.getConfig=function(){return{learningRate:this.learningRate,decay:this.decay,momentum:this.momentum,epsilon:this.epsilon,centered:this.centered}},t.fromConfig=function(e,t){return new e(t.learningRate,t.decay,t.momentum,t.epsilon,t.centered)},t.className=`RMSProp`,t}(Jf);Hf(tp);var np=function(){function e(){}return e.sgd=function(e){return new $f(e)},e.momentum=function(e,t,n){return n===void 0&&(n=!1),new ep(e,t,n)},e.rmsprop=function(e,t,n,r,i){return t===void 0&&(t=.9),n===void 0&&(n=0),r===void 0&&(r=null),i===void 0&&(i=!1),new tp(e,t,n,r,i)},e.adam=function(e,t,n,r){return e===void 0&&(e=.001),t===void 0&&(t=.9),n===void 0&&(n=.999),r===void 0&&(r=null),new Zf(e,t,n,r)},e.adadelta=function(e,t,n){return e===void 0&&(e=.001),t===void 0&&(t=.95),n===void 0&&(n=null),new Yf(e,t,n)},e.adamax=function(e,t,n,r,i){return e===void 0&&(e=.002),t===void 0&&(t=.9),n===void 0&&(n=.999),r===void 0&&(r=null),i===void 0&&(i=0),new Qf(e,t,n,r,i)},e.adagrad=function(e,t){return t===void 0&&(t=.1),new Xf(e,t)},e}();np.sgd,np.momentum,np.adadelta,np.adagrad,np.rmsprop,np.adamax,np.adam,Be.prototype.squaredDifference=function(e){return Ls(this,e)},R=wd;function rp(e,t,n){if(n===void 0&&(n=!1),e.beginPath(),t.slice(1).forEach(function(n,r){var i=n.x,a=n.y,o=t[r];e.moveTo(o.x,o.y),e.lineTo(i,a)}),n){var r=t[t.length-1],i=t[0];if(!r||!i)return;e.moveTo(r.x,r.y),e.lineTo(i.x,i.y)}e.stroke()}var ip=function(e,t){return ip=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])},ip(e,t)};function Z(e,t){ip(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}var ap=function(){return ap=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},ap.apply(this,arguments)};function Q(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})}function $(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(o){if(r)throw TypeError(`Generator is already executing.`);for(;n;)try{if(r=1,i&&(a=o[0]&2?i.return:o[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,o[1])).done)return a;switch(i=0,a&&(o=[o[0]&2,a.value]),o[0]){case 0:case 1:a=o;break;case 4:return n.label++,{value:o[1],done:!1};case 5:n.label++,i=o[1],o=[0];continue;case 7:o=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(o[0]===6||o[0]===2)){n=0;continue}if(o[0]===3&&(!a||o[1]>a[0]&&o[1]<a[3])){n.label=o[1];break}if(o[0]===6&&n.label<a[1]){n.label=a[1],a=o;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(o);break}a[2]&&n.ops.pop(),n.trys.pop();continue}o=t.call(e,n)}catch(e){o=[6,e],i=0}finally{r=a=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}}function op(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var r=Array(e),i=0,t=0;t<n;t++)for(var a=arguments[t],o=0,s=a.length;o<s;o++,i++)r[i]=a[o];return r}var sp=function(){function e(e,t){if(!yp(e)||!yp(t))throw Error(`Dimensions.constructor - expected width and height to be valid numbers, instead have `+JSON.stringify({width:e,height:t}));this._width=e,this._height=t}return Object.defineProperty(e.prototype,`width`,{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`height`,{get:function(){return this._height},enumerable:!0,configurable:!0}),e.prototype.reverse=function(){return new e(1/this.width,1/this.height)},e}();function cp(e,t){return e instanceof Be&&e.shape.length===t}function lp(e){return cp(e,2)}function up(e){return cp(e,3)}function dp(e){return cp(e,4)}function fp(e){return e%1!=0}function pp(e){return e%2==0}function mp(e,t){t===void 0&&(t=2);var n=10**t;return Math.floor(e*n)/n}function hp(e){return e&&e.width&&e.height}function gp(e,t){var n=e.width,r=e.height,i=t/Math.max(r,n);return new sp(Math.round(n*i),Math.round(r*i))}function _p(e){return e.reduce(function(e,t){return e.add(t)},new xp(0,0)).div(new xp(e.length,e.length))}function vp(e,t,n){return Array(e).fill(0).map(function(e,r){return t+r*n})}function yp(e){return!!e&&e!==1/0&&e!==-1/0&&!isNaN(e)||e===0}function bp(e){return yp(e)&&0<=e&&e<=1}var xp=function(){function e(e,t){this._x=e,this._y=t}return Object.defineProperty(e.prototype,`x`,{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`y`,{get:function(){return this._y},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return new e(this.x+t.x,this.y+t.y)},e.prototype.sub=function(t){return new e(this.x-t.x,this.y-t.y)},e.prototype.mul=function(t){return new e(this.x*t.x,this.y*t.y)},e.prototype.div=function(t){return new e(this.x/t.x,this.y/t.y)},e.prototype.abs=function(){return new e(Math.abs(this.x),Math.abs(this.y))},e.prototype.magnitude=function(){return Math.sqrt(this.x**2+this.y**2)},e.prototype.floor=function(){return new e(Math.floor(this.x),Math.floor(this.y))},e}(),Sp=function(){function e(t,n){n===void 0&&(n=!0);var r=t||{},i=[r.left,r.top,r.right,r.bottom].every(yp),a=[r.x,r.y,r.width,r.height].every(yp);if(!a&&!i)throw Error(`Box.constructor - expected box to be IBoundingBox | IRect, instead have `+JSON.stringify(r));var o=a?[r.x,r.y,r.width,r.height]:[r.left,r.top,r.right-r.left,r.bottom-r.top],s=o[0],c=o[1],l=o[2],u=o[3];e.assertIsValidBox({x:s,y:c,width:l,height:u},`Box.constructor`,n),this._x=s,this._y=c,this._width=l,this._height=u}return e.isRect=function(e){return!!e&&[e.x,e.y,e.width,e.height].every(yp)},e.assertIsValidBox=function(t,n,r){if(r===void 0&&(r=!1),!e.isRect(t))throw Error(n+` - invalid box: `+JSON.stringify(t)+`, expected object with properties x, y, width, height`);if(!r&&(t.width<0||t.height<0))throw Error(n+` - width (`+t.width+`) and height (`+t.height+`) must be positive numbers`)},Object.defineProperty(e.prototype,`x`,{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`y`,{get:function(){return this._y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`width`,{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`height`,{get:function(){return this._height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`left`,{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`top`,{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`right`,{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottom`,{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`area`,{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`topLeft`,{get:function(){return new xp(this.left,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`topRight`,{get:function(){return new xp(this.right,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottomLeft`,{get:function(){return new xp(this.left,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottomRight`,{get:function(){return new xp(this.right,this.bottom)},enumerable:!0,configurable:!0}),e.prototype.round=function(){var t=[this.x,this.y,this.width,this.height].map(function(e){return Math.round(e)}),n=t[0],r=t[1],i=t[2],a=t[3];return new e({x:n,y:r,width:i,height:a})},e.prototype.floor=function(){var t=[this.x,this.y,this.width,this.height].map(function(e){return Math.floor(e)}),n=t[0],r=t[1],i=t[2],a=t[3];return new e({x:n,y:r,width:i,height:a})},e.prototype.toSquare=function(){var t=this,n=t.x,r=t.y,i=t.width,a=t.height,o=Math.abs(i-a);return i<a&&(n-=o/2,i+=o),a<i&&(r-=o/2,a+=o),new e({x:n,y:r,width:i,height:a})},e.prototype.rescale=function(t){var n=hp(t)?t.width:t,r=hp(t)?t.height:t;return new e({x:this.x*n,y:this.y*r,width:this.width*n,height:this.height*r})},e.prototype.pad=function(t,n){var r=[this.x-t/2,this.y-n/2,this.width+t,this.height+n],i=r[0],a=r[1],o=r[2],s=r[3];return new e({x:i,y:a,width:o,height:s})},e.prototype.clipAtImageBorders=function(t,n){var r=this,i=r.x,a=r.y,o=r.right,s=r.bottom,c=Math.max(i,0),l=Math.max(a,0),u=o-c,d=s-l;return new e({x:c,y:l,width:Math.min(u,t-c),height:Math.min(d,n-l)}).floor()},e.prototype.shift=function(t,n){var r=this,i=r.width,a=r.height;return new e({x:this.x+t,y:this.y+n,width:i,height:a})},e.prototype.padAtBorders=function(e,t){var n=this.width+1,r=this.height+1,i=1,a=1,o=n,s=r,c=this.left,l=this.top,u=this.right,d=this.bottom;return u>t&&(o=-u+t+n,u=t),d>e&&(s=-d+e+r,d=e),c<1&&(s=2-c,c=1),l<1&&(s=2-l,l=1),{dy:a,edy:s,dx:i,edx:o,y:l,ey:d,x:c,ex:u,w:n,h:r}},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}(),Cp=function(e){Z(t,e);function t(t,n,r,i,a){return a===void 0&&(a=!1),e.call(this,{left:t,top:n,right:r,bottom:i},a)||this}return t}(Sp),wp=function(){function e(e,t,n,r,i){this._imageDims=new sp(i.width,i.height),this._score=e,this._classScore=t,this._className=n,this._box=new Sp(r).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 Sp(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}(),Tp=function(e){Z(t,e);function t(t,n,r){return e.call(this,t,t,``,n,r)||this}return t.prototype.forSize=function(n,r){var i=e.prototype.forSize.call(this,n,r),a=i.score,o=i.relativeBox,s=i.imageDims;return new t(a,o,s)},t}(wp);function Ep(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))*Math.max(0,Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top));return n?r/(e.area+t.area-r):r/Math.min(e.area,t.area)}function Dp(e){var t=e.map(function(e){return e.x}),n=e.map(function(e){return e.y});return new Cp(t.reduce(function(e,t){return t<e?t:e},1/0),n.reduce(function(e,t){return t<e?t:e},1/0),t.reduce(function(e,t){return e<t?t:e},0),n.reduce(function(e,t){return e<t?t:e},0))}function Op(e,t,n,r){r===void 0&&(r=!0);for(var i=t.map(function(e,t){return{score:e,boxIndex:t}}).sort(function(e,t){return e.score-t.score}).map(function(e){return e.boxIndex}),a=[],o=function(){var t=i.pop();a.push(t);for(var o=i,s=[],c=0;c<o.length;c++){var l=o[c],u=e[t],d=e[l];s.push(Ep(u,d,r))}i=i.filter(function(e,t){return s[t]<=n})};i.length>0;)o();return a}function kp(e,t){return H(function(){var n=t[0],r=t[1],i=t[2];return rl(e,Un([Rn(op(e.shape.slice(0,3),[1]),n),Rn(op(e.shape.slice(0,3),[1]),r),Rn(op(e.shape.slice(0,3),[1]),i)],3))})}function Ap(e,t){return t===void 0&&(t=!1),H(function(){var n=e.shape.slice(1),r=n[0],i=n[1];if(r===i)return e;var a=Math.abs(r-i),o=Math.round(a*(t?.5:1)),s=r>i?2:1,c=function(t){var n=e.shape.slice();return n[s]=t,Rn(n,0)},l=c(o),u=a-l.shape[s];return Un([t&&u?c(u):null,e,l].filter(function(e){return!!e}).map(function(e){return e.toFloat()}),s)})}function jp(e){return 1/(1+Math.exp(-e))}var Mp=function(e){Z(t,e);function t(t,n,r,i,a){return a===void 0&&(a=!1),e.call(this,{x:t,y:n,width:r,height:i},a)||this}return t}(Sp),Np=.5,Pp=.43,Fp=.45,Ip=function(){function e(e,t,n){n===void 0&&(n=new xp(0,0));var r=t.width,i=t.height;this._imgDims=new sp(r,i),this._shift=n,this._positions=e.map(function(e){return e.mul(new xp(r,i)).add(n)})}return Object.defineProperty(e.prototype,`shift`,{get:function(){return new xp(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 e=this;return this._positions.map(function(t){return t.sub(e._shift).div(new xp(e.imageWidth,e.imageHeight))})},enumerable:!0,configurable:!0}),e.prototype.forSize=function(e,t){return new this.constructor(this.relativePositions,{width:e,height:t})},e.prototype.shiftBy=function(e,t){return new this.constructor(this.relativePositions,this._imgDims,new xp(e,t))},e.prototype.shiftByPoint=function(e){return this.shiftBy(e.x,e.y)},e.prototype.align=function(e,t){if(t===void 0&&(t={}),e){var n=e instanceof Tp?e.box.floor():new Sp(e);return this.shiftBy(n.x,n.y).align(null,t)}var r=Object.assign({},{useDlibAlignment:!1,minBoxPadding:.2},t),i=r.useDlibAlignment,a=r.minBoxPadding;return i?this.alignDlib():this.alignMinBbox(a)},e.prototype.alignDlib=function(){var e=this.getRefPointsForAlignment(),t=e[0],n=e[1],r=e[2],i=function(e){return r.sub(e).magnitude()},a=(i(t)+i(n))/2,o=Math.floor(a/Fp),s=_p(e),c=Math.floor(Math.max(0,s.x-Np*o)),l=Math.floor(Math.max(0,s.y-Pp*o));return new Mp(c,l,Math.min(o,this.imageWidth+c),Math.min(o,this.imageHeight+l))},e.prototype.alignMinBbox=function(e){var t=Dp(this.positions);return t.pad(t.width*e,t.height*e)},e.prototype.getRefPointsForAlignment=function(){throw Error(`getRefPointsForAlignment not implemented by base class`)},e}(),Lp=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.getRefPointsForAlignment=function(){var e=this.positions;return[e[0],e[1],_p([e[3],e[4]])]},t}(Ip),Rp=function(e){Z(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(_p)},t}(Ip),zp=function(){function e(e,t){this._label=e,this._distance=t}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(e){return e===void 0&&(e=!0),``+this.label+(e?` (`+mp(this.distance)+`)`:``)},e}(),Bp=function(e){Z(t,e);function t(t,n){var r=e.call(this,t)||this;return r._label=n,r}return t.assertIsValidLabeledBox=function(e,t){if(Sp.assertIsValidBox(e,t),!yp(e.label))throw Error(t+` - expected property label (`+e.label+`) to be a number`)},Object.defineProperty(t.prototype,`label`,{get:function(){return this._label},enumerable:!0,configurable:!0}),t}(Sp),Vp=function(){function e(e,t){if(typeof e!=`string`)throw Error(`LabeledFaceDescriptors - constructor expected label to be a string`);if(!Array.isArray(t)||t.some(function(e){return!(e instanceof Float32Array)}))throw Error(`LabeledFaceDescriptors - constructor expected descriptors to be an array of Float32Array`);this._label=e,this._descriptors=t}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(e){return Array.from(e)})}},e.fromJSON=function(t){var n=t.descriptors.map(function(e){return new Float32Array(e)});return new e(t.label,n)},e}();(function(e){Z(t,e);function t(t,n,r,i){var a=e.call(this,t,n)||this;return a._score=r,a._classScore=i,a}return t.assertIsValidPredictedBox=function(e,t){if(Bp.assertIsValidLabeledBox(e,t),!bp(e.score)||!bp(e.classScore))throw Error(t+` - expected properties score (`+e.score+`) and (`+e.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})(Bp);function Hp(e){return e.detection instanceof Tp}function Up(e,t){return Object.assign({},e,{detection:t})}function Wp(){var e=window.fetch||function(){throw Error(`fetch - missing fetch implementation 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:function(){throw Error(`readFile - filesystem not available for browser environment`)}}}function Gp(e){var t=``;if(!e)try{e=o()}catch(e){t=e.toString()}return{readFile:e?function(t){return new Promise(function(n,r){e.readFile(t,function(e,t){return e?r(e):n(t)})})}:function(){throw Error(`readFile - failed to require fs in nodejs environment with error: `+t)}}}function Kp(){var e=global.Canvas||global.HTMLCanvasElement,t=global.Image||global.HTMLImageElement,n=function(){if(e)return new e;throw Error(`createCanvasElement - missing Canvas implementation for nodejs environment`)},r=function(){if(t)return new t;throw Error(`createImageElement - missing Image implementation for nodejs environment`)},i=global.fetch||function(){throw Error(`fetch - missing fetch implementation for nodejs environment`)},a=Gp();return ap({Canvas:e||function(){function e(){}return e}(),CanvasRenderingContext2D:global.CanvasRenderingContext2D||function(){function e(){}return e}(),Image:t||function(){function e(){}return e}(),ImageData:global.ImageData||function(){function e(){}return e}(),Video:global.HTMLVideoElement||function(){function e(){}return e}(),createCanvasElement:n,createImageElement:r,fetch:i},a)}function qp(){return typeof window==`object`&&typeof document<`u`&&typeof HTMLImageElement<`u`&&typeof HTMLCanvasElement<`u`&&typeof HTMLVideoElement<`u`&&typeof ImageData<`u`&&typeof CanvasRenderingContext2D<`u`}function Jp(){return typeof global==`object`&&typeof require==`function`&&typeof module<`u`&&typeof process<`u`&&!!process.version}var Yp;function Xp(){if(!Yp)throw Error(`getEnv - environment is not defined, check isNodejs() and isBrowser()`);return Yp}function Zp(e){Yp=e}function Qp(){qp()&&Zp(Wp()),Jp()&&Zp(Kp())}function $p(e){if(Yp||Qp(),!Yp)throw Error(`monkeyPatch - environment is not defined, check isNodejs() and isBrowser()`);var t=e.Canvas,n=t===void 0?Yp.Canvas:t,r=e.Image,i=r===void 0?Yp.Image:r;Yp.Canvas=n,Yp.Image=i,Yp.createCanvasElement=e.createCanvasElement||(function(){return new n}),Yp.createImageElement=e.createImageElement||(function(){return new i}),Yp.ImageData=e.ImageData||Yp.ImageData,Yp.Video=e.Video||Yp.Video,Yp.fetch=e.fetch||Yp.fetch,Yp.readFile=e.readFile||Yp.readFile}var em={getEnv:Xp,setEnv:Zp,initialize:Qp,createBrowserEnv:Wp,createFileSystem:Gp,createNodejsEnv:Kp,monkeyPatch:$p,isBrowser:qp,isNodejs:Jp};Qp();function tm(e){return!em.isNodejs()&&typeof e==`string`?document.getElementById(e):e}function nm(e){var t=em.getEnv(),n=t.Canvas;if(e instanceof t.CanvasRenderingContext2D)return e;var r=tm(e);if(!(r instanceof n))throw Error(`resolveContext2d - expected canvas to be of instance of Canvas`);var i=r.getContext(`2d`);if(!i)throw Error(`resolveContext2d - canvas 2d context is null`);return i}var rm;(function(e){e.TOP_LEFT=`TOP_LEFT`,e.TOP_RIGHT=`TOP_RIGHT`,e.BOTTOM_LEFT=`BOTTOM_LEFT`,e.BOTTOM_RIGHT=`BOTTOM_RIGHT`})(rm||={});var im=function(){function e(e){e===void 0&&(e={});var t=e.anchorPosition,n=e.backgroundColor,r=e.fontColor,i=e.fontSize,a=e.fontStyle,o=e.padding;this.anchorPosition=t||rm.TOP_LEFT,this.backgroundColor=n||`rgba(0, 0, 0, 0.5)`,this.fontColor=r||`rgba(255, 255, 255, 1)`,this.fontSize=i||14,this.fontStyle=a||`Georgia`,this.padding=o||4}return e}(),am=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 im(r)}return e.prototype.measureWidth=function(e){var t=this.options.padding;return this.text.map(function(t){return e.measureText(t).width}).reduce(function(e,t){return e<t?t:e},0)+2*t},e.prototype.measureHeight=function(){var e=this.options,t=e.fontSize,n=e.padding;return this.text.length*t+2*n},e.prototype.getUpperLeft=function(e,t){var n=this.options.anchorPosition,r=n===rm.BOTTOM_RIGHT||n===rm.TOP_RIGHT,i=n===rm.BOTTOM_LEFT||n===rm.BOTTOM_RIGHT,a=this.measureWidth(e),o=this.measureHeight(),s=r?this.anchor.x-a:this.anchor.x,c=i?this.anchor.y-o:this.anchor.y;if(t){var l=t.width,u=t.height;return{x:Math.max(Math.min(s,l-a),0),y:Math.max(Math.min(c,u-o),0)}}return{x:s,y:c}},e.prototype.draw=function(e){var t=tm(e),n=nm(t),r=this.options,i=r.backgroundColor,a=r.fontColor,o=r.fontSize,s=r.fontStyle,c=r.padding;n.font=o+`px `+s;var l=this.measureWidth(n),u=this.measureHeight();n.fillStyle=i;var d=this.getUpperLeft(n,t);n.fillRect(d.x,d.y,l,u),n.fillStyle=a,this.text.forEach(function(e,t){var r=c+d.x,i=c+d.y+(t+1)*o;n.fillText(e,r,i)})},e}(),om=function(){function e(e){e===void 0&&(e={});var t=e.boxColor,n=e.lineWidth,r=e.label,i=e.drawLabelOptions;this.boxColor=t||`rgba(0, 0, 255, 1)`,this.lineWidth=n||2,this.label=r;var a={anchorPosition:rm.BOTTOM_LEFT,backgroundColor:this.boxColor};this.drawLabelOptions=new im(Object.assign({},a,i))}return e}();(function(){function e(e,t){t===void 0&&(t={}),this.box=new Sp(e),this.options=new om(t)}return e.prototype.draw=function(e){var t=nm(e),n=this.options,r=n.boxColor,i=n.lineWidth,a=this.box,o=a.x,s=a.y,c=a.width,l=a.height;t.strokeStyle=r,t.lineWidth=i,t.strokeRect(o,s,c,l);var u=this.options.label;u&&new am([u],{x:o-i/2,y:s},this.options.drawLabelOptions).draw(e)},e})();function sm(e){var t=em.getEnv(),n=t.Image,r=t.Video;return e instanceof n&&e.complete||e instanceof r&&e.readyState>=3}function cm(e){return new Promise(function(t,n){if(e instanceof em.getEnv().Canvas||sm(e))return t();function r(e){e.currentTarget&&(e.currentTarget.removeEventListener(`load`,r),e.currentTarget.removeEventListener(`error`,i),t(e))}function i(e){e.currentTarget&&(e.currentTarget.removeEventListener(`load`,r),e.currentTarget.removeEventListener(`error`,i),n(e))}e.addEventListener(`load`,r),e.addEventListener(`error`,i)})}function lm(e){var t=em.getEnv(),n=t.Image,r=t.Video;return e instanceof n?new sp(e.naturalWidth,e.naturalHeight):e instanceof r?new sp(e.videoWidth,e.videoHeight):new sp(e.width,e.height)}function um(e){var t=e.width,n=e.height,r=em.getEnv().createCanvasElement,i=r();return i.width=t,i.height=n,i}function dm(e,t){var n=em.getEnv().ImageData;if(!(e instanceof n)&&!sm(e))throw Error(`createCanvasFromMedia - media has not finished loading yet`);var r=t||lm(e),i=r.width,a=r.height,o=um({width:i,height:a});return e instanceof n?nm(o).putImageData(e,0,0):nm(o).drawImage(e,0,0,i,a),o}function fm(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a,o,s;return $(this,function(c){switch(c.label){case 0:return n=t||em.getEnv().createCanvasElement(),r=e.shape.slice(dp(e)?1:0),i=r[0],a=r[1],o=r[2],s=H(function(){return e.as3D(i,a,o).toInt()}),[4,zf.toPixels(s,n)];case 1:return c.sent(),s.dispose(),[2,n]}})})}function pm(e){var t=em.getEnv(),n=t.Image,r=t.Canvas,i=t.Video;return e instanceof n||e instanceof r||e instanceof i}function mm(e,t,n){n===void 0&&(n=!1);var r=em.getEnv(),i=r.Image,a=r.Canvas;if(!(e instanceof i||e instanceof a))throw Error(`imageToSquare - expected arg0 to be HTMLImageElement | HTMLCanvasElement`);var o=lm(e),s=t/Math.max(o.height,o.width),c=s*o.width,l=s*o.height,u=um({width:t,height:t}),d=e instanceof a?e:dm(e),f=Math.abs(c-l)/2,p=n&&c<l?f:0,m=n&&l<c?f:0;return nm(u).drawImage(d,p,m,c,l),u}var hm=function(){function e(e,t){var n=this;if(t===void 0&&(t=!1),this._imageTensors=[],this._canvases=[],this._treatAsBatchInput=!1,this._inputDimensions=[],!Array.isArray(e))throw Error(`NetInput.constructor - expected inputs to be an Array of TResolvedNetInput or to be instanceof tf.Tensor4D, instead have `+e);this._treatAsBatchInput=t,this._batchSize=e.length,e.forEach(function(e,t){if(up(e)){n._imageTensors[t]=e,n._inputDimensions[t]=e.shape;return}if(dp(e)){var r=e.shape[0];if(r!==1)throw Error(`NetInput - tf.Tensor4D with batchSize `+r+` passed, but not supported in input array`);n._imageTensors[t]=e,n._inputDimensions[t]=e.shape.slice(1);return}var i=e instanceof em.getEnv().Canvas?e:dm(e);n._canvases[t]=i,n._inputDimensions[t]=[i.height,i.width,3]})}return Object.defineProperty(e.prototype,`imageTensors`,{get:function(){return this._imageTensors},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`canvases`,{get:function(){return this._canvases},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`isBatchInput`,{get:function(){return this.batchSize>1||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 e=this;return vp(this.batchSize,0,1).map(function(t,n){return e.getReshapedInputDimensions(n)})},enumerable:!0,configurable:!0}),e.prototype.getInput=function(e){return this.canvases[e]||this.imageTensors[e]},e.prototype.getInputDimensions=function(e){return this._inputDimensions[e]},e.prototype.getInputHeight=function(e){return this._inputDimensions[e][0]},e.prototype.getInputWidth=function(e){return this._inputDimensions[e][1]},e.prototype.getReshapedInputDimensions=function(e){if(typeof this.inputSize!=`number`)throw Error(`getReshapedInputDimensions - inputSize not set, toBatchTensor has not been called yet`);return gp({width:this.getInputWidth(e),height:this.getInputHeight(e)},this.inputSize)},e.prototype.toBatchTensor=function(e,t){var n=this;return t===void 0&&(t=!0),this._inputSize=e,H(function(){return Ar(vp(n.batchSize,0,1).map(function(r){var i=n.getInput(r);if(i instanceof Be){var a=dp(i)?i:i.expandDims();return a=Ap(a,t),(a.shape[1]!==e||a.shape[2]!==e)&&(a=hd.resizeBilinear(a,[e,e])),a.as3D(e,e,3)}if(i instanceof em.getEnv().Canvas)return zf.fromPixels(mm(i,e,t));throw Error(`toBatchTensor - at batchIdx `+r+`, expected input to be instanceof tf.Tensor or instanceof HTMLCanvasElement, instead have `+i)}).map(function(e){return e.toFloat()})).as4D(n.batchSize,e,e,3)})},e}();function gm(e){return Q(this,void 0,void 0,function(){var t,n,r;return $(this,function(i){switch(i.label){case 0:if(e instanceof hm)return[2,e];if(t=Array.isArray(e)?e:[e],!t.length)throw Error(`toNetInput - empty array passed as input`);return n=function(t){return Array.isArray(e)?` at input index `+t+`:`:``},r=t.map(tm),r.forEach(function(e,r){if(!pm(e)&&!up(e)&&!dp(e))throw typeof t[r]==`string`?Error(`toNetInput -`+n(r)+` string passed, but could not resolve HTMLElement for element id `+t[r]):Error(`toNetInput -`+n(r)+` expected media to be of type HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | tf.Tensor3D, or to be an element id`);if(dp(e)){var i=e.shape[0];if(i!==1)throw Error(`toNetInput -`+n(r)+` tf.Tensor4D with batchSize `+i+` passed, but not supported in input array`)}}),[4,Promise.all(r.map(function(e){return pm(e)&&cm(e)}))];case 1:return i.sent(),[2,new hm(r,Array.isArray(e))]}})})}function _m(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c;return $(this,function(l){switch(l.label){case 0:return n=em.getEnv().Canvas,r=e,e instanceof n?[3,5]:[4,gm(e)];case 1:if(i=l.sent(),i.batchSize>1)throw Error(`extractFaces - batchSize > 1 not supported`);return a=i.getInput(0),a instanceof n?(o=a,[3,4]):[3,2];case 2:return[4,fm(a)];case 3:o=l.sent(),l.label=4;case 4:r=o,l.label=5;case 5:return s=nm(r),c=t.map(function(e){return e instanceof Tp?e.forSize(r.width,r.height).box.floor():e}).map(function(e){return e.clipAtImageBorders(r.width,r.height)}),[2,c.map(function(e){var t=e.x,n=e.y,r=e.width,i=e.height,a=um({width:r,height:i});return nm(a).putImageData(s.getImageData(t,n,r,i),0,0),a})]}})})}function vm(e,t){return Q(this,void 0,void 0,function(){return $(this,function(n){if(!up(e)&&!dp(e))throw Error(`extractFaceTensors - expected image tensor to be 3D or 4D`);if(dp(e)&&e.shape[0]>1)throw Error(`extractFaceTensors - batchSize > 1 not supported`);return[2,H(function(){var n=e.shape.slice(dp(e)?1:0),r=n[0],i=n[1],a=n[2];return t.map(function(e){return e instanceof Tp?e.forSize(i,r).box:e}).map(function(e){return e.clipAtImageBorders(i,r)}).map(function(t){var n=t.x,o=t.y,s=t.width,c=t.height;return eu(e.as3D(r,i,a),[o,n,0],[c,s,a])})})]})})}function ym(e,t){return Q(this,void 0,void 0,function(){var n,r;return $(this,function(i){switch(i.label){case 0:return n=em.getEnv().fetch,[4,n(e,t)];case 1:if(r=i.sent(),!(r.status<400))throw Error(`failed to fetch: (`+r.status+`) `+r.statusText+`, from url: `+r.url);return[2,r]}})})}function bm(e){return Q(this,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,ym(e)];case 1:return[2,t.sent().json()]}})})}function xm(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 i=e.split(`/`).filter(function(e){return e}),a=e.endsWith(`.json`)?i[i.length-1]:n,o=r+(e.endsWith(`.json`)?i.slice(0,i.length-1):i).join(`/`);return o=e.startsWith(`/`)?`/`+o:o,{modelBaseUri:o,manifestUri:o===`/`?`/`+a:o+`/`+a}}function Sm(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a;return $(this,function(o){switch(o.label){case 0:return n=xm(e,t),r=n.manifestUri,i=n.modelBaseUri,[4,bm(r)];case 1:return a=o.sent(),[2,Ff.loadWeights(a,i)]}})})}var Cm=function(){function e(e){this._name=e,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(e){var t=this.traversePropertyPath(e);return t.obj[t.objProp]},e.prototype.reassignParamFromPath=function(e,t){var n=this.traversePropertyPath(e),r=n.obj,i=n.objProp;r[i].dispose(),r[i]=t},e.prototype.getParamList=function(){var e=this;return this._paramMappings.map(function(t){var n=t.paramPath;return{path:n,tensor:e.getParamFromPath(n)}})},e.prototype.getTrainableParams=function(){return this.getParamList().filter(function(e){return e.tensor instanceof Ke})},e.prototype.getFrozenParams=function(){return this.getParamList().filter(function(e){return!(e.tensor instanceof Ke)})},e.prototype.variable=function(){var e=this;this.getFrozenParams().forEach(function(t){var n=t.path,r=t.tensor;e.reassignParamFromPath(n,r.variable())})},e.prototype.freeze=function(){var e=this;this.getTrainableParams().forEach(function(t){var n=t.path,r=t.tensor,i=Dn(r.dataSync());r.dispose(),e.reassignParamFromPath(n,i)})},e.prototype.dispose=function(e){e===void 0&&(e=!0),this.getParamList().forEach(function(t){if(e&&t.tensor.isDisposed)throw Error(`param tensor has already been disposed for path `+t.path);t.tensor.dispose()}),this._params=void 0},e.prototype.serializeParams=function(){return new Float32Array(this.getParamList().map(function(e){var t=e.tensor;return Array.from(t.dataSync())}).reduce(function(e,t){return e.concat(t)}))},e.prototype.load=function(e){return Q(this,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return e instanceof Float32Array?(this.extractWeights(e),[2]):[4,this.loadFromUri(e)];case 1:return t.sent(),[2]}})})},e.prototype.loadFromUri=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:if(e&&typeof e!=`string`)throw Error(this._name+`.loadFromUri - expected model uri`);return[4,Sm(e,this.getDefaultModelName())];case 1:return t=n.sent(),this.loadFromWeightMap(t),[2]}})})},e.prototype.loadFromDisk=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i,a,o,s,c,l,u;return $(this,function(d){switch(d.label){case 0:if(e&&typeof e!=`string`)throw Error(this._name+`.loadFromDisk - expected model file path`);return t=em.getEnv().readFile,n=xm(e,this.getDefaultModelName()),r=n.manifestUri,i=n.modelBaseUri,a=function(e){return Promise.all(e.map(function(e){return t(e).then(function(e){return e.buffer})}))},o=Ff.weightsLoaderFactory(a),l=(c=JSON).parse,[4,t(r)];case 1:return s=l.apply(c,[d.sent().toString()]),[4,o(s,i)];case 2:return u=d.sent(),this.loadFromWeightMap(u),[2]}})})},e.prototype.loadFromWeightMap=function(e){var t=this.extractParamsFromWeigthMap(e),n=t.paramMappings,r=t.params;this._paramMappings=n,this._params=r},e.prototype.extractWeights=function(e){var t=this.extractParams(e),n=t.paramMappings,r=t.params;this._paramMappings=n,this._params=r},e.prototype.traversePropertyPath=function(e){if(!this.params)throw Error(`traversePropertyPath - model has no loaded params`);var t=e.split(`/`).reduce(function(t,n){if(!t.nextObj.hasOwnProperty(n))throw Error(`traversePropertyPath - object does not have property `+n+`, for path `+e);return{obj:t.nextObj,objProp:n,nextObj:t.nextObj[n]}},{nextObj:this.params}),n=t.obj,r=t.objProp;if(!n||!r||!(n[r]instanceof Be))throw Error(`traversePropertyPath - parameter is not a tensor, for path `+e);return{obj:n,objProp:r}},e}();function wm(e,t,n){return H(function(){var r=Nl(e,t.depthwise_filter,t.pointwise_filter,n,`same`);return r=Rc(r,t.bias),r})}function Tm(e,t,n){return n===void 0&&(n=!1),H(function(){var r=_u(n?Rc(El(e,t.conv0.filters,[2,2],`same`),t.conv0.bias):wm(e,t.conv0,[2,2])),i=wm(r,t.conv1,[1,1]);return _u(Rc(r,Rc(i,wm(_u(Rc(r,i)),t.conv2,[1,1]))))})}function Em(e,t,n,r){return n===void 0&&(n=!1),r===void 0&&(r=!0),H(function(){var i=_u(n?Rc(El(e,t.conv0.filters,r?[2,2]:[1,1],`same`),t.conv0.bias):wm(e,t.conv0,r?[2,2]:[1,1])),a=wm(i,t.conv1,[1,1]),o=wm(_u(Rc(i,a)),t.conv2,[1,1]);return _u(Rc(i,Rc(a,Rc(o,wm(_u(Rc(i,Rc(a,o))),t.conv3,[1,1])))))})}function Dm(e,t,n,r){return n===void 0&&(n=`same`),r===void 0&&(r=!1),H(function(){var i=Rc(El(e,t.filters,[1,1],n),t.bias);return r?_u(i):i})}function Om(e,t){Object.keys(e).forEach(function(n){t.some(function(e){return e.originalPath===n})||e[n].dispose()})}function km(e,t){return function(n,r,i,a){var o=Mn(e(n*r*i*i),[i,i,n,r]),s=kn(e(r));return t.push({paramPath:a+`/filters`},{paramPath:a+`/bias`}),{filters:o,bias:s}}}function Am(e,t){return function(n,r,i){var a=An(e(n*r),[n,r]),o=kn(e(r));return t.push({paramPath:i+`/weights`},{paramPath:i+`/bias`}),{weights:a,bias:o}}}var jm=function(){function e(e,t,n){this.depthwise_filter=e,this.pointwise_filter=t,this.bias=n}return e}();function Mm(e,t){return function(n,r,i){var a=Mn(e(9*n),[3,3,n,1]),o=Mn(e(n*r),[1,1,n,r]),s=kn(e(r));return t.push({paramPath:i+`/depthwise_filter`},{paramPath:i+`/pointwise_filter`},{paramPath:i+`/bias`}),new jm(a,o,s)}}function Nm(e){return function(t){return new jm(e(t+`/depthwise_filter`,4),e(t+`/pointwise_filter`,4),e(t+`/bias`,1))}}function Pm(e,t){return function(n,r,i){var a=e[n];if(!cp(a,r))throw Error(`expected weightMap[`+n+`] to be a Tensor`+r+`D, instead have `+a);return t.push({originalPath:n,paramPath:i||n}),a}}function Fm(e){var t=e;function n(e){var n=t.slice(0,e);return t=t.slice(e),n}function r(){return t}return{extractWeights:n,getRemainingWeights:r}}function Im(e,t){var n=km(e,t),r=Mm(e,t);function i(e,t,i,a){return a===void 0&&(a=!1),{conv0:a?n(e,t,3,i+`/conv0`):r(e,t,i+`/conv0`),conv1:r(t,t,i+`/conv1`),conv2:r(t,t,i+`/conv2`)}}function a(e,t,n,a){a===void 0&&(a=!1);var o=i(e,t,n,a);return{conv0:o.conv0,conv1:o.conv1,conv2:o.conv2,conv3:r(t,t,n+`/conv3`)}}return{extractDenseBlock3Params:i,extractDenseBlock4Params:a}}function Lm(e){var t=[],n=Fm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Im(r,t).extractDenseBlock4Params,o=a(3,32,`dense0`,!0),s=a(32,64,`dense1`),c=a(64,128,`dense2`),l=a(128,256,`dense3`);if(i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{paramMappings:t,params:{dense0:o,dense1:s,dense2:c,dense3:l}}}function Rm(e){return function(t){return{filters:e(t+`/filters`,4),bias:e(t+`/bias`,1)}}}function zm(e,t){var n=Pm(e,t),r=Rm(n),i=Nm(n);function a(e,t){return t===void 0&&(t=!1),{conv0:t?r(e+`/conv0`):i(e+`/conv0`),conv1:i(e+`/conv1`),conv2:i(e+`/conv2`)}}function o(e,t){return t===void 0&&(t=!1),{conv0:t?r(e+`/conv0`):i(e+`/conv0`),conv1:i(e+`/conv1`),conv2:i(e+`/conv2`),conv3:i(e+`/conv3`)}}return{extractDenseBlock3Params:a,extractDenseBlock4Params:o}}function Bm(e){var t=[],n=zm(e,t).extractDenseBlock4Params,r={dense0:n(`dense0`,!0),dense1:n(`dense1`),dense2:n(`dense2`),dense3:n(`dense3`)};return Om(e,t),{params:r,paramMappings:t}}var Vm=function(e){Z(t,e);function t(){return e.call(this,`FaceFeatureExtractor`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`FaceFeatureExtractor - load model before inference`);return H(function(){var n=Em(kp(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(G(255)),t.dense0,!0);return n=Em(n,t.dense1),n=Em(n,t.dense2),n=Em(n,t.dense3),n=ql(n,[7,7],[2,2],`valid`),n})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.getDefaultModelName=function(){return`face_feature_extractor_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Bm(e)},t.prototype.extractParams=function(e){return Lm(e)},t}(Cm);function Hm(e,t){return H(function(){return Rc(Il(e,t.weights),t.bias)})}function Um(e,t,n){var r=[],i=Fm(e),a=i.extractWeights,o=i.getRemainingWeights,s=Am(a,r)(t,n,`fc`);if(o().length!==0)throw Error(`weights remaing after extract: `+o().length);return{paramMappings:r,params:{fc:s}}}function Wm(e){var t=[],n=Pm(e,t);function r(e){return{weights:n(e+`/weights`,2),bias:n(e+`/bias`,1)}}var i={fc:r(`fc`)};return Om(e,t),{params:i,paramMappings:t}}function Gm(e){var t={},n={};return Object.keys(e).forEach(function(r){var i=r.startsWith(`fc`)?n:t;i[r]=e[r]}),{featureExtractorMap:t,classifierMap:n}}var Km=function(e){Z(t,e);function t(t,n){var r=e.call(this,t)||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(e){var t=this,n=this.params;if(!n)throw Error(this._name+` - load model before inference`);return H(function(){var r=e instanceof hm?t.faceFeatureExtractor.forwardInput(e):e;return Hm(r.as2D(r.shape[0],-1),n.fc)})},t.prototype.dispose=function(t){t===void 0&&(t=!0),this.faceFeatureExtractor.dispose(t),e.prototype.dispose.call(this,t)},t.prototype.loadClassifierParams=function(e){var t=this.extractClassifierParams(e),n=t.params,r=t.paramMappings;this._params=n,this._paramMappings=r},t.prototype.extractClassifierParams=function(e){return Um(e,this.getClassifierChannelsIn(),this.getClassifierChannelsOut())},t.prototype.extractParamsFromWeigthMap=function(e){var t=Gm(e),n=t.featureExtractorMap,r=t.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(n),Wm(r)},t.prototype.extractParams=function(e){var t=this.getClassifierChannelsIn(),n=this.getClassifierChannelsOut(),r=n*t+n,i=e.slice(0,e.length-r),a=e.slice(e.length-r);return this.faceFeatureExtractor.extractWeights(i),this.extractClassifierParams(a)},t}(Cm),qm=[`neutral`,`happy`,`sad`,`angry`,`fearful`,`disgusted`,`surprised`],Jm=function(){function e(e){var t=this;if(e.length!==7)throw Error(`FaceExpressions.constructor - expected probabilities.length to be 7, have: `+e.length);qm.forEach(function(n,r){t[n]=e[r]})}return e.prototype.asSortedArray=function(){var e=this;return qm.map(function(t){return{expression:t,probability:e[t]}}).sort(function(e,t){return t.probability-e.probability})},e}(),Ym=function(e){Z(t,e);function t(t){return t===void 0&&(t=new Vm),e.call(this,`FaceExpressionNet`,t)||this}return t.prototype.forwardInput=function(e){var t=this;return H(function(){return ti(t.runNet(e))})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.predictExpressions=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i,a=this;return $(this,function(o){switch(o.label){case 0:return[4,gm(e)];case 1:return t=o.sent(),[4,this.forwardInput(t)];case 2:return n=o.sent(),[4,Promise.all(Nr(n).map(function(e){return Q(a,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return[4,e.data()];case 1:return t=n.sent(),e.dispose(),[2,t]}})})}))];case 3:return r=o.sent(),n.dispose(),i=r.map(function(e){return new Jm(e)}),[2,t.isBatchInput?i:i[0]]}})})},t.prototype.getDefaultModelName=function(){return`face_expression_model`},t.prototype.getClassifierChannelsIn=function(){return 256},t.prototype.getClassifierChannelsOut=function(){return 7},t}(Km);function Xm(e,t){return Object.assign({},e,{expressions:t})}function Zm(e){return Hp(e)&&e.landmarks instanceof Ip&&e.unshiftedLandmarks instanceof Ip&&e.alignedRect instanceof Tp}function Qm(e,t){var n=e.detection.box,r=t.shiftBy(n.x,n.y),i=r.align(),a=e.detection.imageDims,o={landmarks:r,unshiftedLandmarks:t,alignedRect:new Tp(e.detection.score,i.rescale(a.reverse()),a)};return Object.assign({},e,o)}var $m=function(){function e(e){e===void 0&&(e={});var t=e.drawLines,n=t===void 0?!0:t,r=e.drawPoints,i=r===void 0?!0:r,a=e.lineWidth,o=e.lineColor,s=e.pointSize,c=e.pointColor;this.drawLines=n,this.drawPoints=i,this.lineWidth=a||1,this.pointSize=s||2,this.lineColor=o||`rgba(0, 255, 255, 1)`,this.pointColor=c||`rgba(255, 0, 255, 1)`}return e}();(function(){function e(e,t){t===void 0&&(t={}),this.faceLandmarks=e,this.options=new $m(t)}return e.prototype.draw=function(e){var t=nm(e),n=this.options,r=n.drawLines,i=n.drawPoints,a=n.lineWidth,o=n.lineColor,s=n.pointSize,c=n.pointColor;r&&this.faceLandmarks instanceof Rp&&(t.strokeStyle=o,t.lineWidth=a,rp(t,this.faceLandmarks.getJawOutline()),rp(t,this.faceLandmarks.getLeftEyeBrow()),rp(t,this.faceLandmarks.getRightEyeBrow()),rp(t,this.faceLandmarks.getNose()),rp(t,this.faceLandmarks.getLeftEye(),!0),rp(t,this.faceLandmarks.getRightEye(),!0),rp(t,this.faceLandmarks.getMouth(),!0)),i&&(t.strokeStyle=c,t.fillStyle=c,this.faceLandmarks.positions.forEach(function(e){t.beginPath(),t.arc(e.x,e.y,s,0,2*Math.PI),t.fill()}))},e})();function eh(e,t){var n=km(e,t),r=Mm(e,t);function i(e,t,i){return{separable_conv0:r(e,t,i+`/separable_conv0`),separable_conv1:r(t,t,i+`/separable_conv1`),expansion_conv:n(e,t,1,i+`/expansion_conv`)}}function a(e,t){return{separable_conv0:r(e,e,t+`/separable_conv0`),separable_conv1:r(e,e,t+`/separable_conv1`),separable_conv2:r(e,e,t+`/separable_conv2`)}}return{extractConvParams:n,extractSeparableConvParams:r,extractReductionBlockParams:i,extractMainBlockParams:a}}function th(e,t){var n=[],r=Fm(e),i=r.extractWeights,a=r.getRemainingWeights,o=eh(i,n),s=o.extractConvParams,c=o.extractSeparableConvParams,l=o.extractReductionBlockParams,u=o.extractMainBlockParams,d={conv_in:s(3,32,3,`entry_flow/conv_in`),reduction_block_0:l(32,64,`entry_flow/reduction_block_0`),reduction_block_1:l(64,128,`entry_flow/reduction_block_1`)},f={};vp(t,0,1).forEach(function(e){f[`main_block_`+e]=u(128,`middle_flow/main_block_`+e)});var p={reduction_block:l(128,256,`exit_flow/reduction_block`),separable_conv:c(256,512,`exit_flow/separable_conv`)};if(a().length!==0)throw Error(`weights remaing after extract: `+a().length);return{paramMappings:n,params:{entry_flow:d,middle_flow:f,exit_flow:p}}}function nh(e,t){var n=Pm(e,t),r=Rm(n),i=Nm(n);function a(e){return{separable_conv0:i(e+`/separable_conv0`),separable_conv1:i(e+`/separable_conv1`),expansion_conv:r(e+`/expansion_conv`)}}function o(e){return{separable_conv0:i(e+`/separable_conv0`),separable_conv1:i(e+`/separable_conv1`),separable_conv2:i(e+`/separable_conv2`)}}return{extractConvParams:r,extractSeparableConvParams:i,extractReductionBlockParams:a,extractMainBlockParams:o}}function rh(e,t){var n=[],r=nh(e,n),i=r.extractConvParams,a=r.extractSeparableConvParams,o=r.extractReductionBlockParams,s=r.extractMainBlockParams,c={conv_in:i(`entry_flow/conv_in`),reduction_block_0:o(`entry_flow/reduction_block_0`),reduction_block_1:o(`entry_flow/reduction_block_1`)},l={};vp(t,0,1).forEach(function(e){l[`main_block_`+e]=s(`middle_flow/main_block_`+e)});var u={reduction_block:o(`exit_flow/reduction_block`),separable_conv:a(`exit_flow/separable_conv`)};return Om(e,n),{params:{entry_flow:c,middle_flow:l,exit_flow:u},paramMappings:n}}function ih(e,t,n){return Rc(El(e,t.filters,n,`same`),t.bias)}function ah(e,t,n){n===void 0&&(n=!0);var r=n?_u(e):e;return r=wm(r,t.separable_conv0,[1,1]),r=wm(_u(r),t.separable_conv1,[1,1]),r=Kl(r,[3,3],[2,2],`same`),r=Rc(r,ih(e,t.expansion_conv,[2,2])),r}function oh(e,t){var n=wm(_u(e),t.separable_conv0,[1,1]);return n=wm(_u(n),t.separable_conv1,[1,1]),n=wm(_u(n),t.separable_conv2,[1,1]),n=Rc(n,e),n}var sh=function(e){Z(t,e);function t(t){var n=e.call(this,`TinyXception`)||this;return n._numMainBlocks=t,n}return t.prototype.forwardInput=function(e){var t=this,n=this.params;if(!n)throw Error(`TinyXception - load model before inference`);return H(function(){var r=_u(ih(kp(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(G(256)),n.entry_flow.conv_in,[2,2]));return r=ah(r,n.entry_flow.reduction_block_0,!1),r=ah(r,n.entry_flow.reduction_block_1),vp(t._numMainBlocks,0,1).forEach(function(e){r=oh(r,n.middle_flow[`main_block_`+e])}),r=ah(r,n.exit_flow.reduction_block),r=_u(wm(r,n.exit_flow.separable_conv,[1,1])),r})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.getDefaultModelName=function(){return`tiny_xception_model`},t.prototype.extractParamsFromWeigthMap=function(e){return rh(e,this._numMainBlocks)},t.prototype.extractParams=function(e){return th(e,this._numMainBlocks)},t}(Cm);function ch(e){var t=[],n=Fm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Am(r,t),o=a(512,1,`fc/age`),s=a(512,2,`fc/gender`);if(i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{paramMappings:t,params:{fc:{age:o,gender:s}}}}function lh(e){var t=[],n=Pm(e,t);function r(e){return{weights:n(e+`/weights`,2),bias:n(e+`/bias`,1)}}var i={fc:{age:r(`fc/age`),gender:r(`fc/gender`)}};return Om(e,t),{params:i,paramMappings:t}}var uh;(function(e){e.FEMALE=`female`,e.MALE=`male`})(uh||={});var dh=function(e){Z(t,e);function t(t){t===void 0&&(t=new sh(2));var n=e.call(this,`AgeGenderNet`)||this;return n._faceFeatureExtractor=t,n}return Object.defineProperty(t.prototype,`faceFeatureExtractor`,{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),t.prototype.runNet=function(e){var t=this,n=this.params;if(!n)throw Error(this._name+` - load model before inference`);return H(function(){var r=e instanceof hm?t.faceFeatureExtractor.forwardInput(e):e,i=ql(r,[7,7],[2,2],`valid`).as2D(r.shape[0],-1);return{age:Hm(i,n.fc.age).as1D(),gender:Hm(i,n.fc.gender)}})},t.prototype.forwardInput=function(e){var t=this;return H(function(){var n=t.runNet(e),r=n.age,i=n.gender;return{age:r,gender:ti(i)}})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.predictAgeAndGender=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i,a,o,s=this;return $(this,function(c){switch(c.label){case 0:return[4,gm(e)];case 1:return t=c.sent(),[4,this.forwardInput(t)];case 2:return n=c.sent(),r=Nr(n.age),i=Nr(n.gender),a=r.map(function(e,t){return{ageTensor:e,genderTensor:i[t]}}),[4,Promise.all(a.map(function(e){var t=e.ageTensor,n=e.genderTensor;return Q(s,void 0,void 0,function(){var e,r,i,a,o;return $(this,function(s){switch(s.label){case 0:return[4,t.data()];case 1:return e=s.sent()[0],[4,n.data()];case 2:return r=s.sent()[0],i=r>.5,a=i?uh.MALE:uh.FEMALE,o=i?r:1-r,t.dispose(),n.dispose(),[2,{age:e,gender:a,genderProbability:o}]}})})}))];case 3:return o=c.sent(),n.age.dispose(),n.gender.dispose(),[2,t.isBatchInput?o:o[0]]}})})},t.prototype.getDefaultModelName=function(){return`age_gender_model`},t.prototype.dispose=function(t){t===void 0&&(t=!0),this.faceFeatureExtractor.dispose(t),e.prototype.dispose.call(this,t)},t.prototype.loadClassifierParams=function(e){var t=this.extractClassifierParams(e),n=t.params,r=t.paramMappings;this._params=n,this._paramMappings=r},t.prototype.extractClassifierParams=function(e){return ch(e)},t.prototype.extractParamsFromWeigthMap=function(e){var t=Gm(e),n=t.featureExtractorMap,r=t.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(n),lh(r)},t.prototype.extractParams=function(e){var t=1539,n=e.slice(0,e.length-t),r=e.slice(e.length-t);return this.faceFeatureExtractor.extractWeights(n),this.extractClassifierParams(r)},t}(Cm),fh=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.postProcess=function(e,t,n){var r=n.map(function(e){var n=e.width,r=e.height,i=t/Math.max(r,n);return{width:n*i,height:r*i}}),i=r.length;return H(function(){var n=function(e,t){return Ar([Rn([68],e),Rn([68],t)],1).as2D(1,136).as1D()},a=function(e,t){var n=r[e],i=n.width,a=n.height;return t(i,a)?Math.abs(i-a)/2:0},o=function(e){return a(e,function(e,t){return e<t})},s=function(e){return a(e,function(e,t){return t<e})};return e.mul(Rn([i,136],t)).sub(Ar(Array.from(Array(i),function(e,t){return n(o(t),s(t))}))).div(Ar(Array.from(Array(i),function(e,t){return n(r[t].width,r[t].height)})))})},t.prototype.forwardInput=function(e){var t=this;return H(function(){var n=t.runNet(e);return t.postProcess(n,e.inputSize,e.inputDimensions.map(function(e){return{height:e[0],width:e[1]}}))})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.detectLandmarks=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i=this;return $(this,function(a){switch(a.label){case 0:return[4,gm(e)];case 1:return t=a.sent(),n=H(function(){return Nr(i.forwardInput(t))}),[4,Promise.all(n.map(function(e,n){return Q(i,void 0,void 0,function(){var r,i,a,o,s;return $(this,function(c){switch(c.label){case 0:return a=(i=Array).from,[4,e.data()];case 1:return r=a.apply(i,[c.sent()]),o=r.filter(function(e,t){return pp(t)}),s=r.filter(function(e,t){return!pp(t)}),[2,new Rp(Array(68).fill(0).map(function(e,t){return new xp(o[t],s[t])}),{height:t.getInputHeight(n),width:t.getInputWidth(n)})]}})})}))];case 2:return r=a.sent(),n.forEach(function(e){return e.dispose()}),[2,t.isBatchInput?r:r[0]]}})})},t.prototype.getClassifierChannelsOut=function(){return 136},t}(Km),ph=function(e){Z(t,e);function t(t){return t===void 0&&(t=new Vm),e.call(this,`FaceLandmark68Net`,t)||this}return t.prototype.getDefaultModelName=function(){return`face_landmark_68_model`},t.prototype.getClassifierChannelsIn=function(){return 256},t}(fh);function mh(e){var t=[],n=zm(e,t).extractDenseBlock3Params,r={dense0:n(`dense0`,!0),dense1:n(`dense1`),dense2:n(`dense2`)};return Om(e,t),{params:r,paramMappings:t}}function hh(e){var t=[],n=Fm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Im(r,t).extractDenseBlock3Params,o=a(3,32,`dense0`,!0),s=a(32,64,`dense1`),c=a(64,128,`dense2`);if(i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{paramMappings:t,params:{dense0:o,dense1:s,dense2:c}}}var gh=function(e){Z(t,e);function t(){return e.call(this,`TinyFaceFeatureExtractor`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`TinyFaceFeatureExtractor - load model before inference`);return H(function(){var n=Tm(kp(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(G(255)),t.dense0,!0);return n=Tm(n,t.dense1),n=Tm(n,t.dense2),n=ql(n,[14,14],[2,2],`valid`),n})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.getDefaultModelName=function(){return`face_feature_extractor_tiny_model`},t.prototype.extractParamsFromWeigthMap=function(e){return mh(e)},t.prototype.extractParams=function(e){return hh(e)},t}(Cm),_h=function(e){Z(t,e);function t(t){return t===void 0&&(t=new gh),e.call(this,`FaceLandmark68TinyNet`,t)||this}return t.prototype.getDefaultModelName=function(){return`face_landmark_68_tiny_model`},t.prototype.getClassifierChannelsIn=function(){return 128},t}(fh);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t})(ph);function vh(e,t){return Rc(Qc(e,t.weights),t.biases)}function yh(e,t,n,r,i){i===void 0&&(i=`same`);var a=t.conv,o=a.filters,s=a.bias,c=El(e,o,n,i);return c=Rc(c,s),c=vh(c,t.scale),r?_u(c):c}function bh(e,t){return yh(e,t,[1,1],!0)}function xh(e,t){return yh(e,t,[1,1],!1)}function Sh(e,t){return yh(e,t,[2,2],!0,`valid`)}function Ch(e,t){function n(t,n,r){var i=e(t),a=i.length/(n*r*r);if(fp(a))throw Error(`depth has to be an integer: `+a+`, weights.length: `+i.length+`, numFilters: `+n+`, filterSize: `+r);return H(function(){return bu(Mn(i,[n,a,r,r]),[2,3,1,0])})}function r(r,i,a,o){var s=n(r,i,a),c=kn(e(i));return t.push({paramPath:o+`/filters`},{paramPath:o+`/bias`}),{filters:s,bias:c}}function i(n,r){var i=kn(e(n)),a=kn(e(n));return t.push({paramPath:r+`/weights`},{paramPath:r+`/biases`}),{weights:i,biases:a}}function a(e,t,n,a){return{conv:r(e,t,n,a+`/conv`),scale:i(t,a+`/scale`)}}function o(e,t,n,r,i){return i===void 0&&(i=!1),{conv1:a((i?.5:1)*e,t,n,r+`/conv1`),conv2:a(e,t,n,r+`/conv2`)}}return{extractConvLayerParams:a,extractResidualLayerParams:o}}function wh(e){var t=Fm(e),n=t.extractWeights,r=t.getRemainingWeights,i=[],a=Ch(n,i),o=a.extractConvLayerParams,s=a.extractResidualLayerParams,c=o(4704,32,7,`conv32_down`),l=s(9216,32,3,`conv32_1`),u=s(9216,32,3,`conv32_2`),d=s(9216,32,3,`conv32_3`),f=s(36864,64,3,`conv64_down`,!0),p=s(36864,64,3,`conv64_1`),m=s(36864,64,3,`conv64_2`),h=s(36864,64,3,`conv64_3`),g=s(147456,128,3,`conv128_down`,!0),_=s(147456,128,3,`conv128_1`),v=s(147456,128,3,`conv128_2`),y=s(589824,256,3,`conv256_down`,!0),b=s(589824,256,3,`conv256_1`),x=s(589824,256,3,`conv256_2`),S=s(589824,256,3,`conv256_down_out`),C=H(function(){return bu(An(n(256*128),[128,256]),[1,0])});if(i.push({paramPath:`fc`}),r().length!==0)throw Error(`weights remaing after extract: `+r().length);return{params:{conv32_down:c,conv32_1:l,conv32_2:u,conv32_3:d,conv64_down:f,conv64_1:p,conv64_2:m,conv64_3:h,conv128_down:g,conv128_1:_,conv128_2:v,conv256_down:y,conv256_1:b,conv256_2:x,conv256_down_out:S,fc:C},paramMappings:i}}function Th(e,t){var n=Pm(e,t);function r(e){return{weights:n(e+`/scale/weights`,1),biases:n(e+`/scale/biases`,1)}}function i(e){var t=n(e+`/conv/filters`,4),i=n(e+`/conv/bias`,1),a=r(e);return{conv:{filters:t,bias:i},scale:a}}function a(e){return{conv1:i(e+`/conv1`),conv2:i(e+`/conv2`)}}return{extractConvLayerParams:i,extractResidualLayerParams:a}}function Eh(e){var t=[],n=Th(e,t),r=n.extractConvLayerParams,i=n.extractResidualLayerParams,a=r(`conv32_down`),o=i(`conv32_1`),s=i(`conv32_2`),c=i(`conv32_3`),l=i(`conv64_down`),u=i(`conv64_1`),d=i(`conv64_2`),f=i(`conv64_3`),p=i(`conv128_down`),m=i(`conv128_1`),h=i(`conv128_2`),g=i(`conv256_down`),_=i(`conv256_1`),v=i(`conv256_2`),y=i(`conv256_down_out`),b=e.fc;if(t.push({originalPath:`fc`,paramPath:`fc`}),!lp(b))throw Error(`expected weightMap[fc] to be a Tensor2D, instead have `+b);var x={conv32_down:a,conv32_1:o,conv32_2:s,conv32_3:c,conv64_down:l,conv64_1:u,conv64_2:d,conv64_3:f,conv128_down:p,conv128_1:m,conv128_2:h,conv256_down:g,conv256_1:_,conv256_2:v,conv256_down_out:y,fc:b};return Om(e,t),{params:x,paramMappings:t}}function Dh(e,t){var n=bh(e,t.conv1);return n=xh(n,t.conv2),n=Rc(n,e),n=_u(n),n}function Oh(e,t){var n=Sh(e,t.conv1);n=xh(n,t.conv2);var r=ql(e,2,2,`valid`),i=Ln(r.shape),a=r.shape[3]!==n.shape[3];if(r.shape[1]!==n.shape[1]||r.shape[2]!==n.shape[2]){var o=op(n.shape);o[1]=1;var s=Ln(o);n=Un([n,s],1);var c=op(n.shape);c[2]=1;var l=Ln(c);n=Un([n,l],2)}return r=a?Un([r,i],3):r,n=Rc(r,n),n=_u(n),n}var kh=function(e){Z(t,e);function t(){return e.call(this,`FaceRecognitionNet`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`FaceRecognitionNet - load model before inference`);return H(function(){var n=Sh(kp(e.toBatchTensor(150,!0).toFloat(),[122.782,117.001,104.298]).div(G(256)),t.conv32_down);return n=Kl(n,3,2,`valid`),n=Dh(n,t.conv32_1),n=Dh(n,t.conv32_2),n=Dh(n,t.conv32_3),n=Oh(n,t.conv64_down),n=Dh(n,t.conv64_1),n=Dh(n,t.conv64_2),n=Dh(n,t.conv64_3),n=Oh(n,t.conv128_down),n=Dh(n,t.conv128_1),n=Dh(n,t.conv128_2),n=Oh(n,t.conv256_down),n=Dh(n,t.conv256_1),n=Dh(n,t.conv256_2),n=Oh(n,t.conv256_down_out),Il(n.mean([1,2]),t.fc)})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.computeFaceDescriptor=function(e){return Q(this,void 0,void 0,function(){var t,n,r,i=this;return $(this,function(a){switch(a.label){case 0:return[4,gm(e)];case 1:return t=a.sent(),n=H(function(){return Nr(i.forwardInput(t))}),[4,Promise.all(n.map(function(e){return e.data()}))];case 2:return r=a.sent(),n.forEach(function(e){return e.dispose()}),[2,t.isBatchInput?r:r[0]]}})})},t.prototype.getDefaultModelName=function(){return`face_recognition_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Eh(e)},t.prototype.extractParams=function(e){return wh(e)},t}(Cm);function Ah(e,t){return Object.assign({},e,{descriptor:t})}function jh(e,t){return Object.assign({},e,{age:t})}function Mh(e,t,n){return Object.assign({},e,{gender:t,genderProbability:n})}var Nh=function(){function e(e){var t=e===void 0?{}:e,n=t.minFaceSize,r=t.scaleFactor,i=t.maxNumScales,a=t.scoreThresholds,o=t.scaleSteps;if(this._name=`MtcnnOptions`,this._minFaceSize=n||20,this._scaleFactor=r||.709,this._maxNumScales=i||10,this._scoreThresholds=a||[.6,.7,.7],this._scaleSteps=o,typeof this._minFaceSize!=`number`||this._minFaceSize<0)throw Error(this._name+` - expected minFaceSize to be a number > 0`);if(typeof this._scaleFactor!=`number`||this._scaleFactor<=0||this._scaleFactor>=1)throw Error(this._name+` - expected scaleFactor to be a number between 0 and 1`);if(typeof this._maxNumScales!=`number`||this._maxNumScales<0)throw Error(this._name+` - expected maxNumScales to be a number > 0`);if(!Array.isArray(this._scoreThresholds)||this._scoreThresholds.length!==3||this._scoreThresholds.some(function(e){return typeof e!=`number`}))throw 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(e){return typeof e!=`number`})))throw 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 Ph(e,t){function n(n,r){var i=Mn(e(9*n),[3,3,n,1]),a=kn(e(n)),o=kn(e(n)),s=kn(e(n)),c=kn(e(n));return t.push({paramPath:r+`/filters`},{paramPath:r+`/batch_norm_scale`},{paramPath:r+`/batch_norm_offset`},{paramPath:r+`/batch_norm_mean`},{paramPath:r+`/batch_norm_variance`}),{filters:i,batch_norm_scale:a,batch_norm_offset:o,batch_norm_mean:s,batch_norm_variance:c}}function r(n,r,i,a,o){var s=Mn(e(n*r*i*i),[i,i,n,r]),c=kn(e(r));return t.push({paramPath:a+`/filters`},{paramPath:a+`/`+(o?`batch_norm_offset`:`bias`)}),{filters:s,bias:c}}function i(e,t,n,i){var a=r(e,t,n,i,!0);return{filters:a.filters,batch_norm_offset:a.bias}}function a(e,t,r){return{depthwise_conv:n(e,r+`/depthwise_conv`),pointwise_conv:i(e,t,1,r+`/pointwise_conv`)}}function o(){return{conv_0:i(3,32,3,`mobilenetv1/conv_0`),conv_1:a(32,64,`mobilenetv1/conv_1`),conv_2:a(64,128,`mobilenetv1/conv_2`),conv_3:a(128,128,`mobilenetv1/conv_3`),conv_4:a(128,256,`mobilenetv1/conv_4`),conv_5:a(256,256,`mobilenetv1/conv_5`),conv_6:a(256,512,`mobilenetv1/conv_6`),conv_7:a(512,512,`mobilenetv1/conv_7`),conv_8:a(512,512,`mobilenetv1/conv_8`),conv_9:a(512,512,`mobilenetv1/conv_9`),conv_10:a(512,512,`mobilenetv1/conv_10`),conv_11:a(512,512,`mobilenetv1/conv_11`),conv_12:a(512,1024,`mobilenetv1/conv_12`),conv_13:a(1024,1024,`mobilenetv1/conv_13`)}}function s(){var e=i(1024,256,1,`prediction_layer/conv_0`),t=i(256,512,3,`prediction_layer/conv_1`),n=i(512,128,1,`prediction_layer/conv_2`),a=i(128,256,3,`prediction_layer/conv_3`),o=i(256,128,1,`prediction_layer/conv_4`),s=i(128,256,3,`prediction_layer/conv_5`),c=i(256,64,1,`prediction_layer/conv_6`),l=i(64,128,3,`prediction_layer/conv_7`),u=r(512,12,1,`prediction_layer/box_predictor_0/box_encoding_predictor`),d=r(512,9,1,`prediction_layer/box_predictor_0/class_predictor`),f=r(1024,24,1,`prediction_layer/box_predictor_1/box_encoding_predictor`),p=r(1024,18,1,`prediction_layer/box_predictor_1/class_predictor`),m=r(512,24,1,`prediction_layer/box_predictor_2/box_encoding_predictor`),h=r(512,18,1,`prediction_layer/box_predictor_2/class_predictor`),g=r(256,24,1,`prediction_layer/box_predictor_3/box_encoding_predictor`),_=r(256,18,1,`prediction_layer/box_predictor_3/class_predictor`),v=r(256,24,1,`prediction_layer/box_predictor_4/box_encoding_predictor`),y=r(256,18,1,`prediction_layer/box_predictor_4/class_predictor`),b=r(128,24,1,`prediction_layer/box_predictor_5/box_encoding_predictor`),x=r(128,18,1,`prediction_layer/box_predictor_5/class_predictor`);return{conv_0:e,conv_1:t,conv_2:n,conv_3:a,conv_4:o,conv_5:s,conv_6:c,conv_7:l,box_predictor_0:{box_encoding_predictor:u,class_predictor:d},box_predictor_1:{box_encoding_predictor:f,class_predictor:p},box_predictor_2:{box_encoding_predictor:m,class_predictor:h},box_predictor_3:{box_encoding_predictor:g,class_predictor:_},box_predictor_4:{box_encoding_predictor:v,class_predictor:y},box_predictor_5:{box_encoding_predictor:b,class_predictor:x}}}return{extractMobilenetV1Params:o,extractPredictionLayerParams:s}}function Fh(e){var t=[],n=Fm(e),r=n.extractWeights,i=n.getRemainingWeights,a=Ph(r,t),o=a.extractMobilenetV1Params,s=a.extractPredictionLayerParams,c=o(),l=s(),u={extra_dim:jn(r(5118*4),[1,5118,4])};if(t.push({paramPath:`output_layer/extra_dim`}),i().length!==0)throw Error(`weights remaing after extract: `+i().length);return{params:{mobilenetv1:c,prediction_layer:l,output_layer:u},paramMappings:t}}function Ih(e,t){var n=Pm(e,t);function r(e,t,r){return{filters:n(e+`/Conv2d_`+t+`_pointwise/weights`,4,r+`/filters`),batch_norm_offset:n(e+`/Conv2d_`+t+`_pointwise/convolution_bn_offset`,1,r+`/batch_norm_offset`)}}function i(e){var t=`mobilenetv1/conv_`+e,i=`MobilenetV1/Conv2d_`+e+`_depthwise`,a=t+`/depthwise_conv`,o=t+`/pointwise_conv`;return{depthwise_conv:{filters:n(i+`/depthwise_weights`,4,a+`/filters`),batch_norm_scale:n(i+`/BatchNorm/gamma`,1,a+`/batch_norm_scale`),batch_norm_offset:n(i+`/BatchNorm/beta`,1,a+`/batch_norm_offset`),batch_norm_mean:n(i+`/BatchNorm/moving_mean`,1,a+`/batch_norm_mean`),batch_norm_variance:n(i+`/BatchNorm/moving_variance`,1,a+`/batch_norm_variance`)},pointwise_conv:r(`MobilenetV1`,e,o)}}function a(){return{conv_0:r(`MobilenetV1`,0,`mobilenetv1/conv_0`),conv_1:i(1),conv_2:i(2),conv_3:i(3),conv_4:i(4),conv_5:i(5),conv_6:i(6),conv_7:i(7),conv_8:i(8),conv_9:i(9),conv_10:i(10),conv_11:i(11),conv_12:i(12),conv_13:i(13)}}function o(e,t){return{filters:n(e+`/weights`,4,t+`/filters`),bias:n(e+`/biases`,1,t+`/bias`)}}function s(e){return{box_encoding_predictor:o(`Prediction/BoxPredictor_`+e+`/BoxEncodingPredictor`,`prediction_layer/box_predictor_`+e+`/box_encoding_predictor`),class_predictor:o(`Prediction/BoxPredictor_`+e+`/ClassPredictor`,`prediction_layer/box_predictor_`+e+`/class_predictor`)}}function c(){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:s(0),box_predictor_1:s(1),box_predictor_2:s(2),box_predictor_3:s(3),box_predictor_4:s(4),box_predictor_5:s(5)}}return{extractMobilenetV1Params:a,extractPredictionLayerParams:c}}function Lh(e){var t=[],n=Ih(e,t),r=n.extractMobilenetV1Params,i=n.extractPredictionLayerParams,a=e[`Output/extra_dim`];if(t.push({originalPath:`Output/extra_dim`,paramPath:`output_layer/extra_dim`}),!up(a))throw Error(`expected weightMap['Output/extra_dim'] to be a Tensor3D, instead have `+a);var o={mobilenetv1:r(),prediction_layer:i(),output_layer:{extra_dim:a}};return Om(e,t),{params:o,paramMappings:t}}function Rh(e,t,n){return H(function(){var r=El(e,t.filters,n,`same`);return r=Rc(r,t.batch_norm_offset),Ks(r,0,6)})}var zh=.0010000000474974513;function Bh(e,t,n){return H(function(){var r=Al(e,t.filters,n,`same`);return r=Oc(r,t.batch_norm_mean,t.batch_norm_variance,t.batch_norm_offset,t.batch_norm_scale,zh),Ks(r,0,6)})}function Vh(e){return[2,4,6,12].some(function(t){return t===e})?[2,2]:[1,1]}function Hh(e,t){return H(function(){var n=null,r=Rh(e,t.conv_0,[2,2]);if([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].forEach(function(e,t){var i=t+1,a=Vh(i);r=Bh(r,e.depthwise_conv,a),r=Rh(r,e.pointwise_conv,[1,1]),i===11&&(n=r)}),n===null)throw Error(`mobileNetV1 - output of conv layer 11 is null`);return{out:r,conv11:n}})}function Uh(e,t,n,r,i){var a=e.shape[0],o=Math.min(n,a),s=t.map(function(e,t){return{score:e,boxIndex:t}}).filter(function(e){return e.score>i}).sort(function(e,t){return t.score-e.score}),c=function(e){return e<=r?1:0},l=[];return s.forEach(function(t){if(!(l.length>=o)){for(var n=t.score,r=l.length-1;r>=0;--r){var a=Wh(e,t.boxIndex,l[r]);if(a!==0&&(t.score*=c(a),t.score<=i))break}n===t.score&&l.push(t.boxIndex)}}),l}function Wh(e,t,n){var r=e.arraySync(),i=Math.min(r[t][0],r[t][2]),a=Math.min(r[t][1],r[t][3]),o=Math.max(r[t][0],r[t][2]),s=Math.max(r[t][1],r[t][3]),c=Math.min(r[n][0],r[n][2]),l=Math.min(r[n][1],r[n][3]),u=Math.max(r[n][0],r[n][2]),d=Math.max(r[n][1],r[n][3]),f=(o-i)*(s-a),p=(u-c)*(d-l);if(f<=0||p<=0)return 0;var m=Math.max(i,c),h=Math.max(a,l),g=Math.min(o,u),_=Math.min(s,d),v=Math.max(g-m,0)*Math.max(_-h,0);return v/(f+p-v)}function Gh(e){var t=Nr(bu(e,[1,0])),n=[rl(t[2],t[0]),rl(t[3],t[1])];return{sizes:n,centers:[Rc(t[0],Hc(n[0],G(2))),Rc(t[1],Hc(n[1],G(2)))]}}function Kh(e,t){var n=Gh(e),r=n.sizes,i=n.centers,a=Nr(bu(t,[1,0])),o=Hc(Qc(Xs(Hc(a[2],G(5))),r[0]),G(2)),s=Rc(Qc(Hc(a[0],G(10)),r[0]),i[0]),c=Hc(Qc(Xs(Hc(a[3],G(5))),r[1]),G(2)),l=Rc(Qc(Hc(a[1],G(10)),r[1]),i[1]);return bu(Ar([rl(s,o),rl(l,c),Rc(s,o),Rc(l,c)]),[1,0])}function qh(e,t,n){return H(function(){var r=e.shape[0],i=Kh(Dr(jr(n.extra_dim,[r,1,1]),[-1,4]),Dr(e,[-1,4]));i=Dr(i,[r,i.shape[0]/r,4]);var a=Zl(oc(Zl(t,[0,0,1],[-1,-1,-1])),[0,0,0],[-1,-1,1]);return a=Dr(a,[r,a.shape[1]]),{boxes:Nr(i),scores:Nr(a)}})}function Jh(e,t){return H(function(){var n=e.shape[0];return{boxPredictionEncoding:Dr(Dm(e,t.box_encoding_predictor),[n,-1,1,4]),classPrediction:Dr(Dm(e,t.class_predictor),[n,-1,3])}})}function Yh(e,t,n){return H(function(){var r=Rh(Rh(e,n.conv_0,[1,1]),n.conv_1,[2,2]),i=Rh(Rh(r,n.conv_2,[1,1]),n.conv_3,[2,2]),a=Rh(Rh(i,n.conv_4,[1,1]),n.conv_5,[2,2]),o=Rh(Rh(a,n.conv_6,[1,1]),n.conv_7,[2,2]),s=Jh(t,n.box_predictor_0),c=Jh(e,n.box_predictor_1),l=Jh(r,n.box_predictor_2),u=Jh(i,n.box_predictor_3),d=Jh(a,n.box_predictor_4),f=Jh(o,n.box_predictor_5);return{boxPredictions:Un([s.boxPredictionEncoding,c.boxPredictionEncoding,l.boxPredictionEncoding,u.boxPredictionEncoding,d.boxPredictionEncoding,f.boxPredictionEncoding],1),classPredictions:Un([s.classPrediction,c.classPrediction,l.classPrediction,u.classPrediction,d.classPrediction,f.classPrediction],1)}})}var Xh=function(){function e(e){var t=e===void 0?{}:e,n=t.minConfidence,r=t.maxResults;if(this._name=`SsdMobilenetv1Options`,this._minConfidence=n||.5,this._maxResults=r||100,typeof this._minConfidence!=`number`||this._minConfidence<=0||this._minConfidence>=1)throw Error(this._name+` - expected minConfidence to be a number between 0 and 1`);if(typeof this._maxResults!=`number`)throw 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}(),Zh=function(e){Z(t,e);function t(){return e.call(this,`SsdMobilenetv1`)||this}return t.prototype.forwardInput=function(e){var t=this.params;if(!t)throw Error(`SsdMobilenetv1 - load model before inference`);return H(function(){var n=Hh(rl(Qc(e.toBatchTensor(512,!1).toFloat(),G(.007843137718737125)),G(1)),t.mobilenetv1),r=Yh(n.out,n.conv11,t.prediction_layer),i=r.boxPredictions,a=r.classPredictions;return qh(i,a,t.output_layer)})},t.prototype.forward=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=this.forwardInput,[4,gm(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.locateFaces=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S;return $(this,function(C){switch(C.label){case 0:return n=new Xh(t),r=n.maxResults,i=n.minConfidence,[4,gm(e)];case 1:for(a=C.sent(),o=this.forwardInput(a),s=o.boxes,c=o.scores,l=s[0],u=c[0],d=1;d<s.length;d++)s[d].dispose(),c[d].dispose();return m=(p=Array).from,[4,u.data()];case 2:return f=m.apply(p,[C.sent()]),h=.5,g=Uh(l,f,r,h,i),_=a.getReshapedInputDimensions(0),v=a.inputSize,y=v/_.width,b=v/_.height,x=l.arraySync(),S=g.map(function(e){var t=[Math.max(0,x[e][0]),Math.min(1,x[e][2])].map(function(e){return e*b}),n=t[0],r=t[1],i=[Math.max(0,x[e][1]),Math.min(1,x[e][3])].map(function(e){return e*y}),o=i[0],s=i[1];return new Tp(f[e],new Mp(o,n,s-o,r-n),{height:a.getInputHeight(0),width:a.getInputWidth(0)})}),l.dispose(),u.dispose(),[2,S]}})})},t.prototype.getDefaultModelName=function(){return`ssd_mobilenetv1_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Lh(e)},t.prototype.extractParams=function(e){return Fh(e)},t}(Cm);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t})(Zh);var Qh=.4,$h=[new xp(.738768,.874946),new xp(2.42204,2.65704),new xp(4.30971,7.04493),new xp(10.246,4.59428),new xp(12.6868,11.8741)],eg=[new xp(1.603231,2.094468),new xp(6.041143,7.080126),new xp(2.882459,3.518061),new xp(4.266906,5.178857),new xp(9.041765,10.66308)],tg=[117.001,114.697,97.404],ng=`tiny_yolov2_model`,rg=`tiny_yolov2_separable_conv_model`,ig=function(e){return typeof e==`number`};function ag(e){if(!e)throw Error(`invalid config: `+e);if(typeof e.withSeparableConvs!=`boolean`)throw Error(`config.withSeparableConvs has to be a boolean, have: `+e.withSeparableConvs);if(!ig(e.iouThreshold)||e.iouThreshold<0||e.iouThreshold>1)throw 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(e){return typeof e==`string`}))throw 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(e){return e||{}}).every(function(e){return ig(e.x)&&ig(e.y)}))throw 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(ig)))throw Error(`config.meanRgb has to be an array of shape [number, number, number], have: `+JSON.stringify(e.meanRgb))}function og(e){return H(function(){var t=Qc(e,G(.10000000149011612));return Rc(_u(rl(e,t)),t)})}function sg(e,t){return H(function(){var n=vr(e,[[0,0],[1,1],[1,1],[0,0]]);return n=El(n,t.conv.filters,[1,1],`valid`),n=rl(n,t.bn.sub),n=Qc(n,t.bn.truediv),n=Rc(n,t.conv.bias),og(n)})}function cg(e,t){return H(function(){var n=vr(e,[[0,0],[1,1],[1,1],[0,0]]);return n=Nl(n,t.depthwise_filter,t.pointwise_filter,[1,1],`valid`),n=Rc(n,t.bias),og(n)})}function lg(e,t){var n=km(e,t);function r(n,r){var i=kn(e(n)),a=kn(e(n));return t.push({paramPath:r+`/sub`},{paramPath:r+`/truediv`}),{sub:i,truediv:a}}function i(e,t,i){return{conv:n(e,t,3,i+`/conv`),bn:r(t,i+`/bn`)}}return{extractConvParams:n,extractConvWithBatchNormParams:i,extractSeparableConvParams:Mm(e,t)}}function ug(e,t,n,r){var i=Fm(e),a=i.extractWeights,o=i.getRemainingWeights,s=[],c=lg(a,s),l=c.extractConvParams,u=c.extractConvWithBatchNormParams,d=c.extractSeparableConvParams,f;if(t.withSeparableConvs){var p=r[0],m=r[1],h=r[2],g=r[3],_=r[4],v=r[5],y=r[6],b=r[7],x=r[8],S=t.isFirstLayerConv2d?l(p,m,3,`conv0`):d(p,m,`conv0`),C=d(m,h,`conv1`),w=d(h,g,`conv2`),T=d(g,_,`conv3`),E=d(_,v,`conv4`),D=d(v,y,`conv5`),O=b?d(y,b,`conv6`):void 0,k=x?d(b,x,`conv7`):void 0,A=l(x||b||y,5*n,1,`conv8`);f={conv0:S,conv1:C,conv2:w,conv3:T,conv4:E,conv5:D,conv6:O,conv7:k,conv8:A}}else{var p=r[0],m=r[1],h=r[2],g=r[3],_=r[4],v=r[5],y=r[6],b=r[7],x=r[8],S=u(p,m,`conv0`),C=u(m,h,`conv1`),w=u(h,g,`conv2`),T=u(g,_,`conv3`),E=u(_,v,`conv4`),D=u(v,y,`conv5`),O=u(y,b,`conv6`),k=u(b,x,`conv7`),A=l(x,5*n,1,`conv8`);f={conv0:S,conv1:C,conv2:w,conv3:T,conv4:E,conv5:D,conv6:O,conv7:k,conv8:A}}if(o().length!==0)throw Error(`weights remaing after extract: `+o().length);return{params:f,paramMappings:s}}function dg(e,t){var n=Pm(e,t);function r(e){return{sub:n(e+`/sub`,1),truediv:n(e+`/truediv`,1)}}function i(e){return{filters:n(e+`/filters`,4),bias:n(e+`/bias`,1)}}function a(e){return{conv:i(e+`/conv`),bn:r(e+`/bn`)}}return{extractConvParams:i,extractConvWithBatchNormParams:a,extractSeparableConvParams:Nm(n)}}function fg(e,t){var n=[],r=dg(e,n),i=r.extractConvParams,a=r.extractConvWithBatchNormParams,o=r.extractSeparableConvParams,s;if(t.withSeparableConvs){var c=t.filterSizes&&t.filterSizes.length||9;s={conv0:t.isFirstLayerConv2d?i(`conv0`):o(`conv0`),conv1:o(`conv1`),conv2:o(`conv2`),conv3:o(`conv3`),conv4:o(`conv4`),conv5:o(`conv5`),conv6:c>7?o(`conv6`):void 0,conv7:c>8?o(`conv7`):void 0,conv8:i(`conv8`)}}else s={conv0:a(`conv0`),conv1:a(`conv1`),conv2:a(`conv2`),conv3:a(`conv3`),conv4:a(`conv4`),conv5:a(`conv5`),conv6:a(`conv6`),conv7:a(`conv7`),conv8:i(`conv8`)};return Om(e,n),{params:s,paramMappings:n}}var pg;(function(e){e[e.XS=224]=`XS`,e[e.SM=320]=`SM`,e[e.MD=416]=`MD`,e[e.LG=608]=`LG`})(pg||={});var mg=function(){function e(e){var t=e===void 0?{}:e,n=t.inputSize,r=t.scoreThreshold;if(this._name=`TinyYolov2Options`,this._inputSize=n||416,this._scoreThreshold=r||.5,typeof this._inputSize!=`number`||this._inputSize%32!=0)throw Error(this._name+` - expected inputSize to be a number divisible by 32`);if(typeof this._scoreThreshold!=`number`||this._scoreThreshold<=0||this._scoreThreshold>=1)throw 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}(),hg=function(e){Z(t,e);function t(t){var n=e.call(this,`TinyYolov2`)||this;return ag(t),n._config=t,n}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(e,t){var n=sg(e,t.conv0);return n=Kl(n,[2,2],[2,2],`same`),n=sg(n,t.conv1),n=Kl(n,[2,2],[2,2],`same`),n=sg(n,t.conv2),n=Kl(n,[2,2],[2,2],`same`),n=sg(n,t.conv3),n=Kl(n,[2,2],[2,2],`same`),n=sg(n,t.conv4),n=Kl(n,[2,2],[2,2],`same`),n=sg(n,t.conv5),n=Kl(n,[2,2],[1,1],`same`),n=sg(n,t.conv6),n=sg(n,t.conv7),Dm(n,t.conv8,`valid`,!1)},t.prototype.runMobilenet=function(e,t){var n=this.config.isFirstLayerConv2d?og(Dm(e,t.conv0,`valid`,!1)):cg(e,t.conv0);return n=Kl(n,[2,2],[2,2],`same`),n=cg(n,t.conv1),n=Kl(n,[2,2],[2,2],`same`),n=cg(n,t.conv2),n=Kl(n,[2,2],[2,2],`same`),n=cg(n,t.conv3),n=Kl(n,[2,2],[2,2],`same`),n=cg(n,t.conv4),n=Kl(n,[2,2],[2,2],`same`),n=cg(n,t.conv5),n=Kl(n,[2,2],[1,1],`same`),n=t.conv6?cg(n,t.conv6):n,n=t.conv7?cg(n,t.conv7):n,Dm(n,t.conv8,`valid`,!1)},t.prototype.forwardInput=function(e,t){var n=this,r=this.params;if(!r)throw Error(`TinyYolov2 - load model before inference`);return H(function(){var i=e.toBatchTensor(t,!1).toFloat();return i=n.config.meanRgb?kp(i,n.config.meanRgb):i,i=i.div(G(256)),n.config.withSeparableConvs?n.runMobilenet(i,r):n.runTinyYolov2(i,r)})},t.prototype.forward=function(e,t){return Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return n=this.forwardInput,[4,gm(e)];case 1:return[4,n.apply(this,[r.sent(),t])];case 2:return[2,r.sent()]}})})},t.prototype.detect=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c,l,u,d,f,p,m,h,g=this;return $(this,function(_){switch(_.label){case 0:return n=new mg(t),r=n.inputSize,i=n.scoreThreshold,[4,gm(e)];case 1:return a=_.sent(),[4,this.forwardInput(a,r)];case 2:return o=_.sent(),s=H(function(){return Nr(o)[0].expandDims()}),c={width:a.getInputWidth(0),height:a.getInputHeight(0)},[4,this.extractBoxes(s,a.getReshapedInputDimensions(0),i)];case 3:return l=_.sent(),o.dispose(),s.dispose(),u=l.map(function(e){return e.box}),d=l.map(function(e){return e.score}),f=l.map(function(e){return e.classScore}),p=l.map(function(e){return g.config.classes[e.label]}),m=Op(u.map(function(e){return e.rescale(r)}),d,this.config.iouThreshold,!0),h=m.map(function(e){return new wp(d[e],f[e],p[e],u[e],c)}),[2,h]}})})},t.prototype.getDefaultModelName=function(){return``},t.prototype.extractParamsFromWeigthMap=function(e){return fg(e,this.config)},t.prototype.extractParams=function(e){var n=this.config.filterSizes||t.DEFAULT_FILTER_SIZES,r=n?n.length:void 0;if(r!==7&&r!==8&&r!==9)throw Error(`TinyYolov2 - expected 7 | 8 | 9 convolutional filters, but found `+r+` filterSizes in config`);return ug(e,this.config,this.boxEncodingSize,n)},t.prototype.extractBoxes=function(e,t,n){return Q(this,void 0,void 0,function(){var r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M=this;return $(this,function(N){switch(N.label){case 0:return r=t.width,i=t.height,a=Math.max(r,i),o=a/r,s=a/i,c=e.shape[1],l=this.config.anchors.length,u=H(function(){var t=e.reshape([c,c,l,M.boxEncodingSize]);return[t.slice([0,0,0,0],[c,c,l,4]),t.slice([0,0,0,4],[c,c,l,1]),M.withClassScores?ti(t.slice([0,0,0,5],[c,c,l,M.config.classes.length]),3):G(0)]}),d=u[0],f=u[1],p=u[2],m=[],[4,f.array()];case 1:return h=N.sent(),[4,d.array()];case 2:g=N.sent(),_=0,N.label=3;case 3:if(!(_<c))return[3,12];v=0,N.label=4;case 4:if(!(v<c))return[3,11];y=0,N.label=5;case 5:return y<l?(b=jp(h[_][v][y][0]),!n||b>n?(x=(v+jp(g[_][v][y][0]))/c*o,S=(_+jp(g[_][v][y][1]))/c*s,C=Math.exp(g[_][v][y][2])*this.config.anchors[y].x/c*o,w=Math.exp(g[_][v][y][3])*this.config.anchors[y].y/c*s,T=x-C/2,E=S-w/2,D={row:_,col:v,anchor:y},this.withClassScores?[4,this.extractPredictedClass(p,D)]:[3,7]):[3,9]):[3,10];case 6:return j=N.sent(),[3,8];case 7:j={classScore:1,label:0},N.label=8;case 8:O=j,k=O.classScore,A=O.label,m.push(ap({box:new Cp(T,E,T+C,E+w),score:b,classScore:b*k,label:A},D)),N.label=9;case 9:return y++,[3,5];case 10:return v++,[3,4];case 11:return _++,[3,3];case 12:return d.dispose(),f.dispose(),p.dispose(),[2,m]}})})},t.prototype.extractPredictedClass=function(e,t){return Q(this,void 0,void 0,function(){var n,r,i,a;return $(this,function(o){switch(o.label){case 0:return n=t.row,r=t.col,i=t.anchor,[4,e.array()];case 1:return a=o.sent(),[2,Array(this.config.classes.length).fill(0).map(function(e,t){return a[n][r][i][t]}).map(function(e,t){return{classScore:e,label:t}}).reduce(function(e,t){return e.classScore>t.classScore?e:t})]}})})},t.DEFAULT_FILTER_SIZES=[3,16,32,64,128,256,512,1024,1024],t}(Cm),gg=function(e){Z(t,e);function t(t){t===void 0&&(t=!0);var n=this,r=Object.assign({},{withSeparableConvs:t,iouThreshold:Qh,classes:[`face`]},t?{anchors:eg,meanRgb:tg}:{anchors:$h,withClassScores:!0});return n=e.call(this,r)||this,n}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(e,t){return Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return[4,this.detect(e,t)];case 1:return n=r.sent(),[2,n.map(function(e){return new Tp(e.score,e.relativeBox,{width:e.imageWidth,height:e.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return this.withSeparableConvs?rg:ng},t.prototype.extractParamsFromWeigthMap=function(t){return e.prototype.extractParamsFromWeigthMap.call(this,t)},t}(hg),_g=function(e){Z(t,e);function t(){var t=e!==null&&e.apply(this,arguments)||this;return t._name=`TinyFaceDetectorOptions`,t}return t}(mg),vg=function(){function e(){}return e.prototype.then=function(e){return Q(this,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=e,[4,this.run()];case 1:return[2,t.apply(void 0,[n.sent()])]}})})},e.prototype.run=function(){return Q(this,void 0,void 0,function(){return $(this,function(e){throw Error(`ComposableTask - run is not implemented`)})})},e}();function yg(e,t,n,r,i){return i===void 0&&(i=function(e){return e.alignedRect}),Q(this,void 0,void 0,function(){var a,o,s,c,l;return $(this,function(u){switch(u.label){case 0:return a=e.map(function(e){return Zm(e)?i(e):e.detection}),s=r,s?[3,5]:t instanceof Be?[4,vm(t,a)]:[3,2];case 1:return c=u.sent(),[3,4];case 2:return[4,_m(t,a)];case 3:c=u.sent(),u.label=4;case 4:s=c,u.label=5;case 5:return o=s,[4,n(o)];case 6:return l=u.sent(),o.forEach(function(e){return e instanceof Be&&e.dispose()}),[2,l]}})})}function bg(e,t,n,r,i){return Q(this,void 0,void 0,function(){var a=this;return $(this,function(o){return[2,yg([e],t,function(e){return Q(a,void 0,void 0,function(){return $(this,function(t){return[2,n(e[0])]})})},r,i)]})})}function xg(e){return H(function(){return Ar(Nr(e,3).reverse(),3)})}function Sg(e,t){var n=km(e,t),r=Am(e,t);function i(n,r){var i=kn(e(n));return t.push({paramPath:r}),i}function a(e,t,r){return r===void 0&&(r=!1),{conv1:n(e[0],e[1],3,t+`/conv1`),prelu1_alpha:i(e[1],t+`/prelu1_alpha`),conv2:n(e[1],e[2],3,t+`/conv2`),prelu2_alpha:i(e[2],t+`/prelu2_alpha`),conv3:n(e[2],e[3],r?2:3,t+`/conv3`),prelu3_alpha:i(e[3],t+`/prelu3_alpha`)}}function o(){var e=a([3,10,16,32],`pnet`),t=n(32,2,1,`pnet/conv4_1`),r=n(32,4,1,`pnet/conv4_2`);return ap(ap({},e),{conv4_1:t,conv4_2:r})}function s(){var e=a([3,28,48,64],`rnet`,!0),t=r(576,128,`rnet/fc1`),n=i(128,`rnet/prelu4_alpha`),o=r(128,2,`rnet/fc2_1`),s=r(128,4,`rnet/fc2_2`);return ap(ap({},e),{fc1:t,prelu4_alpha:n,fc2_1:o,fc2_2:s})}function c(){var e=a([3,32,64,64],`onet`),t=n(64,128,2,`onet/conv4`),o=i(128,`onet/prelu4_alpha`),s=r(1152,256,`onet/fc1`),c=i(256,`onet/prelu5_alpha`),l=r(256,2,`onet/fc2_1`),u=r(256,4,`onet/fc2_2`),d=r(256,10,`onet/fc2_3`);return ap(ap({},e),{conv4:t,prelu4_alpha:o,fc1:s,prelu5_alpha:c,fc2_1:l,fc2_2:u,fc2_3:d})}return{extractPNetParams:o,extractRNetParams:s,extractONetParams:c}}function Cg(e){var t=Fm(e),n=t.extractWeights,r=t.getRemainingWeights,i=[],a=Sg(n,i),o=a.extractPNetParams,s=a.extractRNetParams,c=a.extractONetParams,l=o(),u=s(),d=c();if(r().length!==0)throw Error(`weights remaing after extract: `+r().length);return{params:{pnet:l,rnet:u,onet:d},paramMappings:i}}function wg(e,t){var n=Pm(e,t);function r(e){return{filters:n(e+`/weights`,4,e+`/filters`),bias:n(e+`/bias`,1)}}function i(e){return{weights:n(e+`/weights`,2),bias:n(e+`/bias`,1)}}function a(e){return n(e,1)}function o(e){return{conv1:r(e+`/conv1`),prelu1_alpha:a(e+`/prelu1_alpha`),conv2:r(e+`/conv2`),prelu2_alpha:a(e+`/prelu2_alpha`),conv3:r(e+`/conv3`),prelu3_alpha:a(e+`/prelu3_alpha`)}}function s(){var e=o(`pnet`),t=r(`pnet/conv4_1`),n=r(`pnet/conv4_2`);return ap(ap({},e),{conv4_1:t,conv4_2:n})}function c(){var e=o(`rnet`),t=i(`rnet/fc1`),n=a(`rnet/prelu4_alpha`),r=i(`rnet/fc2_1`),s=i(`rnet/fc2_2`);return ap(ap({},e),{fc1:t,prelu4_alpha:n,fc2_1:r,fc2_2:s})}function l(){var e=o(`onet`),t=r(`onet/conv4`),n=a(`onet/prelu4_alpha`),s=i(`onet/fc1`),c=a(`onet/prelu5_alpha`),l=i(`onet/fc2_1`),u=i(`onet/fc2_2`),d=i(`onet/fc2_3`);return ap(ap({},e),{conv4:t,prelu4_alpha:n,fc1:s,prelu5_alpha:c,fc2_1:l,fc2_2:u,fc2_3:d})}return{extractPNetParams:s,extractRNetParams:c,extractONetParams:l}}function Tg(e){var t=[],n=wg(e,t),r=n.extractPNetParams,i=n.extractRNetParams,a=n.extractONetParams,o=r(),s=i(),c=a();return Om(e,t),{params:{pnet:o,rnet:s,onet:c},paramMappings:t}}function Eg(e,t){var n=t[0],r=t[1];return{height:Math.floor(n*e),width:Math.floor(r*e)}}function Dg(e,t,n){for(var r=n[0],i=n[1],a=12/e,o=[],s=Math.min(r,i)*a,c=0;s>=12;)o.push(a*t**+c),s*=t,c+=1;return o}var Og=function(e){Z(t,e);function t(t,n,r,i){return e.call(this,{left:t,top:n,right:r,bottom:i},!0)||this}return t}(Sp);function kg(e){return H(function(){return Qc(rl(e,G(127.5)),G(.0078125))})}function Ag(e,t){return H(function(){return Rc(_u(e),Qc(t,nc(_u(nc(e)))))})}function jg(e,t,n){return n===void 0&&(n=!1),H(function(){var r=Dm(e,t.conv1,`valid`);return r=Ag(r,t.prelu1_alpha),r=Kl(r,n?[2,2]:[3,3],[2,2],`same`),r=Dm(r,t.conv2,`valid`),r=Ag(r,t.prelu2_alpha),r=n?r:Kl(r,[3,3],[2,2],`valid`),r=Dm(r,t.conv3,`valid`),r=Ag(r,t.prelu3_alpha),r})}function Mg(e,t){return H(function(){var n=jg(e,t,!0),r=Dm(n,t.conv4_1,`valid`);return{prob:ti(rl(r,mr(cu(r,3),3)),3),regions:Dm(n,t.conv4_2,`valid`)}})}function Ng(e,t){return H(function(){var n=Eg(t,e.shape.slice(1)),r=n.height,i=n.width;return bu(kg(hd.resizeBilinear(e,[r,i])),[0,2,1,3])})}function Pg(e,t,n,r){for(var i=[],a=e.arraySync(),o=0;o<e.shape[0];o++)for(var s=0;s<e.shape[1];s++)a[o][s]>=r&&i.push(new xp(s,o));return i.map(function(e){var r=new Cp(Math.round((e.y*2+1)/n),Math.round((e.x*2+1)/n),Math.round((e.y*2+12)/n),Math.round((e.x*2+12)/n)),i=a[e.y][e.x],o=t.arraySync();return{cell:r,score:i,region:new Og(o[e.y][e.x][0],o[e.y][e.x][1],o[e.y][e.x][2],o[e.y][e.x][3])}})}function Fg(e,t,n,r,i){i.stage1=[];var a=t.map(function(t){return H(function(){var n={scale:t},i=Ng(e,t),a=Date.now(),o=Mg(i,r),s=o.prob,c=o.regions;return n.pnet=Date.now()-a,{scoresTensor:Nr(Nr(s,3)[1])[0],regionsTensor:Nr(c)[0],scale:t,statsForScale:n}})}).map(function(e){var t=e.scoresTensor,r=e.regionsTensor,a=e.scale,o=e.statsForScale,s=Pg(t,r,a,n);if(t.dispose(),r.dispose(),!s.length)return i.stage1.push(o),[];var c=Date.now(),l=Op(s.map(function(e){return e.cell}),s.map(function(e){return e.score}),.5);return o.nms=Date.now()-c,o.numBoxes=l.length,i.stage1.push(o),l.map(function(e){return s[e]})}).reduce(function(e,t){return e.concat(t)},[]),o=[],s=[];if(a.length>0){var c=Date.now(),l=Op(a.map(function(e){return e.cell}),a.map(function(e){return e.score}),.7);i.stage1_nms=Date.now()-c,s=l.map(function(e){return a[e].score}),o=l.map(function(e){return a[e]}).map(function(e){var t=e.cell,n=e.region;return new Cp(t.left+n.left*t.width,t.top+n.top*t.height,t.right+n.right*t.width,t.bottom+n.bottom*t.height).toSquare().round()})}return{boxes:o,scores:s}}function Ig(e,t,n){var r=n.width,i=n.height;return Q(this,void 0,void 0,function(){var n,a,o,s=this;return $(this,function(c){switch(c.label){case 0:return n=nm(e),[4,Promise.all(t.map(function(t){return Q(s,void 0,void 0,function(){var r,i,a,o,s,c,l,u;return $(this,function(d){return r=t.padAtBorders(e.height,e.width),i=r.y,a=r.ey,o=r.x,s=r.ex,c=o-1,l=i-1,u=n.getImageData(c,l,s-c,a-l),[2,em.isNodejs()?dm(u):createImageBitmap(u)]})})}))];case 1:return a=c.sent(),o=[],a.forEach(function(e){var t=nm(um({width:r,height:i}));t.drawImage(e,0,0,r,i);for(var n=t.getImageData(0,0,r,i).data,a=[],s=0;s<n.length;s+=4)a.push(n[s+2]),a.push(n[s+1]),a.push(n[s]);o.push(a)}),[2,o.map(function(e){return H(function(){return kg(bu(Mn(e,[1,r,i,3]),[0,2,1,3]).toFloat())})})]}})})}function Lg(e,t){return H(function(){var n=jg(e,t),r=Ag(Hm(Dr(n,[n.shape[0],t.fc1.weights.shape[0]]),t.fc1),t.prelu4_alpha),i=Hm(r,t.fc2_1),a=ti(rl(i,mr(cu(i,1),1)),1),o=Hm(r,t.fc2_2);return{scores:Nr(a,1)[1],regions:o}})}function Rg(e,t,n,r,i){return Q(this,void 0,void 0,function(){var a,o,s,c,l,u,d,f,p,m,h,g,_,v;return $(this,function(y){switch(y.label){case 0:return a=Date.now(),[4,Ig(e,t,{width:24,height:24})];case 1:return o=y.sent(),i.stage2_extractImagePatches=Date.now()-a,a=Date.now(),s=o.map(function(e){var t=Lg(e,r);return e.dispose(),t}),i.stage2_rnet=Date.now()-a,c=s.length>1?Un(s.map(function(e){return e.scores})):s[0].scores,d=(u=Array).from,[4,c.data()];case 2:return l=d.apply(u,[y.sent()]),c.dispose(),f=l.map(function(e,t){return{score:e,idx:t}}).filter(function(e){return e.score>n}).map(function(e){return e.idx}),p=f.map(function(e){return t[e]}),m=f.map(function(e){return l[e]}),h=[],g=[],p.length>0&&(a=Date.now(),_=Op(p,m,.7),i.stage2_nms=Date.now()-a,v=_.map(function(e){var t=s[f[e]].regions.arraySync();return new Og(t[0][0],t[0][1],t[0][2],t[0][3])}),g=_.map(function(e){return m[e]}),h=_.map(function(e,t){return p[e].calibrate(v[t])})),s.forEach(function(e){e.regions.dispose(),e.scores.dispose()}),[2,{boxes:h,scores:g}]}})})}function zg(e,t){return H(function(){var n=jg(e,t);n=Kl(n,[2,2],[2,2],`same`),n=Dm(n,t.conv4,`valid`),n=Ag(n,t.prelu4_alpha);var r=Ag(Hm(Dr(n,[n.shape[0],t.fc1.weights.shape[0]]),t.fc1),t.prelu5_alpha),i=Hm(r,t.fc2_1),a=ti(rl(i,mr(cu(i,1),1)),1),o=Hm(r,t.fc2_2),s=Hm(r,t.fc2_3);return{scores:Nr(a,1)[1],regions:o,points:s}})}function Bg(e,t,n,r,i){return Q(this,void 0,void 0,function(){var a,o,s,c,l,u,d,f,p,m,h,g,_,v,y;return $(this,function(b){switch(b.label){case 0:return a=Date.now(),[4,Ig(e,t,{width:48,height:48})];case 1:return o=b.sent(),i.stage3_extractImagePatches=Date.now()-a,a=Date.now(),s=o.map(function(e){var t=zg(e,r);return e.dispose(),t}),i.stage3_onet=Date.now()-a,c=s.length>1?Un(s.map(function(e){return e.scores})):s[0].scores,d=(u=Array).from,[4,c.data()];case 2:return l=d.apply(u,[b.sent()]),c.dispose(),f=l.map(function(e,t){return{score:e,idx:t}}).filter(function(e){return e.score>n}).map(function(e){return e.idx}),p=f.map(function(e){var t=s[e].regions.arraySync();return new Og(t[0][0],t[0][1],t[0][2],t[0][3])}),m=f.map(function(e,n){return t[e].calibrate(p[n])}),h=f.map(function(e){return l[e]}),g=[],_=[],v=[],m.length>0&&(a=Date.now(),y=Op(m,h,.7,!1),i.stage3_nms=Date.now()-a,g=y.map(function(e){return m[e]}),_=y.map(function(e){return h[e]}),v=y.map(function(e,t){return[,,,,,].fill(0).map(function(n,r){var i=s[e].points.arraySync();return new xp(i[0][r]*(g[t].width+1)+g[t].left,i[0][r+5]*(g[t].height+1)+g[t].top)})})),s.forEach(function(e){e.regions.dispose(),e.scores.dispose(),e.points.dispose()}),[2,{boxes:g,scores:_,points:v}]}})})}var Vg=function(e){Z(t,e);function t(){return e.call(this,`Mtcnn`)||this}return t.prototype.load=function(t){return Q(this,void 0,void 0,function(){return $(this,function(n){return console.warn(`mtcnn is deprecated and will be removed soon`),[2,e.prototype.load.call(this,t)]})})},t.prototype.loadFromDisk=function(t){return Q(this,void 0,void 0,function(){return $(this,function(n){return console.warn(`mtcnn is deprecated and will be removed soon`),[2,e.prototype.loadFromDisk.call(this,t)]})})},t.prototype.forwardInput=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S;return $(this,function(C){switch(C.label){case 0:if(n=this.params,!n)throw Error(`Mtcnn - load model before inference`);if(r=e.canvases[0],!r)throw Error(`Mtcnn - inputCanvas is not defined, note that passing tensors into Mtcnn.forwardInput is not supported yet.`);return i={},a=Date.now(),o=H(function(){return xg(mr(zf.fromPixels(r)).toFloat())}),s=function(e){return o.dispose(),i.total=Date.now()-a,e},c=o.shape.slice(1),l=c[0],u=c[1],d=new Nh(t),f=d.minFaceSize,p=d.scaleFactor,m=d.maxNumScales,h=d.scoreThresholds,g=d.scaleSteps,_=(g||Dg(f,p,[l,u])).filter(function(e){var t=Eg(e,[l,u]);return Math.min(t.width,t.height)>12}).slice(0,m),i.scales=_,i.pyramid=_.map(function(e){return Eg(e,[l,u])}),v=Date.now(),[4,Fg(o,_,h[0],n.pnet,i)];case 1:return y=C.sent(),i.total_stage1=Date.now()-v,y.boxes.length?(i.stage2_numInputBoxes=y.boxes.length,v=Date.now(),[4,Rg(r,y.boxes,h[1],n.rnet,i)]):[2,s({results:[],stats:i})];case 2:return b=C.sent(),i.total_stage2=Date.now()-v,b.boxes.length?(i.stage3_numInputBoxes=b.boxes.length,v=Date.now(),[4,Bg(r,b.boxes,h[2],n.onet,i)]):[2,s({results:[],stats:i})];case 3:return x=C.sent(),i.total_stage3=Date.now()-v,S=x.boxes.map(function(e,t){return Qm(Up({},new Tp(x.scores[t],new Mp(e.left/u,e.top/l,e.width/u,e.height/l),{height:l,width:u})),new Lp(x.points[t].map(function(t){return t.sub(new xp(e.left,e.top)).div(new xp(e.width,e.height))}),{width:e.width,height:e.height}))}),[2,s({results:S,stats:i})]}})})},t.prototype.forward=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return n=this.forwardInput,[4,gm(e)];case 1:return[4,n.apply(this,[r.sent(),t])];case 2:return[2,r.sent().results]}})})},t.prototype.forwardWithStats=function(e,t){return t===void 0&&(t={}),Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return n=this.forwardInput,[4,gm(e)];case 1:return[2,n.apply(this,[r.sent(),t])]}})})},t.prototype.getDefaultModelName=function(){return`mtcnn_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Tg(e)},t.prototype.extractParams=function(e){return Cg(e)},t}(Cm),Hg=.4,Ug=[new xp(1.603231,2.094468),new xp(6.041143,7.080126),new xp(2.882459,3.518061),new xp(4.266906,5.178857),new xp(9.041765,10.66308)],Wg=[117.001,114.697,97.404],Gg=function(e){Z(t,e);function t(){var t=this,n={withSeparableConvs:!0,iouThreshold:Hg,classes:[`face`],anchors:Ug,meanRgb:Wg,isFirstLayerConv2d:!0,filterSizes:[3,16,32,64,128,256,512]};return t=e.call(this,n)||this,t}return Object.defineProperty(t.prototype,`anchors`,{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),t.prototype.locateFaces=function(e,t){return Q(this,void 0,void 0,function(){var n;return $(this,function(r){switch(r.label){case 0:return[4,this.detect(e,t)];case 1:return n=r.sent(),[2,n.map(function(e){return new Tp(e.score,e.relativeBox,{width:e.imageWidth,height:e.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return`tiny_face_detector_model`},t.prototype.extractParamsFromWeigthMap=function(t){return e.prototype.extractParamsFromWeigthMap.call(this,t)},t}(hg),Kg={ssdMobilenetv1:new Zh,tinyFaceDetector:new Gg,tinyYolov2:new gg,mtcnn:new Vg,faceLandmark68Net:new ph,faceLandmark68TinyNet:new _h,faceRecognitionNet:new kh,faceExpressionNet:new Ym,ageGenderNet:new dh},qg=function(e){Z(t,e);function t(t,n,r){var i=e.call(this)||this;return i.parentTask=t,i.input=n,i.extractedFaces=r,i}return t}(vg),Jg=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n=this;return $(this,function(r){switch(r.label){case 0:return[4,this.parentTask];case 1:return e=r.sent(),[4,yg(e,this.input,function(e){return Q(n,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,Promise.all(e.map(function(e){return Kg.faceExpressionNet.predictExpressions(e)}))];case 1:return[2,t.sent()]}})})},this.extractedFaces)];case 2:return t=r.sent(),[2,e.map(function(e,n){return Xm(e,t[n])})]}})})},t.prototype.withAgeAndGender=function(){return new $g(this,this.input)},t}(qg),Yg=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,this.parentTask];case 1:return e=n.sent(),e?[4,bg(e,this.input,function(e){return Kg.faceExpressionNet.predictExpressions(e)},this.extractedFaces)]:[2];case 2:return t=n.sent(),[2,Xm(e,t)]}})})},t.prototype.withAgeAndGender=function(){return new e_(this,this.input)},t}(qg),Xg=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new t_(this,this.input)},t.prototype.withFaceDescriptors=function(){return new i_(this,this.input)},t}(Jg),Zg=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new n_(this,this.input)},t.prototype.withFaceDescriptor=function(){return new a_(this,this.input)},t}(Yg),Qg=function(e){Z(t,e);function t(t,n,r){var i=e.call(this)||this;return i.parentTask=t,i.input=n,i.extractedFaces=r,i}return t}(vg),$g=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n=this;return $(this,function(r){switch(r.label){case 0:return[4,this.parentTask];case 1:return e=r.sent(),[4,yg(e,this.input,function(e){return Q(n,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,Promise.all(e.map(function(e){return Kg.ageGenderNet.predictAgeAndGender(e)}))];case 1:return[2,t.sent()]}})})},this.extractedFaces)];case 2:return t=r.sent(),[2,e.map(function(e,n){var r=t[n],i=r.age,a=r.gender,o=r.genderProbability;return jh(Mh(e,a,o),i)})]}})})},t.prototype.withFaceExpressions=function(){return new Jg(this,this.input)},t}(Qg),e_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r,i;return $(this,function(a){switch(a.label){case 0:return[4,this.parentTask];case 1:return e=a.sent(),e?[4,bg(e,this.input,function(e){return Kg.ageGenderNet.predictAgeAndGender(e)},this.extractedFaces)]:[2];case 2:return t=a.sent(),n=t.age,r=t.gender,i=t.genderProbability,[2,jh(Mh(e,r,i),n)]}})})},t.prototype.withFaceExpressions=function(){return new Yg(this,this.input)},t}(Qg),t_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new Xg(this,this.input)},t.prototype.withFaceDescriptors=function(){return new i_(this,this.input)},t}($g),n_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new Zg(this,this.input)},t.prototype.withFaceDescriptor=function(){return new a_(this,this.input)},t}(e_),r_=function(e){Z(t,e);function t(t,n){var r=e.call(this)||this;return r.parentTask=t,r.input=n,r}return t}(vg),i_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,this.parentTask];case 1:return e=n.sent(),[4,yg(e,this.input,function(e){return Promise.all(e.map(function(e){return Kg.faceRecognitionNet.computeFaceDescriptor(e)}))},null,function(e){return e.landmarks.align(null,{useDlibAlignment:!0})})];case 2:return t=n.sent(),[2,t.map(function(t,n){return Ah(e[n],t)})]}})})},t.prototype.withFaceExpressions=function(){return new Xg(this,this.input)},t.prototype.withAgeAndGender=function(){return new t_(this,this.input)},t}(r_),a_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,this.parentTask];case 1:return e=n.sent(),e?[4,bg(e,this.input,function(e){return Kg.faceRecognitionNet.computeFaceDescriptor(e)},null,function(e){return e.landmarks.align(null,{useDlibAlignment:!0})})]:[2];case 2:return t=n.sent(),[2,Ah(e,t)]}})})},t.prototype.withFaceExpressions=function(){return new Zg(this,this.input)},t.prototype.withAgeAndGender=function(){return new n_(this,this.input)},t}(r_),o_=function(e){Z(t,e);function t(t,n,r){var i=e.call(this)||this;return i.parentTask=t,i.input=n,i.useTinyLandmarkNet=r,i}return Object.defineProperty(t.prototype,`landmarkNet`,{get:function(){return this.useTinyLandmarkNet?Kg.faceLandmark68TinyNet:Kg.faceLandmark68Net},enumerable:!0,configurable:!0}),t}(vg),s_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r,i,a=this;return $(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return e=o.sent(),t=e.map(function(e){return e.detection}),this.input instanceof Be?[4,vm(this.input,t)]:[3,3];case 2:return r=o.sent(),[3,5];case 3:return[4,_m(this.input,t)];case 4:r=o.sent(),o.label=5;case 5:return n=r,[4,Promise.all(n.map(function(e){return a.landmarkNet.detectLandmarks(e)}))];case 6:return i=o.sent(),n.forEach(function(e){return e instanceof Be&&e.dispose()}),[2,e.map(function(e,t){return Qm(e,i[t])})]}})})},t.prototype.withFaceExpressions=function(){return new Xg(this,this.input)},t.prototype.withAgeAndGender=function(){return new t_(this,this.input)},t.prototype.withFaceDescriptors=function(){return new i_(this,this.input)},t}(o_),c_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r,i;return $(this,function(a){switch(a.label){case 0:return[4,this.parentTask];case 1:return e=a.sent(),e?(t=e.detection,this.input instanceof Be?[4,vm(this.input,[t])]:[3,3]):[2];case 2:return r=a.sent(),[3,5];case 3:return[4,_m(this.input,[t])];case 4:r=a.sent(),a.label=5;case 5:return n=r,[4,this.landmarkNet.detectLandmarks(n[0])];case 6:return i=a.sent(),n.forEach(function(e){return e instanceof Be&&e.dispose()}),[2,Qm(e,i)]}})})},t.prototype.withFaceExpressions=function(){return new Zg(this,this.input)},t.prototype.withAgeAndGender=function(){return new n_(this,this.input)},t.prototype.withFaceDescriptor=function(){return new a_(this,this.input)},t}(o_),l_=function(e){Z(t,e);function t(t,n){n===void 0&&(n=new Xh);var r=e.call(this)||this;return r.input=t,r.options=n,r}return t}(vg),u_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t,n,r;return $(this,function(i){switch(i.label){case 0:return e=this,t=e.input,n=e.options,n instanceof Nh?[4,Kg.mtcnn.forward(t,n)]:[3,2];case 1:return[2,i.sent().map(function(e){return e.detection})];case 2:if(r=n instanceof _g?function(e){return Kg.tinyFaceDetector.locateFaces(e,n)}:n instanceof Xh?function(e){return Kg.ssdMobilenetv1.locateFaces(e,n)}:n instanceof mg?function(e){return Kg.tinyYolov2.locateFaces(e,n)}:null,!r)throw Error(`detectFaces - expected options to be instance of TinyFaceDetectorOptions | SsdMobilenetv1Options | MtcnnOptions | TinyYolov2Options`);return[2,r(t)]}})})},t.prototype.runAndExtendWithFaceDetections=function(){var e=this;return new Promise(function(t){return Q(e,void 0,void 0,function(){var e;return $(this,function(n){switch(n.label){case 0:return[4,this.run()];case 1:return e=n.sent(),[2,t(e.map(function(e){return Up({},e)}))]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new s_(this.runAndExtendWithFaceDetections(),this.input,e)},t.prototype.withFaceExpressions=function(){return new Jg(this.runAndExtendWithFaceDetections(),this.input)},t.prototype.withAgeAndGender=function(){return new $g(this.runAndExtendWithFaceDetections(),this.input)},t}(l_);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.run=function(){return Q(this,void 0,void 0,function(){var e,t;return $(this,function(n){switch(n.label){case 0:return[4,new u_(this.input,this.options)];case 1:return e=n.sent(),t=e[0],e.forEach(function(e){e.score>t.score&&(t=e)}),[2,t]}})})},t.prototype.runAndExtendWithFaceDetection=function(){var e=this;return new Promise(function(t){return Q(e,void 0,void 0,function(){var e;return $(this,function(n){switch(n.label){case 0:return[4,this.run()];case 1:return e=n.sent(),[2,t(e?Up({},e):void 0)]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new c_(this.runAndExtendWithFaceDetection(),this.input,e)},t.prototype.withFaceExpressions=function(){return new Yg(this.runAndExtendWithFaceDetection(),this.input)},t.prototype.withAgeAndGender=function(){return new e_(this.runAndExtendWithFaceDetection(),this.input)},t})(l_);function d_(e,t){return t===void 0&&(t=new Xh),new u_(e,t)}function f_(e,t){if(e.length!==t.length)throw Error(`euclideanDistance: arr1.length !== arr2.length`);var n=Array.from(e),r=Array.from(t);return Math.sqrt(n.map(function(e,t){return e-r[t]}).reduce(function(e,t){return e+t**2},0))}(function(){function e(e,t){t===void 0&&(t=.6),this._distanceThreshold=t;var n=Array.isArray(e)?e:[e];if(!n.length)throw Error(`FaceRecognizer.constructor - expected atleast one input`);var r=1,i=function(){return`person `+ r++};this._labeledDescriptors=n.map(function(e){if(e instanceof Vp)return e;if(e instanceof Float32Array)return new Vp(i(),[e]);if(e.descriptor&&e.descriptor instanceof Float32Array)return new Vp(i(),[e.descriptor]);throw Error(`FaceRecognizer.constructor - expected inputs to be of type LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array | Array<LabeledFaceDescriptors | WithFaceDescriptor<any> | 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(e,t){return t.map(function(t){return f_(t,e)}).reduce(function(e,t){return e+t},0)/(t.length||1)},e.prototype.matchDescriptor=function(e){var t=this;return this.labeledDescriptors.map(function(n){var r=n.descriptors,i=n.label;return new zp(i,t.computeMeanDistance(e,r))}).reduce(function(e,t){return e.distance<t.distance?e:t})},e.prototype.findBestMatch=function(e){var t=this.matchDescriptor(e);return t.distance<this.distanceThreshold?t:new zp(`unknown`,t.distance)},e.prototype.toJSON=function(){return{distanceThreshold:this.distanceThreshold,labeledDescriptors:this.labeledDescriptors.map(function(e){return e.toJSON()})}},e.fromJSON=function(t){return new e(t.labeledDescriptors.map(function(e){return Vp.fromJSON(e)}),t.distanceThreshold)},e})();function p_(){let e=!1;return{load:async t=>{e||=(await Kg.tinyFaceDetector.loadFromUri(t),!0)},detect:async t=>{if(!e)return{faces:0};let n=await d_(t,new _g({inputSize:224,scoreThreshold:.5}));if(!n||n.length===0)return{faces:0};if(n.length>1)return{faces:n.length};let r=n[0].box,i=t.videoWidth||1,a=t.videoHeight||1;return{faces:1,box:{x:r.x/i,y:r.y/a,width:r.width/i,height:r.height/a}}}}}function m_(e){if(e.faces===0)return{message:`Centralize seu rosto`,valid:!1};if(e.faces>1)return{message:`Apenas 1 rosto por vez`,valid:!1};if(!e.box)return{message:`Centralize seu rosto`,valid:!1};let{x:t,y:n,width:r,height:i}=e.box,a=t+r/2,o=n+i/2,s=r*i;return s<.07?{message:`Aproxime o rosto`,valid:!1}:s>.22?{message:`Afaste o rosto`,valid:!1}:Math.abs(a-.5)>.12||Math.abs(o-.5)>.12?{message:`Centralize seu rosto`,valid:!1}:{message:`Pronto para capturar`,valid:!0}}e.AlphaValid=class{_camera=null;_overlay=null;_container=null;_faceDetector=p_();_loopTimer=null;_lastStatusValid=!1;_options=null;async start(e){n(e.container,`options.container`),await this.stop(),this._options={overlay:!0,guideCircleRatio:.72,detectionIntervalMs:200,modelsPath:`/alphavalid-models`,...e},this._container=this._options.container;try{this._options.onFeedback?.(`Inicializando câmera...`),this._camera=await r(this._container),this._options.overlay!==!1&&(this._overlay=a(this._container,this._options.guideCircleRatio)),this._options.onReady?.(),this._options.modelsPath&&await this._faceDetector.load(this._options.modelsPath),this.startDetectionLoop()}catch(e){throw this._options?.onError?.(e),await this.stop(),e}}async stop(){this._loopTimer!=null&&(window.clearTimeout(this._loopTimer),this._loopTimer=null),this._lastStatusValid=!1,this._overlay&&=(this._overlay.dispose(),null),this._camera&&=(this._camera.stop(),null),this._container=null,this._options=null}async capture(){if(!this._camera)throw Error(`Camera not started. Call start() first.`);if(!this._lastStatusValid)throw Error(`Face not valid for capture yet. Wait for feedback "Pronto para capturar".`);return await i(this._camera.video,.9)}startDetectionLoop(){let e=async()=>{let t=this._camera,n=this._options;if(!(!t||!n))try{let e=await this._faceDetector.detect(t.video),r=m_(e);this._lastStatusValid=r.valid,n.onFeedback?.(r.message),this._overlay?.render({message:r.message,box:e.box,valid:r.valid})}catch(e){n.onError?.(e)}finally{this._loopTimer=window.setTimeout(e,n.detectionIntervalMs??200)}};e()}}});