gpt4 book ai didi

python - HTTP 错误 503 : Service Unavailable when trying to download MNIST data

转载 作者:行者123 更新时间:2023-12-04 04:24:59 42 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





HTTP Error when trying to download MNIST data

(7 个回答)


5 个月前关闭。




我正在尝试运行我一周前在 Google Colab 上编写的代码(并且有效),但由于某种原因我现在收到此错误。

#libraries
import torch
import torchvision
from torchvision import datasets, transforms
import torch.nn as nn

train_loader = torch.utils.data.DataLoader(
torchvision.datasets.MNIST(root='./data', train=True, download=True,
transform=torchvision.transforms.Compose([
torchvision.transforms.ToTensor(),
torchvision.transforms.Normalize(
(0.1307,), (0.3081,))
])),
batch_size=batch_size_train, shuffle=True)

test_loader = torch.utils.data.DataLoader(
torchvision.datasets.MNIST(root='./data', train=False, download=True,
transform=torchvision.transforms.Compose([
torchvision.transforms.ToTensor(),
torchvision.transforms.Normalize(
(0.1307,), (0.3081,))
])),
batch_size=batch_size_test, shuffle=True)
输出:
Downloading http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz to ./data/MNIST/raw/train-images-idx3-ubyte.gz
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
<ipython-input-3-03d990013546> in <module>()
6 torchvision.transforms.ToTensor(),
7 torchvision.transforms.Normalize(
----> 8 (0.1307,), (0.3081,))
9 ])),
10 batch_size=batch_size_train, shuffle=True)

11 frames
/usr/lib/python3.7/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
647 class HTTPDefaultErrorHandler(BaseHandler):
648 def http_error_default(self, req, fp, code, msg, hdrs):
--> 649 raise HTTPError(req.full_url, code, msg, hdrs, fp)
650
651 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 503: Service Unavailable
我不完全确定出了什么问题。他们可以移动数据集吗?
更新:
看起来你不能访问 mnist 数据集 here不再

最佳答案

找到解决方案 here .
出于某种原因,LeCun 的网站给出了一个错误,所以这是获取数据集的另一种方法。

!wget www.di.ens.fr/~lelarge/MNIST.tar.gz
!tar -zxvf MNIST.tar.gz

from torchvision.datasets import MNIST

transform = transforms.Compose([transforms.ToTensor()])

train_data = MNIST(root = './', train=True, download=True, transform=transform)
val_data = MNIST(root = './', train=False, download=True, transform=transform)

关于python - HTTP 错误 503 : Service Unavailable when trying to download MNIST data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66646604/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com