open-mmlab/mmdetection · error · NotImplementedError

{kernel} kernel is not supported in matrix nms!

Error message

{kernel} kernel is not supported in matrix nms!

What it means

Raised by mask_matrix_nms in mmdet when the `kernel` argument is neither 'gaussian' nor 'linear'. The kernel controls how overlapping mask IoUs decay the confidence scores of suppressed instances; any other string falls into the else-branch and raises NotImplementedError.

Source

Thrown at mmdet/models/layers/matrix_nms.py:96

    # IoU compensation
    compensate_iou, _ = (iou_matrix * label_matrix).max(0)
    compensate_iou = compensate_iou.expand(num_masks,
                                           num_masks).transpose(1, 0)

    # IoU decay
    decay_iou = iou_matrix * label_matrix

    # Calculate the decay_coefficient
    if kernel == 'gaussian':
        decay_matrix = torch.exp(-1 * sigma * (decay_iou**2))
        compensate_matrix = torch.exp(-1 * sigma * (compensate_iou**2))
        decay_coefficient, _ = (decay_matrix / compensate_matrix).min(0)
    elif kernel == 'linear':
        decay_matrix = (1 - decay_iou) / (1 - compensate_iou)
        decay_coefficient, _ = decay_matrix.min(0)
    else:
        raise NotImplementedError(
            f'{kernel} kernel is not supported in matrix nms!')
    # update the score.
    scores = scores * decay_coefficient

    if filter_thr > 0:
        keep = scores >= filter_thr
        keep_inds = keep_inds[keep]
        if not keep.any():
            return scores.new_zeros(0), labels.new_zeros(0), masks.new_zeros(
                0, *masks.shape[-2:]), labels.new_zeros(0)
        masks = masks[keep]
        scores = scores[keep]
        labels = labels[keep]

    # sort and keep top max_num
    scores, sort_inds = torch.sort(scores, descending=True)
    keep_inds = keep_inds[sort_inds]
    if max_num > 0 and len(sort_inds) > max_num:

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. Set kernel to 'gaussian' or 'linear' in the MatrixNms / mask_matrix_nms config
  2. Fix typos: 'gaussion' -> 'gaussian', 'linear' vs 'linea'
  3. If a custom kernel is needed, subclass and override mask_matrix_nms to add it

Example fix

// before
matrix_nms_cfg=dict(type='MatrixNms', kernel='exp')
// after
matrix_nms_cfg=dict(type='MatrixNms', kernel='gaussian')
Defensive patterns

Strategy: validation

Validate before calling

assert kernel in ('gaussian', 'linear'), f'unsupported kernel: {kernel}'

Try / catch

try: out = mask_matrix_nms(..., kernel=kernel)
except NotImplementedError: out = mask_matrix_nms(..., kernel='gaussian')

Prevention

When it happens

Trigger: Calling mask_matrix_nms(..., kernel='exp') or passing a typo like 'gaussion'/'Linear' from a config (e.g. MatrixNms with kernel='lnear') or calling _predict_by_feat_single of a mask head whose matrix_nms cfg sets an unsupported kernel.

Common situations: Config typos in MatrixNms kernel; copy-pasting configs from other repos that use different kernel names; assuming arbitrary kernel functions are supported.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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