当前位置:网站首页>Pytorch uses data_ Prefetcher improves data reading speed
Pytorch uses data_ Prefetcher improves data reading speed
2022-07-27 06:57:00 【Mr_ health】
Give the code directly :
class data_prefetcher():
def __init__(self, loader):
#loader 1:real
#loader 2:fake
self.stream = torch.cuda.Stream()
self.loader = iter(loader)
self.preload()
def preload(self):
try:
self.next_input, self.next_target = next(self.loader)
except StopIteration:
self.next_input = None
self.next_target = None
return
with torch.cuda.stream(self.stream):
self.next_input = self.next_input.cuda(non_blocking=True).float()
self.next_target = self.next_target.cuda(non_blocking=True).long()
def next(self):
torch.cuda.current_stream().wait_stream(self.stream)
input = self.next_input
target = self.next_target
self.preload()
return input, targetBefore transformation :
- Code
train_datasets = customData()
train_dataloaders = torch.utils.data.DataLoader(train_datasets,shuffle=True)
for data in train_dataloaders:
current_iter += 1
inputs, labels = data- Training time

After transformation :
- Code
train_datasets = customData()
train_dataloaders = torch.utils.data.DataLoader(train_datasets,shuffle=True)
### increase
prefetcher = data_prefetcher(train_dataloaders)
### increase
inputs, labels = prefetcher.next()
while inputs is not None:
current_iter += 1
inputs, labels = prefetcher.next() - Training time
边栏推荐
- EasyRecovery14数据恢复软件官方功能简介
- Sok: the faults in our asrs: an overview of attacks against automatic speech recognition
- DNA偶联PbSe量子点|近红外硒化铅PbSe量子点修饰脱氧核糖核酸DNA|PbSe-DNA QDs
- Basic concepts of program, process, thread, coprocess, single thread and multi thread
- Is it feasible to fix the vulnerability with one click? Sunflower to tell you that one click fix vulnerability is feasible? Sunflower to tell you that one click fix vulnerability is feasible? Sunflowe
- Mysql database
- Redis' idea under windows is not connected
- What is the reason why the channel list is empty on the intelligent security video platform easycvr?
- Sunflower teaches you how to prevent denial of service attacks?
- deepsort源码解读(六)
猜你喜欢

Express接收请求参数

Is it feasible to fix the vulnerability with one click? Sunflower to tell you that one click fix vulnerability is feasible? Sunflower to tell you that one click fix vulnerability is feasible? Sunflowe

改善宝宝过敏就吃伊敏舒,azg与Aibeca爱楽倍佳携手守护中国宝宝成长

众多世界500强企业集聚第二届数博会,数字产业大幕即将开启!

Mysql database

Redis operation of Linux Installation

Px4 source code compilation to establish its own program module

Sunflower teaches you how to prevent denial of service attacks?

The problem of torch loading custom models

如何让最小 API 绑定查询字符串中的数组
随机推荐
FTX.US推出股票和ETF交易服务,让交易更透明
Multimodal database | star ring technology multimode database argodb "one database for multiple purposes", building a high-performance Lake warehouse integrated platform
Log in to Alibaba cloud server with a key
AI:业余时间打比赛—挣它个小小目标—【阿里安全×ICDM 2022】大规模电商图上的风险商品检测比赛
Build cloud native operating environment
硫化镉CdS量子点修饰脱氧核糖核酸DNA|CdS-DNA QDs|近红外CdS量子点偶联DNA规格信息
deepsort源码解读(四)
CASS11.0.0.4 for AutoCAD2010-2023免狗使用方法
GoLand 编写go程序
How to make the minimum API bind the array in the query string
When a subclass calls the constructor of its parent class
What if the website server is attacked? Sunflower tips that preventing loopholes is the key
如何避免漏洞?向日葵远程为你讲解不同场景下的安全使用方法
最新!国资委发布国有企业数字化转型新举措
使用密钥方式登录阿里云服务器
EasyRecovery14数据恢复软件官方功能简介
Relevant preparation materials for system design
Brief introduction of chip, memory and its key indicators I
gin-vue-admin 使用docker容器中的数据库
deepsort源码解读(二)