Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors in notebooks when running from E2E tests #522

Merged
merged 9 commits into from
Nov 21, 2024
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
7 changes: 7 additions & 0 deletions geti_sdk/demos/demo_projects/coco_demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# and limitations under the License.

import logging
import time
from typing import Optional

from geti_sdk import Geti
Expand Down Expand Up @@ -382,6 +383,12 @@ def ensure_trained_example_project(
number_of_images_to_annotate=45,
enable_auto_train=True,
)
# Should wait for some time for the job to appear as scheduled before checking if
# the project is trained. Auto training is triggered after around 5 seconds.
print(
"Project created. Waiting for training job to be scheduled. This may take a few seconds."
)
time.sleep(5)
else:
raise ValueError(
f"The project named `{project_name}` does not exist on the server at "
Expand Down
4 changes: 3 additions & 1 deletion geti_sdk/demos/demo_projects/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def ensure_project_is_trained(geti: Geti, project: Project) -> bool:
)
# If there are no jobs running for the project, we launch them
jobs = training_client.get_jobs(project_only=True)
running_jobs = [job for job in jobs if job.state == JobState.RUNNING]
running_jobs = [
job for job in jobs if job.state in [JobState.RUNNING, JobState.SCHEDULED]
]
tasks = project.get_trainable_tasks()

new_jobs = []
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
103 changes: 52 additions & 51 deletions notebooks/001_create_project.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "3cb49dd2-7032-40e0-a4c2-8203ba1072bf",
"metadata": {},
"outputs": [],
"source": [
"from geti_sdk.utils import get_server_details_from_env\n",
"\n",
"geti_server_configuration = get_server_details_from_env()"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -34,15 +34,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "ba8318f4-3d97-4949-abf0-6cdafe46572e",
"metadata": {},
"outputs": [],
"source": [
"from geti_sdk import Geti\n",
"\n",
"geti = Geti(server_config=geti_server_configuration)"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -55,17 +55,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "081e700d-9e2e-4022-b4d6-dac3adf1d4f8",
"metadata": {},
"outputs": [],
"source": [
"from geti_sdk.rest_clients import ProjectClient\n",
"\n",
"project_client = ProjectClient(session=geti.session, workspace_id=geti.workspace_id)\n",
"\n",
"projects = project_client.list_projects()"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -89,10 +89,8 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "30e46136-5283-4e3d-8dcf-7a89bee4de6b",
"metadata": {},
"outputs": [],
"source": [
"from geti_sdk.data_models.enums import TaskType\n",
"\n",
Expand All @@ -101,7 +99,9 @@
"for task_type in TaskType:\n",
" if task_type.is_trainable:\n",
" print(\" \" + str(task_type))"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -138,29 +138,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "b18c25d1-f53b-495e-a48e-ee89b7f95d4e",
"metadata": {},
"outputs": [],
"source": [
"# First set the project parameters. Feel free to experiment here!\n",
"PROJECT_NAME = \"Segmentation demo\"\n",
"PROJECT_TYPE = \"segmentation\"\n",
"LABELS = [[\"dog\", \"cat\", \"horse\"]]"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"execution_count": null,
"id": "4941f712-f97b-48ff-a11b-74687d0bb49f",
"metadata": {},
"outputs": [],
"source": [
"# Now, use the project client to create the project\n",
"project = project_client.create_project(\n",
" project_name=PROJECT_NAME, project_type=PROJECT_TYPE, labels=LABELS\n",
")"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -173,13 +173,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "c9d3496b-663d-41d3-b381-5e05b4c8e5b0",
"metadata": {},
"outputs": [],
"source": [
"print(project.summary)"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -191,13 +191,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "8786e8df-3ecb-4947-ad71-c8512e0b22ac",
"metadata": {},
"outputs": [],
"source": [
"print(project.overview)"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -209,16 +209,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "01cb2ee6-9d45-4d17-aa6f-2ac0330ce369",
"metadata": {},
"outputs": [],
"source": [
"task_list = project.get_trainable_tasks()\n",
"print(f\"Project '{project.name}' contains {len(task_list)} trainable tasks.\")\n",
"for task in task_list:\n",
" print(task.summary)"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -230,14 +230,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "71dbcca8-b79e-441d-9143-091c2b08ba35",
"metadata": {},
"outputs": [],
"source": [
"project = project_client.get_project(project_name=PROJECT_NAME)\n",
"print(project.summary)"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -250,10 +250,8 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c20a99c-07b6-4cc2-87fa-abf0ba210031",
"metadata": {},
"outputs": [],
"source": [
"PIPELINE_PROJECT_NAME = \"Detection to hierarchical classification demo\"\n",
"PIPELINE_PROJECT_TYPE = \"detection_to_classification\"\n",
Expand All @@ -270,21 +268,23 @@
" {\"name\": \"school bus\", \"parent_id\": \"bus\", \"group\": \"bus\"},\n",
" ],\n",
"]"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"execution_count": null,
"id": "01d01757-035c-4690-86f0-2f40487a6c52",
"metadata": {},
"outputs": [],
"source": [
"pipeline_project = project_client.create_project(\n",
" project_name=PIPELINE_PROJECT_NAME,\n",
" project_type=PIPELINE_PROJECT_TYPE,\n",
" labels=PIPELINE_LABELS,\n",
")"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -296,13 +296,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "71a5b21f-edf6-4be4-8e86-08db768040f2",
"metadata": {},
"outputs": [],
"source": [
"print(pipeline_project.summary)"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -314,13 +314,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "d23f29b8-056d-476a-a244-5f7355e00743",
"metadata": {},
"outputs": [],
"source": [
"print(pipeline_project.overview)"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -339,15 +339,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "e2a2548a-8f84-4395-bdf7-8a4ebf3447a3",
"metadata": {},
"outputs": [],
"source": [
"# Delete the simple project\n",
"\n",
"# project_client.delete_project(project)"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -361,22 +361,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "ab209bce-5195-4f40-9d40-032af0bb5031",
"metadata": {},
"outputs": [],
"source": [
"# Delete the pipeline project\n",
"project_client.delete_project(pipeline_project, requires_confirmation=False)"
]
"\n",
"# project_client.delete_project(pipeline_project, requires_confirmation=False)"
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "code",
"execution_count": null,
"id": "fa885dd0-b669-4c83-b6b2-bbde010144cd",
"metadata": {},
"source": [],
"outputs": [],
"source": []
"execution_count": null
}
],
"metadata": {
Expand Down
Loading
Loading