open-mmlab/mmdetection · warning

DeprecationWarning: Setting "linear=True" in iou_loss is dep

Error message

DeprecationWarning: Setting "linear=True" in iou_loss is deprecated, please use "mode=`linear`" instead.

What it means

Deprecation warning from IoULoss.forward: the legacy `linear=True` constructor/forward argument is deprecated in favor of the unified `mode` parameter (mode must be one of 'linear', 'square', 'log'). When linear=True is passed, the code silently coerces mode='linear' and warns; the linear flag will be removed in a future release.

Source

Thrown at mmdet/models/losses/iou_loss.py:42

    The loss is calculated as negative log of IoU.

    Args:
        pred (Tensor): Predicted bboxes of format (x1, y1, x2, y2),
            shape (n, 4).
        target (Tensor): Corresponding gt bboxes, shape (n, 4).
        linear (bool, optional): If True, use linear scale of loss instead of
            log scale. Default: False.
        mode (str): Loss scaling mode, including "linear", "square", and "log".
            Default: 'log'
        eps (float): Epsilon to avoid log(0).

    Return:
        Tensor: Loss tensor.
    """
    assert mode in ['linear', 'square', 'log']
    if linear:
        mode = 'linear'
        warnings.warn('DeprecationWarning: Setting "linear=True" in '
                      'iou_loss is deprecated, please use "mode=`linear`" '
                      'instead.')
    # avoid fp16 overflow
    if pred.dtype == torch.float16:
        fp16 = True
        pred = pred.to(torch.float32)
    else:
        fp16 = False

    ious = bbox_overlaps(pred, target, is_aligned=True).clamp(min=eps)

    if fp16:
        ious = ious.to(torch.float16)

    if mode == 'linear':
        loss = 1 - ious
    elif mode == 'square':
        loss = 1 - ious**2

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. Replace linear=True with mode='linear' in the loss_iou / IoULoss config dict
  2. Remove any linear= key entirely if 'linear' behavior is not intended
  3. Search configs for 'linear=True' and update all occurrences

Example fix

# before
loss_iou=dict(type='IoULoss', linear=True)
# after
loss_iou=dict(type='IoULoss', mode='linear')
Defensive patterns

Strategy: validation

Validate before calling

assert 'linear' not in loss_cfg, 'use mode=\'linear\' instead of linear=True'

Prevention

When it happens

Trigger: Calling iou_loss(...) / training a detector whose cfg uses loss_iou=dict(type='IoULoss', linear=True), or calling IoULoss.forward with linear=True. Any config carried over from older mmdet versions that still specifies linear=True.

Common situations: Upgrading mmdet (2.x era configs) to newer versions where the loss API was consolidated around `mode`; stale custom configs or third-party config repos.

Related errors


AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27). Data as JSON: /api/errors/93a25829c5de02c5. Report an issue: GitHub.