Prediction¶
sahi.prediction
¶
Prediction classes for object detection results.
Classes¶
PredictionScore
¶
PredictionScore(value: float | ndarray)
Wrapper around a numeric prediction confidence score.
Provides comparison operators and conversion from numpy scalars to native Python floats for serialization safety.
Initialize PredictionScore.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
float | ndarray
|
prediction score between 0 and 1. |
required |
Source code in sahi/prediction.py
ObjectPrediction
¶
ObjectPrediction(
bbox: list[float] | None = None,
category_id: int | None = None,
category_name: str | None = None,
segmentation: list[list[float]] | None = None,
score: float = 0.0,
shift_amount: list[int]
| list[int | float]
| None = None,
full_shape: list[int] | list[int | float] | None = None,
)
Bases: ObjectAnnotation
Class for handling detection model predictions.
Initialize ObjectPrediction from bbox, score, category_id, category_name, segmentation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[float] | None
|
list [minx, miny, maxx, maxy] |
None
|
|
float
|
float Prediction score between 0 and 1 |
0.0
|
|
int | None
|
int ID of the object category |
None
|
|
str | None
|
str Name of the object category |
None
|
|
list[list[float]] | None
|
List[List] [ [x1, y1, x2, y2, x3, y3, ...], [x1, y1, x2, y2, x3, y3, ...], ... ] |
None
|
|
list[int] | list[int | float] | None
|
list To shift the box and mask predictions from sliced image to full sized image, should be in the form of [shift_x, shift_y] |
None
|
|
list[int] | list[int | float] | None
|
list Size of the full image after shifting, should be in the form of [height, width] |
None
|
Source code in sahi/prediction.py
Methods:¶
get_shifted_object_prediction
¶
get_shifted_object_prediction() -> ObjectPrediction
Get shifted version of ObjectPrediction.
Shifts bbox and mask coords. Used for mapping sliced predictions over full image.
Source code in sahi/prediction.py
to_coco_prediction
¶
to_coco_prediction(
image_id: int | None = None,
) -> CocoPrediction
Convert to sahi.utils.coco.CocoPrediction representation.
Source code in sahi/prediction.py
to_fiftyone_detection
¶
Convert to fiftyone.Detection representation.
Source code in sahi/prediction.py
PredictionResult
¶
PredictionResult(
object_prediction_list: list[ObjectPrediction],
image: Image | str | ndarray,
durations_in_seconds: dict[str, Any] = dict(),
)
Container for detection results on a single image.
Holds the list of ObjectPrediction instances together with the
source image and optional profiling durations. Provides helpers for
exporting results to COCO, FiftyOne, and visual formats.
Initialize a PredictionResult.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[ObjectPrediction]
|
list[ObjectPrediction] Detected objects for this image. |
required |
|
Image | str | ndarray
|
Image.Image or str or np.ndarray The source image as a PIL Image, file path, or numpy array. |
required |
|
dict[str, Any]
|
dict[str, Any] Elapsed times for profiling (e.g. inference, postprocess). |
dict()
|
Source code in sahi/prediction.py
Attributes¶
Methods:¶
export_visuals
¶
export_visuals(
export_dir: str,
text_size: float | None = None,
rect_th: int | None = None,
hide_labels: bool = False,
hide_conf: bool = False,
file_name: str = "prediction_visual",
) -> None
Export prediction visualizations to directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
export_dir
¶ |
str
|
directory for resulting visualization to be exported. |
required |
text_size
¶ |
float | None
|
size of the category name over box. |
None
|
rect_th
¶ |
int | None
|
rectangle thickness. |
None
|
hide_labels
¶ |
bool
|
hide labels. |
False
|
hide_conf
¶ |
bool
|
hide confidence. |
False
|
file_name
¶ |
str
|
saving name. |
'prediction_visual'
|
Source code in sahi/prediction.py
to_coco_annotations
¶
Convert predictions to COCO annotation format.
Source code in sahi/prediction.py
to_coco_predictions
¶
Convert predictions to COCO prediction format.
Source code in sahi/prediction.py
to_imantics_annotations
¶
Convert predictions to imantics annotation format.
Source code in sahi/prediction.py
to_fiftyone_detections
¶
Convert predictions to FiftyOne detection format.