tracel-ai / burn

Burn is a new comprehensive dynamic Deep Learning Framework built using Rust with extreme flexibility, compute efficiency and portability as its primary goals.
https://burn.dev
Apache License 2.0
8.34k stars 407 forks source link

ONNX Import issue #2037

Open Codewithteju opened 1 month ago

Codewithteju commented 1 month ago

I am trying to import my onnx model into rust project using burn framework and did the exact steps from this book : https://burn.dev/book/import/onnx-model.html and managed the build.rs and mod.rs according to my model but getting this error : error: failed to run custom build command for onnx v0.1.0 (C:\Users\ASUS\onnx)

Caused by: process didn't exit successfully: C:\Users\ASUS\onnx\target\debug\build\onnx-ae1ba660fde49fe2\build-script-build (exit code: 101) --- stdout INFO burn_import::onnx::to_burn: Starting to convert ONNX to Burn DEBUG burn_import::onnx::to_burn: Output directory: "C:\Users\ASUS\onnx\target\debug\build\onnx-657c7c26da5fb01e\out\model/" INFO burn_import::onnx::to_burn: Converting "src/model/retinaface.onnx" DEBUG burn_import::onnx::to_burn: Input file name: "retinaface" DEBUG burn_import::onnx::to_burn: Output file: "C:\Users\ASUS\onnx\target\debug\build\onnx-657c7c26da5fb01e\out\model/retinaface" INFO burn_import::onnx::to_burn: Generating model from "src/model/retinaface.onnx" DEBUG burn_import::onnx::to_burn: Development mode: false DEBUG burn_import::onnx::to_burn: Output file: "C:\Users\ASUS\onnx\target\debug\build\onnx-657c7c26da5fb01e\out\model/retinaface" INFO burn_import::onnx::from_onnx: Parsing ONNX file: src/model/retinaface.onnx DEBUG burn_import::onnx::from_onnx: Number of nodes: 283 DEBUG burn_import::onnx::from_onnx: Number of inputs: 1 DEBUG burn_import::onnx::from_onnx: Number of initializers: 112 DEBUG burn_import::onnx::from_onnx: Number of outputs: 3 ERROR burn_import::logger: PANIC => panicked at C:\Users\ASUS.cargo\registry\src\index.crates.io-6f17d22bba15001f\burn-import-0.13.2\src\onnx\from_onnx.rs:68:61: called Result::unwrap() on an Err value: VariantNotFound

--- stderr thread 'main' panicked at C:\Users\ASUS.cargo\registry\src\index.crates.io-6f17d22bba15001f\burn-import-0.13.2\src\onnx\from_onnx.rs:68:61: called Result::unwrap() on an Err value: VariantNotFound note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

And in mod.rs, the compiler is throwing a error : [{ "resource": "/C:/Users/ASUS/onnx/src/model/mod.rs", "owner": "rustc", "code": { "value": "macro-error", "target": { "$mid": 1, "path": "/manual.html", "scheme": "https", "authority": "rust-analyzer.github.io", "fragment": "macro-error" } }, "severity": 8, "message": "OUT_DIR not set, enable \"build scripts\" to fix", "source": "rust-analyzer", "startLineNumber": 2, "startColumn": 5, "endLineNumber": 2, "endColumn": 12 }]

Cargo.toml: [package] name = "onnx" version = "0.1.0" edition = "2021"

[features] default = ["embedded-model"]

embedded-model = []

[dependencies] burn = { version = "0.13.2", features = ["ndarray", "dataset", "vision"] } burn-ndarray = "0.13.2" serde = { version = "1.0.204" }

[build-dependencies] burn-import = "0.13.2"

image

Processor Intel(R) Core(TM) i5-10300H CPU @ 2.50GHz 2.50 GHz Installed RAM 16.0 GB (15.8 GB usable) System type 64-bit operating system, x64-based processor Rust version: rustc 1.79.0 (129f3b996 2024-06-10) cargo version: cargo 1.79.0 (ffa9cf99a 2024-06-03) Rust-Analyzer : v0.4.2040 (pre-release)

laggui commented 1 month ago

Had a glimpse at the issue with OP.

The error comes from the input data type:

name: images
tensor: uint8[batch, 1080, 1920, 3]

We don't have uint8 tensor support.

laggui commented 1 month ago

I've manually edited the graph to take a float input instead to check for any further incompatibilities.

I stumbled upon the gather with scalar input issue as described in #1915.

Using onnx-simplifier, the model is simplified (with some problematic nodes removed) but some gather nodes with scalar (followed by unsqueeze of course..). So the linked issue persists.