tensorflow/models · error · TypeError

translations should have rank 1 or 2.

Error message

translations should have rank 1 or 2.

What it means

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.

Solutions

  1. Flatten translations to rank 1 ([dx, dy]) or rank 2 (batch of pairs)
  2. Reshape/fix the upstream augmentation parameter generation
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at official/legacy/image_classification/augment.py:105 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/c441c8b742f358cc. Report an issue: GitHub.

Appendix: source

Thrown at official/legacy/image_classification/augment.py:105

      2-element lists representing [dx dy] to translate for each image. The
      shape must be static.

  Returns:
    The transformation matrix of shape (num_images, 8).

  Raises:
    `TypeError` if
      - the shape of `translations` is not known or
      - the shape of `translations` is not rank 1 or 2.

  """
  translations = tf.convert_to_tensor(translations, dtype=tf.float32)
  if translations.get_shape().ndims is None:
    raise TypeError('translations rank must be statically known')
  elif len(translations.get_shape()) == 1:
    translations = translations[None]
  elif len(translations.get_shape()) != 2:
    raise TypeError('translations should have rank 1 or 2.')
  num_translations = tf.shape(translations)[0]

  return tf.concat(
      values=[
          tf.ones((num_translations, 1), tf.dtypes.float32),
          tf.zeros((num_translations, 1), tf.dtypes.float32),
          -translations[:, 0, None],
          tf.zeros((num_translations, 1), tf.dtypes.float32),
          tf.ones((num_translations, 1), tf.dtypes.float32),
          -translations[:, 1, None],
          tf.zeros((num_translations, 2), tf.dtypes.float32),
      ],
      axis=1,
  )


def _convert_angles_to_transform(angles: tf.Tensor, image_width: tf.Tensor,
                                 image_height: tf.Tensor) -> tf.Tensor:

View on GitHub (pinned to e006f5f0d5)