如何使用Pytorch中的数据加载程序访问下一步数据?
我正在使用训练神经网络的代码。该代码使用Pytorch的数据加载器为每次迭代加载数据。代码看起来如下所示
for step, data in enumerate(dataloader, 0):
............................................................
output = neuralnetwork_model(data)
.............................................................
,步骤是一个整数,可在每个步骤中给出值0、1、2、3的整数。数据给出了一批样本。代码在每个步骤中将相应的批次传递给神经网络。
我需要在步骤n处访问步骤n+1的数据。我需要这样的东西
for step, data in enumerate(dataloader, 0):
............................................................
output = neuralnetwork_model(data)
access = data_of_next_step
.............................................................
我该如何实现?
I am using a code that trains neural networks. The code uses the DataLoader of PyTorch to load the data for every iteration. The code looks as follows
for step, data in enumerate(dataloader, 0):
............................................................
output = neuralnetwork_model(data)
.............................................................
Here the step is an integer that gives values 0, 1, 2, 3, ....... and data gives a batch of samples at each step. The code passes corresponding batches to the neural network at each step.
I need to just access the data of step n+1 at step n. I need something like this
for step, data in enumerate(dataloader, 0):
............................................................
output = neuralnetwork_model(data)
access = data_of_next_step
.............................................................
How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在迭代级别上执行此类操作似乎更加方便,而不必更改数据加载器实现。查看
n
连续元素具有重叠 您可以实现这使用itertools.tees.tees.tees.tee
:因此,您只需要在包装的数据加载程序上迭代以下方式:
It seems to be handier to perform such manipulation at the iteration level rather than having to change the data loaders implementation. Looking at Iterate over
n
successive elements with overlap you can achieve this usingitertools.tee
:Therefore you simply have to iterate over your wrapped data loader with: