@hackbuild/ai-views 0.1.19 → 0.1.20
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 +1 -1
- package/dist/single/index.iife.js +124 -30
- package/dist/single/index.js +124 -30
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -257,6 +257,6 @@ Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LIC
|
|
|
257
257
|
| `dist/index.js` (main entry, imports external) | 21,695 bytes | 22,779 bytes |
|
|
258
258
|
| `dist/single/elements.iife.js` (single file build) | 104,791 bytes | 110,030 bytes |
|
|
259
259
|
|
|
260
|
-
Measured 2026-12-
|
|
260
|
+
Measured 2026-12-03 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
|
|
261
261
|
tarball. Generated from `tools/size-budget.json`; CI fails when a file moves more than
|
|
262
262
|
5 percent from its row.
|
|
@@ -13667,6 +13667,37 @@ var HackbuildAiViews = (function(exports) {
|
|
|
13667
13667
|
}
|
|
13668
13668
|
];
|
|
13669
13669
|
}));
|
|
13670
|
+
// packages/vision/src/release.ts
|
|
13671
|
+
/**
|
|
13672
|
+
* Disposes every tensor among the values: a tensor itself, tensors in an
|
|
13673
|
+
* array, and tensors among the values of a plain record (a processor's or
|
|
13674
|
+
* a session's output), two levels deep. Anything else is left alone, and a
|
|
13675
|
+
* dispose that throws (already freed) is ignored.
|
|
13676
|
+
* @internal
|
|
13677
|
+
*/
|
|
13678
|
+
function release(...values) {
|
|
13679
|
+
const seen = /* @__PURE__ */ new Set();
|
|
13680
|
+
const walk = (v, depth) => {
|
|
13681
|
+
if (!v || typeof v !== "object" || seen.has(v) || depth > 2) return;
|
|
13682
|
+
seen.add(v);
|
|
13683
|
+
if (isTensor(v)) {
|
|
13684
|
+
try {
|
|
13685
|
+
v.dispose();
|
|
13686
|
+
} catch {}
|
|
13687
|
+
return;
|
|
13688
|
+
}
|
|
13689
|
+
if (Array.isArray(v)) {
|
|
13690
|
+
for (const x of v) walk(x, depth + 1);
|
|
13691
|
+
return;
|
|
13692
|
+
}
|
|
13693
|
+
if (Object.getPrototypeOf(v) === Object.prototype) for (const x of Object.values(v)) walk(x, depth + 1);
|
|
13694
|
+
};
|
|
13695
|
+
for (const v of values) walk(v, 0);
|
|
13696
|
+
}
|
|
13697
|
+
var isTensor;
|
|
13698
|
+
var init_release = __esmMin((() => {
|
|
13699
|
+
isTensor = (v) => !!v && typeof v === "object" && typeof v.dispose === "function" && Array.isArray(v.dims);
|
|
13700
|
+
}));
|
|
13670
13701
|
// packages/vision/src/segment.ts
|
|
13671
13702
|
/** True when the prompt has a point or a box. */
|
|
13672
13703
|
function hasPrompt(p) {
|
|
@@ -13674,29 +13705,59 @@ var HackbuildAiViews = (function(exports) {
|
|
|
13674
13705
|
}
|
|
13675
13706
|
/** A segmenter from an encoder and a decoder, with the embedding cache on `cache`. Masks come best first, scores clamped to 0 to 1. */
|
|
13676
13707
|
function promptSegmenter(o) {
|
|
13677
|
-
const
|
|
13708
|
+
const reading = /* @__PURE__ */ new Map();
|
|
13709
|
+
const evicted = /* @__PURE__ */ new Set();
|
|
13710
|
+
const free = (e) => {
|
|
13711
|
+
if (!o.release) return;
|
|
13712
|
+
if (reading.get(e)) evicted.add(e);
|
|
13713
|
+
else o.release(e);
|
|
13714
|
+
};
|
|
13715
|
+
const own = o.cache ?? new EmbeddingCache(4, free);
|
|
13678
13716
|
const seg = {
|
|
13679
13717
|
cache: own,
|
|
13680
13718
|
async segment(image, prompt = {}, so = {}) {
|
|
13681
13719
|
if (!hasPrompt(prompt)) throw new Error("a prompt needs at least one point or a box");
|
|
13682
13720
|
const emb = await (so.cache ?? own).getOr(so.key ?? image, () => o.encode(image));
|
|
13683
|
-
|
|
13721
|
+
reading.set(emb, (reading.get(emb) ?? 0) + 1);
|
|
13722
|
+
let masks;
|
|
13723
|
+
try {
|
|
13724
|
+
masks = await o.decode(emb, prompt, image);
|
|
13725
|
+
} finally {
|
|
13726
|
+
const n = (reading.get(emb) ?? 1) - 1;
|
|
13727
|
+
if (n > 0) reading.set(emb, n);
|
|
13728
|
+
else {
|
|
13729
|
+
reading.delete(emb);
|
|
13730
|
+
if (evicted.delete(emb)) o.release?.(emb);
|
|
13731
|
+
}
|
|
13732
|
+
}
|
|
13684
13733
|
for (const m of masks) if (m.score !== void 0) m.score = Math.min(1, Math.max(0, m.score));
|
|
13685
13734
|
return masks.sort((a, b) => (b.score ?? 0) - (a.score ?? 0));
|
|
13686
13735
|
}
|
|
13687
13736
|
};
|
|
13688
|
-
|
|
13737
|
+
seg.dispose = () => {
|
|
13738
|
+
own.clear();
|
|
13739
|
+
return o.dispose?.();
|
|
13740
|
+
};
|
|
13689
13741
|
return seg;
|
|
13690
13742
|
}
|
|
13691
13743
|
var EmbeddingCache;
|
|
13692
13744
|
var init_segment = __esmMin((() => {
|
|
13693
13745
|
EmbeddingCache = class {
|
|
13694
13746
|
max;
|
|
13747
|
+
onEvict;
|
|
13695
13748
|
m = /* @__PURE__ */ new Map();
|
|
13696
13749
|
hits = 0;
|
|
13697
13750
|
misses = 0;
|
|
13698
|
-
|
|
13751
|
+
/** `onEvict` gets each embedding that leaves the cache (pushed out, deleted, cleared or replaced), to free it. */
|
|
13752
|
+
constructor(max = 4, onEvict) {
|
|
13699
13753
|
this.max = max;
|
|
13754
|
+
this.onEvict = onEvict;
|
|
13755
|
+
}
|
|
13756
|
+
out(p) {
|
|
13757
|
+
if (p && this.onEvict) {
|
|
13758
|
+
const f = this.onEvict;
|
|
13759
|
+
p.then(f, () => {});
|
|
13760
|
+
}
|
|
13700
13761
|
}
|
|
13701
13762
|
has(key) {
|
|
13702
13763
|
return this.m.has(key);
|
|
@@ -13706,9 +13767,16 @@ var HackbuildAiViews = (function(exports) {
|
|
|
13706
13767
|
return this.m.get(key);
|
|
13707
13768
|
}
|
|
13708
13769
|
set(key, v) {
|
|
13770
|
+
const p = Promise.resolve(v);
|
|
13771
|
+
const was = this.m.get(key);
|
|
13709
13772
|
this.m.delete(key);
|
|
13710
|
-
this.m.set(key,
|
|
13711
|
-
|
|
13773
|
+
this.m.set(key, p);
|
|
13774
|
+
if (was !== p) this.out(was);
|
|
13775
|
+
while (this.m.size > this.max) {
|
|
13776
|
+
const k = this.m.keys().next().value;
|
|
13777
|
+
this.out(this.m.get(k));
|
|
13778
|
+
this.m.delete(k);
|
|
13779
|
+
}
|
|
13712
13780
|
}
|
|
13713
13781
|
/** The embedding for `key`, encoding it with `make` on a miss. A failed encode is not kept. */
|
|
13714
13782
|
getOr(key, make) {
|
|
@@ -13728,9 +13796,11 @@ var HackbuildAiViews = (function(exports) {
|
|
|
13728
13796
|
return p;
|
|
13729
13797
|
}
|
|
13730
13798
|
delete(key) {
|
|
13799
|
+
this.out(this.m.get(key));
|
|
13731
13800
|
return this.m.delete(key);
|
|
13732
13801
|
}
|
|
13733
13802
|
clear() {
|
|
13803
|
+
for (const p of this.m.values()) this.out(p);
|
|
13734
13804
|
this.m.clear();
|
|
13735
13805
|
}
|
|
13736
13806
|
get size() {
|
|
@@ -13821,7 +13891,11 @@ var HackbuildAiViews = (function(exports) {
|
|
|
13821
13891
|
});
|
|
13822
13892
|
const start = inputs.input_ids.dims[inputs.input_ids.dims.length - 1];
|
|
13823
13893
|
const gen = ids.slice ? ids.slice(null, [start, null]) : ids;
|
|
13824
|
-
|
|
13894
|
+
try {
|
|
13895
|
+
return (processor.batch_decode(gen, { skip_special_tokens: true })[0] ?? "").trim();
|
|
13896
|
+
} finally {
|
|
13897
|
+
release(inputs, ids, gen);
|
|
13898
|
+
}
|
|
13825
13899
|
},
|
|
13826
13900
|
dispose: () => model.dispose?.()
|
|
13827
13901
|
};
|
|
@@ -13835,10 +13909,12 @@ var HackbuildAiViews = (function(exports) {
|
|
|
13835
13909
|
async encode(image) {
|
|
13836
13910
|
const raw = await toRaw(ctx.tjs, image);
|
|
13837
13911
|
const inputs = await processor(raw);
|
|
13912
|
+
const emb = await model.get_image_embeddings(inputs);
|
|
13913
|
+
release(inputs);
|
|
13838
13914
|
return {
|
|
13839
13915
|
raw,
|
|
13840
13916
|
inputs,
|
|
13841
|
-
emb
|
|
13917
|
+
emb
|
|
13842
13918
|
};
|
|
13843
13919
|
},
|
|
13844
13920
|
async decode(e, prompt) {
|
|
@@ -13863,26 +13939,33 @@ var HackbuildAiViews = (function(exports) {
|
|
|
13863
13939
|
"input_boxes"
|
|
13864
13940
|
]) if (p[k] !== void 0) feed[k] = p[k];
|
|
13865
13941
|
const out = await model(feed);
|
|
13866
|
-
const
|
|
13867
|
-
|
|
13868
|
-
|
|
13869
|
-
|
|
13870
|
-
const
|
|
13871
|
-
for (let
|
|
13872
|
-
|
|
13873
|
-
|
|
13874
|
-
|
|
13875
|
-
|
|
13876
|
-
|
|
13877
|
-
|
|
13942
|
+
const masks = await processor.post_process_masks(out.pred_masks, e.inputs.original_sizes, e.inputs.reshaped_input_sizes);
|
|
13943
|
+
try {
|
|
13944
|
+
const m = masks[0];
|
|
13945
|
+
const [n, h, w] = m.dims.slice(-3);
|
|
13946
|
+
const res = [];
|
|
13947
|
+
for (let k = 0; k < n; k++) {
|
|
13948
|
+
const data = new Uint8Array(w * h);
|
|
13949
|
+
for (let i = 0; i < w * h; i++) data[i] = m.data[k * w * h + i] ? 255 : 0;
|
|
13950
|
+
res.push({
|
|
13951
|
+
width: w,
|
|
13952
|
+
height: h,
|
|
13953
|
+
data,
|
|
13954
|
+
score: out.iou_scores.data[k] ?? 0
|
|
13955
|
+
});
|
|
13956
|
+
}
|
|
13957
|
+
return res;
|
|
13958
|
+
} finally {
|
|
13959
|
+
release(p, out, masks);
|
|
13878
13960
|
}
|
|
13879
|
-
return res;
|
|
13880
13961
|
},
|
|
13962
|
+
release: (e) => release(e.emb),
|
|
13881
13963
|
dispose: () => model.dispose?.()
|
|
13882
13964
|
});
|
|
13883
13965
|
}
|
|
13884
13966
|
var cls;
|
|
13885
13967
|
var init_loaders = __esmMin((() => {
|
|
13968
|
+
init_release();
|
|
13886
13969
|
init_segment();
|
|
13887
13970
|
cls = (tjs, ...names) => {
|
|
13888
13971
|
for (const n of names) if (tjs[n]) return tjs[n];
|
|
@@ -13914,13 +13997,18 @@ var HackbuildAiViews = (function(exports) {
|
|
|
13914
13997
|
});
|
|
13915
13998
|
const start = inputs.input_ids.dims[inputs.input_ids.dims.length - 1];
|
|
13916
13999
|
const gen = ids.slice ? ids.slice(null, [start, null]) : ids;
|
|
13917
|
-
|
|
14000
|
+
try {
|
|
14001
|
+
return (processor.batch_decode(gen, { skip_special_tokens: true })[0] ?? "").trim();
|
|
14002
|
+
} finally {
|
|
14003
|
+
release(inputs, ids, gen);
|
|
14004
|
+
}
|
|
13918
14005
|
},
|
|
13919
14006
|
dispose: () => model.dispose?.()
|
|
13920
14007
|
};
|
|
13921
14008
|
}
|
|
13922
14009
|
var init_janus = __esmMin((() => {
|
|
13923
14010
|
init_loaders();
|
|
14011
|
+
init_release();
|
|
13924
14012
|
}));
|
|
13925
14013
|
// packages/vision/src/yolo.ts
|
|
13926
14014
|
/** The scale and padding that fit a `w` by `h` image into a `size` square (640 by default), centred. */
|
|
@@ -14070,14 +14158,19 @@ var HackbuildAiViews = (function(exports) {
|
|
|
14070
14158
|
size,
|
|
14071
14159
|
size
|
|
14072
14160
|
]) };
|
|
14073
|
-
const
|
|
14074
|
-
|
|
14075
|
-
|
|
14076
|
-
|
|
14077
|
-
|
|
14078
|
-
|
|
14079
|
-
|
|
14080
|
-
|
|
14161
|
+
const res = await m.session.run(feeds);
|
|
14162
|
+
try {
|
|
14163
|
+
const t = res[m.session.outputNames[0]];
|
|
14164
|
+
const d = {
|
|
14165
|
+
...opts.scoreThreshold !== void 0 ? { scoreThreshold: opts.scoreThreshold } : {},
|
|
14166
|
+
...opts.maxResults !== void 0 ? { max: opts.maxResults } : {},
|
|
14167
|
+
...o.labels ? { labels: o.labels } : {}
|
|
14168
|
+
};
|
|
14169
|
+
const out = t.data;
|
|
14170
|
+
return isEnd2End(t.dims) ? decodeYoloEnd2End(out, t.dims, lb, px, d) : decodeYolo(out, t.dims, lb, px, d);
|
|
14171
|
+
} finally {
|
|
14172
|
+
release(feeds, res);
|
|
14173
|
+
}
|
|
14081
14174
|
},
|
|
14082
14175
|
dispose: () => m.dispose()
|
|
14083
14176
|
};
|
|
@@ -14088,6 +14181,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
14088
14181
|
}
|
|
14089
14182
|
var COCO_LABELS, DETECT_SIZES;
|
|
14090
14183
|
var init_yolo = __esmMin((() => {
|
|
14184
|
+
init_release();
|
|
14091
14185
|
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(",");
|
|
14092
14186
|
DETECT_SIZES = {
|
|
14093
14187
|
n: "yolov10n",
|
package/dist/single/index.js
CHANGED
|
@@ -13665,6 +13665,37 @@ var init_records = __esmMin((() => {
|
|
|
13665
13665
|
}
|
|
13666
13666
|
];
|
|
13667
13667
|
}));
|
|
13668
|
+
// packages/vision/src/release.ts
|
|
13669
|
+
/**
|
|
13670
|
+
* Disposes every tensor among the values: a tensor itself, tensors in an
|
|
13671
|
+
* array, and tensors among the values of a plain record (a processor's or
|
|
13672
|
+
* a session's output), two levels deep. Anything else is left alone, and a
|
|
13673
|
+
* dispose that throws (already freed) is ignored.
|
|
13674
|
+
* @internal
|
|
13675
|
+
*/
|
|
13676
|
+
function release(...values) {
|
|
13677
|
+
const seen = /* @__PURE__ */ new Set();
|
|
13678
|
+
const walk = (v, depth) => {
|
|
13679
|
+
if (!v || typeof v !== "object" || seen.has(v) || depth > 2) return;
|
|
13680
|
+
seen.add(v);
|
|
13681
|
+
if (isTensor(v)) {
|
|
13682
|
+
try {
|
|
13683
|
+
v.dispose();
|
|
13684
|
+
} catch {}
|
|
13685
|
+
return;
|
|
13686
|
+
}
|
|
13687
|
+
if (Array.isArray(v)) {
|
|
13688
|
+
for (const x of v) walk(x, depth + 1);
|
|
13689
|
+
return;
|
|
13690
|
+
}
|
|
13691
|
+
if (Object.getPrototypeOf(v) === Object.prototype) for (const x of Object.values(v)) walk(x, depth + 1);
|
|
13692
|
+
};
|
|
13693
|
+
for (const v of values) walk(v, 0);
|
|
13694
|
+
}
|
|
13695
|
+
var isTensor;
|
|
13696
|
+
var init_release = __esmMin((() => {
|
|
13697
|
+
isTensor = (v) => !!v && typeof v === "object" && typeof v.dispose === "function" && Array.isArray(v.dims);
|
|
13698
|
+
}));
|
|
13668
13699
|
// packages/vision/src/segment.ts
|
|
13669
13700
|
/** True when the prompt has a point or a box. */
|
|
13670
13701
|
function hasPrompt(p) {
|
|
@@ -13672,29 +13703,59 @@ function hasPrompt(p) {
|
|
|
13672
13703
|
}
|
|
13673
13704
|
/** A segmenter from an encoder and a decoder, with the embedding cache on `cache`. Masks come best first, scores clamped to 0 to 1. */
|
|
13674
13705
|
function promptSegmenter(o) {
|
|
13675
|
-
const
|
|
13706
|
+
const reading = /* @__PURE__ */ new Map();
|
|
13707
|
+
const evicted = /* @__PURE__ */ new Set();
|
|
13708
|
+
const free = (e) => {
|
|
13709
|
+
if (!o.release) return;
|
|
13710
|
+
if (reading.get(e)) evicted.add(e);
|
|
13711
|
+
else o.release(e);
|
|
13712
|
+
};
|
|
13713
|
+
const own = o.cache ?? new EmbeddingCache(4, free);
|
|
13676
13714
|
const seg = {
|
|
13677
13715
|
cache: own,
|
|
13678
13716
|
async segment(image, prompt = {}, so = {}) {
|
|
13679
13717
|
if (!hasPrompt(prompt)) throw new Error("a prompt needs at least one point or a box");
|
|
13680
13718
|
const emb = await (so.cache ?? own).getOr(so.key ?? image, () => o.encode(image));
|
|
13681
|
-
|
|
13719
|
+
reading.set(emb, (reading.get(emb) ?? 0) + 1);
|
|
13720
|
+
let masks;
|
|
13721
|
+
try {
|
|
13722
|
+
masks = await o.decode(emb, prompt, image);
|
|
13723
|
+
} finally {
|
|
13724
|
+
const n = (reading.get(emb) ?? 1) - 1;
|
|
13725
|
+
if (n > 0) reading.set(emb, n);
|
|
13726
|
+
else {
|
|
13727
|
+
reading.delete(emb);
|
|
13728
|
+
if (evicted.delete(emb)) o.release?.(emb);
|
|
13729
|
+
}
|
|
13730
|
+
}
|
|
13682
13731
|
for (const m of masks) if (m.score !== void 0) m.score = Math.min(1, Math.max(0, m.score));
|
|
13683
13732
|
return masks.sort((a, b) => (b.score ?? 0) - (a.score ?? 0));
|
|
13684
13733
|
}
|
|
13685
13734
|
};
|
|
13686
|
-
|
|
13735
|
+
seg.dispose = () => {
|
|
13736
|
+
own.clear();
|
|
13737
|
+
return o.dispose?.();
|
|
13738
|
+
};
|
|
13687
13739
|
return seg;
|
|
13688
13740
|
}
|
|
13689
13741
|
var EmbeddingCache;
|
|
13690
13742
|
var init_segment = __esmMin((() => {
|
|
13691
13743
|
EmbeddingCache = class {
|
|
13692
13744
|
max;
|
|
13745
|
+
onEvict;
|
|
13693
13746
|
m = /* @__PURE__ */ new Map();
|
|
13694
13747
|
hits = 0;
|
|
13695
13748
|
misses = 0;
|
|
13696
|
-
|
|
13749
|
+
/** `onEvict` gets each embedding that leaves the cache (pushed out, deleted, cleared or replaced), to free it. */
|
|
13750
|
+
constructor(max = 4, onEvict) {
|
|
13697
13751
|
this.max = max;
|
|
13752
|
+
this.onEvict = onEvict;
|
|
13753
|
+
}
|
|
13754
|
+
out(p) {
|
|
13755
|
+
if (p && this.onEvict) {
|
|
13756
|
+
const f = this.onEvict;
|
|
13757
|
+
p.then(f, () => {});
|
|
13758
|
+
}
|
|
13698
13759
|
}
|
|
13699
13760
|
has(key) {
|
|
13700
13761
|
return this.m.has(key);
|
|
@@ -13704,9 +13765,16 @@ var init_segment = __esmMin((() => {
|
|
|
13704
13765
|
return this.m.get(key);
|
|
13705
13766
|
}
|
|
13706
13767
|
set(key, v) {
|
|
13768
|
+
const p = Promise.resolve(v);
|
|
13769
|
+
const was = this.m.get(key);
|
|
13707
13770
|
this.m.delete(key);
|
|
13708
|
-
this.m.set(key,
|
|
13709
|
-
|
|
13771
|
+
this.m.set(key, p);
|
|
13772
|
+
if (was !== p) this.out(was);
|
|
13773
|
+
while (this.m.size > this.max) {
|
|
13774
|
+
const k = this.m.keys().next().value;
|
|
13775
|
+
this.out(this.m.get(k));
|
|
13776
|
+
this.m.delete(k);
|
|
13777
|
+
}
|
|
13710
13778
|
}
|
|
13711
13779
|
/** The embedding for `key`, encoding it with `make` on a miss. A failed encode is not kept. */
|
|
13712
13780
|
getOr(key, make) {
|
|
@@ -13726,9 +13794,11 @@ var init_segment = __esmMin((() => {
|
|
|
13726
13794
|
return p;
|
|
13727
13795
|
}
|
|
13728
13796
|
delete(key) {
|
|
13797
|
+
this.out(this.m.get(key));
|
|
13729
13798
|
return this.m.delete(key);
|
|
13730
13799
|
}
|
|
13731
13800
|
clear() {
|
|
13801
|
+
for (const p of this.m.values()) this.out(p);
|
|
13732
13802
|
this.m.clear();
|
|
13733
13803
|
}
|
|
13734
13804
|
get size() {
|
|
@@ -13819,7 +13889,11 @@ async function vlmLoader(ctx) {
|
|
|
13819
13889
|
});
|
|
13820
13890
|
const start = inputs.input_ids.dims[inputs.input_ids.dims.length - 1];
|
|
13821
13891
|
const gen = ids.slice ? ids.slice(null, [start, null]) : ids;
|
|
13822
|
-
|
|
13892
|
+
try {
|
|
13893
|
+
return (processor.batch_decode(gen, { skip_special_tokens: true })[0] ?? "").trim();
|
|
13894
|
+
} finally {
|
|
13895
|
+
release(inputs, ids, gen);
|
|
13896
|
+
}
|
|
13823
13897
|
},
|
|
13824
13898
|
dispose: () => model.dispose?.()
|
|
13825
13899
|
};
|
|
@@ -13833,10 +13907,12 @@ async function samLoader(ctx) {
|
|
|
13833
13907
|
async encode(image) {
|
|
13834
13908
|
const raw = await toRaw(ctx.tjs, image);
|
|
13835
13909
|
const inputs = await processor(raw);
|
|
13910
|
+
const emb = await model.get_image_embeddings(inputs);
|
|
13911
|
+
release(inputs);
|
|
13836
13912
|
return {
|
|
13837
13913
|
raw,
|
|
13838
13914
|
inputs,
|
|
13839
|
-
emb
|
|
13915
|
+
emb
|
|
13840
13916
|
};
|
|
13841
13917
|
},
|
|
13842
13918
|
async decode(e, prompt) {
|
|
@@ -13861,26 +13937,33 @@ async function samLoader(ctx) {
|
|
|
13861
13937
|
"input_boxes"
|
|
13862
13938
|
]) if (p[k] !== void 0) feed[k] = p[k];
|
|
13863
13939
|
const out = await model(feed);
|
|
13864
|
-
const
|
|
13865
|
-
|
|
13866
|
-
|
|
13867
|
-
|
|
13868
|
-
const
|
|
13869
|
-
for (let
|
|
13870
|
-
|
|
13871
|
-
|
|
13872
|
-
|
|
13873
|
-
|
|
13874
|
-
|
|
13875
|
-
|
|
13940
|
+
const masks = await processor.post_process_masks(out.pred_masks, e.inputs.original_sizes, e.inputs.reshaped_input_sizes);
|
|
13941
|
+
try {
|
|
13942
|
+
const m = masks[0];
|
|
13943
|
+
const [n, h, w] = m.dims.slice(-3);
|
|
13944
|
+
const res = [];
|
|
13945
|
+
for (let k = 0; k < n; k++) {
|
|
13946
|
+
const data = new Uint8Array(w * h);
|
|
13947
|
+
for (let i = 0; i < w * h; i++) data[i] = m.data[k * w * h + i] ? 255 : 0;
|
|
13948
|
+
res.push({
|
|
13949
|
+
width: w,
|
|
13950
|
+
height: h,
|
|
13951
|
+
data,
|
|
13952
|
+
score: out.iou_scores.data[k] ?? 0
|
|
13953
|
+
});
|
|
13954
|
+
}
|
|
13955
|
+
return res;
|
|
13956
|
+
} finally {
|
|
13957
|
+
release(p, out, masks);
|
|
13876
13958
|
}
|
|
13877
|
-
return res;
|
|
13878
13959
|
},
|
|
13960
|
+
release: (e) => release(e.emb),
|
|
13879
13961
|
dispose: () => model.dispose?.()
|
|
13880
13962
|
});
|
|
13881
13963
|
}
|
|
13882
13964
|
var cls;
|
|
13883
13965
|
var init_loaders = __esmMin((() => {
|
|
13966
|
+
init_release();
|
|
13884
13967
|
init_segment();
|
|
13885
13968
|
cls = (tjs, ...names) => {
|
|
13886
13969
|
for (const n of names) if (tjs[n]) return tjs[n];
|
|
@@ -13912,13 +13995,18 @@ async function janusLoader(ctx) {
|
|
|
13912
13995
|
});
|
|
13913
13996
|
const start = inputs.input_ids.dims[inputs.input_ids.dims.length - 1];
|
|
13914
13997
|
const gen = ids.slice ? ids.slice(null, [start, null]) : ids;
|
|
13915
|
-
|
|
13998
|
+
try {
|
|
13999
|
+
return (processor.batch_decode(gen, { skip_special_tokens: true })[0] ?? "").trim();
|
|
14000
|
+
} finally {
|
|
14001
|
+
release(inputs, ids, gen);
|
|
14002
|
+
}
|
|
13916
14003
|
},
|
|
13917
14004
|
dispose: () => model.dispose?.()
|
|
13918
14005
|
};
|
|
13919
14006
|
}
|
|
13920
14007
|
var init_janus = __esmMin((() => {
|
|
13921
14008
|
init_loaders();
|
|
14009
|
+
init_release();
|
|
13922
14010
|
}));
|
|
13923
14011
|
// packages/vision/src/yolo.ts
|
|
13924
14012
|
/** The scale and padding that fit a `w` by `h` image into a `size` square (640 by default), centred. */
|
|
@@ -14068,14 +14156,19 @@ function yoloDetector(m, o = {}) {
|
|
|
14068
14156
|
size,
|
|
14069
14157
|
size
|
|
14070
14158
|
]) };
|
|
14071
|
-
const
|
|
14072
|
-
|
|
14073
|
-
|
|
14074
|
-
|
|
14075
|
-
|
|
14076
|
-
|
|
14077
|
-
|
|
14078
|
-
|
|
14159
|
+
const res = await m.session.run(feeds);
|
|
14160
|
+
try {
|
|
14161
|
+
const t = res[m.session.outputNames[0]];
|
|
14162
|
+
const d = {
|
|
14163
|
+
...opts.scoreThreshold !== void 0 ? { scoreThreshold: opts.scoreThreshold } : {},
|
|
14164
|
+
...opts.maxResults !== void 0 ? { max: opts.maxResults } : {},
|
|
14165
|
+
...o.labels ? { labels: o.labels } : {}
|
|
14166
|
+
};
|
|
14167
|
+
const out = t.data;
|
|
14168
|
+
return isEnd2End(t.dims) ? decodeYoloEnd2End(out, t.dims, lb, px, d) : decodeYolo(out, t.dims, lb, px, d);
|
|
14169
|
+
} finally {
|
|
14170
|
+
release(feeds, res);
|
|
14171
|
+
}
|
|
14079
14172
|
},
|
|
14080
14173
|
dispose: () => m.dispose()
|
|
14081
14174
|
};
|
|
@@ -14086,6 +14179,7 @@ function detectCadenceMs(lastLatencyMs) {
|
|
|
14086
14179
|
}
|
|
14087
14180
|
var COCO_LABELS, DETECT_SIZES;
|
|
14088
14181
|
var init_yolo = __esmMin((() => {
|
|
14182
|
+
init_release();
|
|
14089
14183
|
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(",");
|
|
14090
14184
|
DETECT_SIZES = {
|
|
14091
14185
|
n: "yolov10n",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hackbuild/ai-views",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "Views that bind the browser AI packages to hackbuild-ui: a model picker per job, a chat pane and composer, a drop first transcriber, a mask studio, a frame view and a camera feed. Each ships as a Vue component and a custom element.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@hackbuild/models": "0.2.5",
|
|
52
52
|
"@hackbuild/speak": "0.1.7",
|
|
53
53
|
"@hackbuild/transcribe": "0.1.7",
|
|
54
|
-
"@hackbuild/vision": "0.3.
|
|
54
|
+
"@hackbuild/vision": "0.3.1",
|
|
55
55
|
"@hackbuild/weights": "0.1.4"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|