当前位置:网站首页>mnist有多少张图片(怎么读取图片文字)
mnist有多少张图片(怎么读取图片文字)
2022-07-29 18:52:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
记录用不同的方法读取Mnist数据集
1、Python的PIL模块读取Mnist图片
#读取文件夹mnist下的60000张图片,图片为灰度图,所以为1通道,如果是将彩色图作为输入,则将1替换为3,图像大小28*28
def load_data():
data = np.empty((60000,1,28,28),dtype="float32")
label = np.empty((60000,),dtype="uint8")
imgs = os.listdir("E:\\DataSet\\mnist")
num = len(imgs)
for i in range(num):
img = Image.open("E:\\DataSet\\mnist\\"+imgs[i])
arr = np.asarray(img,dtype="float32")
data[i,:,:,:] = arr
label[i] = int(imgs[i].split('.')[0])
#归一化和零均值化
data /= np.max(data)
data -= np.mean(data)
return data,label
if __name__ == '__main__':
load_data()2、keras自带的 load_data( ) 方法
from keras.datasets import mnist
(X_train, y_train), (X_test, y_test) = mnist.load_data()X_train.shape (60000, 28, 28),X_test.shape (10000, 28, 28); y_train.shape (60000,),y_test.shape (10000,)。
这个方法未进行归一化,像素点数据范围是0-255。
参考:
http://keras-cn.readthedocs.io/en/latest/other/datasets/
https://github.com/wepe/MachineLearning/
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/129521.html原文链接:https://javaforall.cn
边栏推荐
- 洪九果品、百果园抢滩港股,卖水果是门好生意吗?
- Win11网络不稳定怎么办?Win11连接wifi频繁掉线的解决方法
- 关于高考选志愿
- Experience Sharing | Tips for Writing Easy-to-Use Online Product Manuals
- R语言时间序列数据提取:使用xts包的first函数提取时间序列中最前面两周的数据(first 2 week)
- Test basis: Redis of Nosql database
- 小程序onlaunch和onload(小程序onunload)
- Neo4j Open Source NoSQL Database
- FPGA设计8-3线优先编码器与3-8线译码器
- QT 如何计算中英文字符串的长度
猜你喜欢
随机推荐
活动回顾 | 大咖云集“开源安全治理模型和工具”线上研讨会
Gesture password unlock WeChat applet project source code
Experience Sharing | Tips for Writing Easy-to-Use Online Product Manuals
error TS1219: Experimental support for decorators解决
《STL 源码剖析》学习笔记之容器(二)list
无代码开发平台权限设置入门教程
c语言 || 杂
Typescript mix method to class with decorator
会议OA项目之待开会议&&所有会议功能
函数的参数
R语言ggplot2可视化绘制条形图(bar plot)、使用gghighlight包突出高亮条形图中的特定条形(highlight specific bar plot)
我用两行代码实现了一个数据库!
Go 语言如何读取 excel 测试数据,简单易学
第21章 内存管理
无人驾驶技术有什么优点,人工驾驶的优缺点英文
在宇宙中心五道口上班,是怎样一种体验
UE4选不中半透明物体(半透明显示快捷键是啥)
R语言时间序列数据提取:使用xts包的first函数提取时间序列中最前面10天的数据(first 10 day)
小程序组件的总结
2.1寸旋钮屏结合6.86寸串口屏助力集成灶智能升级|启明智显









