Reference for ultralytics/models/fastsam/prompt.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/fastsam/prompt.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.models.fastsam.prompt.FastSAMPrompt
Fast Segment Anything Model class for image annotation and visualization.
Attributes:
Name | Type | Description |
---|---|---|
device |
str
|
Computing device ('cuda' or 'cpu'). |
results |
Object detection or segmentation results. |
|
source |
Source image or image path. |
|
clip |
CLIP model for linear assignment. |
Source code in ultralytics/models/fastsam/prompt.py
box_prompt
Modifies the bounding box properties and calculates IoU between masks and bounding box.
Source code in ultralytics/models/fastsam/prompt.py
everything_prompt
fast_show_mask
staticmethod
fast_show_mask(annotation, ax, random_color=False, bbox=None, points=None, pointlabel=None, retinamask=True, target_height=960, target_width=960)
Quickly shows the mask annotations on the given matplotlib axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotation |
array - like
|
Mask annotation. |
required |
ax |
Axes
|
Matplotlib axis. |
required |
random_color |
bool
|
Whether to use random color for masks. Defaults to False. |
False
|
bbox |
list
|
Bounding box coordinates [x1, y1, x2, y2]. Defaults to None. |
None
|
points |
list
|
Points to be plotted. Defaults to None. |
None
|
pointlabel |
list
|
Labels for the points. Defaults to None. |
None
|
retinamask |
bool
|
Whether to use retina mask. Defaults to True. |
True
|
target_height |
int
|
Target height for resizing. Defaults to 960. |
960
|
target_width |
int
|
Target width for resizing. Defaults to 960. |
960
|
Source code in ultralytics/models/fastsam/prompt.py
plot
plot(annotations, output, bbox=None, points=None, point_label=None, mask_random_color=True, better_quality=True, retina=False, with_contours=True)
Plots annotations, bounding boxes, and points on images and saves the output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotations |
list
|
Annotations to be plotted. |
required |
output |
str or Path
|
Output directory for saving the plots. |
required |
bbox |
list
|
Bounding box coordinates [x1, y1, x2, y2]. Defaults to None. |
None
|
points |
list
|
Points to be plotted. Defaults to None. |
None
|
point_label |
list
|
Labels for the points. Defaults to None. |
None
|
mask_random_color |
bool
|
Whether to use random color for masks. Defaults to True. |
True
|
better_quality |
bool
|
Whether to apply morphological transformations for better mask quality. Defaults to True. |
True
|
retina |
bool
|
Whether to use retina mask. Defaults to False. |
False
|
with_contours |
bool
|
Whether to plot contours. Defaults to True. |
True
|
Source code in ultralytics/models/fastsam/prompt.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
point_prompt
Adjusts points on detected masks based on user input and returns the modified results.
Source code in ultralytics/models/fastsam/prompt.py
retrieve
Processes images and text with a model, calculates similarity, and returns softmax score.
Source code in ultralytics/models/fastsam/prompt.py
text_prompt
Processes a text prompt, applies it to existing results and returns the updated results.