tensorflow/models · error · ValueError
"channels_first" mode is unsupported.
Error message
"channels_first" mode is unsupported.
What it means
Error ""channels_first" mode is unsupported." thrown in tensorflow/models.
Source
Thrown at official/vision/modeling/layers/nn_layers.py:601
"""
frames = input_shape[1]
channels = input_shape[-1]
pos_encoding = self._positional_encoding(
frames, channels, start_position=frame_count, dtype=self.dtype)
pos_encoding = tf.reshape(pos_encoding, [1, frames, 1, 1, channels])
return pos_encoding
def build(self, input_shape):
"""Builds the layer with the given input shape.
Args:
input_shape: The input shape.
Raises:
ValueError: If using 'channels_first' data format.
"""
if tf_keras.backend.image_data_format() == 'channels_first':
raise ValueError('"channels_first" mode is unsupported.')
if self._cache_encoding:
self._pos_encoding = self._get_pos_encoding(input_shape)
super(PositionalEncoding, self).build(input_shape)
def call(
self,
inputs: tf.Tensor,
states: Optional[States] = None,
output_states: bool = True,
) -> Union[tf.Tensor, Tuple[tf.Tensor, States]]:
"""Calls the layer with the given inputs.
Args:
inputs: An input `tf.Tensor`.
states: A `dict` of states such that, if any of the keys match for this
layer, will overwrite the contents of the buffer(s). Expected keysView on GitHub (pinned to e006f5f0d5)
Solutions
- Use 'channels_last' data format.
- Transpose inputs to NHWC instead of using channels_first.
When it happens
Trigger: Thrown at official/vision/modeling/layers/nn_layers.py:601 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/acc03b1a42af6f93.
Report an issue: GitHub.