@camstack/addon-vision 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/addons/animal-classifier/index.d.mts +6 -1
- package/dist/addons/animal-classifier/index.d.ts +6 -1
- package/dist/addons/animal-classifier/index.js +513 -49
- package/dist/addons/animal-classifier/index.js.map +1 -1
- package/dist/addons/animal-classifier/index.mjs +6 -4
- package/dist/addons/audio-classification/index.d.mts +6 -1
- package/dist/addons/audio-classification/index.d.ts +6 -1
- package/dist/addons/audio-classification/index.js +86 -26
- package/dist/addons/audio-classification/index.js.map +1 -1
- package/dist/addons/audio-classification/index.mjs +3 -2
- package/dist/addons/bird-global-classifier/index.d.mts +6 -1
- package/dist/addons/bird-global-classifier/index.d.ts +6 -1
- package/dist/addons/bird-global-classifier/index.js +514 -50
- package/dist/addons/bird-global-classifier/index.js.map +1 -1
- package/dist/addons/bird-global-classifier/index.mjs +6 -4
- package/dist/addons/bird-nabirds-classifier/index.d.mts +6 -1
- package/dist/addons/bird-nabirds-classifier/index.d.ts +6 -1
- package/dist/addons/bird-nabirds-classifier/index.js +523 -60
- package/dist/addons/bird-nabirds-classifier/index.js.map +1 -1
- package/dist/addons/bird-nabirds-classifier/index.mjs +6 -4
- package/dist/addons/face-detection/index.d.mts +6 -1
- package/dist/addons/face-detection/index.d.ts +6 -1
- package/dist/addons/face-detection/index.js +538 -39
- package/dist/addons/face-detection/index.js.map +1 -1
- package/dist/addons/face-detection/index.mjs +5 -3
- package/dist/addons/face-recognition/index.d.mts +6 -1
- package/dist/addons/face-recognition/index.d.ts +6 -1
- package/dist/addons/face-recognition/index.js +487 -33
- package/dist/addons/face-recognition/index.js.map +1 -1
- package/dist/addons/face-recognition/index.mjs +5 -3
- package/dist/addons/motion-detection/index.d.mts +3 -1
- package/dist/addons/motion-detection/index.d.ts +3 -1
- package/dist/addons/motion-detection/index.js +11 -3
- package/dist/addons/motion-detection/index.js.map +1 -1
- package/dist/addons/motion-detection/index.mjs +140 -3
- package/dist/addons/motion-detection/index.mjs.map +1 -1
- package/dist/addons/object-detection/index.d.mts +6 -1
- package/dist/addons/object-detection/index.d.ts +6 -1
- package/dist/addons/object-detection/index.js +369 -72
- package/dist/addons/object-detection/index.js.map +1 -1
- package/dist/addons/object-detection/index.mjs +5 -3
- package/dist/addons/plate-detection/index.d.mts +6 -1
- package/dist/addons/plate-detection/index.d.ts +6 -1
- package/dist/addons/plate-detection/index.js +531 -31
- package/dist/addons/plate-detection/index.js.map +1 -1
- package/dist/addons/plate-detection/index.mjs +5 -3
- package/dist/addons/plate-recognition/index.d.mts +7 -1
- package/dist/addons/plate-recognition/index.d.ts +7 -1
- package/dist/addons/plate-recognition/index.js +176 -44
- package/dist/addons/plate-recognition/index.js.map +1 -1
- package/dist/addons/plate-recognition/index.mjs +4 -3
- package/dist/addons/segmentation-refiner/index.d.mts +30 -0
- package/dist/addons/segmentation-refiner/index.d.ts +30 -0
- package/dist/addons/segmentation-refiner/index.js +1048 -0
- package/dist/addons/segmentation-refiner/index.js.map +1 -0
- package/dist/addons/segmentation-refiner/index.mjs +209 -0
- package/dist/addons/segmentation-refiner/index.mjs.map +1 -0
- package/dist/addons/vehicle-classifier/index.d.mts +31 -0
- package/dist/addons/vehicle-classifier/index.d.ts +31 -0
- package/dist/addons/vehicle-classifier/index.js +688 -0
- package/dist/addons/vehicle-classifier/index.js.map +1 -0
- package/dist/addons/vehicle-classifier/index.mjs +250 -0
- package/dist/addons/vehicle-classifier/index.mjs.map +1 -0
- package/dist/{chunk-6OR5TE7A.mjs → chunk-22BHCDT5.mjs} +2 -2
- package/dist/chunk-22BHCDT5.mjs.map +1 -0
- package/dist/{chunk-LPI42WL6.mjs → chunk-2IOKI4ES.mjs} +23 -12
- package/dist/chunk-2IOKI4ES.mjs.map +1 -0
- package/dist/chunk-7DYHXUPZ.mjs +36 -0
- package/dist/chunk-7DYHXUPZ.mjs.map +1 -0
- package/dist/chunk-BJTO5JO5.mjs +11 -0
- package/dist/chunk-BP7H4NFS.mjs +412 -0
- package/dist/chunk-BP7H4NFS.mjs.map +1 -0
- package/dist/chunk-BR2FPGOX.mjs +98 -0
- package/dist/chunk-BR2FPGOX.mjs.map +1 -0
- package/dist/{chunk-5AIQSN32.mjs → chunk-D6WEHN33.mjs} +66 -17
- package/dist/chunk-D6WEHN33.mjs.map +1 -0
- package/dist/{chunk-3MQFUDRU.mjs → chunk-DRYFGARD.mjs} +76 -47
- package/dist/chunk-DRYFGARD.mjs.map +1 -0
- package/dist/{chunk-ISOIDU4U.mjs → chunk-DUN6XU3N.mjs} +23 -5
- package/dist/chunk-DUN6XU3N.mjs.map +1 -0
- package/dist/{chunk-MEVASN3P.mjs → chunk-ESLHNWWE.mjs} +104 -22
- package/dist/chunk-ESLHNWWE.mjs.map +1 -0
- package/dist/{chunk-B3R66MPF.mjs → chunk-JUQEW6ON.mjs} +58 -21
- package/dist/chunk-JUQEW6ON.mjs.map +1 -0
- package/dist/{chunk-AYBFB7ID.mjs → chunk-R5J3WAUI.mjs} +200 -318
- package/dist/chunk-R5J3WAUI.mjs.map +1 -0
- package/dist/chunk-XZ6ZMXXU.mjs +39 -0
- package/dist/chunk-XZ6ZMXXU.mjs.map +1 -0
- package/dist/{chunk-5JJZGKL7.mjs → chunk-YPU4WTXZ.mjs} +102 -19
- package/dist/chunk-YPU4WTXZ.mjs.map +1 -0
- package/dist/{chunk-J4WRYHHY.mjs → chunk-YUCD2TFH.mjs} +66 -36
- package/dist/chunk-YUCD2TFH.mjs.map +1 -0
- package/dist/{chunk-PDSHDDPV.mjs → chunk-ZTJENCFC.mjs} +159 -35
- package/dist/chunk-ZTJENCFC.mjs.map +1 -0
- package/dist/{chunk-Q3SQOYG6.mjs → chunk-ZWYXXCXP.mjs} +67 -37
- package/dist/chunk-ZWYXXCXP.mjs.map +1 -0
- package/dist/index.d.mts +17 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.js +1343 -550
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +191 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +94 -18
- package/python/coreml_inference.py +61 -18
- package/python/openvino_inference.py +12 -4
- package/python/pytorch_inference.py +12 -4
- package/dist/addons/camera-native-detection/index.d.mts +0 -32
- package/dist/addons/camera-native-detection/index.d.ts +0 -32
- package/dist/addons/camera-native-detection/index.js +0 -99
- package/dist/addons/camera-native-detection/index.js.map +0 -1
- package/dist/addons/camera-native-detection/index.mjs +0 -7
- package/dist/chunk-3MQFUDRU.mjs.map +0 -1
- package/dist/chunk-5AIQSN32.mjs.map +0 -1
- package/dist/chunk-5JJZGKL7.mjs.map +0 -1
- package/dist/chunk-6OR5TE7A.mjs.map +0 -1
- package/dist/chunk-AYBFB7ID.mjs.map +0 -1
- package/dist/chunk-B3R66MPF.mjs.map +0 -1
- package/dist/chunk-DTOAB2CE.mjs +0 -79
- package/dist/chunk-DTOAB2CE.mjs.map +0 -1
- package/dist/chunk-ISOIDU4U.mjs.map +0 -1
- package/dist/chunk-J4WRYHHY.mjs.map +0 -1
- package/dist/chunk-LPI42WL6.mjs.map +0 -1
- package/dist/chunk-MEVASN3P.mjs.map +0 -1
- package/dist/chunk-PDSHDDPV.mjs.map +0 -1
- package/dist/chunk-Q3SQOYG6.mjs.map +0 -1
- package/dist/chunk-QIMDG34B.mjs +0 -229
- package/dist/chunk-QIMDG34B.mjs.map +0 -1
- package/python/__pycache__/coreml_inference.cpython-313.pyc +0 -0
- package/python/__pycache__/openvino_inference.cpython-313.pyc +0 -0
- package/python/__pycache__/pytorch_inference.cpython-313.pyc +0 -0
- /package/dist/{addons/camera-native-detection/index.mjs.map → chunk-BJTO5JO5.mjs.map} +0 -0
|
@@ -0,0 +1,1048 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/addons/segmentation-refiner/index.ts
|
|
31
|
+
var segmentation_refiner_exports = {};
|
|
32
|
+
__export(segmentation_refiner_exports, {
|
|
33
|
+
default: () => SegmentationRefinerAddon
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(segmentation_refiner_exports);
|
|
36
|
+
|
|
37
|
+
// src/catalogs/segmentation-refiner-models.ts
|
|
38
|
+
var import_types2 = require("@camstack/types");
|
|
39
|
+
|
|
40
|
+
// src/catalogs/object-detection-models.ts
|
|
41
|
+
var import_types = require("@camstack/types");
|
|
42
|
+
var HF_REPO = "camstack/camstack-models";
|
|
43
|
+
var MLPACKAGE_FILES = [
|
|
44
|
+
"Manifest.json",
|
|
45
|
+
"Data/com.apple.CoreML/model.mlmodel",
|
|
46
|
+
"Data/com.apple.CoreML/weights/weight.bin"
|
|
47
|
+
];
|
|
48
|
+
var OBJECT_DETECTION_MODELS = [
|
|
49
|
+
// ── YOLOv8 ──────────────────────────────────────────────────────
|
|
50
|
+
{
|
|
51
|
+
id: "yolov8n",
|
|
52
|
+
name: "YOLOv8 Nano",
|
|
53
|
+
description: "YOLOv8 Nano \u2014 fastest, smallest object detection model",
|
|
54
|
+
inputSize: { width: 640, height: 640 },
|
|
55
|
+
labels: import_types.COCO_80_LABELS,
|
|
56
|
+
formats: {
|
|
57
|
+
onnx: {
|
|
58
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/onnx/camstack-yolov8n.onnx"),
|
|
59
|
+
sizeMB: 12
|
|
60
|
+
},
|
|
61
|
+
coreml: {
|
|
62
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/coreml/camstack-yolov8n.mlpackage"),
|
|
63
|
+
sizeMB: 6,
|
|
64
|
+
isDirectory: true,
|
|
65
|
+
files: MLPACKAGE_FILES,
|
|
66
|
+
runtimes: ["python"]
|
|
67
|
+
},
|
|
68
|
+
openvino: {
|
|
69
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/openvino/camstack-yolov8n.xml"),
|
|
70
|
+
sizeMB: 7,
|
|
71
|
+
runtimes: ["python"]
|
|
72
|
+
},
|
|
73
|
+
tflite: {
|
|
74
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/tflite/camstack-yolov8n_float32.tflite"),
|
|
75
|
+
sizeMB: 12,
|
|
76
|
+
runtimes: ["python"]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "yolov8s",
|
|
82
|
+
name: "YOLOv8 Small",
|
|
83
|
+
description: "YOLOv8 Small \u2014 balanced speed and accuracy",
|
|
84
|
+
inputSize: { width: 640, height: 640 },
|
|
85
|
+
labels: import_types.COCO_80_LABELS,
|
|
86
|
+
formats: {
|
|
87
|
+
onnx: {
|
|
88
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/onnx/camstack-yolov8s.onnx"),
|
|
89
|
+
sizeMB: 43
|
|
90
|
+
},
|
|
91
|
+
coreml: {
|
|
92
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/coreml/camstack-yolov8s.mlpackage"),
|
|
93
|
+
sizeMB: 21,
|
|
94
|
+
isDirectory: true,
|
|
95
|
+
files: MLPACKAGE_FILES,
|
|
96
|
+
runtimes: ["python"]
|
|
97
|
+
},
|
|
98
|
+
openvino: {
|
|
99
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/openvino/camstack-yolov8s.xml"),
|
|
100
|
+
sizeMB: 22,
|
|
101
|
+
runtimes: ["python"]
|
|
102
|
+
},
|
|
103
|
+
tflite: {
|
|
104
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/tflite/camstack-yolov8s_float32.tflite"),
|
|
105
|
+
sizeMB: 43,
|
|
106
|
+
runtimes: ["python"]
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: "yolov8s-relu",
|
|
112
|
+
name: "YOLOv8 Small ReLU",
|
|
113
|
+
description: "YOLOv8 Small with ReLU activation \u2014 better hardware compatibility",
|
|
114
|
+
inputSize: { width: 640, height: 640 },
|
|
115
|
+
labels: import_types.COCO_80_LABELS,
|
|
116
|
+
formats: {
|
|
117
|
+
onnx: {
|
|
118
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/onnx/camstack-yolov8s-relu.onnx"),
|
|
119
|
+
sizeMB: 43
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: "yolov8m",
|
|
125
|
+
name: "YOLOv8 Medium",
|
|
126
|
+
description: "YOLOv8 Medium \u2014 higher accuracy, moderate size",
|
|
127
|
+
inputSize: { width: 640, height: 640 },
|
|
128
|
+
labels: import_types.COCO_80_LABELS,
|
|
129
|
+
formats: {
|
|
130
|
+
onnx: {
|
|
131
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/onnx/camstack-yolov8m.onnx"),
|
|
132
|
+
sizeMB: 99
|
|
133
|
+
},
|
|
134
|
+
coreml: {
|
|
135
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/coreml/camstack-yolov8m.mlpackage"),
|
|
136
|
+
sizeMB: 49,
|
|
137
|
+
isDirectory: true,
|
|
138
|
+
files: MLPACKAGE_FILES,
|
|
139
|
+
runtimes: ["python"]
|
|
140
|
+
},
|
|
141
|
+
openvino: {
|
|
142
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/openvino/camstack-yolov8m.xml"),
|
|
143
|
+
sizeMB: 50,
|
|
144
|
+
runtimes: ["python"]
|
|
145
|
+
},
|
|
146
|
+
tflite: {
|
|
147
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/tflite/camstack-yolov8m_float32.tflite"),
|
|
148
|
+
sizeMB: 99,
|
|
149
|
+
runtimes: ["python"]
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: "yolov8l",
|
|
155
|
+
name: "YOLOv8 Large",
|
|
156
|
+
description: "YOLOv8 Large \u2014 high-accuracy large model",
|
|
157
|
+
inputSize: { width: 640, height: 640 },
|
|
158
|
+
labels: import_types.COCO_80_LABELS,
|
|
159
|
+
formats: {
|
|
160
|
+
onnx: {
|
|
161
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/onnx/camstack-yolov8l.onnx"),
|
|
162
|
+
sizeMB: 167
|
|
163
|
+
},
|
|
164
|
+
coreml: {
|
|
165
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/coreml/camstack-yolov8l.mlpackage"),
|
|
166
|
+
sizeMB: 83,
|
|
167
|
+
isDirectory: true,
|
|
168
|
+
files: MLPACKAGE_FILES,
|
|
169
|
+
runtimes: ["python"]
|
|
170
|
+
},
|
|
171
|
+
openvino: {
|
|
172
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/openvino/camstack-yolov8l.xml"),
|
|
173
|
+
sizeMB: 84,
|
|
174
|
+
runtimes: ["python"]
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
id: "yolov8x",
|
|
180
|
+
name: "YOLOv8 Extra-Large",
|
|
181
|
+
description: "YOLOv8 Extra-Large \u2014 maximum accuracy",
|
|
182
|
+
inputSize: { width: 640, height: 640 },
|
|
183
|
+
labels: import_types.COCO_80_LABELS,
|
|
184
|
+
formats: {
|
|
185
|
+
onnx: {
|
|
186
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/onnx/camstack-yolov8x.onnx"),
|
|
187
|
+
sizeMB: 260
|
|
188
|
+
},
|
|
189
|
+
coreml: {
|
|
190
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/coreml/camstack-yolov8x.mlpackage"),
|
|
191
|
+
sizeMB: 130,
|
|
192
|
+
isDirectory: true,
|
|
193
|
+
files: MLPACKAGE_FILES,
|
|
194
|
+
runtimes: ["python"]
|
|
195
|
+
},
|
|
196
|
+
openvino: {
|
|
197
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov8/openvino/camstack-yolov8x.xml"),
|
|
198
|
+
sizeMB: 131,
|
|
199
|
+
runtimes: ["python"]
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
// ── YOLOv9 ──────────────────────────────────────────────────────
|
|
204
|
+
{
|
|
205
|
+
id: "yolov9t",
|
|
206
|
+
name: "YOLOv9 Tiny",
|
|
207
|
+
description: "YOLOv9 Tiny \u2014 ultra-lightweight next-gen detector",
|
|
208
|
+
inputSize: { width: 640, height: 640 },
|
|
209
|
+
labels: import_types.COCO_80_LABELS,
|
|
210
|
+
formats: {
|
|
211
|
+
onnx: {
|
|
212
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov9/onnx/camstack-yolov9t.onnx"),
|
|
213
|
+
sizeMB: 8
|
|
214
|
+
},
|
|
215
|
+
coreml: {
|
|
216
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov9/coreml/camstack-yolov9t.mlpackage"),
|
|
217
|
+
sizeMB: 4,
|
|
218
|
+
isDirectory: true,
|
|
219
|
+
files: MLPACKAGE_FILES,
|
|
220
|
+
runtimes: ["python"]
|
|
221
|
+
},
|
|
222
|
+
openvino: {
|
|
223
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov9/openvino/camstack-yolov9t.xml"),
|
|
224
|
+
sizeMB: 6,
|
|
225
|
+
runtimes: ["python"]
|
|
226
|
+
},
|
|
227
|
+
tflite: {
|
|
228
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov9/tflite/camstack-yolov9t_float32.tflite"),
|
|
229
|
+
sizeMB: 8,
|
|
230
|
+
runtimes: ["python"]
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
id: "yolov9s",
|
|
236
|
+
name: "YOLOv9 Small",
|
|
237
|
+
description: "YOLOv9 Small \u2014 improved efficiency over YOLOv8s",
|
|
238
|
+
inputSize: { width: 640, height: 640 },
|
|
239
|
+
labels: import_types.COCO_80_LABELS,
|
|
240
|
+
formats: {
|
|
241
|
+
onnx: {
|
|
242
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov9/onnx/camstack-yolov9s.onnx"),
|
|
243
|
+
sizeMB: 28
|
|
244
|
+
},
|
|
245
|
+
coreml: {
|
|
246
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov9/coreml/camstack-yolov9s.mlpackage"),
|
|
247
|
+
sizeMB: 14,
|
|
248
|
+
isDirectory: true,
|
|
249
|
+
files: MLPACKAGE_FILES,
|
|
250
|
+
runtimes: ["python"]
|
|
251
|
+
},
|
|
252
|
+
openvino: {
|
|
253
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov9/openvino/camstack-yolov9s.xml"),
|
|
254
|
+
sizeMB: 16,
|
|
255
|
+
runtimes: ["python"]
|
|
256
|
+
},
|
|
257
|
+
tflite: {
|
|
258
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov9/tflite/camstack-yolov9s_float32.tflite"),
|
|
259
|
+
sizeMB: 28,
|
|
260
|
+
runtimes: ["python"]
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
id: "yolov9c",
|
|
266
|
+
name: "YOLOv9 C",
|
|
267
|
+
description: "YOLOv9 C \u2014 high-accuracy compact model",
|
|
268
|
+
inputSize: { width: 640, height: 640 },
|
|
269
|
+
labels: import_types.COCO_80_LABELS,
|
|
270
|
+
formats: {
|
|
271
|
+
onnx: {
|
|
272
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov9/onnx/camstack-yolov9c.onnx"),
|
|
273
|
+
sizeMB: 97
|
|
274
|
+
},
|
|
275
|
+
coreml: {
|
|
276
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov9/coreml/camstack-yolov9c.mlpackage"),
|
|
277
|
+
sizeMB: 48,
|
|
278
|
+
isDirectory: true,
|
|
279
|
+
files: MLPACKAGE_FILES,
|
|
280
|
+
runtimes: ["python"]
|
|
281
|
+
},
|
|
282
|
+
openvino: {
|
|
283
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov9/openvino/camstack-yolov9c.xml"),
|
|
284
|
+
sizeMB: 49,
|
|
285
|
+
runtimes: ["python"]
|
|
286
|
+
},
|
|
287
|
+
tflite: {
|
|
288
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolov9/tflite/camstack-yolov9c_float32.tflite"),
|
|
289
|
+
sizeMB: 97,
|
|
290
|
+
runtimes: ["python"]
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
// ── YOLO11 ────────────────────────────────────────────────────
|
|
295
|
+
{
|
|
296
|
+
id: "yolo11n",
|
|
297
|
+
name: "YOLO11 Nano",
|
|
298
|
+
description: "YOLO11 Nano \u2014 fastest, smallest YOLO11 detection model (mAP 39.5)",
|
|
299
|
+
inputSize: { width: 640, height: 640 },
|
|
300
|
+
labels: import_types.COCO_80_LABELS,
|
|
301
|
+
formats: {
|
|
302
|
+
onnx: {
|
|
303
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/onnx/camstack-yolo11n.onnx"),
|
|
304
|
+
sizeMB: 10
|
|
305
|
+
},
|
|
306
|
+
coreml: {
|
|
307
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/coreml/camstack-yolo11n.mlpackage"),
|
|
308
|
+
sizeMB: 5,
|
|
309
|
+
isDirectory: true,
|
|
310
|
+
files: MLPACKAGE_FILES,
|
|
311
|
+
runtimes: ["python"]
|
|
312
|
+
},
|
|
313
|
+
openvino: {
|
|
314
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/openvino/camstack-yolo11n.xml"),
|
|
315
|
+
sizeMB: 5,
|
|
316
|
+
runtimes: ["python"]
|
|
317
|
+
},
|
|
318
|
+
tflite: {
|
|
319
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/tflite/camstack-yolo11n_float32.tflite"),
|
|
320
|
+
sizeMB: 10,
|
|
321
|
+
runtimes: ["python"]
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
id: "yolo11s",
|
|
327
|
+
name: "YOLO11 Small",
|
|
328
|
+
description: "YOLO11 Small \u2014 balanced speed and accuracy (mAP 47.0)",
|
|
329
|
+
inputSize: { width: 640, height: 640 },
|
|
330
|
+
labels: import_types.COCO_80_LABELS,
|
|
331
|
+
formats: {
|
|
332
|
+
onnx: {
|
|
333
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/onnx/camstack-yolo11s.onnx"),
|
|
334
|
+
sizeMB: 36
|
|
335
|
+
},
|
|
336
|
+
coreml: {
|
|
337
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/coreml/camstack-yolo11s.mlpackage"),
|
|
338
|
+
sizeMB: 18,
|
|
339
|
+
isDirectory: true,
|
|
340
|
+
files: MLPACKAGE_FILES,
|
|
341
|
+
runtimes: ["python"]
|
|
342
|
+
},
|
|
343
|
+
openvino: {
|
|
344
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/openvino/camstack-yolo11s.xml"),
|
|
345
|
+
sizeMB: 18,
|
|
346
|
+
runtimes: ["python"]
|
|
347
|
+
},
|
|
348
|
+
tflite: {
|
|
349
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/tflite/camstack-yolo11s_float32.tflite"),
|
|
350
|
+
sizeMB: 36,
|
|
351
|
+
runtimes: ["python"]
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
id: "yolo11m",
|
|
357
|
+
name: "YOLO11 Medium",
|
|
358
|
+
description: "YOLO11 Medium \u2014 higher accuracy, moderate size (mAP 51.5)",
|
|
359
|
+
inputSize: { width: 640, height: 640 },
|
|
360
|
+
labels: import_types.COCO_80_LABELS,
|
|
361
|
+
formats: {
|
|
362
|
+
onnx: {
|
|
363
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/onnx/camstack-yolo11m.onnx"),
|
|
364
|
+
sizeMB: 77
|
|
365
|
+
},
|
|
366
|
+
coreml: {
|
|
367
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/coreml/camstack-yolo11m.mlpackage"),
|
|
368
|
+
sizeMB: 39,
|
|
369
|
+
isDirectory: true,
|
|
370
|
+
files: MLPACKAGE_FILES,
|
|
371
|
+
runtimes: ["python"]
|
|
372
|
+
},
|
|
373
|
+
openvino: {
|
|
374
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/openvino/camstack-yolo11m.xml"),
|
|
375
|
+
sizeMB: 39,
|
|
376
|
+
runtimes: ["python"]
|
|
377
|
+
},
|
|
378
|
+
tflite: {
|
|
379
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/tflite/camstack-yolo11m_float32.tflite"),
|
|
380
|
+
sizeMB: 77,
|
|
381
|
+
runtimes: ["python"]
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
id: "yolo11l",
|
|
387
|
+
name: "YOLO11 Large",
|
|
388
|
+
description: "YOLO11 Large \u2014 high-accuracy large model (mAP 53.4)",
|
|
389
|
+
inputSize: { width: 640, height: 640 },
|
|
390
|
+
labels: import_types.COCO_80_LABELS,
|
|
391
|
+
formats: {
|
|
392
|
+
onnx: {
|
|
393
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/onnx/camstack-yolo11l.onnx"),
|
|
394
|
+
sizeMB: 97
|
|
395
|
+
},
|
|
396
|
+
coreml: {
|
|
397
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/coreml/camstack-yolo11l.mlpackage"),
|
|
398
|
+
sizeMB: 49,
|
|
399
|
+
isDirectory: true,
|
|
400
|
+
files: MLPACKAGE_FILES,
|
|
401
|
+
runtimes: ["python"]
|
|
402
|
+
},
|
|
403
|
+
openvino: {
|
|
404
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/openvino/camstack-yolo11l.xml"),
|
|
405
|
+
sizeMB: 49,
|
|
406
|
+
runtimes: ["python"]
|
|
407
|
+
},
|
|
408
|
+
tflite: {
|
|
409
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/tflite/camstack-yolo11l_float32.tflite"),
|
|
410
|
+
sizeMB: 97,
|
|
411
|
+
runtimes: ["python"]
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
id: "yolo11x",
|
|
417
|
+
name: "YOLO11 Extra-Large",
|
|
418
|
+
description: "YOLO11 Extra-Large \u2014 maximum accuracy (mAP 54.7)",
|
|
419
|
+
inputSize: { width: 640, height: 640 },
|
|
420
|
+
labels: import_types.COCO_80_LABELS,
|
|
421
|
+
formats: {
|
|
422
|
+
onnx: {
|
|
423
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/onnx/camstack-yolo11x.onnx"),
|
|
424
|
+
sizeMB: 218
|
|
425
|
+
},
|
|
426
|
+
coreml: {
|
|
427
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/coreml/camstack-yolo11x.mlpackage"),
|
|
428
|
+
sizeMB: 109,
|
|
429
|
+
isDirectory: true,
|
|
430
|
+
files: MLPACKAGE_FILES,
|
|
431
|
+
runtimes: ["python"]
|
|
432
|
+
},
|
|
433
|
+
openvino: {
|
|
434
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/openvino/camstack-yolo11x.xml"),
|
|
435
|
+
sizeMB: 109,
|
|
436
|
+
runtimes: ["python"]
|
|
437
|
+
},
|
|
438
|
+
tflite: {
|
|
439
|
+
url: (0, import_types.hfModelUrl)(HF_REPO, "objectDetection/yolo11/tflite/camstack-yolo11x_float32.tflite"),
|
|
440
|
+
sizeMB: 218,
|
|
441
|
+
runtimes: ["python"]
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
];
|
|
446
|
+
|
|
447
|
+
// src/catalogs/segmentation-refiner-models.ts
|
|
448
|
+
var HF_REPO2 = "camstack/camstack-models";
|
|
449
|
+
var hf = (path3) => (0, import_types2.hfModelUrl)(HF_REPO2, path3);
|
|
450
|
+
var MASK_LABELS = [
|
|
451
|
+
{ id: "mask", name: "Segmentation Mask" }
|
|
452
|
+
];
|
|
453
|
+
var SEGMENTATION_REFINER_MODELS = [
|
|
454
|
+
{
|
|
455
|
+
id: "u2netp",
|
|
456
|
+
name: "U2-Net Portable",
|
|
457
|
+
description: "U2-Net-P \u2014 ultra-lightweight salient object segmentation (4.7 MB), no prompt needed",
|
|
458
|
+
inputSize: { width: 320, height: 320 },
|
|
459
|
+
labels: MASK_LABELS,
|
|
460
|
+
formats: {
|
|
461
|
+
onnx: { url: hf("segmentationRefiner/u2netp/onnx/camstack-u2netp.onnx"), sizeMB: 5 },
|
|
462
|
+
coreml: {
|
|
463
|
+
url: hf("segmentationRefiner/u2netp/coreml/camstack-u2netp.mlpackage"),
|
|
464
|
+
sizeMB: 3,
|
|
465
|
+
isDirectory: true,
|
|
466
|
+
files: MLPACKAGE_FILES,
|
|
467
|
+
runtimes: ["python"]
|
|
468
|
+
}
|
|
469
|
+
// OpenVINO: not yet converted
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
];
|
|
473
|
+
|
|
474
|
+
// src/shared/image-utils.ts
|
|
475
|
+
var import_sharp = __toESM(require("sharp"));
|
|
476
|
+
async function cropRegion(jpeg, roi) {
|
|
477
|
+
return (0, import_sharp.default)(jpeg).extract({
|
|
478
|
+
left: Math.round(roi.x),
|
|
479
|
+
top: Math.round(roi.y),
|
|
480
|
+
width: Math.round(roi.w),
|
|
481
|
+
height: Math.round(roi.h)
|
|
482
|
+
}).jpeg().toBuffer();
|
|
483
|
+
}
|
|
484
|
+
async function resizeAndNormalize(jpeg, targetWidth, targetHeight, normalization, layout) {
|
|
485
|
+
const { data } = await (0, import_sharp.default)(jpeg).resize(targetWidth, targetHeight, { fit: "fill" }).removeAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
486
|
+
const numPixels = targetWidth * targetHeight;
|
|
487
|
+
const float32 = new Float32Array(3 * numPixels);
|
|
488
|
+
const mean = [0.485, 0.456, 0.406];
|
|
489
|
+
const std = [0.229, 0.224, 0.225];
|
|
490
|
+
if (layout === "nchw") {
|
|
491
|
+
for (let i = 0; i < numPixels; i++) {
|
|
492
|
+
const srcBase = i * 3;
|
|
493
|
+
for (let c = 0; c < 3; c++) {
|
|
494
|
+
const raw = data[srcBase + c] / 255;
|
|
495
|
+
let val;
|
|
496
|
+
if (normalization === "zero-one") {
|
|
497
|
+
val = raw;
|
|
498
|
+
} else if (normalization === "imagenet") {
|
|
499
|
+
val = (raw - mean[c]) / std[c];
|
|
500
|
+
} else {
|
|
501
|
+
val = data[srcBase + c];
|
|
502
|
+
}
|
|
503
|
+
float32[c * numPixels + i] = val;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
} else {
|
|
507
|
+
for (let i = 0; i < numPixels; i++) {
|
|
508
|
+
const srcBase = i * 3;
|
|
509
|
+
for (let c = 0; c < 3; c++) {
|
|
510
|
+
const raw = data[srcBase + c] / 255;
|
|
511
|
+
let val;
|
|
512
|
+
if (normalization === "zero-one") {
|
|
513
|
+
val = raw;
|
|
514
|
+
} else if (normalization === "imagenet") {
|
|
515
|
+
val = (raw - mean[c]) / std[c];
|
|
516
|
+
} else {
|
|
517
|
+
val = data[srcBase + c];
|
|
518
|
+
}
|
|
519
|
+
float32[i * 3 + c] = val;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
return float32;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// src/shared/engine-resolver.ts
|
|
527
|
+
var fs = __toESM(require("fs"));
|
|
528
|
+
var path2 = __toESM(require("path"));
|
|
529
|
+
|
|
530
|
+
// src/shared/node-engine.ts
|
|
531
|
+
var path = __toESM(require("path"));
|
|
532
|
+
var BACKEND_TO_PROVIDER = {
|
|
533
|
+
cpu: "cpu",
|
|
534
|
+
coreml: "coreml",
|
|
535
|
+
cuda: "cuda",
|
|
536
|
+
tensorrt: "tensorrt",
|
|
537
|
+
dml: "dml"
|
|
538
|
+
};
|
|
539
|
+
var BACKEND_TO_DEVICE = {
|
|
540
|
+
cpu: "cpu",
|
|
541
|
+
coreml: "gpu-mps",
|
|
542
|
+
cuda: "gpu-cuda",
|
|
543
|
+
tensorrt: "tensorrt"
|
|
544
|
+
};
|
|
545
|
+
var NodeInferenceEngine = class {
|
|
546
|
+
constructor(modelPath, backend) {
|
|
547
|
+
this.modelPath = modelPath;
|
|
548
|
+
this.backend = backend;
|
|
549
|
+
this.device = BACKEND_TO_DEVICE[backend] ?? "cpu";
|
|
550
|
+
}
|
|
551
|
+
runtime = "onnx";
|
|
552
|
+
device;
|
|
553
|
+
session = null;
|
|
554
|
+
async initialize() {
|
|
555
|
+
const ort = await import("onnxruntime-node");
|
|
556
|
+
const provider = BACKEND_TO_PROVIDER[this.backend] ?? "cpu";
|
|
557
|
+
const absModelPath = path.isAbsolute(this.modelPath) ? this.modelPath : path.resolve(process.cwd(), this.modelPath);
|
|
558
|
+
const sessionOptions = {
|
|
559
|
+
executionProviders: [provider]
|
|
560
|
+
};
|
|
561
|
+
this.session = await ort.InferenceSession.create(absModelPath, sessionOptions);
|
|
562
|
+
}
|
|
563
|
+
async run(input, inputShape) {
|
|
564
|
+
if (!this.session) {
|
|
565
|
+
throw new Error("NodeInferenceEngine: not initialized \u2014 call initialize() first");
|
|
566
|
+
}
|
|
567
|
+
const ort = await import("onnxruntime-node");
|
|
568
|
+
const sess = this.session;
|
|
569
|
+
const inputName = sess.inputNames[0];
|
|
570
|
+
const tensor = new ort.Tensor("float32", input, [...inputShape]);
|
|
571
|
+
const feeds = { [inputName]: tensor };
|
|
572
|
+
const results = await sess.run(feeds);
|
|
573
|
+
const outputName = sess.outputNames[0];
|
|
574
|
+
const outputTensor = results[outputName];
|
|
575
|
+
return outputTensor.data;
|
|
576
|
+
}
|
|
577
|
+
async runMultiOutput(input, inputShape) {
|
|
578
|
+
if (!this.session) {
|
|
579
|
+
throw new Error("NodeInferenceEngine: not initialized \u2014 call initialize() first");
|
|
580
|
+
}
|
|
581
|
+
const ort = await import("onnxruntime-node");
|
|
582
|
+
const sess = this.session;
|
|
583
|
+
const inputName = sess.inputNames[0];
|
|
584
|
+
const tensor = new ort.Tensor("float32", input, [...inputShape]);
|
|
585
|
+
const feeds = { [inputName]: tensor };
|
|
586
|
+
const results = await sess.run(feeds);
|
|
587
|
+
const out = {};
|
|
588
|
+
for (const name of sess.outputNames) {
|
|
589
|
+
out[name] = results[name].data;
|
|
590
|
+
}
|
|
591
|
+
return out;
|
|
592
|
+
}
|
|
593
|
+
async dispose() {
|
|
594
|
+
this.session = null;
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
// src/shared/python-engine.ts
|
|
599
|
+
var import_node_child_process = require("child_process");
|
|
600
|
+
var PythonInferenceEngine = class {
|
|
601
|
+
constructor(pythonPath, scriptPath, runtime, modelPath, extraArgs = []) {
|
|
602
|
+
this.pythonPath = pythonPath;
|
|
603
|
+
this.scriptPath = scriptPath;
|
|
604
|
+
this.modelPath = modelPath;
|
|
605
|
+
this.extraArgs = extraArgs;
|
|
606
|
+
this.runtime = runtime;
|
|
607
|
+
const runtimeDeviceMap = {
|
|
608
|
+
onnx: "cpu",
|
|
609
|
+
coreml: "gpu-mps",
|
|
610
|
+
pytorch: "cpu",
|
|
611
|
+
openvino: "cpu",
|
|
612
|
+
tflite: "cpu"
|
|
613
|
+
};
|
|
614
|
+
this.device = runtimeDeviceMap[runtime];
|
|
615
|
+
}
|
|
616
|
+
runtime;
|
|
617
|
+
device;
|
|
618
|
+
process = null;
|
|
619
|
+
receiveBuffer = Buffer.alloc(0);
|
|
620
|
+
pendingResolve = null;
|
|
621
|
+
pendingReject = null;
|
|
622
|
+
async initialize() {
|
|
623
|
+
const args = [this.scriptPath, this.modelPath, ...this.extraArgs];
|
|
624
|
+
this.process = (0, import_node_child_process.spawn)(this.pythonPath, args, {
|
|
625
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
626
|
+
});
|
|
627
|
+
if (!this.process.stdout || !this.process.stdin) {
|
|
628
|
+
throw new Error("PythonInferenceEngine: failed to create process pipes");
|
|
629
|
+
}
|
|
630
|
+
this.process.stderr?.on("data", (chunk) => {
|
|
631
|
+
process.stderr.write(`[python-engine] ${chunk.toString()}`);
|
|
632
|
+
});
|
|
633
|
+
this.process.on("error", (err) => {
|
|
634
|
+
this.pendingReject?.(err);
|
|
635
|
+
this.pendingReject = null;
|
|
636
|
+
this.pendingResolve = null;
|
|
637
|
+
});
|
|
638
|
+
this.process.on("exit", (code) => {
|
|
639
|
+
if (code !== 0) {
|
|
640
|
+
const err = new Error(`PythonInferenceEngine: process exited with code ${code}`);
|
|
641
|
+
this.pendingReject?.(err);
|
|
642
|
+
this.pendingReject = null;
|
|
643
|
+
this.pendingResolve = null;
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
this.process.stdout.on("data", (chunk) => {
|
|
647
|
+
this.receiveBuffer = Buffer.concat([this.receiveBuffer, chunk]);
|
|
648
|
+
this._tryReceive();
|
|
649
|
+
});
|
|
650
|
+
await new Promise((resolve2, reject) => {
|
|
651
|
+
const timeout = setTimeout(() => resolve2(), 2e3);
|
|
652
|
+
this.process?.on("error", (err) => {
|
|
653
|
+
clearTimeout(timeout);
|
|
654
|
+
reject(err);
|
|
655
|
+
});
|
|
656
|
+
this.process?.on("exit", (code) => {
|
|
657
|
+
clearTimeout(timeout);
|
|
658
|
+
if (code !== 0) {
|
|
659
|
+
reject(new Error(`PythonInferenceEngine: process exited early with code ${code}`));
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
_tryReceive() {
|
|
665
|
+
if (this.receiveBuffer.length < 4) return;
|
|
666
|
+
const length = this.receiveBuffer.readUInt32LE(0);
|
|
667
|
+
if (this.receiveBuffer.length < 4 + length) return;
|
|
668
|
+
const jsonBytes = this.receiveBuffer.subarray(4, 4 + length);
|
|
669
|
+
this.receiveBuffer = this.receiveBuffer.subarray(4 + length);
|
|
670
|
+
const resolve2 = this.pendingResolve;
|
|
671
|
+
const reject = this.pendingReject;
|
|
672
|
+
this.pendingResolve = null;
|
|
673
|
+
this.pendingReject = null;
|
|
674
|
+
if (!resolve2) return;
|
|
675
|
+
try {
|
|
676
|
+
const parsed = JSON.parse(jsonBytes.toString("utf8"));
|
|
677
|
+
resolve2(parsed);
|
|
678
|
+
} catch (err) {
|
|
679
|
+
reject?.(err instanceof Error ? err : new Error(String(err)));
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
/** Send JPEG buffer, receive JSON detection results */
|
|
683
|
+
async runJpeg(jpeg) {
|
|
684
|
+
if (!this.process?.stdin) {
|
|
685
|
+
throw new Error("PythonInferenceEngine: process not initialized");
|
|
686
|
+
}
|
|
687
|
+
return new Promise((resolve2, reject) => {
|
|
688
|
+
this.pendingResolve = resolve2;
|
|
689
|
+
this.pendingReject = reject;
|
|
690
|
+
const lengthBuf = Buffer.allocUnsafe(4);
|
|
691
|
+
lengthBuf.writeUInt32LE(jpeg.length, 0);
|
|
692
|
+
this.process.stdin.write(Buffer.concat([lengthBuf, jpeg]));
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
/** IInferenceEngine.run — wraps runJpeg for compatibility */
|
|
696
|
+
async run(_input, _inputShape) {
|
|
697
|
+
throw new Error(
|
|
698
|
+
"PythonInferenceEngine: use runJpeg() directly \u2014 this engine operates on JPEG input"
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
/** IInferenceEngine.runMultiOutput — not supported by Python engine (operates on JPEG input) */
|
|
702
|
+
async runMultiOutput(_input, _inputShape) {
|
|
703
|
+
throw new Error(
|
|
704
|
+
"PythonInferenceEngine: runMultiOutput() is not supported \u2014 this engine operates on JPEG input"
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
async dispose() {
|
|
708
|
+
if (this.process) {
|
|
709
|
+
this.process.stdin?.end();
|
|
710
|
+
this.process.kill("SIGTERM");
|
|
711
|
+
this.process = null;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
// src/shared/engine-resolver.ts
|
|
717
|
+
var AUTO_BACKEND_PRIORITY = ["coreml", "cuda", "tensorrt", "cpu"];
|
|
718
|
+
var BACKEND_TO_FORMAT = {
|
|
719
|
+
cpu: "onnx",
|
|
720
|
+
coreml: "onnx",
|
|
721
|
+
cuda: "onnx",
|
|
722
|
+
tensorrt: "onnx"
|
|
723
|
+
};
|
|
724
|
+
var RUNTIME_TO_FORMAT = {
|
|
725
|
+
onnx: "onnx",
|
|
726
|
+
coreml: "coreml",
|
|
727
|
+
openvino: "openvino",
|
|
728
|
+
tflite: "tflite",
|
|
729
|
+
pytorch: "pt"
|
|
730
|
+
};
|
|
731
|
+
function modelFilePath(modelsDir, modelEntry, format) {
|
|
732
|
+
const formatEntry = modelEntry.formats[format];
|
|
733
|
+
if (!formatEntry) {
|
|
734
|
+
throw new Error(`Model ${modelEntry.id} has no ${format} format`);
|
|
735
|
+
}
|
|
736
|
+
const urlParts = formatEntry.url.split("/");
|
|
737
|
+
const filename = urlParts[urlParts.length - 1] ?? `${modelEntry.id}.${format}`;
|
|
738
|
+
return path2.join(modelsDir, filename);
|
|
739
|
+
}
|
|
740
|
+
function modelExists(filePath) {
|
|
741
|
+
try {
|
|
742
|
+
return fs.existsSync(filePath);
|
|
743
|
+
} catch {
|
|
744
|
+
return false;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
async function resolveEngine(options) {
|
|
748
|
+
const { runtime, backend, modelEntry, modelsDir, models } = options;
|
|
749
|
+
let selectedFormat;
|
|
750
|
+
let selectedBackend;
|
|
751
|
+
if (runtime === "auto") {
|
|
752
|
+
const available = await probeOnnxBackends();
|
|
753
|
+
let chosen = null;
|
|
754
|
+
for (const b of AUTO_BACKEND_PRIORITY) {
|
|
755
|
+
if (!available.includes(b)) continue;
|
|
756
|
+
const fmt = BACKEND_TO_FORMAT[b];
|
|
757
|
+
if (!fmt) continue;
|
|
758
|
+
if (!modelEntry.formats[fmt]) continue;
|
|
759
|
+
chosen = { backend: b, format: fmt };
|
|
760
|
+
break;
|
|
761
|
+
}
|
|
762
|
+
if (!chosen) {
|
|
763
|
+
throw new Error(
|
|
764
|
+
`resolveEngine: no compatible backend found for model ${modelEntry.id}. Available backends: ${available.join(", ")}`
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
selectedFormat = chosen.format;
|
|
768
|
+
selectedBackend = chosen.backend;
|
|
769
|
+
} else {
|
|
770
|
+
const fmt = RUNTIME_TO_FORMAT[runtime];
|
|
771
|
+
if (!fmt) {
|
|
772
|
+
throw new Error(`resolveEngine: unsupported runtime "${runtime}"`);
|
|
773
|
+
}
|
|
774
|
+
if (!modelEntry.formats[fmt]) {
|
|
775
|
+
throw new Error(
|
|
776
|
+
`resolveEngine: model ${modelEntry.id} has no ${fmt} format for runtime ${runtime}`
|
|
777
|
+
);
|
|
778
|
+
}
|
|
779
|
+
selectedFormat = fmt;
|
|
780
|
+
selectedBackend = runtime === "onnx" ? backend || "cpu" : runtime;
|
|
781
|
+
}
|
|
782
|
+
let modelPath;
|
|
783
|
+
if (models) {
|
|
784
|
+
modelPath = await models.ensure(modelEntry.id, selectedFormat);
|
|
785
|
+
} else {
|
|
786
|
+
modelPath = modelFilePath(modelsDir, modelEntry, selectedFormat);
|
|
787
|
+
if (!modelExists(modelPath)) {
|
|
788
|
+
throw new Error(
|
|
789
|
+
`resolveEngine: model file not found at ${modelPath} and no model service provided`
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
if (selectedFormat === "onnx") {
|
|
794
|
+
const engine = new NodeInferenceEngine(modelPath, selectedBackend);
|
|
795
|
+
await engine.initialize();
|
|
796
|
+
return { engine, format: selectedFormat, modelPath };
|
|
797
|
+
}
|
|
798
|
+
const { pythonPath } = options;
|
|
799
|
+
const PYTHON_SCRIPT_MAP = {
|
|
800
|
+
coreml: "coreml_inference.py",
|
|
801
|
+
pytorch: "pytorch_inference.py",
|
|
802
|
+
openvino: "openvino_inference.py"
|
|
803
|
+
};
|
|
804
|
+
const effectiveRuntime = runtime === "auto" ? selectedBackend : runtime;
|
|
805
|
+
const scriptName = PYTHON_SCRIPT_MAP[effectiveRuntime];
|
|
806
|
+
if (scriptName && pythonPath) {
|
|
807
|
+
const candidates = [
|
|
808
|
+
path2.join(__dirname, "../../python", scriptName),
|
|
809
|
+
path2.join(__dirname, "../python", scriptName),
|
|
810
|
+
path2.join(__dirname, "../../../python", scriptName)
|
|
811
|
+
];
|
|
812
|
+
const scriptPath = candidates.find((p) => fs.existsSync(p));
|
|
813
|
+
if (!scriptPath) {
|
|
814
|
+
throw new Error(
|
|
815
|
+
`resolveEngine: Python script "${scriptName}" not found. Searched:
|
|
816
|
+
${candidates.join("\n")}`
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
const inputSize = Math.max(modelEntry.inputSize.width, modelEntry.inputSize.height);
|
|
820
|
+
const engine = new PythonInferenceEngine(pythonPath, scriptPath, effectiveRuntime, modelPath, [
|
|
821
|
+
`--input-size=${inputSize}`,
|
|
822
|
+
`--confidence=0.25`
|
|
823
|
+
]);
|
|
824
|
+
await engine.initialize();
|
|
825
|
+
return { engine, format: selectedFormat, modelPath };
|
|
826
|
+
}
|
|
827
|
+
const fallbackPath = modelFilePath(modelsDir, modelEntry, "onnx");
|
|
828
|
+
if (modelEntry.formats["onnx"] && modelExists(fallbackPath)) {
|
|
829
|
+
const engine = new NodeInferenceEngine(fallbackPath, "cpu");
|
|
830
|
+
await engine.initialize();
|
|
831
|
+
return { engine, format: "onnx", modelPath: fallbackPath };
|
|
832
|
+
}
|
|
833
|
+
throw new Error(
|
|
834
|
+
`resolveEngine: format ${selectedFormat} is not yet supported by NodeInferenceEngine, no Python runtime is available, and no ONNX fallback exists`
|
|
835
|
+
);
|
|
836
|
+
}
|
|
837
|
+
async function probeOnnxBackends() {
|
|
838
|
+
const available = ["cpu"];
|
|
839
|
+
try {
|
|
840
|
+
const ort = await import("onnxruntime-node");
|
|
841
|
+
const providers = ort.env?.webgl?.disabled !== void 0 ? ort.InferenceSession?.getAvailableProviders?.() ?? [] : [];
|
|
842
|
+
for (const p of providers) {
|
|
843
|
+
const normalized = p.toLowerCase().replace("executionprovider", "");
|
|
844
|
+
if (normalized === "coreml") available.push("coreml");
|
|
845
|
+
else if (normalized === "cuda") available.push("cuda");
|
|
846
|
+
else if (normalized === "tensorrt") available.push("tensorrt");
|
|
847
|
+
}
|
|
848
|
+
} catch {
|
|
849
|
+
}
|
|
850
|
+
if (process.platform === "darwin" && !available.includes("coreml")) {
|
|
851
|
+
available.push("coreml");
|
|
852
|
+
}
|
|
853
|
+
return [...new Set(available)];
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
// src/addons/segmentation-refiner/index.ts
|
|
857
|
+
var MASK_LABEL = { id: "mask", name: "Segmentation Mask" };
|
|
858
|
+
var MASK_LABELS2 = [MASK_LABEL];
|
|
859
|
+
var MASK_CLASS_MAP = { mapping: {}, preserveOriginal: true };
|
|
860
|
+
var DEFAULT_MASK_THRESHOLD = 0.5;
|
|
861
|
+
var SegmentationRefinerAddon = class {
|
|
862
|
+
id = "segmentation-refiner";
|
|
863
|
+
slot = "refiner";
|
|
864
|
+
inputClasses = null;
|
|
865
|
+
outputClasses = ["mask:*"];
|
|
866
|
+
slotPriority = 0;
|
|
867
|
+
requiredSteps = [];
|
|
868
|
+
manifest = {
|
|
869
|
+
id: "segmentation-refiner",
|
|
870
|
+
name: "Segmentation Refiner",
|
|
871
|
+
version: "0.1.0",
|
|
872
|
+
description: "Post-detection segmentation \u2014 refines bboxes into precise binary masks using U2-Net-P or EdgeSAM",
|
|
873
|
+
slot: "refiner",
|
|
874
|
+
outputClasses: ["mask:*"],
|
|
875
|
+
supportsCustomModels: false,
|
|
876
|
+
mayRequirePython: false,
|
|
877
|
+
defaultConfig: {
|
|
878
|
+
modelId: "u2netp",
|
|
879
|
+
runtime: "node",
|
|
880
|
+
backend: "cpu",
|
|
881
|
+
maskThreshold: DEFAULT_MASK_THRESHOLD
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
engine = null;
|
|
885
|
+
modelEntry;
|
|
886
|
+
maskThreshold = DEFAULT_MASK_THRESHOLD;
|
|
887
|
+
resolvedConfig = null;
|
|
888
|
+
ctx = null;
|
|
889
|
+
getModelRequirements() {
|
|
890
|
+
return SEGMENTATION_REFINER_MODELS.map((m) => ({
|
|
891
|
+
modelId: m.id,
|
|
892
|
+
name: m.name,
|
|
893
|
+
minRAM_MB: 256,
|
|
894
|
+
accuracyScore: 80,
|
|
895
|
+
formats: Object.keys(m.formats)
|
|
896
|
+
}));
|
|
897
|
+
}
|
|
898
|
+
configure(config) {
|
|
899
|
+
this.resolvedConfig = config;
|
|
900
|
+
}
|
|
901
|
+
async initialize(ctx) {
|
|
902
|
+
this.ctx = ctx;
|
|
903
|
+
const cfg = ctx.addonConfig;
|
|
904
|
+
const modelId = cfg["modelId"] ?? this.resolvedConfig?.modelId ?? "u2netp";
|
|
905
|
+
this.maskThreshold = cfg["maskThreshold"] ?? DEFAULT_MASK_THRESHOLD;
|
|
906
|
+
const entry = SEGMENTATION_REFINER_MODELS.find((m) => m.id === modelId);
|
|
907
|
+
if (!entry) {
|
|
908
|
+
throw new Error(`SegmentationRefinerAddon: unknown modelId "${modelId}"`);
|
|
909
|
+
}
|
|
910
|
+
this.modelEntry = entry;
|
|
911
|
+
}
|
|
912
|
+
async refine(input) {
|
|
913
|
+
if (!this.engine) await this.ensureEngine();
|
|
914
|
+
const start = Date.now();
|
|
915
|
+
const { width: inputW, height: inputH } = this.modelEntry.inputSize;
|
|
916
|
+
const crop = await cropRegion(input.frame.data, input.roi);
|
|
917
|
+
const normalized = await resizeAndNormalize(crop, inputW, inputH, "zero-one", "nchw");
|
|
918
|
+
const rawOutput = await this.engine.run(normalized, [1, 3, inputH, inputW]);
|
|
919
|
+
const maskSize = inputW * inputH;
|
|
920
|
+
const mask = new Uint8Array(maskSize);
|
|
921
|
+
const threshold = this.maskThreshold;
|
|
922
|
+
for (let i = 0; i < maskSize; i++) {
|
|
923
|
+
mask[i] = (rawOutput[i] ?? 0) > threshold ? 255 : 0;
|
|
924
|
+
}
|
|
925
|
+
return {
|
|
926
|
+
mask: Buffer.from(mask).toString("base64"),
|
|
927
|
+
maskWidth: inputW,
|
|
928
|
+
maskHeight: inputH,
|
|
929
|
+
inferenceMs: Date.now() - start,
|
|
930
|
+
modelId: this.modelEntry.id
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
async ensureEngine() {
|
|
934
|
+
const config = this.resolvedConfig;
|
|
935
|
+
const modelId = config?.modelId ?? this.modelEntry.id;
|
|
936
|
+
const runtime = config?.runtime === "python" ? "coreml" : config?.runtime === "node" ? "onnx" : "auto";
|
|
937
|
+
const backend = config?.backend ?? "cpu";
|
|
938
|
+
const format = config?.format ?? "onnx";
|
|
939
|
+
const entry = SEGMENTATION_REFINER_MODELS.find((m) => m.id === modelId) ?? this.modelEntry;
|
|
940
|
+
this.modelEntry = entry;
|
|
941
|
+
const modelsDir = this.ctx.models?.getModelsDir() ?? this.ctx.locationPaths.models;
|
|
942
|
+
if (this.ctx.models) {
|
|
943
|
+
await this.ctx.models.ensure(modelId, format);
|
|
944
|
+
}
|
|
945
|
+
const resolved = await resolveEngine({
|
|
946
|
+
runtime,
|
|
947
|
+
backend,
|
|
948
|
+
modelEntry: entry,
|
|
949
|
+
modelsDir,
|
|
950
|
+
models: this.ctx.models
|
|
951
|
+
});
|
|
952
|
+
this.engine = resolved.engine;
|
|
953
|
+
}
|
|
954
|
+
async shutdown() {
|
|
955
|
+
await this.engine?.dispose();
|
|
956
|
+
}
|
|
957
|
+
getConfigSchema() {
|
|
958
|
+
return {
|
|
959
|
+
sections: [
|
|
960
|
+
{
|
|
961
|
+
id: "model",
|
|
962
|
+
title: "Model",
|
|
963
|
+
columns: 1,
|
|
964
|
+
fields: [
|
|
965
|
+
{
|
|
966
|
+
key: "modelId",
|
|
967
|
+
label: "Model",
|
|
968
|
+
type: "model-selector",
|
|
969
|
+
catalog: [...SEGMENTATION_REFINER_MODELS],
|
|
970
|
+
allowCustom: false,
|
|
971
|
+
allowConversion: false,
|
|
972
|
+
acceptFormats: ["onnx", "coreml", "openvino"],
|
|
973
|
+
requiredMetadata: ["inputSize", "labels"],
|
|
974
|
+
outputFormatHint: "segmentation"
|
|
975
|
+
}
|
|
976
|
+
]
|
|
977
|
+
},
|
|
978
|
+
{
|
|
979
|
+
id: "runtime",
|
|
980
|
+
title: "Runtime",
|
|
981
|
+
columns: 2,
|
|
982
|
+
fields: [
|
|
983
|
+
{
|
|
984
|
+
key: "runtime",
|
|
985
|
+
label: "Runtime",
|
|
986
|
+
type: "select",
|
|
987
|
+
options: [
|
|
988
|
+
{ value: "auto", label: "Auto" },
|
|
989
|
+
{ value: "onnx", label: "ONNX Runtime" },
|
|
990
|
+
{ value: "coreml", label: "CoreML (Apple)" },
|
|
991
|
+
{ value: "openvino", label: "OpenVINO (Intel)" }
|
|
992
|
+
]
|
|
993
|
+
},
|
|
994
|
+
{
|
|
995
|
+
key: "backend",
|
|
996
|
+
label: "Backend",
|
|
997
|
+
type: "select",
|
|
998
|
+
showWhen: { field: "runtime", equals: "onnx" },
|
|
999
|
+
options: [
|
|
1000
|
+
{ value: "auto", label: "Auto" },
|
|
1001
|
+
{ value: "cpu", label: "CPU" },
|
|
1002
|
+
{ value: "coreml", label: "CoreML" },
|
|
1003
|
+
{ value: "cuda", label: "CUDA (NVIDIA)" }
|
|
1004
|
+
]
|
|
1005
|
+
}
|
|
1006
|
+
]
|
|
1007
|
+
},
|
|
1008
|
+
{
|
|
1009
|
+
id: "thresholds",
|
|
1010
|
+
title: "Segmentation Settings",
|
|
1011
|
+
columns: 1,
|
|
1012
|
+
fields: [
|
|
1013
|
+
{
|
|
1014
|
+
key: "maskThreshold",
|
|
1015
|
+
label: "Mask Threshold",
|
|
1016
|
+
type: "slider",
|
|
1017
|
+
min: 0.1,
|
|
1018
|
+
max: 0.9,
|
|
1019
|
+
step: 0.05,
|
|
1020
|
+
default: DEFAULT_MASK_THRESHOLD
|
|
1021
|
+
}
|
|
1022
|
+
]
|
|
1023
|
+
}
|
|
1024
|
+
]
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
getClassMap() {
|
|
1028
|
+
return MASK_CLASS_MAP;
|
|
1029
|
+
}
|
|
1030
|
+
getModelCatalog() {
|
|
1031
|
+
return [...SEGMENTATION_REFINER_MODELS];
|
|
1032
|
+
}
|
|
1033
|
+
getAvailableModels() {
|
|
1034
|
+
return [];
|
|
1035
|
+
}
|
|
1036
|
+
getActiveLabels() {
|
|
1037
|
+
return MASK_LABELS2;
|
|
1038
|
+
}
|
|
1039
|
+
async probe() {
|
|
1040
|
+
return {
|
|
1041
|
+
available: true,
|
|
1042
|
+
runtime: this.engine?.runtime ?? "onnx",
|
|
1043
|
+
device: this.engine?.device ?? "cpu",
|
|
1044
|
+
capabilities: ["fp32"]
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
//# sourceMappingURL=index.js.map
|