vision_agent.tools
vision_agent.tools
register_tool
Source code in vision_agent/tools/__init__.py
vision_agent.tools.tools
COLORS
module-attribute
COLORS = [
(158, 218, 229),
(219, 219, 141),
(23, 190, 207),
(188, 189, 34),
(199, 199, 199),
(247, 182, 210),
(127, 127, 127),
(227, 119, 194),
(196, 156, 148),
(197, 176, 213),
(140, 86, 75),
(148, 103, 189),
(255, 152, 150),
(152, 223, 138),
(214, 39, 40),
(44, 160, 44),
(255, 187, 120),
(174, 199, 232),
(255, 127, 14),
(31, 119, 180),
]
FUNCTION_TOOLS
module-attribute
FUNCTION_TOOLS = [
owl_v2_image,
owl_v2_video,
ocr,
vit_image_classification,
vit_nsfw_classification,
countgd_counting,
florence2_ocr,
florence2_sam2_image,
florence2_sam2_video_tracking,
florence2_phrase_grounding,
claude35_text_extraction,
detr_segmentation,
depth_anything_v2,
generate_pose_image,
closest_mask_distance,
closest_box_distance,
qwen2_vl_images_vqa,
qwen2_vl_video_vqa,
video_temporal_localization,
flux_image_inpainting,
siglip_classification,
]
UTIL_TOOLS
module-attribute
UTIL_TOOLS = [
extract_frames_and_timestamps,
save_json,
load_image,
save_image,
save_video,
overlay_bounding_boxes,
overlay_segmentation_masks,
overlay_heat_map,
]
grounding_dino
'grounding_dino' is a tool that can detect and count multiple objects given a text prompt such as category names or referring expressions. The categories in text prompt are separated by commas or periods. It returns a list of bounding boxes with normalized coordinates, label names and associated probability scores.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The prompt to ground to the image.
TYPE:
|
image |
The image to ground the prompt to.
TYPE:
|
box_threshold |
The threshold for the box detection. Defaults to 0.20.
TYPE:
|
iou_threshold |
The threshold for the Intersection over Union (IoU). Defaults to 0.20.
TYPE:
|
model_size |
The size of the model to use.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries containing the score, label, and bounding box of the detected objects with normalized coordinates between 0 and 1 (xmin, ymin, xmax, ymax). xmin and ymin are the coordinates of the top-left and xmax and ymax are the coordinates of the bottom-right of the bounding box. |
Example
>>> grounding_dino("car. dinosaur", image)
[
{'score': 0.99, 'label': 'dinosaur', 'bbox': [0.1, 0.11, 0.35, 0.4]},
{'score': 0.98, 'label': 'car', 'bbox': [0.2, 0.21, 0.45, 0.5},
]
Source code in vision_agent/tools/tools.py
owl_v2_image
'owl_v2_image' is a tool that can detect and count multiple objects given a text prompt such as category names or referring expressions on images. The categories in text prompt are separated by commas. It returns a list of bounding boxes with normalized coordinates, label names and associated probability scores.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The prompt to ground to the image.
TYPE:
|
image |
The image to ground the prompt to.
TYPE:
|
box_threshold |
The threshold for the box detection. Defaults to 0.10.
TYPE:
|
fine_tune_id |
If you have a fine-tuned model, you can pass the fine-tuned model ID here to use it.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries containing the score, label, and bounding box of the detected objects with normalized coordinates between 0 and 1 (xmin, ymin, xmax, ymax). xmin and ymin are the coordinates of the top-left and xmax and ymax are the coordinates of the bottom-right of the bounding box. |
Example
>>> owl_v2_image("car, dinosaur", image)
[
{'score': 0.99, 'label': 'dinosaur', 'bbox': [0.1, 0.11, 0.35, 0.4]},
{'score': 0.98, 'label': 'car', 'bbox': [0.2, 0.21, 0.45, 0.5},
]
Source code in vision_agent/tools/tools.py
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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
owl_v2_video
'owl_v2_video' will run owl_v2 on each frame of a video. It can detect multiple objects independently per frame given a text prompt such as a category name or referring expression but does not track objects across frames. The categories in text prompt are separated by commas. It returns a list of lists where each inner list contains the score, label, and bounding box of the detections for that frame.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The prompt to ground to the video.
TYPE:
|
frames |
The list of frames to ground the prompt to.
TYPE:
|
box_threshold |
The threshold for the box detection. Defaults to 0.30.
TYPE:
|
fine_tune_id |
If you have a fine-tuned model, you can pass the fine-tuned model ID here to use it.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[List[Dict[str, Any]]]
|
List[List[Dict[str, Any]]]: A list of lists of dictionaries containing the score, label, and bounding box of the detected objects with normalized coordinates between 0 and 1 (xmin, ymin, xmax, ymax). xmin and ymin are the coordinates of the top-left and xmax and ymax are the coordinates of the bottom-right of the bounding box. |
Example
>>> owl_v2_video("car, dinosaur", frames)
[
[
{'score': 0.99, 'label': 'dinosaur', 'bbox': [0.1, 0.11, 0.35, 0.4]},
{'score': 0.98, 'label': 'car', 'bbox': [0.2, 0.21, 0.45, 0.5},
],
...
]
Source code in vision_agent/tools/tools.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
grounding_sam
'grounding_sam' is a tool that can segment multiple objects given a text prompt such as category names or referring expressions. The categories in text prompt are separated by commas or periods. It returns a list of bounding boxes, label names, mask file names and associated probability scores.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The prompt to ground to the image.
TYPE:
|
image |
The image to ground the prompt to.
TYPE:
|
box_threshold |
The threshold for the box detection. Defaults to 0.20.
TYPE:
|
iou_threshold |
The threshold for the Intersection over Union (IoU). Defaults to 0.20.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries containing the score, label, bounding box, and mask of the detected objects with normalized coordinates (xmin, ymin, xmax, ymax). xmin and ymin are the coordinates of the top-left and xmax and ymax are the coordinates of the bottom-right of the bounding box. The mask is binary 2D numpy array where 1 indicates the object and 0 indicates the background. |
Example
>>> grounding_sam("car. dinosaur", image)
[
{
'score': 0.99,
'label': 'dinosaur',
'bbox': [0.1, 0.11, 0.35, 0.4],
'mask': array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=uint8),
},
]
Source code in vision_agent/tools/tools.py
florence2_sam2_image
'florence2_sam2_image' is a tool that can segment multiple objects given a text prompt such as category names or referring expressions. The categories in the text prompt are separated by commas. It returns a list of bounding boxes, label names, mask file names and associated probability scores of 1.0.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The prompt to ground to the image.
TYPE:
|
image |
The image to ground the prompt to.
TYPE:
|
fine_tune_id |
If you have a fine-tuned model, you can pass the fine-tuned model ID here to use it.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries containing the score, label, bounding box, and mask of the detected objects with normalized coordinates (xmin, ymin, xmax, ymax). xmin and ymin are the coordinates of the top-left and xmax and ymax are the coordinates of the bottom-right of the bounding box. The mask is binary 2D numpy array where 1 indicates the object and 0 indicates the background. |
Example
>>> florence2_sam2_image("car, dinosaur", image)
[
{
'score': 1.0,
'label': 'dinosaur',
'bbox': [0.1, 0.11, 0.35, 0.4],
'mask': array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=uint8),
},
]
Source code in vision_agent/tools/tools.py
florence2_sam2_video_tracking
'florence2_sam2_video_tracking' is a tool that can segment and track multiple entities in a video given a text prompt such as category names or referring expressions. You can optionally separate the categories in the text with commas. It can find new objects every 'chunk_length' frames and is useful for tracking and counting without duplicating counts and always outputs scores of 1.0.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The prompt to ground to the video.
TYPE:
|
frames |
The list of frames to ground the prompt to.
TYPE:
|
chunk_length |
The number of frames to re-run florence2 to find new objects.
TYPE:
|
fine_tune_id |
If you have a fine-tuned model, you can pass the fine-tuned model ID here to use it.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[List[Dict[str, Any]]]
|
List[List[Dict[str, Any]]]: A list of list of dictionaries containing the |
List[List[Dict[str, Any]]]
|
label,segment mask and bounding boxes. The outer list represents each frame and |
List[List[Dict[str, Any]]]
|
the inner list is the entities per frame. The label contains the object ID |
List[List[Dict[str, Any]]]
|
followed by the label name. The objects are only identified in the first framed |
List[List[Dict[str, Any]]]
|
and tracked throughout the video. |
Example
>>> florence2_sam2_video("car, dinosaur", frames)
[
[
{
'label': '0: dinosaur',
'bbox': [0.1, 0.11, 0.35, 0.4],
'mask': array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=uint8),
},
],
...
]
Source code in vision_agent/tools/tools.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
|
ocr
'ocr' extracts text from an image. It returns a list of detected text, bounding boxes with normalized coordinates, and confidence scores. The results are sorted from top-left to bottom right.
PARAMETER | DESCRIPTION |
---|---|
image |
The image to extract text from.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries containing the detected text, bbox with normalized coordinates, and confidence score. |
Example
>>> ocr(image)
[
{'label': 'hello world', 'bbox': [0.1, 0.11, 0.35, 0.4], 'score': 0.99},
]
Source code in vision_agent/tools/tools.py
loca_zero_shot_counting
'loca_zero_shot_counting' is a tool that counts the dominant foreground object given an image and no other information about the content. It returns only the count of the objects in the image.
PARAMETER | DESCRIPTION |
---|---|
image |
The image that contains lot of instances of a single object
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the key 'count' and the count as a value, e.g. {count: 12} and a heat map for visualization purposes. |
Example
>>> loca_zero_shot_counting(image)
{'count': 83,
'heat_map': array([[ 0, 0, 0, ..., 0, 0, 0],
[ 0, 0, 0, ..., 0, 0, 0],
[ 0, 0, 0, ..., 0, 0, 1],
...,
[ 0, 0, 0, ..., 30, 35, 41],
[ 0, 0, 0, ..., 41, 47, 53],
[ 0, 0, 0, ..., 53, 59, 64]], dtype=uint8)}
Source code in vision_agent/tools/tools.py
loca_visual_prompt_counting
'loca_visual_prompt_counting' is a tool that counts the dominant foreground object given an image and a visual prompt which is a bounding box describing the object. It returns only the count of the objects in the image.
PARAMETER | DESCRIPTION |
---|---|
image |
The image that contains lot of instances of a single object visual_prompt (Dict[str, List[float]]): Bounding box of the object in format [xmin, ymin, xmax, ymax]. Only 1 bounding box can be provided.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the key 'count' and the count as a value, e.g. {count: 12} and a heat map for visualization purposes. |
Example
>>> loca_visual_prompt_counting(image, {"bbox": [0.1, 0.1, 0.4, 0.42]})
{'count': 83,
'heat_map': array([[ 0, 0, 0, ..., 0, 0, 0],
[ 0, 0, 0, ..., 0, 0, 0],
[ 0, 0, 0, ..., 0, 0, 1],
...,
[ 0, 0, 0, ..., 30, 35, 41],
[ 0, 0, 0, ..., 41, 47, 53],
[ 0, 0, 0, ..., 53, 59, 64]], dtype=uint8)}
Source code in vision_agent/tools/tools.py
countgd_counting
'countgd_counting' is a tool that can detect multiple instances of an object given a text prompt. It is particularly useful when trying to detect and count a large number of objects. It returns a list of bounding boxes with normalized coordinates, label names and associated confidence scores.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The object that needs to be counted.
TYPE:
|
image |
The image that contains multiple instances of the object.
TYPE:
|
box_threshold |
The threshold for detection. Defaults to 0.23.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries containing the score, label, and bounding box of the detected objects with normalized coordinates between 0 and 1 (xmin, ymin, xmax, ymax). xmin and ymin are the coordinates of the top-left and xmax and ymax are the coordinates of the bottom-right of the bounding box. |
Example
>>> countgd_counting("flower", image)
[
{'score': 0.49, 'label': 'flower', 'bbox': [0.1, 0.11, 0.35, 0.4]},
{'score': 0.68, 'label': 'flower', 'bbox': [0.2, 0.21, 0.45, 0.5},
{'score': 0.78, 'label': 'flower', 'bbox': [0.3, 0.35, 0.48, 0.52},
{'score': 0.98, 'label': 'flower', 'bbox': [0.44, 0.24, 0.49, 0.58},
]
Source code in vision_agent/tools/tools.py
countgd_example_based_counting
'countgd_example_based_counting' is a tool that can precisely count multiple instances of an object given few visual example prompts. It returns a list of bounding boxes with normalized coordinates, label names and associated confidence scores.
PARAMETER | DESCRIPTION |
---|---|
visual_prompts |
Bounding boxes of the object in format [xmin, ymin, xmax, ymax]. Upto 3 bounding boxes can be provided. image (np.ndarray): The image that contains multiple instances of the object. box_threshold (float, optional): The threshold for detection. Defaults to 0.23.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries containing the score, label, and bounding box of the detected objects with normalized coordinates between 0 and 1 (xmin, ymin, xmax, ymax). xmin and ymin are the coordinates of the top-left and xmax and ymax are the coordinates of the bottom-right of the bounding box. |
Example
>>> countgd_example_based_counting(
visual_prompts=[[0.1, 0.1, 0.4, 0.42], [0.2, 0.3, 0.25, 0.35]],
image=image
)
[
{'score': 0.49, 'label': 'object', 'bounding_box': [0.1, 0.11, 0.35, 0.4]},
{'score': 0.68, 'label': 'object', 'bounding_box': [0.2, 0.21, 0.45, 0.5},
{'score': 0.78, 'label': 'object', 'bounding_box': [0.3, 0.35, 0.48, 0.52},
{'score': 0.98, 'label': 'object', 'bounding_box': [0.44, 0.24, 0.49, 0.58},
]
Source code in vision_agent/tools/tools.py
florence2_roberta_vqa
'florence2_roberta_vqa' is a tool that takes an image and analyzes its contents, generates detailed captions and then tries to answer the given question using the generated context. It returns text as an answer to the question.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The question about the image
TYPE:
|
image |
The reference image used for the question
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string which is the answer to the given prompt.
TYPE:
|
Example
>>> florence2_roberta_vqa('What is the top left animal in this image?', image)
'white tiger'
Source code in vision_agent/tools/tools.py
ixc25_image_vqa
'ixc25_image_vqa' is a tool that can answer any questions about arbitrary images including regular images or images of documents or presentations. It returns text as an answer to the question.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The question about the image
TYPE:
|
image |
The reference image used for the question
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string which is the answer to the given prompt.
TYPE:
|
Example
>>> ixc25_image_vqa('What is the cat doing?', image)
'drinking milk'
Source code in vision_agent/tools/tools.py
qwen2_vl_images_vqa
'qwen2_vl_images_vqa' is a tool that can answer any questions about arbitrary images including regular images or images of documents or presentations. It can be very useful for document QA or OCR text extraction. It returns text as an answer to the question.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The question about the document image
TYPE:
|
images |
The reference images used for the question
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string which is the answer to the given prompt.
TYPE:
|
Example
>>> qwen2_vl_images_vqa('Give a summary of the document', images)
'The document talks about the history of the United States of America and its...'
Source code in vision_agent/tools/tools.py
claude35_text_extraction
'claude35_text_extraction' is a tool that can extract text from an image. It returns the extracted text as a string and can be used as an alternative to OCR if you do not need to know the exact bounding box of the text.
PARAMETER | DESCRIPTION |
---|---|
image |
The image to extract text from.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The extracted text from the image.
TYPE:
|
Source code in vision_agent/tools/tools.py
ixc25_video_vqa
'ixc25_video_vqa' is a tool that can answer any questions about arbitrary videos including regular videos or videos of documents or presentations. It returns text as an answer to the question.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The question about the video
TYPE:
|
frames |
The reference frames used for the question
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string which is the answer to the given prompt.
TYPE:
|
Example
>>> ixc25_video_vqa('Which football player made the goal?', frames)
'Lionel Messi'
Source code in vision_agent/tools/tools.py
qwen2_vl_video_vqa
'qwen2_vl_video_vqa' is a tool that can answer any questions about arbitrary videos including regular videos or videos of documents or presentations. It returns text as an answer to the question.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The question about the video
TYPE:
|
frames |
The reference frames used for the question
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string which is the answer to the given prompt.
TYPE:
|
Example
>>> qwen2_vl_video_vqa('Which football player made the goal?', frames)
'Lionel Messi'
Source code in vision_agent/tools/tools.py
gpt4o_image_vqa
'gpt4o_image_vqa' is a tool that can answer any questions about arbitrary images including regular images or images of documents or presentations. It returns text as an answer to the question.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The question about the image
TYPE:
|
image |
The reference image used for the question
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string which is the answer to the given prompt.
TYPE:
|
Example
>>> gpt4o_image_vqa('What is the cat doing?', image)
'drinking milk'
Source code in vision_agent/tools/tools.py
gpt4o_video_vqa
'gpt4o_video_vqa' is a tool that can answer any questions about arbitrary videos including regular videos or videos of documents or presentations. It returns text as an answer to the question.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The question about the video
TYPE:
|
frames |
The reference frames used for the question
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string which is the answer to the given prompt.
TYPE:
|
Example
>>> gpt4o_video_vqa('Which football player made the goal?', frames)
'Lionel Messi'
Source code in vision_agent/tools/tools.py
git_vqa_v2
'git_vqa_v2' is a tool that can answer questions about the visual contents of an image given a question and an image. It returns an answer to the question
PARAMETER | DESCRIPTION |
---|---|
prompt |
The question about the image
TYPE:
|
image |
The reference image used for the question
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string which is the answer to the given prompt.
TYPE:
|
Example
>>> git_vqa_v2('What is the cat doing ?', image)
'drinking milk'
Source code in vision_agent/tools/tools.py
video_temporal_localization
'video_temporal_localization' will run qwen2vl on each chunk_length_frames value selected for the video. It can detect multiple objects independently per chunk_length_frames given a text prompt such as a referring expression but does not track objects across frames. It returns a list of floats with a value of 1.0 if the objects are found in a given chunk_length_frames of the video.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The question about the video
TYPE:
|
frames |
The reference frames used for the question
TYPE:
|
model |
The model to use for the inference. Valid values are 'qwen2vl', 'gpt4o', 'internlm-xcomposer'
TYPE:
|
chunk_length_frames |
length of each chunk in frames
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[float]
|
List[float]: A list of floats with a value of 1.0 if the objects to be found are present in the chunk_length_frames of the video. |
Example
>>> video_temporal_localization('Did a goal happened?', frames)
[0.0, 0.0, 0.0, 1.0, 1.0, 0.0]
Source code in vision_agent/tools/tools.py
clip
'clip' is a tool that can classify an image or a cropped detection given a list of input classes or tags. It returns the same list of the input classes along with their probability scores based on image content.
PARAMETER | DESCRIPTION |
---|---|
image |
The image to classify or tag
TYPE:
|
classes |
The list of classes or tags that is associated with the image
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the labels and scores. One dictionary contains a list of given labels and other a list of scores. |
Example
>>> clip(image, ['dog', 'cat', 'bird'])
{"labels": ["dog", "cat", "bird"], "scores": [0.68, 0.30, 0.02]},
Source code in vision_agent/tools/tools.py
vit_image_classification
'vit_image_classification' is a tool that can classify an image. It returns a list of classes and their probability scores based on image content.
PARAMETER | DESCRIPTION |
---|---|
image |
The image to classify or tag
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the labels and scores. One dictionary contains a list of labels and other a list of scores. |
Example
>>> vit_image_classification(image)
{"labels": ["leopard", "lemur, otter", "bird"], "scores": [0.68, 0.30, 0.02]},
Source code in vision_agent/tools/tools.py
vit_nsfw_classification
'vit_nsfw_classification' is a tool that can classify an image as 'nsfw' or 'normal'. It returns the predicted label and their probability scores based on image content.
PARAMETER | DESCRIPTION |
---|---|
image |
The image to classify or tag
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the labels and scores. One dictionary contains a list of labels and other a list of scores. |
Example
>>> vit_nsfw_classification(image)
{"label": "normal", "scores": 0.68},
Source code in vision_agent/tools/tools.py
blip_image_caption
'blip_image_caption' is a tool that can caption an image based on its contents. It returns a text describing the image.
PARAMETER | DESCRIPTION |
---|---|
image |
The image to caption
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string which is the caption for the given image.
TYPE:
|
Example
>>> blip_image_caption(image)
'This image contains a cat sitting on a table with a bowl of milk.'
Source code in vision_agent/tools/tools.py
florence2_image_caption
'florence2_image_caption' is a tool that can caption or describe an image based on its contents. It returns a text describing the image.
PARAMETER | DESCRIPTION |
---|---|
image |
The image to caption
TYPE:
|
detail_caption |
If True, the caption will be as detailed as possible else the caption will be a brief description.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string which is the caption for the given image.
TYPE:
|
Example
>>> florence2_image_caption(image, False)
'This image contains a cat sitting on a table with a bowl of milk.'
Source code in vision_agent/tools/tools.py
florence2_phrase_grounding
'florence2_phrase_grounding' is a tool that can detect multiple objects given a text prompt which can be object names or caption. You can optionally separate the object names in the text with commas. It returns a list of bounding boxes with normalized coordinates, label names and associated probability scores of 1.0.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The prompt to ground to the image.
TYPE:
|
image |
The image to used to detect objects
TYPE:
|
fine_tune_id |
If you have a fine-tuned model, you can pass the fine-tuned model ID here to use it.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries containing the score, label, and bounding box of the detected objects with normalized coordinates between 0 and 1 (xmin, ymin, xmax, ymax). xmin and ymin are the coordinates of the top-left and xmax and ymax are the coordinates of the bottom-right of the bounding box. The scores are always 1.0 and cannot be thresholded |
Example
>>> florence2_phrase_grounding('person looking at a coyote', image)
[
{'score': 1.0, 'label': 'person', 'bbox': [0.1, 0.11, 0.35, 0.4]},
{'score': 1.0, 'label': 'coyote', 'bbox': [0.34, 0.21, 0.85, 0.5},
]
Source code in vision_agent/tools/tools.py
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 |
|
florence2_phrase_grounding_video
'florence2_phrase_grounding_video' will run florence2 on each frame of a video. It can detect multiple objects given a text prompt which can be object names or caption. You can optionally separate the object names in the text with commas. It returns a list of lists where each inner list contains bounding boxes with normalized coordinates, label names and associated probability scores of 1.0.
PARAMETER | DESCRIPTION |
---|---|
prompt |
The prompt to ground to the video.
TYPE:
|
frames |
The list of frames to detect objects.
TYPE:
|
fine_tune_id |
If you have a fine-tuned model, you can pass the fine-tuned model ID here to use it.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[List[Dict[str, Any]]]
|
List[List[Dict[str, Any]]]: A list of lists of dictionaries containing the score, label, and bounding box of the detected objects with normalized coordinates between 0 and 1 (xmin, ymin, xmax, ymax). xmin and ymin are the coordinates of the top-left and xmax and ymax are the coordinates of the bottom-right of the bounding box. The scores are always 1.0 and cannot be thresholded. |
Example
>>> florence2_phrase_grounding_video('person looking at a coyote', frames)
[
[
{'score': 1.0, 'label': 'person', 'bbox': [0.1, 0.11, 0.35, 0.4]},
{'score': 1.0, 'label': 'coyote', 'bbox': [0.34, 0.21, 0.85, 0.5},
],
...
]
Source code in vision_agent/tools/tools.py
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 |
|
florence2_ocr
'florence2_ocr' is a tool that can detect text and text regions in an image. Each text region contains one line of text. It returns a list of detected text, the text region as a bounding box with normalized coordinates, and confidence scores. The results are sorted from top-left to bottom right.
PARAMETER | DESCRIPTION |
---|---|
image |
The image to extract text from.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries containing the detected text, bbox with normalized coordinates, and confidence score. |
Example
>>> florence2_ocr(image)
[
{'label': 'hello world', 'bbox': [0.1, 0.11, 0.35, 0.4], 'score': 0.99},
]
Source code in vision_agent/tools/tools.py
detr_segmentation
'detr_segmentation' is a tool that can segment common objects in an image without any text prompt. It returns a list of detected objects as labels, their regions as masks and their scores.
PARAMETER | DESCRIPTION |
---|---|
image |
The image used to segment things and objects
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries containing the score, label and mask of the detected objects. The mask is binary 2D numpy array where 1 indicates the object and 0 indicates the background. |
Example
>>> detr_segmentation(image)
[
{
'score': 0.45,
'label': 'window',
'mask': array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=uint8),
},
{
'score': 0.70,
'label': 'bird',
'mask': array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=uint8),
},
]
Source code in vision_agent/tools/tools.py
depth_anything_v2
'depth_anything_v2' is a tool that runs depth_anythingv2 model to generate a depth image from a given RGB image. The returned depth image is monochrome and represents depth values as pixel intesities with pixel values ranging from 0 to 255.
PARAMETER | DESCRIPTION |
---|---|
image |
The image to used to generate depth image
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: A grayscale depth image with pixel values ranging from 0 to 255. |
Example
>>> depth_anything_v2(image)
array([[0, 0, 0, ..., 0, 0, 0],
[0, 20, 24, ..., 0, 100, 103],
...,
[10, 11, 15, ..., 202, 202, 205],
[10, 10, 10, ..., 200, 200, 200]], dtype=uint8),
Source code in vision_agent/tools/tools.py
generate_soft_edge_image
'generate_soft_edge_image' is a tool that runs Holistically Nested edge detection to generate a soft edge image (HED) from a given RGB image. The returned image is monochrome and represents object boundaries as soft white edges on black background
PARAMETER | DESCRIPTION |
---|---|
image |
The image to used to generate soft edge image
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: A soft edge image with pixel values ranging from 0 to 255. |
Example
>>> generate_soft_edge_image(image)
array([[0, 0, 0, ..., 0, 0, 0],
[0, 20, 24, ..., 0, 100, 103],
...,
[10, 11, 15, ..., 202, 202, 205],
[10, 10, 10, ..., 200, 200, 200]], dtype=uint8),
Source code in vision_agent/tools/tools.py
dpt_hybrid_midas
'dpt_hybrid_midas' is a tool that generates a normal mapped from a given RGB image. The returned RGB image is texture mapped image of the surface normals and the RGB values represent the surface normals in the x, y, z directions.
PARAMETER | DESCRIPTION |
---|---|
image |
The image to used to generate normal image
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: A mapped normal image with RGB pixel values indicating surface |
ndarray
|
normals in x, y, z directions. |
Example
>>> dpt_hybrid_midas(image)
array([[0, 0, 0, ..., 0, 0, 0],
[0, 20, 24, ..., 0, 100, 103],
...,
[10, 11, 15, ..., 202, 202, 205],
[10, 10, 10, ..., 200, 200, 200]], dtype=uint8),
Source code in vision_agent/tools/tools.py
generate_pose_image
'generate_pose_image' is a tool that generates a open pose bone/stick image from a given RGB image. The returned bone image is RGB with the pose amd keypoints colored and background as black.
PARAMETER | DESCRIPTION |
---|---|
image |
The image to used to generate pose image
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: A bone or pose image indicating the pose and keypoints |
Example
>>> generate_pose_image(image)
array([[0, 0, 0, ..., 0, 0, 0],
[0, 20, 24, ..., 0, 100, 103],
...,
[10, 11, 15, ..., 202, 202, 205],
[10, 10, 10, ..., 200, 200, 200]], dtype=uint8),
Source code in vision_agent/tools/tools.py
template_match
'template_match' is a tool that can detect all instances of a template in a given image. It returns the locations of the detected template, a corresponding similarity score of the same
PARAMETER | DESCRIPTION |
---|---|
image |
The image used for searching the template
TYPE:
|
template_image |
The template image or crop to search in the image
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries containing the score and bounding box of the detected template with normalized coordinates between 0 and 1 (xmin, ymin, xmax, ymax). xmin and ymin are the coordinates of the top-left and xmax and ymax are the coordinates of the bottom-right of the bounding box. |
Example
>>> template_match(image, template)
[
{'score': 0.79, 'bbox': [0.1, 0.11, 0.35, 0.4]},
{'score': 0.38, 'bbox': [0.2, 0.21, 0.45, 0.5},
]
Source code in vision_agent/tools/tools.py
closest_mask_distance
'closest_mask_distance' calculates the closest distance between two masks.
PARAMETER | DESCRIPTION |
---|---|
mask1 |
The first mask.
TYPE:
|
mask2 |
The second mask.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
The closest distance between the two masks.
TYPE:
|
Example
>>> closest_mask_distance(mask1, mask2)
0.5
Source code in vision_agent/tools/tools.py
closest_box_distance
'closest_box_distance' calculates the closest distance between two bounding boxes.
PARAMETER | DESCRIPTION |
---|---|
box1 |
The first bounding box.
TYPE:
|
box2 |
The second bounding box.
TYPE:
|
image_size |
The size of the image given as (height, width).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
The closest distance between the two bounding boxes.
TYPE:
|
Example
>>> closest_box_distance([100, 100, 200, 200], [300, 300, 400, 400])
141.42
Source code in vision_agent/tools/tools.py
flux_image_inpainting
'flux_image_inpainting' performs image inpainting to fill the masked regions, given by mask, in the image, given image based on the text prompt and surrounding image context. It can be used to edit regions of an image according to the prompt given.
PARAMETER | DESCRIPTION |
---|---|
prompt |
A detailed text description guiding what should be generated in the masked area. More detailed and specific prompts typically yield better results.
TYPE:
|
image |
The source image to be inpainted. The image will serve as the base context for the inpainting process.
TYPE:
|
mask |
A binary mask image with 0's and 1's, where 1 indicates areas to be inpainted and 0 indicates areas to be preserved.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: The generated image(s) as a numpy array in RGB format with values ranging from 0 to 255. |
Example: >>> # Generate inpainting >>> result = flux_image_inpainting( ... prompt="a modern black leather sofa with white pillows", ... image=image, ... mask=mask, ... ) >>> save_image(result, "inpainted_room.png")
Source code in vision_agent/tools/tools.py
1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 |
|
siglip_classification
'siglip_classification' is a tool that can classify an image or a cropped detection given a list of input labels or tags. It returns the same list of the input labels along with their probability scores based on image content.
PARAMETER | DESCRIPTION |
---|---|
image |
The image to classify or tag
TYPE:
|
labels |
The list of labels or tags that is associated with the image
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the labels and scores. One dictionary contains a list of given labels and other a list of scores. |
Example
>>> siglip_classification(image, ['dog', 'cat', 'bird'])
{"labels": ["dog", "cat", "bird"], "scores": [0.68, 0.30, 0.02]},
Source code in vision_agent/tools/tools.py
extract_frames_and_timestamps
'extract_frames_and_timestamps' extracts frames and timestamps from a video which can be a file path, url or youtube link, returns a list of dictionaries with keys "frame" and "timestamp" where "frame" is a numpy array and "timestamp" is the relative time in seconds where the frame was captured. The frame is a numpy array.
PARAMETER | DESCRIPTION |
---|---|
video_uri |
The path to the video file, url or youtube link
TYPE:
|
fps |
The frame rate per second to extract the frames. Defaults to 1.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[Dict[str, Union[ndarray, float]]]
|
List[Dict[str, Union[np.ndarray, float]]]: A list of dictionaries containing the extracted frame as a numpy array and the timestamp in seconds. |
Example
>>> extract_frames("path/to/video.mp4")
[{"frame": np.ndarray, "timestamp": 0.0}, ...]
Source code in vision_agent/tools/tools.py
1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 |
|
save_json
'save_json' is a utility function that saves data as a JSON file. It is helpful for saving data that contains NumPy arrays which are not JSON serializable.
PARAMETER | DESCRIPTION |
---|---|
data |
The data to save.
TYPE:
|
file_path |
The path to save the JSON file.
TYPE:
|
Example
>>> save_json(data, "path/to/file.json")
Source code in vision_agent/tools/tools.py
load_image
'load_image' is a utility function that loads an image from the given file path string or an URL.
PARAMETER | DESCRIPTION |
---|---|
image_path |
The path or URL to the image.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: The image as a NumPy array. |
Example
>>> load_image("path/to/image.jpg")
Source code in vision_agent/tools/tools.py
save_image
'save_image' is a utility function that saves an image to a file path.
PARAMETER | DESCRIPTION |
---|---|
image |
The image to save.
TYPE:
|
file_path |
The path to save the image file.
TYPE:
|
Example
>>> save_image(image)
Source code in vision_agent/tools/tools.py
save_video
'save_video' is a utility function that saves a list of frames as a mp4 video file on disk.
PARAMETER | DESCRIPTION |
---|---|
frames |
A list of frames to save.
TYPE:
|
output_video_path |
The path to save the video file. If not provided, a temporary file will be created.
TYPE:
|
fps |
The number of frames composes a second in the video.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The path to the saved video file.
TYPE:
|
Example
>>> save_video(frames)
"/tmp/tmpvideo123.mp4"
Source code in vision_agent/tools/tools.py
overlay_bounding_boxes
'overlay_bounding_boxes' is a utility function that displays bounding boxes on an image.
PARAMETER | DESCRIPTION |
---|---|
medias |
The image or frames to display the bounding boxes on.
TYPE:
|
bboxes |
A list of dictionaries or a list of list of dictionaries containing the bounding boxes.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[ndarray, List[ndarray]]
|
np.ndarray: The image with the bounding boxes, labels and scores displayed. |
Example
>>> image_with_bboxes = overlay_bounding_boxes(
image, [{'score': 0.99, 'label': 'dinosaur', 'bbox': [0.1, 0.11, 0.35, 0.4]}],
)
Source code in vision_agent/tools/tools.py
2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 |
|
overlay_segmentation_masks
'overlay_segmentation_masks' is a utility function that displays segmentation masks.
PARAMETER | DESCRIPTION |
---|---|
medias |
The image or frames to display the masks on.
TYPE:
|
masks |
A list of dictionaries or a list of list of dictionaries containing the masks, labels and scores.
TYPE:
|
draw_label |
If True, the labels will be displayed on the image.
TYPE:
|
secondary_label_key |
The key to use for the secondary tracking label which is needed in videos to display tracking information.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[ndarray, List[ndarray]]
|
np.ndarray: The image with the masks displayed. |
Example
>>> image_with_masks = overlay_segmentation_masks(
image,
[{
'score': 0.99,
'label': 'dinosaur',
'mask': array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=uint8),
}],
)
Source code in vision_agent/tools/tools.py
2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 |
|
overlay_heat_map
'overlay_heat_map' is a utility function that displays a heat map on an image.
PARAMETER | DESCRIPTION |
---|---|
image |
The image to display the heat map on.
TYPE:
|
heat_map |
A dictionary containing the heat map under the key 'heat_map'.
TYPE:
|
alpha |
The transparency of the overlay. Defaults to 0.8.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: The image with the heat map displayed. |
Example
>>> image_with_heat_map = overlay_heat_map(
image,
{
'heat_map': array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 125, 125, 125]], dtype=uint8),
},
)
Source code in vision_agent/tools/tools.py
vision_agent.tools.tool_utils
ToolCallTrace
send_inference_request
send_inference_request(
payload,
endpoint_name,
files=None,
v2=False,
metadata_payload=None,
is_form=False,
)