tracel-ai/burn · error

Failed to create cache file

Error message

Failed to create cache file

What it means

I/O guard in the FID metric's weight downloader: creating the cache file (in the burn-dataset/fid cache dir) to store downloaded Inception weights failed, so the download path panics rather than continue without cached weights.

Source

Thrown at crates/burn-train/src/metric/vision/fid/weights.rs:27

const INCEPTION_WEIGHTS_URL: &str = "https://github.com/mseitzer/pytorch-fid/releases/download/fid_weights/pt-inception-2015-12-05-6726825d.pth";

fn get_cache_dir() -> PathBuf {
    let cache_dir = dirs::cache_dir()
        .expect("Could not get cache directory")
        .join("burn-dataset")
        .join("fid");

    if !cache_dir.exists() {
        create_dir_all(&cache_dir).expect("Failed to create cache directory");
    }

    cache_dir
}

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 pytorch-fid InceptionV3 weights.
///
/// Weights are cached in `~/.cache/burn-dataset/fid/`.
pub fn load_pretrained_weights(mut fid: Fid) -> Fid {
    let cache_dir = get_cache_dir();
    let cache_path = cache_dir.join("pt-inception-2015-12-05-6726825d.pth");

    download_if_needed(
        INCEPTION_WEIGHTS_URL,
        &cache_path,
        "Downloading InceptionV3 weights for FID...",
    );

    // PyTorch keys use "Conv2d_1a_3x3.*" etc, our model nests them under "extractor.*"

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Check permissions and free space in the system cache directory
  2. Ensure `dirs::cache_dir()` resolves to a writable location
  3. Pre-place the weights file in the cache path to skip downloading
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/burn-train/src/metric/vision/fid/weights.rs:27 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/bf3364c4e74c67ed. Report an issue: GitHub.