Keras载入mnist数据集出错问题解决方案

  1. 找到本地keras目录下的mnist.py文件
    通常在这个目录下。
    ..\Anaconda3\Lib\site-packages\keras\datasets

  2. 下载mnist.npz文件到本地
    下载链接如下。
    https://pan.baidu.com/s/1C3c2Vn-_616GqeEn7hQQ2Q

  3. 修改mnist.py文件为以下内容,并保存

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from ..utils.data_utils import get_file
import numpy as np

#cui 2018.07.08,修改

def load_data(path='mnist.npz'):
    """Loads the MNIST dataset.

    # Arguments
        path: path where to cache the dataset locally
            (relative to ~/.keras/datasets).

    # Returns
        Tuple of Numpy arrays: `(x_train, y_train), (x_test, y_test)`.
    """
    path = 'E:/Data/Mnist/mnist.npz' #此处的path为你刚刚防止mnist.py的目录。注意斜杠
    f = np.load(path)
    x_train, y_train = f['x_train'], f['y_train']
    x_test, y_test = f['x_test'], f['y_test']
    f.close()
    return (x_train, y_train), (x_test, y_test)

** OK,去尽请使用吧 **

转载于:https://www.cnblogs.com/shinny/p/9283372.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值