This demo showcases how to execute an image classification task in a web browser using a model converted to Rust code. The project utilizes the Burn deep learning framework, WebGPU and WebAssembly . Specifically, it demonstrates:
- Converting an ONNX (Open Neural Networks Exchange) model into Rust code compatible with the Burn framework.
- Executing the model within a web browser using WebGPU via the
burn-wgpu
backend and WebAssembly through theburn-ndarray
andburn-candle
backends.
To compile the Rust code into WebAssembly and build other essential files, execute the following script:
./build-for-web.sh
Run the following command to initiate a web server on your local machine:
./run-server.sh
Open your web browser and navigate to:
http://localhost:8000
As of now, the WebGPU backend is compatible only with Chrome browsers running on macOS and Windows. The application will dynamically detect if WebGPU support is available and proceed accordingly.
The build targets two sets of binaries, one with SIMD support and one without. The web application dynamically detects if SIMD support is available and downloads the appropriate binary.
The image classification task is achieved using the SqueezeNet model, a compact Convolutional Neural Network (CNN). It is trained on the ImageNet dataset and can classify images into 1,000 distinct categories. The included ONNX model is sourced from the ONNX Model Zoo. For further details about the model's architecture and performance, you can refer to the original paper.
This demo was inspired by the ONNX Runtime web demo featuring the SqueezeNet model trained on ImageNet.
The complete list of credits/attribution can be found in the NOTICES file.
-
Fall back to WebGL if WebGPU is not supported by the browser. See wgpu's WebGL support
-
Enable SIMD support for Safari browsers after Release 179.
-
Add image paste functionality to allow users to paste an image from the clipboard.