tempest-react-sdk 0.38.2 → 0.39.0

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.
Files changed (332) hide show
  1. package/README.md +1 -1
  2. package/bin/lib/design/collect.mjs +19 -0
  3. package/bin/lib/design/functions.mjs +5 -0
  4. package/bin/lib/design/index.mjs +8 -3
  5. package/bin/lib/design/index.test.mjs +31 -0
  6. package/bin/lib/design/scan.mjs +34 -2
  7. package/bin/lib/design/scan.test.mjs +78 -0
  8. package/bin/lib/doctor/doctor.e2e.test.mjs +85 -0
  9. package/bin/tempest.mjs +90 -6
  10. package/dist/audio/level-meter.cjs.map +1 -1
  11. package/dist/audio/level-meter.js.map +1 -1
  12. package/dist/audio/use-audio-recorder.cjs.map +1 -1
  13. package/dist/audio/use-audio-recorder.js.map +1 -1
  14. package/dist/auth/passkey.cjs.map +1 -1
  15. package/dist/auth/passkey.js.map +1 -1
  16. package/dist/auth/use-passkey.cjs.map +1 -1
  17. package/dist/auth/use-passkey.js.map +1 -1
  18. package/dist/br/BrazilMap.cjs.map +1 -1
  19. package/dist/br/BrazilMap.js.map +1 -1
  20. package/dist/br/BrazilStateCitySelect.cjs.map +1 -1
  21. package/dist/br/BrazilStateCitySelect.js.map +1 -1
  22. package/dist/br/BrazilStateMap.cjs.map +1 -1
  23. package/dist/br/BrazilStateMap.js.map +1 -1
  24. package/dist/br/PixQRCode.cjs.map +1 -1
  25. package/dist/br/PixQRCode.js.map +1 -1
  26. package/dist/br/boleto.cjs.map +1 -1
  27. package/dist/br/boleto.js.map +1 -1
  28. package/dist/br/pix.cjs.map +1 -1
  29. package/dist/br/pix.js.map +1 -1
  30. package/dist/br.d.ts +8 -0
  31. package/dist/capture/media-recorder.cjs.map +1 -1
  32. package/dist/capture/media-recorder.js.map +1 -1
  33. package/dist/capture/use-barcode-scanner.cjs.map +1 -1
  34. package/dist/capture/use-barcode-scanner.js.map +1 -1
  35. package/dist/capture/use-screen-capture.cjs.map +1 -1
  36. package/dist/capture/use-screen-capture.js.map +1 -1
  37. package/dist/capture/use-speech-recognition.cjs.map +1 -1
  38. package/dist/capture/use-speech-recognition.js.map +1 -1
  39. package/dist/capture/use-video-recorder.cjs.map +1 -1
  40. package/dist/capture/use-video-recorder.js.map +1 -1
  41. package/dist/charts/types.cjs.map +1 -1
  42. package/dist/charts/types.js.map +1 -1
  43. package/dist/charts.d.ts +8 -0
  44. package/dist/components/AIChat/AIChat.cjs.map +1 -1
  45. package/dist/components/AIChat/AIChat.js.map +1 -1
  46. package/dist/components/AIChat/AIChatComposer.cjs.map +1 -1
  47. package/dist/components/AIChat/AIChatComposer.js.map +1 -1
  48. package/dist/components/AIChat/AIChatTurn.cjs.map +1 -1
  49. package/dist/components/AIChat/AIChatTurn.js.map +1 -1
  50. package/dist/components/AppBar/AppBar.cjs.map +1 -1
  51. package/dist/components/AppBar/AppBar.js.map +1 -1
  52. package/dist/components/AudioPlayer/AudioPlayer.cjs.map +1 -1
  53. package/dist/components/AudioPlayer/AudioPlayer.js.map +1 -1
  54. package/dist/components/AudioRecorder/AudioRecorder.cjs.map +1 -1
  55. package/dist/components/AudioRecorder/AudioRecorder.js.map +1 -1
  56. package/dist/components/BarcodeScanner/BarcodeScanner.cjs.map +1 -1
  57. package/dist/components/BarcodeScanner/BarcodeScanner.js.map +1 -1
  58. package/dist/components/Button/Button.cjs.map +1 -1
  59. package/dist/components/Button/Button.js.map +1 -1
  60. package/dist/components/Calendar/Calendar.cjs.map +1 -1
  61. package/dist/components/Calendar/Calendar.js.map +1 -1
  62. package/dist/components/Carousel/Carousel.cjs.map +1 -1
  63. package/dist/components/Carousel/Carousel.js.map +1 -1
  64. package/dist/components/Chat/Chat.cjs.map +1 -1
  65. package/dist/components/Chat/Chat.js.map +1 -1
  66. package/dist/components/ChipInput/ChipInput.cjs.map +1 -1
  67. package/dist/components/ChipInput/ChipInput.js.map +1 -1
  68. package/dist/components/CodeBlock/CodeBlock.cjs.map +1 -1
  69. package/dist/components/CodeBlock/CodeBlock.js.map +1 -1
  70. package/dist/components/Combobox/Combobox.cjs.map +1 -1
  71. package/dist/components/Combobox/Combobox.js.map +1 -1
  72. package/dist/components/Command/Command.cjs.map +1 -1
  73. package/dist/components/Command/Command.js.map +1 -1
  74. package/dist/components/ConfirmDialog/ConfirmDialog.cjs.map +1 -1
  75. package/dist/components/ConfirmDialog/ConfirmDialog.js.map +1 -1
  76. package/dist/components/ContextMenu/ContextMenu.cjs.map +1 -1
  77. package/dist/components/ContextMenu/ContextMenu.js.map +1 -1
  78. package/dist/components/CopyButton/CopyButton.cjs.map +1 -1
  79. package/dist/components/CopyButton/CopyButton.js.map +1 -1
  80. package/dist/components/DataTable/DataTable.cjs.map +1 -1
  81. package/dist/components/DataTable/DataTable.js.map +1 -1
  82. package/dist/components/DataTable/DataTable.module.cjs.map +1 -1
  83. package/dist/components/DataTable/DataTable.module.js.map +1 -1
  84. package/dist/components/DataTable/EditableCell.cjs.map +1 -1
  85. package/dist/components/DataTable/EditableCell.js.map +1 -1
  86. package/dist/components/DatePicker/DatePicker.cjs.map +1 -1
  87. package/dist/components/DatePicker/DatePicker.js.map +1 -1
  88. package/dist/components/DateRangePicker/DateRangePicker.cjs.map +1 -1
  89. package/dist/components/DateRangePicker/DateRangePicker.js.map +1 -1
  90. package/dist/components/Drawer/Drawer.cjs.map +1 -1
  91. package/dist/components/Drawer/Drawer.js.map +1 -1
  92. package/dist/components/DropdownMenu/DropdownMenu.cjs.map +1 -1
  93. package/dist/components/DropdownMenu/DropdownMenu.js.map +1 -1
  94. package/dist/components/Dropzone/Dropzone.cjs.map +1 -1
  95. package/dist/components/Dropzone/Dropzone.js.map +1 -1
  96. package/dist/components/FileUpload/FileUpload.cjs.map +1 -1
  97. package/dist/components/FileUpload/FileUpload.js.map +1 -1
  98. package/dist/components/FilterBar/FilterBar.cjs.map +1 -1
  99. package/dist/components/FilterBar/FilterBar.js.map +1 -1
  100. package/dist/components/ImageCropper/ImageCropper.cjs.map +1 -1
  101. package/dist/components/ImageCropper/ImageCropper.js.map +1 -1
  102. package/dist/components/InstallBanner/InstallBanner.cjs.map +1 -1
  103. package/dist/components/InstallBanner/InstallBanner.js.map +1 -1
  104. package/dist/components/Kanban/Kanban.cjs.map +1 -1
  105. package/dist/components/Kanban/Kanban.js.map +1 -1
  106. package/dist/components/Lightbox/Lightbox.cjs.map +1 -1
  107. package/dist/components/Lightbox/Lightbox.js.map +1 -1
  108. package/dist/components/ListTile/ListTile.cjs.map +1 -1
  109. package/dist/components/ListTile/ListTile.js.map +1 -1
  110. package/dist/components/Markdown/Markdown.cjs.map +1 -1
  111. package/dist/components/Markdown/Markdown.js.map +1 -1
  112. package/dist/components/Markdown/markdown-parse.cjs.map +1 -1
  113. package/dist/components/Markdown/markdown-parse.js.map +1 -1
  114. package/dist/components/Menubar/Menubar.cjs.map +1 -1
  115. package/dist/components/Menubar/Menubar.js.map +1 -1
  116. package/dist/components/Modal/Modal.cjs.map +1 -1
  117. package/dist/components/Modal/Modal.js.map +1 -1
  118. package/dist/components/ModalsManager/ModalsManager.cjs.map +1 -1
  119. package/dist/components/ModalsManager/ModalsManager.js.map +1 -1
  120. package/dist/components/MultiSelect/MultiSelect.cjs.map +1 -1
  121. package/dist/components/MultiSelect/MultiSelect.js.map +1 -1
  122. package/dist/components/NavigationMenu/NavigationMenu.cjs.map +1 -1
  123. package/dist/components/NavigationMenu/NavigationMenu.js.map +1 -1
  124. package/dist/components/NotificationCenter/NotificationCenter.cjs.map +1 -1
  125. package/dist/components/NotificationCenter/NotificationCenter.js.map +1 -1
  126. package/dist/components/Page/Page.cjs.map +1 -1
  127. package/dist/components/Page/Page.js.map +1 -1
  128. package/dist/components/Pagination/Pagination.cjs.map +1 -1
  129. package/dist/components/Pagination/Pagination.js.map +1 -1
  130. package/dist/components/PasswordInput/PasswordInput.cjs.map +1 -1
  131. package/dist/components/PasswordInput/PasswordInput.js.map +1 -1
  132. package/dist/components/PinInput/PinInput.cjs.map +1 -1
  133. package/dist/components/PinInput/PinInput.js.map +1 -1
  134. package/dist/components/Popover/Popover.cjs.map +1 -1
  135. package/dist/components/Popover/Popover.js.map +1 -1
  136. package/dist/components/Progress/Progress.cjs.map +1 -1
  137. package/dist/components/Progress/Progress.js.map +1 -1
  138. package/dist/components/QRCode/qr-encode.cjs.map +1 -1
  139. package/dist/components/QRCode/qr-encode.js.map +1 -1
  140. package/dist/components/Radio/Radio.cjs.map +1 -1
  141. package/dist/components/Radio/Radio.js.map +1 -1
  142. package/dist/components/RangeSlider/RangeSlider.cjs.map +1 -1
  143. package/dist/components/RangeSlider/RangeSlider.js.map +1 -1
  144. package/dist/components/RatingStars/RatingStars.cjs.map +1 -1
  145. package/dist/components/RatingStars/RatingStars.js.map +1 -1
  146. package/dist/components/RefreshIndicator/RefreshIndicator.cjs.map +1 -1
  147. package/dist/components/RefreshIndicator/RefreshIndicator.js.map +1 -1
  148. package/dist/components/Resizable/Resizable.cjs.map +1 -1
  149. package/dist/components/Resizable/Resizable.js.map +1 -1
  150. package/dist/components/Scheduler/Scheduler.cjs.map +1 -1
  151. package/dist/components/Scheduler/Scheduler.js.map +1 -1
  152. package/dist/components/Sidebar/Sidebar.cjs.map +1 -1
  153. package/dist/components/Sidebar/Sidebar.js.map +1 -1
  154. package/dist/components/SignaturePad/SignaturePad.cjs.map +1 -1
  155. package/dist/components/SignaturePad/SignaturePad.js.map +1 -1
  156. package/dist/components/Slider/Slider.cjs.map +1 -1
  157. package/dist/components/Slider/Slider.js.map +1 -1
  158. package/dist/components/Sparkline/Sparkline.cjs.map +1 -1
  159. package/dist/components/Sparkline/Sparkline.js.map +1 -1
  160. package/dist/components/StepperInput/StepperInput.cjs.map +1 -1
  161. package/dist/components/StepperInput/StepperInput.js.map +1 -1
  162. package/dist/components/Table/Table.cjs.map +1 -1
  163. package/dist/components/Table/Table.js.map +1 -1
  164. package/dist/components/TimePicker/TimePicker.cjs.map +1 -1
  165. package/dist/components/TimePicker/TimePicker.js.map +1 -1
  166. package/dist/components/Toast/ToastProvider.cjs.map +1 -1
  167. package/dist/components/Toast/ToastProvider.js.map +1 -1
  168. package/dist/components/Tour/Tour.cjs.map +1 -1
  169. package/dist/components/Tour/Tour.js.map +1 -1
  170. package/dist/components/Transfer/Transfer.cjs.map +1 -1
  171. package/dist/components/Transfer/Transfer.js.map +1 -1
  172. package/dist/components/TreeView/TreeView.cjs.map +1 -1
  173. package/dist/components/TreeView/TreeView.js.map +1 -1
  174. package/dist/components/VirtualList/VirtualList.cjs.map +1 -1
  175. package/dist/components/VirtualList/VirtualList.js.map +1 -1
  176. package/dist/components/VirtualTable/VirtualTable.cjs.map +1 -1
  177. package/dist/components/VirtualTable/VirtualTable.js.map +1 -1
  178. package/dist/components/Wizard/Wizard.cjs.map +1 -1
  179. package/dist/components/Wizard/Wizard.js.map +1 -1
  180. package/dist/editor/RichTextEditor.cjs.map +1 -1
  181. package/dist/editor/RichTextEditor.js.map +1 -1
  182. package/dist/forms/FormField.cjs.map +1 -1
  183. package/dist/forms/FormField.js.map +1 -1
  184. package/dist/geo/TrajectoryMap.cjs.map +1 -1
  185. package/dist/geo/TrajectoryMap.js.map +1 -1
  186. package/dist/geo/estimate.cjs.map +1 -1
  187. package/dist/geo/estimate.js.map +1 -1
  188. package/dist/geo/projection.cjs.map +1 -1
  189. package/dist/geo/projection.js.map +1 -1
  190. package/dist/hooks/use-event-listener.cjs.map +1 -1
  191. package/dist/hooks/use-event-listener.js.map +1 -1
  192. package/dist/hooks/use-local-storage.cjs.map +1 -1
  193. package/dist/hooks/use-local-storage.js.map +1 -1
  194. package/dist/hooks/use-sortable.cjs.map +1 -1
  195. package/dist/hooks/use-sortable.js.map +1 -1
  196. package/dist/http/api-client.cjs.map +1 -1
  197. package/dist/http/api-client.js.map +1 -1
  198. package/dist/http/errors.cjs.map +1 -1
  199. package/dist/http/errors.js.map +1 -1
  200. package/dist/http/resumable-upload.cjs.map +1 -1
  201. package/dist/http/resumable-upload.js.map +1 -1
  202. package/dist/http/upload-with-progress.cjs.map +1 -1
  203. package/dist/http/upload-with-progress.js.map +1 -1
  204. package/dist/i18n/I18nProvider.cjs.map +1 -1
  205. package/dist/i18n/I18nProvider.js.map +1 -1
  206. package/dist/imaging/canvas.cjs.map +1 -1
  207. package/dist/imaging/canvas.js.map +1 -1
  208. package/dist/imaging.d.ts +5 -0
  209. package/dist/logger/logger.cjs.map +1 -1
  210. package/dist/logger/logger.js.map +1 -1
  211. package/dist/oauth/GoogleSignIn.cjs.map +1 -1
  212. package/dist/oauth/GoogleSignIn.js.map +1 -1
  213. package/dist/offline/create-offline-sync.cjs.map +1 -1
  214. package/dist/offline/create-offline-sync.js.map +1 -1
  215. package/dist/perf/cache-size.cjs +1 -1
  216. package/dist/perf/cache-size.cjs.map +1 -1
  217. package/dist/perf/cache-size.js +27 -6
  218. package/dist/perf/cache-size.js.map +1 -1
  219. package/dist/sse/create-event-stream.cjs.map +1 -1
  220. package/dist/sse/create-event-stream.js.map +1 -1
  221. package/dist/styles.css +1 -1
  222. package/dist/sw/background-sync.cjs.map +1 -1
  223. package/dist/sw/background-sync.js.map +1 -1
  224. package/dist/sw/cache.cjs.map +1 -1
  225. package/dist/sw/cache.js.map +1 -1
  226. package/dist/sw.d.ts +12 -0
  227. package/dist/tabular/compact.cjs.map +1 -1
  228. package/dist/tabular/compact.js.map +1 -1
  229. package/dist/tabular/predictor.cjs.map +1 -1
  230. package/dist/tabular/predictor.js.map +1 -1
  231. package/dist/tabular.d.ts +7 -2
  232. package/dist/tempest-react-sdk.d.ts +133 -6
  233. package/dist/theme/ThemeProvider.cjs.map +1 -1
  234. package/dist/theme/ThemeProvider.js.map +1 -1
  235. package/dist/theme/color.cjs.map +1 -1
  236. package/dist/theme/color.js.map +1 -1
  237. package/dist/theme/create-theme.cjs.map +1 -1
  238. package/dist/theme/create-theme.js.map +1 -1
  239. package/dist/theme/data-viz-ramps.cjs +1 -1
  240. package/dist/theme/data-viz-ramps.cjs.map +1 -1
  241. package/dist/theme/data-viz-ramps.js +1 -1
  242. package/dist/theme/data-viz-ramps.js.map +1 -1
  243. package/dist/utils/storage.cjs.map +1 -1
  244. package/dist/utils/storage.js.map +1 -1
  245. package/dist/vision/core/canvas.cjs +1 -1
  246. package/dist/vision/core/canvas.cjs.map +1 -1
  247. package/dist/vision/core/canvas.js +4 -4
  248. package/dist/vision/core/canvas.js.map +1 -1
  249. package/dist/vision/core/exceptions.cjs +1 -1
  250. package/dist/vision/core/exceptions.cjs.map +1 -1
  251. package/dist/vision/core/exceptions.js +2 -2
  252. package/dist/vision/core/exceptions.js.map +1 -1
  253. package/dist/vision/core/graph.cjs.map +1 -1
  254. package/dist/vision/core/graph.js.map +1 -1
  255. package/dist/vision/core/metadata.cjs +2 -2
  256. package/dist/vision/core/metadata.cjs.map +1 -1
  257. package/dist/vision/core/metadata.js +10 -7
  258. package/dist/vision/core/metadata.js.map +1 -1
  259. package/dist/vision/core/providers.cjs.map +1 -1
  260. package/dist/vision/core/providers.js.map +1 -1
  261. package/dist/vision/core/session.cjs +1 -1
  262. package/dist/vision/core/session.cjs.map +1 -1
  263. package/dist/vision/core/session.js +8 -5
  264. package/dist/vision/core/session.js.map +1 -1
  265. package/dist/vision/core/timing.cjs.map +1 -1
  266. package/dist/vision/core/timing.js.map +1 -1
  267. package/dist/vision/fusion.cjs +2 -0
  268. package/dist/vision/fusion.cjs.map +1 -0
  269. package/dist/vision/fusion.js +42 -0
  270. package/dist/vision/fusion.js.map +1 -0
  271. package/dist/vision/index.cjs +1 -1
  272. package/dist/vision/index.cjs.map +1 -1
  273. package/dist/vision/index.js +23 -20
  274. package/dist/vision/index.js.map +1 -1
  275. package/dist/vision/io/image.cjs.map +1 -1
  276. package/dist/vision/io/image.js.map +1 -1
  277. package/dist/vision/labels.cjs +1 -1
  278. package/dist/vision/labels.cjs.map +1 -1
  279. package/dist/vision/labels.js +7 -4
  280. package/dist/vision/labels.js.map +1 -1
  281. package/dist/vision/luminance.cjs.map +1 -1
  282. package/dist/vision/luminance.js.map +1 -1
  283. package/dist/vision/postprocess/classification.cjs.map +1 -1
  284. package/dist/vision/postprocess/classification.js.map +1 -1
  285. package/dist/vision/postprocess/detection.cjs +1 -1
  286. package/dist/vision/postprocess/detection.cjs.map +1 -1
  287. package/dist/vision/postprocess/detection.js +3 -10
  288. package/dist/vision/postprocess/detection.js.map +1 -1
  289. package/dist/vision/postprocess/segmentation.cjs +1 -1
  290. package/dist/vision/postprocess/segmentation.cjs.map +1 -1
  291. package/dist/vision/postprocess/segmentation.js +11 -15
  292. package/dist/vision/postprocess/segmentation.js.map +1 -1
  293. package/dist/vision/preprocess/image.cjs.map +1 -1
  294. package/dist/vision/preprocess/image.js.map +1 -1
  295. package/dist/vision/preprocess/pipeline.cjs +2 -0
  296. package/dist/vision/preprocess/pipeline.cjs.map +1 -0
  297. package/dist/vision/preprocess/pipeline.js +61 -0
  298. package/dist/vision/preprocess/pipeline.js.map +1 -0
  299. package/dist/vision/results.cjs +1 -1
  300. package/dist/vision/results.cjs.map +1 -1
  301. package/dist/vision/results.js +23 -2
  302. package/dist/vision/results.js.map +1 -1
  303. package/dist/vision/tasks/base.cjs +1 -1
  304. package/dist/vision/tasks/base.cjs.map +1 -1
  305. package/dist/vision/tasks/base.js +9 -2
  306. package/dist/vision/tasks/base.js.map +1 -1
  307. package/dist/vision/tasks/classifier.cjs.map +1 -1
  308. package/dist/vision/tasks/classifier.js.map +1 -1
  309. package/dist/vision/tasks/detectClassify.cjs +2 -0
  310. package/dist/vision/tasks/detectClassify.cjs.map +1 -0
  311. package/dist/vision/tasks/detectClassify.js +221 -0
  312. package/dist/vision/tasks/detectClassify.js.map +1 -0
  313. package/dist/vision/tasks/detector.cjs +1 -1
  314. package/dist/vision/tasks/detector.cjs.map +1 -1
  315. package/dist/vision/tasks/detector.js +54 -29
  316. package/dist/vision/tasks/detector.js.map +1 -1
  317. package/dist/vision/tasks/segmenter.cjs +1 -1
  318. package/dist/vision/tasks/segmenter.cjs.map +1 -1
  319. package/dist/vision/tasks/segmenter.js +53 -28
  320. package/dist/vision/tasks/segmenter.js.map +1 -1
  321. package/dist/vision/types.cjs.map +1 -1
  322. package/dist/vision/types.js.map +1 -1
  323. package/dist/vision.cjs +1 -1
  324. package/dist/vision.d.ts +1517 -956
  325. package/dist/vision.js +25 -22
  326. package/dist/vite/tempest-icons.cjs.map +1 -1
  327. package/dist/vite/tempest-icons.js.map +1 -1
  328. package/dist/vite/tempest-pwa-icons.cjs.map +1 -1
  329. package/dist/vite/tempest-pwa-icons.js.map +1 -1
  330. package/dist/ws/create-web-socket.cjs.map +1 -1
  331. package/dist/ws/create-web-socket.js.map +1 -1
  332. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"detector.js","names":[],"sources":["../../../src/vision/tasks/detector.ts"],"sourcesContent":["/**\n * Object detection task using anchor-free YOLO ONNX models (v8/v9/v10/v11/v12).\n */\n\nimport type * as ort from \"onnxruntime-web\";\n\nimport { type ModelSource, type OrtSessionOptions, OrtSession } from \"../core/session\";\nimport { SpeedTimer } from \"../core/timing\";\n\nimport { type ImageInput, loadImage } from \"../io/image\";\nimport { detectionNumClasses, resolveInputSize } from \"../core/graph\";\nimport { modelNames } from \"../core/metadata\";\nimport { type LabelSpec, resolveLabels } from \"../labels\";\nimport { decodeYolo } from \"../postprocess/detection\";\nimport { letterbox, toCHW, toFloat32, toFloat32Tensor } from \"../preprocess/image\";\nimport { Boxes, DetectionResults } from \"../results\";\nimport { VisionTask } from \"./base\";\nimport { type BoundingBox, type DetectionResult, RGBImage } from \"../types\";\n\n/**\n * Decoder family for the model's detection head.\n *\n * - `\"yolo\"`: anchor-free YOLO head with output shape `[1, 4 + nc, N]` —\n * covers YOLOv8, v9, v10, v11, v12, v26 detect exports.\n *\n * The SDK does **not** auto-detect the head from the model — the caller is\n * responsible for picking a head that matches their export. Future families\n * (v5/v6/v7 with `[1, N, 5+nc]`) will be added as new literal members.\n */\nexport type DetectorHead = \"yolo\";\n\nexport interface DetectorOptions extends OrtSessionOptions {\n /**\n * Decoder family for the detection head. Default `\"yolo\"` covers\n * YOLOv8/v9/v10/v11/v12/v26.\n */\n readonly head?: DetectorHead;\n /** Class label spec — see {@link resolveLabels}. Defaults to the COCO 80-class preset. */\n readonly labels?: LabelSpec;\n /** Number of classes — used to validate the supplied labels. */\n readonly numClasses?: number;\n /**\n * Model input `[width, height]` in pixels for letterboxing.\n *\n * Only used when the model's graph leaves its spatial axes dynamic: a graph\n * that declares a static size always wins, since that is the only shape ONNX\n * Runtime will accept. Defaults to `[640, 640]`.\n */\n readonly inputSize?: readonly [number, number];\n /** Default minimum class score to keep a candidate. */\n readonly confThreshold?: number;\n /** Default IoU threshold for non-maximum suppression. */\n readonly iouThreshold?: number;\n /** Maximum number of detections per image. */\n readonly maxDetections?: number;\n}\n\nexport interface DetectorPredictOptions {\n /** Override the default confidence threshold. */\n readonly confThreshold?: number;\n /** Override the default IoU threshold. */\n readonly iouThreshold?: number;\n /**\n * If set, keep only detections whose `classId` is in this list.\n * Mirrors Ultralytics' `model.predict(img, classes=[0, 16])`.\n */\n readonly classes?: readonly number[];\n}\n\n/**\n * Object detector for anchor-free YOLO ONNX models (v8/v9/v10/v11/v12).\n *\n * `predict()` returns `Promise<DetectionResults[]>` (length 1 for a single\n * image), mirroring Ultralytics' `YOLO(\"img.jpg\")`. Iterate the envelope for\n * per-instance dataclasses, or use the bulk `boxes` view (`.xyxy`, `.xywh`,\n * `.xyxyn`, `.xywhn`, `.cls`, `.conf`).\n *\n * @example\n * ```typescript\n * const det = await Detector.create(\"/models/yolov8n.onnx\");\n * const results = await det.predict(\"/images/street.jpg\");\n * const r = results[0];\n * console.log(r.boxes.xyxy, r.boxes.cls, r.boxes.conf, r.names);\n * for (const d of r) {\n * console.log(d.cls, d.conf, d.box.xyxy);\n * }\n * ```\n */\nexport class Detector extends VisionTask {\n private constructor(\n session: OrtSession,\n private readonly _head: DetectorHead,\n private readonly _labels: readonly string[],\n private readonly _names: Readonly<Record<number, string>>,\n private readonly _inputSize: readonly [number, number],\n private readonly _confThreshold: number,\n private readonly _iouThreshold: number,\n private readonly _maxDetections: number,\n ) {\n super(session);\n }\n\n /** Load the model and resolve labels. */\n static async create(model: ModelSource, options: DetectorOptions = {}): Promise<Detector> {\n const head: DetectorHead = options.head ?? \"yolo\";\n if (head !== \"yolo\") {\n throw new Error(`Unsupported detector head '${head}'. Supported: 'yolo'.`);\n }\n const session = await OrtSession.create(model, options);\n const labels = resolveLabels(options.labels ?? modelNames(session.metadata) ?? \"coco\", {\n numClasses: options.numClasses ?? detectionNumClasses(session.outputShape) ?? undefined,\n });\n const names: Record<number, string> = {};\n for (let i = 0; i < labels.length; i++) {\n names[i] = labels[i] as string;\n }\n return new Detector(\n session,\n head,\n labels,\n names,\n resolveInputSize({\n graphShape: session.inputShape,\n requested: options.inputSize,\n fallback: [640, 640],\n }),\n options.confThreshold ?? 0.25,\n options.iouThreshold ?? 0.45,\n options.maxDetections ?? 300,\n );\n }\n\n /** The decoder family used to interpret the model's output. */\n get head(): DetectorHead {\n return this._head;\n }\n\n /** Class labels indexed by class id. */\n get labels(): readonly string[] {\n return this._labels;\n }\n\n /** Class id → class name dict (matches Ultralytics' `model.names`). */\n get names(): Readonly<Record<number, string>> {\n return this._names;\n }\n\n /**\n * The `[width, height]` this task preprocesses to.\n *\n * Resolved at creation time from the model's graph when it declares a static\n * input, so reading it back tells you the resolution inference really runs at\n * — not merely what was requested.\n */\n get inputSize(): readonly [number, number] {\n return this._inputSize;\n }\n\n /** Number of classes the model predicts. */\n get numClasses(): number {\n return this._labels.length;\n }\n\n /**\n * Alias for {@link predict} — call the detector like a torch `nn.Module`.\n *\n * Use as `det.call(img)` since JavaScript class instances are not callable;\n * for direct invocation, prefer `det.predict(img)`. The full\n * {@link DetectorPredictOptions} (including `classes`) is supported.\n */\n async call(\n image: ImageInput,\n options: DetectorPredictOptions = {},\n ): Promise<DetectionResults[]> {\n return this.predict(image, options);\n }\n\n /**\n * Run detection on a single image.\n *\n * The returned envelope carries a {@link Speed} breakdown in `speed`,\n * mirroring Ultralytics' `results[0].speed`.\n */\n async predict(\n image: ImageInput,\n options: DetectorPredictOptions = {},\n ): Promise<DetectionResults[]> {\n const timer = new SpeedTimer();\n const path = typeof image === \"string\" ? image : null;\n const original = await loadImage(image);\n timer.stage(\"load\");\n const { tensor, scale, padLeft, padTop } = this._preprocess(original);\n timer.stage(\"preprocess\");\n const outputs = await this._session.run({ [this._session.inputName]: tensor });\n timer.stage(\"inference\");\n\n const firstOutputName = this._session.outputNames[0];\n if (firstOutputName === undefined) {\n throw new Error(\"Detector model has no outputs.\");\n }\n const raw = outputs[firstOutputName];\n if (raw === undefined) {\n throw new Error(`Detector model output ${firstOutputName} missing from run() result.`);\n }\n\n const decodedAll = decodeYolo(raw.data as Float32Array, raw.dims, {\n originalWidth: original.width,\n originalHeight: original.height,\n padLeft,\n padTop,\n scale,\n confThreshold: options.confThreshold ?? this._confThreshold,\n iouThreshold: options.iouThreshold ?? this._iouThreshold,\n maxDetections: this._maxDetections,\n });\n\n const decoded =\n options.classes !== undefined\n ? (() => {\n const allowed = new Set(options.classes);\n return decodedAll.filter((d) => allowed.has(d.classId));\n })()\n : decodedAll;\n\n const detections = decoded.map((d) =>\n this._buildResult(original, d.bbox, d.classId, d.confidence),\n );\n\n const orig: readonly [number, number] = [original.height, original.width];\n const boxes = this._buildBoxes(detections, orig);\n timer.stage(\"postprocess\");\n return [\n new DetectionResults(\n boxes,\n detections,\n this._names,\n original,\n orig,\n path,\n timer.speed(),\n ),\n ];\n }\n\n private _preprocess(image: RGBImage): {\n tensor: ort.Tensor;\n scale: number;\n padLeft: number;\n padTop: number;\n } {\n const [tw, th] = this._inputSize;\n const lb = letterbox(image, tw, th);\n const f32 = toFloat32(lb.image);\n const chw = toCHW(f32, lb.image.width, lb.image.height, 3);\n return {\n tensor: toFloat32Tensor(chw, [1, 3, lb.image.height, lb.image.width]),\n scale: lb.scale,\n padLeft: lb.padLeft,\n padTop: lb.padTop,\n };\n }\n\n private _buildResult(\n original: RGBImage,\n bbox: BoundingBox,\n classId: number,\n confidence: number,\n ): DetectionResult {\n const [x1, y1, x2, y2] = bbox.asIntXyxy();\n const cx1 = Math.max(0, x1);\n const cy1 = Math.max(0, y1);\n const cx2 = Math.min(original.width, x2);\n const cy2 = Math.min(original.height, y2);\n\n let cropped: RGBImage;\n if (cx2 > cx1 && cy2 > cy1) {\n const cw = cx2 - cx1;\n const ch = cy2 - cy1;\n const out = new Uint8Array(cw * ch * 3);\n for (let row = 0; row < ch; row++) {\n const srcOffset = ((cy1 + row) * original.width + cx1) * 3;\n out.set(original.data.subarray(srcOffset, srcOffset + cw * 3), row * cw * 3);\n }\n cropped = new RGBImage(out, cw, ch);\n } else {\n cropped = new RGBImage(new Uint8Array(0), 0, 0);\n }\n\n const className = this._names[classId] ?? `class_${classId}`;\n\n return {\n classId,\n className,\n confidence,\n bbox,\n cls: classId,\n name: className,\n conf: confidence,\n box: bbox,\n croppedImage: cropped,\n };\n }\n\n private _buildBoxes(\n detections: readonly DetectionResult[],\n origShape: readonly [number, number],\n ): Boxes {\n const n = detections.length;\n const xyxy = new Float32Array(n * 4);\n const cls = new Int32Array(n);\n const conf = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n const d = detections[i] as DetectionResult;\n xyxy[i * 4] = d.bbox.x1;\n xyxy[i * 4 + 1] = d.bbox.y1;\n xyxy[i * 4 + 2] = d.bbox.x2;\n xyxy[i * 4 + 3] = d.bbox.y2;\n cls[i] = d.classId;\n conf[i] = d.confidence;\n }\n return new Boxes(xyxy, cls, conf, origShape);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAwFA,IAAa,IAAb,MAAa,UAAiB,EAAW;CAGhB;CACA;CACA;CACA;CACA;CACA;CACA;CARrB,YACI,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACF;EADmB,AAEjB,MAAM,CAAO,GARI,KAAA,QAAA,GACA,KAAA,UAAA,GACA,KAAA,SAAA,GACA,KAAA,aAAA,GACA,KAAA,iB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K,EAAE,SACX,EAAK,KAAK,EAAE;EAChB;EACA,OAAO,IAAI,EAAM,GAAM,GAAK,GAAM,CAAS;CAC/C;AACJ"}
