mirror of https://github.com/tracel-ai/burn.git
chore(web): better panic (#1051)
This commit is contained in:
parent
d9f93d31b4
commit
ef09b637b9
|
@ -74,6 +74,7 @@ wasm-bindgen = "0.2.88"
|
|||
wasm-bindgen-futures = "0.4.38"
|
||||
wasm-logger = "0.2.0"
|
||||
wasm-timer = "0.2.5"
|
||||
console_error_panic_hook = "0.1.7"
|
||||
|
||||
|
||||
# WGPU stuff
|
||||
|
|
|
@ -29,6 +29,7 @@ wasm-bindgen = { workspace = true }
|
|||
wasm-bindgen-futures = { workspace = true }
|
||||
wasm-logger = { workspace = true }
|
||||
wasm-timer = { workspace = true }
|
||||
console_error_panic_hook = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
# Used to generate code from ONNX model
|
||||
|
|
|
@ -20,6 +20,13 @@ use serde::Serialize;
|
|||
use wasm_bindgen::prelude::*;
|
||||
use wasm_timer::Instant;
|
||||
|
||||
#[wasm_bindgen(start)]
|
||||
pub fn start() {
|
||||
// Initialize the logger so that the logs are printed to the console
|
||||
console_error_panic_hook::set_once();
|
||||
wasm_logger::init(wasm_logger::Config::default());
|
||||
}
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
/// The model is loaded to a specific backend
|
||||
pub enum ModelType {
|
||||
|
@ -49,9 +56,6 @@ impl ImageClassifier {
|
|||
/// Constructor called by JavaScripts with the new keyword.
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new() -> Self {
|
||||
// Initialize the logger so that the logs are printed to the console
|
||||
wasm_logger::init(wasm_logger::Config::default());
|
||||
|
||||
log::info!("Initializing the image classifier");
|
||||
|
||||
Self {
|
||||
|
|
|
@ -20,7 +20,8 @@ burn = { path = "../../burn", default-features = false }
|
|||
serde = { workspace = true }
|
||||
wasm-bindgen = { workspace = true }
|
||||
wasm-bindgen-futures = { workspace = true }
|
||||
js-sys = "0.3.65"
|
||||
js-sys = { workspace = true }
|
||||
console_error_panic_hook = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
pollster = { workspace = true }
|
||||
|
|
|
@ -11,6 +11,11 @@ use crate::state::{build_and_load_model, Backend};
|
|||
|
||||
use burn::tensor::Tensor;
|
||||
|
||||
#[cfg_attr(target_family = "wasm", wasm_bindgen(start))]
|
||||
pub fn start() {
|
||||
console_error_panic_hook::set_once();
|
||||
}
|
||||
|
||||
/// Mnist structure that corresponds to JavaScript class.
|
||||
/// See:[exporting-rust-struct](https://rustwasm.github.io/wasm-bindgen/contributing/design/exporting-rust-struct.html)
|
||||
#[cfg_attr(target_family = "wasm", wasm_bindgen)]
|
||||
|
@ -23,6 +28,7 @@ impl Mnist {
|
|||
/// Constructor called by JavaScripts with the new keyword.
|
||||
#[cfg_attr(target_family = "wasm", wasm_bindgen(constructor))]
|
||||
pub fn new() -> Self {
|
||||
console_error_panic_hook::set_once();
|
||||
Self { model: None }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue