Created
November 11, 2022 20:41
-
-
Save KeAWang/e1baa939bf5bfe83502ab068fa224221 to your computer and use it in GitHub Desktop.
Pytorch data inheriting namedtuples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
class Data(namedtuple("Data", ("x", "y"))): | |
def to(self, device, non_blocking=False): | |
x = self.x.to(device, non_blocking=non_blocking) | |
y = self.y.to(device, non_blocking=non_blocking) | |
return Data(x, y) | |
def contiguous(self): | |
x = self.x.contiguous() | |
y = self.y.contiguous() | |
return Data(x, y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment