{"record":{"id":"af4215373bf75d23","repo":"tensorflow/models","slug":"expected-rank-4-input-was-d-af4215","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/mobilenet.py","lineNumber":1361,"sourceCode":"      return 1\n    else:\n      return self._divisible_by\n\n  def _mobilenet_base(\n      self, inputs: tf.Tensor\n  ) -> tuple[tf.Tensor, dict[str, tf.Tensor], int]:\n    \"\"\"Builds the base MobileNet 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    # The current_stride variable keeps track of the output stride of the\n    # activations, i.e., the running product of convolution strides up to the\n    # current network layer. This allows us to invoke atrous convolution\n    # whenever applying the next convolution would result in the activations\n    # having output stride larger than the target output_stride.\n    current_stride = 1\n\n    # The atrous convolution rate parameter.\n    rate = 1\n\n    # Used to calulate stochastic depth drop rate. Some blocks do not use\n    # stochastic depth since they do not have residuals. For simplicity, we\n    # count here all the blocks in the model. If one or more of the last layers\n    # do not use stochastic depth, it can be compensated with larger stochastic\n    # depth drop rate.\n    num_blocks = len(self._decoded_specs)\n","sourceCodeStart":1343,"sourceCodeEnd":1379,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/modeling/backbones/mobilenet.py#L1343-L1379","documentation":"Error \"Expected rank 4 input, was: %d\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/modeling/backbones/mobilenet.py:1361 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"}