mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-06-30 03:37:44 +00:00
### Description <!-- Describe your changes. --> refactor tensor type in onnxruntime-common. ### Motivation and Context There major motivation is that I am doing a local change to address the API part of #15312. And I am doing a refactoring of onnxruntime-common anyway (#15772). The `tensor.ts` and `tensor-impl.ts` are too large, so I split contents into multiple files to make the type declarations clearer. The original target of this change is for API only ( ie. do not refactor any implementation.). However, there are a few type/implementation inconsistencies so I also made minimal changes to fix them. ### Changes - extract `TensorUtils` for non-template interfaces - extract `TensorFactory` for all overloads of `Tensor.fromImage()` - refactor options type that used for `Tensor.fromImage()` - fix JSDoc comments to make option descriptions consistent with actual type declarations - fix an inconsistency for `options.format` and `options.bitmapFormat`; change all `bitmapFormat` to `format` - extract `ConversionUtils` for `tensor.toDataURL()` and `tensor.toImageData()` - put implementations into multiple files from `tensor-impl.ts` - fix a bug that cause unittest fail. put comments for future fix.
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
import {OptionsFormat, OptionsNormalizationParameters, OptionsTensorLayout} from './tensor-factory';
|
|
|
|
export interface TensorToDataUrlOptions extends OptionsTensorLayout, OptionsFormat, OptionsNormalizationParameters {}
|
|
|
|
export interface TensorToImageDataOptions extends OptionsTensorLayout, OptionsFormat, OptionsNormalizationParameters {}
|
|
|
|
export interface ConversionUtils {
|
|
/**
|
|
* creates a DataURL instance from tensor
|
|
*
|
|
* @param options - An optional object representing options for creating a DataURL instance from the tensor.
|
|
*
|
|
* The following default settings will be applied:
|
|
* - `format`: `'RGB'`
|
|
* - `tensorLayout`: `'NCHW'`
|
|
* @returns a DataURL string representing the image converted from tensor data
|
|
*/
|
|
toDataURL(options?: TensorToDataUrlOptions): string;
|
|
|
|
/**
|
|
* creates an ImageData instance from tensor
|
|
*
|
|
* @param options - An optional object representing options for creating an ImageData instance from the tensor.
|
|
*
|
|
* The following default settings will be applied:
|
|
* - `format`: `'RGB'`
|
|
* - `tensorLayout`: `'NCHW'`
|
|
* @returns an ImageData instance representing the image converted from tensor data
|
|
*/
|
|
toImageData(options?: TensorToImageDataOptions): ImageData;
|
|
}
|