{"record":{"id":"3439b28c3515a327","repo":"tensorflow/models","slug":"expected-rank-4-input-was-d","errorCode":null,"errorMessage":"Expected rank 4 input, was: %d","messagePattern":"Expected rank 4 input, was: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/modeling/backbones/mobiledet.py","lineNumber":448,"sourceCode":"\n  def _get_divisible_by(self):\n    return self._divisible_by\n\n  def _mobiledet_base(self,\n                      inputs: tf.Tensor\n                      ) -> Tuple[tf.Tensor, Dict[str, tf.Tensor], int]:\n    \"\"\"Builds the base MobileDet architecture.\n\n    Args:\n      inputs: A `tf.Tensor` of shape `[batch_size, height, width, channels]`.\n\n    Returns:\n      A tuple of output Tensor and dictionary that collects endpoints.\n    \"\"\"\n\n    input_shape = inputs.get_shape().as_list()\n    if len(input_shape) != 4:\n      raise ValueError('Expected rank 4 input, was: %d' % len(input_shape))\n\n    net = inputs\n    endpoints = {}\n    endpoint_level = 1\n    for i, block_def in enumerate(self._decoded_specs):\n      block_name = 'block_group_{}_{}'.format(block_def.block_fn, i)\n\n      if block_def.block_fn == 'convbn':\n\n        net = mobilenet.Conv2DBNBlock(\n            filters=block_def.filters,\n            kernel_size=block_def.kernel_size,\n            strides=block_def.strides,\n            activation=block_def.activation,\n            use_bias=block_def.use_bias,\n            use_normalization=block_def.use_normalization,\n            kernel_initializer=self._kernel_initializer,\n            kernel_regularizer=self._kernel_regularizer,","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/modeling/backbones/mobiledet.py#L430-L466","documentation":"Error \"Expected rank 4 input, was: %d\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/modeling/backbones/mobiledet.py:448 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"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"}