Skip to content

Commit

Permalink
Add option to omit the NMS placeholder in object detection.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 529212785
  • Loading branch information
tensorflower-gardener authored and Zarjagen committed May 4, 2023
1 parent c978d18 commit 32853cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions official/vision/configs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class PseudoLabelDataConfig(cfg.DataConfig):

@dataclasses.dataclass
class TFLitePostProcessingConfig(hyperparams.Config):
"""TFLite Post Processing config for inference."""
max_detections: int = 200
max_classes_per_detection: int = 5
# Regular NMS run in a multi-class fashion and is slow. Setting it to False
Expand All @@ -148,3 +149,6 @@ class TFLitePostProcessingConfig(hyperparams.Config):
# Whether to normalize coordinates of anchors to [0, 1]. If setting to True,
# coordinates of output boxes is also normalized but latency increases.
normalize_anchor_coordinates: Optional[bool] = False
# Whether to omit the final nms placeholder op. If set to True, the output
# will be a tuple of boxes, scores result right before the NMS operation.
omit_nms: Optional[bool] = False
5 changes: 5 additions & 0 deletions official/vision/modeling/layers/detection_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,11 @@ def dummy_post_processing(input_boxes, input_scores, input_anchors):
num_detections = tf.constant(0.0, dtype=tf.float32, name='num_detections')
return boxes, classes, scores, num_detections

if config.get('omit_nms', False):
dummy_classes = tf.constant(0.0, dtype=tf.float32, name='classes')
dummy_num_detections = tf.constant(
0.0, dtype=tf.float32, name='num_detections')
return boxes, dummy_classes, scores, dummy_num_detections
return dummy_post_processing(boxes, scores, anchors)[::-1]


Expand Down

0 comments on commit 32853cc

Please sign in to comment.