Python EOFError:压缩文件在到达流结束标记之前结束 - MNIST 数据集
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40877781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
EOFError: Compressed file ended before the end-of-stream marker was reached - MNIST data set
提问by Nikhil Raghavendra
I am getting the following error when I run mnist = input_data.read_data_sets("MNIST_data", one_hot = True)
.
运行时出现以下错误mnist = input_data.read_data_sets("MNIST_data", one_hot = True)
。
EOFError: Compressed file ended before the end-of-stream marker was reached
EOFError:压缩文件在到达流结束标记之前结束
Even when I extract the file manually and place it in the MNIST_data
directory, the program is still trying to download the file instead of using the extracted file.
即使我手动提取文件并将其放入MNIST_data
目录中,程序仍会尝试下载文件而不是使用提取的文件。
When I extract the file using WinZip which is the manual way, WinZip tells me that the file is corrupt.
当我使用手动方式 WinZip 解压缩文件时,WinZip 告诉我该文件已损坏。
How do I solve this problem?
我该如何解决这个问题?
I can't even load the data set now, I still have to debug the program itself. Please help.
我现在连数据集都加载不出来,还得自己调试程序。请帮忙。
I pip installed Tensorflow and so I don't have a Tensorflow example. So I went to GitHub to get the input_data
file and saved it in the same directory as my main.py
. The error is just regarding the .gz file. The program could not extract it.
我 pip 安装了 Tensorflow,所以我没有 Tensorflow 示例。所以我去 GitHub 获取input_data
文件并将其保存在与我的main.py
. 该错误仅与 .gz 文件有关。该程序无法提取它。
runfile('C:/Users/Nikhil/Desktop/Tensor Flow/tensf.py', wdir='C:/Users/Nikhil/Desktop/Tensor Flow') Reloaded modules: input_data Extracting MNIST_data/train-images-idx3-ubyte.gz C:\Users\Nikhil\Anaconda3\lib\gzip.py:274: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future return self._buffer.read(size) Traceback (most recent call last):
File "", line 1, in runfile('C:/Users/Nikhil/Desktop/Tensor Flow/tensf.py', wdir='C:/Users/Nikhil/Desktop/Tensor Flow')
File "C:\Users\Nikhil\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile execfile(filename, namespace)
File "C:\Users\Nikhil\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Nikhil/Desktop/Tensor Flow/tensf.py", line 26, in mnist = input_data.read_data_sets("MNIST_data/", one_hot = True)
File "C:\Users\Nikhil\Desktop\Tensor Flow\input_data.py", line 181, in read_data_sets train_images = extract_images(local_file)
File "C:\Users\Nikhil\Desktop\Tensor Flow\input_data.py", line 60, in extract_images buf = bytestream.read(rows * cols * num_images)
File "C:\Users\Nikhil\Anaconda3\lib\gzip.py", line 274, in read return self._buffer.read(size)
File "C:\Users\Nikhil\Anaconda3\lib_compression.py", line 68, in readinto data = self.read(len(byte_view))
File "C:\Users\Nikhil\Anaconda3\lib\gzip.py", line 480, in read raise EOFError("Compressed file ended before the "
EOFError: Compressed file ended before the end-of-stream marker was reached
runfile('C:/Users/Nikhil/Desktop/Tensor Flow/tensf.py', wdir='C:/Users/Nikhil/Desktop/Tensor Flow') 重载模块:input_data 提取 MNIST_data/train-images-idx3-ubyte .gz C:\Users\Nikhil\Anaconda3\lib\gzip.py:274: VisibleDeprecationWarning: 将 ndim > 0 的数组转换为索引将导致将来出现错误 return self._buffer.read(size) Traceback (最近一次通话):
文件 "", line 1, in runfile('C:/Users/Nikhil/Desktop/Tensor Flow/tensf.py', wdir='C:/Users/Nikhil/Desktop/Tensor Flow')
文件“C:\Users\Nikhil\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py”,第 866 行,在运行文件 execfile(filename, namespace) 中
文件“C:\Users\Nikhil\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py”,第 102 行,在 execfile exec(compile(f.read(), filename, 'exec'),命名空间)
文件“C:/Users/Nikhil/Desktop/Tensor Flow/tensf.py”,第 26 行,在 mnist = input_data.read_data_sets("MNIST_data/", one_hot = True)
文件“C:\Users\Nikhil\Desktop\Tensor Flow\input_data.py”,第 181 行,在 read_data_sets train_images = extract_images(local_file)
文件“C:\Users\Nikhil\Desktop\Tensor Flow\input_data.py”,第 60 行,extract_images buf = bytestream.read(rows * cols * num_images)
文件“C:\Users\Nikhil\Anaconda3\lib\gzip.py”,第 274 行,读取返回 self._buffer.read(size)
文件“C:\Users\Nikhil\Anaconda3\lib_compression.py”,第 68 行,读入数据 = self.read(len(byte_view))
文件 "C:\Users\Nikhil\Anaconda3\lib\gzip.py", line 480, in read raise EOFError("压缩文件在"之前结束
EOFError:压缩文件在到达流结束标记之前结束
回答by Payas Pandey
This is because for some reason you have an incomplete download for the MNIST dataset.
这是因为出于某种原因,您对 MNIST 数据集的下载不完整。
You will have to manually delete the downloaded folder which usually resides in ~/.keras/datasets
or any path specified by you relative to this path, in your case MNIST_data
.
~/.keras/datasets
在您的情况下,您必须手动删除通常位于或您指定的相对于该路径的任何路径中的下载文件夹MNIST_data
。
Perform the following steps in the terminal (ctrl + alt + t):
在终端中执行以下步骤(ctrl + alt + t):
cd ~/.keras/datasets/
rm -rf "dataset name"
cd ~/.keras/datasets/
rm -rf "dataset name"
You should be good to go!
你应该很高兴去!
回答by Krackle
To anyone struggling, I had a similar issue. On my Mac Mojave 10.14.3.
Taking a class on UDEMY using Anaconda and Jupyter used the following to fix the issue.
Finder > Go > Go to Folder > In go to folder window input ~/.keras/datasets/fashion_mnist > delete the partially downloaded files
对于任何挣扎的人,我遇到了类似的问题。在我的 Mac Mojave 10.14.3 上。使用 Anaconda 和 Jupyter 上 UDEMY 的课程使用以下内容来解决问题。
Finder > Go > Go to Folder > In go to folder window input ~/.keras/datasets/fashion_mnist > delete the partially downloaded files
Go to GitHub and search fashion-mnist-master from https://github.com/zalandoresearch/fashion-mnist.git
转到 GitHub 并从https://github.com/zalandoresearch/fashion-mnist.git搜索 fashion-mnist-master
Download the file locate the data > fashion file and unzip the four files
下载文件找到数据>时尚文件并解压四个文件
Place the four unzipped files into the ~/.keras/datasets/fashion_mnist >
将解压后的四个文件放入 ~/.keras/datasets/fashion_mnist >
open Jupyter Lab in a new page insert the following:
在新页面中打开 Jupyter Lab 插入以下内容:
from keras.datasets import fashion_mnist
#message states using TensorFlow backend
(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()
#it will then cycle through as if the download were successful
Good luck may the odds be in your favor.
祝你好运,可能对你有利。
回答by Nayan Barde
At first, from the Keras directory remove the partially installed fashion_mnist
directory.
首先,从 Keras 目录中删除部分安装的fashion_mnist
目录。
After that, download the files from GitHub
之后,从GitHub下载文件
https://github.com/zalandoresearch/fashion-mnist/blob/master/data/fashion/train-labels-idx1-ubyte.gz
https://github.com/zalandoresearch/fashion-mnist/blob/master/data/fashion/train-labels-idx1-ubyte.gz
Place those files and the extracted files in the fashion_mnist
directory in the Keras folder.
将这些文件和提取的文件放在fashion_mnist
Keras 文件夹中的目录中。
This will solve your problem.
这将解决您的问题。
回答by Rajnish suryavanshi
It happens when you download the datasets and due to some reasons it is not downloaded. Any one struggling in windows when working with pytorch. I have resolved the same issues by deleting the folder which resides in below path
当您下载数据集并且由于某些原因未下载时会发生这种情况。任何人在使用 pytorch 时都在 Windows 中挣扎。我通过删除位于以下路径中的文件夹解决了相同的问题
C:/Users/UserName/.pytorch/foldername
Also check in your case .pytorch may not be visible due to disable of hidden file.
还要检查您的情况,由于禁用隐藏文件,.pytorch 可能不可见。
回答by Benson Mathew
I had the same issue when downloading datasets using torchvision on Windows. I was able to fix this by deleting all files from the following path: C:\Users\UserName\MNIST\raw
在 Windows 上使用 torchvision 下载数据集时遇到了同样的问题。我可以通过删除以下路径中的所有文件来解决这个问题:C:\Users\UserName\MNIST\raw
回答by AAYUSH SHAH
It is very simple in windows :
在 Windows 中非常简单:
Go to : C:\Users\Username\.keras\datasets
去 : C:\Users\Username\.keras\datasets
and then Delete the Dataset that you want to redownload or has the error
然后删除要重新下载或有错误的数据集
回答by Pikamander2
If the download gets interrupted, delete the C:/tmp/imagenet
folder and restart the download.
如果下载中断,请删除该C:/tmp/imagenet
文件夹并重新开始下载。
Also, for people who get here via Google, run the classify_image.py
file via the command line instead of using IDLE:
此外,对于通过 Google 到达这里的人,请classify_image.py
通过命令行而不是使用 IDLE运行该文件:
python classify_image.py