Пример #1
0
 def gen_batches(self, batch_size, **kwargs):
     assert self.is_ready
     checker.check_positive_integer(self.batches_per_epoch)
     for i in range(self.batches_per_epoch):
         matrix, labels = self._random_signal_matrix(
             batch_size, self.input_size)
         batch = DataSet(matrix, labels)
         batch.name = 'gpat_{}of{}'.format(i + 1, self.batches_per_epoch)
         yield batch
Пример #2
0
    def _gen_rnn_batches(self, x, y, num_steps, *args):
        # Sanity check
        assert isinstance(x, np.ndarray) and isinstance(y, np.ndarray)
        assert isinstance(num_steps, int)
        assert len(x.shape) == 3 and x.shape[2] == self.input_size
        steps = x.shape[1]
        assert y.shape == (x.shape[0], steps, self.NUM_CLASSES)

        # Yield RNN batches
        if num_steps < 0: num_steps = steps
        yield_times = int(np.ceil(steps / num_steps))
        for i in range(yield_times):
            batch_x = x[:, i * num_steps:min((i + 1) * num_steps, steps)]
            batch_y = y[:, i * num_steps:min((i + 1) * num_steps, steps)]
            batch = DataSet(batch_x, batch_y, in_rnn_format=True)

            # State should be reset at the beginning of a sequence
            if i == 0: batch.should_reset_state = True
            batch.name = 'gpat_{}of{}'.format(i + 1, yield_times)
            yield batch