Reference for ultralytics/models/fastsam/predict.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/fastsam/predict.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.models.fastsam.predict.FastSAMPredictor
Bases: DetectionPredictor
FastSAMPredictor is specialized for fast SAM (Segment Anything Model) segmentation prediction tasks in Ultralytics YOLO framework.
This class extends the DetectionPredictor, customizing the prediction pipeline specifically for fast SAM. It adjusts post-processing steps to incorporate mask prediction and non-max suppression while optimizing for single-class segmentation.
Attributes:
Name | Type | Description |
---|---|---|
cfg |
dict
|
Configuration parameters for prediction. |
overrides |
dict
|
Optional parameter overrides for custom behavior. |
_callbacks |
dict
|
Optional list of callback functions to be invoked during prediction. |
Source code in ultralytics/models/fastsam/predict.py
__init__(cfg=DEFAULT_CFG, overrides=None, _callbacks=None)
Initializes the FastSAMPredictor class, inheriting from DetectionPredictor and setting the task to 'segment'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg |
dict
|
Configuration parameters for prediction. |
DEFAULT_CFG
|
overrides |
dict
|
Optional parameter overrides for custom behavior. |
None
|
_callbacks |
dict
|
Optional list of callback functions to be invoked during prediction. |
None
|
Source code in ultralytics/models/fastsam/predict.py
postprocess(preds, img, orig_imgs)
Perform post-processing steps on predictions, including non-max suppression and scaling boxes to original image size, and returns the final results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
preds |
list
|
The raw output predictions from the model. |
required |
img |
Tensor
|
The processed image tensor. |
required |
orig_imgs |
list | Tensor
|
The original image or list of images. |
required |
Returns:
Type | Description |
---|---|
list
|
A list of Results objects, each containing processed boxes, masks, and other metadata. |