Skip to content

Instantly share code, notes, and snippets.

@ahmedfgad
Last active November 20, 2020 12:52
Show Gist options
  • Save ahmedfgad/bad30781383c095380d5de42eaa5892d to your computer and use it in GitHub Desktop.
Save ahmedfgad/bad30781383c095380d5de42eaa5892d to your computer and use it in GitHub Desktop.
def model_averaging(self, model, other_model):
model_weights = pygad.nn.layers_weights(last_layer=model, initial=False)
other_model_weights = pygad.nn.layers_weights(last_layer=other_model, initial=False)
new_weights = numpy.array(model_weights + other_model_weights)/2
pygad.nn.update_layers_trained_weights(last_layer=model, final_weights=new_weights)
@ahmedfgad
Copy link
Author

This commit solves this bug:
Error Decoding the Client's Data: unsupported operand type(s) for /: 'list' and 'int'.

It occurs due to this line in the model_averaging() method in the SocketThread class:
new_weights = (model_weights + other_model_weights)/2

The reason is that (model_weights + other_model_weights) is a list which is then divided by 2. This is an illegal list operation.

The solution is to convert (model_weights + other_model_weights) into a NumPy array then perform the division by 2:
new_weights = numpy.array(model_weights + other_model_weights)/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment