【MNIST数据转化】.idx3-ubyte 转png 格式
python
创建.py文件
终端运行
mnist train训练数据集
import numpy as np
import structfrom PIL import Image
import osdata_file = 'train-images.idx3-ubyte'
# It's 47040016B, but we should set to 47040000B
data_file_size = 47040016
data_file_size = str(data_file_size - 16) + 'B'data_buf = open(data_file, 'rb').read()magic, numImages, numRows, numColumns = struct.unpack_from('>IIII', data_buf, 0)
datas = struct.unpack_from('>' + data_file_size, data_buf, struct.calcsize('>IIII'))
datas = np.array(datas).astype(np.uint8).reshape(numImages, 1, numRows, numColumns)label_file = 'train-labels.idx1-ubyte'# It's 60008B, but we should set to 60000B
label_file_size = 60008
label_file_size = str(label_file_size - 8) + 'B'label_buf = open(label_file, 'rb').read()magic, numLabels = struct.unpack_from('>II', label_buf, 0)
labels = struct.unpack_from('>' + label_file_size, label_buf, struct.calcsize('>II'))
labels = np.array(labels).astype(np.int64)datas_root = 'mnist_train'
if not os.path.exists(datas_root):os.mkdir(datas_root)for i in range(10):file_name = datas_root + os.sep + str(i)if not os.path.exists(file_name):os.mkdir(file_name)for ii in range(numLabels):img = Image.fromarray(datas[ii, 0, 0:28, 0:28])label = labels[ii]file_name = datas_root + os.sep + str(label) + os.sep + \'mnist_train_' + str(ii) + '.png'img.save(file_name)
0——9分别对应10个文件夹
文件0中的手写字体:28*28
MNIST 测试数据集
import numpy as np
import structfrom PIL import Image
import osdata_file = 't10k-images.idx3-ubyte'
# It's 7840016B, but we should set to 7840000B
data_file_size = 7840016
data_file_size = str(data_file_size - 16) + 'B'data_buf = open(data_file, 'rb').read()magic, numImages, numRows, numColumns = struct.unpack_from('>IIII', data_buf, 0)
datas = struct.unpack_from('>' + data_file_size, data_buf, struct.calcsize('>IIII'))
datas = np.array(datas).astype(np.uint8).reshape(numImages, 1, numRows, numColumns)label_file = 't10k-labels.idx1-ubyte'# It's 10008B, but we should set to 10000B
label_file_size = 10008
label_file_size = str(label_file_size - 8) + 'B'label_buf = open(label_file, 'rb').read()magic, numLabels = struct.unpack_from('>II', label_buf, 0)
labels = struct.unpack_from('>' + label_file_size, label_buf, struct.calcsize('>II'))
labels = np.array(labels).astype(np.int64)datas_root = 'mnist_test'
if not os.path.exists(datas_root):os.mkdir(datas_root)for i in range(10):file_name = datas_root + os.sep + str(i)if not os.path.exists(file_name):os.mkdir(file_name)for ii in range(numLabels):img = Image.fromarray(datas[ii, 0, 0:28, 0:28])label = labels[ii]file_name = datas_root + os.sep + str(label) + os.sep + \'mnist_test_' + str(ii) + '.png'img.save(file_name)
【MNIST数据转化】.idx3-ubyte 转png 格式相关推荐
- 关于通过前端xslx解析excel日期格式数据转化问题以及自定义时间格式YYYY-MM-DD转化
如果excel中内容如下,需要解析时间格式的内容 XLSX.read会默认解析为天数的时间戳字符串(从1900年算起到当前日期的天数) 如果想让xlsx帮我们解析时,就完成解析时间格式,只需要加上如下 ...
- Dataset之MNIST:自定义函数mnist.load_mnist根据网址下载mnist数据集(四个ubyte.gz格式数据集文件)
Dataset之MNIST:自定义函数mnist.load_mnist根据网址下载mnist数据集(四个ubyte.gz格式数据集文件) 目录 下载结果 运行代码 下载结果 运行代码 mnist.py ...
- 怎么改mnist数据的标签_MNIST数据处理
MNIST是一个入门级的计算机视觉数据集,它包含各种手写数字图片: 它包含60000张训练图片,10000张测试图片,,每张图片都代表0-9的数字.图片包含28像素X28像素.我们可以用一个数字数组来 ...
- 二、如何保存MNIST数据集中train和test的图片?
如何保存MNIST数据集中train和test的图片? 介绍一种非诚神奇的图片保存方法,尤其是利用字典-format-结合来用,创建保存路径,这是一种史上很难用到的一种方法,哈哈哈哈,有点吹牛皮,不说 ...
- tensorflow学习笔记——使用TensorFlow操作MNIST数据(1)
续集请点击我:tensorflow学习笔记--使用TensorFlow操作MNIST数据(2) 本节开始学习使用tensorflow教程,当然从最简单的MNIST开始.这怎么说呢,就好比编程入门有He ...
- 下载MNIST数据集并使用python将数据转换成NumPy数组(源码解析)
下载MNIST数据集并使用python将数据转换成NumPy数组 首先来分析init_mnist函数 接下来继续分析load_mnist函数 实现数据集转换的python脚本的代码 显示MNIST图像 ...
- uc浏览器下载的视频php格式,如何将UC缓存的视频转化为通用的MP4格式?将缓存的视频转化为MP4格式的方法...
用户在使用uc浏览器的时候,总会需要下载视频,那么用户要如何使用才能将浏览器缓存的视频转化成平常使用的mp4格式呢?用户可以将格式转换,在需要互相传递的时候就会更加的方便,如果你也喜欢这个服务,想要使 ...
- C#和Halcon联合编程完成海康工业相机数据转化
C#调用海康工业相机数据转Halcon格式 C#.工业相机和Halcon的混合编程 文章目录 C#调用海康工业相机数据转Halcon格式 前言 一.命名空间的引用 二.海康相机采集图像 1.查找设备 ...
- (超详细)读取mnist数据集并保存成图片
mnist数据集介绍.读取.保存成图片 1.mnist数据集介绍: MNIST数据集是一个手写体数据集,简单说就是一堆这样东西 MNIST的官网地址是 MNIST; 通过阅读官网我们可以知道,这个数 ...
最新文章
- 设计模式之Builder(建造者)(转)
- Educational Codeforces Round 25
- nginx中configure脚本支持的常用选项,拍摄自《Nginx高性能Web服务器详解》
- vSwitch报文转发分析
- HDU 5536 字典树
- pytorch常见问题之cpu占满
- ios 添加导航栏视图_iOS进度栏(进度视图)
- C#中在窗体间使用消息来处理相关联的事件
- linux桌面系统开启wifi,8089B开启Wifi的方法(默认的红旗linux系统)
- aliez歌词_【aLIEz】附平假名歌词(完整)
- Markdown中表格中内容换行、左对齐等基本操作
- Springer Evolutionary Intelligence投稿,提交Latex文件记录
- 用python批量修改图片尺寸
- python入门教学反思_python函数--教学反思
- 腾讯百度之间地图经纬度的转换
- 手机日常使用技巧、和手机停机如何免费上网 。好多大家不知道的功能:不看后悔哦
- 洗礼灵魂,修炼python(67)--爬虫篇—cookielib之爬取需要账户登录验证的网站
- 添加solidworks许可证服务器,SolidWorks许可服务器问题排查
- vscode搭建Verilog HDL开发环境
- git 不显示远端分支问题