Skip to content

Commit 1a77ca6

Browse files
Push patch for letterbox masks post-processing
1 parent b319769 commit 1a77ca6

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

inference/core/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.57.4"
1+
__version__ = "0.58.0"
22

33

44
if __name__ == "__main__":

inference/models/perception_encoder/vision_encoder/tokenizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" CLIP tokenizer
1+
"""CLIP tokenizer
22
33
Copied from https://github.com/openai/CLIP. Originally MIT License, Copyright (c) 2021 OpenAI.
44
"""
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
from inference.models.rfdetr.rfdetr import RFDETRObjectDetection
2-
from inference.models.rfdetr.rfdetr import RFDETRInstanceSegmentation
1+
from inference.models.rfdetr.rfdetr import (
2+
RFDETRInstanceSegmentation,
3+
RFDETRObjectDetection,
4+
)
5+
36
__all__ = ["RFDETRObjectDetection", "RFDETRInstanceSegmentation"]

inference/models/rfdetr/rfdetr.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,13 +717,21 @@ def make_response(
717717
masks = [pred[7] for pred in predictions[image_ind]]
718718
orig_h, orig_w = img_dims[image_ind]
719719
prediction_h, prediction_w = self.mask_shape[0], self.mask_shape[1]
720+
720721
mask_preds = []
721722
for mask in masks:
722723
points = mask2poly(mask.astype(np.uint8))
723724
new_points = []
724725
for point in points:
725-
new_x = point[0] * (orig_w / prediction_w)
726-
new_y = point[1] * (orig_h / prediction_h)
726+
if self.resize_method == "Stretch to":
727+
new_x = point[0] * (orig_w / prediction_w)
728+
new_y = point[1] * (orig_h / prediction_h)
729+
else:
730+
scale = max(orig_w / prediction_w, orig_h / prediction_h)
731+
pad_x = (orig_w - prediction_w * scale) / 2
732+
pad_y = (orig_h - prediction_h * scale) / 2
733+
new_x = point[0] * scale + pad_x
734+
new_y = point[1] * scale + pad_y
727735
new_points.append(np.array([new_x, new_y]))
728736
mask_preds.append(new_points)
729737
batch_mask_preds.append(mask_preds)

0 commit comments

Comments
 (0)