This repository contains an example of running Segment-Anything, an encoder/decoder model for image segmentation, in a browser using ONNX Runtime Web with WebGPU.
You can try out the live demo here.
Segment-Anything creates embeddings for an image using an encoder. These embeddings are then used by the decoder to create and update the segmentation mask. The decoder can run in ONNX Runtime Web using WebAssembly with latencies at ~200ms.
The encoder is more compute-intensive, taking ~45sec in WebAssembly, which is not practical. However, by using WebGPU, we can speed up the encoder, making it feasible to run it inside the browser, even on an integrated GPU.
Ensure that you have Node.js installed on your machine.
- Install the required dependencies:
npm install
- Bundle the code using webpack:
npm run build
This command generates the bundle file ./dist/index.js
.
The model used in this project is hosted on Hugging Face. It was created using samexporter.
Start a web server to serve the current folder at http://localhost:8888/. To start the server, run:
npm run dev