NeuralNetworkApi¶
- class NeuralNetworkApi(api)[source]¶
Bases:
objectAPI to interact with neural networks in Supervisely. It provides methods to deploy and connect to models for running inference.
Methods
Connect to a running Serving App by its
task_id.Deploy a pretrained model or a custom model checkpoint on the Supervisely instance.
Returns the experiment info of a finished training task by its task_id.
Returns a list of deployed models on the Supervisely instance.
- connect(task_id)[source]¶
Connect to a running Serving App by its
task_id.This allows you to make predictions and control the model state via API.
-
deploy(model, device=
None, runtime=None, workspace_id=None, agent_id=None, **kwargs)[source]¶ Deploy a pretrained model or a custom model checkpoint on the Supervisely instance. This method will start a new Serving App in Supervisely, deploy a given model, and return a
ModelAPIobject for running predictions and managing the model. - To deploy a pretrained model, pass the model name in the formatframework/model_name(e.g., “RT-DETRv2/RT-DETRv2-M”). - To deploy a custom model, pass the path to the model checkpoint in team files (e.g., “/experiments/1089_RT-DETRv2/checkpoints/best.pt”).- Parameters:
- model : str¶
Either a path to a model checkpoint in team files or model name in format
framework/model_name(e.g., “RT-DETRv2/RT-DETRv2-M”).- device : Optional[str]¶
Device to run the model on (e.g., “cuda:0” or “cpu”). If not specified, will automatically use GPU device if available, otherwise CPU will be used.
- runtime : Optional[str]¶
If specified, the model will be converted to the given format (e.g., “onnx”, “tensorrt”) and will be deployed in the corresponding accelerated runtime. This option is used for pretrained models. For custom models, the runtime will be defined automatically based on the model checkpoint.
- workspace_id : Optional[int]¶
Workspace ID, if None, will be got from env.
- agent_id : Optional[int]¶
Agent ID, if not present will be defined automatically.
- **kwargs¶
Additional parameters for deployment.
- Returns:
ModelAPI object for the deployed model.
- Return type:
- Usage Example:
import supervisely as sly import os from dotenv import load_dotenv import supervisely as sly # 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() model = api.nn.deploy(model="RT-DETRv2/RT-DETRv2-M")
- get_experiment_info(task_id)[source]¶
Returns the experiment info of a finished training task by its task_id.
-
list_deployed_models(model=
None, framework=None, task_type=None, team_id=None, workspace_id=None)[source]¶ Returns a list of deployed models on the Supervisely instance. The list can be filtered by model name, framework, task type, team ID, and workspace ID.
- Parameters:
- model : Optional[str]¶
Model name or checkpoint path to filter the results. If None, all models will be returned.
- framework : Optional[str]¶
Framework name to filter the results. If None, all frameworks will be returned.
- task_type : Optional[str]¶
CV Task to filter the results, e.g., “object detection”, “instance segmentation”, etc. If None, all task types will be returned.
- team_id : Optional[int]¶
Team ID to filter the results. If None, the team ID from the environment will be used.
- workspace_id : Optional[int]¶
Workspace ID to filter the results. If None, the workspace ID from the environment will be used.
- Returns:
A list of dictionaries containing information about the deployed models.
- Return type:
List[Dict]
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # 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() deployed_models = api.nn.list_deployed_models(framework="RT-DETRv2")