From 973895d4692336c8d1e288b307bddd1049047ac7 Mon Sep 17 00:00:00 2001 From: Andrea Ovalle <74880762+ovalle15@users.noreply.github.com> Date: Wed, 25 Jan 2023 17:11:28 -0500 Subject: [PATCH 1/5] Updates from ImageData to TextData, 1. Replace ImageData with TextData 2. Remove additional import (ImageData) 3. Removed URL signing function All has been tested ! --- examples/annotation_import/text.ipynb | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/examples/annotation_import/text.ipynb b/examples/annotation_import/text.ipynb index c4d08f679..bf4ba6e24 100644 --- a/examples/annotation_import/text.ipynb +++ b/examples/annotation_import/text.ipynb @@ -124,7 +124,7 @@ "from labelbox.schema.queue_mode import QueueMode\n", "from labelbox.data.annotation_types import (\n", " Label, TextData, Checklist, Radio, ObjectAnnotation, TextEntity,\n", - " ClassificationAnnotation, ClassificationAnswer, LabelList, Text, ImageData\n", + " ClassificationAnnotation, ClassificationAnswer, LabelList, Text \n", ")\n", "from labelbox.data.serialization import NDJsonConverter\n", "import uuid\n", @@ -593,7 +593,7 @@ "source": [ "# Create a Label\n", "label = Label(\n", - " data=ImageData(\n", + " data=TextData(\n", " uid=data_row.uid),\n", " annotations = [\n", " named_entitity_annotation, \n", @@ -605,13 +605,6 @@ ")\n", "\n", "\n", - "# Create urls to mask data for upload\n", - "def signing_function(obj_bytes: bytes) -> str:\n", - " url = client.upload_data(content=obj_bytes, sign=True)\n", - " return url \n", - "\n", - "label.add_url_to_masks(signing_function)\n", - "\n", "# Convert our label from a Labelbox class object to the underlying NDJSON format required for upload \n", "label_ndjson = list(NDJsonConverter.serialize([label]))" ] From 9f3ade64a2853e0ad33d64060a84a5cf9cbe7bcd Mon Sep 17 00:00:00 2001 From: Andrea Ovalle <74880762+ovalle15@users.noreply.github.com> Date: Thu, 26 Jan 2023 12:52:47 -0500 Subject: [PATCH 2/5] Removed nested classifications for python annotation tools --- examples/annotation_import/text.ipynb | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/examples/annotation_import/text.ipynb b/examples/annotation_import/text.ipynb index bf4ba6e24..fa24a611f 100644 --- a/examples/annotation_import/text.ipynb +++ b/examples/annotation_import/text.ipynb @@ -232,20 +232,7 @@ { "cell_type": "code", "source": [ - "########## Classification - Radio (with subclassifcations) ##########\n", - "\n", - "# Python annotation\n", - "radio_annotation_nested = ClassificationAnnotation(\n", - " name=\"radio_question_sub\", \n", - " value=Radio(answer = ClassificationAnswer(name = \"first_radio_answer\")),\n", - " classifications=[\n", - " \tClassificationAnnotation(\n", - " \tname=\"sub_radio_question\",\n", - " \t\tvalue=Radio(answer=ClassificationAnswer(name=\"first_sub_radio_answer\"))\n", - " )\n", - " ]\n", - ")\n", - "\n", + "########## Nested Classifications are only supported with NDJSON tools ##########\n", "\n", "# NDJSON\n", "radio_annotation_ndjson_with_subclass = {\n", From 44061677a7a77280745e1103ae77e4f96b2a5f7a Mon Sep 17 00:00:00 2001 From: Andrea Ovalle <74880762+ovalle15@users.noreply.github.com> Date: Thu, 26 Jan 2023 12:58:20 -0500 Subject: [PATCH 3/5] Removed nested python annotation during label creation --- examples/annotation_import/text.ipynb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/annotation_import/text.ipynb b/examples/annotation_import/text.ipynb index fa24a611f..2d69cfc25 100644 --- a/examples/annotation_import/text.ipynb +++ b/examples/annotation_import/text.ipynb @@ -586,8 +586,7 @@ " named_entitity_annotation, \n", " radio_annotation, \n", " checklist_annotation, \n", - " text_annotation, \n", - " radio_annotation_nested \n", + " text_annotation \n" " ]\n", ")\n", "\n", From c9e591f463c49cd48d2b3d6ac571dd126550e188 Mon Sep 17 00:00:00 2001 From: Andrea Ovalle <74880762+ovalle15@users.noreply.github.com> Date: Thu, 26 Jan 2023 14:11:04 -0500 Subject: [PATCH 4/5] Added media type text to ontology --- examples/annotation_import/text.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/annotation_import/text.ipynb b/examples/annotation_import/text.ipynb index 2d69cfc25..1c1db7cbf 100644 --- a/examples/annotation_import/text.ipynb +++ b/examples/annotation_import/text.ipynb @@ -440,7 +440,7 @@ " ]\n", ")\n", "\n", - "ontology = client.create_ontology(\"Ontology Text Annotations\", ontology_builder.asdict())\n" + "ontology = client.create_ontology(\"Ontology Text Annotations\", ontology_builder.asdict(), media_type=MediaType.Text)\n" ], "metadata": { "id": "_wWxYFoDTsar" From ce1187eccaa7c8435fb12e363814b70ff2bb49ce Mon Sep 17 00:00:00 2001 From: Andrea Ovalle <74880762+ovalle15@users.noreply.github.com> Date: Mon, 30 Jan 2023 13:08:04 -0500 Subject: [PATCH 5/5] Final updates --- examples/annotation_import/text.ipynb | 97 +++++++++++++-------------- 1 file changed, 45 insertions(+), 52 deletions(-) diff --git a/examples/annotation_import/text.ipynb b/examples/annotation_import/text.ipynb index 1c1db7cbf..1ffa020b5 100644 --- a/examples/annotation_import/text.ipynb +++ b/examples/annotation_import/text.ipynb @@ -86,33 +86,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "id": "4d63074b-2379-48af-b9d6-2a66190f03c4", "metadata": { - "id": "4d63074b-2379-48af-b9d6-2a66190f03c4", - "colab": { - "base_uri": "https://localhost:8080/" - }, - "outputId": "0b4547c9-e534-441d-9bf6-7588ee50c8a2" + "id": "4d63074b-2379-48af-b9d6-2a66190f03c4" }, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "\u001b[K |████████████████████████████████| 184 kB 5.2 MB/s \n", - "\u001b[K |████████████████████████████████| 7.8 MB 45.4 MB/s \n", - "\u001b[?25h Building wheel for pygeotile (setup.py) ... \u001b[?25l\u001b[?25hdone\n" - ] - } - ], + "outputs": [], "source": [ "!pip install -q 'labelbox[data]'" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "id": "01fca8c9-0680-4a9c-a11e-1b49f31e9121", "metadata": { "id": "01fca8c9-0680-4a9c-a11e-1b49f31e9121" @@ -124,7 +110,7 @@ "from labelbox.schema.queue_mode import QueueMode\n", "from labelbox.data.annotation_types import (\n", " Label, TextData, Checklist, Radio, ObjectAnnotation, TextEntity,\n", - " ClassificationAnnotation, ClassificationAnswer, LabelList, Text \n", + " ClassificationAnnotation, ClassificationAnswer, LabelList, Text, ImageData\n", ")\n", "from labelbox.data.serialization import NDJsonConverter\n", "import uuid\n", @@ -144,7 +130,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "id": "86003724-4807-4281-95c1-5284a6f9609f", "metadata": { "id": "86003724-4807-4281-95c1-5284a6f9609f" @@ -199,7 +185,7 @@ "id": "Z5ORHD1pZKt1" }, "id": "Z5ORHD1pZKt1", - "execution_count": null, + "execution_count": 39, "outputs": [] }, { @@ -226,13 +212,13 @@ "id": "mrPJ1Ko0ZMdl" }, "id": "mrPJ1Ko0ZMdl", - "execution_count": null, + "execution_count": 40, "outputs": [] }, { "cell_type": "code", "source": [ - "########## Nested Classifications are only supported with NDJSON tools ##########\n", + "########## Classification - Radio (with subclassifcations) is only suppported with NDJSON tools ##########\n", "\n", "# NDJSON\n", "radio_annotation_ndjson_with_subclass = {\n", @@ -250,7 +236,7 @@ "id": "vt7QvfV7ZPAF" }, "id": "vt7QvfV7ZPAF", - "execution_count": null, + "execution_count": 41, "outputs": [] }, { @@ -283,12 +269,12 @@ "id": "45BDh768ZYsH" }, "id": "45BDh768ZYsH", - "execution_count": null, + "execution_count": 42, "outputs": [] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "id": "f9f9287c-aad7-4914-bc87-1453fb8bce81", "metadata": { "id": "f9f9287c-aad7-4914-bc87-1453fb8bce81" @@ -351,27 +337,27 @@ "base_uri": "https://localhost:8080/" }, "id": "Ak-jnABK3OPH", - "outputId": "ff481cce-af08-4748-e8ac-a959085e07de" + "outputId": "0f80ba52-adde-4d97-d04a-fcdbe4d1a414" }, "id": "Ak-jnABK3OPH", - "execution_count": null, + "execution_count": 44, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "\n", - "clbzkhbxy18ws07ysdumbbgnq\n" + "cldj4gyf60fy207xh3z1y2g1h\n" ] } ] @@ -382,7 +368,7 @@ "### Step 2: Create/select an ontology\n", "Your project should have the correct ontology setup with all the tools and classifications supported for your annotations, and the tool names and classification instructions should match the `name`/`instructions` fields in your annotations to ensure the correct feature schemas are matched.\n", "\n", - "For example, when we create the checklist annotation [above](https://colab.research.google.com/drive/1mXfgydXxVR2OMAjJo1nj2EU9QQyVhW90#scrollTo=45BDh768ZYsH&line=1&uniqifier=1), we provided the `name` as `checklist_question`. Now, when we setup our ontology, we must ensure that the name of my classification tool is also `checklist_question`. The same alignment must hold true for the other tools and classifications we create in our ontology.\n", + "For example, when we create the checklist annotation above, we provided the `name` as `checklist_question`. Now, when we setup our ontology, we must ensure that the name of my classification tool is also `checklist_question`. The same alignment must hold true for the other tools and classifications we create in our ontology.\n", "\n", "[Documentation for reference ](https://docs.labelbox.com/reference/import-text-annotations)" ], @@ -440,13 +426,13 @@ " ]\n", ")\n", "\n", - "ontology = client.create_ontology(\"Ontology Text Annotations\", ontology_builder.asdict(), media_type=MediaType.Text)\n" + "ontology = client.create_ontology(\"Ontology Text Annotations\", ontology_builder.asdict())\n" ], "metadata": { "id": "_wWxYFoDTsar" }, "id": "_wWxYFoDTsar", - "execution_count": null, + "execution_count": 45, "outputs": [] }, { @@ -462,7 +448,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "id": "044e9194-d21d-403e-b64c-047c1063b0fe", "metadata": { "id": "044e9194-d21d-403e-b64c-047c1063b0fe" @@ -524,10 +510,10 @@ "colab": { "base_uri": "https://localhost:8080/" }, - "outputId": "153857ae-455d-4c7c-fb36-40fc16dc0819" + "outputId": "6eb66aad-477d-490e-ea91-53de995f1f65" }, "id": "DbwheC8RzI-0", - "execution_count": null, + "execution_count": 47, "outputs": [ { "output_type": "stream", @@ -535,11 +521,11 @@ "text": [ "Batch: \n" ] } @@ -562,7 +548,7 @@ { "cell_type": "markdown", "source": [ - "#### Python Annotations" + "#### Python annotations" ], "metadata": { "id": "7IgSl5SxcO4R" @@ -571,7 +557,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "id": "53aaf87b-114f-4b56-a417-8c7cddc1f532", "metadata": { "id": "53aaf87b-114f-4b56-a417-8c7cddc1f532" @@ -580,17 +566,24 @@ "source": [ "# Create a Label\n", "label = Label(\n", - " data=TextData(\n", + " data=ImageData(\n", " uid=data_row.uid),\n", " annotations = [\n", " named_entitity_annotation, \n", " radio_annotation, \n", " checklist_annotation, \n", - " text_annotation \n" + " text_annotation\n", " ]\n", ")\n", "\n", "\n", + "# Create urls to mask data for upload\n", + "def signing_function(obj_bytes: bytes) -> str:\n", + " url = client.upload_data(content=obj_bytes, sign=True)\n", + " return url \n", + "\n", + "label.add_url_to_masks(signing_function)\n", + "\n", "# Convert our label from a Labelbox class object to the underlying NDJSON format required for upload \n", "label_ndjson = list(NDJsonConverter.serialize([label]))" ] @@ -607,7 +600,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "id": "c66672c7-33e8-4d5d-b79d-2ac76d830341", "metadata": { "id": "c66672c7-33e8-4d5d-b79d-2ac76d830341" @@ -672,10 +665,10 @@ "base_uri": "https://localhost:8080/" }, "id": "izli4zhEfi75", - "outputId": "b1cdc2d0-9541-4df2-d922-be0a7ce80499" + "outputId": "4eb1b790-4e60-4cc6-9224-de6a9ed339bf" }, "id": "izli4zhEfi75", - "execution_count": null, + "execution_count": 50, "outputs": [ { "output_type": "stream", @@ -699,14 +692,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "id": "e8d4e99b-ad7e-48b9-8073-afb764d7c5b4", "metadata": { "id": "e8d4e99b-ad7e-48b9-8073-afb764d7c5b4", "colab": { "base_uri": "https://localhost:8080/" }, - "outputId": "be9df775-f18c-44ed-e02e-82b3c2a3691f" + "outputId": "1e52b23b-cefc-439b-f374-2e8b886280f4" }, "outputs": [ { @@ -749,7 +742,7 @@ "id": "ubbraAmo2_fe" }, "id": "ubbraAmo2_fe", - "execution_count": null, + "execution_count": 52, "outputs": [] } ],