keras-team/keras · error · AttributeError
`Model.layers` attribute is reserved and should not be used.
Error message
`Model.layers` attribute is reserved and should not be used. Please use another name.
What it means
Error "`Model.layers` attribute is reserved and should not be used. Please use another name." thrown in keras-team/keras.
Source
Thrown at keras/src/models/functional.py:169
# Unlike other layers, we allow Functional state to be mutable after
# build. E.g. to attach a layer to a model that is not part of the
# functional DAG.
pass
def _obj_type(self):
return "Functional"
@property
def layers(self):
layers = []
for operation in self._operations:
if isinstance(operation, Layer):
layers.append(operation)
return layers
@layers.setter
def layers(self, _):
raise AttributeError(
"`Model.layers` attribute is reserved and should not be used. "
"Please use another name."
)
def call(self, inputs, training=None, mask=None):
# Add support for training, masking
inputs = self._standardize_inputs(inputs)
if mask is None:
masks = [None] * len(inputs)
else:
masks = tree.flatten(mask)
for x, mask in zip(inputs, masks):
if mask is not None:
backend.set_keras_mask(x, mask)
outputs = self._run_through_graph(inputs)
return unpack_singleton(outputs)
def compute_output_spec(self, inputs, training=None, mask=None):View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/models/functional.py:169 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/d5588b47c9ae4c71.
Report an issue: GitHub.