|
| 1 | +# ExecuTorch JavaScript Bindings Demo |
| 2 | + |
| 3 | +This demo showcases the capabilities of ExecuTorch's JavaScript bindings. It is able to load a model, run inference, and classify an image natively in the browser. |
| 4 | + |
| 5 | +## Installing Emscripten |
| 6 | + |
| 7 | +[Emscripten](https://emscripten.org/index.html) is necessary to compile ExecuTorch for Wasm. You can install Emscripten with these commands: |
| 8 | + |
| 9 | +```bash |
| 10 | +# Clone the emsdk repository |
| 11 | +git clone https://github.com/emscripten-core/emsdk.git |
| 12 | +cd emsdk |
| 13 | + |
| 14 | +# Download and install version 4.0.10 of the SDK |
| 15 | +./emsdk install 4.0.10 |
| 16 | +./emsdk activate 4.0.10 |
| 17 | + |
| 18 | +# Add the Emscripten environment variables to your shell |
| 19 | +source ./emsdk_env.sh |
| 20 | +``` |
| 21 | + |
| 22 | +## Setting up ExecuTorch and Generating the Model File |
| 23 | + |
| 24 | +Make sure you have the system requirements listed in the [Getting Started Guide](https://docs.pytorch.org/executorch/main/getting-started.html#system-requirements) before continuing. |
| 25 | + |
| 26 | +1. Install ExecuTorch from PyPI. |
| 27 | +```bash |
| 28 | +pip3 install executorch |
| 29 | +``` |
| 30 | + |
| 31 | +2. Update the ExecuTorch submodule. |
| 32 | +```bash |
| 33 | +git submodule update --init --recursive executorch |
| 34 | +``` |
| 35 | + |
| 36 | +3. Using the script `examples/portable/scripts/export.py` generate the EfficientSAM binary file for this demo. |
| 37 | + |
| 38 | +```bash |
| 39 | +cd executorch # To the root of the executorch repo |
| 40 | + |
| 41 | +# Export the model file for the demo |
| 42 | +python3 -m examples.portable.scripts.export --model_name="efficient_sam" |
| 43 | +``` |
| 44 | + |
| 45 | +## Building and Running |
| 46 | + |
| 47 | +Once you have Emscripten installed, ExecuTorch set up, and the model file generated, you can build and run the demo. Building may take up to 9 minutes. |
| 48 | + |
| 49 | +```bash |
| 50 | +cd efficient_sam/wasm # The directory containing this README |
| 51 | + |
| 52 | +# Build the demo |
| 53 | +bash build.sh |
| 54 | + |
| 55 | +# Run the demo |
| 56 | +python3 -m http.server --directory build/ |
| 57 | +``` |
| 58 | + |
| 59 | +The page will be available at http://localhost:8000/demo.html. |
| 60 | + |
| 61 | +## Demo Features |
| 62 | + |
| 63 | +- Load a model from a file |
| 64 | + - This demo only supports the EfficientSAM model. Passing in a model with different input/output shapes will result in an error. |
| 65 | +- Run inference on an image |
| 66 | + - Supported formats: `.png`, `.gif`, `.jpeg`, `.jpg` |
| 67 | +- Select a point on the image to run inference |
| 68 | + - May take up to 40 seconds to run inference |
| 69 | +- Show and hide the segmentation mask |
0 commit comments