19cd67a9e2 | ||
---|---|---|
.. | ||
samples | ||
src | ||
Cargo.toml | ||
NOTICES.md | ||
README.md | ||
build-for-web.sh | ||
build.rs | ||
https_server.py | ||
index.css | ||
index.html | ||
index.js | ||
run-server.sh |
README.md
Image Classification Web Demo Using Burn and WebAssembly
Overview
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.
Running the Demo
Step 1: Build the WebAssembly Binary and Other Assets
To compile the Rust code into WebAssembly and build other essential files, execute the following script:
./build-for-web.sh
Step 2: Launch the Web Server
Run the following command to initiate a web server on your local machine:
./run-server.sh
Step 3: Access the Web Demo
Open your web browser and navigate to:
http://localhost:8000
Backend Compatibility
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.
SIMD Support
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.
Model Information
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.
Credits
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.
Future Enhancements
-
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.