当前位置:网站首页>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
边栏推荐
- Recommended by the world's most technologically competent smart contract security audit company in 2022
- Disk management and file system
- Introduction to the official functions of easyrecovery14 data recovery software
- How to delete or replace the loading style of easyplayer streaming media player?
- 2022上半年英特尔有哪些“硬核创新”?看这张图就知道了!
- TS学习(八) :TS中的类
- 【11】 Binary code: "holding two roller handcuffs, crying out for hot hot hot"?
- Soul submitted an application for listing in Hong Kong stocks, accelerating the diversified and scene based layout of social gathering places
- Some applications of std:: bind and std:: function
- How to make the minimum API bind the array in the query string
猜你喜欢

MangoDB

ES6的新特性(2)

The problem of torch loading custom models

2022上半年英特尔有哪些“硬核创新”?看这张图就知道了!

如何让最小 API 绑定查询字符串中的数组

O2O电商线上线下一体化模式分析

Pruning - quantification - turn to onnx Chinese series tutorials

硫化镉CdS量子点修饰脱氧核糖核酸DNA|CdS-DNA QDs|近红外CdS量子点偶联DNA规格信息

Deepsort工作原理分析

To improve the baby's allergy, take yiminshu. Azg and aibeca love la Beijia work together to protect the growth of Chinese babies
随机推荐
Mysql database
MangoDB
Talk about why you need to declare the member function of a class as private
vscode运行命令报错:标记“&&”不是此版本中的有效语句分隔符。
The problem of torch loading custom models
Speech and language processing (3rd ed. draft) Chapter 2 - regular expression, text normalization, editing distance reading notes
Where to connect with user-defined functions leads to slow queries
NFS introduction and configuration
nvidia-smi 各参数意义
Px4 source code compilation to establish its own program module
PNA肽核酸修饰多肽Suc-Tyr-Leu-Val-pNA|Suc-Ala-Pro-Phe-pNA 11
Pymysql query result conversion JSON
Disk management and file system
GoLand writes Go program
正则表达式
PNA修饰多肽ARMS-PNA|PNA-DNA|suc-AAPF-pNA|Suc-(Ala)3-pNA
Deepsort工作原理分析
聊聊大火的多模态
Sunflower teaches you how to prevent denial of service attacks?
Sunflower: don't worry when you encounter computer vulnerabilities, understand clearly and then judge sunflower: don't worry when you encounter computer vulnerabilities, understand clearly and then ju