Prediction¶
sahi.prediction
¶
Prediction classes for object detection results.
Classes¶
ObjectPrediction
¶
Bases: ObjectAnnotation
Class for handling detection model predictions.
Source code in sahi/prediction.py
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 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 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 | |
Functions¶
__init__(bbox=None, category_id=None, category_name=None, segmentation=None, score=0.0, shift_amount=None, full_shape=None)
¶
Initialize ObjectPrediction from bbox, score, category_id, category_name, segmentation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
¶ |
list[float] | None
|
list [minx, miny, maxx, maxy] |
None
|
score
¶ |
float
|
float Prediction score between 0 and 1 |
0.0
|
category_id
¶ |
int | None
|
int ID of the object category |
None
|
category_name
¶ |
str | None
|
str Name of the object category |
None
|
segmentation
¶ |
list[list[float]] | None
|
List[List] [ [x1, y1, x2, y2, x3, y3, ...], [x1, y1, x2, y2, x3, y3, ...], ... ] |
None
|
shift_amount
¶ |
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
|
full_shape
¶ |
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
__repr__()
¶
Return string representation of ObjectPrediction.
get_shifted_object_prediction()
¶
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(image_id=None)
¶
Convert to sahi.utils.coco.CocoPrediction representation.
Source code in sahi/prediction.py
to_fiftyone_detection(image_height, image_width)
¶
Convert to fiftyone.Detection representation.
Source code in sahi/prediction.py
PredictionResult
¶
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.
Source code in sahi/prediction.py
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 226 227 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 | |
Functions¶
__init__(object_prediction_list, image, durations_in_seconds=dict())
¶
Initialize a PredictionResult.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_prediction_list
¶ |
list[ObjectPrediction]
|
list[ObjectPrediction] Detected objects for this image. |
required |
image
¶ |
Image | str | ndarray
|
Image.Image or str or np.ndarray The source image as a PIL Image, file path, or numpy array. |
required |
durations_in_seconds
¶ |
dict[str, Any]
|
dict[str, Any] Elapsed times for profiling (e.g. inference, postprocess). |
dict()
|
Source code in sahi/prediction.py
export_visuals(export_dir, text_size=None, rect_th=None, hide_labels=False, hide_conf=False, file_name='prediction_visual')
¶
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(image_id=None)
¶
Convert predictions to COCO prediction format.
Source code in sahi/prediction.py
to_fiftyone_detections()
¶
Convert predictions to FiftyOne detection format.
Source code in sahi/prediction.py
to_imantics_annotations()
¶
Convert predictions to imantics annotation format.
Source code in sahi/prediction.py
PredictionScore
¶
Wrapper around a numeric prediction confidence score.
Provides comparison operators and conversion from numpy scalars to native Python floats for serialization safety.
Source code in sahi/prediction.py
Functions¶
__eq__(other)
¶
__gt__(other)
¶
__init__(value)
¶
Initialize PredictionScore.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
¶ |
float | ndarray
|
prediction score between 0 and 1. |
required |