Skip to content

Commit 0b760a0

Browse files
authored
Merge pull request #522 from openvinotoolkit/daan/v2.5.0-backport-fixes
Fix errors in notebooks when running from E2E tests
2 parents ff367a2 + 1a7043d commit 0b760a0

19 files changed

+561
-539
lines changed

examples/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ This code sample shows how to get a deployment from the server.
138138
> geti = Geti(server_config=server_config)
139139
>
140140
> # Create deployment for the project, and prepare it for running inference
141-
> deployment = geti.deploy_project(PROJECT_NAME)
141+
> deployment = geti.deploy_project(project_name=PROJECT_NAME)
142142
>
143143
> # Save deployment on local
144144
> deployment.save(PATH_TO_DEPLOYMENT)

geti_sdk/demos/demo_projects/coco_demos.py

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# and limitations under the License.
1414

1515
import logging
16+
import time
1617
from typing import Optional
1718

1819
from geti_sdk import Geti
@@ -382,6 +383,12 @@ def ensure_trained_example_project(
382383
number_of_images_to_annotate=45,
383384
enable_auto_train=True,
384385
)
386+
# Should wait for some time for the job to appear as scheduled before checking if
387+
# the project is trained. Auto training is triggered after around 5 seconds.
388+
print(
389+
"Project created. Waiting for training job to be scheduled. This may take a few seconds."
390+
)
391+
time.sleep(5)
385392
else:
386393
raise ValueError(
387394
f"The project named `{project_name}` does not exist on the server at "

geti_sdk/demos/demo_projects/utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ def ensure_project_is_trained(geti: Geti, project: Project) -> bool:
5151
)
5252
# If there are no jobs running for the project, we launch them
5353
jobs = training_client.get_jobs(project_only=True)
54-
running_jobs = [job for job in jobs if job.state == JobState.RUNNING]
54+
running_jobs = [
55+
job for job in jobs if job.state in [JobState.RUNNING, JobState.SCHEDULED]
56+
]
5557
tasks = project.get_trainable_tasks()
5658

5759
new_jobs = []

