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
YOLOEVPDetectPredictor(
cfg=DEFAULT_CFG,
overrides: Optional[Dict[str, Any]] = None,
_callbacks: Optional[Dict[str, List[callable]]] = None,
)
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 | Tensor
|
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_prompts |
Set the visual prompts for the model. |
pre_transform |
Preprocess images and prompts before inference. |
inference |
Run inference with visual prompts. |
get_vpe |
Process source to get visual prompt embeddings. |
Source code in ultralytics/engine/predictor.py
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 |
|
get_vpe
get_vpe(source)
Process 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
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
inference
inference(im, *args, **kwargs)
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
133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
pre_transform
pre_transform(im)
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
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
set_prompts
set_prompts(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
42 43 44 45 46 47 48 49 50 |
|
setup_model
setup_model(model, verbose: bool = True)
Set 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
31 32 33 34 35 36 37 38 39 40 |
|
ultralytics.models.yolo.yoloe.predict.YOLOEVPSegPredictor
YOLOEVPSegPredictor(cfg=DEFAULT_CFG, overrides=None, _callbacks=None)
Bases: YOLOEVPDetectPredictor
, SegmentationPredictor
Predictor for YOLO-EVP segmentation tasks combining detection and segmentation capabilities.
Source code in ultralytics/models/yolo/segment/predict.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|