Skip to content

Commit

Permalink
Merge pull request #516 from openvinotoolkit/daan/CVS-156929-deployme…
Browse files Browse the repository at this point in the history
…nt-client-error

Project deployment by name
  • Loading branch information
Daankrol authored Nov 20, 2024
2 parents ff367a2 + 3cdfe82 commit d700c89
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ This code sample shows how to get a deployment from the server.
> geti = Geti(server_config=server_config)
>
> # Create deployment for the project, and prepare it for running inference
> deployment = geti.deploy_project(PROJECT_NAME)
> deployment = geti.deploy_project(project_name=PROJECT_NAME)
>
> # Save deployment on local
> deployment.save(PATH_TO_DEPLOYMENT)
Expand Down
15 changes: 12 additions & 3 deletions geti_sdk/geti.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def download_project_data(
# Download deployment
if include_deployment:
logging.info("Creating deployment for project...")
self.deploy_project(project, output_folder=target_folder)
self.deploy_project(project=project, output_folder=target_folder)

logging.info(f"Project '{project.name}' was downloaded successfully.")
return project
Expand Down Expand Up @@ -1132,7 +1132,8 @@ def upload_and_predict_video(

def deploy_project(
self,
project: Project,
project: Optional[Project] = None,
project_name: Optional[str] = None,
output_folder: Optional[Union[str, os.PathLike]] = None,
models: Optional[Sequence[BaseModel]] = None,
enable_explainable_ai: bool = False,
Expand All @@ -1147,7 +1148,10 @@ def deploy_project(
for each task in the project. However, it is possible to specify a particular
model to use, by passing it in the list of `models` as input to this method.
:param project: Project object to deploy
:param project: Project object to deploy. Either `project` or `project_name`
must be specified.
:param project_name: Name of the project to deploy. Either `project` or
`project_name` must be specified.
:param output_folder: Path to a folder on local disk to which the Deployment
should be downloaded. If no path is specified, the deployment will not be
saved.
Expand All @@ -1165,6 +1169,11 @@ def deploy_project(
launch an OVMS container serving the models.
:return: Deployment for the project
"""
if project is None and project_name is None:
raise ValueError("Either `project` or `project_name` must be specified.")
if project is None:
project = self.project_client.get_project_by_name(project_name=project_name)

deployment_client = self._deployment_clients.get(project.id, None)
if deployment_client is None:
# Create deployment client and add to cache.
Expand Down
4 changes: 2 additions & 2 deletions notebooks/012_post_inference_hooks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"metadata": {},
"outputs": [],
"source": [
"deployment = geti.deploy_project(PROJECT_NAME)"
"deployment = geti.deploy_project(project=project)"
]
},
{
Expand Down Expand Up @@ -101,8 +101,8 @@
"source": [
"import cv2\n",
"\n",
"from geti_sdk.demos import EXAMPLE_IMAGE_PATH\n",
"from geti_sdk import Visualizer\n",
"from geti_sdk.demos import EXAMPLE_IMAGE_PATH\n",
"\n",
"numpy_image = cv2.imread(EXAMPLE_IMAGE_PATH)\n",
"numpy_rgb = cv2.cvtColor(numpy_image, cv2.COLOR_BGR2RGB)\n",
Expand Down
4 changes: 3 additions & 1 deletion notebooks/014_asynchronous_inference.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@
"source": [
"DEPLOYMENT_FOLDER = \"deployments\"\n",
"\n",
"deployment = geti.deploy_project(PROJECT_NAME, output_folder=DEPLOYMENT_FOLDER)"
"deployment = geti.deploy_project(\n",
" project_name=PROJECT_NAME, output_folder=DEPLOYMENT_FOLDER\n",
")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion tests/nightly/test_nightly_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_deployment(

deployment_folder = os.path.join(fxt_temp_directory, project.name)
deployment = fxt_geti_no_vcr.deploy_project(
project,
project=project,
output_folder=deployment_folder,
enable_explainable_ai=True,
)
Expand Down
4 changes: 2 additions & 2 deletions tests/pre-merge/integration/test_geti.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def test_deployment(
for _ in range(n_attempts):
try:
deployment = fxt_geti.deploy_project(
project,
project=project,
output_folder=deployment_folder,
enable_explainable_ai=True,
)
Expand Down Expand Up @@ -576,7 +576,7 @@ def test_post_inference_hooks(
project = fxt_project_service.project
deployment_folder = os.path.join(fxt_temp_directory, project.name)

deployment = fxt_geti.deploy_project(project)
deployment = fxt_geti.deploy_project(project=project)
dataset_name = "Test hooks"

# Add a GetiDataCollectionHook
Expand Down

0 comments on commit d700c89

Please sign in to comment.