当前位置:网站首页>Mxnet record IO details
Mxnet record IO details
2022-06-12 20:57:00 【Human high quality Algorithm Engineer】
I am looking at the identification code recently , There are still many things worth learning , For example, distributed training , Data reading , Because the amount of training data identified is very large , Data production 、 Reading will greatly affect the training speed , Here is a summary of the data loading and reading section .
First , When we need to use large data sets to train models , At this time, loading and reading data becomes the bottleneck of our training . and Mxnet Provides a data storage format ImageRecord, With this data storage format, you can use multiple processes to load data , It can greatly improve the efficiency of training .
Mxnet Provides a mx.recordio modular , It can be done to ImageRecord File operation , This module contains two sub modules .MXRecordIO Support sequential read and write ,MXIndexedRecordIO Support random read and write . Let's take a look at , Some interface functions in these two sub modules , And how to use them to read and save ImageRecord file
- Save the data as rec Format , And the corresponding index file

Save the picture as rec Format
import mxnet as mx
write_record = mx.recordio.MXIndexedRecordIO("test.idx","test.rec", 'w')
# Read the picture
img_path = "img/test.jpg"
# Convert picture data to Numpy Array
img = mx.image.imread(img_path).asnumpy()
label = 1.0
header = mx.recordio.IRHeader(flag=0,label=label,id=0,id2=0)
s = mx.recordio.pack_img(header,img,quality=95,img_fmt=".jpg")
# Writes data to rec In file
write_record.write_idx(0,s)
write_record.close()
Read the picture rec Format
import mxnet as mx
read_record = mx.recordio.MXIndexedRecordIO(path_imgidx, path_imgrec, 'r')
def __getitem__(self, index):
idx = self.imgidx[index]
s = self.imgrec.read_idx(idx)
header, img = mx.recordio.unpack(s)
label = header.label
if not isinstance(label, numbers.Number):
label = label[0]
label = torch.tensor(label, dtype=torch.long)
sample = mx.image.imdecode(img).asnumpy()
##########################################
#sample = cv2.cvtColor(sample, cv2.COLOR_BGR2GRAY)
#sample = cv2.cvtColor(sample, cv2.COLOR_GRAY2BGR)
##########################################
if self.transform is not None:
sample = self.transform(sample)
return sample, label
here unpack Read it out MXImageRecord Decompress to image, label and img Change to the corresponding type and process transform, It can be used as the input of the network .
Reference resources :
1.https://xiulian.blog.csdn.net/article/details/107210952
2. https://blog.csdn.net/qq_20622615/article/details/88633767
边栏推荐
- 解决cvxpy报错The solver GLPK_MI is not installed
- 居家办公期间如何提升沟通效率|社区征文
- 同花顺能开户吗,同花顺在APP上可以直接开通券商安全吗 ,买股票怎么网上开户
- UVa11991 Easy Problem from Rujia Liu
- String Basics
- 中小型机房动力环境综合监控解决方案
- Integrated monitoring solution for power environment of small and medium-sized computer rooms
- leetcode:210. 课程表 II
- Technology to understand
- 初步了解认识正则表达式(Regex)
猜你喜欢

Nexus3搭建本地仓库

Properties to YML

设计规则检查约束(set_max_transition、set_max_capacitance)

leetcode:210. 课程表 II

Junda technology is applicable to "kestar" intelligent precision air conditioning network monitoring

逐向双碳:东数西算中的绿色需求与竞争焦点

Data visualization - histogram

What's a good gift for the goddess Festival? Gift recommendation for the goddess Festival on March 8

It has been engaged in the functional test of 10K to the test development of 40W annual salary for 5 years, and spent 7 days sorting out the super comprehensive learning route

中小型机房动力环境综合监控解决方案
随机推荐
竣达技术丨适用于“科士达”智能精密空调网络监控
Why my order by create_ Time ASC becomes order by ASC
字符串基础知识
JS中如何实现重载
同时做测试,别人已经年薪20w起,为什么你还在为达到月薪10k而努力?
It has been engaged in the functional test of 10K to the test development of 40W annual salary for 5 years, and spent 7 days sorting out the super comprehensive learning route
Circularly insert one excel column and the sum of multiple columns
How can CTCM in the inspection lot system status of SAP QM be eliminated?
设计规则检查约束(set_max_transition、set_max_capacitance)
Solution of multi machine room dynamic loop status network touch screen monitoring
逐向双碳:东数西算中的绿色需求与竞争焦点
MinIO客户端(mc命令)实现数据迁移
[live streaming] understand the design of d3js and learn how to read the source code.
P5076 【深基16.例7】普通二叉樹(簡化版)
go --- 监控文件变化
Data visualization - biaxial comparison effect
Simplest ALV template
Algorinote_2_主定理与 Akra-Bazzi 定理
P5076 [deep base 16. Example 7] common binary tree (simplified version)
Shell language