tensorflow/models · error · TypeError

translations rank must be statically known

Error message

translations rank must be statically known

What it means

Static-shape guard in _convert_translation_to_transform: the translations tensor's rank is unknown at graph-construction time (ndims is None). Translation augmentation requires a statically known shape to build the (num_images, 8) transform matrices.

Solutions

  1. Pass translations with a statically known shape (set_shape or concrete constants)
  2. Avoid feeding dynamic-shaped tensors from datasets without static shapes into translate()
Defensive patterns

Strategy: type-guard

When it happens

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

Appendix: source

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

     [0 0 1]]

  Args:
    translations: The 2-element list representing [dx, dy], or a matrix of
      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,
  )

View on GitHub (pinned to e006f5f0d5)