tensorflow实现加载mnist数据集
作者:Missayaa 发布时间:2022-02-06 06:20:24
标签:tensorflow,mnist,数据集
mnist作为最基础的图片数据集,在以后的cnn,rnn任务中都会用到
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
from tensorflow.examples.tutorials.mnist import input_data
#数据集存放地址,采用0-1编码
mnist = input_data.read_data_sets('F:/mnist/data/',one_hot = True)
print(mnist.train.num_examples)
print(mnist.test.num_examples)
trainimg = mnist.train.images
trainlabel = mnist.train.labels
testimg = mnist.test.images
testlabel = mnist.test.labels
#打印相关信息
print(type(trainimg))
print(trainimg.shape,)
print(trainlabel.shape,)
print(testimg.shape,)
print(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))
plt.show()
程序运行结果如下:
Extracting F:/mnist/data/train-images-idx3-ubyte.gz
Extracting F:/mnist/data/train-labels-idx1-ubyte.gz
Extracting F:/mnist/data/t10k-images-idx3-ubyte.gz
Extracting F:/mnist/data/t10k-labels-idx1-ubyte.gz
55000
10000
<class 'numpy.ndarray'>
(55000, 784)
(55000, 10)
(10000, 784)
(10000, 10)
52636th
输出的图片如下:
Training Datalabel is9
下面还有四张其他的类似图片
来源:https://blog.csdn.net/Missayaaa/article/details/80056103
0
投稿
猜你喜欢
- 初学tensorflow,如果写的不对的,请更正,谢谢!tf.reshape(tensor, shape, name=None)函数的作用是
- 我们在使用 requests 这类网络请求第三方库时,可以看到它有一个参数叫做 timeout ,就是指在网络请求发出开始计算,如果超过 t
- YOLOv5的Backbone设计在上一篇文章《YOLOV5的anchor设定》中我们讨论了anchor的产生原理和检测过程,对YOLOv5
- 如何一行输入多个数,并存入列表在python里,如果你仅使用input()的话是输入一行的内容并将该行的内容以字符串的形式存到变量中,但如果
- 1、存储过程基本语法: create procedure sp_name() begin ...... end; 2、如何调用: call
- 1、Tkinter是什么Tkinter 是使用 python 进行窗口视窗设计的模块。Tkinter模块(“Tk 接口&
- 1.定义ResNet残差模块一个block中,有两个卷积层,之后的输出还要和输入进行相加。因此一个block的前向流程如下:输入x→卷积层→
- 今天做visual transformer研究的时候,发现了einops这么个神兵利器,决定大肆安利一波。先看链接:https://gith
- 本文实例为大家分享了python调用百度语音REST API的具体代码,供大家参考,具体内容如下(百度的rest接口的部分网址发生了一定的变
- 注意:我使用的是 Entity Framework Core 2.0 (2.0.0-preview2-final)。正式版发布时,功能可能存
- PHP PDO预定义常量以下常量由本扩展模块定义,因此只有在本扩展的模块被编译到PHP中,或者在运行时被动态加载后才有效。注意:PDO使用类
- 看代码吧~# 加载库import numpy as npfrom fancyimpute import KNNfrom sklearn.pr
- 在查看Mysql对文件的操作中,它在不同的操作系统上对文件的操作,除了使用标准C运行库函数,包括open、close、seek等,在Win3
- Python是编译型语言还是解释型语言?回答这个问题前,应该先弄清楚什么是编译型语言,什么是解释型语言。所谓编译执行就是源代码经过编译器编译
- 前言python 文件操作、文件读写(write、read、readlines、readline)、文件的相关操作,简单易懂1 文件操作文件
- 1、使用说明首先说明,本文所使用的功能为pycharm专业版所支持,其他版本如社区版,教育版,则不一定支持。作为一名后端开发,我猜你的桌面上
- 本文实例为大家分享了python实现决策树分类算法的具体代码,供大家参考,具体内容如下1、概述决策树(decision tree)——是一种
- 1.python 中创建进程的两种方式:from multiprocessing import Processimport timedef
- Access保留字&变量名列表,建表时应避免使用这些词汇和符号。Access 2002/2003-A &nbs
- list1 和list2 两个list , 想要得到list1是不是包含 list2 (是不是其子集 )a = [1,2] b = [1,2