Reference for ultralytics/models/sam/amg.py
Note
Full source code for this file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/sam/amg.py. Help us fix any issues you see by submitting a Pull Request 🛠️. Thank you 🙏!
ultralytics.models.sam.amg.is_box_near_crop_edge(boxes, crop_box, orig_box, atol=20.0)
Return a boolean tensor indicating if boxes are near the crop edge.
Source code in ultralytics/models/sam/amg.py
ultralytics.models.sam.amg.batch_iterator(batch_size, *args)
Yield batches of data from the input arguments.
Source code in ultralytics/models/sam/amg.py
ultralytics.models.sam.amg.calculate_stability_score(masks, mask_threshold, threshold_offset)
Computes the stability score for a batch of masks. The stability score is the IoU between the binary masks obtained by thresholding the predicted mask logits at high and low values.
Source code in ultralytics/models/sam/amg.py
ultralytics.models.sam.amg.build_point_grid(n_per_side)
Generate a 2D grid of evenly spaced points in the range [0,1]x[0,1].
Source code in ultralytics/models/sam/amg.py
ultralytics.models.sam.amg.build_all_layer_point_grids(n_per_side, n_layers, scale_per_layer)
Generate point grids for all crop layers.
Source code in ultralytics/models/sam/amg.py
ultralytics.models.sam.amg.generate_crop_boxes(im_size, n_layers, overlap_ratio)
Generates a list of crop boxes of different sizes. Each layer has (2i)2 boxes for the ith layer.
Source code in ultralytics/models/sam/amg.py
ultralytics.models.sam.amg.uncrop_boxes_xyxy(boxes, crop_box)
Uncrop bounding boxes by adding the crop box offset.
Source code in ultralytics/models/sam/amg.py
ultralytics.models.sam.amg.uncrop_points(points, crop_box)
Uncrop points by adding the crop box offset.
Source code in ultralytics/models/sam/amg.py
ultralytics.models.sam.amg.uncrop_masks(masks, crop_box, orig_h, orig_w)
Uncrop masks by padding them to the original image size.
Source code in ultralytics/models/sam/amg.py
ultralytics.models.sam.amg.remove_small_regions(mask, area_thresh, mode)
Remove small disconnected regions or holes in a mask, returning the mask and a modification indicator.
Source code in ultralytics/models/sam/amg.py
ultralytics.models.sam.amg.batched_mask_to_box(masks)
Calculates boxes in XYXY format around masks. Return [0,0,0,0] for an empty mask. For input shape C1xC2x...xHxW, the output shape is C1xC2x...x4.