如何解决Pytorch torchvision FasionMNIST 数据集无法加载
我在运行 vanilla Python 3.9.5 的 Windows 10 机器上使用 IDLE。我正在关注 here 的一些 Pytorch 教程。一切正常,直到 Datasets & Dataloaders 我尝试下载 FashionMNIST 数据集。
我首先使用 pip 安装了 torchvision 包。
pip install torchvision===0.9.1+cu111 -f https://download.pytorch.org/whl/torch_stable.html
以下是我安装的软件包。
Package Version
----------------- -----------
cycler 0.10.0
keyboard 0.13.5
kiwisolver 1.3.1
matplotlib 3.4.1
MouseInfo 0.1.3
mss 6.1.0
numpy 1.20.2
opencv-python 4.5.2.52
Pillow 8.2.0
pip 21.1.1
PyAutoGUI 0.9.52
PyGetWindow 0.0.9
PyMsgBox 1.0.9
pyparsing 2.4.7
pyperclip 1.8.2
PyRect 0.1.4
PyScreeze 0.1.27
python-dateutil 2.8.1
PyTweening 1.0.3
setuptools 56.0.0
six 1.16.0
torch 1.8.1+cu111
torchaudio 0.8.1
torchvision 0.9.1+cu111
typing-extensions 3.10.0.0
我尝试运行以下脚本。
import torch
from torch.utils.data import Dataset
from torchvision import datasets
from torchvision.transforms import ToTensor
import matplotlib.pyplot as plt
training_data = datasets.FashionMNIST(
root="C:/../../../Python/LearningPytorch/data",train=True,download=True,transform=ToTensor()
)
test_data = datasets.FashionMNIST(
root="C:/../../../Python/LearningPytorch/data",train=False,transform=ToTensor()
)
一切似乎都以预期的输出开始。
Python 3.9.5 (tags/v3.9.5:0a7dcbd,May 3 2021,17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help","copyright","credits" or "license()" for more information.
>>>
= RESTART: C:/../../../Python/LearningPytorch/DatasetsAndDataLoaders.py
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz to C:/../../../Python/LearningPytorch/data\FashionMNIST\raw\train-images-idx3-ubyte.gz
= RESTART: C:/../../../Python/LearningPytorch/DatasetsAndDataLoaders.py
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz to C:/../../../Python/LearningPytorch/data\FashionMNIST\raw\train-images-idx3-ubyte.gz
0.0%0.0%0.0%0.0%0.0%0.0%0.0%0.0%0.0%0.0%0.0%0.0%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.1%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.2%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%0.3%...
大约半小时后,在大约 50% 的下载量时,它失败了。我有很棒的互联网,整个过程中速度下降了 500 Mbps。
我收到以下错误消息。
Traceback (most recent call last):
File "C:\..\..\..\DatasetsAndDataLoaders.py",line 8,in <module>
training_data = datasets.FashionMNIST(
File "C:\..\..\..\Python\Python39\lib\site-packages\torchvision\datasets\mnist.py",line 85,in __init__
self.download()
File "C:\..\..\..\Python\Python39\lib\site-packages\torchvision\datasets\mnist.py",line 155,in download
download_and_extract_archive(
File "C:\..\..\..\Python\Python39\lib\site-packages\torchvision\datasets\utils.py",line 316,in download_and_extract_archive
download_url(url,download_root,filename,md5)
File "C:\..\..\..\Python\Python39\lib\site-packages\torchvision\datasets\utils.py",line 142,in download_url
raise e
File "C:\..\..\..\Python\Python39\lib\site-packages\torchvision\datasets\utils.py",line 134,in download_url
_urlretrieve(url,fpath)
File "C:\..\..\..\Python\Python39\lib\site-packages\torchvision\datasets\utils.py",line 31,in _urlretrieve
for chunk in iter(lambda: response.read(chunk_size),""):
File "C:\..\..\..\Python\Python39\lib\site-packages\torchvision\datasets\utils.py",in <lambda>
for chunk in iter(lambda: response.read(chunk_size),""):
File "C:\..\..\..\Python\Python39\lib\http\client.py",line 455,in read
n = self.readinto(b)
File "C:\..\..\..\Python\Python39\lib\http\client.py",line 499,in readinto
n = self.fp.readinto(b)
File "C:\..\..\..\Python\Python39\lib\socket.py",line 704,in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
单个下载的 gzip 文件的一部分可以在 C:......\Python\LearningPytorch\data\FashionMNIST\raw 中找到 数据/FashionMNIST/raw/train-images-idx3-ubyte.gz
我尝试从 other sources 下载,仅替换下载过程中创建的文件夹结构中的数据。这也不起作用。
这里出了什么问题?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。