TensorFlow入门(三)——MNIST数据下载

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/PinkRiverside/article/details/73028453

MNIST是一个入门级的计算机视觉数据集,它包含各种手写数字图片:
这里写图片描述
它也包含每一张图片对应的标签,告诉我们这个是数字几。比如,上面这四张图片的标签分别是5,0,4,1。

input_data.py:用于自动下载和安装MNIST数据集。

# 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

使用下面的代码导入到自己的项目里(也可以直接复制粘贴到代码文件里)

import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

运行后自动下载到./MNIST_data文件夹:
这里写图片描述

下载下来的数据集被分成两部分:60000行的训练数据集(mnist.train)和10000行的测试数据集(mnist.test)。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章