tensorflow/models · error · ValueError

If not using TFLite custom NMS, `use_class_agnostic_nms` can

Error message

If not using TFLite custom NMS, `use_class_agnostic_nms` can only be enabled for NMS v2 for now, but NMS {} is used! If you are using TFLite NMS, please configure TFLite custom NMS for class-agnostic NMS.

What it means

Error "If not using TFLite custom NMS, `use_class_agnostic_nms` can only be enabled for NMS v2 for now, but NMS {} is used! If you are using TFLite NMS, please configure TFLite custom NMS for class-agnostic NMS." thrown in tensorflow/models.

Source

Thrown at official/vision/modeling/layers/detection_generator.py:1191

        if == 0, AP is reduced 1.0%, AR is reduced 5% on COCO
        if == 1, AP is reduced 0.2%, AR is reduced 2% on COCO
        if == 2, AP is reduced <0.1%, AR is reduced <1% on COCO
      return_decoded: A `bool` of whether to return decoded boxes before NMS
        regardless of whether `apply_nms` is True or not.
      use_class_agnostic_nms: A `bool` of whether non max suppression is
        operated on all the boxes using max scores across all classes.
      box_coder_weights: An optional `list` of 4 positive floats to scale y, x,
        h, and w when encoding box coordinates. If set to None, does not perform
        scaling. For Faster RCNN, the open-source implementation recommends
        using [10.0, 10.0, 5.0, 5.0].
      **kwargs: Additional keyword arguments passed to Layer.

    Raises:
      ValueError: If `use_class_agnostic_nms` is required by `nms_version` is
      not specified as `v2`.
    """
    if use_class_agnostic_nms and nms_version != 'v2':
      raise ValueError(
          'If not using TFLite custom NMS, `use_class_agnostic_nms` can only be'
          ' enabled for NMS v2 for now, but NMS {} is used! If you are using'
          ' TFLite NMS, please configure TFLite custom NMS for class-agnostic'
          ' NMS.'.format(nms_version)
      )
    self._config_dict = {
        'apply_nms': apply_nms,
        'pre_nms_top_k': pre_nms_top_k,
        'pre_nms_score_threshold': pre_nms_score_threshold,
        'nms_iou_threshold': nms_iou_threshold,
        'max_num_detections': max_num_detections,
        'nms_version': nms_version,
        'use_cpu_nms': use_cpu_nms,
        'soft_nms_sigma': soft_nms_sigma,
        'return_decoded': return_decoded,
        'use_class_agnostic_nms': use_class_agnostic_nms,
        'box_coder_weights': box_coder_weights,
    }

View on GitHub (pinned to e006f5f0d5)

Solutions

  1. Set nms_version to 2 when enabling use_class_agnostic_nms without TFLite custom NMS.
  2. If deploying to TFLite, configure the TFLite custom NMS for class-agnostic NMS instead.

When it happens

Trigger: Thrown at official/vision/modeling/layers/detection_generator.py:1191 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/7d5d0b6e860eb014. Report an issue: GitHub.