没有合适的资源?快使用搜索试试~ 我知道了~
TensorFlow写卷积神经网络_数据集MNist_详细说明
1 下载量 2 浏览量
2020-12-21
04:45:08
上传
评论
收藏 175KB PDF 举报
温馨提示
试读
6页
导入包和MNist from __future__ import division, print_function #__future__的作用是升级py2到py3的一些用法,division:精确除法 import tensorflow as tf import matplotlib.pyplot as plt import numpy as np from tensorflow.examples.tutorials.mnist import input_data #从当前文件夹中找到MNist数据,“”中为文件路径 #MNist中,每一幅图片都是由28*28像素矩阵构成的,(28*28=7
资源详情
资源评论
资源推荐
TensorFlow写卷积神经网络写卷积神经网络_数据集数据集MNist_详细说明详细说明
导入包和导入包和MNist
from __future__ import division, print_function #__future__的作用是升级py2到py3的一些用法,division:精确除法
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
from tensorflow.examples.tutorials.mnist import input_data
#从当前文件夹中找到MNist数据,“”中为文件路径
#MNist中,每一幅图片都是由28*28像素矩阵构成的,(28*28=784即784个像素点)
mnist = input_data.read_data_sets("datasets/MNIST_data/", one_hot = True)
观察数据观察数据
def train_size(num):
print('Training = ' + str(mnist.train.images.shape))
print('-------------------------------------------')
x_train = mnist.train.images[:num, :] print('x_Training = ' + str(x_train.shape))
y_train = mnist.train.labels[:num, :] print('y_Training = ' + str(y_train.shape))
print('')
return x_train, y_train
def test_size(num):
print('Test = ' + str(mnist.train.images.shape))
print('-------------------------------------------')
x_test = mnist.test.images[:num, :] print('x_Test = ' + str(x_test.shape))
y_test = mnist.test.labels[:num, :] print('y_Training = ' + str(y_test.shape))
print('')
return x_test, y_test
显示图显示图
def display_digit(num):
print(y_train[num])
label = y_train[num].argmax(axis = 0)
image = x_train[num].reshape([28, 28]) #将784位一组改一下形状写成28*28变成容易观察的图形
plt.title('Example: %d Label: %d' % (num, label))
plt.imshow(image, cmap = plt.get_cmap('gray_r')) #cmap:可视化色彩图。gray:【0:黑;255:白】,gray_r:【0:白,255:黑】
plt.show()
显示重新塑形的矩阵显示重新塑形的矩阵
def display_mult_flat(start, stop):
images = x_train[start].reshape([1,784])
for i in range(start + 1, stop):
#将多幅图形连接在一起显示,numpy.concatenate((a1, a2, ...), axis=0)(按轴axis连接array组成一个新的array,default=0:逐行)
images = np.concatenate((images, x_train[i].reshape([1, 784])))
plt.imshow(images, cmap = plt.get_cmap('gray_r'))
plt.show()
x_train, y_train = train_size(55000)
#随机显示一个数字。np.random.randint(low, high=None, size=None, dtype='l')。函数的作用是,返回一个随机整型数,范围从低(包括)到高(不包
括),即[low, high)。如果没有写参数high的值,则返回[0,low)的值。
display_digit(np.random.randint(0, x_train.shape[0])) #x_train.shape是55000*784
display_mult_flat(0, 400)
Training = (55000, 784)
-------------------------------------------
x_Training = (55000, 784)
y_Training = (55000, 10)
[0. 1. 0. 0. 0. 0. 0. 0. 0. 0.]
weixin_38660069
- 粉丝: 2
- 资源: 946
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- IMG_0694.GIF
- 基于图像的三维模型重建C++源代码+文档说明(高分课程设计)
- 基于聚焦法的工件立体测量方案,根据数据进行三维重建 使用HALCON处理图像,MATLAB拟合数据+源代码+数据集+效果图
- 锄战三国村 修改:货币使用不减 v1.10(2) 原创 (中文).apk
- 基于python实现的单目双目视觉三维重建+源代码+图像图片(高分课程设计)
- 基于C+++OPENCV的全景图像拼接源码(课程设计)
- 基于Python+OpenCV对多张图片进行全景图像拼接,消除鬼影,消除裂缝+源代码+文档说明+界面截图(高分课程设计)
- 基于C++实现的全景图像拼接源码(课程设计)
- 基于SIFT特征点提取和RASIC算法实现全景图像拼接python源码+文档说明+界面截图+详细注释(95分以上课程大作业)
- 基于matlab实现眼部判别的疲劳检测系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0