tensorflow/models · error · ValueError
`layer` must be a `tf_keras.layer.Layer`. Observed `{}`
Error message
`layer` must be a `tf_keras.layer.Layer`. Observed `{}` What it means
Error "`layer` must be a `tf_keras.layer.Layer`. Observed `{}`" thrown in tensorflow/models.
Source
Thrown at official/nlp/modeling/layers/spectral_normalization.py:75
value estimate.
aggregation: (tf.VariableAggregation) Indicates how a distributed variable
will be aggregated. Accepted values are constants defined in the class
tf.VariableAggregation.
inhere_layer_name: (bool) Whether to inhere the name of the input layer.
**kwargs: (dict) Other keyword arguments for the layers.Wrapper class.
"""
self.iteration = iteration
self.do_power_iteration = training
self.aggregation = aggregation
self.norm_multiplier = norm_multiplier
# Set layer name.
wrapper_name = kwargs.pop('name', None)
if inhere_layer_name:
wrapper_name = layer.name
if not isinstance(layer, tf_keras.layers.Layer):
raise ValueError('`layer` must be a `tf_keras.layer.Layer`. '
'Observed `{}`'.format(layer))
super().__init__(
layer, name=wrapper_name, **kwargs)
def build(self, input_shape): # pytype: disable=signature-mismatch # overriding-parameter-count-checks
super().build(input_shape)
self.layer.kernel._aggregation = self.aggregation # pylint: disable=protected-access
self._dtype = self.layer.kernel.dtype
self.w = self.layer.kernel
self.w_shape = self.w.shape.as_list()
self.v = self.add_weight(
shape=(1, np.prod(self.w_shape[:-1])),
initializer=tf.initializers.random_normal(),
trainable=False,
name='v',
dtype=self.dtype,View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/nlp/modeling/layers/spectral_normalization.py:75 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/a5c95a31bbbe09d3.
Report an issue: GitHub.