Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/PeterYYZhang/few-shot-self-prompt-SAM
/ functions
Functions
116 in github.com/PeterYYZhang/few-shot-self-prompt-SAM
⨍
Functions
116
◇
Types & classes
19
↓ 11 callers
Method
cat
(self, new_stats: "MaskData")
segment_anything/utils/amg.py:59
↓ 8 callers
Function
dice_coef
(groundtruth_mask, pred_mask)
utils/utils.py:47
↓ 8 callers
Method
predict
Predict masks for the given input prompts, using the currently set image. Arguments: point_coords (np.ndarray or None): A
segment_anything/predictor.py:92
↓ 6 callers
Method
filter
(self, keep: torch.Tensor)
segment_anything/utils/amg.py:44
↓ 4 callers
Function
get_embedding
(img, predictor)
main.py:18
↓ 4 callers
Method
get_preprocess_shape
Compute the output size given input size and target long side length.
segment_anything/utils/transforms.py:94
↓ 4 callers
Method
set_image
Calculates the image embeddings for the provided image, allowing masks to be predicted with the 'predict' method. Arguments:
segment_anything/predictor.py:34
↓ 3 callers
Method
__init__
Args: dim (int): Number of input channels. num_heads (int): Number of attention heads in each ViT block.
segment_anything/modeling/image_encoder.py:122
↓ 3 callers
Function
_build_sam
( encoder_embed_dim, encoder_depth, encoder_num_heads, encoder_global_attn_indexes, checkp
segment_anything/build_sam.py:55
↓ 3 callers
Method
_pe_encoding
Positionally encode points that are normalized to [0,1].
segment_anything/modeling/prompt_encoder.py:185
↓ 3 callers
Method
_separate_heads
(self, x: Tensor, num_heads: int)
segment_anything/modeling/transformer.py:208
↓ 3 callers
Method
apply_coords
Expects a numpy array of length 2 in the final dimension. Requires the original image size in (H, W) format.
segment_anything/utils/transforms.py:33
↓ 3 callers
Function
calculate_stability_score
Computes the stability score for a batch of masks. The stability score is the IoU between the binary masks obtained by thresholding the p
segment_anything/utils/amg.py:156
↓ 3 callers
Method
get_dense_pe
Returns the positional encoding used to encode point prompts, applied to a dense set of points the shape of the image encoding.
segment_anything/modeling/prompt_encoder.py:62
↓ 3 callers
Method
items
(self)
segment_anything/utils/amg.py:41
↓ 3 callers
Method
reset_image
Resets the currently set image.
segment_anything/predictor.py:262
↓ 2 callers
Method
__init__
( self, embedding_dim: int, num_heads: int, downsample_rate: int = 1, )
segment_anything/modeling/transformer.py:191
↓ 2 callers
Function
batched_mask_to_box
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..
segment_anything/utils/amg.py:303
↓ 2 callers
Function
box_xyxy_to_xywh
(box_xyxy: torch.Tensor)
segment_anything/utils/amg.py:91
↓ 2 callers
Function
crop_len
(orig_len, n_crops, overlap)
segment_anything/utils/amg.py:215
↓ 2 callers
Method
forward_with_coords
Positionally encode points that are not normalized to [0,1].
segment_anything/modeling/prompt_encoder.py:207
↓ 2 callers
Function
get_max_dist_point
(mask)
utils/utils.py:60
↓ 2 callers
Function
get_rel_pos
Get relative positional embeddings according to the relative positions of query and key sizes. Args: q_size (int): size of qu
segment_anything/modeling/image_encoder.py:292
↓ 2 callers
Function
mask_to_rle_pytorch
Encodes masks to an uncompressed RLE, in the format expected by pycoco tools.
segment_anything/utils/amg.py:107
↓ 2 callers
Method
postprocess_masks
Remove padding and upscale masks to the original image size. Arguments: masks (torch.Tensor): Batched masks from the mask_
segment_anything/modeling/sam.py:133
↓ 2 callers
Method
predict_masks
Predicts masks. See 'forward' for more details.
segment_anything/modeling/mask_decoder.py:112
↓ 2 callers
Method
predict_torch
Predict masks for the given input prompts, using the currently set image. Input prompts are batched torch tensors and are expected to
segment_anything/predictor.py:169
↓ 2 callers
Method
preprocess
Normalize pixel values and pad to a square input.
segment_anything/modeling/sam.py:164
↓ 2 callers
Function
remove_small_regions
Removes small disconnected regions and holes in a mask. Returns the mask and an indicator of if the mask has been modified.
segment_anything/utils/amg.py:267
↓ 2 callers
Function
rle_to_mask
Compute a binary mask from an uncompressed RLE.
segment_anything/utils/amg.py:138
↓ 2 callers
Function
show_box
(box, ax)
utils/utils.py:25
↓ 2 callers
Function
uncrop_boxes_xyxy
(boxes: torch.Tensor, crop_box: List[int])
segment_anything/utils/amg.py:237
↓ 1 callers
Method
__init__
( self, input_dim: int, hidden_dim: int, output_dim: int, num_layers:
segment_anything/modeling/mask_decoder.py:155
↓ 1 callers
Method
__init__
( self, embedding_dim: int, mlp_dim: int, act: Type[nn.Module] = nn.GELU,
segment_anything/modeling/common.py:14
↓ 1 callers
Method
__init__
Encodes prompts for input to SAM's mask decoder. Arguments: embed_dim (int): The prompts' embedding dimension im
segment_anything/modeling/prompt_encoder.py:17
↓ 1 callers
Method
_embed_boxes
Embeds box prompts.
segment_anything/modeling/prompt_encoder.py:93
↓ 1 callers
Method
_embed_masks
Embeds mask inputs.
segment_anything/modeling/prompt_encoder.py:102
↓ 1 callers
Method
_embed_masks
(self, input_mask: torch.Tensor, has_mask_input: torch.Tensor)
segment_anything/utils/onnx.py:69
↓ 1 callers
Method
_embed_points
Embeds point prompts.
segment_anything/modeling/prompt_encoder.py:73
↓ 1 callers
Method
_embed_points
(self, point_coords: torch.Tensor, point_labels: torch.Tensor)
segment_anything/utils/onnx.py:51
↓ 1 callers
Method
_generate_masks
(self, image: np.ndarray)
segment_anything/automatic_mask_generator.py:197
↓ 1 callers
Method
_get_batch_size
Gets the batch size of the output given the batch size of the input prompts.
segment_anything/modeling/prompt_encoder.py:107
↓ 1 callers
Method
_get_device
(self)
segment_anything/modeling/prompt_encoder.py:125
↓ 1 callers
Method
_process_batch
( self, points: np.ndarray, im_size: Tuple[int, ...], crop_box: List[int],
segment_anything/automatic_mask_generator.py:266
↓ 1 callers
Method
_process_crop
( self, image: np.ndarray, crop_box: List[int], crop_layer_idx: int, o
segment_anything/automatic_mask_generator.py:225
↓ 1 callers
Method
_recombine_heads
(self, x: Tensor)
segment_anything/modeling/transformer.py:213
↓ 1 callers
Function
add_decomposed_rel_pos
Calculate decomposed Relative Positional Embeddings from :paper:`mvitv2`. https://github.com/facebookresearch/mvit/blob/19786631e330df9f3622e
segment_anything/modeling/image_encoder.py:325
↓ 1 callers
Method
apply_boxes
Expects a numpy array shape Bx4. Requires the original image size in (H, W) format.
segment_anything/utils/transforms.py:47
↓ 1 callers
Method
apply_coords_torch
Expects a torch tensor with length 2 in the last dimension. Requires the original image size in (H, W) format.
segment_anything/utils/transforms.py:67
↓ 1 callers
Method
apply_image
Expects a numpy array with shape HxWxC in uint8 format.
segment_anything/utils/transforms.py:26
↓ 1 callers
Function
area_from_rle
(rle: Dict[str, Any])
segment_anything/utils/amg.py:152
↓ 1 callers
Function
batch_iterator
(batch_size: int, *args)
segment_anything/utils/amg.py:98
↓ 1 callers
Function
build_all_layer_point_grids
Generates point grids for all crop layers.
segment_anything/utils/amg.py:189
↓ 1 callers
Function
build_point_grid
Generates a 2D grid of points evenly spaced in [0,1]x[0,1].
segment_anything/utils/amg.py:179
↓ 1 callers
Function
coco_encode_rle
(uncompressed_rle: Dict[str, Any])
segment_anything/utils/amg.py:294
↓ 1 callers
Function
generate_crop_boxes
Generates a list of crop boxes of different sizes. Each layer has (2**i)**2 boxes for the ith layer.
segment_anything/utils/amg.py:200
↓ 1 callers
Method
get_image_embedding
Returns the image embeddings for the currently set image, with shape 1xCxHxW, where C is the embedding dimension and (H,W) are
segment_anything/predictor.py:245
↓ 1 callers
Function
is_box_near_crop_edge
Filter masks at the edge of a crop, but not at the edge of the original image.
segment_anything/utils/amg.py:78
↓ 1 callers
Function
main
()
main.py:325
↓ 1 callers
Method
mask_postprocessing
(self, masks: torch.Tensor, orig_im_size: torch.Tensor)
segment_anything/utils/onnx.py:76
↓ 1 callers
Method
postprocess_small_regions
Removes small disconnected regions and holes in masks, then reruns box NMS to remove any new duplicates. Edits mask_data in
segment_anything/automatic_mask_generator.py:324
↓ 1 callers
Method
resize_longest_image_size
( input_image_size: torch.Tensor, longest_side: int )
segment_anything/utils/onnx.py:42
↓ 1 callers
Method
select_masks
( self, masks: torch.Tensor, iou_preds: torch.Tensor, num_points: int )
segment_anything/utils/onnx.py:92
↓ 1 callers
Method
set_torch_image
Calculates the image embeddings for the provided image, allowing masks to be predicted with the 'predict' method. Expects the input
segment_anything/predictor.py:63
↓ 1 callers
Function
test
(args, predictor)
main.py:195
↓ 1 callers
Function
test_visualize
(args, model, predictor)
main.py:69
↓ 1 callers
Method
to_numpy
(self)
segment_anything/utils/amg.py:72
↓ 1 callers
Function
train
(args, predictor)
main.py:24
↓ 1 callers
Function
uncrop_masks
( masks: torch.Tensor, crop_box: List[int], orig_h: int, orig_w: int )
segment_anything/utils/amg.py:255
↓ 1 callers
Function
uncrop_points
(points: torch.Tensor, crop_box: List[int])
segment_anything/utils/amg.py:246
↓ 1 callers
Function
window_partition
Partition into non-overlapping windows with padding if needed. Args: x (tensor): input tokens with [B, H, W, C]. window_size
segment_anything/modeling/image_encoder.py:243
↓ 1 callers
Function
window_unpartition
Window unpartition into original sequences and removing padding. Args: windows (tensor): input tokens with [B * num_windows, window_s
segment_anything/modeling/image_encoder.py:267
Method
__delitem__
(self, key: str)
segment_anything/utils/amg.py:35
Method
__getitem__
(self, key: str)
segment_anything/utils/amg.py:38
Method
__init__
Uses SAM to calculate the image embedding for an image, and then allow repeated, efficient mask prediction given prompts. Ar
segment_anything/predictor.py:18
Method
__init__
Using a SAM model, generates masks for the entire image. Generates a grid of point prompts over the image, then filters low q
segment_anything/automatic_mask_generator.py:36
Method
__init__
Predicts masks given an image and prompt embeddings, using a transformer architecture. Arguments: transformer_dim
segment_anything/modeling/mask_decoder.py:17
Method
__init__
Args: img_size (int): Input image size. patch_size (int): Patch size. in_chans (int): Number of input ima
segment_anything/modeling/image_encoder.py:18
Method
__init__
Args: dim (int): Number of input channels. num_heads (int): Number of attention heads. qkv_bias (bool):
segment_anything/modeling/image_encoder.py:188
Method
__init__
Args: kernel_size (Tuple): kernel size of the projection layer. stride (Tuple): stride of the projection layer.
segment_anything/modeling/image_encoder.py:369
Method
__init__
(self, num_channels: int, eps: float = 1e-6)
segment_anything/modeling/common.py:32
Method
__init__
A transformer decoder that attends to an input image using queries whose positional embedding is supplied. Args: d
segment_anything/modeling/transformer.py:17
Method
__init__
A transformer block with four layers: (1) self-attention of sparse inputs, (2) cross attention of sparse inputs to dense inputs, (3)
segment_anything/modeling/transformer.py:110
Method
__init__
SAM predicts object masks from an image and input prompts. Arguments: image_encoder (ImageEncoderViT): The backbone used t
segment_anything/modeling/sam.py:22
Method
__init__
(self, num_pos_feats: int = 64, scale: Optional[float] = None)
segment_anything/modeling/prompt_encoder.py:176
Method
__init__
(self, target_length: int)
segment_anything/utils/transforms.py:23
Method
__init__
( self, model: Sam, return_single_mask: bool, use_stability_score: bool = Fals
segment_anything/utils/onnx.py:25
Method
__init__
(self, **kwargs)
segment_anything/utils/amg.py:22
Method
__setitem__
(self, key: str, item: Any)
segment_anything/utils/amg.py:29
Method
apply_boxes_torch
Expects a torch tensor with shape Bx4. Requires the original image size in (H, W) format.
segment_anything/utils/transforms.py:83
Method
apply_image_torch
Expects batched images with shape BxCxHxW and float format. This transformation may not exactly match apply_image. apply_image is
segment_anything/utils/transforms.py:55
Function
build_sam_vit_b
(checkpoint=None)
segment_anything/build_sam.py:37
Function
build_sam_vit_h
(checkpoint=None)
segment_anything/build_sam.py:14
Function
build_sam_vit_l
(checkpoint=None)
segment_anything/build_sam.py:27
Method
device
(self)
segment_anything/predictor.py:259
Method
device
(self)
segment_anything/modeling/sam.py:50
Method
forward
Predict masks given image and prompt embeddings. Arguments: image_embeddings (torch.Tensor): the embeddings from the image
segment_anything/modeling/mask_decoder.py:71
Method
forward
(self, x)
segment_anything/modeling/mask_decoder.py:171
Method
forward
(self, x: torch.Tensor)
segment_anything/modeling/image_encoder.py:106
Method
forward
(self, x: torch.Tensor)
segment_anything/modeling/image_encoder.py:166
next →
1–100 of 116, ranked by callers