|
46 | 46 | }, |
47 | 47 | { |
48 | 48 | "cell_type": "code", |
49 | | - "execution_count": null, |
| 49 | + "execution_count": 1, |
50 | 50 | "id": "improving-demonstration", |
51 | 51 | "metadata": {}, |
52 | 52 | "outputs": [], |
53 | | - "source": [ |
54 | | - "!pip install \"labelbox[data]\"" |
55 | | - ] |
| 53 | + "source": "!pip install \"labelbox[data]\"" |
56 | 54 | }, |
57 | 55 | { |
58 | 56 | "cell_type": "code", |
59 | | - "execution_count": 1, |
| 57 | + "execution_count": 2, |
60 | 58 | "id": "acute-serve", |
61 | 59 | "metadata": {}, |
62 | 60 | "outputs": [], |
63 | | - "source": [ |
64 | | - "from labelbox.data.annotation_types import (\n", |
65 | | - " LabelList, \n", |
66 | | - " Label, \n", |
67 | | - " Rectangle, \n", |
68 | | - " Point, \n", |
69 | | - " ObjectAnnotation, \n", |
70 | | - " Geometry\n", |
71 | | - ")\n", |
72 | | - "from labelbox.data.serialization import LBV1Converter, NDJsonConverter\n", |
73 | | - "from labelbox import Client\n", |
74 | | - "\n", |
75 | | - "import IPython\n", |
76 | | - "import numpy as np\n", |
77 | | - "from PIL import Image\n", |
78 | | - "from getpass import getpass\n", |
79 | | - "import os\n", |
80 | | - "import cv2" |
81 | | - ] |
| 61 | + "source": "from labelbox.data.annotation_types import (LabelList, Label, Rectangle, Point,\n ObjectAnnotation, Geometry)\nfrom labelbox.data.serialization import LBV1Converter, NDJsonConverter\nfrom labelbox import Client\n\nimport IPython\nimport numpy as np\nfrom PIL import Image\nfrom getpass import getpass\nimport os\nimport cv2" |
82 | 62 | }, |
83 | 63 | { |
84 | 64 | "cell_type": "code", |
85 | | - "execution_count": 2, |
| 65 | + "execution_count": 3, |
86 | 66 | "id": "psychological-airfare", |
87 | 67 | "metadata": {}, |
88 | 68 | "outputs": [], |
89 | | - "source": [ |
90 | | - "# If you don't want to give google access to drive you can skip this cell\n", |
91 | | - "# and manually set `API_KEY` below.\n", |
92 | | - "COLAB = \"google.colab\" in str(get_ipython())\n", |
93 | | - "if COLAB:\n", |
94 | | - " !pip install colab-env -qU\n", |
95 | | - " from colab_env import envvar_handler\n", |
96 | | - " envvar_handler.envload()\n", |
97 | | - "\n", |
98 | | - "API_KEY = os.environ.get(\"LABELBOX_API_KEY\")\n", |
99 | | - "if not os.environ.get(\"LABELBOX_API_KEY\"):\n", |
100 | | - " API_KEY = getpass(\"Please enter your labelbox api key\")\n", |
101 | | - " if COLAB:\n", |
102 | | - " envvar_handler.add_env(\"LABELBOX_API_KEY\", API_KEY)" |
103 | | - ] |
| 69 | + "source": "# If you don't want to give google access to drive you can skip this cell\n# and manually set `API_KEY` below.\nCOLAB = \"google.colab\" in str(get_ipython())\nif COLAB:\n !pip install colab-env -qU\n from colab_env import envvar_handler\n envvar_handler.envload()\n\nAPI_KEY = os.environ.get(\"LABELBOX_API_KEY\")\nif not os.environ.get(\"LABELBOX_API_KEY\"):\n API_KEY = getpass(\"Please enter your labelbox api key\")\n if COLAB:\n envvar_handler.add_env(\"LABELBOX_API_KEY\", API_KEY)" |
104 | 70 | }, |
105 | 71 | { |
106 | 72 | "cell_type": "code", |
107 | | - "execution_count": 3, |
| 73 | + "execution_count": 4, |
108 | 74 | "id": "adult-fleet", |
109 | 75 | "metadata": {}, |
110 | 76 | "outputs": [], |
111 | | - "source": [ |
112 | | - "# Only update this if you have an on-prem deployment\n", |
113 | | - "ENDPOINT = \"https://api.labelbox.com/graphql\"\n", |
114 | | - "client = Client(api_key=API_KEY, endpoint=ENDPOINT)" |
115 | | - ] |
| 77 | + "source": "# Only update this if you have an on-prem deployment\nENDPOINT = \"https://api.labelbox.com/graphql\"\nclient = Client(api_key=API_KEY, endpoint=ENDPOINT)" |
116 | 78 | }, |
117 | 79 | { |
118 | 80 | "cell_type": "markdown", |
|
136 | 98 | }, |
137 | 99 | { |
138 | 100 | "cell_type": "code", |
139 | | - "execution_count": 4, |
| 101 | + "execution_count": 5, |
140 | 102 | "id": "electronic-heart", |
141 | 103 | "metadata": {}, |
142 | 104 | "outputs": [ |
|
381 | 343 | "output_type": "display_data" |
382 | 344 | } |
383 | 345 | ], |
384 | | - "source": [ |
385 | | - "project = client.get_project(\"ckqcx1d58068c0y619qv7hzgu\")\n", |
386 | | - "labels = project.video_label_generator()\n", |
387 | | - "\n", |
388 | | - "for label in labels:\n", |
389 | | - " annotation_lookup = label.frame_annotations()\n", |
390 | | - " for idx, frame in label.data.value:\n", |
391 | | - " if idx % 30 != 1:\n", |
392 | | - " continue\n", |
393 | | - " \n", |
394 | | - " for annotation in annotation_lookup[idx]:\n", |
395 | | - " if isinstance(annotation.value, Rectangle):\n", |
396 | | - " frame = annotation.value.draw(canvas = frame.astype(np.uint8), thickness = 10, color= (255,0,0))\n", |
397 | | - " \n", |
398 | | - " im = Image.fromarray(frame)\n", |
399 | | - " w,h = im.size\n", |
400 | | - " IPython.display.display(im.resize((w//6, h//6) )) " |
401 | | - ] |
| 346 | + "source": "project = client.get_project(\"ckqcx1d58068c0y619qv7hzgu\")\nlabels = project.video_label_generator()\n\nfor label in labels:\n annotation_lookup = label.frame_annotations()\n for idx, frame in label.data.value:\n if idx % 30 != 1:\n continue\n\n for annotation in annotation_lookup[idx]:\n if isinstance(annotation.value, Rectangle):\n frame = annotation.value.draw(canvas=frame.astype(np.uint8),\n thickness=10,\n color=(255, 0, 0))\n\n im = Image.fromarray(frame)\n w, h = im.size\n IPython.display.display(im.resize((w // 6, h // 6)))" |
402 | 347 | }, |
403 | 348 | { |
404 | 349 | "cell_type": "markdown", |
|
410 | 355 | }, |
411 | 356 | { |
412 | 357 | "cell_type": "code", |
413 | | - "execution_count": 5, |
| 358 | + "execution_count": 6, |
414 | 359 | "id": "western-lebanon", |
415 | 360 | "metadata": {}, |
416 | 361 | "outputs": [], |
417 | | - "source": [ |
418 | | - "project = client.get_project(\"ckrdn049u5dia0y3h4l577t1v\")\n", |
419 | | - "label_list = project.label_generator().as_list()" |
420 | | - ] |
| 362 | + "source": "project = client.get_project(\"ckrdn049u5dia0y3h4l577t1v\")\nlabel_list = project.label_generator().as_list()" |
421 | 363 | }, |
422 | 364 | { |
423 | 365 | "cell_type": "code", |
424 | | - "execution_count": 6, |
| 366 | + "execution_count": 7, |
425 | 367 | "id": "likely-cleaners", |
426 | 368 | "metadata": {}, |
427 | 369 | "outputs": [ |
|
437 | 379 | "output_type": "execute_result" |
438 | 380 | } |
439 | 381 | ], |
440 | | - "source": [ |
441 | | - "im_data = label_list[0].data.value\n", |
442 | | - "h,w = im_data.shape[:2]\n", |
443 | | - "Image.fromarray(im_data)" |
444 | | - ] |
| 382 | + "source": "im_data = label_list[0].data.value\nh, w = im_data.shape[:2]\nImage.fromarray(im_data)" |
445 | 383 | }, |
446 | 384 | { |
447 | 385 | "cell_type": "code", |
448 | | - "execution_count": 7, |
| 386 | + "execution_count": 8, |
449 | 387 | "id": "incredible-storage", |
450 | 388 | "metadata": {}, |
451 | 389 | "outputs": [ |
|
461 | 399 | "output_type": "execute_result" |
462 | 400 | } |
463 | 401 | ], |
464 | | - "source": [ |
465 | | - "canvas = np.zeros((h, w, 3), dtype = np.uint8)\n", |
466 | | - "for annotation in label_list[0].annotations:\n", |
467 | | - " if isinstance(annotation.value, Geometry):\n", |
468 | | - " canvas = annotation.value.draw(canvas = canvas)\n", |
469 | | - "Image.fromarray(canvas)" |
470 | | - ] |
| 402 | + "source": "canvas = np.zeros((h, w, 3), dtype=np.uint8)\nfor annotation in label_list[0].annotations:\n if isinstance(annotation.value, Geometry):\n canvas = annotation.value.draw(canvas=canvas)\nImage.fromarray(canvas)" |
471 | 403 | }, |
472 | 404 | { |
473 | 405 | "cell_type": "code", |
474 | | - "execution_count": 8, |
| 406 | + "execution_count": 9, |
475 | 407 | "id": "greenhouse-discrimination", |
476 | 408 | "metadata": {}, |
477 | 409 | "outputs": [ |
|
489 | 421 | "output_type": "execute_result" |
490 | 422 | } |
491 | 423 | ], |
492 | | - "source": [ |
493 | | - "geoms = []\n", |
494 | | - "for annotation in label_list[0].annotations:\n", |
495 | | - " if isinstance(annotation.value, Geometry):\n", |
496 | | - " geoms.append(annotation.value.shapely)\n", |
497 | | - "from shapely.geometry import MultiPolygon\n", |
498 | | - "MultiPolygon(geoms)" |
499 | | - ] |
| 424 | + "source": "geoms = []\nfor annotation in label_list[0].annotations:\n if isinstance(annotation.value, Geometry):\n geoms.append(annotation.value.shapely)\nfrom shapely.geometry import MultiPolygon\n\nMultiPolygon(geoms)" |
500 | 425 | }, |
501 | 426 | { |
502 | 427 | "cell_type": "code", |
503 | | - "execution_count": 9, |
| 428 | + "execution_count": 10, |
504 | 429 | "id": "dried-lightning", |
505 | 430 | "metadata": {}, |
506 | 431 | "outputs": [ |
|
512 | 437 | ] |
513 | 438 | } |
514 | 439 | ], |
515 | | - "source": [ |
516 | | - "# We can also serialize back to the original payload:\n", |
517 | | - "for result in LBV1Converter.serialize(label_list):\n", |
518 | | - " print(result)" |
519 | | - ] |
| 440 | + "source": "# We can also serialize back to the original payload:\nfor result in LBV1Converter.serialize(label_list):\n print(result)" |
520 | 441 | }, |
521 | 442 | { |
522 | 443 | "cell_type": "markdown", |
|
530 | 451 | }, |
531 | 452 | { |
532 | 453 | "cell_type": "code", |
533 | | - "execution_count": 10, |
| 454 | + "execution_count": 11, |
534 | 455 | "id": "printable-wagon", |
535 | 456 | "metadata": {}, |
536 | 457 | "outputs": [ |
|
545 | 466 | ] |
546 | 467 | } |
547 | 468 | ], |
548 | | - "source": [ |
549 | | - "ndjson = []\n", |
550 | | - "for row in NDJsonConverter.serialize(label_list):\n", |
551 | | - " ndjson.append(row)\n", |
552 | | - " print(row)" |
553 | | - ] |
| 469 | + "source": "ndjson = []\nfor row in NDJsonConverter.serialize(label_list):\n ndjson.append(row)\n print(row)" |
554 | 470 | }, |
555 | 471 | { |
556 | 472 | "cell_type": "code", |
557 | | - "execution_count": 11, |
| 473 | + "execution_count": 12, |
558 | 474 | "id": "operational-project", |
559 | 475 | "metadata": {}, |
560 | 476 | "outputs": [ |
|
569 | 485 | "output_type": "execute_result" |
570 | 486 | } |
571 | 487 | ], |
572 | | - "source": [ |
573 | | - "# Convert back\n", |
574 | | - "NDJsonConverter.deserialize(ndjson)" |
575 | | - ] |
| 488 | + "source": "# Convert back\nNDJsonConverter.deserialize(ndjson)" |
576 | 489 | }, |
577 | 490 | { |
578 | 491 | "cell_type": "markdown", |
|
584 | 497 | }, |
585 | 498 | { |
586 | 499 | "cell_type": "code", |
587 | | - "execution_count": null, |
| 500 | + "execution_count": 13, |
588 | 501 | "id": "placed-danger", |
589 | 502 | "metadata": {}, |
590 | 503 | "outputs": [], |
591 | | - "source": [] |
| 504 | + "source": "" |
592 | 505 | } |
593 | 506 | ], |
594 | 507 | "metadata": { |
|
0 commit comments