geti_sdk/geti.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def download_project_data(
371371
# Download deployment
372372
if include_deployment:
373373
logging.info("Creating deployment for project...")
374-
self.deploy_project(project, output_folder=target_folder)
374+
self.deploy_project(project=project, output_folder=target_folder)
375375

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

11331133
def deploy_project(
11341134
self,
1135-
project: Project,
1135+
project: Optional[Project] = None,
1136+
project_name: Optional[str] = None,
11361137
output_folder: Optional[Union[str, os.PathLike]] = None,
11371138
models: Optional[Sequence[BaseModel]] = None,
11381139
enable_explainable_ai: bool = False,
@@ -1147,7 +1148,10 @@ def deploy_project(
11471148
for each task in the project. However, it is possible to specify a particular
11481149
model to use, by passing it in the list of `models` as input to this method.
11491150
1150-
:param project: Project object to deploy
1151+
:param project: Project object to deploy. Either `project` or `project_name`
1152+
must be specified.
1153+
:param project_name: Name of the project to deploy. Either `project` or
1154+
`project_name` must be specified.
11511155
:param output_folder: Path to a folder on local disk to which the Deployment
11521156
should be downloaded. If no path is specified, the deployment will not be
11531157
saved.
@@ -1165,6 +1169,11 @@ def deploy_project(
11651169
launch an OVMS container serving the models.
11661170
:return: Deployment for the project
11671171
"""
1172+
if project is None and project_name is None:
1173+
raise ValueError("Either `project` or `project_name` must be specified.")
1174+
if project is None:
1175+
project = self.project_client.get_project_by_name(project_name=project_name)
1176+
11681177
deployment_client = self._deployment_clients.get(project.id, None)
11691178
if deployment_client is None:
11701179
# Create deployment client and add to cache.

notebooks/001_create_project.ipynb

+52-51
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": null,
1817
"id": "3cb49dd2-7032-40e0-a4c2-8203ba1072bf",
1918
"metadata": {},
20-
"outputs": [],
2119
"source": [
2220
"from geti_sdk.utils import get_server_details_from_env\n",
2321
"\n",
2422
"geti_server_configuration = get_server_details_from_env()"
25-
]
23+
],
24+
"outputs": [],
25+
"execution_count": null
2626
},
2727
{
2828
"cell_type": "markdown",
@@ -34,15 +34,15 @@
3434
},
3535
{
3636
"cell_type": "code",
37-
"execution_count": null,
3837
"id": "ba8318f4-3d97-4949-abf0-6cdafe46572e",
3938
"metadata": {},
40-
"outputs": [],
4139
"source": [
4240
"from geti_sdk import Geti\n",
4341
"\n",
4442
"geti = Geti(server_config=geti_server_configuration)"
45-
]
43+
],
44+
"outputs": [],
45+
"execution_count": null
4646
},
4747
{
4848
"cell_type": "markdown",
@@ -55,17 +55,17 @@
5555
},
5656
{
5757
"cell_type": "code",
58-
"execution_count": null,
5958
"id": "081e700d-9e2e-4022-b4d6-dac3adf1d4f8",
6059
"metadata": {},
61-
"outputs": [],
6260
"source": [
6361
"from geti_sdk.rest_clients import ProjectClient\n",
6462
"\n",
6563
"project_client = ProjectClient(session=geti.session, workspace_id=geti.workspace_id)\n",
6664
"\n",
6765
"projects = project_client.list_projects()"
68-
]
66+
],
67+
"outputs": [],
68+
"execution_count": null
6969
},
7070
{
7171
"cell_type": "markdown",
@@ -89,10 +89,8 @@
8989
},
9090
{
9191
"cell_type": "code",
92-
"execution_count": null,
9392
"id": "30e46136-5283-4e3d-8dcf-7a89bee4de6b",
9493
"metadata": {},
95-
"outputs": [],
9694
"source": [
9795
"from geti_sdk.data_models.enums import TaskType\n",
9896
"\n",
@@ -101,7 +99,9 @@
10199
"for task_type in TaskType:\n",
102100
" if task_type.is_trainable:\n",
103101
" print(\" \" + str(task_type))"
104-
]
102+
],
103+
"outputs": [],
104+
"execution_count": null
105105
},
106106
{
107107
"cell_type": "markdown",
@@ -138,29 +138,29 @@
138138
},
139139
{
140140
"cell_type": "code",
141-
"execution_count": null,
142141
"id": "b18c25d1-f53b-495e-a48e-ee89b7f95d4e",
143142
"metadata": {},
144-
"outputs": [],
145143
"source": [
146144
"# First set the project parameters. Feel free to experiment here!\n",
147145
"PROJECT_NAME = \"Segmentation demo\"\n",
148146
"PROJECT_TYPE = \"segmentation\"\n",
149147
"LABELS = [[\"dog\", \"cat\", \"horse\"]]"
150-
]
148+
],
149+
"outputs": [],
150+
"execution_count": null
151151
},
152152
{
153153
"cell_type": "code",
154-
"execution_count": null,
155154
"id": "4941f712-f97b-48ff-a11b-74687d0bb49f",
156155
"metadata": {},
157-
"outputs": [],
158156
"source": [
159157
"# Now, use the project client to create the project\n",
160158
"project = project_client.create_project(\n",
161159
" project_name=PROJECT_NAME, project_type=PROJECT_TYPE, labels=LABELS\n",
162160
")"
163-
]
161+
],
162+
"outputs": [],
163+
"execution_count": null
164164
},
165165
{
166166
"cell_type": "markdown",
@@ -173,13 +173,13 @@
173173
},
174174
{
175175
"cell_type": "code",
176-
"execution_count": null,
177176
"id": "c9d3496b-663d-41d3-b381-5e05b4c8e5b0",
178177
"metadata": {},
179-
"outputs": [],
180178
"source": [
181179
"print(project.summary)"
182-
]
180+
],
181+
"outputs": [],
182+
"execution_count": null
183183
},
184184
{
185185
"cell_type": "markdown",
@@ -191,13 +191,13 @@
191191
},
192192
{
193193
"cell_type": "code",
194-
"execution_count": null,
195194
"id": "8786e8df-3ecb-4947-ad71-c8512e0b22ac",
196195
"metadata": {},
197-
"outputs": [],
198196
"source": [
199197
"print(project.overview)"
200-
]
198+
],
199+
"outputs": [],
200+
"execution_count": null
201201
},
202202
{
203203
"cell_type": "markdown",
@@ -209,16 +209,16 @@
209209
},
210210
{
211211
"cell_type": "code",
212-
"execution_count": null,
213212
"id": "01cb2ee6-9d45-4d17-aa6f-2ac0330ce369",
214213
"metadata": {},
215-
"outputs": [],
216214
"source": [
217215
"task_list = project.get_trainable_tasks()\n",
218216
"print(f\"Project '{project.name}' contains {len(task_list)} trainable tasks.\")\n",
219217
"for task in task_list:\n",
220218
" print(task.summary)"
221-
]
219+
],
220+
"outputs": [],
221+
"execution_count": null
222222
},
223223
{
224224
"cell_type": "markdown",
@@ -230,14 +230,14 @@
230230
},
231231
{
232232
"cell_type": "code",
233-
"execution_count": null,
234233
"id": "71dbcca8-b79e-441d-9143-091c2b08ba35",
235234
"metadata": {},
236-
"outputs": [],
237235
"source": [
238236
"project = project_client.get_project(project_name=PROJECT_NAME)\n",
239237
"print(project.summary)"
240-
]
238+
],
239+
"outputs": [],
240+
"execution_count": null
241241
},
242242
{
243243
"cell_type": "markdown",
@@ -250,10 +250,8 @@
250250
},
251251
{
252252
"cell_type": "code",
253-
"execution_count": null,
254253
"id": "9c20a99c-07b6-4cc2-87fa-abf0ba210031",
255254
"metadata": {},
256-
"outputs": [],
257255
"source": [
258256
"PIPELINE_PROJECT_NAME = \"Detection to hierarchical classification demo\"\n",
259257
"PIPELINE_PROJECT_TYPE = \"detection_to_classification\"\n",
@@ -270,21 +268,23 @@
270268
" {\"name\": \"school bus\", \"parent_id\": \"bus\", \"group\": \"bus\"},\n",
271269
" ],\n",
272270
"]"
273-
]
271+
],
272+
"outputs": [],
273+
"execution_count": null
274274
},
275275
{
276276
"cell_type": "code",
277-
"execution_count": null,
278277
"id": "01d01757-035c-4690-86f0-2f40487a6c52",
279278
"metadata": {},
280-
"outputs": [],
281279
"source": [
282280
"pipeline_project = project_client.create_project(\n",
283281
" project_name=PIPELINE_PROJECT_NAME,\n",
284282
" project_type=PIPELINE_PROJECT_TYPE,\n",
285283
" labels=PIPELINE_LABELS,\n",
286284
")"
287-
]
285+
],
286+
"outputs": [],
287+
"execution_count": null
288288
},
289289
{
290290
"cell_type": "markdown",
@@ -296,13 +296,13 @@
296296
},
297297
{
298298
"cell_type": "code",
299-
"execution_count": null,
300299
"id": "71a5b21f-edf6-4be4-8e86-08db768040f2",
301300
"metadata": {},
302-
"outputs": [],
303301
"source": [
304302
"print(pipeline_project.summary)"
305-
]
303+
],
304+
"outputs": [],
305+
"execution_count": null
306306
},
307307
{
308308
"cell_type": "markdown",
@@ -314,13 +314,13 @@
314314
},
315315
{
316316
"cell_type": "code",
317-
"execution_count": null,
318317
"id": "d23f29b8-056d-476a-a244-5f7355e00743",
319318
"metadata": {},
320-
"outputs": [],
321319
"source": [
322320
"print(pipeline_project.overview)"
323-
]
321+
],
322+
"outputs": [],
323+
"execution_count": null
324324
},
325325
{
326326
"cell_type": "markdown",
@@ -339,15 +339,15 @@
339339
},
340340
{
341341
"cell_type": "code",
342-
"execution_count": null,
343342
"id": "e2a2548a-8f84-4395-bdf7-8a4ebf3447a3",
344343
"metadata": {},
345-
"outputs": [],
346344
"source": [
347345
"# Delete the simple project\n",
348346
"\n",
349347
"# project_client.delete_project(project)"
350-
]
348+
],
349+
"outputs": [],
350+
"execution_count": null
351351
},
352352
{
353353
"cell_type": "markdown",
@@ -361,22 +361,23 @@
361361
},
362362
{
363363
"cell_type": "code",
364-
"execution_count": null,
365364
"id": "ab209bce-5195-4f40-9d40-032af0bb5031",
366365
"metadata": {},
367-
"outputs": [],
368366
"source": [
369367
"# Delete the pipeline project\n",
370-
"project_client.delete_project(pipeline_project, requires_confirmation=False)"
371-
]
368+
"\n",
369+
"# project_client.delete_project(pipeline_project, requires_confirmation=False)"
370+
],
371+
"outputs": [],
372+
"execution_count": null
372373
},
373374
{
374375
"cell_type": "code",
375-
"execution_count": null,
376376
"id": "fa885dd0-b669-4c83-b6b2-bbde010144cd",
377377
"metadata": {},
378+
"source": [],
378379
"outputs": [],
379-
"source": []
380+
"execution_count": null
380381
}
381382
],
382383
"metadata": {

0 commit comments

Comments
 (0)