@ohos-ports/sillytavern-transformers 2.17.2-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +361 -0
  3. package/dist/ort-wasm-simd-threaded.wasm +0 -0
  4. package/dist/ort-wasm-simd.wasm +0 -0
  5. package/dist/ort-wasm-threaded.wasm +0 -0
  6. package/dist/ort-wasm.wasm +0 -0
  7. package/dist/transformers.js +26758 -0
  8. package/dist/transformers.js.map +1 -0
  9. package/dist/transformers.min.js +107 -0
  10. package/dist/transformers.min.js.map +1 -0
  11. package/package.json +85 -0
  12. package/src/backends/onnx.js +50 -0
  13. package/src/configs.js +107 -0
  14. package/src/env.js +128 -0
  15. package/src/models.js +6267 -0
  16. package/src/pipelines.js +3287 -0
  17. package/src/processors.js +2248 -0
  18. package/src/tokenizers.js +4479 -0
  19. package/src/transformers.js +24 -0
  20. package/src/utils/audio.js +672 -0
  21. package/src/utils/core.js +175 -0
  22. package/src/utils/data-structures.js +415 -0
  23. package/src/utils/generation.js +873 -0
  24. package/src/utils/hub.js +658 -0
  25. package/src/utils/image.js +731 -0
  26. package/src/utils/maths.js +985 -0
  27. package/src/utils/tensor.js +1250 -0
  28. package/types/backends/onnx.d.ts +5 -0
  29. package/types/backends/onnx.d.ts.map +1 -0
  30. package/types/configs.d.ts +43 -0
  31. package/types/configs.d.ts.map +1 -0
  32. package/types/env.d.ts +28 -0
  33. package/types/env.d.ts.map +1 -0
  34. package/types/models.d.ts +3661 -0
  35. package/types/models.d.ts.map +1 -0
  36. package/types/pipelines.d.ts +2427 -0
  37. package/types/pipelines.d.ts.map +1 -0
  38. package/types/processors.d.ts +769 -0
  39. package/types/processors.d.ts.map +1 -0
  40. package/types/tokenizers.d.ts +932 -0
  41. package/types/tokenizers.d.ts.map +1 -0
  42. package/types/transformers.d.ts +11 -0
  43. package/types/transformers.d.ts.map +1 -0
  44. package/types/utils/audio.d.ts +121 -0
  45. package/types/utils/audio.d.ts.map +1 -0
  46. package/types/utils/core.d.ts +99 -0
  47. package/types/utils/core.d.ts.map +1 -0
  48. package/types/utils/data-structures.d.ts +224 -0
  49. package/types/utils/data-structures.d.ts.map +1 -0
  50. package/types/utils/generation.d.ts +593 -0
  51. package/types/utils/generation.d.ts.map +1 -0
  52. package/types/utils/hub.d.ts +154 -0
  53. package/types/utils/hub.d.ts.map +1 -0
  54. package/types/utils/image.d.ts +113 -0
  55. package/types/utils/image.d.ts.map +1 -0
  56. package/types/utils/maths.d.ts +280 -0
  57. package/types/utils/maths.d.ts.map +1 -0
  58. package/types/utils/tensor.d.ts +318 -0
  59. package/types/utils/tensor.d.ts.map +1 -0
