{"record":{"id":"c441c8b742f358cc","repo":"tensorflow/models","slug":"translations-should-have-rank-1-or-2","errorCode":null,"errorMessage":"translations should have rank 1 or 2.","messagePattern":"translations should have rank 1 or 2\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"official/legacy/image_classification/augment.py","lineNumber":105,"sourceCode":"      2-element lists representing [dx dy] to translate for each image. The\n      shape must be static.\n\n  Returns:\n    The transformation matrix of shape (num_images, 8).\n\n  Raises:\n    `TypeError` if\n      - the shape of `translations` is not known or\n      - the shape of `translations` is not rank 1 or 2.\n\n  \"\"\"\n  translations = tf.convert_to_tensor(translations, dtype=tf.float32)\n  if translations.get_shape().ndims is None:\n    raise TypeError('translations rank must be statically known')\n  elif len(translations.get_shape()) == 1:\n    translations = translations[None]\n  elif len(translations.get_shape()) != 2:\n    raise TypeError('translations should have rank 1 or 2.')\n  num_translations = tf.shape(translations)[0]\n\n  return tf.concat(\n      values=[\n          tf.ones((num_translations, 1), tf.dtypes.float32),\n          tf.zeros((num_translations, 1), tf.dtypes.float32),\n          -translations[:, 0, None],\n          tf.zeros((num_translations, 1), tf.dtypes.float32),\n          tf.ones((num_translations, 1), tf.dtypes.float32),\n          -translations[:, 1, None],\n          tf.zeros((num_translations, 2), tf.dtypes.float32),\n      ],\n      axis=1,\n  )\n\n\ndef _convert_angles_to_transform(angles: tf.Tensor, image_width: tf.Tensor,\n                                 image_height: tf.Tensor) -> tf.Tensor:","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/legacy/image_classification/augment.py#L87-L123","documentation":"Rank guard in _convert_translation_to_transform: translations has rank > 2; only a 2-element [dx, dy] list (rank 1) or a batched matrix of such pairs (rank 2) is supported for building transform matrices.","triggerScenarios":"Thrown at official/legacy/image_classification/augment.py:105 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Flatten translations to rank 1 ([dx, dy]) or rank 2 (batch of pairs)","Reshape/fix the upstream augmentation parameter generation"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}