PredictionSession¶
-
class PredictionSession(url, input=
None, image_id=None, video_id=None, dataset_id=None, project_id=None, api=None, tracking=None, tracking_config=None, **kwargs)[source]¶ Bases:
objectAsynchronous inference session that yields
Prediction.The session starts inference immediately during construction and becomes an iterator. Use it directly when you need streaming results or progress control, or use higher-level helpers like
predict_detached()method.Exactly one of the following inputs must be provided:
input,image_id,video_id,dataset_id,project_id(or their plural forms inkwargs:image_idsetc.).- Parameters:
- url : str¶
Deployment base URL (e.g.
https://.../net/<sessionToken>).- input : numpy.ndarray or str or PathLike or list, optional¶
Local input (NumPy image, image/video path, directory, or list of them).
- image_id : int or List[int], optional¶
Image id (or list in
image_idskwarg).- video_id : int or List[int], optional¶
Video id (single video supported).
- dataset_id : int or List[int], optional¶
Dataset id(s). Requires
apito resolve datasets/projects.- project_id : int or List[int], optional¶
Project id (single project supported).
- api=
None¶ API client used for downloading by id / resolving datasets/projects.
- tracking : bool, optional¶
Enable video tracking (if supported by deployment).
- tracking_config : dict, optional¶
Tracking configuration dict (may include
trackerkey).- kwargs : dict¶
Additional inference settings (confidence, classes, batch size, etc.).
- Raises:
AssertionError – If more than one input source is provided.
ValueError – For unsupported inputs or invalid combinations.
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly from supervisely.nn.model.prediction_session import PredictionSession # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() session = PredictionSession( url='https://app.supervisely.com/net/<sessionToken>', image_id=123, api=api, conf=0.25, ) for pred in session: _ = pred.boxes _ = pred.scores
Methods
Check whether server-side inference is finished.
nextReturn numeric progress of the current inference request.
Return raw status JSON for the current inference request.
Stop the current inference request on the server (if running).
Attributes
Lazily fetch output
ProjectMetafrom the deployment.-
class Iterator(total, session, tqdm=
None)[source]¶ Bases:
objectInternal iterator that fetches pending results in chunks.
- is_done()[source]¶
Check whether server-side inference is finished.
- Returns:
True if finished.
- Return type:
- Raises:
RuntimeError – If inference has not been started yet.
- progress()[source]¶
Return numeric progress of the current inference request.
- Returns:
Progress value as returned by the backend.
- Return type:
Any
- Raises:
RuntimeError – If inference has not been started yet.
- status()[source]¶
Return raw status JSON for the current inference request.
- Returns:
Status dict.
- Return type:
- Raises:
RuntimeError – If inference has not been started yet.
- stop()[source]¶
Stop the current inference request on the server (if running).
Also tries to fetch final result metadata and clears the server-side request state.
- property model_meta : supervisely.project.project_meta.ProjectMeta¶
Lazily fetch output
ProjectMetafrom the deployment.- Returns:
Model meta.
- Return type: