加载Fashion MNIST数据集时遭遇EOFError问题,重新下载文件无法解决
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 fortrain-labels-idx1-ubyte.gz, ~4.3MB fort10k-images-idx3-ubyte.gz, ~5KB fort10k-labels-idx1-ubyte.gz). Place these files into the default path, overwriting any existing corrupted files, then re-run your original code.- Windows:
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'sload_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 gzipAfter 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

