tensorflow/models · error · ValueError

Feature map sizes {(h, w)} not divisible by window size ({gr

Error message

Feature map sizes {(h, w)} not divisible by window size ({grid_size}).

What it means

Error "Feature map sizes {(h, w)} not divisible by window size ({grid_size})." thrown in tensorflow/models.

Source

Thrown at official/projects/maxvit/modeling/maxvit.py:329

    """Partition the input feature maps into non-overlapping windows.

    Note that unsuitable feature or window sizes may be costly on TPU due to
    padding sizes:
    https://docs.google.com/document/d/1GojE1Q7hR2qyi0mIfnTHgERfl7Dmsj6xPQ31MQo3xUk/edit#

    Args:
      features: [B, H, W, C] feature maps.

    Returns:
      Partitioned features: [B, nH, nW, wSize, wSize, c].

    Raises:
      ValueError: If the feature map sizes are not divisible by window sizes.
    """
    _, h, w, c = features.shape
    grid_size = self._grid_size
    if h % grid_size != 0 or w % grid_size != 0:
      raise ValueError(
          f'Feature map sizes {(h, w)} '
          f'not divisible by window size ({grid_size}).'
      )
    features = tf.reshape(
        features, (-1, grid_size, h // grid_size, grid_size, w // grid_size, c)
    )
    features = tf.transpose(features, (0, 2, 4, 1, 3, 5))
    features = tf.reshape(features, (-1, grid_size, grid_size, c))
    return features

  def grid_stitch_back(
      self, features: tf.Tensor, grid_size: int, h: int, w: int
  ) -> tf.Tensor:
    """Reverse window_partition."""
    features = tf.reshape(
        features,
        [
            -1,

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/projects/maxvit/modeling/maxvit.py:329 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/2b7b0dc318dbf3c5. Report an issue: GitHub.