Skip to content

Commit aa62651

Browse files
ovalle15ovalle15Gabefiregithub-actions[bot]
authored
[DOCS-424] removed label typing for annotation/prediction import examples (#1606)
Co-authored-by: ovalle15 <aovalle@Andreas-MacBook-Pro-2.local> Co-authored-by: Gabe <33893811+Gabefire@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 6ca7fe9 commit aa62651

20 files changed

+93
-114
lines changed

examples/annotation_import/audio.ipynb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,7 @@
349349
"label = []\n",
350350
"label.append(\n",
351351
" lb_types.Label(\n",
352-
" data=lb_types.AudioData(\n",
353-
" global_key=global_key\n",
354-
" ),\n",
352+
" data={\"global_key\" : global_key },\n",
355353
" annotations=[\n",
356354
" text_annotation,\n",
357355
" checklist_annotation,\n",

examples/annotation_import/conversational.ipynb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,7 @@
495495
"label = []\n",
496496
"label.append(\n",
497497
" lb_types.Label(\n",
498-
" data=lb_types.ConversationData(\n",
499-
" global_key=global_key\n",
500-
" ),\n",
498+
" data={\"global_key\" : global_key },\n",
501499
" annotations=[\n",
502500
" ner_annotation,\n",
503501
" text_annotation,\n",

examples/annotation_import/conversational_LLM.ipynb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,7 @@
542542
"label = []\n",
543543
"label.append(\n",
544544
" lb_types.Label(\n",
545-
" data=lb_types.ConversationData(\n",
546-
" global_key=global_key\n",
547-
" ),\n",
545+
" data={\"global_key\" : global_key },\n",
548546
" annotations=[\n",
549547
" ner_annotation,\n",
550548
" text_annotation,\n",

examples/annotation_import/dicom.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@
343343
"annotations_list = polyline_annotation + mask_annotation\n",
344344
"labels = [\n",
345345
" lb_types.Label(\n",
346-
" data=lb_types.DicomData(global_key=global_key),\n",
346+
" data={\"global_key\" : global_key },\n",
347347
" annotations=annotations_list\n",
348348
" )\n",
349349
"]"

examples/annotation_import/html.ipynb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,7 @@
454454
"label = []\n",
455455
"label.append(\n",
456456
" lb_types.Label(\n",
457-
" data=lb_types.HTMLData(\n",
458-
" global_key=global_key\n",
459-
" ),\n",
457+
" data={\"global_key\" : global_key },\n",
460458
" annotations=[\n",
461459
" text_annotation,\n",
462460
" checklist_annotation,\n",

examples/annotation_import/image.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@
938938
"] + cp_mask\n",
939939
"\n",
940940
"label.append(\n",
941-
" lb_types.Label(data=lb_types.ImageData(global_key=global_key),\n",
941+
" lb_types.Label(data={\"global_key\" : global_key },\n",
942942
" annotations=annotations))"
943943
],
944944
"cell_type": "code",

examples/annotation_import/import_labeled_dataset_image.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"metadata": {},
7171
"source": [
7272
"# Initialize the Labelbox client\n",
73-
"API_KEY = \"\" # Place API key\n",
73+
"API_KEY = \"\"\n",
7474
"client = lb.Client(API_KEY)"
7575
],
7676
"cell_type": "code",
@@ -376,7 +376,7 @@
376376
" name=class_name,\n",
377377
" value=Rectangle(start=Point(x=bbox[0], y=bbox[1]), end=Point(x=bbox[2]+bbox[0], y=bbox[3]+bbox[1]))\n",
378378
" ))\n",
379-
" image_data = ImageData(uid=data_row_dict['id'])\n",
379+
" image_data = {\"uid\":data_row_dict['id']}\n",
380380
" labels.append(Label(data=image_data, annotations=annotations_list))"
381381
],
382382
"cell_type": "code",

examples/annotation_import/pdf.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,8 +1024,7 @@
10241024
"\n",
10251025
"labels.append(\n",
10261026
" lb_types.Label(\n",
1027-
" data=lb_types.DocumentData(\n",
1028-
" global_key=global_key),\n",
1027+
" data={\"global_key\" : global_key },\n",
10291028
" annotations = [\n",
10301029
" entities_annotation,\n",
10311030
" checklist_annotation,\n",

examples/annotation_import/text.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,7 @@
492492
"labels = []\n",
493493
"labels.append(\n",
494494
" lb_types.Label(\n",
495-
" data=lb_types.TextData(\n",
496-
" global_key=global_key),\n",
495+
" data={\"global_key\" : global_key },\n",
497496
" annotations = [\n",
498497
" named_entitity_annotation,\n",
499498
" radio_annotation,\n",

