:param xs: :param ys: :param batch_size: :param pad_with_last_sample: pad with the last sample to make number of samples divisible to batch_size.
(self, xs, ys, batch_size, pad_with_last_sample=True, shuffle=False)
| 11 | |
| 12 | class DataLoader(object): |
| 13 | def __init__(self, xs, ys, batch_size, pad_with_last_sample=True, shuffle=False): |
| 14 | """ |
| 15 | |
| 16 | :param xs: |
| 17 | :param ys: |
| 18 | :param batch_size: |
| 19 | :param pad_with_last_sample: pad with the last sample to make number of samples divisible to batch_size. |
| 20 | """ |
| 21 | self.batch_size = batch_size |
| 22 | self.current_ind = 0 |
| 23 | if pad_with_last_sample: |
| 24 | num_padding = (batch_size - (len(xs) % batch_size)) % batch_size |
| 25 | x_padding = np.repeat(xs[-1:], num_padding, axis=0) |
| 26 | y_padding = np.repeat(ys[-1:], num_padding, axis=0) |
| 27 | xs = np.concatenate([xs, x_padding], axis=0) |
| 28 | ys = np.concatenate([ys, y_padding], axis=0) |
| 29 | self.size = len(xs) |
| 30 | self.num_batch = int(self.size // self.batch_size) |
| 31 | if shuffle: |
| 32 | permutation = np.random.permutation(self.size) |
| 33 | xs, ys = xs[permutation], ys[permutation] |
| 34 | self.xs = xs |
| 35 | self.ys = ys |
| 36 | |
| 37 | def get_iterator(self): |
| 38 | self.current_ind = 0 |
nothing calls this directly
no outgoing calls
no test coverage detected