Skip to content

Commit

Permalink
Optimizer - set_weights : check weights length (#9435)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbensimon authored and fchollet committed Feb 20, 2018
1 parent ba204bc commit 531a8ea
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions keras/optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ def set_weights(self, weights):
ValueError: in case of incompatible weight shapes.
"""
params = self.weights
if len(params) != len(weights):
raise ValueError('Length of the specified weight list (' +
str(len(weights)) +
') does not match the number of weights ' +
'of the optimizer (' + str(len(params)) + ')')
weight_value_tuples = []
param_values = K.batch_get_value(params)
for pv, p, w in zip(param_values, params, weights):
Expand Down

0 comments on commit 531a8ea

Please sign in to comment.