Skip to content

Commit 9d54198

Browse files
authored
Merge pull request huggingface#9 from Superb-AI-Suite/develop
add num_nms parameters and set to 100
2 parents d3fa1d9 + 16cf17a commit 9d54198

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

src/transformers/models/deta/image_processing_deta.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,7 @@ def post_process_object_detection(
10961096
threshold: float = 0.5,
10971097
target_sizes: Union[TensorType, List[Tuple]] = None,
10981098
nms_threshold: float = 0.7,
1099+
num_nms: int = 100,
10991100
):
11001101
"""
11011102
Converts the output of [`DetaForObjectDetection`] into final bounding boxes in (top_left_x, top_left_y,
@@ -1111,6 +1112,8 @@ def post_process_object_detection(
11111112
(height, width) of each image in the batch. If left to None, predictions will not be resized.
11121113
nms_threshold (`float`, *optional*, defaults to 0.7):
11131114
NMS threshold.
1115+
num_nms (`int`, *optional*, defaults to 100):
1116+
Number of objects threshold.
11141117
11151118
Returns:
11161119
`List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image
@@ -1158,7 +1161,7 @@ def post_process_object_detection(
11581161
lbls = lbls[pre_topk]
11591162

11601163
# apply NMS
1161-
keep_inds = batched_nms(box, score, lbls, nms_threshold)[:100]
1164+
keep_inds = batched_nms(box, score, lbls, nms_threshold)[:num_nms]
11621165
score = score[keep_inds]
11631166
lbls = lbls[keep_inds]
11641167
box = box[keep_inds]

src/transformers/models/mask2former/image_processing_mask2former.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,10 +1121,6 @@ def post_process_instance_segmentation(
11211121
pred_scores = scores_per_image * mask_scores_per_image
11221122
pred_classes = labels_per_image
11231123

1124-
mask_pred, pred_scores, pred_classes = remove_low_and_no_objects(
1125-
mask_pred, pred_scores, pred_classes, threshold, num_classes
1126-
)
1127-
11281124
segmentation = torch.zeros((384, 384)) - 1
11291125
if target_sizes is not None:
11301126
size = target_sizes[i] if isinstance(target_sizes[i], tuple) else target_sizes[i].cpu().tolist()

src/transformers/models/yolov6/image_processing_yolov6.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ def post_process_object_detection(
10081008
target_sizes: Union[TensorType, List[Tuple]] = None,
10091009
nms_threshold: float = 0.65,
10101010
max_nms: int = 30000,
1011+
num_nms: int = 100,
10111012
):
10121013
"""
10131014
Converts the raw output of [`Yolov6ForObjectDetection`] into final bounding boxes in (top_left_x, top_left_y,
@@ -1022,6 +1023,12 @@ def post_process_object_detection(
10221023
target_sizes (`torch.Tensor` or `List[Tuple[int, int]]`, *optional*):
10231024
Tensor of shape `(batch_size, 2)` or list of tuples (`Tuple[int, int]`) containing the target size
10241025
`(height, width)` of each image in the batch. If unset, predictions will not be resized.
1026+
nms_threshold (`float`, *optional*):
1027+
NMS score threshold to keep duplicated object detection predictions.
1028+
max_nms (`int`, *optional*):
1029+
Number of maximum output for intermediate results.
1030+
num_nms (`int`, *optional*):
1031+
Number of final output after the nms results.
10251032
Returns:
10261033
`List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image
10271034
in the batch as predicted by the model.
@@ -1067,7 +1074,7 @@ def post_process_object_detection(
10671074
score = score[indices]
10681075

10691076
# apply NMS
1070-
keep_inds = nms(box, score, nms_threshold)[:300]
1077+
keep_inds = nms(box, score, nms_threshold)[:num_nms]
10711078
score = score[keep_inds]
10721079
lbls = lbls[keep_inds]
10731080
box = box[keep_inds]

src/transformers/models/yolov6/modeling_yolov6.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ def _init_weights(self, module: Union[nn.Linear, nn.Conv2d, nn.LayerNorm]) -> No
10771077
# cf https://github.com/pytorch/pytorch/pull/5617
10781078
module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
10791079
if module.bias is not None:
1080-
module.bias.data.zero_()
1080+
module.bias.data.zero_()
10811081
elif isinstance(module, nn.LayerNorm):
10821082
module.bias.data.zero_()
10831083
module.weight.data.fill_(1.0)

0 commit comments

Comments
 (0)