在学习神经网络是时,读入mnist数据集时总是出现错误,测试了各种·方法都不能有效的解决
代码如下
import sys,os
sys.path.append(os.pardir)
from dataset.mnist import load_mnist
( x_train, t_train), (x_test, t_test) = load_mnist(normalize=False, flatten=True)
print(x_train.shape)
print(t_train.shape)
print(x_test.shape)
print(t_test.shape)
import numpy as np
from PIL import Image
def img_show(img):
pil_img=Image.fromarray(np.uint8(img))
pil_img.show()
( x_train, t_train), (x_test, t_test) = load_mnist(normalize=False, flatten=True)
img=x_train[0]
lable=t_train[0]
print(lable)
print(img.shape) #(784,)
img=img.reshape(28,28) #把图片的形状变为原来的尺寸
print(img.shape) #28*28
img_show()
错误是这样
Downloading t10k-labels-idx1-ubyte.gz ...
Traceback (most recent call last):
File "E:\pycharm\ch3\minst_show.py", line 4, in <module>
( x_train, t_train), (x_test, t_test) = load_mnist(normalize=False, flatten=True)
File "E:\pycharm\dataset\mnist.py", line 106, in load_mnist
init_mnist()
File "E:\pycharm\dataset\mnist.py", line 75, in init_mnist
download_mnist()
File "E:\pycharm\dataset\mnist.py", line 42, in download_mnist
_download(v)
File "E:\pycharm\dataset\mnist.py", line 37, in _download
urllib.request.urlretrieve(url_base + file_name, file_path)
File "C:\Python\Python39\lib\urllib\request.py", line 239, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "C:\Python\Python39\lib\urllib\request.py", line 214, in urlopen
return opener.open(url, data, timeout)
File "C:\Python\Python39\lib\urllib\request.py", line 523, in open
response = meth(req, response)
File "C:\Python\Python39\lib\urllib\request.py", line 632, in http_response
response = self.parent.error(
File "C:\Python\Python39\lib\urllib\request.py", line 561, in error
return self._call_chain(*args)
File "C:\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
result = func(*args)
File "C:\Python\Python39\lib\urllib\request.py", line 641, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 503: Service Unavailable