Reference for ultralytics/models/fastsam/utils.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/fastsam/utils.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.models.fastsam.utils.adjust_bboxes_to_image_border(boxes, image_shape, threshold=20)
Adjust bounding boxes to stick to image border if they are within a certain threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
boxes |
Tensor
|
(n, 4) |
required |
image_shape |
tuple
|
(height, width) |
required |
threshold |
int
|
pixel threshold |
20
|
Returns:
Name | Type | Description |
---|---|---|
adjusted_boxes |
Tensor
|
adjusted bounding boxes |
Source code in ultralytics/models/fastsam/utils.py
ultralytics.models.fastsam.utils.bbox_iou(box1, boxes, iou_thres=0.9, image_shape=(640, 640), raw_output=False)
Compute the Intersection-Over-Union of a bounding box with respect to an array of other bounding boxes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
box1 |
Tensor
|
(4, ) |
required |
boxes |
Tensor
|
(n, 4) |
required |
iou_thres |
float
|
IoU threshold |
0.9
|
image_shape |
tuple
|
(height, width) |
(640, 640)
|
raw_output |
bool
|
If True, return the raw IoU values instead of the indices |
False
|
Returns:
Name | Type | Description |
---|---|---|
high_iou_indices |
Tensor
|
Indices of boxes with IoU > thres |