TensorFlow 下 mnist 数据集的操作及可视化
2017-03-16 15:12
417 查看
from tensorflow.examples.tutorials.mnist import input_data
首先需要连网下载数据集:
mnsit = input_data.read_data_sets(train_dir='./MNIST_DATA', one_hot=True) # 如果当前文件夹下没有 MNIST_DATA,会首先创建该文件夹,然后下载 mnist 数据集
训练集与测试集的划分:
X_train, y_train = mnist.train.images, mnist.train.labels # 返回的 X_train 是 numpy 下的 多维数组,(55000, 784) X_test, y_test = mnist.test.images, mnist.test.labels # (10000, 784) X_valid, y_valid = mnist.valid.images, mnist.valid.labels # (5000, 784)
当然可以通过迭代的形式以一定 batch_size 读取数据:
mnist.train.next_batch(100)
mnist.train.next_batch() ⇒ 返回两个值,一个是图像数据,一个是图像数据对应的类别信息。
>> X_batch, y_batch = mnist.train.next_batch(100) >> X_batch.shape (100, 784) >> y_batch.shape (100, 10) # one hot 编码
1. 可视化
# images:9*(28*28) 的 numpy.ndarray # y_ 表示其真实的标签信息 def plot_mnist_3_3(images, y_, y=None): assert images.shape[0] == len(y_) fig, axes = plt.subplots(3, 3) for i, ax in enumerate(axes.flat): ax.imshow(images[i].reshape(image_shp), cmap='binary') if y is None: xlabel = 'True: {}'.format(y_[i]) else: xlabel = 'True: {0}, Pred: {1}'.format(y_[i], y[i]) ax.set_xlabel(xlabel) ax.set_xticks([]) ax.set_yticks([]) plt.show()
相关文章推荐
- TensorFlow学习_01_安装_基本操作_可视化结构、过程_Mnist
- TensorFlow官方教程学习笔记(四)——MNIST数据集的读取
- 用tensorflow实现usps和mnist数据集的迁移学习
- Tensorboard学习——mnist_with_summaries.py ---- TensorFlow可视化
- 神经网络与深度学习 使用Python实现基于梯度下降算法的神经网络和自制仿MNIST数据集的手写数字分类可视化程序 web版本
- DeepLearning&Tensorflow学习笔记2__mnist数据集CNN
- 深度学习框架Caffe学习笔记(4)-MNIST数据集转换成可视化图片
- tensorflow MNIST数据集的训练(线性模型)及tensorboard计算结果可视化
- TensorFlow官方教程学习笔记之2-用于机器学习初学者学习的MNIST数据集(MNIST For ML Beginners)
- 【tensorflow学习】卷积神经网络CNN(mnist数据集)
- tensorflow之MNIST手写字符集训练可视化
- 用tensorflow实现的,基于mnist数据集上的一个简易模型
- 用tensorflow实现usps和mnist数据集的迁移学习
- TensorFlow学习笔记--mnist可视化版本
- TensorFlow官方教程学习笔记之3-用于机器学习专家学习的MNIST数据集(MNIST For ML Beginners)
- TensorFlow入门之训练mnist数据集
- 【Python | TensorBoard】用 PCA 可视化 MNIST 手写数字识别数据集
- Deep Learning-TensorFlow (2) CNN卷积神经网络_TensorBoard可视化使用及MNIST代码实例
- TensorFlow训练mnist数据集(卷积神经网络lenet5)
- 【机器学习】MNIST数据集上的python读取和使用操作