N3PDF / evolutionary_keras

An evolutionary algorithm implementation for Keras
GNU General Public License v3.0
10 stars 7 forks source link

Weight undo_flatten method bug #34

Closed europaer closed 3 years ago

europaer commented 3 years ago

There is a bug in the undo_flatten method inside the CMA optimizer. The weights are not well positioned back in place because length_flat_layer contains lengths and not indices.

for i, layer_shape in enumerate(self.shape):
    flat_layer = flattened_weights[
                           self.length_flat_layer[i]: self.length_flat_layer[i] + self.length_flat_layer[i + 1]
                      ]

This could be a quick fix

index_start = self.length_flat_layer[i] + sum(self.length_flat_layer[:i])
index_end = index_start + self.length_flat_layer[i + 1]
flat_layer = weights_flattened[index_start:index_end]
RoyStegeman commented 3 years ago

Ah yes, you are absolutely correct, the starting index should have been calculated cumulatively. Thanks for pointing this out!