Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved error in FastSAMPredictor.postprocess method #251

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fastsam/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def postprocess(self, preds, img, orig_imgs):
full_box = full_box.view(1, -1)
critical_iou_index = bbox_iou(full_box[0][:4], p[0][:, :4], iou_thres=0.9, image_shape=img.shape[2:])
if critical_iou_index.numel() != 0:
critical_iou_index = critical_iou_index[:1]
full_box[0][4] = p[0][critical_iou_index][:,4]
full_box[0][6:] = p[0][critical_iou_index][:,6:]
p[0][critical_iou_index] = full_box
Expand Down
5 changes: 3 additions & 2 deletions fastsam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def bbox_iou(box1, boxes, iou_thres=0.9, image_shape=(640, 640), raw_output=Fals
box1: (4, )
boxes: (n, 4)
Returns:
high_iou_indices: Indices of boxes with IoU > thres
high_iou_indices: Indices of boxes with IoU > thres sorted in descending order
'''
boxes = adjust_bboxes_to_image_border(boxes, image_shape)
# obtain coordinates for intersections
Expand Down Expand Up @@ -72,8 +72,9 @@ def bbox_iou(box1, boxes, iou_thres=0.9, image_shape=(640, 640), raw_output=Fals

# get indices of boxes with IoU > thres
high_iou_indices = torch.nonzero(iou > iou_thres).flatten()
sorted_high_iou_indices = high_iou_indices[torch.argsort(iou[high_iou_indices], descending=True)]

return high_iou_indices
return sorted_high_iou_indices


def image_to_np_ndarray(image):
Expand Down