MCPcopy Create free account
hub / github.com/tensorflow/tfjs / load

Method load

tfjs-react-native/src/async_storage_io.ts:131–160  ·  view source on GitHub ↗

* Load a model from local storage. * * See the documentation to `browserLocalStorage` for details on the saved * artifacts. * * @returns The loaded model (if loading succeeds).

()

Source from the content-addressed store, hash-verified

129 * @returns The loaded model (if loading succeeds).
130 */
131 async load(): Promise<io.ModelArtifacts> {
132 const info = JSON.parse(await this.asyncStorage.getItem(this.keys.info)) as
133 io.ModelArtifactsInfo;
134 if (info == null) {
135 throw new Error(
136 `In local storage, there is no model with name '${this.modelPath}'`);
137 }
138
139 if (info.modelTopologyType !== 'JSON') {
140 throw new Error(
141 'BrowserLocalStorage does not support loading non-JSON model ' +
142 'topology yet.');
143 }
144
145 const modelArtifacts: io.ModelArtifacts =
146 JSON.parse(await this.asyncStorage.getItem(
147 this.keys.modelArtifactsWithoutWeights));
148
149 // Load weight data.
150 const weightDataBase64 =
151 await this.asyncStorage.getItem(this.keys.weightData);
152 if (weightDataBase64 == null) {
153 throw new Error(
154 `In local storage, the binary weight values of model ` +
155 `'${this.modelPath}' are missing.`);
156 }
157 modelArtifacts.weightData = toByteArray(weightDataBase64).buffer;
158
159 return modelArtifacts;
160 }
161}
162
163/**

Callers 6

mobilenetRunnerFunction · 0.45
componentDidMountMethod · 0.45
loadPosenetModelMethod · 0.45
loadBlazefaceModelMethod · 0.45

Calls 1

getItemMethod · 0.80

Tested by

no test coverage detected