# 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
打开 pychram, 新建input_data.py
文件,将以上代码 保存进去
使用时新建test.py
文件(与input_data.py
在同一目录下,比如我的是Home/PycharmProjects/MNIST_data/mnist),执行下面命令来下载MNIST数据集,执行这个程序就会在mnist文件夹
下生成一个data文件夹
,
#下载用于训练和测试的mnist数据集的源码
import input_data # 调用input_data
print('Download and Extract MNISIT dataset: ')
mnist = input_data.read_data_sets('data/', one_hot=True)
print("type of 'mnnist' is %s"% (type(mnist)))
print("number of train data is %d " % (mnist.train.num_examples))
print("number of test data is %d" %(mnist.test.num_examples))
如图:
输出结果看到mnist的类型,并且有55000张的训练数据和10000张的测试数据: