tensorflow/models · error · ValueError

maximum change in aspect ratio must be between 0 and 0.5

Error message

maximum change in aspect ratio must be between 0 and 0.5

What it means

Parameter validation in resize_and_jitter_image: the aspect-ratio-change limit must lie in (0, 0.5] — the jitter logic stretches and crops within that bound, and values outside it produce invalid crop geometry (degenerate or negative regions in the intersection math). Fires when the preprocessing config passes 0, a negative number, or something above 0.5 for the maximum aspect-ratio distortion.

Solutions

  1. Set the max aspect-ratio change parameter to a value in (0, 0.5], e.g. 0.1 or 0.25
  2. Check the preprocessing YAML/flags for a zero, negative, or missing value that defaults badly
  3. Use the same bounds as the reference augmentation configs
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at official/projects/yolo/ops/preprocessing_ops.py:384 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/0f47ef3d6377630d. Report an issue: GitHub.

Appendix: source

Thrown at official/projects/yolo/ops/preprocessing_ops.py:384

      scaled dimension / original dimension.
    cast([original_width, original_height, width, height, ptop, pleft, pbottom,
      pright], tf.float32): a `Tensor` containing the information of the image
        andthe applied preprocessing.
  """

  def intersection(a, b):
    """Finds the intersection between 2 crops."""
    minx = tf.maximum(a[0], b[0])
    miny = tf.maximum(a[1], b[1])
    maxx = tf.minimum(a[2], b[2])
    maxy = tf.minimum(a[3], b[3])
    return tf.convert_to_tensor([minx, miny, maxx, maxy])

  def cast(values, dtype):
    return [tf.cast(value, dtype) for value in values]

  if jitter > 0.5 or jitter < 0:
    raise ValueError('maximum change in aspect ratio must be between 0 and 0.5')

  with tf.name_scope('resize_and_jitter_image'):
    # Cast all parameters to a usable float data type.
    jitter = tf.cast(jitter, tf.float32)
    original_dtype, original_dims = image.dtype, tf.shape(image)[:2]

    # original width, original height, desigered width, desired height
    original_width, original_height, width, height = cast(
        [original_dims[1], original_dims[0], desired_size[1], desired_size[0]],
        tf.float32)

    # Compute the random delta width and height etc. and randomize the
    # location of the corner points.
    jitter_width = original_width * jitter
    jitter_height = original_height * jitter
    pleft = random_uniform_strong(
        -jitter_width, jitter_width, jitter_width.dtype, seed=seed)
    pright = random_uniform_strong(

View on GitHub (pinned to e006f5f0d5)