tensorflow/models · error · ValueError
Expected rank 4 input, was: %d
Error message
Expected rank 4 input, was: %d
What it means
Error "Expected rank 4 input, was: %d" thrown in tensorflow/models.
Source
Thrown at official/vision/modeling/backbones/mobiledet.py:448
def _get_divisible_by(self):
return self._divisible_by
def _mobiledet_base(self,
inputs: tf.Tensor
) -> Tuple[tf.Tensor, Dict[str, tf.Tensor], int]:
"""Builds the base MobileDet architecture.
Args:
inputs: A `tf.Tensor` of shape `[batch_size, height, width, channels]`.
Returns:
A tuple of output Tensor and dictionary that collects endpoints.
"""
input_shape = inputs.get_shape().as_list()
if len(input_shape) != 4:
raise ValueError('Expected rank 4 input, was: %d' % len(input_shape))
net = inputs
endpoints = {}
endpoint_level = 1
for i, block_def in enumerate(self._decoded_specs):
block_name = 'block_group_{}_{}'.format(block_def.block_fn, i)
if block_def.block_fn == 'convbn':
net = mobilenet.Conv2DBNBlock(
filters=block_def.filters,
kernel_size=block_def.kernel_size,
strides=block_def.strides,
activation=block_def.activation,
use_bias=block_def.use_bias,
use_normalization=block_def.use_normalization,
kernel_initializer=self._kernel_initializer,
kernel_regularizer=self._kernel_regularizer,View on GitHub (pinned to e006f5f0d5)
Solutions
- Feed a rank-4 tensor [batch, height, width, channels] as input.
- Add the missing batch or channel dimension, e.g. with tf.expand_dims, before calling the backbone.
When it happens
Trigger: Thrown at official/vision/modeling/backbones/mobiledet.py:448 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/3439b28c3515a327.
Report an issue: GitHub.