tensorflow下数据集MNIST下载源代码

本人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_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/可以自己指定

到此问题得以解决。

猜你喜欢

转载自blog.csdn.net/tanlangqie/article/details/78890362