tracel-ai/burn · error
Could not get cache directory
Error message
Could not get cache directory
What it means
Generic guard panic in get_cache_dir: dirs::cache_dir() returned None, meaning the platform cache directory could not be determined. On Linux this happens when XDG_CACHE_HOME is set but empty or non-absolute (or HOME is unavailable); on other platforms when the OS API for the user cache path fails. The faulty input is the environment/platform configuration, not the code's arguments. It surfaces when load_pretrained_weights tries to place downloaded LPIPS weights.
Source
Thrown at crates/burn-train/src/metric/vision/lpips/weights.rs:47
LpipsNet::Vgg => LPIPS_VGG_URL,
LpipsNet::Alex => LPIPS_ALEX_URL,
LpipsNet::Squeeze => LPIPS_SQUEEZE_URL,
}
}
/// Get the download URL for backbone ImageNet weights.
pub fn get_backbone_weights_url(net: LpipsNet) -> &'static str {
match net {
LpipsNet::Vgg => VGG16_IMAGENET_URL,
LpipsNet::Alex => ALEXNET_IMAGENET_URL,
LpipsNet::Squeeze => SQUEEZENET_IMAGENET_URL,
}
}
/// Get the cache directory for LPIPS weights.
fn get_cache_dir() -> PathBuf {
let cache_dir = dirs::cache_dir()
.expect("Could not get cache directory")
.join("burn-dataset")
.join("lpips");
if !cache_dir.exists() {
create_dir_all(&cache_dir).expect("Failed to create cache directory");
}
cache_dir
}
/// Download file if not cached and return the cache path.
fn download_if_needed(url: &str, cache_path: &PathBuf, message: &str) {
if !cache_path.exists() {
let bytes = download_file_as_bytes(url, message);
let mut file = File::create(cache_path).expect("Failed to create cache file");
file.write_all(&bytes).expect("Failed to write weights");
}
}View on GitHub (pinned to d16f7ba2ed)
Solutions
- Ensure XDG_CACHE_HOME (Linux) or the user home directory is set
- Run in an environment with a resolvable user cache dir
- Override by providing weights manually if the environment lacks a cache dir
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at crates/burn-train/src/metric/vision/lpips/weights.rs:47 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/ca8ca64f20f0f32f.
Report an issue: GitHub.