栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

《深度学习入门:基于Python的理论与实现》(deeplearning-from-scratch)下载mnist数据集的解决方案

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

《深度学习入门:基于Python的理论与实现》(deeplearning-from-scratch)下载mnist数据集的解决方案

在《深度学习入门:基于Python的理论与实现》章节的第三章就开始以MNIST数据集为基础编写代码。然而根据源码的操作,很有可能会出现mnist下载超时的情况。以下是解决方案:

1. 获取代码读取数据集的路径

以mnist_show.py为例:
mnist_show.py源码:

# coding: utf-8
import sys, os
sys.path.append(os.pardir)  # 为了导入父目录的文件而进行的设定
import numpy as np
from dataset.mnist import load_mnist
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(flatten=True, normalize=False)

img = x_train[0]
label = t_train[0]
print(label)  # 5

print(img.shape)  # (784,)
img = img.reshape(28, 28)  # 把图像的形状变为原来的尺寸
print(img.shape)  # (28, 28)

img_show(img)

然后就会执行load_mnist函数。
dataset目录内mnist.py文件的 load_mnist函数代码的开头:

    print("!!!!",save_file) # 打印读取的路径
    if not os.path.exists(save_file):
        init_mnist()

然后打印save_file变量,获得路径地址,一般都是默认的dataset目录内。

2. 手动下载MNIST数据集

MNIST数据集的官网,下载:

train-images-idx3-ubyte: training set images
train-labels-idx1-ubyte: training set labels
t10k-images-idx3-ubyte:  test set images
t10k-labels-idx1-ubyte:  test set labels 


保存到第一步中获取的路径。

3. 执行代码

一般都可以顺利执行了:

PS.如果自己来复现项目,一定记得要复制dataset目录到自己项目的目录下。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/350757.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号