fix: update model and labels URLs, normalize pixel values in image loading

This commit is contained in:
Cheikh Seck committed 2026-04-06 01:18:35 +00:00
1 parent 6e5fa89dde
commit b179ea02e6
2 files changed
+7 -8

No files matched your search

+4 -4
View File
@@ -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
}
+3 -4
View File
@@ -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<P: AsRef<Path>>(path: P) -> Result<Tensor> {
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;
}
}