|
86 | 86 | }, |
87 | 87 | { |
88 | 88 | "cell_type": "code", |
89 | | - "execution_count": null, |
| 89 | + "execution_count": 36, |
90 | 90 | "id": "4d63074b-2379-48af-b9d6-2a66190f03c4", |
91 | 91 | "metadata": { |
92 | | - "id": "4d63074b-2379-48af-b9d6-2a66190f03c4", |
93 | | - "colab": { |
94 | | - "base_uri": "https://localhost:8080/" |
95 | | - }, |
96 | | - "outputId": "0b4547c9-e534-441d-9bf6-7588ee50c8a2" |
| 92 | + "id": "4d63074b-2379-48af-b9d6-2a66190f03c4" |
97 | 93 | }, |
98 | | - "outputs": [ |
99 | | - { |
100 | | - "output_type": "stream", |
101 | | - "name": "stdout", |
102 | | - "text": [ |
103 | | - "\u001b[K |████████████████████████████████| 184 kB 5.2 MB/s \n", |
104 | | - "\u001b[K |████████████████████████████████| 7.8 MB 45.4 MB/s \n", |
105 | | - "\u001b[?25h Building wheel for pygeotile (setup.py) ... \u001b[?25l\u001b[?25hdone\n" |
106 | | - ] |
107 | | - } |
108 | | - ], |
| 94 | + "outputs": [], |
109 | 95 | "source": [ |
110 | 96 | "!pip install -q 'labelbox[data]'" |
111 | 97 | ] |
112 | 98 | }, |
113 | 99 | { |
114 | 100 | "cell_type": "code", |
115 | | - "execution_count": null, |
| 101 | + "execution_count": 37, |
116 | 102 | "id": "01fca8c9-0680-4a9c-a11e-1b49f31e9121", |
117 | 103 | "metadata": { |
118 | 104 | "id": "01fca8c9-0680-4a9c-a11e-1b49f31e9121" |
|
124 | 110 | "from labelbox.schema.queue_mode import QueueMode\n", |
125 | 111 | "from labelbox.data.annotation_types import (\n", |
126 | 112 | " Label, TextData, Checklist, Radio, ObjectAnnotation, TextEntity,\n", |
127 | | - " ClassificationAnnotation, ClassificationAnswer, LabelList, Text \n", |
| 113 | + " ClassificationAnnotation, ClassificationAnswer, LabelList, Text, ImageData\n", |
128 | 114 | ")\n", |
129 | 115 | "from labelbox.data.serialization import NDJsonConverter\n", |
130 | 116 | "import uuid\n", |
|
144 | 130 | }, |
145 | 131 | { |
146 | 132 | "cell_type": "code", |
147 | | - "execution_count": null, |
| 133 | + "execution_count": 38, |
148 | 134 | "id": "86003724-4807-4281-95c1-5284a6f9609f", |
149 | 135 | "metadata": { |
150 | 136 | "id": "86003724-4807-4281-95c1-5284a6f9609f" |
|
199 | 185 | "id": "Z5ORHD1pZKt1" |
200 | 186 | }, |
201 | 187 | "id": "Z5ORHD1pZKt1", |
202 | | - "execution_count": null, |
| 188 | + "execution_count": 39, |
203 | 189 | "outputs": [] |
204 | 190 | }, |
205 | 191 | { |
|
226 | 212 | "id": "mrPJ1Ko0ZMdl" |
227 | 213 | }, |
228 | 214 | "id": "mrPJ1Ko0ZMdl", |
229 | | - "execution_count": null, |
| 215 | + "execution_count": 40, |
230 | 216 | "outputs": [] |
231 | 217 | }, |
232 | 218 | { |
233 | 219 | "cell_type": "code", |
234 | 220 | "source": [ |
235 | | - "########## Nested Classifications are only supported with NDJSON tools ##########\n", |
| 221 | + "########## Classification - Radio (with subclassifcations) is only suppported with NDJSON tools ##########\n", |
236 | 222 | "\n", |
237 | 223 | "# NDJSON\n", |
238 | 224 | "radio_annotation_ndjson_with_subclass = {\n", |
|
250 | 236 | "id": "vt7QvfV7ZPAF" |
251 | 237 | }, |
252 | 238 | "id": "vt7QvfV7ZPAF", |
253 | | - "execution_count": null, |
| 239 | + "execution_count": 41, |
254 | 240 | "outputs": [] |
255 | 241 | }, |
256 | 242 | { |
|
283 | 269 | "id": "45BDh768ZYsH" |
284 | 270 | }, |
285 | 271 | "id": "45BDh768ZYsH", |
286 | | - "execution_count": null, |
| 272 | + "execution_count": 42, |
287 | 273 | "outputs": [] |
288 | 274 | }, |
289 | 275 | { |
290 | 276 | "cell_type": "code", |
291 | | - "execution_count": null, |
| 277 | + "execution_count": 43, |
292 | 278 | "id": "f9f9287c-aad7-4914-bc87-1453fb8bce81", |
293 | 279 | "metadata": { |
294 | 280 | "id": "f9f9287c-aad7-4914-bc87-1453fb8bce81" |
|
351 | 337 | "base_uri": "https://localhost:8080/" |
352 | 338 | }, |
353 | 339 | "id": "Ak-jnABK3OPH", |
354 | | - "outputId": "ff481cce-af08-4748-e8ac-a959085e07de" |
| 340 | + "outputId": "0f80ba52-adde-4d97-d04a-fcdbe4d1a414" |
355 | 341 | }, |
356 | 342 | "id": "Ak-jnABK3OPH", |
357 | | - "execution_count": null, |
| 343 | + "execution_count": 44, |
358 | 344 | "outputs": [ |
359 | 345 | { |
360 | 346 | "output_type": "stream", |
361 | 347 | "name": "stdout", |
362 | 348 | "text": [ |
363 | 349 | "<DataRow {\n", |
364 | | - " \"created_at\": \"2022-12-22 20:59:28+00:00\",\n", |
| 350 | + " \"created_at\": \"2023-01-30 18:06:23+00:00\",\n", |
365 | 351 | " \"external_id\": null,\n", |
366 | | - " \"global_key\": \"TEST-ID-190217471490724126308456269288159181446d\",\n", |
| 352 | + " \"global_key\": \"TEST-ID-321668750509639104503407808903937477958d\",\n", |
367 | 353 | " \"media_attributes\": {},\n", |
368 | 354 | " \"metadata\": [],\n", |
369 | 355 | " \"metadata_fields\": [],\n", |
370 | 356 | " \"row_data\": \"https://storage.googleapis.com/labelbox-sample-datasets/nlp/lorem-ipsum.txt\",\n", |
371 | | - " \"uid\": \"clbzkhbxy18ws07ysdumbbgnq\",\n", |
372 | | - " \"updated_at\": \"2022-12-22 20:59:28+00:00\"\n", |
| 357 | + " \"uid\": \"cldj4gyf60fy207xh3z1y2g1h\",\n", |
| 358 | + " \"updated_at\": \"2023-01-30 18:06:23+00:00\"\n", |
373 | 359 | "}>\n", |
374 | | - "clbzkhbxy18ws07ysdumbbgnq\n" |
| 360 | + "cldj4gyf60fy207xh3z1y2g1h\n" |
375 | 361 | ] |
376 | 362 | } |
377 | 363 | ] |
|
382 | 368 | "### Step 2: Create/select an ontology\n", |
383 | 369 | "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", |
384 | 370 | "\n", |
385 | | - "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", |
| 371 | + "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", |
386 | 372 | "\n", |
387 | 373 | "[Documentation for reference ](https://docs.labelbox.com/reference/import-text-annotations)" |
388 | 374 | ], |
|
440 | 426 | " ]\n", |
441 | 427 | ")\n", |
442 | 428 | "\n", |
443 | | - "ontology = client.create_ontology(\"Ontology Text Annotations\", ontology_builder.asdict(), media_type=MediaType.Text)\n" |
| 429 | + "ontology = client.create_ontology(\"Ontology Text Annotations\", ontology_builder.asdict())\n" |
444 | 430 | ], |
445 | 431 | "metadata": { |
446 | 432 | "id": "_wWxYFoDTsar" |
447 | 433 | }, |
448 | 434 | "id": "_wWxYFoDTsar", |
449 | | - "execution_count": null, |
| 435 | + "execution_count": 45, |
450 | 436 | "outputs": [] |
451 | 437 | }, |
452 | 438 | { |
|
462 | 448 | }, |
463 | 449 | { |
464 | 450 | "cell_type": "code", |
465 | | - "execution_count": null, |
| 451 | + "execution_count": 46, |
466 | 452 | "id": "044e9194-d21d-403e-b64c-047c1063b0fe", |
467 | 453 | "metadata": { |
468 | 454 | "id": "044e9194-d21d-403e-b64c-047c1063b0fe" |
|
524 | 510 | "colab": { |
525 | 511 | "base_uri": "https://localhost:8080/" |
526 | 512 | }, |
527 | | - "outputId": "153857ae-455d-4c7c-fb36-40fc16dc0819" |
| 513 | + "outputId": "6eb66aad-477d-490e-ea91-53de995f1f65" |
528 | 514 | }, |
529 | 515 | "id": "DbwheC8RzI-0", |
530 | | - "execution_count": null, |
| 516 | + "execution_count": 47, |
531 | 517 | "outputs": [ |
532 | 518 | { |
533 | 519 | "output_type": "stream", |
534 | 520 | "name": "stdout", |
535 | 521 | "text": [ |
536 | 522 | "Batch: <Batch {\n", |
537 | 523 | " \"consensus_settings_json\": \"{\\\"numberOfLabels\\\":1,\\\"coveragePercentage\\\":0}\",\n", |
538 | | - " \"created_at\": \"2022-12-22 20:59:51+00:00\",\n", |
| 524 | + " \"created_at\": \"2023-01-30 18:06:28+00:00\",\n", |
539 | 525 | " \"name\": \"first-batch-text-demo\",\n", |
540 | 526 | " \"size\": 1,\n", |
541 | | - " \"uid\": \"94297660-823b-11ed-8039-c1b641c04d88\",\n", |
542 | | - " \"updated_at\": \"2022-12-22 20:59:51+00:00\"\n", |
| 527 | + " \"uid\": \"d14be9f0-a0c8-11ed-a7e5-f9da6146996d\",\n", |
| 528 | + " \"updated_at\": \"2023-01-30 18:06:28+00:00\"\n", |
543 | 529 | "}>\n" |
544 | 530 | ] |
545 | 531 | } |
|
562 | 548 | { |
563 | 549 | "cell_type": "markdown", |
564 | 550 | "source": [ |
565 | | - "#### Python Annotations" |
| 551 | + "#### Python annotations" |
566 | 552 | ], |
567 | 553 | "metadata": { |
568 | 554 | "id": "7IgSl5SxcO4R" |
|
571 | 557 | }, |
572 | 558 | { |
573 | 559 | "cell_type": "code", |
574 | | - "execution_count": null, |
| 560 | + "execution_count": 48, |
575 | 561 | "id": "53aaf87b-114f-4b56-a417-8c7cddc1f532", |
576 | 562 | "metadata": { |
577 | 563 | "id": "53aaf87b-114f-4b56-a417-8c7cddc1f532" |
|
580 | 566 | "source": [ |
581 | 567 | "# Create a Label\n", |
582 | 568 | "label = Label(\n", |
583 | | - " data=TextData(\n", |
| 569 | + " data=ImageData(\n", |
584 | 570 | " uid=data_row.uid),\n", |
585 | 571 | " annotations = [\n", |
586 | 572 | " named_entitity_annotation, \n", |
587 | 573 | " radio_annotation, \n", |
588 | 574 | " checklist_annotation, \n", |
589 | | - " text_annotation \n" |
| 575 | + " text_annotation\n", |
590 | 576 | " ]\n", |
591 | 577 | ")\n", |
592 | 578 | "\n", |
593 | 579 | "\n", |
| 580 | + "# Create urls to mask data for upload\n", |
| 581 | + "def signing_function(obj_bytes: bytes) -> str:\n", |
| 582 | + " url = client.upload_data(content=obj_bytes, sign=True)\n", |
| 583 | + " return url \n", |
| 584 | + "\n", |
| 585 | + "label.add_url_to_masks(signing_function)\n", |
| 586 | + "\n", |
594 | 587 | "# Convert our label from a Labelbox class object to the underlying NDJSON format required for upload \n", |
595 | 588 | "label_ndjson = list(NDJsonConverter.serialize([label]))" |
596 | 589 | ] |
|
607 | 600 | }, |
608 | 601 | { |
609 | 602 | "cell_type": "code", |
610 | | - "execution_count": null, |
| 603 | + "execution_count": 49, |
611 | 604 | "id": "c66672c7-33e8-4d5d-b79d-2ac76d830341", |
612 | 605 | "metadata": { |
613 | 606 | "id": "c66672c7-33e8-4d5d-b79d-2ac76d830341" |
|
672 | 665 | "base_uri": "https://localhost:8080/" |
673 | 666 | }, |
674 | 667 | "id": "izli4zhEfi75", |
675 | | - "outputId": "b1cdc2d0-9541-4df2-d922-be0a7ce80499" |
| 668 | + "outputId": "4eb1b790-4e60-4cc6-9224-de6a9ed339bf" |
676 | 669 | }, |
677 | 670 | "id": "izli4zhEfi75", |
678 | | - "execution_count": null, |
| 671 | + "execution_count": 50, |
679 | 672 | "outputs": [ |
680 | 673 | { |
681 | 674 | "output_type": "stream", |
|
699 | 692 | }, |
700 | 693 | { |
701 | 694 | "cell_type": "code", |
702 | | - "execution_count": null, |
| 695 | + "execution_count": 51, |
703 | 696 | "id": "e8d4e99b-ad7e-48b9-8073-afb764d7c5b4", |
704 | 697 | "metadata": { |
705 | 698 | "id": "e8d4e99b-ad7e-48b9-8073-afb764d7c5b4", |
706 | 699 | "colab": { |
707 | 700 | "base_uri": "https://localhost:8080/" |
708 | 701 | }, |
709 | | - "outputId": "be9df775-f18c-44ed-e02e-82b3c2a3691f" |
| 702 | + "outputId": "1e52b23b-cefc-439b-f374-2e8b886280f4" |
710 | 703 | }, |
711 | 704 | "outputs": [ |
712 | 705 | { |
|
749 | 742 | "id": "ubbraAmo2_fe" |
750 | 743 | }, |
751 | 744 | "id": "ubbraAmo2_fe", |
752 | | - "execution_count": null, |
| 745 | + "execution_count": 52, |
753 | 746 | "outputs": [] |
754 | 747 | } |
755 | 748 | ], |
|
0 commit comments