{"record":{"id":"572195193153fd00","repo":"tensorflow/models","slug":"tensor-rank-must-be-at-least-d-got-d","errorCode":null,"errorMessage":"Tensor rank must be at least %d. Got %d","messagePattern":"Tensor rank must be at least (.+?)\\. Got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/unified_detector/utils/utilities.py","lineNumber":54,"sourceCode":"    dimension otherwise.\n  \"\"\"\n  with tf.name_scope('resolve_shape'):\n    shape = tensor.get_shape().as_list()\n    if None in shape:\n      shape_dynamic = tf.shape(tensor)\n      if shape[0] is None:\n        shape[0] = shape_dynamic[0] if resolve_batch_size else -1\n      for i in range(1, len(shape)):\n        if shape[i] is None:\n          shape[i] = shape_dynamic[i]\n    return shape\n\n\ndef set_shape_dim(tensor: tf.Tensor, index: int, size: int) -> None:\n  \"\"\"Set value of index-th element of tensor shape to size.\"\"\"\n  shape = tensor.get_shape().as_list()\n  if len(shape) <= index:\n    raise ValueError(\n        'Tensor rank must be at least %d. Got %d' % (index + 1, len(shape)))\n  shape[index] = size\n  tensor.set_shape(shape)\n\n\ndef truncate_or_pad(input_tensor: tf.Tensor,\n                    new_size: int,\n                    axis: int = 1,\n                    constant_value: Union[int, float] = 0) -> tf.Tensor:\n  \"\"\"Truncate or zeros pad the axis of input tensor to new size.\"\"\"\n  rank = len(input_tensor.shape)\n\n  if rank <= axis:\n    raise ValueError(\n        'Tensor rank must be at least %d. Got %d' % (axis + 1, rank))\n\n  orig_size = tf.shape(input_tensor)[axis]\n","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/unified_detector/utils/utilities.py#L36-L72","documentation":"Error \"Tensor rank must be at least %d. Got %d\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/unified_detector/utils/utilities.py:54 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"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"}