Search code examples
tensorflowobject-detection

Tensorflow Object Detection API: disable nonmaxima suppression for off-the-shelf models


Is it possible and/or easy to disable the non-maxima suppression part of the off-the-shelf object detectors provided in the Tensorflow Object Detection API? E.g., I'd like to run the provided "SSD mobilenet which was trained on MSCOCO" without the non-maxima operation at the end. How can I achieve this?


Solution

  • If you want to do this for speed reasons, the only way is to edit the code itself (see https://github.com/tensorflow/models/blob/master/object_detection/meta_architectures/ssd_meta_arch.py#L331) --- this is a bit involved as you need to replace the call to NMS by code that would still put the boxes in the expected output format.

    If you just want to get rid of the effect of NMS, you can simply set the score_threshold and iou_threshold of the postprocessing part of the config file: https://github.com/tensorflow/models/blob/master/object_detection/samples/configs/ssd_mobilenet_v1_pets.config#L131 to be 0.0 and 1.0 respectively, meaning, don't filter low scoring boxes, and prune boxes based on iou only if they perfectly overlap (which in practice will be never).