tempest-react-sdk 0.34.0 → 0.35.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.
- package/README.md +2 -0
- package/dist/perf/cache-size.cjs +2 -0
- package/dist/perf/cache-size.cjs.map +1 -0
- package/dist/perf/cache-size.js +16 -0
- package/dist/perf/cache-size.js.map +1 -0
- package/dist/perf/device.cjs +2 -0
- package/dist/perf/device.cjs.map +1 -0
- package/dist/perf/device.js +22 -0
- package/dist/perf/device.js.map +1 -0
- package/dist/perf/format.cjs +2 -0
- package/dist/perf/format.cjs.map +1 -0
- package/dist/perf/format.js +8 -0
- package/dist/perf/format.js.map +1 -0
- package/dist/perf/profiler.cjs +2 -0
- package/dist/perf/profiler.cjs.map +1 -0
- package/dist/perf/profiler.js +46 -0
- package/dist/perf/profiler.js.map +1 -0
- package/dist/tempest-react-sdk.cjs +1 -1
- package/dist/tempest-react-sdk.d.ts +211 -0
- package/dist/tempest-react-sdk.js +5 -1
- package/dist/vision/core/timing.cjs +2 -0
- package/dist/vision/core/timing.cjs.map +1 -0
- package/dist/vision/core/timing.js +24 -0
- package/dist/vision/core/timing.js.map +1 -0
- package/dist/vision/index.cjs +1 -1
- package/dist/vision/index.cjs.map +1 -1
- package/dist/vision/index.js +16 -15
- package/dist/vision/index.js.map +1 -1
- package/dist/vision/postprocess/detection.cjs +1 -1
- package/dist/vision/postprocess/detection.cjs.map +1 -1
- package/dist/vision/postprocess/detection.js +2 -2
- package/dist/vision/postprocess/detection.js.map +1 -1
- package/dist/vision/postprocess/segmentation.cjs +1 -1
- package/dist/vision/postprocess/segmentation.cjs.map +1 -1
- package/dist/vision/postprocess/segmentation.js +1 -1
- package/dist/vision/postprocess/segmentation.js.map +1 -1
- package/dist/vision/results.cjs +1 -1
- package/dist/vision/results.cjs.map +1 -1
- package/dist/vision/results.js +18 -13
- package/dist/vision/results.js.map +1 -1
- package/dist/vision/tasks/classifier.cjs +1 -1
- package/dist/vision/tasks/classifier.cjs.map +1 -1
- package/dist/vision/tasks/classifier.js +46 -39
- package/dist/vision/tasks/classifier.js.map +1 -1
- package/dist/vision/tasks/detector.cjs +1 -1
- package/dist/vision/tasks/detector.cjs.map +1 -1
- package/dist/vision/tasks/detector.js +40 -33
- package/dist/vision/tasks/detector.js.map +1 -1
- package/dist/vision/tasks/segmenter.cjs +1 -1
- package/dist/vision/tasks/segmenter.cjs.map +1 -1
- package/dist/vision/tasks/segmenter.js +35 -28
- package/dist/vision/tasks/segmenter.js.map +1 -1
- package/dist/vision.cjs +1 -1
- package/dist/vision.d.ts +68 -10
- package/dist/vision.js +19 -18
- package/package.json +1 -1
|
@@ -1214,6 +1214,30 @@ export declare const CACHE_TIME: {
|
|
|
1214
1214
|
readonly LONG: number;
|
|
1215
1215
|
};
|
|
1216
1216
|
|
|
1217
|
+
/**
|
|
1218
|
+
* How large the assets a page precached actually are.
|
|
1219
|
+
*
|
|
1220
|
+
* Reads the `Content-Length` of a stored response instead of its body:
|
|
1221
|
+
* materializing a cached ONNX model or WASM binary to learn its length would
|
|
1222
|
+
* pull tens of megabytes into memory on every measurement.
|
|
1223
|
+
*/
|
|
1224
|
+
/**
|
|
1225
|
+
* Byte size of a response sitting in a Cache Storage bucket.
|
|
1226
|
+
*
|
|
1227
|
+
* @param cacheName The cache bucket to look in.
|
|
1228
|
+
* @param url The request URL the response was stored under.
|
|
1229
|
+
* @returns The size in bytes, or `null` when Cache Storage is unavailable,
|
|
1230
|
+
* the entry is absent, or the stored response carries no usable
|
|
1231
|
+
* `Content-Length` (a chunked transfer, typically).
|
|
1232
|
+
*
|
|
1233
|
+
* @example
|
|
1234
|
+
* ```typescript
|
|
1235
|
+
* const bytes = await cachedResponseBytes("app-models", "/models/detect.onnx");
|
|
1236
|
+
* console.log(bytes === null ? "—" : formatBytes(bytes)); // "12.0 MB"
|
|
1237
|
+
* ```
|
|
1238
|
+
*/
|
|
1239
|
+
export declare function cachedResponseBytes(cacheName: string, url: string): Promise<number | null>;
|
|
1240
|
+
|
|
1217
1241
|
/** A cache-name matcher: a prefix string, a `RegExp`, or a predicate. */
|
|
1218
1242
|
export declare type CacheFilter = string | RegExp | ((name: string) => boolean);
|
|
1219
1243
|
|
|
@@ -2237,6 +2261,46 @@ export declare interface CreateI18nOptions {
|
|
|
2237
2261
|
messages: Catalog;
|
|
2238
2262
|
}
|
|
2239
2263
|
|
|
2264
|
+
/**
|
|
2265
|
+
* Timing and cost accounting for a pipeline that runs on the user's device.
|
|
2266
|
+
*/
|
|
2267
|
+
/**
|
|
2268
|
+
* Create a profiler for one run of a pipeline.
|
|
2269
|
+
*
|
|
2270
|
+
* Wrap each step in {@link InferenceProfiler.stage}, fold in durations you
|
|
2271
|
+
* already have (an SDK `speed` breakdown, say) with
|
|
2272
|
+
* {@link InferenceProfiler.mark}, then call `report()` once the run finishes.
|
|
2273
|
+
*
|
|
2274
|
+
* Stages are timed independently rather than as a tiling of the run, so
|
|
2275
|
+
* concurrent work is charged its real wall-clock span to each stage and the
|
|
2276
|
+
* timings can sum to more than `totalMs`. Surface that to users when you
|
|
2277
|
+
* render the breakdown — a bar chart implying a partition of the total would
|
|
2278
|
+
* be wrong for a pipeline that overlaps stages.
|
|
2279
|
+
*
|
|
2280
|
+
* @returns A profiler bound to the moment it was created.
|
|
2281
|
+
*
|
|
2282
|
+
* @example
|
|
2283
|
+
* ```typescript
|
|
2284
|
+
* import { createInferenceProfiler } from "tempest-react-sdk";
|
|
2285
|
+
* import { Detector } from "tempest-react-sdk/vision";
|
|
2286
|
+
*
|
|
2287
|
+
* const profiler = createInferenceProfiler();
|
|
2288
|
+
* const detector = await profiler.stage("load-model", () =>
|
|
2289
|
+
* Detector.create("/models/detect.onnx"),
|
|
2290
|
+
* );
|
|
2291
|
+
* const results = await profiler.stage("detect", () => detector.predict(blob));
|
|
2292
|
+
* profiler.mark("forward-pass", results[0].speed.inference);
|
|
2293
|
+
*
|
|
2294
|
+
* const report = await profiler.report({
|
|
2295
|
+
* models: [
|
|
2296
|
+
* { name: "detector", cacheName: "app-models", url: "/models/detect.onnx" },
|
|
2297
|
+
* ],
|
|
2298
|
+
* });
|
|
2299
|
+
* console.log(report.timings, report.totalMs, report.device, report.models);
|
|
2300
|
+
* ```
|
|
2301
|
+
*/
|
|
2302
|
+
export declare function createInferenceProfiler(): InferenceProfiler;
|
|
2303
|
+
|
|
2240
2304
|
/**
|
|
2241
2305
|
* Trivial in-memory adapter. Suitable for tests, local development, or as a
|
|
2242
2306
|
* fallback wrapping the real provider while it loads.
|
|
@@ -3182,6 +3246,31 @@ export declare interface DescriptionListProps extends HTMLAttributes<HTMLDListEl
|
|
|
3182
3246
|
items: DescriptionListItem[];
|
|
3183
3247
|
}
|
|
3184
3248
|
|
|
3249
|
+
/**
|
|
3250
|
+
* Shapes describing what an on-device inference run cost.
|
|
3251
|
+
*
|
|
3252
|
+
* The browser exposes no energy counter and no FLOP counter, so "cost" here
|
|
3253
|
+
* is assembled from what a page can actually observe: how long each stage
|
|
3254
|
+
* took, how much parallelism and memory the device reports, and how large the
|
|
3255
|
+
* cached model weights are. Anything the platform does not expose stays
|
|
3256
|
+
* `null` — a UI can then render "—" instead of a fabricated number.
|
|
3257
|
+
*/
|
|
3258
|
+
/**
|
|
3259
|
+
* Device capabilities as reported by the browser.
|
|
3260
|
+
*
|
|
3261
|
+
* Every field is best-effort. `deviceMemoryGb` and `jsHeapUsedMb` come from
|
|
3262
|
+
* Chromium-only APIs (`navigator.deviceMemory`, `performance.memory`) and are
|
|
3263
|
+
* `null` everywhere else, including Firefox and Safari.
|
|
3264
|
+
*/
|
|
3265
|
+
export declare interface DeviceProfile {
|
|
3266
|
+
/** Logical cores available to workers, or `null` when unreported. */
|
|
3267
|
+
hardwareConcurrency: number | null;
|
|
3268
|
+
/** Approximate device RAM in GiB (coarse, Chromium-only), or `null`. */
|
|
3269
|
+
deviceMemoryGb: number | null;
|
|
3270
|
+
/** Used JS heap in MiB (Chromium-only), or `null`. */
|
|
3271
|
+
jsHeapUsedMb: number | null;
|
|
3272
|
+
}
|
|
3273
|
+
|
|
3185
3274
|
export declare interface DisclosureHandlers {
|
|
3186
3275
|
open: () => void;
|
|
3187
3276
|
close: () => void;
|
|
@@ -3901,6 +3990,31 @@ export declare function formatDate(value: string | Date): string;
|
|
|
3901
3990
|
*/
|
|
3902
3991
|
export declare function formatDateTime(value: string | Date): string;
|
|
3903
3992
|
|
|
3993
|
+
/**
|
|
3994
|
+
* Rendering helpers for the numbers a profiler produces.
|
|
3995
|
+
*/
|
|
3996
|
+
/**
|
|
3997
|
+
* Format a millisecond duration for display.
|
|
3998
|
+
*
|
|
3999
|
+
* Sub-second values keep millisecond resolution — the interesting range for a
|
|
4000
|
+
* single forward pass — and anything longer switches to seconds so a cold
|
|
4001
|
+
* start that pays a model download does not read as a five-digit number.
|
|
4002
|
+
* Durations under `1 ms` render as `"<1 ms"` rather than `"0 ms"`, which
|
|
4003
|
+
* would read as "not measured".
|
|
4004
|
+
*
|
|
4005
|
+
* @param value Duration in milliseconds.
|
|
4006
|
+
* @returns The formatted string, or `"—"` for a non-finite or negative input.
|
|
4007
|
+
*
|
|
4008
|
+
* @example
|
|
4009
|
+
* ```typescript
|
|
4010
|
+
* formatDurationMs(0.04); // "<1 ms"
|
|
4011
|
+
* formatDurationMs(142.6); // "143 ms"
|
|
4012
|
+
* formatDurationMs(4321); // "4.32 s"
|
|
4013
|
+
* formatDurationMs(NaN); // "—"
|
|
4014
|
+
* ```
|
|
4015
|
+
*/
|
|
4016
|
+
export declare function formatDurationMs(value: number): string;
|
|
4017
|
+
|
|
3904
4018
|
/**
|
|
3905
4019
|
* Format a fraction (0-1) as a percentage with one decimal.
|
|
3906
4020
|
*
|
|
@@ -4478,6 +4592,70 @@ export declare interface ImageProps extends Omit<ImgHTMLAttributes<HTMLImageElem
|
|
|
4478
4592
|
lazy?: boolean;
|
|
4479
4593
|
}
|
|
4480
4594
|
|
|
4595
|
+
/**
|
|
4596
|
+
* Records how long each stage of a pipeline took.
|
|
4597
|
+
*
|
|
4598
|
+
* Stages are measured **independently**, not as a tiling of the whole run:
|
|
4599
|
+
* two stages started concurrently are each charged their full wall-clock
|
|
4600
|
+
* span, so the sum can exceed {@link InferenceReport.totalMs}. That is the
|
|
4601
|
+
* honest reading for a pipeline that decodes an image while the model
|
|
4602
|
+
* sessions are still loading.
|
|
4603
|
+
*/
|
|
4604
|
+
export declare interface InferenceProfiler {
|
|
4605
|
+
/**
|
|
4606
|
+
* Run an async stage and record its duration.
|
|
4607
|
+
*
|
|
4608
|
+
* @param name Stage label used as the key in the report.
|
|
4609
|
+
* @param run The work to time.
|
|
4610
|
+
* @returns Whatever `run` resolved to.
|
|
4611
|
+
*/
|
|
4612
|
+
stage<T>(name: string, run: () => Promise<T>): Promise<T>;
|
|
4613
|
+
/**
|
|
4614
|
+
* Run a synchronous stage and record its duration.
|
|
4615
|
+
*
|
|
4616
|
+
* @param name Stage label used as the key in the report.
|
|
4617
|
+
* @param run The work to time.
|
|
4618
|
+
* @returns Whatever `run` returned.
|
|
4619
|
+
*/
|
|
4620
|
+
stageSync<T>(name: string, run: () => T): T;
|
|
4621
|
+
/**
|
|
4622
|
+
* Record a duration measured elsewhere — a `speed` breakdown returned by
|
|
4623
|
+
* `tempest-react-sdk/vision`, for instance.
|
|
4624
|
+
*
|
|
4625
|
+
* Repeated names accumulate, so folding two passes of the same kind into
|
|
4626
|
+
* one row is a matter of calling `mark` twice.
|
|
4627
|
+
*
|
|
4628
|
+
* @param name Stage label used as the key in the report.
|
|
4629
|
+
* @param durationMs How long it took, in milliseconds.
|
|
4630
|
+
*/
|
|
4631
|
+
mark(name: string, durationMs: number): void;
|
|
4632
|
+
/**
|
|
4633
|
+
* Assemble the report for everything recorded so far.
|
|
4634
|
+
*
|
|
4635
|
+
* @param options Which models to size up in Cache Storage.
|
|
4636
|
+
* @returns The finished report.
|
|
4637
|
+
*/
|
|
4638
|
+
report(options?: InferenceReportOptions): Promise<InferenceReport>;
|
|
4639
|
+
}
|
|
4640
|
+
|
|
4641
|
+
/** What one profiled run cost. */
|
|
4642
|
+
export declare interface InferenceReport {
|
|
4643
|
+
/** Duration in milliseconds per stage name, in the order first recorded. */
|
|
4644
|
+
timings: Readonly<Record<string, number>>;
|
|
4645
|
+
/** Milliseconds from profiler creation to the `report()` call. */
|
|
4646
|
+
totalMs: number;
|
|
4647
|
+
device: DeviceProfile;
|
|
4648
|
+
models: readonly ProfiledModelSize[];
|
|
4649
|
+
/** Epoch millis at which the report was assembled. */
|
|
4650
|
+
measuredAt: number;
|
|
4651
|
+
}
|
|
4652
|
+
|
|
4653
|
+
/** Options for {@link InferenceProfiler.report}. */
|
|
4654
|
+
export declare interface InferenceReportOptions {
|
|
4655
|
+
/** Models to measure in Cache Storage. Omit to report none. */
|
|
4656
|
+
models?: readonly ProfiledModel[];
|
|
4657
|
+
}
|
|
4658
|
+
|
|
4481
4659
|
export declare interface InMemoryFlagsOptions {
|
|
4482
4660
|
initial?: Record<string, FlagValue>;
|
|
4483
4661
|
}
|
|
@@ -6733,6 +6911,23 @@ export declare interface PostHogLike {
|
|
|
6733
6911
|
reset?: () => void;
|
|
6734
6912
|
}
|
|
6735
6913
|
|
|
6914
|
+
/** A model whose cached size should appear in the report. */
|
|
6915
|
+
export declare interface ProfiledModel {
|
|
6916
|
+
/** Label for the report row, e.g. `"detector"`. */
|
|
6917
|
+
name: string;
|
|
6918
|
+
/** Cache Storage bucket holding the response, e.g. `"app-models"`. */
|
|
6919
|
+
cacheName: string;
|
|
6920
|
+
/** Request URL the model was cached under. */
|
|
6921
|
+
url: string;
|
|
6922
|
+
}
|
|
6923
|
+
|
|
6924
|
+
/** A model's size as found in the cache. */
|
|
6925
|
+
export declare interface ProfiledModelSize {
|
|
6926
|
+
name: string;
|
|
6927
|
+
/** Size in bytes, or `null` when uncached or the size is unreported. */
|
|
6928
|
+
bytes: number | null;
|
|
6929
|
+
}
|
|
6930
|
+
|
|
6736
6931
|
/**
|
|
6737
6932
|
* Linear progress bar with determinate / indeterminate modes.
|
|
6738
6933
|
*
|
|
@@ -7050,6 +7245,22 @@ export declare interface RatingStarsProps {
|
|
|
7050
7245
|
*/
|
|
7051
7246
|
export declare function readableForeground(background: string, light?: string, dark?: string): string;
|
|
7052
7247
|
|
|
7248
|
+
/**
|
|
7249
|
+
* Sample the device capabilities the browser reports.
|
|
7250
|
+
*
|
|
7251
|
+
* Safe to call during SSR: without a `navigator` every field is `null`.
|
|
7252
|
+
*
|
|
7253
|
+
* @returns The profile, with `null` for anything this platform withholds.
|
|
7254
|
+
*
|
|
7255
|
+
* @example
|
|
7256
|
+
* ```typescript
|
|
7257
|
+
* const device = readDeviceProfile();
|
|
7258
|
+
* console.log(device.hardwareConcurrency); // 8
|
|
7259
|
+
* console.log(device.deviceMemoryGb); // 8 on Chromium, null on Safari
|
|
7260
|
+
* ```
|
|
7261
|
+
*/
|
|
7262
|
+
export declare function readDeviceProfile(): DeviceProfile;
|
|
7263
|
+
|
|
7053
7264
|
/**
|
|
7054
7265
|
* Read a token's computed value from an element (default: `<html>`).
|
|
7055
7266
|
*
|
|
@@ -292,4 +292,8 @@ import { createLaunchDarklyFeatureFlagsAdapter as Ss } from "./feature-flags/lau
|
|
|
292
292
|
import { isShareSupported as Cs, share as ws } from "./share/share.js";
|
|
293
293
|
import { shareOrDownloadBlob as Ts } from "./share/share-or-download.js";
|
|
294
294
|
import { DIVERGING_STEP_COUNT as Es, ORDINAL_START_STEP as Ds, SEQUENTIAL_STEP_COUNT as Os, divergingScale as ks, scaleSteps as As, sequentialScale as js } from "./charts/scales.js";
|
|
295
|
-
|
|
295
|
+
import { cachedResponseBytes as Ms } from "./perf/cache-size.js";
|
|
296
|
+
import { readDeviceProfile as Ns } from "./perf/device.js";
|
|
297
|
+
import { formatDurationMs as Ps } from "./perf/format.js";
|
|
298
|
+
import { createInferenceProfiler as Fs } from "./perf/profiler.js";
|
|
299
|
+
export { cr as AIChat, rr as AIChatComposer, sr as AIChatTurn, hi as AccessControlProvider, t as Accordion, n as Alert, r as AppBar, Sa as AppProviders, Yi as AppRouter, o as AppShell, s as AspectRatio, li as AuthGuard, c as Avatar, l as AvatarGroup, i as BREAKPOINTS, u as Badge, d as Banner, f as BottomNavigation, p as BottomSheet, m as Breadcrumbs, Zi as BrowserRouter, h as Button, Ci as CACHE_TIME, io as CEPInput, ao as CNPJInput, oo as CPFInput, Dn as Calendar, vi as Can, g as Card, Nn as Carousel, _ as Center, Yn as Chat, Jn as ChatComposer, v as Checkbox, y as ChipInput, un as ClickOutside, nn as CodeBlock, xn as Collapsible, b as Combobox, wn as Command, dn as ConditionalWrapper, S as ConfirmDialog, I as Container, Sn as ContextMenu, uo as Controller, Qt as CopyButton, Ao as DEFAULT_CAR_SPEED_KMH, jo as DEFAULT_CIRCUITY_FACTOR, Mo as DEFAULT_MODE_DURATION_FACTORS, Es as DIVERGING_STEP_COUNT, hn as DataList, Pn as DataTable, w as DatePicker, An as DateRangePicker, gn as DescriptionList, T as Divider, E as Drawer, D as DropdownMenu, O as Dropzone, To as EARTH_RADIUS_KM, k as EmptyState, xa as ErrorBoundary, A as ErrorState, pn as ErrorText, _s as FeatureFlagsProvider, j as FileUpload, vr as FilterBar, In as FloatingActionButton, fn as For, M as Form, N as FormActions, Ya as FormField, fo as FormProvider, P as FormRow, F as FormSection, xi as GoogleSignIn, L as Grid, Qi as HashRouter, pt as Hide, Cn as HoverCard, va as I18nProvider, mn as Image, Rt as ImageCropper, C as Input, B as InstallBanner, V as InstallButton, Je as Kanban, Xe as Kbd, bn as Label, Vn as Lightbox, $i as Link, Fn as ListTile, Ro as MERCATOR_MAX_LATITUDE, or as Markdown, fr as Masonry, ea as MemoryRouter, Mn as Menubar, x as Modal, Ze as ModalsProvider, an as Money, so as MoneyInput, kn as MultiSelect, et as NProgressBar, ta as NavLink, $e as Navbar, na as Navigate, jn as NavigationMenu, Ln as NavigationRail, Ht as NotificationCenter, Ds as ORDINAL_START_STEP, Ue as OfflineIndicator, ra as Outlet, nt as Page, rt as Pagination, it as PasswordInput, co as PhoneInput, ot as PinInput, st as Popover, ln as Portal, ct as Progress, qt as QRCapacityError, Zt as QRCode, Di as QueryProvider, wi as REFETCH_TIME, lt as Radio, ut as RadioGroup, dt as RangeSlider, ft as RatingStars, zn as RefreshIndicator, rn as RelativeTime, En as Resizable, ia as Route, Ji as RouteGuard, aa as Routes, Os as SEQUENTIAL_STEP_COUNT, Ti as STALE_TIME, ht as SafeArea, Bt as Scheduler, Tn as ScrollArea, gt as SearchBar, _t as SegmentedControl, vt as Select, mt as Show, yt as Sidebar, Hn as SignaturePad, bt as Skeleton, On as Slider, xt as Spacer, zt as Sparkline, St as Spinner, R as Stack, Ct as Stat, wt as Stepper, Ot as StepperInput, kt as Switch, Ke as SyncStatusBadge, Ko as THEME_STYLE_ID, jt as Table, Mt as Tabs, At as Tag, fs as TelemetryProvider, $r as TempestApiError, zi as TempestDataProvider, Nt as Textarea, ha as ThemeProvider, Rn as TimePicker, Pt as Timeline, It as ToastProvider, _n as Toggle, vn as ToggleGroup, yn as ToggleGroupItem, Ft as Tooltip, pr as Tour, Go as TrajectoryMap, dr as Transfer, on as TreeView, sn as TruncateText, qe as UpdatePrompt, Wt as VirtualList, Kt as VirtualTable, cn as VisuallyHidden, Da as WebPushClient, Oa as WebPushPermissionDeniedError, ka as WebPushUnsupportedError, Bn as Wizard, Xn as aiChatStrings, Ye as applyKanbanMove, qo as applyTheme, lr as applyTransferMove, Br as assertNever, Eo as bearingDeg, Fo as boundingBox, Io as boundsCenter, ei as buildApiError, De as buildOpenInChromeIntent, Ms as cachedResponseBytes, Er as camelCase, Dr as capitalize, Un as chatStrings, Mr as chunk, Tt as clamp, bo as clampLatitude, za as clearCaches, e as cn, Gt as compareValues, us as consoleSink, ms as consoleTelemetryAdapter, Yo as contrastRatio, ni as createApiClient, Va as createAudioPlayer, ci as createAuthStore, Xo as createColorScale, Ri as createDataProvider, Ca as createEventStream, xs as createGrowthBookFeatureFlagsAdapter, _a as createI18n, bs as createInMemoryFlags, Fs as createInferenceProfiler, Ss as createLaunchDarklyFeatureFlagsAdapter, ds as createLogger, Ho as createOSRMBackend, Ii as createOfflineStore, Ga as createOfflineSync, Pa as createPartialResponse, Uo as createPositionTracker, gs as createPostHogTelemetryAdapter, Ei as createQueryKeys, pi as createRefreshQueue, yi as createRoleAccessControl, ma as createSelectors, hs as createSentryTelemetryAdapter, pa as createStore, mi as createTempestAuth, is as createTheme, vo as createWebSocket, Wn as dayLabel, Gr as debounce, ui as decodeJWT, Ir as deepMerge, Xi as defineRoutes, mr as describeFilter, ks as divergingScale, No as durationFactor, Oi as emptyOffsetPage, Jt as encodeQR, at as estimatePasswordStrength, Le as estimateStorage, Po as estimateTravel, Lo as expandBounds, hr as filtersFromSearchParams, gr as filtersToSearchParams, zo as fitProjection, Et as formatBytes, $a as formatCEP, eo as formatCNPJ, yr as formatCPF, Dt as formatCompactNumber, br as formatCurrency, xr as formatDate, Sr as formatDateTime, Ps as formatDurationMs, Cr as formatPercent, wr as formatPhone, oi as generateIdempotencyKey, cs as getInitialTheme, os as getThemePreset, Nr as groupBy, Gn as groupMessages, Do as haversineKm, Zo as hexToOklch, Qo as hexToRgb, $o as hexToRgbaString, Ka as higherVersionWins, Ba as inspectCaches, La as installBackgroundSync, ja as installNotificationClickHandler, Fa as installPrecache, Ma as installPushHandler, Ia as installRuntimeCache, Na as installSkipWaitingListener, Oe as isAndroid, ke as isAndroidWithoutPromptApi, ti as isApiError, xo as isCoordinate, ki as isCursorPage, Vr as isDefined, Lr as isEmpty, Zn as isGenerating, Ae as isIOS, di as isJWTExpired, Hr as isNumber, Ai as isOffsetPage, Ur as isPlainObject, Ta as isPushSupported, Cs as isShareSupported, je as isStandalone, Wr as isString, So as isValidLatitude, Co as isValidLongitude, Or as kebabCase, Qn as lastAssistantId, qa as lastWriteWins, fi as lazyWithRetry, Vi as listQueryKey, Yt as matrixToPath, Kr as memoizeOne, Be as moveItem, wo as normalizeLongitude, tt as nprogress, es as oklchToHex, Rr as omit, qr as once, Hi as oneQueryKey, _r as operatorsFor, ar as parseMarkdown, ri as parseResponse, Oo as pathLengthKm, bi as permissionsFromToken, Li as persistQueryClientOffline, zr as pick, Ha as playAudio, kr as pluralize, Bo as projectMercator, Zr as randomId, Pr as range, Ns as readDeviceProfile, Jo as readThemeToken, ts as readableForeground, oa as redirect, Ra as registerPeriodicSync, Ne as registerServiceWorker, ns as relativeLuminance, Vt as relativeTime, Pi as removeById, Re as requestPersistentStorage, $t as resolveLanguage, ai as retry, rs as rgbToHex, $n as roleLabel, ir as safeLinkUrl, As as scaleSteps, Xt as selectMode, js as sequentialScale, ws as share, Ts as shareOrDownloadBlob, Pe as skipWaiting, Yr as sleep, Ar as slugify, ur as splitTransferSides, Ua as stopAudio, Tr as storage, er as tailSignature, as as themeContrast, ls as themeInitScript, ss as themePresets, Jr as throttle, Kn as timeLabel, ko as toRadians, en as tokenize, tn as tokenizeLines, jr as truncate, tr as turnTime, qn as typingLabel, Fr as uniqueBy, to as unmask, Vo as unprojectMercator, Fe as unregisterAllServiceWorkers, ii as uploadWithProgress, Fi as upsertById, Ea as urlBase64ToUint8Array, gi as useAccessControl, Y as useAsync, Wa as useAudio, z as useBeforeInstallPrompt, a as useBreakpoint, _i as useCan, Ce as useClickOutside, W as useClientFilter, ee as useClipboard, _e as useCounter, Ui as useCreate, Mi as useCursorQuery, Bi as useDataProvider, H as useDebounce, se as useDeepMemo, Wi as useDelete, he as useDisclosure, ve as useDocumentTitle, Z as useDocumentVisibility, Ja as useErrorHandler, K as useEventListener, wa as useEventStream, ye as useFavicon, vs as useFeatureFlag, po as useFieldArray, ys as useFlagValue, ae as useFocusTrap, mo as useForm, ho as useFormContext, go as useFormState, re as useGeolocation, pe as useHover, ya as useI18n, ne as useIdle, Me as useInstallPrompt, Q as useIntersectionObserver, le as useInterval, we as useIsFirstRender, te as useKeyboardShortcut, Gi as useList, ge as useListState, q as useLocalStorage, sa as useLocation, me as useLongPress, Ee as useLongPressHandlers, be as useMap, ca as useMatch, G as useMediaQuery, Qe as useModals, la as useNavigate, Ut as useNotificationInbox, Si as useOAuthCallback, Te as useObjectUrl, Ni as useOfflineMutation, We as useOfflineSync, Ki as useOne, X as useOnline, ji as usePaginatedQuery, U as usePagination, ua as useParams, si as usePoll, Wo as usePositionTracker, ce as usePrevious, Aa as usePushSubscription, Se as useQueue, $ as useResizeObserver, da as useRouteError, ie as useScrollLock, He as useScrollOverflow, fa as useSearchParams, Ie as useServiceWorkerUpdate, xe as useSet, Ve as useSortable, oe as useStableCallback, ze as useStorageEstimate, Ge as useSyncStatus, ps as useTelemetry, ga as useTheme, de as useThrottle, ue as useTimeout, Lt as useToast, J as useToggle, ba as useTranslate, qi as useUpdate, lo as useViaCEP, _o as useWatch, yo as useWebSocket, fe as useWindowSize, Qa as useZodForm, no as validateCNPJ, ro as validateCPF, Xa as validateForm, nr as visibleTurns, Xr as withTimeout, Qr as writeXlsx, Za as zodResolver };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=class{_last;_speed={load:0,preprocess:0,inference:0,postprocess:0};constructor(){this._last=performance.now()}stage(e){let t=performance.now();this._speed[e]+=t-this._last,this._last=t}speed(){return{...this._speed}}};exports.SpeedTimer=e;
|
|
2
|
+
//# sourceMappingURL=timing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.cjs","names":[],"sources":["../../../src/vision/core/timing.ts"],"sourcesContent":["/**\n * Per-stage timing for a single `predict()` call.\n *\n * Populates the `speed` field every `Results` envelope carries, mirroring\n * Ultralytics' `results[0].speed`. All values are milliseconds measured with\n * `performance.now()`.\n */\n\n/**\n * Stage durations of one inference, in milliseconds.\n *\n * `preprocess`, `inference` and `postprocess` are the three keys Ultralytics\n * reports, measured over the same boundaries. `load` is specific to this SDK:\n * `predict()` accepts a URL, `Blob` or DOM element and decodes it internally,\n * so the fetch/decode cost would otherwise be invisible — and on a cold cache\n * it dominates everything else.\n */\nexport interface Speed {\n /** Fetching and decoding the input into an `RGBImage`. */\n load: number;\n /** Letterbox/resize, normalization and tensor packing. */\n preprocess: number;\n /** The ONNX Runtime forward pass. */\n inference: number;\n /** Decoding raw outputs into results (NMS, mask assembly, top-k). */\n postprocess: number;\n}\n\n/**\n * Accumulate stage durations while a `predict()` call runs.\n *\n * Each `stage()` call closes the previous stage: the elapsed time since the\n * last boundary is attributed to the name given. This keeps the call sites\n * free of paired start/stop bookkeeping and guarantees the four stages tile\n * the whole call without gaps.\n */\nexport class SpeedTimer {\n private _last: number;\n private readonly _speed: Speed = {\n load: 0,\n preprocess: 0,\n inference: 0,\n postprocess: 0,\n };\n\n constructor() {\n this._last = performance.now();\n }\n\n /**\n * Attribute the time elapsed since the previous boundary to `stage`.\n *\n * @param stage Which stage just finished.\n */\n stage(stage: keyof Speed): void {\n const now = performance.now();\n this._speed[stage] += now - this._last;\n this._last = now;\n }\n\n /**\n * The accumulated durations.\n *\n * @returns The `speed` object to hand to the `Results` envelope.\n */\n speed(): Speed {\n return { ...this._speed };\n }\n}\n"],"mappings":"AAoCA,IAAa,EAAb,KAAwB,CACpB,MACA,OAAiC,CAC7B,KAAM,EACN,WAAY,EACZ,UAAW,EACX,YAAa,CACjB,EAEA,aAAc,CACV,KAAK,MAAQ,YAAY,IAAI,CACjC,CAOA,MAAM,EAA0B,CAC5B,IAAM,EAAM,YAAY,IAAI,EAC5B,KAAK,OAAO,IAAU,EAAM,KAAK,MACjC,KAAK,MAAQ,CACjB,CAOA,OAAe,CACX,MAAO,CAAE,GAAG,KAAK,MAAO,CAC5B,CACJ"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/vision/core/timing.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
_last;
|
|
4
|
+
_speed = {
|
|
5
|
+
load: 0,
|
|
6
|
+
preprocess: 0,
|
|
7
|
+
inference: 0,
|
|
8
|
+
postprocess: 0
|
|
9
|
+
};
|
|
10
|
+
constructor() {
|
|
11
|
+
this._last = performance.now();
|
|
12
|
+
}
|
|
13
|
+
stage(e) {
|
|
14
|
+
let t = performance.now();
|
|
15
|
+
this._speed[e] += t - this._last, this._last = t;
|
|
16
|
+
}
|
|
17
|
+
speed() {
|
|
18
|
+
return { ...this._speed };
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { e as SpeedTimer };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=timing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.js","names":[],"sources":["../../../src/vision/core/timing.ts"],"sourcesContent":["/**\n * Per-stage timing for a single `predict()` call.\n *\n * Populates the `speed` field every `Results` envelope carries, mirroring\n * Ultralytics' `results[0].speed`. All values are milliseconds measured with\n * `performance.now()`.\n */\n\n/**\n * Stage durations of one inference, in milliseconds.\n *\n * `preprocess`, `inference` and `postprocess` are the three keys Ultralytics\n * reports, measured over the same boundaries. `load` is specific to this SDK:\n * `predict()` accepts a URL, `Blob` or DOM element and decodes it internally,\n * so the fetch/decode cost would otherwise be invisible — and on a cold cache\n * it dominates everything else.\n */\nexport interface Speed {\n /** Fetching and decoding the input into an `RGBImage`. */\n load: number;\n /** Letterbox/resize, normalization and tensor packing. */\n preprocess: number;\n /** The ONNX Runtime forward pass. */\n inference: number;\n /** Decoding raw outputs into results (NMS, mask assembly, top-k). */\n postprocess: number;\n}\n\n/**\n * Accumulate stage durations while a `predict()` call runs.\n *\n * Each `stage()` call closes the previous stage: the elapsed time since the\n * last boundary is attributed to the name given. This keeps the call sites\n * free of paired start/stop bookkeeping and guarantees the four stages tile\n * the whole call without gaps.\n */\nexport class SpeedTimer {\n private _last: number;\n private readonly _speed: Speed = {\n load: 0,\n preprocess: 0,\n inference: 0,\n postprocess: 0,\n };\n\n constructor() {\n this._last = performance.now();\n }\n\n /**\n * Attribute the time elapsed since the previous boundary to `stage`.\n *\n * @param stage Which stage just finished.\n */\n stage(stage: keyof Speed): void {\n const now = performance.now();\n this._speed[stage] += now - this._last;\n this._last = now;\n }\n\n /**\n * The accumulated durations.\n *\n * @returns The `speed` object to hand to the `Results` envelope.\n */\n speed(): Speed {\n return { ...this._speed };\n }\n}\n"],"mappings":";AAoCA,IAAa,IAAb,MAAwB;CACpB;CACA,SAAiC;EAC7B,MAAM;EACN,YAAY;EACZ,WAAW;EACX,aAAa;CACjB;CAEA,cAAc;EACV,KAAK,QAAQ,YAAY,IAAI;CACjC;CAOA,MAAM,GAA0B;EAC5B,IAAM,IAAM,YAAY,IAAI;EAE5B,AADA,KAAK,OAAO,MAAU,IAAM,KAAK,OACjC,KAAK,QAAQ;CACjB;CAOA,QAAe;EACX,OAAO,EAAE,GAAG,KAAK,OAAO;CAC5B;AACJ"}
|
package/dist/vision/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./core/exceptions.cjs"),t=require("./types.cjs"),n=require("./
|
|
1
|
+
const e=require("./core/exceptions.cjs"),t=require("./types.cjs"),n=require("./core/timing.cjs"),r=require("./results.cjs"),i=require("./labels.cjs"),a=require("./core/providers.cjs"),o=require("./core/session.cjs"),s=require("./io/image.cjs"),c=require("./preprocess/image.cjs"),l=require("./postprocess/classification.cjs"),u=require("./postprocess/detection.cjs"),d=require("./postprocess/segmentation.cjs"),f=require("./tasks/base.cjs"),p=require("./tasks/classifier.cjs"),m=require("./tasks/detector.cjs"),h=require("./tasks/segmenter.cjs");var g=`0.3.0`;exports.BoundingBox=t.BoundingBox,exports.Boxes=r.Boxes,exports.COCO_CLASSES=i.COCO_CLASSES,exports.ClassificationResults=r.ClassificationResults,exports.Classifier=p.Classifier,exports.DEFAULT_PROVIDERS=a.DEFAULT_PROVIDERS,exports.DetectionResults=r.DetectionResults,exports.Detector=m.Detector,exports.ImageLoadError=e.ImageLoadError,exports.InferenceError=e.InferenceError,exports.LabelMapError=e.LabelMapError,exports.Mask=t.Mask,exports.Masks=r.Masks,exports.ModelLoadError=e.ModelLoadError,exports.OrtSession=o.OrtSession,exports.OrtVisionError=e.OrtVisionError,exports.Probs=r.Probs,exports.ProviderNotAvailableError=e.ProviderNotAvailableError,exports.RGBImage=t.RGBImage,exports.SegmentationResults=r.SegmentationResults,exports.Segmenter=h.Segmenter,exports.SpeedTimer=n.SpeedTimer,exports.VERSION=g,exports.VisionTask=f.VisionTask,exports.batchedNms=u.batchedNms,exports.decodeYolo=u.decodeYolo,exports.decodeYoloAnchors=u.decodeYoloAnchors,exports.decodeYoloSeg=d.decodeYoloSeg,exports.decodeYoloV8=u.decodeYoloV8,exports.decodeYoloV8Anchors=u.decodeYoloV8Anchors,exports.decodeYoloV8Seg=d.decodeYoloV8Seg,exports.fromCv2=c.fromCv2,exports.letterbox=c.letterbox,exports.loadImage=s.loadImage,exports.nms=u.nms,exports.normalize=c.normalize,exports.resize=c.resize,exports.resolveLabels=i.resolveLabels,exports.resolveProviders=a.resolveProviders,exports.softmax=l.softmax,exports.toCHW=c.toCHW,exports.toCv2=c.toCv2,exports.toFloat32=c.toFloat32,exports.toFloat32Tensor=c.toFloat32Tensor,exports.toTensor=c.toTensor,exports.topK=l.topK;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/vision/index.ts"],"sourcesContent":["/**\n * `tempest-react-sdk/vision` — browser computer-vision inference with ONNX\n * Runtime Web (classification, detection, segmentation).\n *\n * Vendored from `@mauriciobenjamin700/ort-vision-sdk-web@0.
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/vision/index.ts"],"sourcesContent":["/**\n * `tempest-react-sdk/vision` — browser computer-vision inference with ONNX\n * Runtime Web (classification, detection, segmentation).\n *\n * Vendored from `@mauriciobenjamin700/ort-vision-sdk-web@0.3.0` (MIT, same\n * author) so it ships inside this SDK without an extra package install.\n * `onnxruntime-web` stays an optional peer dependency — install it (and ship\n * the matching `.wasm` files) only when you use this subpath.\n *\n * Do not hand-edit — regenerate with `npm run vendor:vision`.\n */\n\nexport {\n BoundingBox,\n Mask,\n RGBImage,\n type ClassProbability,\n type ClassificationResult,\n type DetectionResult,\n type SegmentationResult,\n} from \"./types\";\n\nexport {\n Boxes,\n ClassificationResults,\n DetectionResults,\n Masks,\n Probs,\n SegmentationResults,\n} from \"./results\";\n\nexport { COCO_CLASSES, type LabelSpec, type ResolveLabelsOptions, resolveLabels } from \"./labels\";\n\nexport {\n ImageLoadError,\n InferenceError,\n LabelMapError,\n ModelLoadError,\n OrtVisionError,\n ProviderNotAvailableError,\n} from \"./core/exceptions\";\n\nexport { type ModelSource, type OrtSessionOptions, OrtSession } from \"./core/session\";\nexport { DEFAULT_PROVIDERS, resolveProviders } from \"./core/providers\";\nexport { type Speed, SpeedTimer } from \"./core/timing\";\n\nexport { type ImageInput, loadImage } from \"./io/image\";\n\nexport {\n type LetterboxResult,\n fromCv2,\n letterbox,\n normalize,\n resize,\n toCHW,\n toCv2,\n toFloat32,\n toFloat32Tensor,\n toTensor,\n} from \"./preprocess/image\";\n\nexport { type TopKResult, softmax, topK } from \"./postprocess/classification\";\n\nexport {\n type DecodeYoloAnchorsOptions,\n type DecodeYoloOptions,\n type DecodeYoloV8AnchorsOptions,\n type DecodeYoloV8Options,\n type DecodedAnchors,\n type DecodedDetection,\n batchedNms,\n decodeYolo,\n decodeYoloAnchors,\n decodeYoloV8,\n decodeYoloV8Anchors,\n nms,\n} from \"./postprocess/detection\";\n\nexport {\n type DecodeYoloSegOptions,\n type DecodeYoloV8SegOptions,\n type DecodedSegmentation,\n decodeYoloSeg,\n decodeYoloV8Seg,\n} from \"./postprocess/segmentation\";\n\nexport { VisionTask } from \"./tasks/base\";\nexport {\n type ClassifierOptions,\n type ClassifierPredictOptions,\n Classifier,\n} from \"./tasks/classifier\";\nexport {\n type DetectorHead,\n type DetectorOptions,\n type DetectorPredictOptions,\n Detector,\n} from \"./tasks/detector\";\nexport {\n type SegmenterHead,\n type SegmenterOptions,\n type SegmenterPredictOptions,\n Segmenter,\n} from \"./tasks/segmenter\";\n\nexport const VERSION: string = \"0.3.0\";\n"],"mappings":"kiBAyGA,IAAa,EAAkB"}
|
package/dist/vision/index.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { ImageLoadError as e, InferenceError as t, LabelMapError as n, ModelLoadError as r, OrtVisionError as i, ProviderNotAvailableError as a } from "./core/exceptions.js";
|
|
2
2
|
import { BoundingBox as o, Mask as s, RGBImage as c } from "./types.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
3
|
+
import { SpeedTimer as l } from "./core/timing.js";
|
|
4
|
+
import { Boxes as u, ClassificationResults as d, DetectionResults as f, Masks as p, Probs as m, SegmentationResults as h } from "./results.js";
|
|
5
|
+
import { COCO_CLASSES as g, resolveLabels as _ } from "./labels.js";
|
|
6
|
+
import { DEFAULT_PROVIDERS as v, resolveProviders as y } from "./core/providers.js";
|
|
7
|
+
import { OrtSession as b } from "./core/session.js";
|
|
8
|
+
import { loadImage as x } from "./io/image.js";
|
|
9
|
+
import { fromCv2 as S, letterbox as C, normalize as w, resize as T, toCHW as E, toCv2 as D, toFloat32 as O, toFloat32Tensor as k, toTensor as A } from "./preprocess/image.js";
|
|
10
|
+
import { softmax as j, topK as M } from "./postprocess/classification.js";
|
|
11
|
+
import { batchedNms as N, decodeYolo as P, decodeYoloAnchors as F, decodeYoloV8 as I, decodeYoloV8Anchors as L, nms as R } from "./postprocess/detection.js";
|
|
12
|
+
import { decodeYoloSeg as z, decodeYoloV8Seg as B } from "./postprocess/segmentation.js";
|
|
13
|
+
import { VisionTask as V } from "./tasks/base.js";
|
|
14
|
+
import { Classifier as H } from "./tasks/classifier.js";
|
|
15
|
+
import { Detector as U } from "./tasks/detector.js";
|
|
16
|
+
import { Segmenter as W } from "./tasks/segmenter.js";
|
|
16
17
|
//#region src/vision/index.ts
|
|
17
|
-
var
|
|
18
|
+
var G = "0.3.0";
|
|
18
19
|
//#endregion
|
|
19
|
-
export { o as BoundingBox,
|
|
20
|
+
export { o as BoundingBox, u as Boxes, g as COCO_CLASSES, d as ClassificationResults, H as Classifier, v as DEFAULT_PROVIDERS, f as DetectionResults, U as Detector, e as ImageLoadError, t as InferenceError, n as LabelMapError, s as Mask, p as Masks, r as ModelLoadError, b as OrtSession, i as OrtVisionError, m as Probs, a as ProviderNotAvailableError, c as RGBImage, h as SegmentationResults, W as Segmenter, l as SpeedTimer, G as VERSION, V as VisionTask, N as batchedNms, P as decodeYolo, F as decodeYoloAnchors, z as decodeYoloSeg, I as decodeYoloV8, L as decodeYoloV8Anchors, B as decodeYoloV8Seg, S as fromCv2, C as letterbox, x as loadImage, R as nms, w as normalize, T as resize, _ as resolveLabels, y as resolveProviders, j as softmax, E as toCHW, D as toCv2, O as toFloat32, k as toFloat32Tensor, A as toTensor, M as topK };
|
|
20
21
|
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
package/dist/vision/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/vision/index.ts"],"sourcesContent":["/**\n * `tempest-react-sdk/vision` — browser computer-vision inference with ONNX\n * Runtime Web (classification, detection, segmentation).\n *\n * Vendored from `@mauriciobenjamin700/ort-vision-sdk-web@0.
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/vision/index.ts"],"sourcesContent":["/**\n * `tempest-react-sdk/vision` — browser computer-vision inference with ONNX\n * Runtime Web (classification, detection, segmentation).\n *\n * Vendored from `@mauriciobenjamin700/ort-vision-sdk-web@0.3.0` (MIT, same\n * author) so it ships inside this SDK without an extra package install.\n * `onnxruntime-web` stays an optional peer dependency — install it (and ship\n * the matching `.wasm` files) only when you use this subpath.\n *\n * Do not hand-edit — regenerate with `npm run vendor:vision`.\n */\n\nexport {\n BoundingBox,\n Mask,\n RGBImage,\n type ClassProbability,\n type ClassificationResult,\n type DetectionResult,\n type SegmentationResult,\n} from \"./types\";\n\nexport {\n Boxes,\n ClassificationResults,\n DetectionResults,\n Masks,\n Probs,\n SegmentationResults,\n} from \"./results\";\n\nexport { COCO_CLASSES, type LabelSpec, type ResolveLabelsOptions, resolveLabels } from \"./labels\";\n\nexport {\n ImageLoadError,\n InferenceError,\n LabelMapError,\n ModelLoadError,\n OrtVisionError,\n ProviderNotAvailableError,\n} from \"./core/exceptions\";\n\nexport { type ModelSource, type OrtSessionOptions, OrtSession } from \"./core/session\";\nexport { DEFAULT_PROVIDERS, resolveProviders } from \"./core/providers\";\nexport { type Speed, SpeedTimer } from \"./core/timing\";\n\nexport { type ImageInput, loadImage } from \"./io/image\";\n\nexport {\n type LetterboxResult,\n fromCv2,\n letterbox,\n normalize,\n resize,\n toCHW,\n toCv2,\n toFloat32,\n toFloat32Tensor,\n toTensor,\n} from \"./preprocess/image\";\n\nexport { type TopKResult, softmax, topK } from \"./postprocess/classification\";\n\nexport {\n type DecodeYoloAnchorsOptions,\n type DecodeYoloOptions,\n type DecodeYoloV8AnchorsOptions,\n type DecodeYoloV8Options,\n type DecodedAnchors,\n type DecodedDetection,\n batchedNms,\n decodeYolo,\n decodeYoloAnchors,\n decodeYoloV8,\n decodeYoloV8Anchors,\n nms,\n} from \"./postprocess/detection\";\n\nexport {\n type DecodeYoloSegOptions,\n type DecodeYoloV8SegOptions,\n type DecodedSegmentation,\n decodeYoloSeg,\n decodeYoloV8Seg,\n} from \"./postprocess/segmentation\";\n\nexport { VisionTask } from \"./tasks/base\";\nexport {\n type ClassifierOptions,\n type ClassifierPredictOptions,\n Classifier,\n} from \"./tasks/classifier\";\nexport {\n type DetectorHead,\n type DetectorOptions,\n type DetectorPredictOptions,\n Detector,\n} from \"./tasks/detector\";\nexport {\n type SegmenterHead,\n type SegmenterOptions,\n type SegmenterPredictOptions,\n Segmenter,\n} from \"./tasks/segmenter\";\n\nexport const VERSION: string = \"0.3.0\";\n"],"mappings":";;;;;;;;;;;;;;;;;AAyGA,IAAa,IAAkB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../types.cjs");function t(e,t,n){let r=t.length;if(r===0)return new Int32Array;let i=new Float32Array(r);for(let t=0;t<r;t++){let n=e[t*4],r=e[t*4+1],a=e[t*4+2],o=e[t*4+3];i[t]=Math.max(0,a-n)*Math.max(0,o-r)}let a=Array(r);for(let e=0;e<r;e++)a[e]=e;a.sort((e,n)=>t[n]-t[e]);let o=new Uint8Array(r),s=[];for(let t=0;t<a.length;t++){let r=a[t];if(o[r])continue;s.push(r);let c=e[r*4],l=e[r*4+1],u=e[r*4+2],d=e[r*4+3],f=i[r];for(let r=t+1;r<a.length;r++){let t=a[r];if(o[t])continue;let s=e[t*4],p=e[t*4+1],m=e[t*4+2],h=e[t*4+3],g=Math.max(c,s),_=Math.max(l,p),v=Math.min(u,m),y=Math.min(d,h),b=Math.max(0,v-g)*Math.max(0,y-_),x=f+i[t]-b;(x>0?b/x:0)>n&&(o[t]=1)}}return Int32Array.from(s)}function n(e,n,r,i){if(n.length===0)return new Int32Array;let a=new Map;for(let e=0;e<r.length;e++){let t=r[e],n=a.get(t);n===void 0?a.set(t,[e]):n.push(e)}let o=[];for(let r of a.values()){let a=r.length,s=new Float32Array(a*4),c=new Float32Array(a);for(let t=0;t<a;t++){let i=r[t];s[t*4]=e[i*4],s[t*4+1]=e[i*4+1],s[t*4+2]=e[i*4+2],s[t*4+3]=e[i*4+3],c[t]=n[i]}let l=t(s,c,i);for(let e=0;e<l.length;e++)o.push(r[l[e]])}return o.sort((e,t)=>n[t]-n[e]),Int32Array.from(o)}function r(e,t,r){let a=t;if(a.length===3){if(a[0]!==1)throw Error(`decodeYoloAnchors: expected batch size 1, got ${a[0]}.`);a=[a[1],a[2]]}if(a.length!==2)throw Error(`decodeYoloAnchors: expected 2-D output after batch removal, got dims=${JSON.stringify(t)}.`);let o=a[0],s=a[1],{numClasses:c,originalWidth:l,originalHeight:u,padLeft:d,padTop:f,scale:p,confThreshold:m,iouThreshold:h,maxDetections:g}=r;if(c<1||c+4>o)throw Error(`decodeYoloAnchors: invalid numClasses=${c} for channels=${o}.`);if(e.length!==o*s)throw Error(`decodeYoloAnchors: data length ${e.length} does not match channels*numAnchors=${o*s}.`);let _=[];for(let t=0;t<s;t++){let n=0,r=-1/0;for(let i=0;i<c;i++){let a=e[(4+i)*s+t];a!==void 0&&a>r&&(r=a,n=i)}if(r<m)continue;let i=e[t],a=e[s+t],o=e[2*s+t],h=e[3*s+t],g=i-o/2,v=a-h/2,y=i+o/2,b=a+h/2;g=(g-d)/p,v=(v-f)/p,y=(y-d)/p,b=(b-f)/p,g=Math.max(0,Math.min(l,g)),v=Math.max(0,Math.min(u,v)),y=Math.max(0,Math.min(l,y)),b=Math.max(0,Math.min(u,b)),_.push({anchorIdx:t,x1:g,y1:v,x2:y,y2:b,classId:n,confidence:r})}if(_.length===0)return i();let v=new Float32Array(_.length*4),y=new Float32Array(_.length),b=new Int32Array(_.length);for(let e=0;e<_.length;e++){let t=_[e];v[e*4]=t.x1,v[e*4+1]=t.y1,v[e*4+2]=t.x2,v[e*4+3]=t.y2,y[e]=t.confidence,b[e]=t.classId}let x=n(v,y,b,h);if(x.length===0)return i();let S=Array.from(x).slice(0,g),C=S.length,w=new Int32Array(C),T=new Float32Array(C*4),E=new Int32Array(C),D=new Float32Array(C);for(let e=0;e<C;e++){let t=_[S[e]];w[e]=t.anchorIdx,T[e*4]=t.x1,T[e*4+1]=t.y1,T[e*4+2]=t.x2,T[e*4+3]=t.y2,E[e]=t.classId,D[e]=t.confidence}return{anchorIndices:w,boxesXyxy:T,classIds:E,confidences:D}}function i(){return{anchorIndices:new Int32Array,boxesXyxy:new Float32Array,classIds:new Int32Array,confidences:new Float32Array}}function a(t,n,i){let a=n.length===3?n[1]:n[0];if(a===void 0||a<5)throw Error(`decodeYolo: invalid output channel count ${a} (expected >= 5).`);let o=r(t,n,{numClasses:a-4,...i}),s=[];for(let t=0;t<o.classIds.length;t++)s.push({bbox:new e.BoundingBox(o.boxesXyxy[t*4],o.boxesXyxy[t*4+1],o.boxesXyxy[t*4+2],o.boxesXyxy[t*4+3]),classId:o.classIds[t],confidence:o.confidences[t]});return s}var o=!1,s=!1;function c(e,t,n){return o||(o=!0,console.warn(`[@ort-vision-sdk/web] decodeYoloV8 is deprecated since 0.2.0; use decodeYolo. The alias will be removed in 0.
|
|
1
|
+
const e=require("../types.cjs");function t(e,t,n){let r=t.length;if(r===0)return new Int32Array;let i=new Float32Array(r);for(let t=0;t<r;t++){let n=e[t*4],r=e[t*4+1],a=e[t*4+2],o=e[t*4+3];i[t]=Math.max(0,a-n)*Math.max(0,o-r)}let a=Array(r);for(let e=0;e<r;e++)a[e]=e;a.sort((e,n)=>t[n]-t[e]);let o=new Uint8Array(r),s=[];for(let t=0;t<a.length;t++){let r=a[t];if(o[r])continue;s.push(r);let c=e[r*4],l=e[r*4+1],u=e[r*4+2],d=e[r*4+3],f=i[r];for(let r=t+1;r<a.length;r++){let t=a[r];if(o[t])continue;let s=e[t*4],p=e[t*4+1],m=e[t*4+2],h=e[t*4+3],g=Math.max(c,s),_=Math.max(l,p),v=Math.min(u,m),y=Math.min(d,h),b=Math.max(0,v-g)*Math.max(0,y-_),x=f+i[t]-b;(x>0?b/x:0)>n&&(o[t]=1)}}return Int32Array.from(s)}function n(e,n,r,i){if(n.length===0)return new Int32Array;let a=new Map;for(let e=0;e<r.length;e++){let t=r[e],n=a.get(t);n===void 0?a.set(t,[e]):n.push(e)}let o=[];for(let r of a.values()){let a=r.length,s=new Float32Array(a*4),c=new Float32Array(a);for(let t=0;t<a;t++){let i=r[t];s[t*4]=e[i*4],s[t*4+1]=e[i*4+1],s[t*4+2]=e[i*4+2],s[t*4+3]=e[i*4+3],c[t]=n[i]}let l=t(s,c,i);for(let e=0;e<l.length;e++)o.push(r[l[e]])}return o.sort((e,t)=>n[t]-n[e]),Int32Array.from(o)}function r(e,t,r){let a=t;if(a.length===3){if(a[0]!==1)throw Error(`decodeYoloAnchors: expected batch size 1, got ${a[0]}.`);a=[a[1],a[2]]}if(a.length!==2)throw Error(`decodeYoloAnchors: expected 2-D output after batch removal, got dims=${JSON.stringify(t)}.`);let o=a[0],s=a[1],{numClasses:c,originalWidth:l,originalHeight:u,padLeft:d,padTop:f,scale:p,confThreshold:m,iouThreshold:h,maxDetections:g}=r;if(c<1||c+4>o)throw Error(`decodeYoloAnchors: invalid numClasses=${c} for channels=${o}.`);if(e.length!==o*s)throw Error(`decodeYoloAnchors: data length ${e.length} does not match channels*numAnchors=${o*s}.`);let _=[];for(let t=0;t<s;t++){let n=0,r=-1/0;for(let i=0;i<c;i++){let a=e[(4+i)*s+t];a!==void 0&&a>r&&(r=a,n=i)}if(r<m)continue;let i=e[t],a=e[s+t],o=e[2*s+t],h=e[3*s+t],g=i-o/2,v=a-h/2,y=i+o/2,b=a+h/2;g=(g-d)/p,v=(v-f)/p,y=(y-d)/p,b=(b-f)/p,g=Math.max(0,Math.min(l,g)),v=Math.max(0,Math.min(u,v)),y=Math.max(0,Math.min(l,y)),b=Math.max(0,Math.min(u,b)),_.push({anchorIdx:t,x1:g,y1:v,x2:y,y2:b,classId:n,confidence:r})}if(_.length===0)return i();let v=new Float32Array(_.length*4),y=new Float32Array(_.length),b=new Int32Array(_.length);for(let e=0;e<_.length;e++){let t=_[e];v[e*4]=t.x1,v[e*4+1]=t.y1,v[e*4+2]=t.x2,v[e*4+3]=t.y2,y[e]=t.confidence,b[e]=t.classId}let x=n(v,y,b,h);if(x.length===0)return i();let S=Array.from(x).slice(0,g),C=S.length,w=new Int32Array(C),T=new Float32Array(C*4),E=new Int32Array(C),D=new Float32Array(C);for(let e=0;e<C;e++){let t=_[S[e]];w[e]=t.anchorIdx,T[e*4]=t.x1,T[e*4+1]=t.y1,T[e*4+2]=t.x2,T[e*4+3]=t.y2,E[e]=t.classId,D[e]=t.confidence}return{anchorIndices:w,boxesXyxy:T,classIds:E,confidences:D}}function i(){return{anchorIndices:new Int32Array,boxesXyxy:new Float32Array,classIds:new Int32Array,confidences:new Float32Array}}function a(t,n,i){let a=n.length===3?n[1]:n[0];if(a===void 0||a<5)throw Error(`decodeYolo: invalid output channel count ${a} (expected >= 5).`);let o=r(t,n,{numClasses:a-4,...i}),s=[];for(let t=0;t<o.classIds.length;t++)s.push({bbox:new e.BoundingBox(o.boxesXyxy[t*4],o.boxesXyxy[t*4+1],o.boxesXyxy[t*4+2],o.boxesXyxy[t*4+3]),classId:o.classIds[t],confidence:o.confidences[t]});return s}var o=!1,s=!1;function c(e,t,n){return o||(o=!0,console.warn(`[@ort-vision-sdk/web] decodeYoloV8 is deprecated since 0.2.0; use decodeYolo. The alias will be removed in 0.4.0.`)),a(e,t,n)}function l(e,t,n){return s||(s=!0,console.warn(`[@ort-vision-sdk/web] decodeYoloV8Anchors is deprecated since 0.2.0; use decodeYoloAnchors. The alias will be removed in 0.4.0.`)),r(e,t,n)}exports.batchedNms=n,exports.decodeYolo=a,exports.decodeYoloAnchors=r,exports.decodeYoloV8=c,exports.decodeYoloV8Anchors=l,exports.nms=t;
|
|
2
2
|
//# sourceMappingURL=detection.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detection.cjs","names":[],"sources":["../../../src/vision/postprocess/detection.ts"],"sourcesContent":["/**\n * Detection head postprocessing: anchor-free YOLO decoding + non-maximum suppression.\n *\n * The shared {@link decodeYoloAnchors} helper does the per-anchor work that\n * is identical for plain detection and segmentation (transpose, xywh→xyxy,\n * letterbox unmap, per-class NMS, sort & cap). {@link decodeYolo} is a thin\n * wrapper around it; the segmentation module ({@link ./segmentation.js})\n * calls the helper directly so it can also recover the per-anchor mask\n * coefficients.\n *\n * Works for any YOLO export with the post-v8 anchor-free head:\n * **YOLOv8 / v9 / v10 / v11 / v12** detect heads, all of which share the\n * `[1, 4 + nc, N]` output layout.\n */\n\nimport { BoundingBox } from \"../types\";\n\n/**\n * Greedy non-maximum suppression on axis-aligned bounding boxes.\n *\n * Mirrors `torchvision.ops.nms` (keeps boxes with the highest score, drops\n * any subsequent box whose IoU exceeds the threshold).\n *\n * @param boxes Flat array of length `4 * N` in xyxy order: `[x1,y1,x2,y2, ...]`.\n * @param scores Detection score per box, length `N`.\n * @param iouThreshold Boxes with IoU above this threshold relative to a kept box are suppressed.\n * @returns Indices of kept boxes, in descending score order.\n */\nexport function nms(boxes: Float32Array, scores: Float32Array, iouThreshold: number): Int32Array {\n const n = scores.length;\n if (n === 0) return new Int32Array(0);\n\n const areas = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n const x1 = boxes[i * 4] as number;\n const y1 = boxes[i * 4 + 1] as number;\n const x2 = boxes[i * 4 + 2] as number;\n const y2 = boxes[i * 4 + 3] as number;\n areas[i] = Math.max(0, x2 - x1) * Math.max(0, y2 - y1);\n }\n\n const order = new Array<number>(n);\n for (let i = 0; i < n; i++) order[i] = i;\n order.sort((a, b) => (scores[b] as number) - (scores[a] as number));\n\n const suppressed = new Uint8Array(n);\n const keep: number[] = [];\n\n for (let oi = 0; oi < order.length; oi++) {\n const i = order[oi] as number;\n if (suppressed[i]) continue;\n keep.push(i);\n\n const ax1 = boxes[i * 4] as number;\n const ay1 = boxes[i * 4 + 1] as number;\n const ax2 = boxes[i * 4 + 2] as number;\n const ay2 = boxes[i * 4 + 3] as number;\n const ai = areas[i] as number;\n\n for (let oj = oi + 1; oj < order.length; oj++) {\n const j = order[oj] as number;\n if (suppressed[j]) continue;\n\n const bx1 = boxes[j * 4] as number;\n const by1 = boxes[j * 4 + 1] as number;\n const bx2 = boxes[j * 4 + 2] as number;\n const by2 = boxes[j * 4 + 3] as number;\n\n const ix1 = Math.max(ax1, bx1);\n const iy1 = Math.max(ay1, by1);\n const ix2 = Math.min(ax2, bx2);\n const iy2 = Math.min(ay2, by2);\n const iw = Math.max(0, ix2 - ix1);\n const ih = Math.max(0, iy2 - iy1);\n const inter = iw * ih;\n const union = ai + (areas[j] as number) - inter;\n const iou = union > 0 ? inter / union : 0;\n if (iou > iouThreshold) suppressed[j] = 1;\n }\n }\n\n return Int32Array.from(keep);\n}\n\n/**\n * Per-class NMS — boxes are suppressed only by other boxes of the same class.\n *\n * Mirrors `torchvision.ops.batched_nms`.\n *\n * @param boxes Flat array of length `4 * N` in xyxy order.\n * @param scores Detection score per box, length `N`.\n * @param idxs Class index per box, length `N`. Boxes with different `idxs`\n * never suppress each other.\n * @param iouThreshold IoU threshold for suppression within a class.\n */\nexport function batchedNms(\n boxes: Float32Array,\n scores: Float32Array,\n idxs: Int32Array,\n iouThreshold: number,\n): Int32Array {\n if (scores.length === 0) return new Int32Array(0);\n\n const byClass = new Map<number, number[]>();\n for (let i = 0; i < idxs.length; i++) {\n const c = idxs[i] as number;\n const list = byClass.get(c);\n if (list === undefined) byClass.set(c, [i]);\n else list.push(i);\n }\n\n const keep: number[] = [];\n for (const indices of byClass.values()) {\n const m = indices.length;\n const subBoxes = new Float32Array(m * 4);\n const subScores = new Float32Array(m);\n for (let k = 0; k < m; k++) {\n const i = indices[k] as number;\n subBoxes[k * 4] = boxes[i * 4] as number;\n subBoxes[k * 4 + 1] = boxes[i * 4 + 1] as number;\n subBoxes[k * 4 + 2] = boxes[i * 4 + 2] as number;\n subBoxes[k * 4 + 3] = boxes[i * 4 + 3] as number;\n subScores[k] = scores[i] as number;\n }\n const subKeep = nms(subBoxes, subScores, iouThreshold);\n for (let k = 0; k < subKeep.length; k++) {\n keep.push(indices[subKeep[k] as number] as number);\n }\n }\n\n keep.sort((a, b) => (scores[b] as number) - (scores[a] as number));\n return Int32Array.from(keep);\n}\n\nexport interface DecodeYoloAnchorsOptions {\n /** Number of class-score channels following the 4 box channels. */\n readonly numClasses: number;\n readonly originalWidth: number;\n readonly originalHeight: number;\n readonly padLeft: number;\n readonly padTop: number;\n readonly scale: number;\n readonly confThreshold: number;\n readonly iouThreshold: number;\n readonly maxDetections: number;\n}\n\nexport interface DecodedAnchors {\n /** Indices into the original `numAnchors` axis, in descending confidence order. */\n readonly anchorIndices: Int32Array;\n /** `[k, 4]` boxes in original-image pixel coords, flat row-major xyxy. */\n readonly boxesXyxy: Float32Array;\n /** Predicted class id per survivor. */\n readonly classIds: Int32Array;\n /** Confidence per survivor. */\n readonly confidences: Float32Array;\n}\n\n/**\n * Shared YOLO per-anchor decode used by both detection and segmentation\n * (v8 / v9 / v10 / v11 / v12).\n *\n * Only the first `4 + numClasses` channels are read; later channels (e.g.\n * mask coefficients) are ignored — callers can fetch them via the returned\n * {@link DecodedAnchors.anchorIndices}.\n *\n * @param data Flat per-anchor output, length `channels * numAnchors`.\n * @param dims Dims as reported by ORT, e.g. `[1, 84, 8400]` (det) or\n * `[1, 116, 8400]` (seg). The leading batch dim must be 1.\n */\nexport function decodeYoloAnchors(\n data: Float32Array,\n dims: readonly number[],\n options: DecodeYoloAnchorsOptions,\n): DecodedAnchors {\n let normalized = dims;\n if (normalized.length === 3) {\n if (normalized[0] !== 1) {\n throw new Error(`decodeYoloAnchors: expected batch size 1, got ${normalized[0]}.`);\n }\n normalized = [normalized[1] as number, normalized[2] as number];\n }\n if (normalized.length !== 2) {\n throw new Error(\n `decodeYoloAnchors: expected 2-D output after batch removal, got dims=${JSON.stringify(dims)}.`,\n );\n }\n const channels = normalized[0] as number;\n const numAnchors = normalized[1] as number;\n\n const {\n numClasses,\n originalWidth,\n originalHeight,\n padLeft,\n padTop,\n scale,\n confThreshold,\n iouThreshold,\n maxDetections,\n } = options;\n\n if (numClasses < 1 || numClasses + 4 > channels) {\n throw new Error(\n `decodeYoloAnchors: invalid numClasses=${numClasses} for channels=${channels}.`,\n );\n }\n if (data.length !== channels * numAnchors) {\n throw new Error(\n `decodeYoloAnchors: data length ${data.length} does not match channels*numAnchors=${channels * numAnchors}.`,\n );\n }\n\n type Candidate = {\n anchorIdx: number;\n x1: number;\n y1: number;\n x2: number;\n y2: number;\n classId: number;\n confidence: number;\n };\n const candidates: Candidate[] = [];\n\n for (let a = 0; a < numAnchors; a++) {\n let bestCls = 0;\n let bestScore = -Infinity;\n for (let c = 0; c < numClasses; c++) {\n const s = data[(4 + c) * numAnchors + a];\n if (s !== undefined && s > bestScore) {\n bestScore = s;\n bestCls = c;\n }\n }\n if (bestScore < confThreshold) continue;\n\n const cx = data[a] as number;\n const cy = data[numAnchors + a] as number;\n const w = data[2 * numAnchors + a] as number;\n const h = data[3 * numAnchors + a] as number;\n\n let x1 = cx - w / 2;\n let y1 = cy - h / 2;\n let x2 = cx + w / 2;\n let y2 = cy + h / 2;\n\n x1 = (x1 - padLeft) / scale;\n y1 = (y1 - padTop) / scale;\n x2 = (x2 - padLeft) / scale;\n y2 = (y2 - padTop) / scale;\n\n x1 = Math.max(0, Math.min(originalWidth, x1));\n y1 = Math.max(0, Math.min(originalHeight, y1));\n x2 = Math.max(0, Math.min(originalWidth, x2));\n y2 = Math.max(0, Math.min(originalHeight, y2));\n\n candidates.push({ anchorIdx: a, x1, y1, x2, y2, classId: bestCls, confidence: bestScore });\n }\n\n if (candidates.length === 0) return emptyDecoded();\n\n // Build flat arrays then delegate to batchedNms — same algorithm as before\n // but funnelled through the public per-class NMS helper.\n const flatBoxes = new Float32Array(candidates.length * 4);\n const scoresArr = new Float32Array(candidates.length);\n const idxsArr = new Int32Array(candidates.length);\n for (let i = 0; i < candidates.length; i++) {\n const c = candidates[i] as Candidate;\n flatBoxes[i * 4] = c.x1;\n flatBoxes[i * 4 + 1] = c.y1;\n flatBoxes[i * 4 + 2] = c.x2;\n flatBoxes[i * 4 + 3] = c.y2;\n scoresArr[i] = c.confidence;\n idxsArr[i] = c.classId;\n }\n const kept = batchedNms(flatBoxes, scoresArr, idxsArr, iouThreshold);\n if (kept.length === 0) return emptyDecoded();\n\n const limited = Array.from(kept).slice(0, maxDetections);\n const k = limited.length;\n const anchorIndices = new Int32Array(k);\n const boxesXyxy = new Float32Array(k * 4);\n const classIds = new Int32Array(k);\n const confidences = new Float32Array(k);\n for (let i = 0; i < k; i++) {\n const c = candidates[limited[i] as number] as Candidate;\n anchorIndices[i] = c.anchorIdx;\n boxesXyxy[i * 4] = c.x1;\n boxesXyxy[i * 4 + 1] = c.y1;\n boxesXyxy[i * 4 + 2] = c.x2;\n boxesXyxy[i * 4 + 3] = c.y2;\n classIds[i] = c.classId;\n confidences[i] = c.confidence;\n }\n return { anchorIndices, boxesXyxy, classIds, confidences };\n}\n\nfunction emptyDecoded(): DecodedAnchors {\n return {\n anchorIndices: new Int32Array(0),\n boxesXyxy: new Float32Array(0),\n classIds: new Int32Array(0),\n confidences: new Float32Array(0),\n };\n}\n\nexport interface DecodeYoloOptions {\n readonly originalWidth: number;\n readonly originalHeight: number;\n readonly padLeft: number;\n readonly padTop: number;\n readonly scale: number;\n readonly confThreshold: number;\n readonly iouThreshold: number;\n readonly maxDetections: number;\n}\n\nexport interface DecodedDetection {\n readonly bbox: BoundingBox;\n readonly classId: number;\n readonly confidence: number;\n}\n\n/**\n * Decode an anchor-free YOLO detection output into a list of detections.\n *\n * Works for **YOLOv8 / v9 / v10 / v11 / v12** detect heads.\n *\n * Expected raw shape: `[1, 4 + numClasses, N]`. `numClasses` is inferred\n * from the channel count.\n */\nexport function decodeYolo(\n output: Float32Array,\n outputDims: readonly number[],\n options: DecodeYoloOptions,\n): DecodedDetection[] {\n const channels = outputDims.length === 3 ? outputDims[1] : outputDims[0];\n if (channels === undefined || channels < 5) {\n throw new Error(`decodeYolo: invalid output channel count ${channels} (expected >= 5).`);\n }\n const numClasses = channels - 4;\n\n const decoded = decodeYoloAnchors(output, outputDims, {\n numClasses,\n ...options,\n });\n\n const results: DecodedDetection[] = [];\n for (let i = 0; i < decoded.classIds.length; i++) {\n results.push({\n bbox: new BoundingBox(\n decoded.boxesXyxy[i * 4] as number,\n decoded.boxesXyxy[i * 4 + 1] as number,\n decoded.boxesXyxy[i * 4 + 2] as number,\n decoded.boxesXyxy[i * 4 + 3] as number,\n ),\n classId: decoded.classIds[i] as number,\n confidence: decoded.confidences[i] as number,\n });\n }\n return results;\n}\n\nlet _warnedDecodeYoloV8 = false;\nlet _warnedDecodeYoloV8Anchors = false;\n\n/**\n * @deprecated since 0.2.0 — use {@link decodeYolo}. Same behavior; the\n * decoder covers v8/v9/v10/v11/v12 detect heads. Will be removed in 0.3.0.\n */\nexport function decodeYoloV8(\n output: Float32Array,\n outputDims: readonly number[],\n options: DecodeYoloOptions,\n): DecodedDetection[] {\n if (!_warnedDecodeYoloV8) {\n _warnedDecodeYoloV8 = true;\n console.warn(\n \"[@ort-vision-sdk/web] decodeYoloV8 is deprecated since 0.2.0; use decodeYolo. \" +\n \"The alias will be removed in 0.3.0.\",\n );\n }\n return decodeYolo(output, outputDims, options);\n}\n\n/**\n * @deprecated since 0.2.0 — use {@link decodeYoloAnchors}. Will be removed in 0.3.0.\n */\nexport function decodeYoloV8Anchors(\n data: Float32Array,\n dims: readonly number[],\n options: DecodeYoloAnchorsOptions,\n): DecodedAnchors {\n if (!_warnedDecodeYoloV8Anchors) {\n _warnedDecodeYoloV8Anchors = true;\n console.warn(\n \"[@ort-vision-sdk/web] decodeYoloV8Anchors is deprecated since 0.2.0; use decodeYoloAnchors. \" +\n \"The alias will be removed in 0.3.0.\",\n );\n }\n return decodeYoloAnchors(data, dims, options);\n}\n\n/** @deprecated since 0.2.0 — use {@link DecodeYoloAnchorsOptions}. */\nexport type DecodeYoloV8AnchorsOptions = DecodeYoloAnchorsOptions;\n\n/** @deprecated since 0.2.0 — use {@link DecodeYoloOptions}. */\nexport type DecodeYoloV8Options = DecodeYoloOptions;\n"],"mappings":"gCA4BA,SAAgB,EAAI,EAAqB,EAAsB,EAAkC,CAC7F,IAAM,EAAI,EAAO,OACjB,GAAI,IAAM,EAAG,OAAO,IAAI,WAExB,IAAM,EAAQ,IAAI,aAAa,CAAC,EAChC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,CACxB,IAAM,EAAK,EAAM,EAAI,GACf,EAAK,EAAM,EAAI,EAAI,GAC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IAAM,EAAW,EAAW,SAAW,EAAI,EAAW,GAAK,EAAW,GACtE,GAAI,IAAa,IAAA,IAAa,EAAW,EACrC,MAAU,MAAM,4CAA4C,EAAS,kBAAkB,EAI3F,IAAM,EAAU,EAAkB,EAAQ,EAAY,CAClD,WAHe,EAAW,EAI1B,GAAG,CACP,CAAC,EAEK,EAA8B,CAAC,EACrC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,SAAS,OAAQ,IACzC,EAAQ,KAAK,CACT,KAAM,IAAI,EAAA,YACN,EAAQ,UAAU,EAAI,GACtB,EAAQ,UAAU,EAAI,EAAI,GAC1B,EAAQ,UAAU,EAAI,EAAI,GAC1B,EAAQ,UAAU,EAAI,EAAI,EAC9B,EACA,QAAS,EAAQ,SAAS,GAC1B,WAAY,EAAQ,YAAY,EACpC,CAAC,EAEL,OAAO,CACX,CAEA,IAAI,EAAsB,GACtB,EAA6B,GAMjC,SAAgB,EACZ,EACA,EACA,EACkB,CAQlB,OAPK,IACD,EAAsB,GACtB,QAAQ,KACJ,mHAEJ,GAEG,EAAW,EAAQ,EAAY,CAAO,CACjD,CAKA,SAAgB,EACZ,EACA,EACA,EACc,CAQd,OAPK,IACD,EAA6B,GAC7B,QAAQ,KACJ,iIAEJ,GAEG,EAAkB,EAAM,EAAM,CAAO,CAChD"}
|
|
1
|
+
{"version":3,"file":"detection.cjs","names":[],"sources":["../../../src/vision/postprocess/detection.ts"],"sourcesContent":["/**\n * Detection head postprocessing: anchor-free YOLO decoding + non-maximum suppression.\n *\n * The shared {@link decodeYoloAnchors} helper does the per-anchor work that\n * is identical for plain detection and segmentation (transpose, xywh→xyxy,\n * letterbox unmap, per-class NMS, sort & cap). {@link decodeYolo} is a thin\n * wrapper around it; the segmentation module ({@link ./segmentation.js})\n * calls the helper directly so it can also recover the per-anchor mask\n * coefficients.\n *\n * Works for any YOLO export with the post-v8 anchor-free head:\n * **YOLOv8 / v9 / v10 / v11 / v12** detect heads, all of which share the\n * `[1, 4 + nc, N]` output layout.\n */\n\nimport { BoundingBox } from \"../types\";\n\n/**\n * Greedy non-maximum suppression on axis-aligned bounding boxes.\n *\n * Mirrors `torchvision.ops.nms` (keeps boxes with the highest score, drops\n * any subsequent box whose IoU exceeds the threshold).\n *\n * @param boxes Flat array of length `4 * N` in xyxy order: `[x1,y1,x2,y2, ...]`.\n * @param scores Detection score per box, length `N`.\n * @param iouThreshold Boxes with IoU above this threshold relative to a kept box are suppressed.\n * @returns Indices of kept boxes, in descending score order.\n */\nexport function nms(boxes: Float32Array, scores: Float32Array, iouThreshold: number): Int32Array {\n const n = scores.length;\n if (n === 0) return new Int32Array(0);\n\n const areas = new Float32Array(n);\n for (let i = 0; i < n; i++) {\n const x1 = boxes[i * 4] as number;\n const y1 = boxes[i * 4 + 1] as number;\n const x2 = boxes[i * 4 + 2] as number;\n const y2 = boxes[i * 4 + 3] as number;\n areas[i] = Math.max(0, x2 - x1) * Math.max(0, y2 - y1);\n }\n\n const order = new Array<number>(n);\n for (let i = 0; i < n; i++) order[i] = i;\n order.sort((a, b) => (scores[b] as number) - (scores[a] as number));\n\n const suppressed = new Uint8Array(n);\n const keep: number[] = [];\n\n for (let oi = 0; oi < order.length; oi++) {\n const i = order[oi] as number;\n if (suppressed[i]) continue;\n keep.push(i);\n\n const ax1 = boxes[i * 4] as number;\n const ay1 = boxes[i * 4 + 1] as number;\n const ax2 = boxes[i * 4 + 2] as number;\n const ay2 = boxes[i * 4 + 3] as number;\n const ai = areas[i] as number;\n\n for (let oj = oi + 1; oj < order.length; oj++) {\n const j = order[oj] as number;\n if (suppressed[j]) continue;\n\n const bx1 = boxes[j * 4] as number;\n const by1 = boxes[j * 4 + 1] as number;\n const bx2 = boxes[j * 4 + 2] as number;\n const by2 = boxes[j * 4 + 3] as number;\n\n const ix1 = Math.max(ax1, bx1);\n const iy1 = Math.max(ay1, by1);\n const ix2 = Math.min(ax2, bx2);\n const iy2 = Math.min(ay2, by2);\n const iw = Math.max(0, ix2 - ix1);\n const ih = Math.max(0, iy2 - iy1);\n const inter = iw * ih;\n const union = ai + (areas[j] as number) - inter;\n const iou = union > 0 ? inter / union : 0;\n if (iou > iouThreshold) suppressed[j] = 1;\n }\n }\n\n return Int32Array.from(keep);\n}\n\n/**\n * Per-class NMS — boxes are suppressed only by other boxes of the same class.\n *\n * Mirrors `torchvision.ops.batched_nms`.\n *\n * @param boxes Flat array of length `4 * N` in xyxy order.\n * @param scores Detection score per box, length `N`.\n * @param idxs Class index per box, length `N`. Boxes with different `idxs`\n * never suppress each other.\n * @param iouThreshold IoU threshold for suppression within a class.\n */\nexport function batchedNms(\n boxes: Float32Array,\n scores: Float32Array,\n idxs: Int32Array,\n iouThreshold: number,\n): Int32Array {\n if (scores.length === 0) return new Int32Array(0);\n\n const byClass = new Map<number, number[]>();\n for (let i = 0; i < idxs.length; i++) {\n const c = idxs[i] as number;\n const list = byClass.get(c);\n if (list === undefined) byClass.set(c, [i]);\n else list.push(i);\n }\n\n const keep: number[] = [];\n for (const indices of byClass.values()) {\n const m = indices.length;\n const subBoxes = new Float32Array(m * 4);\n const subScores = new Float32Array(m);\n for (let k = 0; k < m; k++) {\n const i = indices[k] as number;\n subBoxes[k * 4] = boxes[i * 4] as number;\n subBoxes[k * 4 + 1] = boxes[i * 4 + 1] as number;\n subBoxes[k * 4 + 2] = boxes[i * 4 + 2] as number;\n subBoxes[k * 4 + 3] = boxes[i * 4 + 3] as number;\n subScores[k] = scores[i] as number;\n }\n const subKeep = nms(subBoxes, subScores, iouThreshold);\n for (let k = 0; k < subKeep.length; k++) {\n keep.push(indices[subKeep[k] as number] as number);\n }\n }\n\n keep.sort((a, b) => (scores[b] as number) - (scores[a] as number));\n return Int32Array.from(keep);\n}\n\nexport interface DecodeYoloAnchorsOptions {\n /** Number of class-score channels following the 4 box channels. */\n readonly numClasses: number;\n readonly originalWidth: number;\n readonly originalHeight: number;\n readonly padLeft: number;\n readonly padTop: number;\n readonly scale: number;\n readonly confThreshold: number;\n readonly iouThreshold: number;\n readonly maxDetections: number;\n}\n\nexport interface DecodedAnchors {\n /** Indices into the original `numAnchors` axis, in descending confidence order. */\n readonly anchorIndices: Int32Array;\n /** `[k, 4]` boxes in original-image pixel coords, flat row-major xyxy. */\n readonly boxesXyxy: Float32Array;\n /** Predicted class id per survivor. */\n readonly classIds: Int32Array;\n /** Confidence per survivor. */\n readonly confidences: Float32Array;\n}\n\n/**\n * Shared YOLO per-anchor decode used by both detection and segmentation\n * (v8 / v9 / v10 / v11 / v12).\n *\n * Only the first `4 + numClasses` channels are read; later channels (e.g.\n * mask coefficients) are ignored — callers can fetch them via the returned\n * {@link DecodedAnchors.anchorIndices}.\n *\n * @param data Flat per-anchor output, length `channels * numAnchors`.\n * @param dims Dims as reported by ORT, e.g. `[1, 84, 8400]` (det) or\n * `[1, 116, 8400]` (seg). The leading batch dim must be 1.\n */\nexport function decodeYoloAnchors(\n data: Float32Array,\n dims: readonly number[],\n options: DecodeYoloAnchorsOptions,\n): DecodedAnchors {\n let normalized = dims;\n if (normalized.length === 3) {\n if (normalized[0] !== 1) {\n throw new Error(`decodeYoloAnchors: expected batch size 1, got ${normalized[0]}.`);\n }\n normalized = [normalized[1] as number, normalized[2] as number];\n }\n if (normalized.length !== 2) {\n throw new Error(\n `decodeYoloAnchors: expected 2-D output after batch removal, got dims=${JSON.stringify(dims)}.`,\n );\n }\n const channels = normalized[0] as number;\n const numAnchors = normalized[1] as number;\n\n const {\n numClasses,\n originalWidth,\n originalHeight,\n padLeft,\n padTop,\n scale,\n confThreshold,\n iouThreshold,\n maxDetections,\n } = options;\n\n if (numClasses < 1 || numClasses + 4 > channels) {\n throw new Error(\n `decodeYoloAnchors: invalid numClasses=${numClasses} for channels=${channels}.`,\n );\n }\n if (data.length !== channels * numAnchors) {\n throw new Error(\n `decodeYoloAnchors: data length ${data.length} does not match channels*numAnchors=${channels * numAnchors}.`,\n );\n }\n\n type Candidate = {\n anchorIdx: number;\n x1: number;\n y1: number;\n x2: number;\n y2: number;\n classId: number;\n confidence: number;\n };\n const candidates: Candidate[] = [];\n\n for (let a = 0; a < numAnchors; a++) {\n let bestCls = 0;\n let bestScore = -Infinity;\n for (let c = 0; c < numClasses; c++) {\n const s = data[(4 + c) * numAnchors + a];\n if (s !== undefined && s > bestScore) {\n bestScore = s;\n bestCls = c;\n }\n }\n if (bestScore < confThreshold) continue;\n\n const cx = data[a] as number;\n const cy = data[numAnchors + a] as number;\n const w = data[2 * numAnchors + a] as number;\n const h = data[3 * numAnchors + a] as number;\n\n let x1 = cx - w / 2;\n let y1 = cy - h / 2;\n let x2 = cx + w / 2;\n let y2 = cy + h / 2;\n\n x1 = (x1 - padLeft) / scale;\n y1 = (y1 - padTop) / scale;\n x2 = (x2 - padLeft) / scale;\n y2 = (y2 - padTop) / scale;\n\n x1 = Math.max(0, Math.min(originalWidth, x1));\n y1 = Math.max(0, Math.min(originalHeight, y1));\n x2 = Math.max(0, Math.min(originalWidth, x2));\n y2 = Math.max(0, Math.min(originalHeight, y2));\n\n candidates.push({ anchorIdx: a, x1, y1, x2, y2, classId: bestCls, confidence: bestScore });\n }\n\n if (candidates.length === 0) return emptyDecoded();\n\n // Build flat arrays then delegate to batchedNms — same algorithm as before\n // but funnelled through the public per-class NMS helper.\n const flatBoxes = new Float32Array(candidates.length * 4);\n const scoresArr = new Float32Array(candidates.length);\n const idxsArr = new Int32Array(candidates.length);\n for (let i = 0; i < candidates.length; i++) {\n const c = candidates[i] as Candidate;\n flatBoxes[i * 4] = c.x1;\n flatBoxes[i * 4 + 1] = c.y1;\n flatBoxes[i * 4 + 2] = c.x2;\n flatBoxes[i * 4 + 3] = c.y2;\n scoresArr[i] = c.confidence;\n idxsArr[i] = c.classId;\n }\n const kept = batchedNms(flatBoxes, scoresArr, idxsArr, iouThreshold);\n if (kept.length === 0) return emptyDecoded();\n\n const limited = Array.from(kept).slice(0, maxDetections);\n const k = limited.length;\n const anchorIndices = new Int32Array(k);\n const boxesXyxy = new Float32Array(k * 4);\n const classIds = new Int32Array(k);\n const confidences = new Float32Array(k);\n for (let i = 0; i < k; i++) {\n const c = candidates[limited[i] as number] as Candidate;\n anchorIndices[i] = c.anchorIdx;\n boxesXyxy[i * 4] = c.x1;\n boxesXyxy[i * 4 + 1] = c.y1;\n boxesXyxy[i * 4 + 2] = c.x2;\n boxesXyxy[i * 4 + 3] = c.y2;\n classIds[i] = c.classId;\n confidences[i] = c.confidence;\n }\n return { anchorIndices, boxesXyxy, classIds, confidences };\n}\n\nfunction emptyDecoded(): DecodedAnchors {\n return {\n anchorIndices: new Int32Array(0),\n boxesXyxy: new Float32Array(0),\n classIds: new Int32Array(0),\n confidences: new Float32Array(0),\n };\n}\n\nexport interface DecodeYoloOptions {\n readonly originalWidth: number;\n readonly originalHeight: number;\n readonly padLeft: number;\n readonly padTop: number;\n readonly scale: number;\n readonly confThreshold: number;\n readonly iouThreshold: number;\n readonly maxDetections: number;\n}\n\nexport interface DecodedDetection {\n readonly bbox: BoundingBox;\n readonly classId: number;\n readonly confidence: number;\n}\n\n/**\n * Decode an anchor-free YOLO detection output into a list of detections.\n *\n * Works for **YOLOv8 / v9 / v10 / v11 / v12** detect heads.\n *\n * Expected raw shape: `[1, 4 + numClasses, N]`. `numClasses` is inferred\n * from the channel count.\n */\nexport function decodeYolo(\n output: Float32Array,\n outputDims: readonly number[],\n options: DecodeYoloOptions,\n): DecodedDetection[] {\n const channels = outputDims.length === 3 ? outputDims[1] : outputDims[0];\n if (channels === undefined || channels < 5) {\n throw new Error(`decodeYolo: invalid output channel count ${channels} (expected >= 5).`);\n }\n const numClasses = channels - 4;\n\n const decoded = decodeYoloAnchors(output, outputDims, {\n numClasses,\n ...options,\n });\n\n const results: DecodedDetection[] = [];\n for (let i = 0; i < decoded.classIds.length; i++) {\n results.push({\n bbox: new BoundingBox(\n decoded.boxesXyxy[i * 4] as number,\n decoded.boxesXyxy[i * 4 + 1] as number,\n decoded.boxesXyxy[i * 4 + 2] as number,\n decoded.boxesXyxy[i * 4 + 3] as number,\n ),\n classId: decoded.classIds[i] as number,\n confidence: decoded.confidences[i] as number,\n });\n }\n return results;\n}\n\nlet _warnedDecodeYoloV8 = false;\nlet _warnedDecodeYoloV8Anchors = false;\n\n/**\n * @deprecated since 0.2.0 — use {@link decodeYolo}. Same behavior; the\n * decoder covers v8/v9/v10/v11/v12 detect heads. Will be removed in 0.4.0.\n */\nexport function decodeYoloV8(\n output: Float32Array,\n outputDims: readonly number[],\n options: DecodeYoloOptions,\n): DecodedDetection[] {\n if (!_warnedDecodeYoloV8) {\n _warnedDecodeYoloV8 = true;\n console.warn(\n \"[@ort-vision-sdk/web] decodeYoloV8 is deprecated since 0.2.0; use decodeYolo. \" +\n \"The alias will be removed in 0.4.0.\",\n );\n }\n return decodeYolo(output, outputDims, options);\n}\n\n/**\n * @deprecated since 0.2.0 — use {@link decodeYoloAnchors}. Will be removed in 0.4.0.\n */\nexport function decodeYoloV8Anchors(\n data: Float32Array,\n dims: readonly number[],\n options: DecodeYoloAnchorsOptions,\n): DecodedAnchors {\n if (!_warnedDecodeYoloV8Anchors) {\n _warnedDecodeYoloV8Anchors = true;\n console.warn(\n \"[@ort-vision-sdk/web] decodeYoloV8Anchors is deprecated since 0.2.0; use decodeYoloAnchors. \" +\n \"The alias will be removed in 0.4.0.\",\n );\n }\n return decodeYoloAnchors(data, dims, options);\n}\n\n/** @deprecated since 0.2.0 — use {@link DecodeYoloAnchorsOptions}. */\nexport type DecodeYoloV8AnchorsOptions = DecodeYoloAnchorsOptions;\n\n/** @deprecated since 0.2.0 — use {@link DecodeYoloOptions}. */\nexport type DecodeYoloV8Options = DecodeYoloOptions;\n"],"mappings":"gCA4BA,SAAgB,EAAI,EAAqB,EAAsB,EAAkC,CAC7F,IAAM,EAAI,EAAO,OACjB,GAAI,IAAM,EAAG,OAAO,IAAI,WAExB,IAAM,EAAQ,IAAI,aAAa,CAAC,EAChC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,CACxB,IAAM,EAAK,EAAM,EAAI,GACf,EAA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,EACA,EACA,EACkB,CAClB,IAAM,EAAW,EAAW,SAAW,EAAI,EAAW,GAAK,EAAW,GACtE,GAAI,IAAa,IAAA,IAAa,EAAW,EACrC,MAAU,MAAM,4CAA4C,EAAS,kBAAkB,EAI3F,IAAM,EAAU,EAAkB,EAAQ,EAAY,CAClD,WAHe,EAAW,EAI1B,GAAG,CACP,CAAC,EAEK,EAA8B,CAAC,EACrC,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,SAAS,OAAQ,IACzC,EAAQ,KAAK,CACT,KAAM,IAAI,EAAA,YACN,EAAQ,UAAU,EAAI,GACtB,EAAQ,UAAU,EAAI,EAAI,GAC1B,EAAQ,UAAU,EAAI,EAAI,GAC1B,EAAQ,UAAU,EAAI,EAAI,EAC9B,EACA,QAAS,EAAQ,SAAS,GAC1B,WAAY,EAAQ,YAAY,EACpC,CAAC,EAEL,OAAO,CACX,CAEA,IAAI,EAAsB,GACtB,EAA6B,GAMjC,SAAgB,EACZ,EACA,EACA,EACkB,CAQlB,OAPK,IACD,EAAsB,GACtB,QAAQ,KACJ,mHAEJ,GAEG,EAAW,EAAQ,EAAY,CAAO,CACjD,CAKA,SAAgB,EACZ,EACA,EACA,EACc,CAQd,OAPK,IACD,EAA6B,GAC7B,QAAQ,KACJ,iIAEJ,GAEG,EAAkB,EAAM,EAAM,CAAO,CAChD"}
|
|
@@ -118,10 +118,10 @@ function a(t, n, i) {
|
|
|
118
118
|
}
|
|
119
119
|
var o = !1, s = !1;
|
|
120
120
|
function c(e, t, n) {
|
|
121
|
-
return o || (o = !0, console.warn("[@ort-vision-sdk/web] decodeYoloV8 is deprecated since 0.2.0; use decodeYolo. The alias will be removed in 0.
|
|
121
|
+
return o || (o = !0, console.warn("[@ort-vision-sdk/web] decodeYoloV8 is deprecated since 0.2.0; use decodeYolo. The alias will be removed in 0.4.0.")), a(e, t, n);
|
|
122
122
|
}
|
|
123
123
|
function l(e, t, n) {
|
|
124
|
-
return s || (s = !0, console.warn("[@ort-vision-sdk/web] decodeYoloV8Anchors is deprecated since 0.2.0; use decodeYoloAnchors. The alias will be removed in 0.
|
|
124
|
+
return s || (s = !0, console.warn("[@ort-vision-sdk/web] decodeYoloV8Anchors is deprecated since 0.2.0; use decodeYoloAnchors. The alias will be removed in 0.4.0.")), r(e, t, n);
|
|
125
125
|
}
|
|
126
126
|
//#endregion
|
|
127
127
|
export { n as batchedNms, a as decodeYolo, r as decodeYoloAnchors, c as decodeYoloV8, l as decodeYoloV8Anchors, t as nms };
|