Skip to content

Commit ee1056b

Browse files
committed
[version] Update to v1.4.2
1 parent 3b9ebf0 commit ee1056b

File tree

12 files changed

+1375
-147
lines changed

12 files changed

+1375
-147
lines changed

dist/transformers.js

Lines changed: 1161 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/transformers.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/transformers.min.js

Lines changed: 26 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/transformers.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/types/image_utils.d.ts

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,81 @@
1-
/**
2-
*
3-
* @param {string} url
4-
* @returns {Promise<any>}
5-
*/
6-
export function loadImage(url: string): Promise<any>;
7-
export const Jimp: any;
8-
export const ImageType: any;
1+
export class CustomImage {
2+
/**
3+
* Helper method for reading an image from a variety of input types.
4+
* @param {CustomImage|string|URL} input
5+
* @returns The image object.
6+
*/
7+
static read(input: CustomImage | string | URL): Promise<CustomImage>;
8+
/**
9+
* Read an image from a URL or file path.
10+
* @param {string|URL} url - The URL or file path to read the image from.
11+
* @returns {Promise<CustomImage>} - The image object.
12+
*/
13+
static fromURL(url: string | URL): Promise<CustomImage>;
14+
/**
15+
* Helper method to create a new canvas, draw an image/canvas to it, then return the pixel data. * @param {ImageClass|CanvasClass} img - The image/canvas to draw to the canvas.
16+
* @param {number} [width=null] - Width of the canvas. If null, the width of the image is used.
17+
* @param {number} [height=null] - Height of the canvas. If null, the height of the image is used.
18+
* @returns {CustomImage} - The image object.
19+
*/
20+
static createCanvasAndDraw(img: any, width?: number, height?: number): CustomImage;
21+
/**
22+
* Create a new CustomImage object.
23+
* @param {Uint8ClampedArray} data - The pixel data.
24+
* @param {number} width - The width of the image.
25+
* @param {number} height - The height of the image.
26+
* @param {number} channels - The number of channels.
27+
*/
28+
constructor(data: Uint8ClampedArray, width: number, height: number, channels: number);
29+
/**
30+
* Convert the image to grayscale format.
31+
* @returns {CustomImage} - `this` to support chaining.
32+
*/
33+
grayscale(): CustomImage;
34+
/**
35+
* Convert the image to RGB format.
36+
* @returns {CustomImage} - `this` to support chaining.
37+
*/
38+
rgb(): CustomImage;
39+
/**
40+
* Convert the image to RGBA format.
41+
* @returns {CustomImage} - `this` to support chaining.
42+
*/
43+
rgba(): CustomImage;
44+
/**
45+
* Resize the image to the given dimensions. This method uses the canvas API to perform the resizing.
46+
* @param {number} width - The width of the new image.
47+
* @param {number} height - The height of the new image.
48+
* @returns {CustomImage} - `this` to support chaining.
49+
*/
50+
resize(width: number, height: number): CustomImage;
51+
toCanvas(): any;
52+
/**
53+
* Helper method to update the image data.
54+
* @param {Uint8ClampedArray} data - The new image data.
55+
* @param {number} width - The new width of the image.
56+
* @param {number} height - The new height of the image.
57+
* @param {number} channels - The new number of channels of the image.
58+
*/
59+
_update(data: Uint8ClampedArray, width: number, height: number, channels?: number): CustomImage;
60+
data: Uint8ClampedArray;
61+
width: number;
62+
height: number;
63+
channels: number;
64+
/**
65+
* Clone the image
66+
* @returns {CustomImage} - The cloned image
67+
*/
68+
clone(): CustomImage;
69+
/**
70+
* Helper method for converting image to have a certain number of channels
71+
* @param {number} numChannels - The number of channels. Must be 1, 3, or 4.
72+
* @returns {CustomImage} - `this` to support chaining.
73+
*/
74+
convert(numChannels: number): CustomImage;
75+
/**
76+
* Save the image to the given path. This method is only available in environments with access to the FileSystem.
77+
* @param {string|Buffer|URL} path - The path to save the image to.
78+
* @param {string} [mime='image/png'] - The mime type of the image.
79+
*/
80+
save(path: string | Buffer | URL, mime?: string): void;
81+
}

