Skip to content

Commit 32853cc

Browse files
tensorflower-gardenerZarjagen
authored andcommitted
Add option to omit the NMS placeholder in object detection.
PiperOrigin-RevId: 529212785
1 parent c978d18 commit 32853cc

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

official/vision/configs/common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class PseudoLabelDataConfig(cfg.DataConfig):
138138

139139
@dataclasses.dataclass
140140
class TFLitePostProcessingConfig(hyperparams.Config):
141+
"""TFLite Post Processing config for inference."""
141142
max_detections: int = 200
142143
max_classes_per_detection: int = 5
143144
# Regular NMS run in a multi-class fashion and is slow. Setting it to False
@@ -148,3 +149,6 @@ class TFLitePostProcessingConfig(hyperparams.Config):
148149
# Whether to normalize coordinates of anchors to [0, 1]. If setting to True,
149150
# coordinates of output boxes is also normalized but latency increases.
150151
normalize_anchor_coordinates: Optional[bool] = False
152+
# Whether to omit the final nms placeholder op. If set to True, the output
153+
# will be a tuple of boxes, scores result right before the NMS operation.
154+
omit_nms: Optional[bool] = False

official/vision/modeling/layers/detection_generator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,11 @@ def dummy_post_processing(input_boxes, input_scores, input_anchors):
889889
num_detections = tf.constant(0.0, dtype=tf.float32, name='num_detections')
890890
return boxes, classes, scores, num_detections
891891

892+
if config.get('omit_nms', False):
893+
dummy_classes = tf.constant(0.0, dtype=tf.float32, name='classes')
894+
dummy_num_detections = tf.constant(
895+
0.0, dtype=tf.float32, name='num_detections')
896+
return boxes, dummy_classes, scores, dummy_num_detections
892897
return dummy_post_processing(boxes, scores, anchors)[::-1]
893898

894899

0 commit comments

Comments
 (0)