Skip to content

Commit aded075

Browse files
author
gdj0nes
committed
CHG: minimize diff
1 parent a0075db commit aded075

26 files changed

+753
-4176
lines changed

examples/annotation_types/basics.ipynb

Lines changed: 94 additions & 517 deletions
Large diffs are not rendered by default.

examples/annotation_types/converters.ipynb

Lines changed: 26 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -46,73 +46,35 @@
4646
},
4747
{
4848
"cell_type": "code",
49-
"execution_count": null,
49+
"execution_count": 1,
5050
"id": "improving-demonstration",
5151
"metadata": {},
5252
"outputs": [],
53-
"source": [
54-
"!pip install \"labelbox[data]\""
55-
]
53+
"source": "!pip install \"labelbox[data]\""
5654
},
5755
{
5856
"cell_type": "code",
59-
"execution_count": 1,
57+
"execution_count": 2,
6058
"id": "acute-serve",
6159
"metadata": {},
6260
"outputs": [],
63-
"source": [
64-
"from labelbox.data.annotation_types import (\n",
65-
" LabelList, \n",
66-
" Label, \n",
67-
" Rectangle, \n",
68-
" Point, \n",
69-
" ObjectAnnotation, \n",
70-
" Geometry\n",
71-
")\n",
72-
"from labelbox.data.serialization import LBV1Converter, NDJsonConverter\n",
73-
"from labelbox import Client\n",
74-
"\n",
75-
"import IPython\n",
76-
"import numpy as np\n",
77-
"from PIL import Image\n",
78-
"from getpass import getpass\n",
79-
"import os\n",
80-
"import cv2"
81-
]
61+
"source": "from labelbox.data.annotation_types import (LabelList, Label, Rectangle, Point,\n ObjectAnnotation, Geometry)\nfrom labelbox.data.serialization import LBV1Converter, NDJsonConverter\nfrom labelbox import Client\n\nimport IPython\nimport numpy as np\nfrom PIL import Image\nfrom getpass import getpass\nimport os\nimport cv2"
8262
},
8363
{
8464
"cell_type": "code",
85-
"execution_count": 2,
65+
"execution_count": 3,
8666
"id": "psychological-airfare",
8767
"metadata": {},
8868
"outputs": [],
89-
"source": [
90-
"# If you don't want to give google access to drive you can skip this cell\n",
91-
"# and manually set `API_KEY` below.\n",
92-
"COLAB = \"google.colab\" in str(get_ipython())\n",
93-
"if COLAB:\n",
94-
" !pip install colab-env -qU\n",
95-
" from colab_env import envvar_handler\n",
96-
" envvar_handler.envload()\n",
97-
"\n",
98-
"API_KEY = os.environ.get(\"LABELBOX_API_KEY\")\n",
99-
"if not os.environ.get(\"LABELBOX_API_KEY\"):\n",
100-
" API_KEY = getpass(\"Please enter your labelbox api key\")\n",
101-
" if COLAB:\n",
102-
" envvar_handler.add_env(\"LABELBOX_API_KEY\", API_KEY)"
103-
]
69+
"source": "# If you don't want to give google access to drive you can skip this cell\n# and manually set `API_KEY` below.\nCOLAB = \"google.colab\" in str(get_ipython())\nif COLAB:\n !pip install colab-env -qU\n from colab_env import envvar_handler\n envvar_handler.envload()\n\nAPI_KEY = os.environ.get(\"LABELBOX_API_KEY\")\nif not os.environ.get(\"LABELBOX_API_KEY\"):\n API_KEY = getpass(\"Please enter your labelbox api key\")\n if COLAB:\n envvar_handler.add_env(\"LABELBOX_API_KEY\", API_KEY)"
10470
},
10571
{
10672
"cell_type": "code",
107-
"execution_count": 3,
73+
"execution_count": 4,
10874
"id": "adult-fleet",
10975
"metadata": {},
11076
"outputs": [],
111-
"source": [
112-
"# Only update this if you have an on-prem deployment\n",
113-
"ENDPOINT = \"https://api.labelbox.com/graphql\"\n",
114-
"client = Client(api_key=API_KEY, endpoint=ENDPOINT)"
115-
]
77+
"source": "# Only update this if you have an on-prem deployment\nENDPOINT = \"https://api.labelbox.com/graphql\"\nclient = Client(api_key=API_KEY, endpoint=ENDPOINT)"
11678
},
11779
{
11880
"cell_type": "markdown",
@@ -136,7 +98,7 @@
13698
},
13799
{
138100
"cell_type": "code",
139-
"execution_count": 4,
101+
"execution_count": 5,
140102
"id": "electronic-heart",
141103
"metadata": {},
142104
"outputs": [
@@ -381,24 +343,7 @@
381343
"output_type": "display_data"
382344
}
383345
],
384-
"source": [
385-
"project = client.get_project(\"ckqcx1d58068c0y619qv7hzgu\")\n",
386-
"labels = project.video_label_generator()\n",
387-
"\n",
388-
"for label in labels:\n",
389-
" annotation_lookup = label.frame_annotations()\n",
390-
" for idx, frame in label.data.value:\n",
391-
" if idx % 30 != 1:\n",
392-
" continue\n",
393-
" \n",
394-
" for annotation in annotation_lookup[idx]:\n",
395-
" if isinstance(annotation.value, Rectangle):\n",
396-
" frame = annotation.value.draw(canvas = frame.astype(np.uint8), thickness = 10, color= (255,0,0))\n",
397-
" \n",
398-
" im = Image.fromarray(frame)\n",
399-
" w,h = im.size\n",
400-
" IPython.display.display(im.resize((w//6, h//6) )) "
401-
]
346+
"source": "project = client.get_project(\"ckqcx1d58068c0y619qv7hzgu\")\nlabels = project.video_label_generator()\n\nfor label in labels:\n annotation_lookup = label.frame_annotations()\n for idx, frame in label.data.value:\n if idx % 30 != 1:\n continue\n\n for annotation in annotation_lookup[idx]:\n if isinstance(annotation.value, Rectangle):\n frame = annotation.value.draw(canvas=frame.astype(np.uint8),\n thickness=10,\n color=(255, 0, 0))\n\n im = Image.fromarray(frame)\n w, h = im.size\n IPython.display.display(im.resize((w // 6, h // 6)))"
402347
},
403348
{
404349
"cell_type": "markdown",
@@ -410,18 +355,15 @@
410355
},
411356
{
412357
"cell_type": "code",
413-
"execution_count": 5,
358+
"execution_count": 6,
414359
"id": "western-lebanon",
415360
"metadata": {},
416361
"outputs": [],
417-
"source": [
418-
"project = client.get_project(\"ckrdn049u5dia0y3h4l577t1v\")\n",
419-
"label_list = project.label_generator().as_list()"
420-
]
362+
"source": "project = client.get_project(\"ckrdn049u5dia0y3h4l577t1v\")\nlabel_list = project.label_generator().as_list()"
421363
},
422364
{
423365
"cell_type": "code",
424-
"execution_count": 6,
366+
"execution_count": 7,
425367
"id": "likely-cleaners",
426368
"metadata": {},
427369
"outputs": [
@@ -437,15 +379,11 @@
437379
"output_type": "execute_result"
438380
}
439381
],
440-
"source": [
441-
"im_data = label_list[0].data.value\n",
442-
"h,w = im_data.shape[:2]\n",
443-
"Image.fromarray(im_data)"
444-
]
382+
"source": "im_data = label_list[0].data.value\nh, w = im_data.shape[:2]\nImage.fromarray(im_data)"
445383
},
446384
{
447385
"cell_type": "code",
448-
"execution_count": 7,
386+
"execution_count": 8,
449387
"id": "incredible-storage",
450388
"metadata": {},
451389
"outputs": [
@@ -461,17 +399,11 @@
461399
"output_type": "execute_result"
462400
}
463401
],
464-
"source": [
465-
"canvas = np.zeros((h, w, 3), dtype = np.uint8)\n",
466-
"for annotation in label_list[0].annotations:\n",
467-
" if isinstance(annotation.value, Geometry):\n",
468-
" canvas = annotation.value.draw(canvas = canvas)\n",
469-
"Image.fromarray(canvas)"
470-
]
402+
"source": "canvas = np.zeros((h, w, 3), dtype=np.uint8)\nfor annotation in label_list[0].annotations:\n if isinstance(annotation.value, Geometry):\n canvas = annotation.value.draw(canvas=canvas)\nImage.fromarray(canvas)"
471403
},
472404
{
473405
"cell_type": "code",
474-
"execution_count": 8,
406+
"execution_count": 9,
475407
"id": "greenhouse-discrimination",
476408
"metadata": {},
477409
"outputs": [
@@ -489,18 +421,11 @@
489421
"output_type": "execute_result"
490422
}
491423
],
492-
"source": [
493-
"geoms = []\n",
494-
"for annotation in label_list[0].annotations:\n",
495-
" if isinstance(annotation.value, Geometry):\n",
496-
" geoms.append(annotation.value.shapely)\n",
497-
"from shapely.geometry import MultiPolygon\n",
498-
"MultiPolygon(geoms)"
499-
]
424+
"source": "geoms = []\nfor annotation in label_list[0].annotations:\n if isinstance(annotation.value, Geometry):\n geoms.append(annotation.value.shapely)\nfrom shapely.geometry import MultiPolygon\n\nMultiPolygon(geoms)"
500425
},
501426
{
502427
"cell_type": "code",
503-
"execution_count": 9,
428+
"execution_count": 10,
504429
"id": "dried-lightning",
505430
"metadata": {},
506431
"outputs": [
@@ -512,11 +437,7 @@
512437
]
513438
}
514439
],
515-
"source": [
516-
"# We can also serialize back to the original payload:\n",
517-
"for result in LBV1Converter.serialize(label_list):\n",
518-
" print(result)"
519-
]
440+
"source": "# We can also serialize back to the original payload:\nfor result in LBV1Converter.serialize(label_list):\n print(result)"
520441
},
521442
{
522443
"cell_type": "markdown",
@@ -530,7 +451,7 @@
530451
},
531452
{
532453
"cell_type": "code",
533-
"execution_count": 10,
454+
"execution_count": 11,
534455
"id": "printable-wagon",
535456
"metadata": {},
536457
"outputs": [
@@ -545,16 +466,11 @@
545466
]
546467
}
547468
],
548-
"source": [
549-
"ndjson = []\n",
550-
"for row in NDJsonConverter.serialize(label_list):\n",
551-
" ndjson.append(row)\n",
552-
" print(row)"
553-
]
469+
"source": "ndjson = []\nfor row in NDJsonConverter.serialize(label_list):\n ndjson.append(row)\n print(row)"
554470
},
555471
{
556472
"cell_type": "code",
557-
"execution_count": 11,
473+
"execution_count": 12,
558474
"id": "operational-project",
559475
"metadata": {},
560476
"outputs": [
@@ -569,10 +485,7 @@
569485
"output_type": "execute_result"
570486
}
571487
],
572-
"source": [
573-
"# Convert back\n",
574-
"NDJsonConverter.deserialize(ndjson)"
575-
]
488+
"source": "# Convert back\nNDJsonConverter.deserialize(ndjson)"
576489
},
577490
{
578491
"cell_type": "markdown",
@@ -584,11 +497,11 @@
584497
},
585498
{
586499
"cell_type": "code",
587-
"execution_count": null,
500+
"execution_count": 13,
588501
"id": "placed-danger",
589502
"metadata": {},
590503
"outputs": [],
591-
"source": []
504+
"source": ""
592505
}
593506
],
594507
"metadata": {

0 commit comments

Comments
 (0)