dist/types/math_utils.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
2+
export type BigTypedArray = BigInt64Array | BigUint64Array;
3+
export type AnyTypedArray = TypedArray | BigTypedArray;
4+
/**
5+
* @typedef {Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array} TypedArray
6+
* @typedef {BigInt64Array | BigUint64Array} BigTypedArray
7+
* @typedef {TypedArray | BigTypedArray} AnyTypedArray
8+
*/
9+
/**
10+
* @param {TypedArray} input
11+
*/
12+
export function interpolate(input: TypedArray, [in_channels, in_height, in_width]: [any, any, any], [out_height, out_width]: [any, any], mode?: string, align_corners?: boolean): any;
13+
/**
14+
* Helper method to transpose a AnyTypedArray directly
15+
* @param {T} array
16+
* @template {AnyTypedArray} T
17+
* @param {number[]} dims
18+
* @param {number[]} axes
19+
* @returns {[T, number[]]} The transposed array and the new shape.
20+
*/
21+
declare function transpose_data<T extends AnyTypedArray>(array: T, dims: number[], axes: number[]): [T, number[]];
22+
export { transpose_data as transpose };

dist/types/models.d.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class AutoModelForImageClassification {
175175
* Loads a pre-trained image classification model from a given directory path.
176176
* @param {string} modelPath - The path to the directory containing the pre-trained model.
177177
* @param {function} [progressCallback=null] - A callback function to monitor the loading progress.
178-
* @returns {Promise<PreTrainedModel>} A Promise that resolves with an instance of the ViTForImageClassification class.
178+
* @returns {Promise<PreTrainedModel>} A Promise that resolves with the model.
179179
* @throws {Error} If the specified model type is not supported.
180180
*/
181181
static from_pretrained(modelPath: string, progressCallback?: Function): Promise<PreTrainedModel>;
@@ -188,7 +188,23 @@ export class AutoModelForObjectDetection {
188188
* Loads a pre-trained image classification model from a given directory path.
189189
* @param {string} modelPath - The path to the directory containing the pre-trained model.
190190
* @param {function} [progressCallback=null] - A callback function to monitor the loading progress.
191-
* @returns {Promise<PreTrainedModel>} A Promise that resolves with an instance of the ViTForImageClassification class.
191+
* @returns {Promise<PreTrainedModel>} A Promise that resolves with the model.
192+
* @throws {Error} If the specified model type is not supported.
193+
*/
194+
static from_pretrained(modelPath: string, progressCallback?: Function): Promise<PreTrainedModel>;
195+
}
196+
/**
197+
* AutoModelForImageSegmentation is a class for loading pre-trained image classification models from ONNX format.
198+
*/
199+
export class AutoModelForImageSegmentation {
200+
static MODEL_CLASS_MAPPING: {
201+
detr: typeof DetrForSegmentation;
202+
};
203+
/**
204+
* Loads a pre-trained image classification model from a given directory path.
205+
* @param {string} modelPath - The path to the directory containing the pre-trained model.
206+
* @param {function} [progressCallback=null] - A callback function to monitor the loading progress.
207+
* @returns {Promise<PreTrainedModel>} A Promise that resolves with the model.
192208
* @throws {Error} If the specified model type is not supported.
193209
*/
194210
static from_pretrained(modelPath: string, progressCallback?: Function): Promise<PreTrainedModel>;
@@ -1039,6 +1055,14 @@ declare class DetrForObjectDetection extends DetrPreTrainedModel {
10391055
*/
10401056
_call(model_inputs: any): Promise<DetrObjectDetectionOutput>;
10411057
}
1058+
declare class DetrForSegmentation extends DetrPreTrainedModel {
1059+
/**
1060+
* Runs the model with the provided inputs
1061+
* @param {Object} model_inputs - Model inputs
1062+
* @returns {Promise<DetrSegmentationOutput>} - Object containing segmentation outputs
1063+
*/
1064+
_call(model_inputs: any): Promise<DetrSegmentationOutput>;
1065+
}
10421066
declare class BertPreTrainedModel extends PreTrainedModel {
10431067
}
10441068
declare class AlbertPreTrainedModel extends PreTrainedModel {
@@ -1127,6 +1151,17 @@ declare class DetrObjectDetectionOutput extends ModelOutput {
11271151
logits: any;
11281152
pred_boxes: any;
11291153
}
1154+
declare class DetrSegmentationOutput extends ModelOutput {
1155+
/**
1156+
* @param {Tensor} logits - The output logits of the model.
1157+
* @param {Tensor} pred_boxes - Predicted boxes.
1158+
* @param {Tensor} pred_masks - Predicted masks.
1159+
*/
1160+
constructor(logits: Tensor, pred_boxes: Tensor, pred_masks: Tensor);
1161+
logits: Tensor;
1162+
pred_boxes: Tensor;
1163+
pred_masks: Tensor;
1164+
}
11301165
declare class ModelOutput {
11311166
}
11321167
export {};

dist/types/processors.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class AutoProcessor {
1717
* Represents a Processor that extracts features from an input.
1818
* @extends Callable
1919
*/
20-
declare class Processor extends Callable {
20+
export class Processor extends Callable {
2121
/**
2222
* Creates a new Processor with the given feature extractor.
2323
* @param {function} feature_extractor - The function used to extract features from the input.
@@ -33,4 +33,3 @@ declare class Processor extends Callable {
3333
_call(input: any): Promise<any>;
3434
}
3535
import { Callable } from "./utils.js";
36-
export {};

dist/types/tensor_utils.d.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22
* This creates a nested array of a given type and depth (see examples).
33
*/
44
export type NestArray<T, Depth extends number, Acc extends never[] = []> = Acc['length'] extends Depth ? T : NestArray<T[], Depth, [...Acc, never]>;
5+
export type AnyTypedArray = import('./math_utils.js').AnyTypedArray;
56
declare const Tensor_base: any;
67
export class Tensor extends Tensor_base {
78
[x: string]: any;
8-
constructor(...args: any[]);
9+
/**
10+
* Create a new Tensor or copy an existing Tensor.
11+
* @param {[string, Array|AnyTypedArray, number[]]|[ONNXTensor]} args
12+
*/
13+
constructor(...args: [string, any[] | AnyTypedArray, number[]] | [any]);
914
/**
1015
*
1116
* @param {number} index
12-
* @returns
17+
* @returns {Tensor}
18+
* @todo Set type based on dims
1319
*/
14-
get(index: number): any;
20+
get(index: number): Tensor;
1521
/**
1622
* @param {any} item
1723
* @returns {number}
@@ -25,6 +31,23 @@ export class Tensor extends Tensor_base {
2531
*/
2632
_subarray(index: number, iterSize: number, iterDims: any): Tensor;
2733
tolist(): any;
34+
/**
35+
* Return a new Tensor the sigmoid function applied to each element.
36+
* @returns {Tensor} - The tensor with the sigmoid function applied.
37+
*/
38+
sigmoid(): Tensor;
39+
/**
40+
* Applies the sigmoid function to the tensor in place.
41+
* @returns {Tensor} - Returns `this`.
42+
*/
43+
sigmoid_(): Tensor;
44+
clone(): Tensor;
45+
/**
46+
* Return a transposed version of this Tensor, according to the provided dimensions.
47+
* @param {...number} dims - Dimensions to transpose.
48+
* @returns {Tensor} - The transposed tensor.
49+
*/
50+
transpose(...dims: number[]): Tensor;
2851
/**
2952
* Returns an iterator object for iterating over the tensor data in row-major order.
3053
* If the tensor has more than one dimension, the iterator will yield subarrays.
@@ -46,4 +69,14 @@ export function transpose(tensor: any, axes: any[]): Tensor;
4669
* @returns {Tensor} - The concatenated tensor.
4770
*/
4871
export function cat(tensors: any): Tensor;
49-
export {};
72+
/**
73+
* Interpolates an Tensor to the given size.
74+
* @param {Tensor} input - The input tensor to interpolate. Data must be channel-first (i.e., [c, h, w])
75+
* @param {number[]} size - The output size of the image
76+
* @param {string} mode - The interpolation mode
77+
* @param {boolean} align_corners - Whether to align corners.
78+
* @returns {Tensor} - The interpolated tensor.
79+
*/
80+
export function interpolate(input: Tensor, [out_height, out_width]: number[], mode?: string, align_corners?: boolean): Tensor;
81+
import { transpose as transpose_data } from "./math_utils.js";
82+
export { transpose_data };

dist/types/transformers.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ import { AutoModelForImageClassification } from "./models.js";
1515
import { AutoModelForObjectDetection } from "./models.js";
1616
import { AutoProcessor } from "./processors.js";
1717
import { pipeline } from "./pipelines.js";
18+
import { Tensor } from "./tensor_utils.js";
1819
import { env } from "./env.js";
19-
export { AutoTokenizer, BertTokenizer, DistilBertTokenizer, T5Tokenizer, GPT2Tokenizer, AutoModel, AutoModelForSeq2SeqLM, AutoModelForSequenceClassification, AutoModelForTokenClassification, AutoModelForCausalLM, AutoModelForMaskedLM, AutoModelForQuestionAnswering, AutoModelForVision2Seq, AutoModelForImageClassification, AutoModelForObjectDetection, AutoProcessor, pipeline, env };
20+
export { AutoTokenizer, BertTokenizer, DistilBertTokenizer, T5Tokenizer, GPT2Tokenizer, AutoModel, AutoModelForSeq2SeqLM, AutoModelForSequenceClassification, AutoModelForTokenClassification, AutoModelForCausalLM, AutoModelForMaskedLM, AutoModelForQuestionAnswering, AutoModelForVision2Seq, AutoModelForImageClassification, AutoModelForObjectDetection, AutoProcessor, pipeline, Tensor, env };

0 commit comments

Comments
 (0)