alphavalid-sdk 0.0.22 → 0.0.24
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.
- package/README.md +67 -7
- package/dist/alphavalid.es.js +39 -33
- package/dist/alphavalid.umd.js +1 -1
- package/dist/core/feedback.d.ts.map +1 -1
- package/dist/types/sdk.d.ts +25 -0
- package/dist/types/sdk.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -75,25 +75,85 @@ await sdk.stop();
|
|
|
75
75
|
|
|
76
76
|
Você pode exigir que só seja considerado **válido olhando para frente**, e/ou definir uma sequência de desafios.
|
|
77
77
|
|
|
78
|
+
#### Importante (fluxo com challenges)
|
|
79
|
+
|
|
80
|
+
- Quando `liveness.challenges` é informado, o SDK **não** força `lookForward` globalmente a cada frame.
|
|
81
|
+
- Se você quiser `lookForward`, coloque como **um step explícito** (recomendado como último step).
|
|
82
|
+
|
|
83
|
+
#### Ajuste de sensibilidade do lookForward
|
|
84
|
+
|
|
85
|
+
Use `liveness.lookForwardTolerance` (0..1):
|
|
86
|
+
- **maior = mais tolerante** (mais fácil passar)
|
|
87
|
+
- se omitido, é derivado de `strictness`
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
await sdk.start({
|
|
91
|
+
// ...
|
|
92
|
+
liveness: {
|
|
93
|
+
strictness: 0.5,
|
|
94
|
+
lookForwardTolerance: 0.75
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Exemplo com sequência (cliente orquestra a ordem, SDK valida e controla o progresso):
|
|
100
|
+
|
|
78
101
|
```ts
|
|
79
102
|
await sdk.start({
|
|
80
103
|
container: document.getElementById('cameraContainer')!,
|
|
81
104
|
modelsPath: '/assets/alphavalid-models',
|
|
82
105
|
liveness: {
|
|
83
|
-
requireLookForward: true,
|
|
84
106
|
strictness: 0.5,
|
|
107
|
+
lookForwardTolerance: 0.75,
|
|
85
108
|
challenges: [
|
|
86
|
-
{ type: 'lookForward' },
|
|
87
109
|
{ type: 'lookLeft' },
|
|
88
110
|
{ type: 'lookRight' },
|
|
89
|
-
{ type: '
|
|
90
|
-
{ type: '
|
|
91
|
-
{ type: 'blink' }
|
|
111
|
+
{ type: 'lookUp' },
|
|
112
|
+
{ type: 'lookDown' },
|
|
113
|
+
{ type: 'blink' },
|
|
114
|
+
{ type: 'lookForward' } // recomendado como último
|
|
92
115
|
]
|
|
93
116
|
},
|
|
94
117
|
onStateChange: (state) => {
|
|
95
|
-
|
|
96
|
-
|
|
118
|
+
console.log('step:', state.challenge?.current, state.challenge?.index, '/', state.challenge?.total);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### Auto-capture (recomendado no cliente)
|
|
124
|
+
|
|
125
|
+
O SDK expõe `state.isReadyToCapture`. Para auto-capture sem duplicar disparos, use lock + debounce:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
let lock = false;
|
|
129
|
+
let timer: any = null;
|
|
130
|
+
|
|
131
|
+
await sdk.start({
|
|
132
|
+
// ...
|
|
133
|
+
onStateChange: async (state) => {
|
|
134
|
+
if (lock) return;
|
|
135
|
+
|
|
136
|
+
if (state.isReadyToCapture) {
|
|
137
|
+
if (timer) return;
|
|
138
|
+
timer = setTimeout(async () => {
|
|
139
|
+
timer = null;
|
|
140
|
+
if (lock) return;
|
|
141
|
+
if (!sdk.getState()?.isReadyToCapture) return;
|
|
142
|
+
|
|
143
|
+
lock = true;
|
|
144
|
+
try {
|
|
145
|
+
const blob = await sdk.capture();
|
|
146
|
+
// envie o blob pro backend...
|
|
147
|
+
} finally {
|
|
148
|
+
await sdk.stop();
|
|
149
|
+
}
|
|
150
|
+
}, 500); // 300-600ms costuma funcionar bem
|
|
151
|
+
} else {
|
|
152
|
+
if (timer) {
|
|
153
|
+
clearTimeout(timer);
|
|
154
|
+
timer = null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
97
157
|
}
|
|
98
158
|
});
|
|
99
159
|
```
|
package/dist/alphavalid.es.js
CHANGED
|
@@ -18088,7 +18088,11 @@ function y_(e) {
|
|
|
18088
18088
|
function b_(e) {
|
|
18089
18089
|
return y_(e?.strictness ?? .5);
|
|
18090
18090
|
}
|
|
18091
|
-
function x_(e
|
|
18091
|
+
function x_(e) {
|
|
18092
|
+
let t = b_(e), n = e?.lookForwardTolerance;
|
|
18093
|
+
return y_(typeof n == "number" ? n : 1 - t);
|
|
18094
|
+
}
|
|
18095
|
+
function S_(e, t, n) {
|
|
18092
18096
|
if (e.faces === 0) return {
|
|
18093
18097
|
feedback: v_("FACE_NOT_FOUND", "Centralize seu rosto"),
|
|
18094
18098
|
valid: !1,
|
|
@@ -18107,35 +18111,37 @@ function x_(e, t, n) {
|
|
|
18107
18111
|
frameOk: !1,
|
|
18108
18112
|
stepOk: !1
|
|
18109
18113
|
};
|
|
18110
|
-
let r = b_(t), { x:
|
|
18111
|
-
if (
|
|
18114
|
+
let r = b_(t), i = x_(t), { x: a, y: o, width: s, height: c } = e.box, l = a + s / 2, u = o + c / 2, d = e.area ?? s * c, f = s / Math.max(1e-6, c), p = .07 + r * .02, m = .22 - r * .03;
|
|
18115
|
+
if (d < p) return {
|
|
18112
18116
|
feedback: v_("FACE_TOO_FAR", "Aproxime o rosto"),
|
|
18113
18117
|
valid: !1,
|
|
18114
18118
|
frameOk: !1,
|
|
18115
18119
|
stepOk: !1
|
|
18116
18120
|
};
|
|
18117
|
-
if (
|
|
18121
|
+
if (d > m) return {
|
|
18118
18122
|
feedback: v_("FACE_TOO_CLOSE", "Afaste o rosto"),
|
|
18119
18123
|
valid: !1,
|
|
18120
18124
|
frameOk: !1,
|
|
18121
18125
|
stepOk: !1
|
|
18122
18126
|
};
|
|
18123
|
-
let
|
|
18124
|
-
if (Math.abs(
|
|
18127
|
+
let h = .12 - r * .03;
|
|
18128
|
+
if (Math.abs(l - .5) > h || Math.abs(u - .5) > h) return {
|
|
18125
18129
|
feedback: v_("FACE_OFF_CENTER", "Centralize seu rosto"),
|
|
18126
18130
|
valid: !1,
|
|
18127
18131
|
frameOk: !1,
|
|
18128
18132
|
stepOk: !1
|
|
18129
18133
|
};
|
|
18130
|
-
let
|
|
18131
|
-
|
|
18132
|
-
|
|
18134
|
+
let g = t?.requireLookForward !== !1, _ = (t?.challenges?.length ?? 0) > 0, v = g && !_, y = .1 - r * .02, b = typeof t?.lookForwardCenterTol == "number" ? y_(t.lookForwardCenterTol) : y_(y + i * .08), x = t?.minEyeDistance ?? .06, S = (t?.maxEyeSymmetryError ?? .1 - r * .03) + i * .1, C = .74 + r * .1, w = typeof t?.minFrontalRatio == "number" ? Math.max(.5, t.minFrontalRatio) : Math.max(.52, C - i * .18), T = !!e.leftEyeCenter && !!e.rightEyeCenter && typeof e.eyeDist == "number", E = e.eyeDist ?? 0, D = T ? Math.abs(Math.abs(e.leftEyeCenter.x - (e.centerX ?? l)) - Math.abs(e.rightEyeCenter.x - (e.centerX ?? l))) / Math.max(1e-6, E) : null, O = .78 + r * .12;
|
|
18135
|
+
Math.max(.55, O - i * .18);
|
|
18136
|
+
let k = () => {
|
|
18137
|
+
let t = Math.abs((e.centerX ?? l) - .5) > b, n = f >= w, r = !1, i = !1;
|
|
18138
|
+
return T && E >= x && D != null ? r = D > S || !n : (i = !0, r = !n), {
|
|
18133
18139
|
ok: !t && !r,
|
|
18134
18140
|
usedFallback: i
|
|
18135
18141
|
};
|
|
18136
18142
|
};
|
|
18137
|
-
if (
|
|
18138
|
-
let e =
|
|
18143
|
+
if (v) {
|
|
18144
|
+
let e = k();
|
|
18139
18145
|
if (!e.ok) return {
|
|
18140
18146
|
feedback: v_("LOOK_FORWARD", e.usedFallback ? "Olhe para a câmera (aproxime/ilumine para melhor detecção)" : "Olhe para a câmera"),
|
|
18141
18147
|
valid: !1,
|
|
@@ -18143,16 +18149,16 @@ function x_(e, t, n) {
|
|
|
18143
18149
|
stepOk: !1
|
|
18144
18150
|
};
|
|
18145
18151
|
}
|
|
18146
|
-
let
|
|
18147
|
-
if (!
|
|
18152
|
+
let A = n?.current ?? null;
|
|
18153
|
+
if (!A) return {
|
|
18148
18154
|
feedback: v_("READY", "Pronto para capturar"),
|
|
18149
18155
|
valid: !0,
|
|
18150
18156
|
frameOk: !0,
|
|
18151
18157
|
stepOk: !0
|
|
18152
18158
|
};
|
|
18153
|
-
let
|
|
18154
|
-
if (
|
|
18155
|
-
let e =
|
|
18159
|
+
let j = t?.lookSideTol ?? .18 - r * .05, M = t?.lookUpDownTol ?? .12 - r * .03, N = t?.zoomInMinArea ?? .16 + r * .02, P = t?.zoomOutMaxArea ?? .12 - r * .02, F = t?.blinkClosedThreshold ?? .35;
|
|
18160
|
+
if (A === "lookForward") {
|
|
18161
|
+
let e = k();
|
|
18156
18162
|
return {
|
|
18157
18163
|
feedback: v_("LOOK_FORWARD", e.usedFallback ? "Olhe para a câmera (aproxime/ilumine para melhor detecção)" : "Olhe para a câmera"),
|
|
18158
18164
|
valid: e.ok,
|
|
@@ -18160,8 +18166,8 @@ function x_(e, t, n) {
|
|
|
18160
18166
|
stepOk: e.ok
|
|
18161
18167
|
};
|
|
18162
18168
|
}
|
|
18163
|
-
if (
|
|
18164
|
-
let e = (
|
|
18169
|
+
if (A === "lookUp") {
|
|
18170
|
+
let e = (u ?? .5) < .5 - M;
|
|
18165
18171
|
return {
|
|
18166
18172
|
feedback: v_("LOOK_UP", "Olhe para cima"),
|
|
18167
18173
|
valid: e,
|
|
@@ -18169,8 +18175,8 @@ function x_(e, t, n) {
|
|
|
18169
18175
|
stepOk: e
|
|
18170
18176
|
};
|
|
18171
18177
|
}
|
|
18172
|
-
if (
|
|
18173
|
-
let e = (
|
|
18178
|
+
if (A === "lookDown") {
|
|
18179
|
+
let e = (u ?? .5) > .5 + M;
|
|
18174
18180
|
return {
|
|
18175
18181
|
feedback: v_("LOOK_DOWN", "Olhe para baixo"),
|
|
18176
18182
|
valid: e,
|
|
@@ -18178,8 +18184,8 @@ function x_(e, t, n) {
|
|
|
18178
18184
|
stepOk: e
|
|
18179
18185
|
};
|
|
18180
18186
|
}
|
|
18181
|
-
if (
|
|
18182
|
-
let t = (e.centerX ??
|
|
18187
|
+
if (A === "lookLeft") {
|
|
18188
|
+
let t = (e.centerX ?? l) < .5 - j;
|
|
18183
18189
|
return {
|
|
18184
18190
|
feedback: v_("LOOK_LEFT", "Olhe para a esquerda"),
|
|
18185
18191
|
valid: t,
|
|
@@ -18187,8 +18193,8 @@ function x_(e, t, n) {
|
|
|
18187
18193
|
stepOk: t
|
|
18188
18194
|
};
|
|
18189
18195
|
}
|
|
18190
|
-
if (
|
|
18191
|
-
let t = (e.centerX ??
|
|
18196
|
+
if (A === "lookRight") {
|
|
18197
|
+
let t = (e.centerX ?? l) > .5 + j;
|
|
18192
18198
|
return {
|
|
18193
18199
|
feedback: v_("LOOK_RIGHT", "Olhe para a direita"),
|
|
18194
18200
|
valid: t,
|
|
@@ -18196,8 +18202,8 @@ function x_(e, t, n) {
|
|
|
18196
18202
|
stepOk: t
|
|
18197
18203
|
};
|
|
18198
18204
|
}
|
|
18199
|
-
if (
|
|
18200
|
-
let e =
|
|
18205
|
+
if (A === "zoomIn") {
|
|
18206
|
+
let e = d > N;
|
|
18201
18207
|
return {
|
|
18202
18208
|
feedback: v_("ZOOM_IN", "Aproxime (zoom in)"),
|
|
18203
18209
|
valid: e,
|
|
@@ -18205,8 +18211,8 @@ function x_(e, t, n) {
|
|
|
18205
18211
|
stepOk: e
|
|
18206
18212
|
};
|
|
18207
18213
|
}
|
|
18208
|
-
if (
|
|
18209
|
-
let e =
|
|
18214
|
+
if (A === "zoomOut") {
|
|
18215
|
+
let e = d < P;
|
|
18210
18216
|
return {
|
|
18211
18217
|
feedback: v_("ZOOM_OUT", "Afaste (zoom out)"),
|
|
18212
18218
|
valid: e,
|
|
@@ -18214,8 +18220,8 @@ function x_(e, t, n) {
|
|
|
18214
18220
|
stepOk: e
|
|
18215
18221
|
};
|
|
18216
18222
|
}
|
|
18217
|
-
if (
|
|
18218
|
-
let t = e.leftEyeOpenProb, n = e.rightEyeOpenProb, r = typeof t == "number" && typeof n == "number" && t <
|
|
18223
|
+
if (A === "blink") {
|
|
18224
|
+
let t = e.leftEyeOpenProb, n = e.rightEyeOpenProb, r = typeof t == "number" && typeof n == "number" && t < F && n < F;
|
|
18219
18225
|
return {
|
|
18220
18226
|
feedback: v_("BLINK", "Pisque"),
|
|
18221
18227
|
valid: !!r,
|
|
@@ -18232,7 +18238,7 @@ function x_(e, t, n) {
|
|
|
18232
18238
|
}
|
|
18233
18239
|
//#endregion
|
|
18234
18240
|
//#region src/index.ts
|
|
18235
|
-
var
|
|
18241
|
+
var C_ = class {
|
|
18236
18242
|
_camera = null;
|
|
18237
18243
|
_overlay = null;
|
|
18238
18244
|
_container = null;
|
|
@@ -18337,7 +18343,7 @@ var S_ = class {
|
|
|
18337
18343
|
if (!(!t || !n)) try {
|
|
18338
18344
|
let e = this.getCurrentChallenge(), r = e === "blink" || n.liveness?.requireLookForward !== !1, i = await this._faceDetector.detect(t.video, { withLandmarks: r }), a = n.liveness?.challenges, o = !!a && a.length > 0;
|
|
18339
18345
|
o && this._challengeStartedAt == null && (this._challengeStartedAt = Date.now());
|
|
18340
|
-
let s =
|
|
18346
|
+
let s = S_(i, n.liveness, { current: e });
|
|
18341
18347
|
this.markStepCompletedIfNeeded(s.stepOk);
|
|
18342
18348
|
let c = !o || this._challengeIndex >= (a?.length ?? 0), l = s.frameOk && c;
|
|
18343
18349
|
this._lastStatusValid = l, this._status = l ? "ready" : "running";
|
|
@@ -18392,4 +18398,4 @@ var S_ = class {
|
|
|
18392
18398
|
}
|
|
18393
18399
|
};
|
|
18394
18400
|
//#endregion
|
|
18395
|
-
export {
|
|
18401
|
+
export { C_ as AlphaValid };
|
package/dist/alphavalid.umd.js
CHANGED
|
@@ -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 Jf(e,t,n){return!isFinite(e)&&!isFinite(t)||!(isNaN(e)||isNaN(t)||Math.abs(e-t)>n)}Object.freeze({TEST_EPSILON_FLOAT16:Gf,expectArraysClose:function(e,t,n){return n??=Kf(),qf(e,t,(function(e,t){return Jf(e,t,n)}))},testEpsilon:Kf,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 fe(e)||fe(e[0])||fe(t)||fe(t[0])?qf(e,n,(function(e,t){return e==t})):qf(e,t,(function(e,t){return Jf(e,t,0)}))},expectNumbersClose:function(e,t,n){if(n??=Kf(),!Jf(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:vo,webgl_util:sn,forceHalfFloat:function(){m().set(`WEBGL_FORCE_F16_TEXTURES`,!0)},MathBackendWebGL:Fs,setWebGLContext:ut,GPGPUContext:yo});var Yf=function(e){function t(){return e!==null&&e.apply(this,arguments)||this}return l(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 ln(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 ei(e,t)},t.prototype.dispose=function(){this.iterations_!=null&&ln(this.iterations_)},t.prototype.saveIterations=function(){return u(this,void 0,void 0,(function(){return d(this,(function(e){return this.iterations_??=0,[2,{name:`iter`,tensor:G(this.iterations_,`int32`)}]}))}))},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){return d(this,(function(e){throw Error(`getWeights() is not implemented for this optimizer yet.`)}))}))},t.prototype.setWeights=function(e){return u(this,void 0,void 0,(function(){return d(this,(function(e){throw Error(`setWeights() is not implemented for this optimizer class `+this.getClassName())}))}))},t.prototype.extractIterations=function(e){return u(this,void 0,void 0,(function(){var t;return d(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}(Vf);Object.defineProperty(Yf,Symbol.hasInstance,{value:function(e){return e.minimize!=null&&e.computeGradients!=null&&e.applyGradients!=null}});var Xf=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 l(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 Un(i).variable(!1)}))}),t.accumulatedUpdates[r]??(t.accumulatedUpdates[r]={originalName:n+`/accum_var`,variable:H((function(){return Un(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&&(ln(this.accumulatedGrads.map((function(e){return e.variable}))),ln(this.accumulatedUpdates.map((function(e){return e.variable}))))},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){var e;return d(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 u(this,void 0,void 0,(function(){var t;return d(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}(Yf);Uf(Xf);var Zf=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 l(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 zn(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&&ln(this.accumulatedGrads.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){return d(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 u(this,void 0,void 0,(function(){return d(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}(Yf);Uf(Zf);var Qf=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 l(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=il(1,t.accBeta1),i=il(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 Un(o).variable(!1)}))}),t.accumulatedSecondMoment[a]??(t.accumulatedSecondMoment[a]={originalName:n+`/v`,variable:H((function(){return Un(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&&ln(this.accumulatedFirstMoment.map((function(e){return e.variable}))),this.accumulatedSecondMoment!=null&&ln(this.accumulatedSecondMoment.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){var e;return d(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 u(this,void 0,void 0,(function(){var t,n=this;return d(this,(function(r){switch(r.label){case 0:return[4,this.extractIterations(e)];case 1:return e=r.sent(),H((function(){n.accBeta1.assign(tl(n.beta1,n.iterations_+1)),n.accBeta2.assign(tl(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}(Yf);Uf(Qf);var $f=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 l(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=il(1,t.accBeta1),i=Uc(-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:Un(o).variable(!1)}),t.accumulatedWeightedInfNorm[a]??(t.accumulatedWeightedInfNorm[a]={originalName:n+`/v`,variable:Un(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&&ln(this.accumulatedFirstMoment.map((function(e){return e.variable}))),this.accumulatedWeightedInfNorm!=null&&ln(this.accumulatedWeightedInfNorm.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){return d(this,(function(e){throw Error(`getWeights() is not implemented for Adamax yet.`)}))}))},t.prototype.setWeights=function(e){return u(this,void 0,void 0,(function(){return d(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}(Yf);Uf($f);var ep=function(e){function t(t){var n=e.call(this)||this;return n.learningRate=t,n.setLearningRate(t),n}return l(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=un(G(-e))},t.prototype.dispose=function(){this.c.dispose()},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){return d(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()]]}}))}))},t.prototype.setWeights=function(e){return u(this,void 0,void 0,(function(){return d(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}(Yf);Uf(ep);var tp=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 l(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 Un(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&&ln(this.accumulations.map((function(e){return e.variable})))},t.prototype.setMomentum=function(e){this.momentum=e},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){return d(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 u(this,void 0,void 0,(function(){return d(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}(ep);Uf(tp);var np=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 l(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 Un(i).variable(!1)}))}),t.accumulatedMoments[r]??(t.accumulatedMoments[r]={originalName:n+`/momentum`,variable:H((function(){return Un(i).variable(!1)}))}),t.accumulatedMeanGrads[r]==null&&t.centered&&(t.accumulatedMeanGrads[r]={originalName:n+`/mg`,variable:H((function(){return Un(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&&ln(this.accumulatedMeanSquares.map((function(e){return e.variable}))),this.accumulatedMeanGrads!=null&&this.centered&&ln(this.accumulatedMeanGrads.map((function(e){return e.variable}))),this.accumulatedMoments!=null&&ln(this.accumulatedMoments.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){var e;return d(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 u(this,void 0,void 0,(function(){var t;return d(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}(Yf);Uf(np);var rp=function(){function e(){}return e.sgd=function(e){return new ep(e)},e.momentum=function(e,t,n){return n===void 0&&(n=!1),new tp(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 np(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 Qf(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 Xf(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 $f(e,t,n,r,i)},e.adagrad=function(e,t){return t===void 0&&(t=.1),new Zf(e,t)},e}();rp.sgd,rp.momentum,rp.adadelta,rp.adagrad,rp.rmsprop,rp.adamax,rp.adam,Ve.prototype.squaredDifference=function(e){return Rs(this,e)},R=Td;function ip(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 ap=function(e,t){return ap=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])},ap(e,t)};function Z(e,t){ap(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}var op=function(){return op=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},op.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 sp(){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 cp=function(){function e(e,t){if(!bp(e)||!bp(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 lp(e,t){return e instanceof Ve&&e.shape.length===t}function up(e){return lp(e,2)}function dp(e){return lp(e,3)}function fp(e){return lp(e,4)}function pp(e){return e%1!=0}function mp(e){return e%2==0}function hp(e,t){t===void 0&&(t=2);var n=10**t;return Math.floor(e*n)/n}function gp(e){return e&&e.width&&e.height}function _p(e,t){var n=e.width,r=e.height,i=t/Math.max(r,n);return new cp(Math.round(n*i),Math.round(r*i))}function vp(e){return e.reduce(function(e,t){return e.add(t)},new Sp(0,0)).div(new Sp(e.length,e.length))}function yp(e,t,n){return Array(e).fill(0).map(function(e,r){return t+r*n})}function bp(e){return!!e&&e!==1/0&&e!==-1/0&&!isNaN(e)||e===0}function xp(e){return bp(e)&&0<=e&&e<=1}var Sp=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}(),Cp=function(){function e(t,n){n===void 0&&(n=!0);var r=t||{},i=[r.left,r.top,r.right,r.bottom].every(bp),a=[r.x,r.y,r.width,r.height].every(bp);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(bp)},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 Sp(this.left,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`topRight`,{get:function(){return new Sp(this.right,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottomLeft`,{get:function(){return new Sp(this.left,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottomRight`,{get:function(){return new Sp(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=gp(t)?t.width:t,r=gp(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}(),wp=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}(Cp),Tp=function(){function e(e,t,n,r,i){this._imageDims=new cp(i.width,i.height),this._score=e,this._classScore=t,this._className=n,this._box=new Cp(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 Cp(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}(),Ep=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}(Tp);function Dp(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 Op(e){var t=e.map(function(e){return e.x}),n=e.map(function(e){return e.y});return new wp(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 kp(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(Dp(u,d,r))}i=i.filter(function(e,t){return s[t]<=n})};i.length>0;)o();return a}function Ap(e,t){return H(function(){var n=t[0],r=t[1],i=t[2];return il(e,Wn([zn(sp(e.shape.slice(0,3),[1]),n),zn(sp(e.shape.slice(0,3),[1]),r),zn(sp(e.shape.slice(0,3),[1]),i)],3))})}function jp(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,zn(n,0)},l=c(o),u=a-l.shape[s];return Wn([t&&u?c(u):null,e,l].filter(function(e){return!!e}).map(function(e){return e.toFloat()}),s)})}function Mp(e){return 1/(1+Math.exp(-e))}var Np=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}(Cp),Pp=.5,Fp=.43,Ip=.45,Lp=function(){function e(e,t,n){n===void 0&&(n=new Sp(0,0));var r=t.width,i=t.height;this._imgDims=new cp(r,i),this._shift=n,this._positions=e.map(function(e){return e.mul(new Sp(r,i)).add(n)})}return Object.defineProperty(e.prototype,`shift`,{get:function(){return new Sp(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 Sp(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 Sp(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 Ep?e.box.floor():new Cp(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/Ip),s=vp(e),c=Math.floor(Math.max(0,s.x-Pp*o)),l=Math.floor(Math.max(0,s.y-Fp*o));return new Np(c,l,Math.min(o,this.imageWidth+c),Math.min(o,this.imageHeight+l))},e.prototype.alignMinBbox=function(e){var t=Op(this.positions);return t.pad(t.width*e,t.height*e)},e.prototype.getRefPointsForAlignment=function(){throw Error(`getRefPointsForAlignment not implemented by base class`)},e}(),Rp=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],vp([e[3],e[4]])]},t}(Lp),zp=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(vp)},t}(Lp),Bp=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?` (`+hp(this.distance)+`)`:``)},e}(),Vp=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(Cp.assertIsValidBox(e,t),!bp(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}(Cp),Hp=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(Vp.assertIsValidLabeledBox(e,t),!xp(e.score)||!xp(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})(Vp);function Up(e){return e.detection instanceof Ep}function Wp(e,t){return Object.assign({},e,{detection:t})}function Gp(){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 Kp(e){var t=``;if(!e)try{e=s()}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 qp(){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=Kp();return op({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 Jp(){return typeof window==`object`&&typeof document<`u`&&typeof HTMLImageElement<`u`&&typeof HTMLCanvasElement<`u`&&typeof HTMLVideoElement<`u`&&typeof ImageData<`u`&&typeof CanvasRenderingContext2D<`u`}function Yp(){return typeof global==`object`&&typeof require==`function`&&typeof module<`u`&&typeof process<`u`&&!!process.version}var Xp;function Zp(){if(!Xp)throw Error(`getEnv - environment is not defined, check isNodejs() and isBrowser()`);return Xp}function Qp(e){Xp=e}function $p(){Jp()&&Qp(Gp()),Yp()&&Qp(qp())}function em(e){if(Xp||$p(),!Xp)throw Error(`monkeyPatch - environment is not defined, check isNodejs() and isBrowser()`);var t=e.Canvas,n=t===void 0?Xp.Canvas:t,r=e.Image,i=r===void 0?Xp.Image:r;Xp.Canvas=n,Xp.Image=i,Xp.createCanvasElement=e.createCanvasElement||(function(){return new n}),Xp.createImageElement=e.createImageElement||(function(){return new i}),Xp.ImageData=e.ImageData||Xp.ImageData,Xp.Video=e.Video||Xp.Video,Xp.fetch=e.fetch||Xp.fetch,Xp.readFile=e.readFile||Xp.readFile}var tm={getEnv:Zp,setEnv:Qp,initialize:$p,createBrowserEnv:Gp,createFileSystem:Kp,createNodejsEnv:qp,monkeyPatch:em,isBrowser:Jp,isNodejs:Yp};$p();function nm(e){return!tm.isNodejs()&&typeof e==`string`?document.getElementById(e):e}function rm(e){var t=tm.getEnv(),n=t.Canvas;if(e instanceof t.CanvasRenderingContext2D)return e;var r=nm(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 im;(function(e){e.TOP_LEFT=`TOP_LEFT`,e.TOP_RIGHT=`TOP_RIGHT`,e.BOTTOM_LEFT=`BOTTOM_LEFT`,e.BOTTOM_RIGHT=`BOTTOM_RIGHT`})(im||={});var am=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||im.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}(),om=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 am(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===im.BOTTOM_RIGHT||n===im.TOP_RIGHT,i=n===im.BOTTOM_LEFT||n===im.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=nm(e),n=rm(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}(),sm=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:im.BOTTOM_LEFT,backgroundColor:this.boxColor};this.drawLabelOptions=new am(Object.assign({},a,i))}return e}();(function(){function e(e,t){t===void 0&&(t={}),this.box=new Cp(e),this.options=new sm(t)}return e.prototype.draw=function(e){var t=rm(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 om([u],{x:o-i/2,y:s},this.options.drawLabelOptions).draw(e)},e})();function cm(e){var t=tm.getEnv(),n=t.Image,r=t.Video;return e instanceof n&&e.complete||e instanceof r&&e.readyState>=3}function lm(e){return new Promise(function(t,n){if(e instanceof tm.getEnv().Canvas||cm(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 um(e){var t=tm.getEnv(),n=t.Image,r=t.Video;return e instanceof n?new cp(e.naturalWidth,e.naturalHeight):e instanceof r?new cp(e.videoWidth,e.videoHeight):new cp(e.width,e.height)}function dm(e){var t=e.width,n=e.height,r=tm.getEnv().createCanvasElement,i=r();return i.width=t,i.height=n,i}function fm(e,t){var n=tm.getEnv().ImageData;if(!(e instanceof n)&&!cm(e))throw Error(`createCanvasFromMedia - media has not finished loading yet`);var r=t||um(e),i=r.width,a=r.height,o=dm({width:i,height:a});return e instanceof n?rm(o).putImageData(e,0,0):rm(o).drawImage(e,0,0,i,a),o}function pm(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||tm.getEnv().createCanvasElement(),r=e.shape.slice(fp(e)?1:0),i=r[0],a=r[1],o=r[2],s=H(function(){return e.as3D(i,a,o).toInt()}),[4,Bf.toPixels(s,n)];case 1:return c.sent(),s.dispose(),[2,n]}})})}function mm(e){var t=tm.getEnv(),n=t.Image,r=t.Canvas,i=t.Video;return e instanceof n||e instanceof r||e instanceof i}function hm(e,t,n){n===void 0&&(n=!1);var r=tm.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=um(e),s=t/Math.max(o.height,o.width),c=s*o.width,l=s*o.height,u=dm({width:t,height:t}),d=e instanceof a?e:fm(e),f=Math.abs(c-l)/2,p=n&&c<l?f:0,m=n&&l<c?f:0;return rm(u).drawImage(d,p,m,c,l),u}var gm=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(dp(e)){n._imageTensors[t]=e,n._inputDimensions[t]=e.shape;return}if(fp(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 tm.getEnv().Canvas?e:fm(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 yp(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 _p({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 jr(yp(n.batchSize,0,1).map(function(r){var i=n.getInput(r);if(i instanceof Ve){var a=fp(i)?i:i.expandDims();return a=jp(a,t),(a.shape[1]!==e||a.shape[2]!==e)&&(a=gd.resizeBilinear(a,[e,e])),a.as3D(e,e,3)}if(i instanceof tm.getEnv().Canvas)return Bf.fromPixels(hm(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 _m(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 gm)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(nm),r.forEach(function(e,r){if(!mm(e)&&!dp(e)&&!fp(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(fp(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 mm(e)&&lm(e)}))];case 1:return i.sent(),[2,new gm(r,Array.isArray(e))]}})})}function vm(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=tm.getEnv().Canvas,r=e,e instanceof n?[3,5]:[4,_m(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,pm(a)];case 3:o=l.sent(),l.label=4;case 4:r=o,l.label=5;case 5:return s=rm(r),c=t.map(function(e){return e instanceof Ep?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=dm({width:r,height:i});return rm(a).putImageData(s.getImageData(t,n,r,i),0,0),a})]}})})}function ym(e,t){return Q(this,void 0,void 0,function(){return $(this,function(n){if(!dp(e)&&!fp(e))throw Error(`extractFaceTensors - expected image tensor to be 3D or 4D`);if(fp(e)&&e.shape[0]>1)throw Error(`extractFaceTensors - batchSize > 1 not supported`);return[2,H(function(){var n=e.shape.slice(fp(e)?1:0),r=n[0],i=n[1],a=n[2];return t.map(function(e){return e instanceof Ep?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 tu(e.as3D(r,i,a),[o,n,0],[c,s,a])})})]})})}function bm(e,t){return Q(this,void 0,void 0,function(){var n,r;return $(this,function(i){switch(i.label){case 0:return n=tm.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 xm(e){return Q(this,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,bm(e)];case 1:return[2,t.sent().json()]}})})}function Sm(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 Cm(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=Sm(e,t),r=n.manifestUri,i=n.modelBaseUri,[4,xm(r)];case 1:return a=o.sent(),[2,If.loadWeights(a,i)]}})})}var wm=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 qe})},e.prototype.getFrozenParams=function(){return this.getParamList().filter(function(e){return!(e.tensor instanceof qe)})},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=On(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,Cm(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=tm.getEnv().readFile,n=Sm(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=If.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 Ve))throw Error(`traversePropertyPath - parameter is not a tensor, for path `+e);return{obj:n,objProp:r}},e}();function Tm(e,t,n){return H(function(){var r=Pl(e,t.depthwise_filter,t.pointwise_filter,n,`same`);return r=zc(r,t.bias),r})}function Em(e,t,n){return n===void 0&&(n=!1),H(function(){var r=vu(n?zc(Dl(e,t.conv0.filters,[2,2],`same`),t.conv0.bias):Tm(e,t.conv0,[2,2])),i=Tm(r,t.conv1,[1,1]);return vu(zc(r,zc(i,Tm(vu(zc(r,i)),t.conv2,[1,1]))))})}function Dm(e,t,n,r){return n===void 0&&(n=!1),r===void 0&&(r=!0),H(function(){var i=vu(n?zc(Dl(e,t.conv0.filters,r?[2,2]:[1,1],`same`),t.conv0.bias):Tm(e,t.conv0,r?[2,2]:[1,1])),a=Tm(i,t.conv1,[1,1]),o=Tm(vu(zc(i,a)),t.conv2,[1,1]);return vu(zc(i,zc(a,zc(o,Tm(vu(zc(i,zc(a,o))),t.conv3,[1,1])))))})}function Om(e,t,n,r){return n===void 0&&(n=`same`),r===void 0&&(r=!1),H(function(){var i=zc(Dl(e,t.filters,[1,1],n),t.bias);return r?vu(i):i})}function km(e,t){Object.keys(e).forEach(function(n){t.some(function(e){return e.originalPath===n})||e[n].dispose()})}function Am(e,t){return function(n,r,i,a){var o=Nn(e(n*r*i*i),[i,i,n,r]),s=An(e(r));return t.push({paramPath:a+`/filters`},{paramPath:a+`/bias`}),{filters:o,bias:s}}}function jm(e,t){return function(n,r,i){var a=jn(e(n*r),[n,r]),o=An(e(r));return t.push({paramPath:i+`/weights`},{paramPath:i+`/bias`}),{weights:a,bias:o}}}var Mm=function(){function e(e,t,n){this.depthwise_filter=e,this.pointwise_filter=t,this.bias=n}return e}();function Nm(e,t){return function(n,r,i){var a=Nn(e(9*n),[3,3,n,1]),o=Nn(e(n*r),[1,1,n,r]),s=An(e(r));return t.push({paramPath:i+`/depthwise_filter`},{paramPath:i+`/pointwise_filter`},{paramPath:i+`/bias`}),new Mm(a,o,s)}}function Pm(e){return function(t){return new Mm(e(t+`/depthwise_filter`,4),e(t+`/pointwise_filter`,4),e(t+`/bias`,1))}}function Fm(e,t){return function(n,r,i){var a=e[n];if(!lp(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 Im(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 Lm(e,t){var n=Am(e,t),r=Nm(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 Rm(e){var t=[],n=Im(e),r=n.extractWeights,i=n.getRemainingWeights,a=Lm(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 zm(e){return function(t){return{filters:e(t+`/filters`,4),bias:e(t+`/bias`,1)}}}function Bm(e,t){var n=Fm(e,t),r=zm(n),i=Pm(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 Vm(e){var t=[],n=Bm(e,t).extractDenseBlock4Params,r={dense0:n(`dense0`,!0),dense1:n(`dense1`),dense2:n(`dense2`),dense3:n(`dense3`)};return km(e,t),{params:r,paramMappings:t}}var Hm=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=Dm(Ap(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(G(255)),t.dense0,!0);return n=Dm(n,t.dense1),n=Dm(n,t.dense2),n=Dm(n,t.dense3),n=Jl(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,_m(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 Vm(e)},t.prototype.extractParams=function(e){return Rm(e)},t}(wm);function Um(e,t){return H(function(){return zc(Ll(e,t.weights),t.bias)})}function Wm(e,t,n){var r=[],i=Im(e),a=i.extractWeights,o=i.getRemainingWeights,s=jm(a,r)(t,n,`fc`);if(o().length!==0)throw Error(`weights remaing after extract: `+o().length);return{paramMappings:r,params:{fc:s}}}function Gm(e){var t=[],n=Fm(e,t);function r(e){return{weights:n(e+`/weights`,2),bias:n(e+`/bias`,1)}}var i={fc:r(`fc`)};return km(e,t),{params:i,paramMappings:t}}function Km(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 qm=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 gm?t.faceFeatureExtractor.forwardInput(e):e;return Um(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 Wm(e,this.getClassifierChannelsIn(),this.getClassifierChannelsOut())},t.prototype.extractParamsFromWeigthMap=function(e){var t=Km(e),n=t.featureExtractorMap,r=t.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(n),Gm(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}(wm),Jm=[`neutral`,`happy`,`sad`,`angry`,`fearful`,`disgusted`,`surprised`],Ym=function(){function e(e){var t=this;if(e.length!==7)throw Error(`FaceExpressions.constructor - expected probabilities.length to be 7, have: `+e.length);Jm.forEach(function(n,r){t[n]=e[r]})}return e.prototype.asSortedArray=function(){var e=this;return Jm.map(function(t){return{expression:t,probability:e[t]}}).sort(function(e,t){return t.probability-e.probability})},e}(),Xm=function(e){Z(t,e);function t(t){return t===void 0&&(t=new Hm),e.call(this,`FaceExpressionNet`,t)||this}return t.prototype.forwardInput=function(e){var t=this;return H(function(){return ni(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,_m(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,_m(e)];case 1:return t=o.sent(),[4,this.forwardInput(t)];case 2:return n=o.sent(),[4,Promise.all(Pr(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 Ym(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}(qm);function Zm(e,t){return Object.assign({},e,{expressions:t})}function Qm(e){return Up(e)&&e.landmarks instanceof Lp&&e.unshiftedLandmarks instanceof Lp&&e.alignedRect instanceof Ep}function $m(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 Ep(e.detection.score,i.rescale(a.reverse()),a)};return Object.assign({},e,o)}var eh=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 eh(t)}return e.prototype.draw=function(e){var t=rm(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 zp&&(t.strokeStyle=o,t.lineWidth=a,ip(t,this.faceLandmarks.getJawOutline()),ip(t,this.faceLandmarks.getLeftEyeBrow()),ip(t,this.faceLandmarks.getRightEyeBrow()),ip(t,this.faceLandmarks.getNose()),ip(t,this.faceLandmarks.getLeftEye(),!0),ip(t,this.faceLandmarks.getRightEye(),!0),ip(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 th(e,t){var n=Am(e,t),r=Nm(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 nh(e,t){var n=[],r=Im(e),i=r.extractWeights,a=r.getRemainingWeights,o=th(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={};yp(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 rh(e,t){var n=Fm(e,t),r=zm(n),i=Pm(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 ih(e,t){var n=[],r=rh(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={};yp(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 km(e,n),{params:{entry_flow:c,middle_flow:l,exit_flow:u},paramMappings:n}}function ah(e,t,n){return zc(Dl(e,t.filters,n,`same`),t.bias)}function oh(e,t,n){n===void 0&&(n=!0);var r=n?vu(e):e;return r=Tm(r,t.separable_conv0,[1,1]),r=Tm(vu(r),t.separable_conv1,[1,1]),r=ql(r,[3,3],[2,2],`same`),r=zc(r,ah(e,t.expansion_conv,[2,2])),r}function sh(e,t){var n=Tm(vu(e),t.separable_conv0,[1,1]);return n=Tm(vu(n),t.separable_conv1,[1,1]),n=Tm(vu(n),t.separable_conv2,[1,1]),n=zc(n,e),n}var ch=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=vu(ah(Ap(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(G(256)),n.entry_flow.conv_in,[2,2]));return r=oh(r,n.entry_flow.reduction_block_0,!1),r=oh(r,n.entry_flow.reduction_block_1),yp(t._numMainBlocks,0,1).forEach(function(e){r=sh(r,n.middle_flow[`main_block_`+e])}),r=oh(r,n.exit_flow.reduction_block),r=vu(Tm(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,_m(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.getDefaultModelName=function(){return`tiny_xception_model`},t.prototype.extractParamsFromWeigthMap=function(e){return ih(e,this._numMainBlocks)},t.prototype.extractParams=function(e){return nh(e,this._numMainBlocks)},t}(wm);function lh(e){var t=[],n=Im(e),r=n.extractWeights,i=n.getRemainingWeights,a=jm(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 uh(e){var t=[],n=Fm(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 km(e,t),{params:i,paramMappings:t}}var dh;(function(e){e.FEMALE=`female`,e.MALE=`male`})(dh||={});var fh=function(e){Z(t,e);function t(t){t===void 0&&(t=new ch(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 gm?t.faceFeatureExtractor.forwardInput(e):e,i=Jl(r,[7,7],[2,2],`valid`).as2D(r.shape[0],-1);return{age:Um(i,n.fc.age).as1D(),gender:Um(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:ni(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,_m(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,_m(e)];case 1:return t=c.sent(),[4,this.forwardInput(t)];case 2:return n=c.sent(),r=Pr(n.age),i=Pr(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?dh.MALE:dh.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 lh(e)},t.prototype.extractParamsFromWeigthMap=function(e){var t=Km(e),n=t.featureExtractorMap,r=t.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(n),uh(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}(wm),ph=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 jr([zn([68],e),zn([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(zn([i,136],t)).sub(jr(Array.from(Array(i),function(e,t){return n(o(t),s(t))}))).div(jr(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,_m(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,_m(e)];case 1:return t=a.sent(),n=H(function(){return Pr(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 mp(t)}),s=r.filter(function(e,t){return!mp(t)}),[2,new zp(Array(68).fill(0).map(function(e,t){return new Sp(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}(qm),mh=function(e){Z(t,e);function t(t){return t===void 0&&(t=new Hm),e.call(this,`FaceLandmark68Net`,t)||this}return t.prototype.getDefaultModelName=function(){return`face_landmark_68_model`},t.prototype.getClassifierChannelsIn=function(){return 256},t}(ph);function hh(e){var t=[],n=Bm(e,t).extractDenseBlock3Params,r={dense0:n(`dense0`,!0),dense1:n(`dense1`),dense2:n(`dense2`)};return km(e,t),{params:r,paramMappings:t}}function gh(e){var t=[],n=Im(e),r=n.extractWeights,i=n.getRemainingWeights,a=Lm(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 _h=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=Em(Ap(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=Jl(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,_m(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 hh(e)},t.prototype.extractParams=function(e){return gh(e)},t}(wm),vh=function(e){Z(t,e);function t(t){return t===void 0&&(t=new _h),e.call(this,`FaceLandmark68TinyNet`,t)||this}return t.prototype.getDefaultModelName=function(){return`face_landmark_68_tiny_model`},t.prototype.getClassifierChannelsIn=function(){return 128},t}(ph);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t})(mh);function yh(e,t){return zc($c(e,t.weights),t.biases)}function bh(e,t,n,r,i){i===void 0&&(i=`same`);var a=t.conv,o=a.filters,s=a.bias,c=Dl(e,o,n,i);return c=zc(c,s),c=yh(c,t.scale),r?vu(c):c}function xh(e,t){return bh(e,t,[1,1],!0)}function Sh(e,t){return bh(e,t,[1,1],!1)}function Ch(e,t){return bh(e,t,[2,2],!0,`valid`)}function wh(e,t){function n(t,n,r){var i=e(t),a=i.length/(n*r*r);if(pp(a))throw Error(`depth has to be an integer: `+a+`, weights.length: `+i.length+`, numFilters: `+n+`, filterSize: `+r);return H(function(){return xu(Nn(i,[n,a,r,r]),[2,3,1,0])})}function r(r,i,a,o){var s=n(r,i,a),c=An(e(i));return t.push({paramPath:o+`/filters`},{paramPath:o+`/bias`}),{filters:s,bias:c}}function i(n,r){var i=An(e(n)),a=An(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 Th(e){var t=Im(e),n=t.extractWeights,r=t.getRemainingWeights,i=[],a=wh(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 xu(jn(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 Eh(e,t){var n=Fm(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 Dh(e){var t=[],n=Eh(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`}),!up(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 km(e,t),{params:x,paramMappings:t}}function Oh(e,t){var n=xh(e,t.conv1);return n=Sh(n,t.conv2),n=zc(n,e),n=vu(n),n}function kh(e,t){var n=Ch(e,t.conv1);n=Sh(n,t.conv2);var r=Jl(e,2,2,`valid`),i=Rn(r.shape),a=r.shape[3]!==n.shape[3];if(r.shape[1]!==n.shape[1]||r.shape[2]!==n.shape[2]){var o=sp(n.shape);o[1]=1;var s=Rn(o);n=Wn([n,s],1);var c=sp(n.shape);c[2]=1;var l=Rn(c);n=Wn([n,l],2)}return r=a?Wn([r,i],3):r,n=zc(r,n),n=vu(n),n}var Ah=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=Ch(Ap(e.toBatchTensor(150,!0).toFloat(),[122.782,117.001,104.298]).div(G(256)),t.conv32_down);return n=ql(n,3,2,`valid`),n=Oh(n,t.conv32_1),n=Oh(n,t.conv32_2),n=Oh(n,t.conv32_3),n=kh(n,t.conv64_down),n=Oh(n,t.conv64_1),n=Oh(n,t.conv64_2),n=Oh(n,t.conv64_3),n=kh(n,t.conv128_down),n=Oh(n,t.conv128_1),n=Oh(n,t.conv128_2),n=kh(n,t.conv256_down),n=Oh(n,t.conv256_1),n=Oh(n,t.conv256_2),n=kh(n,t.conv256_down_out),Ll(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,_m(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,_m(e)];case 1:return t=a.sent(),n=H(function(){return Pr(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 Dh(e)},t.prototype.extractParams=function(e){return Th(e)},t}(wm);function jh(e,t){return Object.assign({},e,{descriptor:t})}function Mh(e,t){return Object.assign({},e,{age:t})}function Nh(e,t,n){return Object.assign({},e,{gender:t,genderProbability:n})}var Ph=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 Fh(e,t){function n(n,r){var i=Nn(e(9*n),[3,3,n,1]),a=An(e(n)),o=An(e(n)),s=An(e(n)),c=An(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=Nn(e(n*r*i*i),[i,i,n,r]),c=An(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 Ih(e){var t=[],n=Im(e),r=n.extractWeights,i=n.getRemainingWeights,a=Fh(r,t),o=a.extractMobilenetV1Params,s=a.extractPredictionLayerParams,c=o(),l=s(),u={extra_dim:Mn(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 Lh(e,t){var n=Fm(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 Rh(e){var t=[],n=Lh(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`}),!dp(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 km(e,t),{params:o,paramMappings:t}}function zh(e,t,n){return H(function(){var r=Dl(e,t.filters,n,`same`);return r=zc(r,t.batch_norm_offset),qs(r,0,6)})}var Bh=.0010000000474974513;function Vh(e,t,n){return H(function(){var r=jl(e,t.filters,n,`same`);return r=kc(r,t.batch_norm_mean,t.batch_norm_variance,t.batch_norm_offset,t.batch_norm_scale,Bh),qs(r,0,6)})}function Hh(e){return[2,4,6,12].some(function(t){return t===e})?[2,2]:[1,1]}function Uh(e,t){return H(function(){var n=null,r=zh(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=Hh(i);r=Vh(r,e.depthwise_conv,a),r=zh(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 Wh(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=Gh(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 Gh(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 Kh(e){var t=Pr(xu(e,[1,0])),n=[il(t[2],t[0]),il(t[3],t[1])];return{sizes:n,centers:[zc(t[0],Uc(n[0],G(2))),zc(t[1],Uc(n[1],G(2)))]}}function qh(e,t){var n=Kh(e),r=n.sizes,i=n.centers,a=Pr(xu(t,[1,0])),o=Uc($c(Zs(Uc(a[2],G(5))),r[0]),G(2)),s=zc($c(Uc(a[0],G(10)),r[0]),i[0]),c=Uc($c(Zs(Uc(a[3],G(5))),r[1]),G(2)),l=zc($c(Uc(a[1],G(10)),r[1]),i[1]);return xu(jr([il(s,o),il(l,c),zc(s,o),zc(l,c)]),[1,0])}function Jh(e,t,n){return H(function(){var r=e.shape[0],i=qh(Or(Mr(n.extra_dim,[r,1,1]),[-1,4]),Or(e,[-1,4]));i=Or(i,[r,i.shape[0]/r,4]);var a=Ql(sc(Ql(t,[0,0,1],[-1,-1,-1])),[0,0,0],[-1,-1,1]);return a=Or(a,[r,a.shape[1]]),{boxes:Pr(i),scores:Pr(a)}})}function Yh(e,t){return H(function(){var n=e.shape[0];return{boxPredictionEncoding:Or(Om(e,t.box_encoding_predictor),[n,-1,1,4]),classPrediction:Or(Om(e,t.class_predictor),[n,-1,3])}})}function Xh(e,t,n){return H(function(){var r=zh(zh(e,n.conv_0,[1,1]),n.conv_1,[2,2]),i=zh(zh(r,n.conv_2,[1,1]),n.conv_3,[2,2]),a=zh(zh(i,n.conv_4,[1,1]),n.conv_5,[2,2]),o=zh(zh(a,n.conv_6,[1,1]),n.conv_7,[2,2]),s=Yh(t,n.box_predictor_0),c=Yh(e,n.box_predictor_1),l=Yh(r,n.box_predictor_2),u=Yh(i,n.box_predictor_3),d=Yh(a,n.box_predictor_4),f=Yh(o,n.box_predictor_5);return{boxPredictions:Wn([s.boxPredictionEncoding,c.boxPredictionEncoding,l.boxPredictionEncoding,u.boxPredictionEncoding,d.boxPredictionEncoding,f.boxPredictionEncoding],1),classPredictions:Wn([s.classPrediction,c.classPrediction,l.classPrediction,u.classPrediction,d.classPrediction,f.classPrediction],1)}})}var Zh=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}(),Qh=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=Uh(il($c(e.toBatchTensor(512,!1).toFloat(),G(.007843137718737125)),G(1)),t.mobilenetv1),r=Xh(n.out,n.conv11,t.prediction_layer),i=r.boxPredictions,a=r.classPredictions;return Jh(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,_m(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 Zh(t),r=n.maxResults,i=n.minConfidence,[4,_m(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=Wh(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 Ep(f[e],new Np(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 Rh(e)},t.prototype.extractParams=function(e){return Ih(e)},t}(wm);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t})(Qh);var $h=.4,eg=[new Sp(.738768,.874946),new Sp(2.42204,2.65704),new Sp(4.30971,7.04493),new Sp(10.246,4.59428),new Sp(12.6868,11.8741)],tg=[new Sp(1.603231,2.094468),new Sp(6.041143,7.080126),new Sp(2.882459,3.518061),new Sp(4.266906,5.178857),new Sp(9.041765,10.66308)],ng=[117.001,114.697,97.404],rg=`tiny_yolov2_model`,ig=`tiny_yolov2_separable_conv_model`,ag=function(e){return typeof e==`number`};function og(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(!ag(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 ag(e.x)&&ag(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(ag)))throw Error(`config.meanRgb has to be an array of shape [number, number, number], have: `+JSON.stringify(e.meanRgb))}function sg(e){return H(function(){var t=$c(e,G(.10000000149011612));return zc(vu(il(e,t)),t)})}function cg(e,t){return H(function(){var n=yr(e,[[0,0],[1,1],[1,1],[0,0]]);return n=Dl(n,t.conv.filters,[1,1],`valid`),n=il(n,t.bn.sub),n=$c(n,t.bn.truediv),n=zc(n,t.conv.bias),sg(n)})}function lg(e,t){return H(function(){var n=yr(e,[[0,0],[1,1],[1,1],[0,0]]);return n=Pl(n,t.depthwise_filter,t.pointwise_filter,[1,1],`valid`),n=zc(n,t.bias),sg(n)})}function ug(e,t){var n=Am(e,t);function r(n,r){var i=An(e(n)),a=An(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:Nm(e,t)}}function dg(e,t,n,r){var i=Im(e),a=i.extractWeights,o=i.getRemainingWeights,s=[],c=ug(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 fg(e,t){var n=Fm(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:Pm(n)}}function pg(e,t){var n=[],r=fg(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 km(e,n),{params:s,paramMappings:n}}var mg;(function(e){e[e.XS=224]=`XS`,e[e.SM=320]=`SM`,e[e.MD=416]=`MD`,e[e.LG=608]=`LG`})(mg||={});var hg=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}(),gg=function(e){Z(t,e);function t(t){var n=e.call(this,`TinyYolov2`)||this;return og(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=cg(e,t.conv0);return n=ql(n,[2,2],[2,2],`same`),n=cg(n,t.conv1),n=ql(n,[2,2],[2,2],`same`),n=cg(n,t.conv2),n=ql(n,[2,2],[2,2],`same`),n=cg(n,t.conv3),n=ql(n,[2,2],[2,2],`same`),n=cg(n,t.conv4),n=ql(n,[2,2],[2,2],`same`),n=cg(n,t.conv5),n=ql(n,[2,2],[1,1],`same`),n=cg(n,t.conv6),n=cg(n,t.conv7),Om(n,t.conv8,`valid`,!1)},t.prototype.runMobilenet=function(e,t){var n=this.config.isFirstLayerConv2d?sg(Om(e,t.conv0,`valid`,!1)):lg(e,t.conv0);return n=ql(n,[2,2],[2,2],`same`),n=lg(n,t.conv1),n=ql(n,[2,2],[2,2],`same`),n=lg(n,t.conv2),n=ql(n,[2,2],[2,2],`same`),n=lg(n,t.conv3),n=ql(n,[2,2],[2,2],`same`),n=lg(n,t.conv4),n=ql(n,[2,2],[2,2],`same`),n=lg(n,t.conv5),n=ql(n,[2,2],[1,1],`same`),n=t.conv6?lg(n,t.conv6):n,n=t.conv7?lg(n,t.conv7):n,Om(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?Ap(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,_m(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 hg(t),r=n.inputSize,i=n.scoreThreshold,[4,_m(e)];case 1:return a=_.sent(),[4,this.forwardInput(a,r)];case 2:return o=_.sent(),s=H(function(){return Pr(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=kp(u.map(function(e){return e.rescale(r)}),d,this.config.iouThreshold,!0),h=m.map(function(e){return new Tp(d[e],f[e],p[e],u[e],c)}),[2,h]}})})},t.prototype.getDefaultModelName=function(){return``},t.prototype.extractParamsFromWeigthMap=function(e){return pg(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 dg(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?ni(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=Mp(h[_][v][y][0]),!n||b>n?(x=(v+Mp(g[_][v][y][0]))/c*o,S=(_+Mp(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(op({box:new wp(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}(wm),_g=function(e){Z(t,e);function t(t){t===void 0&&(t=!0);var n=this,r=Object.assign({},{withSeparableConvs:t,iouThreshold:$h,classes:[`face`]},t?{anchors:tg,meanRgb:ng}:{anchors:eg,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 Ep(e.score,e.relativeBox,{width:e.imageWidth,height:e.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return this.withSeparableConvs?ig:rg},t.prototype.extractParamsFromWeigthMap=function(t){return e.prototype.extractParamsFromWeigthMap.call(this,t)},t}(gg),vg=function(e){Z(t,e);function t(){var t=e!==null&&e.apply(this,arguments)||this;return t._name=`TinyFaceDetectorOptions`,t}return t}(hg),yg=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 bg(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 Qm(e)?i(e):e.detection}),s=r,s?[3,5]:t instanceof Ve?[4,ym(t,a)]:[3,2];case 1:return c=u.sent(),[3,4];case 2:return[4,vm(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 Ve&&e.dispose()}),[2,l]}})})}function xg(e,t,n,r,i){return Q(this,void 0,void 0,function(){var a=this;return $(this,function(o){return[2,bg([e],t,function(e){return Q(a,void 0,void 0,function(){return $(this,function(t){return[2,n(e[0])]})})},r,i)]})})}function Sg(e){return H(function(){return jr(Pr(e,3).reverse(),3)})}function Cg(e,t){var n=Am(e,t),r=jm(e,t);function i(n,r){var i=An(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 op(op({},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 op(op({},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 op(op({},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 wg(e){var t=Im(e),n=t.extractWeights,r=t.getRemainingWeights,i=[],a=Cg(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 Tg(e,t){var n=Fm(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 op(op({},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 op(op({},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 op(op({},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 Eg(e){var t=[],n=Tg(e,t),r=n.extractPNetParams,i=n.extractRNetParams,a=n.extractONetParams,o=r(),s=i(),c=a();return km(e,t),{params:{pnet:o,rnet:s,onet:c},paramMappings:t}}function Dg(e,t){var n=t[0],r=t[1];return{height:Math.floor(n*e),width:Math.floor(r*e)}}function Og(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 kg=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}(Cp);function Ag(e){return H(function(){return $c(il(e,G(127.5)),G(.0078125))})}function jg(e,t){return H(function(){return zc(vu(e),$c(t,rc(vu(rc(e)))))})}function Mg(e,t,n){return n===void 0&&(n=!1),H(function(){var r=Om(e,t.conv1,`valid`);return r=jg(r,t.prelu1_alpha),r=ql(r,n?[2,2]:[3,3],[2,2],`same`),r=Om(r,t.conv2,`valid`),r=jg(r,t.prelu2_alpha),r=n?r:ql(r,[3,3],[2,2],`valid`),r=Om(r,t.conv3,`valid`),r=jg(r,t.prelu3_alpha),r})}function Ng(e,t){return H(function(){var n=Mg(e,t,!0),r=Om(n,t.conv4_1,`valid`);return{prob:ni(il(r,hr(lu(r,3),3)),3),regions:Om(n,t.conv4_2,`valid`)}})}function Pg(e,t){return H(function(){var n=Dg(t,e.shape.slice(1)),r=n.height,i=n.width;return xu(Ag(gd.resizeBilinear(e,[r,i])),[0,2,1,3])})}function Fg(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 Sp(s,o));return i.map(function(e){var r=new wp(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 kg(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 Ig(e,t,n,r,i){i.stage1=[];var a=t.map(function(t){return H(function(){var n={scale:t},i=Pg(e,t),a=Date.now(),o=Ng(i,r),s=o.prob,c=o.regions;return n.pnet=Date.now()-a,{scoresTensor:Pr(Pr(s,3)[1])[0],regionsTensor:Pr(c)[0],scale:t,statsForScale:n}})}).map(function(e){var t=e.scoresTensor,r=e.regionsTensor,a=e.scale,o=e.statsForScale,s=Fg(t,r,a,n);if(t.dispose(),r.dispose(),!s.length)return i.stage1.push(o),[];var c=Date.now(),l=kp(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=kp(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 wp(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 Lg(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=rm(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,tm.isNodejs()?fm(u):createImageBitmap(u)]})})}))];case 1:return a=c.sent(),o=[],a.forEach(function(e){var t=rm(dm({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 Ag(xu(Nn(e,[1,r,i,3]),[0,2,1,3]).toFloat())})})]}})})}function Rg(e,t){return H(function(){var n=Mg(e,t),r=jg(Um(Or(n,[n.shape[0],t.fc1.weights.shape[0]]),t.fc1),t.prelu4_alpha),i=Um(r,t.fc2_1),a=ni(il(i,hr(lu(i,1),1)),1),o=Um(r,t.fc2_2);return{scores:Pr(a,1)[1],regions:o}})}function zg(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,Lg(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=Rg(e,r);return e.dispose(),t}),i.stage2_rnet=Date.now()-a,c=s.length>1?Wn(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(),_=kp(p,m,.7),i.stage2_nms=Date.now()-a,v=_.map(function(e){var t=s[f[e]].regions.arraySync();return new kg(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 Bg(e,t){return H(function(){var n=Mg(e,t);n=ql(n,[2,2],[2,2],`same`),n=Om(n,t.conv4,`valid`),n=jg(n,t.prelu4_alpha);var r=jg(Um(Or(n,[n.shape[0],t.fc1.weights.shape[0]]),t.fc1),t.prelu5_alpha),i=Um(r,t.fc2_1),a=ni(il(i,hr(lu(i,1),1)),1),o=Um(r,t.fc2_2),s=Um(r,t.fc2_3);return{scores:Pr(a,1)[1],regions:o,points:s}})}function Vg(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,Lg(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=Bg(e,r);return e.dispose(),t}),i.stage3_onet=Date.now()-a,c=s.length>1?Wn(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 kg(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=kp(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 Sp(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 Hg=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 Sg(hr(Bf.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 Ph(t),f=d.minFaceSize,p=d.scaleFactor,m=d.maxNumScales,h=d.scoreThresholds,g=d.scaleSteps,_=(g||Og(f,p,[l,u])).filter(function(e){var t=Dg(e,[l,u]);return Math.min(t.width,t.height)>12}).slice(0,m),i.scales=_,i.pyramid=_.map(function(e){return Dg(e,[l,u])}),v=Date.now(),[4,Ig(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,zg(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,Vg(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 $m(Wp({},new Ep(x.scores[t],new Np(e.left/u,e.top/l,e.width/u,e.height/l),{height:l,width:u})),new Rp(x.points[t].map(function(t){return t.sub(new Sp(e.left,e.top)).div(new Sp(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,_m(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,_m(e)];case 1:return[2,n.apply(this,[r.sent(),t])]}})})},t.prototype.getDefaultModelName=function(){return`mtcnn_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Eg(e)},t.prototype.extractParams=function(e){return wg(e)},t}(wm),Ug=.4,Wg=[new Sp(1.603231,2.094468),new Sp(6.041143,7.080126),new Sp(2.882459,3.518061),new Sp(4.266906,5.178857),new Sp(9.041765,10.66308)],Gg=[117.001,114.697,97.404],Kg=function(e){Z(t,e);function t(){var t=this,n={withSeparableConvs:!0,iouThreshold:Ug,classes:[`face`],anchors:Wg,meanRgb:Gg,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 Ep(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}(gg),qg={ssdMobilenetv1:new Qh,tinyFaceDetector:new Kg,tinyYolov2:new _g,mtcnn:new Hg,faceLandmark68Net:new mh,faceLandmark68TinyNet:new vh,faceRecognitionNet:new Ah,faceExpressionNet:new Xm,ageGenderNet:new fh},Jg=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}(yg),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,n=this;return $(this,function(r){switch(r.label){case 0:return[4,this.parentTask];case 1:return e=r.sent(),[4,bg(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 qg.faceExpressionNet.predictExpressions(e)}))];case 1:return[2,t.sent()]}})})},this.extractedFaces)];case 2:return t=r.sent(),[2,e.map(function(e,n){return Zm(e,t[n])})]}})})},t.prototype.withAgeAndGender=function(){return new e_(this,this.input)},t}(Jg),Xg=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,xg(e,this.input,function(e){return qg.faceExpressionNet.predictExpressions(e)},this.extractedFaces)]:[2];case 2:return t=n.sent(),[2,Zm(e,t)]}})})},t.prototype.withAgeAndGender=function(){return new t_(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.withFaceDescriptors=function(){return new a_(this,this.input)},t}(Yg),Qg=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new r_(this,this.input)},t.prototype.withFaceDescriptor=function(){return new o_(this,this.input)},t}(Xg),$g=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}(yg),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=this;return $(this,function(r){switch(r.label){case 0:return[4,this.parentTask];case 1:return e=r.sent(),[4,bg(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 qg.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 Mh(Nh(e,a,o),i)})]}})})},t.prototype.withFaceExpressions=function(){return new Yg(this,this.input)},t}($g),t_=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,xg(e,this.input,function(e){return qg.ageGenderNet.predictAgeAndGender(e)},this.extractedFaces)]:[2];case 2:return t=a.sent(),n=t.age,r=t.gender,i=t.genderProbability,[2,Mh(Nh(e,r,i),n)]}})})},t.prototype.withFaceExpressions=function(){return new Xg(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.withFaceDescriptors=function(){return new a_(this,this.input)},t}(e_),r_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new Qg(this,this.input)},t.prototype.withFaceDescriptor=function(){return new o_(this,this.input)},t}(t_),i_=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}(yg),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(),[4,bg(e,this.input,function(e){return Promise.all(e.map(function(e){return qg.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 jh(e[n],t)})]}})})},t.prototype.withFaceExpressions=function(){return new Zg(this,this.input)},t.prototype.withAgeAndGender=function(){return new n_(this,this.input)},t}(i_),o_=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,xg(e,this.input,function(e){return qg.faceRecognitionNet.computeFaceDescriptor(e)},null,function(e){return e.landmarks.align(null,{useDlibAlignment:!0})})]:[2];case 2:return t=n.sent(),[2,jh(e,t)]}})})},t.prototype.withFaceExpressions=function(){return new Qg(this,this.input)},t.prototype.withAgeAndGender=function(){return new r_(this,this.input)},t}(i_),s_=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?qg.faceLandmark68TinyNet:qg.faceLandmark68Net},enumerable:!0,configurable:!0}),t}(yg),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,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 Ve?[4,ym(this.input,t)]:[3,3];case 2:return r=o.sent(),[3,5];case 3:return[4,vm(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 Ve&&e.dispose()}),[2,e.map(function(e,t){return $m(e,i[t])})]}})})},t.prototype.withFaceExpressions=function(){return new Zg(this,this.input)},t.prototype.withAgeAndGender=function(){return new n_(this,this.input)},t.prototype.withFaceDescriptors=function(){return new a_(this,this.input)},t}(s_),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,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 Ve?[4,ym(this.input,[t])]:[3,3]):[2];case 2:return r=a.sent(),[3,5];case 3:return[4,vm(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 Ve&&e.dispose()}),[2,$m(e,i)]}})})},t.prototype.withFaceExpressions=function(){return new Qg(this,this.input)},t.prototype.withAgeAndGender=function(){return new r_(this,this.input)},t.prototype.withFaceDescriptor=function(){return new o_(this,this.input)},t}(s_),u_=function(e){Z(t,e);function t(t,n){n===void 0&&(n=new Zh);var r=e.call(this)||this;return r.input=t,r.options=n,r}return t}(yg),d_=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 Ph?[4,qg.mtcnn.forward(t,n)]:[3,2];case 1:return[2,i.sent().map(function(e){return e.detection})];case 2:if(r=n instanceof vg?function(e){return qg.tinyFaceDetector.locateFaces(e,n)}:n instanceof Zh?function(e){return qg.ssdMobilenetv1.locateFaces(e,n)}:n instanceof hg?function(e){return qg.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 Wp({},e)}))]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new c_(this.runAndExtendWithFaceDetections(),this.input,e)},t.prototype.withFaceExpressions=function(){return new Yg(this.runAndExtendWithFaceDetections(),this.input)},t.prototype.withAgeAndGender=function(){return new e_(this.runAndExtendWithFaceDetections(),this.input)},t}(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;return $(this,function(n){switch(n.label){case 0:return[4,new d_(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?Wp({},e):void 0)]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new l_(this.runAndExtendWithFaceDetection(),this.input,e)},t.prototype.withFaceExpressions=function(){return new Xg(this.runAndExtendWithFaceDetection(),this.input)},t.prototype.withAgeAndGender=function(){return new t_(this.runAndExtendWithFaceDetection(),this.input)},t})(u_);function f_(e,t){return t===void 0&&(t=new Zh),new d_(e,t)}function p_(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 Hp)return e;if(e instanceof Float32Array)return new Hp(i(),[e]);if(e.descriptor&&e.descriptor instanceof Float32Array)return new Hp(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 p_(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 Bp(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 Bp(`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 Hp.fromJSON(e)}),t.distanceThreshold)},e})();function m_(e){return Math.max(0,Math.min(1,e))}function h_(e){let t=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],s=e[5];return(t(r,s)+t(i,o))/(2*t(n,a))}function g_(e,t,n){return!t||t<=0?e:new Promise((r,i)=>{let a=setTimeout(()=>i(n()),t);e.then(e=>{clearTimeout(a),r(e)},e=>{clearTimeout(a),i(e)})})}function __(){let e=!1;return{load:async(t,n)=>{if(!e)try{let r=n?.timeoutMs??15e3;await g_(qg.tinyFaceDetector.loadFromUri(t),r,()=>({code:`MODEL_LOAD_TIMEOUT`,message:`Timeout ao carregar modelo TinyFaceDetector em: ${t}`})),await g_(qg.faceLandmark68TinyNet.loadFromUri(t),r,()=>({code:`MODEL_LOAD_TIMEOUT`,message:`Timeout ao carregar modelo faceLandmark68TinyNet em: ${t}`})),e=!0}catch(e){throw e?.code===`MODEL_LOAD_TIMEOUT`?e:{code:`MODEL_LOAD_FAILED`,message:`Falha ao carregar modelos face-api.js em: ${t}`,cause:e}}},detect:async(t,n)=>{if(!e)return{faces:0};let r=new vg({inputSize:416,scoreThreshold:.5}),i=t.videoWidth||1,a=t.videoHeight||1;if(n?.withLandmarks){let e=await f_(t,r).withFaceLandmarks(!0);if(!e||e.length===0)return{faces:0};if(e.length>1)return{faces:e.length};let n=e[0].detection.box,o=e[0].landmarks,s=o.getLeftEye(),c=o.getRightEye(),l=e=>e.map(e=>({x:m_(e.x/i),y:m_(e.y/a)})),u=e=>e.reduce((t,n)=>({x:t.x+n.x/e.length,y:t.y+n.y/e.length}),{x:0,y:0}),d=u(s),f=u(c),p=Math.hypot(d.x-f.x,d.y-f.y),m=h_(s),h=h_(c),g=e=>m_((e-.16)/.12),_=n.x/i,v=n.y/a,y=n.width/i,b=n.height/a;return{faces:1,box:{x:_,y:v,width:y,height:b},centerX:m_(_+y/2),area:y*b,leftEyeOpenProb:g(m),rightEyeOpenProb:g(h),leftEyeCenter:{x:m_(d.x/i),y:m_(d.y/a)},rightEyeCenter:{x:m_(f.x/i),y:m_(f.y/a)},eyeDist:m_(p/Math.max(i,a)),leftEyePoints:l(s),rightEyePoints:l(c),poseSource:`landmarks`}}let o=await f_(t,r);if(!o||o.length===0)return{faces:0};if(o.length>1)return{faces:o.length};let s=o[0].box,c=s.x/i,l=s.y/a,u=s.width/i,d=s.height/a;return{faces:1,box:{x:c,y:l,width:u,height:d},centerX:m_(c+u/2),area:u*d,poseSource:`bbox`}}}}function v_(e,t){return{code:e,message:t}}function y_(e){return Math.max(0,Math.min(1,e))}function b_(e){return y_(e?.strictness??.5)}function x_(e,t,n){if(e.faces===0)return{feedback:v_(`FACE_NOT_FOUND`,`Centralize seu rosto`),valid:!1,frameOk:!1,stepOk:!1};if(e.faces>1)return{feedback:v_(`MULTIPLE_FACES`,`Apenas 1 rosto por vez`),valid:!1,frameOk:!1,stepOk:!1};if(!e.box)return{feedback:v_(`FACE_NOT_FOUND`,`Centralize seu rosto`),valid:!1,frameOk:!1,stepOk:!1};let r=b_(t),{x:i,y:a,width:o,height:s}=e.box,c=i+o/2,l=a+s/2,u=e.area??o*s,d=o/Math.max(1e-6,s),f=.07+r*.02,p=.22-r*.03;if(u<f)return{feedback:v_(`FACE_TOO_FAR`,`Aproxime o rosto`),valid:!1,frameOk:!1,stepOk:!1};if(u>p)return{feedback:v_(`FACE_TOO_CLOSE`,`Afaste o rosto`),valid:!1,frameOk:!1,stepOk:!1};let m=.12-r*.03;if(Math.abs(c-.5)>m||Math.abs(l-.5)>m)return{feedback:v_(`FACE_OFF_CENTER`,`Centralize seu rosto`),valid:!1,frameOk:!1,stepOk:!1};let h=t?.requireLookForward!==!1,g=.08-r*.02,_=t?.minEyeDistance??.06,v=t?.maxEyeSymmetryError??.08-r*.03,y=!!e.leftEyeCenter&&!!e.rightEyeCenter&&typeof e.eyeDist==`number`,b=e.eyeDist??0,x=y?Math.abs(Math.abs(e.leftEyeCenter.x-(e.centerX??c))-Math.abs(e.rightEyeCenter.x-(e.centerX??c)))/Math.max(1e-6,b):null,S=.78+r*.12,C=()=>{let t=Math.abs((e.centerX??c)-.5)>g,n=d>=S,r=!1,i=!1;return y&&b>=_&&x!=null?r=x>v||!n:(i=!0,r=!n),{ok:!t&&!r,usedFallback:i}};if(h){let e=C();if(!e.ok)return{feedback:v_(`LOOK_FORWARD`,e.usedFallback?`Olhe para a câmera (aproxime/ilumine para melhor detecção)`:`Olhe para a câmera`),valid:!1,frameOk:!1,stepOk:!1}}let w=n?.current??null;if(!w)return{feedback:v_(`READY`,`Pronto para capturar`),valid:!0,frameOk:!0,stepOk:!0};let T=.18-r*.05,E=.12-r*.03;if(w===`lookForward`){let e=C();return{feedback:v_(`LOOK_FORWARD`,e.usedFallback?`Olhe para a câmera (aproxime/ilumine para melhor detecção)`:`Olhe para a câmera`),valid:e.ok,frameOk:!0,stepOk:e.ok}}if(w===`lookUp`){let e=(l??.5)<.5-E;return{feedback:v_(`LOOK_UP`,`Olhe para cima`),valid:e,frameOk:!0,stepOk:e}}if(w===`lookDown`){let e=(l??.5)>.5+E;return{feedback:v_(`LOOK_DOWN`,`Olhe para baixo`),valid:e,frameOk:!0,stepOk:e}}if(w===`lookLeft`){let t=(e.centerX??c)<.5-T;return{feedback:v_(`LOOK_LEFT`,`Olhe para a esquerda`),valid:t,frameOk:!0,stepOk:t}}if(w===`lookRight`){let t=(e.centerX??c)>.5+T;return{feedback:v_(`LOOK_RIGHT`,`Olhe para a direita`),valid:t,frameOk:!0,stepOk:t}}if(w===`zoomIn`){let e=u>.16+r*.02;return{feedback:v_(`ZOOM_IN`,`Aproxime (zoom in)`),valid:e,frameOk:!0,stepOk:e}}if(w===`zoomOut`){let e=u<.12-r*.02;return{feedback:v_(`ZOOM_OUT`,`Afaste (zoom out)`),valid:e,frameOk:!0,stepOk:e}}if(w===`blink`){let t=e.leftEyeOpenProb,n=e.rightEyeOpenProb,r=typeof t==`number`&&typeof n==`number`&&t<.35&&n<.35;return{feedback:v_(`BLINK`,`Pisque`),valid:!!r,frameOk:!0,stepOk:!!r}}return{feedback:v_(`READY`,`Pronto para capturar`),valid:!0,frameOk:!0,stepOk:!0}}e.AlphaValid=class{_camera=null;_overlay=null;_container=null;_faceDetector=__();_loopTimer=null;_lastStatusValid=!1;_options=null;_challengeIndex=0;_challengeStartedAt=null;_blinkArmed=!1;_state=null;_status=`idle`;async start(e){n(e.container,`options.container`),await this.stop(),this._options={overlay:!0,uiMode:`default`,guideCircleRatio:.72,detectionIntervalMs:200,modelsPath:`/alphavalid-models`,...e},this._container=this._options.container,this._status=`initializing`,e.onStateChange?.({status:this._status,feedback:{code:`INITIALIZING`,message:`Inicializando câmera...`},message:`Inicializando câmera...`,isReadyToCapture:!1,challenge:{enabled:!1,index:0,total:0,completed:!1}});try{this._options.onFeedback?.({code:`INITIALIZING`,message:`Inicializando câmera...`}),this._camera=await i(this._container),this._options.onVideo?.(this._camera.video),this._options.uiMode!==`headless`&&this._options.overlay!==!1&&(this._overlay=o(this._container,this._options.guideCircleRatio)),this._options.onReady?.(),this._options.modelsPath&&await this._faceDetector.load(this._options.modelsPath,{timeoutMs:this._options.modelLoadTimeoutMs??15e3}),this._status=`running`,this.startDetectionLoop()}catch(e){this._status=`error`;let t=e,n=t&&typeof t==`object`&&typeof t.code==`string`&&typeof t.message==`string`?t:{code:`CAMERA_UNKNOWN`,message:`Erro inesperado ao iniciar o SDK.`,cause:e};throw this._options?.onError?.(n),this._options?.onStateChange?.({status:this._status,feedback:{code:`FACE_NOT_FOUND`,message:`Centralize seu rosto`},message:`Centralize seu rosto`,isReadyToCapture:!1,challenge:{enabled:!1,index:0,total:0,completed:!1}}),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,this._challengeIndex=0,this._challengeStartedAt=null,this._blinkArmed=!1,this._state=null,this._status=`idle`}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 a(this._camera.video,.9)}getState(){return this._state}getCurrentChallenge(){let e=this._options?.liveness?.challenges;return!e||e.length===0?null:e[Math.min(this._challengeIndex,e.length-1)]?.type??null}markStepCompletedIfNeeded(e){let t=this._options,n=t?.liveness?.challenges;if(!t||!n||n.length===0)return;let r=this.getCurrentChallenge();if(!r)return;let i=n[this._challengeIndex];if(i?.timeoutMs&&this._challengeStartedAt!=null&&Date.now()-this._challengeStartedAt>i.timeoutMs){this._challengeStartedAt=Date.now(),this._blinkArmed=!1;return}if(r===`blink`){if(!this._blinkArmed){e||(this._blinkArmed=!0);return}if(!e)return}else if(!e)return;this._challengeIndex+=1,this._challengeStartedAt=Date.now(),this._blinkArmed=!1}startDetectionLoop(){let e=async()=>{let t=this._camera,n=this._options;if(!(!t||!n))try{let e=this.getCurrentChallenge(),r=e===`blink`||n.liveness?.requireLookForward!==!1,i=await this._faceDetector.detect(t.video,{withLandmarks:r}),a=n.liveness?.challenges,o=!!a&&a.length>0;o&&this._challengeStartedAt==null&&(this._challengeStartedAt=Date.now());let s=x_(i,n.liveness,{current:e});this.markStepCompletedIfNeeded(s.stepOk);let c=!o||this._challengeIndex>=(a?.length??0),l=s.frameOk&&c;this._lastStatusValid=l,this._status=l?`ready`:`running`;let u={status:this._status,feedback:s.feedback,message:s.feedback.message,isReadyToCapture:l,challenge:{enabled:o,index:Math.min(this._challengeIndex,a?.length??0),total:a?.length??0,current:c?void 0:this.getCurrentChallenge()??void 0,completed:c}};this._state=u,n.onStateChange?.(u),n.onFeedback?.(s.feedback);let d=n.debug?.drawLandmarks===!0;this._overlay?.render({message:s.feedback.message,box:i.box,valid:l,landmarks:d?{leftEye:i.leftEyePoints,rightEye:i.rightEyePoints,leftEyeCenter:i.leftEyeCenter,rightEyeCenter:i.rightEyeCenter}:void 0})}catch(e){this._status=`error`;let t=e,r=t&&typeof t==`object`&&typeof t.code==`string`&&typeof t.message==`string`?t:{code:`CAMERA_UNKNOWN`,message:`Erro durante detecção/validação.`,cause:e};n.onError?.(r),n.onStateChange?.({status:this._status,feedback:{code:`FACE_NOT_FOUND`,message:`Centralize seu rosto`},message:`Centralize seu rosto`,isReadyToCapture:!1,challenge:this._state?.challenge})}finally{this._loopTimer=window.setTimeout(e,n.detectionIntervalMs??200)}};e()}}});
|
|
3804
|
+
Expected: `+l+`.`)}}function Jf(e,t,n){return!isFinite(e)&&!isFinite(t)||!(isNaN(e)||isNaN(t)||Math.abs(e-t)>n)}Object.freeze({TEST_EPSILON_FLOAT16:Gf,expectArraysClose:function(e,t,n){return n??=Kf(),qf(e,t,(function(e,t){return Jf(e,t,n)}))},testEpsilon:Kf,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 fe(e)||fe(e[0])||fe(t)||fe(t[0])?qf(e,n,(function(e,t){return e==t})):qf(e,t,(function(e,t){return Jf(e,t,0)}))},expectNumbersClose:function(e,t,n){if(n??=Kf(),!Jf(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:vo,webgl_util:sn,forceHalfFloat:function(){m().set(`WEBGL_FORCE_F16_TEXTURES`,!0)},MathBackendWebGL:Fs,setWebGLContext:ut,GPGPUContext:yo});var Yf=function(e){function t(){return e!==null&&e.apply(this,arguments)||this}return l(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 ln(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 ei(e,t)},t.prototype.dispose=function(){this.iterations_!=null&&ln(this.iterations_)},t.prototype.saveIterations=function(){return u(this,void 0,void 0,(function(){return d(this,(function(e){return this.iterations_??=0,[2,{name:`iter`,tensor:G(this.iterations_,`int32`)}]}))}))},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){return d(this,(function(e){throw Error(`getWeights() is not implemented for this optimizer yet.`)}))}))},t.prototype.setWeights=function(e){return u(this,void 0,void 0,(function(){return d(this,(function(e){throw Error(`setWeights() is not implemented for this optimizer class `+this.getClassName())}))}))},t.prototype.extractIterations=function(e){return u(this,void 0,void 0,(function(){var t;return d(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}(Vf);Object.defineProperty(Yf,Symbol.hasInstance,{value:function(e){return e.minimize!=null&&e.computeGradients!=null&&e.applyGradients!=null}});var Xf=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 l(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 Un(i).variable(!1)}))}),t.accumulatedUpdates[r]??(t.accumulatedUpdates[r]={originalName:n+`/accum_var`,variable:H((function(){return Un(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&&(ln(this.accumulatedGrads.map((function(e){return e.variable}))),ln(this.accumulatedUpdates.map((function(e){return e.variable}))))},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){var e;return d(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 u(this,void 0,void 0,(function(){var t;return d(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}(Yf);Uf(Xf);var Zf=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 l(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 zn(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&&ln(this.accumulatedGrads.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){return d(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 u(this,void 0,void 0,(function(){return d(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}(Yf);Uf(Zf);var Qf=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 l(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=il(1,t.accBeta1),i=il(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 Un(o).variable(!1)}))}),t.accumulatedSecondMoment[a]??(t.accumulatedSecondMoment[a]={originalName:n+`/v`,variable:H((function(){return Un(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&&ln(this.accumulatedFirstMoment.map((function(e){return e.variable}))),this.accumulatedSecondMoment!=null&&ln(this.accumulatedSecondMoment.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){var e;return d(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 u(this,void 0,void 0,(function(){var t,n=this;return d(this,(function(r){switch(r.label){case 0:return[4,this.extractIterations(e)];case 1:return e=r.sent(),H((function(){n.accBeta1.assign(tl(n.beta1,n.iterations_+1)),n.accBeta2.assign(tl(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}(Yf);Uf(Qf);var $f=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 l(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=il(1,t.accBeta1),i=Uc(-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:Un(o).variable(!1)}),t.accumulatedWeightedInfNorm[a]??(t.accumulatedWeightedInfNorm[a]={originalName:n+`/v`,variable:Un(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&&ln(this.accumulatedFirstMoment.map((function(e){return e.variable}))),this.accumulatedWeightedInfNorm!=null&&ln(this.accumulatedWeightedInfNorm.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){return d(this,(function(e){throw Error(`getWeights() is not implemented for Adamax yet.`)}))}))},t.prototype.setWeights=function(e){return u(this,void 0,void 0,(function(){return d(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}(Yf);Uf($f);var ep=function(e){function t(t){var n=e.call(this)||this;return n.learningRate=t,n.setLearningRate(t),n}return l(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=un(G(-e))},t.prototype.dispose=function(){this.c.dispose()},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){return d(this,(function(e){switch(e.label){case 0:return[4,this.saveIterations()];case 1:return[2,[e.sent()]]}}))}))},t.prototype.setWeights=function(e){return u(this,void 0,void 0,(function(){return d(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}(Yf);Uf(ep);var tp=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 l(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 Un(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&&ln(this.accumulations.map((function(e){return e.variable})))},t.prototype.setMomentum=function(e){this.momentum=e},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){return d(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 u(this,void 0,void 0,(function(){return d(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}(ep);Uf(tp);var np=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 l(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 Un(i).variable(!1)}))}),t.accumulatedMoments[r]??(t.accumulatedMoments[r]={originalName:n+`/momentum`,variable:H((function(){return Un(i).variable(!1)}))}),t.accumulatedMeanGrads[r]==null&&t.centered&&(t.accumulatedMeanGrads[r]={originalName:n+`/mg`,variable:H((function(){return Un(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&&ln(this.accumulatedMeanSquares.map((function(e){return e.variable}))),this.accumulatedMeanGrads!=null&&this.centered&&ln(this.accumulatedMeanGrads.map((function(e){return e.variable}))),this.accumulatedMoments!=null&&ln(this.accumulatedMoments.map((function(e){return e.variable})))},t.prototype.getWeights=function(){return u(this,void 0,void 0,(function(){var e;return d(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 u(this,void 0,void 0,(function(){var t;return d(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}(Yf);Uf(np);var rp=function(){function e(){}return e.sgd=function(e){return new ep(e)},e.momentum=function(e,t,n){return n===void 0&&(n=!1),new tp(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 np(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 Qf(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 Xf(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 $f(e,t,n,r,i)},e.adagrad=function(e,t){return t===void 0&&(t=.1),new Zf(e,t)},e}();rp.sgd,rp.momentum,rp.adadelta,rp.adagrad,rp.rmsprop,rp.adamax,rp.adam,Ve.prototype.squaredDifference=function(e){return Rs(this,e)},R=Td;function ip(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 ap=function(e,t){return ap=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])},ap(e,t)};function Z(e,t){ap(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}var op=function(){return op=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},op.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 sp(){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 cp=function(){function e(e,t){if(!bp(e)||!bp(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 lp(e,t){return e instanceof Ve&&e.shape.length===t}function up(e){return lp(e,2)}function dp(e){return lp(e,3)}function fp(e){return lp(e,4)}function pp(e){return e%1!=0}function mp(e){return e%2==0}function hp(e,t){t===void 0&&(t=2);var n=10**t;return Math.floor(e*n)/n}function gp(e){return e&&e.width&&e.height}function _p(e,t){var n=e.width,r=e.height,i=t/Math.max(r,n);return new cp(Math.round(n*i),Math.round(r*i))}function vp(e){return e.reduce(function(e,t){return e.add(t)},new Sp(0,0)).div(new Sp(e.length,e.length))}function yp(e,t,n){return Array(e).fill(0).map(function(e,r){return t+r*n})}function bp(e){return!!e&&e!==1/0&&e!==-1/0&&!isNaN(e)||e===0}function xp(e){return bp(e)&&0<=e&&e<=1}var Sp=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}(),Cp=function(){function e(t,n){n===void 0&&(n=!0);var r=t||{},i=[r.left,r.top,r.right,r.bottom].every(bp),a=[r.x,r.y,r.width,r.height].every(bp);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(bp)},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 Sp(this.left,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`topRight`,{get:function(){return new Sp(this.right,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottomLeft`,{get:function(){return new Sp(this.left,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,`bottomRight`,{get:function(){return new Sp(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=gp(t)?t.width:t,r=gp(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}(),wp=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}(Cp),Tp=function(){function e(e,t,n,r,i){this._imageDims=new cp(i.width,i.height),this._score=e,this._classScore=t,this._className=n,this._box=new Cp(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 Cp(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}(),Ep=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}(Tp);function Dp(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 Op(e){var t=e.map(function(e){return e.x}),n=e.map(function(e){return e.y});return new wp(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 kp(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(Dp(u,d,r))}i=i.filter(function(e,t){return s[t]<=n})};i.length>0;)o();return a}function Ap(e,t){return H(function(){var n=t[0],r=t[1],i=t[2];return il(e,Wn([zn(sp(e.shape.slice(0,3),[1]),n),zn(sp(e.shape.slice(0,3),[1]),r),zn(sp(e.shape.slice(0,3),[1]),i)],3))})}function jp(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,zn(n,0)},l=c(o),u=a-l.shape[s];return Wn([t&&u?c(u):null,e,l].filter(function(e){return!!e}).map(function(e){return e.toFloat()}),s)})}function Mp(e){return 1/(1+Math.exp(-e))}var Np=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}(Cp),Pp=.5,Fp=.43,Ip=.45,Lp=function(){function e(e,t,n){n===void 0&&(n=new Sp(0,0));var r=t.width,i=t.height;this._imgDims=new cp(r,i),this._shift=n,this._positions=e.map(function(e){return e.mul(new Sp(r,i)).add(n)})}return Object.defineProperty(e.prototype,`shift`,{get:function(){return new Sp(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 Sp(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 Sp(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 Ep?e.box.floor():new Cp(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/Ip),s=vp(e),c=Math.floor(Math.max(0,s.x-Pp*o)),l=Math.floor(Math.max(0,s.y-Fp*o));return new Np(c,l,Math.min(o,this.imageWidth+c),Math.min(o,this.imageHeight+l))},e.prototype.alignMinBbox=function(e){var t=Op(this.positions);return t.pad(t.width*e,t.height*e)},e.prototype.getRefPointsForAlignment=function(){throw Error(`getRefPointsForAlignment not implemented by base class`)},e}(),Rp=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],vp([e[3],e[4]])]},t}(Lp),zp=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(vp)},t}(Lp),Bp=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?` (`+hp(this.distance)+`)`:``)},e}(),Vp=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(Cp.assertIsValidBox(e,t),!bp(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}(Cp),Hp=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(Vp.assertIsValidLabeledBox(e,t),!xp(e.score)||!xp(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})(Vp);function Up(e){return e.detection instanceof Ep}function Wp(e,t){return Object.assign({},e,{detection:t})}function Gp(){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 Kp(e){var t=``;if(!e)try{e=s()}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 qp(){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=Kp();return op({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 Jp(){return typeof window==`object`&&typeof document<`u`&&typeof HTMLImageElement<`u`&&typeof HTMLCanvasElement<`u`&&typeof HTMLVideoElement<`u`&&typeof ImageData<`u`&&typeof CanvasRenderingContext2D<`u`}function Yp(){return typeof global==`object`&&typeof require==`function`&&typeof module<`u`&&typeof process<`u`&&!!process.version}var Xp;function Zp(){if(!Xp)throw Error(`getEnv - environment is not defined, check isNodejs() and isBrowser()`);return Xp}function Qp(e){Xp=e}function $p(){Jp()&&Qp(Gp()),Yp()&&Qp(qp())}function em(e){if(Xp||$p(),!Xp)throw Error(`monkeyPatch - environment is not defined, check isNodejs() and isBrowser()`);var t=e.Canvas,n=t===void 0?Xp.Canvas:t,r=e.Image,i=r===void 0?Xp.Image:r;Xp.Canvas=n,Xp.Image=i,Xp.createCanvasElement=e.createCanvasElement||(function(){return new n}),Xp.createImageElement=e.createImageElement||(function(){return new i}),Xp.ImageData=e.ImageData||Xp.ImageData,Xp.Video=e.Video||Xp.Video,Xp.fetch=e.fetch||Xp.fetch,Xp.readFile=e.readFile||Xp.readFile}var tm={getEnv:Zp,setEnv:Qp,initialize:$p,createBrowserEnv:Gp,createFileSystem:Kp,createNodejsEnv:qp,monkeyPatch:em,isBrowser:Jp,isNodejs:Yp};$p();function nm(e){return!tm.isNodejs()&&typeof e==`string`?document.getElementById(e):e}function rm(e){var t=tm.getEnv(),n=t.Canvas;if(e instanceof t.CanvasRenderingContext2D)return e;var r=nm(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 im;(function(e){e.TOP_LEFT=`TOP_LEFT`,e.TOP_RIGHT=`TOP_RIGHT`,e.BOTTOM_LEFT=`BOTTOM_LEFT`,e.BOTTOM_RIGHT=`BOTTOM_RIGHT`})(im||={});var am=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||im.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}(),om=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 am(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===im.BOTTOM_RIGHT||n===im.TOP_RIGHT,i=n===im.BOTTOM_LEFT||n===im.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=nm(e),n=rm(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}(),sm=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:im.BOTTOM_LEFT,backgroundColor:this.boxColor};this.drawLabelOptions=new am(Object.assign({},a,i))}return e}();(function(){function e(e,t){t===void 0&&(t={}),this.box=new Cp(e),this.options=new sm(t)}return e.prototype.draw=function(e){var t=rm(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 om([u],{x:o-i/2,y:s},this.options.drawLabelOptions).draw(e)},e})();function cm(e){var t=tm.getEnv(),n=t.Image,r=t.Video;return e instanceof n&&e.complete||e instanceof r&&e.readyState>=3}function lm(e){return new Promise(function(t,n){if(e instanceof tm.getEnv().Canvas||cm(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 um(e){var t=tm.getEnv(),n=t.Image,r=t.Video;return e instanceof n?new cp(e.naturalWidth,e.naturalHeight):e instanceof r?new cp(e.videoWidth,e.videoHeight):new cp(e.width,e.height)}function dm(e){var t=e.width,n=e.height,r=tm.getEnv().createCanvasElement,i=r();return i.width=t,i.height=n,i}function fm(e,t){var n=tm.getEnv().ImageData;if(!(e instanceof n)&&!cm(e))throw Error(`createCanvasFromMedia - media has not finished loading yet`);var r=t||um(e),i=r.width,a=r.height,o=dm({width:i,height:a});return e instanceof n?rm(o).putImageData(e,0,0):rm(o).drawImage(e,0,0,i,a),o}function pm(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||tm.getEnv().createCanvasElement(),r=e.shape.slice(fp(e)?1:0),i=r[0],a=r[1],o=r[2],s=H(function(){return e.as3D(i,a,o).toInt()}),[4,Bf.toPixels(s,n)];case 1:return c.sent(),s.dispose(),[2,n]}})})}function mm(e){var t=tm.getEnv(),n=t.Image,r=t.Canvas,i=t.Video;return e instanceof n||e instanceof r||e instanceof i}function hm(e,t,n){n===void 0&&(n=!1);var r=tm.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=um(e),s=t/Math.max(o.height,o.width),c=s*o.width,l=s*o.height,u=dm({width:t,height:t}),d=e instanceof a?e:fm(e),f=Math.abs(c-l)/2,p=n&&c<l?f:0,m=n&&l<c?f:0;return rm(u).drawImage(d,p,m,c,l),u}var gm=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(dp(e)){n._imageTensors[t]=e,n._inputDimensions[t]=e.shape;return}if(fp(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 tm.getEnv().Canvas?e:fm(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 yp(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 _p({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 jr(yp(n.batchSize,0,1).map(function(r){var i=n.getInput(r);if(i instanceof Ve){var a=fp(i)?i:i.expandDims();return a=jp(a,t),(a.shape[1]!==e||a.shape[2]!==e)&&(a=gd.resizeBilinear(a,[e,e])),a.as3D(e,e,3)}if(i instanceof tm.getEnv().Canvas)return Bf.fromPixels(hm(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 _m(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 gm)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(nm),r.forEach(function(e,r){if(!mm(e)&&!dp(e)&&!fp(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(fp(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 mm(e)&&lm(e)}))];case 1:return i.sent(),[2,new gm(r,Array.isArray(e))]}})})}function vm(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=tm.getEnv().Canvas,r=e,e instanceof n?[3,5]:[4,_m(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,pm(a)];case 3:o=l.sent(),l.label=4;case 4:r=o,l.label=5;case 5:return s=rm(r),c=t.map(function(e){return e instanceof Ep?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=dm({width:r,height:i});return rm(a).putImageData(s.getImageData(t,n,r,i),0,0),a})]}})})}function ym(e,t){return Q(this,void 0,void 0,function(){return $(this,function(n){if(!dp(e)&&!fp(e))throw Error(`extractFaceTensors - expected image tensor to be 3D or 4D`);if(fp(e)&&e.shape[0]>1)throw Error(`extractFaceTensors - batchSize > 1 not supported`);return[2,H(function(){var n=e.shape.slice(fp(e)?1:0),r=n[0],i=n[1],a=n[2];return t.map(function(e){return e instanceof Ep?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 tu(e.as3D(r,i,a),[o,n,0],[c,s,a])})})]})})}function bm(e,t){return Q(this,void 0,void 0,function(){var n,r;return $(this,function(i){switch(i.label){case 0:return n=tm.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 xm(e){return Q(this,void 0,void 0,function(){return $(this,function(t){switch(t.label){case 0:return[4,bm(e)];case 1:return[2,t.sent().json()]}})})}function Sm(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 Cm(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=Sm(e,t),r=n.manifestUri,i=n.modelBaseUri,[4,xm(r)];case 1:return a=o.sent(),[2,If.loadWeights(a,i)]}})})}var wm=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 qe})},e.prototype.getFrozenParams=function(){return this.getParamList().filter(function(e){return!(e.tensor instanceof qe)})},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=On(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,Cm(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=tm.getEnv().readFile,n=Sm(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=If.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 Ve))throw Error(`traversePropertyPath - parameter is not a tensor, for path `+e);return{obj:n,objProp:r}},e}();function Tm(e,t,n){return H(function(){var r=Pl(e,t.depthwise_filter,t.pointwise_filter,n,`same`);return r=zc(r,t.bias),r})}function Em(e,t,n){return n===void 0&&(n=!1),H(function(){var r=vu(n?zc(Dl(e,t.conv0.filters,[2,2],`same`),t.conv0.bias):Tm(e,t.conv0,[2,2])),i=Tm(r,t.conv1,[1,1]);return vu(zc(r,zc(i,Tm(vu(zc(r,i)),t.conv2,[1,1]))))})}function Dm(e,t,n,r){return n===void 0&&(n=!1),r===void 0&&(r=!0),H(function(){var i=vu(n?zc(Dl(e,t.conv0.filters,r?[2,2]:[1,1],`same`),t.conv0.bias):Tm(e,t.conv0,r?[2,2]:[1,1])),a=Tm(i,t.conv1,[1,1]),o=Tm(vu(zc(i,a)),t.conv2,[1,1]);return vu(zc(i,zc(a,zc(o,Tm(vu(zc(i,zc(a,o))),t.conv3,[1,1])))))})}function Om(e,t,n,r){return n===void 0&&(n=`same`),r===void 0&&(r=!1),H(function(){var i=zc(Dl(e,t.filters,[1,1],n),t.bias);return r?vu(i):i})}function km(e,t){Object.keys(e).forEach(function(n){t.some(function(e){return e.originalPath===n})||e[n].dispose()})}function Am(e,t){return function(n,r,i,a){var o=Nn(e(n*r*i*i),[i,i,n,r]),s=An(e(r));return t.push({paramPath:a+`/filters`},{paramPath:a+`/bias`}),{filters:o,bias:s}}}function jm(e,t){return function(n,r,i){var a=jn(e(n*r),[n,r]),o=An(e(r));return t.push({paramPath:i+`/weights`},{paramPath:i+`/bias`}),{weights:a,bias:o}}}var Mm=function(){function e(e,t,n){this.depthwise_filter=e,this.pointwise_filter=t,this.bias=n}return e}();function Nm(e,t){return function(n,r,i){var a=Nn(e(9*n),[3,3,n,1]),o=Nn(e(n*r),[1,1,n,r]),s=An(e(r));return t.push({paramPath:i+`/depthwise_filter`},{paramPath:i+`/pointwise_filter`},{paramPath:i+`/bias`}),new Mm(a,o,s)}}function Pm(e){return function(t){return new Mm(e(t+`/depthwise_filter`,4),e(t+`/pointwise_filter`,4),e(t+`/bias`,1))}}function Fm(e,t){return function(n,r,i){var a=e[n];if(!lp(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 Im(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 Lm(e,t){var n=Am(e,t),r=Nm(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 Rm(e){var t=[],n=Im(e),r=n.extractWeights,i=n.getRemainingWeights,a=Lm(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 zm(e){return function(t){return{filters:e(t+`/filters`,4),bias:e(t+`/bias`,1)}}}function Bm(e,t){var n=Fm(e,t),r=zm(n),i=Pm(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 Vm(e){var t=[],n=Bm(e,t).extractDenseBlock4Params,r={dense0:n(`dense0`,!0),dense1:n(`dense1`),dense2:n(`dense2`),dense3:n(`dense3`)};return km(e,t),{params:r,paramMappings:t}}var Hm=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=Dm(Ap(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(G(255)),t.dense0,!0);return n=Dm(n,t.dense1),n=Dm(n,t.dense2),n=Dm(n,t.dense3),n=Jl(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,_m(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 Vm(e)},t.prototype.extractParams=function(e){return Rm(e)},t}(wm);function Um(e,t){return H(function(){return zc(Ll(e,t.weights),t.bias)})}function Wm(e,t,n){var r=[],i=Im(e),a=i.extractWeights,o=i.getRemainingWeights,s=jm(a,r)(t,n,`fc`);if(o().length!==0)throw Error(`weights remaing after extract: `+o().length);return{paramMappings:r,params:{fc:s}}}function Gm(e){var t=[],n=Fm(e,t);function r(e){return{weights:n(e+`/weights`,2),bias:n(e+`/bias`,1)}}var i={fc:r(`fc`)};return km(e,t),{params:i,paramMappings:t}}function Km(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 qm=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 gm?t.faceFeatureExtractor.forwardInput(e):e;return Um(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 Wm(e,this.getClassifierChannelsIn(),this.getClassifierChannelsOut())},t.prototype.extractParamsFromWeigthMap=function(e){var t=Km(e),n=t.featureExtractorMap,r=t.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(n),Gm(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}(wm),Jm=[`neutral`,`happy`,`sad`,`angry`,`fearful`,`disgusted`,`surprised`],Ym=function(){function e(e){var t=this;if(e.length!==7)throw Error(`FaceExpressions.constructor - expected probabilities.length to be 7, have: `+e.length);Jm.forEach(function(n,r){t[n]=e[r]})}return e.prototype.asSortedArray=function(){var e=this;return Jm.map(function(t){return{expression:t,probability:e[t]}}).sort(function(e,t){return t.probability-e.probability})},e}(),Xm=function(e){Z(t,e);function t(t){return t===void 0&&(t=new Hm),e.call(this,`FaceExpressionNet`,t)||this}return t.prototype.forwardInput=function(e){var t=this;return H(function(){return ni(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,_m(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,_m(e)];case 1:return t=o.sent(),[4,this.forwardInput(t)];case 2:return n=o.sent(),[4,Promise.all(Pr(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 Ym(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}(qm);function Zm(e,t){return Object.assign({},e,{expressions:t})}function Qm(e){return Up(e)&&e.landmarks instanceof Lp&&e.unshiftedLandmarks instanceof Lp&&e.alignedRect instanceof Ep}function $m(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 Ep(e.detection.score,i.rescale(a.reverse()),a)};return Object.assign({},e,o)}var eh=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 eh(t)}return e.prototype.draw=function(e){var t=rm(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 zp&&(t.strokeStyle=o,t.lineWidth=a,ip(t,this.faceLandmarks.getJawOutline()),ip(t,this.faceLandmarks.getLeftEyeBrow()),ip(t,this.faceLandmarks.getRightEyeBrow()),ip(t,this.faceLandmarks.getNose()),ip(t,this.faceLandmarks.getLeftEye(),!0),ip(t,this.faceLandmarks.getRightEye(),!0),ip(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 th(e,t){var n=Am(e,t),r=Nm(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 nh(e,t){var n=[],r=Im(e),i=r.extractWeights,a=r.getRemainingWeights,o=th(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={};yp(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 rh(e,t){var n=Fm(e,t),r=zm(n),i=Pm(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 ih(e,t){var n=[],r=rh(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={};yp(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 km(e,n),{params:{entry_flow:c,middle_flow:l,exit_flow:u},paramMappings:n}}function ah(e,t,n){return zc(Dl(e,t.filters,n,`same`),t.bias)}function oh(e,t,n){n===void 0&&(n=!0);var r=n?vu(e):e;return r=Tm(r,t.separable_conv0,[1,1]),r=Tm(vu(r),t.separable_conv1,[1,1]),r=ql(r,[3,3],[2,2],`same`),r=zc(r,ah(e,t.expansion_conv,[2,2])),r}function sh(e,t){var n=Tm(vu(e),t.separable_conv0,[1,1]);return n=Tm(vu(n),t.separable_conv1,[1,1]),n=Tm(vu(n),t.separable_conv2,[1,1]),n=zc(n,e),n}var ch=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=vu(ah(Ap(e.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(G(256)),n.entry_flow.conv_in,[2,2]));return r=oh(r,n.entry_flow.reduction_block_0,!1),r=oh(r,n.entry_flow.reduction_block_1),yp(t._numMainBlocks,0,1).forEach(function(e){r=sh(r,n.middle_flow[`main_block_`+e])}),r=oh(r,n.exit_flow.reduction_block),r=vu(Tm(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,_m(e)];case 1:return[2,t.apply(this,[n.sent()])]}})})},t.prototype.getDefaultModelName=function(){return`tiny_xception_model`},t.prototype.extractParamsFromWeigthMap=function(e){return ih(e,this._numMainBlocks)},t.prototype.extractParams=function(e){return nh(e,this._numMainBlocks)},t}(wm);function lh(e){var t=[],n=Im(e),r=n.extractWeights,i=n.getRemainingWeights,a=jm(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 uh(e){var t=[],n=Fm(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 km(e,t),{params:i,paramMappings:t}}var dh;(function(e){e.FEMALE=`female`,e.MALE=`male`})(dh||={});var fh=function(e){Z(t,e);function t(t){t===void 0&&(t=new ch(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 gm?t.faceFeatureExtractor.forwardInput(e):e,i=Jl(r,[7,7],[2,2],`valid`).as2D(r.shape[0],-1);return{age:Um(i,n.fc.age).as1D(),gender:Um(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:ni(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,_m(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,_m(e)];case 1:return t=c.sent(),[4,this.forwardInput(t)];case 2:return n=c.sent(),r=Pr(n.age),i=Pr(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?dh.MALE:dh.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 lh(e)},t.prototype.extractParamsFromWeigthMap=function(e){var t=Km(e),n=t.featureExtractorMap,r=t.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(n),uh(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}(wm),ph=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 jr([zn([68],e),zn([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(zn([i,136],t)).sub(jr(Array.from(Array(i),function(e,t){return n(o(t),s(t))}))).div(jr(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,_m(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,_m(e)];case 1:return t=a.sent(),n=H(function(){return Pr(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 mp(t)}),s=r.filter(function(e,t){return!mp(t)}),[2,new zp(Array(68).fill(0).map(function(e,t){return new Sp(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}(qm),mh=function(e){Z(t,e);function t(t){return t===void 0&&(t=new Hm),e.call(this,`FaceLandmark68Net`,t)||this}return t.prototype.getDefaultModelName=function(){return`face_landmark_68_model`},t.prototype.getClassifierChannelsIn=function(){return 256},t}(ph);function hh(e){var t=[],n=Bm(e,t).extractDenseBlock3Params,r={dense0:n(`dense0`,!0),dense1:n(`dense1`),dense2:n(`dense2`)};return km(e,t),{params:r,paramMappings:t}}function gh(e){var t=[],n=Im(e),r=n.extractWeights,i=n.getRemainingWeights,a=Lm(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 _h=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=Em(Ap(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=Jl(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,_m(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 hh(e)},t.prototype.extractParams=function(e){return gh(e)},t}(wm),vh=function(e){Z(t,e);function t(t){return t===void 0&&(t=new _h),e.call(this,`FaceLandmark68TinyNet`,t)||this}return t.prototype.getDefaultModelName=function(){return`face_landmark_68_tiny_model`},t.prototype.getClassifierChannelsIn=function(){return 128},t}(ph);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t})(mh);function yh(e,t){return zc($c(e,t.weights),t.biases)}function bh(e,t,n,r,i){i===void 0&&(i=`same`);var a=t.conv,o=a.filters,s=a.bias,c=Dl(e,o,n,i);return c=zc(c,s),c=yh(c,t.scale),r?vu(c):c}function xh(e,t){return bh(e,t,[1,1],!0)}function Sh(e,t){return bh(e,t,[1,1],!1)}function Ch(e,t){return bh(e,t,[2,2],!0,`valid`)}function wh(e,t){function n(t,n,r){var i=e(t),a=i.length/(n*r*r);if(pp(a))throw Error(`depth has to be an integer: `+a+`, weights.length: `+i.length+`, numFilters: `+n+`, filterSize: `+r);return H(function(){return xu(Nn(i,[n,a,r,r]),[2,3,1,0])})}function r(r,i,a,o){var s=n(r,i,a),c=An(e(i));return t.push({paramPath:o+`/filters`},{paramPath:o+`/bias`}),{filters:s,bias:c}}function i(n,r){var i=An(e(n)),a=An(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 Th(e){var t=Im(e),n=t.extractWeights,r=t.getRemainingWeights,i=[],a=wh(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 xu(jn(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 Eh(e,t){var n=Fm(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 Dh(e){var t=[],n=Eh(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`}),!up(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 km(e,t),{params:x,paramMappings:t}}function Oh(e,t){var n=xh(e,t.conv1);return n=Sh(n,t.conv2),n=zc(n,e),n=vu(n),n}function kh(e,t){var n=Ch(e,t.conv1);n=Sh(n,t.conv2);var r=Jl(e,2,2,`valid`),i=Rn(r.shape),a=r.shape[3]!==n.shape[3];if(r.shape[1]!==n.shape[1]||r.shape[2]!==n.shape[2]){var o=sp(n.shape);o[1]=1;var s=Rn(o);n=Wn([n,s],1);var c=sp(n.shape);c[2]=1;var l=Rn(c);n=Wn([n,l],2)}return r=a?Wn([r,i],3):r,n=zc(r,n),n=vu(n),n}var Ah=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=Ch(Ap(e.toBatchTensor(150,!0).toFloat(),[122.782,117.001,104.298]).div(G(256)),t.conv32_down);return n=ql(n,3,2,`valid`),n=Oh(n,t.conv32_1),n=Oh(n,t.conv32_2),n=Oh(n,t.conv32_3),n=kh(n,t.conv64_down),n=Oh(n,t.conv64_1),n=Oh(n,t.conv64_2),n=Oh(n,t.conv64_3),n=kh(n,t.conv128_down),n=Oh(n,t.conv128_1),n=Oh(n,t.conv128_2),n=kh(n,t.conv256_down),n=Oh(n,t.conv256_1),n=Oh(n,t.conv256_2),n=kh(n,t.conv256_down_out),Ll(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,_m(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,_m(e)];case 1:return t=a.sent(),n=H(function(){return Pr(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 Dh(e)},t.prototype.extractParams=function(e){return Th(e)},t}(wm);function jh(e,t){return Object.assign({},e,{descriptor:t})}function Mh(e,t){return Object.assign({},e,{age:t})}function Nh(e,t,n){return Object.assign({},e,{gender:t,genderProbability:n})}var Ph=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 Fh(e,t){function n(n,r){var i=Nn(e(9*n),[3,3,n,1]),a=An(e(n)),o=An(e(n)),s=An(e(n)),c=An(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=Nn(e(n*r*i*i),[i,i,n,r]),c=An(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 Ih(e){var t=[],n=Im(e),r=n.extractWeights,i=n.getRemainingWeights,a=Fh(r,t),o=a.extractMobilenetV1Params,s=a.extractPredictionLayerParams,c=o(),l=s(),u={extra_dim:Mn(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 Lh(e,t){var n=Fm(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 Rh(e){var t=[],n=Lh(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`}),!dp(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 km(e,t),{params:o,paramMappings:t}}function zh(e,t,n){return H(function(){var r=Dl(e,t.filters,n,`same`);return r=zc(r,t.batch_norm_offset),qs(r,0,6)})}var Bh=.0010000000474974513;function Vh(e,t,n){return H(function(){var r=jl(e,t.filters,n,`same`);return r=kc(r,t.batch_norm_mean,t.batch_norm_variance,t.batch_norm_offset,t.batch_norm_scale,Bh),qs(r,0,6)})}function Hh(e){return[2,4,6,12].some(function(t){return t===e})?[2,2]:[1,1]}function Uh(e,t){return H(function(){var n=null,r=zh(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=Hh(i);r=Vh(r,e.depthwise_conv,a),r=zh(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 Wh(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=Gh(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 Gh(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 Kh(e){var t=Pr(xu(e,[1,0])),n=[il(t[2],t[0]),il(t[3],t[1])];return{sizes:n,centers:[zc(t[0],Uc(n[0],G(2))),zc(t[1],Uc(n[1],G(2)))]}}function qh(e,t){var n=Kh(e),r=n.sizes,i=n.centers,a=Pr(xu(t,[1,0])),o=Uc($c(Zs(Uc(a[2],G(5))),r[0]),G(2)),s=zc($c(Uc(a[0],G(10)),r[0]),i[0]),c=Uc($c(Zs(Uc(a[3],G(5))),r[1]),G(2)),l=zc($c(Uc(a[1],G(10)),r[1]),i[1]);return xu(jr([il(s,o),il(l,c),zc(s,o),zc(l,c)]),[1,0])}function Jh(e,t,n){return H(function(){var r=e.shape[0],i=qh(Or(Mr(n.extra_dim,[r,1,1]),[-1,4]),Or(e,[-1,4]));i=Or(i,[r,i.shape[0]/r,4]);var a=Ql(sc(Ql(t,[0,0,1],[-1,-1,-1])),[0,0,0],[-1,-1,1]);return a=Or(a,[r,a.shape[1]]),{boxes:Pr(i),scores:Pr(a)}})}function Yh(e,t){return H(function(){var n=e.shape[0];return{boxPredictionEncoding:Or(Om(e,t.box_encoding_predictor),[n,-1,1,4]),classPrediction:Or(Om(e,t.class_predictor),[n,-1,3])}})}function Xh(e,t,n){return H(function(){var r=zh(zh(e,n.conv_0,[1,1]),n.conv_1,[2,2]),i=zh(zh(r,n.conv_2,[1,1]),n.conv_3,[2,2]),a=zh(zh(i,n.conv_4,[1,1]),n.conv_5,[2,2]),o=zh(zh(a,n.conv_6,[1,1]),n.conv_7,[2,2]),s=Yh(t,n.box_predictor_0),c=Yh(e,n.box_predictor_1),l=Yh(r,n.box_predictor_2),u=Yh(i,n.box_predictor_3),d=Yh(a,n.box_predictor_4),f=Yh(o,n.box_predictor_5);return{boxPredictions:Wn([s.boxPredictionEncoding,c.boxPredictionEncoding,l.boxPredictionEncoding,u.boxPredictionEncoding,d.boxPredictionEncoding,f.boxPredictionEncoding],1),classPredictions:Wn([s.classPrediction,c.classPrediction,l.classPrediction,u.classPrediction,d.classPrediction,f.classPrediction],1)}})}var Zh=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}(),Qh=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=Uh(il($c(e.toBatchTensor(512,!1).toFloat(),G(.007843137718737125)),G(1)),t.mobilenetv1),r=Xh(n.out,n.conv11,t.prediction_layer),i=r.boxPredictions,a=r.classPredictions;return Jh(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,_m(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 Zh(t),r=n.maxResults,i=n.minConfidence,[4,_m(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=Wh(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 Ep(f[e],new Np(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 Rh(e)},t.prototype.extractParams=function(e){return Ih(e)},t}(wm);(function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t})(Qh);var $h=.4,eg=[new Sp(.738768,.874946),new Sp(2.42204,2.65704),new Sp(4.30971,7.04493),new Sp(10.246,4.59428),new Sp(12.6868,11.8741)],tg=[new Sp(1.603231,2.094468),new Sp(6.041143,7.080126),new Sp(2.882459,3.518061),new Sp(4.266906,5.178857),new Sp(9.041765,10.66308)],ng=[117.001,114.697,97.404],rg=`tiny_yolov2_model`,ig=`tiny_yolov2_separable_conv_model`,ag=function(e){return typeof e==`number`};function og(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(!ag(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 ag(e.x)&&ag(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(ag)))throw Error(`config.meanRgb has to be an array of shape [number, number, number], have: `+JSON.stringify(e.meanRgb))}function sg(e){return H(function(){var t=$c(e,G(.10000000149011612));return zc(vu(il(e,t)),t)})}function cg(e,t){return H(function(){var n=yr(e,[[0,0],[1,1],[1,1],[0,0]]);return n=Dl(n,t.conv.filters,[1,1],`valid`),n=il(n,t.bn.sub),n=$c(n,t.bn.truediv),n=zc(n,t.conv.bias),sg(n)})}function lg(e,t){return H(function(){var n=yr(e,[[0,0],[1,1],[1,1],[0,0]]);return n=Pl(n,t.depthwise_filter,t.pointwise_filter,[1,1],`valid`),n=zc(n,t.bias),sg(n)})}function ug(e,t){var n=Am(e,t);function r(n,r){var i=An(e(n)),a=An(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:Nm(e,t)}}function dg(e,t,n,r){var i=Im(e),a=i.extractWeights,o=i.getRemainingWeights,s=[],c=ug(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 fg(e,t){var n=Fm(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:Pm(n)}}function pg(e,t){var n=[],r=fg(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 km(e,n),{params:s,paramMappings:n}}var mg;(function(e){e[e.XS=224]=`XS`,e[e.SM=320]=`SM`,e[e.MD=416]=`MD`,e[e.LG=608]=`LG`})(mg||={});var hg=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}(),gg=function(e){Z(t,e);function t(t){var n=e.call(this,`TinyYolov2`)||this;return og(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=cg(e,t.conv0);return n=ql(n,[2,2],[2,2],`same`),n=cg(n,t.conv1),n=ql(n,[2,2],[2,2],`same`),n=cg(n,t.conv2),n=ql(n,[2,2],[2,2],`same`),n=cg(n,t.conv3),n=ql(n,[2,2],[2,2],`same`),n=cg(n,t.conv4),n=ql(n,[2,2],[2,2],`same`),n=cg(n,t.conv5),n=ql(n,[2,2],[1,1],`same`),n=cg(n,t.conv6),n=cg(n,t.conv7),Om(n,t.conv8,`valid`,!1)},t.prototype.runMobilenet=function(e,t){var n=this.config.isFirstLayerConv2d?sg(Om(e,t.conv0,`valid`,!1)):lg(e,t.conv0);return n=ql(n,[2,2],[2,2],`same`),n=lg(n,t.conv1),n=ql(n,[2,2],[2,2],`same`),n=lg(n,t.conv2),n=ql(n,[2,2],[2,2],`same`),n=lg(n,t.conv3),n=ql(n,[2,2],[2,2],`same`),n=lg(n,t.conv4),n=ql(n,[2,2],[2,2],`same`),n=lg(n,t.conv5),n=ql(n,[2,2],[1,1],`same`),n=t.conv6?lg(n,t.conv6):n,n=t.conv7?lg(n,t.conv7):n,Om(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?Ap(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,_m(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 hg(t),r=n.inputSize,i=n.scoreThreshold,[4,_m(e)];case 1:return a=_.sent(),[4,this.forwardInput(a,r)];case 2:return o=_.sent(),s=H(function(){return Pr(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=kp(u.map(function(e){return e.rescale(r)}),d,this.config.iouThreshold,!0),h=m.map(function(e){return new Tp(d[e],f[e],p[e],u[e],c)}),[2,h]}})})},t.prototype.getDefaultModelName=function(){return``},t.prototype.extractParamsFromWeigthMap=function(e){return pg(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 dg(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?ni(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=Mp(h[_][v][y][0]),!n||b>n?(x=(v+Mp(g[_][v][y][0]))/c*o,S=(_+Mp(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(op({box:new wp(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}(wm),_g=function(e){Z(t,e);function t(t){t===void 0&&(t=!0);var n=this,r=Object.assign({},{withSeparableConvs:t,iouThreshold:$h,classes:[`face`]},t?{anchors:tg,meanRgb:ng}:{anchors:eg,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 Ep(e.score,e.relativeBox,{width:e.imageWidth,height:e.imageHeight})})]}})})},t.prototype.getDefaultModelName=function(){return this.withSeparableConvs?ig:rg},t.prototype.extractParamsFromWeigthMap=function(t){return e.prototype.extractParamsFromWeigthMap.call(this,t)},t}(gg),vg=function(e){Z(t,e);function t(){var t=e!==null&&e.apply(this,arguments)||this;return t._name=`TinyFaceDetectorOptions`,t}return t}(hg),yg=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 bg(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 Qm(e)?i(e):e.detection}),s=r,s?[3,5]:t instanceof Ve?[4,ym(t,a)]:[3,2];case 1:return c=u.sent(),[3,4];case 2:return[4,vm(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 Ve&&e.dispose()}),[2,l]}})})}function xg(e,t,n,r,i){return Q(this,void 0,void 0,function(){var a=this;return $(this,function(o){return[2,bg([e],t,function(e){return Q(a,void 0,void 0,function(){return $(this,function(t){return[2,n(e[0])]})})},r,i)]})})}function Sg(e){return H(function(){return jr(Pr(e,3).reverse(),3)})}function Cg(e,t){var n=Am(e,t),r=jm(e,t);function i(n,r){var i=An(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 op(op({},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 op(op({},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 op(op({},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 wg(e){var t=Im(e),n=t.extractWeights,r=t.getRemainingWeights,i=[],a=Cg(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 Tg(e,t){var n=Fm(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 op(op({},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 op(op({},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 op(op({},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 Eg(e){var t=[],n=Tg(e,t),r=n.extractPNetParams,i=n.extractRNetParams,a=n.extractONetParams,o=r(),s=i(),c=a();return km(e,t),{params:{pnet:o,rnet:s,onet:c},paramMappings:t}}function Dg(e,t){var n=t[0],r=t[1];return{height:Math.floor(n*e),width:Math.floor(r*e)}}function Og(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 kg=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}(Cp);function Ag(e){return H(function(){return $c(il(e,G(127.5)),G(.0078125))})}function jg(e,t){return H(function(){return zc(vu(e),$c(t,rc(vu(rc(e)))))})}function Mg(e,t,n){return n===void 0&&(n=!1),H(function(){var r=Om(e,t.conv1,`valid`);return r=jg(r,t.prelu1_alpha),r=ql(r,n?[2,2]:[3,3],[2,2],`same`),r=Om(r,t.conv2,`valid`),r=jg(r,t.prelu2_alpha),r=n?r:ql(r,[3,3],[2,2],`valid`),r=Om(r,t.conv3,`valid`),r=jg(r,t.prelu3_alpha),r})}function Ng(e,t){return H(function(){var n=Mg(e,t,!0),r=Om(n,t.conv4_1,`valid`);return{prob:ni(il(r,hr(lu(r,3),3)),3),regions:Om(n,t.conv4_2,`valid`)}})}function Pg(e,t){return H(function(){var n=Dg(t,e.shape.slice(1)),r=n.height,i=n.width;return xu(Ag(gd.resizeBilinear(e,[r,i])),[0,2,1,3])})}function Fg(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 Sp(s,o));return i.map(function(e){var r=new wp(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 kg(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 Ig(e,t,n,r,i){i.stage1=[];var a=t.map(function(t){return H(function(){var n={scale:t},i=Pg(e,t),a=Date.now(),o=Ng(i,r),s=o.prob,c=o.regions;return n.pnet=Date.now()-a,{scoresTensor:Pr(Pr(s,3)[1])[0],regionsTensor:Pr(c)[0],scale:t,statsForScale:n}})}).map(function(e){var t=e.scoresTensor,r=e.regionsTensor,a=e.scale,o=e.statsForScale,s=Fg(t,r,a,n);if(t.dispose(),r.dispose(),!s.length)return i.stage1.push(o),[];var c=Date.now(),l=kp(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=kp(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 wp(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 Lg(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=rm(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,tm.isNodejs()?fm(u):createImageBitmap(u)]})})}))];case 1:return a=c.sent(),o=[],a.forEach(function(e){var t=rm(dm({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 Ag(xu(Nn(e,[1,r,i,3]),[0,2,1,3]).toFloat())})})]}})})}function Rg(e,t){return H(function(){var n=Mg(e,t),r=jg(Um(Or(n,[n.shape[0],t.fc1.weights.shape[0]]),t.fc1),t.prelu4_alpha),i=Um(r,t.fc2_1),a=ni(il(i,hr(lu(i,1),1)),1),o=Um(r,t.fc2_2);return{scores:Pr(a,1)[1],regions:o}})}function zg(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,Lg(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=Rg(e,r);return e.dispose(),t}),i.stage2_rnet=Date.now()-a,c=s.length>1?Wn(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(),_=kp(p,m,.7),i.stage2_nms=Date.now()-a,v=_.map(function(e){var t=s[f[e]].regions.arraySync();return new kg(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 Bg(e,t){return H(function(){var n=Mg(e,t);n=ql(n,[2,2],[2,2],`same`),n=Om(n,t.conv4,`valid`),n=jg(n,t.prelu4_alpha);var r=jg(Um(Or(n,[n.shape[0],t.fc1.weights.shape[0]]),t.fc1),t.prelu5_alpha),i=Um(r,t.fc2_1),a=ni(il(i,hr(lu(i,1),1)),1),o=Um(r,t.fc2_2),s=Um(r,t.fc2_3);return{scores:Pr(a,1)[1],regions:o,points:s}})}function Vg(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,Lg(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=Bg(e,r);return e.dispose(),t}),i.stage3_onet=Date.now()-a,c=s.length>1?Wn(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 kg(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=kp(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 Sp(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 Hg=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 Sg(hr(Bf.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 Ph(t),f=d.minFaceSize,p=d.scaleFactor,m=d.maxNumScales,h=d.scoreThresholds,g=d.scaleSteps,_=(g||Og(f,p,[l,u])).filter(function(e){var t=Dg(e,[l,u]);return Math.min(t.width,t.height)>12}).slice(0,m),i.scales=_,i.pyramid=_.map(function(e){return Dg(e,[l,u])}),v=Date.now(),[4,Ig(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,zg(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,Vg(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 $m(Wp({},new Ep(x.scores[t],new Np(e.left/u,e.top/l,e.width/u,e.height/l),{height:l,width:u})),new Rp(x.points[t].map(function(t){return t.sub(new Sp(e.left,e.top)).div(new Sp(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,_m(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,_m(e)];case 1:return[2,n.apply(this,[r.sent(),t])]}})})},t.prototype.getDefaultModelName=function(){return`mtcnn_model`},t.prototype.extractParamsFromWeigthMap=function(e){return Eg(e)},t.prototype.extractParams=function(e){return wg(e)},t}(wm),Ug=.4,Wg=[new Sp(1.603231,2.094468),new Sp(6.041143,7.080126),new Sp(2.882459,3.518061),new Sp(4.266906,5.178857),new Sp(9.041765,10.66308)],Gg=[117.001,114.697,97.404],Kg=function(e){Z(t,e);function t(){var t=this,n={withSeparableConvs:!0,iouThreshold:Ug,classes:[`face`],anchors:Wg,meanRgb:Gg,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 Ep(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}(gg),qg={ssdMobilenetv1:new Qh,tinyFaceDetector:new Kg,tinyYolov2:new _g,mtcnn:new Hg,faceLandmark68Net:new mh,faceLandmark68TinyNet:new vh,faceRecognitionNet:new Ah,faceExpressionNet:new Xm,ageGenderNet:new fh},Jg=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}(yg),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,n=this;return $(this,function(r){switch(r.label){case 0:return[4,this.parentTask];case 1:return e=r.sent(),[4,bg(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 qg.faceExpressionNet.predictExpressions(e)}))];case 1:return[2,t.sent()]}})})},this.extractedFaces)];case 2:return t=r.sent(),[2,e.map(function(e,n){return Zm(e,t[n])})]}})})},t.prototype.withAgeAndGender=function(){return new e_(this,this.input)},t}(Jg),Xg=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,xg(e,this.input,function(e){return qg.faceExpressionNet.predictExpressions(e)},this.extractedFaces)]:[2];case 2:return t=n.sent(),[2,Zm(e,t)]}})})},t.prototype.withAgeAndGender=function(){return new t_(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.withFaceDescriptors=function(){return new a_(this,this.input)},t}(Yg),Qg=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withAgeAndGender=function(){return new r_(this,this.input)},t.prototype.withFaceDescriptor=function(){return new o_(this,this.input)},t}(Xg),$g=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}(yg),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=this;return $(this,function(r){switch(r.label){case 0:return[4,this.parentTask];case 1:return e=r.sent(),[4,bg(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 qg.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 Mh(Nh(e,a,o),i)})]}})})},t.prototype.withFaceExpressions=function(){return new Yg(this,this.input)},t}($g),t_=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,xg(e,this.input,function(e){return qg.ageGenderNet.predictAgeAndGender(e)},this.extractedFaces)]:[2];case 2:return t=a.sent(),n=t.age,r=t.gender,i=t.genderProbability,[2,Mh(Nh(e,r,i),n)]}})})},t.prototype.withFaceExpressions=function(){return new Xg(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.withFaceDescriptors=function(){return new a_(this,this.input)},t}(e_),r_=function(e){Z(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.withFaceExpressions=function(){return new Qg(this,this.input)},t.prototype.withFaceDescriptor=function(){return new o_(this,this.input)},t}(t_),i_=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}(yg),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(),[4,bg(e,this.input,function(e){return Promise.all(e.map(function(e){return qg.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 jh(e[n],t)})]}})})},t.prototype.withFaceExpressions=function(){return new Zg(this,this.input)},t.prototype.withAgeAndGender=function(){return new n_(this,this.input)},t}(i_),o_=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,xg(e,this.input,function(e){return qg.faceRecognitionNet.computeFaceDescriptor(e)},null,function(e){return e.landmarks.align(null,{useDlibAlignment:!0})})]:[2];case 2:return t=n.sent(),[2,jh(e,t)]}})})},t.prototype.withFaceExpressions=function(){return new Qg(this,this.input)},t.prototype.withAgeAndGender=function(){return new r_(this,this.input)},t}(i_),s_=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?qg.faceLandmark68TinyNet:qg.faceLandmark68Net},enumerable:!0,configurable:!0}),t}(yg),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,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 Ve?[4,ym(this.input,t)]:[3,3];case 2:return r=o.sent(),[3,5];case 3:return[4,vm(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 Ve&&e.dispose()}),[2,e.map(function(e,t){return $m(e,i[t])})]}})})},t.prototype.withFaceExpressions=function(){return new Zg(this,this.input)},t.prototype.withAgeAndGender=function(){return new n_(this,this.input)},t.prototype.withFaceDescriptors=function(){return new a_(this,this.input)},t}(s_),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,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 Ve?[4,ym(this.input,[t])]:[3,3]):[2];case 2:return r=a.sent(),[3,5];case 3:return[4,vm(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 Ve&&e.dispose()}),[2,$m(e,i)]}})})},t.prototype.withFaceExpressions=function(){return new Qg(this,this.input)},t.prototype.withAgeAndGender=function(){return new r_(this,this.input)},t.prototype.withFaceDescriptor=function(){return new o_(this,this.input)},t}(s_),u_=function(e){Z(t,e);function t(t,n){n===void 0&&(n=new Zh);var r=e.call(this)||this;return r.input=t,r.options=n,r}return t}(yg),d_=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 Ph?[4,qg.mtcnn.forward(t,n)]:[3,2];case 1:return[2,i.sent().map(function(e){return e.detection})];case 2:if(r=n instanceof vg?function(e){return qg.tinyFaceDetector.locateFaces(e,n)}:n instanceof Zh?function(e){return qg.ssdMobilenetv1.locateFaces(e,n)}:n instanceof hg?function(e){return qg.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 Wp({},e)}))]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new c_(this.runAndExtendWithFaceDetections(),this.input,e)},t.prototype.withFaceExpressions=function(){return new Yg(this.runAndExtendWithFaceDetections(),this.input)},t.prototype.withAgeAndGender=function(){return new e_(this.runAndExtendWithFaceDetections(),this.input)},t}(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;return $(this,function(n){switch(n.label){case 0:return[4,new d_(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?Wp({},e):void 0)]}})})})},t.prototype.withFaceLandmarks=function(e){return e===void 0&&(e=!1),new l_(this.runAndExtendWithFaceDetection(),this.input,e)},t.prototype.withFaceExpressions=function(){return new Xg(this.runAndExtendWithFaceDetection(),this.input)},t.prototype.withAgeAndGender=function(){return new t_(this.runAndExtendWithFaceDetection(),this.input)},t})(u_);function f_(e,t){return t===void 0&&(t=new Zh),new d_(e,t)}function p_(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 Hp)return e;if(e instanceof Float32Array)return new Hp(i(),[e]);if(e.descriptor&&e.descriptor instanceof Float32Array)return new Hp(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 p_(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 Bp(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 Bp(`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 Hp.fromJSON(e)}),t.distanceThreshold)},e})();function m_(e){return Math.max(0,Math.min(1,e))}function h_(e){let t=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],s=e[5];return(t(r,s)+t(i,o))/(2*t(n,a))}function g_(e,t,n){return!t||t<=0?e:new Promise((r,i)=>{let a=setTimeout(()=>i(n()),t);e.then(e=>{clearTimeout(a),r(e)},e=>{clearTimeout(a),i(e)})})}function __(){let e=!1;return{load:async(t,n)=>{if(!e)try{let r=n?.timeoutMs??15e3;await g_(qg.tinyFaceDetector.loadFromUri(t),r,()=>({code:`MODEL_LOAD_TIMEOUT`,message:`Timeout ao carregar modelo TinyFaceDetector em: ${t}`})),await g_(qg.faceLandmark68TinyNet.loadFromUri(t),r,()=>({code:`MODEL_LOAD_TIMEOUT`,message:`Timeout ao carregar modelo faceLandmark68TinyNet em: ${t}`})),e=!0}catch(e){throw e?.code===`MODEL_LOAD_TIMEOUT`?e:{code:`MODEL_LOAD_FAILED`,message:`Falha ao carregar modelos face-api.js em: ${t}`,cause:e}}},detect:async(t,n)=>{if(!e)return{faces:0};let r=new vg({inputSize:416,scoreThreshold:.5}),i=t.videoWidth||1,a=t.videoHeight||1;if(n?.withLandmarks){let e=await f_(t,r).withFaceLandmarks(!0);if(!e||e.length===0)return{faces:0};if(e.length>1)return{faces:e.length};let n=e[0].detection.box,o=e[0].landmarks,s=o.getLeftEye(),c=o.getRightEye(),l=e=>e.map(e=>({x:m_(e.x/i),y:m_(e.y/a)})),u=e=>e.reduce((t,n)=>({x:t.x+n.x/e.length,y:t.y+n.y/e.length}),{x:0,y:0}),d=u(s),f=u(c),p=Math.hypot(d.x-f.x,d.y-f.y),m=h_(s),h=h_(c),g=e=>m_((e-.16)/.12),_=n.x/i,v=n.y/a,y=n.width/i,b=n.height/a;return{faces:1,box:{x:_,y:v,width:y,height:b},centerX:m_(_+y/2),area:y*b,leftEyeOpenProb:g(m),rightEyeOpenProb:g(h),leftEyeCenter:{x:m_(d.x/i),y:m_(d.y/a)},rightEyeCenter:{x:m_(f.x/i),y:m_(f.y/a)},eyeDist:m_(p/Math.max(i,a)),leftEyePoints:l(s),rightEyePoints:l(c),poseSource:`landmarks`}}let o=await f_(t,r);if(!o||o.length===0)return{faces:0};if(o.length>1)return{faces:o.length};let s=o[0].box,c=s.x/i,l=s.y/a,u=s.width/i,d=s.height/a;return{faces:1,box:{x:c,y:l,width:u,height:d},centerX:m_(c+u/2),area:u*d,poseSource:`bbox`}}}}function v_(e,t){return{code:e,message:t}}function y_(e){return Math.max(0,Math.min(1,e))}function b_(e){return y_(e?.strictness??.5)}function x_(e){let t=b_(e),n=e?.lookForwardTolerance;return y_(typeof n==`number`?n:1-t)}function S_(e,t,n){if(e.faces===0)return{feedback:v_(`FACE_NOT_FOUND`,`Centralize seu rosto`),valid:!1,frameOk:!1,stepOk:!1};if(e.faces>1)return{feedback:v_(`MULTIPLE_FACES`,`Apenas 1 rosto por vez`),valid:!1,frameOk:!1,stepOk:!1};if(!e.box)return{feedback:v_(`FACE_NOT_FOUND`,`Centralize seu rosto`),valid:!1,frameOk:!1,stepOk:!1};let r=b_(t),i=x_(t),{x:a,y:o,width:s,height:c}=e.box,l=a+s/2,u=o+c/2,d=e.area??s*c,f=s/Math.max(1e-6,c),p=.07+r*.02,m=.22-r*.03;if(d<p)return{feedback:v_(`FACE_TOO_FAR`,`Aproxime o rosto`),valid:!1,frameOk:!1,stepOk:!1};if(d>m)return{feedback:v_(`FACE_TOO_CLOSE`,`Afaste o rosto`),valid:!1,frameOk:!1,stepOk:!1};let h=.12-r*.03;if(Math.abs(l-.5)>h||Math.abs(u-.5)>h)return{feedback:v_(`FACE_OFF_CENTER`,`Centralize seu rosto`),valid:!1,frameOk:!1,stepOk:!1};let g=t?.requireLookForward!==!1,_=(t?.challenges?.length??0)>0,v=g&&!_,y=.1-r*.02,b=typeof t?.lookForwardCenterTol==`number`?y_(t.lookForwardCenterTol):y_(y+i*.08),x=t?.minEyeDistance??.06,S=(t?.maxEyeSymmetryError??.1-r*.03)+i*.1,C=.74+r*.1,w=typeof t?.minFrontalRatio==`number`?Math.max(.5,t.minFrontalRatio):Math.max(.52,C-i*.18),T=!!e.leftEyeCenter&&!!e.rightEyeCenter&&typeof e.eyeDist==`number`,E=e.eyeDist??0,D=T?Math.abs(Math.abs(e.leftEyeCenter.x-(e.centerX??l))-Math.abs(e.rightEyeCenter.x-(e.centerX??l)))/Math.max(1e-6,E):null,O=.78+r*.12;Math.max(.55,O-i*.18);let k=()=>{let t=Math.abs((e.centerX??l)-.5)>b,n=f>=w,r=!1,i=!1;return T&&E>=x&&D!=null?r=D>S||!n:(i=!0,r=!n),{ok:!t&&!r,usedFallback:i}};if(v){let e=k();if(!e.ok)return{feedback:v_(`LOOK_FORWARD`,e.usedFallback?`Olhe para a câmera (aproxime/ilumine para melhor detecção)`:`Olhe para a câmera`),valid:!1,frameOk:!1,stepOk:!1}}let A=n?.current??null;if(!A)return{feedback:v_(`READY`,`Pronto para capturar`),valid:!0,frameOk:!0,stepOk:!0};let j=t?.lookSideTol??.18-r*.05,M=t?.lookUpDownTol??.12-r*.03,N=t?.zoomInMinArea??.16+r*.02,P=t?.zoomOutMaxArea??.12-r*.02,F=t?.blinkClosedThreshold??.35;if(A===`lookForward`){let e=k();return{feedback:v_(`LOOK_FORWARD`,e.usedFallback?`Olhe para a câmera (aproxime/ilumine para melhor detecção)`:`Olhe para a câmera`),valid:e.ok,frameOk:!0,stepOk:e.ok}}if(A===`lookUp`){let e=(u??.5)<.5-M;return{feedback:v_(`LOOK_UP`,`Olhe para cima`),valid:e,frameOk:!0,stepOk:e}}if(A===`lookDown`){let e=(u??.5)>.5+M;return{feedback:v_(`LOOK_DOWN`,`Olhe para baixo`),valid:e,frameOk:!0,stepOk:e}}if(A===`lookLeft`){let t=(e.centerX??l)<.5-j;return{feedback:v_(`LOOK_LEFT`,`Olhe para a esquerda`),valid:t,frameOk:!0,stepOk:t}}if(A===`lookRight`){let t=(e.centerX??l)>.5+j;return{feedback:v_(`LOOK_RIGHT`,`Olhe para a direita`),valid:t,frameOk:!0,stepOk:t}}if(A===`zoomIn`){let e=d>N;return{feedback:v_(`ZOOM_IN`,`Aproxime (zoom in)`),valid:e,frameOk:!0,stepOk:e}}if(A===`zoomOut`){let e=d<P;return{feedback:v_(`ZOOM_OUT`,`Afaste (zoom out)`),valid:e,frameOk:!0,stepOk:e}}if(A===`blink`){let t=e.leftEyeOpenProb,n=e.rightEyeOpenProb,r=typeof t==`number`&&typeof n==`number`&&t<F&&n<F;return{feedback:v_(`BLINK`,`Pisque`),valid:!!r,frameOk:!0,stepOk:!!r}}return{feedback:v_(`READY`,`Pronto para capturar`),valid:!0,frameOk:!0,stepOk:!0}}e.AlphaValid=class{_camera=null;_overlay=null;_container=null;_faceDetector=__();_loopTimer=null;_lastStatusValid=!1;_options=null;_challengeIndex=0;_challengeStartedAt=null;_blinkArmed=!1;_state=null;_status=`idle`;async start(e){n(e.container,`options.container`),await this.stop(),this._options={overlay:!0,uiMode:`default`,guideCircleRatio:.72,detectionIntervalMs:200,modelsPath:`/alphavalid-models`,...e},this._container=this._options.container,this._status=`initializing`,e.onStateChange?.({status:this._status,feedback:{code:`INITIALIZING`,message:`Inicializando câmera...`},message:`Inicializando câmera...`,isReadyToCapture:!1,challenge:{enabled:!1,index:0,total:0,completed:!1}});try{this._options.onFeedback?.({code:`INITIALIZING`,message:`Inicializando câmera...`}),this._camera=await i(this._container),this._options.onVideo?.(this._camera.video),this._options.uiMode!==`headless`&&this._options.overlay!==!1&&(this._overlay=o(this._container,this._options.guideCircleRatio)),this._options.onReady?.(),this._options.modelsPath&&await this._faceDetector.load(this._options.modelsPath,{timeoutMs:this._options.modelLoadTimeoutMs??15e3}),this._status=`running`,this.startDetectionLoop()}catch(e){this._status=`error`;let t=e,n=t&&typeof t==`object`&&typeof t.code==`string`&&typeof t.message==`string`?t:{code:`CAMERA_UNKNOWN`,message:`Erro inesperado ao iniciar o SDK.`,cause:e};throw this._options?.onError?.(n),this._options?.onStateChange?.({status:this._status,feedback:{code:`FACE_NOT_FOUND`,message:`Centralize seu rosto`},message:`Centralize seu rosto`,isReadyToCapture:!1,challenge:{enabled:!1,index:0,total:0,completed:!1}}),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,this._challengeIndex=0,this._challengeStartedAt=null,this._blinkArmed=!1,this._state=null,this._status=`idle`}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 a(this._camera.video,.9)}getState(){return this._state}getCurrentChallenge(){let e=this._options?.liveness?.challenges;return!e||e.length===0?null:e[Math.min(this._challengeIndex,e.length-1)]?.type??null}markStepCompletedIfNeeded(e){let t=this._options,n=t?.liveness?.challenges;if(!t||!n||n.length===0)return;let r=this.getCurrentChallenge();if(!r)return;let i=n[this._challengeIndex];if(i?.timeoutMs&&this._challengeStartedAt!=null&&Date.now()-this._challengeStartedAt>i.timeoutMs){this._challengeStartedAt=Date.now(),this._blinkArmed=!1;return}if(r===`blink`){if(!this._blinkArmed){e||(this._blinkArmed=!0);return}if(!e)return}else if(!e)return;this._challengeIndex+=1,this._challengeStartedAt=Date.now(),this._blinkArmed=!1}startDetectionLoop(){let e=async()=>{let t=this._camera,n=this._options;if(!(!t||!n))try{let e=this.getCurrentChallenge(),r=e===`blink`||n.liveness?.requireLookForward!==!1,i=await this._faceDetector.detect(t.video,{withLandmarks:r}),a=n.liveness?.challenges,o=!!a&&a.length>0;o&&this._challengeStartedAt==null&&(this._challengeStartedAt=Date.now());let s=S_(i,n.liveness,{current:e});this.markStepCompletedIfNeeded(s.stepOk);let c=!o||this._challengeIndex>=(a?.length??0),l=s.frameOk&&c;this._lastStatusValid=l,this._status=l?`ready`:`running`;let u={status:this._status,feedback:s.feedback,message:s.feedback.message,isReadyToCapture:l,challenge:{enabled:o,index:Math.min(this._challengeIndex,a?.length??0),total:a?.length??0,current:c?void 0:this.getCurrentChallenge()??void 0,completed:c}};this._state=u,n.onStateChange?.(u),n.onFeedback?.(s.feedback);let d=n.debug?.drawLandmarks===!0;this._overlay?.render({message:s.feedback.message,box:i.box,valid:l,landmarks:d?{leftEye:i.leftEyePoints,rightEye:i.rightEyePoints,leftEyeCenter:i.leftEyeCenter,rightEyeCenter:i.rightEyeCenter}:void 0})}catch(e){this._status=`error`;let t=e,r=t&&typeof t==`object`&&typeof t.code==`string`&&typeof t.message==`string`?t:{code:`CAMERA_UNKNOWN`,message:`Erro durante detecção/validação.`,cause:e};n.onError?.(r),n.onStateChange?.({status:this._status,feedback:{code:`FACE_NOT_FOUND`,message:`Centralize seu rosto`},message:`Centralize seu rosto`,isReadyToCapture:!1,challenge:this._state?.challenge})}finally{this._loopTimer=window.setTimeout(e,n.detectionIntervalMs??200)}};e()}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feedback.d.ts","sourceRoot":"","sources":["../../src/core/feedback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAElB,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;CACjB;
|
|
1
|
+
{"version":3,"file":"feedback.d.ts","sourceRoot":"","sources":["../../src/core/feedback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAElB,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;CACjB;AAsBD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,mBAAmB,EAC3B,QAAQ,CAAC,EAAE,yBAAyB,EACpC,SAAS,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,IAAI,CAAA;CAAE,GACvD,cAAc,CAuLhB"}
|
package/dist/types/sdk.d.ts
CHANGED
|
@@ -12,10 +12,35 @@ export interface AlphaValidLivenessOptions {
|
|
|
12
12
|
challenges?: AlphaValidChallengeStep[];
|
|
13
13
|
/** How strict are heuristics (0..1). Higher is stricter. Default: 0.5 */
|
|
14
14
|
strictness?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Optional: tolerance for look-forward check (0..1). Higher is more tolerant (easier to pass).
|
|
17
|
+
* If omitted, it is derived from `strictness`.
|
|
18
|
+
*/
|
|
19
|
+
lookForwardTolerance?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Optional: minimum frontal face box ratio (width/height) required to consider the pose frontal.
|
|
22
|
+
* Lower values are more permissive (but may accept profile). If omitted, computed from strictness.
|
|
23
|
+
*/
|
|
24
|
+
minFrontalRatio?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Optional: maximum horizontal offset allowed for look-forward (0..1) relative to center.
|
|
27
|
+
* Higher values are more permissive. If omitted, computed from strictness/tolerance.
|
|
28
|
+
*/
|
|
29
|
+
lookForwardCenterTol?: number;
|
|
15
30
|
/** Optional: minimum normalized inter-eye distance required to evaluate look-forward robustly. Default: 0.06 */
|
|
16
31
|
minEyeDistance?: number;
|
|
17
32
|
/** Optional: maximum allowed eye symmetry error. Lower = stricter. Default: derived from strictness. */
|
|
18
33
|
maxEyeSymmetryError?: number;
|
|
34
|
+
/** Optional: threshold for lookLeft/lookRight centerX offset. If omitted, derived from strictness. */
|
|
35
|
+
lookSideTol?: number;
|
|
36
|
+
/** Optional: threshold for lookUp/lookDown face center offset. If omitted, derived from strictness. */
|
|
37
|
+
lookUpDownTol?: number;
|
|
38
|
+
/** Optional: face area threshold (normalized) to satisfy zoomIn. If omitted, derived from strictness. */
|
|
39
|
+
zoomInMinArea?: number;
|
|
40
|
+
/** Optional: face area threshold (normalized) to satisfy zoomOut. If omitted, derived from strictness. */
|
|
41
|
+
zoomOutMaxArea?: number;
|
|
42
|
+
/** Optional: blink eye-open probability threshold. Lower = more permissive. Default: 0.35 */
|
|
43
|
+
blinkClosedThreshold?: number;
|
|
19
44
|
}
|
|
20
45
|
export type AlphaValidErrorCode = 'CAMERA_PERMISSION_DENIED' | 'CAMERA_NOT_FOUND' | 'CAMERA_NOT_READABLE' | 'CAMERA_OVERCONSTRAINED' | 'CAMERA_NOT_SUPPORTED' | 'CAMERA_UNKNOWN' | 'MODEL_LOAD_FAILED' | 'MODEL_LOAD_TIMEOUT';
|
|
21
46
|
export interface AlphaValidSdkError {
|
package/dist/types/sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/types/sdk.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,yBAAyB,GACjC,yBAAyB,GACzB,sBAAsB,GACtB,kBAAkB,GAClB,gBAAgB,GAChB,qBAAqB,GACrB,wBAAwB,GACxB,iBAAiB,GACjB,sBAAsB,GACtB,oBAAoB,GACpB,gBAAgB,GAChB,iBAAiB,GACjB,sBAAsB,GACtB,qBAAqB,GACrB,oBAAoB,GACpB,mBAAmB,GACnB,QAAQ,CAAC;AAEb,MAAM,MAAM,uBAAuB,GAC/B,aAAa,GACb,QAAQ,GACR,UAAU,GACV,UAAU,GACV,WAAW,GACX,QAAQ,GACR,SAAS,GACT,OAAO,CAAC;AAEZ,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,qFAAqF;IACrF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,yBAAyB;IACxC,+FAA+F;IAC/F,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,oHAAoH;IACpH,UAAU,CAAC,EAAE,uBAAuB,EAAE,CAAC;IAEvC,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,gHAAgH;IAChH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,wGAAwG;IACxG,mBAAmB,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/types/sdk.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,yBAAyB,GACjC,yBAAyB,GACzB,sBAAsB,GACtB,kBAAkB,GAClB,gBAAgB,GAChB,qBAAqB,GACrB,wBAAwB,GACxB,iBAAiB,GACjB,sBAAsB,GACtB,oBAAoB,GACpB,gBAAgB,GAChB,iBAAiB,GACjB,sBAAsB,GACtB,qBAAqB,GACrB,oBAAoB,GACpB,mBAAmB,GACnB,QAAQ,CAAC;AAEb,MAAM,MAAM,uBAAuB,GAC/B,aAAa,GACb,QAAQ,GACR,UAAU,GACV,UAAU,GACV,WAAW,GACX,QAAQ,GACR,SAAS,GACT,OAAO,CAAC;AAEZ,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,qFAAqF;IACrF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,yBAAyB;IACxC,+FAA+F;IAC/F,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,oHAAoH;IACpH,UAAU,CAAC,EAAE,uBAAuB,EAAE,CAAC;IAEvC,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,gHAAgH;IAChH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,wGAAwG;IACxG,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B,sGAAsG;IACtG,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,uGAAuG;IACvG,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,yGAAyG;IACzG,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,0GAA0G;IAC1G,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,6FAA6F;IAC7F,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,MAAM,mBAAmB,GAC3B,0BAA0B,GAC1B,kBAAkB,GAClB,qBAAqB,GACrB,wBAAwB,GACxB,sBAAsB,GACtB,gBAAgB,GAChB,mBAAmB,GACnB,oBAAoB,CAAC;AAEzB,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,cAAc,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAEvF,MAAM,MAAM,sBAAsB,GAC9B,cAAc,GACd,gBAAgB,GAChB,gBAAgB,GAChB,cAAc,GACd,gBAAgB,GAChB,iBAAiB,GACjB,cAAc,GACd,SAAS,GACT,WAAW,GACX,WAAW,GACX,YAAY,GACZ,SAAS,GACT,UAAU,GACV,OAAO,GACP,OAAO,CAAC;AAEZ,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,WAAW,CAAC;IAEvB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAErB,mEAAmE;IACnE,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAEpD,4DAA4D;IAC5D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAE9C,6DAA6D;IAC7D,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,4EAA4E;IAC5E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,yDAAyD;IACzD,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,yBAAyB,CAAC;IAErC,8FAA8F;IAC9F,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAEjD;;;;OAIG;IACH,MAAM,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;IAEhC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAE5C,mEAAmE;IACnE,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B,iDAAiD;IACjD,KAAK,CAAC,EAAE;QACN,8EAA8E;QAC9E,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;CACH;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,GAAG,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAE9D,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,yDAAyD;IACzD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,oDAAoD;IACpD,aAAa,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,cAAc,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAE1C,6EAA6E;IAC7E,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,4EAA4E;IAC5E,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChD,cAAc,CAAC,EAAE,KAAK,CAAC;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAEjD;;;;OAIG;IACH,UAAU,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;CACnC;AAED,MAAM,WAAW,eAAe;IAC9B,oBAAoB;IACpB,MAAM,EAAE,gBAAgB,CAAC;IAEzB,wCAAwC;IACxC,QAAQ,EAAE,kBAAkB,CAAC;IAE7B,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;IAEhB,8FAA8F;IAC9F,gBAAgB,EAAE,OAAO,CAAC;IAE1B,uCAAuC;IACvC,SAAS,CAAC,EAAE;QACV,OAAO,EAAE,OAAO,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,uBAAuB,CAAC;QAClC,SAAS,EAAE,OAAO,CAAC;KACpB,CAAC;CACH"}
|