热门标签 | HotTags
当前位置:  开发笔记 > 后端 > 正文

tensorflowtutorials(八):手写数字数据集MNIST介绍

声明:版权所有,转载请联系作者并注明出处:http:blog.csdn.netu013719780?viewmodecontents在做机器学习相关实验的时候,首先我们就


声明:版权所有,转载请联系作者并注明出处:  http://blog.csdn.net/u013719780?viewmode=contents


在做机器学习相关实验的时候,首先我们就是需要一份通用的数据集,以便与其他的算法得到的实验结果进行比较。在图像分类领域MNIST数据集就是这样一个通用的数据集,前面几篇博文都用到了MNIST数据集,本文对其进行一些简单的介绍!


MNIST

In [1]:
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
from tensorflow.examples.tutorials.mnist import input_data

%matplotlib inline
print ("packs loaded")
packs loaded

Download and Extract MNIST dataset

In [2]:
print ("Download and Extract MNIST dataset")
mnist = input_data.read_data_sets('/tmp/data/', one_hot=True)
print
print (" tpye of 'mnist' is %s" % (type(mnist)))
print (" number of trian data is %d" % (mnist.train.num_examples))
print (" number of test data is %d" % (mnist.test.num_examples))
Download and Extract MNIST dataset
Extracting /tmp/data/train-images-idx3-ubyte.gz
Extracting /tmp/data/train-labels-idx1-ubyte.gz
Extracting /tmp/data/t10k-images-idx3-ubyte.gz
Extracting /tmp/data/t10k-labels-idx1-ubyte.gz

tpye of 'mnist' is
number of trian data is 55000
number of test data is 10000
In [3]:
# What does the data of MNIST look like? 
print ("What does the data of MNIST look like?")
trainimg = mnist.train.images
trainlabel = mnist.train.labels
testimg = mnist.test.images
testlabel = mnist.test.labels
print
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,))
What does the data of MNIST look like?

type of 'trainimg' is
type of 'trainlabel' is
type of 'testimg' is
type of 'testlabel' is
shape of 'trainimg' is (55000, 784)
shape of 'trainlabel' is (55000, 10)
shape of 'testimg' is (10000, 784)
shape of 'testlabel' is (10000, 10)
In [4]:
# How does the training data look like?
print ("How does the training data look like?")
nsample = 5
randidx = np.random.randint(trainimg.shape[0], size=nsample)

for i in randidx:
curr_img = np.reshape(trainimg[i, :], (28, 28)) # 28 by 28 matrix
curr_label = np.argmax(trainlabel[i, :] ) # Label
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))
How does the training data look like?
12118th Training Data Label is 5
46324th Training Data Label is 8
33th Training Data Label is 4
36491th Training Data Label is 3
6910th Training Data Label is 3
In [5]:
# Batch Learning? 
print ("Batch Learning? ")
batch_size = 100
batch_xs, batch_ys = mnist.train.next_batch(batch_size)
print ("type of 'batch_xs' is %s" % (type(batch_xs)))
print ("type of 'batch_ys' is %s" % (type(batch_ys)))
print ("shape of 'batch_xs' is %s" % (batch_xs.shape,))
print ("shape of 'batch_ys' is %s" % (batch_ys.shape,))
Batch Learning? 
type of 'batch_xs' is
type of 'batch_ys' is
shape of 'batch_xs' is (100, 784)
shape of 'batch_ys' is (100, 10)
In [6]:
# Get Random Batch with 'np.random.randint'
print ("5. Get Random Batch with 'np.random.randint'")
randidx = np.random.randint(trainimg.shape[0], size=batch_size)
batch_xs2 = trainimg[randidx, :]
batch_ys2 = trainlabel[randidx, :]
print ("type of 'batch_xs2' is %s" % (type(batch_xs2)))
print ("type of 'batch_ys2' is %s" % (type(batch_ys2)))
print ("shape of 'batch_xs2' is %s" % (batch_xs2.shape,))
print ("shape of 'batch_ys2' is %s" % (batch_ys2.shape,))
5. Get Random Batch with 'np.random.randint'
type of 'batch_xs2' is
type of 'batch_ys2' is
shape of 'batch_xs2' is (100, 784)
shape of 'batch_ys2' is (100, 10)
In [7]:
randidx
Out[7]:
array([51472, 13751, 33562, 23281,  8489, 48481,  7799, 30307, 37366,
25312, 46149, 49712, 5083, 52853, 29819, 36444, 34829, 8769,
39518, 54911, 6720, 43675, 41703, 35594, 9300, 14474, 33318,
14808, 53456, 41978, 8047, 34524, 30978, 53455, 42119, 22660,
30329, 27169, 53798, 2125, 41759, 38951, 1438, 33511, 38784,
15822, 16785, 9229, 1216, 19569, 3116, 22172, 14766, 16153,
1707, 20899, 9087, 21263, 24853, 27784, 38324, 29287, 21828,
34511, 26340, 39194, 38272, 34238, 28050, 29294, 42672, 18696,
17796, 48147, 41841, 47077, 5925, 48237, 30605, 9169, 11260,
9155, 39346, 41049, 11342, 536, 5927, 11155, 40424, 33583,
38991, 16569, 34801, 870, 20546, 25061, 17601, 4521, 24359, 4613])


