@hackbuild/vision 0.1.2 → 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 +257 -178
- 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/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 +3 -0
- package/dist/records.js +13 -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 +69 -29
- package/dist/single/index.js +69 -29
- 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/loop.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A perception loop beside a render loop: one step at a time (
|
|
3
|
-
*
|
|
4
|
-
* after the previous one began (an
|
|
5
|
-
*
|
|
2
|
+
* A perception loop beside a render loop: one step at a time (a busy
|
|
3
|
+
* guard), each step started no sooner than `interval(lastLatency)`
|
|
4
|
+
* after the previous one began (an adaptive cadence or a fixed
|
|
5
|
+
* period), stopped by `stop()` or an abort signal. The scheduler is
|
|
6
6
|
* injectable so tests run without timers.
|
|
7
7
|
*/
|
|
8
8
|
export interface LoopOptions<T> {
|
|
@@ -18,6 +18,7 @@ export interface LoopOptions<T> {
|
|
|
18
18
|
/** Called on each frame that found the previous step still running. */
|
|
19
19
|
onBusy?: () => void;
|
|
20
20
|
}
|
|
21
|
+
/** A running loop: `stop`, whether it runs or is busy, the last step's latency and the step count. */
|
|
21
22
|
export interface Loop {
|
|
22
23
|
stop(): void;
|
|
23
24
|
readonly running: boolean;
|
|
@@ -25,13 +26,15 @@ export interface Loop {
|
|
|
25
26
|
readonly lastLatencyMs: number;
|
|
26
27
|
readonly steps: number;
|
|
27
28
|
}
|
|
29
|
+
/** Run a perception step beside a render loop, one at a time, each started no sooner than `interval(lastLatency)` after the previous one began. */
|
|
28
30
|
export declare function perceptionLoop<T>(o: LoopOptions<T>): Loop;
|
|
31
|
+
/** Options for {@link readbackLoop}: the async read, the frame consumer, a rate cap (10 Hz), and an abort signal. */
|
|
29
32
|
export interface ReadbackOptions<T> {
|
|
30
33
|
/** An async readback, e.g. three.js readRenderTargetPixelsAsync or a canvas createImageBitmap. */
|
|
31
34
|
read: () => Promise<T>;
|
|
32
35
|
/** Consumer of each frame; a slow consumer holds the loop (it runs inside the busy window). */
|
|
33
36
|
onFrame: (frame: T) => void | Promise<void>;
|
|
34
|
-
/** Rate cap. Default 10 Hz
|
|
37
|
+
/** Rate cap. Default 10 Hz. */
|
|
35
38
|
maxHz?: number;
|
|
36
39
|
onError?: (e: unknown) => void;
|
|
37
40
|
now?: () => number;
|
|
@@ -46,7 +49,7 @@ export interface ReadbackOptions<T> {
|
|
|
46
49
|
export declare function readbackLoop<T>(o: ReadbackOptions<T>): Loop & {
|
|
47
50
|
readonly skipped: number;
|
|
48
51
|
};
|
|
49
|
-
/** A small LRU of results by key
|
|
52
|
+
/** A small LRU of results by key, so a depth map is computed once per image. */
|
|
50
53
|
export declare class ResultCache<T> {
|
|
51
54
|
private readonly max;
|
|
52
55
|
private readonly m;
|
|
@@ -56,13 +59,13 @@ export declare class ResultCache<T> {
|
|
|
56
59
|
getOr(key: string, make: () => Promise<T>): Promise<T>;
|
|
57
60
|
get size(): number;
|
|
58
61
|
}
|
|
59
|
-
/** A depth map as an 8 bit grey RGBA buffer, for a canvas or a PNG (
|
|
62
|
+
/** 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). */
|
|
60
63
|
export declare function depthToRgba(d: {
|
|
61
64
|
width: number;
|
|
62
65
|
height: number;
|
|
63
66
|
data: Float32Array;
|
|
64
67
|
}): Uint8ClampedArray;
|
|
65
|
-
/** Scale so the longest side is at most maxPx
|
|
68
|
+
/** Scale so the longest side is at most maxPx. */
|
|
66
69
|
export declare function fitSize(w: number, h: number, maxPx?: number): {
|
|
67
70
|
width: number;
|
|
68
71
|
height: number;
|
package/dist/loop.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A perception loop beside a render loop: one step at a time (
|
|
3
|
-
*
|
|
4
|
-
* after the previous one began (an
|
|
5
|
-
*
|
|
2
|
+
* A perception loop beside a render loop: one step at a time (a busy
|
|
3
|
+
* guard), each step started no sooner than `interval(lastLatency)`
|
|
4
|
+
* after the previous one began (an adaptive cadence or a fixed
|
|
5
|
+
* period), stopped by `stop()` or an abort signal. The scheduler is
|
|
6
6
|
* injectable so tests run without timers.
|
|
7
7
|
*/
|
|
8
|
+
/** Run a perception step beside a render loop, one at a time, each started no sooner than `interval(lastLatency)` after the previous one began. */
|
|
8
9
|
export function perceptionLoop(o) {
|
|
9
10
|
const now = o.now ?? (() => (globalThis.performance ? performance.now() : Date.now()));
|
|
10
11
|
const g = globalThis;
|
|
@@ -103,7 +104,7 @@ export function readbackLoop(o) {
|
|
|
103
104
|
},
|
|
104
105
|
};
|
|
105
106
|
}
|
|
106
|
-
/** A small LRU of results by key
|
|
107
|
+
/** A small LRU of results by key, so a depth map is computed once per image. */
|
|
107
108
|
export class ResultCache {
|
|
108
109
|
max;
|
|
109
110
|
m = new Map();
|
|
@@ -136,7 +137,7 @@ export class ResultCache {
|
|
|
136
137
|
return this.m.size;
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
|
-
/** A depth map as an 8 bit grey RGBA buffer, for a canvas or a PNG (
|
|
140
|
+
/** 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). */
|
|
140
141
|
export function depthToRgba(d) {
|
|
141
142
|
const out = new Uint8ClampedArray(d.width * d.height * 4);
|
|
142
143
|
for (let i = 0; i < d.width * d.height; i++) {
|
|
@@ -146,7 +147,7 @@ export function depthToRgba(d) {
|
|
|
146
147
|
}
|
|
147
148
|
return out;
|
|
148
149
|
}
|
|
149
|
-
/** Scale so the longest side is at most maxPx
|
|
150
|
+
/** Scale so the longest side is at most maxPx. */
|
|
150
151
|
export function fitSize(w, h, maxPx = 1024) {
|
|
151
152
|
const s = Math.min(1, maxPx / Math.max(w, h));
|
|
152
153
|
return { width: Math.max(1, Math.round(w * s)), height: Math.max(1, Math.round(h * s)), scale: s };
|
package/dist/masks.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Mask operations and mask export, as plain functions on `Mask` (0 to 255
|
|
3
|
-
* per pixel, 128 and up counts as inside). The operations are
|
|
4
|
-
*
|
|
3
|
+
* per pixel, 128 and up counts as inside). The operations are a mask
|
|
4
|
+
* editor's set (union, subtract, invert, smooth, expand, shrink,
|
|
5
5
|
* keep the largest piece); dilate and erode use an exact distance
|
|
6
6
|
* transform, so a radius costs the same at any size and the image border
|
|
7
7
|
* is not eaten. Exports: grey PNG, PNG with the mask as alpha, an SVG
|
|
@@ -14,16 +14,19 @@ export declare function emptyMask(width: number, height: number): Mask;
|
|
|
14
14
|
export declare function maskArea(m: Mask): number;
|
|
15
15
|
/** Every value to 0 or 255 at `t`. */
|
|
16
16
|
export declare function maskThreshold(m: Mask, t?: number): Mask;
|
|
17
|
+
/** Pixels inside either mask, the larger value of each. Throws when the sizes differ. */
|
|
17
18
|
export declare function maskUnion(a: Mask, b: Mask): Mask;
|
|
19
|
+
/** Pixels inside both masks, the smaller value of each. Throws when the sizes differ. */
|
|
18
20
|
export declare function maskIntersect(a: Mask, b: Mask): Mask;
|
|
19
|
-
/** `a` with `b` taken out (shift with a selection tool in
|
|
21
|
+
/** `a` with `b` taken out (shift with a selection tool in a mask editor). */
|
|
20
22
|
export declare function maskSubtract(a: Mask, b: Mask): Mask;
|
|
23
|
+
/** The mask with inside and outside swapped, 255 minus each value. */
|
|
21
24
|
export declare function maskInvert(m: Mask): Mask;
|
|
22
25
|
/** Grow by a disc of radius `r` pixels (expand). */
|
|
23
26
|
export declare function maskDilate(m: Mask, r: number): Mask;
|
|
24
27
|
/** Shrink by a disc of radius `r` pixels; the image border does not count as outside. */
|
|
25
28
|
export declare function maskErode(m: Mask, r: number): Mask;
|
|
26
|
-
/** Soft edges: a gaussian of radius `r` with sigma r / 2 (
|
|
29
|
+
/** Soft edges: a gaussian of radius `r` with sigma r / 2 (a smooth without a rethreshold), edges clamped. */
|
|
27
30
|
export declare function maskFeather(m: Mask, r: number): Mask;
|
|
28
31
|
/** Keep only the largest connected piece (8 connected by default). */
|
|
29
32
|
export declare function maskLargestComponent(m: Mask, connectivity?: 4 | 8): Mask;
|
|
@@ -63,5 +66,7 @@ export interface MaskRle {
|
|
|
63
66
|
size: [height: number, width: number];
|
|
64
67
|
counts: number[];
|
|
65
68
|
}
|
|
69
|
+
/** The mask as COCO style uncompressed run length, column major, 128 and up inside. */
|
|
66
70
|
export declare function maskToRle(m: Mask): MaskRle;
|
|
71
|
+
/** A mask from COCO style run length, inside 255. Throws when the counts do not cover the image. */
|
|
67
72
|
export declare function maskFromRle(r: MaskRle): Mask;
|
package/dist/masks.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Mask operations and mask export, as plain functions on `Mask` (0 to 255
|
|
3
|
-
* per pixel, 128 and up counts as inside). The operations are
|
|
4
|
-
*
|
|
3
|
+
* per pixel, 128 and up counts as inside). The operations are a mask
|
|
4
|
+
* editor's set (union, subtract, invert, smooth, expand, shrink,
|
|
5
5
|
* keep the largest piece); dilate and erode use an exact distance
|
|
6
6
|
* transform, so a radius costs the same at any size and the image border
|
|
7
7
|
* is not eaten. Exports: grey PNG, PNG with the mask as alpha, an SVG
|
|
@@ -29,19 +29,22 @@ export function maskArea(m) {
|
|
|
29
29
|
export function maskThreshold(m, t = ON) {
|
|
30
30
|
return make(m, m.data.map((v) => (v >= t ? 255 : 0)));
|
|
31
31
|
}
|
|
32
|
+
/** Pixels inside either mask, the larger value of each. Throws when the sizes differ. */
|
|
32
33
|
export function maskUnion(a, b) {
|
|
33
34
|
same("maskUnion", a, b);
|
|
34
35
|
return make(a, a.data.map((v, i) => Math.max(v, b.data[i])));
|
|
35
36
|
}
|
|
37
|
+
/** Pixels inside both masks, the smaller value of each. Throws when the sizes differ. */
|
|
36
38
|
export function maskIntersect(a, b) {
|
|
37
39
|
same("maskIntersect", a, b);
|
|
38
40
|
return make(a, a.data.map((v, i) => Math.min(v, b.data[i])));
|
|
39
41
|
}
|
|
40
|
-
/** `a` with `b` taken out (shift with a selection tool in
|
|
42
|
+
/** `a` with `b` taken out (shift with a selection tool in a mask editor). */
|
|
41
43
|
export function maskSubtract(a, b) {
|
|
42
44
|
same("maskSubtract", a, b);
|
|
43
45
|
return make(a, a.data.map((v, i) => Math.min(v, 255 - b.data[i])));
|
|
44
46
|
}
|
|
47
|
+
/** The mask with inside and outside swapped, 255 minus each value. */
|
|
45
48
|
export function maskInvert(m) {
|
|
46
49
|
return make(m, m.data.map((v) => 255 - v));
|
|
47
50
|
}
|
|
@@ -103,7 +106,7 @@ export function maskErode(m, r) {
|
|
|
103
106
|
const d = distance2((i) => m.data[i] < ON, m.width, m.height);
|
|
104
107
|
return make(m, Uint8Array.from(d, (v) => (v > r * r ? 255 : 0)));
|
|
105
108
|
}
|
|
106
|
-
/** Soft edges: a gaussian of radius `r` with sigma r / 2 (
|
|
109
|
+
/** Soft edges: a gaussian of radius `r` with sigma r / 2 (a smooth without a rethreshold), edges clamped. */
|
|
107
110
|
export function maskFeather(m, r) {
|
|
108
111
|
if (r <= 0)
|
|
109
112
|
return make(m, m.data.slice());
|
|
@@ -364,6 +367,7 @@ export function maskToSvg(m, o = {}) {
|
|
|
364
367
|
.join("");
|
|
365
368
|
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>`;
|
|
366
369
|
}
|
|
370
|
+
/** The mask as COCO style uncompressed run length, column major, 128 and up inside. */
|
|
367
371
|
export function maskToRle(m) {
|
|
368
372
|
const { width: w, height: h } = m;
|
|
369
373
|
const counts = [];
|
|
@@ -382,6 +386,7 @@ export function maskToRle(m) {
|
|
|
382
386
|
counts.push(run);
|
|
383
387
|
return { size: [h, w], counts };
|
|
384
388
|
}
|
|
389
|
+
/** A mask from COCO style run length, inside 255. Throws when the counts do not cover the image. */
|
|
385
390
|
export function maskFromRle(r) {
|
|
386
391
|
const [h, w] = r.size;
|
|
387
392
|
const data = new Uint8Array(w * h);
|
package/dist/mediapipe.d.ts
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
* A MediaPipe tasks-vision provider for the models hub. One wasm fileset
|
|
3
3
|
* per page; one task per record, created with the GPU delegate on a
|
|
4
4
|
* "webgl" rung and the CPU delegate on a "wasm" rung, so a failed GPU
|
|
5
|
-
* delegate falls to the CPU one
|
|
5
|
+
* delegate falls to the CPU one.
|
|
6
6
|
* Results are turned into the package's Detector, Segmenter and
|
|
7
7
|
* Landmarker shapes.
|
|
8
8
|
*/
|
|
9
9
|
import type { Factory } from "@hackbuild/models";
|
|
10
10
|
import type { WeightStore } from "@hackbuild/weights";
|
|
11
|
+
/** The pinned @mediapipe/tasks-vision version, 1.2.3. */
|
|
11
12
|
export declare const TASKS_VISION = "1.2.3";
|
|
12
13
|
interface TaskClass {
|
|
13
14
|
createFromOptions(fileset: unknown, opts: Record<string, unknown>): Promise<Record<string, (...a: unknown[]) => unknown>>;
|
|
@@ -24,14 +25,19 @@ export interface TasksVision {
|
|
|
24
25
|
PoseLandmarker?: TaskClass;
|
|
25
26
|
GestureRecognizer?: TaskClass;
|
|
26
27
|
}
|
|
28
|
+
/** The URL @mediapipe/tasks-vision is imported from, on jsDelivr. */
|
|
27
29
|
export declare function tasksVisionUrls(version?: string): string[];
|
|
30
|
+
/** The directory of the tasks-vision wasm fileset, on jsDelivr. */
|
|
28
31
|
export declare function tasksVisionWasm(version?: string): string;
|
|
32
|
+
/** A loader that imports the pinned @mediapipe/tasks-vision at run time; pass it as `runtime` to {@link mediapipeProvider}. */
|
|
29
33
|
export declare const loadTasksVision: (version?: string) => () => Promise<TasksVision>;
|
|
34
|
+
/** Options for {@link mediapipeProvider}: the runtime loader, the wasm fileset directory, and a weight store to read model files through. */
|
|
30
35
|
export interface MediapipeProviderOptions {
|
|
31
36
|
runtime: () => Promise<TasksVision>;
|
|
32
37
|
wasmBase?: string;
|
|
33
38
|
/** Read model files through the weight store (resume, sha-256, licence line) and pass them as buffers. */
|
|
34
39
|
store?: WeightStore;
|
|
35
40
|
}
|
|
41
|
+
/** 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. */
|
|
36
42
|
export declare function mediapipeProvider(opts: MediapipeProviderOptions): Factory;
|
|
37
43
|
export {};
|
package/dist/mediapipe.js
CHANGED
|
@@ -2,18 +2,22 @@
|
|
|
2
2
|
* A MediaPipe tasks-vision provider for the models hub. One wasm fileset
|
|
3
3
|
* per page; one task per record, created with the GPU delegate on a
|
|
4
4
|
* "webgl" rung and the CPU delegate on a "wasm" rung, so a failed GPU
|
|
5
|
-
* delegate falls to the CPU one
|
|
5
|
+
* delegate falls to the CPU one.
|
|
6
6
|
* Results are turned into the package's Detector, Segmenter and
|
|
7
7
|
* Landmarker shapes.
|
|
8
8
|
*/
|
|
9
9
|
import { importEsm } from "@hackbuild/ai-env";
|
|
10
|
+
/** The pinned @mediapipe/tasks-vision version, 1.2.3. */
|
|
10
11
|
export const TASKS_VISION = "1.2.3";
|
|
12
|
+
/** The URL @mediapipe/tasks-vision is imported from, on jsDelivr. */
|
|
11
13
|
export function tasksVisionUrls(version = TASKS_VISION) {
|
|
12
14
|
return [`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${version}/vision_bundle.mjs`];
|
|
13
15
|
}
|
|
16
|
+
/** The directory of the tasks-vision wasm fileset, on jsDelivr. */
|
|
14
17
|
export function tasksVisionWasm(version = TASKS_VISION) {
|
|
15
18
|
return `https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${version}/wasm`;
|
|
16
19
|
}
|
|
20
|
+
/** A loader that imports the pinned @mediapipe/tasks-vision at run time; pass it as `runtime` to {@link mediapipeProvider}. */
|
|
17
21
|
export const loadTasksVision = (version = TASKS_VISION) => () => importEsm(tasksVisionUrls(version));
|
|
18
22
|
const CLASS = {
|
|
19
23
|
detect: "ObjectDetector",
|
|
@@ -80,6 +84,7 @@ function landmarker(t, kind, video, source) {
|
|
|
80
84
|
dispose: () => call(t, "close"),
|
|
81
85
|
};
|
|
82
86
|
}
|
|
87
|
+
/** 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. */
|
|
83
88
|
export function mediapipeProvider(opts) {
|
|
84
89
|
let fileset = null;
|
|
85
90
|
return async ({ record, rung, signal }) => {
|
package/dist/records.d.ts
CHANGED
|
@@ -8,10 +8,13 @@
|
|
|
8
8
|
* swap set sit in PICKER_RECORDS.
|
|
9
9
|
*/
|
|
10
10
|
import type { ModelRecord, Rung } from "@hackbuild/models";
|
|
11
|
+
/** The MediaPipe model storage base URL the MediaPipe records load from. */
|
|
11
12
|
export declare const MP_MODELS = "https://storage.googleapis.com/mediapipe-models/";
|
|
12
13
|
/** MediaPipe ladder: GPU delegate (webgl), then the CPU delegate (wasm). */
|
|
13
14
|
export declare const mediapipeLadder: () => Rung[];
|
|
15
|
+
/** The vision records registered by `attachVision`: Depth Anything V2 small, MediaPipe detection, segmentation and landmarks, SlimSAM, SmolVLM 256M and LFM2-VL 450M. */
|
|
14
16
|
export declare const VISION_RECORDS: ModelRecord[];
|
|
17
|
+
/** Records listed for pickers and never registered by default: larger alternates, and records under licences that limit use (YOLOv10, FastSAM, the face swap set). */
|
|
15
18
|
export declare const PICKER_RECORDS: ModelRecord[];
|
|
16
19
|
/** A face landmark fallback record over face-api.js tiny nets (code MIT; weights MIT from @vladmandic/face-api). */
|
|
17
20
|
export declare function faceApiRecord(baseUrl: string): ModelRecord;
|
package/dist/records.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* swap set sit in PICKER_RECORDS.
|
|
9
9
|
*/
|
|
10
10
|
import { LADDERS, tjsLadder } from "@hackbuild/devices";
|
|
11
|
+
/** The MediaPipe model storage base URL the MediaPipe records load from. */
|
|
11
12
|
export const MP_MODELS = "https://storage.googleapis.com/mediapipe-models/";
|
|
12
13
|
/** MediaPipe ladder: GPU delegate (webgl), then the CPU delegate (wasm). */
|
|
13
14
|
export const mediapipeLadder = () => [{ device: "webgl" }, { device: "wasm" }];
|
|
@@ -28,6 +29,7 @@ const mp = (id, provides, path, sizeMB, label, verdict = "light, on the gpu", gr
|
|
|
28
29
|
place: "main",
|
|
29
30
|
runtime: "@mediapipe/tasks-vision@1.2.3",
|
|
30
31
|
});
|
|
32
|
+
/** The vision records registered by `attachVision`: Depth Anything V2 small, MediaPipe detection, segmentation and landmarks, SlimSAM, SmolVLM 256M and LFM2-VL 450M. */
|
|
31
33
|
export const VISION_RECORDS = [
|
|
32
34
|
{
|
|
33
35
|
id: "depth-anything-v2-small",
|
|
@@ -45,7 +47,7 @@ export const VISION_RECORDS = [
|
|
|
45
47
|
commercial: true,
|
|
46
48
|
place: "cpu-worker",
|
|
47
49
|
runtime: "@huggingface/transformers@4.3.2",
|
|
48
|
-
notes: ["
|
|
50
|
+
notes: ["fp16 on webgpu, fp32 on the same device after a failure"],
|
|
49
51
|
},
|
|
50
52
|
mp("efficientdet-lite0", "detect", "object_detector/efficientdet_lite0/float16/1/efficientdet_lite0.tflite", 7, "mediapipe efficientdet lite0 (coco, 80 classes)", "light, 80 things"),
|
|
51
53
|
mp("selfie-segmenter", "segment.person", "image_segmenter/selfie_segmenter/float16/latest/selfie_segmenter.tflite", 1, "mediapipe selfie segmenter"),
|
|
@@ -76,7 +78,7 @@ export const VISION_RECORDS = [
|
|
|
76
78
|
commercial: true,
|
|
77
79
|
place: "cpu-worker",
|
|
78
80
|
runtime: "@huggingface/transformers@4.3.2",
|
|
79
|
-
notes: ["
|
|
81
|
+
notes: ["one image embedding, then any number of point prompts"],
|
|
80
82
|
},
|
|
81
83
|
{
|
|
82
84
|
id: "smolvlm-256m-instruct",
|
|
@@ -115,13 +117,12 @@ export const VISION_RECORDS = [
|
|
|
115
117
|
commercial: "unknown",
|
|
116
118
|
place: "gpu",
|
|
117
119
|
runtime: "@huggingface/transformers@4.3.2",
|
|
118
|
-
notes: ["
|
|
120
|
+
notes: ["q4f16 on webgpu only; the licence limits commercial use by revenue, read it before shipping"],
|
|
119
121
|
},
|
|
120
122
|
];
|
|
121
123
|
/**
|
|
122
124
|
* Records listed for pickers and never registered by default, so a hub's
|
|
123
|
-
* routing by capability keeps its small defaults: larger alternates
|
|
124
|
-
* earlier tools offered (smolvlm 500m and 2 video, gemma 4 e2b, two more
|
|
125
|
+
* routing by capability keeps its small defaults: larger alternates (smolvlm 500m and 2 video, gemma 4 e2b, two more
|
|
125
126
|
* depth models), and records under licences that limit use (YOLOv10 and
|
|
126
127
|
* FastSAM are AGPL-3.0 upstream, Ultralytics; the face swap set is
|
|
127
128
|
* InsightFace, non-commercial). A hub that runs one adds it itself. Sizes
|
|
@@ -145,8 +146,9 @@ const yolo10 = (size, mb, speed, verdict) => ({
|
|
|
145
146
|
licence: "AGPL-3.0 (Ultralytics weights, the model card's licence field)",
|
|
146
147
|
commercial: false,
|
|
147
148
|
place: "gpu",
|
|
148
|
-
notes: ["output [1, 300, 6] after the model's own selection, so no nms pass (vendor, the yolov10 paper)", "
|
|
149
|
+
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"],
|
|
149
150
|
});
|
|
151
|
+
/** Records listed for pickers and never registered by default: larger alternates, and records under licences that limit use (YOLOv10, FastSAM, the face swap set). */
|
|
150
152
|
export const PICKER_RECORDS = [
|
|
151
153
|
{
|
|
152
154
|
id: "smolvlm-500m-instruct",
|
|
@@ -185,7 +187,7 @@ export const PICKER_RECORDS = [
|
|
|
185
187
|
commercial: true,
|
|
186
188
|
place: "cpu-worker",
|
|
187
189
|
runtime: "@huggingface/transformers@4.3.2",
|
|
188
|
-
notes: ["an
|
|
190
|
+
notes: ["an option beside smolvlm 256m and 500m"],
|
|
189
191
|
},
|
|
190
192
|
{
|
|
191
193
|
id: "depth-anything-v2-base",
|
|
@@ -241,7 +243,7 @@ export const PICKER_RECORDS = [
|
|
|
241
243
|
commercial: true,
|
|
242
244
|
place: "gpu",
|
|
243
245
|
runtime: "@huggingface/transformers@4.3.2",
|
|
244
|
-
notes: ["
|
|
246
|
+
notes: ["about 3.3 GB (vendor)"],
|
|
245
247
|
},
|
|
246
248
|
yolo10("n", 9, "instant", "nano, quick"),
|
|
247
249
|
yolo10("s", 28, "fast", "small, sharper"),
|
|
@@ -264,7 +266,7 @@ export const PICKER_RECORDS = [
|
|
|
264
266
|
licence: "AGPL-3.0 upstream (Ultralytics FastSAM); the export's card says apache-2.0",
|
|
265
267
|
commercial: false,
|
|
266
268
|
place: "cpu-worker",
|
|
267
|
-
notes: ["
|
|
269
|
+
notes: ["finds every mask in one pass on onnxruntime-web (93 MB, vendor)", "segment everything: prototype masks, nms, then a pick by click"],
|
|
268
270
|
},
|
|
269
271
|
{
|
|
270
272
|
id: "scrfd-10g",
|
|
@@ -319,7 +321,7 @@ export const PICKER_RECORDS = [
|
|
|
319
321
|
licence: "InsightFace: non-commercial research only; the mirror's card says gpl-3.0",
|
|
320
322
|
commercial: false,
|
|
321
323
|
place: "gpu",
|
|
322
|
-
notes: ["128 px faces;
|
|
324
|
+
notes: ["128 px faces; paste the result back with a feathered mask"],
|
|
323
325
|
},
|
|
324
326
|
];
|
|
325
327
|
/** A face landmark fallback record over face-api.js tiny nets (code MIT; weights MIT from @vladmandic/face-api). */
|
|
@@ -361,6 +363,6 @@ export function yoloRecord(o) {
|
|
|
361
363
|
licence: o.licence ?? "AGPL-3.0 (Ultralytics YOLOv8 weights), supplied by the app",
|
|
362
364
|
commercial: false,
|
|
363
365
|
place: "gpu",
|
|
364
|
-
notes: ["
|
|
366
|
+
notes: ["640 letterbox, per class nms at iou 0.45, at most 13 boxes"],
|
|
365
367
|
};
|
|
366
368
|
}
|
package/dist/segment.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Prompted segmentation with one image embedding per image. The encoder
|
|
3
3
|
* runs once per image; every later point or box prompt on that image
|
|
4
|
-
* decodes from the cached embedding
|
|
5
|
-
*
|
|
4
|
+
* decodes from the cached embedding, so hover and click prompts stay
|
|
5
|
+
* cheap.
|
|
6
6
|
*/
|
|
7
7
|
import type { ImageInput, Mask, SegmentPrompt, Segmenter } from "./types.js";
|
|
8
8
|
/**
|
|
@@ -26,6 +26,7 @@ export declare class EmbeddingCache<E = unknown> {
|
|
|
26
26
|
clear(): void;
|
|
27
27
|
get size(): number;
|
|
28
28
|
}
|
|
29
|
+
/** The parts of a prompted segmenter: an image encoder run once per image, a prompt decoder, and the embedding cache. */
|
|
29
30
|
export interface PromptSegmenterOptions<E> {
|
|
30
31
|
/** The image encoder: runs once per image. */
|
|
31
32
|
encode(image: ImageInput): Promise<E>;
|
package/dist/segment.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Prompted segmentation with one image embedding per image. The encoder
|
|
3
3
|
* runs once per image; every later point or box prompt on that image
|
|
4
|
-
* decodes from the cached embedding
|
|
5
|
-
*
|
|
4
|
+
* decodes from the cached embedding, so hover and click prompts stay
|
|
5
|
+
* cheap.
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
8
|
* Least recently used embeddings by image. A key is a string the caller
|
package/dist/signals.d.ts
CHANGED
|
@@ -14,11 +14,12 @@
|
|
|
14
14
|
* language model, written only when it changed. Frames never leave the
|
|
15
15
|
* tab: only these signals and the text made from them do.
|
|
16
16
|
*
|
|
17
|
-
* Thresholds below are vendor figures
|
|
18
|
-
* measured here.
|
|
17
|
+
* Thresholds below are vendor figures; none was measured here.
|
|
19
18
|
*/
|
|
20
19
|
import type { Landmarks } from "./types.js";
|
|
20
|
+
/** The hand gestures the tracker reports: a wave from wrist motion, and the canned recognizer gestures by name. */
|
|
21
21
|
export type HandGesture = "wave" | "thumbs_up" | "thumbs_down" | "open_palm" | "victory" | "pointing_up" | "fist" | "love";
|
|
22
|
+
/** Steady signals for one moment: present, where the face is, facing, smile, surprise and frown strengths, and the held gesture. */
|
|
22
23
|
export interface Perception {
|
|
23
24
|
present: boolean;
|
|
24
25
|
/** The face in the viewer's frame, -1 to 1 on both axes: +x the character's left (the person's right), +y up. Null when no face is seen. */
|
|
@@ -34,6 +35,7 @@ export interface Perception {
|
|
|
34
35
|
frown: number;
|
|
35
36
|
gesture: HandGesture | null;
|
|
36
37
|
}
|
|
38
|
+
/** A discrete perception event: someone arrived, left, smiled, or made a gesture. */
|
|
37
39
|
export type PerceptionEvent = {
|
|
38
40
|
type: "arrived";
|
|
39
41
|
} | {
|
|
@@ -55,6 +57,7 @@ export interface RawFace {
|
|
|
55
57
|
surprise: number;
|
|
56
58
|
frown: number;
|
|
57
59
|
}
|
|
60
|
+
/** One hand reading before smoothing: wrist position, the recognizer's canned label and its score. */
|
|
58
61
|
export interface RawHand {
|
|
59
62
|
/** Wrist position. */
|
|
60
63
|
x: number;
|
|
@@ -63,6 +66,7 @@ export interface RawHand {
|
|
|
63
66
|
gesture: string | null;
|
|
64
67
|
score: number;
|
|
65
68
|
}
|
|
69
|
+
/** One frame's readings for {@link SignalTracker}: the face, and the hands when they were checked. */
|
|
66
70
|
export interface RawFrame {
|
|
67
71
|
face: RawFace | null;
|
|
68
72
|
/** Null on frames where hands were not checked. */
|
|
@@ -70,6 +74,7 @@ export interface RawFrame {
|
|
|
70
74
|
}
|
|
71
75
|
/** Canned recognizer labels to gesture names. */
|
|
72
76
|
export declare const CANNED_GESTURES: Readonly<Record<string, HandGesture>>;
|
|
77
|
+
/** Turns raw face and hand frames into steady signals and discrete events, smoothed or held so one noisy frame never fires a reaction. */
|
|
73
78
|
export declare class SignalTracker {
|
|
74
79
|
private p;
|
|
75
80
|
private lastSeen;
|
|
@@ -110,6 +115,7 @@ export declare class SeenNotes {
|
|
|
110
115
|
}
|
|
111
116
|
/** Questions that call for an on demand look rather than the steady signals. Replace it to suit a persona. */
|
|
112
117
|
export declare const LOOK_PATTERN: RegExp;
|
|
118
|
+
/** True when a message asks the character to look, by {@link LOOK_PATTERN} or the pattern you pass. */
|
|
113
119
|
export declare const wantsLook: (text: string, pattern?: RegExp) => boolean;
|
|
114
120
|
/** One reaction to a perception event: a mood or a gesture by common name, after a delay, with a chance. */
|
|
115
121
|
export interface Reaction {
|
package/dist/signals.js
CHANGED
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
* language model, written only when it changed. Frames never leave the
|
|
15
15
|
* tab: only these signals and the text made from them do.
|
|
16
16
|
*
|
|
17
|
-
* Thresholds below are vendor figures
|
|
18
|
-
* measured here.
|
|
17
|
+
* Thresholds below are vendor figures; none was measured here.
|
|
19
18
|
*/
|
|
20
19
|
// all vendor
|
|
21
20
|
const PRESENT_GRACE_MS = 2500;
|
|
@@ -45,6 +44,7 @@ export const CANNED_GESTURES = {
|
|
|
45
44
|
ILoveYou: "love",
|
|
46
45
|
};
|
|
47
46
|
const absent = () => ({ present: false, face: null, facing: false, smile: 0, surprise: 0, frown: 0, gesture: null });
|
|
47
|
+
/** Turns raw face and hand frames into steady signals and discrete events, smoothed or held so one noisy frame never fires a reaction. */
|
|
48
48
|
export class SignalTracker {
|
|
49
49
|
p = absent();
|
|
50
50
|
lastSeen = -Infinity;
|
|
@@ -271,6 +271,7 @@ export class SeenNotes {
|
|
|
271
271
|
}
|
|
272
272
|
/** Questions that call for an on demand look rather than the steady signals. Replace it to suit a persona. */
|
|
273
273
|
export 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;
|
|
274
|
+
/** True when a message asks the character to look, by {@link LOOK_PATTERN} or the pattern you pass. */
|
|
274
275
|
export const wantsLook = (text, pattern = LOOK_PATTERN) => pattern.test(text);
|
|
275
276
|
/** Default reactions (vendor): greet on arrival, smile back after 600 ms at 0.7 chance, answer waves and a few gestures. */
|
|
276
277
|
export const DEFAULT_REACTIONS = [
|