From b179ea02e6ddfa285f1f7403f83627c6bd4e995c Mon Sep 17 00:00:00 2001 From: Cheikh Seck Date: Mon, 6 Apr 2026 01:18:35 +0000 Subject: [PATCH] fix: update model and labels URLs, normalize pixel values in image loading --- internal/vision/vision.go | 8 ++++---- packaging/vision/src/main.rs | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/internal/vision/vision.go b/internal/vision/vision.go index 8c47eee..016ba4d 100644 --- a/internal/vision/vision.go +++ b/internal/vision/vision.go @@ -24,8 +24,8 @@ import ( const ( wasmURL = "https://raw.githubusercontent.com/cheikh2shift/godex/main/packaging/vision/vision.wasm" - modelURL = "https://huggingface.co/onnxmodelzoo/efficientnet-lite4-11/resolve/main/efficientnet-lite4-11.onnx" - labelsURL = "https://raw.githubusercontent.com/anishathalye/imagenet-simple-labels/master/imagenet-simple-labels.json" + modelURL = "https://huggingface.co/onnx-community/mobilenetv3_large_100.miil_in21k_ft_in1k/resolve/main/onnx/model.onnx" + labelsURL = "https://huggingface.co/datasets/huggingface/label-files/raw/main/imagenet-1k-id2label.json" ) type Summary struct { @@ -109,8 +109,8 @@ func requiredPaths() (runtimePaths, error) { return runtimePaths{ BaseDir: base, WasmPath: filepath.Join(base, "vision.wasm"), - ModelPath: filepath.Join(base, "efficientnet-lite4.onnx"), - LabelsPath: filepath.Join(base, "labels.json"), + ModelPath: filepath.Join(base, "mobilenetv3-large.onnx"), + LabelsPath: filepath.Join(base, "imagenet-labels.json"), }, nil } diff --git a/packaging/vision/src/main.rs b/packaging/vision/src/main.rs index 131d02f..7874bae 100644 --- a/packaging/vision/src/main.rs +++ b/packaging/vision/src/main.rs @@ -36,7 +36,6 @@ fn main() -> Result<()> { let model = tract_onnx::onnx() .model_for_path(model_path) .with_context(|| format!("failed to load model: {}", model_path))? - .with_input_fact(0, InferenceFact::dt_shape(f32::datum_type(), tvec!(1, 3, INPUT_SIZE as usize, INPUT_SIZE as usize)))? .into_optimized()? .into_runnable()?; @@ -97,15 +96,15 @@ fn load_image>(path: P) -> Result { let idx = (0usize * INPUT_SIZE as usize * INPUT_SIZE as usize) + (y as usize * INPUT_SIZE as usize) + (x as usize); - data[idx] = (pixel[0] as f32 - 127.0) / 128.0; + data[idx] = pixel[0] as f32 / 255.0; let idx = (1usize * INPUT_SIZE as usize * INPUT_SIZE as usize) + (y as usize * INPUT_SIZE as usize) + (x as usize); - data[idx] = (pixel[1] as f32 - 127.0) / 128.0; + data[idx] = pixel[1] as f32 / 255.0; let idx = (2usize * INPUT_SIZE as usize * INPUT_SIZE as usize) + (y as usize * INPUT_SIZE as usize) + (x as usize); - data[idx] = (pixel[2] as f32 - 127.0) / 128.0; + data[idx] = pixel[2] as f32 / 255.0; } }