{"record":{"id":"64df7b66eb11a999","repo":"tensorflow/models","slug":"layer-must-be-a-tf-keras-layer-conv2d-instance","errorCode":null,"errorMessage":"layer must be a `tf_keras.layer.Conv2D` instance. You passed: {input}","messagePattern":"layer must be a `tf_keras\\.layer\\.Conv2D` instance\\. You passed: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/layers/spectral_normalization.py","lineNumber":193,"sourceCode":"      aggregation: (tf.VariableAggregation) Indicates how a distributed variable\n        will be aggregated. Accepted values are constants defined in the class\n        tf.VariableAggregation.\n      legacy_mode: (bool) Whether to use the legacy implementation where the\n        dimension of the u and v vectors are set to the batch size. It should\n        not be enabled unless for backward compatibility reasons.\n      **kwargs: (dict) Other keyword arguments for the layers.Wrapper class.\n    \"\"\"\n    self.iteration = iteration\n    self.do_power_iteration = training\n    self.aggregation = aggregation\n    self.norm_multiplier = norm_multiplier\n    self.legacy_mode = legacy_mode\n\n    # Set layer attributes.\n    layer._name += '_spec_norm'\n\n    if not isinstance(layer, tf_keras.layers.Conv2D):\n      raise ValueError(\n          'layer must be a `tf_keras.layer.Conv2D` instance. You passed: {input}'\n          .format(input=layer))\n    super().__init__(layer, **kwargs)\n\n  def build(self, input_shape):  # pytype: disable=signature-mismatch  # overriding-parameter-count-checks\n    if not self.layer.built:\n      self.layer.build(input_shape)\n    self.layer.kernel._aggregation = self.aggregation  # pylint: disable=protected-access\n    self._dtype = self.layer.kernel.dtype\n\n    # Shape (kernel_size_1, kernel_size_2, in_channel, out_channel).\n    self.w = self.layer.kernel\n    self.w_shape = self.w.shape.as_list()\n    self.strides = self.layer.strides\n\n    # Set the dimensions of u and v vectors.\n    batch_size = input_shape[0]\n    uv_dim = batch_size if self.legacy_mode else 1","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/layers/spectral_normalization.py#L175-L211","documentation":"Error \"layer must be a `tf_keras.layer.Conv2D` instance. You passed: {input}\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/layers/spectral_normalization.py:193 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}