keras-team/keras · error · ValueError

The number of repeats in `EfficientNetV2` must be > 0. Recei

Error message

The number of repeats in `EfficientNetV2` must be > 0. Received: num_repeat={args['num_repeat']}

What it means

Cropping output-spec check that right_cropping (explicit or inferred as width - target_width - left_cropping) is non-negative; a negative value means the requested horizontal crop exceeds the image width.

Source

Thrown at keras/src/applications/efficientnet_v2.py:978

        padding="same",
        use_bias=False,
        name="stem_conv",
    )(x)
    x = layers.BatchNormalization(
        axis=bn_axis,
        momentum=bn_momentum,
        name="stem_bn",
    )(x)
    x = layers.Activation(activation, name="stem_activation")(x)

    # Build blocks
    blocks_args = copy.deepcopy(blocks_args)
    b = 0
    blocks = float(sum(args["num_repeat"] for args in blocks_args))

    for i, args in enumerate(blocks_args):
        if args["num_repeat"] <= 0:
            raise ValueError(
                f"The number of repeats in `EfficientNetV2` must be > 0. "
                f"Received: num_repeat={args['num_repeat']}"
            )

        # Update block input and output filters based on depth multiplier.
        args["input_filters"] = round_filters(
            filters=args["input_filters"],
            width_coefficient=width_coefficient,
            min_depth=min_depth,
            depth_divisor=depth_divisor,
        )
        args["output_filters"] = round_filters(
            filters=args["output_filters"],
            width_coefficient=width_coefficient,
            min_depth=min_depth,
            depth_divisor=depth_divisor,
        )

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Reduce crop amounts or target_width to fit within width
  2. Use padding first when inputs are smaller than the crop window
  3. Sanitize augmentation parameters against the actual input size

Example fix

# before
out = ops.image.crop_images(img, target_width=(48, 48), left_cropping=30)  # width 64
# after
out = ops.image.crop_images(img, target_width=(48, 48), left_cropping=16)
Defensive patterns

Strategy: validation

Validate before calling

if right_cropping is not None:
    assert right_cropping >= 0 and (left_cropping or 0) + target_width + right_cropping <= width

Prevention

When it happens

Trigger: Explicit negative right_cropping, or inferred negative when left_cropping + target_width > width.

Common situations: Oversized crop windows from config; random-crop augmentation sampling crops larger than small inputs; pixel-vs-fraction unit confusion.

Related errors


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/b47ba1142de55fed. Report an issue: GitHub.