robertknight / ocrs

Rust library and CLI tool for OCR (extracting text from images)
Apache License 2.0
1.09k stars 44 forks source link

ocr-node example errors with unreachable code (possibly due to rten v0.11?) #93

Closed Robjam closed 1 month ago

Robjam commented 1 month ago

I cloned the project and after the following steps tried the ocr-node example and got the error:

❯ node index.js text-detection.rten text-recognition.rten ../../../ocrs/examples/rust-book.jpg
wasm://wasm/ocrs.wasm-0048fb06:1

RuntimeError: unreachable
    at ocrs.wasm.__rust_start_panic (wasm://wasm/ocrs.wasm-0048fb06:wasm-function[1845]:0xf1583)
    at ocrs.wasm.rust_panic (wasm://wasm/ocrs.wasm-0048fb06:wasm-function[1711]:0xf0f9d)
    at ocrs.wasm.std::panicking::rust_panic_with_hook::h6731baa78621a747 (wasm://wasm/ocrs.wasm-0048fb06:wasm-function[955]:0xde7c4)
    at ocrs.wasm.std::panicking::begin_panic_handler::{{closure}}::hb6cd8464ed39ae71 (wasm://wasm/ocrs.wasm-0048fb06:wasm-function[1123]:0xe6b81)
    at ocrs.wasm.std::sys_common::backtrace::__rust_end_short_backtrace::hbdf3ddeb21a1e747 (wasm://wasm/ocrs.wasm-0048fb06:wasm-function[1808]:0xf149f)
    at ocrs.wasm.rust_begin_unwind (wasm://wasm/ocrs.wasm-0048fb06:wasm-function[1381]:0xedfe6)
    at ocrs.wasm.core::panicking::panic_fmt::h5c7ce52813e94bcd (wasm://wasm/ocrs.wasm-0048fb06:wasm-function[1410]:0xee6dd)
    at ocrs.wasm.std::time::Instant::now::ha67cff2d60f49302 (wasm://wasm/ocrs.wasm-0048fb06:wasm-function[1439]:0xeed82)
    at ocrs.wasm.rten::graph::Graph::run_plan::hb41e2a985b803f13 (wasm://wasm/ocrs.wasm-0048fb06:wasm-function[10]:0x12dcc)
    at ocrs.wasm.rten::threading::ThreadPool::run::ha413ceca52feeedc (wasm://wasm/ocrs.wasm-0048fb06:wasm-function[823]:0xd5d10)

Node.js v20.2.0

(slightly pedantic) Steps for reproduction:

  1. git checkout main
  2. cargo install wasm-bindgen-cli --version 0.2.89
  3. cargo install wasm-opt
  4. rustup target add wasm32-unknown-unknown
  5. make wasm
  6. cd ocrs/examples
  7. sh ./download-models.sh
  8. cp text-detection.rten ../../js/examples/ocr-node
  9. cp text-recognition.rten ../../js/examples/ocr-node
  10. node index.js text-detection.rten text-recognition.rten ../../../ocrs/examples/rust-book.jpg

I looked through the commit log and found that I can get a working wasm build with commit: 7e00182983b571fefd8302e10823dc4a09754140 git checkout 7e00182983b571fefd8302e10823dc4a09754140

robertknight commented 1 month ago

Thanks for the report. This is indeed a bug in rten v0.11.0. I have updated the dependency to a patch release which resolves the issue. Please let me know if you still encounter issues running the example.