@@ -0,0 +1,769 @@
1
+ declare const FeatureExtractor_base: new () => {
2
+ (...args: any[]): any;
3
+ _call(...args: any[]): any;
4
+ };
5
+ /**
6
+ * Base class for feature extractors.
7
+ *
8
+ * @extends Callable
9
+ */
10
+ export class FeatureExtractor extends FeatureExtractor_base {
11
+ /**
12
+ * Constructs a new FeatureExtractor instance.
13
+ *
14
+ * @param {Object} config The configuration for the feature extractor.
15
+ */
16
+ constructor(config: any);
17
+ config: any;
18
+ }
19
+ /**
20
+ * @typedef {object} ImageFeatureExtractorResult
21
+ * @property {Tensor} pixel_values The pixel values of the batched preprocessed images.
22
+ * @property {HeightWidth[]} original_sizes Array of two-dimensional tuples like [[480, 640]].
23
+ * @property {HeightWidth[]} reshaped_input_sizes Array of two-dimensional tuples like [[1000, 1330]].
24
+ */
25
+ /**
26
+ * Feature extractor for image models.
27
+ *
28
+ * @extends FeatureExtractor
29
+ */
30
+ export class ImageFeatureExtractor extends FeatureExtractor {
31
+ /**
32
+ * Constructs a new ImageFeatureExtractor instance.
33
+ *
34
+ * @param {Object} config The configuration for the feature extractor.
35
+ * @param {number[]} config.image_mean The mean values for image normalization.
36
+ * @param {number[]} config.image_std The standard deviation values for image normalization.
37
+ * @param {boolean} config.do_rescale Whether to rescale the image pixel values to the [0,1] range.
38
+ * @param {number} config.rescale_factor The factor to use for rescaling the image pixel values.
39
+ * @param {boolean} config.do_normalize Whether to normalize the image pixel values.
40
+ * @param {boolean} config.do_resize Whether to resize the image.
41
+ * @param {number} config.resample What method to use for resampling.
42
+ * @param {number|Object} config.size The size to resize the image to.
43
+ * @param {boolean} [config.do_flip_channel_order=false] Whether to flip the color channels from RGB to BGR.
44
+ * Can be overridden by the `do_flip_channel_order` parameter in the `preprocess` method.
45
+ */
46
+ constructor(config: {
47
+ image_mean: number[];
48
+ image_std: number[];
49
+ do_rescale: boolean;
50
+ rescale_factor: number;
51
+ do_normalize: boolean;
52
+ do_resize: boolean;
53
+ resample: number;
54
+ size: number | any;
55
+ do_flip_channel_order?: boolean;
56
+ });
57
+ image_mean: any;
58
+ image_std: any;
59
+ resample: any;
60
+ do_rescale: any;
61
+ rescale_factor: any;
62
+ do_normalize: any;
63
+ do_resize: any;
64
+ do_thumbnail: any;
65
+ size: any;
66
+ size_divisibility: any;
67
+ do_center_crop: any;
68
+ crop_size: any;
69
+ do_convert_rgb: any;
70
+ do_crop_margin: any;
71
+ pad_size: any;
72
+ do_pad: any;
73
+ do_flip_channel_order: any;
74
+ /**
75
+ * Resize the image to make a thumbnail. The image is resized so that no dimension is larger than any
76
+ * corresponding dimension of the specified size.
77
+ * @param {RawImage} image The image to be resized.
78
+ * @param {{height:number, width:number}} size The size `{"height": h, "width": w}` to resize the image to.
79
+ * @param {string | 0 | 1 | 2 | 3 | 4 | 5} [resample=2] The resampling filter to use.
80
+ * @returns {Promise<RawImage>} The resized image.
81
+ */
82
+ thumbnail(image: RawImage, size: {
83
+ height: number;
84
+ width: number;
85
+ }, resample?: string | 0 | 1 | 2 | 3 | 4 | 5): Promise<RawImage>;
86
+ /**
87
+ * Crops the margin of the image. Gray pixels are considered margin (i.e., pixels with a value below the threshold).
88
+ * @param {RawImage} image The image to be cropped.
89
+ * @param {number} gray_threshold Value below which pixels are considered to be gray.
90
+ * @returns {Promise<RawImage>} The cropped image.
91
+ */
92
+ crop_margin(image: RawImage, gray_threshold?: number): Promise<RawImage>;
93
+ /**
94
+ * Pad the image by a certain amount.
95
+ * @param {Float32Array} pixelData The pixel data to pad.
96
+ * @param {number[]} imgDims The dimensions of the image (height, width, channels).
97
+ * @param {{width:number; height:number}|number} padSize The dimensions of the padded image.
98
+ * @param {Object} options The options for padding.
99
+ * @param {'constant'|'symmetric'} [options.mode='constant'] The type of padding to add.
100
+ * @param {boolean} [options.center=false] Whether to center the image.
101
+ * @param {number} [options.constant_values=0] The constant value to use for padding.
102
+ * @returns {[Float32Array, number[]]} The padded pixel data and image dimensions.
103
+ */
104
+ pad_image(pixelData: Float32Array, imgDims: number[], padSize: {
105
+ width: number;
106
+ height: number;
107
+ } | number, { mode, center, constant_values, }?: {
108
+ mode?: 'constant' | 'symmetric';
109
+ center?: boolean;
110
+ constant_values?: number;
111
+ }): [Float32Array, number[]];
112
+ /**
113
+ * Rescale the image' pixel values by `this.rescale_factor`.
114
+ * @param {Float32Array} pixelData The pixel data to rescale.
115
+ * @returns {void}
116
+ */
117
+ rescale(pixelData: Float32Array): void;
118
+ /**
119
+ * Find the target (width, height) dimension of the output image after
120
+ * resizing given the input image and the desired size.
121
+ * @param {RawImage} image The image to resize.
122
+ * @param {any} size The size to use for resizing the image.
123
+ * @returns {[number, number]} The target (width, height) dimension of the output image after resizing.
124
+ */
125
+ get_resize_output_image_size(image: RawImage, size: any): [number, number];
126
+ /**
127
+ * Resizes the image.
128
+ * @param {RawImage} image The image to resize.
129
+ * @returns {Promise<RawImage>} The resized image.
130
+ */
131
+ resize(image: RawImage): Promise<RawImage>;
132
+ /**
133
+ * @typedef {object} PreprocessedImage
134
+ * @property {HeightWidth} original_size The original size of the image.
135
+ * @property {HeightWidth} reshaped_input_size The reshaped input size of the image.
136
+ * @property {Tensor} pixel_values The pixel values of the preprocessed image.
137
+ */
138
+ /**
139
+ * Preprocesses the given image.
140
+ *
141
+ * @param {RawImage} image The image to preprocess.
142
+ * @param {Object} overrides The overrides for the preprocessing options.
143
+ * @returns {Promise<PreprocessedImage>} The preprocessed image.
144
+ */
145
+ preprocess(image: RawImage, { do_normalize, do_pad, do_convert_rgb, do_convert_grayscale, do_flip_channel_order, }?: any): Promise<{
146
+ /**
147
+ * The original size of the image.
148
+ */
149
+ original_size: HeightWidth;
150
+ /**
151
+ * The reshaped input size of the image.
152
+ */
153
+ reshaped_input_size: HeightWidth;
154
+ /**
155
+ * The pixel values of the preprocessed image.
156
+ */
157
+ pixel_values: Tensor;
158
+ }>;
159
+ /**
160
+ * Calls the feature extraction process on an array of images,
161
+ * preprocesses each image, and concatenates the resulting
162
+ * features into a single Tensor.
163
+ * @param {RawImage[]} images The image(s) to extract features from.
164
+ * @param {...any} args Additional arguments.
165
+ * @returns {Promise<ImageFeatureExtractorResult>} An object containing the concatenated pixel values (and other metadata) of the preprocessed images.
166
+ */
167
+ _call(images: RawImage[], ...args: any[]): Promise<ImageFeatureExtractorResult>;
168
+ }
169
+ export class SegformerFeatureExtractor extends ImageFeatureExtractor {
170
+ /**
171
+ * Converts the output of `SegformerForSemanticSegmentation` into semantic segmentation maps.
172
+ * @param {*} outputs Raw outputs of the model.
173
+ * @param {number[][]} [target_sizes=null] List of tuples corresponding to the requested final size
174
+ * (height, width) of each prediction. If unset, predictions will not be resized.
175
+ * @returns {{segmentation: Tensor; labels: number[]}[]} The semantic segmentation maps.
176
+ */
177
+ post_process_semantic_segmentation(outputs: any, target_sizes?: number[][]): {
178
+ segmentation: Tensor;
179
+ labels: number[];
180
+ }[];
181
+ }
182
+ export class DPTFeatureExtractor extends ImageFeatureExtractor {
183
+ }
184
+ export class DPTImageProcessor extends DPTFeatureExtractor {
185
+ }
186
+ export class BitImageProcessor extends ImageFeatureExtractor {
187
+ }
188
+ export class GLPNFeatureExtractor extends ImageFeatureExtractor {
189
+ }
190
+ export class CLIPFeatureExtractor extends ImageFeatureExtractor {
191
+ }
192
+ export class ChineseCLIPFeatureExtractor extends ImageFeatureExtractor {
193
+ }
194
+ export class SiglipImageProcessor extends ImageFeatureExtractor {
195
+ }
196
+ export class ConvNextFeatureExtractor extends ImageFeatureExtractor {
197
+ constructor(config: any);
198
+ /**
199
+ * Percentage of the image to crop. Only has an effect if this.size < 384.
200
+ */
201
+ crop_pct: any;
202
+ resize(image: any): Promise<any>;
203
+ }
204
+ export class ConvNextImageProcessor extends ConvNextFeatureExtractor {
205
+ }
206
+ export class ViTFeatureExtractor extends ImageFeatureExtractor {
207
+ }
208
+ export class ViTImageProcessor extends ImageFeatureExtractor {
209
+ }
210
+ export class EfficientNetImageProcessor extends ImageFeatureExtractor {
211
+ constructor(config: any);
212
+ include_top: any;
213
+ }
214
+ export class MobileViTFeatureExtractor extends ImageFeatureExtractor {
215
+ }
216
+ export class MobileViTImageProcessor extends MobileViTFeatureExtractor {
217
+ }
218
+ export class OwlViTFeatureExtractor extends ImageFeatureExtractor {
219
+ /**
220
+ * Post-processes the outputs of the model (for object detection).
221
+ * @param {Object} outputs The outputs of the model that must be post-processed
222
+ * @param {Tensor} outputs.logits The logits
223
+ * @param {Tensor} outputs.pred_boxes The predicted boxes.
224
+ * @param {number} [threshold=0.5] The threshold to use for the scores.
225
+ * @param {number[][]} [target_sizes=null] The sizes of the original images.
226
+ * @param {boolean} [is_zero_shot=false] Whether zero-shot object detection was performed.
227
+ * @return {Object[]} An array of objects containing the post-processed outputs.
228
+ * @private
229
+ */
230
+ post_process_object_detection(outputs: {
231
+ logits: Tensor;
232
+ pred_boxes: Tensor;
233
+ }, threshold?: number, target_sizes?: number[][], is_zero_shot?: boolean): any[];
234
+ }
235
+ export class Owlv2ImageProcessor extends OwlViTFeatureExtractor {
236
+ }
237
+ export class DeiTFeatureExtractor extends ImageFeatureExtractor {
238
+ }
239
+ export class BeitFeatureExtractor extends ImageFeatureExtractor {
240
+ }
241
+ export class DonutFeatureExtractor extends ImageFeatureExtractor {
242
+ pad_image(pixelData: any, imgDims: any, padSize: any, options?: {}): [Float32Array, number[]];
243
+ }
244
+ export class NougatImageProcessor extends DonutFeatureExtractor {
245
+ }
246
+ /**
247
+ * @typedef {object} DetrFeatureExtractorResultProps
248
+ * @property {Tensor} pixel_mask
249
+ * @typedef {ImageFeatureExtractorResult & DetrFeatureExtractorResultProps} DetrFeatureExtractorResult
250
+ */
251
+ /**
252
+ * Detr Feature Extractor.
253
+ *
254
+ * @extends ImageFeatureExtractor
255
+ */
256
+ export class DetrFeatureExtractor extends ImageFeatureExtractor {
257
+ /**
258
+ * Calls the feature extraction process on an array of images, preprocesses
259
+ * each image, and concatenates the resulting features into a single Tensor.
260
+ * @param {RawImage[]} images The image(s) to extract features from.
261
+ * @returns {Promise<DetrFeatureExtractorResult>} An object containing the concatenated pixel values of the preprocessed images.
262
+ */
263
+ _call(images: RawImage[]): Promise<DetrFeatureExtractorResult>;
264
+ /**
265
+ * Post-processes the outputs of the model (for object detection).
266
+ * @param {Object} outputs The outputs of the model that must be post-processed
267
+ * @param {Tensor} outputs.logits The logits
268
+ * @param {Tensor} outputs.pred_boxes The predicted boxes.
269
+ * @param {number} [threshold=0.5] The threshold to use for the scores.
270
+ * @param {number[][]} [target_sizes=null] The sizes of the original images.
271
+ * @param {boolean} [is_zero_shot=false] Whether zero-shot object detection was performed.
272
+ * @return {Object[]} An array of objects containing the post-processed outputs.
273
+ * @private
274
+ */
275
+ post_process_object_detection(outputs: {
276
+ logits: Tensor;
277
+ pred_boxes: Tensor;
278
+ }, threshold?: number, target_sizes?: number[][], is_zero_shot?: boolean): any[];
279
+ /**
280
+ * Binarize the given masks using `object_mask_threshold`, it returns the associated values of `masks`, `scores` and `labels`.
281
+ * @param {Tensor} class_logits The class logits.
282
+ * @param {Tensor} mask_logits The mask logits.
283
+ * @param {number} object_mask_threshold A number between 0 and 1 used to binarize the masks.
284
+ * @param {number} num_labels The number of labels.
285
+ * @returns {[Tensor[], number[], number[]]} The binarized masks, the scores, and the labels.
286
+ */
287
+ remove_low_and_no_objects(class_logits: Tensor, mask_logits: Tensor, object_mask_threshold: number, num_labels: number): [Tensor[], number[], number[]];
288
+ /**
289
+ * Checks whether the segment is valid or not.
290
+ * @param {Int32Array} mask_labels Labels for each pixel in the mask.
291
+ * @param {Tensor[]} mask_probs Probabilities for each pixel in the masks.
292
+ * @param {number} k The class id of the segment.
293
+ * @param {number} mask_threshold The mask threshold.
294
+ * @param {number} overlap_mask_area_threshold The overlap mask area threshold.
295
+ * @returns {[boolean, number[]]} Whether the segment is valid or not, and the indices of the valid labels.
296
+ */
297
+ check_segment_validity(mask_labels: Int32Array, mask_probs: Tensor[], k: number, mask_threshold?: number, overlap_mask_area_threshold?: number): [boolean, number[]];
298
+ /**
299
+ * Computes the segments.
300
+ * @param {Tensor[]} mask_probs The mask probabilities.
301
+ * @param {number[]} pred_scores The predicted scores.
302
+ * @param {number[]} pred_labels The predicted labels.
303
+ * @param {number} mask_threshold The mask threshold.
304
+ * @param {number} overlap_mask_area_threshold The overlap mask area threshold.
305
+ * @param {Set<number>} label_ids_to_fuse The label ids to fuse.
306
+ * @param {number[]} target_size The target size of the image.
307
+ * @returns {[Tensor, Array<{id: number, label_id: number, score: number}>]} The computed segments.
308
+ */
309
+ compute_segments(mask_probs: Tensor[], pred_scores: number[], pred_labels: number[], mask_threshold: number, overlap_mask_area_threshold: number, label_ids_to_fuse?: Set<number>, target_size?: number[]): [Tensor, Array<{
310
+ id: number;
311
+ label_id: number;
312
+ score: number;
313
+ }>];
314
+ /**
315
+ * Post-process the model output to generate the final panoptic segmentation.
316
+ * @param {*} outputs The model output to post process
317
+ * @param {number} [threshold=0.5] The probability score threshold to keep predicted instance masks.
318
+ * @param {number} [mask_threshold=0.5] Threshold to use when turning the predicted masks into binary values.
319
+ * @param {number} [overlap_mask_area_threshold=0.8] The overlap mask area threshold to merge or discard small disconnected parts within each binary instance mask.
320
+ * @param {Set<number>} [label_ids_to_fuse=null] The labels in this state will have all their instances be fused together.
321
+ * @param {number[][]} [target_sizes=null] The target sizes to resize the masks to.
322
+ * @returns {Array<{ segmentation: Tensor, segments_info: Array<{id: number, label_id: number, score: number}>}>}
323
+ */
324
+ post_process_panoptic_segmentation(outputs: any, threshold?: number, mask_threshold?: number, overlap_mask_area_threshold?: number, label_ids_to_fuse?: Set<number>, target_sizes?: number[][]): Array<{
325
+ segmentation: Tensor;
326
+ segments_info: Array<{
327
+ id: number;
328
+ label_id: number;
329
+ score: number;
330
+ }>;
331
+ }>;
332
+ post_process_instance_segmentation(): void;
333
+ }
334
+ export class YolosFeatureExtractor extends ImageFeatureExtractor {
335
+ /**
336
+ * Post-processes the outputs of the model (for object detection).
337
+ * @param {Object} outputs The outputs of the model that must be post-processed
338
+ * @param {Tensor} outputs.logits The logits
339
+ * @param {Tensor} outputs.pred_boxes The predicted boxes.
340
+ * @param {number} [threshold=0.5] The threshold to use for the scores.
341
+ * @param {number[][]} [target_sizes=null] The sizes of the original images.
342
+ * @param {boolean} [is_zero_shot=false] Whether zero-shot object detection was performed.
343
+ * @return {Object[]} An array of objects containing the post-processed outputs.
344
+ * @private
345
+ */
346
+ post_process_object_detection(outputs: {
347
+ logits: Tensor;
348
+ pred_boxes: Tensor;
349
+ }, threshold?: number, target_sizes?: number[][], is_zero_shot?: boolean): any[];
350
+ }
351
+ /**
352
+ * @typedef {object} SamImageProcessorResult
353
+ * @property {Tensor} pixel_values
354
+ * @property {HeightWidth[]} original_sizes
355
+ * @property {HeightWidth[]} reshaped_input_sizes
356
+ * @property {Tensor} [input_points]
357
+ * @property {Tensor} [input_labels]
358
+ */
359
+ export class SamImageProcessor extends ImageFeatureExtractor {
360
+ /**
361
+ *
362
+ * @param {any} input_points
363
+ * @param {HeightWidth[]} original_sizes
364
+ * @param {HeightWidth[]} reshaped_input_sizes
365
+ * @returns {Tensor}
366
+ */
367
+ reshape_input_points(input_points: any, original_sizes: HeightWidth[], reshaped_input_sizes: HeightWidth[]): Tensor;
368
+ /**
369
+ *
370
+ * @param {any} input_labels
371
+ * @param {Tensor} input_points
372
+ * @returns {Tensor}
373
+ */
374
+ add_input_labels(input_labels: any, input_points: Tensor): Tensor;
375
+ /**
376
+ * @param {any[]} images The URL(s) of the image(s) to extract features from.
377
+ * @param {any} [input_points] A 3D or 4D array, representing the input points provided by the user.
378
+ * - 3D: `[point_batch_size, nb_points_per_image, 2]`. In this case, `batch_size` is assumed to be 1.
379
+ * - 4D: `[batch_size, point_batch_size, nb_points_per_image, 2]`.
380
+ * @param {any} [input_labels] A 2D or 3D array, representing the input labels for the points, used by the prompt encoder to encode the prompt.
381
+ * - 2D: `[point_batch_size, nb_points_per_image]`. In this case, `batch_size` is assumed to be 1.
382
+ * - 3D: `[batch_size, point_batch_size, nb_points_per_image]`.
383
+ * @returns {Promise<SamImageProcessorResult>}
384
+ */
385
+ _call(images: any[], input_points?: any, input_labels?: any): Promise<SamImageProcessorResult>;
386
+ /**
387
+ * Remove padding and upscale masks to the original image size.
388
+ * @param {Tensor} masks Batched masks from the mask_decoder in (batch_size, num_channels, height, width) format.
389
+ * @param {number[][]} original_sizes The original sizes of each image before it was resized to the model's expected input shape, in (height, width) format.
390
+ * @param {number[][]} reshaped_input_sizes The size of each image as it is fed to the model, in (height, width) format. Used to remove padding.
391
+ * @param {Object} options Optional parameters for post-processing.
392
+ * @param {number} [options.mask_threshold] The threshold to use for binarizing the masks.
393
+ * @param {boolean} [options.binarize] Whether to binarize the masks.
394
+ * @param {Object} [options.pad_size] The target size the images were padded to before being passed to the model. If `null`, the target size is assumed to be the processor's `pad_size`.
395
+ * @param {number} [options.pad_size.height] The height the images were padded to.
396
+ * @param {number} [options.pad_size.width] The width the images were padded to.
397
+ * @returns {Tensor[]} Batched masks in batch_size, num_channels, height, width) format, where (height, width) is given by original_size.
398
+ */
399
+ post_process_masks(masks: Tensor, original_sizes: number[][], reshaped_input_sizes: number[][], { mask_threshold, binarize, pad_size, }?: {
400
+ mask_threshold?: number;
401
+ binarize?: boolean;
402
+ pad_size?: {
403
+ height?: number;
404
+ width?: number;
405
+ };
406
+ }): Tensor[];
407
+ }
408
+ export class Swin2SRImageProcessor extends ImageFeatureExtractor {
409
+ pad_image(pixelData: any, imgDims: any, padSize: any, options?: {}): [Float32Array, number[]];
410
+ }
411
+ export class VitMatteImageProcessor extends ImageFeatureExtractor {
412
+ /**
413
+ * Calls the feature extraction process on an array of images, preprocesses
414
+ * each image, and concatenates the resulting features into a single Tensor.
415
+ * @param {RawImage[]} images The image(s) to extract features from.
416
+ * @param {RawImage[]} trimaps The trimaps(s) to extract features from.
417
+ * @returns {Promise<ImageFeatureExtractorResult>} An object containing the concatenated pixel values of the preprocessed images.
418
+ */
419
+ _call(images: RawImage[], trimaps: RawImage[]): Promise<ImageFeatureExtractorResult>;
420
+ }
421
+ export class WhisperFeatureExtractor extends FeatureExtractor {
422
+ constructor(config: any);
423
+ window: Float64Array;
424
+ /**
425
+ * Computes the log-Mel spectrogram of the provided audio waveform.
426
+ * @param {Float32Array|Float64Array} waveform The audio waveform to process.
427
+ * @returns {{data: Float32Array, dims: number[]}} An object containing the log-Mel spectrogram data as a Float32Array and its dimensions as an array of numbers.
428
+ */
429
+ _extract_fbank_features(waveform: Float32Array | Float64Array): {
430
+ data: Float32Array;
431
+ dims: number[];
432
+ };
433
+ /**
434
+ * Asynchronously extracts features from a given audio using the provided configuration.
435
+ * @param {Float32Array|Float64Array} audio The audio data as a Float32Array/Float64Array.
436
+ * @returns {Promise<{ input_features: Tensor }>} A Promise resolving to an object containing the extracted input features as a Tensor.
437
+ */
438
+ _call(audio: Float32Array | Float64Array): Promise<{
439
+ input_features: Tensor;
440
+ }>;
441
+ }
442
+ export class Wav2Vec2FeatureExtractor extends FeatureExtractor {
443
+ /**
444
+ * @param {Float32Array} input_values
445
+ * @returns {Float32Array}
446
+ */
447
+ _zero_mean_unit_var_norm(input_values: Float32Array): Float32Array;
448
+ /**
449
+ * Asynchronously extracts features from a given audio using the provided configuration.
450
+ * @param {Float32Array|Float64Array} audio The audio data as a Float32Array/Float64Array.
451
+ * @returns {Promise<{ input_values: Tensor; attention_mask: Tensor }>} A Promise resolving to an object containing the extracted input features and attention mask as Tensors.
452
+ */
453
+ _call(audio: Float32Array | Float64Array): Promise<{
454
+ input_values: Tensor;
455
+ attention_mask: Tensor;
456
+ }>;
457
+ }
458
+ export class SeamlessM4TFeatureExtractor extends FeatureExtractor {
459
+ constructor(config: any);
460
+ mel_filters: number[][];
461
+ window: Float64Array;
462
+ /**
463
+ * Computes the log-Mel spectrogram of the provided audio waveform.
464
+ * @param {Float32Array|Float64Array} waveform The audio waveform to process.
465
+ * @param {number} max_length The maximum number of frames to return.
466
+ * @returns {{data: Float32Array, dims: number[]}} An object containing the log-Mel spectrogram data as a Float32Array and its dimensions as an array of numbers.
467
+ */
468
+ _extract_fbank_features(waveform: Float32Array | Float64Array, max_length: number): {
469
+ data: Float32Array;
470
+ dims: number[];
471
+ };
472
+ /**
473
+ * Asynchronously extracts features from a given audio using the provided configuration.
474
+ * @param {Float32Array|Float64Array} audio The audio data as a Float32Array/Float64Array.
475
+ * @param {Object} options Optional parameters for feature extraction.
476
+ * @param {boolean} [options.padding=true] Whether to pad the sequence to a multiple of `pad_to_multiple_of`.
477
+ * @param {number} [options.pad_to_multiple_of=2] The number to pad the sequence to a multiple of.
478
+ * @param {boolean} [options.do_normalize_per_mel_bins=true] Whether or not to zero-mean unit-variance normalize the input per mel-channel.
479
+ * @param {boolean} [options.return_attention_mask=true] Whether to return the attention mask.
480
+ * @returns {Promise<{ input_features: Tensor, attention_mask?: Tensor }>} A Promise resolving to an object containing the extracted input features and attention masks as Tensors.
481
+ */
482
+ _call(audio: Float32Array | Float64Array, { padding, pad_to_multiple_of, do_normalize_per_mel_bins, return_attention_mask, }?: {
483
+ padding?: boolean;
484
+ pad_to_multiple_of?: number;
485
+ do_normalize_per_mel_bins?: boolean;
486
+ return_attention_mask?: boolean;
487
+ }): Promise<{
488
+ input_features: Tensor;
489
+ attention_mask?: Tensor;
490
+ }>;
491
+ }
492
+ export class ASTFeatureExtractor extends FeatureExtractor {
493
+ constructor(config: any);
494
+ mel_filters: number[][];
495
+ window: Float64Array;
496
+ mean: any;
497
+ std: any;
498
+ /**
499
+ * Computes the log-Mel spectrogram of the provided audio waveform.
500
+ * @param {Float32Array|Float64Array} waveform The audio waveform to process.
501
+ * @param {number} max_length The maximum number of frames to return.
502
+ * @returns {{data: Float32Array, dims: number[]}} An object containing the log-Mel spectrogram data as a Float32Array and its dimensions as an array of numbers.
503
+ */
504
+ _extract_fbank_features(waveform: Float32Array | Float64Array, max_length: number): {
505
+ data: Float32Array;
506
+ dims: number[];
507
+ };
508
+ /**
509
+ * Asynchronously extracts features from a given audio using the provided configuration.
510
+ * @param {Float32Array|Float64Array} audio The audio data as a Float32Array/Float64Array.
511
+ * @returns {Promise<{ input_values: Tensor }>} A Promise resolving to an object containing the extracted input features as a Tensor.
512
+ */
513
+ _call(audio: Float32Array | Float64Array): Promise<{
514
+ input_values: Tensor;
515
+ }>;
516
+ }
517
+ export class ClapFeatureExtractor extends FeatureExtractor {
518
+ constructor(config: any);
519
+ mel_filters: number[][];
520
+ mel_filters_slaney: number[][];
521
+ window: Float64Array;
522
+ /**
523
+ * Extracts the mel spectrogram and prepares it for the mode based on the `truncation` and `padding` arguments.
524
+ *
525
+ * Four different path are possible:
526
+ * - `truncation="fusion"` and the length of the waveform is greater than the max length: the mel spectrogram
527
+ * will be computed on the entire audio. 3 random crops and a dowsampled version of the full mel spectrogram
528
+ * are then stacked together. They will later be used for `feature_fusion`.
529
+ * - `truncation="rand_trunc"` and the length of the waveform is smaller than the max length: the audio is
530
+ * padded based on `padding`.
531
+ * - `truncation="fusion"` and the length of the waveform is smaller than the max length: the audio is padded
532
+ * based on `padding`, and is repeated `4` times.
533
+ * - `truncation="rand_trunc"` and the length of the waveform is greater than the max length: the mel
534
+ * spectrogram will be computed on a random crop of the waveform.
535
+ *
536
+ * @param {Float32Array|Float64Array} waveform The input waveform.
537
+ * @param {number} max_length The maximum length of the waveform.
538
+ * @param {string} truncation The truncation strategy to use.
539
+ * @param {string} padding The padding strategy to use.
540
+ * @returns {{ data: Float32Array; dims: number[]; longer: boolean; }} An object containing the mel spectrogram data as a Float32Array, its dimensions as an array of numbers, and a boolean indicating whether the waveform was longer than the max length.
541
+ */
542
+ _get_input_mel(waveform: Float32Array | Float64Array, max_length: number, truncation: string, padding: string): {
543
+ data: Float32Array;
544
+ dims: number[];
545
+ longer: boolean;
546
+ };
547
+ /**
548
+ * Compute the log-mel spectrogram of the provided `waveform` using the Hann window.
549
+ * In CLAP, two different filter banks are used depending on the truncation pattern:
550
+ * - `self.mel_filters`: they correspond to the default parameters of `torchaudio` which can be obtained from
551
+ * calling `torchaudio.transforms.MelSpectrogram().mel_scale.fb`. These filters are used when `truncation`
552
+ * is set to `"fusion"`.
553
+ * - `self.mel_filteres_slaney` : they correspond to the default parameters of `librosa` which used
554
+ * `librosa.filters.mel` when computing the mel spectrogram. These filters were only used in the original
555
+ * implementation when the truncation mode is not `"fusion"`.
556
+ *
557
+ * @param {Float32Array|Float64Array} waveform The audio waveform to process.
558
+ * @param {number[][]} mel_filters The mel filters to use.
559
+ * @param {number} [max_length=null] The maximum number of frames to return.
560
+ * @returns {{data: Float32Array, dims: number[]}} An object containing the log-Mel spectrogram data as a Float32Array and its dimensions as an array of numbers.
561
+ */
562
+ _extract_fbank_features(waveform: Float32Array | Float64Array, mel_filters: number[][], max_length?: number): {
563
+ data: Float32Array;
564
+ dims: number[];
565
+ };
566
+ /**
567
+ * Asynchronously extracts features from a given audio using the provided configuration.
568
+ * @param {Float32Array|Float64Array} audio The audio data as a Float32Array/Float64Array.
569
+ * @returns {Promise<{ input_features: Tensor }>} A Promise resolving to an object containing the extracted input features as a Tensor.
570
+ */
571
+ _call(audio: Float32Array | Float64Array, { max_length, }?: {
572
+ max_length?: any;
573
+ }): Promise<{
574
+ input_features: Tensor;
575
+ }>;
576
+ }
577
+ export class SpeechT5FeatureExtractor extends FeatureExtractor {
578
+ }
579
+ declare const Processor_base: new () => {
580
+ (...args: any[]): any;
581
+ _call(...args: any[]): any;
582
+ };
583
+ /**
584
+ * Represents a Processor that extracts features from an input.
585
+ * @extends Callable
586
+ */
587
+ export class Processor extends Processor_base {
588
+ /**
589
+ * Creates a new Processor with the given feature extractor.
590
+ * @param {FeatureExtractor} feature_extractor The function used to extract features from the input.
591
+ */
592
+ constructor(feature_extractor: FeatureExtractor);
593
+ feature_extractor: FeatureExtractor;
594
+ /**
595
+ * Calls the feature_extractor function with the given input.
596
+ * @param {any} input The input to extract features from.
597
+ * @param {...any} args Additional arguments.
598
+ * @returns {Promise<any>} A Promise that resolves with the extracted features.
599
+ */
600
+ _call(input: any, ...args: any[]): Promise<any>;
601
+ }
602
+ export class SamProcessor extends Processor {
603
+ /**
604
+ * @borrows SamImageProcessor#_call as _call
605
+ */
606
+ _call(...args: any[]): Promise<any>;
607
+ /**
608
+ * @borrows SamImageProcessor#post_process_masks as post_process_masks
609
+ */
610
+ post_process_masks(...args: any[]): any;
611
+ /**
612
+ * @borrows SamImageProcessor#reshape_input_points as reshape_input_points
613
+ */
614
+ reshape_input_points(...args: any[]): any;
615
+ }
616
+ /**
617
+ * Represents a WhisperProcessor that extracts features from an audio input.
618
+ * @extends Processor
619
+ */
620
+ export class WhisperProcessor extends Processor {
621
+ /**
622
+ * Calls the feature_extractor function with the given audio input.
623
+ * @param {any} audio The audio input to extract features from.
624
+ * @returns {Promise<any>} A Promise that resolves with the extracted features.
625
+ */
626
+ _call(audio: any): Promise<any>;
627
+ }
628
+ export class Wav2Vec2ProcessorWithLM extends Processor {
629
+ /**
630
+ * Calls the feature_extractor function with the given audio input.
631
+ * @param {any} audio The audio input to extract features from.
632
+ * @returns {Promise<any>} A Promise that resolves with the extracted features.
633
+ */
634
+ _call(audio: any): Promise<any>;
635
+ }
636
+ export class SpeechT5Processor extends Processor {
637
+ /**
638
+ * Calls the feature_extractor function with the given input.
639
+ * @param {any} input The input to extract features from.
640
+ * @returns {Promise<any>} A Promise that resolves with the extracted features.
641
+ */
642
+ _call(input: any): Promise<any>;
643
+ }
644
+ export class OwlViTProcessor extends Processor {
645
+ }
646
+ /**
647
+ * Helper class which is used to instantiate pretrained processors with the `from_pretrained` function.
648
+ * The chosen processor class is determined by the type specified in the processor config.
649
+ *
650
+ * **Example:** Load a processor using `from_pretrained`.
651
+ * ```javascript
652
+ * let processor = await AutoProcessor.from_pretrained('openai/whisper-tiny.en');
653
+ * ```
654
+ *
655
+ * **Example:** Run an image through a processor.
656
+ * ```javascript
657
+ * let processor = await AutoProcessor.from_pretrained('Xenova/clip-vit-base-patch16');
658
+ * let image = await RawImage.read('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg');
659
+ * let image_inputs = await processor(image);
660
+ * // {
661
+ * // "pixel_values": {
662
+ * // "dims": [ 1, 3, 224, 224 ],
663
+ * // "type": "float32",
664
+ * // "data": Float32Array [ -1.558687686920166, -1.558687686920166, -1.5440893173217773, ... ],
665
+ * // "size": 150528
666
+ * // },
667
+ * // "original_sizes": [
668
+ * // [ 533, 800 ]
669
+ * // ],
670
+ * // "reshaped_input_sizes": [
671
+ * // [ 224, 224 ]
672
+ * // ]
673
+ * // }
674
+ * ```
675
+ */
676
+ export class AutoProcessor {
677
+ static FEATURE_EXTRACTOR_CLASS_MAPPING: {
678
+ ImageFeatureExtractor: typeof ImageFeatureExtractor;
679
+ WhisperFeatureExtractor: typeof WhisperFeatureExtractor;
680
+ ViTFeatureExtractor: typeof ViTFeatureExtractor;
681
+ MobileViTFeatureExtractor: typeof MobileViTFeatureExtractor;
682
+ MobileViTImageProcessor: typeof MobileViTImageProcessor;
683
+ OwlViTFeatureExtractor: typeof OwlViTFeatureExtractor;
684
+ Owlv2ImageProcessor: typeof Owlv2ImageProcessor;
685
+ CLIPFeatureExtractor: typeof CLIPFeatureExtractor;
686
+ ChineseCLIPFeatureExtractor: typeof ChineseCLIPFeatureExtractor;
687
+ SiglipImageProcessor: typeof SiglipImageProcessor;
688
+ ConvNextFeatureExtractor: typeof ConvNextFeatureExtractor;
689
+ ConvNextImageProcessor: typeof ConvNextImageProcessor;
690
+ SegformerFeatureExtractor: typeof SegformerFeatureExtractor;
691
+ BitImageProcessor: typeof BitImageProcessor;
692
+ DPTImageProcessor: typeof DPTImageProcessor;
693
+ DPTFeatureExtractor: typeof DPTFeatureExtractor;
694
+ GLPNFeatureExtractor: typeof GLPNFeatureExtractor;
695
+ BeitFeatureExtractor: typeof BeitFeatureExtractor;
696
+ DeiTFeatureExtractor: typeof DeiTFeatureExtractor;
697
+ DetrFeatureExtractor: typeof DetrFeatureExtractor;
698
+ YolosFeatureExtractor: typeof YolosFeatureExtractor;
699
+ DonutFeatureExtractor: typeof DonutFeatureExtractor;
700
+ NougatImageProcessor: typeof NougatImageProcessor;
701
+ EfficientNetImageProcessor: typeof EfficientNetImageProcessor;
702
+ ViTImageProcessor: typeof ViTImageProcessor;
703
+ VitMatteImageProcessor: typeof VitMatteImageProcessor;
704
+ SamImageProcessor: typeof SamImageProcessor;
705
+ Swin2SRImageProcessor: typeof Swin2SRImageProcessor;
706
+ Wav2Vec2FeatureExtractor: typeof Wav2Vec2FeatureExtractor;
707
+ SeamlessM4TFeatureExtractor: typeof SeamlessM4TFeatureExtractor;
708
+ SpeechT5FeatureExtractor: typeof SpeechT5FeatureExtractor;
709
+ ASTFeatureExtractor: typeof ASTFeatureExtractor;
710
+ ClapFeatureExtractor: typeof ClapFeatureExtractor;
711
+ };
712
+ static PROCESSOR_CLASS_MAPPING: {
713
+ WhisperProcessor: typeof WhisperProcessor;
714
+ Wav2Vec2ProcessorWithLM: typeof Wav2Vec2ProcessorWithLM;
715
+ SamProcessor: typeof SamProcessor;
716
+ SpeechT5Processor: typeof SpeechT5Processor;
717
+ OwlViTProcessor: typeof OwlViTProcessor;
718
+ };
719
+ /**
720
+ * Instantiate one of the processor classes of the library from a pretrained model.
721
+ *
722
+ * The processor class to instantiate is selected based on the `feature_extractor_type` property of the config object
723
+ * (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible)
724
+ *
725
+ * @param {string} pretrained_model_name_or_path The name or path of the pretrained model. Can be either:
726
+ * - A string, the *model id* of a pretrained processor hosted inside a model repo on huggingface.co.
727
+ * Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a
728
+ * user or organization name, like `dbmdz/bert-base-german-cased`.
729
+ * - A path to a *directory* containing processor files, e.g., `./my_model_directory/`.
730
+ * @param {import('./utils/hub.js').PretrainedOptions} options Additional options for loading the processor.
731
+ *
732
+ * @returns {Promise<Processor>} A new instance of the Processor class.
733
+ */
734
+ static from_pretrained(pretrained_model_name_or_path: string, { progress_callback, config, cache_dir, local_files_only, revision, }?: import('./utils/hub.js').PretrainedOptions): Promise<Processor>;
735
+ }
736
+ /**
737
+ * Named tuple to indicate the order we are using is (height x width), even though
738
+ * the Graphics’ industry standard is (width x height).
739
+ */
740
+ export type HeightWidth = [height: number, width: number];
741
+ export type ImageFeatureExtractorResult = {
742
+ /**
743
+ * The pixel values of the batched preprocessed images.
744
+ */
745
+ pixel_values: Tensor;
746
+ /**
747
+ * Array of two-dimensional tuples like [[480, 640]].
748
+ */
749
+ original_sizes: HeightWidth[];
750
+ /**
751
+ * Array of two-dimensional tuples like [[1000, 1330]].
752
+ */
753
+ reshaped_input_sizes: HeightWidth[];
754
+ };
755
+ export type DetrFeatureExtractorResultProps = {
756
+ pixel_mask: Tensor;
757
+ };
758
+ export type DetrFeatureExtractorResult = ImageFeatureExtractorResult & DetrFeatureExtractorResultProps;
759
+ export type SamImageProcessorResult = {
760
+ pixel_values: Tensor;
761
+ original_sizes: HeightWidth[];
762
+ reshaped_input_sizes: HeightWidth[];
763
+ input_points?: Tensor;
764
+ input_labels?: Tensor;
765
+ };
766
+ import { RawImage } from './utils/image.js';
767
+ import { Tensor } from './utils/tensor.js';
768
+ export {};
769
+ //# sourceMappingURL=processors.d.ts.map