Combine / concat dataset instances
I came up with two ideas: <SCODE>class Concat(Dataset):

    def __init__(self, datasets):
        self.datasets = datasets
        self.lengths = [len(d) for d in datasets]
        self.offsets = np.cumsum(self.lengths)
        self.length = np.sum(self.lengths)

    def __getitem__(self, index):
        for i, offset in enumerate(self.offsets):
            if index < offset:
                if i > 0:
                    index -= self.offsets[i-1]
                return self.datasets[i][index]
        raise IndexError(f'{index} exceeds {self.length}')

    def __len__(self):
        return self.length
<ECODE> <SCODE>loader = itertools.chain(*[MyDataset(f'file{i}') for i in range(1, 4)])
<ECODE>
bodokaiser
apaszke
<SCODE>x = itertools.repeat(itertools.chain.from_iterable([dataset1, dataset2]), times=epochs)

next(next(iter(x))

# or 

for epoch in x:
    for (inputs, targets) in epoch:
       print(inputs)
<ECODE>
bodokaiser
<SCODE>for epoch in range(num_epochs):
    dset = itertools.chain(...)
    dloader = # create DataLoader
    for ... in dloader:
        ...
<ECODE>
apaszke
acgtyrant
jnhwkim
<SCODE>def return_all_items(dataset):
  all_items = []
  for i in range(len(dataset)):
    all_items.append(dataset[i])
  return all_items
<ECODE> <SCODE>list1 = return_all_items(original_data)
list2 = return_all_items(transformed_data)
list1.extend(list2)
<ECODE> then converting the list to dataset object <SCODE>class AugmentedDataset(Dataset):
  
  def __init__(self, combined_list, transform=None):
    self.combined_list = combined_list
    
  def __len__(self):
    return len(self.combined_list)
  
  def __getitem__(self, idx):
    sample = self.combined_list[idx]      
    return sample
  
augmented_dataset = AugmentedDataset(list1)
<ECODE>
kavyajeetbora
jasha