Reference for ultralytics/models/yolo/yoloe/predict.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/yolo/yoloe/predict.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.models.yolo.yoloe.predict.YOLOEVPDetectPredictor
Bases: DetectionPredictor
A mixin class for YOLO-EVP (Enhanced Visual Prompting) predictors.
This mixin provides common functionality for YOLO models that use visual prompting, including model setup, prompt handling, and preprocessing transformations.
Attributes:
Name | Type | Description |
---|---|---|
model |
Module
|
The YOLO model for inference. |
device |
device
|
Device to run the model on (CPU or CUDA). |
prompts |
dict
|
Visual prompts containing class indices and bounding boxes or masks. |
Methods:
Name | Description |
---|---|
setup_model |
Initialize the YOLO model and set it to evaluation mode. |
set_return_vpe |
Set whether to return visual prompt embeddings. |
set_prompts |
Set the visual prompts for the model. |
pre_transform |
Preprocess images and prompts before inference. |
inference |
Run inference with visual prompts. |
Source code in ultralytics/engine/predictor.py
get_vpe
Processes the source to get the visual prompt embeddings (VPE).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
str | Path | int | Image | ndarray | Tensor | List | Tuple
|
The source of the image to make predictions on. Accepts various types including file paths, URLs, PIL images, numpy arrays, and torch tensors. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The visual prompt embeddings (VPE) from the model. |
Source code in ultralytics/models/yolo/yoloe/predict.py
inference
Run inference with visual prompts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
im
|
Tensor
|
Input image tensor. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
Model prediction results. |
Source code in ultralytics/models/yolo/yoloe/predict.py
pre_transform
Preprocess images and prompts before inference.
This method applies letterboxing to the input image and transforms the visual prompts (bounding boxes or masks) accordingly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
im
|
list
|
List containing a single input image. |
required |
Returns:
Type | Description |
---|---|
list
|
Preprocessed image ready for model inference. |
Raises:
Type | Description |
---|---|
ValueError
|
If neither valid bounding boxes nor masks are provided in the prompts. |
Source code in ultralytics/models/yolo/yoloe/predict.py
set_prompts
Set the visual prompts for the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompts
|
dict
|
Dictionary containing class indices and bounding boxes or masks. Must include a 'cls' key with class indices. |
required |
Source code in ultralytics/models/yolo/yoloe/predict.py
setup_model
Sets up the model for prediction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Module
|
Model to load or use. |
required |
verbose
|
bool
|
If True, provides detailed logging. |
True
|
Source code in ultralytics/models/yolo/yoloe/predict.py
ultralytics.models.yolo.yoloe.predict.YOLOEVPSegPredictor
Bases: YOLOEVPDetectPredictor
, SegmentationPredictor
Predictor for YOLOE VP segmentation.