@hackbuild/vision 0.1.1 → 0.1.3
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 +258 -171
- package/dist/api.d.ts +5 -1
- package/dist/api.js +4 -1
- package/dist/faceapi.d.ts +1 -0
- package/dist/faceapi.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/loaders.d.ts +3 -1
- package/dist/loaders.js +3 -1
- package/dist/loop.d.ts +11 -8
- package/dist/loop.js +8 -7
- package/dist/masks.d.ts +9 -4
- package/dist/masks.js +9 -4
- package/dist/mediapipe.d.ts +7 -1
- package/dist/mediapipe.js +6 -1
- package/dist/records.d.ts +9 -3
- package/dist/records.js +241 -11
- package/dist/segment.d.ts +3 -2
- package/dist/segment.js +2 -2
- package/dist/signals.d.ts +8 -2
- package/dist/signals.js +3 -2
- package/dist/single/index.iife.js +336 -29
- package/dist/single/index.js +336 -30
- package/dist/stubs.d.ts +4 -0
- package/dist/stubs.js +4 -0
- package/dist/types.d.ts +13 -1
- package/dist/worker.d.ts +3 -0
- package/dist/yolo.d.ts +5 -1
- package/dist/yolo.js +4 -1
- package/llms.md +982 -0
- package/package.json +6 -5
package/dist/single/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// packages/models/src/record.ts
|
|
2
|
-
/** The onnxruntime-web ladder
|
|
2
|
+
/** The onnxruntime-web ladder to walk after one fetch: webgpu at basic, all, disabled, then wasm. */
|
|
3
3
|
function ortLadder() {
|
|
4
4
|
return [
|
|
5
5
|
{
|
|
@@ -33,6 +33,7 @@ function ortLadder() {
|
|
|
33
33
|
];
|
|
34
34
|
}
|
|
35
35
|
// packages/models/src/pins.ts
|
|
36
|
+
/** Pinned commits and file hashes per Hugging Face repo, written by tools/pin-weights.mjs. */
|
|
36
37
|
const PINS = {
|
|
37
38
|
"HuggingFaceTB/SmolLM2-135M-Instruct": {
|
|
38
39
|
"revision": "12fd25f77366fa6b3b4b768ec3050bf629380bac",
|
|
@@ -2881,6 +2882,7 @@ const PINS = {
|
|
|
2881
2882
|
* added to a registry, so every loader resolves `resolve/<commit>/` URLs,
|
|
2882
2883
|
* and pinnedSha gives the SHA-256 for such a URL.
|
|
2883
2884
|
*/
|
|
2885
|
+
/** The pin of a repo, or undefined when the repo is not pinned. */
|
|
2884
2886
|
function pinOf(repo) {
|
|
2885
2887
|
return repo && Object.hasOwn(PINS, repo) ? PINS[repo] : void 0;
|
|
2886
2888
|
}
|
|
@@ -2919,25 +2921,25 @@ function tjsLadder(spec) {
|
|
|
2919
2921
|
}
|
|
2920
2922
|
return spec.wasmFirst ? [...cpu, ...gpu] : [...gpu, ...cpu];
|
|
2921
2923
|
}
|
|
2922
|
-
/** onnxruntime-web rungs:
|
|
2924
|
+
/** onnxruntime-web rungs: webgpu then wasm, or wasm only when the graph is known to fail on webgpu. */
|
|
2923
2925
|
function ortRungs(opts = {}) {
|
|
2924
2926
|
const all = ortLadder();
|
|
2925
2927
|
return opts.webgpu === false ? all.filter((r) => r.device === "wasm") : all;
|
|
2926
2928
|
}
|
|
2927
|
-
/** Ladders by name,
|
|
2929
|
+
/** Ladders by name, one per model family. Each model record may copy one or write its own. */
|
|
2928
2930
|
const LADDERS = {
|
|
2929
|
-
/**
|
|
2931
|
+
/** Depth: fp16 then fp32 on webgpu, q8 then fp32 on wasm. */
|
|
2930
2932
|
depth: () => tjsLadder({
|
|
2931
2933
|
webgpu: ["fp16", "fp32"],
|
|
2932
2934
|
wasm: ["q8", "fp32"]
|
|
2933
2935
|
}),
|
|
2934
|
-
/**
|
|
2936
|
+
/** Perception models on cpu by default. */
|
|
2935
2937
|
perceptionCpu: () => tjsLadder({
|
|
2936
2938
|
webgpu: ["fp32"],
|
|
2937
2939
|
wasm: ["q8", "fp32"],
|
|
2938
2940
|
wasmFirst: true
|
|
2939
2941
|
}),
|
|
2940
|
-
/** whisper-large-v3-turbo (weights MIT)
|
|
2942
|
+
/** whisper-large-v3-turbo (weights MIT). */
|
|
2941
2943
|
whisperTurbo: () => tjsLadder({
|
|
2942
2944
|
webgpu: [{
|
|
2943
2945
|
encoder_model: "fp16",
|
|
@@ -2962,7 +2964,7 @@ const LADDERS = {
|
|
|
2962
2964
|
decoder_model_merged: "q8"
|
|
2963
2965
|
}]
|
|
2964
2966
|
}),
|
|
2965
|
-
/** SmolVLM (weights Apache-2.0): fp16 embed and vision, q4 decoder on webgpu; q8 vision on wasm
|
|
2967
|
+
/** SmolVLM (weights Apache-2.0): fp16 embed and vision, q4 decoder on webgpu; q8 vision on wasm. */
|
|
2966
2968
|
smolvlm: () => tjsLadder({
|
|
2967
2969
|
webgpu: [{
|
|
2968
2970
|
embed_tokens: "fp32",
|
|
@@ -2980,11 +2982,12 @@ const LADDERS = {
|
|
|
2980
2982
|
}],
|
|
2981
2983
|
freshHeapRetry: true
|
|
2982
2984
|
}),
|
|
2983
|
-
/**
|
|
2985
|
+
/** q4f16 on webgpu only. */
|
|
2984
2986
|
vlmGpuOnly: () => tjsLadder({ webgpu: ["q4f16", "q4"] }),
|
|
2985
2987
|
ort: ortRungs
|
|
2986
2988
|
};
|
|
2987
2989
|
// packages/ai-env/src/source.ts
|
|
2990
|
+
/** Applies string or RegExp rewrites to source text and reports each one that matched nothing. */
|
|
2988
2991
|
function rewriteSource(src, rewrites) {
|
|
2989
2992
|
let text = src;
|
|
2990
2993
|
const missed = [];
|
|
@@ -3014,7 +3017,7 @@ function rewriteSource(src, rewrites) {
|
|
|
3014
3017
|
const MODULE_WORKER = /new\s+Worker\(\s*([^,()]+(?:\([^()]*\))?[^,()]*)\s*,\s*\{([^{}]*)\}\s*\)/g;
|
|
3015
3018
|
/**
|
|
3016
3019
|
* Turn module workers into classic workers: Chrome refuses module workers
|
|
3017
|
-
* from a file:// page
|
|
3020
|
+
* from a file:// page. Other option keys
|
|
3018
3021
|
* are kept. Returns the text and how many constructors changed.
|
|
3019
3022
|
*/
|
|
3020
3023
|
function toClassicWorker(src) {
|
|
@@ -3059,6 +3062,7 @@ function bytesToBase64(bytes) {
|
|
|
3059
3062
|
}
|
|
3060
3063
|
return parts.join("");
|
|
3061
3064
|
}
|
|
3065
|
+
/** Encodes text as a base64 data: URL, JavaScript by default. */
|
|
3062
3066
|
function textToDataUrl(text, mime = "text/javascript") {
|
|
3063
3067
|
return `data:${mime};base64,${bytesToBase64(new TextEncoder().encode(text))}`;
|
|
3064
3068
|
}
|
|
@@ -3068,7 +3072,7 @@ function textToDataUrl(text, mime = "text/javascript") {
|
|
|
3068
3072
|
*
|
|
3069
3073
|
* importEsm: plain import() first when nothing needs patching and the page
|
|
3070
3074
|
* is served over http(s); else fetch the text, patch it, import it from a
|
|
3071
|
-
* Blob URL, then from a base64 data: URL
|
|
3075
|
+
* Blob URL, then from a base64 data: URL. Each URL in
|
|
3072
3076
|
* `urls` is tried in order, so a CDN fallback list is one call.
|
|
3073
3077
|
*
|
|
3074
3078
|
* spawnWorker: the worker ladder, written once. Rungs are module-blob,
|
|
@@ -3087,6 +3091,10 @@ async function sha256Text(text) {
|
|
|
3087
3091
|
const d = new Uint8Array(await subtle.digest("SHA-256", new TextEncoder().encode(text)));
|
|
3088
3092
|
return Array.from(d, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
3089
3093
|
}
|
|
3094
|
+
/**
|
|
3095
|
+
* The error importEsm and spawnWorker throw when every URL or rung failed, with one entry per
|
|
3096
|
+
* attempt in `attempts`.
|
|
3097
|
+
*/
|
|
3090
3098
|
var LoadError = class extends Error {
|
|
3091
3099
|
attempts;
|
|
3092
3100
|
constructor(message, attempts) {
|
|
@@ -3102,6 +3110,10 @@ const nativeImport = (s) => import(
|
|
|
3102
3110
|
function errText(e) {
|
|
3103
3111
|
return e instanceof Error ? `${e.name}: ${e.message}` : String(e);
|
|
3104
3112
|
}
|
|
3113
|
+
/**
|
|
3114
|
+
* Imports an ES module from the first URL that loads, through plain import, then a patched Blob
|
|
3115
|
+
* URL, then a base64 data: URL, checking a SHA-256 when you give one.
|
|
3116
|
+
*/
|
|
3105
3117
|
async function importEsm(urls, opts = {}) {
|
|
3106
3118
|
const list = typeof urls === "string" ? [urls] : urls;
|
|
3107
3119
|
const importer = opts.importer ?? nativeImport;
|
|
@@ -3390,17 +3402,23 @@ async function spawnWorker(source, opts = {}) {
|
|
|
3390
3402
|
// packages/vision/src/records.ts
|
|
3391
3403
|
/**
|
|
3392
3404
|
* Vision records for the models hub. Licences are the model cards' as of
|
|
3393
|
-
* 2026-11-22; sizes are inferred from the builds and parameter counts
|
|
3405
|
+
* 2026-11-22; sizes are inferred from the builds and parameter counts, except where
|
|
3406
|
+
* a row says vendor: those sum the hub listing's files (no download), in MiB.
|
|
3394
3407
|
* YOLO weights are AGPL-3.0 (Ultralytics): they are never registered by
|
|
3395
|
-
* default,
|
|
3396
|
-
* supplies
|
|
3408
|
+
* default. YOLOv8n has no public hub repo, so `yoloRecord` builds a record
|
|
3409
|
+
* only for a URL the app supplies; YOLOv10 n, s and m, FastSAM and the face
|
|
3410
|
+
* swap set sit in PICKER_RECORDS.
|
|
3397
3411
|
*/
|
|
3412
|
+
/** The MediaPipe model storage base URL the MediaPipe records load from. */
|
|
3398
3413
|
const MP_MODELS = "https://storage.googleapis.com/mediapipe-models/";
|
|
3399
3414
|
/** MediaPipe ladder: GPU delegate (webgl), then the CPU delegate (wasm). */
|
|
3400
3415
|
const mediapipeLadder = () => [{ device: "webgl" }, { device: "wasm" }];
|
|
3401
|
-
const mp = (id, provides, path, sizeMB, label) => ({
|
|
3416
|
+
const mp = (id, provides, path, sizeMB, label, verdict = "light, on the gpu", group = "start here") => ({
|
|
3402
3417
|
id,
|
|
3403
3418
|
label,
|
|
3419
|
+
group,
|
|
3420
|
+
speed: "instant",
|
|
3421
|
+
verdict,
|
|
3404
3422
|
provides: [provides],
|
|
3405
3423
|
provider: "mediapipe",
|
|
3406
3424
|
source: { url: MP_MODELS + path },
|
|
@@ -3412,10 +3430,14 @@ const mp = (id, provides, path, sizeMB, label) => ({
|
|
|
3412
3430
|
place: "main",
|
|
3413
3431
|
runtime: "@mediapipe/tasks-vision@1.2.3"
|
|
3414
3432
|
});
|
|
3433
|
+
/** The vision records registered by `attachVision`: Depth Anything V2 small, MediaPipe detection, segmentation and landmarks, SlimSAM, SmolVLM 256M and LFM2-VL 450M. */
|
|
3415
3434
|
const VISION_RECORDS = [
|
|
3416
3435
|
{
|
|
3417
3436
|
id: "depth-anything-v2-small",
|
|
3418
3437
|
label: "depth anything v2 small",
|
|
3438
|
+
speed: "fast",
|
|
3439
|
+
verdict: "good edges",
|
|
3440
|
+
group: "start here",
|
|
3419
3441
|
provides: ["depth"],
|
|
3420
3442
|
provider: "tjs",
|
|
3421
3443
|
source: { modelId: "onnx-community/depth-anything-v2-small" },
|
|
@@ -3426,9 +3448,9 @@ const VISION_RECORDS = [
|
|
|
3426
3448
|
commercial: true,
|
|
3427
3449
|
place: "cpu-worker",
|
|
3428
3450
|
runtime: "@huggingface/transformers@4.3.2",
|
|
3429
|
-
notes: ["
|
|
3451
|
+
notes: ["fp16 on webgpu, fp32 on the same device after a failure"]
|
|
3430
3452
|
},
|
|
3431
|
-
mp("efficientdet-lite0", "detect", "object_detector/efficientdet_lite0/float16/1/efficientdet_lite0.tflite", 7, "mediapipe efficientdet lite0 (coco, 80 classes)"),
|
|
3453
|
+
mp("efficientdet-lite0", "detect", "object_detector/efficientdet_lite0/float16/1/efficientdet_lite0.tflite", 7, "mediapipe efficientdet lite0 (coco, 80 classes)", "light, 80 things"),
|
|
3432
3454
|
mp("selfie-segmenter", "segment.person", "image_segmenter/selfie_segmenter/float16/latest/selfie_segmenter.tflite", 1, "mediapipe selfie segmenter"),
|
|
3433
3455
|
mp("face-landmarker", "landmarks.face", "face_landmarker/face_landmarker/float16/1/face_landmarker.task", 4, "mediapipe face landmarker with blendshapes"),
|
|
3434
3456
|
mp("hand-landmarker", "landmarks.hand", "hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task", 8, "mediapipe hand landmarker"),
|
|
@@ -3442,11 +3464,14 @@ const VISION_RECORDS = [
|
|
|
3442
3464
|
{
|
|
3443
3465
|
id: "slimsam-77-uniform",
|
|
3444
3466
|
label: "slimsam 77 uniform (point prompts)",
|
|
3467
|
+
speed: "fast",
|
|
3468
|
+
verdict: "click to cut",
|
|
3469
|
+
group: "start here",
|
|
3445
3470
|
provides: ["segment"],
|
|
3446
3471
|
provider: "tjs",
|
|
3447
3472
|
source: { modelId: "Xenova/slimsam-77-uniform" },
|
|
3448
|
-
sizeMB:
|
|
3449
|
-
sizeSource: "
|
|
3473
|
+
sizeMB: 38,
|
|
3474
|
+
sizeSource: "vendor",
|
|
3450
3475
|
ladder: tjsLadder({
|
|
3451
3476
|
webgpu: ["fp16", "fp32"],
|
|
3452
3477
|
wasm: ["fp32"]
|
|
@@ -3455,11 +3480,14 @@ const VISION_RECORDS = [
|
|
|
3455
3480
|
commercial: true,
|
|
3456
3481
|
place: "cpu-worker",
|
|
3457
3482
|
runtime: "@huggingface/transformers@4.3.2",
|
|
3458
|
-
notes: ["
|
|
3483
|
+
notes: ["one image embedding, then any number of point prompts"]
|
|
3459
3484
|
},
|
|
3460
3485
|
{
|
|
3461
3486
|
id: "smolvlm-256m-instruct",
|
|
3462
3487
|
label: "smolvlm 256m",
|
|
3488
|
+
speed: "fast",
|
|
3489
|
+
verdict: "fastest, short answers",
|
|
3490
|
+
group: "start here",
|
|
3463
3491
|
provides: ["vision.caption", "vision.ask"],
|
|
3464
3492
|
provider: "tjs",
|
|
3465
3493
|
source: { modelId: "HuggingFaceTB/SmolVLM-256M-Instruct" },
|
|
@@ -3478,6 +3506,9 @@ const VISION_RECORDS = [
|
|
|
3478
3506
|
{
|
|
3479
3507
|
id: "lfm2-vl-450m",
|
|
3480
3508
|
label: "lfm2-vl 450m",
|
|
3509
|
+
speed: "fast",
|
|
3510
|
+
verdict: "faster, sharper",
|
|
3511
|
+
group: "tiny",
|
|
3481
3512
|
provides: ["vision.caption", "vision.ask"],
|
|
3482
3513
|
provider: "tjs",
|
|
3483
3514
|
source: { modelId: "onnx-community/LFM2-VL-450M-ONNX" },
|
|
@@ -3492,7 +3523,250 @@ const VISION_RECORDS = [
|
|
|
3492
3523
|
commercial: "unknown",
|
|
3493
3524
|
place: "gpu",
|
|
3494
3525
|
runtime: "@huggingface/transformers@4.3.2",
|
|
3495
|
-
notes: ["
|
|
3526
|
+
notes: ["q4f16 on webgpu only; the licence limits commercial use by revenue, read it before shipping"]
|
|
3527
|
+
}
|
|
3528
|
+
];
|
|
3529
|
+
/**
|
|
3530
|
+
* Records listed for pickers and never registered by default, so a hub's
|
|
3531
|
+
* routing by capability keeps its small defaults: larger alternates (smolvlm 500m and 2 video, gemma 4 e2b, two more
|
|
3532
|
+
* depth models), and records under licences that limit use (YOLOv10 and
|
|
3533
|
+
* FastSAM are AGPL-3.0 upstream, Ultralytics; the face swap set is
|
|
3534
|
+
* InsightFace, non-commercial). A hub that runs one adds it itself. Sizes
|
|
3535
|
+
* are the hub listings' files (vendor, 2026-11-25), in MiB.
|
|
3536
|
+
*/
|
|
3537
|
+
const yolo10 = (size, mb, speed, verdict) => ({
|
|
3538
|
+
id: `yolov10${size}`,
|
|
3539
|
+
label: `yolov10 ${{
|
|
3540
|
+
n: "nano",
|
|
3541
|
+
s: "small",
|
|
3542
|
+
m: "medium"
|
|
3543
|
+
}[size]}`,
|
|
3544
|
+
group: size === "n" ? "tiny" : "good",
|
|
3545
|
+
speed,
|
|
3546
|
+
verdict,
|
|
3547
|
+
provides: ["detect"],
|
|
3548
|
+
provider: "ort",
|
|
3549
|
+
source: {
|
|
3550
|
+
repo: `onnx-community/yolov10${size}`,
|
|
3551
|
+
file: "onnx/model.onnx"
|
|
3552
|
+
},
|
|
3553
|
+
sizeMB: mb,
|
|
3554
|
+
sizeSource: "vendor",
|
|
3555
|
+
ladder: [{
|
|
3556
|
+
device: "webgpu",
|
|
3557
|
+
ort: { executionProviders: ["webgpu", "wasm"] }
|
|
3558
|
+
}, {
|
|
3559
|
+
device: "wasm",
|
|
3560
|
+
ort: { executionProviders: ["wasm"] }
|
|
3561
|
+
}],
|
|
3562
|
+
licence: "AGPL-3.0 (Ultralytics weights, the model card's licence field)",
|
|
3563
|
+
commercial: false,
|
|
3564
|
+
place: "gpu",
|
|
3565
|
+
notes: ["output [1, 300, 6] after the model's own selection, so no nms pass (vendor, the yolov10 paper)", "comes in nano, small and medium"]
|
|
3566
|
+
});
|
|
3567
|
+
/** Records listed for pickers and never registered by default: larger alternates, and records under licences that limit use (YOLOv10, FastSAM, the face swap set). */
|
|
3568
|
+
const PICKER_RECORDS = [
|
|
3569
|
+
{
|
|
3570
|
+
id: "smolvlm-500m-instruct",
|
|
3571
|
+
label: "smolvlm 500m",
|
|
3572
|
+
speed: "steady",
|
|
3573
|
+
verdict: "better captions, slower",
|
|
3574
|
+
group: "good",
|
|
3575
|
+
provides: ["vision.caption", "vision.ask"],
|
|
3576
|
+
provider: "tjs",
|
|
3577
|
+
source: { modelId: "HuggingFaceTB/SmolVLM-500M-Instruct" },
|
|
3578
|
+
sizeMB: 463,
|
|
3579
|
+
sizeSource: "vendor",
|
|
3580
|
+
ladder: LADDERS.smolvlm(),
|
|
3581
|
+
quirks: {
|
|
3582
|
+
repetitionPenalty: 1.3,
|
|
3583
|
+
maxTokensAction: 64
|
|
3584
|
+
},
|
|
3585
|
+
licence: "Apache-2.0",
|
|
3586
|
+
commercial: true,
|
|
3587
|
+
place: "cpu-worker",
|
|
3588
|
+
runtime: "@huggingface/transformers@4.3.2"
|
|
3589
|
+
},
|
|
3590
|
+
{
|
|
3591
|
+
id: "smolvlm2-256m-video-instruct",
|
|
3592
|
+
label: "smolvlm2 256m video",
|
|
3593
|
+
speed: "fast",
|
|
3594
|
+
verdict: "watches short clips",
|
|
3595
|
+
group: "tiny",
|
|
3596
|
+
provides: ["vision.caption", "vision.ask"],
|
|
3597
|
+
provider: "tjs",
|
|
3598
|
+
source: { modelId: "HuggingFaceTB/SmolVLM2-256M-Video-Instruct" },
|
|
3599
|
+
sizeMB: 252,
|
|
3600
|
+
sizeSource: "vendor",
|
|
3601
|
+
ladder: LADDERS.smolvlm(),
|
|
3602
|
+
quirks: {
|
|
3603
|
+
repetitionPenalty: 1.3,
|
|
3604
|
+
maxTokensAction: 64
|
|
3605
|
+
},
|
|
3606
|
+
licence: "Apache-2.0",
|
|
3607
|
+
commercial: true,
|
|
3608
|
+
place: "cpu-worker",
|
|
3609
|
+
runtime: "@huggingface/transformers@4.3.2",
|
|
3610
|
+
notes: ["an option beside smolvlm 256m and 500m"]
|
|
3611
|
+
},
|
|
3612
|
+
{
|
|
3613
|
+
id: "depth-anything-v2-base",
|
|
3614
|
+
label: "depth anything v2 base",
|
|
3615
|
+
speed: "steady",
|
|
3616
|
+
verdict: "finer depth, non commercial",
|
|
3617
|
+
group: "good",
|
|
3618
|
+
provides: ["depth"],
|
|
3619
|
+
provider: "tjs",
|
|
3620
|
+
source: { modelId: "onnx-community/depth-anything-v2-base" },
|
|
3621
|
+
sizeMB: 186,
|
|
3622
|
+
sizeSource: "vendor",
|
|
3623
|
+
ladder: LADDERS.depth(),
|
|
3624
|
+
licence: "CC-BY-NC-4.0 (the model card's licence field)",
|
|
3625
|
+
commercial: false,
|
|
3626
|
+
place: "cpu-worker",
|
|
3627
|
+
runtime: "@huggingface/transformers@4.3.2"
|
|
3628
|
+
},
|
|
3629
|
+
{
|
|
3630
|
+
id: "depth-anything-small-v1",
|
|
3631
|
+
label: "depth anything v1 small",
|
|
3632
|
+
speed: "fast",
|
|
3633
|
+
verdict: "the first version",
|
|
3634
|
+
group: "tiny",
|
|
3635
|
+
provides: ["depth"],
|
|
3636
|
+
provider: "tjs",
|
|
3637
|
+
source: { modelId: "Xenova/depth-anything-small-hf" },
|
|
3638
|
+
sizeMB: 48,
|
|
3639
|
+
sizeSource: "vendor",
|
|
3640
|
+
ladder: LADDERS.depth(),
|
|
3641
|
+
licence: "Apache-2.0 (the upstream card; this export's card has no licence field)",
|
|
3642
|
+
commercial: "unknown",
|
|
3643
|
+
place: "cpu-worker",
|
|
3644
|
+
runtime: "@huggingface/transformers@4.3.2"
|
|
3645
|
+
},
|
|
3646
|
+
{
|
|
3647
|
+
id: "gemma-4-e2b-vision",
|
|
3648
|
+
label: "gemma 4 e2b",
|
|
3649
|
+
speed: "slow",
|
|
3650
|
+
verdict: "sees most, heavy",
|
|
3651
|
+
group: "good",
|
|
3652
|
+
provides: ["vision.caption", "vision.ask"],
|
|
3653
|
+
provider: "tjs",
|
|
3654
|
+
source: { modelId: "onnx-community/gemma-4-E2B-it-ONNX" },
|
|
3655
|
+
sizeMB: 3566,
|
|
3656
|
+
sizeSource: "vendor",
|
|
3657
|
+
ladder: LADDERS.vlmGpuOnly(),
|
|
3658
|
+
quirks: {
|
|
3659
|
+
systemRole: false,
|
|
3660
|
+
strictAlternation: true,
|
|
3661
|
+
maxTokensAction: 96
|
|
3662
|
+
},
|
|
3663
|
+
licence: "Apache-2.0 (the model card's licence field)",
|
|
3664
|
+
commercial: true,
|
|
3665
|
+
place: "gpu",
|
|
3666
|
+
runtime: "@huggingface/transformers@4.3.2",
|
|
3667
|
+
notes: ["about 3.3 GB (vendor)"]
|
|
3668
|
+
},
|
|
3669
|
+
yolo10("n", 9, "instant", "nano, quick"),
|
|
3670
|
+
yolo10("s", 28, "fast", "small, sharper"),
|
|
3671
|
+
yolo10("m", 59, "steady", "medium, best boxes"),
|
|
3672
|
+
{
|
|
3673
|
+
id: "fastsam-s",
|
|
3674
|
+
label: "fastsam s",
|
|
3675
|
+
speed: "fast",
|
|
3676
|
+
verdict: "finds everything, cpu ok",
|
|
3677
|
+
group: "good",
|
|
3678
|
+
provides: ["segment.everything"],
|
|
3679
|
+
provider: "ort",
|
|
3680
|
+
source: {
|
|
3681
|
+
repo: "anakhiu/fastsam-onnx",
|
|
3682
|
+
file: "fastsam_s.onnx"
|
|
3683
|
+
},
|
|
3684
|
+
sizeMB: 45,
|
|
3685
|
+
sizeSource: "vendor",
|
|
3686
|
+
ladder: [{
|
|
3687
|
+
device: "webgpu",
|
|
3688
|
+
ort: { executionProviders: ["webgpu", "wasm"] }
|
|
3689
|
+
}, {
|
|
3690
|
+
device: "wasm",
|
|
3691
|
+
ort: { executionProviders: ["wasm"] }
|
|
3692
|
+
}],
|
|
3693
|
+
licence: "AGPL-3.0 upstream (Ultralytics FastSAM); the export's card says apache-2.0",
|
|
3694
|
+
commercial: false,
|
|
3695
|
+
place: "cpu-worker",
|
|
3696
|
+
notes: ["finds every mask in one pass on onnxruntime-web (93 MB, vendor)", "segment everything: prototype masks, nms, then a pick by click"]
|
|
3697
|
+
},
|
|
3698
|
+
{
|
|
3699
|
+
id: "scrfd-10g",
|
|
3700
|
+
label: "face finder (scrfd 10g)",
|
|
3701
|
+
speed: "fast",
|
|
3702
|
+
verdict: "finds faces",
|
|
3703
|
+
group: "start here",
|
|
3704
|
+
provides: ["face.detect"],
|
|
3705
|
+
provider: "ort",
|
|
3706
|
+
source: {
|
|
3707
|
+
repo: "immich-app/buffalo_l",
|
|
3708
|
+
file: "detection/model.onnx"
|
|
3709
|
+
},
|
|
3710
|
+
sizeMB: 16,
|
|
3711
|
+
sizeSource: "vendor",
|
|
3712
|
+
ladder: [{
|
|
3713
|
+
device: "wasm",
|
|
3714
|
+
ort: { executionProviders: ["wasm"] }
|
|
3715
|
+
}],
|
|
3716
|
+
licence: "InsightFace model pack: non-commercial research only (the buffalo_l pack terms)",
|
|
3717
|
+
commercial: false,
|
|
3718
|
+
place: "cpu-worker"
|
|
3719
|
+
},
|
|
3720
|
+
{
|
|
3721
|
+
id: "arcface-w600k-r50",
|
|
3722
|
+
label: "face id (arcface r50)",
|
|
3723
|
+
speed: "steady",
|
|
3724
|
+
verdict: "who is who",
|
|
3725
|
+
group: "start here",
|
|
3726
|
+
provides: ["face.embed"],
|
|
3727
|
+
provider: "ort",
|
|
3728
|
+
source: {
|
|
3729
|
+
repo: "immich-app/buffalo_l",
|
|
3730
|
+
file: "recognition/model.onnx"
|
|
3731
|
+
},
|
|
3732
|
+
sizeMB: 166,
|
|
3733
|
+
sizeSource: "vendor",
|
|
3734
|
+
ladder: [{
|
|
3735
|
+
device: "webgpu",
|
|
3736
|
+
ort: { executionProviders: ["webgpu", "wasm"] }
|
|
3737
|
+
}, {
|
|
3738
|
+
device: "wasm",
|
|
3739
|
+
ort: { executionProviders: ["wasm"] }
|
|
3740
|
+
}],
|
|
3741
|
+
licence: "InsightFace model pack: non-commercial research only (the buffalo_l pack terms)",
|
|
3742
|
+
commercial: false,
|
|
3743
|
+
place: "cpu-worker"
|
|
3744
|
+
},
|
|
3745
|
+
{
|
|
3746
|
+
id: "inswapper-128",
|
|
3747
|
+
label: "face swap (inswapper 128)",
|
|
3748
|
+
speed: "slow",
|
|
3749
|
+
verdict: "the swap itself",
|
|
3750
|
+
group: "start here",
|
|
3751
|
+
provides: ["face.swap"],
|
|
3752
|
+
provider: "ort",
|
|
3753
|
+
source: {
|
|
3754
|
+
repo: "hacksider/inswapper_128",
|
|
3755
|
+
file: "inswapper_128.onnx"
|
|
3756
|
+
},
|
|
3757
|
+
sizeMB: 529,
|
|
3758
|
+
sizeSource: "vendor",
|
|
3759
|
+
ladder: [{
|
|
3760
|
+
device: "webgpu",
|
|
3761
|
+
ort: { executionProviders: ["webgpu", "wasm"] }
|
|
3762
|
+
}, {
|
|
3763
|
+
device: "wasm",
|
|
3764
|
+
ort: { executionProviders: ["wasm"] }
|
|
3765
|
+
}],
|
|
3766
|
+
licence: "InsightFace: non-commercial research only; the mirror's card says gpl-3.0",
|
|
3767
|
+
commercial: false,
|
|
3768
|
+
place: "gpu",
|
|
3769
|
+
notes: ["128 px faces; paste the result back with a feathered mask"]
|
|
3496
3770
|
}
|
|
3497
3771
|
];
|
|
3498
3772
|
/** A face landmark fallback record over face-api.js tiny nets (code MIT; weights MIT from @vladmandic/face-api). */
|
|
@@ -3500,6 +3774,9 @@ function faceApiRecord(baseUrl) {
|
|
|
3500
3774
|
return {
|
|
3501
3775
|
id: "face-api-tiny",
|
|
3502
3776
|
label: "face-api tiny landmarks (68 points)",
|
|
3777
|
+
speed: "instant",
|
|
3778
|
+
verdict: "68 points, cpu",
|
|
3779
|
+
group: "cpu",
|
|
3503
3780
|
provides: ["landmarks.face"],
|
|
3504
3781
|
provider: "faceapi",
|
|
3505
3782
|
source: { url: baseUrl },
|
|
@@ -3516,6 +3793,9 @@ function yoloRecord(o) {
|
|
|
3516
3793
|
return {
|
|
3517
3794
|
id: o.id ?? "yolov8n",
|
|
3518
3795
|
label: "yolov8n (external)",
|
|
3796
|
+
group: "tiny",
|
|
3797
|
+
speed: "instant",
|
|
3798
|
+
verdict: "nano, your file",
|
|
3519
3799
|
provides: ["detect"],
|
|
3520
3800
|
provider: "ort",
|
|
3521
3801
|
source: {
|
|
@@ -3534,7 +3814,7 @@ function yoloRecord(o) {
|
|
|
3534
3814
|
licence: o.licence ?? "AGPL-3.0 (Ultralytics YOLOv8 weights), supplied by the app",
|
|
3535
3815
|
commercial: false,
|
|
3536
3816
|
place: "gpu",
|
|
3537
|
-
notes: ["
|
|
3817
|
+
notes: ["640 letterbox, per class nms at iou 0.45, at most 13 boxes"]
|
|
3538
3818
|
};
|
|
3539
3819
|
}
|
|
3540
3820
|
// packages/vision/src/segment.ts
|
|
@@ -3619,7 +3899,7 @@ async function toRaw(tjs, img) {
|
|
|
3619
3899
|
const R = tjs.RawImage;
|
|
3620
3900
|
return R?.read ? R.read(img) : img;
|
|
3621
3901
|
}
|
|
3622
|
-
/** Normalize a depth pipeline result. predicted_depth keeps the raw range
|
|
3902
|
+
/** Normalize a depth pipeline result. predicted_depth keeps the raw range; depth is the 8 bit image. */
|
|
3623
3903
|
function depthFromOutput(out) {
|
|
3624
3904
|
const pd = out.predicted_depth;
|
|
3625
3905
|
if (pd && pd.data && pd.dims?.length >= 2) {
|
|
@@ -3654,6 +3934,7 @@ function depthFromOutput(out) {
|
|
|
3654
3934
|
range: [0, 255]
|
|
3655
3935
|
};
|
|
3656
3936
|
}
|
|
3937
|
+
/** The transformers.js loader for depth records: a depth-estimation pipeline wrapped as a {@link DepthModel}. */
|
|
3657
3938
|
async function depthLoader(ctx) {
|
|
3658
3939
|
const pipe = await ctx.tjs.pipeline("depth-estimation", ctx.record.source.modelId, ctx.options);
|
|
3659
3940
|
return {
|
|
@@ -3661,6 +3942,7 @@ async function depthLoader(ctx) {
|
|
|
3661
3942
|
dispose: () => pipe.dispose?.()
|
|
3662
3943
|
};
|
|
3663
3944
|
}
|
|
3945
|
+
/** The transformers.js loader for caption and question records: the VLM's processor and model wrapped as a {@link Vlm}. */
|
|
3664
3946
|
async function vlmLoader(ctx) {
|
|
3665
3947
|
const id = ctx.record.source.modelId;
|
|
3666
3948
|
const processor = await cls(ctx.tjs, "AutoProcessor").from_pretrained(id);
|
|
@@ -3748,7 +4030,9 @@ async function samLoader(ctx) {
|
|
|
3748
4030
|
});
|
|
3749
4031
|
}
|
|
3750
4032
|
// packages/vision/src/yolo.ts
|
|
4033
|
+
/** The 80 COCO class names, in YOLO class index order. */
|
|
3751
4034
|
const COCO_LABELS = "person,bicycle,car,motorcycle,airplane,bus,train,truck,boat,traffic light,fire hydrant,stop sign,parking meter,bench,bird,cat,dog,horse,sheep,cow,elephant,bear,zebra,giraffe,backpack,umbrella,handbag,tie,suitcase,frisbee,skis,snowboard,sports ball,kite,baseball bat,baseball glove,skateboard,surfboard,tennis racket,bottle,wine glass,cup,fork,knife,spoon,bowl,banana,apple,sandwich,orange,broccoli,carrot,hot dog,pizza,donut,cake,chair,couch,potted plant,bed,dining table,toilet,tv,laptop,mouse,remote,keyboard,cell phone,microwave,oven,toaster,sink,refrigerator,book,clock,vase,scissors,teddy bear,hair drier,toothbrush".split(",");
|
|
4035
|
+
/** The scale and padding that fit a `w` by `h` image into a `size` square (640 by default), centred. */
|
|
3752
4036
|
function letterboxParams(w, h, size = 640) {
|
|
3753
4037
|
const scale = Math.min(size / w, size / h);
|
|
3754
4038
|
return {
|
|
@@ -3781,6 +4065,7 @@ function letterboxTensor(px, size = 640) {
|
|
|
3781
4065
|
lb
|
|
3782
4066
|
};
|
|
3783
4067
|
}
|
|
4068
|
+
/** Intersection over union of two boxes, 0 to 1. */
|
|
3784
4069
|
function iou(a, b) {
|
|
3785
4070
|
const x1 = Math.max(a.x, b.x);
|
|
3786
4071
|
const y1 = Math.max(a.y, b.y);
|
|
@@ -3864,7 +4149,7 @@ function yoloDetector(m, o = {}) {
|
|
|
3864
4149
|
dispose: () => m.dispose()
|
|
3865
4150
|
};
|
|
3866
4151
|
}
|
|
3867
|
-
/** Detection cadence
|
|
4152
|
+
/** Detection cadence: wait max(0.45 s, 4 times the last latency) between runs. */
|
|
3868
4153
|
function detectCadenceMs(lastLatencyMs) {
|
|
3869
4154
|
return Math.max(450, 4 * lastLatencyMs);
|
|
3870
4155
|
}
|
|
@@ -3894,6 +4179,7 @@ async function withModel(hub, what, fn, o = {}) {
|
|
|
3894
4179
|
}
|
|
3895
4180
|
}
|
|
3896
4181
|
const target = (cap, o) => o.model ? { id: o.model } : cap;
|
|
4182
|
+
/** A depth map of an image from the routed depth model (Depth Anything V2 small by default), loaded and released through the hub. */
|
|
3897
4183
|
function depth(hub, image, o = {}) {
|
|
3898
4184
|
return withModel(hub, target("depth", o), (m) => m.estimate(image), o);
|
|
3899
4185
|
}
|
|
@@ -3901,6 +4187,7 @@ function asDetector(v, toPixels) {
|
|
|
3901
4187
|
if (v && typeof v === "object" && "sessions" in v) return yoloDetector(v, toPixels ? { toPixels } : {});
|
|
3902
4188
|
return v;
|
|
3903
4189
|
}
|
|
4190
|
+
/** Objects in an image from the routed detector (MediaPipe EfficientDet by default, or a YOLO ort model), loaded and released through the hub. */
|
|
3904
4191
|
function detect(hub, image, o = {}) {
|
|
3905
4192
|
const opts = {};
|
|
3906
4193
|
if (o.scoreThreshold !== void 0) opts.scoreThreshold = o.scoreThreshold;
|
|
@@ -3958,6 +4245,7 @@ async function landmarks(hub, kind, image, o = {}) {
|
|
|
3958
4245
|
function caption(hub, image, o = {}) {
|
|
3959
4246
|
return hub.chain("vlm")(() => withModel(hub, target("vision.caption", o), (m) => m.ask(image, void 0, o.maxTokens ? { maxTokens: o.maxTokens } : {}), o));
|
|
3960
4247
|
}
|
|
4248
|
+
/** Answer a question about an image with the routed vision language model. VLM calls are serialized on one chain. */
|
|
3961
4249
|
function ask(hub, image, question, o = {}) {
|
|
3962
4250
|
return hub.chain("vlm")(() => withModel(hub, target("vision.ask", o), (m) => m.ask(image, question, o.maxTokens ? { maxTokens: o.maxTokens } : {}), o));
|
|
3963
4251
|
}
|
|
@@ -3966,17 +4254,21 @@ function ask(hub, image, question, o = {}) {
|
|
|
3966
4254
|
* A MediaPipe tasks-vision provider for the models hub. One wasm fileset
|
|
3967
4255
|
* per page; one task per record, created with the GPU delegate on a
|
|
3968
4256
|
* "webgl" rung and the CPU delegate on a "wasm" rung, so a failed GPU
|
|
3969
|
-
* delegate falls to the CPU one
|
|
4257
|
+
* delegate falls to the CPU one.
|
|
3970
4258
|
* Results are turned into the package's Detector, Segmenter and
|
|
3971
4259
|
* Landmarker shapes.
|
|
3972
4260
|
*/
|
|
4261
|
+
/** The pinned @mediapipe/tasks-vision version, 1.2.3. */
|
|
3973
4262
|
const TASKS_VISION = "1.2.3";
|
|
4263
|
+
/** The URL @mediapipe/tasks-vision is imported from, on jsDelivr. */
|
|
3974
4264
|
function tasksVisionUrls(version = TASKS_VISION) {
|
|
3975
4265
|
return [`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${version}/vision_bundle.mjs`];
|
|
3976
4266
|
}
|
|
4267
|
+
/** The directory of the tasks-vision wasm fileset, on jsDelivr. */
|
|
3977
4268
|
function tasksVisionWasm(version = TASKS_VISION) {
|
|
3978
4269
|
return `https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${version}/wasm`;
|
|
3979
4270
|
}
|
|
4271
|
+
/** A loader that imports the pinned @mediapipe/tasks-vision at run time; pass it as `runtime` to {@link mediapipeProvider}. */
|
|
3980
4272
|
const loadTasksVision = (version = TASKS_VISION) => () => importEsm(tasksVisionUrls(version));
|
|
3981
4273
|
const CLASS = {
|
|
3982
4274
|
detect: "ObjectDetector",
|
|
@@ -4065,6 +4357,7 @@ function landmarker(t, kind, video, source) {
|
|
|
4065
4357
|
dispose: () => call(t, "close")
|
|
4066
4358
|
};
|
|
4067
4359
|
}
|
|
4360
|
+
/** The MediaPipe tasks-vision provider for the models hub: one task per record, the GPU delegate on a webgl rung and the CPU delegate on a wasm rung. */
|
|
4068
4361
|
function mediapipeProvider(opts) {
|
|
4069
4362
|
let fileset = null;
|
|
4070
4363
|
return async ({ record, rung, signal }) => {
|
|
@@ -4102,6 +4395,7 @@ function mediapipeProvider(opts) {
|
|
|
4102
4395
|
};
|
|
4103
4396
|
}
|
|
4104
4397
|
// packages/vision/src/faceapi.ts
|
|
4398
|
+
/** The face-api.js provider for the models hub: the tiny face detector and 68 point tiny landmark net, as a face {@link Landmarker}. */
|
|
4105
4399
|
function faceApiProvider(opts) {
|
|
4106
4400
|
return async ({ record }) => {
|
|
4107
4401
|
const fa = await opts.runtime();
|
|
@@ -4121,6 +4415,7 @@ function faceApiProvider(opts) {
|
|
|
4121
4415
|
};
|
|
4122
4416
|
}
|
|
4123
4417
|
// packages/vision/src/loop.ts
|
|
4418
|
+
/** Run a perception step beside a render loop, one at a time, each started no sooner than `interval(lastLatency)` after the previous one began. */
|
|
4124
4419
|
function perceptionLoop(o) {
|
|
4125
4420
|
const now = o.now ?? (() => globalThis.performance ? performance.now() : Date.now());
|
|
4126
4421
|
const g = globalThis;
|
|
@@ -4214,7 +4509,7 @@ function readbackLoop(o) {
|
|
|
4214
4509
|
}
|
|
4215
4510
|
};
|
|
4216
4511
|
}
|
|
4217
|
-
/** A small LRU of results by key
|
|
4512
|
+
/** A small LRU of results by key, so a depth map is computed once per image. */
|
|
4218
4513
|
var ResultCache = class {
|
|
4219
4514
|
max;
|
|
4220
4515
|
m = /* @__PURE__ */ new Map();
|
|
@@ -4245,7 +4540,7 @@ var ResultCache = class {
|
|
|
4245
4540
|
return this.m.size;
|
|
4246
4541
|
}
|
|
4247
4542
|
};
|
|
4248
|
-
/** A depth map as an 8 bit grey RGBA buffer, for a canvas or a PNG (
|
|
4543
|
+
/** A depth map as an 8 bit grey RGBA buffer, for a canvas or a PNG (store it as a PNG data URL to keep it with a design). */
|
|
4249
4544
|
function depthToRgba(d) {
|
|
4250
4545
|
const out = new Uint8ClampedArray(d.width * d.height * 4);
|
|
4251
4546
|
for (let i = 0; i < d.width * d.height; i++) {
|
|
@@ -4255,7 +4550,7 @@ function depthToRgba(d) {
|
|
|
4255
4550
|
}
|
|
4256
4551
|
return out;
|
|
4257
4552
|
}
|
|
4258
|
-
/** Scale so the longest side is at most maxPx
|
|
4553
|
+
/** Scale so the longest side is at most maxPx. */
|
|
4259
4554
|
function fitSize(w, h, maxPx = 1024) {
|
|
4260
4555
|
const s = Math.min(1, maxPx / Math.max(w, h));
|
|
4261
4556
|
return {
|
|
@@ -4397,6 +4692,7 @@ const dims = (img) => {
|
|
|
4397
4692
|
height: o?.height ?? 48
|
|
4398
4693
|
};
|
|
4399
4694
|
};
|
|
4695
|
+
/** A stub depth model with no weights: a left to right ramp at the image's size. */
|
|
4400
4696
|
function rampDepth() {
|
|
4401
4697
|
return { async estimate(img) {
|
|
4402
4698
|
const { width, height } = dims(img);
|
|
@@ -4410,6 +4706,7 @@ function rampDepth() {
|
|
|
4410
4706
|
};
|
|
4411
4707
|
} };
|
|
4412
4708
|
}
|
|
4709
|
+
/** A stub detector with no weights: one centred box with the given label. */
|
|
4413
4710
|
function centreDetector(label = "person") {
|
|
4414
4711
|
return { async detect(img) {
|
|
4415
4712
|
const { width, height } = dims(img);
|
|
@@ -4475,6 +4772,7 @@ const centreBox = (img) => {
|
|
|
4475
4772
|
h: 2 * r
|
|
4476
4773
|
};
|
|
4477
4774
|
};
|
|
4775
|
+
/** A stub landmarker with no weights: one list of `count` fixed points. */
|
|
4478
4776
|
function fixedLandmarker(count, source = "stub") {
|
|
4479
4777
|
return { async detect() {
|
|
4480
4778
|
return {
|
|
@@ -4487,6 +4785,7 @@ function fixedLandmarker(count, source = "stub") {
|
|
|
4487
4785
|
};
|
|
4488
4786
|
} };
|
|
4489
4787
|
}
|
|
4788
|
+
/** A stub vision language model with no weights: a fixed caption, or a fixed answer that repeats the question. */
|
|
4490
4789
|
function fixedVlm(text = "a stub caption.") {
|
|
4491
4790
|
return { ask: async (_img, q) => q ? `stub answer to: ${q}` : text };
|
|
4492
4791
|
}
|
|
@@ -4532,19 +4831,22 @@ function maskArea(m) {
|
|
|
4532
4831
|
function maskThreshold(m, t = ON) {
|
|
4533
4832
|
return make(m, m.data.map((v) => v >= t ? 255 : 0));
|
|
4534
4833
|
}
|
|
4834
|
+
/** Pixels inside either mask, the larger value of each. Throws when the sizes differ. */
|
|
4535
4835
|
function maskUnion(a, b) {
|
|
4536
4836
|
same("maskUnion", a, b);
|
|
4537
4837
|
return make(a, a.data.map((v, i) => Math.max(v, b.data[i])));
|
|
4538
4838
|
}
|
|
4839
|
+
/** Pixels inside both masks, the smaller value of each. Throws when the sizes differ. */
|
|
4539
4840
|
function maskIntersect(a, b) {
|
|
4540
4841
|
same("maskIntersect", a, b);
|
|
4541
4842
|
return make(a, a.data.map((v, i) => Math.min(v, b.data[i])));
|
|
4542
4843
|
}
|
|
4543
|
-
/** `a` with `b` taken out (shift with a selection tool in
|
|
4844
|
+
/** `a` with `b` taken out (shift with a selection tool in a mask editor). */
|
|
4544
4845
|
function maskSubtract(a, b) {
|
|
4545
4846
|
same("maskSubtract", a, b);
|
|
4546
4847
|
return make(a, a.data.map((v, i) => Math.min(v, 255 - b.data[i])));
|
|
4547
4848
|
}
|
|
4849
|
+
/** The mask with inside and outside swapped, 255 minus each value. */
|
|
4548
4850
|
function maskInvert(m) {
|
|
4549
4851
|
return make(m, m.data.map((v) => 255 - v));
|
|
4550
4852
|
}
|
|
@@ -4598,7 +4900,7 @@ function maskErode(m, r) {
|
|
|
4598
4900
|
const d = distance2((i) => m.data[i] < ON, m.width, m.height);
|
|
4599
4901
|
return make(m, Uint8Array.from(d, (v) => v > r * r ? 255 : 0));
|
|
4600
4902
|
}
|
|
4601
|
-
/** Soft edges: a gaussian of radius `r` with sigma r / 2 (
|
|
4903
|
+
/** Soft edges: a gaussian of radius `r` with sigma r / 2 (a smooth without a rethreshold), edges clamped. */
|
|
4602
4904
|
function maskFeather(m, r) {
|
|
4603
4905
|
if (r <= 0) return make(m, m.data.slice());
|
|
4604
4906
|
const { width: w, height: h } = m;
|
|
@@ -4839,6 +5141,7 @@ function maskToSvg(m, o = {}) {
|
|
|
4839
5141
|
const d = maskOutline(m).map((l) => `M${l.map((p) => `${p[0]} ${p[1]}`).join("L")}Z`).join("");
|
|
4840
5142
|
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${m.width} ${m.height}" width="${m.width}" height="${m.height}"><path d="${d}" fill="${o.fill ?? "#000"}" fill-rule="evenodd"/></svg>`;
|
|
4841
5143
|
}
|
|
5144
|
+
/** The mask as COCO style uncompressed run length, column major, 128 and up inside. */
|
|
4842
5145
|
function maskToRle(m) {
|
|
4843
5146
|
const { width: w, height: h } = m;
|
|
4844
5147
|
const counts = [];
|
|
@@ -4859,6 +5162,7 @@ function maskToRle(m) {
|
|
|
4859
5162
|
counts
|
|
4860
5163
|
};
|
|
4861
5164
|
}
|
|
5165
|
+
/** A mask from COCO style run length, inside 255. Throws when the counts do not cover the image. */
|
|
4862
5166
|
function maskFromRle(r) {
|
|
4863
5167
|
const [h, w] = r.size;
|
|
4864
5168
|
const data = new Uint8Array(w * h);
|
|
@@ -4910,6 +5214,7 @@ const absent = () => ({
|
|
|
4910
5214
|
frown: 0,
|
|
4911
5215
|
gesture: null
|
|
4912
5216
|
});
|
|
5217
|
+
/** Turns raw face and hand frames into steady signals and discrete events, smoothed or held so one noisy frame never fires a reaction. */
|
|
4913
5218
|
var SignalTracker = class {
|
|
4914
5219
|
p = absent();
|
|
4915
5220
|
lastSeen = -Infinity;
|
|
@@ -5170,6 +5475,7 @@ var SeenNotes = class {
|
|
|
5170
5475
|
};
|
|
5171
5476
|
/** Questions that call for an on demand look rather than the steady signals. Replace it to suit a persona. */
|
|
5172
5477
|
const LOOK_PATTERN = /\b(what (am i|is this|'?s this|do you see|can you see)|can you see|do you see|look at (this|me|my)|what('?s| is) in my hand|holding|wearing|show(ing)? you)\b/i;
|
|
5478
|
+
/** True when a message asks the character to look, by {@link LOOK_PATTERN} or the pattern you pass. */
|
|
5173
5479
|
const wantsLook = (text, pattern = LOOK_PATTERN) => pattern.test(text);
|
|
5174
5480
|
/** Default reactions (vendor): greet on arrival, smile back after 600 ms at 0.7 chance, answer waves and a few gestures. */
|
|
5175
5481
|
const DEFAULT_REACTIONS = [
|
|
@@ -5233,4 +5539,4 @@ function gazeTarget(p, gain = 1.3) {
|
|
|
5233
5539
|
y: clamp(p.face.y * gain)
|
|
5234
5540
|
} : null;
|
|
5235
5541
|
}
|
|
5236
|
-
export { CANNED_GESTURES, COCO_LABELS, DEFAULT_REACTIONS, DEPTH_WORKER_SOURCE, EmbeddingCache, LOOK_PATTERN, MP_MODELS, ResultCache, SeenNotes, SignalTracker, TASKS_VISION, VISION_RECORDS, ask, attachVision, caption, centreDetector, cutoutPng, cutoutRgba, decodeYolo, depth, depthFromOutput, depthLoader, depthToRgba, depthWorker, describePerception, detect, detectCadenceMs, discSegmenter, emptyMask, encodePng, faceApiProvider, faceApiRecord, fitSize, fixedLandmarker, fixedVlm, gazeTarget, hasPrompt, iou, landmarkChain, landmarks, letterboxParams, letterboxTensor, loadTasksVision, maskArea, maskDilate, maskErode, maskFeather, maskFromRle, maskIntersect, maskInvert, maskLargestComponent, maskOutline, maskSubtract, maskThreshold, maskToPng, maskToRgba, maskToRle, maskToSvg, maskUnion, mediapipeLadder, mediapipeProvider, nms, perceptionLoop, promptSegmenter, rampDepth, rawFace, rawFromLandmarks, rawHands, reactionsFor, readbackLoop, samLoader, segment, tasksVisionUrls, tasksVisionWasm, visionStubs, vlmLoader, wantsLook, yoloDetector, yoloRecord };
|
|
5542
|
+
export { CANNED_GESTURES, COCO_LABELS, DEFAULT_REACTIONS, DEPTH_WORKER_SOURCE, EmbeddingCache, LOOK_PATTERN, MP_MODELS, PICKER_RECORDS, ResultCache, SeenNotes, SignalTracker, TASKS_VISION, VISION_RECORDS, ask, attachVision, caption, centreDetector, cutoutPng, cutoutRgba, decodeYolo, depth, depthFromOutput, depthLoader, depthToRgba, depthWorker, describePerception, detect, detectCadenceMs, discSegmenter, emptyMask, encodePng, faceApiProvider, faceApiRecord, fitSize, fixedLandmarker, fixedVlm, gazeTarget, hasPrompt, iou, landmarkChain, landmarks, letterboxParams, letterboxTensor, loadTasksVision, maskArea, maskDilate, maskErode, maskFeather, maskFromRle, maskIntersect, maskInvert, maskLargestComponent, maskOutline, maskSubtract, maskThreshold, maskToPng, maskToRgba, maskToRle, maskToSvg, maskUnion, mediapipeLadder, mediapipeProvider, nms, perceptionLoop, promptSegmenter, rampDepth, rawFace, rawFromLandmarks, rawHands, reactionsFor, readbackLoop, samLoader, segment, tasksVisionUrls, tasksVisionWasm, visionStubs, vlmLoader, wantsLook, yoloDetector, yoloRecord };
|