85
85
"metadata" : {},
86
86
"source" : [
87
87
" import uuid\n " ,
88
+ " import requests\n " ,
89
+ " import base64\n " ,
88
90
" import numpy as np\n " ,
89
91
" import labelbox as lb\n " ,
90
92
" import labelbox.types as lb_types"
297
299
" bbox_annotation = lb_types.ObjectAnnotation(\n " ,
298
300
" name=\" bounding_box\" , # must match your ontology feature\" s name\n " ,
299
301
" value=lb_types.Rectangle(\n " ,
300
- " start=lb_types.Point(x=1690, y=977), # x = left, y = top \n " ,
302
+ " start=lb_types.Point(x=1690, y=977), # x = left, y = top\n " ,
301
303
" end=lb_types.Point(x=1915, y=1307), # x= left + width , y = top + height\n " ,
302
304
" ))\n " ,
303
305
" \n " ,
330
332
" bbox_with_radio_subclass_annotation = lb_types.ObjectAnnotation(\n " ,
331
333
" name=\" bbox_with_radio_subclass\" ,\n " ,
332
334
" value=lb_types.Rectangle(\n " ,
333
- " start=lb_types.Point(x=541, y=933), # x = left, y = top \n " ,
335
+ " start=lb_types.Point(x=541, y=933), # x = left, y = top\n " ,
334
336
" end=lb_types.Point(x=871, y=1124), # x= left + width , y = top + height\n " ,
335
337
" ),\n " ,
336
338
" classifications=[\n " ,
373
375
"source" : [
374
376
" # Python annotation\n " ,
375
377
" polygon_annotation = lb_types.ObjectAnnotation(\n " ,
376
- " name=\" polygon\" , # must match your ontology feature\" s name \n " ,
378
+ " name=\" polygon\" , # must match your ontology feature\" s name\n " ,
377
379
" value=lb_types.Polygon( # Coordinates for the vertices of your polygon\n " ,
378
380
" points=[\n " ,
379
381
" lb_types.Point(x=1489.581, y=183.934),\n " ,
430
432
{
431
433
"metadata" : {},
432
434
"source" : [
433
- " # Identifying what values in the numpy array correspond to the mask annotation \n " ,
434
- " color = (255, 255, 255) \n " ,
435
- " mask_data = lb_types.MaskData (url= \" https://storage.googleapis.com/labelbox-datasets/image_sample_data/raster_seg.png \" )\n " ,
435
+ " ### Raster Segmentation (Byte string array) \n " ,
436
+ " url = \" https://storage.googleapis.com/labelbox-datasets/image_sample_data/raster_seg.png \" \n" ,
437
+ " response = requests.get (url)\n " ,
436
438
" \n " ,
437
- " # Python annotation \n " ,
439
+ " mask_data = lb.types.MaskData(im_bytes=response.content) # You can also use \" url \" instead of img_bytes to pass the PNG mask url. \n " ,
438
440
" mask_annotation = lb_types.ObjectAnnotation(\n " ,
439
- " name = \" mask\" , # must match your ontology feature\" s name\n " ,
440
- " value=lb_types.Mask(mask=mask_data, color=color),\n " ,
441
+ " name=\" mask\" ,\n " ,
442
+ " value=lb_types.Mask(\n " ,
443
+ " mask=mask_data,\n " ,
444
+ " color=(255, 255, 255))\n " ,
441
445
" )\n " ,
442
446
" \n " ,
443
- " # NDJSON\n " ,
447
+ " # NDJSON using instanceURI, bytes array is not fully supported. \n " ,
444
448
" mask_annotation_ndjson = {\n " ,
445
449
" \" name\" : \" mask\" ,\n " ,
446
450
" \" classifications\" : [],\n " ,
447
- " \" mask\" : {\" instanceURI\" : \" https://storage.googleapis.com/labelbox-datasets/image_sample_data/raster_seg.png \" ,\n " ,
451
+ " \" mask\" : {\" instanceURI\" : url ,\n " ,
448
452
" \" colorRGB\" : (255, 255, 255)}\n " ,
449
- " }"
453
+ " }\n "
450
454
],
451
455
"cell_type" : " code" ,
452
456
"outputs" : [],
591
595
" type=lb_types.Relationship.Type.UNIDIRECTIONAL,\n " ,
592
596
" ))\n " ,
593
597
" \n " ,
594
- " ## Only supported for MAL imports \n " ,
598
+ " ## Only supported for MAL imports\n " ,
595
599
" uuid_source = str(uuid.uuid4())\n " ,
596
600
" uuid_target = str(uuid.uuid4())\n " ,
597
601
" \n " ,
855
859
{
856
860
"metadata" : {},
857
861
"source" : [
858
- " ndjson_label = []\n " ,
862
+ " label_ndjson = []\n " ,
859
863
" annotations = [\n " ,
860
864
" radio_annotation_ndjson,\n " ,
861
865
" nested_radio_annotation_ndjson,\n " ,
870
874
" polyline_annotation_ndjson,\n " ,
871
875
" bbox_source_ndjson,\n " ,
872
876
" bbox_target_ndjson,\n " ,
873
- " relationship_ndjson, ## Only supported for MAL imports \n " ,
877
+ " relationship_ndjson, ## Only supported for MAL imports\n " ,
874
878
" ]\n " ,
875
879
" for annotation in annotations:\n " ,
876
880
" annotation.update({\n " ,
877
881
" \" dataRow\" : {\n " ,
878
882
" \" globalKey\" : global_key\n " ,
879
- " }, \n " ,
883
+ " }\n " ,
880
884
" })\n " ,
881
- " ndjson_label .append(annotation)"
885
+ " label_ndjson .append(annotation)"
882
886
],
883
887
"cell_type" : " code" ,
884
888
"outputs" : [],
911
915
" )\n " ,
912
916
" upload_job.wait_until_done()\n " ,
913
917
" \n " ,
914
- " print(f\" Errors: {upload_job.errors}\" , )\n " ,
918
+ " print(f\" Errors: {upload_job.errors}\" )\n " ,
915
919
" print(f\" Status of uploads: {upload_job.statuses}\" )"
916
920
],
917
921
"cell_type" : " code" ,
928
932
{
929
933
"metadata" : {},
930
934
"source" : [
931
- " # Uncomment if relationships are not being imported. \n " ,
932
- " # Relationships will be supported for label import in the near future. \n " ,
935
+ " # Relationships are not supported with LabelImport \n " ,
936
+ " # For this demo either run MAL or Ground Truth, not both \n " ,
933
937
" \n " ,
934
938
" # Upload label for this data row in project\n " ,
935
939
" # upload_job = lb.LabelImport.create_from_objects(\n " ,
936
- " # client = client, \n " ,
937
- " # project_id = project.uid, \n " ,
938
- " # name=\" label_import_job\" +str(uuid.uuid4()), \n " ,
940
+ " # client = client,\n " ,
941
+ " # project_id = project.uid,\n " ,
942
+ " # name=\" label_import_job\" +str(uuid.uuid4()),\n " ,
939
943
" # labels=label)\n " ,
940
944
" \n " ,
941
945
" # print(\" Errors:\" , upload_job.errors)\n " ,
954
958
"cell_type" : " code" ,
955
959
"outputs" : [],
956
960
"execution_count" : null
961
+ },
962
+ {
963
+ "metadata" : {},
964
+ "source" : [],
965
+ "cell_type" : " code" ,
966
+ "outputs" : [],
967
+ "execution_count" : null
957
968
}
958
969
]
959
970
}
0 commit comments