怎樣使用tensorflow導入已經下載好的mnist數據集?

我在學習tensorflow入門教程的時候,由於網路原因沒有從腳本下載mnist手寫識別數據集,於是我就手動下載的數據集,並把它放在相應的目錄上。但是我看極客學院的教程上沒有提供相應的從文件夾當中插入數據的方法。那麼應該怎樣直接導入數據集呢?


下載好的文件放到代碼目錄下就可以了呀,調用read_data_sets()的時候第一個路徑參數寫".",表示當前目錄,mnist.py會判斷是否下載,因為源碼里調用的函數是maybe_download(),這個函數會判斷本地是否已經有文件了。

如果還不行,就直接閱讀tensorflow/contrib/learn/python/learn/datasets/mnist.py源文件,將相應的讀取代碼稍加重組織粘貼到程序中。


from tensorflow.examples.tutorials.mnist import input_data

MNIST_data_folder="" mnist data 的文件夾""

mnist=input_data.read_data_sets(MNIST_data_folder,one_hot=True)

print mnist.train.next_batch(1)


import tensorflow.examples.tutorials.mnist.input_data as input_data

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


from tensorflow.examples.tutorials.mnist import input_data

MNIST_data_folder="D:\TestTensorflow\……\MNIST_data"

mnist=input_data.read_data_sets(MNIST_data_folder,one_hot=True)

把本地下載好的數據路徑加進去,要用\


The Environment: Ubuntu + Anaconda + Jupyter notebook

My Anaconda is installed in default in the directory of the "/home"

When run the code below in the reference documentation:

from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
mnist = input_data.read_data_sets("MNIST_data", one_hot=True)
...

In default, the program would download the dataset from the official website.

Since you have downloaded the MNIST dataset, named (they all are not unpacked) :

  • t10k-images-idx3-ubyte.gz
  • t10k-labels-idx1-ubyte.gz
  • train-images-idx3-ubyte.gz
  • train-labels-idx1-ubyte.gz

You should put them in the "/home/anaconda/"MNIST_data""

Then the input_data.py would recognize then folder "MNIST_data" have dataset or not, if yes, you load the downloading dataset successfully.


可以自己解析mnist數據,這樣就清楚數據怎麼弄近神經網路的


推薦閱讀:

Google I/O 2017 上有哪些關於 TensorFlow 的前沿應用和分享?
anaconda安裝tensorflow,在import tensorflow時報錯,要怎麼解決?
求通俗講解下tensorflow的embedding_lookup介面的意思?
用Tensorflow自動化構建海洋生物系統,利用上萬的圖片訓練,找到瀕臨物種「海牛」是什麼原理?
請問batch_normalization做了normalization後為什麼要變回來?

TAG:深度學習DeepLearning | TensorFlow |