Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 34 additions & 23 deletions examples/annotation_import/image.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
"metadata": {},
"source": [
"import uuid\n",
"import requests\n",
"import base64\n",
"import numpy as np\n",
"import labelbox as lb\n",
"import labelbox.types as lb_types"
Expand Down Expand Up @@ -297,7 +299,7 @@
"bbox_annotation = lb_types.ObjectAnnotation(\n",
" name=\"bounding_box\", # must match your ontology feature\"s name\n",
" value=lb_types.Rectangle(\n",
" start=lb_types.Point(x=1690, y=977), # x = left, y = top \n",
" start=lb_types.Point(x=1690, y=977), # x = left, y = top\n",
" end=lb_types.Point(x=1915, y=1307), # x= left + width , y = top + height\n",
" ))\n",
"\n",
Expand Down Expand Up @@ -330,7 +332,7 @@
"bbox_with_radio_subclass_annotation = lb_types.ObjectAnnotation(\n",
" name=\"bbox_with_radio_subclass\",\n",
" value=lb_types.Rectangle(\n",
" start=lb_types.Point(x=541, y=933), # x = left, y = top \n",
" start=lb_types.Point(x=541, y=933), # x = left, y = top\n",
" end=lb_types.Point(x=871, y=1124), # x= left + width , y = top + height\n",
" ),\n",
" classifications=[\n",
Expand Down Expand Up @@ -373,7 +375,7 @@
"source": [
"# Python annotation\n",
"polygon_annotation = lb_types.ObjectAnnotation(\n",
" name=\"polygon\", # must match your ontology feature\"s name \n",
" name=\"polygon\", # must match your ontology feature\"s name\n",
" value=lb_types.Polygon( # Coordinates for the vertices of your polygon\n",
" points=[\n",
" lb_types.Point(x=1489.581, y=183.934),\n",
Expand Down Expand Up @@ -430,23 +432,25 @@
{
"metadata": {},
"source": [
"# Identifying what values in the numpy array correspond to the mask annotation\n",
"color = (255, 255, 255)\n",
"mask_data = lb_types.MaskData(url=\"https://storage.googleapis.com/labelbox-datasets/image_sample_data/raster_seg.png\")\n",
"### Raster Segmentation (Byte string array)\n",
"url = \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/raster_seg.png\"\n",
"response = requests.get(url)\n",
"\n",
"# Python annotation\n",
"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",
"mask_annotation = lb_types.ObjectAnnotation(\n",
" name = \"mask\", # must match your ontology feature\"s name\n",
" value=lb_types.Mask(mask=mask_data, color=color),\n",
" name=\"mask\",\n",
" value=lb_types.Mask(\n",
" mask=mask_data,\n",
" color=(255, 255, 255))\n",
")\n",
"\n",
"# NDJSON\n",
"# NDJSON using instanceURI, bytes array is not fully supported.\n",
"mask_annotation_ndjson = {\n",
" \"name\": \"mask\",\n",
" \"classifications\": [],\n",
" \"mask\": {\"instanceURI\": \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/raster_seg.png\",\n",
" \"mask\": {\"instanceURI\": url,\n",
" \"colorRGB\": (255, 255, 255)}\n",
"}"
"}\n"
],
"cell_type": "code",
"outputs": [],
Expand Down Expand Up @@ -591,7 +595,7 @@
" type=lb_types.Relationship.Type.UNIDIRECTIONAL,\n",
" ))\n",
"\n",
"## Only supported for MAL imports \n",
"## Only supported for MAL imports\n",
"uuid_source = str(uuid.uuid4())\n",
"uuid_target = str(uuid.uuid4())\n",
"\n",
Expand Down Expand Up @@ -855,7 +859,7 @@
{
"metadata": {},
"source": [
"ndjson_label = []\n",
"label_ndjson = []\n",
"annotations = [\n",
" radio_annotation_ndjson,\n",
" nested_radio_annotation_ndjson,\n",
Expand All @@ -870,15 +874,15 @@
" polyline_annotation_ndjson,\n",
" bbox_source_ndjson,\n",
" bbox_target_ndjson,\n",
" relationship_ndjson, ## Only supported for MAL imports \n",
" relationship_ndjson, ## Only supported for MAL imports\n",
"]\n",
"for annotation in annotations:\n",
" annotation.update({\n",
" \"dataRow\": {\n",
" \"globalKey\": global_key\n",
" },\n",
" }\n",
" })\n",
" ndjson_label.append(annotation)"
" label_ndjson.append(annotation)"
],
"cell_type": "code",
"outputs": [],
Expand Down Expand Up @@ -911,7 +915,7 @@
")\n",
"upload_job.wait_until_done()\n",
"\n",
"print(f\"Errors: {upload_job.errors}\", )\n",
"print(f\"Errors: {upload_job.errors}\")\n",
"print(f\"Status of uploads: {upload_job.statuses}\")"
],
"cell_type": "code",
Expand All @@ -928,14 +932,14 @@
{
"metadata": {},
"source": [
"# Uncomment if relationships are not being imported. \n",
"# Relationships will be supported for label import in the near future. \n",
"# Relationships are not supported with LabelImport\n",
"# For this demo either run MAL or Ground Truth, not both\n",
"\n",
"# Upload label for this data row in project\n",
"# upload_job = lb.LabelImport.create_from_objects(\n",
"# client = client, \n",
"# project_id = project.uid, \n",
"# name=\"label_import_job\"+str(uuid.uuid4()), \n",
"# client = client,\n",
"# project_id = project.uid,\n",
"# name=\"label_import_job\"+str(uuid.uuid4()),\n",
"# labels=label)\n",
"\n",
"# print(\"Errors:\", upload_job.errors)\n",
Expand All @@ -954,6 +958,13 @@
"cell_type": "code",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
"source": [],
"cell_type": "code",
"outputs": [],
"execution_count": null
}
]
}
Loading