Created
June 7, 2024 13:43
-
-
Save sulmanen/69b6e473d9a652cd8f489b98302be3f2 to your computer and use it in GitHub Desktop.
tfjs model loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async loadModel(): Promise<io.ModelArtifacts> { | |
return fetch(`${BUCKET_URL}/model.json`) | |
.then((response: Response) => response.json()) | |
.then((modelJson) => | |
io.getModelArtifactsForJSON(modelJson, (weightsManifest: WeightsManifestConfig) => | |
fetch(`${BUCKET_URL}/group1-shard1of1.bin`) | |
.then((response: Response) => response.arrayBuffer()) | |
.then((weightData: WeightData) => [io.getWeightSpecs(weightsManifest), weightData]) | |
) | |
) as Promise<io.ModelArtifacts> | |
} | |
async loadAssets(): Promise<Blob> { | |
return fetch(`${BUCKET_URL}/assets.zip`).then((response: Response) => response.arrayBuffer()) as Promise<Blob>; | |
} | |
async load(): Promise<TFDFModel> { | |
return await loadTFDFModel({ | |
loadModel: () => this.loadModel(), | |
loadAssets: () => this.loadAssets(), | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment