def generate_batch(episodes, batch_size, device):
    total_steps = sum([len(e) for e in episodes])
    print('Total Steps: {}'.format(total_steps))
    sampler = BatchSampler(RandomSampler(range(len(episodes)), replacement=True, num_samples=total_steps), batch_size, drop_last=True)
    for (nr, indices) in enumerate(sampler):
        x = []
        episodes_batch = [episodes[i] for i in indices]
        for e in episodes_batch:
            t = np.random.randint(0, len(e))
            x.append(e[t])
        (yield (torch.stack(x).float().to(device) / 255.0))
def generate_batch(episodes, batch_size, device):
    total_steps = sum([len(e) for e in episodes])
    print('Total Steps: {}'.format(total_steps))
    sampler = BatchSampler(RandomSampler(range(len(episodes)), replacement=True, num_samples=total_steps), batch_size, drop_last=True)
    for (nr, indices) in enumerate(sampler):
        x = []
        episodes_batch = [episodes[i] for i in indices]
        for e in episodes_batch:
            t = np.random.randint(0, len(e))
            x.append(e[t])
        (yield (torch.stack(x).float().to(device) / 255.0))