tensorflow MNIST数据集
2017-07-25 20:58
465 查看
____tz_zs
关于MNIST数据集的下载和更多介绍:
http://yann.lecun.com/exdb/mnist/
详解 MNIST 数据集
MNIST数据集的操作
这里介绍的是tensorflow提供的一个用来处理MNIST数据集的类,它将会自动的下载并转化MNIST数据的格式,便于初学者学习和练习。# -*- coding: utf-8 -*-
"""
@author: tz_zs
MNIST数据集的操作
"""
from tensorflow.examples.tutorials.mnist import input_data
# 载入MNIST数据集
'''
第一次运行时,会先下载数据集
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Extracting /path/to/MNIST_data/train-images-idx3-ubyte.gz
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Extracting /path/to/MNIST_data/train-labels-idx1-ubyte.gz
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Extracting /path/to/MNIST_data/t10k-images-idx3-ubyte.gz
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting /path/to/MNIST_data/t10k-labels-idx1-ubyte.gz
之后在运行则直接从文件夹提取
Extracting /path/to/MNIST_data/train-images-idx3-ubyte.gz
Extracting /path/to/MNIST_data/train-labels-idx1-ubyte.gz
Extracting /path/to/MNIST_data/t10k-images-idx3-ubyte.gz
Extracting /path/to/MNIST_data/t10k-labels-idx1-ubyte.gz
'''
mnist = input_data.read_data_sets("/path/to/MNIST_data/", one_hot=True)
print("Training data size: ", mnist.train.num_examples) # Training data size: 55000
print("Validating data size: ", mnist.validation.num_examples) # Validating data size: 5000
print("Testing data size: ", mnist.test.num_examples) # Testing data size: 10000
print("Example training data: \n", mnist.train.images[0])
'''
Example training data:
[ 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.38039219 0.37647063
0.3019608 0.46274513 0.2392157 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.35294119 0.5411765
0.92156869 0.92156869 0.92156869 0.92156869 0.92156869 0.92156869
0.98431379 0.98431379 0.97254908 0.99607849 0.96078438 0.92156869
0.74509805 0.08235294 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.54901963 0.98431379 0.99607849 0.99607849 0.99607849 0.99607849
0.99607849 0.99607849 0.99607849 0.99607849 0.99607849 0.99607849
0.99607849 0.99607849 0.99607849 0.99607849 0.74117649 0.09019608
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0.88627458 0.99607849 0.81568635
0.78039223 0.78039223 0.78039223 0.78039223 0.54509807 0.2392157
0.2392157 0.2392157 0.2392157 0.2392157 0.50196081 0.8705883
0.99607849 0.99607849 0.74117649 0.08235294 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.14901961 0.32156864 0.0509804 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0.13333334 0.83529419 0.99607849 0.99607849 0.45098042 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0.32941177 0.99607849 0.99607849 0.91764712 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0.32941177 0.99607849 0.99607849 0.91764712 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0.41568631 0.6156863 0.99607849 0.99607849 0.95294124 0.20000002
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0.09803922 0.45882356 0.89411771
0.89411771 0.89411771 0.99215692 0.99607849 0.99607849 0.99607849
0.99607849 0.94117653 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0.26666668 0.4666667 0.86274517
0.99607849 0.99607849 0.99607849 0.99607849 0.99607849 0.99607849
0.99607849 0.99607849 0.99607849 0.55686277 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0.14509805 0.73333335 0.99215692
0.99607849 0.99607849 0.99607849 0.87450987 0.80784321 0.80784321
0.29411766 0.26666668 0.84313732 0.99607849 0.99607849 0.45882356
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.44313729
0.8588236 0.99607849 0.94901967 0.89019614 0.45098042 0.34901962
0.12156864 0. 0. 0. 0. 0.7843138
0.99607849 0.9450981 0.16078432 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0.66274512 0.99607849 0.6901961 0.24313727 0. 0.
0. 0. 0. 0. 0. 0.18823531
0.90588242 0.99607849 0.91764712 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0.07058824 0.
4000
48627454 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.32941177 0.99607849 0.99607849 0.65098041 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0.54509807 0.99607849 0.9333334 0.22352943 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.82352948 0.98039222 0.99607849 0.65882355 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0.94901967 0.99607849 0.93725497 0.22352943 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.34901962 0.98431379 0.9450981 0.33725491 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.01960784 0.80784321 0.96470594 0.6156863 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0.01568628 0.45882356 0.27058825 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. ]
'''
print("Example training data label: ",
mnist.train.labels[0]) # Example training data label: [ 0. 0. 0. 0. 0. 0. 0. 1. 0. 0.]
# mnist.train.next_batch可以取出一部分数据作为一个batch
batch_size = 100
xs, ys = mnist.train.next_batch(batch_size)
print("X shape:", xs.shape) # X shape: (100, 784)
print("Y shape: ", ys.shape) # Y shape: (100, 10)
关于MNIST数据集的下载和更多介绍:
http://yann.lecun.com/exdb/mnist/
详解 MNIST 数据集
MNIST数据集的操作
这里介绍的是tensorflow提供的一个用来处理MNIST数据集的类,它将会自动的下载并转化MNIST数据的格式,便于初学者学习和练习。# -*- coding: utf-8 -*-
"""
@author: tz_zs
MNIST数据集的操作
"""
from tensorflow.examples.tutorials.mnist import input_data
# 载入MNIST数据集
'''
第一次运行时,会先下载数据集
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Extracting /path/to/MNIST_data/train-images-idx3-ubyte.gz
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Extracting /path/to/MNIST_data/train-labels-idx1-ubyte.gz
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Extracting /path/to/MNIST_data/t10k-images-idx3-ubyte.gz
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting /path/to/MNIST_data/t10k-labels-idx1-ubyte.gz
之后在运行则直接从文件夹提取
Extracting /path/to/MNIST_data/train-images-idx3-ubyte.gz
Extracting /path/to/MNIST_data/train-labels-idx1-ubyte.gz
Extracting /path/to/MNIST_data/t10k-images-idx3-ubyte.gz
Extracting /path/to/MNIST_data/t10k-labels-idx1-ubyte.gz
'''
mnist = input_data.read_data_sets("/path/to/MNIST_data/", one_hot=True)
print("Training data size: ", mnist.train.num_examples) # Training data size: 55000
print("Validating data size: ", mnist.validation.num_examples) # Validating data size: 5000
print("Testing data size: ", mnist.test.num_examples) # Testing data size: 10000
print("Example training data: \n", mnist.train.images[0])
'''
Example training data:
[ 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.38039219 0.37647063
0.3019608 0.46274513 0.2392157 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.35294119 0.5411765
0.92156869 0.92156869 0.92156869 0.92156869 0.92156869 0.92156869
0.98431379 0.98431379 0.97254908 0.99607849 0.96078438 0.92156869
0.74509805 0.08235294 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.54901963 0.98431379 0.99607849 0.99607849 0.99607849 0.99607849
0.99607849 0.99607849 0.99607849 0.99607849 0.99607849 0.99607849
0.99607849 0.99607849 0.99607849 0.99607849 0.74117649 0.09019608
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0.88627458 0.99607849 0.81568635
0.78039223 0.78039223 0.78039223 0.78039223 0.54509807 0.2392157
0.2392157 0.2392157 0.2392157 0.2392157 0.50196081 0.8705883
0.99607849 0.99607849 0.74117649 0.08235294 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.14901961 0.32156864 0.0509804 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0.13333334 0.83529419 0.99607849 0.99607849 0.45098042 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0.32941177 0.99607849 0.99607849 0.91764712 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0.32941177 0.99607849 0.99607849 0.91764712 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0.41568631 0.6156863 0.99607849 0.99607849 0.95294124 0.20000002
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0.09803922 0.45882356 0.89411771
0.89411771 0.89411771 0.99215692 0.99607849 0.99607849 0.99607849
0.99607849 0.94117653 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0.26666668 0.4666667 0.86274517
0.99607849 0.99607849 0.99607849 0.99607849 0.99607849 0.99607849
0.99607849 0.99607849 0.99607849 0.55686277 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0.14509805 0.73333335 0.99215692
0.99607849 0.99607849 0.99607849 0.87450987 0.80784321 0.80784321
0.29411766 0.26666668 0.84313732 0.99607849 0.99607849 0.45882356
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.44313729
0.8588236 0.99607849 0.94901967 0.89019614 0.45098042 0.34901962
0.12156864 0. 0. 0. 0. 0.7843138
0.99607849 0.9450981 0.16078432 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0.66274512 0.99607849 0.6901961 0.24313727 0. 0.
0. 0. 0. 0. 0. 0.18823531
0.90588242 0.99607849 0.91764712 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0.07058824 0.
4000
48627454 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.32941177 0.99607849 0.99607849 0.65098041 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0.54509807 0.99607849 0.9333334 0.22352943 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.82352948 0.98039222 0.99607849 0.65882355 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0.94901967 0.99607849 0.93725497 0.22352943 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.34901962 0.98431379 0.9450981 0.33725491 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0.01960784 0.80784321 0.96470594 0.6156863 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0.01568628 0.45882356 0.27058825 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. ]
'''
print("Example training data label: ",
mnist.train.labels[0]) # Example training data label: [ 0. 0. 0. 0. 0. 0. 0. 1. 0. 0.]
# mnist.train.next_batch可以取出一部分数据作为一个batch
batch_size = 100
xs, ys = mnist.train.next_batch(batch_size)
print("X shape:", xs.shape) # X shape: (100, 784)
print("Y shape: ", ys.shape) # Y shape: (100, 10)
相关文章推荐
- tensorflow tutorials(八):手写数字数据集MNIST介绍
- TensorFlow mnist数据集路径 MNIST_data 数据下载问题
- TensorFlow mnist 数据集练习
- tensorflow mnist数据集手写字识别
- Tensorflow MNIST 数据集测试代码入门
- 学习笔记TF056:TensorFlow MNIST,数据集、分类、可视化
- Tensorflow MNIST 数据集测试代码入门
- tensorflow mnist实战笔记(二)制作和读取自己的数据集
- Tensorflow学习系列(三): tensorflow mnist数据集如何跑出99+的准确率
- tensorflow MNIST数据集上简单的MLP网络
- tensorflow MNIST数据集的训练(线性模型)及tensorboard计算结果可视化
- tensorflow mnist数据集 cnn demo
- Tensorflow MNIST 数据集測试代码入门
- TensorFlow CNN 以库函数的方式实现MNIST手写识别
- tensorflow mnist 结果验证
- ROS机器人Diego 1#整合Tensorflow MNIST,玩数字识别
- Tensorflow Cnn mnist 的一些细节
- tensorflow mnist入门
- 学习笔记TF067:TensorFlow Serving、Flod、计算加速,机器学习评测体系,公开数据集
- tensorflow mnist实战笔记(一)了解官方mnist数据格式