(三)Tensorflow学习——mnist数据集简介
程序员文章站
2024-03-07 21:45:21
...
导入相关包
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
# tensorflow自带的一些数据集
from tensorflow.examples.tutorials.mnist import input_data
加载数据集
在该目录下,建立一个空文件夹data
,加载mnist数据集时,会自动从网上下载
print('Download and Extract MNIST dataset')
mnist = input_data.read_data_sets('data/', one_hot=True)
print('type of "mnist" is %s' % (type(mnist)))
print('number of train data is %d' % (mnist.train.num_examples))
print('number of test data is %d' % (mnist.test.num_examples))
mnist数据集的描述信息
trainimg = mnist.train.images
trainlabel = mnist.train.labels
testimg = mnist.test.images
testlabel = mnist.test.labels
print('type of "trainimg" is %s' % (type(trainimg)))
print('type of "trainlabel" is %s' % (type(trainlabel)))
print('type of "testimg" is %s' % (type(testimg)))
print('type of "testlabel" is %s' % (type(testlabel)))
print('shape of "trainimg" is %s' % (trainimg.shape,))
print('shape of "trainlabel" is %s' % (trainlabel.shape,))
print('shape of "testimg" is %s' % (testimg.shape,))
print('shape of "testlabel" is %s' % (testlabel.shape,))
输出结果:
打印原数据集
nsample = 5
randidx = np.random.randint(trainimg.shape[0], size=nsample)
for i in randidx:
curr_img = np.reshape(trainimg[i, :], (28, 28))
curr_label = np.argmax(trainlabel[i, :])
plt.matshow(curr_img, cmap=plt.get_cmap('gray'))
plt.title('' + str(i) + 'th Training Data'
+ 'Label is ' + str(curr_label))
print('' + str(i) + 'th Training Data'
+ 'Label is ' + str(curr_label))
这里只展示一张图片:
推荐阅读
-
Tensorflow学习-MNIST数据集
-
tensorflow中mnist数据集
-
(三)Tensorflow学习——mnist数据集简介
-
tensorflow入门之mnist手写数据集识别
-
tensorflow 离线使用 fashion_mnist 数据集
-
初识人工智能(二):机器学习(三):sklearn数据集
-
5.1tensorflow5.1神经网络调参实现mnist数据集分类正确率98%以上(实现动态学习率调整)
-
tensorflow实现加载mnist数据集
-
Tensorflow机器学习入门——MINIST数据集识别
-
深度学习 从零开始 —— 神经网络数学基础(一),学习Keras库的使用,神经网络简单流程,MNIST数据集使用