tensorflow下数据集MNIST下载源代码
来源:互联网 发布:java 软引用 弱引用 编辑:程序博客网 时间:2024/05/16 02:08
本人Tensorflow新手,在下载经典数据集MNIST时遇到问题,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
将上述脚本运行后即可得到数据集。(注意第一次运行此脚本需要在国外网站上下载数据,因此需要翻墙)
以后再调用此数据集时加上如下代码即可:
import input_datamnist = input_data.read_data_sets("MNIST_data/", one_hot=True) #文件夹名字 MNIST_data/可以自己指定
到此问题得以解决。
阅读全文