Skip to content

Commit 9c7020f

Browse files
lgautierfchollet
authored andcommitted
Only allow the addition to Sequential objects of layers that are instances of Layer (keras-team#4184)
* Check that the added object is an instance of class Layer * Update models.py * Fix ValueError error message
1 parent 556399c commit 9c7020f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

keras/models.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from . import backend as K
99
from .utils.io_utils import ask_to_proceed_with_overwrite
1010
from .engine.training import Model
11-
from .engine.topology import get_source_inputs, Node
11+
from .engine.topology import get_source_inputs, Node, Layer
1212
from .optimizers import optimizer_from_config
1313
from .legacy.models import Graph
1414

@@ -260,6 +260,10 @@ def add(self, layer):
260260
# Arguments
261261
layer: layer instance.
262262
'''
263+
if not isinstance(layer, Layer):
264+
raise ValueError('The added layer must be '
265+
'an instance of class Layer. '
266+
'Found: ' + str(layer))
263267
if not self.outputs:
264268
# first layer in model: check that it is an input layer
265269
if len(layer.inbound_nodes) == 0:

0 commit comments

Comments
 (0)