DataLoader for a LSTM Model with a Sliding Window

The SequantialSampler samples your data sequentially in the same order.
To use a sliding window, I would create an own Dataset and use the __getitem__ method to get the sliding window.
Here is a small example (untested):

class MyDataset(Dataset):
    def __init__(self, data, window):
        self.data = data
        self.window = window

    def __getitem__(self, index):
        x = self.data[index:index+self.window]
        return x

    def __len__(self):
        return len(self.data) - self.window
14 Likes