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)。

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