You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

加载Fashion MNIST数据集时遭遇EOFError问题,重新下载文件无法解决

Fixing EOFError When Loading Fashion MNIST Dataset in TensorFlow

Hey there, sorry to hear you're stuck with this EOFError even after deleting and re-downloading the dataset. Let's walk through some other troubleshooting steps that should help resolve this issue:

  • Manually download and replace dataset files
    First, locate TensorFlow's default storage path for Fashion MNIST:

    • Windows: C:\Users\<YourUsername>\.keras\datasets\fashion-mnist
    • macOS/Linux: ~/.keras/datasets/fashion-mnist

    Download the four required dataset files (ensure they're fully downloaded and not corrupted—check file sizes: ~26MB for train-images-idx3-ubyte.gz, ~29KB for train-labels-idx1-ubyte.gz, ~4.3MB for t10k-images-idx3-ubyte.gz, ~5KB for t10k-labels-idx1-ubyte.gz). Place these files into the default path, overwriting any existing corrupted files, then re-run your original code.

  • Load dataset from a custom path
    If the default directory has read/write issues, download the files to a custom folder and use direct file reading instead of TensorFlow's load_data():

    import tensorflow as tf
    from tensorflow import keras
    import numpy as np
    import gzip
    
    # Replace with your custom folder path
    custom_data_path = "path/to/your/fashion-mnist-files/"
    
    # Load training data
    with gzip.open(custom_data_path + 'train-labels-idx1-ubyte.gz', 'rb') as lbpath:
        train_labels = np.frombuffer(lbpath.read(), np.uint8, offset=8)
    with gzip.open(custom_data_path + 'train-images-idx3-ubyte.gz', 'rb') as imgpath:
        train_images = np.frombuffer(imgpath.read(), np.uint8, offset=16).reshape(len(train_labels), 28, 28)
    
    # Load test data
    with gzip.open(custom_data_path + 't10k-labels-idx1-ubyte.gz', 'rb') as lbpath:
        test_labels = np.frombuffer(lbpath.read(), np.uint8, offset=8)
    with gzip.open(custom_data_path + 't10k-images-idx3-ubyte.gz', 'rb') as imgpath:
        test_images = np.frombuffer(imgpath.read(), np.uint8, offset=16).reshape(len(test_labels), 28, 28)
    
  • Check network and proxy settings
    Incomplete downloads often happen due to unstable networks or proxy/firewall interference:

    • Temporarily disable any proxy servers if you're using them
    • Switch to a stable wired network, delete the existing corrupted dataset files, and re-run the download code
  • Update TensorFlow and dependencies
    Older TensorFlow versions might have bugs in the dataset download pipeline. Update to the latest stable version:

    pip install --upgrade tensorflow numpy gzip
    

    After updating, delete the old dataset files and try loading again.

Give these steps a shot—one of them should get your dataset loading correctly.

内容的提问来源于stack exchange,提问作者Slimshady

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 14:47:34