TensorFlow在数字识别统计中的应用

数据整理

tensorflow开发 之数字识别统计_数据


样本数量统计

tensorflow开发 之数字识别统计_数据_02


源码

# author: suoxd123@126.comimport tensorflow as tf# 读取数据mnist = tf.keras.datasets
.mnist(imgTrain, labelTrain),(imgTest, labelTest) = mnist.load_data(path='mnist.npz')1.2.3.4.5.6.

# author: suoxd123@126.com# 将2维矩阵变为1维向量print('source data structure')print
(imgTrain.shape, type(imgTrain))print(imgTest.shape, type(imgTest))imgTrain = imgTrain
.reshape(60000, 784)imgTest = imgTest.reshape(10000, 784)print('data structure after reshape')
print(imgTrain.shape, type(imgTrain))print(imgTest.shape, type(imgTest))
# 数据归一化处理imgTrain = imgTrain.astype('float32')imgTest = imgTest.astype('float32')imgTrain 
/= 255imgTest /= 2551.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.

# author: suoxd123@126.com# 统计当前实际数据import numpy as npimport matplotlib.pyplot as pltlabel, 
count = np.unique(labelTrain, return_counts=True)
# 打印数值对应数量print('0-9各数值对应的训练样本个数:')for m,n in zip(label, count): 
print("%d:%d;" % (m, n), end='')# 绘图显示对应数量fig = plt.figure()plt.bar(label, count, 
width = 0.6, align = 'center')plt.title('0-9 label distruibution')plt.xlabel('samble data')plt
.ylabel('quantity')plt.xticks(label)plt.ylim(0,8000) #设置y轴边界for m,n in zip(label, count):plt
.text(m,n, '%d'%n , ha = 'center', va = 'bottom', fontsize = 10)1.2.3.4.5.6.7.8.9.10.11.12.13.14.
15.16.17.18.19.20.21.

               

               


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删

QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空