diff --git a/keras_preprocessing/image/iterator.py b/keras_preprocessing/image/iterator.py index c62b1d3a..d810ef9d 100644 --- a/keras_preprocessing/image/iterator.py +++ b/keras_preprocessing/image/iterator.py @@ -33,6 +33,7 @@ def __init__(self, n, batch_size, shuffle, seed): self.n = n self.batch_size = batch_size self.seed = seed + self.numpy_generator = np.random.default_rnq(seed) self.shuffle = shuffle self.batch_index = 0 self.total_batches_seen = 0 @@ -43,7 +44,7 @@ def __init__(self, n, batch_size, shuffle, seed): def _set_index_array(self): self.index_array = np.arange(self.n) if self.shuffle: - self.index_array = np.random.permutation(self.n) + self.index_array = self.numpy_generator.permutation(self.n) def __getitem__(self, idx): if idx >= len(self): @@ -51,8 +52,6 @@ def __getitem__(self, idx): 'but the Sequence ' 'has length {length}'.format(idx=idx, length=len(self))) - if self.seed is not None: - np.random.seed(self.seed + self.total_batches_seen) self.total_batches_seen += 1 if self.index_array is None: self._set_index_array() @@ -73,8 +72,6 @@ def _flow_index(self): # Ensure self.batch_index is 0. self.reset() while 1: - if self.seed is not None: - np.random.seed(self.seed + self.total_batches_seen) if self.batch_index == 0: self._set_index_array()