From 3ea9cca3d53f453dd71f6a4f6a9d44b07b8cd5ec Mon Sep 17 00:00:00 2001
From: Gabefire <33893811+Gabefire@users.noreply.github.com>
Date: Wed, 12 Jun 2024 09:54:13 -0500
Subject: [PATCH 1/5] fixed composite notebook
---
examples/exports/composite_mask_export.ipynb | 284 ++++++++++++++-----
1 file changed, 206 insertions(+), 78 deletions(-)
diff --git a/examples/exports/composite_mask_export.ipynb b/examples/exports/composite_mask_export.ipynb
index 0a1cbfd45..81141b44c 100644
--- a/examples/exports/composite_mask_export.ipynb
+++ b/examples/exports/composite_mask_export.ipynb
@@ -1,18 +1,16 @@
{
- "nbformat": 4,
- "nbformat_minor": 2,
- "metadata": {},
"cells": [
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
- "
",
- " ",
+ " | \n",
+ " \n",
" | \n"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"\n",
@@ -24,10 +22,10 @@
" \n",
" | "
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"# Export composite masks \n",
@@ -36,56 +34,66 @@
"Composite masks are a combination of mask instances grouped in a single mask URL. \n",
"\n",
"The purpose of this demo is to demonstrate how to transition from exporting single masks to exporting composite masks. "
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
- "## Imports"
- ],
- "cell_type": "markdown"
+ "## Set up"
+ ]
},
{
- "metadata": {},
- "source": "%pip install -q \"labelbox[data]\"",
"cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
"outputs": [],
- "execution_count": null
+ "source": [
+ "%pip install -q --upgrade \"labelbox[data]\""
+ ]
},
{
- "metadata": {},
- "source": "import labelbox as lb\nimport urllib.request\nfrom PIL import Image\nimport json",
"cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
"outputs": [],
- "execution_count": null
+ "source": [
+ "import labelbox as lb\n",
+ "import urllib.request\n",
+ "from PIL import Image\n",
+ "import json"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
- "## API Key and Client\n",
- "See the developer guide for [creating an API key](https://docs.labelbox.com/reference/create-api-key)."
- ],
- "cell_type": "markdown"
+ "## API key and client\n",
+ "Provide a valid API key below in order to properly connect to the Labelbox client. Please review [Create API key guide](https://docs.labelbox.com/reference/create-api-key) for more information."
+ ]
},
{
- "metadata": {},
- "source": "API_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)\nclient.enable_experimental = (\n True ## This is required if using the export() streamable method\n)",
"cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
"outputs": [],
- "execution_count": null
+ "source": [
+ "API_KEY = None\n",
+ "client = lb.Client(api_key=API_KEY)"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"## Key differences between single mask instance and composite mask."
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
- "#### Composite masks\n",
+ "### Composite masks\n",
"**IMPORTANT :** The URL for the ```composite_mask``` from exports older than 30 days will no longer be accessible. To obtain a functional URL after this period, please generate a new export for the mask.\n",
"1. A single mask url contains all mask instances from a single label. For videos a composite mask contains all mask instances for the frame in each label. \n",
"2. The export and mask URL adhere to the following convention:\n",
@@ -117,17 +125,31 @@
" }\n",
"```\n",
"3. A unique RGB color is assigned to each mask instance. The example below shows a composite mask of a label, and while it contains all mask instances, only the RGB color associated with this particular annotation will be filled in under the ```color_rgb``` field."
- ],
- "cell_type": "markdown"
+ ]
},
{
- "metadata": {},
- "source": "# Example on how to fetch a composite mask\n# The mask here shows all the mask instances associated with a label\ntask_id = \"\"\ncomposite_mask_id = \"\"\n\nmask_url = f\"https://api.labelbox.com/api/v1/tasks/{task_id}/masks/{composite_mask_id}/index/1\"\nreq = urllib.request.Request(mask_url, headers=client.headers)\nimage = Image.open(urllib.request.urlopen(req))\nw, h = image.size\nnew_w = w // 4\nnew_h = h // 4\n\nimage.resize((new_w, new_h), Image.BICUBIC)",
"cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
"outputs": [],
- "execution_count": null
+ "source": [
+ "# Example on how to fetch a composite mask\n",
+ "# The mask here shows all the mask instances associated with a label\n",
+ "task_id = \"\"\n",
+ "composite_mask_id = \"\"\n",
+ "\n",
+ "mask_url = f\"https://api.labelbox.com/api/v1/tasks/{task_id}/masks/{composite_mask_id}/index/1\"\n",
+ "req = urllib.request.Request(mask_url, headers=client.headers)\n",
+ "image = Image.open(urllib.request.urlopen(req))\n",
+ "w, h = image.size\n",
+ "new_w = w // 4\n",
+ "new_h = h // 4\n",
+ "\n",
+ "image.resize((new_w, new_h), Image.BICUBIC)"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"Here's an example of an entry featuring a composite mask (see image above) containing the mask instance's RGB color uniquely associated with the annotation.\n",
@@ -151,22 +173,14 @@
" }\n",
"```\n",
"- rgb(123,103,152) = Purple\n"
- ],
- "cell_type": "markdown"
- },
- {
- "metadata": {},
- "source": [
- "---"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
- "#### Single mask instance:\n",
- "We are planning on removing single mask instances, but for now they will be displayed adjecent to the composite mask.\n",
- "1. A single mask instance and mask url is generated for each individual annotation for each label.\n",
+ "### Single mask instance:\n",
+ "1. A single mask instance and mask url is generated for each individual annotation per label.\n",
"2. The export and mask URL adhere to the following convention: \n",
"```json\n",
" {\n",
@@ -177,79 +191,193 @@
"\n",
"```\n",
"3. RGB color is not present"
- ],
- "cell_type": "markdown"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
- "## Create an export from an Image project with mask annotations\n",
+ "## Create an export from a project with mask annotations\n",
"To better showcase composite masks, make sure you have different mask tools and mask annotations in your project"
- ],
- "cell_type": "markdown"
+ ]
},
{
- "metadata": {},
- "source": "# Insert the project ID of the project from which you wish to export data rows.\nPROJECT_ID = \"\"\nproject = client.get_project(PROJECT_ID)",
"cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
"outputs": [],
- "execution_count": null
+ "source": [
+ "# Insert the project ID of the project from which you wish to export data rows.\n",
+ "PROJECT_ID = \"\"\n",
+ "project = client.get_project(PROJECT_ID)"
+ ]
},
{
- "metadata": {},
- "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n}\n\nfilters = {}\n\n# export() is the streamable option of exports V2, for more information please visit our documentation:\n# https://docs.labelbox.com/reference/label-export#export-v2-methods\n\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()\n\nif export_task.has_result():\n print(export_task.result)",
"cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
"outputs": [],
- "execution_count": null
+ "source": [
+ "export_params = {\n",
+ " \"attachments\": True,\n",
+ " \"metadata_fields\": True,\n",
+ " \"data_row_details\": True,\n",
+ " \"project_details\": True,\n",
+ " \"label_details\": True,\n",
+ " \"performance_details\": True,\n",
+ " \"interpolated_frames\": True,\n",
+ "}\n",
+ "\n",
+ "filters = {}\n",
+ "\n",
+ "# export() is the streamable option of exports V2, for more information please visit our documentation:\n",
+ "# https://docs.labelbox.com/reference/label-export#export-v2-methods\n",
+ "\n",
+ "export_task = project.export(params=export_params, filters=filters)\n",
+ "export_task.wait_till_done()\n",
+ "\n",
+ "if export_task.has_result():\n",
+ " print(export_task.result)"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"#### Get all the ```color_rgb``` associated with annotations that are using a specific mask tool "
- ],
- "cell_type": "markdown"
+ ]
},
{
- "metadata": {},
- "source": "stream = export_task.get_buffered_stream()\n\nmask_tool_rgb_mapping = {}\n\nfor output in stream:\n # Parse the JSON string from the output\n output_json = output.json\n\n # Get the labels for the specified project ID or an empty list if the project ID is not found\n project_labels = (output_json[\"projects\"].get(PROJECT_ID,\n {}).get(\"labels\", []))\n\n # Iterate through each label\n for label in project_labels:\n # Get the list of annotations (objects) for the label\n annotations = label[\"annotations\"].get(\"objects\", [])\n\n # Iterate through each annotation\n for annotation in annotations:\n # Check if the annotation is of type \"ImageSegmentationMask\"\n if annotation.get(\"annotation_kind\") == \"ImageSegmentationMask\":\n # Add the color RGB information to the mapping dictionary\n mask_tool_rgb_mapping.setdefault(annotation[\"name\"], []).append(\n annotation[\"composite_mask\"][\"color_rgb\"])\n\nprint(mask_tool_rgb_mapping)",
"cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
"outputs": [],
- "execution_count": null
+ "source": [
+ "stream = export_task.get_buffered_stream()\n",
+ "\n",
+ "mask_tool_rgb_mapping = {}\n",
+ "\n",
+ "for output in stream:\n",
+ " # Parse the JSON string from the output\n",
+ " output_json = output.json\n",
+ "\n",
+ " # Get the labels for the specified project ID or an empty list if the project ID is not found\n",
+ " project_labels = (output_json[\"projects\"].get(PROJECT_ID,\n",
+ " {}).get(\"labels\", []))\n",
+ "\n",
+ " # Iterate through each label\n",
+ " for label in project_labels:\n",
+ " # Get the list of annotations (objects) for the label\n",
+ " annotations = label[\"annotations\"].get(\"objects\", [])\n",
+ "\n",
+ " # Iterate through each annotation\n",
+ " for annotation in annotations:\n",
+ " # Check if the annotation is of type \"ImageSegmentationMask\"\n",
+ " if annotation.get(\"annotation_kind\") == \"ImageSegmentationMask\":\n",
+ " # Add the color RGB information to the mapping dictionary\n",
+ " mask_tool_rgb_mapping.setdefault(annotation[\"name\"], []).append(\n",
+ " annotation[\"composite_mask\"][\"color_rgb\"])\n",
+ "\n",
+ "print(mask_tool_rgb_mapping)"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"## Create an export from a Video project with mask annotations "
- ],
- "cell_type": "markdown"
+ ]
},
{
- "metadata": {},
- "source": "VIDEO_PROJECT_ID = \"\"\nproject_video = client.get_project(VIDEO_PROJECT_ID)",
"cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
"outputs": [],
- "execution_count": null
+ "source": [
+ "VIDEO_PROJECT_ID = \"\"\n",
+ "project_video = client.get_project(VIDEO_PROJECT_ID)"
+ ]
},
{
- "metadata": {},
- "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n}\n\nfilters = {}\n\n# export() is the streamable option of exports V2, for more information please visit our documentation:\n# https://docs.labelbox.com/reference/label-export#export-v2-methods\n\nexport_task_video = project_video.export(params=export_params, filters=filters)\nexport_task_video.wait_till_done()\n\nif export_task_video.has_result():\n print(export_task_video.result)",
"cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
"outputs": [],
- "execution_count": null
+ "source": [
+ "export_params = {\n",
+ " \"attachments\": True,\n",
+ " \"metadata_fields\": True,\n",
+ " \"data_row_details\": True,\n",
+ " \"project_details\": True,\n",
+ " \"label_details\": True,\n",
+ " \"performance_details\": True,\n",
+ " \"interpolated_frames\": True,\n",
+ "}\n",
+ "\n",
+ "filters = {}\n",
+ "\n",
+ "# export() is the streamable option of exports V2, for more information please visit our documentation:\n",
+ "# https://docs.labelbox.com/reference/label-export#export-v2-methods\n",
+ "\n",
+ "export_task_video = project_video.export(params=export_params, filters=filters)\n",
+ "export_task_video.wait_till_done()\n",
+ "\n",
+ "if export_task_video.has_result():\n",
+ " print(export_task_video.result)"
+ ]
},
{
+ "cell_type": "markdown",
"metadata": {},
"source": [
"#### Get all the ```color_rgb``` associated with annotations that are using a specific mask tool from each frame"
- ],
- "cell_type": "markdown"
+ ]
},
{
- "metadata": {},
- "source": "tools_frames_color = {}\nstream = export_task_video.get_buffered_stream()\n\n# Iterate over each output in the stream\nfor output in stream:\n output_json = output.json\n\n # Iterate over the labels in the specific project\n for dr in output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]:\n frames_data = dr[\"annotations\"][\"frames\"]\n\n # Iterate over each frame in the frames data\n for frame_key, frame_value in frames_data.items():\n\n # Iterate over each annotation in the frame\n for annotation_key, annotation_value in frame_value.items():\n if \"objects\" in annotation_key and annotation_value.values():\n\n # Iterate over each object in the annotation\n for object_key, object_value in annotation_value.items():\n if (object_value[\"annotation_kind\"] ==\n \"VideoSegmentationMask\"):\n # Update tools_frames_color with object information\n tools_frames_color.setdefault(\n object_value[\"name\"], []).append({\n frame_key:\n object_value[\"composite_mask\"]\n [\"color_rgb\"]\n })\n\nprint(tools_frames_color)",
"cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
"outputs": [],
- "execution_count": null
+ "source": [
+ "tools_frames_color = {}\n",
+ "stream = export_task_video.get_buffered_stream()\n",
+ "\n",
+ "# Iterate over each output in the stream\n",
+ "for output in stream:\n",
+ " output_json = output.json\n",
+ "\n",
+ " # Iterate over the labels in the specific project\n",
+ " for dr in output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]:\n",
+ " frames_data = dr[\"annotations\"][\"frames\"]\n",
+ "\n",
+ " # Iterate over each frame in the frames data\n",
+ " for frame_key, frame_value in frames_data.items():\n",
+ "\n",
+ " # Iterate over each annotation in the frame\n",
+ " for annotation_key, annotation_value in frame_value.items():\n",
+ " if \"objects\" in annotation_key and annotation_value.values():\n",
+ "\n",
+ " # Iterate over each object in the annotation\n",
+ " for object_key, object_value in annotation_value.items():\n",
+ " if (object_value[\"annotation_kind\"] ==\n",
+ " \"VideoSegmentationMask\"):\n",
+ " # Update tools_frames_color with object information\n",
+ " tools_frames_color.setdefault(\n",
+ " object_value[\"name\"], []).append({\n",
+ " frame_key:\n",
+ " object_value[\"composite_mask\"]\n",
+ " [\"color_rgb\"]\n",
+ " })\n",
+ "\n",
+ "print(tools_frames_color)"
+ ]
+ }
+ ],
+ "metadata": {
+ "language_info": {
+ "name": "python"
}
- ]
-}
\ No newline at end of file
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
From 693d22c314a3bd3ce1357b7d6f84d49968ec5e5a Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
Date: Wed, 12 Jun 2024 14:56:11 +0000
Subject: [PATCH 2/5] :art: Cleaned
---
examples/exports/composite_mask_export.ipynb | 262 +++++--------------
1 file changed, 63 insertions(+), 199 deletions(-)
diff --git a/examples/exports/composite_mask_export.ipynb b/examples/exports/composite_mask_export.ipynb
index 81141b44c..bc4c73a3d 100644
--- a/examples/exports/composite_mask_export.ipynb
+++ b/examples/exports/composite_mask_export.ipynb
@@ -1,16 +1,18 @@
{
+ "nbformat": 4,
+ "nbformat_minor": 2,
+ "metadata": {},
"cells": [
{
- "cell_type": "markdown",
"metadata": {},
"source": [
- "\n",
- " \n",
+ " | ",
+ " ",
" | \n"
- ]
+ ],
+ "cell_type": "markdown"
},
{
- "cell_type": "markdown",
"metadata": {},
"source": [
"\n",
@@ -22,10 +24,10 @@
" \n",
" | "
- ]
+ ],
+ "cell_type": "markdown"
},
{
- "cell_type": "markdown",
"metadata": {},
"source": [
"# Export composite masks \n",
@@ -34,63 +36,53 @@
"Composite masks are a combination of mask instances grouped in a single mask URL. \n",
"\n",
"The purpose of this demo is to demonstrate how to transition from exporting single masks to exporting composite masks. "
- ]
+ ],
+ "cell_type": "markdown"
},
{
- "cell_type": "markdown",
"metadata": {},
"source": [
"## Set up"
- ]
+ ],
+ "cell_type": "markdown"
},
{
- "cell_type": "code",
- "execution_count": null,
"metadata": {},
+ "source": "%pip install -q --upgrade \"labelbox[data]\"",
+ "cell_type": "code",
"outputs": [],
- "source": [
- "%pip install -q --upgrade \"labelbox[data]\""
- ]
+ "execution_count": null
},
{
- "cell_type": "code",
- "execution_count": null,
"metadata": {},
+ "source": "import labelbox as lb\nimport urllib.request\nfrom PIL import Image\nimport json",
+ "cell_type": "code",
"outputs": [],
- "source": [
- "import labelbox as lb\n",
- "import urllib.request\n",
- "from PIL import Image\n",
- "import json"
- ]
+ "execution_count": null
},
{
- "cell_type": "markdown",
"metadata": {},
"source": [
"## API key and client\n",
"Provide a valid API key below in order to properly connect to the Labelbox client. Please review [Create API key guide](https://docs.labelbox.com/reference/create-api-key) for more information."
- ]
+ ],
+ "cell_type": "markdown"
},
{
- "cell_type": "code",
- "execution_count": null,
"metadata": {},
+ "source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)",
+ "cell_type": "code",
"outputs": [],
- "source": [
- "API_KEY = None\n",
- "client = lb.Client(api_key=API_KEY)"
- ]
+ "execution_count": null
},
{
- "cell_type": "markdown",
"metadata": {},
"source": [
"## Key differences between single mask instance and composite mask."
- ]
+ ],
+ "cell_type": "markdown"
},
{
- "cell_type": "markdown",
"metadata": {},
"source": [
"### Composite masks\n",
@@ -125,31 +117,17 @@
" }\n",
"```\n",
"3. A unique RGB color is assigned to each mask instance. The example below shows a composite mask of a label, and while it contains all mask instances, only the RGB color associated with this particular annotation will be filled in under the ```color_rgb``` field."
- ]
+ ],
+ "cell_type": "markdown"
},
{
- "cell_type": "code",
- "execution_count": null,
"metadata": {},
+ "source": "# Example on how to fetch a composite mask\n# The mask here shows all the mask instances associated with a label\ntask_id = \"\"\ncomposite_mask_id = \"\"\n\nmask_url = f\"https://api.labelbox.com/api/v1/tasks/{task_id}/masks/{composite_mask_id}/index/1\"\nreq = urllib.request.Request(mask_url, headers=client.headers)\nimage = Image.open(urllib.request.urlopen(req))\nw, h = image.size\nnew_w = w // 4\nnew_h = h // 4\n\nimage.resize((new_w, new_h), Image.BICUBIC)",
+ "cell_type": "code",
"outputs": [],
- "source": [
- "# Example on how to fetch a composite mask\n",
- "# The mask here shows all the mask instances associated with a label\n",
- "task_id = \"\"\n",
- "composite_mask_id = \"\"\n",
- "\n",
- "mask_url = f\"https://api.labelbox.com/api/v1/tasks/{task_id}/masks/{composite_mask_id}/index/1\"\n",
- "req = urllib.request.Request(mask_url, headers=client.headers)\n",
- "image = Image.open(urllib.request.urlopen(req))\n",
- "w, h = image.size\n",
- "new_w = w // 4\n",
- "new_h = h // 4\n",
- "\n",
- "image.resize((new_w, new_h), Image.BICUBIC)"
- ]
+ "execution_count": null
},
{
- "cell_type": "markdown",
"metadata": {},
"source": [
"Here's an example of an entry featuring a composite mask (see image above) containing the mask instance's RGB color uniquely associated with the annotation.\n",
@@ -173,10 +151,10 @@
" }\n",
"```\n",
"- rgb(123,103,152) = Purple\n"
- ]
+ ],
+ "cell_type": "markdown"
},
{
- "cell_type": "markdown",
"metadata": {},
"source": [
"### Single mask instance:\n",
@@ -191,193 +169,79 @@
"\n",
"```\n",
"3. RGB color is not present"
- ]
+ ],
+ "cell_type": "markdown"
},
{
- "cell_type": "markdown",
"metadata": {},
"source": [
"## Create an export from a project with mask annotations\n",
"To better showcase composite masks, make sure you have different mask tools and mask annotations in your project"
- ]
+ ],
+ "cell_type": "markdown"
},
{
- "cell_type": "code",
- "execution_count": null,
"metadata": {},
+ "source": "# Insert the project ID of the project from which you wish to export data rows.\nPROJECT_ID = \"\"\nproject = client.get_project(PROJECT_ID)",
+ "cell_type": "code",
"outputs": [],
- "source": [
- "# Insert the project ID of the project from which you wish to export data rows.\n",
- "PROJECT_ID = \"\"\n",
- "project = client.get_project(PROJECT_ID)"
- ]
+ "execution_count": null
},
{
- "cell_type": "code",
- "execution_count": null,
"metadata": {},
+ "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n}\n\nfilters = {}\n\n# export() is the streamable option of exports V2, for more information please visit our documentation:\n# https://docs.labelbox.com/reference/label-export#export-v2-methods\n\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()\n\nif export_task.has_result():\n print(export_task.result)",
+ "cell_type": "code",
"outputs": [],
- "source": [
- "export_params = {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"label_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"interpolated_frames\": True,\n",
- "}\n",
- "\n",
- "filters = {}\n",
- "\n",
- "# export() is the streamable option of exports V2, for more information please visit our documentation:\n",
- "# https://docs.labelbox.com/reference/label-export#export-v2-methods\n",
- "\n",
- "export_task = project.export(params=export_params, filters=filters)\n",
- "export_task.wait_till_done()\n",
- "\n",
- "if export_task.has_result():\n",
- " print(export_task.result)"
- ]
+ "execution_count": null
},
{
- "cell_type": "markdown",
"metadata": {},
"source": [
"#### Get all the ```color_rgb``` associated with annotations that are using a specific mask tool "
- ]
+ ],
+ "cell_type": "markdown"
},
{
- "cell_type": "code",
- "execution_count": null,
"metadata": {},
+ "source": "stream = export_task.get_buffered_stream()\n\nmask_tool_rgb_mapping = {}\n\nfor output in stream:\n # Parse the JSON string from the output\n output_json = output.json\n\n # Get the labels for the specified project ID or an empty list if the project ID is not found\n project_labels = (output_json[\"projects\"].get(PROJECT_ID,\n {}).get(\"labels\", []))\n\n # Iterate through each label\n for label in project_labels:\n # Get the list of annotations (objects) for the label\n annotations = label[\"annotations\"].get(\"objects\", [])\n\n # Iterate through each annotation\n for annotation in annotations:\n # Check if the annotation is of type \"ImageSegmentationMask\"\n if annotation.get(\"annotation_kind\") == \"ImageSegmentationMask\":\n # Add the color RGB information to the mapping dictionary\n mask_tool_rgb_mapping.setdefault(annotation[\"name\"], []).append(\n annotation[\"composite_mask\"][\"color_rgb\"])\n\nprint(mask_tool_rgb_mapping)",
+ "cell_type": "code",
"outputs": [],
- "source": [
- "stream = export_task.get_buffered_stream()\n",
- "\n",
- "mask_tool_rgb_mapping = {}\n",
- "\n",
- "for output in stream:\n",
- " # Parse the JSON string from the output\n",
- " output_json = output.json\n",
- "\n",
- " # Get the labels for the specified project ID or an empty list if the project ID is not found\n",
- " project_labels = (output_json[\"projects\"].get(PROJECT_ID,\n",
- " {}).get(\"labels\", []))\n",
- "\n",
- " # Iterate through each label\n",
- " for label in project_labels:\n",
- " # Get the list of annotations (objects) for the label\n",
- " annotations = label[\"annotations\"].get(\"objects\", [])\n",
- "\n",
- " # Iterate through each annotation\n",
- " for annotation in annotations:\n",
- " # Check if the annotation is of type \"ImageSegmentationMask\"\n",
- " if annotation.get(\"annotation_kind\") == \"ImageSegmentationMask\":\n",
- " # Add the color RGB information to the mapping dictionary\n",
- " mask_tool_rgb_mapping.setdefault(annotation[\"name\"], []).append(\n",
- " annotation[\"composite_mask\"][\"color_rgb\"])\n",
- "\n",
- "print(mask_tool_rgb_mapping)"
- ]
+ "execution_count": null
},
{
- "cell_type": "markdown",
"metadata": {},
"source": [
"## Create an export from a Video project with mask annotations "
- ]
+ ],
+ "cell_type": "markdown"
},
{
- "cell_type": "code",
- "execution_count": null,
"metadata": {},
+ "source": "VIDEO_PROJECT_ID = \"\"\nproject_video = client.get_project(VIDEO_PROJECT_ID)",
+ "cell_type": "code",
"outputs": [],
- "source": [
- "VIDEO_PROJECT_ID = \"\"\n",
- "project_video = client.get_project(VIDEO_PROJECT_ID)"
- ]
+ "execution_count": null
},
{
- "cell_type": "code",
- "execution_count": null,
"metadata": {},
+ "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n \"interpolated_frames\": True,\n}\n\nfilters = {}\n\n# export() is the streamable option of exports V2, for more information please visit our documentation:\n# https://docs.labelbox.com/reference/label-export#export-v2-methods\n\nexport_task_video = project_video.export(params=export_params, filters=filters)\nexport_task_video.wait_till_done()\n\nif export_task_video.has_result():\n print(export_task_video.result)",
+ "cell_type": "code",
"outputs": [],
- "source": [
- "export_params = {\n",
- " \"attachments\": True,\n",
- " \"metadata_fields\": True,\n",
- " \"data_row_details\": True,\n",
- " \"project_details\": True,\n",
- " \"label_details\": True,\n",
- " \"performance_details\": True,\n",
- " \"interpolated_frames\": True,\n",
- "}\n",
- "\n",
- "filters = {}\n",
- "\n",
- "# export() is the streamable option of exports V2, for more information please visit our documentation:\n",
- "# https://docs.labelbox.com/reference/label-export#export-v2-methods\n",
- "\n",
- "export_task_video = project_video.export(params=export_params, filters=filters)\n",
- "export_task_video.wait_till_done()\n",
- "\n",
- "if export_task_video.has_result():\n",
- " print(export_task_video.result)"
- ]
+ "execution_count": null
},
{
- "cell_type": "markdown",
"metadata": {},
"source": [
"#### Get all the ```color_rgb``` associated with annotations that are using a specific mask tool from each frame"
- ]
+ ],
+ "cell_type": "markdown"
},
{
- "cell_type": "code",
- "execution_count": null,
"metadata": {},
+ "source": "tools_frames_color = {}\nstream = export_task_video.get_buffered_stream()\n\n# Iterate over each output in the stream\nfor output in stream:\n output_json = output.json\n\n # Iterate over the labels in the specific project\n for dr in output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]:\n frames_data = dr[\"annotations\"][\"frames\"]\n\n # Iterate over each frame in the frames data\n for frame_key, frame_value in frames_data.items():\n\n # Iterate over each annotation in the frame\n for annotation_key, annotation_value in frame_value.items():\n if \"objects\" in annotation_key and annotation_value.values():\n\n # Iterate over each object in the annotation\n for object_key, object_value in annotation_value.items():\n if (object_value[\"annotation_kind\"] ==\n \"VideoSegmentationMask\"):\n # Update tools_frames_color with object information\n tools_frames_color.setdefault(\n object_value[\"name\"], []).append({\n frame_key:\n object_value[\"composite_mask\"]\n [\"color_rgb\"]\n })\n\nprint(tools_frames_color)",
+ "cell_type": "code",
"outputs": [],
- "source": [
- "tools_frames_color = {}\n",
- "stream = export_task_video.get_buffered_stream()\n",
- "\n",
- "# Iterate over each output in the stream\n",
- "for output in stream:\n",
- " output_json = output.json\n",
- "\n",
- " # Iterate over the labels in the specific project\n",
- " for dr in output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]:\n",
- " frames_data = dr[\"annotations\"][\"frames\"]\n",
- "\n",
- " # Iterate over each frame in the frames data\n",
- " for frame_key, frame_value in frames_data.items():\n",
- "\n",
- " # Iterate over each annotation in the frame\n",
- " for annotation_key, annotation_value in frame_value.items():\n",
- " if \"objects\" in annotation_key and annotation_value.values():\n",
- "\n",
- " # Iterate over each object in the annotation\n",
- " for object_key, object_value in annotation_value.items():\n",
- " if (object_value[\"annotation_kind\"] ==\n",
- " \"VideoSegmentationMask\"):\n",
- " # Update tools_frames_color with object information\n",
- " tools_frames_color.setdefault(\n",
- " object_value[\"name\"], []).append({\n",
- " frame_key:\n",
- " object_value[\"composite_mask\"]\n",
- " [\"color_rgb\"]\n",
- " })\n",
- "\n",
- "print(tools_frames_color)"
- ]
- }
- ],
- "metadata": {
- "language_info": {
- "name": "python"
+ "execution_count": null
}
- },
- "nbformat": 4,
- "nbformat_minor": 2
-}
+ ]
+}
\ No newline at end of file
From 627a2a724f952f1574518ee06b8be7a8594bce4b Mon Sep 17 00:00:00 2001
From: Gabe <33893811+Gabefire@users.noreply.github.com>
Date: Wed, 12 Jun 2024 09:58:03 -0500
Subject: [PATCH 3/5] Update composite_mask_export.ipynb
---
examples/exports/composite_mask_export.ipynb | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/examples/exports/composite_mask_export.ipynb b/examples/exports/composite_mask_export.ipynb
index bc4c73a3d..4c960bdc8 100644
--- a/examples/exports/composite_mask_export.ipynb
+++ b/examples/exports/composite_mask_export.ipynb
@@ -35,7 +35,7 @@
"\n",
"Composite masks are a combination of mask instances grouped in a single mask URL. \n",
"\n",
- "The purpose of this demo is to demonstrate how to transition from exporting single masks to exporting composite masks. "
+ "This demo aims to demonstrate how to transition from exporting single masks to exporting composite masks. "
],
"cell_type": "markdown"
},
@@ -64,7 +64,7 @@
"metadata": {},
"source": [
"## API key and client\n",
- "Provide a valid API key below in order to properly connect to the Labelbox client. Please review [Create API key guide](https://docs.labelbox.com/reference/create-api-key) for more information."
+ "Provide a valid API key below to properly connect to the Labelbox client. Please review [Create API key guide](https://docs.labelbox.com/reference/create-api-key) for more information."
],
"cell_type": "markdown"
},
@@ -87,8 +87,8 @@
"source": [
"### Composite masks\n",
"**IMPORTANT :** The URL for the ```composite_mask``` from exports older than 30 days will no longer be accessible. To obtain a functional URL after this period, please generate a new export for the mask.\n",
- "1. A single mask url contains all mask instances from a single label. For videos a composite mask contains all mask instances for the frame in each label. \n",
- "2. The export and mask URL adhere to the following convention:\n",
+ "1. A single mask URL contains all mask instances from a single label. For videos a composite mask contains all mask instances for the frame in each label. \n",
+ "2. The export and mask URL adheres to the following convention:\n",
" - ***Image example***\n",
"```json \n",
" {\n",
@@ -244,4 +244,4 @@
"execution_count": null
}
]
-}
\ No newline at end of file
+}
From 22dc352d424a8a54ec68db1a6008f8ff42496e4c Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
Date: Wed, 12 Jun 2024 14:59:03 +0000
Subject: [PATCH 4/5] :art: Cleaned
---
examples/exports/composite_mask_export.ipynb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/exports/composite_mask_export.ipynb b/examples/exports/composite_mask_export.ipynb
index 4c960bdc8..2caab0188 100644
--- a/examples/exports/composite_mask_export.ipynb
+++ b/examples/exports/composite_mask_export.ipynb
@@ -244,4 +244,4 @@
"execution_count": null
}
]
-}
+}
\ No newline at end of file
From b8843c8aa2e1b7b956441a2412c1e11546d4a3c3 Mon Sep 17 00:00:00 2001
From: Gabefire <33893811+Gabefire@users.noreply.github.com>
Date: Wed, 12 Jun 2024 10:59:12 -0500
Subject: [PATCH 5/5] changed composite url
---
examples/exports/composite_mask_export.ipynb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/exports/composite_mask_export.ipynb b/examples/exports/composite_mask_export.ipynb
index 2caab0188..206637d5b 100644
--- a/examples/exports/composite_mask_export.ipynb
+++ b/examples/exports/composite_mask_export.ipynb
@@ -87,7 +87,7 @@
"source": [
"### Composite masks\n",
"**IMPORTANT :** The URL for the ```composite_mask``` from exports older than 30 days will no longer be accessible. To obtain a functional URL after this period, please generate a new export for the mask.\n",
- "1. A single mask URL contains all mask instances from a single label. For videos a composite mask contains all mask instances for the frame in each label. \n",
+ "1. A composite URL contains all mask instances from a single label. For videos a composite mask contains all mask instances per frame in each label. \n",
"2. The export and mask URL adheres to the following convention:\n",
" - ***Image example***\n",
"```json \n",