keras-team/keras · error · ValueError
A KerasTensor is symbolic: it's a placeholder for a shape…
Error message
A KerasTensor is symbolic: it's a placeholder for a shape an a dtype. It doesn't have any actual numerical value. You cannot convert it to an int.
What it means
Raised from KerasTensor.__int__ when int() (or implicit integer coercion) is applied to a KerasTensor. A KerasTensor only records shape/dtype metadata in a Functional-model graph and holds no data, so no numeric conversion exists; the dunder is a guard that makes this fail fast and clearly.
Solutions
- Run the model (or the enclosing Keras Function) on real inputs and call int() on the resulting backend tensor
- Replace symbolic tensor usage with concrete values when a numeric scalar is required
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/backend/common/keras_tensor.py:150 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/82400e6cbe98c53c.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/backend/common/keras_tensor.py:150
"create a new instance of KerasTensor for this."
)
@property
def ndim(self):
return len(self.shape)
def reshape(self, newshape):
from keras.src import ops
return ops.Reshape(newshape)(self)
def squeeze(self, axis=None):
from keras.src import ops
return ops.Squeeze(axis)(self)
def __int__(self):
raise ValueError(
"A KerasTensor is symbolic: it's a placeholder for a shape "
"an a dtype. It doesn't have any actual numerical value. "
"You cannot convert it to an int."
)
def __float__(self):
raise ValueError(
"A KerasTensor is symbolic: it's a placeholder for a shape "
"an a dtype. It doesn't have any actual numerical value. "
"You cannot convert it to a float."
)
def __array__(self):
raise ValueError(
"A KerasTensor is symbolic: it's a placeholder for a shape "
"an a dtype. It doesn't have any actual numerical value. "
"You cannot convert it to a NumPy array."
)View on GitHub (pinned to 7a34a03db6)