io

interface LoadOptions {
    fetchFunc?: {
        (input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
        (input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
        (input: string | Request | URL, init?: RequestInit): Promise<Response>;
    };
    fromTFHub?: boolean;
    onProgress?: OnProgressCallback;
    requestInit?: RequestInit;
    streamWeights?: boolean;
    strict?: boolean;
    weightPathPrefix?: string;
    weightUrlConverter?: ((weightFileName: string) => Promise<string>);
}

Properties

fetchFunc?: {
    (input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
    (input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
    (input: string | Request | URL, init?: RequestInit): Promise<Response>;
}

A function used to override the window.fetch function.

Type declaration

    • (input, init?): Promise<Response>
    • Parameters

      • input: RequestInfo | URL
      • Optionalinit: RequestInit

      Returns Promise<Response>

    • (input, init?): Promise<Response>
    • Parameters

      • input: RequestInfo | URL
      • Optionalinit: RequestInit

      Returns Promise<Response>

    • (input, init?): Promise<Response>
    • Parameters

      • input: string | Request | URL
      • Optionalinit: RequestInit

      Returns Promise<Response>

fromTFHub?: boolean

Whether the module or model is to be loaded from TF Hub.

Setting this to true allows passing a TF-Hub module URL, omitting the standard model file name and the query parameters.

Default: false.

onProgress?: OnProgressCallback

Progress callback.

requestInit?: RequestInit

RequestInit (options) for HTTP requests.

For detailed information on the supported fields, see https://developer.mozilla.org/en-US/docs/Web/API/Request/Request

streamWeights?: boolean

Whether to stream the model directly to the backend or cache all its weights on CPU first. Useful for large models.

strict?: boolean

Strict loading model: whether extraneous weights or missing weights should trigger an Error.

If true, require that the provided weights exactly match those required by the layers. false means that both extra weights and missing weights will be silently ignored.

Default: true.

weightPathPrefix?: string

Path prefix for weight files, by default this is calculated from the path of the model JSON file.

For instance, if the path to the model JSON file is http://localhost/foo/model.json, then the default path prefix will be http://localhost/foo/. If a weight file has the path value group1-shard1of2 in the weight manifest, then the weight file will be loaded from http://localhost/foo/group1-shard1of2 by default. However, if you provide a weightPathPrefix value of http://localhost/foo/alt-weights, then the weight file will be loaded from the path http://localhost/foo/alt-weights/group1-shard1of2 instead.

weightUrlConverter?: ((weightFileName: string) => Promise<string>)

An async function to convert weight file name to URL. The weight file names are stored in model.json's weightsManifest.paths field. By default we consider weight files are colocated with the model.json file. For example: model.json URL: https://www.google.com/models/1/model.json group1-shard1of1.bin url: https://www.google.com/models/1/group1-shard1of1.bin

With this func you can convert the weight file name to any URL.