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