keras-team/keras · error · ValueError

The number of repeats in `EfficientNet` must be > 0. Receive

Error message

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

What it means

Cropping output-spec check that bottom_cropping (explicit or inferred as height - target_height - top_cropping) is non-negative; otherwise the vertical crop exceeds the input height.

Source

Thrown at keras/src/applications/efficientnet.py:362

        round_filters(32),
        3,
        strides=2,
        padding="valid",
        use_bias=False,
        kernel_initializer=CONV_KERNEL_INITIALIZER,
        name="stem_conv",
    )(x)
    x = layers.BatchNormalization(axis=bn_axis, 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(round_repeats(args["repeats"]) for args in blocks_args))
    for i, args in enumerate(blocks_args):
        if args["repeats"] <= 0:
            raise ValueError(
                f"The number of repeats in `EfficientNet` must be > 0. "
                f"Received: repeats={args['repeats']}"
            )
        # Update block input and output filters based on depth multiplier.
        args["filters_in"] = round_filters(args["filters_in"])
        args["filters_out"] = round_filters(args["filters_out"])

        for j in range(round_repeats(args.pop("repeats"))):
            # The first block needs to take care of stride and filter size
            # increase.
            if j > 0:
                args["strides"] = 1
                args["filters_in"] = args["filters_out"]
            x = block(
                x,
                activation,
                drop_connect_rate * b / blocks,
                name=f"block{i + 1}{chr(j + 97)}_",

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Lower target_height or the other cropping so the sum fits within height
  2. Use padding to enlarge
  3. Verify data_format when computing axes

Example fix

# before
out = ops.image.crop_images(img, target_height=(100, 100), top_cropping=50)  # height 120
# after
out = ops.image.crop_images(img, target_height=(100, 100), top_cropping=20)
Defensive patterns

Strategy: validation

Validate before calling

top = top_cropping or 0
assert (bottom_cropping is None or bottom_cropping >= 0) and top + target_height <= height

Prevention

When it happens

Trigger: Negative bottom_cropping argument, or inferred negative when top_cropping + target_height > height.

Common situations: Center-crop helpers computing crop = (size - target)/2 with target > size; height/width swaps; wrong data_format axis.

Related errors


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