Skip to content

Instantly share code, notes, and snippets.

@sulmanen
Created June 7, 2024 13:43
Show Gist options
  • Save sulmanen/69b6e473d9a652cd8f489b98302be3f2 to your computer and use it in GitHub Desktop.
Save sulmanen/69b6e473d9a652cd8f489b98302be3f2 to your computer and use it in GitHub Desktop.
tfjs model loader
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