MCPcopy
hub / github.com/tensorflow/tfjs / load

Method load

tfjs-core/src/io/browser_files.ts:138–175  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

136 }
137
138 async load(): Promise<ModelArtifacts> {
139 return new Promise((resolve, reject) => {
140 const jsonReader = new FileReader();
141 jsonReader.onload = (event: Event) => {
142 // tslint:disable-next-line:no-any
143 const modelJSON = JSON.parse((event.target as any).result) as ModelJSON;
144
145 const modelTopology = modelJSON.modelTopology;
146 if (modelTopology == null) {
147 reject(new Error(`modelTopology field is missing from file ${
148 this.jsonFile.name}`));
149 return;
150 }
151
152 const weightsManifest = modelJSON.weightsManifest;
153 if (weightsManifest == null) {
154 reject(new Error(`weightManifest field is missing from file ${
155 this.jsonFile.name}`));
156 return;
157 }
158
159 if (this.weightsFiles.length === 0) {
160 resolve({modelTopology});
161 return;
162 }
163
164 const modelArtifactsPromise = getModelArtifactsForJSON(
165 modelJSON, (weightsManifest) => this.loadWeights(weightsManifest));
166 resolve(modelArtifactsPromise);
167 };
168
169 jsonReader.onerror = error => reject(
170 `Failed to read model topology and weights manifest JSON ` +
171 `from file '${this.jsonFile.name}'. BrowserFiles supports loading ` +
172 `Keras-style tf.Model artifacts only.`);
173 jsonReader.readAsText(this.jsonFile);
174 });
175 }
176
177 private loadWeights(weightsManifest: WeightsManifestConfig): Promise<[
178 /* weightSpecs */ WeightsManifestEntry[], WeightData,

Callers

nothing calls this directly

Calls 2

loadWeightsMethod · 0.95
getModelArtifactsForJSONFunction · 0.90

Tested by

no test coverage detected