keras-team/keras · error · ValueError
Variable {self.path} is already initialized.
Error message
Variable {self.path} is already initialized. What it means
Error "Variable {self.path} is already initialized." thrown in keras-team/keras.
Source
Thrown at keras/src/backend/tensorflow/core.py:58
if isinstance(value, tf.Variable):
self._value = value
else:
self._value = tf.Variable(
value,
shape=self._shape,
dtype=self._dtype,
trainable=self.trainable,
name=self.name,
aggregation=self._map_aggregation(self.aggregation),
synchronization=self._map_synchronization(self.synchronization),
)
def _initialize_with_initializer(self, initializer):
self._initialize(lambda: initializer(self._shape, dtype=self._dtype))
def _deferred_initialize(self):
if self._value is not None:
raise ValueError(f"Variable {self.path} is already initialized.")
if in_stateless_scope():
raise ValueError(
"You are attempting to initialize a variable "
"while in a stateless scope. This is disallowed. "
"Make sure that all variables are initialized "
"before you start using your layer/model objects."
)
with tf.init_scope():
self._initialize_with_initializer(self._initializer)
self._initializer = None
def _direct_assign(self, value):
self._value.assign(tf.cast(value, self._value.dtype))
def _convert_to_tensor(self, value, dtype=None):
return convert_to_tensor(value, dtype=dtype)
View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/backend/tensorflow/core.py:58 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/7596822f07f2aec5.
Report an issue: GitHub.