Skip to content

Commit

Permalink
Add a pure Wasm image classification benchmark
Browse files Browse the repository at this point in the history
Add a benchmark which performs image classification in pure Wasm using
tract and ONNX. This can be useful to track the performance of float
heavy computations.
  • Loading branch information
adambratschikaye committed Apr 23, 2024
1 parent 8bc0d50 commit d0ac5de
Show file tree
Hide file tree
Showing 11 changed files with 1,162 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ exclude = [
"benchmarks/shootout-switch",
"benchmarks/shootout-xblabla20",
"benchmarks/shootout-xchacha20",
"engines/native/libengine"
"benchmarks/tract-onnx-image-classification",
"engines/native/libengine",
]
3 changes: 3 additions & 0 deletions benchmarks/tract-onnx-image-classification/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/rust-benchmark/target
/rust-benchmark/Cargo.lock
/assets/mobilenetv2-7.onnx
13 changes: 13 additions & 0 deletions benchmarks/tract-onnx-image-classification/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM rust:1.75
RUN rustup target add wasm32-wasi
WORKDIR /usr/src
ADD rust-benchmark rust-benchmark
ADD assets assets
WORKDIR /usr/src/rust-benchmark
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
RUN cargo build --release --target wasm32-wasi
RUN ls target/wasm32-wasi/release
RUN mkdir /benchmark
RUN cp target/wasm32-wasi/release/benchmark.wasm /benchmark/
# We output the Wasm file to the `/benchmark` directory, where the client
# expects it.
7 changes: 7 additions & 0 deletions benchmarks/tract-onnx-image-classification/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Image Classification Wasmtime Benchmark

A benchmark that runs an image classifier in pure Wasm. This can be used to
benchmark the performance of float heavy computations.

Note that the classifier model is not included in the repo because it is large
and is instead downloaded if needed when running the `setup.sh` script.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Classification { label: "tiger", score: 17.559244 }, Classification { label: "tiger cat", score: 14.740076 }, Classification { label: "zebra", score: 12.357242 }]
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "benchmark"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib"]

[dependencies]
anyhow = "1.0"
bytes = "1.5.0"
prost = "0.11.0"
image = { version = "0.25.1", features = ["png"], default-features = false }
tract-onnx = { git = "https://github.com/sonos/tract", version = "=0.21.4-pre" }
Loading

0 comments on commit d0ac5de

Please sign in to comment.