APACHE-2.0 License
[!NOTE] This library is a work in progress and is likely to change
This repo is split into 2 parts:
yolo-rs-wasm
: A library to process images and videos in WasmEdge, using trained YoloV8 weightsyolo-rs-video-plugin
: A WasmEdge Plugin to load videos, split out frames, pass frames yolo-rs-wasm
, and re-assemble frames with detection information drawn onto the framewasmedge
built with the WASI-NN Plugin
https://wasmedge.org/docs/start/install
https://wasmedge.org/docs/start/install/#wasi-nn-plug-in-with-pytorch-backend
This library relies on ffmpeg for video processing,
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends \
clang \
libavcodec-dev \
libavdevice-dev \
libavfilter-dev \
libavformat-dev \
libavutil-dev \
pkg-config
Rust outputs unoptimized wasm by default, wasmedge has an Ahead of Time compiler that can improve the performance significantly !
From project root ./
wasmedge compile ./target/wasm32-wasi/release/examples/image-inference.wasm ./image-inference-optimized.wasm
If you are running into performance issues with your WASM binary, consider this a first port of call for improving your runtime execution.
You can read more on the AOT compiler here https://wasmedge.org/docs/start/build-and-run/aot/
From directory ./yolo-rs-wasm
cargo build --release --example image-inference
From project root ./
wasmedge --dir .:. ./image-inference-optimized.wasm \
--model-path ./yolo-rs-wasm/example_inputs/yolov8n.torchscript \
--image-path ./yolo-rs-wasm/example_inputs/busy_street.png \
--class-names-path ./yolo-rs-wasm/example_inputs/class_names
Note: We are running the optimized WASM binary in the command above, if you wish to run the unoptimized binary for comparison please use the path ./target/wasm32-wasi/release/examples/image-inference.wasm
From directory ./yolo-rs-wasm
cargo build --release --example video-inference
From directory ./yolo-rs-video-plugin
cargo build --release
From project root ./
WASMEDGE_PLUGIN_PATH=./target/x86_64-unknown-linux-gnu/release/libyolo_rs_video_plugin.so \
wasmedge --dir .:. \
./video-inference-optimized.wasm \
--model-path ./yolo-rs-wasm/example_inputs/yolov8n.torchscript \
--input-video-path ./yolo-rs-wasm/example_inputs/times_square.mp4 \
--output-video-path ./yolo-rs-wasm/example_inputs/times_square_output.mp4 \
--class-names-path ./yolo-rs-wasm/example_inputs/class_names