-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[js] enable external data loading for ort-web (#19087)
### Description enable external data loading for ort-web. ### Why The ORT external data design is highly depending on the file system, especially synchronous file I/O APIs. Those are not available in web platforms. We need to have extra code to make external data working on web. ### How Considering there is no file system in web, an implementation for web to support external data is to use pre-loaded data. Assume model file a.onnx includes initializers that linked to ./b.bin, we require users to pass a full data file list when creating the session. The user code will be look like: ```js const mySess = await ort.InferenceSession.create('./path/model/a.onnx', { // session options externalData: [ { // relative or absolute path/URL of the file, // or a pre-loaded Uint8Array containing the data of the external data file data: './path/data/b.bin', // the relative path of the external data. Should match initializers' "location" value defined in the model file path: './b.bin' }, // { } if multiple external data file ] }); ``` Currently, this feature only works with JSEP build enabled.
- Loading branch information
Showing
19 changed files
with
420 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* A string that represents a file's URL or path. | ||
* | ||
* Path is vailable only in onnxruntime-node or onnxruntime-web running in Node.js. | ||
*/ | ||
export type FileUrlOrPath = string; | ||
|
||
/** | ||
* A Blob object that represents a file. | ||
*/ | ||
export type FileBlob = Blob; | ||
|
||
/** | ||
* A Uint8Array, ArrayBuffer or SharedArrayBuffer object that represents a file content. | ||
* | ||
* When it is an ArrayBuffer or SharedArrayBuffer, the whole buffer is assumed to be the file content. | ||
*/ | ||
export type FileData = Uint8Array|ArrayBufferLike; | ||
|
||
/** | ||
* Represents a file that can be loaded by the ONNX Runtime JavaScript API. | ||
*/ | ||
export type FileType = FileUrlOrPath|FileBlob|FileData; | ||
|
||
/** | ||
* Represents an external data file. | ||
*/ | ||
export interface ExternalDataFileDescription { | ||
/** | ||
* Specify the external data file. | ||
*/ | ||
data: FileType; | ||
/** | ||
* Specify the file path. | ||
*/ | ||
path: string; | ||
} | ||
|
||
/** | ||
* Represents an external data file. | ||
* | ||
* When using a string, it should be a file URL or path that in the same directory as the model file. | ||
*/ | ||
export type ExternalDataFileType = ExternalDataFileDescription|FileUrlOrPath; | ||
|
||
/** | ||
* Options for model loading. | ||
*/ | ||
export interface OnnxModelOptions { | ||
/** | ||
* Specifying a list of files that represents the external data. | ||
*/ | ||
externalData?: readonly ExternalDataFileType[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.