NeuralNetworkApi

class NeuralNetworkApi[source]

Bases: object

API to interact with neural networks in Supervisely. It provides methods to deploy and connect to models for running inference.

Methods

connect

Connect to a running Serving App by its task_id.

deploy

Deploy a pretrained model or a custom model checkpoint in Supervisely platform.

get_experiment_info

Returns the experiment info of a finished training task by its task_id.

list_deployed_models

Returns a list of deployed models in the Supervisely platform.

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.

Parameters
task_id : int

the task_id of a running Serving App session in the Supervisely platform.

Returns

a ModelAPI object

Return type

ModelAPI

deploy(model, device=None, runtime=None, workspace_id=None, agent_id=None, **kwargs)[source]

Deploy a pretrained model or a custom model checkpoint in Supervisely platform. This method will start a new Serving App in Supervisely, deploy a given model, and return a ModelAPI object for running predictions and managing the model. - To deploy a pretrained model, pass the model name in the format framework/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

A ModelAPI object for the deployed model.

Return type

ModelAPI

Usage example
import supervisely as sly

api = sly.Api()
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.

Parameters
task_id : int

the task_id of a finished training task in the Supervisely platform.

Returns

an ExperimentInfo object with information about the training, model, and results.

Return type

ExperimentInfo

list_deployed_models(model=None, framework=None, task_type=None, team_id=None, workspace_id=None)[source]

Returns a list of deployed models in the Supervisely platform. 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 supervisely as sly

api = sly.Api()
deployed_models = api.nn.list_deployed_models(framework="RT-DETRv2")