推荐阅读
  • 浏览器中的异常检测算法及其在深度学习中的应用
    本文介绍了在浏览器中进行异常检测的算法,包括统计学方法和机器学习方法,并探讨了异常检测在深度学习中的应用。异常检测在金融领域的信用卡欺诈、企业安全领域的非法入侵、IT运维中的设备维护时间点预测等方面具有广泛的应用。通过使用TensorFlow.js进行异常检测,可以实现对单变量和多变量异常的检测。统计学方法通过估计数据的分布概率来计算数据点的异常概率,而机器学习方法则通过训练数据来建立异常检测模型。 ... [详细]
  • 建立分类感知器二元模型对样本数据进行分类
    本文介绍了建立分类感知器二元模型对样本数据进行分类的方法。通过建立线性模型,使用最小二乘、Logistic回归等方法进行建模,考虑到可能性的大小等因素。通过极大似然估计求得分类器的参数,使用牛顿-拉菲森迭代方法求解方程组。同时介绍了梯度上升算法和牛顿迭代的收敛速度比较。最后给出了公式法和logistic regression的实现示例。 ... [详细]
  • cs231n Lecture 3 线性分类笔记(一)
    内容列表线性分类器简介线性评分函数阐明线性分类器损失函数多类SVMSoftmax分类器SVM和Softmax的比较基于Web的可交互线性分类器原型小结注:中文翻译 ... [详细]
  • 【论文】ICLR 2020 九篇满分论文!!!
    点击上方,选择星标或置顶,每天给你送干货!阅读大概需要11分钟跟随小博主,每天进步一丢丢来自:深度学习技术前沿 ... [详细]
  • Python入门后,想要从事自由职业可以做哪方面工作?1.爬虫很多人入门Python的必修课之一就是web开发和爬虫。但是这两项想要赚钱的话 ... [详细]
  • 马尔可夫决策过程Markov Decision Process,MDPKintoki
    Originalurl:http:www.tuicool.comarticlesb6BjAva1.马尔可夫模型的几类子模型我想大家一定听说过马尔科夫链(MarkovChain)& ... [详细]
  • 使用nodejs爬取b站番剧数据,计算最佳追番推荐
    本文介绍了如何使用nodejs爬取b站番剧数据,并通过计算得出最佳追番推荐。通过调用相关接口获取番剧数据和评分数据,以及使用相应的算法进行计算。该方法可以帮助用户找到适合自己的番剧进行观看。 ... [详细]
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • 近年来,大数据成为互联网世界的新宠儿,被列入阿里巴巴、谷歌等公司的战略规划中,也在政府报告中频繁提及。据《大数据人才报告》显示,目前全国大数据人才仅46万,未来3-5年将出现高达150万的人才缺口。根据领英报告,数据剖析人才供应指数最低,且跳槽速度最快。中国商业结合会数据剖析专业委员会统计显示,未来中国基础性数据剖析人才缺口将高达1400万。目前BAT企业中,60%以上的招聘职位都是针对大数据人才的。 ... [详细]
  • 本文介绍了Java工具类库Hutool,该工具包封装了对文件、流、加密解密、转码、正则、线程、XML等JDK方法的封装,并提供了各种Util工具类。同时,还介绍了Hutool的组件,包括动态代理、布隆过滤、缓存、定时任务等功能。该工具包可以简化Java代码,提高开发效率。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • 支持向量机训练集多少个_25道题检测你对支持向量机算法的掌握程度
    介绍在我们学习机器算法的时候,可以将机器学习算法视为包含刀枪剑戟斧钺钩叉的一个军械库。你可以使用各种各样的兵器,但你要明白这些兵器是需要在合适的时间合理 ... [详细]
  • plt python 画直线_机器学习干货,一步一步通过Python实现梯度下降的学习
    GradientDescent-梯度下降梯度下降法(英语:Gradientdescent)是一个一阶最优化算法,通常也称为最速下降法。要使用梯度下降法找 ... [详细]
  • 人工智能推理能力与假设检验
    最近Google的Deepmind开始研究如何让AI做数学题。这个问题的提出非常有启发,逻辑推理,发现新知识的能力应该是强人工智能出现自我意识之前最需要发展的能力。深度学习目前可以 ... [详细]
author-avatar
O依楼观雪O
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有