Prediction¶
-
class Prediction(annotation_json, source=
None, model_meta=None, name=None, path=None, url=None, project_id=None, dataset_id=None, image_id=None, video_id=None, frame_index=None, api=None, **kwargs)[source]¶ Bases:
objectA single prediction result.
The prediction is primarily represented by
annotation_json(Supervisely annotation format). If you providemodel_meta(aProjectMetaor its JSON), you can access the parsedAnnotationviaannotation.- Parameters:
- annotation_json¶
Prediction in Supervisely annotation JSON format.
- source : str or int, optional¶
Optional source descriptor (path, id, etc.), used as a hint for loading/visualization.
- model_meta=
None¶ Output meta of the model, required to construct an
Annotation.- name : str, optional¶
Optional name for this prediction (used in visualization filenames).
- path : str, optional¶
Local path to the source image/video.
- url : str, optional¶
URL to the source image/video.
- project_id : int, optional¶
Project id associated with the source.
- dataset_id : int, optional¶
Dataset id associated with the source.
- image_id : int, optional¶
Image id associated with the source.
- video_id : int, optional¶
Video id associated with the source (for frame predictions).
- frame_index : int, optional¶
Frame index for video predictions.
- api=
None¶ API client used to download image/frame by id.
Methods
Create
Predictionfrom a JSON dict.Load the source image (or video frame) into a NumPy array.
Serialize prediction to a JSON-compatible dict.
Render prediction on top of the source image/frame.
Attributes
Get the annotation of the prediction.
Get the bounding boxes of the prediction.
Get the class indexes of the prediction.
Get the classes of the prediction.
Get the masks of the prediction.
Get the scores of the prediction.
Get track IDs for each detection.
- classmethod from_json(json_data, **kwargs)[source]¶
Create
Predictionfrom a JSON dict.This helper accepts both styles of keys coming from different backends:
annotation_jsonorannotation.- Parameters:
- Returns:
Prediction instance.
- Return type:
- Raises:
ValueError – If annotation payload is missing.
- load_image()[source]¶
Load the source image (or video frame) into a NumPy array.
The loader uses the first available source in the following order:
path→url→image_id(requiresapior environment config) →video_id+frame_index→ videopath/url+frame_index.- Returns:
Image (or frame) as
H×W×CNumPy array.- Return type:
-
visualize(save_path=
None, save_dir=None, color=None, thickness=None, opacity=0.5, draw_tags=False, fill_rectangles=True)[source]¶ Render prediction on top of the source image/frame.
If
save_path(file or directory) orsave_diris provided, the visualization is saved. Otherwise the rendered image is returned.- Parameters:
- save_path : str, optional¶
Output file path or directory.
- save_dir : str, optional¶
Output directory (alias for directory
save_path).- color : List[int], optional¶
Optional RGB color for drawing.
- thickness : int, optional¶
Optional line thickness.
- opacity : float, optional¶
Bitmap opacity.
If True, draws tags on objects.
- fill_rectangles : bool, optional¶
If True, fills rectangles.
- Returns:
Rendered image.
- Return type:
- property annotation : supervisely.annotation.annotation.Annotation¶
Get the annotation of the prediction.
- property boxes¶
Get the bounding boxes of the prediction.
- property class_idxs : numpy.ndarray¶
Get the class indexes of the prediction.
- property classes¶
Get the classes of the prediction.
- property masks¶
Get the masks of the prediction.
- property scores¶
Get the scores of the prediction.
- property track_ids¶
Get track IDs for each detection. Returns None for detections without tracking.
- Returns:
Track IDs for each detection.
- Return type:
np.ndarray