examples/annotation_import/tiled.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -962,12 +962,12 @@
962962
"labels =[]\n",
963963
"labels.append(\n",
964964
" lb_types.Label(\n",
965-
" data=lb_types.TiledImageData(\n",
966-
" global_key=global_key,\n",
967-
" tile_layer=tile_layer,\n",
968-
" tile_bounds=bounds,\n",
969-
" zoom_levels=[12, 20]\n",
970-
" ),\n",
965+
" data={\n",
966+
" \"global_key\": global_key,\n",
967+
" \"tile_layer\": tile_layer,\n",
968+
" \"tile_bounds\":bounds,\n",
969+
" \"zoom_levels\": [12, 20]\n",
970+
" },\n",
971971
" annotations = [\n",
972972
" point_annotation,\n",
973973
" polyline_annotation,\n",

examples/annotation_import/video.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@
11401140
"for annotation in annotations_list:\n",
11411141
" label.append(\n",
11421142
" lb_types.Label(\n",
1143-
" data=lb_types.VideoData(global_key=global_key),\n",
1143+
" data= {\"global_key\": global_key},\n",
11441144
" annotations = annotation\n",
11451145
" )\n",
11461146
" )\n"
Lines changed: 63 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {},
25
"cells": [
36
{
4-
"cell_type": "markdown",
57
"metadata": {},
68
"source": [
79
"<td>\n",
810
" <a target=\"_blank\" href=\"https://labelbox.com\" ><img src=\"https://labelbox.com/blog/content/images/2021/02/logo-v4.svg\" width=256/></a>\n",
911
"</td>"
10-
]
12+
],
13+
"cell_type": "markdown"
1114
},
1215
{
13-
"cell_type": "markdown",
1416
"metadata": {},
1517
"source": [
1618
"<td>\n",
@@ -22,37 +24,35 @@
2224
"<a href=\"https://github.com/Labelbox/labelbox-python/tree/develop/examples/integrations/huggingface/huggingface.ipynb\" target=\"_blank\"><img\n",
2325
"src=\"https://img.shields.io/badge/GitHub-100000?logo=github&logoColor=white\" alt=\"GitHub\"></a>\n",
2426
"</td>"
25-
]
27+
],
28+
"cell_type": "markdown"
2629
},
2730
{
28-
"cell_type": "markdown",
2931
"metadata": {},
3032
"source": [
3133
"# Install required libraries"
32-
]
34+
],
35+
"cell_type": "markdown"
3336
},
3437
{
35-
"cell_type": "code",
36-
"execution_count": null,
3738
"metadata": {},
38-
"outputs": [],
3939
"source": [
4040
"!pip install -q \"labelbox\"\n",
4141
"!pip install -q transformers"
42-
]
42+
],
43+
"cell_type": "code",
44+
"outputs": [],
45+
"execution_count": null
4346
},
4447
{
45-
"cell_type": "markdown",
4648
"metadata": {},
4749
"source": [
4850
"# Imports"
49-
]
51+
],
52+
"cell_type": "markdown"
5053
},
5154
{
52-
"cell_type": "code",
53-
"execution_count": null,
5455
"metadata": {},
55-
"outputs": [],
5656
"source": [
5757
"import labelbox as lb\n",
5858
"import transformers\n",
@@ -63,58 +63,58 @@
6363
"import requests\n",
6464
"from tqdm import tqdm\n",
6565
"import numpy as np"
66-
]
66+
],
67+
"cell_type": "code",
68+
"outputs": [],
69+
"execution_count": null
6770
},
6871
{
69-
"cell_type": "markdown",
7072
"metadata": {},
7173
"source": [
7274
"# Labelbox Credentials"
73-
]
75+
],
76+
"cell_type": "markdown"
7477
},
7578
{
76-
"cell_type": "code",
77-
"execution_count": null,
7879
"metadata": {},
79-
"outputs": [],
8080
"source": [
8181
"# Add your API key\n",
8282
"API_KEY = \"\"\n",
8383
"client = lb.Client(API_KEY)"
84-
]
84+
],
85+
"cell_type": "code",
86+
"outputs": [],
87+
"execution_count": null
8588
},
8689
{
87-
"cell_type": "markdown",
8890
"metadata": {},
8991
"source": [
9092
"# Select data rows in Labelbox for custom embeddings"
91-
]
93+
],
94+
"cell_type": "markdown"
9295
},
9396
{
94-
"cell_type": "code",
95-
"execution_count": null,
9697
"metadata": {},
97-
"outputs": [],
9898
"source": [
9999
"# Get images from a Labelbox dataset,\n",
100100
"# Ensure the images are available by obtaining a token from your cloud provider if necessary\n",
101101
"DATASET_ID = \"\""
102-
]
102+
],
103+
"cell_type": "code",
104+
"outputs": [],
105+
"execution_count": null
103106
},
104107
{
105-
"cell_type": "code",
106-
"execution_count": null,
107108
"metadata": {},
108-
"outputs": [],
109109
"source": [
110110
"dataset = client.get_dataset(DATASET_ID)"
111-
]
111+
],
112+
"cell_type": "code",
113+
"outputs": [],
114+
"execution_count": null
112115
},
113116
{
114-
"cell_type": "code",
115-
"execution_count": null,
116117
"metadata": {},
117-
"outputs": [],
118118
"source": [
119119
"export_task = dataset.export_v2()\n",
120120
"\n",
@@ -124,58 +124,58 @@
124124
"export_json = export_task.result\n",
125125
"\n",
126126
"data_row_urls = [dr_url['data_row']['row_data'] for dr_url in export_json]"
127-
]
127+
],
128+
"cell_type": "code",
129+
"outputs": [],
130+
"execution_count": null
128131
},
129132
{
130-
"cell_type": "markdown",
131133
"metadata": {},
132134
"source": [
133135
"# Get a HuggingFace Model to generate custom embeddings"
134-
]
136+
],
137+
"cell_type": "markdown"
135138
},
136139
{
137-
"cell_type": "code",
138-
"execution_count": null,
139140
"metadata": {},
140-
"outputs": [],
141141
"source": [
142142
"# Get ResNet-50 from HuggingFace\n",
143143
"image_processor = transformers.AutoImageProcessor.from_pretrained(\"microsoft/resnet-50\")\n",
144144
"model = transformers.ResNetModel.from_pretrained(\"microsoft/resnet-50\")"
145-
]
145+
],
146+
"cell_type": "code",
147+
"outputs": [],
148+
"execution_count": null
146149
},
147150
{
148-
"cell_type": "markdown",
149151
"metadata": {},
150152
"source": [
151153
"# Pick an existing custom embedding in Labelbox, or create a custom embedding"
152-
]
154+
],
155+
"cell_type": "markdown"
153156
},
154157
{
155-
"cell_type": "code",
156-
"execution_count": null,
157158
"metadata": {},
158-
"outputs": [],
159159
"source": [
160160
"# Create a new embedding in your workspace, use the right dimensions to your use case, here we use 2048 for ResNet-50\n",
161161
"new_custom_embedding_id = client.create_embedding(name=\"My new awesome embedding\", dims=2048).id\n",
162162
"\n",
163163
"# Or use an existing embedding from your workspace\n",
164164
"# existing_embedding_id = client.get_embedding_by_name(name=\"ResNet img 2048\").id"
165-
]
165+
],
166+
"cell_type": "code",
167+
"outputs": [],
168+
"execution_count": null
166169
},
167170
{
168-
"cell_type": "markdown",
169171
"metadata": {},
170172
"source": [
171173
"# Generate and upload custom embeddings"
172-
]
174+
],
175+
"cell_type": "markdown"
173176
},
174177
{
175-
"cell_type": "code",
176-
"execution_count": null,
177178
"metadata": {},
178-
"outputs": [],
179179
"source": [
180180
"img_emb = []\n",
181181
"\n",
@@ -209,26 +209,22 @@
209209
" \"row_data\": url,\n",
210210
" \"embeddings\": [{\"embedding_id\": new_custom_embedding_id, \"vector\": embedding[0].tolist()}]\n",
211211
" })"
212-
]
212+
],
213+
"cell_type": "code",
214+
"outputs": [],
215+
"execution_count": null
213216
},
214217
{
215-
"cell_type": "code",
216-
"execution_count": null,
217218
"metadata": {},
218-
"outputs": [],
219219
"source": [
220220
"# Upload to a new dataset\n",
221221
"dataset = client.create_dataset(name='image_custom_embedding_resnet', iam_integration=None)\n",
222222
"task = dataset.create_data_rows(data_rows)\n",
223223
"print(task.errors)"
224-
]
225-
}
226-
],
227-
"metadata": {
228-
"language_info": {
229-
"name": "python"
224+
],
225+
"cell_type": "code",
226+
"outputs": [],
227+
"execution_count": null
230228
}
231-
},
232-
"nbformat": 4,
233-
"nbformat_minor": 0
234-
}
229+
]
230+
}

0 commit comments

Comments
 (0)