Skip to content

Commit 316fefc

Browse files
authored
SN-87/85 (#1298)
- Updates to Image and Video notebook format - Added additional byte array examples for Image/Video import and Image prediction import notebook - Added a new LLM folder for new LLM import (MAL/MEA/Ground truth)
1 parent deac9c4 commit 316fefc

File tree

5 files changed

+1278
-345
lines changed

5 files changed

+1278
-345
lines changed

examples/annotation_import/image.ipynb

Lines changed: 157 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@
8686
"source": [
8787
"import uuid\n",
8888
"import requests\n",
89-
"import base64\n",
90-
"import numpy as np\n",
9189
"import labelbox as lb\n",
9290
"import labelbox.types as lb_types"
9391
],
@@ -124,7 +122,7 @@
124122
{
125123
"metadata": {},
126124
"source": [
127-
"### Radio classification"
125+
"### Classification : Radio (single-choice)"
128126
],
129127
"cell_type": "markdown"
130128
},
@@ -152,7 +150,39 @@
152150
{
153151
"metadata": {},
154152
"source": [
155-
"### Nested radio and checklist classification\n",
153+
"### Classification: Checklist (multi-choice)"
154+
],
155+
"cell_type": "markdown"
156+
},
157+
{
158+
"metadata": {},
159+
"source": [
160+
"# Python annotation\n",
161+
"checklist_annotation = lb_types.ClassificationAnnotation(\n",
162+
" name=\"checklist_question\", # must match your ontology feature\"s name\n",
163+
" value=lb_types.Checklist(answer=[\n",
164+
" lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n",
165+
" lb_types.ClassificationAnswer(name=\"second_checklist_answer\")\n",
166+
" ]))\n",
167+
"\n",
168+
"# NDJSON\n",
169+
"checklist_annotation_ndjson = {\n",
170+
" \"name\": \"checklist_question\",\n",
171+
" \"answer\": [{\n",
172+
" \"name\": \"first_checklist_answer\"\n",
173+
" }, {\n",
174+
" \"name\": \"second_checklist_answer\"\n",
175+
" }]\n",
176+
"}"
177+
],
178+
"cell_type": "code",
179+
"outputs": [],
180+
"execution_count": null
181+
},
182+
{
183+
"metadata": {},
184+
"source": [
185+
"### Classification: Nested radio and checklist\n",
156186
"\n"
157187
],
158188
"cell_type": "markdown"
@@ -231,29 +261,22 @@
231261
{
232262
"metadata": {},
233263
"source": [
234-
"### Checklist question"
264+
"### Classification: Free-form text "
235265
],
236266
"cell_type": "markdown"
237267
},
238268
{
239269
"metadata": {},
240270
"source": [
241271
"# Python annotation\n",
242-
"checklist_annotation = lb_types.ClassificationAnnotation(\n",
243-
" name=\"checklist_question\", # must match your ontology feature\"s name\n",
244-
" value=lb_types.Checklist(answer=[\n",
245-
" lb_types.ClassificationAnswer(name=\"first_checklist_answer\"),\n",
246-
" lb_types.ClassificationAnswer(name=\"second_checklist_answer\")\n",
247-
" ]))\n",
272+
"text_annotation = lb_types.ClassificationAnnotation(\n",
273+
" name=\"free_text\", # must match your ontology feature\"s name\n",
274+
" value=lb_types.Text(answer=\"sample text\"))\n",
248275
"\n",
249276
"# NDJSON\n",
250-
"checklist_annotation_ndjson = {\n",
251-
" \"name\": \"checklist_question\",\n",
252-
" \"answer\": [{\n",
253-
" \"name\": \"first_checklist_answer\"\n",
254-
" }, {\n",
255-
" \"name\": \"second_checklist_answer\"\n",
256-
" }]\n",
277+
"text_annotation_ndjson = {\n",
278+
" \"name\": \"free_text\",\n",
279+
" \"answer\": \"sample text\",\n",
257280
"}"
258281
],
259282
"cell_type": "code",
@@ -263,22 +286,73 @@
263286
{
264287
"metadata": {},
265288
"source": [
266-
"### Free form text classification"
289+
"### Relationship with bounding box\n",
290+
"> **NOTE:** \n",
291+
"> Only supported for MAL imports"
267292
],
268293
"cell_type": "markdown"
269294
},
270295
{
271296
"metadata": {},
272297
"source": [
273-
"# Python annotation\n",
274-
"text_annotation = lb_types.ClassificationAnnotation(\n",
275-
" name=\"free_text\", # must match your ontology feature\"s name\n",
276-
" value=lb_types.Text(answer=\"sample text\"))\n",
298+
"# Python Annotation\n",
299+
"bbox_source = lb_types.ObjectAnnotation(\n",
300+
" name=\"bounding_box\",\n",
301+
" value=lb_types.Rectangle(\n",
302+
" start=lb_types.Point(x=2096, y=1264),\n",
303+
" end=lb_types.Point(x=2240, y=1689),\n",
304+
" ),\n",
305+
")\n",
277306
"\n",
278-
"# NDJSON\n",
279-
"text_annotation_ndjson = {\n",
280-
" \"name\": \"free_text\",\n",
281-
" \"answer\": \"sample text\",\n",
307+
"bbox_target = lb_types.ObjectAnnotation(\n",
308+
" name=\"bounding_box\",\n",
309+
" value=lb_types.Rectangle(\n",
310+
" start=lb_types.Point(x=2272, y=1346),\n",
311+
" end=lb_types.Point(x=2416, y=1704),\n",
312+
" ),\n",
313+
")\n",
314+
"\n",
315+
"relationship = lb_types.RelationshipAnnotation(\n",
316+
" name=\"relationship\",\n",
317+
" value=lb_types.Relationship(\n",
318+
" source=bbox_source,\n",
319+
" target=bbox_target,\n",
320+
" type=lb_types.Relationship.Type.UNIDIRECTIONAL,\n",
321+
" ))\n",
322+
"\n",
323+
"## Only supported for MAL imports\n",
324+
"uuid_source = str(uuid.uuid4())\n",
325+
"uuid_target = str(uuid.uuid4())\n",
326+
"\n",
327+
"bbox_source_ndjson = {\n",
328+
" \"uuid\": uuid_source,\n",
329+
" \"name\": \"bounding_box\",\n",
330+
" \"bbox\": {\n",
331+
" \"top\": 1264.0,\n",
332+
" \"left\": 2096.0,\n",
333+
" \"height\": 425.0,\n",
334+
" \"width\": 144.0\n",
335+
" }\n",
336+
"}\n",
337+
"\n",
338+
"bbox_target_ndjson = {\n",
339+
" \"uuid\": uuid_target,\n",
340+
" \"name\": \"bounding_box\",\n",
341+
" \"bbox\": {\n",
342+
" \"top\": 1346.0,\n",
343+
" \"left\": 2272.0,\n",
344+
" \"height\": 358.0,\n",
345+
" \"width\": 144.0\n",
346+
" }\n",
347+
"}\n",
348+
"\n",
349+
"relationship_ndjson = {\n",
350+
" \"name\": \"relationship\",\n",
351+
" \"relationship\": {\n",
352+
" \"source\": uuid_source,\n",
353+
" \"target\": uuid_target,\n",
354+
" \"type\": \"unidirectional\"\n",
355+
" }\n",
282356
"}"
283357
],
284358
"cell_type": "code",
@@ -425,7 +499,7 @@
425499
{
426500
"metadata": {},
427501
"source": [
428-
"### Mask"
502+
"### Segmentation Mask"
429503
],
430504
"cell_type": "markdown"
431505
},
@@ -456,6 +530,48 @@
456530
"outputs": [],
457531
"execution_count": null
458532
},
533+
{
534+
"metadata": {},
535+
"source": [
536+
"### Segmentation mask with nested classification "
537+
],
538+
"cell_type": "markdown"
539+
},
540+
{
541+
"metadata": {},
542+
"source": [
543+
"url_2 = \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/raster_seg_with_subclass.png\"\n",
544+
"response = requests.get(url_2)\n",
545+
"mask_data = lb_types.MaskData(im_bytes=response.content)\n",
546+
"\n",
547+
"# Python annotation\n",
548+
"mask_with_text_subclass_annotation = lb_types.ObjectAnnotation(\n",
549+
" name = \"mask_with_text_subclass\", # must match your ontology feature\"s name\n",
550+
" value=lb_types.Mask(\n",
551+
" mask=mask_data,\n",
552+
" color=(255, 255, 255)),\n",
553+
" classifications=[\n",
554+
" lb_types.ClassificationAnnotation(\n",
555+
" name=\"sub_free_text\",\n",
556+
" value=lb_types.Text(answer=\"free text answer\")\n",
557+
" )]\n",
558+
")\n",
559+
"\n",
560+
"# NDJSON using instanceURI, bytes array is not fully supported.\n",
561+
"mask_with_text_subclass_ndjson = {\n",
562+
" \"name\": \"mask_with_text_subclass\",\n",
563+
" \"mask\": {\"instanceURI\": url_2,\n",
564+
" \"colorRGB\": (255, 255, 255)},\n",
565+
" \"classifications\":[{\n",
566+
" \"name\": \"sub_free_text\",\n",
567+
" \"answer\": \"free text answer\"\n",
568+
" }]\n",
569+
"}"
570+
],
571+
"cell_type": "code",
572+
"outputs": [],
573+
"execution_count": null
574+
},
459575
{
460576
"metadata": {},
461577
"source": [
@@ -561,83 +677,7 @@
561677
{
562678
"metadata": {},
563679
"source": [
564-
"### Relationship\n",
565-
"> **NOTE:** \n",
566-
"> Only supported for MAL imports"
567-
],
568-
"cell_type": "markdown"
569-
},
570-
{
571-
"metadata": {},
572-
"source": [
573-
"# Python Annotation\n",
574-
"bbox_source = lb_types.ObjectAnnotation(\n",
575-
" name=\"bounding_box\",\n",
576-
" value=lb_types.Rectangle(\n",
577-
" start=lb_types.Point(x=2096, y=1264),\n",
578-
" end=lb_types.Point(x=2240, y=1689),\n",
579-
" ),\n",
580-
")\n",
581-
"\n",
582-
"bbox_target = lb_types.ObjectAnnotation(\n",
583-
" name=\"bounding_box\",\n",
584-
" value=lb_types.Rectangle(\n",
585-
" start=lb_types.Point(x=2272, y=1346),\n",
586-
" end=lb_types.Point(x=2416, y=1704),\n",
587-
" ),\n",
588-
")\n",
589-
"\n",
590-
"relationship = lb_types.RelationshipAnnotation(\n",
591-
" name=\"relationship\",\n",
592-
" value=lb_types.Relationship(\n",
593-
" source=bbox_source,\n",
594-
" target=bbox_target,\n",
595-
" type=lb_types.Relationship.Type.UNIDIRECTIONAL,\n",
596-
" ))\n",
597-
"\n",
598-
"## Only supported for MAL imports\n",
599-
"uuid_source = str(uuid.uuid4())\n",
600-
"uuid_target = str(uuid.uuid4())\n",
601-
"\n",
602-
"bbox_source_ndjson = {\n",
603-
" \"uuid\": uuid_source,\n",
604-
" \"name\": \"bounding_box\",\n",
605-
" \"bbox\": {\n",
606-
" \"top\": 1264.0,\n",
607-
" \"left\": 2096.0,\n",
608-
" \"height\": 425.0,\n",
609-
" \"width\": 144.0\n",
610-
" }\n",
611-
"}\n",
612-
"\n",
613-
"bbox_target_ndjson = {\n",
614-
" \"uuid\": uuid_target,\n",
615-
" \"name\": \"bounding_box\",\n",
616-
" \"bbox\": {\n",
617-
" \"top\": 1346.0,\n",
618-
" \"left\": 2272.0,\n",
619-
" \"height\": 358.0,\n",
620-
" \"width\": 144.0\n",
621-
" }\n",
622-
"}\n",
623-
"\n",
624-
"relationship_ndjson = {\n",
625-
" \"name\": \"relationship\",\n",
626-
" \"relationship\": {\n",
627-
" \"source\": uuid_source,\n",
628-
" \"target\": uuid_target,\n",
629-
" \"type\": \"unidirectional\"\n",
630-
" }\n",
631-
"}"
632-
],
633-
"cell_type": "code",
634-
"outputs": [],
635-
"execution_count": null
636-
},
637-
{
638-
"metadata": {},
639-
"source": [
640-
"# Uploading annotations - putting it all together\n"
680+
"# End-to-end example: Import pre-labels or ground truth"
641681
],
642682
"cell_type": "markdown"
643683
},
@@ -740,12 +780,20 @@
740780
" ]),\n",
741781
" lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"polygon\"),\n",
742782
" lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION, name=\"mask\"),\n",
783+
" lb.Tool(tool=lb.Tool.Type.RASTER_SEGMENTATION,\n",
784+
" name=\"mask_with_text_subclass\",\n",
785+
" classifications=[\n",
786+
" lb.Classification(\n",
787+
" class_type=lb.Classification.Type.TEXT,\n",
788+
" name=\"sub_free_text\")\n",
789+
" ]\n",
790+
" ),\n",
743791
" lb.Tool(tool=lb.Tool.Type.POINT, name=\"point\"),\n",
744792
" lb.Tool(tool=lb.Tool.Type.LINE, name=\"polyline\"),\n",
745793
" lb.Tool(tool=lb.Tool.Type.RELATIONSHIP, name=\"relationship\")\n",
746794
" ])\n",
747795
"\n",
748-
"ontology = client.create_ontology(\"Image Prediction Import Demo\",\n",
796+
"ontology = client.create_ontology(\"Image Annotation Import Demo Ontology\",\n",
749797
" ontology_builder.asdict(),\n",
750798
" media_type=lb.MediaType.Image\n",
751799
" )"
@@ -767,7 +815,7 @@
767815
"source": [
768816
"# Project defaults to batch mode with benchmark quality settings if this argument is not provided\n",
769817
"# Queue mode will be deprecated once dataset mode is deprecated\n",
770-
"project = client.create_project(name=\"image-demo-project\",\n",
818+
"project = client.create_project(name=\"Image Annotation Import Demo\",\n",
771819
" media_type=lb.MediaType.Image)\n",
772820
"\n",
773821
"project.setup_editor(ontology)"
@@ -834,6 +882,7 @@
834882
" bbox_with_radio_subclass_annotation,\n",
835883
" polygon_annotation,\n",
836884
" mask_annotation,\n",
885+
" mask_with_text_subclass_annotation,\n",
837886
" point_annotation,\n",
838887
" polyline_annotation,\n",
839888
" bbox_source,\n",
@@ -870,6 +919,7 @@
870919
" bbox_with_radio_subclass_ndjson,\n",
871920
" polygon_annotation_ndjson,\n",
872921
" mask_annotation_ndjson,\n",
922+
" mask_with_text_subclass_ndjson,\n",
873923
" point_annotation_ndjson,\n",
874924
" polyline_annotation_ndjson,\n",
875925
" bbox_source_ndjson,\n",
@@ -958,13 +1008,6 @@
9581008
"cell_type": "code",
9591009
"outputs": [],
9601010
"execution_count": null
961-
},
962-
{
963-
"metadata": {},
964-
"source": [],
965-
"cell_type": "code",
966-
"outputs": [],
967-
"execution_count": null
9681011
}
9691012
]
9701013
}

0 commit comments

Comments
 (0)