1
+ {"version":3,"file":"detector.js","names":[],"sources":["../../../src/vision/tasks/detector.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Object detection task using anchor-free YOLO ONNX models (v8/v9/v10/v11/v12).\n */\n\nimport type * as ort from \"onnxruntime-web\";\n\nimport { type ModelSource, type OrtSessionOptions, OrtSession } from \"../core/session\";\nimport { SpeedTimer } from \"../core/timing\";\n\nimport { type ImageInput, loadImage } from \"../io/image\";\nimport { detectionNumClasses, resolveInputSize } from \"../core/graph\";\nimport { modelNames } from \"../core/metadata\";\nimport { type LabelSpec, defaultLabels, resolveLabels } from \"../labels\";\nimport { decodeYolo } from \"../postprocess/detection\";\nimport { toFloat32Tensor } from \"../preprocess/image\";\nimport { LetterboxPipeline, zeroTensorData } from \"../preprocess/pipeline\";\nimport { Boxes, DetectionResults } from \"../results\";\nimport { VisionTask, requireDetections } from \"./base\";\nimport { type BoundingBox, type DetectionResult, RGBImage } from \"../types\";\n\n/**\n * Decoder family for the model's detection head.\n *\n * - `\"yolo\"`: anchor-free YOLO head with output shape `[1, 4 + nc, N]` —\n * covers YOLOv8, v9, v10, v11, v12, v26 detect exports.\n *\n * The SDK does **not** auto-detect the head from the model — the caller is\n * responsible for picking a head that matches their export. Future families\n * (v5/v6/v7 with `[1, N, 5+nc]`) will be added as new literal members.\n */\nexport type DetectorHead = \"yolo\";\n\nexport interface DetectorOptions extends OrtSessionOptions {\n /**\n * Decoder family for the detection head. Default `\"yolo\"` covers\n * YOLOv8/v9/v10/v11/v12/v26.\n */\n readonly head?: DetectorHead;\n /** Class label spec — see {@link resolveLabels}. Defaults to the COCO 80-class preset. */\n readonly labels?: LabelSpec;\n /** Number of classes — used to validate the supplied labels. */\n readonly numClasses?: number;\n /**\n * Model input `[width, height]` in pixels for letterboxing.\n *\n * Only used when the model's graph leaves its spatial axes dynamic: a graph\n * that declares a static size always wins, since that is the only shape ONNX\n * Runtime will accept. Defaults to `[640, 640]`.\n */\n readonly inputSize?: readonly [number, number];\n /** Default minimum class score to keep a candidate. */\n readonly confThreshold?: number;\n /** Default IoU threshold for non-maximum suppression. */\n readonly iouThreshold?: number;\n /** Maximum number of detections per image. */\n readonly maxDetections?: number;\n /**\n * If `true`, a run that finds nothing throws {@link NoDetectionsError}\n * instead of returning an empty envelope. Default `false`, because looking\n * and finding nothing is a successful inference. Turn it on when an empty\n * result means the surrounding pipeline should stop rather than carry on with\n * zero rows. Can be overridden per `predict` call.\n */\n readonly raiseOnEmpty?: boolean;\n}\n\nexport interface DetectorPredictOptions {\n /** Override the default confidence threshold. */\n readonly confThreshold?: number;\n /** Override the default IoU threshold. */\n readonly iouThreshold?: number;\n /**\n * If set, keep only detections whose `classId` is in this list.\n * Mirrors Ultralytics' `model.predict(img, classes=[0, 16])`.\n */\n readonly classes?: readonly number[];\n /** Override the constructor's `raiseOnEmpty` setting for this call. */\n readonly raiseOnEmpty?: boolean;\n}\n\n/**\n * Object detector for anchor-free YOLO ONNX models (v8/v9/v10/v11/v12).\n *\n * `predict()` returns `Promise<DetectionResults[]>` (length 1 for a single\n * image), mirroring Ultralytics' `YOLO(\"img.jpg\")`. Iterate the envelope for\n * per-instance dataclasses, or use the bulk `boxes` view (`.xyxy`, `.xywh`,\n * `.xyxyn`, `.xywhn`, `.cls`, `.conf`).\n *\n * @example\n * ```typescript\n * const det = await Detector.create(\"/models/yolov8n.onnx\");\n * const results = await det.predict(\"/images/street.jpg\");\n * const r = results[0];\n * console.log(r.boxes.xyxy, r.boxes.cls, r.boxes.conf, r.names);\n * for (const d of r) {\n * console.log(d.cls, d.conf, d.box.xyxy);\n * }\n * ```\n */\nexport class Detector extends VisionTask {\n private constructor(\n session: OrtSession,\n private readonly _head: DetectorHead,\n private readonly _labels: readonly string[],\n private readonly _names: Readonly<Record<number, string>>,\n private readonly _inputSize: readonly [number, number],\n private readonly _confThreshold: number,\n private readonly _iouThreshold: number,\n private readonly _maxDetections: number,\n private readonly _raiseOnEmpty: boolean,\n ) {\n super(session);\n }\n\n private _pipelineCache: LetterboxPipeline | null = null;\n\n /**\n * Run the model once on a zero-filled tensor, paying one-time costs up front.\n *\n * The first inference of a session is not representative: WebGPU compiles its\n * shaders on it and the WASM backend faults in its arenas, which on a phone\n * can turn the first frame into seconds while every later frame is tens of\n * milliseconds. Calling this while a loading spinner is still up moves that\n * cost somewhere the user is already waiting.\n *\n * @param runs How many warm-up inferences to run. One is enough for WASM;\n * WebGPU sometimes settles on the second.\n */\n async warmup(runs: number = 1): Promise<void> {\n const [tw, th] = this._inputSize;\n for (let i = 0; i < runs; i++) {\n const tensor = toFloat32Tensor(zeroTensorData(tw, th), [1, 3, th, tw]);\n await this._session.run({ [this._session.inputName]: tensor });\n }\n }\n\n /**\n * The fused preprocessing pipeline, built on first use.\n *\n * Lazily, because constructing it allocates canvases: a task built in an\n * environment without a canvas implementation stays constructible, and only\n * fails if it is actually asked to preprocess something.\n */\n private get _pipeline(): LetterboxPipeline {\n if (this._pipelineCache === null) {\n this._pipelineCache = new LetterboxPipeline(this._inputSize[0], this._inputSize[1]);\n }\n return this._pipelineCache;\n }\n\n /** Load the model and resolve labels. */\n static async create(model: ModelSource, options: DetectorOptions = {}): Promise<Detector> {\n const head: DetectorHead = options.head ?? \"yolo\";\n if (head !== \"yolo\") {\n throw new Error(`Unsupported detector head '${head}'. Supported: 'yolo'.`);\n }\n const session = await OrtSession.create(model, options);\n const numClasses =\n options.numClasses ?? detectionNumClasses(session.outputShape) ?? undefined;\n const labels = resolveLabels(\n options.labels ?? modelNames(session.metadata) ?? defaultLabels(numClasses),\n { numClasses },\n );\n const names: Record<number, string> = {};\n for (let i = 0; i < labels.length; i++) {\n names[i] = labels[i] as string;\n }\n return new Detector(\n session,\n head,\n labels,\n names,\n resolveInputSize({\n graphShape: session.inputShape,\n requested: options.inputSize,\n fallback: [640, 640],\n }),\n options.confThreshold ?? 0.25,\n options.iouThreshold ?? 0.45,\n options.maxDetections ?? 300,\n options.raiseOnEmpty ?? false,\n );\n }\n\n /** The decoder family used to interpret the model's output. */\n get head(): DetectorHead {\n return this._head;\n }\n\n /** Class labels indexed by class id. */\n get labels(): readonly string[] {\n return this._labels;\n }\n\n /** Class id → class name dict (matches Ultralytics' `model.names`). */\n get names(): Readonly<Record<number, string>> {\n return this._names;\n }\n\n /**\n * The `[width, height]` this task preprocesses to.\n *\n * Resolved at creation time from the model's graph when it declares a static\n * input, so reading it back tells you the resolution inference really runs at\n * — not merely what was requested.\n */\n get inputSize(): readonly [number, number] {\n return this._inputSize;\n }\n\n /** Number of classes the model predicts. */\n get numClasses(): number {\n return this._labels.length;\n }\n\n /**\n * Alias for {@link predict} — call the detector like a torch `nn.Module`.\n *\n * Use as `det.call(img)` since JavaScript class instances are not callable;\n * for direct invocation, prefer `det.predict(img)`. The full\n * {@link DetectorPredictOptions} (including `classes`) is supported.\n */\n async call(\n image: ImageInput,\n options: DetectorPredictOptions = {},\n ): Promise<DetectionResults[]> {\n return this.predict(image, options);\n }\n\n /**\n * Run detection on a single image.\n *\n * The returned envelope carries a {@link Speed} breakdown in `speed`,\n * mirroring Ultralytics' `results[0].speed`.\n */\n async predict(\n image: ImageInput,\n options: DetectorPredictOptions = {},\n ): Promise<DetectionResults[]> {\n const timer = new SpeedTimer();\n const path = typeof image === \"string\" ? image : null;\n const original = await loadImage(image);\n timer.stage(\"load\");\n const { tensor, scale, padLeft, padTop } = this._preprocess(original);\n timer.stage(\"preprocess\");\n const outputs = await this._session.run({ [this._session.inputName]: tensor });\n this._pipeline.release();\n timer.stage(\"inference\");\n\n const firstOutputName = this._session.outputNames[0];\n if (firstOutputName === undefined) {\n throw new Error(\"Detector model has no outputs.\");\n }\n const raw = outputs[firstOutputName];\n if (raw === undefined) {\n throw new Error(`Detector model output ${firstOutputName} missing from run() result.`);\n }\n\n const threshold = options.confThreshold ?? this._confThreshold;\n const decodedAll = decodeYolo(raw.data as Float32Array, raw.dims, {\n originalWidth: original.width,\n originalHeight: original.height,\n padLeft,\n padTop,\n scale,\n confThreshold: threshold,\n iouThreshold: options.iouThreshold ?? this._iouThreshold,\n maxDetections: this._maxDetections,\n });\n\n const decoded =\n options.classes !== undefined\n ? (() => {\n const allowed = new Set(options.classes);\n return decodedAll.filter((d) => allowed.has(d.classId));\n })()\n : decodedAll;\n\n requireDetections(decoded.length, {\n raiseOnEmpty: options.raiseOnEmpty ?? this._raiseOnEmpty,\n confThreshold: threshold,\n classes: options.classes,\n path,\n });\n\n const detections = decoded.map((d) =>\n this._buildResult(original, d.bbox, d.classId, d.confidence),\n );\n\n const orig: readonly [number, number] = [original.height, original.width];\n const boxes = this._buildBoxes(detections, orig);\n timer.stage(\"postprocess\");\n return [\n new DetectionResults(\n boxes,\n detections,\n this._names,\n original,\n orig,\n path,\n timer.speed(),\n ),\n ];\n }\n\n /**\n * Letterbox and pack the image into the tensor the model expects.\n *\n * Runs through {@link LetterboxPipeline}, which fuses the resize, the\n * padding and the HWC-to-CHW float conversion into one `drawImage` plus one\n * readback loop, and reuses its output buffer between frames. The buffer is\n * handed straight to ONNX Runtime, so {@link _pipeline.release} must not be\n * called until the run resolves.\n */\n private _preprocess(image: RGBImage): {\n tensor: ort.Tensor;\n scale: number;\n padLeft: number;\n padTop: number;\n } {\n const [tw, th] = this._inputSize;\n const fused = this._pipeline.run(image);\n return {\n tensor: toFloat32Tensor(fused.data, [1, 3, th, tw]),\n scale: fused.scale,\n padLeft: fused.padLeft,\n padTop: fused.padTop,\n };\n }\n\n private _buildResult(\n original: RGBImage,\n bbox: BoundingBox,\n classId: number,\n confidence: number,\n ): DetectionResult {\n const [x1, y1, x2, y2] = bbox.asIntXyxy();\n const cx1 = Math.max(0, x1);\n const cy1 = Math.max(0, y1);\n const cx2 = Math.min(original.width, x2);\n const cy2 = Math.min(original.height, y2);\n\n let cropped: RGBImage;\n if (cx2 > cx1 && cy2 > cy1) {\n const cw = cx2 - cx1;\n const ch = cy2 - cy1;\n const out = new Uint8Array(cw * ch * 3);\n for (let row = 0; row < ch; row++) {\n const srcOffset = ((cy1 + row) * original.width + cx1) * 3;\n out.set(original.data.subarray(srcOffset, srcOffset + cw * 3), row * cw * 3);\n }\n cropped = new RGBImage(out, cw, ch);\n } else {\n cropped = new RGBImage(new Uint8Array(0), 0, 0);\n }\n\n const className = this._names[classId] ?? `class_${classId}`;\n\n return {\n classId,\n className,\n confidence,\n bbox,\n cls: classId,\n name: className,\n conf: confidence,\n box: bbox,\n croppedImage: cropped,\n };\n }\n\n private _buildBoxes(\n detections: readonly DetectionResult[],\n origShape: readonly [number, number],\n ): Boxes {\n const n = detections.length;\n const xyxy = new Float32Array(n * 4);\n const cls = new Int32Array(n);\n const conf = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n const d = detections[i] as DetectionResult;\n xyxy[i * 4] = d.bbox.x1;\n xyxy[i * 4 + 1] = d.bbox.y1;\n xyxy[i * 4 + 2] = d.bbox.x2;\n xyxy[i * 4 + 3] = d.bbox.y2;\n cls[i] = d.classId;\n conf[i] = d.confidence;\n }\n return new Boxes(xyxy, cls, conf, origShape);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAoGA,IAAa,IAAb,MAAa,UAAiB,EAAW;CAGhB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CATrB,YACI,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACF;EADmB,AAEjB,MAAM,CAAO,GATI,KAAA,QAAA,GACA,KAAA,UAAA,GACA,KAAA,SAAA,GACA,KAAA,aAAA,GACA,KAAA,iBAAA,GACA,KAAA,gBAAA,GACA,KAAA,iBAAA,GACA,KAAA,gBAAA;CAGrB;CAEA,iBAAmD;CAcnD,MAAM,OAAO,IAAe,GAAkB;EAC1C,IAAM,CAAC,GAAI,KAAM,KAAK;EACtB,KAAK,IAAI,IAAI,GAAG,IAAI,G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L,IAAM,IAAI,EAAW,QACf,IAAO,IAAI,aAAa,IAAI,CAAC,GAC7B,IAAM,IAAI,WAAW,CAAC,GACtB,IAAO,IAAI,aAAa,CAAC;EAC/B,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;GACxB,IAAM,IAAI,EAAW;GAMrB,AALA,EAAK,IAAI,KAAK,EAAE,KAAK,IACrB,EAAK,IAAI,IAAI,KAAK,EAAE,KAAK,IACzB,EAAK,IAAI,IAAI,KAAK,EAAE,KAAK,IACzB,EAAK,IAAI,IAAI,KAAK,EAAE,KAAK,IACzB,EAAI,KAAK,EAAE,SACX,EAAK,KAAK,EAAE;EAChB;EACA,OAAO,IAAI,EAAM,GAAM,GAAK,GAAM,CAAS;CAC/C;AACJ"}
@@ -1,2 +1,2 @@
1
- const e=require("../types.cjs"),t=require("../core/timing.cjs"),n=require("../results.cjs"),r=require("../labels.cjs"),i=require("../core/graph.cjs"),a=require("../core/metadata.cjs"),o=require("../core/session.cjs"),s=require("../io/image.cjs"),c=require("../preprocess/image.cjs"),l=require("../postprocess/segmentation.cjs"),u=require("./base.cjs");var d=class d extends u.VisionTask{_head;_labels;_names;_inputSize;_confThreshold;_iouThreshold;_maxDetections;_maskThreshold;constructor(e,t,n,r,i,a,o,s,c){super(e),this._head=t,this._labels=n,this._names=r,this._inputSize=i,this._confThreshold=a,this._iouThreshold=o,this._maxDetections=s,this._maskThreshold=c}static async create(e,t={}){let n=t.head??`yolo-seg`;if(n!==`yolo-seg`)throw Error(`Unsupported segmenter head '${n}'. Supported: 'yolo-seg'.`);let s=await o.OrtSession.create(e,t),c=r.resolveLabels(t.labels??a.modelNames(s.metadata)??`coco`,{numClasses:t.numClasses??i.detectionNumClasses(s.outputShape)??void 0}),l={};for(let e=0;e<c.length;e++)l[e]=c[e];return new d(s,n,c,l,i.resolveInputSize({graphShape:s.inputShape,requested:t.inputSize,fallback:[640,640]}),t.confThreshold??.25,t.iouThreshold??.45,t.maxDetections??300,t.maskThreshold??.5)}get head(){return this._head}get labels(){return this._labels}get names(){return this._names}get inputSize(){return this._inputSize}get numClasses(){return this._labels.length}async call(e,t={}){return this.predict(e,t)}async predict(e,r={}){let i=new t.SpeedTimer,a=typeof e==`string`?e:null,o=await s.loadImage(e);i.stage(`load`);let{tensor:c,scale:u,padLeft:d,padTop:f}=this._preprocess(o);i.stage(`preprocess`);let p=await this._session.run({[this._session.inputName]:c});i.stage(`inference`);let{perAnchor:m,prototypes:h}=this._splitOutputs(p),g=l.decodeYoloSeg(m.data,m.dims,h.data,h.dims,{numClasses:this._labels.length,inputWidth:this._inputSize[0],inputHeight:this._inputSize[1],originalWidth:o.width,originalHeight:o.height,padLeft:d,padTop:f,scale:u,confThreshold:r.confThreshold??this._confThreshold,iouThreshold:r.iouThreshold??this._iouThreshold,maxDetections:this._maxDetections,maskThreshold:this._maskThreshold}),_=(r.classes===void 0?g:(()=>{let e=new Set(r.classes);return g.filter(t=>e.has(t.classId))})()).map(e=>this._buildResult(o,e.bbox,e.classId,e.confidence,e.mask)),v=[o.height,o.width],y=this._buildBoxes(_,v),b=this._buildMasks(_,v);return i.stage(`postprocess`),[new n.SegmentationResults(y,b,_,this._names,o,v,a,i.speed())]}_preprocess(e){let[t,n]=this._inputSize,r=c.letterbox(e,t,n);return{tensor:c.toFloat32Tensor(c.toCHW(c.toFloat32(r.image),r.image.width,r.image.height,3),[1,3,r.image.height,r.image.width]),scale:r.scale,padLeft:r.padLeft,padTop:r.padTop}}_splitOutputs(e){let t,n;for(let r of this._session.outputNames){let i=e[r];i!==void 0&&(i.dims.length===3&&t===void 0?t=i:i.dims.length===4&&n===void 0&&(n=i))}if(t===void 0||n===void 0){let t=this._session.outputNames.map(t=>`${t}: ${JSON.stringify(e[t]?.dims??[])}`);throw Error(`Segmenter expected one 3-D and one 4-D output, got [${t.join(`, `)}].`)}return{perAnchor:t,prototypes:n}}_buildResult(t,n,r,i,a){let[o,s,c,l]=n.asIntXyxy(),u=Math.max(0,o),d=Math.max(0,s),f=Math.min(t.width,c),p=Math.min(t.height,l),m,h=a;if(f>u&&p>d&&a.data.length>0){let n=f-u,r=p-d,i=Math.min(a.width,n),o=Math.min(a.height,r),s=new Uint8Array(i*o*3);for(let e=0;e<o;e++){let n=((d+e)*t.width+u)*3,r=e*i*3,o=e*a.width;for(let e=0;e<i;e++)if(a.data[o+e]!==0){let i=n+e*3,a=r+e*3;s[a]=t.data[i],s[a+1]=t.data[i+1],s[a+2]=t.data[i+2]}}if(m=new e.RGBImage(s,i,o),i!==a.width||o!==a.height){let t=new Uint8Array(i*o);for(let e=0;e<o;e++)t.set(a.data.subarray(e*a.width,e*a.width+i),e*i);h=new e.Mask(t,i,o)}}else h=new e.Mask(new Uint8Array,0,0),m=new e.RGBImage(new Uint8Array,0,0);let g=this._names[r]??`class_${r}`;return{classId:r,className:g,confidence:i,bbox:n,cls:r,name:g,conf:i,box:n,mask:h,segmentedImage:m}}_buildBoxes(e,t){let r=e.length,i=new Float32Array(r*4),a=new Int32Array(r),o=new Float32Array(r);for(let t=0;t<r;t++){let n=e[t];i[t*4]=n.bbox.x1,i[t*4+1]=n.bbox.y1,i[t*4+2]=n.bbox.x2,i[t*4+3]=n.bbox.y2,a[t]=n.classId,o[t]=n.confidence}return new n.Boxes(i,a,o,t)}_buildMasks(e,t){let r=new Float32Array(e.length*4);for(let t=0;t<e.length;t++){let n=e[t];r[t*4]=n.bbox.x1,r[t*4+1]=n.bbox.y1,r[t*4+2]=n.bbox.x2,r[t*4+3]=n.bbox.y2}return new n.Masks(e.map(e=>e.mask),r,t)}};exports.Segmenter=d;
1
+ const e=require("../types.cjs"),t=require("../core/timing.cjs"),n=require("../results.cjs"),r=require("../labels.cjs"),i=require("../core/graph.cjs"),a=require("../core/metadata.cjs"),o=require("../core/session.cjs"),s=require("../io/image.cjs"),c=require("../preprocess/image.cjs"),l=require("../preprocess/pipeline.cjs"),u=require("../postprocess/segmentation.cjs"),d=require("./base.cjs");var f=class f extends d.VisionTask{_head;_labels;_names;_inputSize;_confThreshold;_iouThreshold;_maxDetections;_maskThreshold;_raiseOnEmpty;constructor(e,t,n,r,i,a,o,s,c,l){super(e),this._head=t,this._labels=n,this._names=r,this._inputSize=i,this._confThreshold=a,this._iouThreshold=o,this._maxDetections=s,this._maskThreshold=c,this._raiseOnEmpty=l}_pipelineCache=null;async warmup(e=1){let[t,n]=this._inputSize;for(let r=0;r<e;r++){let e=c.toFloat32Tensor(l.zeroTensorData(t,n),[1,3,n,t]);await this._session.run({[this._session.inputName]:e})}}get _pipeline(){return this._pipelineCache===null&&(this._pipelineCache=new l.LetterboxPipeline(this._inputSize[0],this._inputSize[1])),this._pipelineCache}static async create(e,t={}){let n=t.head??`yolo-seg`;if(n!==`yolo-seg`)throw Error(`Unsupported segmenter head '${n}'. Supported: 'yolo-seg'.`);let s=await o.OrtSession.create(e,t),c=t.numClasses??i.detectionNumClasses(s.outputShape)??void 0,l=r.resolveLabels(t.labels??a.modelNames(s.metadata)??r.defaultLabels(c),{numClasses:c}),u={};for(let e=0;e<l.length;e++)u[e]=l[e];return new f(s,n,l,u,i.resolveInputSize({graphShape:s.inputShape,requested:t.inputSize,fallback:[640,640]}),t.confThreshold??.25,t.iouThreshold??.45,t.maxDetections??300,t.maskThreshold??.5,t.raiseOnEmpty??!1)}get head(){return this._head}get labels(){return this._labels}get names(){return this._names}get inputSize(){return this._inputSize}get numClasses(){return this._labels.length}async call(e,t={}){return this.predict(e,t)}async predict(e,r={}){let i=new t.SpeedTimer,a=typeof e==`string`?e:null,o=await s.loadImage(e);i.stage(`load`);let{tensor:c,scale:l,padLeft:f,padTop:p}=this._preprocess(o);i.stage(`preprocess`);let m=await this._session.run({[this._session.inputName]:c});this._pipeline.release(),i.stage(`inference`);let{perAnchor:h,prototypes:g}=this._splitOutputs(m),_=r.confThreshold??this._confThreshold,v=u.decodeYoloSeg(h.data,h.dims,g.data,g.dims,{numClasses:this._labels.length,inputWidth:this._inputSize[0],inputHeight:this._inputSize[1],originalWidth:o.width,originalHeight:o.height,padLeft:f,padTop:p,scale:l,confThreshold:_,iouThreshold:r.iouThreshold??this._iouThreshold,maxDetections:this._maxDetections,maskThreshold:this._maskThreshold}),y=r.classes===void 0?v:(()=>{let e=new Set(r.classes);return v.filter(t=>e.has(t.classId))})();d.requireDetections(y.length,{raiseOnEmpty:r.raiseOnEmpty??this._raiseOnEmpty,confThreshold:_,classes:r.classes,path:a});let b=y.map(e=>this._buildResult(o,e.bbox,e.classId,e.confidence,e.mask)),x=[o.height,o.width],S=this._buildBoxes(b,x),C=this._buildMasks(b,x);return i.stage(`postprocess`),[new n.SegmentationResults(S,C,b,this._names,o,x,a,i.speed())]}_preprocess(e){let[t,n]=this._inputSize,r=this._pipeline.run(e);return{tensor:c.toFloat32Tensor(r.data,[1,3,n,t]),scale:r.scale,padLeft:r.padLeft,padTop:r.padTop}}_splitOutputs(e){let t,n;for(let r of this._session.outputNames){let i=e[r];i!==void 0&&(i.dims.length===3&&t===void 0?t=i:i.dims.length===4&&n===void 0&&(n=i))}if(t===void 0||n===void 0){let t=this._session.outputNames.map(t=>`${t}: ${JSON.stringify(e[t]?.dims??[])}`);throw Error(`Segmenter expected one 3-D and one 4-D output, got [${t.join(`, `)}].`)}return{perAnchor:t,prototypes:n}}_buildResult(t,n,r,i,a){let[o,s,c,l]=n.asIntXyxy(),u=Math.max(0,o),d=Math.max(0,s),f=Math.min(t.width,c),p=Math.min(t.height,l),m,h=a;if(f>u&&p>d&&a.data.length>0){let n=f-u,r=p-d,i=Math.min(a.width,n),o=Math.min(a.height,r),s=new Uint8Array(i*o*3);for(let e=0;e<o;e++){let n=((d+e)*t.width+u)*3,r=e*i*3,o=e*a.width;for(let e=0;e<i;e++)if(a.data[o+e]!==0){let i=n+e*3,a=r+e*3;s[a]=t.data[i],s[a+1]=t.data[i+1],s[a+2]=t.data[i+2]}}if(m=new e.RGBImage(s,i,o),i!==a.width||o!==a.height){let t=new Uint8Array(i*o);for(let e=0;e<o;e++)t.set(a.data.subarray(e*a.width,e*a.width+i),e*i);h=new e.Mask(t,i,o)}}else h=new e.Mask(new Uint8Array,0,0),m=new e.RGBImage(new Uint8Array,0,0);let g=this._names[r]??`class_${r}`;return{classId:r,className:g,confidence:i,bbox:n,cls:r,name:g,conf:i,box:n,mask:h,segmentedImage:m}}_buildBoxes(e,t){let r=e.length,i=new Float32Array(r*4),a=new Int32Array(r),o=new Float32Array(r);for(let t=0;t<r;t++){let n=e[t];i[t*4]=n.bbox.x1,i[t*4+1]=n.bbox.y1,i[t*4+2]=n.bbox.x2,i[t*4+3]=n.bbox.y2,a[t]=n.classId,o[t]=n.confidence}return new n.Boxes(i,a,o,t)}_buildMasks(e,t){let r=new Float32Array(e.length*4);for(let t=0;t<e.length;t++){let n=e[t];r[t*4]=n.bbox.x1,r[t*4+1]=n.bbox.y1,r[t*4+2]=n.bbox.x2,r[t*4+3]=n.bbox.y2}return new n.Masks(e.map(e=>e.mask),r,t)}};exports.Segmenter=f;
2
2
  //# sourceMappingURL=segmenter.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"segmenter.cjs","names":[],"sources":["../../../src/vision/tasks/segmenter.ts"],"sourcesContent":["/**\n * Instance-segmentation task using YOLO seg ONNX models (v8-seg / v11-seg / ...).\n */\n\nimport type * as ort from \"onnxruntime-web\";\n\nimport { type ModelSource, type OrtSessionOptions, OrtSession } from \"../core/session\";\nimport { SpeedTimer } from \"../core/timing\";\n\nimport { type ImageInput, loadImage } from \"../io/image\";\nimport { detectionNumClasses, resolveInputSize } from \"../core/graph\";\nimport { modelNames } from \"../core/metadata\";\nimport { type LabelSpec, resolveLabels } from \"../labels\";\nimport { decodeYoloSeg } from \"../postprocess/segmentation\";\nimport { letterbox, toCHW, toFloat32, toFloat32Tensor } from \"../preprocess/image\";\nimport { Boxes, Masks, SegmentationResults } from \"../results\";\nimport { VisionTask } from \"./base\";\nimport { type BoundingBox, type SegmentationResult, Mask, RGBImage } from \"../types\";\n\n/**\n * Decoder family for the segmentation head.\n *\n * - `\"yolo-seg\"`: YOLO instance-segmentation head with two outputs —\n * `[1, 4 + nc + nm, N]` per-anchor predictions plus `[1, nm, mh, mw]`\n * prototype masks. Covers YOLOv8-seg, v11-seg, v26-seg.\n *\n * The SDK does **not** auto-detect this — the caller is responsible for\n * picking a head that matches their export.\n */\nexport type SegmenterHead = \"yolo-seg\";\n\nexport interface SegmenterOptions extends OrtSessionOptions {\n /**\n * Decoder family for the segmentation head. Default `\"yolo-seg\"` covers\n * YOLOv8-seg/v11-seg/v26-seg.\n */\n readonly head?: SegmenterHead;\n /** Class label spec — see {@link resolveLabels}. Defaults to the COCO 80-class preset. */\n readonly labels?: LabelSpec;\n /** Number of classes — used to validate the supplied labels. */\n readonly numClasses?: number;\n /**\n * Model input `[width, height]` in pixels for letterboxing.\n *\n * Only used when the model's graph leaves its spatial axes dynamic: a graph\n * that declares a static size always wins, since that is the only shape ONNX\n * Runtime will accept. Defaults to `[640, 640]`.\n */\n readonly inputSize?: readonly [number, number];\n /** Default minimum class score to keep a candidate. */\n readonly confThreshold?: number;\n /** Default IoU threshold for non-maximum suppression. */\n readonly iouThreshold?: number;\n /** Maximum number of instances per image. */\n readonly maxDetections?: number;\n /** Probability cutoff applied to soft masks. Defaults to `0.5`. */\n readonly maskThreshold?: number;\n}\n\nexport interface SegmenterPredictOptions {\n readonly confThreshold?: number;\n readonly iouThreshold?: number;\n /**\n * If set, keep only instances whose `classId` is in this list.\n * Mirrors Ultralytics' `model.predict(img, classes=[0, 16])`.\n */\n readonly classes?: readonly number[];\n}\n\n/**\n * Instance segmenter for YOLO seg ONNX models (v8-seg / v11-seg / ...).\n *\n * The model is expected to expose two outputs:\n *\n * 1. `output0`: `(1, 4 + numClasses + numMaskCoefs, numAnchors)` — per-anchor\n * predictions (boxes, class scores, mask coefficients).\n * 2. `output1`: `(1, numMaskCoefs, maskH, maskW)` — prototype masks.\n *\n * `predict()` returns `Promise<SegmentationResults[]>` (length 1 for a\n * single image), mirroring Ultralytics' API. The envelope exposes:\n *\n * - `boxes`: bulk numpy view (`xyxy`, `xywh`, `xyxyn`, `xywhn`, `cls`, `conf`).\n * - `masks`: per-instance binary masks cropped to each box.\n * - per-instance {@link SegmentationResult} via iteration.\n *\n * @example\n * ```typescript\n * const seg = await Segmenter.create(\"/models/yolov8n-seg.onnx\");\n * const r = (await seg.predict(\"/images/street.jpg\"))[0];\n * for (const inst of r) {\n * console.log(inst.cls, inst.conf, inst.box.xyxy);\n * }\n * ```\n */\nexport class Segmenter extends VisionTask {\n private constructor(\n session: OrtSession,\n private readonly _head: SegmenterHead,\n private readonly _labels: readonly string[],\n private readonly _names: Readonly<Record<number, string>>,\n private readonly _inputSize: readonly [number, number],\n private readonly _confThreshold: number,\n private readonly _iouThreshold: number,\n private readonly _maxDetections: number,\n private readonly _maskThreshold: number,\n ) {\n super(session);\n }\n\n /** Load the model and resolve labels. */\n static async create(model: ModelSource, options: SegmenterOptions = {}): Promise<Segmenter> {\n const head: SegmenterHead = options.head ?? \"yolo-seg\";\n if (head !== \"yolo-seg\") {\n throw new Error(`Unsupported segmenter head '${head}'. Supported: 'yolo-seg'.`);\n }\n const session = await OrtSession.create(model, options);\n const labels = resolveLabels(options.labels ?? modelNames(session.metadata) ?? \"coco\", {\n numClasses: options.numClasses ?? detectionNumClasses(session.outputShape) ?? undefined,\n });\n const names: Record<number, string> = {};\n for (let i = 0; i < labels.length; i++) {\n names[i] = labels[i] as string;\n }\n return new Segmenter(\n session,\n head,\n labels,\n names,\n resolveInputSize({\n graphShape: session.inputShape,\n requested: options.inputSize,\n fallback: [640, 640],\n }),\n options.confThreshold ?? 0.25,\n options.iouThreshold ?? 0.45,\n options.maxDetections ?? 300,\n options.maskThreshold ?? 0.5,\n );\n }\n\n /** The decoder family used to interpret the model's output. */\n get head(): SegmenterHead {\n return this._head;\n }\n\n /** Class labels indexed by class id. */\n get labels(): readonly string[] {\n return this._labels;\n }\n\n /** Class id → class name dict (matches Ultralytics' `model.names`). */\n get names(): Readonly<Record<number, string>> {\n return this._names;\n }\n\n /**\n * The `[width, height]` this task preprocesses to.\n *\n * Resolved at creation time from the model's graph when it declares a static\n * input, so reading it back tells you the resolution inference really runs at\n * — not merely what was requested.\n */\n get inputSize(): readonly [number, number] {\n return this._inputSize;\n }\n\n /** Number of classes the model predicts. */\n get numClasses(): number {\n return this._labels.length;\n }\n\n /** Alias for {@link predict} (parity with PyTorch `nn.Module.__call__`). */\n async call(\n image: ImageInput,\n options: SegmenterPredictOptions = {},\n ): Promise<SegmentationResults[]> {\n return this.predict(image, options);\n }\n\n /** Run instance segmentation on a single image. */\n async predict(\n image: ImageInput,\n options: SegmenterPredictOptions = {},\n ): Promise<SegmentationResults[]> {\n const timer = new SpeedTimer();\n const path = typeof image === \"string\" ? image : null;\n const original = await loadImage(image);\n timer.stage(\"load\");\n const { tensor, scale, padLeft, padTop } = this._preprocess(original);\n timer.stage(\"preprocess\");\n const outputs = await this._session.run({ [this._session.inputName]: tensor });\n timer.stage(\"inference\");\n\n const { perAnchor, prototypes } = this._splitOutputs(outputs);\n\n const decodedAll = decodeYoloSeg(\n perAnchor.data as Float32Array,\n perAnchor.dims,\n prototypes.data as Float32Array,\n prototypes.dims,\n {\n numClasses: this._labels.length,\n inputWidth: this._inputSize[0],\n inputHeight: this._inputSize[1],\n originalWidth: original.width,\n originalHeight: original.height,\n padLeft,\n padTop,\n scale,\n confThreshold: options.confThreshold ?? this._confThreshold,\n iouThreshold: options.iouThreshold ?? this._iouThreshold,\n maxDetections: this._maxDetections,\n maskThreshold: this._maskThreshold,\n },\n );\n\n const decoded =\n options.classes !== undefined\n ? (() => {\n const allowed = new Set(options.classes);\n return decodedAll.filter((d) => allowed.has(d.classId));\n })()\n : decodedAll;\n\n const detections = decoded.map((d) =>\n this._buildResult(original, d.bbox, d.classId, d.confidence, d.mask),\n );\n\n const orig: readonly [number, number] = [original.height, original.width];\n const boxes = this._buildBoxes(detections, orig);\n const masks = this._buildMasks(detections, orig);\n timer.stage(\"postprocess\");\n return [\n new SegmentationResults(\n boxes,\n masks,\n detections,\n this._names,\n original,\n orig,\n path,\n timer.speed(),\n ),\n ];\n }\n\n private _preprocess(image: RGBImage): {\n tensor: ort.Tensor;\n scale: number;\n padLeft: number;\n padTop: number;\n } {\n const [tw, th] = this._inputSize;\n const lb = letterbox(image, tw, th);\n const f32 = toFloat32(lb.image);\n const chw = toCHW(f32, lb.image.width, lb.image.height, 3);\n return {\n tensor: toFloat32Tensor(chw, [1, 3, lb.image.height, lb.image.width]),\n scale: lb.scale,\n padLeft: lb.padLeft,\n padTop: lb.padTop,\n };\n }\n\n private _splitOutputs(outputs: Record<string, ort.Tensor>): {\n perAnchor: ort.Tensor;\n prototypes: ort.Tensor;\n } {\n let perAnchor: ort.Tensor | undefined;\n let prototypes: ort.Tensor | undefined;\n for (const name of this._session.outputNames) {\n const t = outputs[name];\n if (t === undefined) continue;\n if (t.dims.length === 3 && perAnchor === undefined) {\n perAnchor = t;\n } else if (t.dims.length === 4 && prototypes === undefined) {\n prototypes = t;\n }\n }\n if (perAnchor === undefined || prototypes === undefined) {\n const shapes = this._session.outputNames.map(\n (n) => `${n}: ${JSON.stringify(outputs[n]?.dims ?? [])}`,\n );\n throw new Error(\n `Segmenter expected one 3-D and one 4-D output, got [${shapes.join(\", \")}].`,\n );\n }\n return { perAnchor, prototypes };\n }\n\n private _buildResult(\n original: RGBImage,\n bbox: BoundingBox,\n classId: number,\n confidence: number,\n mask: Mask,\n ): SegmentationResult {\n const [x1, y1, x2, y2] = bbox.asIntXyxy();\n const cx1 = Math.max(0, x1);\n const cy1 = Math.max(0, y1);\n const cx2 = Math.min(original.width, x2);\n const cy2 = Math.min(original.height, y2);\n\n let segmentedImage: RGBImage;\n let finalMask = mask;\n if (cx2 > cx1 && cy2 > cy1 && mask.data.length > 0) {\n const cropW = cx2 - cx1;\n const cropH = cy2 - cy1;\n const mw = Math.min(mask.width, cropW);\n const mh = Math.min(mask.height, cropH);\n const segData = new Uint8Array(mw * mh * 3);\n for (let row = 0; row < mh; row++) {\n const srcRowOffset = ((cy1 + row) * original.width + cx1) * 3;\n const dstRowOffset = row * mw * 3;\n const maskRowOffset = row * mask.width;\n for (let col = 0; col < mw; col++) {\n const m = mask.data[maskRowOffset + col];\n if (m !== 0) {\n const s = srcRowOffset + col * 3;\n const d = dstRowOffset + col * 3;\n segData[d] = original.data[s];\n segData[d + 1] = original.data[s + 1];\n segData[d + 2] = original.data[s + 2];\n }\n }\n }\n segmentedImage = new RGBImage(segData, mw, mh);\n if (mw !== mask.width || mh !== mask.height) {\n const trimmed = new Uint8Array(mw * mh);\n for (let row = 0; row < mh; row++) {\n trimmed.set(\n mask.data.subarray(row * mask.width, row * mask.width + mw),\n row * mw,\n );\n }\n finalMask = new Mask(trimmed, mw, mh);\n }\n } else {\n finalMask = new Mask(new Uint8Array(0), 0, 0);\n segmentedImage = new RGBImage(new Uint8Array(0), 0, 0);\n }\n\n const className = this._names[classId] ?? `class_${classId}`;\n\n return {\n classId,\n className,\n confidence,\n bbox,\n cls: classId,\n name: className,\n conf: confidence,\n box: bbox,\n mask: finalMask,\n segmentedImage,\n };\n }\n\n private _buildBoxes(\n detections: readonly SegmentationResult[],\n origShape: readonly [number, number],\n ): Boxes {\n const n = detections.length;\n const xyxy = new Float32Array(n * 4);\n const cls = new Int32Array(n);\n const conf = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n const d = detections[i] as SegmentationResult;\n xyxy[i * 4] = d.bbox.x1;\n xyxy[i * 4 + 1] = d.bbox.y1;\n xyxy[i * 4 + 2] = d.bbox.x2;\n xyxy[i * 4 + 3] = d.bbox.y2;\n cls[i] = d.classId;\n conf[i] = d.confidence;\n }\n return new Boxes(xyxy, cls, conf, origShape);\n }\n\n private _buildMasks(\n detections: readonly SegmentationResult[],\n origShape: readonly [number, number],\n ): Masks {\n const xyxy = new Float32Array(detections.length * 4);\n for (let i = 0; i < detections.length; i++) {\n const d = detections[i] as SegmentationResult;\n xyxy[i * 4] = d.bbox.x1;\n xyxy[i * 4 + 1] = d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AAO,CACH,UACA,YACA,aACA,OACA,IAAK,EACL,KAAM,EACN,KAAM,EACN,IAAK,EACL,KAAM,EACN,gBACJ,CACJ,CAEA,YACI,EACA,EACK,CACL,IAAM,EAAI,EAAW,OACf,EAAO,IAAI,aAAa,EAAI,CAAC,EAC7B,EAAM,IAAI,WAAW,CAAC,EACtB,EAAO,IAAI,aAAa,CAAC,EAC/B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,CACxB,IAAM,EAAI,EAAW,GACrB,EAAK,EAAI,GAAK,EAAE,KAAK,GACrB,EAAK,EAAI,EAAI,GAAK,EAAE,KAAK,GACzB,EAAK,EAAI,EAAI,GAAK,EAAE,KAAK,GACzB,EAAK,EAAI,EAAI,GAAK,EAAE,KAAK,GACzB,EAAI,GAAK,EAAE,QACX,EAAK,GAAK,EAAE,UAChB,CACA,OAAO,IAAI,EAAA,MAAM,EAAM,EAAK,EAAM,CAAS,CAC/C,CAEA,YACI,EACA,EACK,CACL,IAAM,EAAO,IAAI,aAAa,EAAW,OAAS,CAAC,EACnD,IAAK,IAAI,EAAI,EAAG,EAAI,EAAW,OAAQ,IAAK,CACxC,IAAM,EAAI,EAAW,GACrB,EAAK,EAAI,GAAK,EAAE,KAAK,GACrB,EAAK,EAAI,EAAI,GAAK,EAAE,KAAK,GACzB,EAAK,EAAI,EAAI,GAAK,EAAE,KAAK,GACzB,EAAK,EAAI,EAAI,GAAK,EAAE,KAAK,EAC7B,CACA,OAAO,IAAI,EAAA,MACP,EAAW,IAAK,GAAM,EAAE,IAAI,EAC5B,EACA,CACJ,CACJ,CACJ"}
1
+ {"version":3,"file":"segmenter.cjs","names":[],"sources":["../../../src/vision/tasks/segmenter.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Instance-segmentation task using YOLO seg ONNX models (v8-seg / v11-seg / ...).\n */\n\nimport type * as ort from \"onnxruntime-web\";\n\nimport { type ModelSource, type OrtSessionOptions, OrtSession } from \"../core/session\";\nimport { SpeedTimer } from \"../core/timing\";\n\nimport { type ImageInput, loadImage } from \"../io/image\";\nimport { detectionNumClasses, resolveInputSize } from \"../core/graph\";\nimport { modelNames } from \"../core/metadata\";\nimport { type LabelSpec, defaultLabels, resolveLabels } from \"../labels\";\nimport { decodeYoloSeg } from \"../postprocess/segmentation\";\nimport { toFloat32Tensor } from \"../preprocess/image\";\nimport { LetterboxPipeline, zeroTensorData } from \"../preprocess/pipeline\";\nimport { Boxes, Masks, SegmentationResults } from \"../results\";\nimport { VisionTask, requireDetections } from \"./base\";\nimport { type BoundingBox, type SegmentationResult, Mask, RGBImage } from \"../types\";\n\n/**\n * Decoder family for the segmentation head.\n *\n * - `\"yolo-seg\"`: YOLO instance-segmentation head with two outputs —\n * `[1, 4 + nc + nm, N]` per-anchor predictions plus `[1, nm, mh, mw]`\n * prototype masks. Covers YOLOv8-seg, v11-seg, v26-seg.\n *\n * The SDK does **not** auto-detect this — the caller is responsible for\n * picking a head that matches their export.\n */\nexport type SegmenterHead = \"yolo-seg\";\n\nexport interface SegmenterOptions extends OrtSessionOptions {\n /**\n * Decoder family for the segmentation head. Default `\"yolo-seg\"` covers\n * YOLOv8-seg/v11-seg/v26-seg.\n */\n readonly head?: SegmenterHead;\n /** Class label spec — see {@link resolveLabels}. Defaults to the COCO 80-class preset. */\n readonly labels?: LabelSpec;\n /** Number of classes — used to validate the supplied labels. */\n readonly numClasses?: number;\n /**\n * Model input `[width, height]` in pixels for letterboxing.\n *\n * Only used when the model's graph leaves its spatial axes dynamic: a graph\n * that declares a static size always wins, since that is the only shape ONNX\n * Runtime will accept. Defaults to `[640, 640]`.\n */\n readonly inputSize?: readonly [number, number];\n /** Default minimum class score to keep a candidate. */\n readonly confThreshold?: number;\n /** Default IoU threshold for non-maximum suppression. */\n readonly iouThreshold?: number;\n /** Maximum number of instances per image. */\n readonly maxDetections?: number;\n /**\n * If `true`, a run that finds nothing throws {@link NoDetectionsError}\n * instead of returning an empty envelope. Default `false`, because looking\n * and finding nothing is a successful inference. Turn it on when an empty\n * result means the surrounding pipeline should stop rather than carry on with\n * zero rows. Can be overridden per `predict` call.\n */\n readonly raiseOnEmpty?: boolean;\n /** Probability cutoff applied to soft masks. Defaults to `0.5`. */\n readonly maskThreshold?: number;\n}\n\nexport interface SegmenterPredictOptions {\n readonly confThreshold?: number;\n readonly iouThreshold?: number;\n /**\n * If set, keep only instances whose `classId` is in this list.\n * Mirrors Ultralytics' `model.predict(img, classes=[0, 16])`.\n */\n readonly classes?: readonly number[];\n /** Override the constructor's `raiseOnEmpty` setting for this call. */\n readonly raiseOnEmpty?: boolean;\n}\n\n/**\n * Instance segmenter for YOLO seg ONNX models (v8-seg / v11-seg / ...).\n *\n * The model is expected to expose two outputs:\n *\n * 1. `output0`: `(1, 4 + numClasses + numMaskCoefs, numAnchors)` — per-anchor\n * predictions (boxes, class scores, mask coefficients).\n * 2. `output1`: `(1, numMaskCoefs, maskH, maskW)` — prototype masks.\n *\n * `predict()` returns `Promise<SegmentationResults[]>` (length 1 for a\n * single image), mirroring Ultralytics' API. The envelope exposes:\n *\n * - `boxes`: bulk numpy view (`xyxy`, `xywh`, `xyxyn`, `xywhn`, `cls`, `conf`).\n * - `masks`: per-instance binary masks cropped to each box.\n * - per-instance {@link SegmentationResult} via iteration.\n *\n * @example\n * ```typescript\n * const seg = await Segmenter.create(\"/models/yolov8n-seg.onnx\");\n * const r = (await seg.predict(\"/images/street.jpg\"))[0];\n * for (const inst of r) {\n * console.log(inst.cls, inst.conf, inst.box.xyxy);\n * }\n * ```\n */\nexport class Segmenter extends VisionTask {\n private constructor(\n session: OrtSession,\n private readonly _head: SegmenterHead,\n private readonly _labels: readonly string[],\n private readonly _names: Readonly<Record<number, string>>,\n private readonly _inputSize: readonly [number, number],\n private readonly _confThreshold: number,\n private readonly _iouThreshold: number,\n private readonly _maxDetections: number,\n private readonly _maskThreshold: number,\n private readonly _raiseOnEmpty: boolean,\n ) {\n super(session);\n }\n\n private _pipelineCache: LetterboxPipeline | null = null;\n\n /**\n * Run the model once on a zero-filled tensor, paying one-time costs up front.\n *\n * The first inference of a session is not representative: WebGPU compiles its\n * shaders on it and the WASM backend faults in its arenas, which on a phone\n * can turn the first frame into seconds while every later frame is tens of\n * milliseconds. Calling this while a loading spinner is still up moves that\n * cost somewhere the user is already waiting.\n *\n * @param runs How many warm-up inferences to run. One is enough for WASM;\n * WebGPU sometimes settles on the second.\n */\n async warmup(runs: number = 1): Promise<void> {\n const [tw, th] = this._inputSize;\n for (let i = 0; i < runs; i++) {\n const tensor = toFloat32Tensor(zeroTensorData(tw, th), [1, 3, th, tw]);\n await this._session.run({ [this._session.inputName]: tensor });\n }\n }\n\n /**\n * The fused preprocessing pipeline, built on first use.\n *\n * Lazily, because constructing it allocates canvases: a task built in an\n * environment without a canvas implementation stays constructible, and only\n * fails if it is actually asked to preprocess something.\n */\n private get _pipeline(): LetterboxPipeline {\n if (this._pipelineCache === null) {\n this._pipelineCache = new LetterboxPipeline(this._inputSize[0], this._inputSize[1]);\n }\n return this._pipelineCache;\n }\n\n /** Load the model and resolve labels. */\n static async create(model: ModelSource, options: SegmenterOptions = {}): Promise<Segmenter> {\n const head: SegmenterHead = options.head ?? \"yolo-seg\";\n if (head !== \"yolo-seg\") {\n throw new Error(`Unsupported segmenter head '${head}'. Supported: 'yolo-seg'.`);\n }\n const session = await OrtSession.create(model, options);\n const numClasses =\n options.numClasses ?? detectionNumClasses(session.outputShape) ?? undefined;\n const labels = resolveLabels(\n options.labels ?? modelNames(session.metadata) ?? defaultLabels(numClasses),\n { numClasses },\n );\n const names: Record<number, string> = {};\n for (let i = 0; i < labels.length; i++) {\n names[i] = labels[i] as string;\n }\n return new Segmenter(\n session,\n head,\n labels,\n names,\n resolveInputSize({\n graphShape: session.inputShape,\n requested: options.inputSize,\n fallback: [640, 640],\n }),\n options.confThreshold ?? 0.25,\n options.iouThreshold ?? 0.45,\n options.maxDetections ?? 300,\n options.maskThreshold ?? 0.5,\n options.raiseOnEmpty ?? false,\n );\n }\n\n /** The decoder family used to interpret the model's output. */\n get head(): SegmenterHead {\n return this._head;\n }\n\n /** Class labels indexed by class id. */\n get labels(): readonly string[] {\n return this._labels;\n }\n\n /** Class id → class name dict (matches Ultralytics' `model.names`). */\n get names(): Readonly<Record<number, string>> {\n return this._names;\n }\n\n /**\n * The `[width, height]` this task preprocesses to.\n *\n * Resolved at creation time from the model's graph when it declares a static\n * input, so reading it back tells you the resolution inference really runs at\n * — not merely what was requested.\n */\n get inputSize(): readonly [number, number] {\n return this._inputSize;\n }\n\n /** Number of classes the model predicts. */\n get numClasses(): number {\n return this._labels.length;\n }\n\n /** Alias for {@link predict} (parity with PyTorch `nn.Module.__call__`). */\n async call(\n image: ImageInput,\n options: SegmenterPredictOptions = {},\n ): Promise<SegmentationResults[]> {\n return this.predict(image, options);\n }\n\n /** Run instance segmentation on a single image. */\n async predict(\n image: ImageInput,\n options: SegmenterPredictOptions = {},\n ): Promise<SegmentationResults[]> {\n const timer = new SpeedTimer();\n const path = typeof image === \"string\" ? image : null;\n const original = await loadImage(image);\n timer.stage(\"load\");\n const { tensor, scale, padLeft, padTop } = this._preprocess(original);\n timer.stage(\"preprocess\");\n const outputs = await this._session.run({ [this._session.inputName]: tensor });\n this._pipeline.release();\n timer.stage(\"inference\");\n\n const { perAnchor, prototypes } = this._splitOutputs(outputs);\n\n const threshold = options.confThreshold ?? this._confThreshold;\n const decodedAll = decodeYoloSeg(\n perAnchor.data as Float32Array,\n perAnchor.dims,\n prototypes.data as Float32Array,\n prototypes.dims,\n {\n numClasses: this._labels.length,\n inputWidth: this._inputSize[0],\n inputHeight: this._inputSize[1],\n originalWidth: original.width,\n originalHeight: original.height,\n padLeft,\n padTop,\n scale,\n confThreshold: threshold,\n iouThreshold: options.iouThreshold ?? this._iouThreshold,\n maxDetections: this._maxDetections,\n maskThreshold: this._maskThreshold,\n },\n );\n\n const decoded =\n options.classes !== undefined\n ? (() => {\n const allowed = new Set(options.classes);\n return decodedAll.filter((d) => allowed.has(d.classId));\n })()\n : decodedAll;\n\n requireDetections(decoded.length, {\n raiseOnEmpty: options.raiseOnEmpty ?? this._raiseOnEmpty,\n confThreshold: threshold,\n classes: options.classes,\n path,\n });\n\n const detections = decoded.map((d) =>\n this._buildResult(original, d.bbox, d.classId, d.confidence, d.mask),\n );\n\n const orig: readonly [number, number] = [original.height, original.width];\n const boxes = this._buildBoxes(detections, orig);\n const masks = this._buildMasks(detections, orig);\n timer.stage(\"postprocess\");\n return [\n new SegmentationResults(\n boxes,\n masks,\n detections,\n this._names,\n original,\n orig,\n path,\n timer.speed(),\n ),\n ];\n }\n\n private _preprocess(image: RGBImage): {\n tensor: ort.Tensor;\n scale: number;\n padLeft: number;\n padTop: number;\n } {\n const [tw, th] = this._inputSize;\n const fused = this._pipeline.run(image);\n return {\n tensor: toFloat32Tensor(fused.data, [1, 3, th, tw]),\n scale: fused.scale,\n padLeft: fused.padLeft,\n padTop: fused.padTop,\n };\n }\n\n private _splitOutputs(outputs: Record<string, ort.Tensor>): {\n perAnchor: ort.Tensor;\n prototypes: ort.Tensor;\n } {\n let perAnchor: ort.Tensor | undefined;\n let prototypes: ort.Tensor | undefined;\n for (const name of this._session.outputNames) {\n const t = outputs[name];\n if (t === undefined) continue;\n if (t.dims.length === 3 && perAnchor === undefined) {\n perAnchor = t;\n } else if (t.dims.length === 4 && prototypes === undefined) {\n prototypes = t;\n }\n }\n if (perAnchor === undefined || prototypes === undefined) {\n const shapes = this._session.outputNames.map(\n (n) => `${n}: ${JSON.stringify(outputs[n]?.dims ?? [])}`,\n );\n throw new Error(\n `Segmenter expected one 3-D and one 4-D output, got [${shapes.join(\", \")}].`,\n );\n }\n return { perAnchor, prototypes };\n }\n\n private _buildResult(\n original: RGBImage,\n bbox: BoundingBox,\n classId: number,\n confidence: number,\n mask: Mask,\n ): SegmentationResult {\n const [x1, y1, x2, y2] = bbox.asIntXyxy();\n const cx1 = Math.max(0, x1);\n const cy1 = Math.max(0, y1);\n const cx2 = Math.min(original.width, x2);\n const cy2 = Math.min(original.height, y2);\n\n let segmentedImage: RGBImage;\n let finalMask = mask;\n if (cx2 > cx1 && cy2 > cy1 && mask.data.length > 0) {\n const cropW = cx2 - cx1;\n const cropH = cy2 - cy1;\n const mw = Math.min(mask.width, cropW);\n const mh = Math.min(mask.height, cropH);\n const segData = new Uint8Array(mw * mh * 3);\n for (let row = 0; row < mh; row++) {\n const srcRowOffset = ((cy1 + row) * original.width + cx1) * 3;\n const dstRowOffset = row * mw * 3;\n const maskRowOffset = row * mask.width;\n for (let col = 0; col < mw; col++) {\n const m = mask.data[maskRowOffset + col];\n if (m !== 0) {\n const s = srcRowOffset + col * 3;\n const d = dstRowOffset + col * 3;\n segData[d] = original.data[s];\n segData[d + 1] = original.data[s + 1];\n segData[d + 2] = original.data[s + 2];\n }\n }\n }\n segmentedImage = new RGBImage(segData, mw, mh);\n if (mw !== mask.width || mh !== mask.height) {\n const trimmed = new Uint8Array(mw * mh);\n for (let row = 0; row < mh; row++) {\n trimmed.set(\n mask.data.subarray(row * mask.width, row * mask.width + mw),\n row * mw,\n );\n }\n finalMask = new Mask(trimmed, mw, mh);\n }\n } else {\n finalMask = new Mask(new Uint8Array(0), 0, 0);\n segmentedImage = new RGBImage(new Uint8Array(0), 0, 0);\n }\n\n const className = this._names[classId] ?? `class_${classId}`;\n\n return {\n classId,\n className,\n confidence,\n bbox,\n cls: classId,\n name: className,\n conf: confidence,\n box: bbox,\n mask: finalMask,\n segmentedImage,\n };\n }\n\n private _buildBoxes(\n detections: readonly SegmentationResult[],\n origShape: readonly [number, number],\n ): Boxes {\n const n = detections.length;\n const xyxy = new Float32Array(n * 4);\n const cls = new Int32Array(n);\n const conf = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n const d = detections[i] as SegmentationResult;\n xyxy[i * 4] = d.bbox.x1;\n xyxy[i * 4 + 1] = d.bbox.y1;\n xyxy[i * 4 + 2] = d.bbox.x2;\n xyxy[i * 4 + 3] = d.bbox.y2;\n cls[i] = d.classId;\n conf[i] = d.confidence;\n }\n return new Boxes(xyxy, cls, conf, origShape);\n }\n\n private _buildMasks(\n detections: readonly SegmentationResult[],\n origShape: readonly [number, number],\n ): Masks {\n const xyxy = new Float32Array(detections.length * 4);\n for (let i = 0; i < detections.length; i++) {\n const d = detections[i] as SegmentationResult;\n xyxy[i * 4] = d.bbox.x1;\n xyxy[i * 4 + 1] = d.bbox.y1;\n xyxy[i * 4 + 2] = d.bbox.x2;\n xyxy[i * 4 + 3] = d.bbox.y2;\n }\n return new Masks(\n detections.map((d) => d.mask),\n xyxy,\n origShape,\n );\n }\n}\n"],"mappings":"wYA0GA,IAAa,EAAb,MAAa,UAAkB,EAAA,UAAW,CAGjB,MACA,QACA,OACA,WACA,eACA,cACA,eACA,eACA,cAVrB,YACI,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACF,CACE,MAAM,CAAO,EAVI,KAAA,MAAA,EACA,KAAA,QAAA,EACA,KAAA,OAAA,EACA,KAAA,WAAA,EACA,KAAA,eAAA,EACA,KAAA,cAAA,EACA,KAAA,eAAA,EACA,KAAA,eAAA,EACA,KAAA,cAAA,CAGrB,CAEA,eAAmD,KAcnD,MAAM,OAAO,EAAe,EAAkB,CAC1C,GAAM,CAAC,EAAI,GAAM,KAAK,WACtB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,IAAK,CAC3B,IAAM,EAAS,EAAA,gBAAgB,EAAA,eAAe,EAAI,CAAE,EAAG,CAAC,EAAG,EAAG,EAAI,CAAE,CAAC,EACrE,MAAM,KAAK,SAAS,IAAI,EAAG,KAAK,SAAS,WAAY,CAAO,CAAC,CACjE,CACJ,CASA,IAAY,WAA+B,CAIvC,OAHI,KAAK,iBAAmB,OACxB,KAAK,eAAiB,IAAI,EAAA,kBAAkB,KAAK,WAAW,GAAI,KAAK,WAAW,EAAE,GAE/E,KAAK,cAChB,CAGA,aAAa,OAAO,EAAoB,EA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AAK,EAAE,KAAK,GACzB,EAAK,EAAI,EAAI,GAAK,EAAE,KAAK,GACzB,EAAK,EAAI,EAAI,GAAK,EAAE,KAAK,GACzB,EAAI,GAAK,EAAE,QACX,EAAK,GAAK,EAAE,UAChB,CACA,OAAO,IAAI,EAAA,MAAM,EAAM,EAAK,EAAM,CAAS,CAC/C,CAEA,YACI,EACA,EACK,CACL,IAAM,EAAO,IAAI,aAAa,EAAW,OAAS,CAAC,EACnD,IAAK,IAAI,EAAI,EAAG,EAAI,EAAW,OAAQ,IAAK,CACxC,IAAM,EAAI,EAAW,GACrB,EAAK,EAAI,GAAK,EAAE,KAAK,GACrB,EAAK,EAAI,EAAI,GAAK,EAAE,KAAK,GACzB,EAAK,EAAI,EAAI,GAAK,EAAE,KAAK,GACzB,EAAK,EAAI,EAAI,GAAK,EAAE,KAAK,EAC7B,CACA,OAAO,IAAI,EAAA,MACP,EAAW,IAAK,GAAM,EAAE,IAAI,EAC5B,EACA,CACJ,CACJ,CACJ"}
@@ -1,16 +1,17 @@
1
1
  import { Mask as e, RGBImage as t } from "../types.js";
2
2
  import { SpeedTimer as n } from "../core/timing.js";
3
3
  import { Boxes as r, Masks as i, SegmentationResults as a } from "../results.js";
4
- import { resolveLabels as o } from "../labels.js";
5
- import { detectionNumClasses as s, resolveInputSize as c } from "../core/graph.js";
6
- import { modelNames as l } from "../core/metadata.js";
7
- import { OrtSession as u } from "../core/session.js";
8
- import { loadImage as d } from "../io/image.js";
9
- import { letterbox as f, toCHW as p, toFloat32 as m, toFloat32Tensor as h } from "../preprocess/image.js";
4
+ import { defaultLabels as o, resolveLabels as s } from "../labels.js";
5
+ import { detectionNumClasses as c, resolveInputSize as l } from "../core/graph.js";
6
+ import { modelNames as u } from "../core/metadata.js";
7
+ import { OrtSession as d } from "../core/session.js";
8
+ import { loadImage as f } from "../io/image.js";
9
+ import { toFloat32Tensor as p } from "../preprocess/image.js";
10
+ import { LetterboxPipeline as m, zeroTensorData as h } from "../preprocess/pipeline.js";
10
11
  import { decodeYoloSeg as g } from "../postprocess/segmentation.js";
11
- import { VisionTask as _ } from "./base.js";
12
+ import { VisionTask as _, requireDetections as v } from "./base.js";
12
13
  //#region src/vision/tasks/segmenter.ts
13
- var v = class v extends _ {
14
+ var y = class y extends _ {
14
15
  _head;
15
16
  _labels;
16
17
  _names;
@@ -19,19 +20,36 @@ var v = class v extends _ {
19
20
  _iouThreshold;
20
21
  _maxDetections;
21
22
  _maskThreshold;
22
- constructor(e, t, n, r, i, a, o, s, c) {
23
- super(e), this._head = t, this._labels = n, this._names = r, this._inputSize = i, this._confThreshold = a, this._iouThreshold = o, this._maxDetections = s, this._maskThreshold = c;
23
+ _raiseOnEmpty;
24
+ constructor(e, t, n, r, i, a, o, s, c, l) {
25
+ super(e), this._head = t, this._labels = n, this._names = r, this._inputSize = i, this._confThreshold = a, this._iouThreshold = o, this._maxDetections = s, this._maskThreshold = c, this._raiseOnEmpty = l;
26
+ }
27
+ _pipelineCache = null;
28
+ async warmup(e = 1) {
29
+ let [t, n] = this._inputSize;
30
+ for (let r = 0; r < e; r++) {
31
+ let e = p(h(t, n), [
32
+ 1,
33
+ 3,
34
+ n,
35
+ t
36
+ ]);
37
+ await this._session.run({ [this._session.inputName]: e });
38
+ }
39
+ }
40
+ get _pipeline() {
41
+ return this._pipelineCache === null && (this._pipelineCache = new m(this._inputSize[0], this._inputSize[1])), this._pipelineCache;
24
42
  }
25
43
  static async create(e, t = {}) {
26
44
  let n = t.head ?? "yolo-seg";
27
45
  if (n !== "yolo-seg") throw Error(`Unsupported segmenter head '${n}'. Supported: 'yolo-seg'.`);
28
- let r = await u.create(e, t), i = o(t.labels ?? l(r.metadata) ?? "coco", { numClasses: t.numClasses ?? s(r.outputShape) ?? void 0 }), a = {};
29
- for (let e = 0; e < i.length; e++) a[e] = i[e];
30
- return new v(r, n, i, a, c({
46
+ let r = await d.create(e, t), i = t.numClasses ?? c(r.outputShape) ?? void 0, a = s(t.labels ?? u(r.metadata) ?? o(i), { numClasses: i }), f = {};
47
+ for (let e = 0; e < a.length; e++) f[e] = a[e];
48
+ return new y(r, n, a, f, l({
31
49
  graphShape: r.inputShape,
32
50
  requested: t.inputSize,
33
51
  fallback: [640, 640]
34
- }), t.confThreshold ?? .25, t.iouThreshold ?? .45, t.maxDetections ?? 300, t.maskThreshold ?? .5);
52
+ }), t.confThreshold ?? .25, t.iouThreshold ?? .45, t.maxDetections ?? 300, t.maskThreshold ?? .5, t.raiseOnEmpty ?? !1);
35
53
  }
36
54
  get head() {
37
55
  return this._head;
@@ -52,13 +70,13 @@ var v = class v extends _ {
52
70
  return this.predict(e, t);
53
71
  }
54
72
  async predict(e, t = {}) {
55
- let r = new n(), i = typeof e == "string" ? e : null, o = await d(e);
73
+ let r = new n(), i = typeof e == "string" ? e : null, o = await f(e);
56
74
  r.stage("load");
57
75
  let { tensor: s, scale: c, padLeft: l, padTop: u } = this._preprocess(o);
58
76
  r.stage("preprocess");
59
- let f = await this._session.run({ [this._session.inputName]: s });
60
- r.stage("inference");
61
- let { perAnchor: p, prototypes: m } = this._splitOutputs(f), h = g(p.data, p.dims, m.data, m.dims, {
77
+ let d = await this._session.run({ [this._session.inputName]: s });
78
+ this._pipeline.release(), r.stage("inference");
79
+ let { perAnchor: p, prototypes: m } = this._splitOutputs(d), h = t.confThreshold ?? this._confThreshold, _ = g(p.data, p.dims, m.data, m.dims, {
62
80
  numClasses: this._labels.length,
63
81
  inputWidth: this._inputSize[0],
64
82
  inputHeight: this._inputSize[1],
@@ -67,24 +85,31 @@ var v = class v extends _ {
67
85
  padLeft: l,
68
86
  padTop: u,
69
87
  scale: c,
70
- confThreshold: t.confThreshold ?? this._confThreshold,
88
+ confThreshold: h,
71
89
  iouThreshold: t.iouThreshold ?? this._iouThreshold,
72
90
  maxDetections: this._maxDetections,
73
91
  maskThreshold: this._maskThreshold
74
- }), _ = (t.classes === void 0 ? h : (() => {
92
+ }), y = t.classes === void 0 ? _ : (() => {
75
93
  let e = new Set(t.classes);
76
- return h.filter((t) => e.has(t.classId));
77
- })()).map((e) => this._buildResult(o, e.bbox, e.classId, e.confidence, e.mask)), v = [o.height, o.width], y = this._buildBoxes(_, v), b = this._buildMasks(_, v);
78
- return r.stage("postprocess"), [new a(y, b, _, this._names, o, v, i, r.speed())];
94
+ return _.filter((t) => e.has(t.classId));
95
+ })();
96
+ v(y.length, {
97
+ raiseOnEmpty: t.raiseOnEmpty ?? this._raiseOnEmpty,
98
+ confThreshold: h,
99
+ classes: t.classes,
100
+ path: i
101
+ });
102
+ let b = y.map((e) => this._buildResult(o, e.bbox, e.classId, e.confidence, e.mask)), x = [o.height, o.width], S = this._buildBoxes(b, x), C = this._buildMasks(b, x);
103
+ return r.stage("postprocess"), [new a(S, C, b, this._names, o, x, i, r.speed())];
79
104
  }
80
105
  _preprocess(e) {
81
- let [t, n] = this._inputSize, r = f(e, t, n);
106
+ let [t, n] = this._inputSize, r = this._pipeline.run(e);
82
107
  return {
83
- tensor: h(p(m(r.image), r.image.width, r.image.height, 3), [
108
+ tensor: p(r.data, [
84
109
  1,
85
110
  3,
86
- r.image.height,
87
- r.image.width
111
+ n,
112
+ t
88
113
  ]),
89
114
  scale: r.scale,
90
115
  padLeft: r.padLeft,
@@ -155,6 +180,6 @@ var v = class v extends _ {
155
180
  }
156
181
  };
157
182
  //#endregion
158
- export { v as Segmenter };
183
+ export { y as Segmenter };
159
184
 
160
185
  //# sourceMappingURL=segmenter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"segmenter.js","names":[],"sources":["../../../src/vision/tasks/segmenter.ts"],"sourcesContent":["/**\n * Instance-segmentation task using YOLO seg ONNX models (v8-seg / v11-seg / ...).\n */\n\nimport type * as ort from \"onnxruntime-web\";\n\nimport { type ModelSource, type OrtSessionOptions, OrtSession } from \"../core/session\";\nimport { SpeedTimer } from \"../core/timing\";\n\nimport { type ImageInput, loadImage } from \"../io/image\";\nimport { detectionNumClasses, resolveInputSize } from \"../core/graph\";\nimport { modelNames } from \"../core/metadata\";\nimport { type LabelSpec, resolveLabels } from \"../labels\";\nimport { decodeYoloSeg } from \"../postprocess/segmentation\";\nimport { letterbox, toCHW, toFloat32, toFloat32Tensor } from \"../preprocess/image\";\nimport { Boxes, Masks, SegmentationResults } from \"../results\";\nimport { VisionTask } from \"./base\";\nimport { type BoundingBox, type SegmentationResult, Mask, RGBImage } from \"../types\";\n\n/**\n * Decoder family for the segmentation head.\n *\n * - `\"yolo-seg\"`: YOLO instance-segmentation head with two outputs —\n * `[1, 4 + nc + nm, N]` per-anchor predictions plus `[1, nm, mh, mw]`\n * prototype masks. Covers YOLOv8-seg, v11-seg, v26-seg.\n *\n * The SDK does **not** auto-detect this — the caller is responsible for\n * picking a head that matches their export.\n */\nexport type SegmenterHead = \"yolo-seg\";\n\nexport interface SegmenterOptions extends OrtSessionOptions {\n /**\n * Decoder family for the segmentation head. Default `\"yolo-seg\"` covers\n * YOLOv8-seg/v11-seg/v26-seg.\n */\n readonly head?: SegmenterHead;\n /** Class label spec — see {@link resolveLabels}. Defaults to the COCO 80-class preset. */\n readonly labels?: LabelSpec;\n /** Number of classes — used to validate the supplied labels. */\n readonly numClasses?: number;\n /**\n * Model input `[width, height]` in pixels for letterboxing.\n *\n * Only used when the model's graph leaves its spatial axes dynamic: a graph\n * that declares a static size always wins, since that is the only shape ONNX\n * Runtime will accept. Defaults to `[640, 640]`.\n */\n readonly inputSize?: readonly [number, number];\n /** Default minimum class score to keep a candidate. */\n readonly confThreshold?: number;\n /** Default IoU threshold for non-maximum suppression. */\n readonly iouThreshold?: number;\n /** Maximum number of instances per image. */\n readonly maxDetections?: number;\n /** Probability cutoff applied to soft masks. Defaults to `0.5`. */\n readonly maskThreshold?: number;\n}\n\nexport interface SegmenterPredictOptions {\n readonly confThreshold?: number;\n readonly iouThreshold?: number;\n /**\n * If set, keep only instances whose `classId` is in this list.\n * Mirrors Ultralytics' `model.predict(img, classes=[0, 16])`.\n */\n readonly classes?: readonly number[];\n}\n\n/**\n * Instance segmenter for YOLO seg ONNX models (v8-seg / v11-seg / ...).\n *\n * The model is expected to expose two outputs:\n *\n * 1. `output0`: `(1, 4 + numClasses + numMaskCoefs, numAnchors)` — per-anchor\n * predictions (boxes, class scores, mask coefficients).\n * 2. `output1`: `(1, numMaskCoefs, maskH, maskW)` — prototype masks.\n *\n * `predict()` returns `Promise<SegmentationResults[]>` (length 1 for a\n * single image), mirroring Ultralytics' API. The envelope exposes:\n *\n * - `boxes`: bulk numpy view (`xyxy`, `xywh`, `xyxyn`, `xywhn`, `cls`, `conf`).\n * - `masks`: per-instance binary masks cropped to each box.\n * - per-instance {@link SegmentationResult} via iteration.\n *\n * @example\n * ```typescript\n * const seg = await Segmenter.create(\"/models/yolov8n-seg.onnx\");\n * const r = (await seg.predict(\"/images/street.jpg\"))[0];\n * for (const inst of r) {\n * console.log(inst.cls, inst.conf, inst.box.xyxy);\n * }\n * ```\n */\nexport class Segmenter extends VisionTask {\n private constructor(\n session: OrtSession,\n private readonly _head: SegmenterHead,\n private readonly _labels: readonly string[],\n private readonly _names: Readonly<Record<number, string>>,\n private readonly _inputSize: readonly [number, number],\n private readonly _confThreshold: number,\n private readonly _iouThreshold: number,\n private readonly _maxDetections: number,\n private readonly _maskThreshold: number,\n ) {\n super(session);\n }\n\n /** Load the model and resolve labels. */\n static async create(model: ModelSource, options: SegmenterOptions = {}): Promise<Segmenter> {\n const head: SegmenterHead = options.head ?? \"yolo-seg\";\n if (head !== \"yolo-seg\") {\n throw new Error(`Unsupported segmenter head '${head}'. Supported: 'yolo-seg'.`);\n }\n const session = await OrtSession.create(model, options);\n const labels = resolveLabels(options.labels ?? modelNames(session.metadata) ?? \"coco\", {\n numClasses: options.numClasses ?? detectionNumClasses(session.outputShape) ?? undefined,\n });\n const names: Record<number, string> = {};\n for (let i = 0; i < labels.length; i++) {\n names[i] = labels[i] as string;\n }\n return new Segmenter(\n session,\n head,\n labels,\n names,\n resolveInputSize({\n graphShape: session.inputShape,\n requested: options.inputSize,\n fallback: [640, 640],\n }),\n options.confThreshold ?? 0.25,\n options.iouThreshold ?? 0.45,\n options.maxDetections ?? 300,\n options.maskThreshold ?? 0.5,\n );\n }\n\n /** The decoder family used to interpret the model's output. */\n get head(): SegmenterHead {\n return this._head;\n }\n\n /** Class labels indexed by class id. */\n get labels(): readonly string[] {\n return this._labels;\n }\n\n /** Class id → class name dict (matches Ultralytics' `model.names`). */\n get names(): Readonly<Record<number, string>> {\n return this._names;\n }\n\n /**\n * The `[width, height]` this task preprocesses to.\n *\n * Resolved at creation time from the model's graph when it declares a static\n * input, so reading it back tells you the resolution inference really runs at\n * — not merely what was requested.\n */\n get inputSize(): readonly [number, number] {\n return this._inputSize;\n }\n\n /** Number of classes the model predicts. */\n get numClasses(): number {\n return this._labels.length;\n }\n\n /** Alias for {@link predict} (parity with PyTorch `nn.Module.__call__`). */\n async call(\n image: ImageInput,\n options: SegmenterPredictOptions = {},\n ): Promise<SegmentationResults[]> {\n return this.predict(image, options);\n }\n\n /** Run instance segmentation on a single image. */\n async predict(\n image: ImageInput,\n options: SegmenterPredictOptions = {},\n ): Promise<SegmentationResults[]> {\n const timer = new SpeedTimer();\n const path = typeof image === \"string\" ? image : null;\n const original = await loadImage(image);\n timer.stage(\"load\");\n const { tensor, scale, padLeft, padTop } = this._preprocess(original);\n timer.stage(\"preprocess\");\n const outputs = await this._session.run({ [this._session.inputName]: tensor });\n timer.stage(\"inference\");\n\n const { perAnchor, prototypes } = this._splitOutputs(outputs);\n\n const decodedAll = decodeYoloSeg(\n perAnchor.data as Float32Array,\n perAnchor.dims,\n prototypes.data as Float32Array,\n prototypes.dims,\n {\n numClasses: this._labels.length,\n inputWidth: this._inputSize[0],\n inputHeight: this._inputSize[1],\n originalWidth: original.width,\n originalHeight: original.height,\n padLeft,\n padTop,\n scale,\n confThreshold: options.confThreshold ?? this._confThreshold,\n iouThreshold: options.iouThreshold ?? this._iouThreshold,\n maxDetections: this._maxDetections,\n maskThreshold: this._maskThreshold,\n },\n );\n\n const decoded =\n options.classes !== undefined\n ? (() => {\n const allowed = new Set(options.classes);\n return decodedAll.filter((d) => allowed.has(d.classId));\n })()\n : decodedAll;\n\n const detections = decoded.map((d) =>\n this._buildResult(original, d.bbox, d.classId, d.confidence, d.mask),\n );\n\n const orig: readonly [number, number] = [original.height, original.width];\n const boxes = this._buildBoxes(detections, orig);\n const masks = this._buildMasks(detections, orig);\n timer.stage(\"postprocess\");\n return [\n new SegmentationResults(\n boxes,\n masks,\n detections,\n this._names,\n original,\n orig,\n path,\n timer.speed(),\n ),\n ];\n }\n\n private _preprocess(image: RGBImage): {\n tensor: ort.Tensor;\n scale: number;\n padLeft: number;\n padTop: number;\n } {\n const [tw, th] = this._inputSize;\n const lb = letterbox(image, tw, th);\n const f32 = toFloat32(lb.image);\n const chw = toCHW(f32, lb.image.width, lb.image.height, 3);\n return {\n tensor: toFloat32Tensor(chw, [1, 3, lb.image.height, lb.image.width]),\n scale: lb.scale,\n padLeft: lb.padLeft,\n padTop: lb.padTop,\n };\n }\n\n private _splitOutputs(outputs: Record<string, ort.Tensor>): {\n perAnchor: ort.Tensor;\n prototypes: ort.Tensor;\n } {\n let perAnchor: ort.Tensor | undefined;\n let prototypes: ort.Tensor | undefined;\n for (const name of this._session.outputNames) {\n const t = outputs[name];\n if (t === undefined) continue;\n if (t.dims.length === 3 && perAnchor === undefined) {\n perAnchor = t;\n } else if (t.dims.length === 4 && prototypes === undefined) {\n prototypes = t;\n }\n }\n if (perAnchor === undefined || prototypes === undefined) {\n const shapes = this._session.outputNames.map(\n (n) => `${n}: ${JSON.stringify(outputs[n]?.dims ?? [])}`,\n );\n throw new Error(\n `Segmenter expected one 3-D and one 4-D output, got [${shapes.join(\", \")}].`,\n );\n }\n return { perAnchor, prototypes };\n }\n\n private _buildResult(\n original: RGBImage,\n bbox: BoundingBox,\n classId: number,\n confidence: number,\n mask: Mask,\n ): SegmentationResult {\n const [x1, y1, x2, y2] = bbox.asIntXyxy();\n const cx1 = Math.max(0, x1);\n const cy1 = Math.max(0, y1);\n const cx2 = Math.min(original.width, x2);\n const cy2 = Math.min(original.height, y2);\n\n let segmentedImage: RGBImage;\n let finalMask = mask;\n if (cx2 > cx1 && cy2 > cy1 && mask.data.length > 0) {\n const cropW = cx2 - cx1;\n const cropH = cy2 - cy1;\n const mw = Math.min(mask.width, cropW);\n const mh = Math.min(mask.height, cropH);\n const segData = new Uint8Array(mw * mh * 3);\n for (let row = 0; row < mh; row++) {\n const srcRowOffset = ((cy1 + row) * original.width + cx1) * 3;\n const dstRowOffset = row * mw * 3;\n const maskRowOffset = row * mask.width;\n for (let col = 0; col < mw; col++) {\n const m = mask.data[maskRowOffset + col];\n if (m !== 0) {\n const s = srcRowOffset + col * 3;\n const d = dstRowOffset + col * 3;\n segData[d] = original.data[s];\n segData[d + 1] = original.data[s + 1];\n segData[d + 2] = original.data[s + 2];\n }\n }\n }\n segmentedImage = new RGBImage(segData, mw, mh);\n if (mw !== mask.width || mh !== mask.height) {\n const trimmed = new Uint8Array(mw * mh);\n for (let row = 0; row < mh; row++) {\n trimmed.set(\n mask.data.subarray(row * mask.width, row * mask.width + mw),\n row * mw,\n );\n }\n finalMask = new Mask(trimmed, mw, mh);\n }\n } else {\n finalMask = new Mask(new Uint8Array(0), 0, 0);\n segmentedImage = new RGBImage(new Uint8Array(0), 0, 0);\n }\n\n const className = this._names[classId] ?? `class_${classId}`;\n\n return {\n classId,\n className,\n confidence,\n bbox,\n cls: classId,\n name: className,\n conf: confidence,\n box: bbox,\n mask: finalMask,\n segmentedImage,\n };\n }\n\n private _buildBoxes(\n detections: readonly SegmentationResult[],\n origShape: readonly [number, number],\n ): Boxes {\n const n = detections.length;\n const xyxy = new Float32Array(n * 4);\n const cls = new Int32Array(n);\n const conf = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n const d = detections[i] as SegmentationResult;\n xyxy[i * 4] = d.bbox.x1;\n xyxy[i * 4 + 1] = d.bbox.y1;\n xyxy[i * 4 + 2] = d.bbox.x2;\n xyxy[i * 4 + 3] = d.bbox.y2;\n cls[i] = d.classId;\n conf[i] = d.confidence;\n }\n return new Boxes(xyxy, cls, conf, origShape);\n }\n\n private _buildMasks(\n detections: readonly SegmentationResult[],\n origShape: readonly [number, number],\n ): Masks {\n const xyxy = new Float32Array(detections.length * 4);\n for (let i = 0; i < detections.length; i++) {\n const d = detections[i] as SegmentationResult;\n xyxy[i * 4] = d.bbox.x1;\n xyxy[i * 4 + 1] = d.bbox.y1;\n xyxy[i * 4 + 2] = d.bbox.x2;\n xyxy[i * 4 + 3] = d.bbox.y2;\n }\n return new Masks(\n detections.map((d) => d.mask),\n xyxy,\n origShape,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;AA8FA,IAAa,IAAb,MAAa,UAAkB,EAAW;CAGjB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CATrB,YACI,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACF;EADmB,AAEjB,MAAM,CAAO,GATI,KAAA,QAAA,GACA,KAAA,UAAA,GACA,KAAA,SAAA,GACA,KAAA,aAAA,GACA,KAAA,iBAAA,GACA,KAAA,gBAAA,GACA,KAAA,iBAAA,GACA,KAAA,iBAAA;CAGrB;CAGA,aAAa,OAAO,GAAoB,IAA4B,CAAC,GAAuB;EACxF,IAAM,IAAsB,EAAQ,QAAQ;EAC5C,IAAI,MAAS,YACT,MAAU,MAAM,+BAA+B,EAAK,0BAA0B;EAElF,IAAM,IAAU,MAAM,EAAW,OAAO,GAAO,CAAO,GAChD,IAAS,EAAc,EAAQ,UAAU,EAAW,EAAQ,QAAQ,KAAK,QAAQ,EACnF,YAAY,EAAQ,cAAc,EAAoB,EAAQ,WAAW,KAAK,KAAA,EAClF,CAAC,GACK,IAAgC,CAAC;EACvC,KAAK,IAAI,IAAI,GAAG,IAAI,EAAO,QAAQ,KAC/B,EAAM,KAAK,EAAO;EAEtB,OAAO,IAAI,EACP,GACA,GACA,GACA,GACA,EAAiB;GACb,YAAY,EAAQ;GACpB,WAAW,EAAQ;GAC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enter.js","names":[],"sources":["../../../src/vision/tasks/segmenter.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Instance-segmentation task using YOLO seg ONNX models (v8-seg / v11-seg / ...).\n */\n\nimport type * as ort from \"onnxruntime-web\";\n\nimport { type ModelSource, type OrtSessionOptions, OrtSession } from \"../core/session\";\nimport { SpeedTimer } from \"../core/timing\";\n\nimport { type ImageInput, loadImage } from \"../io/image\";\nimport { detectionNumClasses, resolveInputSize } from \"../core/graph\";\nimport { modelNames } from \"../core/metadata\";\nimport { type LabelSpec, defaultLabels, resolveLabels } from \"../labels\";\nimport { decodeYoloSeg } from \"../postprocess/segmentation\";\nimport { toFloat32Tensor } from \"../preprocess/image\";\nimport { LetterboxPipeline, zeroTensorData } from \"../preprocess/pipeline\";\nimport { Boxes, Masks, SegmentationResults } from \"../results\";\nimport { VisionTask, requireDetections } from \"./base\";\nimport { type BoundingBox, type SegmentationResult, Mask, RGBImage } from \"../types\";\n\n/**\n * Decoder family for the segmentation head.\n *\n * - `\"yolo-seg\"`: YOLO instance-segmentation head with two outputs —\n * `[1, 4 + nc + nm, N]` per-anchor predictions plus `[1, nm, mh, mw]`\n * prototype masks. Covers YOLOv8-seg, v11-seg, v26-seg.\n *\n * The SDK does **not** auto-detect this — the caller is responsible for\n * picking a head that matches their export.\n */\nexport type SegmenterHead = \"yolo-seg\";\n\nexport interface SegmenterOptions extends OrtSessionOptions {\n /**\n * Decoder family for the segmentation head. Default `\"yolo-seg\"` covers\n * YOLOv8-seg/v11-seg/v26-seg.\n */\n readonly head?: SegmenterHead;\n /** Class label spec — see {@link resolveLabels}. Defaults to the COCO 80-class preset. */\n readonly labels?: LabelSpec;\n /** Number of classes — used to validate the supplied labels. */\n readonly numClasses?: number;\n /**\n * Model input `[width, height]` in pixels for letterboxing.\n *\n * Only used when the model's graph leaves its spatial axes dynamic: a graph\n * that declares a static size always wins, since that is the only shape ONNX\n * Runtime will accept. Defaults to `[640, 640]`.\n */\n readonly inputSize?: readonly [number, number];\n /** Default minimum class score to keep a candidate. */\n readonly confThreshold?: number;\n /** Default IoU threshold for non-maximum suppression. */\n readonly iouThreshold?: number;\n /** Maximum number of instances per image. */\n readonly maxDetections?: number;\n /**\n * If `true`, a run that finds nothing throws {@link NoDetectionsError}\n * instead of returning an empty envelope. Default `false`, because looking\n * and finding nothing is a successful inference. Turn it on when an empty\n * result means the surrounding pipeline should stop rather than carry on with\n * zero rows. Can be overridden per `predict` call.\n */\n readonly raiseOnEmpty?: boolean;\n /** Probability cutoff applied to soft masks. Defaults to `0.5`. */\n readonly maskThreshold?: number;\n}\n\nexport interface SegmenterPredictOptions {\n readonly confThreshold?: number;\n readonly iouThreshold?: number;\n /**\n * If set, keep only instances whose `classId` is in this list.\n * Mirrors Ultralytics' `model.predict(img, classes=[0, 16])`.\n */\n readonly classes?: readonly number[];\n /** Override the constructor's `raiseOnEmpty` setting for this call. */\n readonly raiseOnEmpty?: boolean;\n}\n\n/**\n * Instance segmenter for YOLO seg ONNX models (v8-seg / v11-seg / ...).\n *\n * The model is expected to expose two outputs:\n *\n * 1. `output0`: `(1, 4 + numClasses + numMaskCoefs, numAnchors)` — per-anchor\n * predictions (boxes, class scores, mask coefficients).\n * 2. `output1`: `(1, numMaskCoefs, maskH, maskW)` — prototype masks.\n *\n * `predict()` returns `Promise<SegmentationResults[]>` (length 1 for a\n * single image), mirroring Ultralytics' API. The envelope exposes:\n *\n * - `boxes`: bulk numpy view (`xyxy`, `xywh`, `xyxyn`, `xywhn`, `cls`, `conf`).\n * - `masks`: per-instance binary masks cropped to each box.\n * - per-instance {@link SegmentationResult} via iteration.\n *\n * @example\n * ```typescript\n * const seg = await Segmenter.create(\"/models/yolov8n-seg.onnx\");\n * const r = (await seg.predict(\"/images/street.jpg\"))[0];\n * for (const inst of r) {\n * console.log(inst.cls, inst.conf, inst.box.xyxy);\n * }\n * ```\n */\nexport class Segmenter extends VisionTask {\n private constructor(\n session: OrtSession,\n private readonly _head: SegmenterHead,\n private readonly _labels: readonly string[],\n private readonly _names: Readonly<Record<number, string>>,\n private readonly _inputSize: readonly [number, number],\n private readonly _confThreshold: number,\n private readonly _iouThreshold: number,\n private readonly _maxDetections: number,\n private readonly _maskThreshold: number,\n private readonly _raiseOnEmpty: boolean,\n ) {\n super(session);\n }\n\n private _pipelineCache: LetterboxPipeline | null = null;\n\n /**\n * Run the model once on a zero-filled tensor, paying one-time costs up front.\n *\n * The first inference of a session is not representative: WebGPU compiles its\n * shaders on it and the WASM backend faults in its arenas, which on a phone\n * can turn the first frame into seconds while every later frame is tens of\n * milliseconds. Calling this while a loading spinner is still up moves that\n * cost somewhere the user is already waiting.\n *\n * @param runs How many warm-up inferences to run. One is enough for WASM;\n * WebGPU sometimes settles on the second.\n */\n async warmup(runs: number = 1): Promise<void> {\n const [tw, th] = this._inputSize;\n for (let i = 0; i < runs; i++) {\n const tensor = toFloat32Tensor(zeroTensorData(tw, th), [1, 3, th, tw]);\n await this._session.run({ [this._session.inputName]: tensor });\n }\n }\n\n /**\n * The fused preprocessing pipeline, built on first use.\n *\n * Lazily, because constructing it allocates canvases: a task built in an\n * environment without a canvas implementation stays constructible, and only\n * fails if it is actually asked to preprocess something.\n */\n private get _pipeline(): LetterboxPipeline {\n if (this._pipelineCache === null) {\n this._pipelineCache = new LetterboxPipeline(this._inputSize[0], this._inputSize[1]);\n }\n return this._pipelineCache;\n }\n\n /** Load the model and resolve labels. */\n static async create(model: ModelSource, options: SegmenterOptions = {}): Promise<Segmenter> {\n const head: SegmenterHead = options.head ?? \"yolo-seg\";\n if (head !== \"yolo-seg\") {\n throw new Error(`Unsupported segmenter head '${head}'. Supported: 'yolo-seg'.`);\n }\n const session = await OrtSession.create(model, options);\n const numClasses =\n options.numClasses ?? detectionNumClasses(session.outputShape) ?? undefined;\n const labels = resolveLabels(\n options.labels ?? modelNames(session.metadata) ?? defaultLabels(numClasses),\n { numClasses },\n );\n const names: Record<number, string> = {};\n for (let i = 0; i < labels.length; i++) {\n names[i] = labels[i] as string;\n }\n return new Segmenter(\n session,\n head,\n labels,\n names,\n resolveInputSize({\n graphShape: session.inputShape,\n requested: options.inputSize,\n fallback: [640, 640],\n }),\n options.confThreshold ?? 0.25,\n options.iouThreshold ?? 0.45,\n options.maxDetections ?? 300,\n options.maskThreshold ?? 0.5,\n options.raiseOnEmpty ?? false,\n );\n }\n\n /** The decoder family used to interpret the model's output. */\n get head(): SegmenterHead {\n return this._head;\n }\n\n /** Class labels indexed by class id. */\n get labels(): readonly string[] {\n return this._labels;\n }\n\n /** Class id → class name dict (matches Ultralytics' `model.names`). */\n get names(): Readonly<Record<number, string>> {\n return this._names;\n }\n\n /**\n * The `[width, height]` this task preprocesses to.\n *\n * Resolved at creation time from the model's graph when it declares a static\n * input, so reading it back tells you the resolution inference really runs at\n * — not merely what was requested.\n */\n get inputSize(): readonly [number, number] {\n return this._inputSize;\n }\n\n /** Number of classes the model predicts. */\n get numClasses(): number {\n return this._labels.length;\n }\n\n /** Alias for {@link predict} (parity with PyTorch `nn.Module.__call__`). */\n async call(\n image: ImageInput,\n options: SegmenterPredictOptions = {},\n ): Promise<SegmentationResults[]> {\n return this.predict(image, options);\n }\n\n /** Run instance segmentation on a single image. */\n async predict(\n image: ImageInput,\n options: SegmenterPredictOptions = {},\n ): Promise<SegmentationResults[]> {\n const timer = new SpeedTimer();\n const path = typeof image === \"string\" ? image : null;\n const original = await loadImage(image);\n timer.stage(\"load\");\n const { tensor, scale, padLeft, padTop } = this._preprocess(original);\n timer.stage(\"preprocess\");\n const outputs = await this._session.run({ [this._session.inputName]: tensor });\n this._pipeline.release();\n timer.stage(\"inference\");\n\n const { perAnchor, prototypes } = this._splitOutputs(outputs);\n\n const threshold = options.confThreshold ?? this._confThreshold;\n const decodedAll = decodeYoloSeg(\n perAnchor.data as Float32Array,\n perAnchor.dims,\n prototypes.data as Float32Array,\n prototypes.dims,\n {\n numClasses: this._labels.length,\n inputWidth: this._inputSize[0],\n inputHeight: this._inputSize[1],\n originalWidth: original.width,\n originalHeight: original.height,\n padLeft,\n padTop,\n scale,\n confThreshold: threshold,\n iouThreshold: options.iouThreshold ?? this._iouThreshold,\n maxDetections: this._maxDetections,\n maskThreshold: this._maskThreshold,\n },\n );\n\n const decoded =\n options.classes !== undefined\n ? (() => {\n const allowed = new Set(options.classes);\n return decodedAll.filter((d) => allowed.has(d.classId));\n })()\n : decodedAll;\n\n requireDetections(decoded.length, {\n raiseOnEmpty: options.raiseOnEmpty ?? this._raiseOnEmpty,\n confThreshold: threshold,\n classes: options.classes,\n path,\n });\n\n const detections = decoded.map((d) =>\n this._buildResult(original, d.bbox, d.classId, d.confidence, d.mask),\n );\n\n const orig: readonly [number, number] = [original.height, original.width];\n const boxes = this._buildBoxes(detections, orig);\n const masks = this._buildMasks(detections, orig);\n timer.stage(\"postprocess\");\n return [\n new SegmentationResults(\n boxes,\n masks,\n detections,\n this._names,\n original,\n orig,\n path,\n timer.speed(),\n ),\n ];\n }\n\n private _preprocess(image: RGBImage): {\n tensor: ort.Tensor;\n scale: number;\n padLeft: number;\n padTop: number;\n } {\n const [tw, th] = this._inputSize;\n const fused = this._pipeline.run(image);\n return {\n tensor: toFloat32Tensor(fused.data, [1, 3, th, tw]),\n scale: fused.scale,\n padLeft: fused.padLeft,\n padTop: fused.padTop,\n };\n }\n\n private _splitOutputs(outputs: Record<string, ort.Tensor>): {\n perAnchor: ort.Tensor;\n prototypes: ort.Tensor;\n } {\n let perAnchor: ort.Tensor | undefined;\n let prototypes: ort.Tensor | undefined;\n for (const name of this._session.outputNames) {\n const t = outputs[name];\n if (t === undefined) continue;\n if (t.dims.length === 3 && perAnchor === undefined) {\n perAnchor = t;\n } else if (t.dims.length === 4 && prototypes === undefined) {\n prototypes = t;\n }\n }\n if (perAnchor === undefined || prototypes === undefined) {\n const shapes = this._session.outputNames.map(\n (n) => `${n}: ${JSON.stringify(outputs[n]?.dims ?? [])}`,\n );\n throw new Error(\n `Segmenter expected one 3-D and one 4-D output, got [${shapes.join(\", \")}].`,\n );\n }\n return { perAnchor, prototypes };\n }\n\n private _buildResult(\n original: RGBImage,\n bbox: BoundingBox,\n classId: number,\n confidence: number,\n mask: Mask,\n ): SegmentationResult {\n const [x1, y1, x2, y2] = bbox.asIntXyxy();\n const cx1 = Math.max(0, x1);\n const cy1 = Math.max(0, y1);\n const cx2 = Math.min(original.width, x2);\n const cy2 = Math.min(original.height, y2);\n\n let segmentedImage: RGBImage;\n let finalMask = mask;\n if (cx2 > cx1 && cy2 > cy1 && mask.data.length > 0) {\n const cropW = cx2 - cx1;\n const cropH = cy2 - cy1;\n const mw = Math.min(mask.width, cropW);\n const mh = Math.min(mask.height, cropH);\n const segData = new Uint8Array(mw * mh * 3);\n for (let row = 0; row < mh; row++) {\n const srcRowOffset = ((cy1 + row) * original.width + cx1) * 3;\n const dstRowOffset = row * mw * 3;\n const maskRowOffset = row * mask.width;\n for (let col = 0; col < mw; col++) {\n const m = mask.data[maskRowOffset + col];\n if (m !== 0) {\n const s = srcRowOffset + col * 3;\n const d = dstRowOffset + col * 3;\n segData[d] = original.data[s];\n segData[d + 1] = original.data[s + 1];\n segData[d + 2] = original.data[s + 2];\n }\n }\n }\n segmentedImage = new RGBImage(segData, mw, mh);\n if (mw !== mask.width || mh !== mask.height) {\n const trimmed = new Uint8Array(mw * mh);\n for (let row = 0; row < mh; row++) {\n trimmed.set(\n mask.data.subarray(row * mask.width, row * mask.width + mw),\n row * mw,\n );\n }\n finalMask = new Mask(trimmed, mw, mh);\n }\n } else {\n finalMask = new Mask(new Uint8Array(0), 0, 0);\n segmentedImage = new RGBImage(new Uint8Array(0), 0, 0);\n }\n\n const className = this._names[classId] ?? `class_${classId}`;\n\n return {\n classId,\n className,\n confidence,\n bbox,\n cls: classId,\n name: className,\n conf: confidence,\n box: bbox,\n mask: finalMask,\n segmentedImage,\n };\n }\n\n private _buildBoxes(\n detections: readonly SegmentationResult[],\n origShape: readonly [number, number],\n ): Boxes {\n const n = detections.length;\n const xyxy = new Float32Array(n * 4);\n const cls = new Int32Array(n);\n const conf = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n const d = detections[i] as SegmentationResult;\n xyxy[i * 4] = d.bbox.x1;\n xyxy[i * 4 + 1] = d.bbox.y1;\n xyxy[i * 4 + 2] = d.bbox.x2;\n xyxy[i * 4 + 3] = d.bbox.y2;\n cls[i] = d.classId;\n conf[i] = d.confidence;\n }\n return new Boxes(xyxy, cls, conf, origShape);\n }\n\n private _buildMasks(\n detections: readonly SegmentationResult[],\n origShape: readonly [number, number],\n ): Masks {\n const xyxy = new Float32Array(detections.length * 4);\n for (let i = 0; i < detections.length; i++) {\n const d = detections[i] as SegmentationResult;\n xyxy[i * 4] = d.bbox.x1;\n xyxy[i * 4 + 1] = d.bbox.y1;\n xyxy[i * 4 + 2] = d.bbox.x2;\n xyxy[i * 4 + 3] = d.bbox.y2;\n }\n return new Masks(\n detections.map((d) => d.mask),\n xyxy,\n origShape,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA0GA,IAAa,IAAb,MAAa,UAAkB,EAAW;CAGjB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAVrB,YACI,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GACF;EADmB,AAEjB,MAAM,CAAO,GAVI,KAAA,QAAA,GACA,KAAA,UAAA,GACA,KAAA,SAAA,GACA,KAAA,aAAA,GACA,KAAA,iBAAA,GACA,KAAA,gBAAA,GACA,KAAA,iBAAA,GACA,KAAA,iBAAA,GACA,KAAA,gBAAA;CAGrB;CAEA,iBAAmD;CAcnD,MAAM,OAAO,IAAe,GAAkB;EAC1C,IAAM,CAAC,GAAI,KAAM,KAAK;EACtB,KAAK,IAAI,IAAI,GAAG,IAAI,GAAM,KAAK;GAC3B,IAAM,IAAS,EAAgB,EAAe,GAAI,CAAE,GAAG;IAAC;IAAG;IAAG;IAAI;GAAE,CAAC;GACrE,MAAM,KAAK,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AAC,GACtB,IAAO,IAAI,aAAa,CAAC;EAC/B,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;GACxB,IAAM,IAAI,EAAW;GAMrB,AALA,EAAK,IAAI,KAAK,EAAE,KAAK,IACrB,EAAK,IAAI,IAAI,KAAK,EAAE,KAAK,IACzB,EAAK,IAAI,IAAI,KAAK,EAAE,KAAK,IACzB,EAAK,IAAI,IAAI,KAAK,EAAE,KAAK,IACzB,EAAI,KAAK,EAAE,SACX,EAAK,KAAK,EAAE;EAChB;EACA,OAAO,IAAI,EAAM,GAAM,GAAK,GAAM,CAAS;CAC/C;CAEA,YACI,GACA,GACK;EACL,IAAM,IAAO,IAAI,aAAa,EAAW,SAAS,CAAC;EACnD,KAAK,IAAI,IAAI,GAAG,IAAI,EAAW,QAAQ,KAAK;GACxC,IAAM,IAAI,EAAW;GAIrB,AAHA,EAAK,IAAI,KAAK,EAAE,KAAK,IACrB,EAAK,IAAI,IAAI,KAAK,EAAE,KAAK,IACzB,EAAK,IAAI,IAAI,KAAK,EAAE,KAAK,IACzB,EAAK,IAAI,IAAI,KAAK,EAAE,KAAK;EAC7B;EACA,OAAO,IAAI,EACP,EAAW,KAAK,MAAM,EAAE,IAAI,GAC5B,GACA,CACJ;CACJ;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","names":[],"sources":["../../src/vision/types.ts"],"sourcesContent":["/**\n * Public output types returned by the SDK's vision tasks.\n *\n * These types form the contract between the SDK and its callers. They mirror\n * the Python `ort-vision-sdk` output dataclasses 1-to-1.\n *\n * Naming is intentionally compatible with the Ultralytics / torchvision idiom\n * (`cls`, `conf`, `box`, `xyxy`, `xywh`, normalized variants) so code ported\n * from those projects keeps working with minimal edits. The original verbose\n * names (`classId`, `className`, `confidence`, `bbox`) are still populated for\n * backwards compatibility.\n */\n\nimport { ImageLoadError } from \"./core/exceptions\";\n\n/**\n * HWC RGB uint8 image — the canonical image format used across the SDK.\n *\n * `data.length` must equal `width * height * 3`. The buffer is laid out row\n * by row, top-to-bottom, with each pixel as `[R, G, B]`.\n */\nexport class RGBImage {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height * 3) {\n throw new ImageLoadError(\n `RGBImage data length ${data.length} does not match width * height * 3 = ${\n width * height * 3\n }.`,\n );\n }\n }\n}\n\n/**\n * Axis-aligned bounding box in absolute pixel coordinates (xyxy format).\n *\n * Coordinates refer to the original input image (before any internal resize),\n * so callers can map detections back onto their source image without any\n * additional bookkeeping.\n */\nexport class BoundingBox {\n constructor(\n public readonly x1: number,\n public readonly y1: number,\n public readonly x2: number,\n public readonly y2: number,\n ) {}\n\n /** Box width in pixels (clamped to non-negative). */\n get width(): number {\n return Math.max(0, this.x2 - this.x1);\n }\n\n /** Box height in pixels (clamped to non-negative). */\n get height(): number {\n return Math.max(0, this.y2 - this.y1);\n }\n\n /** Box area in pixels squared. */\n get area(): number {\n return this.width * this.height;\n }\n\n /** The box as `[x1, y1, x2, y2]` in absolute pixels (Ultralytics-style). */\n get xyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * The box as `[cx, cy, w, h]` with `(cx, cy)` at the center.\n *\n * Matches Ultralytics' `boxes.xywh` and YOLO's native head format. For the\n * top-left `[x, y, w, h]` convention, use {@link asXywh}.\n */\n get xywh(): readonly [number, number, number, number] {\n return [(this.x1 + this.x2) / 2, (this.y1 + this.y2) / 2, this.width, this.height];\n }\n\n /**\n * The box as `[x1, y1, x2, y2]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xyxyn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n return [this.x1 / w, this.y1 / h, this.x2 / w, this.y2 / h];\n }\n\n /**\n * The box as `[cx, cy, w, h]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xywhn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n const [cx, cy, bw, bh] = this.xywh;\n return [cx / w, cy / h, bw / w, bh / h];\n }\n\n /** Returns `[x1, y1, x2, y2]`. */\n asXyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * Returns `[x, y, width, height]` with `(x, y)` at the **top-left**.\n *\n * Note: this is the top-left convention. Ultralytics' `xywh` getter uses\n * **center** coordinates — for that, read {@link xywh}.\n */\n asXywh(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.width, this.height];\n }\n\n /** Returns `[x1, y1, x2, y2]` truncated to integers, useful for slicing arrays. */\n asIntXyxy(): readonly [number, number, number, number] {\n return [Math.trunc(this.x1), Math.trunc(this.y1), Math.trunc(this.x2), Math.trunc(this.y2)];\n }\n}\n\n/**\n * Probability assigned to a single class for a classification prediction.\n *\n * `cls` / `name` / `conf` are Ultralytics-style aliases populated alongside\n * the verbose `classId` / `className` / `probability` fields.\n */\nexport interface ClassProbability {\n readonly classId: number;\n readonly className: string;\n readonly probability: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `probability` (Ultralytics-style). */\n readonly conf: number;\n}\n\n/**\n * Output of an image classification inference.\n */\nexport interface ClassificationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** The original input image as an HWC RGB uint8 array. */\n readonly image: RGBImage;\n /**\n * Probabilities per class, sorted in descending order. The first entry\n * mirrors `classId`, `className`, and `confidence`. When `topK` was passed\n * to `predict`, the array is truncated to that length.\n */\n readonly probabilities: readonly ClassProbability[];\n}\n\n/**\n * Single detected object produced by an object-detection model.\n */\nexport interface DetectionResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * The original image cropped to `bbox`, HWC RGB uint8. Empty boxes\n * (zero area) yield a zero-sized `RGBImage`.\n */\n readonly croppedImage: RGBImage;\n}\n\n/**\n * Single-channel binary or grayscale mask, laid out row-major.\n *\n * `data.length` must equal `width * height`. For binary masks, values are\n * `0` (background) or `255` (foreground); soft masks may use the full\n * `[0, 255]` range.\n */\nexport class Mask {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height) {\n throw new ImageLoadError(\n `Mask data length ${data.length} does not match width * height = ${\n width * height\n }.`,\n );\n }\n }\n}\n\n/**\n * Single segmented instance produced by an instance-segmentation model.\n *\n * Mirrors {@link DetectionResult} and adds the per-instance binary mask\n * plus a \"ready-to-display\" background-removed crop.\n */\nexport interface SegmentationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * Binary mask cropped to `bbox`. Values are `0` (background) or `255`\n * (foreground). Empty boxes yield a zero-sized `Mask`.\n */\n readonly mask: Mask;\n /**\n * The original image cropped to `bbox` with background pixels (where\n * `mask.data[i] === 0`) zeroed out. Empty boxes yield a zero-sized\n * `RGBImage`.\n */\n readonly segmentedImage: RGBImage;\n}\n"],"mappings":"yCAqBA,IAAa,EAAb,KAAsB,CAEE,KACA,MACA,OAHpB,YACI,EACA,EACA,EACF,CACE,GAJgB,KAAA,K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,KAAK,GAAI,KAAK,GAAI,KAAK,EAAE,CAC9C,CAQA,QAAoD,CAChD,MAAO,CAAC,KAAK,GAAI,KAAK,GAAI,KAAK,MAAO,KAAK,MAAM,CACrD,CAGA,WAAuD,CACnD,MAAO,CAAC,KAAK,MAAM,KAAK,EAAE,EAAG,KAAK,MAAM,KAAK,EAAE,EAAG,KAAK,MAAM,KAAK,EAAE,EAAG,KAAK,MAAM,KAAK,EAAE,CAAC,CAC9F,CACJ,EAyEa,EAAb,KAAkB,CAEM,KACA,MACA,OAHpB,YACI,EACA,EACA,EACF,CACE,GAJgB,KAAA,KAAA,EACA,KAAA,MAAA,EACA,KAAA,OAAA,EAEZ,EAAK,SAAW,EAAQ,EACxB,MAAM,IAAI,EAAA,eACN,oBAAoB,EAAK,OAAO,mCAC5B,EAAQ,EACX,EACL,CAER,CACJ"}
1
+ {"version":3,"file":"types.cjs","names":[],"sources":["../../src/vision/types.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Public output types returned by the SDK's vision tasks.\n *\n * These types form the contract between the SDK and its callers. They mirror\n * the Python `ort-vision-sdk` output dataclasses 1-to-1.\n *\n * Naming is intentionally compatible with the Ultralytics / torchvision idiom\n * (`cls`, `conf`, `box`, `xyxy`, `xywh`, normalized variants) so code ported\n * from those projects keeps working with minimal edits. The original verbose\n * names (`classId`, `className`, `confidence`, `bbox`) are still populated for\n * backwards compatibility.\n */\n\nimport { ImageLoadError } from \"./core/exceptions\";\n\n/**\n * HWC RGB uint8 image — the canonical image format used across the SDK.\n *\n * `data.length` must equal `width * height * 3`. The buffer is laid out row\n * by row, top-to-bottom, with each pixel as `[R, G, B]`.\n */\nexport class RGBImage {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height * 3) {\n throw new ImageLoadError(\n `RGBImage data length ${data.length} does not match width * height * 3 = ${\n width * height * 3\n }.`,\n );\n }\n }\n}\n\n/**\n * Axis-aligned bounding box in absolute pixel coordinates (xyxy format).\n *\n * Coordinates refer to the original input image (before any internal resize),\n * so callers can map detections back onto their source image without any\n * additional bookkeeping.\n */\nexport class BoundingBox {\n constructor(\n public readonly x1: number,\n public readonly y1: number,\n public readonly x2: number,\n public readonly y2: number,\n ) {}\n\n /** Box width in pixels (clamped to non-negative). */\n get width(): number {\n return Math.max(0, this.x2 - this.x1);\n }\n\n /** Box height in pixels (clamped to non-negative). */\n get height(): number {\n return Math.max(0, this.y2 - this.y1);\n }\n\n /** Box area in pixels squared. */\n get area(): number {\n return this.width * this.height;\n }\n\n /** The box as `[x1, y1, x2, y2]` in absolute pixels (Ultralytics-style). */\n get xyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * The box as `[cx, cy, w, h]` with `(cx, cy)` at the center.\n *\n * Matches Ultralytics' `boxes.xywh` and YOLO's native head format. For the\n * top-left `[x, y, w, h]` convention, use {@link asXywh}.\n */\n get xywh(): readonly [number, number, number, number] {\n return [(this.x1 + this.x2) / 2, (this.y1 + this.y2) / 2, this.width, this.height];\n }\n\n /**\n * The box as `[x1, y1, x2, y2]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xyxyn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n return [this.x1 / w, this.y1 / h, this.x2 / w, this.y2 / h];\n }\n\n /**\n * The box as `[cx, cy, w, h]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xywhn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n const [cx, cy, bw, bh] = this.xywh;\n return [cx / w, cy / h, bw / w, bh / h];\n }\n\n /** Returns `[x1, y1, x2, y2]`. */\n asXyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * Returns `[x, y, width, height]` with `(x, y)` at the **top-left**.\n *\n * Note: this is the top-left convention. Ultralytics' `xywh` getter uses\n * **center** coordinates — for that, read {@link xywh}.\n */\n asXywh(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.width, this.height];\n }\n\n /** Returns `[x1, y1, x2, y2]` truncated to integers, useful for slicing arrays. */\n asIntXyxy(): readonly [number, number, number, number] {\n return [Math.trunc(this.x1), Math.trunc(this.y1), Math.trunc(this.x2), Math.trunc(this.y2)];\n }\n}\n\n/**\n * Probability assigned to a single class for a classification prediction.\n *\n * `cls` / `name` / `conf` are Ultralytics-style aliases populated alongside\n * the verbose `classId` / `className` / `probability` fields.\n */\nexport interface ClassProbability {\n readonly classId: number;\n readonly className: string;\n readonly probability: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `probability` (Ultralytics-style). */\n readonly conf: number;\n}\n\n/**\n * Output of an image classification inference.\n */\nexport interface ClassificationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** The original input image as an HWC RGB uint8 array. */\n readonly image: RGBImage;\n /**\n * Probabilities per class, sorted in descending order. The first entry\n * mirrors `classId`, `className`, and `confidence`. When `topK` was passed\n * to `predict`, the array is truncated to that length.\n */\n readonly probabilities: readonly ClassProbability[];\n}\n\n/**\n * Single detected object produced by an object-detection model.\n */\nexport interface DetectionResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * The original image cropped to `bbox`, HWC RGB uint8. Empty boxes\n * (zero area) yield a zero-sized `RGBImage`.\n */\n readonly croppedImage: RGBImage;\n /**\n * What a second, classification stage predicted **for this crop** —\n * populated only by {@link DetectClassify}, and `null` for a plain detector.\n *\n * Kept as its own field rather than folded into `classId`/`className`\n * because the two answers are different questions: the detector says *what\n * kind of object this is*, the classifier says *which sub-category the object\n * belongs to*, and collapsing them would lose one of the two.\n */\n readonly classification?: ClassificationResult | null;\n}\n\n/**\n * Single-channel binary or grayscale mask, laid out row-major.\n *\n * `data.length` must equal `width * height`. For binary masks, values are\n * `0` (background) or `255` (foreground); soft masks may use the full\n * `[0, 255]` range.\n */\nexport class Mask {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height) {\n throw new ImageLoadError(\n `Mask data length ${data.length} does not match width * height = ${\n width * height\n }.`,\n );\n }\n }\n}\n\n/**\n * Single segmented instance produced by an instance-segmentation model.\n *\n * Mirrors {@link DetectionResult} and adds the per-instance binary mask\n * plus a \"ready-to-display\" background-removed crop.\n */\nexport interface SegmentationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * Binary mask cropped to `bbox`. Values are `0` (background) or `255`\n * (foreground). Empty boxes yield a zero-sized `Mask`.\n */\n readonly mask: Mask;\n /**\n * The original image cropped to `bbox` with background pixels (where\n * `mask.data[i] === 0`) zeroed out. Empty boxes yield a zero-sized\n * `RGBImage`.\n */\n readonly segmentedImage: RGBImage;\n}\n"],"mappings":"yCAsBA,IAAa,EAAb,KAAsB,CAEE,KACA,MACA,OAHpB,YACI,EACA,EACA,EACF,CACE,GAJgB,KAA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AAI,KAAK,GAAI,KAAK,GAAI,KAAK,EAAE,CAC9C,CAQA,QAAoD,CAChD,MAAO,CAAC,KAAK,GAAI,KAAK,GAAI,KAAK,MAAO,KAAK,MAAM,CACrD,CAGA,WAAuD,CACnD,MAAO,CAAC,KAAK,MAAM,KAAK,EAAE,EAAG,KAAK,MAAM,KAAK,EAAE,EAAG,KAAK,MAAM,KAAK,EAAE,EAAG,KAAK,MAAM,KAAK,EAAE,CAAC,CAC9F,CACJ,EAmFa,EAAb,KAAkB,CAEM,KACA,MACA,OAHpB,YACI,EACA,EACA,EACF,CACE,GAJgB,KAAA,KAAA,EACA,KAAA,MAAA,EACA,KAAA,OAAA,EAEZ,EAAK,SAAW,EAAQ,EACxB,MAAM,IAAI,EAAA,eACN,oBAAoB,EAAK,OAAO,mCAC5B,EAAQ,EACX,EACL,CAER,CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../src/vision/types.ts"],"sourcesContent":["/**\n * Public output types returned by the SDK's vision tasks.\n *\n * These types form the contract between the SDK and its callers. They mirror\n * the Python `ort-vision-sdk` output dataclasses 1-to-1.\n *\n * Naming is intentionally compatible with the Ultralytics / torchvision idiom\n * (`cls`, `conf`, `box`, `xyxy`, `xywh`, normalized variants) so code ported\n * from those projects keeps working with minimal edits. The original verbose\n * names (`classId`, `className`, `confidence`, `bbox`) are still populated for\n * backwards compatibility.\n */\n\nimport { ImageLoadError } from \"./core/exceptions\";\n\n/**\n * HWC RGB uint8 image — the canonical image format used across the SDK.\n *\n * `data.length` must equal `width * height * 3`. The buffer is laid out row\n * by row, top-to-bottom, with each pixel as `[R, G, B]`.\n */\nexport class RGBImage {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height * 3) {\n throw new ImageLoadError(\n `RGBImage data length ${data.length} does not match width * height * 3 = ${\n width * height * 3\n }.`,\n );\n }\n }\n}\n\n/**\n * Axis-aligned bounding box in absolute pixel coordinates (xyxy format).\n *\n * Coordinates refer to the original input image (before any internal resize),\n * so callers can map detections back onto their source image without any\n * additional bookkeeping.\n */\nexport class BoundingBox {\n constructor(\n public readonly x1: number,\n public readonly y1: number,\n public readonly x2: number,\n public readonly y2: number,\n ) {}\n\n /** Box width in pixels (clamped to non-negative). */\n get width(): number {\n return Math.max(0, this.x2 - this.x1);\n }\n\n /** Box height in pixels (clamped to non-negative). */\n get height(): number {\n return Math.max(0, this.y2 - this.y1);\n }\n\n /** Box area in pixels squared. */\n get area(): number {\n return this.width * this.height;\n }\n\n /** The box as `[x1, y1, x2, y2]` in absolute pixels (Ultralytics-style). */\n get xyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * The box as `[cx, cy, w, h]` with `(cx, cy)` at the center.\n *\n * Matches Ultralytics' `boxes.xywh` and YOLO's native head format. For the\n * top-left `[x, y, w, h]` convention, use {@link asXywh}.\n */\n get xywh(): readonly [number, number, number, number] {\n return [(this.x1 + this.x2) / 2, (this.y1 + this.y2) / 2, this.width, this.height];\n }\n\n /**\n * The box as `[x1, y1, x2, y2]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xyxyn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n return [this.x1 / w, this.y1 / h, this.x2 / w, this.y2 / h];\n }\n\n /**\n * The box as `[cx, cy, w, h]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xywhn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n const [cx, cy, bw, bh] = this.xywh;\n return [cx / w, cy / h, bw / w, bh / h];\n }\n\n /** Returns `[x1, y1, x2, y2]`. */\n asXyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * Returns `[x, y, width, height]` with `(x, y)` at the **top-left**.\n *\n * Note: this is the top-left convention. Ultralytics' `xywh` getter uses\n * **center** coordinates — for that, read {@link xywh}.\n */\n asXywh(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.width, this.height];\n }\n\n /** Returns `[x1, y1, x2, y2]` truncated to integers, useful for slicing arrays. */\n asIntXyxy(): readonly [number, number, number, number] {\n return [Math.trunc(this.x1), Math.trunc(this.y1), Math.trunc(this.x2), Math.trunc(this.y2)];\n }\n}\n\n/**\n * Probability assigned to a single class for a classification prediction.\n *\n * `cls` / `name` / `conf` are Ultralytics-style aliases populated alongside\n * the verbose `classId` / `className` / `probability` fields.\n */\nexport interface ClassProbability {\n readonly classId: number;\n readonly className: string;\n readonly probability: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `probability` (Ultralytics-style). */\n readonly conf: number;\n}\n\n/**\n * Output of an image classification inference.\n */\nexport interface ClassificationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** The original input image as an HWC RGB uint8 array. */\n readonly image: RGBImage;\n /**\n * Probabilities per class, sorted in descending order. The first entry\n * mirrors `classId`, `className`, and `confidence`. When `topK` was passed\n * to `predict`, the array is truncated to that length.\n */\n readonly probabilities: readonly ClassProbability[];\n}\n\n/**\n * Single detected object produced by an object-detection model.\n */\nexport interface DetectionResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * The original image cropped to `bbox`, HWC RGB uint8. Empty boxes\n * (zero area) yield a zero-sized `RGBImage`.\n */\n readonly croppedImage: RGBImage;\n}\n\n/**\n * Single-channel binary or grayscale mask, laid out row-major.\n *\n * `data.length` must equal `width * height`. For binary masks, values are\n * `0` (background) or `255` (foreground); soft masks may use the full\n * `[0, 255]` range.\n */\nexport class Mask {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height) {\n throw new ImageLoadError(\n `Mask data length ${data.length} does not match width * height = ${\n width * height\n }.`,\n );\n }\n }\n}\n\n/**\n * Single segmented instance produced by an instance-segmentation model.\n *\n * Mirrors {@link DetectionResult} and adds the per-instance binary mask\n * plus a \"ready-to-display\" background-removed crop.\n */\nexport interface SegmentationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * Binary mask cropped to `bbox`. Values are `0` (background) or `255`\n * (foreground). Empty boxes yield a zero-sized `Mask`.\n */\n readonly mask: Mask;\n /**\n * The original image cropped to `bbox` with background pixels (where\n * `mask.data[i] === 0`) zeroed out. Empty boxes yield a zero-sized\n * `RGBImage`.\n */\n readonly segmentedImage: RGBImage;\n}\n"],"mappings":";;AAqBA,IAAa,IAAb,MAAsB;CAEE;CACA;CACA;CAHpB,YACI,GACA,GACA,GACF;EACE,IAJgB,KAAA,OAAA,GACA,KAAA,QAAA,GACA,KAAA,SAAA,GAEZ,EAAK,WAAW,IAAQ,IAAS,GACjC,MAAM,IAAI,EACN,wBAAwB,EAAK,OAAO,uCAChC,IAAQ,IAAS,EACpB,EACL;CAER;AACJ,GASa,IAAb,MAAyB;CAED;CACA;CACA;CACA;CAJpB,YACI,GACA,GACA,GACA,GACF;EADkB,AAHA,KAAA,KAAA,GACA,KAAA,K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,KAAK,EAAE;EAAC;CAC9F;AACJ,GAyEa,IAAb,MAAkB;CAEM;CACA;CACA;CAHpB,YACI,GACA,GACA,GACF;EACE,IAJgB,KAAA,OAAA,GACA,KAAA,QAAA,GACA,KAAA,SAAA,GAEZ,EAAK,WAAW,IAAQ,GACxB,MAAM,IAAI,EACN,oBAAoB,EAAK,OAAO,mCAC5B,IAAQ,EACX,EACL;CAER;AACJ"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../src/vision/types.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Public output types returned by the SDK's vision tasks.\n *\n * These types form the contract between the SDK and its callers. They mirror\n * the Python `ort-vision-sdk` output dataclasses 1-to-1.\n *\n * Naming is intentionally compatible with the Ultralytics / torchvision idiom\n * (`cls`, `conf`, `box`, `xyxy`, `xywh`, normalized variants) so code ported\n * from those projects keeps working with minimal edits. The original verbose\n * names (`classId`, `className`, `confidence`, `bbox`) are still populated for\n * backwards compatibility.\n */\n\nimport { ImageLoadError } from \"./core/exceptions\";\n\n/**\n * HWC RGB uint8 image — the canonical image format used across the SDK.\n *\n * `data.length` must equal `width * height * 3`. The buffer is laid out row\n * by row, top-to-bottom, with each pixel as `[R, G, B]`.\n */\nexport class RGBImage {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height * 3) {\n throw new ImageLoadError(\n `RGBImage data length ${data.length} does not match width * height * 3 = ${\n width * height * 3\n }.`,\n );\n }\n }\n}\n\n/**\n * Axis-aligned bounding box in absolute pixel coordinates (xyxy format).\n *\n * Coordinates refer to the original input image (before any internal resize),\n * so callers can map detections back onto their source image without any\n * additional bookkeeping.\n */\nexport class BoundingBox {\n constructor(\n public readonly x1: number,\n public readonly y1: number,\n public readonly x2: number,\n public readonly y2: number,\n ) {}\n\n /** Box width in pixels (clamped to non-negative). */\n get width(): number {\n return Math.max(0, this.x2 - this.x1);\n }\n\n /** Box height in pixels (clamped to non-negative). */\n get height(): number {\n return Math.max(0, this.y2 - this.y1);\n }\n\n /** Box area in pixels squared. */\n get area(): number {\n return this.width * this.height;\n }\n\n /** The box as `[x1, y1, x2, y2]` in absolute pixels (Ultralytics-style). */\n get xyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * The box as `[cx, cy, w, h]` with `(cx, cy)` at the center.\n *\n * Matches Ultralytics' `boxes.xywh` and YOLO's native head format. For the\n * top-left `[x, y, w, h]` convention, use {@link asXywh}.\n */\n get xywh(): readonly [number, number, number, number] {\n return [(this.x1 + this.x2) / 2, (this.y1 + this.y2) / 2, this.width, this.height];\n }\n\n /**\n * The box as `[x1, y1, x2, y2]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xyxyn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n return [this.x1 / w, this.y1 / h, this.x2 / w, this.y2 / h];\n }\n\n /**\n * The box as `[cx, cy, w, h]` normalized to `[0, 1]`.\n *\n * @param origShape `[height, width]` of the source image, in pixels.\n */\n xywhn(origShape: readonly [number, number]): readonly [number, number, number, number] {\n const [h, w] = origShape;\n if (w <= 0 || h <= 0) return [0, 0, 0, 0];\n const [cx, cy, bw, bh] = this.xywh;\n return [cx / w, cy / h, bw / w, bh / h];\n }\n\n /** Returns `[x1, y1, x2, y2]`. */\n asXyxy(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.x2, this.y2];\n }\n\n /**\n * Returns `[x, y, width, height]` with `(x, y)` at the **top-left**.\n *\n * Note: this is the top-left convention. Ultralytics' `xywh` getter uses\n * **center** coordinates — for that, read {@link xywh}.\n */\n asXywh(): readonly [number, number, number, number] {\n return [this.x1, this.y1, this.width, this.height];\n }\n\n /** Returns `[x1, y1, x2, y2]` truncated to integers, useful for slicing arrays. */\n asIntXyxy(): readonly [number, number, number, number] {\n return [Math.trunc(this.x1), Math.trunc(this.y1), Math.trunc(this.x2), Math.trunc(this.y2)];\n }\n}\n\n/**\n * Probability assigned to a single class for a classification prediction.\n *\n * `cls` / `name` / `conf` are Ultralytics-style aliases populated alongside\n * the verbose `classId` / `className` / `probability` fields.\n */\nexport interface ClassProbability {\n readonly classId: number;\n readonly className: string;\n readonly probability: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `probability` (Ultralytics-style). */\n readonly conf: number;\n}\n\n/**\n * Output of an image classification inference.\n */\nexport interface ClassificationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** The original input image as an HWC RGB uint8 array. */\n readonly image: RGBImage;\n /**\n * Probabilities per class, sorted in descending order. The first entry\n * mirrors `classId`, `className`, and `confidence`. When `topK` was passed\n * to `predict`, the array is truncated to that length.\n */\n readonly probabilities: readonly ClassProbability[];\n}\n\n/**\n * Single detected object produced by an object-detection model.\n */\nexport interface DetectionResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * The original image cropped to `bbox`, HWC RGB uint8. Empty boxes\n * (zero area) yield a zero-sized `RGBImage`.\n */\n readonly croppedImage: RGBImage;\n /**\n * What a second, classification stage predicted **for this crop** —\n * populated only by {@link DetectClassify}, and `null` for a plain detector.\n *\n * Kept as its own field rather than folded into `classId`/`className`\n * because the two answers are different questions: the detector says *what\n * kind of object this is*, the classifier says *which sub-category the object\n * belongs to*, and collapsing them would lose one of the two.\n */\n readonly classification?: ClassificationResult | null;\n}\n\n/**\n * Single-channel binary or grayscale mask, laid out row-major.\n *\n * `data.length` must equal `width * height`. For binary masks, values are\n * `0` (background) or `255` (foreground); soft masks may use the full\n * `[0, 255]` range.\n */\nexport class Mask {\n constructor(\n public readonly data: Uint8Array,\n public readonly width: number,\n public readonly height: number,\n ) {\n if (data.length !== width * height) {\n throw new ImageLoadError(\n `Mask data length ${data.length} does not match width * height = ${\n width * height\n }.`,\n );\n }\n }\n}\n\n/**\n * Single segmented instance produced by an instance-segmentation model.\n *\n * Mirrors {@link DetectionResult} and adds the per-instance binary mask\n * plus a \"ready-to-display\" background-removed crop.\n */\nexport interface SegmentationResult {\n readonly classId: number;\n readonly className: string;\n readonly confidence: number;\n readonly bbox: BoundingBox;\n /** Alias for `classId` (Ultralytics-style). */\n readonly cls: number;\n /** Alias for `className`. */\n readonly name: string;\n /** Alias for `confidence` (Ultralytics-style). */\n readonly conf: number;\n /** Alias for `bbox` (Ultralytics-style). */\n readonly box: BoundingBox;\n /**\n * Binary mask cropped to `bbox`. Values are `0` (background) or `255`\n * (foreground). Empty boxes yield a zero-sized `Mask`.\n */\n readonly mask: Mask;\n /**\n * The original image cropped to `bbox` with background pixels (where\n * `mask.data[i] === 0`) zeroed out. Empty boxes yield a zero-sized\n * `RGBImage`.\n */\n readonly segmentedImage: RGBImage;\n}\n"],"mappings":";;AAsBA,IAAa,IAAb,MAAsB;CAEE;CACA;CACA;CAHpB,YACI,GACA,GACA,GACF;EACE,IAJgB,KAAA,OAAA,GACA,KAAA,QAAA,GACA,KAAA,SAAA,GAEZ,EAAK,WAAW,IAAQ,IAAS,GACjC,MAAM,IAAI,EACN,wBAAwB,EAAK,OAAO,uCAChC,IAAQ,IAAS,EACpB,EACL;CAER;AACJ,GASa,IAAb,MAAyB;CAED;CACA;CACA;CACA;CAJpB,YACI,GACA,GACA,GACA,GACF;EADkB,AAHA,KAAA,KAAA,GACA,KAAA,KAAA,G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,EAAE;EAAC;CAC9F;AACJ,GAmFa,IAAb,MAAkB;CAEM;CACA;CACA;CAHpB,YACI,GACA,GACA,GACF;EACE,IAJgB,KAAA,OAAA,GACA,KAAA,QAAA,GACA,KAAA,SAAA,GAEZ,EAAK,WAAW,IAAQ,GACxB,MAAM,IAAI,EACN,oBAAoB,EAAK,OAAO,mCAC5B,IAAQ,EACX,EACL;CAER;AACJ"}
package/dist/vision.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./vision/use-camera-stream.cjs"),t=require("./vision/core/exceptions.cjs"),n=require("./vision/types.cjs"),r=require("./vision/core/timing.cjs"),i=require("./vision/results.cjs"),a=require("./vision/labels.cjs"),o=require("./vision/core/graph.cjs"),s=require("./vision/core/metadata.cjs"),c=require("./vision/core/providers.cjs"),l=require("./vision/core/session.cjs"),u=require("./vision/io/image.cjs"),d=require("./vision/preprocess/image.cjs"),f=require("./vision/postprocess/classification.cjs"),p=require("./vision/postprocess/detection.cjs"),m=require("./vision/postprocess/segmentation.cjs"),h=require("./vision/tasks/base.cjs"),g=require("./vision/tasks/classifier.cjs"),_=require("./vision/tasks/detector.cjs"),v=require("./vision/tasks/segmenter.cjs"),y=require("./vision/index.cjs"),b=require("./vision/luminance.cjs"),x=require("./vision/use-live-luminance.cjs");exports.BoundingBox=n.BoundingBox,exports.Boxes=i.Boxes,exports.COCO_CLASSES=a.COCO_CLASSES,exports.ClassificationResults=i.ClassificationResults,exports.Classifier=g.Classifier,exports.DEFAULT_PROVIDERS=c.DEFAULT_PROVIDERS,exports.DetectionResults=i.DetectionResults,exports.Detector=_.Detector,exports.ImageLoadError=t.ImageLoadError,exports.InferenceError=t.InferenceError,exports.LUMINANCE_SAMPLE_MAX_EDGE=b.LUMINANCE_SAMPLE_MAX_EDGE,exports.LabelMapError=t.LabelMapError,exports.LowLuminanceError=b.LowLuminanceError,exports.Mask=n.Mask,exports.Masks=i.Masks,exports.ModelLoadError=t.ModelLoadError,exports.OrtSession=l.OrtSession,exports.OrtVisionError=t.OrtVisionError,exports.Probs=i.Probs,exports.ProviderNotAvailableError=t.ProviderNotAvailableError,exports.RGBImage=n.RGBImage,exports.SegmentationResults=i.SegmentationResults,exports.Segmenter=v.Segmenter,exports.SpeedTimer=r.SpeedTimer,exports.VERSION=y.VERSION,exports.VisionTask=h.VisionTask,exports.batchedNms=p.batchedNms,exports.classificationNumClasses=o.classificationNumClasses,exports.computeImageLuminance=b.computeImageLuminance,exports.declaredShapesFrom=o.declaredShapesFrom,exports.decodeYolo=p.decodeYolo,exports.decodeYoloAnchors=p.decodeYoloAnchors,exports.decodeYoloSeg=m.decodeYoloSeg,exports.decodeYoloV8=p.decodeYoloV8,exports.decodeYoloV8Anchors=p.decodeYoloV8Anchors,exports.decodeYoloV8Seg=m.decodeYoloV8Seg,exports.detectionNumClasses=o.detectionNumClasses,exports.fromCv2=d.fromCv2,exports.isLuminanceAcceptable=b.isLuminanceAcceptable,exports.letterbox=d.letterbox,exports.loadImage=u.loadImage,exports.modelNames=s.modelNames,exports.nms=p.nms,exports.normalize=d.normalize,exports.readModelMetadata=s.readModelMetadata,exports.resize=d.resize,exports.resolveInputSize=o.resolveInputSize,exports.resolveLabels=a.resolveLabels,exports.resolveProviders=c.resolveProviders,exports.softmax=f.softmax,exports.spatialInputSize=o.spatialInputSize,exports.toCHW=d.toCHW,exports.toCv2=d.toCv2,exports.toFloat32=d.toFloat32,exports.toFloat32Tensor=d.toFloat32Tensor,exports.toTensor=d.toTensor,exports.topK=f.topK,exports.useCameraStream=e.useCameraStream,exports.useLiveLuminance=x.useLiveLuminance;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./vision/use-camera-stream.cjs"),t=require("./vision/core/exceptions.cjs"),n=require("./vision/types.cjs"),r=require("./vision/core/timing.cjs"),i=require("./vision/results.cjs"),a=require("./vision/labels.cjs"),o=require("./vision/core/graph.cjs"),s=require("./vision/core/metadata.cjs"),c=require("./vision/core/providers.cjs"),l=require("./vision/core/session.cjs"),u=require("./vision/io/image.cjs"),d=require("./vision/fusion.cjs"),f=require("./vision/preprocess/image.cjs"),p=require("./vision/preprocess/pipeline.cjs"),m=require("./vision/postprocess/classification.cjs"),h=require("./vision/postprocess/detection.cjs"),g=require("./vision/postprocess/segmentation.cjs"),_=require("./vision/tasks/base.cjs"),v=require("./vision/tasks/classifier.cjs"),y=require("./vision/tasks/detectClassify.cjs"),b=require("./vision/tasks/detector.cjs"),x=require("./vision/tasks/segmenter.cjs"),S=require("./vision/index.cjs"),C=require("./vision/luminance.cjs"),w=require("./vision/use-live-luminance.cjs");exports.BoundingBox=n.BoundingBox,exports.Boxes=i.Boxes,exports.COCO_CLASSES=a.COCO_CLASSES,exports.ClassificationResults=i.ClassificationResults,exports.Classifier=v.Classifier,exports.DEFAULT_PROVIDERS=c.DEFAULT_PROVIDERS,exports.DetectClassify=y.DetectClassify,exports.DetectClassifyResults=i.DetectClassifyResults,exports.DetectionResults=i.DetectionResults,exports.Detector=b.Detector,exports.FUSION_KIND_DETECT_CLASSIFY=d.FUSION_KIND_DETECT_CLASSIFY,exports.FusionError=t.FusionError,exports.INPUT_IMAGE=d.INPUT_IMAGE,exports.INPUT_PAD=d.INPUT_PAD,exports.INPUT_SCALE=d.INPUT_SCALE,exports.INPUT_SOURCE=d.INPUT_SOURCE,exports.ImageLoadError=t.ImageLoadError,exports.InferenceError=t.InferenceError,exports.LUMINANCE_SAMPLE_MAX_EDGE=C.LUMINANCE_SAMPLE_MAX_EDGE,exports.LabelMapError=t.LabelMapError,exports.LetterboxPipeline=p.LetterboxPipeline,exports.LowLuminanceError=C.LowLuminanceError,exports.METADATA_PREFIX=d.METADATA_PREFIX,exports.Mask=n.Mask,exports.Masks=i.Masks,exports.ModelLoadError=t.ModelLoadError,exports.NoDetectionsError=t.NoDetectionsError,exports.OUTPUT_BOXES=d.OUTPUT_BOXES,exports.OUTPUT_CLASSES=d.OUTPUT_CLASSES,exports.OUTPUT_NUM_DETECTIONS=d.OUTPUT_NUM_DETECTIONS,exports.OUTPUT_PROBS=d.OUTPUT_PROBS,exports.OUTPUT_SCORES=d.OUTPUT_SCORES,exports.OrtSession=l.OrtSession,exports.OrtVisionError=t.OrtVisionError,exports.Probs=i.Probs,exports.ProviderNotAvailableError=t.ProviderNotAvailableError,exports.RGBImage=n.RGBImage,exports.SegmentationResults=i.SegmentationResults,exports.Segmenter=x.Segmenter,exports.SpeedTimer=r.SpeedTimer,exports.VERSION=S.VERSION,exports.VisionTask=_.VisionTask,exports.batchedNms=h.batchedNms,exports.classificationNumClasses=o.classificationNumClasses,exports.computeImageLuminance=C.computeImageLuminance,exports.declaredShapesFrom=o.declaredShapesFrom,exports.decodeYolo=h.decodeYolo,exports.decodeYoloAnchors=h.decodeYoloAnchors,exports.decodeYoloSeg=g.decodeYoloSeg,exports.defaultLabels=a.defaultLabels,exports.detectionNumClasses=o.detectionNumClasses,exports.fromCv2=f.fromCv2,exports.isLuminanceAcceptable=C.isLuminanceAcceptable,exports.letterbox=f.letterbox,exports.letterboxToTensorData=p.letterboxToTensorData,exports.loadImage=u.loadImage,exports.modelNames=s.modelNames,exports.nms=h.nms,exports.normalize=f.normalize,exports.parseNames=s.parseNames,exports.readFusionSpec=d.readFusionSpec,exports.readModelMetadata=s.readModelMetadata,exports.requireDetections=_.requireDetections,exports.resize=f.resize,exports.resolveInputSize=o.resolveInputSize,exports.resolveLabels=a.resolveLabels,exports.resolveProviders=c.resolveProviders,exports.softmax=m.softmax,exports.spatialInputSize=o.spatialInputSize,exports.toCHW=f.toCHW,exports.toCv2=f.toCv2,exports.toFloat32=f.toFloat32,exports.toFloat32Tensor=f.toFloat32Tensor,exports.toTensor=f.toTensor,exports.topK=m.topK,exports.useCameraStream=e.useCameraStream,exports.useLiveLuminance=w.useLiveLuminance,exports.zeroTensorData=p.zeroTensorData;