• Creates a function, which reads a weights manifest JSON configuration, fetches the weight files using the specified function and returns them as Tensors.

    // example for creating a nodejs weight loader, which reads the weight files
    // from disk using fs.readFileSync

    import * as fs from 'fs'

    const fetchWeightsFromDisk = (filePaths: string[]) =>
    filePaths.map(filePath => fs.readFileSync(filePath).buffer)

    const loadWeights = tf.io.weightsLoaderFactory(fetchWeightsFromDisk)

    const manifest = JSON.parse(
    fs.readFileSync('./my_model-weights_manifest').toString()
    )
    const weightMap = await loadWeights(manifest, './')

    Parameters

    • fetchWeightsFunction: (fetchUrls: string[]) => Promise<ArrayBuffer[]>

      The function used for fetching the weight files.

    Returns (
        manifest: WeightsManifestConfig,
        filePathPrefix?: string,
        weightNames?: string[],
    ) => Promise<NamedTensorMap>

    Weight loading function.