Skip to content
Snippets Groups Projects
Commit dc525c31 authored by Felix Kleinert's avatar Felix Kleinert
Browse files

related to #57

- add static method to permutate inputs and labels
- call static method within distribute on batches
parent 029ffbb0
No related branches found
No related tags found
2 merge requests!50release for v0.7.0,!44Felix issue057 permutate data for minibatches
Pipeline #29812 passed
...@@ -33,6 +33,16 @@ class Distributor(keras.utils.Sequence): ...@@ -33,6 +33,16 @@ class Distributor(keras.utils.Sequence):
def _get_number_of_mini_batches(self, values): def _get_number_of_mini_batches(self, values):
return math.ceil(values[0].shape[0] / self.batch_size) return math.ceil(values[0].shape[0] / self.batch_size)
@staticmethod
def _permutate_data(x, y):
"""
Permutate inputs x and labels y
"""
p = np.random.permutation(len(x)) # equiv to .shape[0]
x = x[p]
y = y[p]
return x, y
def distribute_on_batches(self, fit_call=True): def distribute_on_batches(self, fit_call=True):
while True: while True:
for k, v in enumerate(self.generator): for k, v in enumerate(self.generator):
...@@ -42,6 +52,8 @@ class Distributor(keras.utils.Sequence): ...@@ -42,6 +52,8 @@ class Distributor(keras.utils.Sequence):
num_mini_batches = self._get_number_of_mini_batches(v) num_mini_batches = self._get_number_of_mini_batches(v)
x_total = np.copy(v[0]) x_total = np.copy(v[0])
y_total = np.copy(v[1]) y_total = np.copy(v[1])
# permutate order for mini-batches
x_total, y_total = self._permutate_data(x_total, y_total)
for prev, curr in enumerate(range(1, num_mini_batches+1)): for prev, curr in enumerate(range(1, num_mini_batches+1)):
x = x_total[prev*self.batch_size:curr*self.batch_size, ...] x = x_total[prev*self.batch_size:curr*self.batch_size, ...]
y = [y_total[prev*self.batch_size:curr*self.batch_size, ...] for _ in range(mod_rank)] y = [y_total[prev*self.batch_size:curr*self.batch_size, ...] for _ in range(mod_rank)]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment