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