From 531a8eabe222c3831cc5b55bafc81d2aa36f0672 Mon Sep 17 00:00:00 2001 From: charlesbensimon Date: Tue, 20 Feb 2018 19:43:14 +0100 Subject: [PATCH] Optimizer - set_weights : check weights length (#9435) --- keras/optimizers.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/keras/optimizers.py b/keras/optimizers.py index 5ea63dccb62..afa93d45bf1 100644 --- a/keras/optimizers.py +++ b/keras/optimizers.py @@ -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):