Path: blob/main/crates/wasi-nn/tests/check/onnx.rs
1693 views
use super::{DOWNLOAD_LOCK, artifacts_dir, download};1use anyhow::{Context, Result};2use std::{env, fs};34/// Return `Ok` if we find the cached MobileNet test artifacts; this will5/// download the artifacts if necessary.6pub fn are_artifacts_available() -> Result<()> {7let _exclusively_retrieve_artifacts = DOWNLOAD_LOCK.lock().unwrap();89const ONNX_BASE_URL: &str = "https://github.com/onnx/models/raw/bec48b6a70e5e9042c0badbaafefe4454e072d08/validated/vision/classification/mobilenet/model/mobilenetv2-10.onnx?download=";1011let artifacts_dir = artifacts_dir();12if !artifacts_dir.is_dir() {13fs::create_dir(&artifacts_dir)?;14}1516for (from, to) in [(ONNX_BASE_URL.to_string(), "model.onnx")] {17let local_path = artifacts_dir.join(to);18if !local_path.is_file() {19download(&from, &local_path).with_context(|| "unable to retrieve test artifact")?;20} else {21println!("> using cached artifact: {}", local_path.display())22}23}2425// Copy image from source tree to artifact directory.26let image_path = env::current_dir()?27.join("tests")28.join("fixtures")29.join("000000062808.rgb");30let dest_path = artifacts_dir.join("000000062808.rgb");31fs::copy(&image_path, &dest_path)?;32Ok(())33}343536