async load()

in src/plugin/utils/local_storage.ts [131:163]


  async load(): Promise<io.ModelArtifacts> {
    const info =
      JSON.parse(await getStorage(this.keys.info)) as io.ModelArtifactsInfo;
    if (info == null) {
      throw new Error(
        `In local storage, there is no model with name '${this.modelPath}'`);
    }

    if (info.modelTopologyType !== 'JSON') {
      throw new Error(
        'BrowserLocalStorage does not support loading non-JSON model ' +
        'topology yet.');
    }

    const modelArtifacts: io.ModelArtifacts =
      JSON.parse(await getStorage(this.keys.modelArtifactsWithoutWeights));

    // Load weight data.
    const weightDataSize = await getStorage(this.keys.weightDataChunkSize);
    let weightDataBase64 = '';
    for (let i = 0; i < weightDataSize; i++) {
      const partialData = await getStorage(`${this.keys.weightData}:${i}`);
      if (partialData == null) {
        throw new Error(
          `In local storage, the binary weight values of model ` +
          `'${this.modelPath}' are missing.`);
      }
      weightDataBase64 += partialData;
    }
    modelArtifacts.weightData = toByteArray(weightDataBase64).buffer;

    return modelArtifacts;
  }