@neofaceid/web-sdk 2.1.1 → 2.1.2
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 +5 -4
- package/dist/{biometricDetection-8utmtR25.js → biometricDetection-CR31mETT.js} +15 -1
- package/dist/index.d.ts +1 -1
- package/dist/neoface-id-sdk.es.js +2717 -153
- package/dist/neoface-id-sdk.umd.js +1 -1
- package/dist/{qrcode-DYfGiWu6.js → qrcode-DZJ8v41k.js} +5 -6
- package/package.json +4 -2
|
@@ -4,7 +4,2447 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4
4
|
import React, { useRef, useState, useCallback, useEffect, useReducer, forwardRef } from "react";
|
|
5
5
|
import { createRoot } from "react-dom/client";
|
|
6
6
|
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
7
|
-
import
|
|
7
|
+
import "@tensorflow/tfjs-core/dist/public/chained_ops/register_all_chained_ops";
|
|
8
|
+
import "@tensorflow/tfjs-backend-cpu";
|
|
9
|
+
import * as tfjsCore from "@tensorflow/tfjs-core";
|
|
10
|
+
import * as pn from "@tensorflow/tfjs-backend-webgl/dist/index.js";
|
|
11
|
+
function _mergeNamespaces(n2, m) {
|
|
12
|
+
for (var i = 0; i < m.length; i++) {
|
|
13
|
+
const e = m[i];
|
|
14
|
+
if (typeof e !== "string" && !Array.isArray(e)) {
|
|
15
|
+
for (const k2 in e) {
|
|
16
|
+
if (k2 !== "default" && !(k2 in n2)) {
|
|
17
|
+
const d = Object.getOwnPropertyDescriptor(e, k2);
|
|
18
|
+
if (d) {
|
|
19
|
+
Object.defineProperty(n2, k2, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: () => e[k2]
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return Object.freeze(Object.defineProperty(n2, Symbol.toStringTag, { value: "Module" }));
|
|
29
|
+
}
|
|
30
|
+
const mn = /* @__PURE__ */ _mergeNamespaces({
|
|
31
|
+
__proto__: null
|
|
32
|
+
}, [tfjsCore]);
|
|
33
|
+
const un = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
34
|
+
__proto__: null
|
|
35
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
36
|
+
var ur = Object.defineProperty;
|
|
37
|
+
var ho = Object.getOwnPropertyDescriptor;
|
|
38
|
+
var bo = Object.getOwnPropertyNames;
|
|
39
|
+
var go = Object.prototype.hasOwnProperty;
|
|
40
|
+
var xo = ((o9) => typeof require != "undefined" ? require : typeof Proxy != "undefined" ? new Proxy(o9, { get: (t, e) => (typeof require != "undefined" ? require : t)[e] }) : o9)(function(o9) {
|
|
41
|
+
if (typeof require != "undefined") return require.apply(this, arguments);
|
|
42
|
+
throw Error('Dynamic require of "' + o9 + '" is not supported');
|
|
43
|
+
});
|
|
44
|
+
var Ye = (o9, t) => {
|
|
45
|
+
for (var e in t) ur(o9, e, { get: t[e], enumerable: true });
|
|
46
|
+
}, pr = (o9, t, e, r) => {
|
|
47
|
+
if (t && typeof t == "object" || typeof t == "function") for (let a of bo(t)) !go.call(o9, a) && a !== e && ur(o9, a, { get: () => t[a], enumerable: !(r = ho(t, a)) || r.enumerable });
|
|
48
|
+
return o9;
|
|
49
|
+
}, w = (o9, t, e) => (pr(o9, t, "default"), e);
|
|
50
|
+
var n = {};
|
|
51
|
+
Ye(n, { version: () => Po });
|
|
52
|
+
w(n, mn);
|
|
53
|
+
w(n, pn);
|
|
54
|
+
w(n, un);
|
|
55
|
+
var fr = "4.22.0", vo = "4.22.0", yo = "4.22.0", To = "4.22.0", _o = "4.22.0", Po = { tfjs: fr, "tfjs-core": fr, "tfjs-converter": vo, "tfjs-backend-cpu": yo, "tfjs-backend-webgl": To, "tfjs-backend-wasm": _o };
|
|
56
|
+
var Sr = {};
|
|
57
|
+
Ye(Sr, { AnchorPosition: () => Ke, DrawBox: () => ee, DrawBoxOptions: () => de, DrawFaceLandmarks: () => De, DrawFaceLandmarksOptions: () => Fe, DrawTextField: () => xt, DrawTextFieldOptions: () => Wt, drawContour: () => Z, drawDetections: () => Io, drawFaceExpressions: () => No, drawFaceLandmarks: () => So });
|
|
58
|
+
function Z(o9, t, e = false) {
|
|
59
|
+
if (o9.beginPath(), t.slice(1).forEach(({ x: r, y: a }, i) => {
|
|
60
|
+
let s = t[i];
|
|
61
|
+
o9.moveTo(s.x, s.y), o9.lineTo(r, a);
|
|
62
|
+
}), e) {
|
|
63
|
+
let r = t[t.length - 1], a = t[0];
|
|
64
|
+
if (!r || !a) return;
|
|
65
|
+
o9.moveTo(r.x, r.y), o9.lineTo(a.x, a.y);
|
|
66
|
+
}
|
|
67
|
+
o9.stroke();
|
|
68
|
+
}
|
|
69
|
+
var lr = {};
|
|
70
|
+
Ye(lr, { computeReshapedDimensions: () => je, getCenterPoint: () => bt, isDimensions: () => ue, isEven: () => pe, isFloat: () => Ge, isTensor: () => dt, isTensor1D: () => wo, isTensor2D: () => Ve, isTensor3D: () => K, isTensor4D: () => R, isValidNumber: () => G, isValidProbablitiy: () => Mt, range: () => X, round: () => ht });
|
|
71
|
+
var A = class o {
|
|
72
|
+
constructor(t, e) {
|
|
73
|
+
if (!G(t) || !G(e)) throw new Error(`Dimensions.constructor - expected width and height to be valid numbers, instead have ${JSON.stringify({ width: t, height: e })}`);
|
|
74
|
+
this._width = t, this._height = e;
|
|
75
|
+
}
|
|
76
|
+
get width() {
|
|
77
|
+
return this._width;
|
|
78
|
+
}
|
|
79
|
+
get height() {
|
|
80
|
+
return this._height;
|
|
81
|
+
}
|
|
82
|
+
reverse() {
|
|
83
|
+
return new o(1 / this.width, 1 / this.height);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
function dt(o9, t) {
|
|
87
|
+
return o9 instanceof n.Tensor && o9.shape.length === t;
|
|
88
|
+
}
|
|
89
|
+
function wo(o9) {
|
|
90
|
+
return dt(o9, 1);
|
|
91
|
+
}
|
|
92
|
+
function Ve(o9) {
|
|
93
|
+
return dt(o9, 2);
|
|
94
|
+
}
|
|
95
|
+
function K(o9) {
|
|
96
|
+
return dt(o9, 3);
|
|
97
|
+
}
|
|
98
|
+
function R(o9) {
|
|
99
|
+
return dt(o9, 4);
|
|
100
|
+
}
|
|
101
|
+
function Ge(o9) {
|
|
102
|
+
return o9 % 1 !== 0;
|
|
103
|
+
}
|
|
104
|
+
function pe(o9) {
|
|
105
|
+
return o9 % 2 === 0;
|
|
106
|
+
}
|
|
107
|
+
function ht(o9, t = 2) {
|
|
108
|
+
let e = 10 ** t;
|
|
109
|
+
return Math.floor(o9 * e) / e;
|
|
110
|
+
}
|
|
111
|
+
function ue(o9) {
|
|
112
|
+
return o9 && o9.width && o9.height;
|
|
113
|
+
}
|
|
114
|
+
function je({ width: o9, height: t }, e) {
|
|
115
|
+
let r = e / Math.max(t, o9);
|
|
116
|
+
return new A(Math.round(o9 * r), Math.round(t * r));
|
|
117
|
+
}
|
|
118
|
+
function bt(o9) {
|
|
119
|
+
return o9.reduce((t, e) => t.add(e), new v(0, 0)).div(new v(o9.length, o9.length));
|
|
120
|
+
}
|
|
121
|
+
function X(o9, t, e) {
|
|
122
|
+
return Array(o9).fill(0).map((r, a) => t + a * e);
|
|
123
|
+
}
|
|
124
|
+
function G(o9) {
|
|
125
|
+
return !!o9 && o9 !== 1 / 0 && o9 !== -1 / 0 && !Number.isNaN(o9) || o9 === 0;
|
|
126
|
+
}
|
|
127
|
+
function Mt(o9) {
|
|
128
|
+
return G(o9) && o9 >= 0 && o9 <= 1;
|
|
129
|
+
}
|
|
130
|
+
var v = class o2 {
|
|
131
|
+
constructor(t, e) {
|
|
132
|
+
this._x = t, this._y = e;
|
|
133
|
+
}
|
|
134
|
+
get x() {
|
|
135
|
+
return this._x;
|
|
136
|
+
}
|
|
137
|
+
get y() {
|
|
138
|
+
return this._y;
|
|
139
|
+
}
|
|
140
|
+
add(t) {
|
|
141
|
+
return new o2(this.x + t.x, this.y + t.y);
|
|
142
|
+
}
|
|
143
|
+
sub(t) {
|
|
144
|
+
return new o2(this.x - t.x, this.y - t.y);
|
|
145
|
+
}
|
|
146
|
+
mul(t) {
|
|
147
|
+
return new o2(this.x * t.x, this.y * t.y);
|
|
148
|
+
}
|
|
149
|
+
div(t) {
|
|
150
|
+
return new o2(this.x / t.x, this.y / t.y);
|
|
151
|
+
}
|
|
152
|
+
abs() {
|
|
153
|
+
return new o2(Math.abs(this.x), Math.abs(this.y));
|
|
154
|
+
}
|
|
155
|
+
magnitude() {
|
|
156
|
+
return Math.sqrt(this.x ** 2 + this.y ** 2);
|
|
157
|
+
}
|
|
158
|
+
floor() {
|
|
159
|
+
return new o2(Math.floor(this.x), Math.floor(this.y));
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var C = class o3 {
|
|
163
|
+
static isRect(t) {
|
|
164
|
+
return !!t && [t.x, t.y, t.width, t.height].every(G);
|
|
165
|
+
}
|
|
166
|
+
static assertIsValidBox(t, e, r = false) {
|
|
167
|
+
if (!o3.isRect(t)) throw new Error(`${e} - invalid box: ${JSON.stringify(t)}, expected object with properties x, y, width, height`);
|
|
168
|
+
if (!r && (t.width < 0 || t.height < 0)) throw new Error(`${e} - width (${t.width}) and height (${t.height}) must be positive numbers`);
|
|
169
|
+
}
|
|
170
|
+
constructor(t, e = true) {
|
|
171
|
+
let r = t || {}, a = [r.left, r.top, r.right, r.bottom].every(G), i = [r.x, r.y, r.width, r.height].every(G);
|
|
172
|
+
if (!i && !a) throw new Error(`Box.constructor - expected box to be IBoundingBox | IRect, instead have ${JSON.stringify(r)}`);
|
|
173
|
+
let [s, c, m, p] = i ? [r.x, r.y, r.width, r.height] : [r.left, r.top, r.right - r.left, r.bottom - r.top];
|
|
174
|
+
o3.assertIsValidBox({ x: s, y: c, width: m, height: p }, "Box.constructor", e), this._x = s, this._y = c, this._width = m, this._height = p;
|
|
175
|
+
}
|
|
176
|
+
get x() {
|
|
177
|
+
return this._x;
|
|
178
|
+
}
|
|
179
|
+
get y() {
|
|
180
|
+
return this._y;
|
|
181
|
+
}
|
|
182
|
+
get width() {
|
|
183
|
+
return this._width;
|
|
184
|
+
}
|
|
185
|
+
get height() {
|
|
186
|
+
return this._height;
|
|
187
|
+
}
|
|
188
|
+
get left() {
|
|
189
|
+
return this.x;
|
|
190
|
+
}
|
|
191
|
+
get top() {
|
|
192
|
+
return this.y;
|
|
193
|
+
}
|
|
194
|
+
get right() {
|
|
195
|
+
return this.x + this.width;
|
|
196
|
+
}
|
|
197
|
+
get bottom() {
|
|
198
|
+
return this.y + this.height;
|
|
199
|
+
}
|
|
200
|
+
get area() {
|
|
201
|
+
return this.width * this.height;
|
|
202
|
+
}
|
|
203
|
+
get topLeft() {
|
|
204
|
+
return new v(this.left, this.top);
|
|
205
|
+
}
|
|
206
|
+
get topRight() {
|
|
207
|
+
return new v(this.right, this.top);
|
|
208
|
+
}
|
|
209
|
+
get bottomLeft() {
|
|
210
|
+
return new v(this.left, this.bottom);
|
|
211
|
+
}
|
|
212
|
+
get bottomRight() {
|
|
213
|
+
return new v(this.right, this.bottom);
|
|
214
|
+
}
|
|
215
|
+
round() {
|
|
216
|
+
let [t, e, r, a] = [this.x, this.y, this.width, this.height].map((i) => Math.round(i));
|
|
217
|
+
return new o3({ x: t, y: e, width: r, height: a });
|
|
218
|
+
}
|
|
219
|
+
floor() {
|
|
220
|
+
let [t, e, r, a] = [this.x, this.y, this.width, this.height].map((i) => Math.floor(i));
|
|
221
|
+
return new o3({ x: t, y: e, width: r, height: a });
|
|
222
|
+
}
|
|
223
|
+
toSquare() {
|
|
224
|
+
let { x: t, y: e, width: r, height: a } = this, i = Math.abs(r - a);
|
|
225
|
+
return r < a && (t -= i / 2, r += i), a < r && (e -= i / 2, a += i), new o3({ x: t, y: e, width: r, height: a });
|
|
226
|
+
}
|
|
227
|
+
rescale(t) {
|
|
228
|
+
let e = ue(t) ? t.width : t, r = ue(t) ? t.height : t;
|
|
229
|
+
return new o3({ x: this.x * e, y: this.y * r, width: this.width * e, height: this.height * r });
|
|
230
|
+
}
|
|
231
|
+
pad(t, e) {
|
|
232
|
+
let [r, a, i, s] = [this.x - t / 2, this.y - e / 2, this.width + t, this.height + e];
|
|
233
|
+
return new o3({ x: r, y: a, width: i, height: s });
|
|
234
|
+
}
|
|
235
|
+
clipAtImageBorders(t, e) {
|
|
236
|
+
let { x: r, y: a, right: i, bottom: s } = this, c = Math.max(r, 0), m = Math.max(a, 0), p = i - c, u = s - m, f = Math.min(p, t - c), l = Math.min(u, e - m);
|
|
237
|
+
return new o3({ x: c, y: m, width: f, height: l }).floor();
|
|
238
|
+
}
|
|
239
|
+
shift(t, e) {
|
|
240
|
+
let { width: r, height: a } = this, i = this.x + t, s = this.y + e;
|
|
241
|
+
return new o3({ x: i, y: s, width: r, height: a });
|
|
242
|
+
}
|
|
243
|
+
padAtBorders(t, e) {
|
|
244
|
+
let r = this.width + 1, a = this.height + 1, i = 1, s = 1, c = r, m = a, p = this.left, u = this.top, f = this.right, l = this.bottom;
|
|
245
|
+
return f > e && (c = -f + e + r, f = e), l > t && (m = -l + t + a, l = t), p < 1 && (m = 2 - p, p = 1), u < 1 && (m = 2 - u, u = 1), { dy: s, edy: m, dx: i, edx: c, y: u, ey: l, x: p, ex: f, w: r, h: a };
|
|
246
|
+
}
|
|
247
|
+
calibrate(t) {
|
|
248
|
+
return new o3({ 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();
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
var Ct = class extends C {
|
|
252
|
+
constructor(t, e, r, a, i = false) {
|
|
253
|
+
super({ left: t, top: e, right: r, bottom: a }, i);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
var It = class o4 {
|
|
257
|
+
constructor(t, e, r, a, i) {
|
|
258
|
+
this._imageDims = new A(i.width, i.height), this._score = t, this._classScore = e, this._className = r, this._box = new C(a).rescale(this._imageDims);
|
|
259
|
+
}
|
|
260
|
+
get score() {
|
|
261
|
+
return this._score;
|
|
262
|
+
}
|
|
263
|
+
get classScore() {
|
|
264
|
+
return this._classScore;
|
|
265
|
+
}
|
|
266
|
+
get className() {
|
|
267
|
+
return this._className;
|
|
268
|
+
}
|
|
269
|
+
get box() {
|
|
270
|
+
return this._box;
|
|
271
|
+
}
|
|
272
|
+
get imageDims() {
|
|
273
|
+
return this._imageDims;
|
|
274
|
+
}
|
|
275
|
+
get imageWidth() {
|
|
276
|
+
return this.imageDims.width;
|
|
277
|
+
}
|
|
278
|
+
get imageHeight() {
|
|
279
|
+
return this.imageDims.height;
|
|
280
|
+
}
|
|
281
|
+
get relativeBox() {
|
|
282
|
+
return new C(this._box).rescale(this.imageDims.reverse());
|
|
283
|
+
}
|
|
284
|
+
forSize(t, e) {
|
|
285
|
+
return new o4(this.score, this.classScore, this.className, this.relativeBox, { width: t, height: e });
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
var D = class o5 extends It {
|
|
289
|
+
constructor(t, e, r) {
|
|
290
|
+
super(t, t, "", e, r);
|
|
291
|
+
}
|
|
292
|
+
forSize(t, e) {
|
|
293
|
+
let { score: r, relativeBox: a, imageDims: i } = super.forSize(t, e);
|
|
294
|
+
return new o5(r, a, i);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
function dr(o9, t, e = true) {
|
|
298
|
+
let r = Math.max(0, Math.min(o9.right, t.right) - Math.max(o9.left, t.left)), a = Math.max(0, Math.min(o9.bottom, t.bottom) - Math.max(o9.top, t.top)), i = r * a;
|
|
299
|
+
return e ? i / (o9.area + t.area - i) : i / Math.min(o9.area, t.area);
|
|
300
|
+
}
|
|
301
|
+
function hr(o9) {
|
|
302
|
+
let t = o9.map((c) => c.x), e = o9.map((c) => c.y), r = t.reduce((c, m) => m < c ? m : c, 1 / 0), a = e.reduce((c, m) => m < c ? m : c, 1 / 0), i = t.reduce((c, m) => c < m ? m : c, 0), s = e.reduce((c, m) => c < m ? m : c, 0);
|
|
303
|
+
return new Ct(r, a, i, s);
|
|
304
|
+
}
|
|
305
|
+
function br(o9, t, e, r = true) {
|
|
306
|
+
let a = t.map((s, c) => ({ score: s, boxIndex: c })).sort((s, c) => s.score - c.score).map((s) => s.boxIndex), i = [];
|
|
307
|
+
for (; a.length > 0; ) {
|
|
308
|
+
let s = a.pop();
|
|
309
|
+
i.push(s);
|
|
310
|
+
let c = a, m = [];
|
|
311
|
+
for (let p = 0; p < c.length; p++) {
|
|
312
|
+
let u = c[p], f = o9[s], l = o9[u];
|
|
313
|
+
m.push(dr(f, l, r));
|
|
314
|
+
}
|
|
315
|
+
a = a.filter((p, u) => m[u] <= e);
|
|
316
|
+
}
|
|
317
|
+
return i;
|
|
318
|
+
}
|
|
319
|
+
function J(o9, t) {
|
|
320
|
+
return n.tidy(() => {
|
|
321
|
+
let [e, r, a] = t, i = n.fill([...o9.shape.slice(0, 3), 1], e, "float32"), s = n.fill([...o9.shape.slice(0, 3), 1], r, "float32"), c = n.fill([...o9.shape.slice(0, 3), 1], a, "float32"), m = n.concat([i, s, c], 3);
|
|
322
|
+
return n.sub(o9, m);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
function gr(o9, t = false) {
|
|
326
|
+
return n.tidy(() => {
|
|
327
|
+
let [e, r] = o9.shape.slice(1);
|
|
328
|
+
if (e === r) return o9;
|
|
329
|
+
let a = Math.abs(e - r), i = Math.round(a * (t ? 0.5 : 1)), s = e > r ? 2 : 1, c = (l) => {
|
|
330
|
+
let d = o9.shape.slice();
|
|
331
|
+
return d[s] = l, n.fill(d, 0, "float32");
|
|
332
|
+
}, m = c(i), p = a - m.shape[s], f = [t && p ? c(p) : null, o9, m].filter((l) => !!l).map((l) => n.cast(l, "float32"));
|
|
333
|
+
return n.concat(f, s);
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
function Rn(o9) {
|
|
337
|
+
let t = o9.slice();
|
|
338
|
+
for (let e = t.length - 1; e > 0; e--) {
|
|
339
|
+
let r = Math.floor(Math.random() * (e + 1)), a = t[e];
|
|
340
|
+
t[e] = t[r], t[r] = a;
|
|
341
|
+
}
|
|
342
|
+
return t;
|
|
343
|
+
}
|
|
344
|
+
function fe(o9) {
|
|
345
|
+
return 1 / (1 + Math.exp(-o9));
|
|
346
|
+
}
|
|
347
|
+
function On(o9) {
|
|
348
|
+
return Math.log(o9 / (1 - o9));
|
|
349
|
+
}
|
|
350
|
+
var Nt = class extends C {
|
|
351
|
+
constructor(t, e, r, a, i = false) {
|
|
352
|
+
super({ x: t, y: e, width: r, height: a }, i);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
var Fo = 0.5, Do = 0.43, Eo = 0.45, $ = class {
|
|
356
|
+
constructor(t, e, r = new v(0, 0)) {
|
|
357
|
+
let { width: a, height: i } = e;
|
|
358
|
+
this._imgDims = new A(a, i), this._shift = r, this._positions = t.map((s) => s.mul(new v(a, i)).add(r));
|
|
359
|
+
}
|
|
360
|
+
get shift() {
|
|
361
|
+
return new v(this._shift.x, this._shift.y);
|
|
362
|
+
}
|
|
363
|
+
get imageWidth() {
|
|
364
|
+
return this._imgDims.width;
|
|
365
|
+
}
|
|
366
|
+
get imageHeight() {
|
|
367
|
+
return this._imgDims.height;
|
|
368
|
+
}
|
|
369
|
+
get positions() {
|
|
370
|
+
return this._positions;
|
|
371
|
+
}
|
|
372
|
+
get relativePositions() {
|
|
373
|
+
return this._positions.map((t) => t.sub(this._shift).div(new v(this.imageWidth, this.imageHeight)));
|
|
374
|
+
}
|
|
375
|
+
forSize(t, e) {
|
|
376
|
+
return new this.constructor(this.relativePositions, { width: t, height: e });
|
|
377
|
+
}
|
|
378
|
+
shiftBy(t, e) {
|
|
379
|
+
return new this.constructor(this.relativePositions, this._imgDims, new v(t, e));
|
|
380
|
+
}
|
|
381
|
+
shiftByPoint(t) {
|
|
382
|
+
return this.shiftBy(t.x, t.y);
|
|
383
|
+
}
|
|
384
|
+
align(t, e = {}) {
|
|
385
|
+
if (t) {
|
|
386
|
+
let i = t instanceof D ? t.box.floor() : new C(t);
|
|
387
|
+
return this.shiftBy(i.x, i.y).align(null, e);
|
|
388
|
+
}
|
|
389
|
+
let { useDlibAlignment: r, minBoxPadding: a } = { useDlibAlignment: false, minBoxPadding: 0.2, ...e };
|
|
390
|
+
return r ? this.alignDlib() : this.alignMinBbox(a);
|
|
391
|
+
}
|
|
392
|
+
alignDlib() {
|
|
393
|
+
let t = this.getRefPointsForAlignment(), [e, r, a] = t, i = (f) => a.sub(f).magnitude(), s = (i(e) + i(r)) / 2, c = Math.floor(s / Eo), m = bt(t), p = Math.floor(Math.max(0, m.x - Fo * c)), u = Math.floor(Math.max(0, m.y - Do * c));
|
|
394
|
+
return new Nt(p, u, Math.min(c, this.imageWidth + p), Math.min(c, this.imageHeight + u));
|
|
395
|
+
}
|
|
396
|
+
alignMinBbox(t) {
|
|
397
|
+
let e = hr(this.positions);
|
|
398
|
+
return e.pad(e.width * t, e.height * t);
|
|
399
|
+
}
|
|
400
|
+
getRefPointsForAlignment() {
|
|
401
|
+
throw new Error("getRefPointsForAlignment not implemented by base class");
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
var xr = class extends $ {
|
|
405
|
+
getRefPointsForAlignment() {
|
|
406
|
+
let t = this.positions;
|
|
407
|
+
return [t[0], t[1], bt([t[3], t[4]])];
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
var Lt = class extends $ {
|
|
411
|
+
getJawOutline() {
|
|
412
|
+
return this.positions.slice(0, 17);
|
|
413
|
+
}
|
|
414
|
+
getLeftEyeBrow() {
|
|
415
|
+
return this.positions.slice(17, 22);
|
|
416
|
+
}
|
|
417
|
+
getRightEyeBrow() {
|
|
418
|
+
return this.positions.slice(22, 27);
|
|
419
|
+
}
|
|
420
|
+
getNose() {
|
|
421
|
+
return this.positions.slice(27, 36);
|
|
422
|
+
}
|
|
423
|
+
getLeftEye() {
|
|
424
|
+
return this.positions.slice(36, 42);
|
|
425
|
+
}
|
|
426
|
+
getRightEye() {
|
|
427
|
+
return this.positions.slice(42, 48);
|
|
428
|
+
}
|
|
429
|
+
getMouth() {
|
|
430
|
+
return this.positions.slice(48, 68);
|
|
431
|
+
}
|
|
432
|
+
getRefPointsForAlignment() {
|
|
433
|
+
return [this.getLeftEye(), this.getRightEye(), this.getMouth()].map(bt);
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
var Kt = class {
|
|
437
|
+
constructor(t, e) {
|
|
438
|
+
this._label = t, this._distance = e;
|
|
439
|
+
}
|
|
440
|
+
get label() {
|
|
441
|
+
return this._label;
|
|
442
|
+
}
|
|
443
|
+
get distance() {
|
|
444
|
+
return this._distance;
|
|
445
|
+
}
|
|
446
|
+
toString(t = true) {
|
|
447
|
+
return `${this.label}${t ? ` (${ht(this.distance)})` : ""}`;
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
var Qt = class extends C {
|
|
451
|
+
static assertIsValidLabeledBox(t, e) {
|
|
452
|
+
if (C.assertIsValidBox(t, e), !G(t.label)) throw new Error(`${e} - expected property label (${t.label}) to be a number`);
|
|
453
|
+
}
|
|
454
|
+
constructor(t, e) {
|
|
455
|
+
super(t), this._label = e;
|
|
456
|
+
}
|
|
457
|
+
get label() {
|
|
458
|
+
return this._label;
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
var gt = class o6 {
|
|
462
|
+
constructor(t, e) {
|
|
463
|
+
if (typeof t != "string") throw new Error("LabeledFaceDescriptors - constructor expected label to be a string");
|
|
464
|
+
if (!Array.isArray(e) || e.some((r) => !(r instanceof Float32Array))) throw new Error("LabeledFaceDescriptors - constructor expected descriptors to be an array of Float32Array");
|
|
465
|
+
this._label = t, this._descriptors = e;
|
|
466
|
+
}
|
|
467
|
+
get label() {
|
|
468
|
+
return this._label;
|
|
469
|
+
}
|
|
470
|
+
get descriptors() {
|
|
471
|
+
return this._descriptors;
|
|
472
|
+
}
|
|
473
|
+
toJSON() {
|
|
474
|
+
return { label: this.label, descriptors: this.descriptors.map((t) => Array.from(t)) };
|
|
475
|
+
}
|
|
476
|
+
static fromJSON(t) {
|
|
477
|
+
let e = t.descriptors.map((r) => new Float32Array(r));
|
|
478
|
+
return new o6(t.label, e);
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
var vr = class extends Qt {
|
|
482
|
+
static assertIsValidPredictedBox(t, e) {
|
|
483
|
+
if (Qt.assertIsValidLabeledBox(t, e), !Mt(t.score) || !Mt(t.classScore)) throw new Error(`${e} - expected properties score (${t.score}) and (${t.classScore}) to be a number between [0, 1]`);
|
|
484
|
+
}
|
|
485
|
+
constructor(t, e, r, a) {
|
|
486
|
+
super(t, e), this._score = r, this._classScore = a;
|
|
487
|
+
}
|
|
488
|
+
get score() {
|
|
489
|
+
return this._score;
|
|
490
|
+
}
|
|
491
|
+
get classScore() {
|
|
492
|
+
return this._classScore;
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
function Q(o9) {
|
|
496
|
+
return o9.detection instanceof D;
|
|
497
|
+
}
|
|
498
|
+
function St(o9, t) {
|
|
499
|
+
return { ...o9, ...{ detection: t } };
|
|
500
|
+
}
|
|
501
|
+
function Ue() {
|
|
502
|
+
let o9 = window.fetch;
|
|
503
|
+
if (!o9) throw new Error("fetch - missing fetch implementation for browser environment");
|
|
504
|
+
return { Canvas: HTMLCanvasElement, CanvasRenderingContext2D, Image: HTMLImageElement, ImageData, Video: HTMLVideoElement, createCanvasElement: () => document.createElement("canvas"), createImageElement: () => document.createElement("img"), createVideoElement: () => document.createElement("video"), fetch: o9, readFile: () => {
|
|
505
|
+
throw new Error("readFile - filesystem not available for browser environment");
|
|
506
|
+
} };
|
|
507
|
+
}
|
|
508
|
+
function te() {
|
|
509
|
+
return typeof global == "object" && typeof process != "undefined" && process.versions != null && process.versions.node != null;
|
|
510
|
+
}
|
|
511
|
+
function le(o9) {
|
|
512
|
+
let t = "";
|
|
513
|
+
if (!o9 && te()) try {
|
|
514
|
+
o9 = xo("fs");
|
|
515
|
+
} catch (r) {
|
|
516
|
+
t = r.toString();
|
|
517
|
+
}
|
|
518
|
+
return { readFile: o9 ? (r) => new Promise((a, i) => {
|
|
519
|
+
o9.readFile(r, (s, c) => s ? i(s) : a(c));
|
|
520
|
+
}) : () => {
|
|
521
|
+
throw new Error(`readFile - failed to require fs in nodejs environment with error: ${t}`);
|
|
522
|
+
} };
|
|
523
|
+
}
|
|
524
|
+
function Xe() {
|
|
525
|
+
let o9 = global.Canvas || global.HTMLCanvasElement, t = global.Image || global.HTMLImageElement, e = global.Video || global.HTMLVideoElement, r = () => {
|
|
526
|
+
if (o9) return new o9();
|
|
527
|
+
throw new Error("createCanvasElement - missing Canvas implementation for nodejs environment");
|
|
528
|
+
}, a = () => {
|
|
529
|
+
if (t) return new t();
|
|
530
|
+
throw new Error("createImageElement - missing Image implementation for nodejs environment");
|
|
531
|
+
}, i = () => {
|
|
532
|
+
if (e) return new e();
|
|
533
|
+
throw new Error("createVideoElement - missing Video implementation for nodejs environment");
|
|
534
|
+
}, s = global.fetch, c = le();
|
|
535
|
+
return { Canvas: o9 || class {
|
|
536
|
+
}, CanvasRenderingContext2D: global.CanvasRenderingContext2D || class {
|
|
537
|
+
}, Image: t || class {
|
|
538
|
+
}, ImageData: global.ImageData || class {
|
|
539
|
+
}, Video: global.HTMLVideoElement || class {
|
|
540
|
+
}, createCanvasElement: r, createImageElement: a, createVideoElement: i, fetch: s, ...c };
|
|
541
|
+
}
|
|
542
|
+
function Je() {
|
|
543
|
+
return typeof window == "object" && typeof document != "undefined" && typeof HTMLImageElement != "undefined" && typeof HTMLCanvasElement != "undefined" && typeof HTMLVideoElement != "undefined" && typeof ImageData != "undefined" && typeof CanvasRenderingContext2D != "undefined";
|
|
544
|
+
}
|
|
545
|
+
var M;
|
|
546
|
+
function Mo() {
|
|
547
|
+
if (!M) throw new Error("getEnv - environment is not defined, check isNodejs() and isBrowser()");
|
|
548
|
+
return M;
|
|
549
|
+
}
|
|
550
|
+
function qe(o9) {
|
|
551
|
+
M = o9;
|
|
552
|
+
}
|
|
553
|
+
function Ze() {
|
|
554
|
+
return Je() ? qe(Ue()) : te() ? qe(Xe()) : null;
|
|
555
|
+
}
|
|
556
|
+
function Co(o9) {
|
|
557
|
+
if (M || Ze(), !M) throw new Error("monkeyPatch - environment is not defined, check isNodejs() and isBrowser()");
|
|
558
|
+
let { Canvas: t = M.Canvas, Image: e = M.Image } = o9;
|
|
559
|
+
M.Canvas = t, M.Image = e, M.createCanvasElement = o9.createCanvasElement || (() => new t()), M.createImageElement = o9.createImageElement || (() => new e()), M.ImageData = o9.ImageData || M.ImageData, M.Video = o9.Video || M.Video, M.fetch = o9.fetch || M.fetch, M.readFile = o9.readFile || M.readFile;
|
|
560
|
+
}
|
|
561
|
+
var _ = { getEnv: Mo, setEnv: qe, initialize: Ze, createBrowserEnv: Ue, createFileSystem: le, createNodejsEnv: Xe, monkeyPatch: Co, isBrowser: Je, isNodejs: te };
|
|
562
|
+
Ze();
|
|
563
|
+
function At(o9) {
|
|
564
|
+
return !_.isNodejs() && typeof o9 == "string" ? document.getElementById(o9) : o9;
|
|
565
|
+
}
|
|
566
|
+
function W(o9) {
|
|
567
|
+
let { Canvas: t, CanvasRenderingContext2D: e } = _.getEnv();
|
|
568
|
+
if (o9 instanceof e) return o9;
|
|
569
|
+
let r = At(o9);
|
|
570
|
+
if (!(r instanceof t)) throw new Error("resolveContext2d - expected canvas to be of instance of Canvas");
|
|
571
|
+
let a = r.getContext("2d", { willReadFrequently: true });
|
|
572
|
+
if (!a) throw new Error("resolveContext2d - canvas 2d context is null");
|
|
573
|
+
return a;
|
|
574
|
+
}
|
|
575
|
+
var Ke = ((a) => (a.TOP_LEFT = "TOP_LEFT", a.TOP_RIGHT = "TOP_RIGHT", a.BOTTOM_LEFT = "BOTTOM_LEFT", a.BOTTOM_RIGHT = "BOTTOM_RIGHT", a))(Ke || {}), Wt = class {
|
|
576
|
+
constructor(t = {}) {
|
|
577
|
+
let { anchorPosition: e, backgroundColor: r, fontColor: a, fontSize: i, fontStyle: s, padding: c } = t;
|
|
578
|
+
this.anchorPosition = e || "TOP_LEFT", this.backgroundColor = r || "rgba(0, 0, 0, 0.5)", this.fontColor = a || "rgba(255, 255, 255, 1)", this.fontSize = i || 14, this.fontStyle = s || "Georgia", this.padding = c || 4;
|
|
579
|
+
}
|
|
580
|
+
}, xt = class o7 {
|
|
581
|
+
constructor(t, e, r = {}) {
|
|
582
|
+
this.text = typeof t == "string" ? [t] : t instanceof o7 ? t.text : t, this.anchor = e, this.options = new Wt(r);
|
|
583
|
+
}
|
|
584
|
+
measureWidth(t) {
|
|
585
|
+
let { padding: e } = this.options;
|
|
586
|
+
return this.text.map((r) => t.measureText(r).width).reduce((r, a) => r < a ? a : r, 0) + 2 * e;
|
|
587
|
+
}
|
|
588
|
+
measureHeight() {
|
|
589
|
+
let { fontSize: t, padding: e } = this.options;
|
|
590
|
+
return this.text.length * t + 2 * e;
|
|
591
|
+
}
|
|
592
|
+
getUpperLeft(t, e) {
|
|
593
|
+
let { anchorPosition: r } = this.options, a = r === "BOTTOM_RIGHT" || r === "TOP_RIGHT", i = r === "BOTTOM_LEFT" || r === "BOTTOM_RIGHT", s = this.measureWidth(t), c = this.measureHeight(), m = a ? this.anchor.x - s : this.anchor.x, p = i ? this.anchor.y - c : this.anchor.y;
|
|
594
|
+
if (e) {
|
|
595
|
+
let { width: u, height: f } = e, l = Math.max(Math.min(m, u - s), 0), d = Math.max(Math.min(p, f - c), 0);
|
|
596
|
+
return { x: l, y: d };
|
|
597
|
+
}
|
|
598
|
+
return { x: m, y: p };
|
|
599
|
+
}
|
|
600
|
+
draw(t) {
|
|
601
|
+
let e = At(t), r = W(e), { backgroundColor: a, fontColor: i, fontSize: s, fontStyle: c, padding: m } = this.options;
|
|
602
|
+
r.font = `${s}px ${c}`;
|
|
603
|
+
let p = this.measureWidth(r), u = this.measureHeight();
|
|
604
|
+
r.fillStyle = a;
|
|
605
|
+
let f = this.getUpperLeft(r, e);
|
|
606
|
+
r.fillRect(f.x, f.y, p, u), r.fillStyle = i, this.text.forEach((l, d) => {
|
|
607
|
+
let b = m + f.x, y = m + f.y + (d + 1) * s;
|
|
608
|
+
r.fillText(l, b, y);
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
var de = class {
|
|
613
|
+
constructor(t = {}) {
|
|
614
|
+
let { boxColor: e, lineWidth: r, label: a, drawLabelOptions: i } = t;
|
|
615
|
+
this.boxColor = e || "rgba(0, 0, 255, 1)", this.lineWidth = r || 2, this.label = a;
|
|
616
|
+
let s = { anchorPosition: "BOTTOM_LEFT", backgroundColor: this.boxColor };
|
|
617
|
+
this.drawLabelOptions = new Wt({ ...s, ...i });
|
|
618
|
+
}
|
|
619
|
+
}, ee = class {
|
|
620
|
+
constructor(t, e = {}) {
|
|
621
|
+
this.box = new C(t), this.options = new de(e);
|
|
622
|
+
}
|
|
623
|
+
draw(t) {
|
|
624
|
+
let e = W(t), { boxColor: r, lineWidth: a } = this.options, { x: i, y: s, width: c, height: m } = this.box;
|
|
625
|
+
e.strokeStyle = r, e.lineWidth = a, e.strokeRect(i, s, c, m);
|
|
626
|
+
let { label: p } = this.options;
|
|
627
|
+
p && new xt([p], { x: i - a / 2, y: s }, this.options.drawLabelOptions).draw(t);
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
function Io(o9, t) {
|
|
631
|
+
(Array.isArray(t) ? t : [t]).forEach((r) => {
|
|
632
|
+
let a = r instanceof D ? r.score : Q(r) ? r.detection.score : void 0, i = r instanceof D ? r.box : Q(r) ? r.detection.box : new C(r), s = a ? `${ht(a)}` : void 0;
|
|
633
|
+
new ee(i, { label: s }).draw(o9);
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
function he(o9) {
|
|
637
|
+
let { Image: t, Video: e } = _.getEnv();
|
|
638
|
+
return o9 instanceof t && o9.complete || o9 instanceof e && o9.readyState >= 3;
|
|
639
|
+
}
|
|
640
|
+
function yr(o9) {
|
|
641
|
+
return new Promise((t, e) => {
|
|
642
|
+
if (o9 instanceof _.getEnv().Canvas || he(o9)) {
|
|
643
|
+
t(null);
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
function r(i) {
|
|
647
|
+
i.currentTarget && (i.currentTarget.removeEventListener("load", a), i.currentTarget.removeEventListener("error", r), e(i));
|
|
648
|
+
}
|
|
649
|
+
function a(i) {
|
|
650
|
+
i.currentTarget && (i.currentTarget.removeEventListener("load", a), i.currentTarget.removeEventListener("error", r), t(i));
|
|
651
|
+
}
|
|
652
|
+
o9.addEventListener("load", a), o9.addEventListener("error", r);
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
function Tr(o9) {
|
|
656
|
+
return new Promise((t, e) => {
|
|
657
|
+
o9 instanceof Blob || e(new Error("bufferToImage - expected buf to be of type: Blob"));
|
|
658
|
+
let r = new FileReader();
|
|
659
|
+
r.onload = () => {
|
|
660
|
+
typeof r.result != "string" && e(new Error("bufferToImage - expected reader.result to be a string, in onload"));
|
|
661
|
+
let a = _.getEnv().createImageElement();
|
|
662
|
+
a.onload = () => t(a), a.onerror = e, a.src = r.result;
|
|
663
|
+
}, r.onerror = e, r.readAsDataURL(o9);
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
function kt(o9) {
|
|
667
|
+
let { Image: t, Video: e } = _.getEnv();
|
|
668
|
+
return o9 instanceof t ? new A(o9.naturalWidth, o9.naturalHeight) : o9 instanceof e ? new A(o9.videoWidth, o9.videoHeight) : new A(o9.width, o9.height);
|
|
669
|
+
}
|
|
670
|
+
function Bt({ width: o9, height: t }) {
|
|
671
|
+
let { createCanvasElement: e } = _.getEnv(), r = e();
|
|
672
|
+
return r.width = o9, r.height = t, r;
|
|
673
|
+
}
|
|
674
|
+
function be(o9, t) {
|
|
675
|
+
let { ImageData: e } = _.getEnv();
|
|
676
|
+
if (!(o9 instanceof e) && !he(o9)) throw new Error("createCanvasFromMedia - media has not finished loading yet");
|
|
677
|
+
let { width: r, height: a } = t || kt(o9), i = Bt({ width: r, height: a });
|
|
678
|
+
return o9 instanceof e ? W(i).putImageData(o9, 0, 0) : W(i).drawImage(o9, 0, 0, r, a), i;
|
|
679
|
+
}
|
|
680
|
+
async function _r(o9, t) {
|
|
681
|
+
let e = t || _.getEnv().createCanvasElement(), [r, a, i] = o9.shape.slice(R(o9) ? 1 : 0), s = n.tidy(() => o9.as3D(r, a, i).toInt());
|
|
682
|
+
return await n.browser.toPixels(s, e), s.dispose(), e;
|
|
683
|
+
}
|
|
684
|
+
function Qe(o9) {
|
|
685
|
+
let { Image: t, Canvas: e, Video: r } = _.getEnv();
|
|
686
|
+
return o9 instanceof t || o9 instanceof e || o9 instanceof r;
|
|
687
|
+
}
|
|
688
|
+
function Pr(o9, t, e = false) {
|
|
689
|
+
let { Image: r, Canvas: a } = _.getEnv();
|
|
690
|
+
if (!(o9 instanceof r || o9 instanceof a)) throw new Error("imageToSquare - expected arg0 to be HTMLImageElement | HTMLCanvasElement");
|
|
691
|
+
if (t <= 0) return Bt({ width: 1, height: 1 });
|
|
692
|
+
let i = kt(o9), s = t / Math.max(i.height, i.width), c = s * i.width, m = s * i.height, p = Bt({ width: t, height: t }), u = o9 instanceof a ? o9 : be(o9), f = Math.abs(c - m) / 2, l = e && c < m ? f : 0, d = e && m < c ? f : 0;
|
|
693
|
+
return u.width > 0 && u.height > 0 && W(p).drawImage(u, l, d, c, m), p;
|
|
694
|
+
}
|
|
695
|
+
var tt = class {
|
|
696
|
+
constructor(t, e = false) {
|
|
697
|
+
this._imageTensors = [];
|
|
698
|
+
this._canvases = [];
|
|
699
|
+
this._treatAsBatchInput = false;
|
|
700
|
+
this._inputDimensions = [];
|
|
701
|
+
this._inputSize = 0;
|
|
702
|
+
if (!Array.isArray(t)) throw new Error(`NetInput.constructor - expected inputs to be an Array of TResolvedNetInput or to be instanceof tf.Tensor4D, instead have ${t}`);
|
|
703
|
+
this._treatAsBatchInput = e, this._batchSize = t.length, t.forEach((r, a) => {
|
|
704
|
+
if (K(r)) {
|
|
705
|
+
this._imageTensors[a] = r, this._inputDimensions[a] = r.shape;
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
if (R(r)) {
|
|
709
|
+
let s = r.shape[0];
|
|
710
|
+
if (s !== 1) throw new Error(`NetInput - tf.Tensor4D with batchSize ${s} passed, but not supported in input array`);
|
|
711
|
+
this._imageTensors[a] = r, this._inputDimensions[a] = r.shape.slice(1);
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
let i = r instanceof _.getEnv().Canvas ? r : be(r);
|
|
715
|
+
this._canvases[a] = i, this._inputDimensions[a] = [i.height, i.width, 3];
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
get imageTensors() {
|
|
719
|
+
return this._imageTensors;
|
|
720
|
+
}
|
|
721
|
+
get canvases() {
|
|
722
|
+
return this._canvases;
|
|
723
|
+
}
|
|
724
|
+
get isBatchInput() {
|
|
725
|
+
return this.batchSize > 1 || this._treatAsBatchInput;
|
|
726
|
+
}
|
|
727
|
+
get batchSize() {
|
|
728
|
+
return this._batchSize;
|
|
729
|
+
}
|
|
730
|
+
get inputDimensions() {
|
|
731
|
+
return this._inputDimensions;
|
|
732
|
+
}
|
|
733
|
+
get inputSize() {
|
|
734
|
+
return this._inputSize;
|
|
735
|
+
}
|
|
736
|
+
get reshapedInputDimensions() {
|
|
737
|
+
return X(this.batchSize, 0, 1).map((t, e) => this.getReshapedInputDimensions(e));
|
|
738
|
+
}
|
|
739
|
+
getInput(t) {
|
|
740
|
+
return this.canvases[t] || this.imageTensors[t];
|
|
741
|
+
}
|
|
742
|
+
getInputDimensions(t) {
|
|
743
|
+
return this._inputDimensions[t];
|
|
744
|
+
}
|
|
745
|
+
getInputHeight(t) {
|
|
746
|
+
return this._inputDimensions[t][0];
|
|
747
|
+
}
|
|
748
|
+
getInputWidth(t) {
|
|
749
|
+
return this._inputDimensions[t][1];
|
|
750
|
+
}
|
|
751
|
+
getReshapedInputDimensions(t) {
|
|
752
|
+
if (typeof this.inputSize != "number") throw new Error("getReshapedInputDimensions - inputSize not set, toBatchTensor has not been called yet");
|
|
753
|
+
let e = this.getInputWidth(t), r = this.getInputHeight(t);
|
|
754
|
+
return je({ width: e, height: r }, this.inputSize);
|
|
755
|
+
}
|
|
756
|
+
toBatchTensor(t, e = true) {
|
|
757
|
+
return this._inputSize = t, n.tidy(() => {
|
|
758
|
+
let r = X(this.batchSize, 0, 1).map((i) => {
|
|
759
|
+
let s = this.getInput(i);
|
|
760
|
+
if (s instanceof n.Tensor) {
|
|
761
|
+
let c = R(s) ? s : n.expandDims(s);
|
|
762
|
+
return c = gr(c, e), (c.shape[1] !== t || c.shape[2] !== t) && (c = n.image.resizeBilinear(c, [t, t], false, false)), c.as3D(t, t, 3);
|
|
763
|
+
}
|
|
764
|
+
if (s instanceof _.getEnv().Canvas) return n.browser.fromPixels(Pr(s, t, e));
|
|
765
|
+
throw new Error(`toBatchTensor - at batchIdx ${i}, expected input to be instanceof tf.Tensor or instanceof HTMLCanvasElement, instead have ${s}`);
|
|
766
|
+
});
|
|
767
|
+
return n.stack(r.map((i) => n.cast(i, "float32"))).as4D(this.batchSize, t, t, 3);
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
async function F(o9) {
|
|
772
|
+
if (o9 instanceof tt) return o9;
|
|
773
|
+
let t = Array.isArray(o9) ? o9 : [o9];
|
|
774
|
+
if (!t.length) throw new Error("toNetInput - empty array passed as input");
|
|
775
|
+
let e = (a) => Array.isArray(o9) ? ` at input index ${a}:` : "", r = t.map(At);
|
|
776
|
+
return r.forEach((a, i) => {
|
|
777
|
+
if (!Qe(a) && !K(a) && !R(a)) throw typeof t[i] == "string" ? new Error(`toNetInput -${e(i)} string passed, but could not resolve HTMLElement for element id ${t[i]}`) : new Error(`toNetInput -${e(i)} expected media to be of type HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | tf.Tensor3D, or to be an element id`);
|
|
778
|
+
if (R(a)) {
|
|
779
|
+
let s = a.shape[0];
|
|
780
|
+
if (s !== 1) throw new Error(`toNetInput -${e(i)} tf.Tensor4D with batchSize ${s} passed, but not supported in input array`);
|
|
781
|
+
}
|
|
782
|
+
}), await Promise.all(r.map((a) => Qe(a) && yr(a))), new tt(r, Array.isArray(o9));
|
|
783
|
+
}
|
|
784
|
+
async function re(o9, t) {
|
|
785
|
+
let { Canvas: e } = _.getEnv(), r = o9;
|
|
786
|
+
if (!(o9 instanceof e)) {
|
|
787
|
+
let s = await F(o9);
|
|
788
|
+
if (s.batchSize > 1) throw new Error("extractFaces - batchSize > 1 not supported");
|
|
789
|
+
let c = s.getInput(0);
|
|
790
|
+
r = c instanceof e ? c : await _r(c);
|
|
791
|
+
}
|
|
792
|
+
let a = W(r);
|
|
793
|
+
return t.map((s) => s instanceof D ? s.forSize(r.width, r.height).box.floor() : s).map((s) => s.clipAtImageBorders(r.width, r.height)).map(({ x: s, y: c, width: m, height: p }) => {
|
|
794
|
+
let u = Bt({ width: m, height: p });
|
|
795
|
+
return m > 0 && p > 0 && W(u).putImageData(a.getImageData(s, c, m, p), 0, 0), u;
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
async function oe(o9, t) {
|
|
799
|
+
if (!K(o9) && !R(o9)) throw new Error("extractFaceTensors - expected image tensor to be 3D or 4D");
|
|
800
|
+
if (R(o9) && o9.shape[0] > 1) throw new Error("extractFaceTensors - batchSize > 1 not supported");
|
|
801
|
+
return n.tidy(() => {
|
|
802
|
+
let [e, r, a] = o9.shape.slice(R(o9) ? 1 : 0);
|
|
803
|
+
return t.map((c) => c instanceof D ? c.forSize(r, e).box : c).map((c) => c.clipAtImageBorders(r, e)).filter((c) => c.width > 0 && c.height > 0).map(({ x: c, y: m, width: p, height: u }) => n.slice3d(o9.as3D(e, r, a), [m, c, 0], [u, p, a]));
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
async function st(o9, t) {
|
|
807
|
+
let { fetch: e } = _.getEnv(), r = await e(o9, t);
|
|
808
|
+
if (!(r.status < 400)) throw new Error(`failed to fetch: (${r.status}) ${r.statusText}, from url: ${r.url}`);
|
|
809
|
+
return r;
|
|
810
|
+
}
|
|
811
|
+
async function Fi(o9) {
|
|
812
|
+
let t = await st(o9), e = await t.blob();
|
|
813
|
+
if (!e.type.startsWith("image/")) throw new Error(`fetchImage - expected blob type to be of type image/*, instead have: ${e.type}, for url: ${t.url}`);
|
|
814
|
+
return Tr(e);
|
|
815
|
+
}
|
|
816
|
+
async function wr(o9) {
|
|
817
|
+
return (await st(o9)).json();
|
|
818
|
+
}
|
|
819
|
+
async function Ii(o9) {
|
|
820
|
+
return new Float32Array(await (await st(o9)).arrayBuffer());
|
|
821
|
+
}
|
|
822
|
+
function Fr(o9) {
|
|
823
|
+
return new Promise((t, e) => {
|
|
824
|
+
o9 instanceof Blob || e(new Error("bufferToVideo - expected buf to be of type: Blob"));
|
|
825
|
+
let r = _.getEnv().createVideoElement();
|
|
826
|
+
r.oncanplay = () => t(r), r.onerror = e, r.playsInline = true, r.muted = true, r.src = URL.createObjectURL(o9), r.play();
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
async function ki(o9) {
|
|
830
|
+
let t = await st(o9), e = await t.blob();
|
|
831
|
+
if (!e.type.startsWith("video/")) throw new Error(`fetchVideo - expected blob type to be of type video/*, instead have: ${e.type}, for url: ${t.url}`);
|
|
832
|
+
return Fr(e);
|
|
833
|
+
}
|
|
834
|
+
function ge(o9, t) {
|
|
835
|
+
let e = `${t}-weights_manifest.json`;
|
|
836
|
+
if (!o9) return { modelBaseUri: "", manifestUri: e };
|
|
837
|
+
if (o9 === "/") return { modelBaseUri: "/", manifestUri: `/${e}` };
|
|
838
|
+
let r = o9.startsWith("http://") ? "http://" : o9.startsWith("https://") ? "https://" : "";
|
|
839
|
+
o9 = o9.replace(r, "");
|
|
840
|
+
let a = o9.split("/").filter((c) => c), i = o9.endsWith(".json") ? a[a.length - 1] : e, s = r + (o9.endsWith(".json") ? a.slice(0, a.length - 1) : a).join("/");
|
|
841
|
+
return s = o9.startsWith("/") ? `/${s}` : s, { modelBaseUri: s, manifestUri: s === "/" ? `/${i}` : `${s}/${i}` };
|
|
842
|
+
}
|
|
843
|
+
async function Dr(o9, t) {
|
|
844
|
+
let { manifestUri: e, modelBaseUri: r } = ge(o9, t), a = await wr(e);
|
|
845
|
+
return n.io.loadWeights(a, r);
|
|
846
|
+
}
|
|
847
|
+
function Yi(o9, t, e = false) {
|
|
848
|
+
let { width: r, height: a } = e ? kt(t) : t;
|
|
849
|
+
return o9.width = r, o9.height = a, { width: r, height: a };
|
|
850
|
+
}
|
|
851
|
+
var I = class {
|
|
852
|
+
constructor(t) {
|
|
853
|
+
this._params = void 0;
|
|
854
|
+
this._paramMappings = [];
|
|
855
|
+
this._name = t;
|
|
856
|
+
}
|
|
857
|
+
get params() {
|
|
858
|
+
return this._params;
|
|
859
|
+
}
|
|
860
|
+
get paramMappings() {
|
|
861
|
+
return this._paramMappings;
|
|
862
|
+
}
|
|
863
|
+
get isLoaded() {
|
|
864
|
+
return !!this.params;
|
|
865
|
+
}
|
|
866
|
+
getParamFromPath(t) {
|
|
867
|
+
let { obj: e, objProp: r } = this.traversePropertyPath(t);
|
|
868
|
+
return e[r];
|
|
869
|
+
}
|
|
870
|
+
reassignParamFromPath(t, e) {
|
|
871
|
+
let { obj: r, objProp: a } = this.traversePropertyPath(t);
|
|
872
|
+
r[a].dispose(), r[a] = e;
|
|
873
|
+
}
|
|
874
|
+
getParamList() {
|
|
875
|
+
return this._paramMappings.map(({ paramPath: t }) => ({ path: t, tensor: this.getParamFromPath(t) }));
|
|
876
|
+
}
|
|
877
|
+
getTrainableParams() {
|
|
878
|
+
return this.getParamList().filter((t) => t.tensor instanceof n.Variable);
|
|
879
|
+
}
|
|
880
|
+
getFrozenParams() {
|
|
881
|
+
return this.getParamList().filter((t) => !(t.tensor instanceof n.Variable));
|
|
882
|
+
}
|
|
883
|
+
variable() {
|
|
884
|
+
this.getFrozenParams().forEach(({ path: t, tensor: e }) => {
|
|
885
|
+
this.reassignParamFromPath(t, e.variable());
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
freeze() {
|
|
889
|
+
this.getTrainableParams().forEach(({ path: t, tensor: e }) => {
|
|
890
|
+
let r = n.tensor(e.dataSync());
|
|
891
|
+
e.dispose(), this.reassignParamFromPath(t, r);
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
dispose(t = true) {
|
|
895
|
+
this.getParamList().forEach((e) => {
|
|
896
|
+
if (t && e.tensor.isDisposed) throw new Error(`param tensor has already been disposed for path ${e.path}`);
|
|
897
|
+
e.tensor.dispose();
|
|
898
|
+
}), this._params = void 0;
|
|
899
|
+
}
|
|
900
|
+
serializeParams() {
|
|
901
|
+
return new Float32Array(this.getParamList().map(({ tensor: t }) => Array.from(t.dataSync())).reduce((t, e) => t.concat(e)));
|
|
902
|
+
}
|
|
903
|
+
async load(t) {
|
|
904
|
+
if (t instanceof Float32Array) {
|
|
905
|
+
this.extractWeights(t);
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
await this.loadFromUri(t);
|
|
909
|
+
}
|
|
910
|
+
async loadFromUri(t) {
|
|
911
|
+
if (t && typeof t != "string") throw new Error(`${this._name}.loadFromUri - expected model uri`);
|
|
912
|
+
let e = await Dr(t, this.getDefaultModelName());
|
|
913
|
+
this.loadFromWeightMap(e);
|
|
914
|
+
}
|
|
915
|
+
async loadFromDisk(t) {
|
|
916
|
+
if (t && typeof t != "string") throw new Error(`${this._name}.loadFromDisk - expected model file path`);
|
|
917
|
+
let { readFile: e } = _.getEnv(), { manifestUri: r, modelBaseUri: a } = ge(t, this.getDefaultModelName()), i = (p) => Promise.all(p.map((u) => e(u).then((f) => typeof f == "string" ? Buffer.from(f) : f.buffer))), s = n.io.weightsLoaderFactory(i), c = JSON.parse((await e(r)).toString()), m = await s(c, a);
|
|
918
|
+
this.loadFromWeightMap(m);
|
|
919
|
+
}
|
|
920
|
+
loadFromWeightMap(t) {
|
|
921
|
+
let { paramMappings: e, params: r } = this.extractParamsFromWeightMap(t);
|
|
922
|
+
this._paramMappings = e, this._params = r;
|
|
923
|
+
}
|
|
924
|
+
extractWeights(t) {
|
|
925
|
+
let { paramMappings: e, params: r } = this.extractParams(t);
|
|
926
|
+
this._paramMappings = e, this._params = r;
|
|
927
|
+
}
|
|
928
|
+
traversePropertyPath(t) {
|
|
929
|
+
if (!this.params) throw new Error("traversePropertyPath - model has no loaded params");
|
|
930
|
+
let e = t.split("/").reduce((i, s) => {
|
|
931
|
+
if (!i.nextObj.hasOwnProperty(s)) throw new Error(`traversePropertyPath - object does not have property ${s}, for path ${t}`);
|
|
932
|
+
return { obj: i.nextObj, objProp: s, nextObj: i.nextObj[s] };
|
|
933
|
+
}, { nextObj: this.params }), { obj: r, objProp: a } = e;
|
|
934
|
+
if (!r || !a || !(r[a] instanceof n.Tensor)) throw new Error(`traversePropertyPath - parameter is not a tensor, for path ${t}`);
|
|
935
|
+
return { obj: r, objProp: a };
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
function S(o9, t, e) {
|
|
939
|
+
return n.tidy(() => {
|
|
940
|
+
let r = n.separableConv2d(o9, t.depthwise_filter, t.pointwise_filter, e, "same");
|
|
941
|
+
return r = n.add(r, t.bias), r;
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
function xe(o9, t, e = false) {
|
|
945
|
+
return n.tidy(() => {
|
|
946
|
+
let r = n.relu(e ? n.add(n.conv2d(o9, t.conv0.filters, [2, 2], "same"), t.conv0.bias) : S(o9, t.conv0, [2, 2])), a = S(r, t.conv1, [1, 1]), i = n.relu(n.add(r, a)), s = S(i, t.conv2, [1, 1]);
|
|
947
|
+
return n.relu(n.add(r, n.add(a, s)));
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
function ne(o9, t, e = false, r = true) {
|
|
951
|
+
return n.tidy(() => {
|
|
952
|
+
let a = n.relu(e ? n.add(n.conv2d(o9, t.conv0.filters, r ? [2, 2] : [1, 1], "same"), t.conv0.bias) : S(o9, t.conv0, r ? [2, 2] : [1, 1])), i = S(a, t.conv1, [1, 1]), s = n.relu(n.add(a, i)), c = S(s, t.conv2, [1, 1]), m = n.relu(n.add(a, n.add(i, c))), p = S(m, t.conv3, [1, 1]);
|
|
953
|
+
return n.relu(n.add(a, n.add(i, n.add(c, p))));
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
function vt(o9, t, e = "same", r = false) {
|
|
957
|
+
return n.tidy(() => {
|
|
958
|
+
let a = n.add(n.conv2d(o9, t.filters, [1, 1], e), t.bias);
|
|
959
|
+
return r ? n.relu(a) : a;
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
function N(o9, t) {
|
|
963
|
+
Object.keys(o9).forEach((e) => {
|
|
964
|
+
t.some((r) => r.originalPath === e) || o9[e].dispose();
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
function Rt(o9, t) {
|
|
968
|
+
return (e, r, a, i) => {
|
|
969
|
+
let s = n.tensor4d(o9(e * r * a * a), [a, a, e, r]), c = n.tensor1d(o9(r));
|
|
970
|
+
return t.push({ paramPath: `${i}/filters` }, { paramPath: `${i}/bias` }), { filters: s, bias: c };
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
function ve(o9, t) {
|
|
974
|
+
return (e, r, a) => {
|
|
975
|
+
let i = n.tensor2d(o9(e * r), [e, r]), s = n.tensor1d(o9(r));
|
|
976
|
+
return t.push({ paramPath: `${a}/weights` }, { paramPath: `${a}/bias` }), { weights: i, bias: s };
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
var ae = class {
|
|
980
|
+
constructor(t, e, r) {
|
|
981
|
+
this.depthwise_filter = t;
|
|
982
|
+
this.pointwise_filter = e;
|
|
983
|
+
this.bias = r;
|
|
984
|
+
}
|
|
985
|
+
};
|
|
986
|
+
function $t(o9, t) {
|
|
987
|
+
return (e, r, a) => {
|
|
988
|
+
let i = n.tensor4d(o9(9 * e), [3, 3, e, 1]), s = n.tensor4d(o9(e * r), [1, 1, e, r]), c = n.tensor1d(o9(r));
|
|
989
|
+
return t.push({ paramPath: `${a}/depthwise_filter` }, { paramPath: `${a}/pointwise_filter` }, { paramPath: `${a}/bias` }), new ae(i, s, c);
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
function Ot(o9) {
|
|
993
|
+
return (t) => {
|
|
994
|
+
let e = o9(`${t}/depthwise_filter`, 4), r = o9(`${t}/pointwise_filter`, 4), a = o9(`${t}/bias`, 1);
|
|
995
|
+
return new ae(e, r, a);
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
function k(o9, t) {
|
|
999
|
+
return (e, r, a) => {
|
|
1000
|
+
let i = o9[e];
|
|
1001
|
+
if (!dt(i, r)) throw new Error(`expected weightMap[${e}] to be a Tensor${r}D, instead have ${i}`);
|
|
1002
|
+
return t.push({ originalPath: e, paramPath: a || e }), i;
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
function L(o9) {
|
|
1006
|
+
let t = o9;
|
|
1007
|
+
function e(a) {
|
|
1008
|
+
let i = t.slice(0, a);
|
|
1009
|
+
return t = t.slice(a), i;
|
|
1010
|
+
}
|
|
1011
|
+
function r() {
|
|
1012
|
+
return t;
|
|
1013
|
+
}
|
|
1014
|
+
return { extractWeights: e, getRemainingWeights: r };
|
|
1015
|
+
}
|
|
1016
|
+
function ye(o9, t) {
|
|
1017
|
+
let e = Rt(o9, t), r = $t(o9, t);
|
|
1018
|
+
function a(s, c, m, p = false) {
|
|
1019
|
+
let u = p ? e(s, c, 3, `${m}/conv0`) : r(s, c, `${m}/conv0`), f = r(c, c, `${m}/conv1`), l = r(c, c, `${m}/conv2`);
|
|
1020
|
+
return { conv0: u, conv1: f, conv2: l };
|
|
1021
|
+
}
|
|
1022
|
+
function i(s, c, m, p = false) {
|
|
1023
|
+
let { conv0: u, conv1: f, conv2: l } = a(s, c, m, p), d = r(c, c, `${m}/conv3`);
|
|
1024
|
+
return { conv0: u, conv1: f, conv2: l, conv3: d };
|
|
1025
|
+
}
|
|
1026
|
+
return { extractDenseBlock3Params: a, extractDenseBlock4Params: i };
|
|
1027
|
+
}
|
|
1028
|
+
function Er(o9) {
|
|
1029
|
+
let t = [], { extractWeights: e, getRemainingWeights: r } = L(o9), { extractDenseBlock4Params: a } = ye(e, t), i = a(3, 32, "dense0", true), s = a(32, 64, "dense1"), c = a(64, 128, "dense2"), m = a(128, 256, "dense3");
|
|
1030
|
+
if (r().length !== 0) throw new Error(`weights remaing after extract: ${r().length}`);
|
|
1031
|
+
return { paramMappings: t, params: { dense0: i, dense1: s, dense2: c, dense3: m } };
|
|
1032
|
+
}
|
|
1033
|
+
function Te(o9) {
|
|
1034
|
+
return (t) => {
|
|
1035
|
+
let e = o9(`${t}/filters`, 4), r = o9(`${t}/bias`, 1);
|
|
1036
|
+
return { filters: e, bias: r };
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
function _e(o9, t) {
|
|
1040
|
+
let e = k(o9, t), r = Te(e), a = Ot(e);
|
|
1041
|
+
function i(c, m = false) {
|
|
1042
|
+
let p = m ? r(`${c}/conv0`) : a(`${c}/conv0`), u = a(`${c}/conv1`), f = a(`${c}/conv2`);
|
|
1043
|
+
return { conv0: p, conv1: u, conv2: f };
|
|
1044
|
+
}
|
|
1045
|
+
function s(c, m = false) {
|
|
1046
|
+
let p = m ? r(`${c}/conv0`) : a(`${c}/conv0`), u = a(`${c}/conv1`), f = a(`${c}/conv2`), l = a(`${c}/conv3`);
|
|
1047
|
+
return { conv0: p, conv1: u, conv2: f, conv3: l };
|
|
1048
|
+
}
|
|
1049
|
+
return { extractDenseBlock3Params: i, extractDenseBlock4Params: s };
|
|
1050
|
+
}
|
|
1051
|
+
function Mr(o9) {
|
|
1052
|
+
let t = [], { extractDenseBlock4Params: e } = _e(o9, t), r = { dense0: e("dense0", true), dense1: e("dense1"), dense2: e("dense2"), dense3: e("dense3") };
|
|
1053
|
+
return N(o9, t), { params: r, paramMappings: t };
|
|
1054
|
+
}
|
|
1055
|
+
var Ht = class extends I {
|
|
1056
|
+
constructor() {
|
|
1057
|
+
super("FaceFeatureExtractor");
|
|
1058
|
+
}
|
|
1059
|
+
forwardInput(t) {
|
|
1060
|
+
let { params: e } = this;
|
|
1061
|
+
if (!e) throw new Error("FaceFeatureExtractor - load model before inference");
|
|
1062
|
+
return n.tidy(() => {
|
|
1063
|
+
let r = n.cast(t.toBatchTensor(112, true), "float32"), i = J(r, [122.782, 117.001, 104.298]).div(255), s = ne(i, e.dense0, true);
|
|
1064
|
+
return s = ne(s, e.dense1), s = ne(s, e.dense2), s = ne(s, e.dense3), s = n.avgPool(s, [7, 7], [2, 2], "valid"), s;
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
async forward(t) {
|
|
1068
|
+
return this.forwardInput(await F(t));
|
|
1069
|
+
}
|
|
1070
|
+
getDefaultModelName() {
|
|
1071
|
+
return "face_feature_extractor_model";
|
|
1072
|
+
}
|
|
1073
|
+
extractParamsFromWeightMap(t) {
|
|
1074
|
+
return Mr(t);
|
|
1075
|
+
}
|
|
1076
|
+
extractParams(t) {
|
|
1077
|
+
return Er(t);
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1080
|
+
function se(o9, t) {
|
|
1081
|
+
return n.tidy(() => n.add(n.matMul(o9, t.weights), t.bias));
|
|
1082
|
+
}
|
|
1083
|
+
function Cr(o9, t, e) {
|
|
1084
|
+
let r = [], { extractWeights: a, getRemainingWeights: i } = L(o9), c = ve(a, r)(t, e, "fc");
|
|
1085
|
+
if (i().length !== 0) throw new Error(`weights remaing after extract: ${i().length}`);
|
|
1086
|
+
return { paramMappings: r, params: { fc: c } };
|
|
1087
|
+
}
|
|
1088
|
+
function Ir(o9) {
|
|
1089
|
+
let t = [], e = k(o9, t);
|
|
1090
|
+
function r(i) {
|
|
1091
|
+
let s = e(`${i}/weights`, 2), c = e(`${i}/bias`, 1);
|
|
1092
|
+
return { weights: s, bias: c };
|
|
1093
|
+
}
|
|
1094
|
+
let a = { fc: r("fc") };
|
|
1095
|
+
return N(o9, t), { params: a, paramMappings: t };
|
|
1096
|
+
}
|
|
1097
|
+
function Pe(o9) {
|
|
1098
|
+
let t = {}, e = {};
|
|
1099
|
+
return Object.keys(o9).forEach((r) => {
|
|
1100
|
+
let a = r.startsWith("fc") ? e : t;
|
|
1101
|
+
a[r] = o9[r];
|
|
1102
|
+
}), { featureExtractorMap: t, classifierMap: e };
|
|
1103
|
+
}
|
|
1104
|
+
var zt = class extends I {
|
|
1105
|
+
constructor(t, e) {
|
|
1106
|
+
super(t), this._faceFeatureExtractor = e;
|
|
1107
|
+
}
|
|
1108
|
+
get faceFeatureExtractor() {
|
|
1109
|
+
return this._faceFeatureExtractor;
|
|
1110
|
+
}
|
|
1111
|
+
runNet(t) {
|
|
1112
|
+
let { params: e } = this;
|
|
1113
|
+
if (!e) throw new Error(`${this._name} - load model before inference`);
|
|
1114
|
+
return n.tidy(() => {
|
|
1115
|
+
let r = t instanceof tt ? this.faceFeatureExtractor.forwardInput(t) : t;
|
|
1116
|
+
return se(r.as2D(r.shape[0], -1), e.fc);
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
dispose(t = true) {
|
|
1120
|
+
this.faceFeatureExtractor.dispose(t), super.dispose(t);
|
|
1121
|
+
}
|
|
1122
|
+
loadClassifierParams(t) {
|
|
1123
|
+
let { params: e, paramMappings: r } = this.extractClassifierParams(t);
|
|
1124
|
+
this._params = e, this._paramMappings = r;
|
|
1125
|
+
}
|
|
1126
|
+
extractClassifierParams(t) {
|
|
1127
|
+
return Cr(t, this.getClassifierChannelsIn(), this.getClassifierChannelsOut());
|
|
1128
|
+
}
|
|
1129
|
+
extractParamsFromWeightMap(t) {
|
|
1130
|
+
let { featureExtractorMap: e, classifierMap: r } = Pe(t);
|
|
1131
|
+
return this.faceFeatureExtractor.loadFromWeightMap(e), Ir(r);
|
|
1132
|
+
}
|
|
1133
|
+
extractParams(t) {
|
|
1134
|
+
let e = this.getClassifierChannelsIn(), r = this.getClassifierChannelsOut(), a = r * e + r, i = t.slice(0, t.length - a), s = t.slice(t.length - a);
|
|
1135
|
+
return this.faceFeatureExtractor.extractWeights(i), this.extractClassifierParams(s);
|
|
1136
|
+
}
|
|
1137
|
+
};
|
|
1138
|
+
var Nr = ["neutral", "happy", "sad", "angry", "fearful", "disgusted", "surprised"], it = class {
|
|
1139
|
+
constructor(t) {
|
|
1140
|
+
this.neutral = 0;
|
|
1141
|
+
this.happy = 0;
|
|
1142
|
+
this.sad = 0;
|
|
1143
|
+
this.angry = 0;
|
|
1144
|
+
this.fearful = 0;
|
|
1145
|
+
this.disgusted = 0;
|
|
1146
|
+
this.surprised = 0;
|
|
1147
|
+
if (t.length !== 7) throw new Error(`FaceExpressions.constructor - expected probabilities.length to be 7, have: ${t.length}`);
|
|
1148
|
+
Nr.forEach((e, r) => {
|
|
1149
|
+
this[e] = t[r];
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
asSortedArray() {
|
|
1153
|
+
return Nr.map((t) => ({ expression: t, probability: this[t] })).sort((t, e) => e.probability - t.probability);
|
|
1154
|
+
}
|
|
1155
|
+
};
|
|
1156
|
+
var we = class extends zt {
|
|
1157
|
+
constructor(t = new Ht()) {
|
|
1158
|
+
super("FaceExpressionNet", t);
|
|
1159
|
+
}
|
|
1160
|
+
forwardInput(t) {
|
|
1161
|
+
return n.tidy(() => n.softmax(this.runNet(t)));
|
|
1162
|
+
}
|
|
1163
|
+
async forward(t) {
|
|
1164
|
+
return this.forwardInput(await F(t));
|
|
1165
|
+
}
|
|
1166
|
+
async predictExpressions(t) {
|
|
1167
|
+
let e = await F(t), r = await this.forwardInput(e), a = await Promise.all(n.unstack(r).map(async (s) => {
|
|
1168
|
+
let c = s.dataSync();
|
|
1169
|
+
return s.dispose(), c;
|
|
1170
|
+
}));
|
|
1171
|
+
r.dispose();
|
|
1172
|
+
let i = a.map((s) => new it(s));
|
|
1173
|
+
return e.isBatchInput ? i : i[0];
|
|
1174
|
+
}
|
|
1175
|
+
getDefaultModelName() {
|
|
1176
|
+
return "face_expression_model";
|
|
1177
|
+
}
|
|
1178
|
+
getClassifierChannelsIn() {
|
|
1179
|
+
return 256;
|
|
1180
|
+
}
|
|
1181
|
+
getClassifierChannelsOut() {
|
|
1182
|
+
return 7;
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
function Lr(o9) {
|
|
1186
|
+
return o9.expressions instanceof it;
|
|
1187
|
+
}
|
|
1188
|
+
function tr(o9, t) {
|
|
1189
|
+
return { ...o9, ...{ expressions: t } };
|
|
1190
|
+
}
|
|
1191
|
+
function No(o9, t, e = 0.1, r) {
|
|
1192
|
+
(Array.isArray(t) ? t : [t]).forEach((i) => {
|
|
1193
|
+
let s = i instanceof it ? i : Lr(i) ? i.expressions : void 0;
|
|
1194
|
+
if (!s) throw new Error("drawFaceExpressions - expected faceExpressions to be FaceExpressions | WithFaceExpressions<{}> or array thereof");
|
|
1195
|
+
let m = s.asSortedArray().filter((f) => f.probability > e), p = Q(i) ? i.detection.box.bottomLeft : r || new v(0, 0);
|
|
1196
|
+
new xt(m.map((f) => `${f.expression} (${ht(f.probability)})`), p).draw(o9);
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
function Yt(o9) {
|
|
1200
|
+
return Q(o9) && o9.landmarks instanceof $ && o9.unshiftedLandmarks instanceof $ && o9.alignedRect instanceof D;
|
|
1201
|
+
}
|
|
1202
|
+
function Lo(o9) {
|
|
1203
|
+
let t = (m) => m * 180 / Math.PI, e = (m, p) => Math.sqrt((m.x - p.x) ** 2 + (m.y - p.y) ** 2), r = { roll: void 0, pitch: void 0, yaw: void 0 }, a = (m, p, u) => {
|
|
1204
|
+
let f = Math.floor(m.x - p.x), l = Math.floor(p.x - u.x);
|
|
1205
|
+
return f - l;
|
|
1206
|
+
}, i = (m, p) => {
|
|
1207
|
+
let u = Math.hypot(p.x - m.x, p.y - m.y), f = p.y - m.y, l = Math.asin(f / u), d = t(l), b = Math.floor(90 - d), y = p.x - m.x < 0 ? -1 : 1;
|
|
1208
|
+
return b * y;
|
|
1209
|
+
}, s = (m, p, u) => {
|
|
1210
|
+
let f = e(m, u), l = new v((m.x + u.x) / 2, (m.y + u.y) / 2), d = e(p, l), b = Math.atan(d / f), y = Math.floor(t(b)), h = l.y - p.y < 0 ? -1 : 1;
|
|
1211
|
+
return y * h;
|
|
1212
|
+
};
|
|
1213
|
+
if (!o9 || !o9.positions || o9.positions.length !== 68) return r;
|
|
1214
|
+
let c = o9.positions;
|
|
1215
|
+
return r.roll = i(c[27], c[66]), r.pitch = s(c[14], c[30], c[2]), r.yaw = a(c[14], c[33], c[2]), r;
|
|
1216
|
+
}
|
|
1217
|
+
function ie(o9, t) {
|
|
1218
|
+
let { box: e } = o9.detection, r = t.shiftBy(e.x, e.y), a = r.align(), { imageDims: i } = o9.detection, s = new D(o9.detection.score, a.rescale(i.reverse()), i), c = Lo(t);
|
|
1219
|
+
return { ...o9, ...{ landmarks: r, unshiftedLandmarks: t, alignedRect: s, angle: c } };
|
|
1220
|
+
}
|
|
1221
|
+
var Fe = class {
|
|
1222
|
+
constructor(t = {}) {
|
|
1223
|
+
let { drawLines: e = true, drawPoints: r = true, lineWidth: a, lineColor: i, pointSize: s, pointColor: c } = t;
|
|
1224
|
+
this.drawLines = e, this.drawPoints = r, this.lineWidth = a || 1, this.pointSize = s || 2, this.lineColor = i || "rgba(0, 255, 255, 1)", this.pointColor = c || "rgba(255, 0, 255, 1)";
|
|
1225
|
+
}
|
|
1226
|
+
}, De = class {
|
|
1227
|
+
constructor(t, e = {}) {
|
|
1228
|
+
this.faceLandmarks = t, this.options = new Fe(e);
|
|
1229
|
+
}
|
|
1230
|
+
draw(t) {
|
|
1231
|
+
let e = W(t), { drawLines: r, drawPoints: a, lineWidth: i, lineColor: s, pointSize: c, pointColor: m } = this.options;
|
|
1232
|
+
if (r && this.faceLandmarks instanceof Lt && (e.strokeStyle = s, e.lineWidth = i, Z(e, this.faceLandmarks.getJawOutline()), Z(e, this.faceLandmarks.getLeftEyeBrow()), Z(e, this.faceLandmarks.getRightEyeBrow()), Z(e, this.faceLandmarks.getNose()), Z(e, this.faceLandmarks.getLeftEye(), true), Z(e, this.faceLandmarks.getRightEye(), true), Z(e, this.faceLandmarks.getMouth(), true)), a) {
|
|
1233
|
+
e.strokeStyle = m, e.fillStyle = m;
|
|
1234
|
+
let p = (u) => {
|
|
1235
|
+
e.beginPath(), e.arc(u.x, u.y, c, 0, 2 * Math.PI), e.fill();
|
|
1236
|
+
};
|
|
1237
|
+
this.faceLandmarks.positions.forEach(p);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
function So(o9, t) {
|
|
1242
|
+
(Array.isArray(t) ? t : [t]).forEach((r) => {
|
|
1243
|
+
let a = r instanceof $ ? r : Yt(r) ? r.landmarks : void 0;
|
|
1244
|
+
if (!a) throw new Error("drawFaceLandmarks - expected faceExpressions to be FaceLandmarks | WithFaceLandmarks<WithFaceDetection<{}>> or array thereof");
|
|
1245
|
+
new De(a).draw(o9);
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
var Ar = "1.7.15";
|
|
1249
|
+
function ko(o9, t) {
|
|
1250
|
+
let e = Rt(o9, t), r = $t(o9, t);
|
|
1251
|
+
function a(s, c, m) {
|
|
1252
|
+
let p = r(s, c, `${m}/separable_conv0`), u = r(c, c, `${m}/separable_conv1`), f = e(s, c, 1, `${m}/expansion_conv`);
|
|
1253
|
+
return { separable_conv0: p, separable_conv1: u, expansion_conv: f };
|
|
1254
|
+
}
|
|
1255
|
+
function i(s, c) {
|
|
1256
|
+
let m = r(s, s, `${c}/separable_conv0`), p = r(s, s, `${c}/separable_conv1`), u = r(s, s, `${c}/separable_conv2`);
|
|
1257
|
+
return { separable_conv0: m, separable_conv1: p, separable_conv2: u };
|
|
1258
|
+
}
|
|
1259
|
+
return { extractConvParams: e, extractSeparableConvParams: r, extractReductionBlockParams: a, extractMainBlockParams: i };
|
|
1260
|
+
}
|
|
1261
|
+
function Wr(o9, t) {
|
|
1262
|
+
let e = [], { extractWeights: r, getRemainingWeights: a } = L(o9), { extractConvParams: i, extractSeparableConvParams: s, extractReductionBlockParams: c, extractMainBlockParams: m } = ko(r, e), p = i(3, 32, 3, "entry_flow/conv_in"), u = c(32, 64, "entry_flow/reduction_block_0"), f = c(64, 128, "entry_flow/reduction_block_1"), l = { conv_in: p, reduction_block_0: u, reduction_block_1: f }, d = {};
|
|
1263
|
+
X(t, 0, 1).forEach((g) => {
|
|
1264
|
+
d[`main_block_${g}`] = m(128, `middle_flow/main_block_${g}`);
|
|
1265
|
+
});
|
|
1266
|
+
let b = c(128, 256, "exit_flow/reduction_block"), y = s(256, 512, "exit_flow/separable_conv"), h = { reduction_block: b, separable_conv: y };
|
|
1267
|
+
if (a().length !== 0) throw new Error(`weights remaing after extract: ${a().length}`);
|
|
1268
|
+
return { paramMappings: e, params: { entry_flow: l, middle_flow: d, exit_flow: h } };
|
|
1269
|
+
}
|
|
1270
|
+
function Bo(o9, t) {
|
|
1271
|
+
let e = k(o9, t), r = Te(e), a = Ot(e);
|
|
1272
|
+
function i(c) {
|
|
1273
|
+
let m = a(`${c}/separable_conv0`), p = a(`${c}/separable_conv1`), u = r(`${c}/expansion_conv`);
|
|
1274
|
+
return { separable_conv0: m, separable_conv1: p, expansion_conv: u };
|
|
1275
|
+
}
|
|
1276
|
+
function s(c) {
|
|
1277
|
+
let m = a(`${c}/separable_conv0`), p = a(`${c}/separable_conv1`), u = a(`${c}/separable_conv2`);
|
|
1278
|
+
return { separable_conv0: m, separable_conv1: p, separable_conv2: u };
|
|
1279
|
+
}
|
|
1280
|
+
return { extractConvParams: r, extractSeparableConvParams: a, extractReductionBlockParams: i, extractMainBlockParams: s };
|
|
1281
|
+
}
|
|
1282
|
+
function kr(o9, t) {
|
|
1283
|
+
let e = [], { extractConvParams: r, extractSeparableConvParams: a, extractReductionBlockParams: i, extractMainBlockParams: s } = Bo(o9, e), c = r("entry_flow/conv_in"), m = i("entry_flow/reduction_block_0"), p = i("entry_flow/reduction_block_1"), u = { conv_in: c, reduction_block_0: m, reduction_block_1: p }, f = {};
|
|
1284
|
+
X(t, 0, 1).forEach((y) => {
|
|
1285
|
+
f[`main_block_${y}`] = s(`middle_flow/main_block_${y}`);
|
|
1286
|
+
});
|
|
1287
|
+
let l = i("exit_flow/reduction_block"), d = a("exit_flow/separable_conv"), b = { reduction_block: l, separable_conv: d };
|
|
1288
|
+
return N(o9, e), { params: { entry_flow: u, middle_flow: f, exit_flow: b }, paramMappings: e };
|
|
1289
|
+
}
|
|
1290
|
+
function Br(o9, t, e) {
|
|
1291
|
+
return n.add(n.conv2d(o9, t.filters, e, "same"), t.bias);
|
|
1292
|
+
}
|
|
1293
|
+
function er(o9, t, e = true) {
|
|
1294
|
+
let r = e ? n.relu(o9) : o9;
|
|
1295
|
+
return r = S(r, t.separable_conv0, [1, 1]), r = S(n.relu(r), t.separable_conv1, [1, 1]), r = n.maxPool(r, [3, 3], [2, 2], "same"), r = n.add(r, Br(o9, t.expansion_conv, [2, 2])), r;
|
|
1296
|
+
}
|
|
1297
|
+
function Ro(o9, t) {
|
|
1298
|
+
let e = S(n.relu(o9), t.separable_conv0, [1, 1]);
|
|
1299
|
+
return e = S(n.relu(e), t.separable_conv1, [1, 1]), e = S(n.relu(e), t.separable_conv2, [1, 1]), e = n.add(e, o9), e;
|
|
1300
|
+
}
|
|
1301
|
+
var Ee = class extends I {
|
|
1302
|
+
constructor(t) {
|
|
1303
|
+
super("TinyXception"), this._numMainBlocks = t;
|
|
1304
|
+
}
|
|
1305
|
+
forwardInput(t) {
|
|
1306
|
+
let { params: e } = this;
|
|
1307
|
+
if (!e) throw new Error("TinyXception - load model before inference");
|
|
1308
|
+
return n.tidy(() => {
|
|
1309
|
+
let r = n.cast(t.toBatchTensor(112, true), "float32"), i = J(r, [122.782, 117.001, 104.298]).div(255), s = n.relu(Br(i, e.entry_flow.conv_in, [2, 2]));
|
|
1310
|
+
return s = er(s, e.entry_flow.reduction_block_0, false), s = er(s, e.entry_flow.reduction_block_1), X(this._numMainBlocks, 0, 1).forEach((c) => {
|
|
1311
|
+
s = Ro(s, e.middle_flow[`main_block_${c}`]);
|
|
1312
|
+
}), s = er(s, e.exit_flow.reduction_block), s = n.relu(S(s, e.exit_flow.separable_conv, [1, 1])), s;
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
async forward(t) {
|
|
1316
|
+
return this.forwardInput(await F(t));
|
|
1317
|
+
}
|
|
1318
|
+
getDefaultModelName() {
|
|
1319
|
+
return "tiny_xception_model";
|
|
1320
|
+
}
|
|
1321
|
+
extractParamsFromWeightMap(t) {
|
|
1322
|
+
return kr(t, this._numMainBlocks);
|
|
1323
|
+
}
|
|
1324
|
+
extractParams(t) {
|
|
1325
|
+
return Wr(t, this._numMainBlocks);
|
|
1326
|
+
}
|
|
1327
|
+
};
|
|
1328
|
+
function Rr(o9) {
|
|
1329
|
+
let t = [], { extractWeights: e, getRemainingWeights: r } = L(o9), a = ve(e, t), i = a(512, 1, "fc/age"), s = a(512, 2, "fc/gender");
|
|
1330
|
+
if (r().length !== 0) throw new Error(`weights remaing after extract: ${r().length}`);
|
|
1331
|
+
return { paramMappings: t, params: { fc: { age: i, gender: s } } };
|
|
1332
|
+
}
|
|
1333
|
+
function $r(o9) {
|
|
1334
|
+
let t = [], e = k(o9, t);
|
|
1335
|
+
function r(i) {
|
|
1336
|
+
let s = e(`${i}/weights`, 2), c = e(`${i}/bias`, 1);
|
|
1337
|
+
return { weights: s, bias: c };
|
|
1338
|
+
}
|
|
1339
|
+
let a = { fc: { age: r("fc/age"), gender: r("fc/gender") } };
|
|
1340
|
+
return N(o9, t), { params: a, paramMappings: t };
|
|
1341
|
+
}
|
|
1342
|
+
var rr = ((e) => (e.FEMALE = "female", e.MALE = "male", e))(rr || {});
|
|
1343
|
+
var Me = class extends I {
|
|
1344
|
+
constructor(t = new Ee(2)) {
|
|
1345
|
+
super("AgeGenderNet"), this._faceFeatureExtractor = t;
|
|
1346
|
+
}
|
|
1347
|
+
get faceFeatureExtractor() {
|
|
1348
|
+
return this._faceFeatureExtractor;
|
|
1349
|
+
}
|
|
1350
|
+
runNet(t) {
|
|
1351
|
+
let { params: e } = this;
|
|
1352
|
+
if (!e) throw new Error(`${this._name} - load model before inference`);
|
|
1353
|
+
return n.tidy(() => {
|
|
1354
|
+
let r = t instanceof tt ? this.faceFeatureExtractor.forwardInput(t) : t, a = n.avgPool(r, [7, 7], [2, 2], "valid").as2D(r.shape[0], -1), i = se(a, e.fc.age).as1D(), s = se(a, e.fc.gender);
|
|
1355
|
+
return { age: i, gender: s };
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1358
|
+
forwardInput(t) {
|
|
1359
|
+
return n.tidy(() => {
|
|
1360
|
+
let { age: e, gender: r } = this.runNet(t);
|
|
1361
|
+
return { age: e, gender: n.softmax(r) };
|
|
1362
|
+
});
|
|
1363
|
+
}
|
|
1364
|
+
async forward(t) {
|
|
1365
|
+
return this.forwardInput(await F(t));
|
|
1366
|
+
}
|
|
1367
|
+
async predictAgeAndGender(t) {
|
|
1368
|
+
let e = await F(t), r = await this.forwardInput(e), a = n.unstack(r.age), i = n.unstack(r.gender), s = a.map((m, p) => ({ ageTensor: m, genderTensor: i[p] })), c = await Promise.all(s.map(async ({ ageTensor: m, genderTensor: p }) => {
|
|
1369
|
+
let u = m.dataSync()[0], f = p.dataSync()[0], l = f > 0.5, d = l ? "male" : "female", b = l ? f : 1 - f;
|
|
1370
|
+
return m.dispose(), p.dispose(), { age: u, gender: d, genderProbability: b };
|
|
1371
|
+
}));
|
|
1372
|
+
return r.age.dispose(), r.gender.dispose(), e.isBatchInput ? c : c[0];
|
|
1373
|
+
}
|
|
1374
|
+
getDefaultModelName() {
|
|
1375
|
+
return "age_gender_model";
|
|
1376
|
+
}
|
|
1377
|
+
dispose(t = true) {
|
|
1378
|
+
this.faceFeatureExtractor.dispose(t), super.dispose(t);
|
|
1379
|
+
}
|
|
1380
|
+
loadClassifierParams(t) {
|
|
1381
|
+
let { params: e, paramMappings: r } = this.extractClassifierParams(t);
|
|
1382
|
+
this._params = e, this._paramMappings = r;
|
|
1383
|
+
}
|
|
1384
|
+
extractClassifierParams(t) {
|
|
1385
|
+
return Rr(t);
|
|
1386
|
+
}
|
|
1387
|
+
extractParamsFromWeightMap(t) {
|
|
1388
|
+
let { featureExtractorMap: e, classifierMap: r } = Pe(t);
|
|
1389
|
+
return this.faceFeatureExtractor.loadFromWeightMap(e), $r(r);
|
|
1390
|
+
}
|
|
1391
|
+
extractParams(t) {
|
|
1392
|
+
let r = t.slice(0, t.length - 1539), a = t.slice(t.length - 1539);
|
|
1393
|
+
return this.faceFeatureExtractor.extractWeights(r), this.extractClassifierParams(a);
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
var Vt = class extends zt {
|
|
1397
|
+
postProcess(t, e, r) {
|
|
1398
|
+
let a = r.map(({ width: s, height: c }) => {
|
|
1399
|
+
let m = e / Math.max(c, s);
|
|
1400
|
+
return { width: s * m, height: c * m };
|
|
1401
|
+
}), i = a.length;
|
|
1402
|
+
return n.tidy(() => {
|
|
1403
|
+
let s = (f, l) => n.stack([n.fill([68], f, "float32"), n.fill([68], l, "float32")], 1).as2D(1, 136).as1D(), c = (f, l) => {
|
|
1404
|
+
let { width: d, height: b } = a[f];
|
|
1405
|
+
return l(d, b) ? Math.abs(d - b) / 2 : 0;
|
|
1406
|
+
}, m = (f) => c(f, (l, d) => l < d), p = (f) => c(f, (l, d) => d < l);
|
|
1407
|
+
return t.mul(n.fill([i, 136], e, "float32")).sub(n.stack(Array.from(Array(i), (f, l) => s(m(l), p(l))))).div(n.stack(Array.from(Array(i), (f, l) => s(a[l].width, a[l].height))));
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
forwardInput(t) {
|
|
1411
|
+
return n.tidy(() => {
|
|
1412
|
+
let e = this.runNet(t);
|
|
1413
|
+
return this.postProcess(e, t.inputSize, t.inputDimensions.map(([r, a]) => ({ height: r, width: a })));
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
async forward(t) {
|
|
1417
|
+
return this.forwardInput(await F(t));
|
|
1418
|
+
}
|
|
1419
|
+
async detectLandmarks(t) {
|
|
1420
|
+
let e = await F(t), r = n.tidy(() => n.unstack(this.forwardInput(e))), a = await Promise.all(r.map(async (i, s) => {
|
|
1421
|
+
let c = Array.from(i.dataSync()), m = c.filter((u, f) => pe(f)), p = c.filter((u, f) => !pe(f));
|
|
1422
|
+
return new Lt(Array(68).fill(0).map((u, f) => new v(m[f], p[f])), { height: e.getInputHeight(s), width: e.getInputWidth(s) });
|
|
1423
|
+
}));
|
|
1424
|
+
return r.forEach((i) => i.dispose()), e.isBatchInput ? a : a[0];
|
|
1425
|
+
}
|
|
1426
|
+
getClassifierChannelsOut() {
|
|
1427
|
+
return 136;
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
var Gt = class extends Vt {
|
|
1431
|
+
constructor(t = new Ht()) {
|
|
1432
|
+
super("FaceLandmark68Net", t);
|
|
1433
|
+
}
|
|
1434
|
+
getDefaultModelName() {
|
|
1435
|
+
return "face_landmark_68_model";
|
|
1436
|
+
}
|
|
1437
|
+
getClassifierChannelsIn() {
|
|
1438
|
+
return 256;
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
function Or(o9) {
|
|
1442
|
+
let t = [], { extractDenseBlock3Params: e } = _e(o9, t), r = { dense0: e("dense0", true), dense1: e("dense1"), dense2: e("dense2") };
|
|
1443
|
+
return N(o9, t), { params: r, paramMappings: t };
|
|
1444
|
+
}
|
|
1445
|
+
function Hr(o9) {
|
|
1446
|
+
let t = [], { extractWeights: e, getRemainingWeights: r } = L(o9), { extractDenseBlock3Params: a } = ye(e, t), i = a(3, 32, "dense0", true), s = a(32, 64, "dense1"), c = a(64, 128, "dense2");
|
|
1447
|
+
if (r().length !== 0) throw new Error(`weights remaing after extract: ${r().length}`);
|
|
1448
|
+
return { paramMappings: t, params: { dense0: i, dense1: s, dense2: c } };
|
|
1449
|
+
}
|
|
1450
|
+
var Ce = class extends I {
|
|
1451
|
+
constructor() {
|
|
1452
|
+
super("TinyFaceFeatureExtractor");
|
|
1453
|
+
}
|
|
1454
|
+
forwardInput(t) {
|
|
1455
|
+
let { params: e } = this;
|
|
1456
|
+
if (!e) throw new Error("TinyFaceFeatureExtractor - load model before inference");
|
|
1457
|
+
return n.tidy(() => {
|
|
1458
|
+
let r = n.cast(t.toBatchTensor(112, true), "float32"), i = J(r, [122.782, 117.001, 104.298]).div(255), s = xe(i, e.dense0, true);
|
|
1459
|
+
return s = xe(s, e.dense1), s = xe(s, e.dense2), s = n.avgPool(s, [14, 14], [2, 2], "valid"), s;
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
async forward(t) {
|
|
1463
|
+
return this.forwardInput(await F(t));
|
|
1464
|
+
}
|
|
1465
|
+
getDefaultModelName() {
|
|
1466
|
+
return "face_feature_extractor_tiny_model";
|
|
1467
|
+
}
|
|
1468
|
+
extractParamsFromWeightMap(t) {
|
|
1469
|
+
return Or(t);
|
|
1470
|
+
}
|
|
1471
|
+
extractParams(t) {
|
|
1472
|
+
return Hr(t);
|
|
1473
|
+
}
|
|
1474
|
+
};
|
|
1475
|
+
var Ie = class extends Vt {
|
|
1476
|
+
constructor(t = new Ce()) {
|
|
1477
|
+
super("FaceLandmark68TinyNet", t);
|
|
1478
|
+
}
|
|
1479
|
+
getDefaultModelName() {
|
|
1480
|
+
return "face_landmark_68_tiny_model";
|
|
1481
|
+
}
|
|
1482
|
+
getClassifierChannelsIn() {
|
|
1483
|
+
return 128;
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1486
|
+
var zr = class extends Gt {
|
|
1487
|
+
};
|
|
1488
|
+
function Yr(o9, t) {
|
|
1489
|
+
return n.add(n.mul(o9, t.weights), t.biases);
|
|
1490
|
+
}
|
|
1491
|
+
function or(o9, t, e, r, a = "same") {
|
|
1492
|
+
let { filters: i, bias: s } = t.conv, c = n.conv2d(o9, i, e, a);
|
|
1493
|
+
return c = n.add(c, s), c = Yr(c, t.scale), r ? n.relu(c) : c;
|
|
1494
|
+
}
|
|
1495
|
+
function Vr(o9, t) {
|
|
1496
|
+
return or(o9, t, [1, 1], true);
|
|
1497
|
+
}
|
|
1498
|
+
function nr(o9, t) {
|
|
1499
|
+
return or(o9, t, [1, 1], false);
|
|
1500
|
+
}
|
|
1501
|
+
function Ne(o9, t) {
|
|
1502
|
+
return or(o9, t, [2, 2], true, "valid");
|
|
1503
|
+
}
|
|
1504
|
+
function $o(o9, t) {
|
|
1505
|
+
function e(c, m, p) {
|
|
1506
|
+
let u = o9(c), f = u.length / (m * p * p);
|
|
1507
|
+
if (Ge(f)) throw new Error(`depth has to be an integer: ${f}, weights.length: ${u.length}, numFilters: ${m}, filterSize: ${p}`);
|
|
1508
|
+
return n.tidy(() => n.transpose(n.tensor4d(u, [m, f, p, p]), [2, 3, 1, 0]));
|
|
1509
|
+
}
|
|
1510
|
+
function r(c, m, p, u) {
|
|
1511
|
+
let f = e(c, m, p), l = n.tensor1d(o9(m));
|
|
1512
|
+
return t.push({ paramPath: `${u}/filters` }, { paramPath: `${u}/bias` }), { filters: f, bias: l };
|
|
1513
|
+
}
|
|
1514
|
+
function a(c, m) {
|
|
1515
|
+
let p = n.tensor1d(o9(c)), u = n.tensor1d(o9(c));
|
|
1516
|
+
return t.push({ paramPath: `${m}/weights` }, { paramPath: `${m}/biases` }), { weights: p, biases: u };
|
|
1517
|
+
}
|
|
1518
|
+
function i(c, m, p, u) {
|
|
1519
|
+
let f = r(c, m, p, `${u}/conv`), l = a(m, `${u}/scale`);
|
|
1520
|
+
return { conv: f, scale: l };
|
|
1521
|
+
}
|
|
1522
|
+
function s(c, m, p, u, f = false) {
|
|
1523
|
+
let l = i((f ? 0.5 : 1) * c, m, p, `${u}/conv1`), d = i(c, m, p, `${u}/conv2`);
|
|
1524
|
+
return { conv1: l, conv2: d };
|
|
1525
|
+
}
|
|
1526
|
+
return { extractConvLayerParams: i, extractResidualLayerParams: s };
|
|
1527
|
+
}
|
|
1528
|
+
function Gr(o9) {
|
|
1529
|
+
let { extractWeights: t, getRemainingWeights: e } = L(o9), r = [], { extractConvLayerParams: a, extractResidualLayerParams: i } = $o(t, r), s = a(4704, 32, 7, "conv32_down"), c = i(9216, 32, 3, "conv32_1"), m = i(9216, 32, 3, "conv32_2"), p = i(9216, 32, 3, "conv32_3"), u = i(36864, 64, 3, "conv64_down", true), f = i(36864, 64, 3, "conv64_1"), l = i(36864, 64, 3, "conv64_2"), d = i(36864, 64, 3, "conv64_3"), b = i(147456, 128, 3, "conv128_down", true), y = i(147456, 128, 3, "conv128_1"), h = i(147456, 128, 3, "conv128_2"), g = i(589824, 256, 3, "conv256_down", true), T = i(589824, 256, 3, "conv256_1"), x = i(589824, 256, 3, "conv256_2"), E = i(589824, 256, 3, "conv256_down_out"), B = n.tidy(() => n.transpose(n.tensor2d(t(256 * 128), [128, 256]), [1, 0]));
|
|
1530
|
+
if (r.push({ paramPath: "fc" }), e().length !== 0) throw new Error(`weights remaing after extract: ${e().length}`);
|
|
1531
|
+
return { params: { conv32_down: s, conv32_1: c, conv32_2: m, conv32_3: p, conv64_down: u, conv64_1: f, conv64_2: l, conv64_3: d, conv128_down: b, conv128_1: y, conv128_2: h, conv256_down: g, conv256_1: T, conv256_2: x, conv256_down_out: E, fc: B }, paramMappings: r };
|
|
1532
|
+
}
|
|
1533
|
+
function Oo(o9, t) {
|
|
1534
|
+
let e = k(o9, t);
|
|
1535
|
+
function r(s) {
|
|
1536
|
+
let c = e(`${s}/scale/weights`, 1), m = e(`${s}/scale/biases`, 1);
|
|
1537
|
+
return { weights: c, biases: m };
|
|
1538
|
+
}
|
|
1539
|
+
function a(s) {
|
|
1540
|
+
let c = e(`${s}/conv/filters`, 4), m = e(`${s}/conv/bias`, 1), p = r(s);
|
|
1541
|
+
return { conv: { filters: c, bias: m }, scale: p };
|
|
1542
|
+
}
|
|
1543
|
+
function i(s) {
|
|
1544
|
+
return { conv1: a(`${s}/conv1`), conv2: a(`${s}/conv2`) };
|
|
1545
|
+
}
|
|
1546
|
+
return { extractConvLayerParams: a, extractResidualLayerParams: i };
|
|
1547
|
+
}
|
|
1548
|
+
function jr(o9) {
|
|
1549
|
+
let t = [], { extractConvLayerParams: e, extractResidualLayerParams: r } = Oo(o9, t), a = e("conv32_down"), i = r("conv32_1"), s = r("conv32_2"), c = r("conv32_3"), m = r("conv64_down"), p = r("conv64_1"), u = r("conv64_2"), f = r("conv64_3"), l = r("conv128_down"), d = r("conv128_1"), b = r("conv128_2"), y = r("conv256_down"), h = r("conv256_1"), g = r("conv256_2"), T = r("conv256_down_out"), { fc: x } = o9;
|
|
1550
|
+
if (t.push({ originalPath: "fc", paramPath: "fc" }), !Ve(x)) throw new Error(`expected weightMap[fc] to be a Tensor2D, instead have ${x}`);
|
|
1551
|
+
let E = { conv32_down: a, conv32_1: i, conv32_2: s, conv32_3: c, conv64_down: m, conv64_1: p, conv64_2: u, conv64_3: f, conv128_down: l, conv128_1: d, conv128_2: b, conv256_down: y, conv256_1: h, conv256_2: g, conv256_down_out: T, fc: x };
|
|
1552
|
+
return N(o9, t), { params: E, paramMappings: t };
|
|
1553
|
+
}
|
|
1554
|
+
function j(o9, t) {
|
|
1555
|
+
let e = Vr(o9, t.conv1);
|
|
1556
|
+
return e = nr(e, t.conv2), e = n.add(e, o9), e = n.relu(e), e;
|
|
1557
|
+
}
|
|
1558
|
+
function ce(o9, t) {
|
|
1559
|
+
let e = Ne(o9, t.conv1);
|
|
1560
|
+
e = nr(e, t.conv2);
|
|
1561
|
+
let r = n.avgPool(o9, 2, 2, "valid"), a = n.zeros(r.shape), i = r.shape[3] !== e.shape[3];
|
|
1562
|
+
if (r.shape[1] !== e.shape[1] || r.shape[2] !== e.shape[2]) {
|
|
1563
|
+
let c = [...e.shape];
|
|
1564
|
+
c[1] = 1;
|
|
1565
|
+
let m = n.zeros(c);
|
|
1566
|
+
e = n.concat([e, m], 1);
|
|
1567
|
+
let p = [...e.shape];
|
|
1568
|
+
p[2] = 1;
|
|
1569
|
+
let u = n.zeros(p);
|
|
1570
|
+
e = n.concat([e, u], 2);
|
|
1571
|
+
}
|
|
1572
|
+
return r = i ? n.concat([r, a], 3) : r, e = n.add(r, e), e = n.relu(e), e;
|
|
1573
|
+
}
|
|
1574
|
+
var jt = class extends I {
|
|
1575
|
+
constructor() {
|
|
1576
|
+
super("FaceRecognitionNet");
|
|
1577
|
+
}
|
|
1578
|
+
forwardInput(t) {
|
|
1579
|
+
let { params: e } = this;
|
|
1580
|
+
if (!e) throw new Error("FaceRecognitionNet - load model before inference");
|
|
1581
|
+
return n.tidy(() => {
|
|
1582
|
+
let r = n.cast(t.toBatchTensor(150, true), "float32"), i = J(r, [122.782, 117.001, 104.298]).div(255), s = Ne(i, e.conv32_down);
|
|
1583
|
+
s = n.maxPool(s, 3, 2, "valid"), s = j(s, e.conv32_1), s = j(s, e.conv32_2), s = j(s, e.conv32_3), s = ce(s, e.conv64_down), s = j(s, e.conv64_1), s = j(s, e.conv64_2), s = j(s, e.conv64_3), s = ce(s, e.conv128_down), s = j(s, e.conv128_1), s = j(s, e.conv128_2), s = ce(s, e.conv256_down), s = j(s, e.conv256_1), s = j(s, e.conv256_2), s = ce(s, e.conv256_down_out);
|
|
1584
|
+
let c = s.mean([1, 2]);
|
|
1585
|
+
return n.matMul(c, e.fc);
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
async forward(t) {
|
|
1589
|
+
return this.forwardInput(await F(t));
|
|
1590
|
+
}
|
|
1591
|
+
async computeFaceDescriptor(t) {
|
|
1592
|
+
var i;
|
|
1593
|
+
if ((i = t == null ? void 0 : t.shape) != null && i.some((s) => s <= 0)) return new Float32Array(128);
|
|
1594
|
+
let e = await F(t), r = n.tidy(() => n.unstack(this.forwardInput(e))), a = await Promise.all(r.map((s) => s.data()));
|
|
1595
|
+
return r.forEach((s) => s.dispose()), e.isBatchInput ? a : a[0];
|
|
1596
|
+
}
|
|
1597
|
+
getDefaultModelName() {
|
|
1598
|
+
return "face_recognition_model";
|
|
1599
|
+
}
|
|
1600
|
+
extractParamsFromWeightMap(t) {
|
|
1601
|
+
return jr(t);
|
|
1602
|
+
}
|
|
1603
|
+
extractParams(t) {
|
|
1604
|
+
return Gr(t);
|
|
1605
|
+
}
|
|
1606
|
+
};
|
|
1607
|
+
function gf(o9) {
|
|
1608
|
+
let t = new jt();
|
|
1609
|
+
return t.extractWeights(o9), t;
|
|
1610
|
+
}
|
|
1611
|
+
function ar(o9, t) {
|
|
1612
|
+
return { ...o9, ...{ descriptor: t } };
|
|
1613
|
+
}
|
|
1614
|
+
function Tf(o9) {
|
|
1615
|
+
return typeof o9.age == "number";
|
|
1616
|
+
}
|
|
1617
|
+
function sr(o9, t) {
|
|
1618
|
+
return { ...o9, ...{ age: t } };
|
|
1619
|
+
}
|
|
1620
|
+
function Ff(o9) {
|
|
1621
|
+
return (o9.gender === "male" || o9.gender === "female") && Mt(o9.genderProbability);
|
|
1622
|
+
}
|
|
1623
|
+
function ir(o9, t, e) {
|
|
1624
|
+
return { ...o9, ...{ gender: t, genderProbability: e } };
|
|
1625
|
+
}
|
|
1626
|
+
function Ho(o9, t) {
|
|
1627
|
+
function e(m, p) {
|
|
1628
|
+
let u = n.tensor4d(o9(9 * m), [3, 3, m, 1]), f = n.tensor1d(o9(m)), l = n.tensor1d(o9(m)), d = n.tensor1d(o9(m)), b = n.tensor1d(o9(m));
|
|
1629
|
+
return t.push({ paramPath: `${p}/filters` }, { paramPath: `${p}/batch_norm_scale` }, { paramPath: `${p}/batch_norm_offset` }, { paramPath: `${p}/batch_norm_mean` }, { paramPath: `${p}/batch_norm_variance` }), { filters: u, batch_norm_scale: f, batch_norm_offset: l, batch_norm_mean: d, batch_norm_variance: b };
|
|
1630
|
+
}
|
|
1631
|
+
function r(m, p, u, f, l) {
|
|
1632
|
+
let d = n.tensor4d(o9(m * p * u * u), [u, u, m, p]), b = n.tensor1d(o9(p));
|
|
1633
|
+
return t.push({ paramPath: `${f}/filters` }, { paramPath: `${f}/${l ? "batch_norm_offset" : "bias"}` }), { filters: d, bias: b };
|
|
1634
|
+
}
|
|
1635
|
+
function a(m, p, u, f) {
|
|
1636
|
+
let { filters: l, bias: d } = r(m, p, u, f, true);
|
|
1637
|
+
return { filters: l, batch_norm_offset: d };
|
|
1638
|
+
}
|
|
1639
|
+
function i(m, p, u) {
|
|
1640
|
+
let f = e(m, `${u}/depthwise_conv`), l = a(m, p, 1, `${u}/pointwise_conv`);
|
|
1641
|
+
return { depthwise_conv: f, pointwise_conv: l };
|
|
1642
|
+
}
|
|
1643
|
+
function s() {
|
|
1644
|
+
let m = a(3, 32, 3, "mobilenetv1/conv_0"), p = i(32, 64, "mobilenetv1/conv_1"), u = i(64, 128, "mobilenetv1/conv_2"), f = i(128, 128, "mobilenetv1/conv_3"), l = i(128, 256, "mobilenetv1/conv_4"), d = i(256, 256, "mobilenetv1/conv_5"), b = i(256, 512, "mobilenetv1/conv_6"), y = i(512, 512, "mobilenetv1/conv_7"), h = i(512, 512, "mobilenetv1/conv_8"), g = i(512, 512, "mobilenetv1/conv_9"), T = i(512, 512, "mobilenetv1/conv_10"), x = i(512, 512, "mobilenetv1/conv_11"), E = i(512, 1024, "mobilenetv1/conv_12"), B = i(1024, 1024, "mobilenetv1/conv_13");
|
|
1645
|
+
return { conv_0: m, conv_1: p, conv_2: u, conv_3: f, conv_4: l, conv_5: d, conv_6: b, conv_7: y, conv_8: h, conv_9: g, conv_10: T, conv_11: x, conv_12: E, conv_13: B };
|
|
1646
|
+
}
|
|
1647
|
+
function c() {
|
|
1648
|
+
let m = a(1024, 256, 1, "prediction_layer/conv_0"), p = a(256, 512, 3, "prediction_layer/conv_1"), u = a(512, 128, 1, "prediction_layer/conv_2"), f = a(128, 256, 3, "prediction_layer/conv_3"), l = a(256, 128, 1, "prediction_layer/conv_4"), d = a(128, 256, 3, "prediction_layer/conv_5"), b = a(256, 64, 1, "prediction_layer/conv_6"), y = a(64, 128, 3, "prediction_layer/conv_7"), h = r(512, 12, 1, "prediction_layer/box_predictor_0/box_encoding_predictor"), g = r(512, 9, 1, "prediction_layer/box_predictor_0/class_predictor"), T = r(1024, 24, 1, "prediction_layer/box_predictor_1/box_encoding_predictor"), x = r(1024, 18, 1, "prediction_layer/box_predictor_1/class_predictor"), E = r(512, 24, 1, "prediction_layer/box_predictor_2/box_encoding_predictor"), B = r(512, 18, 1, "prediction_layer/box_predictor_2/class_predictor"), V = r(256, 24, 1, "prediction_layer/box_predictor_3/box_encoding_predictor"), U = r(256, 18, 1, "prediction_layer/box_predictor_3/class_predictor"), O = r(256, 24, 1, "prediction_layer/box_predictor_4/box_encoding_predictor"), ot = r(256, 18, 1, "prediction_layer/box_predictor_4/class_predictor"), nt = r(128, 24, 1, "prediction_layer/box_predictor_5/box_encoding_predictor"), at = r(128, 18, 1, "prediction_layer/box_predictor_5/class_predictor");
|
|
1649
|
+
return { conv_0: m, conv_1: p, conv_2: u, conv_3: f, conv_4: l, conv_5: d, conv_6: b, conv_7: y, box_predictor_0: { box_encoding_predictor: h, class_predictor: g }, box_predictor_1: { box_encoding_predictor: T, class_predictor: x }, box_predictor_2: { box_encoding_predictor: E, class_predictor: B }, box_predictor_3: { box_encoding_predictor: V, class_predictor: U }, box_predictor_4: { box_encoding_predictor: O, class_predictor: ot }, box_predictor_5: { box_encoding_predictor: nt, class_predictor: at } };
|
|
1650
|
+
}
|
|
1651
|
+
return { extractMobilenetV1Params: s, extractPredictionLayerParams: c };
|
|
1652
|
+
}
|
|
1653
|
+
function Ur(o9) {
|
|
1654
|
+
let t = [], { extractWeights: e, getRemainingWeights: r } = L(o9), { extractMobilenetV1Params: a, extractPredictionLayerParams: i } = Ho(e, t), s = a(), c = i(), p = { extra_dim: n.tensor3d(e(5118 * 4), [1, 5118, 4]) };
|
|
1655
|
+
if (t.push({ paramPath: "output_layer/extra_dim" }), r().length !== 0) throw new Error(`weights remaing after extract: ${r().length}`);
|
|
1656
|
+
return { params: { mobilenetv1: s, prediction_layer: c, output_layer: p }, paramMappings: t };
|
|
1657
|
+
}
|
|
1658
|
+
function zo(o9, t) {
|
|
1659
|
+
let e = k(o9, t);
|
|
1660
|
+
function r(p, u, f) {
|
|
1661
|
+
let l = e(`${p}/Conv2d_${u}_pointwise/weights`, 4, `${f}/filters`), d = e(`${p}/Conv2d_${u}_pointwise/convolution_bn_offset`, 1, `${f}/batch_norm_offset`);
|
|
1662
|
+
return { filters: l, batch_norm_offset: d };
|
|
1663
|
+
}
|
|
1664
|
+
function a(p) {
|
|
1665
|
+
let u = `mobilenetv1/conv_${p}`, f = `MobilenetV1/Conv2d_${p}_depthwise`, l = `${u}/depthwise_conv`, d = `${u}/pointwise_conv`, b = e(`${f}/depthwise_weights`, 4, `${l}/filters`), y = e(`${f}/BatchNorm/gamma`, 1, `${l}/batch_norm_scale`), h = e(`${f}/BatchNorm/beta`, 1, `${l}/batch_norm_offset`), g = e(`${f}/BatchNorm/moving_mean`, 1, `${l}/batch_norm_mean`), T = e(`${f}/BatchNorm/moving_variance`, 1, `${l}/batch_norm_variance`);
|
|
1666
|
+
return { depthwise_conv: { filters: b, batch_norm_scale: y, batch_norm_offset: h, batch_norm_mean: g, batch_norm_variance: T }, pointwise_conv: r("MobilenetV1", p, d) };
|
|
1667
|
+
}
|
|
1668
|
+
function i() {
|
|
1669
|
+
return { conv_0: r("MobilenetV1", 0, "mobilenetv1/conv_0"), conv_1: a(1), conv_2: a(2), conv_3: a(3), conv_4: a(4), conv_5: a(5), conv_6: a(6), conv_7: a(7), conv_8: a(8), conv_9: a(9), conv_10: a(10), conv_11: a(11), conv_12: a(12), conv_13: a(13) };
|
|
1670
|
+
}
|
|
1671
|
+
function s(p, u) {
|
|
1672
|
+
let f = e(`${p}/weights`, 4, `${u}/filters`), l = e(`${p}/biases`, 1, `${u}/bias`);
|
|
1673
|
+
return { filters: f, bias: l };
|
|
1674
|
+
}
|
|
1675
|
+
function c(p) {
|
|
1676
|
+
let u = s(`Prediction/BoxPredictor_${p}/BoxEncodingPredictor`, `prediction_layer/box_predictor_${p}/box_encoding_predictor`), f = s(`Prediction/BoxPredictor_${p}/ClassPredictor`, `prediction_layer/box_predictor_${p}/class_predictor`);
|
|
1677
|
+
return { box_encoding_predictor: u, class_predictor: f };
|
|
1678
|
+
}
|
|
1679
|
+
function m() {
|
|
1680
|
+
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: c(0), box_predictor_1: c(1), box_predictor_2: c(2), box_predictor_3: c(3), box_predictor_4: c(4), box_predictor_5: c(5) };
|
|
1681
|
+
}
|
|
1682
|
+
return { extractMobilenetV1Params: i, extractPredictionLayerParams: m };
|
|
1683
|
+
}
|
|
1684
|
+
function Xr(o9) {
|
|
1685
|
+
let t = [], { extractMobilenetV1Params: e, extractPredictionLayerParams: r } = zo(o9, t), a = o9["Output/extra_dim"];
|
|
1686
|
+
if (t.push({ originalPath: "Output/extra_dim", paramPath: "output_layer/extra_dim" }), !K(a)) throw new Error(`expected weightMap['Output/extra_dim'] to be a Tensor3D, instead have ${a}`);
|
|
1687
|
+
let i = { mobilenetv1: e(), prediction_layer: r(), output_layer: { extra_dim: a } };
|
|
1688
|
+
return N(o9, t), { params: i, paramMappings: t };
|
|
1689
|
+
}
|
|
1690
|
+
function H(o9, t, e) {
|
|
1691
|
+
return n.tidy(() => {
|
|
1692
|
+
let r = n.conv2d(o9, t.filters, e, "same");
|
|
1693
|
+
return r = n.add(r, t.batch_norm_offset), n.clipByValue(r, 0, 6);
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
var Yo = 0.0010000000474974513;
|
|
1697
|
+
function Vo(o9, t, e) {
|
|
1698
|
+
return n.tidy(() => {
|
|
1699
|
+
let r = n.depthwiseConv2d(o9, t.filters, e, "same");
|
|
1700
|
+
return r = n.batchNorm(r, t.batch_norm_mean, t.batch_norm_variance, t.batch_norm_offset, t.batch_norm_scale, Yo), n.clipByValue(r, 0, 6);
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
function Go(o9) {
|
|
1704
|
+
return [2, 4, 6, 12].some((t) => t === o9) ? [2, 2] : [1, 1];
|
|
1705
|
+
}
|
|
1706
|
+
function Jr(o9, t) {
|
|
1707
|
+
return n.tidy(() => {
|
|
1708
|
+
let e, r = H(o9, t.conv_0, [2, 2]);
|
|
1709
|
+
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((i, s) => {
|
|
1710
|
+
let c = s + 1, m = Go(c);
|
|
1711
|
+
r = Vo(r, i.depthwise_conv, m), r = H(r, i.pointwise_conv, [1, 1]), c === 11 && (e = r);
|
|
1712
|
+
}), e === null) throw new Error("mobileNetV1 - output of conv layer 11 is null");
|
|
1713
|
+
return { out: r, conv11: e };
|
|
1714
|
+
});
|
|
1715
|
+
}
|
|
1716
|
+
function jo(o9, t, e) {
|
|
1717
|
+
let r = o9.arraySync(), a = Math.min(r[t][0], r[t][2]), i = Math.min(r[t][1], r[t][3]), s = Math.max(r[t][0], r[t][2]), c = Math.max(r[t][1], r[t][3]), m = Math.min(r[e][0], r[e][2]), p = Math.min(r[e][1], r[e][3]), u = Math.max(r[e][0], r[e][2]), f = Math.max(r[e][1], r[e][3]), l = (s - a) * (c - i), d = (u - m) * (f - p);
|
|
1718
|
+
if (l <= 0 || d <= 0) return 0;
|
|
1719
|
+
let b = Math.max(a, m), y = Math.max(i, p), h = Math.min(s, u), g = Math.min(c, f), T = Math.max(h - b, 0) * Math.max(g - y, 0);
|
|
1720
|
+
return T / (l + d - T);
|
|
1721
|
+
}
|
|
1722
|
+
function qr(o9, t, e, r, a) {
|
|
1723
|
+
let i = o9.shape[0], s = Math.min(e, i), c = t.map((u, f) => ({ score: u, boxIndex: f })).filter((u) => u.score > a).sort((u, f) => f.score - u.score), m = (u) => u <= r ? 1 : 0, p = [];
|
|
1724
|
+
return c.forEach((u) => {
|
|
1725
|
+
if (p.length >= s) return;
|
|
1726
|
+
let f = u.score;
|
|
1727
|
+
for (let l = p.length - 1; l >= 0; --l) {
|
|
1728
|
+
let d = jo(o9, u.boxIndex, p[l]);
|
|
1729
|
+
if (d !== 0 && (u.score *= m(d), u.score <= a)) break;
|
|
1730
|
+
}
|
|
1731
|
+
f === u.score && p.push(u.boxIndex);
|
|
1732
|
+
}), p;
|
|
1733
|
+
}
|
|
1734
|
+
function Uo(o9) {
|
|
1735
|
+
let t = n.unstack(n.transpose(o9, [1, 0])), e = [n.sub(t[2], t[0]), n.sub(t[3], t[1])], r = [n.add(t[0], n.div(e[0], 2)), n.add(t[1], n.div(e[1], 2))];
|
|
1736
|
+
return { sizes: e, centers: r };
|
|
1737
|
+
}
|
|
1738
|
+
function Xo(o9, t) {
|
|
1739
|
+
let { sizes: e, centers: r } = Uo(o9), a = n.unstack(n.transpose(t, [1, 0])), i = n.div(n.mul(n.exp(n.div(a[2], 5)), e[0]), 2), s = n.add(n.mul(n.div(a[0], 10), e[0]), r[0]), c = n.div(n.mul(n.exp(n.div(a[3], 5)), e[1]), 2), m = n.add(n.mul(n.div(a[1], 10), e[1]), r[1]);
|
|
1740
|
+
return n.transpose(n.stack([n.sub(s, i), n.sub(m, c), n.add(s, i), n.add(m, c)]), [1, 0]);
|
|
1741
|
+
}
|
|
1742
|
+
function Zr(o9, t, e) {
|
|
1743
|
+
return n.tidy(() => {
|
|
1744
|
+
let r = o9.shape[0], a = Xo(n.reshape(n.tile(e.extra_dim, [r, 1, 1]), [-1, 4]), n.reshape(o9, [-1, 4]));
|
|
1745
|
+
a = n.reshape(a, [r, a.shape[0] / r, 4]);
|
|
1746
|
+
let i = n.sigmoid(n.slice(t, [0, 0, 1], [-1, -1, -1])), s = n.slice(i, [0, 0, 0], [-1, -1, 1]);
|
|
1747
|
+
s = n.reshape(s, [r, s.shape[1]]);
|
|
1748
|
+
let c = n.unstack(a), m = n.unstack(s);
|
|
1749
|
+
return { boxes: c, scores: m };
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
function yt(o9, t) {
|
|
1753
|
+
return n.tidy(() => {
|
|
1754
|
+
let e = o9.shape[0], r = n.reshape(vt(o9, t.box_encoding_predictor), [e, -1, 1, 4]), a = n.reshape(vt(o9, t.class_predictor), [e, -1, 3]);
|
|
1755
|
+
return { boxPredictionEncoding: r, classPrediction: a };
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
function Kr(o9, t, e) {
|
|
1759
|
+
return n.tidy(() => {
|
|
1760
|
+
let r = H(o9, e.conv_0, [1, 1]), a = H(r, e.conv_1, [2, 2]), i = H(a, e.conv_2, [1, 1]), s = H(i, e.conv_3, [2, 2]), c = H(s, e.conv_4, [1, 1]), m = H(c, e.conv_5, [2, 2]), p = H(m, e.conv_6, [1, 1]), u = H(p, e.conv_7, [2, 2]), f = yt(t, e.box_predictor_0), l = yt(o9, e.box_predictor_1), d = yt(a, e.box_predictor_2), b = yt(s, e.box_predictor_3), y = yt(m, e.box_predictor_4), h = yt(u, e.box_predictor_5), g = n.concat([f.boxPredictionEncoding, l.boxPredictionEncoding, d.boxPredictionEncoding, b.boxPredictionEncoding, y.boxPredictionEncoding, h.boxPredictionEncoding], 1), T = n.concat([f.classPrediction, l.classPrediction, d.classPrediction, b.classPrediction, y.classPrediction, h.classPrediction], 1);
|
|
1761
|
+
return { boxPredictions: g, classPredictions: T };
|
|
1762
|
+
});
|
|
1763
|
+
}
|
|
1764
|
+
var z = class {
|
|
1765
|
+
constructor({ minConfidence: t, maxResults: e } = {}) {
|
|
1766
|
+
this._name = "SsdMobilenetv1Options";
|
|
1767
|
+
if (this._minConfidence = t || 0.5, this._maxResults = e || 100, typeof this._minConfidence != "number" || this._minConfidence <= 0 || this._minConfidence >= 1) throw new Error(`${this._name} - expected minConfidence to be a number between 0 and 1`);
|
|
1768
|
+
if (typeof this._maxResults != "number") throw new Error(`${this._name} - expected maxResults to be a number`);
|
|
1769
|
+
}
|
|
1770
|
+
get minConfidence() {
|
|
1771
|
+
return this._minConfidence;
|
|
1772
|
+
}
|
|
1773
|
+
get maxResults() {
|
|
1774
|
+
return this._maxResults;
|
|
1775
|
+
}
|
|
1776
|
+
};
|
|
1777
|
+
var Tt = class extends I {
|
|
1778
|
+
constructor() {
|
|
1779
|
+
super("SsdMobilenetv1");
|
|
1780
|
+
}
|
|
1781
|
+
forwardInput(t) {
|
|
1782
|
+
let { params: e } = this;
|
|
1783
|
+
if (!e) throw new Error("SsdMobilenetv1 - load model before inference");
|
|
1784
|
+
return n.tidy(() => {
|
|
1785
|
+
let r = n.cast(t.toBatchTensor(512, false), "float32"), a = n.sub(n.div(r, 127.5), 1), i = Jr(a, e.mobilenetv1), { boxPredictions: s, classPredictions: c } = Kr(i.out, i.conv11, e.prediction_layer);
|
|
1786
|
+
return Zr(s, c, e.output_layer);
|
|
1787
|
+
});
|
|
1788
|
+
}
|
|
1789
|
+
async forward(t) {
|
|
1790
|
+
return this.forwardInput(await F(t));
|
|
1791
|
+
}
|
|
1792
|
+
async locateFaces(t, e = {}) {
|
|
1793
|
+
let { maxResults: r, minConfidence: a } = new z(e), i = await F(t), { boxes: s, scores: c } = this.forwardInput(i), m = s[0], p = c[0];
|
|
1794
|
+
for (let x = 1; x < s.length; x++) s[x].dispose(), c[x].dispose();
|
|
1795
|
+
let u = Array.from(p.dataSync()), l = qr(m, u, r, 0.5, a), d = i.getReshapedInputDimensions(0), b = i.inputSize, y = b / d.width, h = b / d.height, g = m.arraySync(), T = l.map((x) => {
|
|
1796
|
+
let [E, B] = [Math.max(0, g[x][0]), Math.min(1, g[x][2])].map((O) => O * h), [V, U] = [Math.max(0, g[x][1]), Math.min(1, g[x][3])].map((O) => O * y);
|
|
1797
|
+
return new D(u[x], new Nt(V, E, U - V, B - E), { height: i.getInputHeight(0), width: i.getInputWidth(0) });
|
|
1798
|
+
});
|
|
1799
|
+
return m.dispose(), p.dispose(), T;
|
|
1800
|
+
}
|
|
1801
|
+
getDefaultModelName() {
|
|
1802
|
+
return "ssd_mobilenetv1_model";
|
|
1803
|
+
}
|
|
1804
|
+
extractParamsFromWeightMap(t) {
|
|
1805
|
+
return Xr(t);
|
|
1806
|
+
}
|
|
1807
|
+
extractParams(t) {
|
|
1808
|
+
return Ur(t);
|
|
1809
|
+
}
|
|
1810
|
+
};
|
|
1811
|
+
function Jo(o9) {
|
|
1812
|
+
let t = new Tt();
|
|
1813
|
+
return t.extractWeights(o9), t;
|
|
1814
|
+
}
|
|
1815
|
+
function gl(o9) {
|
|
1816
|
+
return Jo(o9);
|
|
1817
|
+
}
|
|
1818
|
+
var Qr = class extends Tt {
|
|
1819
|
+
};
|
|
1820
|
+
var to = 0.4, eo = [new v(0.738768, 0.874946), new v(2.42204, 2.65704), new v(4.30971, 7.04493), new v(10.246, 4.59428), new v(12.6868, 11.8741)], ro = [new v(1.603231, 2.094468), new v(6.041143, 7.080126), new v(2.882459, 3.518061), new v(4.266906, 5.178857), new v(9.041765, 10.66308)], oo = [117.001, 114.697, 97.404], no = "tiny_yolov2_model", ao = "tiny_yolov2_separable_conv_model";
|
|
1821
|
+
var Le = (o9) => typeof o9 == "number";
|
|
1822
|
+
function so(o9) {
|
|
1823
|
+
if (!o9) throw new Error(`invalid config: ${o9}`);
|
|
1824
|
+
if (typeof o9.withSeparableConvs != "boolean") throw new Error(`config.withSeparableConvs has to be a boolean, have: ${o9.withSeparableConvs}`);
|
|
1825
|
+
if (!Le(o9.iouThreshold) || o9.iouThreshold < 0 || o9.iouThreshold > 1) throw new Error(`config.iouThreshold has to be a number between [0, 1], have: ${o9.iouThreshold}`);
|
|
1826
|
+
if (!Array.isArray(o9.classes) || !o9.classes.length || !o9.classes.every((t) => typeof t == "string")) throw new Error(`config.classes has to be an array class names: string[], have: ${JSON.stringify(o9.classes)}`);
|
|
1827
|
+
if (!Array.isArray(o9.anchors) || !o9.anchors.length || !o9.anchors.map((t) => t || {}).every((t) => Le(t.x) && Le(t.y))) throw new Error(`config.anchors has to be an array of { x: number, y: number }, have: ${JSON.stringify(o9.anchors)}`);
|
|
1828
|
+
if (o9.meanRgb && (!Array.isArray(o9.meanRgb) || o9.meanRgb.length !== 3 || !o9.meanRgb.every(Le))) throw new Error(`config.meanRgb has to be an array of shape [number, number, number], have: ${JSON.stringify(o9.meanRgb)}`);
|
|
1829
|
+
}
|
|
1830
|
+
function Ut(o9) {
|
|
1831
|
+
return n.tidy(() => {
|
|
1832
|
+
let t = n.mul(o9, n.scalar(0.10000000149011612));
|
|
1833
|
+
return n.add(n.relu(n.sub(o9, t)), t);
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
function et(o9, t) {
|
|
1837
|
+
return n.tidy(() => {
|
|
1838
|
+
let e = n.pad(o9, [[0, 0], [1, 1], [1, 1], [0, 0]]);
|
|
1839
|
+
return e = n.conv2d(e, t.conv.filters, [1, 1], "valid"), e = n.sub(e, t.bn.sub), e = n.mul(e, t.bn.truediv), e = n.add(e, t.conv.bias), Ut(e);
|
|
1840
|
+
});
|
|
1841
|
+
}
|
|
1842
|
+
function rt(o9, t) {
|
|
1843
|
+
return n.tidy(() => {
|
|
1844
|
+
let e = n.pad(o9, [[0, 0], [1, 1], [1, 1], [0, 0]]);
|
|
1845
|
+
return e = n.separableConv2d(e, t.depthwise_filter, t.pointwise_filter, [1, 1], "valid"), e = n.add(e, t.bias), Ut(e);
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
function qo(o9, t) {
|
|
1849
|
+
let e = Rt(o9, t);
|
|
1850
|
+
function r(s, c) {
|
|
1851
|
+
let m = n.tensor1d(o9(s)), p = n.tensor1d(o9(s));
|
|
1852
|
+
return t.push({ paramPath: `${c}/sub` }, { paramPath: `${c}/truediv` }), { sub: m, truediv: p };
|
|
1853
|
+
}
|
|
1854
|
+
function a(s, c, m) {
|
|
1855
|
+
let p = e(s, c, 3, `${m}/conv`), u = r(c, `${m}/bn`);
|
|
1856
|
+
return { conv: p, bn: u };
|
|
1857
|
+
}
|
|
1858
|
+
let i = $t(o9, t);
|
|
1859
|
+
return { extractConvParams: e, extractConvWithBatchNormParams: a, extractSeparableConvParams: i };
|
|
1860
|
+
}
|
|
1861
|
+
function io(o9, t, e, r) {
|
|
1862
|
+
let { extractWeights: a, getRemainingWeights: i } = L(o9), s = [], { extractConvParams: c, extractConvWithBatchNormParams: m, extractSeparableConvParams: p } = qo(a, s), u;
|
|
1863
|
+
if (t.withSeparableConvs) {
|
|
1864
|
+
let [f, l, d, b, y, h, g, T, x] = r, E = t.isFirstLayerConv2d ? c(f, l, 3, "conv0") : p(f, l, "conv0"), B = p(l, d, "conv1"), V = p(d, b, "conv2"), U = p(b, y, "conv3"), O = p(y, h, "conv4"), ot = p(h, g, "conv5"), nt = T ? p(g, T, "conv6") : void 0, at = x ? p(T, x, "conv7") : void 0, Et = c(x || T || g, 5 * e, 1, "conv8");
|
|
1865
|
+
u = { conv0: E, conv1: B, conv2: V, conv3: U, conv4: O, conv5: ot, conv6: nt, conv7: at, conv8: Et };
|
|
1866
|
+
} else {
|
|
1867
|
+
let [f, l, d, b, y, h, g, T, x] = r, E = m(f, l, "conv0"), B = m(l, d, "conv1"), V = m(d, b, "conv2"), U = m(b, y, "conv3"), O = m(y, h, "conv4"), ot = m(h, g, "conv5"), nt = m(g, T, "conv6"), at = m(T, x, "conv7"), Et = c(x, 5 * e, 1, "conv8");
|
|
1868
|
+
u = { conv0: E, conv1: B, conv2: V, conv3: U, conv4: O, conv5: ot, conv6: nt, conv7: at, conv8: Et };
|
|
1869
|
+
}
|
|
1870
|
+
if (i().length !== 0) throw new Error(`weights remaing after extract: ${i().length}`);
|
|
1871
|
+
return { params: u, paramMappings: s };
|
|
1872
|
+
}
|
|
1873
|
+
function Zo(o9, t) {
|
|
1874
|
+
let e = k(o9, t);
|
|
1875
|
+
function r(c) {
|
|
1876
|
+
let m = e(`${c}/sub`, 1), p = e(`${c}/truediv`, 1);
|
|
1877
|
+
return { sub: m, truediv: p };
|
|
1878
|
+
}
|
|
1879
|
+
function a(c) {
|
|
1880
|
+
let m = e(`${c}/filters`, 4), p = e(`${c}/bias`, 1);
|
|
1881
|
+
return { filters: m, bias: p };
|
|
1882
|
+
}
|
|
1883
|
+
function i(c) {
|
|
1884
|
+
let m = a(`${c}/conv`), p = r(`${c}/bn`);
|
|
1885
|
+
return { conv: m, bn: p };
|
|
1886
|
+
}
|
|
1887
|
+
let s = Ot(e);
|
|
1888
|
+
return { extractConvParams: a, extractConvWithBatchNormParams: i, extractSeparableConvParams: s };
|
|
1889
|
+
}
|
|
1890
|
+
function co(o9, t) {
|
|
1891
|
+
let e = [], { extractConvParams: r, extractConvWithBatchNormParams: a, extractSeparableConvParams: i } = Zo(o9, e), s;
|
|
1892
|
+
if (t.withSeparableConvs) {
|
|
1893
|
+
let c = t.filterSizes && t.filterSizes.length || 9;
|
|
1894
|
+
s = { conv0: t.isFirstLayerConv2d ? r("conv0") : i("conv0"), conv1: i("conv1"), conv2: i("conv2"), conv3: i("conv3"), conv4: i("conv4"), conv5: i("conv5"), conv6: c > 7 ? i("conv6") : void 0, conv7: c > 8 ? i("conv7") : void 0, conv8: r("conv8") };
|
|
1895
|
+
} 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: r("conv8") };
|
|
1896
|
+
return N(o9, e), { params: s, paramMappings: e };
|
|
1897
|
+
}
|
|
1898
|
+
var q = class {
|
|
1899
|
+
constructor({ inputSize: t, scoreThreshold: e } = {}) {
|
|
1900
|
+
this._name = "TinyYolov2Options";
|
|
1901
|
+
if (this._inputSize = t || 416, this._scoreThreshold = e || 0.5, typeof this._inputSize != "number" || this._inputSize % 32 !== 0) throw new Error(`${this._name} - expected inputSize to be a number divisible by 32`);
|
|
1902
|
+
if (typeof this._scoreThreshold != "number" || this._scoreThreshold <= 0 || this._scoreThreshold >= 1) throw new Error(`${this._name} - expected scoreThreshold to be a number between 0 and 1`);
|
|
1903
|
+
}
|
|
1904
|
+
get inputSize() {
|
|
1905
|
+
return this._inputSize;
|
|
1906
|
+
}
|
|
1907
|
+
get scoreThreshold() {
|
|
1908
|
+
return this._scoreThreshold;
|
|
1909
|
+
}
|
|
1910
|
+
};
|
|
1911
|
+
var Se = class Se2 extends I {
|
|
1912
|
+
constructor(t) {
|
|
1913
|
+
super("TinyYolov2"), so(t), this._config = t;
|
|
1914
|
+
}
|
|
1915
|
+
get config() {
|
|
1916
|
+
return this._config;
|
|
1917
|
+
}
|
|
1918
|
+
get withClassScores() {
|
|
1919
|
+
return this.config.withClassScores || this.config.classes.length > 1;
|
|
1920
|
+
}
|
|
1921
|
+
get boxEncodingSize() {
|
|
1922
|
+
return 5 + (this.withClassScores ? this.config.classes.length : 0);
|
|
1923
|
+
}
|
|
1924
|
+
runTinyYolov2(t, e) {
|
|
1925
|
+
let r = et(t, e.conv0);
|
|
1926
|
+
return r = n.maxPool(r, [2, 2], [2, 2], "same"), r = et(r, e.conv1), r = n.maxPool(r, [2, 2], [2, 2], "same"), r = et(r, e.conv2), r = n.maxPool(r, [2, 2], [2, 2], "same"), r = et(r, e.conv3), r = n.maxPool(r, [2, 2], [2, 2], "same"), r = et(r, e.conv4), r = n.maxPool(r, [2, 2], [2, 2], "same"), r = et(r, e.conv5), r = n.maxPool(r, [2, 2], [1, 1], "same"), r = et(r, e.conv6), r = et(r, e.conv7), vt(r, e.conv8, "valid", false);
|
|
1927
|
+
}
|
|
1928
|
+
runMobilenet(t, e) {
|
|
1929
|
+
let r = this.config.isFirstLayerConv2d ? Ut(vt(t, e.conv0, "valid", false)) : rt(t, e.conv0);
|
|
1930
|
+
return r = n.maxPool(r, [2, 2], [2, 2], "same"), r = rt(r, e.conv1), r = n.maxPool(r, [2, 2], [2, 2], "same"), r = rt(r, e.conv2), r = n.maxPool(r, [2, 2], [2, 2], "same"), r = rt(r, e.conv3), r = n.maxPool(r, [2, 2], [2, 2], "same"), r = rt(r, e.conv4), r = n.maxPool(r, [2, 2], [2, 2], "same"), r = rt(r, e.conv5), r = n.maxPool(r, [2, 2], [1, 1], "same"), r = e.conv6 ? rt(r, e.conv6) : r, r = e.conv7 ? rt(r, e.conv7) : r, vt(r, e.conv8, "valid", false);
|
|
1931
|
+
}
|
|
1932
|
+
forwardInput(t, e) {
|
|
1933
|
+
let { params: r } = this;
|
|
1934
|
+
if (!r) throw new Error("TinyYolov2 - load model before inference");
|
|
1935
|
+
return n.tidy(() => {
|
|
1936
|
+
let a = n.cast(t.toBatchTensor(e, false), "float32");
|
|
1937
|
+
return a = this.config.meanRgb ? J(a, this.config.meanRgb) : a, a = a.div(255), this.config.withSeparableConvs ? this.runMobilenet(a, r) : this.runTinyYolov2(a, r);
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
async forward(t, e) {
|
|
1941
|
+
return this.forwardInput(await F(t), e);
|
|
1942
|
+
}
|
|
1943
|
+
async detect(t, e = {}) {
|
|
1944
|
+
let { inputSize: r, scoreThreshold: a } = new q(e), i = await F(t), s = await this.forwardInput(i, r), c = n.tidy(() => n.unstack(s)[0].expandDims()), m = { width: i.getInputWidth(0), height: i.getInputHeight(0) }, p = await this.extractBoxes(c, i.getReshapedInputDimensions(0), a);
|
|
1945
|
+
s.dispose(), c.dispose();
|
|
1946
|
+
let u = p.map((h) => h.box), f = p.map((h) => h.score), l = p.map((h) => h.classScore), d = p.map((h) => this.config.classes[h.label]);
|
|
1947
|
+
return br(u.map((h) => h.rescale(r)), f, this.config.iouThreshold, true).map((h) => new It(f[h], l[h], d[h], u[h], m));
|
|
1948
|
+
}
|
|
1949
|
+
getDefaultModelName() {
|
|
1950
|
+
return "";
|
|
1951
|
+
}
|
|
1952
|
+
extractParamsFromWeightMap(t) {
|
|
1953
|
+
return co(t, this.config);
|
|
1954
|
+
}
|
|
1955
|
+
extractParams(t) {
|
|
1956
|
+
let e = this.config.filterSizes || Se2.DEFAULT_FILTER_SIZES, r = e ? e.length : void 0;
|
|
1957
|
+
if (r !== 7 && r !== 8 && r !== 9) throw new Error(`TinyYolov2 - expected 7 | 8 | 9 convolutional filters, but found ${r} filterSizes in config`);
|
|
1958
|
+
return io(t, this.config, this.boxEncodingSize, e);
|
|
1959
|
+
}
|
|
1960
|
+
async extractBoxes(t, e, r) {
|
|
1961
|
+
let { width: a, height: i } = e, s = Math.max(a, i), c = s / a, m = s / i, p = t.shape[1], u = this.config.anchors.length, [f, l, d] = n.tidy(() => {
|
|
1962
|
+
let g = t.reshape([p, p, u, this.boxEncodingSize]), T = g.slice([0, 0, 0, 0], [p, p, u, 4]), x = g.slice([0, 0, 0, 4], [p, p, u, 1]), E = this.withClassScores ? n.softmax(g.slice([0, 0, 0, 5], [p, p, u, this.config.classes.length]), 3) : n.scalar(0);
|
|
1963
|
+
return [T, x, E];
|
|
1964
|
+
}), b = [], y = await l.array(), h = await f.array();
|
|
1965
|
+
for (let g = 0; g < p; g++) for (let T = 0; T < p; T++) for (let x = 0; x < u; x++) {
|
|
1966
|
+
let E = fe(y[g][T][x][0]);
|
|
1967
|
+
if (!r || E > r) {
|
|
1968
|
+
let B = (T + fe(h[g][T][x][0])) / p * c, V = (g + fe(h[g][T][x][1])) / p * m, U = Math.exp(h[g][T][x][2]) * this.config.anchors[x].x / p * c, O = Math.exp(h[g][T][x][3]) * this.config.anchors[x].y / p * m, ot = B - U / 2, nt = V - O / 2, at = { row: g, col: T, anchor: x }, { classScore: Et, label: mr } = this.withClassScores ? await this.extractPredictedClass(d, at) : { classScore: 1, label: 0 };
|
|
1969
|
+
b.push({ box: new Ct(ot, nt, ot + U, nt + O), score: E, classScore: E * Et, label: mr, ...at });
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
return f.dispose(), l.dispose(), d.dispose(), b;
|
|
1973
|
+
}
|
|
1974
|
+
async extractPredictedClass(t, e) {
|
|
1975
|
+
let { row: r, col: a, anchor: i } = e, s = await t.array();
|
|
1976
|
+
return Array(this.config.classes.length).fill(0).map((c, m) => s[r][a][i][m]).map((c, m) => ({ classScore: c, label: m })).reduce((c, m) => c.classScore > m.classScore ? c : m);
|
|
1977
|
+
}
|
|
1978
|
+
};
|
|
1979
|
+
Se.DEFAULT_FILTER_SIZES = [3, 16, 32, 64, 128, 256, 512, 1024, 1024];
|
|
1980
|
+
var Xt = Se;
|
|
1981
|
+
var Jt = class extends Xt {
|
|
1982
|
+
constructor(t = true) {
|
|
1983
|
+
let e = { withSeparableConvs: t, iouThreshold: to, classes: ["face"], ...t ? { anchors: ro, meanRgb: oo } : { anchors: eo, withClassScores: true } };
|
|
1984
|
+
super(e);
|
|
1985
|
+
}
|
|
1986
|
+
get withSeparableConvs() {
|
|
1987
|
+
return this.config.withSeparableConvs;
|
|
1988
|
+
}
|
|
1989
|
+
get anchors() {
|
|
1990
|
+
return this.config.anchors;
|
|
1991
|
+
}
|
|
1992
|
+
async locateFaces(t, e) {
|
|
1993
|
+
return (await this.detect(t, e)).map((a) => new D(a.score, a.relativeBox, { width: a.imageWidth, height: a.imageHeight }));
|
|
1994
|
+
}
|
|
1995
|
+
getDefaultModelName() {
|
|
1996
|
+
return this.withSeparableConvs ? ao : no;
|
|
1997
|
+
}
|
|
1998
|
+
extractParamsFromWeightMap(t) {
|
|
1999
|
+
return super.extractParamsFromWeightMap(t);
|
|
2000
|
+
}
|
|
2001
|
+
};
|
|
2002
|
+
function cd(o9, t = true) {
|
|
2003
|
+
let e = new Jt(t);
|
|
2004
|
+
return e.extractWeights(o9), e;
|
|
2005
|
+
}
|
|
2006
|
+
var Ae = class extends q {
|
|
2007
|
+
constructor() {
|
|
2008
|
+
super(...arguments);
|
|
2009
|
+
this._name = "TinyFaceDetectorOptions";
|
|
2010
|
+
}
|
|
2011
|
+
};
|
|
2012
|
+
var Y = class {
|
|
2013
|
+
async then(t) {
|
|
2014
|
+
return t(await this.run());
|
|
2015
|
+
}
|
|
2016
|
+
async run() {
|
|
2017
|
+
throw new Error("ComposableTask - run is not implemented");
|
|
2018
|
+
}
|
|
2019
|
+
};
|
|
2020
|
+
async function _t(o9, t, e, r, a = ({ alignedRect: i }) => i) {
|
|
2021
|
+
let i = o9.map((m) => Yt(m) ? a(m) : m.detection), s = r || (t instanceof n.Tensor ? await oe(t, i) : await re(t, i)), c = await e(s);
|
|
2022
|
+
return s.forEach((m) => m instanceof n.Tensor && m.dispose()), c;
|
|
2023
|
+
}
|
|
2024
|
+
async function qt(o9, t, e, r, a) {
|
|
2025
|
+
return _t([o9], t, async (i) => e(i[0]), r, a);
|
|
2026
|
+
}
|
|
2027
|
+
var mo = 0.4, po = [new v(1.603231, 2.094468), new v(6.041143, 7.080126), new v(2.882459, 3.518061), new v(4.266906, 5.178857), new v(9.041765, 10.66308)], uo = [117.001, 114.697, 97.404];
|
|
2028
|
+
var Zt = class extends Xt {
|
|
2029
|
+
constructor() {
|
|
2030
|
+
let t = { withSeparableConvs: true, iouThreshold: mo, classes: ["face"], anchors: po, meanRgb: uo, isFirstLayerConv2d: true, filterSizes: [3, 16, 32, 64, 128, 256, 512] };
|
|
2031
|
+
super(t);
|
|
2032
|
+
}
|
|
2033
|
+
get anchors() {
|
|
2034
|
+
return this.config.anchors;
|
|
2035
|
+
}
|
|
2036
|
+
async locateFaces(t, e) {
|
|
2037
|
+
return (await this.detect(t, e)).map((a) => new D(a.score, a.relativeBox, { width: a.imageWidth, height: a.imageHeight }));
|
|
2038
|
+
}
|
|
2039
|
+
getDefaultModelName() {
|
|
2040
|
+
return "tiny_face_detector_model";
|
|
2041
|
+
}
|
|
2042
|
+
extractParamsFromWeightMap(t) {
|
|
2043
|
+
return super.extractParamsFromWeightMap(t);
|
|
2044
|
+
}
|
|
2045
|
+
};
|
|
2046
|
+
var P = { ssdMobilenetv1: new Tt(), tinyFaceDetector: new Zt(), tinyYolov2: new Jt(), faceLandmark68Net: new Gt(), faceLandmark68TinyNet: new Ie(), faceRecognitionNet: new jt(), faceExpressionNet: new we(), ageGenderNet: new Me() }, Ko = (o9, t) => P.ssdMobilenetv1.locateFaces(o9, t), Rd = (o9, t) => P.tinyFaceDetector.locateFaces(o9, t), $d = (o9, t) => P.tinyYolov2.locateFaces(o9, t), Qo = (o9) => P.faceLandmark68Net.detectLandmarks(o9), Od = (o9) => P.faceLandmark68TinyNet.detectLandmarks(o9), Hd = (o9) => P.faceRecognitionNet.computeFaceDescriptor(o9), zd = (o9) => P.faceExpressionNet.predictExpressions(o9), Yd = (o9) => P.ageGenderNet.predictAgeAndGender(o9), tn = (o9) => P.ssdMobilenetv1.load(o9), Vd = (o9) => P.tinyFaceDetector.load(o9), Gd = (o9) => P.tinyYolov2.load(o9), jd = (o9) => P.faceLandmark68Net.load(o9), Ud = (o9) => P.faceLandmark68TinyNet.load(o9), Xd = (o9) => P.faceRecognitionNet.load(o9), Jd = (o9) => P.faceExpressionNet.load(o9), qd = (o9) => P.ageGenderNet.load(o9), Zd = tn, Kd = Ko, Qd = Qo;
|
|
2047
|
+
var We = class extends Y {
|
|
2048
|
+
constructor(e, r, a) {
|
|
2049
|
+
super();
|
|
2050
|
+
this.parentTask = e;
|
|
2051
|
+
this.input = r;
|
|
2052
|
+
this.extractedFaces = a;
|
|
2053
|
+
}
|
|
2054
|
+
}, Pt = class extends We {
|
|
2055
|
+
async run() {
|
|
2056
|
+
let t = await this.parentTask, e = await _t(t, this.input, async (r) => Promise.all(r.map((a) => P.faceExpressionNet.predictExpressions(a))), this.extractedFaces);
|
|
2057
|
+
return t.map((r, a) => tr(r, e[a]));
|
|
2058
|
+
}
|
|
2059
|
+
withAgeAndGender() {
|
|
2060
|
+
return new Ft(this, this.input);
|
|
2061
|
+
}
|
|
2062
|
+
}, wt = class extends We {
|
|
2063
|
+
async run() {
|
|
2064
|
+
let t = await this.parentTask;
|
|
2065
|
+
if (!t) return;
|
|
2066
|
+
let e = await qt(t, this.input, (r) => P.faceExpressionNet.predictExpressions(r), this.extractedFaces);
|
|
2067
|
+
return tr(t, e);
|
|
2068
|
+
}
|
|
2069
|
+
withAgeAndGender() {
|
|
2070
|
+
return new Dt(this, this.input);
|
|
2071
|
+
}
|
|
2072
|
+
}, ct = class extends Pt {
|
|
2073
|
+
withAgeAndGender() {
|
|
2074
|
+
return new pt(this, this.input);
|
|
2075
|
+
}
|
|
2076
|
+
withFaceDescriptors() {
|
|
2077
|
+
return new ft(this, this.input);
|
|
2078
|
+
}
|
|
2079
|
+
}, mt = class extends wt {
|
|
2080
|
+
withAgeAndGender() {
|
|
2081
|
+
return new ut(this, this.input);
|
|
2082
|
+
}
|
|
2083
|
+
withFaceDescriptor() {
|
|
2084
|
+
return new lt(this, this.input);
|
|
2085
|
+
}
|
|
2086
|
+
};
|
|
2087
|
+
var ke = class extends Y {
|
|
2088
|
+
constructor(e, r, a) {
|
|
2089
|
+
super();
|
|
2090
|
+
this.parentTask = e;
|
|
2091
|
+
this.input = r;
|
|
2092
|
+
this.extractedFaces = a;
|
|
2093
|
+
}
|
|
2094
|
+
}, Ft = class extends ke {
|
|
2095
|
+
async run() {
|
|
2096
|
+
let t = await this.parentTask, e = await _t(t, this.input, async (r) => Promise.all(r.map((a) => P.ageGenderNet.predictAgeAndGender(a))), this.extractedFaces);
|
|
2097
|
+
return t.map((r, a) => {
|
|
2098
|
+
let { age: i, gender: s, genderProbability: c } = e[a];
|
|
2099
|
+
return sr(ir(r, s, c), i);
|
|
2100
|
+
});
|
|
2101
|
+
}
|
|
2102
|
+
withFaceExpressions() {
|
|
2103
|
+
return new Pt(this, this.input);
|
|
2104
|
+
}
|
|
2105
|
+
}, Dt = class extends ke {
|
|
2106
|
+
async run() {
|
|
2107
|
+
let t = await this.parentTask;
|
|
2108
|
+
if (!t) return;
|
|
2109
|
+
let { age: e, gender: r, genderProbability: a } = await qt(t, this.input, (i) => P.ageGenderNet.predictAgeAndGender(i), this.extractedFaces);
|
|
2110
|
+
return sr(ir(t, r, a), e);
|
|
2111
|
+
}
|
|
2112
|
+
withFaceExpressions() {
|
|
2113
|
+
return new wt(this, this.input);
|
|
2114
|
+
}
|
|
2115
|
+
}, pt = class extends Ft {
|
|
2116
|
+
withFaceExpressions() {
|
|
2117
|
+
return new ct(this, this.input);
|
|
2118
|
+
}
|
|
2119
|
+
withFaceDescriptors() {
|
|
2120
|
+
return new ft(this, this.input);
|
|
2121
|
+
}
|
|
2122
|
+
}, ut = class extends Dt {
|
|
2123
|
+
withFaceExpressions() {
|
|
2124
|
+
return new mt(this, this.input);
|
|
2125
|
+
}
|
|
2126
|
+
withFaceDescriptor() {
|
|
2127
|
+
return new lt(this, this.input);
|
|
2128
|
+
}
|
|
2129
|
+
};
|
|
2130
|
+
var Be = class extends Y {
|
|
2131
|
+
constructor(e, r) {
|
|
2132
|
+
super();
|
|
2133
|
+
this.parentTask = e;
|
|
2134
|
+
this.input = r;
|
|
2135
|
+
}
|
|
2136
|
+
}, ft = class extends Be {
|
|
2137
|
+
async run() {
|
|
2138
|
+
let t = await this.parentTask;
|
|
2139
|
+
return (await _t(t, this.input, (r) => Promise.all(r.map((a) => P.faceRecognitionNet.computeFaceDescriptor(a))), null, (r) => r.landmarks.align(null, { useDlibAlignment: true }))).map((r, a) => ar(t[a], r));
|
|
2140
|
+
}
|
|
2141
|
+
withFaceExpressions() {
|
|
2142
|
+
return new ct(this, this.input);
|
|
2143
|
+
}
|
|
2144
|
+
withAgeAndGender() {
|
|
2145
|
+
return new pt(this, this.input);
|
|
2146
|
+
}
|
|
2147
|
+
}, lt = class extends Be {
|
|
2148
|
+
async run() {
|
|
2149
|
+
let t = await this.parentTask;
|
|
2150
|
+
if (!t) return;
|
|
2151
|
+
let e = await qt(t, this.input, (r) => P.faceRecognitionNet.computeFaceDescriptor(r), null, (r) => r.landmarks.align(null, { useDlibAlignment: true }));
|
|
2152
|
+
return ar(t, e);
|
|
2153
|
+
}
|
|
2154
|
+
withFaceExpressions() {
|
|
2155
|
+
return new mt(this, this.input);
|
|
2156
|
+
}
|
|
2157
|
+
withAgeAndGender() {
|
|
2158
|
+
return new ut(this, this.input);
|
|
2159
|
+
}
|
|
2160
|
+
};
|
|
2161
|
+
var Re = class extends Y {
|
|
2162
|
+
constructor(e, r, a) {
|
|
2163
|
+
super();
|
|
2164
|
+
this.parentTask = e;
|
|
2165
|
+
this.input = r;
|
|
2166
|
+
this.useTinyLandmarkNet = a;
|
|
2167
|
+
}
|
|
2168
|
+
get landmarkNet() {
|
|
2169
|
+
return this.useTinyLandmarkNet ? P.faceLandmark68TinyNet : P.faceLandmark68Net;
|
|
2170
|
+
}
|
|
2171
|
+
}, $e = class extends Re {
|
|
2172
|
+
async run() {
|
|
2173
|
+
let t = await this.parentTask, e = t.map((s) => s.detection), r = this.input instanceof n.Tensor ? await oe(this.input, e) : await re(this.input, e), a = await Promise.all(r.map((s) => this.landmarkNet.detectLandmarks(s)));
|
|
2174
|
+
return r.forEach((s) => s instanceof n.Tensor && s.dispose()), t.filter((s, c) => a[c]).map((s, c) => ie(s, a[c]));
|
|
2175
|
+
}
|
|
2176
|
+
withFaceExpressions() {
|
|
2177
|
+
return new ct(this, this.input);
|
|
2178
|
+
}
|
|
2179
|
+
withAgeAndGender() {
|
|
2180
|
+
return new pt(this, this.input);
|
|
2181
|
+
}
|
|
2182
|
+
withFaceDescriptors() {
|
|
2183
|
+
return new ft(this, this.input);
|
|
2184
|
+
}
|
|
2185
|
+
}, Oe = class extends Re {
|
|
2186
|
+
async run() {
|
|
2187
|
+
let t = await this.parentTask;
|
|
2188
|
+
if (!t) return;
|
|
2189
|
+
let { detection: e } = t, r = this.input instanceof n.Tensor ? await oe(this.input, [e]) : await re(this.input, [e]), a = await this.landmarkNet.detectLandmarks(r[0]);
|
|
2190
|
+
return r.forEach((i) => i instanceof n.Tensor && i.dispose()), ie(t, a);
|
|
2191
|
+
}
|
|
2192
|
+
withFaceExpressions() {
|
|
2193
|
+
return new mt(this, this.input);
|
|
2194
|
+
}
|
|
2195
|
+
withAgeAndGender() {
|
|
2196
|
+
return new ut(this, this.input);
|
|
2197
|
+
}
|
|
2198
|
+
withFaceDescriptor() {
|
|
2199
|
+
return new lt(this, this.input);
|
|
2200
|
+
}
|
|
2201
|
+
};
|
|
2202
|
+
var He = class extends Y {
|
|
2203
|
+
constructor(e, r = new z()) {
|
|
2204
|
+
super();
|
|
2205
|
+
this.input = e;
|
|
2206
|
+
this.options = r;
|
|
2207
|
+
}
|
|
2208
|
+
}, me = class extends He {
|
|
2209
|
+
async run() {
|
|
2210
|
+
let { input: t, options: e } = this, r;
|
|
2211
|
+
if (e instanceof Ae) r = P.tinyFaceDetector.locateFaces(t, e);
|
|
2212
|
+
else if (e instanceof z) r = P.ssdMobilenetv1.locateFaces(t, e);
|
|
2213
|
+
else if (e instanceof q) r = P.tinyYolov2.locateFaces(t, e);
|
|
2214
|
+
else throw new Error("detectFaces - expected options to be instance of TinyFaceDetectorOptions | SsdMobilenetv1Options | TinyYolov2Options");
|
|
2215
|
+
return r;
|
|
2216
|
+
}
|
|
2217
|
+
runAndExtendWithFaceDetections() {
|
|
2218
|
+
return new Promise((t, e) => {
|
|
2219
|
+
this.run().then((r) => t(r.map((a) => St({}, a)))).catch((r) => e(r));
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
withFaceLandmarks(t = false) {
|
|
2223
|
+
return new $e(this.runAndExtendWithFaceDetections(), this.input, t);
|
|
2224
|
+
}
|
|
2225
|
+
withFaceExpressions() {
|
|
2226
|
+
return new Pt(this.runAndExtendWithFaceDetections(), this.input);
|
|
2227
|
+
}
|
|
2228
|
+
withAgeAndGender() {
|
|
2229
|
+
return new Ft(this.runAndExtendWithFaceDetections(), this.input);
|
|
2230
|
+
}
|
|
2231
|
+
}, ze = class extends He {
|
|
2232
|
+
async run() {
|
|
2233
|
+
let t = await new me(this.input, this.options), e = t[0];
|
|
2234
|
+
return t.forEach((r) => {
|
|
2235
|
+
r.score > e.score && (e = r);
|
|
2236
|
+
}), e;
|
|
2237
|
+
}
|
|
2238
|
+
runAndExtendWithFaceDetection() {
|
|
2239
|
+
return new Promise(async (t) => {
|
|
2240
|
+
let e = await this.run();
|
|
2241
|
+
t(e ? St({}, e) : void 0);
|
|
2242
|
+
});
|
|
2243
|
+
}
|
|
2244
|
+
withFaceLandmarks(t = false) {
|
|
2245
|
+
return new Oe(this.runAndExtendWithFaceDetection(), this.input, t);
|
|
2246
|
+
}
|
|
2247
|
+
withFaceExpressions() {
|
|
2248
|
+
return new wt(this.runAndExtendWithFaceDetection(), this.input);
|
|
2249
|
+
}
|
|
2250
|
+
withAgeAndGender() {
|
|
2251
|
+
return new Dt(this.runAndExtendWithFaceDetection(), this.input);
|
|
2252
|
+
}
|
|
2253
|
+
};
|
|
2254
|
+
function qh(o9, t = new z()) {
|
|
2255
|
+
return new ze(o9, t);
|
|
2256
|
+
}
|
|
2257
|
+
function cr(o9, t = new z()) {
|
|
2258
|
+
return new me(o9, t);
|
|
2259
|
+
}
|
|
2260
|
+
async function en(o9, t) {
|
|
2261
|
+
return cr(o9, new z(t ? { minConfidence: t } : {})).withFaceLandmarks().withFaceDescriptors();
|
|
2262
|
+
}
|
|
2263
|
+
async function rb(o9, t = {}) {
|
|
2264
|
+
return cr(o9, new q(t)).withFaceLandmarks().withFaceDescriptors();
|
|
2265
|
+
}
|
|
2266
|
+
var ob = en;
|
|
2267
|
+
function fo(o9, t) {
|
|
2268
|
+
if (o9.length !== t.length) throw new Error("euclideanDistance: arr1.length !== arr2.length");
|
|
2269
|
+
let e = Array.from(o9), r = Array.from(t);
|
|
2270
|
+
return Math.sqrt(e.map((a, i) => a - r[i]).reduce((a, i) => a + i * i, 0));
|
|
2271
|
+
}
|
|
2272
|
+
var lo = class o8 {
|
|
2273
|
+
constructor(t, e = 0.6) {
|
|
2274
|
+
this._distanceThreshold = e;
|
|
2275
|
+
let r = Array.isArray(t) ? t : [t];
|
|
2276
|
+
if (!r.length) throw new Error("FaceRecognizer.constructor - expected atleast one input");
|
|
2277
|
+
let a = 1, i = () => `person ${a++}`;
|
|
2278
|
+
this._labeledDescriptors = r.map((s) => {
|
|
2279
|
+
if (s instanceof gt) return s;
|
|
2280
|
+
if (s instanceof Float32Array) return new gt(i(), [s]);
|
|
2281
|
+
if (s.descriptor && s.descriptor instanceof Float32Array) return new gt(i(), [s.descriptor]);
|
|
2282
|
+
throw new Error("FaceRecognizer.constructor - expected inputs to be of type LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array | Array<LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array>");
|
|
2283
|
+
});
|
|
2284
|
+
}
|
|
2285
|
+
get labeledDescriptors() {
|
|
2286
|
+
return this._labeledDescriptors;
|
|
2287
|
+
}
|
|
2288
|
+
get distanceThreshold() {
|
|
2289
|
+
return this._distanceThreshold;
|
|
2290
|
+
}
|
|
2291
|
+
computeMeanDistance(t, e) {
|
|
2292
|
+
return e.map((r) => fo(r, t)).reduce((r, a) => r + a, 0) / (e.length || 1);
|
|
2293
|
+
}
|
|
2294
|
+
matchDescriptor(t) {
|
|
2295
|
+
return this.labeledDescriptors.map(({ descriptors: e, label: r }) => new Kt(r, this.computeMeanDistance(t, e))).reduce((e, r) => e.distance < r.distance ? e : r);
|
|
2296
|
+
}
|
|
2297
|
+
findBestMatch(t) {
|
|
2298
|
+
let e = this.matchDescriptor(t);
|
|
2299
|
+
return e.distance < this._distanceThreshold ? e : new Kt("unknown", e.distance);
|
|
2300
|
+
}
|
|
2301
|
+
toJSON() {
|
|
2302
|
+
return { distanceThreshold: this._distanceThreshold, labeledDescriptors: this._labeledDescriptors.map((t) => t.toJSON()) };
|
|
2303
|
+
}
|
|
2304
|
+
static fromJSON(t) {
|
|
2305
|
+
let e = t.labeledDescriptors.map((r) => gt.fromJSON(r));
|
|
2306
|
+
return new o8(e, t.distanceThreshold);
|
|
2307
|
+
}
|
|
2308
|
+
};
|
|
2309
|
+
function Tb(o9) {
|
|
2310
|
+
let t = new Zt();
|
|
2311
|
+
return t.extractWeights(o9), t;
|
|
2312
|
+
}
|
|
2313
|
+
function rn(o9, t) {
|
|
2314
|
+
let { width: e, height: r } = new A(t.width, t.height);
|
|
2315
|
+
if (e <= 0 || r <= 0) throw new Error(`resizeResults - invalid dimensions: ${JSON.stringify({ width: e, height: r })}`);
|
|
2316
|
+
if (Array.isArray(o9)) return o9.map((a) => rn(a, { width: e, height: r }));
|
|
2317
|
+
if (Yt(o9)) {
|
|
2318
|
+
let a = o9.detection.forSize(e, r), i = o9.unshiftedLandmarks.forSize(a.box.width, a.box.height);
|
|
2319
|
+
return ie(St(o9, a), i);
|
|
2320
|
+
}
|
|
2321
|
+
return Q(o9) ? St(o9, o9.detection.forSize(e, r)) : o9 instanceof $ || o9 instanceof D ? o9.forSize(e, r) : o9;
|
|
2322
|
+
}
|
|
2323
|
+
var Lb = Ar;
|
|
2324
|
+
const faceapi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2325
|
+
__proto__: null,
|
|
2326
|
+
AgeGenderNet: Me,
|
|
2327
|
+
BoundingBox: Ct,
|
|
2328
|
+
Box: C,
|
|
2329
|
+
ComposableTask: Y,
|
|
2330
|
+
ComputeAllFaceDescriptorsTask: ft,
|
|
2331
|
+
ComputeFaceDescriptorsTaskBase: Be,
|
|
2332
|
+
ComputeSingleFaceDescriptorTask: lt,
|
|
2333
|
+
DetectAllFaceLandmarksTask: $e,
|
|
2334
|
+
DetectAllFacesTask: me,
|
|
2335
|
+
DetectFaceLandmarksTaskBase: Re,
|
|
2336
|
+
DetectFacesTaskBase: He,
|
|
2337
|
+
DetectSingleFaceLandmarksTask: Oe,
|
|
2338
|
+
DetectSingleFaceTask: ze,
|
|
2339
|
+
Dimensions: A,
|
|
2340
|
+
FACE_EXPRESSION_LABELS: Nr,
|
|
2341
|
+
FaceDetection: D,
|
|
2342
|
+
FaceDetectionNet: Qr,
|
|
2343
|
+
FaceExpressionNet: we,
|
|
2344
|
+
FaceExpressions: it,
|
|
2345
|
+
FaceLandmark68Net: Gt,
|
|
2346
|
+
FaceLandmark68TinyNet: Ie,
|
|
2347
|
+
FaceLandmarkNet: zr,
|
|
2348
|
+
FaceLandmarks: $,
|
|
2349
|
+
FaceLandmarks5: xr,
|
|
2350
|
+
FaceLandmarks68: Lt,
|
|
2351
|
+
FaceMatch: Kt,
|
|
2352
|
+
FaceMatcher: lo,
|
|
2353
|
+
FaceRecognitionNet: jt,
|
|
2354
|
+
Gender: rr,
|
|
2355
|
+
LabeledBox: Qt,
|
|
2356
|
+
LabeledFaceDescriptors: gt,
|
|
2357
|
+
NetInput: tt,
|
|
2358
|
+
NeuralNetwork: I,
|
|
2359
|
+
ObjectDetection: It,
|
|
2360
|
+
Point: v,
|
|
2361
|
+
PredictedBox: vr,
|
|
2362
|
+
Rect: Nt,
|
|
2363
|
+
SsdMobilenetv1: Tt,
|
|
2364
|
+
SsdMobilenetv1Options: z,
|
|
2365
|
+
TinyFaceDetector: Zt,
|
|
2366
|
+
TinyFaceDetectorOptions: Ae,
|
|
2367
|
+
TinyYolov2: Jt,
|
|
2368
|
+
TinyYolov2Options: q,
|
|
2369
|
+
allFaces: ob,
|
|
2370
|
+
allFacesSsdMobilenetv1: en,
|
|
2371
|
+
allFacesTinyYolov2: rb,
|
|
2372
|
+
awaitMediaLoaded: yr,
|
|
2373
|
+
bufferToImage: Tr,
|
|
2374
|
+
computeFaceDescriptor: Hd,
|
|
2375
|
+
createCanvas: Bt,
|
|
2376
|
+
createCanvasFromMedia: be,
|
|
2377
|
+
createFaceDetectionNet: gl,
|
|
2378
|
+
createFaceRecognitionNet: gf,
|
|
2379
|
+
createSsdMobilenetv1: Jo,
|
|
2380
|
+
createTinyFaceDetector: Tb,
|
|
2381
|
+
createTinyYolov2: cd,
|
|
2382
|
+
detectAllFaces: cr,
|
|
2383
|
+
detectFaceLandmarks: Qo,
|
|
2384
|
+
detectFaceLandmarksTiny: Od,
|
|
2385
|
+
detectLandmarks: Qd,
|
|
2386
|
+
detectSingleFace: qh,
|
|
2387
|
+
draw: Sr,
|
|
2388
|
+
env: _,
|
|
2389
|
+
euclideanDistance: fo,
|
|
2390
|
+
extendWithAge: sr,
|
|
2391
|
+
extendWithFaceDescriptor: ar,
|
|
2392
|
+
extendWithFaceDetection: St,
|
|
2393
|
+
extendWithFaceExpressions: tr,
|
|
2394
|
+
extendWithFaceLandmarks: ie,
|
|
2395
|
+
extendWithGender: ir,
|
|
2396
|
+
extractFaceTensors: oe,
|
|
2397
|
+
extractFaces: re,
|
|
2398
|
+
fetchImage: Fi,
|
|
2399
|
+
fetchJson: wr,
|
|
2400
|
+
fetchNetWeights: Ii,
|
|
2401
|
+
fetchOrThrow: st,
|
|
2402
|
+
fetchVideo: ki,
|
|
2403
|
+
getContext2dOrThrow: W,
|
|
2404
|
+
getMediaDimensions: kt,
|
|
2405
|
+
imageTensorToCanvas: _r,
|
|
2406
|
+
imageToSquare: Pr,
|
|
2407
|
+
inverseSigmoid: On,
|
|
2408
|
+
iou: dr,
|
|
2409
|
+
isMediaElement: Qe,
|
|
2410
|
+
isMediaLoaded: he,
|
|
2411
|
+
isWithAge: Tf,
|
|
2412
|
+
isWithFaceDetection: Q,
|
|
2413
|
+
isWithFaceExpressions: Lr,
|
|
2414
|
+
isWithFaceLandmarks: Yt,
|
|
2415
|
+
isWithGender: Ff,
|
|
2416
|
+
loadAgeGenderModel: qd,
|
|
2417
|
+
loadFaceDetectionModel: Zd,
|
|
2418
|
+
loadFaceExpressionModel: Jd,
|
|
2419
|
+
loadFaceLandmarkModel: jd,
|
|
2420
|
+
loadFaceLandmarkTinyModel: Ud,
|
|
2421
|
+
loadFaceRecognitionModel: Xd,
|
|
2422
|
+
loadSsdMobilenetv1Model: tn,
|
|
2423
|
+
loadTinyFaceDetectorModel: Vd,
|
|
2424
|
+
loadTinyYolov2Model: Gd,
|
|
2425
|
+
loadWeightMap: Dr,
|
|
2426
|
+
locateFaces: Kd,
|
|
2427
|
+
matchDimensions: Yi,
|
|
2428
|
+
minBbox: hr,
|
|
2429
|
+
nets: P,
|
|
2430
|
+
nonMaxSuppression: br,
|
|
2431
|
+
normalize: J,
|
|
2432
|
+
padToSquare: gr,
|
|
2433
|
+
predictAgeAndGender: Yd,
|
|
2434
|
+
recognizeFaceExpressions: zd,
|
|
2435
|
+
resizeResults: rn,
|
|
2436
|
+
resolveInput: At,
|
|
2437
|
+
shuffleArray: Rn,
|
|
2438
|
+
sigmoid: fe,
|
|
2439
|
+
ssdMobilenetv1: Ko,
|
|
2440
|
+
tf: n,
|
|
2441
|
+
tinyFaceDetector: Rd,
|
|
2442
|
+
tinyYolov2: $d,
|
|
2443
|
+
toNetInput: F,
|
|
2444
|
+
utils: lr,
|
|
2445
|
+
validateConfig: so,
|
|
2446
|
+
version: Lb
|
|
2447
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
8
2448
|
class CameraPermissionDenied extends Error {
|
|
9
2449
|
constructor(message) {
|
|
10
2450
|
super(message);
|
|
@@ -220,7 +2660,7 @@ function $constructor(name, initializer2, params) {
|
|
|
220
2660
|
Object.defineProperty(inst, "_zod", {
|
|
221
2661
|
value: {
|
|
222
2662
|
def,
|
|
223
|
-
constr:
|
|
2663
|
+
constr: _2,
|
|
224
2664
|
traits: /* @__PURE__ */ new Set()
|
|
225
2665
|
},
|
|
226
2666
|
enumerable: false
|
|
@@ -231,12 +2671,12 @@ function $constructor(name, initializer2, params) {
|
|
|
231
2671
|
}
|
|
232
2672
|
inst._zod.traits.add(name);
|
|
233
2673
|
initializer2(inst, def);
|
|
234
|
-
const proto =
|
|
2674
|
+
const proto = _2.prototype;
|
|
235
2675
|
const keys = Object.keys(proto);
|
|
236
2676
|
for (let i = 0; i < keys.length; i++) {
|
|
237
|
-
const
|
|
238
|
-
if (!(
|
|
239
|
-
inst[
|
|
2677
|
+
const k2 = keys[i];
|
|
2678
|
+
if (!(k2 in inst)) {
|
|
2679
|
+
inst[k2] = proto[k2].bind(inst);
|
|
240
2680
|
}
|
|
241
2681
|
}
|
|
242
2682
|
}
|
|
@@ -244,7 +2684,7 @@ function $constructor(name, initializer2, params) {
|
|
|
244
2684
|
class Definition extends Parent {
|
|
245
2685
|
}
|
|
246
2686
|
Object.defineProperty(Definition, "name", { value: name });
|
|
247
|
-
function
|
|
2687
|
+
function _2(def) {
|
|
248
2688
|
var _a2;
|
|
249
2689
|
const inst = (params == null ? void 0 : params.Parent) ? new Definition() : this;
|
|
250
2690
|
init2(inst, def);
|
|
@@ -254,8 +2694,8 @@ function $constructor(name, initializer2, params) {
|
|
|
254
2694
|
}
|
|
255
2695
|
return inst;
|
|
256
2696
|
}
|
|
257
|
-
Object.defineProperty(
|
|
258
|
-
Object.defineProperty(
|
|
2697
|
+
Object.defineProperty(_2, "init", { value: init2 });
|
|
2698
|
+
Object.defineProperty(_2, Symbol.hasInstance, {
|
|
259
2699
|
value: (inst) => {
|
|
260
2700
|
var _a2, _b;
|
|
261
2701
|
if ((params == null ? void 0 : params.Parent) && inst instanceof params.Parent)
|
|
@@ -263,8 +2703,8 @@ function $constructor(name, initializer2, params) {
|
|
|
263
2703
|
return (_b = (_a2 = inst == null ? void 0 : inst._zod) == null ? void 0 : _a2.traits) == null ? void 0 : _b.has(name);
|
|
264
2704
|
}
|
|
265
2705
|
});
|
|
266
|
-
Object.defineProperty(
|
|
267
|
-
return
|
|
2706
|
+
Object.defineProperty(_2, "name", { value: name });
|
|
2707
|
+
return _2;
|
|
268
2708
|
}
|
|
269
2709
|
class $ZodAsyncError extends Error {
|
|
270
2710
|
constructor() {
|
|
@@ -282,11 +2722,11 @@ function config(newConfig) {
|
|
|
282
2722
|
return globalConfig$1;
|
|
283
2723
|
}
|
|
284
2724
|
function getEnumValues(entries) {
|
|
285
|
-
const numericValues = Object.values(entries).filter((
|
|
286
|
-
const values = Object.entries(entries).filter(([
|
|
2725
|
+
const numericValues = Object.values(entries).filter((v2) => typeof v2 === "number");
|
|
2726
|
+
const values = Object.entries(entries).filter(([k2, _2]) => numericValues.indexOf(+k2) === -1).map(([_2, v2]) => v2);
|
|
287
2727
|
return values;
|
|
288
2728
|
}
|
|
289
|
-
function jsonStringifyReplacer(
|
|
2729
|
+
function jsonStringifyReplacer(_2, value) {
|
|
290
2730
|
if (typeof value === "bigint")
|
|
291
2731
|
return value.toString();
|
|
292
2732
|
return value;
|
|
@@ -339,9 +2779,9 @@ function defineLazy(object2, key, getter) {
|
|
|
339
2779
|
}
|
|
340
2780
|
return value;
|
|
341
2781
|
},
|
|
342
|
-
set(
|
|
2782
|
+
set(v2) {
|
|
343
2783
|
Object.defineProperty(object2, key, {
|
|
344
|
-
value:
|
|
2784
|
+
value: v2
|
|
345
2785
|
// configurable: true,
|
|
346
2786
|
});
|
|
347
2787
|
},
|
|
@@ -381,17 +2821,17 @@ const allowsEval = cached(() => {
|
|
|
381
2821
|
return false;
|
|
382
2822
|
}
|
|
383
2823
|
try {
|
|
384
|
-
const
|
|
385
|
-
new
|
|
2824
|
+
const F2 = Function;
|
|
2825
|
+
new F2("");
|
|
386
2826
|
return true;
|
|
387
|
-
} catch (
|
|
2827
|
+
} catch (_2) {
|
|
388
2828
|
return false;
|
|
389
2829
|
}
|
|
390
2830
|
});
|
|
391
|
-
function isPlainObject(
|
|
392
|
-
if (isObject(
|
|
2831
|
+
function isPlainObject(o9) {
|
|
2832
|
+
if (isObject(o9) === false)
|
|
393
2833
|
return false;
|
|
394
|
-
const ctor =
|
|
2834
|
+
const ctor = o9.constructor;
|
|
395
2835
|
if (ctor === void 0)
|
|
396
2836
|
return true;
|
|
397
2837
|
if (typeof ctor !== "function")
|
|
@@ -404,12 +2844,12 @@ function isPlainObject(o) {
|
|
|
404
2844
|
}
|
|
405
2845
|
return true;
|
|
406
2846
|
}
|
|
407
|
-
function shallowClone(
|
|
408
|
-
if (isPlainObject(
|
|
409
|
-
return { ...
|
|
410
|
-
if (Array.isArray(
|
|
411
|
-
return [...
|
|
412
|
-
return
|
|
2847
|
+
function shallowClone(o9) {
|
|
2848
|
+
if (isPlainObject(o9))
|
|
2849
|
+
return { ...o9 };
|
|
2850
|
+
if (Array.isArray(o9))
|
|
2851
|
+
return [...o9];
|
|
2852
|
+
return o9;
|
|
413
2853
|
}
|
|
414
2854
|
const propertyKeyTypes = /* @__PURE__ */ new Set(["string", "number", "symbol"]);
|
|
415
2855
|
function escapeRegex(str) {
|
|
@@ -438,8 +2878,8 @@ function normalizeParams(_params) {
|
|
|
438
2878
|
return params;
|
|
439
2879
|
}
|
|
440
2880
|
function optionalKeys(shape) {
|
|
441
|
-
return Object.keys(shape).filter((
|
|
442
|
-
return shape[
|
|
2881
|
+
return Object.keys(shape).filter((k2) => {
|
|
2882
|
+
return shape[k2]._zod.optin === "optional" && shape[k2]._zod.optout === "optional";
|
|
443
2883
|
});
|
|
444
2884
|
}
|
|
445
2885
|
const NUMBER_FORMAT_RANGES = {
|
|
@@ -642,10 +3082,10 @@ function unwrapMessage(message) {
|
|
|
642
3082
|
return typeof message === "string" ? message : message == null ? void 0 : message.message;
|
|
643
3083
|
}
|
|
644
3084
|
function finalizeIssue(iss, ctx, config2) {
|
|
645
|
-
var _a2, _b, _c, _d,
|
|
3085
|
+
var _a2, _b, _c, _d, _e2, _f;
|
|
646
3086
|
const full = { ...iss, path: iss.path ?? [] };
|
|
647
3087
|
if (!iss.message) {
|
|
648
|
-
const message = unwrapMessage((_c = (_b = (_a2 = iss.inst) == null ? void 0 : _a2._zod.def) == null ? void 0 : _b.error) == null ? void 0 : _c.call(_b, iss)) ?? unwrapMessage((_d = ctx == null ? void 0 : ctx.error) == null ? void 0 : _d.call(ctx, iss)) ?? unwrapMessage((
|
|
3088
|
+
const message = unwrapMessage((_c = (_b = (_a2 = iss.inst) == null ? void 0 : _a2._zod.def) == null ? void 0 : _b.error) == null ? void 0 : _c.call(_b, iss)) ?? unwrapMessage((_d = ctx == null ? void 0 : ctx.error) == null ? void 0 : _d.call(ctx, iss)) ?? unwrapMessage((_e2 = config2.customError) == null ? void 0 : _e2.call(config2, iss)) ?? unwrapMessage((_f = config2.localeError) == null ? void 0 : _f.call(config2, iss)) ?? "Invalid input";
|
|
649
3089
|
full.message = message;
|
|
650
3090
|
}
|
|
651
3091
|
delete full.inst;
|
|
@@ -1284,11 +3724,11 @@ class Doc {
|
|
|
1284
3724
|
}
|
|
1285
3725
|
}
|
|
1286
3726
|
compile() {
|
|
1287
|
-
const
|
|
3727
|
+
const F2 = Function;
|
|
1288
3728
|
const args = this == null ? void 0 : this.args;
|
|
1289
3729
|
const content = (this == null ? void 0 : this.content) ?? [``];
|
|
1290
3730
|
const lines = [...content.map((x) => ` ${x}`)];
|
|
1291
|
-
return new
|
|
3731
|
+
return new F2(...args, lines.join("\n"));
|
|
1292
3732
|
}
|
|
1293
3733
|
}
|
|
1294
3734
|
const version = {
|
|
@@ -1330,13 +3770,13 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
|
1330
3770
|
continue;
|
|
1331
3771
|
}
|
|
1332
3772
|
const currLen = payload.issues.length;
|
|
1333
|
-
const
|
|
1334
|
-
if (
|
|
3773
|
+
const _2 = ch._zod.check(payload);
|
|
3774
|
+
if (_2 instanceof Promise && (ctx == null ? void 0 : ctx.async) === false) {
|
|
1335
3775
|
throw new $ZodAsyncError();
|
|
1336
3776
|
}
|
|
1337
|
-
if (asyncResult ||
|
|
3777
|
+
if (asyncResult || _2 instanceof Promise) {
|
|
1338
3778
|
asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
|
|
1339
|
-
await
|
|
3779
|
+
await _2;
|
|
1340
3780
|
const nextLen = payload.issues.length;
|
|
1341
3781
|
if (nextLen === currLen)
|
|
1342
3782
|
return;
|
|
@@ -1399,7 +3839,7 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
|
1399
3839
|
try {
|
|
1400
3840
|
const r = safeParse$1(inst, value);
|
|
1401
3841
|
return r.success ? { value: r.data } : { issues: (_a4 = r.error) == null ? void 0 : _a4.issues };
|
|
1402
|
-
} catch (
|
|
3842
|
+
} catch (_2) {
|
|
1403
3843
|
return safeParseAsync$1(inst, value).then((r) => {
|
|
1404
3844
|
var _a5;
|
|
1405
3845
|
return r.success ? { value: r.data } : { issues: (_a5 = r.error) == null ? void 0 : _a5.issues };
|
|
@@ -1414,11 +3854,11 @@ const $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
|
|
|
1414
3854
|
var _a2;
|
|
1415
3855
|
$ZodType.init(inst, def);
|
|
1416
3856
|
inst._zod.pattern = [...((_a2 = inst == null ? void 0 : inst._zod.bag) == null ? void 0 : _a2.patterns) ?? []].pop() ?? string$1(inst._zod.bag);
|
|
1417
|
-
inst._zod.parse = (payload,
|
|
3857
|
+
inst._zod.parse = (payload, _2) => {
|
|
1418
3858
|
if (def.coerce)
|
|
1419
3859
|
try {
|
|
1420
3860
|
payload.value = String(payload.value);
|
|
1421
|
-
} catch (
|
|
3861
|
+
} catch (_3) {
|
|
1422
3862
|
}
|
|
1423
3863
|
if (typeof payload.value === "string")
|
|
1424
3864
|
return payload;
|
|
@@ -1451,10 +3891,10 @@ const $ZodUUID = /* @__PURE__ */ $constructor("$ZodUUID", (inst, def) => {
|
|
|
1451
3891
|
v7: 7,
|
|
1452
3892
|
v8: 8
|
|
1453
3893
|
};
|
|
1454
|
-
const
|
|
1455
|
-
if (
|
|
3894
|
+
const v2 = versionMap[def.version];
|
|
3895
|
+
if (v2 === void 0)
|
|
1456
3896
|
throw new Error(`Invalid UUID version: "${def.version}"`);
|
|
1457
|
-
def.pattern ?? (def.pattern = uuid(
|
|
3897
|
+
def.pattern ?? (def.pattern = uuid(v2));
|
|
1458
3898
|
} else
|
|
1459
3899
|
def.pattern ?? (def.pattern = uuid());
|
|
1460
3900
|
$ZodStringFormat.init(inst, def);
|
|
@@ -1503,7 +3943,7 @@ const $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
|
|
|
1503
3943
|
payload.value = trimmed;
|
|
1504
3944
|
}
|
|
1505
3945
|
return;
|
|
1506
|
-
} catch (
|
|
3946
|
+
} catch (_2) {
|
|
1507
3947
|
payload.issues.push({
|
|
1508
3948
|
code: "invalid_format",
|
|
1509
3949
|
format: "url",
|
|
@@ -1709,7 +4149,7 @@ const $ZodNumber = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
|
|
|
1709
4149
|
if (def.coerce)
|
|
1710
4150
|
try {
|
|
1711
4151
|
payload.value = Number(payload.value);
|
|
1712
|
-
} catch (
|
|
4152
|
+
} catch (_2) {
|
|
1713
4153
|
}
|
|
1714
4154
|
const input = payload.value;
|
|
1715
4155
|
if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) {
|
|
@@ -1737,7 +4177,7 @@ const $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
|
|
|
1737
4177
|
if (def.coerce)
|
|
1738
4178
|
try {
|
|
1739
4179
|
payload.value = Boolean(payload.value);
|
|
1740
|
-
} catch (
|
|
4180
|
+
} catch (_2) {
|
|
1741
4181
|
}
|
|
1742
4182
|
const input = payload.value;
|
|
1743
4183
|
if (typeof input === "boolean")
|
|
@@ -1828,9 +4268,9 @@ function handlePropertyResult(result, final, key, input, isOptionalOut) {
|
|
|
1828
4268
|
function normalizeDef(def) {
|
|
1829
4269
|
var _a2, _b, _c, _d;
|
|
1830
4270
|
const keys = Object.keys(def.shape);
|
|
1831
|
-
for (const
|
|
1832
|
-
if (!((_d = (_c = (_b = (_a2 = def.shape) == null ? void 0 : _a2[
|
|
1833
|
-
throw new Error(`Invalid element at key "${
|
|
4271
|
+
for (const k2 of keys) {
|
|
4272
|
+
if (!((_d = (_c = (_b = (_a2 = def.shape) == null ? void 0 : _a2[k2]) == null ? void 0 : _b._zod) == null ? void 0 : _c.traits) == null ? void 0 : _d.has("$ZodType"))) {
|
|
4273
|
+
throw new Error(`Invalid element at key "${k2}": expected a Zod schema`);
|
|
1834
4274
|
}
|
|
1835
4275
|
}
|
|
1836
4276
|
const okeys = optionalKeys(def.shape);
|
|
@@ -1899,8 +4339,8 @@ const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
1899
4339
|
const field = shape[key]._zod;
|
|
1900
4340
|
if (field.values) {
|
|
1901
4341
|
propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
|
|
1902
|
-
for (const
|
|
1903
|
-
propValues[key].add(
|
|
4342
|
+
for (const v2 of field.values)
|
|
4343
|
+
propValues[key].add(v2);
|
|
1904
4344
|
}
|
|
1905
4345
|
}
|
|
1906
4346
|
return propValues;
|
|
@@ -1948,8 +4388,8 @@ const $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def)
|
|
|
1948
4388
|
const doc = new Doc(["shape", "payload", "ctx"]);
|
|
1949
4389
|
const normalized = _normalized.value;
|
|
1950
4390
|
const parseStr = (key) => {
|
|
1951
|
-
const
|
|
1952
|
-
return `shape[${
|
|
4391
|
+
const k2 = esc(key);
|
|
4392
|
+
return `shape[${k2}]._zod.run({ value: input[${k2}], issues: [] }, ctx)`;
|
|
1953
4393
|
};
|
|
1954
4394
|
doc.write(`const input = payload.value;`);
|
|
1955
4395
|
const ids = /* @__PURE__ */ Object.create(null);
|
|
@@ -1960,27 +4400,27 @@ const $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def)
|
|
|
1960
4400
|
doc.write(`const newResult = {};`);
|
|
1961
4401
|
for (const key of normalized.keys) {
|
|
1962
4402
|
const id = ids[key];
|
|
1963
|
-
const
|
|
4403
|
+
const k2 = esc(key);
|
|
1964
4404
|
const schema = shape[key];
|
|
1965
4405
|
const isOptionalOut = ((_a2 = schema == null ? void 0 : schema._zod) == null ? void 0 : _a2.optout) === "optional";
|
|
1966
4406
|
doc.write(`const ${id} = ${parseStr(key)};`);
|
|
1967
4407
|
if (isOptionalOut) {
|
|
1968
4408
|
doc.write(`
|
|
1969
4409
|
if (${id}.issues.length) {
|
|
1970
|
-
if (${
|
|
4410
|
+
if (${k2} in input) {
|
|
1971
4411
|
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
1972
4412
|
...iss,
|
|
1973
|
-
path: iss.path ? [${
|
|
4413
|
+
path: iss.path ? [${k2}, ...iss.path] : [${k2}]
|
|
1974
4414
|
})));
|
|
1975
4415
|
}
|
|
1976
4416
|
}
|
|
1977
4417
|
|
|
1978
4418
|
if (${id}.value === undefined) {
|
|
1979
|
-
if (${
|
|
1980
|
-
newResult[${
|
|
4419
|
+
if (${k2} in input) {
|
|
4420
|
+
newResult[${k2}] = undefined;
|
|
1981
4421
|
}
|
|
1982
4422
|
} else {
|
|
1983
|
-
newResult[${
|
|
4423
|
+
newResult[${k2}] = ${id}.value;
|
|
1984
4424
|
}
|
|
1985
4425
|
|
|
1986
4426
|
`);
|
|
@@ -1989,16 +4429,16 @@ const $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def)
|
|
|
1989
4429
|
if (${id}.issues.length) {
|
|
1990
4430
|
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
1991
4431
|
...iss,
|
|
1992
|
-
path: iss.path ? [${
|
|
4432
|
+
path: iss.path ? [${k2}, ...iss.path] : [${k2}]
|
|
1993
4433
|
})));
|
|
1994
4434
|
}
|
|
1995
4435
|
|
|
1996
4436
|
if (${id}.value === undefined) {
|
|
1997
|
-
if (${
|
|
1998
|
-
newResult[${
|
|
4437
|
+
if (${k2} in input) {
|
|
4438
|
+
newResult[${k2}] = undefined;
|
|
1999
4439
|
}
|
|
2000
4440
|
} else {
|
|
2001
|
-
newResult[${
|
|
4441
|
+
newResult[${k2}] = ${id}.value;
|
|
2002
4442
|
}
|
|
2003
4443
|
|
|
2004
4444
|
`);
|
|
@@ -2061,17 +4501,17 @@ function handleUnionResults(results, final, inst, ctx) {
|
|
|
2061
4501
|
}
|
|
2062
4502
|
const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
2063
4503
|
$ZodType.init(inst, def);
|
|
2064
|
-
defineLazy(inst._zod, "optin", () => def.options.some((
|
|
2065
|
-
defineLazy(inst._zod, "optout", () => def.options.some((
|
|
4504
|
+
defineLazy(inst._zod, "optin", () => def.options.some((o9) => o9._zod.optin === "optional") ? "optional" : void 0);
|
|
4505
|
+
defineLazy(inst._zod, "optout", () => def.options.some((o9) => o9._zod.optout === "optional") ? "optional" : void 0);
|
|
2066
4506
|
defineLazy(inst._zod, "values", () => {
|
|
2067
|
-
if (def.options.every((
|
|
4507
|
+
if (def.options.every((o9) => o9._zod.values)) {
|
|
2068
4508
|
return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
|
|
2069
4509
|
}
|
|
2070
4510
|
return void 0;
|
|
2071
4511
|
});
|
|
2072
4512
|
defineLazy(inst._zod, "pattern", () => {
|
|
2073
|
-
if (def.options.every((
|
|
2074
|
-
const patterns = def.options.map((
|
|
4513
|
+
if (def.options.every((o9) => o9._zod.pattern)) {
|
|
4514
|
+
const patterns = def.options.map((o9) => o9._zod.pattern);
|
|
2075
4515
|
return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
|
|
2076
4516
|
}
|
|
2077
4517
|
return void 0;
|
|
@@ -2170,10 +4610,10 @@ function handleIntersectionResults(result, left, right) {
|
|
|
2170
4610
|
for (const iss of left.issues) {
|
|
2171
4611
|
if (iss.code === "unrecognized_keys") {
|
|
2172
4612
|
unrecIssue ?? (unrecIssue = iss);
|
|
2173
|
-
for (const
|
|
2174
|
-
if (!unrecKeys.has(
|
|
2175
|
-
unrecKeys.set(
|
|
2176
|
-
unrecKeys.get(
|
|
4613
|
+
for (const k2 of iss.keys) {
|
|
4614
|
+
if (!unrecKeys.has(k2))
|
|
4615
|
+
unrecKeys.set(k2, {});
|
|
4616
|
+
unrecKeys.get(k2).l = true;
|
|
2177
4617
|
}
|
|
2178
4618
|
} else {
|
|
2179
4619
|
result.issues.push(iss);
|
|
@@ -2181,16 +4621,16 @@ function handleIntersectionResults(result, left, right) {
|
|
|
2181
4621
|
}
|
|
2182
4622
|
for (const iss of right.issues) {
|
|
2183
4623
|
if (iss.code === "unrecognized_keys") {
|
|
2184
|
-
for (const
|
|
2185
|
-
if (!unrecKeys.has(
|
|
2186
|
-
unrecKeys.set(
|
|
2187
|
-
unrecKeys.get(
|
|
4624
|
+
for (const k2 of iss.keys) {
|
|
4625
|
+
if (!unrecKeys.has(k2))
|
|
4626
|
+
unrecKeys.set(k2, {});
|
|
4627
|
+
unrecKeys.get(k2).r = true;
|
|
2188
4628
|
}
|
|
2189
4629
|
} else {
|
|
2190
4630
|
result.issues.push(iss);
|
|
2191
4631
|
}
|
|
2192
4632
|
}
|
|
2193
|
-
const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([
|
|
4633
|
+
const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k2]) => k2);
|
|
2194
4634
|
if (bothKeys.length && unrecIssue) {
|
|
2195
4635
|
result.issues.push({ ...unrecIssue, keys: bothKeys });
|
|
2196
4636
|
}
|
|
@@ -2208,7 +4648,7 @@ const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
|
|
|
2208
4648
|
const values = getEnumValues(def.entries);
|
|
2209
4649
|
const valuesSet = new Set(values);
|
|
2210
4650
|
inst._zod.values = valuesSet;
|
|
2211
|
-
inst._zod.pattern = new RegExp(`^(${values.filter((
|
|
4651
|
+
inst._zod.pattern = new RegExp(`^(${values.filter((k2) => propertyKeyTypes.has(typeof k2)).map((o9) => typeof o9 === "string" ? escapeRegex(o9) : o9.toString()).join("|")})$`);
|
|
2212
4652
|
inst._zod.parse = (payload, _ctx) => {
|
|
2213
4653
|
const input = payload.value;
|
|
2214
4654
|
if (valuesSet.has(input)) {
|
|
@@ -2341,8 +4781,8 @@ const $ZodPrefault = /* @__PURE__ */ $constructor("$ZodPrefault", (inst, def) =>
|
|
|
2341
4781
|
const $ZodNonOptional = /* @__PURE__ */ $constructor("$ZodNonOptional", (inst, def) => {
|
|
2342
4782
|
$ZodType.init(inst, def);
|
|
2343
4783
|
defineLazy(inst._zod, "values", () => {
|
|
2344
|
-
const
|
|
2345
|
-
return
|
|
4784
|
+
const v2 = def.innerType._zod.values;
|
|
4785
|
+
return v2 ? new Set([...v2].filter((x) => x !== void 0)) : void 0;
|
|
2346
4786
|
});
|
|
2347
4787
|
inst._zod.parse = (payload, ctx) => {
|
|
2348
4788
|
const result = def.innerType._zod.run(payload, ctx);
|
|
@@ -2461,7 +4901,7 @@ function handleReadonlyResult(payload) {
|
|
|
2461
4901
|
const $ZodCustom = /* @__PURE__ */ $constructor("$ZodCustom", (inst, def) => {
|
|
2462
4902
|
$ZodCheck.init(inst, def);
|
|
2463
4903
|
$ZodType.init(inst, def);
|
|
2464
|
-
inst._zod.parse = (payload,
|
|
4904
|
+
inst._zod.parse = (payload, _2) => {
|
|
2465
4905
|
return payload;
|
|
2466
4906
|
};
|
|
2467
4907
|
inst._zod.check = (payload) => {
|
|
@@ -3071,7 +5511,7 @@ function initializeContext(params) {
|
|
|
3071
5511
|
external: (params == null ? void 0 : params.external) ?? void 0
|
|
3072
5512
|
};
|
|
3073
5513
|
}
|
|
3074
|
-
function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
|
|
5514
|
+
function process$1(schema, ctx, _params = { path: [], schemaPath: [] }) {
|
|
3075
5515
|
var _a3, _b;
|
|
3076
5516
|
var _a2;
|
|
3077
5517
|
const def = schema._zod.def;
|
|
@@ -3109,7 +5549,7 @@ function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
|
|
|
3109
5549
|
if (parent) {
|
|
3110
5550
|
if (!result.ref)
|
|
3111
5551
|
result.ref = parent;
|
|
3112
|
-
process(parent, ctx, params);
|
|
5552
|
+
process$1(parent, ctx, params);
|
|
3113
5553
|
ctx.seen.get(parent).isParent = true;
|
|
3114
5554
|
}
|
|
3115
5555
|
}
|
|
@@ -3392,14 +5832,14 @@ function isTransforming(_schema, _ctx) {
|
|
|
3392
5832
|
}
|
|
3393
5833
|
const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
|
|
3394
5834
|
const ctx = initializeContext({ ...params, processors });
|
|
3395
|
-
process(schema, ctx);
|
|
5835
|
+
process$1(schema, ctx);
|
|
3396
5836
|
extractDefs(ctx, schema);
|
|
3397
5837
|
return finalize(ctx, schema);
|
|
3398
5838
|
};
|
|
3399
|
-
const createStandardJSONSchemaMethod = (schema,
|
|
5839
|
+
const createStandardJSONSchemaMethod = (schema, io2, processors = {}) => (params) => {
|
|
3400
5840
|
const { libraryOptions, target } = params ?? {};
|
|
3401
|
-
const ctx = initializeContext({ ...libraryOptions ?? {}, target, io, processors });
|
|
3402
|
-
process(schema, ctx);
|
|
5841
|
+
const ctx = initializeContext({ ...libraryOptions ?? {}, target, io: io2, processors });
|
|
5842
|
+
process$1(schema, ctx);
|
|
3403
5843
|
extractDefs(ctx, schema);
|
|
3404
5844
|
return finalize(ctx, schema);
|
|
3405
5845
|
};
|
|
@@ -3500,9 +5940,9 @@ const unknownProcessor = (_schema, _ctx, _json, _params) => {
|
|
|
3500
5940
|
const enumProcessor = (schema, _ctx, json, _params) => {
|
|
3501
5941
|
const def = schema._zod.def;
|
|
3502
5942
|
const values = getEnumValues(def.entries);
|
|
3503
|
-
if (values.every((
|
|
5943
|
+
if (values.every((v2) => typeof v2 === "number"))
|
|
3504
5944
|
json.type = "number";
|
|
3505
|
-
if (values.every((
|
|
5945
|
+
if (values.every((v2) => typeof v2 === "string"))
|
|
3506
5946
|
json.type = "string";
|
|
3507
5947
|
json.enum = values;
|
|
3508
5948
|
};
|
|
@@ -3525,7 +5965,7 @@ const arrayProcessor = (schema, ctx, _json, params) => {
|
|
|
3525
5965
|
if (typeof maximum === "number")
|
|
3526
5966
|
json.maxItems = maximum;
|
|
3527
5967
|
json.type = "array";
|
|
3528
|
-
json.items = process(def.element, ctx, { ...params, path: [...params.path, "items"] });
|
|
5968
|
+
json.items = process$1(def.element, ctx, { ...params, path: [...params.path, "items"] });
|
|
3529
5969
|
};
|
|
3530
5970
|
const objectProcessor = (schema, ctx, _json, params) => {
|
|
3531
5971
|
var _a2;
|
|
@@ -3535,18 +5975,18 @@ const objectProcessor = (schema, ctx, _json, params) => {
|
|
|
3535
5975
|
json.properties = {};
|
|
3536
5976
|
const shape = def.shape;
|
|
3537
5977
|
for (const key in shape) {
|
|
3538
|
-
json.properties[key] = process(shape[key], ctx, {
|
|
5978
|
+
json.properties[key] = process$1(shape[key], ctx, {
|
|
3539
5979
|
...params,
|
|
3540
5980
|
path: [...params.path, "properties", key]
|
|
3541
5981
|
});
|
|
3542
5982
|
}
|
|
3543
5983
|
const allKeys = new Set(Object.keys(shape));
|
|
3544
5984
|
const requiredKeys = new Set([...allKeys].filter((key) => {
|
|
3545
|
-
const
|
|
5985
|
+
const v2 = def.shape[key]._zod;
|
|
3546
5986
|
if (ctx.io === "input") {
|
|
3547
|
-
return
|
|
5987
|
+
return v2.optin === void 0;
|
|
3548
5988
|
} else {
|
|
3549
|
-
return
|
|
5989
|
+
return v2.optout === void 0;
|
|
3550
5990
|
}
|
|
3551
5991
|
}));
|
|
3552
5992
|
if (requiredKeys.size > 0) {
|
|
@@ -3558,7 +5998,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
|
|
|
3558
5998
|
if (ctx.io === "output")
|
|
3559
5999
|
json.additionalProperties = false;
|
|
3560
6000
|
} else if (def.catchall) {
|
|
3561
|
-
json.additionalProperties = process(def.catchall, ctx, {
|
|
6001
|
+
json.additionalProperties = process$1(def.catchall, ctx, {
|
|
3562
6002
|
...params,
|
|
3563
6003
|
path: [...params.path, "additionalProperties"]
|
|
3564
6004
|
});
|
|
@@ -3567,7 +6007,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
|
|
|
3567
6007
|
const unionProcessor = (schema, ctx, json, params) => {
|
|
3568
6008
|
const def = schema._zod.def;
|
|
3569
6009
|
const isExclusive = def.inclusive === false;
|
|
3570
|
-
const options = def.options.map((x, i) => process(x, ctx, {
|
|
6010
|
+
const options = def.options.map((x, i) => process$1(x, ctx, {
|
|
3571
6011
|
...params,
|
|
3572
6012
|
path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
|
|
3573
6013
|
}));
|
|
@@ -3579,11 +6019,11 @@ const unionProcessor = (schema, ctx, json, params) => {
|
|
|
3579
6019
|
};
|
|
3580
6020
|
const intersectionProcessor = (schema, ctx, json, params) => {
|
|
3581
6021
|
const def = schema._zod.def;
|
|
3582
|
-
const a = process(def.left, ctx, {
|
|
6022
|
+
const a = process$1(def.left, ctx, {
|
|
3583
6023
|
...params,
|
|
3584
6024
|
path: [...params.path, "allOf", 0]
|
|
3585
6025
|
});
|
|
3586
|
-
const b = process(def.right, ctx, {
|
|
6026
|
+
const b = process$1(def.right, ctx, {
|
|
3587
6027
|
...params,
|
|
3588
6028
|
path: [...params.path, "allOf", 1]
|
|
3589
6029
|
});
|
|
@@ -3596,7 +6036,7 @@ const intersectionProcessor = (schema, ctx, json, params) => {
|
|
|
3596
6036
|
};
|
|
3597
6037
|
const nullableProcessor = (schema, ctx, json, params) => {
|
|
3598
6038
|
const def = schema._zod.def;
|
|
3599
|
-
const inner = process(def.innerType, ctx, params);
|
|
6039
|
+
const inner = process$1(def.innerType, ctx, params);
|
|
3600
6040
|
const seen = ctx.seen.get(schema);
|
|
3601
6041
|
if (ctx.target === "openapi-3.0") {
|
|
3602
6042
|
seen.ref = def.innerType;
|
|
@@ -3607,20 +6047,20 @@ const nullableProcessor = (schema, ctx, json, params) => {
|
|
|
3607
6047
|
};
|
|
3608
6048
|
const nonoptionalProcessor = (schema, ctx, _json, params) => {
|
|
3609
6049
|
const def = schema._zod.def;
|
|
3610
|
-
process(def.innerType, ctx, params);
|
|
6050
|
+
process$1(def.innerType, ctx, params);
|
|
3611
6051
|
const seen = ctx.seen.get(schema);
|
|
3612
6052
|
seen.ref = def.innerType;
|
|
3613
6053
|
};
|
|
3614
6054
|
const defaultProcessor = (schema, ctx, json, params) => {
|
|
3615
6055
|
const def = schema._zod.def;
|
|
3616
|
-
process(def.innerType, ctx, params);
|
|
6056
|
+
process$1(def.innerType, ctx, params);
|
|
3617
6057
|
const seen = ctx.seen.get(schema);
|
|
3618
6058
|
seen.ref = def.innerType;
|
|
3619
6059
|
json.default = JSON.parse(JSON.stringify(def.defaultValue));
|
|
3620
6060
|
};
|
|
3621
6061
|
const prefaultProcessor = (schema, ctx, json, params) => {
|
|
3622
6062
|
const def = schema._zod.def;
|
|
3623
|
-
process(def.innerType, ctx, params);
|
|
6063
|
+
process$1(def.innerType, ctx, params);
|
|
3624
6064
|
const seen = ctx.seen.get(schema);
|
|
3625
6065
|
seen.ref = def.innerType;
|
|
3626
6066
|
if (ctx.io === "input")
|
|
@@ -3628,7 +6068,7 @@ const prefaultProcessor = (schema, ctx, json, params) => {
|
|
|
3628
6068
|
};
|
|
3629
6069
|
const catchProcessor = (schema, ctx, json, params) => {
|
|
3630
6070
|
const def = schema._zod.def;
|
|
3631
|
-
process(def.innerType, ctx, params);
|
|
6071
|
+
process$1(def.innerType, ctx, params);
|
|
3632
6072
|
const seen = ctx.seen.get(schema);
|
|
3633
6073
|
seen.ref = def.innerType;
|
|
3634
6074
|
let catchValue;
|
|
@@ -3642,20 +6082,20 @@ const catchProcessor = (schema, ctx, json, params) => {
|
|
|
3642
6082
|
const pipeProcessor = (schema, ctx, _json, params) => {
|
|
3643
6083
|
const def = schema._zod.def;
|
|
3644
6084
|
const innerType = ctx.io === "input" ? def.in._zod.def.type === "transform" ? def.out : def.in : def.out;
|
|
3645
|
-
process(innerType, ctx, params);
|
|
6085
|
+
process$1(innerType, ctx, params);
|
|
3646
6086
|
const seen = ctx.seen.get(schema);
|
|
3647
6087
|
seen.ref = innerType;
|
|
3648
6088
|
};
|
|
3649
6089
|
const readonlyProcessor = (schema, ctx, json, params) => {
|
|
3650
6090
|
const def = schema._zod.def;
|
|
3651
|
-
process(def.innerType, ctx, params);
|
|
6091
|
+
process$1(def.innerType, ctx, params);
|
|
3652
6092
|
const seen = ctx.seen.get(schema);
|
|
3653
6093
|
seen.ref = def.innerType;
|
|
3654
6094
|
json.readOnly = true;
|
|
3655
6095
|
};
|
|
3656
6096
|
const optionalProcessor = (schema, ctx, _json, params) => {
|
|
3657
6097
|
const def = schema._zod.def;
|
|
3658
|
-
process(def.innerType, ctx, params);
|
|
6098
|
+
process$1(def.innerType, ctx, params);
|
|
3659
6099
|
const seen = ctx.seen.get(schema);
|
|
3660
6100
|
seen.ref = def.innerType;
|
|
3661
6101
|
};
|
|
@@ -4137,7 +6577,7 @@ const ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
|
4137
6577
|
};
|
|
4138
6578
|
});
|
|
4139
6579
|
function _enum(values, params) {
|
|
4140
|
-
const entries = Array.isArray(values) ? Object.fromEntries(values.map((
|
|
6580
|
+
const entries = Array.isArray(values) ? Object.fromEntries(values.map((v2) => [v2, v2])) : values;
|
|
4141
6581
|
return new ZodEnum({
|
|
4142
6582
|
type: "enum",
|
|
4143
6583
|
entries,
|
|
@@ -4315,7 +6755,7 @@ function superRefine(fn) {
|
|
|
4315
6755
|
return /* @__PURE__ */ _superRefine(fn);
|
|
4316
6756
|
}
|
|
4317
6757
|
const AuthMethodSchema = _enum(["face", "password"]);
|
|
4318
|
-
object({
|
|
6758
|
+
const BiometricLoginResultSchema = object({
|
|
4319
6759
|
success: boolean(),
|
|
4320
6760
|
accessToken: string().optional(),
|
|
4321
6761
|
/**
|
|
@@ -4343,7 +6783,7 @@ object({
|
|
|
4343
6783
|
status: string().optional(),
|
|
4344
6784
|
message: string().optional()
|
|
4345
6785
|
});
|
|
4346
|
-
object({
|
|
6786
|
+
const RegistrationResultSchema = object({
|
|
4347
6787
|
success: boolean(),
|
|
4348
6788
|
message: string(),
|
|
4349
6789
|
person_id: string().optional(),
|
|
@@ -4411,12 +6851,12 @@ const DARK_TOKENS = {
|
|
|
4411
6851
|
function contrastRatio(hexA, hexB) {
|
|
4412
6852
|
const lumA = luminance(hexA);
|
|
4413
6853
|
const lumB = luminance(hexB);
|
|
4414
|
-
const [hi,
|
|
4415
|
-
return (hi + 0.05) / (
|
|
6854
|
+
const [hi, lo2] = lumA > lumB ? [lumA, lumB] : [lumB, lumA];
|
|
6855
|
+
return (hi + 0.05) / (lo2 + 0.05);
|
|
4416
6856
|
}
|
|
4417
6857
|
function luminance(hex) {
|
|
4418
|
-
const [r, g, b] = parseHex(hex).map((
|
|
4419
|
-
const s =
|
|
6858
|
+
const [r, g, b] = parseHex(hex).map((v2) => {
|
|
6859
|
+
const s = v2 / 255;
|
|
4420
6860
|
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
4421
6861
|
});
|
|
4422
6862
|
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
@@ -5130,7 +7570,7 @@ const recognize = async (image, applicationToken) => {
|
|
|
5130
7570
|
}
|
|
5131
7571
|
};
|
|
5132
7572
|
const loginWithBiometric = async (image, applicationToken) => {
|
|
5133
|
-
var _a2, _b, _c, _d,
|
|
7573
|
+
var _a2, _b, _c, _d, _e2;
|
|
5134
7574
|
ensureSecureContext();
|
|
5135
7575
|
const controller = createTimeoutController();
|
|
5136
7576
|
const compressedImage = await compressImage(image);
|
|
@@ -5176,7 +7616,7 @@ const loginWithBiometric = async (image, applicationToken) => {
|
|
|
5176
7616
|
email: ((_b = data.user) == null ? void 0 : _b.email) || "",
|
|
5177
7617
|
role: ((_c = data.user) == null ? void 0 : _c.role) || "",
|
|
5178
7618
|
validated: ((_d = data.user) == null ? void 0 : _d.validated) || false,
|
|
5179
|
-
active: ((
|
|
7619
|
+
active: ((_e2 = data.user) == null ? void 0 : _e2.active) || false
|
|
5180
7620
|
},
|
|
5181
7621
|
person: data.person ? {
|
|
5182
7622
|
id: data.person.id || "",
|
|
@@ -5199,6 +7639,127 @@ const loginWithBiometric = async (image, applicationToken) => {
|
|
|
5199
7639
|
throw new NeoFaceError("Unknown error occurred", ErrorType.NETWORK);
|
|
5200
7640
|
}
|
|
5201
7641
|
};
|
|
7642
|
+
const loginWithBiometricSSE = async (image, applicationToken) => {
|
|
7643
|
+
var _a2, _b;
|
|
7644
|
+
ensureSecureContext();
|
|
7645
|
+
const compressedImage = await compressImage(image);
|
|
7646
|
+
const arrayBuffer = await compressedImage.arrayBuffer();
|
|
7647
|
+
const base64Image = btoa(
|
|
7648
|
+
new Uint8Array(arrayBuffer).reduce((data, byte) => data + String.fromCharCode(byte), "")
|
|
7649
|
+
);
|
|
7650
|
+
const controller = createTimeoutController();
|
|
7651
|
+
let response;
|
|
7652
|
+
try {
|
|
7653
|
+
response = await fetch(`${getApiBaseUrl()}/api/v1/auth/recognition/face/`, {
|
|
7654
|
+
method: "POST",
|
|
7655
|
+
headers: {
|
|
7656
|
+
"Content-Type": "application/json",
|
|
7657
|
+
"X-App-Token": applicationToken
|
|
7658
|
+
},
|
|
7659
|
+
body: JSON.stringify({ image: base64Image, purpose: "LOGIN" }),
|
|
7660
|
+
signal: controller.signal
|
|
7661
|
+
});
|
|
7662
|
+
} catch (error) {
|
|
7663
|
+
if (error instanceof Error) {
|
|
7664
|
+
if (error.name === "AbortError") {
|
|
7665
|
+
throw new NeoFaceError("Request timed out", ErrorType.NETWORK);
|
|
7666
|
+
}
|
|
7667
|
+
if (error instanceof NeoFaceError) throw error;
|
|
7668
|
+
throw new NeoFaceError(error.message, ErrorType.NETWORK);
|
|
7669
|
+
}
|
|
7670
|
+
throw new NeoFaceError("Unknown error occurred", ErrorType.NETWORK);
|
|
7671
|
+
}
|
|
7672
|
+
if (!response.ok) {
|
|
7673
|
+
if (response.status === 401 || response.status === 403) {
|
|
7674
|
+
throw new NeoFaceError("Invalid application token", ErrorType.INVALID_TOKEN);
|
|
7675
|
+
}
|
|
7676
|
+
throw new NeoFaceError(`API Error ${response.status}`, ErrorType.API_ERROR);
|
|
7677
|
+
}
|
|
7678
|
+
const initData = await response.json();
|
|
7679
|
+
if (!initData.success || !((_a2 = initData.data) == null ? void 0 : _a2.task_id)) {
|
|
7680
|
+
throw new NeoFaceError(initData.message || "Failed to start login", ErrorType.LOGIN_FAILED);
|
|
7681
|
+
}
|
|
7682
|
+
const taskId = initData.data.task_id;
|
|
7683
|
+
const ticketUrl = `${getApiBaseUrl()}/api/v1/auth/recognition/face/login/events/${taskId}/ticket/`;
|
|
7684
|
+
const ticketRes = await fetch(ticketUrl, {
|
|
7685
|
+
method: "POST",
|
|
7686
|
+
headers: { "Content-Type": "application/json", "X-App-Token": applicationToken }
|
|
7687
|
+
});
|
|
7688
|
+
if (!ticketRes.ok) {
|
|
7689
|
+
throw new NeoFaceError(`SSE ticket request failed: ${ticketRes.status}`, ErrorType.NETWORK);
|
|
7690
|
+
}
|
|
7691
|
+
const ticketData = await ticketRes.json();
|
|
7692
|
+
const ticket = ((_b = ticketData == null ? void 0 : ticketData.data) == null ? void 0 : _b.ticket) ?? (ticketData == null ? void 0 : ticketData.ticket);
|
|
7693
|
+
if (!ticket) {
|
|
7694
|
+
throw new NeoFaceError("SSE ticket ausente na resposta", ErrorType.API_ERROR);
|
|
7695
|
+
}
|
|
7696
|
+
return new Promise((resolve, reject) => {
|
|
7697
|
+
const sseUrl = `${getApiBaseUrl()}/api/v1/auth/recognition/face/login/events/${taskId}/?ticket=${encodeURIComponent(ticket)}`;
|
|
7698
|
+
const eventSource = new EventSource(sseUrl);
|
|
7699
|
+
const timeoutId = setTimeout(() => {
|
|
7700
|
+
eventSource.close();
|
|
7701
|
+
reject(new NeoFaceError("Login timeout", ErrorType.NETWORK));
|
|
7702
|
+
}, 31e4);
|
|
7703
|
+
const cleanup = () => {
|
|
7704
|
+
clearTimeout(timeoutId);
|
|
7705
|
+
eventSource.close();
|
|
7706
|
+
};
|
|
7707
|
+
eventSource.addEventListener("success", (event) => {
|
|
7708
|
+
var _a3, _b2, _c, _d, _e2, _f;
|
|
7709
|
+
cleanup();
|
|
7710
|
+
try {
|
|
7711
|
+
const data = JSON.parse(event.data);
|
|
7712
|
+
resolve({
|
|
7713
|
+
success: true,
|
|
7714
|
+
accessToken: data.token || data.access_token || "",
|
|
7715
|
+
alias: ((_a3 = data.user) == null ? void 0 : _a3.alias) || data.alias || "",
|
|
7716
|
+
user: {
|
|
7717
|
+
id: ((_b2 = data.user) == null ? void 0 : _b2.id) || "",
|
|
7718
|
+
email: ((_c = data.user) == null ? void 0 : _c.email) || "",
|
|
7719
|
+
role: ((_d = data.user) == null ? void 0 : _d.role) || "",
|
|
7720
|
+
validated: ((_e2 = data.user) == null ? void 0 : _e2.validated) ?? false,
|
|
7721
|
+
active: ((_f = data.user) == null ? void 0 : _f.active) ?? false
|
|
7722
|
+
},
|
|
7723
|
+
person: data.person ? {
|
|
7724
|
+
id: data.person.id || "",
|
|
7725
|
+
name: data.person.name || "",
|
|
7726
|
+
birth_date: data.person.birth_date || ""
|
|
7727
|
+
} : void 0,
|
|
7728
|
+
confidence_score: data.confidence_score,
|
|
7729
|
+
recognition_id: data.recognition_id ?? data.history_id
|
|
7730
|
+
});
|
|
7731
|
+
} catch {
|
|
7732
|
+
reject(new NeoFaceError("Erro ao processar resposta de login", ErrorType.API_ERROR));
|
|
7733
|
+
}
|
|
7734
|
+
});
|
|
7735
|
+
eventSource.addEventListener("failed", (event) => {
|
|
7736
|
+
cleanup();
|
|
7737
|
+
try {
|
|
7738
|
+
const data = JSON.parse(event.data);
|
|
7739
|
+
reject(new NeoFaceError(data.message || "Login failed", ErrorType.LOGIN_FAILED));
|
|
7740
|
+
} catch {
|
|
7741
|
+
reject(new NeoFaceError("Login failed", ErrorType.LOGIN_FAILED));
|
|
7742
|
+
}
|
|
7743
|
+
});
|
|
7744
|
+
eventSource.addEventListener("error", (event) => {
|
|
7745
|
+
cleanup();
|
|
7746
|
+
try {
|
|
7747
|
+
const data = JSON.parse(event.data || "{}");
|
|
7748
|
+
reject(new NeoFaceError(data.message || "Processing error", ErrorType.API_ERROR));
|
|
7749
|
+
} catch {
|
|
7750
|
+
reject(new NeoFaceError("Processing error", ErrorType.API_ERROR));
|
|
7751
|
+
}
|
|
7752
|
+
});
|
|
7753
|
+
eventSource.addEventListener("timeout", () => {
|
|
7754
|
+
cleanup();
|
|
7755
|
+
reject(new NeoFaceError("Login timeout", ErrorType.NETWORK));
|
|
7756
|
+
});
|
|
7757
|
+
eventSource.onerror = () => {
|
|
7758
|
+
cleanup();
|
|
7759
|
+
reject(new NeoFaceError("SSE connection error", ErrorType.NETWORK));
|
|
7760
|
+
};
|
|
7761
|
+
});
|
|
7762
|
+
};
|
|
5202
7763
|
const recognizeBiometric = async (image, applicationToken, livenessCheck = true, confidenceThreshold = 0.8) => {
|
|
5203
7764
|
ensureSecureContext();
|
|
5204
7765
|
const controller = createTimeoutController();
|
|
@@ -5480,7 +8041,7 @@ const checkUserExistence = async (params) => {
|
|
|
5480
8041
|
}
|
|
5481
8042
|
};
|
|
5482
8043
|
const registerPersonWithBiometric = async (personData, facePhotos, applicationToken, options) => {
|
|
5483
|
-
var _a2, _b, _c, _d,
|
|
8044
|
+
var _a2, _b, _c, _d, _e2, _f, _g, _h;
|
|
5484
8045
|
ensureSecureContext();
|
|
5485
8046
|
if (!facePhotos || facePhotos.length === 0) {
|
|
5486
8047
|
throw new NeoFaceError(
|
|
@@ -5615,7 +8176,7 @@ const registerPersonWithBiometric = async (personData, facePhotos, applicationTo
|
|
|
5615
8176
|
person_id: ((_b = data.data) == null ? void 0 : _b.person_id) || data.person_id,
|
|
5616
8177
|
user_id: ((_c = data.data) == null ? void 0 : _c.user_id) || data.user_id,
|
|
5617
8178
|
person_validated: ((_d = data.data) == null ? void 0 : _d.person_validated) || data.person_validated,
|
|
5618
|
-
face_processing: ((
|
|
8179
|
+
face_processing: ((_e2 = data.data) == null ? void 0 : _e2.face_processing) || data.face_processing,
|
|
5619
8180
|
onboarding_link: ((_f = data.data) == null ? void 0 : _f.onboarding_link) || data.onboarding_link,
|
|
5620
8181
|
task_id: (_g = data.data) == null ? void 0 : _g.task_id,
|
|
5621
8182
|
status: (_h = data.data) == null ? void 0 : _h.status
|
|
@@ -6096,7 +8657,7 @@ const recordFaceVideo = async (options = {}) => {
|
|
|
6096
8657
|
});
|
|
6097
8658
|
};
|
|
6098
8659
|
const pollTaskStatus = async (taskId, applicationToken, options = {}) => {
|
|
6099
|
-
var _a2, _b, _c, _d,
|
|
8660
|
+
var _a2, _b, _c, _d, _e2, _f, _g, _h, _i, _j;
|
|
6100
8661
|
const { maxAttempts = 60, intervalMs = 1e3, onStatusChange } = options;
|
|
6101
8662
|
const wait2 = (ms = intervalMs) => new Promise((resolve) => {
|
|
6102
8663
|
setTimeout(resolve, ms);
|
|
@@ -6158,7 +8719,7 @@ const pollTaskStatus = async (taskId, applicationToken, options = {}) => {
|
|
|
6158
8719
|
return data.data.result;
|
|
6159
8720
|
}
|
|
6160
8721
|
if (status === "failure") {
|
|
6161
|
-
const errorMessage = ((
|
|
8722
|
+
const errorMessage = ((_e2 = (_d = data.data) == null ? void 0 : _d.result) == null ? void 0 : _e2.message) || ((_f = data.data) == null ? void 0 : _f.error) || "Task failed";
|
|
6162
8723
|
throw new NeoFaceError(errorMessage, ErrorType.RECOGNITION_FAILED);
|
|
6163
8724
|
}
|
|
6164
8725
|
if (status === "revoked") {
|
|
@@ -6309,7 +8870,7 @@ const registerDocumentByImage$1 = async (personId, jwtToken, images) => {
|
|
|
6309
8870
|
};
|
|
6310
8871
|
const getTaskStatus = async (taskId, applicationToken) => {
|
|
6311
8872
|
const controller = createTimeoutController();
|
|
6312
|
-
{
|
|
8873
|
+
if (!applicationToken) {
|
|
6313
8874
|
console.warn(
|
|
6314
8875
|
"[NeoFaceID SDK] getTaskStatus sem applicationToken — /tasks/status/ vai responder 401."
|
|
6315
8876
|
);
|
|
@@ -6412,6 +8973,8 @@ async function confirmPasswordReset(token, new_password) {
|
|
|
6412
8973
|
}
|
|
6413
8974
|
const api = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
6414
8975
|
__proto__: null,
|
|
8976
|
+
BiometricLoginResultSchema,
|
|
8977
|
+
RegistrationResultSchema,
|
|
6415
8978
|
checkUserExistence,
|
|
6416
8979
|
completeOnboarding,
|
|
6417
8980
|
completeOnboardingWithData,
|
|
@@ -6421,6 +8984,7 @@ const api = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty(
|
|
|
6421
8984
|
identifyPerson,
|
|
6422
8985
|
identifyPersonAsync,
|
|
6423
8986
|
loginWithBiometric,
|
|
8987
|
+
loginWithBiometricSSE,
|
|
6424
8988
|
loginWithEmail,
|
|
6425
8989
|
pollTaskStatus,
|
|
6426
8990
|
recognize,
|
|
@@ -6471,12 +9035,12 @@ function measureFrameBrightness(video, options = {}) {
|
|
|
6471
9035
|
}
|
|
6472
9036
|
}
|
|
6473
9037
|
function centerRoi(vw, vh, fraction) {
|
|
6474
|
-
const
|
|
9038
|
+
const w2 = Math.round(vw * fraction);
|
|
6475
9039
|
const h = Math.round(vh * fraction);
|
|
6476
9040
|
return {
|
|
6477
|
-
x: Math.round((vw -
|
|
9041
|
+
x: Math.round((vw - w2) / 2),
|
|
6478
9042
|
y: Math.round((vh - h) / 2),
|
|
6479
|
-
width:
|
|
9043
|
+
width: w2,
|
|
6480
9044
|
height: h
|
|
6481
9045
|
};
|
|
6482
9046
|
}
|
|
@@ -6484,16 +9048,16 @@ function computeLumaMean(rgba) {
|
|
|
6484
9048
|
const len = rgba.length;
|
|
6485
9049
|
if (len === 0) return 0;
|
|
6486
9050
|
let sum = 0;
|
|
6487
|
-
let
|
|
9051
|
+
let n2 = 0;
|
|
6488
9052
|
for (let i = 0; i < len; i += 4) {
|
|
6489
9053
|
const r = rgba[i];
|
|
6490
9054
|
const g = rgba[i + 1];
|
|
6491
9055
|
const b = rgba[i + 2];
|
|
6492
9056
|
sum += 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
6493
|
-
|
|
9057
|
+
n2 += 1;
|
|
6494
9058
|
}
|
|
6495
|
-
if (
|
|
6496
|
-
return sum / (
|
|
9059
|
+
if (n2 === 0) return 0;
|
|
9060
|
+
return sum / (n2 * 255);
|
|
6497
9061
|
}
|
|
6498
9062
|
const DARK_THRESHOLD$1 = 0.235;
|
|
6499
9063
|
const IMPROVEMENT_TARGET$1 = 0.12;
|
|
@@ -6859,9 +9423,9 @@ function FaceCaptureModal({
|
|
|
6859
9423
|
const detectFaces = async () => {
|
|
6860
9424
|
if (!videoRef.current || state.status !== "ready") return;
|
|
6861
9425
|
try {
|
|
6862
|
-
const detections = await
|
|
9426
|
+
const detections = await cr(
|
|
6863
9427
|
videoRef.current,
|
|
6864
|
-
new
|
|
9428
|
+
new Ae()
|
|
6865
9429
|
);
|
|
6866
9430
|
const isOneFace = detections.length === 1;
|
|
6867
9431
|
const isCentered = isOneFace && isFaceCentered(detections[0]);
|
|
@@ -6889,8 +9453,8 @@ function FaceCaptureModal({
|
|
|
6889
9453
|
const loadModels = async () => {
|
|
6890
9454
|
try {
|
|
6891
9455
|
await Promise.all([
|
|
6892
|
-
|
|
6893
|
-
|
|
9456
|
+
P.tinyFaceDetector.loadFromUri("/models"),
|
|
9457
|
+
P.faceLandmark68Net.loadFromUri("/models")
|
|
6894
9458
|
]);
|
|
6895
9459
|
} catch (error) {
|
|
6896
9460
|
console.error("Failed to load face-api.js models:", error);
|
|
@@ -7486,8 +10050,8 @@ const livenessInstructions = {
|
|
|
7486
10050
|
const generateRandomStepSequence = () => {
|
|
7487
10051
|
const middleSteps = ["up", "down", "left", "right"];
|
|
7488
10052
|
for (let i = middleSteps.length - 1; i > 0; i--) {
|
|
7489
|
-
const
|
|
7490
|
-
[middleSteps[i], middleSteps[
|
|
10053
|
+
const j2 = Math.floor(Math.random() * (i + 1));
|
|
10054
|
+
[middleSteps[i], middleSteps[j2]] = [middleSteps[j2], middleSteps[i]];
|
|
7491
10055
|
}
|
|
7492
10056
|
return ["center", ...middleSteps, "complete"];
|
|
7493
10057
|
};
|
|
@@ -7698,12 +10262,12 @@ function BiometricRegistrationModal({
|
|
|
7698
10262
|
try {
|
|
7699
10263
|
const MODEL_URL = "/models";
|
|
7700
10264
|
const timeout = new Promise(
|
|
7701
|
-
(
|
|
10265
|
+
(_2, reject) => setTimeout(() => reject(new Error("Timeout ao carregar modelos")), 1e4)
|
|
7702
10266
|
);
|
|
7703
10267
|
await Promise.race([
|
|
7704
10268
|
Promise.all([
|
|
7705
|
-
|
|
7706
|
-
|
|
10269
|
+
P.tinyFaceDetector.loadFromUri(MODEL_URL),
|
|
10270
|
+
P.faceLandmark68Net.loadFromUri(MODEL_URL)
|
|
7707
10271
|
]),
|
|
7708
10272
|
timeout
|
|
7709
10273
|
]);
|
|
@@ -7851,9 +10415,9 @@ function BiometricRegistrationModal({
|
|
|
7851
10415
|
}
|
|
7852
10416
|
lastDetectionTime = now;
|
|
7853
10417
|
try {
|
|
7854
|
-
const detection = await
|
|
10418
|
+
const detection = await qh(
|
|
7855
10419
|
videoRef.current,
|
|
7856
|
-
new
|
|
10420
|
+
new Ae({
|
|
7857
10421
|
inputSize: 224,
|
|
7858
10422
|
// Aumentado para detectar rostos menores/mais distantes
|
|
7859
10423
|
scoreThreshold: 0.35
|
|
@@ -8919,7 +11483,7 @@ function BiometricRegistrationModal({
|
|
|
8919
11483
|
/* @__PURE__ */ jsx("canvas", { ref: canvasRef })
|
|
8920
11484
|
] });
|
|
8921
11485
|
}
|
|
8922
|
-
const VERSION = "2.1.
|
|
11486
|
+
const VERSION = "2.1.2";
|
|
8923
11487
|
const RELEASE_DATE = "2026-09-23";
|
|
8924
11488
|
const CONSENT_TRAIL_STORAGE_KEY = "neoface_consent_trail_v1";
|
|
8925
11489
|
const CONSENT_TRAIL_MAX_LIMIT = 100;
|
|
@@ -9009,7 +11573,7 @@ const COPY = {
|
|
|
9009
11573
|
primary: "Começar cadastro"
|
|
9010
11574
|
}
|
|
9011
11575
|
};
|
|
9012
|
-
const plural = (
|
|
11576
|
+
const plural = (n2) => n2 === 1 ? "dia" : "dias";
|
|
9013
11577
|
function terceiroMarcador(flow, retentionDays) {
|
|
9014
11578
|
const prazoDeclarado = Number.isFinite(retentionDays) && retentionDays > 0;
|
|
9015
11579
|
if (flow === "registration") {
|
|
@@ -10082,17 +12646,17 @@ function QrCode({ value }) {
|
|
|
10082
12646
|
const [path, setPath] = useState(null);
|
|
10083
12647
|
useEffect(() => {
|
|
10084
12648
|
let cancelled = false;
|
|
10085
|
-
import("./qrcode-
|
|
12649
|
+
import("./qrcode-DZJ8v41k.js").then((mod) => {
|
|
10086
12650
|
if (cancelled) return;
|
|
10087
12651
|
const qrcode = mod.default ?? mod;
|
|
10088
|
-
const
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
const count =
|
|
12652
|
+
const qr2 = qrcode(0, "M");
|
|
12653
|
+
qr2.addData(value);
|
|
12654
|
+
qr2.make();
|
|
12655
|
+
const count = qr2.getModuleCount();
|
|
10092
12656
|
const parts = [];
|
|
10093
12657
|
for (let r = 0; r < count; r += 1) {
|
|
10094
12658
|
for (let c = 0; c < count; c += 1) {
|
|
10095
|
-
if (
|
|
12659
|
+
if (qr2.isDark(r, c)) parts.push(`M${c} ${r}h1v1h-1z`);
|
|
10096
12660
|
}
|
|
10097
12661
|
}
|
|
10098
12662
|
setPath({ d: parts.join(""), count });
|
|
@@ -11552,7 +14116,7 @@ async function preloadFaceDetectionModels() {
|
|
|
11552
14116
|
modelsLoading = (async () => {
|
|
11553
14117
|
try {
|
|
11554
14118
|
const MODEL_URL = "/models";
|
|
11555
|
-
await
|
|
14119
|
+
await P.tinyFaceDetector.loadFromUri(MODEL_URL);
|
|
11556
14120
|
modelsLoaded = true;
|
|
11557
14121
|
console.log("✅ Face detection models preloaded");
|
|
11558
14122
|
} catch (error) {
|
|
@@ -11630,9 +14194,9 @@ async function captureFaceSilently() {
|
|
|
11630
14194
|
const detectFace = async () => {
|
|
11631
14195
|
if (!modelsLoaded) return true;
|
|
11632
14196
|
try {
|
|
11633
|
-
const detection = await
|
|
14197
|
+
const detection = await qh(
|
|
11634
14198
|
video,
|
|
11635
|
-
new
|
|
14199
|
+
new Ae({ inputSize: 160, scoreThreshold: 0.3 })
|
|
11636
14200
|
);
|
|
11637
14201
|
return !!detection;
|
|
11638
14202
|
} catch {
|
|
@@ -11726,9 +14290,9 @@ async function detectFaceWithPosition(video, stream, guideModal, maxTime = FACE_
|
|
|
11726
14290
|
return;
|
|
11727
14291
|
}
|
|
11728
14292
|
try {
|
|
11729
|
-
const detection = await
|
|
14293
|
+
const detection = await qh(
|
|
11730
14294
|
video,
|
|
11731
|
-
new
|
|
14295
|
+
new Ae({ inputSize: 160, scoreThreshold: 0.3 })
|
|
11732
14296
|
);
|
|
11733
14297
|
const { faceState, instruction } = evaluateFacePosition(
|
|
11734
14298
|
detection ? detection.box : null,
|
|
@@ -12264,7 +14828,7 @@ class BiometricCaptureModal {
|
|
|
12264
14828
|
*/
|
|
12265
14829
|
async detectBiometricType(imageData) {
|
|
12266
14830
|
try {
|
|
12267
|
-
const { detectBiometricType } = await import("./biometricDetection-
|
|
14831
|
+
const { detectBiometricType } = await import("./biometricDetection-CR31mETT.js");
|
|
12268
14832
|
const result = await detectBiometricType(imageData);
|
|
12269
14833
|
if (result.type !== "unknown" && result.confidence > 0.6) {
|
|
12270
14834
|
return result.type;
|