Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image classification web demo with WebGPU, CPU backends #840

Merged
merged 6 commits into from
Oct 5, 2023

Conversation

antimora
Copy link
Collaborator

@antimora antimora commented Oct 2, 2023

Pull Request Template

Checklist

  • Confirm that run-checks script has been executed.

Changes

Added a new web demo example for classifying images using ndarray, candle and wgpu backends.

Testing

Tested locally in the browser. See screenshots:

WebGPU backed:

image

Ndarray:
image

Candle:
image

@louisfd
Copy link
Member

louisfd commented Oct 2, 2023

Hi @antimora
This looks amazing!
I cloned your fork and sadly when I try to execute it I get Uncaught SyntaxError: The requested module './index.js' does not provide an export named 'extractLabelsAndProbabilities' (at (index):100:9)
I'm on Chrome and MacOS so this should not be the issue, do you have any idea?

@antimora
Copy link
Collaborator Author

antimora commented Oct 2, 2023

Hi @antimora This looks amazing! I cloned your fork and sadly when I try to execute it I get Uncaught SyntaxError: The requested module './index.js' does not provide an export named 'extractLabelsAndProbabilities' (at (index):100:9) I'm on Chrome and MacOS so this should not be the issue, do you have any idea?

I am not sure why this error is showing but I re-did the index.js import to use an old fashion style import.

When you have a chance, please give a try again.

Copy link
Member

@nathanielsimard nathanielsimard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing demo, great job! I have a few comments, but nothing very important. Let me know what you think, but we can probably merge this quite soon!

examples/image-classification-web/Cargo.toml Outdated Show resolved Hide resolved
examples/image-classification-web/README.md Show resolved Hide resolved
examples/image-classification-web/index.html Outdated Show resolved Hide resolved
examples/image-classification-web/index.html Outdated Show resolved Hide resolved
examples/image-classification-web/index.html Show resolved Hide resolved
examples/image-classification-web/src/model/normalizer.rs Outdated Show resolved Hide resolved
@louisfd
Copy link
Member

louisfd commented Oct 2, 2023

When I play around for a while, changing backend then selecting an image several times, I always end up with an error:

Uncaught (in promise) RuntimeError: unreachable
    at rust_panic (image_classification_web_bg.wasm:0x12f468)
    at std::panicking::rust_panic_with_hook::h7601402c0a383194 (image_classification_web_bg.wasm:0x12b021)
    at std::panicking::begin_panic_handler::{{closure}}::he405aaeb801d5772 (image_classification_web_bg.wasm:0x12acf6)
    at std::sys_common::backtrace::__rust_end_short_backtrace::h04fac26f88d230df (image_classification_web_bg.wasm:0x12f3d3)
    at rust_begin_unwind (image_classification_web_bg.wasm:0x12d00d)
    at core::panicking::panic_fmt::h6dad0405f48e39e2 (image_classification_web_bg.wasm:0x12d46e)
    at wasm_bindgen_futures::future_to_promise::{{closure}}::{{closure}}::hab9ff4ad861eb6c2 (image_classification_web_bg.wasm:0xc2c84)
    at wasm_bindgen_futures::queue::Queue::new::{{closure}}::h268429c4d3d8462b (image_classification_web_bg.wasm:0x10ce34)
    at <dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::h6a26306e30d1963a (image_classification_web_bg.wasm:0x12e622)
    at __wbg_adapter_28 (image_classification_web.js:240:10)

@nathanielsimard
Copy link
Member

I'm not able to make the demo work on my computer (Linux Pop OS) I'm having a javascript error:

image

Both tested on Google Chrome and Firefox.

@louisfd
Copy link
Member

louisfd commented Oct 2, 2023

I'm not able to make the demo work on my computer (Linux Pop OS) I'm having a javascript error:

image

Both tested on Google Chrome and Firefox.

Strangely I get this error too on one of my Chrome profiles, but on the other it works. Don't know why.
Also, it is written in the readme that it is still only expected to work on Windows / MacOS with Chrome

@antimora
Copy link
Collaborator Author

antimora commented Oct 2, 2023

When I play around for a while, changing backend then selecting an image several times, I always end up with an error:

Uncaught (in promise) RuntimeError: unreachable
    at rust_panic (image_classification_web_bg.wasm:0x12f468)
    at std::panicking::rust_panic_with_hook::h7601402c0a383194 (image_classification_web_bg.wasm:0x12b021)
    at std::panicking::begin_panic_handler::{{closure}}::he405aaeb801d5772 (image_classification_web_bg.wasm:0x12acf6)
    at std::sys_common::backtrace::__rust_end_short_backtrace::h04fac26f88d230df (image_classification_web_bg.wasm:0x12f3d3)
    at rust_begin_unwind (image_classification_web_bg.wasm:0x12d00d)
    at core::panicking::panic_fmt::h6dad0405f48e39e2 (image_classification_web_bg.wasm:0x12d46e)
    at wasm_bindgen_futures::future_to_promise::{{closure}}::{{closure}}::hab9ff4ad861eb6c2 (image_classification_web_bg.wasm:0xc2c84)
    at wasm_bindgen_futures::queue::Queue::new::{{closure}}::h268429c4d3d8462b (image_classification_web_bg.wasm:0x10ce34)
    at <dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::h6a26306e30d1963a (image_classification_web_bg.wasm:0x12e622)
    at __wbg_adapter_28 (image_classification_web.js:240:10)

Yeah I came across some strange errors too when I immediately change and select image. I have a feeling there is a racing condition.

Initially when I implemented switch backend and immediately run inference, I had similar errors. This is something to look into this.

@nathanielsimard nathanielsimard merged commit e2a17e4 into tracel-ai:main Oct 5, 2023
5 checks passed
@nathanielsimard nathanielsimard deleted the webgpu-demo branch October 5, 2023 14:29
@AlexErrant AlexErrant mentioned this pull request Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants