tempest-react-sdk 0.36.0 → 0.37.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/dist/vision.d.ts CHANGED
@@ -196,6 +196,14 @@ export declare class Classifier extends VisionTask {
196
196
  get labels(): readonly string[];
197
197
  /** Class id → class name dict (matches Ultralytics' `model.names`). */
198
198
  get names(): Readonly<Record<number, string>>;
199
+ /**
200
+ * The `[width, height]` this task preprocesses to.
201
+ *
202
+ * Resolved at creation time from the model's graph when it declares a static
203
+ * input, so reading it back tells you the resolution inference really runs at
204
+ * — not merely what was requested.
205
+ */
206
+ get inputSize(): readonly [number, number];
199
207
  /** Number of classes the model can predict. */
200
208
  get numClasses(): number;
201
209
  /** Alias for {@link predict} (parity with PyTorch `nn.Module.__call__`). */
@@ -214,7 +222,13 @@ export declare interface ClassifierOptions extends OrtSessionOptions {
214
222
  * or when you want to validate that the supplied labels match the model.
215
223
  */
216
224
  readonly numClasses?: number;
217
- /** Model input `[width, height]` in pixels. Defaults to `[224, 224]`. */
225
+ /**
226
+ * Model input `[width, height]` in pixels.
227
+ *
228
+ * Only used when the model's graph leaves its spatial axes dynamic: a graph
229
+ * that declares a static size always wins, since that is the only shape ONNX
230
+ * Runtime will accept. Defaults to `[224, 224]`.
231
+ */
218
232
  readonly inputSize?: readonly [number, number];
219
233
  /** Per-channel RGB mean used for normalization. Defaults to ImageNet. */
220
234
  readonly mean?: readonly [number, number, number];
@@ -277,6 +291,26 @@ export declare const COCO_CLASSES: readonly string[];
277
291
  */
278
292
  export declare function computeImageLuminance(source: LuminanceSource, reusableCanvas?: HTMLCanvasElement): number;
279
293
 
294
+ /**
295
+ * One declared dimension: a number when the graph pins it, `null` when the
296
+ * dimension is symbolic (dynamic).
297
+ */
298
+ export declare type DeclaredDim = number | null;
299
+
300
+ /** A declared input/output shape, dynamic axes appearing as `null`. */
301
+ export declare type DeclaredShape = readonly DeclaredDim[];
302
+
303
+ /**
304
+ * Convert ORT value metadata into declared shapes.
305
+ *
306
+ * @param metadata Metadata as reported by `InferenceSession.inputMetadata`, or
307
+ * `undefined` on ORT builds that predate it (added in onnxruntime 1.21).
308
+ * @returns One shape per value, in declaration order. Non-tensor values and
309
+ * builds without metadata yield empty shapes, which read as "nothing
310
+ * declared" everywhere downstream.
311
+ */
312
+ export declare function declaredShapesFrom(metadata: readonly ort.InferenceSession.ValueMetadata[] | undefined): readonly DeclaredShape[];
313
+
280
314
  export declare interface DecodedAnchors {
281
315
  /** Indices into the original `numAnchors` axis, in descending confidence order. */
282
316
  readonly anchorIndices: Int32Array;
@@ -504,6 +538,14 @@ export declare class Detector extends VisionTask {
504
538
  get labels(): readonly string[];
505
539
  /** Class id → class name dict (matches Ultralytics' `model.names`). */
506
540
  get names(): Readonly<Record<number, string>>;
541
+ /**
542
+ * The `[width, height]` this task preprocesses to.
543
+ *
544
+ * Resolved at creation time from the model's graph when it declares a static
545
+ * input, so reading it back tells you the resolution inference really runs at
546
+ * — not merely what was requested.
547
+ */
548
+ get inputSize(): readonly [number, number];
507
549
  /** Number of classes the model predicts. */
508
550
  get numClasses(): number;
509
551
  /**
@@ -548,7 +590,13 @@ export declare interface DetectorOptions extends OrtSessionOptions {
548
590
  readonly labels?: LabelSpec;
549
591
  /** Number of classes — used to validate the supplied labels. */
550
592
  readonly numClasses?: number;
551
- /** Model input `[width, height]` for letterboxing. Defaults to `[640, 640]`. */
593
+ /**
594
+ * Model input `[width, height]` in pixels for letterboxing.
595
+ *
596
+ * Only used when the model's graph leaves its spatial axes dynamic: a graph
597
+ * that declares a static size always wins, since that is the only shape ONNX
598
+ * Runtime will accept. Defaults to `[640, 640]`.
599
+ */
552
600
  readonly inputSize?: readonly [number, number];
553
601
  /** Default minimum class score to keep a candidate. */
554
602
  readonly confThreshold?: number;
@@ -763,8 +811,9 @@ export declare interface LetterboxResult {
763
811
  /**
764
812
  * Wrap an ONNX Runtime Web `InferenceSession` with convenient metadata access.
765
813
  *
766
- * The wrapper exposes input/output names, manages execution-provider
767
- * selection, and provides a typed {@link OrtSession.run} method.
814
+ * The wrapper exposes input/output names and the shapes the graph declares,
815
+ * manages execution-provider selection, provides a typed {@link OrtSession.run}
816
+ * method, and releases the native session through {@link OrtSession.release}.
768
817
  */
769
818
  export declare class OrtSession {
770
819
  private readonly _session;
@@ -784,6 +833,29 @@ export declare interface LetterboxResult {
784
833
  get inputName(): string;
785
834
  /** Names of the model's outputs, in declaration order. */
786
835
  get outputNames(): readonly string[];
836
+ /**
837
+ * Shapes the graph declares for its inputs, in declaration order.
838
+ *
839
+ * Dynamic (symbolic) axes appear as `null`. Empty shapes mean the runtime
840
+ * reported no metadata — either a non-tensor input, or an `onnxruntime-web`
841
+ * older than 1.21, which predates input metadata.
842
+ */
843
+ get inputShapes(): readonly DeclaredShape[];
844
+ /**
845
+ * Shape the graph declares for its first input, dynamic axes as `null`.
846
+ *
847
+ * Empty when the runtime reports no metadata for it.
848
+ */
849
+ get inputShape(): DeclaredShape;
850
+ /**
851
+ * Release the native session and free its memory.
852
+ *
853
+ * Call it when a session is discarded while the page lives on — rebuilding a
854
+ * task at a different input size, swapping in a newer model. A failure from
855
+ * the runtime is ignored: a session being torn down has nothing left to fail
856
+ * at, and the caller is already moving on.
857
+ */
858
+ release(): Promise<void>;
787
859
  /** The underlying `onnxruntime-web` session, for advanced use cases. */
788
860
  get raw(): ort.InferenceSession;
789
861
  /**
@@ -843,6 +915,29 @@ export declare interface LetterboxResult {
843
915
  /** Resize an image to `(targetWidth, targetHeight)` using high-quality canvas resampling. */
844
916
  export declare function resize(image: RGBImage, targetWidth: number, targetHeight: number): RGBImage;
845
917
 
918
+ /**
919
+ * Decide the input size a task will preprocess to.
920
+ *
921
+ * Precedence is graph → caller → fallback. The graph wins over an explicit
922
+ * `inputSize` because a static shape is not a preference, it is what ORT will
923
+ * accept: honoring the caller there would only turn a fixable mismatch into a
924
+ * failed run. A disagreement is a configuration bug in the caller, so it is
925
+ * reported through `console.warn` instead of being swallowed.
926
+ *
927
+ * @param options Graph shape, requested size and per-task fallback.
928
+ * @returns The `[width, height]` to preprocess to.
929
+ */
930
+ export declare function resolveInputSize(options: ResolveInputSizeOptions): readonly [number, number];
931
+
932
+ export declare interface ResolveInputSizeOptions {
933
+ /** Declared shape of the model's image input, from {@link declaredShapesFrom}. */
934
+ readonly graphShape?: DeclaredShape;
935
+ /** Size the caller asked for, if any. */
936
+ readonly requested?: readonly [number, number];
937
+ /** Size to use when neither the graph nor the caller pins one. */
938
+ readonly fallback: readonly [number, number];
939
+ }
940
+
846
941
  /**
847
942
  * Resolve a labels specification into an ordered array of class names.
848
943
  *
@@ -991,6 +1086,14 @@ export declare interface LetterboxResult {
991
1086
  get labels(): readonly string[];
992
1087
  /** Class id → class name dict (matches Ultralytics' `model.names`). */
993
1088
  get names(): Readonly<Record<number, string>>;
1089
+ /**
1090
+ * The `[width, height]` this task preprocesses to.
1091
+ *
1092
+ * Resolved at creation time from the model's graph when it declares a static
1093
+ * input, so reading it back tells you the resolution inference really runs at
1094
+ * — not merely what was requested.
1095
+ */
1096
+ get inputSize(): readonly [number, number];
994
1097
  /** Number of classes the model predicts. */
995
1098
  get numClasses(): number;
996
1099
  /** Alias for {@link predict} (parity with PyTorch `nn.Module.__call__`). */
@@ -1026,7 +1129,13 @@ export declare interface LetterboxResult {
1026
1129
  readonly labels?: LabelSpec;
1027
1130
  /** Number of classes — used to validate the supplied labels. */
1028
1131
  readonly numClasses?: number;
1029
- /** Model input `[width, height]` for letterboxing. Defaults to `[640, 640]`. */
1132
+ /**
1133
+ * Model input `[width, height]` in pixels for letterboxing.
1134
+ *
1135
+ * Only used when the model's graph leaves its spatial axes dynamic: a graph
1136
+ * that declares a static size always wins, since that is the only shape ONNX
1137
+ * Runtime will accept. Defaults to `[640, 640]`.
1138
+ */
1030
1139
  readonly inputSize?: readonly [number, number];
1031
1140
  /** Default minimum class score to keep a candidate. */
1032
1141
  readonly confThreshold?: number;
@@ -1054,6 +1163,16 @@ export declare interface LetterboxResult {
1054
1163
  /** Apply numerically-stable softmax to a 1-D vector of logits. */
1055
1164
  export declare function softmax(logits: Float32Array | readonly number[]): Float32Array;
1056
1165
 
1166
+ /**
1167
+ * Read the spatial input size out of a declared NCHW shape.
1168
+ *
1169
+ * @param shape The declared shape of the model's image input.
1170
+ * @returns `[width, height]` in pixels, or `null` when the shape is not 4D or
1171
+ * leaves either spatial axis dynamic — in which case the model accepts more
1172
+ * than one resolution and there is nothing to correct.
1173
+ */
1174
+ export declare function spatialInputSize(shape: DeclaredShape): readonly [number, number] | null;
1175
+
1057
1176
  /**
1058
1177
  * Per-stage timing for a single `predict()` call.
1059
1178
  *
package/dist/vision.js CHANGED
@@ -4,18 +4,19 @@ import { BoundingBox as s, Mask as c, RGBImage as l } from "./vision/types.js";
4
4
  import { SpeedTimer as u } from "./vision/core/timing.js";
5
5
  import { Boxes as d, ClassificationResults as f, DetectionResults as p, Masks as m, Probs as h, SegmentationResults as g } from "./vision/results.js";
6
6
  import { COCO_CLASSES as _, resolveLabels as v } from "./vision/labels.js";
7
- import { DEFAULT_PROVIDERS as y, resolveProviders as b } from "./vision/core/providers.js";
8
- import { OrtSession as x } from "./vision/core/session.js";
9
- import { loadImage as S } from "./vision/io/image.js";
10
- import { fromCv2 as C, letterbox as w, normalize as T, resize as E, toCHW as D, toCv2 as O, toFloat32 as k, toFloat32Tensor as A, toTensor as j } from "./vision/preprocess/image.js";
11
- import { softmax as M, topK as N } from "./vision/postprocess/classification.js";
12
- import { batchedNms as P, decodeYolo as F, decodeYoloAnchors as I, decodeYoloV8 as L, decodeYoloV8Anchors as R, nms as z } from "./vision/postprocess/detection.js";
13
- import { decodeYoloSeg as B, decodeYoloV8Seg as V } from "./vision/postprocess/segmentation.js";
14
- import { VisionTask as H } from "./vision/tasks/base.js";
15
- import { Classifier as U } from "./vision/tasks/classifier.js";
16
- import { Detector as W } from "./vision/tasks/detector.js";
17
- import { Segmenter as G } from "./vision/tasks/segmenter.js";
18
- import { VERSION as K } from "./vision/index.js";
19
- import { LUMINANCE_SAMPLE_MAX_EDGE as q, LowLuminanceError as J, computeImageLuminance as Y, isLuminanceAcceptable as X } from "./vision/luminance.js";
20
- import { useLiveLuminance as Z } from "./vision/use-live-luminance.js";
21
- export { s as BoundingBox, d as Boxes, _ as COCO_CLASSES, f as ClassificationResults, U as Classifier, y as DEFAULT_PROVIDERS, p as DetectionResults, W as Detector, t as ImageLoadError, n as InferenceError, q as LUMINANCE_SAMPLE_MAX_EDGE, r as LabelMapError, J as LowLuminanceError, c as Mask, m as Masks, i as ModelLoadError, x as OrtSession, a as OrtVisionError, h as Probs, o as ProviderNotAvailableError, l as RGBImage, g as SegmentationResults, G as Segmenter, u as SpeedTimer, K as VERSION, H as VisionTask, P as batchedNms, Y as computeImageLuminance, F as decodeYolo, I as decodeYoloAnchors, B as decodeYoloSeg, L as decodeYoloV8, R as decodeYoloV8Anchors, V as decodeYoloV8Seg, C as fromCv2, X as isLuminanceAcceptable, w as letterbox, S as loadImage, z as nms, T as normalize, E as resize, v as resolveLabels, b as resolveProviders, M as softmax, D as toCHW, O as toCv2, k as toFloat32, A as toFloat32Tensor, j as toTensor, N as topK, e as useCameraStream, Z as useLiveLuminance };
7
+ import { declaredShapesFrom as y, resolveInputSize as b, spatialInputSize as x } from "./vision/core/graph.js";
8
+ import { DEFAULT_PROVIDERS as S, resolveProviders as C } from "./vision/core/providers.js";
9
+ import { OrtSession as w } from "./vision/core/session.js";
10
+ import { loadImage as T } from "./vision/io/image.js";
11
+ import { fromCv2 as E, letterbox as D, normalize as O, resize as k, toCHW as A, toCv2 as j, toFloat32 as M, toFloat32Tensor as N, toTensor as P } from "./vision/preprocess/image.js";
12
+ import { softmax as F, topK as I } from "./vision/postprocess/classification.js";
13
+ import { batchedNms as L, decodeYolo as R, decodeYoloAnchors as z, decodeYoloV8 as B, decodeYoloV8Anchors as V, nms as H } from "./vision/postprocess/detection.js";
14
+ import { decodeYoloSeg as U, decodeYoloV8Seg as W } from "./vision/postprocess/segmentation.js";
15
+ import { VisionTask as G } from "./vision/tasks/base.js";
16
+ import { Classifier as K } from "./vision/tasks/classifier.js";
17
+ import { Detector as q } from "./vision/tasks/detector.js";
18
+ import { Segmenter as J } from "./vision/tasks/segmenter.js";
19
+ import { VERSION as Y } from "./vision/index.js";
20
+ import { LUMINANCE_SAMPLE_MAX_EDGE as X, LowLuminanceError as Z, computeImageLuminance as Q, isLuminanceAcceptable as $ } from "./vision/luminance.js";
21
+ import { useLiveLuminance as ee } from "./vision/use-live-luminance.js";
22
+ export { s as BoundingBox, d as Boxes, _ as COCO_CLASSES, f as ClassificationResults, K as Classifier, S as DEFAULT_PROVIDERS, p as DetectionResults, q as Detector, t as ImageLoadError, n as InferenceError, X as LUMINANCE_SAMPLE_MAX_EDGE, r as LabelMapError, Z as LowLuminanceError, c as Mask, m as Masks, i as ModelLoadError, w as OrtSession, a as OrtVisionError, h as Probs, o as ProviderNotAvailableError, l as RGBImage, g as SegmentationResults, J as Segmenter, u as SpeedTimer, Y as VERSION, G as VisionTask, L as batchedNms, Q as computeImageLuminance, y as declaredShapesFrom, R as decodeYolo, z as decodeYoloAnchors, U as decodeYoloSeg, B as decodeYoloV8, V as decodeYoloV8Anchors, W as decodeYoloV8Seg, E as fromCv2, $ as isLuminanceAcceptable, D as letterbox, T as loadImage, H as nms, O as normalize, k as resize, b as resolveInputSize, v as resolveLabels, C as resolveProviders, F as softmax, x as spatialInputSize, A as toCHW, j as toCv2, M as toFloat32, N as toFloat32Tensor, P as toTensor, I as topK, e as useCameraStream, ee as useLiveLuminance };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tempest-react-sdk",
3
- "version": "0.36.0",
3
+ "version": "0.37.0",
4
4
  "description": "SDK público da Tempest com componentes, hooks e integrações para projetos React.",
5
5
  "type": "module",
6
6
  "license": "MIT",