TensorFlow下MNIST数据集下载脚本input_data.py

来源:互联网 发布:淘宝联盟提现钱没到账 编辑:程序博客网 时间:2024/05/17 07:35

TensorFlow官方文档里面,MNIST数据集下载脚本。 网页原始url打不开,这里给出github地址。下面也贴出源码。
这里写图片描述

下面代码存为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_importfrom __future__ import divisionfrom __future__ import print_functionimport gzipimport osimport tempfileimport numpyfrom six.moves import urllibfrom six.moves import xrange  # pylint: disable=redefined-builtinimport tensorflow as tffrom tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets

使用时新建test.py文件(与input_data.py在同一工程目录下,比如我的是E:\Anaconda3\Lib\site-packages\tensorflow\examples\tutorials\mnist),执行下面命令来下载MNIST数据集,就会在mnist文件夹下生成一个data文件夹,如图:

#下载用于训练和测试的mnist数据集的源码import input_data # 调用input_datamnist = input_data.read_data_sets('data/', one_hot=True)

可以看到有55000张的训练数据和10000张的测试数据

这里写图片描述
这里写图片描述

0 0