{"record":{"id":"acc03b1a42af6f93","repo":"tensorflow/models","slug":"channels-first-mode-is-unsupported","errorCode":null,"errorMessage":"\"channels_first\" mode is unsupported.","messagePattern":"\"channels_first\" mode is unsupported\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/modeling/layers/nn_layers.py","lineNumber":601,"sourceCode":"    \"\"\"\n    frames = input_shape[1]\n    channels = input_shape[-1]\n    pos_encoding = self._positional_encoding(\n        frames, channels, start_position=frame_count, dtype=self.dtype)\n    pos_encoding = tf.reshape(pos_encoding, [1, frames, 1, 1, channels])\n    return pos_encoding\n\n  def build(self, input_shape):\n    \"\"\"Builds the layer with the given input shape.\n\n    Args:\n      input_shape: The input shape.\n\n    Raises:\n      ValueError: If using 'channels_first' data format.\n    \"\"\"\n    if tf_keras.backend.image_data_format() == 'channels_first':\n      raise ValueError('\"channels_first\" mode is unsupported.')\n\n    if self._cache_encoding:\n      self._pos_encoding = self._get_pos_encoding(input_shape)\n\n    super(PositionalEncoding, self).build(input_shape)\n\n  def call(\n      self,\n      inputs: tf.Tensor,\n      states: Optional[States] = None,\n      output_states: bool = True,\n  ) -> Union[tf.Tensor, Tuple[tf.Tensor, States]]:\n    \"\"\"Calls the layer with the given inputs.\n\n    Args:\n      inputs: An input `tf.Tensor`.\n      states: A `dict` of states such that, if any of the keys match for this\n        layer, will overwrite the contents of the buffer(s). Expected keys","sourceCodeStart":583,"sourceCodeEnd":619,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/modeling/layers/nn_layers.py#L583-L619","documentation":"Error \"\"channels_first\" mode is unsupported.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/modeling/layers/nn_layers.py:601 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use 'channels_last' data format.","Transpose inputs to NHWC instead of using channels_first."],"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"}