From 665480bb3ce574b01be6dd34501ce88ee165b089 Mon Sep 17 00:00:00 2001 From: Andrea Ovalle <74880762+ovalle15@users.noreply.github.com> Date: Fri, 28 Oct 2022 09:17:57 -0400 Subject: [PATCH 1/2] Update image.ipynb / image annotation import --- examples/annotation_import/image.ipynb | 513 +++++++++++++++---------- 1 file changed, 306 insertions(+), 207 deletions(-) diff --git a/examples/annotation_import/image.ipynb b/examples/annotation_import/image.ipynb index 3bf330770..23d6cd9f1 100644 --- a/examples/annotation_import/image.ipynb +++ b/examples/annotation_import/image.ipynb @@ -8,7 +8,7 @@ }, "source": [ "\n", - " \n", + " \n", "" ] }, @@ -20,12 +20,12 @@ }, "source": [ "\n", - "\n", "\n", "\n", "\n", - "\n", "" ] @@ -63,7 +63,8 @@ "source": [ "* Notes:\n", " * If you are importing more than 1,000 mask annotations at a time, consider submitting separate jobs, as they can take longer than other annotation types to import.\n", - " * Wait until the import job is complete before opening the Editor to make sure all annotations are imported properly." + " * Wait until the import job is complete before opening the Editor to make sure all annotations are imported properly.\n", + " * After the execution of this notebook a complete MAL and Label Import project with annotations will be created in your organization. " ] }, { @@ -78,26 +79,12 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "4d63074b-2379-48af-b9d6-2a66190f03c4", "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "4d63074b-2379-48af-b9d6-2a66190f03c4", - "outputId": "2560882d-6542-4dda-c075-d197ef2da5e3" + "id": "4d63074b-2379-48af-b9d6-2a66190f03c4" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[K |████████████████████████████████| 172 kB 9.3 MB/s \n", - "\u001b[K |████████████████████████████████| 6.3 MB 15.2 MB/s \n", - "\u001b[?25h Building wheel for pygeotile (setup.py) ... \u001b[?25l\u001b[?25hdone\n" - ] - } - ], + "outputs": [], "source": [ "!pip install -q 'labelbox[data]'" ] @@ -117,23 +104,39 @@ "execution_count": 2, "id": "01fca8c9-0680-4a9c-a11e-1b49f31e9121", "metadata": { - "id": "01fca8c9-0680-4a9c-a11e-1b49f31e9121" + "id": "01fca8c9-0680-4a9c-a11e-1b49f31e9121", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "11b988f5-5b81-4701-d78a-892e9acf7ae9" }, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "3.28.0\n" + ] + } + ], "source": [ + "import labelbox\n", "from labelbox.schema.ontology import OntologyBuilder, Tool, Classification, Option\n", - "from labelbox import Client, LabelingFrontend, LabelImport, MALPredictionImport\n", + "from labelbox.schema.queue_mode import QueueMode\n", + "from labelbox import Client, LabelingFrontend, LabelImport, MALPredictionImport, MediaType\n", "from labelbox.data.annotation_types import (\n", " Label, ImageData, ObjectAnnotation, MaskData,\n", " Rectangle, Point, Line, Mask, Polygon,\n", " Radio, Checklist, Text,\n", - " ClassificationAnnotation, ClassificationAnswer\n", + " ClassificationAnnotation, ClassificationAnswer, LabelList\n", ")\n", "from labelbox.data.serialization import NDJsonConverter\n", - "from labelbox.schema.media_type import MediaType\n", "import uuid\n", "import json\n", - "import numpy as np" + "import numpy as np\n", + "import uuid\n", + "import copy\n", + "print(labelbox.__version__)" ] }, { @@ -149,7 +152,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 3, "id": "86003724-4807-4281-95c1-5284a6f9609f", "metadata": { "id": "86003724-4807-4281-95c1-5284a6f9609f" @@ -197,19 +200,19 @@ }, { "cell_type": "markdown", - "id": "49i_juOUr6av", - "metadata": { - "id": "49i_juOUr6av" - }, "source": [ "First, we create an ontology with all the possible tools and classifications supported for images. The official list of supported annotations to import can be found here:\n", "- [Model-Assisted Labeling](https://docs.labelbox.com/docs/model-assisted-labeling) (annotations/labels are not submitted)\n", "- [Ground Truth](https://docs.labelbox.com/docs/import-ground-truth) (annotations/labels are submitted)" - ] + ], + "metadata": { + "id": "49i_juOUr6av" + }, + "id": "49i_juOUr6av" }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 4, "id": "f9f9287c-aad7-4914-bc87-1453fb8bce81", "metadata": { "id": "f9f9287c-aad7-4914-bc87-1453fb8bce81" @@ -259,48 +262,137 @@ }, { "cell_type": "markdown", - "id": "1GdimALBuzRU", + "source": [ + "To show the two different ways to upload annotations, we create two projects - one to showcase MAL (Model-Assisted Labeling) and one to showcase Label Import." + ], "metadata": { "id": "1GdimALBuzRU" }, - "source": [ - "To show the two different ways to upload annotations, we create two projects - one to showcase MAL (Model-Assisted Labeling) and one to showcase Label Import." - ] + "id": "1GdimALBuzRU" }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 6, "id": "044e9194-d21d-403e-b64c-047c1063b0fe", "metadata": { - "id": "044e9194-d21d-403e-b64c-047c1063b0fe" + "id": "044e9194-d21d-403e-b64c-047c1063b0fe", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "5172b654-6d94-45ed-a6ed-402ed8d0c069" }, - "outputs": [], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\n" + ] + } + ], "source": [ - "# Create two Labelbox projects\n", - "mal_project = client.create_project(\n", - " name=\"image_mal_project\",\n", - " media_type=MediaType.Image\n", - ")\n", - "li_project = client.create_project(\n", - " name=\"image_label_import_project\",\n", - " media_type=MediaType.Image\n", - ")\n", + "# Create two Labelbox batch projects\n", + "# Project defaults to batch mode with benchmark quality settings if this argument is not provided\n", + "# Queue mode will be deprecated once dataset mode is deprecated\n", + "\n", + "mal_project = client.create_project(name=\"image_mal_project\", \n", + " queue_mode=QueueMode.Batch,\n", + " # Quality Settings setup \n", + " auto_audit_percentage=1,\n", + " auto_audit_number_of_labels=1,\n", + " media_type=MediaType.Image)\n", "\n", - "# Create one Labelbox dataset\n", + "li_project = client.create_project(name=\"image_label_import_project\",\n", + " queue_mode=QueueMode.Batch,\n", + " auto_audit_percentage=1,\n", + " auto_audit_number_of_labels=1,\n", + " media_type=MediaType.Image)\n", + "\n", + "# # Create one Labelbox dataset\n", "dataset = client.create_dataset(name=\"image_annotation_import_demo_dataset\")\n", + "# Grab an example image and create a Labelbox data row in the dataset\n", + "uploads = {\n", + " \"row_data\": \"https://raw.githubusercontent.com/Labelbox/labelbox-python/develop/examples/assets/2560px-Kitano_Street_Kobe01s5s4110.jpg\",\n", + " # To learn more about Global Keys : https://docs.labelbox.com/docs/global-keys\n", + " \"global_key\": \"TEST-ID-%id\" % uuid.uuid1()\n", + " }\n", + "data_row = dataset.create_data_row(uploads)\n", + "print(data_row)\n", "\n", - "# Grab an example image and create a Labelbox data row\n", - "test_img_url = \"https://raw.githubusercontent.com/Labelbox/labelbox-python/develop/examples/assets/2560px-Kitano_Street_Kobe01s5s4110.jpg\"\n", - "data_row = dataset.create_data_row(row_data=test_img_url)\n", "\n", - "# Setup your ontology / labeling editor\n", - "editor = next(client.get_labeling_frontends(where=LabelingFrontend.name == \"Editor\")) # Unless using a custom editor, do not modify this\n", + "######################### DATASET CONSENSUS OPTION ########################\n", + "#Note that dataset base projects will be deprecated in the near future.\n", + "\n", + "#To use Datasets/Consensus instead of Batches/Benchmarks use the following query: \n", + "#In this case, 10% of all data rows need to be annotated by three labelers.\n", "\n", - "mal_project.setup(editor, ontology_builder.asdict()) # Connect your ontology and editor to your MAL project\n", - "mal_project.datasets.connect(dataset) # Connect your dataset to your MAL project\n", + "# dataset_project = client.create_project(name=\"dataset-test-project\",\n", + "# description=\"a description\",\n", + "# media_type=MediaType.Image,\n", + "# auto_audit_percentage=0.1,\n", + "# auto_audit_number_of_labels=3,\n", + "# queue_mode=QueueMode.Dataset)\n", "\n", - "li_project.setup(editor, ontology_builder.asdict()) # Connect your ontology and editor to your Label Import project\n", - "li_project.datasets.connect(dataset) # Connect your dataset to your Label Import project" + "# dataset_project.datasets.connect(dataset)\n" + ] + }, + { + "cell_type": "markdown", + "source": [ + "### Setup Batches and Ontology for each project" + ], + "metadata": { + "id": "8eRGvN8ynJD6" + }, + "id": "8eRGvN8ynJD6" + }, + { + "cell_type": "code", + "source": [ + "# We need data row ID(s) to create a batch\n", + "batch_datarows = [dr.uid for dr in list(dataset.export_data_rows())]\n", + "\n", + "# Create a batch to send to your MAL project\n", + "batch_mal = mal_project.create_batch(\n", + " \"first-batch-MAL\", # Each batch in a project must have a unique name\n", + " batch_datarows, # A list of data rows or data row ids\n", + " 5 # priority between 1(Highest) - 5(lowest)\n", + ")\n", + "\n", + "# Create a batch to send to you LIM project\n", + "batch_li = li_project.create_batch(\n", + " \"first-batch-LIM\", # Each batch in a project must have a unique name\n", + " batch_datarows, # A list of data rows or data row ids\n", + " 1 # priority between 1(Highest) - 5(lowest)\n", + ")\n", + "\n", + "# Setup your ontology / labeling editor\n", + "editor = next(client.get_labeling_frontends(where=LabelingFrontend.name == \"Editor\"))\n", + "# Connect your ontology and editor to your MAL and LI project\n", + "mal_project.setup(editor, ontology_builder.asdict())\n", + "li_project.setup(editor, ontology_builder.asdict())\n", + "\n", + "print(\"Batch Li: \", batch_li)\n", + "print(\"Batch Mal: \", batch_mal)" + ], + "metadata": { + "id": "yfNPsINLnPcO", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "f8e22b73-6f85-46e2-b618-bf37647fa4e6" + }, + "id": "yfNPsINLnPcO", + "execution_count": 7, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Batch Li: \n", + "Batch Mal: \n" + ] + } ] }, { @@ -310,8 +402,8 @@ "id": "8da94c48-72a5-4535-ab66-6d14b0b79aed" }, "source": [ - "### Create Label using Annotation Type Objects\n", - "* It is recommended to use the Python SDK's annotation types for importing into Labelbox." + "### Create labels using annotation type objects\n", + "* It is recommended to use the Python SDK's annotation types when importing labels into Labelbox." ] }, { @@ -326,12 +418,6 @@ }, { "cell_type": "code", - "execution_count": 33, - "id": "qzBqhV4Pv3yp", - "metadata": { - "id": "qzBqhV4Pv3yp" - }, - "outputs": [], "source": [ "point_annotation=ObjectAnnotation(\n", " value=Point(x=882,y=159), # Coordinates for this point annotation\n", @@ -376,7 +462,13 @@ " ),\n", " name=\"mask\" # Name of the tool in your ontology\n", ")" - ] + ], + "metadata": { + "id": "qzBqhV4Pv3yp" + }, + "id": "qzBqhV4Pv3yp", + "execution_count": 8, + "outputs": [] }, { "cell_type": "markdown", @@ -390,12 +482,6 @@ }, { "cell_type": "code", - "execution_count": 34, - "id": "f2RtQQPCymOB", - "metadata": { - "id": "f2RtQQPCymOB" - }, - "outputs": [], "source": [ "text_annotation=ClassificationAnnotation(\n", " value=Text( # String value for the text annotation\n", @@ -422,7 +508,13 @@ " ), \n", " name=\"radio\" # Name of the classification in your ontology\n", ")" - ] + ], + "metadata": { + "id": "f2RtQQPCymOB" + }, + "id": "f2RtQQPCymOB", + "execution_count": 9, + "outputs": [] }, { "cell_type": "markdown", @@ -431,48 +523,40 @@ "id": "15bd593b-509d-4114-af95-ae0be081c42d" }, "source": [ - "### Create a Label object with all of our annotations" + "### Create a Label object with all of the annotations created previously." ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 10, "id": "6d72fe25-ff7e-4e0a-94cf-095e4df73da0", "metadata": { + "id": "6d72fe25-ff7e-4e0a-94cf-095e4df73da0", "colab": { "base_uri": "https://localhost:8080/" }, - "id": "6d72fe25-ff7e-4e0a-94cf-095e4df73da0", - "outputId": "f9447913-c3ea-40c6-c1a4-449640add743" + "outputId": "304be251-ec7a-4e3f-972c-0df327650375" }, "outputs": [ { - "name": "stderr", - "output_type": "stream", - "text": [ - "/usr/local/lib/python3.7/dist-packages/labelbox/data/annotation_types/classification/classification.py:85: UserWarning: Dropdown classification is deprecated and will be removed in a future release\n", - " warnings.warn(\"Dropdown classification is deprecated and will be \"\n" - ] - }, - { + "output_type": "execute_result", "data": { "text/plain": [ - "{'annotations': [ObjectAnnotation(name='point', feature_schema_id=None, extra={}, value=Point(extra={}, x=882.0, y=159.0), classifications=[]),\n", + "{'uid': None,\n", + " 'data': ImageData(im_bytes=None,file_path=None,url=None,arr=None),\n", + " 'annotations': [ObjectAnnotation(name='point', feature_schema_id=None, extra={}, value=Point(extra={}, x=882.0, y=159.0), classifications=[]),\n", " ObjectAnnotation(name='box', feature_schema_id=None, extra={}, value=Rectangle(extra={}, start=Point(extra={}, x=557.0, y=898.0), end=Point(extra={}, x=852.0, y=1140.0)), classifications=[]),\n", " ObjectAnnotation(name='line', feature_schema_id=None, extra={}, value=Line(extra={}, points=[Point(extra={}, x=2534.353, y=249.471), Point(extra={}, x=2429.492, y=182.092), Point(extra={}, x=2294.322, y=221.962), Point(extra={}, x=2224.491, y=180.463), Point(extra={}, x=2136.123, y=204.716), Point(extra={}, x=1712.247, y=173.949), Point(extra={}, x=1703.838, y=84.438), Point(extra={}, x=1579.772, y=82.61), Point(extra={}, x=1583.442, y=167.552), Point(extra={}, x=1478.869, y=164.903), Point(extra={}, x=1418.941, y=318.149), Point(extra={}, x=1243.128, y=400.815), Point(extra={}, x=1022.067, y=319.007), Point(extra={}, x=892.367, y=379.216), Point(extra={}, x=670.273, y=364.408), Point(extra={}, x=613.114, y=288.16), Point(extra={}, x=377.559, y=238.251), Point(extra={}, x=368.087, y=185.064), Point(extra={}, x=246.557, y=167.286), Point(extra={}, x=236.648, y=285.61), Point(extra={}, x=90.929, y=326.412)]), classifications=[]),\n", " ObjectAnnotation(name='polygon', feature_schema_id=None, extra={}, value=Polygon(extra={}, points=[Point(extra={}, x=1489.581, y=183.934), Point(extra={}, x=2278.306, y=256.885), Point(extra={}, x=2428.197, y=200.437), Point(extra={}, x=2560.0, y=335.419), Point(extra={}, x=2557.386, y=503.165), Point(extra={}, x=2320.596, y=503.103), Point(extra={}, x=2156.083, y=628.943), Point(extra={}, x=2161.111, y=785.519), Point(extra={}, x=2002.115, y=894.647), Point(extra={}, x=1838.456, y=877.874), Point(extra={}, x=1436.53, y=874.636), Point(extra={}, x=1411.403, y=758.579), Point(extra={}, x=1353.853, y=751.74), Point(extra={}, x=1345.264, y=453.461), Point(extra={}, x=1426.011, y=421.129), Point(extra={}, x=1489.581, y=183.934)]), classifications=[]),\n", - " ObjectAnnotation(name='mask', feature_schema_id=None, extra={}, value=Mask(extra={}, mask=MaskData(im_bytes=None,file_path=None,url=https://storage.labelbox.com/cjhfn5y6s0pk507024nz1ocys%2F2ba259af-0914-adc4-7dce-d6ecf990ba12-1?Expires=1659035110433&KeyName=labelbox-assets-key-3&Signature=LVFadNLVlG1TzO0OuvSY7Qq72SM,arr=...), color=(0, 0, 0)), classifications=[]),\n", + " ObjectAnnotation(name='mask', feature_schema_id=None, extra={}, value=Mask(extra={}, mask=MaskData(im_bytes=None,file_path=None,url=https://storage.labelbox.com/cl3ahv73w1891087qbwzs3edd%2Ff9d14187-290c-722e-31d7-72d9af747f22-1?Expires=1667049180772&KeyName=labelbox-assets-key-3&Signature=B2NZmnrbARin5szWt5ge8pG1Wts,arr=...), color=(0, 0, 0)), classifications=[]),\n", " ClassificationAnnotation(name='text', feature_schema_id=None, extra={}, value=Text(answer='the answer to the text question')),\n", " ClassificationAnnotation(name='checklist', feature_schema_id=None, extra={}, value=Checklist(name='checklist', answer=[ClassificationAnswer(name='first_checklist_answer', feature_schema_id=None, extra={}, keyframe=None), ClassificationAnswer(name='second_checklist_answer', feature_schema_id=None, extra={}, keyframe=None)])),\n", " ClassificationAnnotation(name='radio', feature_schema_id=None, extra={}, value=Radio(answer=ClassificationAnswer(name='second_radio_answer', feature_schema_id=None, extra={}, keyframe=None)))],\n", - " 'data': ImageData(im_bytes=None,file_path=None,url=None,arr=None),\n", - " 'extra': {},\n", - " 'uid': None}" + " 'extra': {}}" ] }, - "execution_count": 35, "metadata": {}, - "output_type": "execute_result" + "execution_count": 10 } ], "source": [ @@ -525,43 +609,34 @@ }, { "cell_type": "code", - "execution_count": 16, - "id": "0U_cA2Cw0pH1", - "metadata": { - "id": "0U_cA2Cw0pH1" - }, - "outputs": [], - "source": [ - "import copy # We import this python package so we can create copies of our hard-coded annotations and upload one copy to each" - ] - }, - { - "cell_type": "code", - "execution_count": 39, + "execution_count": 11, "id": "53aaf87b-114f-4b56-a417-8c7cddc1f532", "metadata": { + "id": "53aaf87b-114f-4b56-a417-8c7cddc1f532", "colab": { "base_uri": "https://localhost:8080/" }, - "id": "53aaf87b-114f-4b56-a417-8c7cddc1f532", - "outputId": "e525feac-9f8e-49e7-95d0-33932998b0bd" + "outputId": "c4a8aeef-470c-4ef4-d5d5-e3160168164c" }, "outputs": [ { + "output_type": "execute_result", "data": { "text/plain": [ - "[{'classifications': [],\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", + "[{'uuid': '386e7306-aa6d-44eb-bb09-7492dbed72a1',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'},\n", " 'name': 'point',\n", - " 'point': {'x': 882.0, 'y': 159.0},\n", - " 'uuid': 'adbdf3bf-6474-4beb-8726-3ee4bb3a35af'},\n", - " {'bbox': {'height': 242.0, 'left': 557.0, 'top': 898.0, 'width': 295.0},\n", " 'classifications': [],\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", + " 'point': {'x': 882.0, 'y': 159.0}},\n", + " {'uuid': 'f92a31ce-1801-4cbc-837a-b6e45d106dc2',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'},\n", " 'name': 'box',\n", - " 'uuid': '29503cec-4a69-43d3-8ab1-64d6813d93d4'},\n", - " {'classifications': [],\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", + " 'classifications': [],\n", + " 'bbox': {'top': 898.0, 'left': 557.0, 'height': 242.0, 'width': 295.0}},\n", + " {'uuid': '59b9282b-ea5e-4242-b57f-0098c61bb15f',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'},\n", + " 'name': 'line',\n", + " 'classifications': [],\n", " 'line': [{'x': 2534.353, 'y': 249.471},\n", " {'x': 2429.492, 'y': 182.092},\n", " {'x': 2294.322, 'y': 221.962},\n", @@ -582,12 +657,11 @@ " {'x': 368.087, 'y': 185.064},\n", " {'x': 246.557, 'y': 167.286},\n", " {'x': 236.648, 'y': 285.61},\n", - " {'x': 90.929, 'y': 326.412}],\n", - " 'name': 'line',\n", - " 'uuid': 'c9221716-d76e-45ba-9983-cd09bded5909'},\n", - " {'classifications': [],\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", + " {'x': 90.929, 'y': 326.412}]},\n", + " {'uuid': '82fc4c39-2d3d-40fc-99e8-b2daa0853fe9',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'},\n", " 'name': 'polygon',\n", + " 'classifications': [],\n", " 'polygon': [{'x': 1489.581, 'y': 183.934},\n", " {'x': 2278.306, 'y': 256.885},\n", " {'x': 2428.197, 'y': 200.437},\n", @@ -603,46 +677,45 @@ " {'x': 1353.853, 'y': 751.74},\n", " {'x': 1345.264, 'y': 453.461},\n", " {'x': 1426.011, 'y': 421.129},\n", - " {'x': 1489.581, 'y': 183.934}],\n", - " 'uuid': '66d74cc3-e163-4bd9-a4cd-499c5b33b1fa'},\n", - " {'classifications': [],\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", - " 'mask': {'colorRGB': (0, 0, 0),\n", - " 'instanceURI': 'https://storage.labelbox.com/cjhfn5y6s0pk507024nz1ocys%2F2ba259af-0914-adc4-7dce-d6ecf990ba12-1?Expires=1659035110433&KeyName=labelbox-assets-key-3&Signature=LVFadNLVlG1TzO0OuvSY7Qq72SM'},\n", + " {'x': 1489.581, 'y': 183.934}]},\n", + " {'uuid': 'a4b82fe6-9aba-4dd1-87e7-3a6c3a909c67',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'},\n", " 'name': 'mask',\n", - " 'uuid': 'b5ead711-9fdc-4fe8-b563-7cffdfbd1f14'},\n", - " {'answer': 'the answer to the text question',\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", - " 'name': 'text',\n", - " 'uuid': 'd31cdf47-055f-42d2-860c-8deefb25647f'},\n", - " {'answer': [{'name': 'first_checklist_answer'},\n", - " {'name': 'second_checklist_answer'}],\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", - " 'name': 'checklist',\n", - " 'uuid': '9a851586-02fb-4894-ab72-f1967b00a6f9'},\n", - " {'answer': {'name': 'second_radio_answer'},\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", - " 'name': 'radio',\n", - " 'uuid': '7e92e01b-740d-48b4-935e-560ba0b63fa5'}]" + " 'classifications': [],\n", + " 'mask': {'instanceURI': 'https://storage.labelbox.com/cl3ahv73w1891087qbwzs3edd%2Ff9d14187-290c-722e-31d7-72d9af747f22-1?Expires=1667049180772&KeyName=labelbox-assets-key-3&Signature=B2NZmnrbARin5szWt5ge8pG1Wts',\n", + " 'colorRGB': (0, 0, 0)}},\n", + " {'name': 'text',\n", + " 'answer': 'the answer to the text question',\n", + " 'uuid': '8f6f4b70-61aa-4d50-999f-59b218e0ed31',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'}},\n", + " {'name': 'checklist',\n", + " 'uuid': 'b9651b71-fb6f-469c-979d-0998115e8fe3',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'},\n", + " 'answer': [{'name': 'first_checklist_answer'},\n", + " {'name': 'second_checklist_answer'}]},\n", + " {'name': 'radio',\n", + " 'answer': {'name': 'second_radio_answer'},\n", + " 'uuid': 'a3961f40-44e7-4c83-b35d-f1e65a2c567c',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'}}]" ] }, - "execution_count": 39, "metadata": {}, - "output_type": "execute_result" + "execution_count": 11 } ], "source": [ "# Make a copy of the label to upload to the MAL project\n", "mal_label = copy.deepcopy(label)\n", - "\n", + "## Create a list of labels\n", + "mal_label_list = [mal_label]\n", "# Convert our label from a Labelbox class object to the underlying NDJSON format required for upload - uploads can be directly built in this syntax as well\n", - "mal_ndjson = list(NDJsonConverter.serialize([mal_label]))\n", + "mal_ndjson = list(NDJsonConverter.serialize(mal_label_list))\n", "mal_ndjson" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 12, "id": "c66672c7-33e8-4d5d-b79d-2ac76d830341", "metadata": { "id": "c66672c7-33e8-4d5d-b79d-2ac76d830341" @@ -659,28 +732,28 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 13, "id": "2a8f9e5f-eeeb-4cfa-9b97-a09495a64d41", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "2a8f9e5f-eeeb-4cfa-9b97-a09495a64d41", - "outputId": "83237748-ede9-49fe-f0c2-5e046173ef17" + "outputId": "076963ad-209e-4ea6-aa0a-95a655387b12" }, "outputs": [ { - "name": "stdout", "output_type": "stream", + "name": "stdout", "text": [ "Errors: []\n" ] } ], "source": [ - "# Errors will appear for each annotation that failed.\n", - "# Empty list means that there were no errors\n", "# This will provide information only after the upload_job is complete, so we do not need to worry about having to rerun\n", + "upload_job.wait_until_done()\n", + "# Errors will appear for each annotation that failed.\n", "print(\"Errors:\", upload_job.errors)" ] }, @@ -701,36 +774,39 @@ "id": "9d4fa318-7d08-4d98-b0ff-e2086814d75d" }, "source": [ - "Label import is very similar to model-assisted labeling. We will create a Label called li_label which has the same original structure as the label above" + "Label import is very similar to model-assisted labeling. We will create a Label called li_label which has the same original structure as the label above. Remember that label imports will submit the labels in your project. " ] }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 14, "id": "e8d4e99b-ad7e-48b9-8073-afb764d7c5b4", "metadata": { + "id": "e8d4e99b-ad7e-48b9-8073-afb764d7c5b4", "colab": { "base_uri": "https://localhost:8080/" }, - "id": "e8d4e99b-ad7e-48b9-8073-afb764d7c5b4", - "outputId": "704fac54-8f45-46f0-ce2d-3769c5b11f23" + "outputId": "885fc6ba-0714-4fd9-a24c-e08acd0f7070" }, "outputs": [ { + "output_type": "execute_result", "data": { "text/plain": [ - "[{'classifications': [],\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", + "[{'uuid': '2fe442b9-655d-4667-bb5f-af3c2617ae75',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'},\n", " 'name': 'point',\n", - " 'point': {'x': 882.0, 'y': 159.0},\n", - " 'uuid': '078ba35d-733e-403f-9299-519685ef2998'},\n", - " {'bbox': {'height': 242.0, 'left': 557.0, 'top': 898.0, 'width': 295.0},\n", " 'classifications': [],\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", + " 'point': {'x': 882.0, 'y': 159.0}},\n", + " {'uuid': '1ff8243f-070e-4149-8392-5d80ac44644b',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'},\n", " 'name': 'box',\n", - " 'uuid': '1a4e8c0e-98e5-4adc-9723-552067e09d1c'},\n", - " {'classifications': [],\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", + " 'classifications': [],\n", + " 'bbox': {'top': 898.0, 'left': 557.0, 'height': 242.0, 'width': 295.0}},\n", + " {'uuid': 'b3c7e46e-c509-42d7-84af-548c2c287d67',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'},\n", + " 'name': 'line',\n", + " 'classifications': [],\n", " 'line': [{'x': 2534.353, 'y': 249.471},\n", " {'x': 2429.492, 'y': 182.092},\n", " {'x': 2294.322, 'y': 221.962},\n", @@ -751,12 +827,11 @@ " {'x': 368.087, 'y': 185.064},\n", " {'x': 246.557, 'y': 167.286},\n", " {'x': 236.648, 'y': 285.61},\n", - " {'x': 90.929, 'y': 326.412}],\n", - " 'name': 'line',\n", - " 'uuid': '4250dc8a-4d71-4b8a-a6c8-dc1197745afa'},\n", - " {'classifications': [],\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", + " {'x': 90.929, 'y': 326.412}]},\n", + " {'uuid': '8ef17595-d7c2-461d-922d-e2757869fc8b',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'},\n", " 'name': 'polygon',\n", + " 'classifications': [],\n", " 'polygon': [{'x': 1489.581, 'y': 183.934},\n", " {'x': 2278.306, 'y': 256.885},\n", " {'x': 2428.197, 'y': 200.437},\n", @@ -772,46 +847,47 @@ " {'x': 1353.853, 'y': 751.74},\n", " {'x': 1345.264, 'y': 453.461},\n", " {'x': 1426.011, 'y': 421.129},\n", - " {'x': 1489.581, 'y': 183.934}],\n", - " 'uuid': '997c1234-bda1-4226-9b1c-30fc468eb747'},\n", - " {'classifications': [],\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", - " 'mask': {'colorRGB': (0, 0, 0),\n", - " 'instanceURI': 'https://storage.labelbox.com/cjhfn5y6s0pk507024nz1ocys%2F2ba259af-0914-adc4-7dce-d6ecf990ba12-1?Expires=1659035110433&KeyName=labelbox-assets-key-3&Signature=LVFadNLVlG1TzO0OuvSY7Qq72SM'},\n", + " {'x': 1489.581, 'y': 183.934}]},\n", + " {'uuid': 'd3822d97-d565-448c-8ca3-f455d35d77f8',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'},\n", " 'name': 'mask',\n", - " 'uuid': '92ff52c8-7621-455f-b28f-a97fd06224b3'},\n", - " {'answer': 'the answer to the text question',\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", - " 'name': 'text',\n", - " 'uuid': '5d98f605-cf02-499f-9376-263f76ee7439'},\n", - " {'answer': [{'name': 'first_checklist_answer'},\n", - " {'name': 'second_checklist_answer'}],\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", - " 'name': 'checklist',\n", - " 'uuid': '74e4c460-f980-47a2-97eb-29cb2df107d4'},\n", - " {'answer': {'name': 'second_radio_answer'},\n", - " 'dataRow': {'id': 'cl63z7sm83xv608vs0bpjb51e'},\n", - " 'name': 'radio',\n", - " 'uuid': 'f413b3a2-1e71-473c-b3b0-c952791284df'}]" + " 'classifications': [],\n", + " 'mask': {'instanceURI': 'https://storage.labelbox.com/cl3ahv73w1891087qbwzs3edd%2Ff9d14187-290c-722e-31d7-72d9af747f22-1?Expires=1667049180772&KeyName=labelbox-assets-key-3&Signature=B2NZmnrbARin5szWt5ge8pG1Wts',\n", + " 'colorRGB': (0, 0, 0)}},\n", + " {'name': 'text',\n", + " 'answer': 'the answer to the text question',\n", + " 'uuid': '34f9f242-4e74-4ae8-a6dc-d2b19d2418f0',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'}},\n", + " {'name': 'checklist',\n", + " 'uuid': 'e72b6a24-c26e-488a-a439-49bd5a4888a8',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'},\n", + " 'answer': [{'name': 'first_checklist_answer'},\n", + " {'name': 'second_checklist_answer'}]},\n", + " {'name': 'radio',\n", + " 'answer': {'name': 'second_radio_answer'},\n", + " 'uuid': '89656338-80a3-4b65-8e0d-d4e2d7756872',\n", + " 'dataRow': {'id': 'cl9siksqy2pif07wfha2d3w54'}}]" ] }, - "execution_count": 36, "metadata": {}, - "output_type": "execute_result" + "execution_count": 14 } ], "source": [ "# Make a copy of the label to upload to the Label Import project\n", "li_label = copy.deepcopy(label)\n", "\n", + "## Create a label list \n", + "mal_label_list = [li_label]\n", + "\n", "# Convert our label from a Labelbox class object to the underlying NDJSON format required for upload - uploads can be directly built in this syntax as well\n", - "li_ndjson = list(NDJsonConverter.serialize([li_label]))\n", + "li_ndjson = list(NDJsonConverter.serialize(mal_label_list))\n", "li_ndjson" ] }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 15, "id": "e937ea0a-8beb-4dbc-974b-0316f0b980a5", "metadata": { "id": "e937ea0a-8beb-4dbc-974b-0316f0b980a5" @@ -819,45 +895,68 @@ "outputs": [], "source": [ "# Upload our label using Label Import\n", - "upload_job = LabelImport.create_from_objects(\n", - " client = client, \n", - " project_id = li_project.uid, \n", - " name=\"label_import_job\", \n", + "upload_job_li = LabelImport.create_from_objects(\n", + " client = client,\n", + " project_id = li_project.uid,\n", + " name=\"label_import_job\",\n", " labels=li_ndjson)" ] }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 16, "id": "3669b646-2d41-4c98-9e5b-f8ef3ce82f35", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "3669b646-2d41-4c98-9e5b-f8ef3ce82f35", - "outputId": "2545fd27-813f-41e3-bee3-7bb600c71c3a" + "outputId": "686a3edf-7479-4fb2-8226-20546eac8fa3" }, "outputs": [ { - "name": "stdout", "output_type": "stream", + "name": "stdout", "text": [ "Errors: []\n" ] } ], "source": [ - "# Errors will appear for each annotation that failed.\n", - "# Empty list means that there were no errors\n", "# This will provide information only after the upload_job is complete, so we do not need to worry about having to rerun\n", - "print(\"Errors:\", upload_job.errors)" + "upload_job_li.wait_until_done()\n", + "# Errors will appear for each annotation that failed.\n", + "print(\"Errors:\", upload_job_li.errors)" ] + }, + { + "cell_type": "markdown", + "source": [ + "## Cleanup " + ], + "metadata": { + "id": "OhgYk6byutP4" + }, + "id": "OhgYk6byutP4" + }, + { + "cell_type": "code", + "source": [ + "# mal_project.delete()\n", + "# li_project.delete()\n", + "# dataset.delete()" + ], + "metadata": { + "id": "_9FDSkrhur2q" + }, + "id": "_9FDSkrhur2q", + "execution_count": 17, + "outputs": [] } ], "metadata": { "colab": { "collapsed_sections": [], - "name": "image_annotation_import.ipynb", "provenance": [] }, "kernelspec": { From 17e2ac28d5a6813d6aaf90a5d5a8642457205f52 Mon Sep 17 00:00:00 2001 From: Andrea Ovalle <74880762+ovalle15@users.noreply.github.com> Date: Tue, 1 Nov 2022 14:49:19 -0400 Subject: [PATCH 2/2] Latest updates 1. Clean up imports 2. Fix name of label import 3. other small issues. --- examples/annotation_import/image.ipynb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/annotation_import/image.ipynb b/examples/annotation_import/image.ipynb index 23d6cd9f1..5a74bbc3e 100644 --- a/examples/annotation_import/image.ipynb +++ b/examples/annotation_import/image.ipynb @@ -128,12 +128,10 @@ " Label, ImageData, ObjectAnnotation, MaskData,\n", " Rectangle, Point, Line, Mask, Polygon,\n", " Radio, Checklist, Text,\n", - " ClassificationAnnotation, ClassificationAnswer, LabelList\n", + " ClassificationAnnotation, ClassificationAnswer\n", ")\n", "from labelbox.data.serialization import NDJsonConverter\n", - "import uuid\n", "import json\n", - "import numpy as np\n", "import uuid\n", "import copy\n", "print(labelbox.__version__)" @@ -878,10 +876,10 @@ "li_label = copy.deepcopy(label)\n", "\n", "## Create a label list \n", - "mal_label_list = [li_label]\n", + "li_label_list = [li_label]\n", "\n", "# Convert our label from a Labelbox class object to the underlying NDJSON format required for upload - uploads can be directly built in this syntax as well\n", - "li_ndjson = list(NDJsonConverter.serialize(mal_label_list))\n", + "li_ndjson = list(NDJsonConverter.serialize(li_label_list))\n", "li_ndjson" ] },