tracel-ai/burn · error

Failed to create cache directory

Error message

Failed to create cache directory

What it means

I/O guard in the LPIPS weights loader: creating the burn-dataset/lpips cache directory failed (permissions or path issues), so obtaining the cache dir panics instead of proceeding to download weights.

Source

Thrown at crates/burn-train/src/metric/vision/lpips/weights.rs:52

/// 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");
    }
}

/// Download and load pretrained weights into an LPIPS module.
///
/// This loads both:
/// 1. ImageNet pretrained backbone weights (VGG16/AlexNet/SqueezeNet)

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Check write permissions on the parent cache directory
  2. Ensure no file exists at the directory path blocking creation
  3. Create the directory manually with correct ownership
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/burn-train/src/metric/vision/lpips/weights.rs:52 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/8ad025b7a459e53a. Report an issue: GitHub.