xenova / transformers.js

State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!
https://huggingface.co/docs/transformers.js
Apache License 2.0
9.71k stars 571 forks source link

Pipeline execution time with 'image-classification' pipeline #778

Open MayuraRam opened 1 month ago

MayuraRam commented 1 month ago

Question

While calling the 'image-classification' pipeline we pass the image url. So this does a fetch of the image. So will the time taken to process the image include the download time of the image? So if the network is slow this may impact the pipeline performance. Is there a way to use an image thats already been downloaded by the webpage for an image element?

Th3G33k commented 1 month ago

To reduce the impact of Internet speed on pipeline performance, you can prefetch the image and provide a blob url to the pipeline:

let blob = await fetch(url).then(x=>x.blob())
let bloburl = URL.createObjectURL(blob)
await pipe(bloburl)