首先,必须向各位强调的是:该数据集名字叫MNIST,而非MINIST~ 我之前就一直弄错了! 哈哈~
网上有很多使用MNIST数据集的教程,要么太麻烦,要么需要翻墙下载,很慢。 在这里分享一下我找到的最方便的方法
1 下载数据集并解压。
法1 从这个百度云链接下载
没有网络限制会比较快: 链接: https://pan.baidu.com/s/1ydcCsPBlP6U9Hw52TMnhkw 提取码: 8zjp
法2 (需要翻墙) 从MNIST官网中下载下图四个文件,下载速度很慢!
下载的是4个.gz格式的压缩包
解压后得到四个新文件
之前的4个.gz压缩包就可以删除了
2 新建一个.py文件,起名为 input_data.py
将下面的代码复制粘贴进input_data.py中
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Functions for downloading and reading MNIST data."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import gzip
import os
import tempfile
import numpy
from six.moves import urllib
from six.moves import xrange # pylint: disable=redefined-builtin
import tensorflow as tf
from tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets
3 建立你的python项目,将input_data.py放在你的项目中
4 在你的python文件中(我的就是main.py,需要和input_data.py在头一个目录下)使用input_data
import tensorflow as tf
import input_data
# 下载并载入MNIST手写数据库
# 下面这句话的功能是使用input_data.py的内容自动下载数据集,如果数据集已经存在,则不用下载直接调用
mnist = input_data.read_data_sets(