SoFunction
Updated on 2024-11-18

python deep learning tensorflow example data download and reading

I. mnist data

An introductory example of deep learning is typically mnist handwritten digit classification recognition, so we should download this dataset first.

tensorflow provides an input_data.py file, specifically for downloading mnist data, we can call it directly, the code is as follows:

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

After execution, a new folder MNIST_data will be created in the current directory, and the downloaded data will be placed in this folder. The four files downloaded are:

The input_data file calls a maybe_download function to make sure the data is downloaded successfully. This function also determines if the data has already been downloaded, and if it has, it will not repeat the download.

The downloaded dataset was divided into three subsets: the 5.5W-row training dataset (), a validation dataset of 5k rows () and a test dataset of 1W rows (). Since each image is a 28x28 black and white image, each row is a 784-dimensional vector.

Each subset consists of two parts: the images part (images) and the labels part (labels), which we can view with the following code :

print 
print 
print 
print 
print 
print 

If you want to view specific values in the spyder editor, you can extract this data as variables to view them as:

val_data=
val_label=

II. CSV data

In addition to the mnist handwritten font image data, tf also provides several csv's for you to practice with, the storage path is:

/home/xxx/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/datasets/data/text_train.csv

To read this data out, use the code:

import  as base
iris_data,iris_label=base.load_iris()
house_data,house_label=base.load_boston()

The former is the iris Iris dataset and the latter is the Boston house price data.

iii. cifar10 data

tf provides functions for downloading and reading cifar10 data, we can call them directly. Execute the following code:

import .cifar10.cifar10 as cifar10
cifar10.maybe_download_and_extract()
images, labels = cifar10.distorted_inputs()
print images
print labels

It will be possible to download and read out the cifar10.

Above is the detailed content of python deep learning tensorflow example data download and read, more information about python tensorflow data download and read please pay attention to my other related articles!