Skip to content

Commit 7538302

Browse files
authored
Clean up some notebooks (#1669)
1 parent 88c846b commit 7538302

File tree

10 files changed

+84
-40
lines changed

10 files changed

+84
-40
lines changed

examples/annotation_import/pdf.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@
282282
},
283283
{
284284
"metadata": {},
285-
"source": "client.enable_experimental = True\ntask = lb.DataRow.export(client=client, global_keys=[global_key])\ntask.wait_till_done()\nstream = task.get_buffered_stream()\n\ntext_layer = \"\"\nfor output in stream:\n output_json = json.loads(output.json)\n text_layer = output_json[\"media_attributes\"][\"text_layer_url\"]\nprint(text_layer)",
285+
"source": "client.enable_experimental = True\ntask = lb.DataRow.export(client=client, global_keys=[global_key])\ntask.wait_till_done()\nstream = task.get_buffered_stream()\n\ntext_layer = \"\"\nfor output in stream:\n output_json = output.json\n text_layer = output_json[\"media_attributes\"][\"text_layer_url\"]\nprint(text_layer)",
286286
"cell_type": "code",
287287
"outputs": [],
288288
"execution_count": null

examples/basics/batches.ipynb

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@
3030
{
3131
"metadata": {},
3232
"source": [
33-
"# Batches\n",
34-
"https://docs.labelbox.com/docs/batches"
33+
"# Batches"
3534
],
3635
"cell_type": "markdown"
3736
},
3837
{
3938
"metadata": {},
4039
"source": [
40+
"This notebook covers the basics of batches:\n",
41+
"\n",
4142
"* A batch is collection of data rows.\n",
4243
"* A data row cannot be part of more than one batch in a given project.\n",
4344
"* Batches work for all data types, but there can only be one data type per project.\n",
@@ -50,7 +51,14 @@
5051
},
5152
{
5253
"metadata": {},
53-
"source": "%pip install -q \"labelbox[data]\"",
54+
"source": [
55+
"## Set up"
56+
],
57+
"cell_type": "markdown"
58+
},
59+
{
60+
"metadata": {},
61+
"source": "%pip install -q --upgrade \"labelbox[data]\"",
5462
"cell_type": "code",
5563
"outputs": [],
5664
"execution_count": null
@@ -66,13 +74,13 @@
6674
"metadata": {},
6775
"source": [
6876
"## API key and client\n",
69-
"Provide a valid API key below in order to properly connect to the Labelbox Client."
77+
"Provide a valid API key below to connect to the Labelbox client properly. For more information, please review the [Create API key](https://docs.labelbox.com/reference/create-api-key) guide."
7078
],
7179
"cell_type": "markdown"
7280
},
7381
{
7482
"metadata": {},
75-
"source": "# Add your API key\nAPI_KEY = None\n# To get your API key go to: Workspace settings -> API -> Create API Key\nclient = lb.Client(api_key=API_KEY)",
83+
"source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)",
7684
"cell_type": "code",
7785
"outputs": [],
7886
"execution_count": null
@@ -121,7 +129,7 @@
121129
},
122130
{
123131
"metadata": {},
124-
"source": "client.enable_experimental = True\n\nexport_task = dataset.export()\nexport_task.wait_till_done()\n\ndata_rows = []\n\n\ndef json_stream_handler(output: lb.BufferedJsonConverterOutput):\n data_row = json.loads(output.json)\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_buffered_stream(\n stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
132+
"source": "export_task = dataset.export()\nexport_task.wait_till_done()\n\ndata_rows = []\n\n\ndef json_stream_handler(output: lb.BufferedJsonConverterOutput):\n data_row = output.json\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_buffered_stream(\n stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
125133
"cell_type": "code",
126134
"outputs": [],
127135
"execution_count": null
@@ -247,14 +255,14 @@
247255
},
248256
{
249257
"metadata": {},
250-
"source": "client.enable_experimental = True\n\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"performance_details\": True,\n \"batch_ids\": [\n batch.uid\n ], # Include batch ids if you only want to export specific batches, otherwise,\n # you can export all the data without using this parameter\n}\nfilters = {}\n\n# A task is returned, this provides additional information about the status of your task, such as\n# any errors encountered\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()",
258+
"source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"performance_details\": True,\n \"batch_ids\": [\n batch.uid\n ], # Include batch ids if you only want to export specific batches, otherwise,\n # you can export all the data without using this parameter\n}\nfilters = {}\n\n# A task is returned, this provides additional information about the status of your task, such as\n# any errors encountered\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()",
251259
"cell_type": "code",
252260
"outputs": [],
253261
"execution_count": null
254262
},
255263
{
256264
"metadata": {},
257-
"source": "data_rows = []\n\n\ndef json_stream_handler(output: lb.BufferedJsonConverterOutput):\n data_row = json.loads(output.json)\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_buffered_stream(\n stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
265+
"source": "data_rows = []\n\n\ndef json_stream_handler(output: lb.BufferedJsonConverterOutput):\n data_row = output.json\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_buffered_stream(\n stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
258266
"cell_type": "code",
259267
"outputs": [],
260268
"execution_count": null
@@ -283,14 +291,14 @@
283291
{
284292
"metadata": {},
285293
"source": [
286-
"## Clean up \n",
287-
"Uncomment and run the cell below to optionally delete the batch, dataset, and/or project created in this demo."
294+
"## Clean up\n",
295+
"Uncomment and run the cell below to optionally delete Labelbox objects created."
288296
],
289297
"cell_type": "markdown"
290298
},
291299
{
292300
"metadata": {},
293-
"source": "# Delete Batch\n# batch.delete()\n\n# Delete Project\n# project.delete()\n\n# Delete DataSet\n# dataset.delete()",
301+
"source": "# batch.delete()\n# project.delete()\n# dataset.delete()",
294302
"cell_type": "code",
295303
"outputs": [],
296304
"execution_count": null

examples/basics/custom_embeddings.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
},
4646
{
4747
"metadata": {},
48-
"source": "%pip3 install -q \"labelbox[data]\"",
48+
"source": "%pip install -q --upgrade \"labelbox[data]\"",
4949
"cell_type": "code",
5050
"outputs": [],
5151
"execution_count": null
@@ -102,7 +102,7 @@
102102
},
103103
{
104104
"metadata": {},
105-
"source": "data_rows = []\n\n\ndef json_stream_handler(output: lb.BufferedJsonConverterOutput):\n data_row = json.loads(output.json)\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_buffered_stream(\n stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
105+
"source": "data_rows = []\n\n\ndef json_stream_handler(output: lb.BufferedJsonConverterOutput):\n data_row = output.json\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_buffered_stream(\n stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
106106
"cell_type": "code",
107107
"outputs": [],
108108
"execution_count": null

examples/basics/data_rows.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
},
114114
{
115115
"metadata": {},
116-
"source": "data_rows = []\n\n\ndef json_stream_handler(output: lb.BufferedJsonConverterOutput):\n data_row = json.loads(output.json)\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_buffered_stream(\n stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
116+
"source": "data_rows = []\n\n\ndef json_stream_handler(output: lb.BufferedJsonConverterOutput):\n data_row = output.json\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\nif export_task.has_result():\n export_json = export_task.get_buffered_stream(\n stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
117117
"cell_type": "code",
118118
"outputs": [],
119119
"execution_count": null
@@ -236,7 +236,7 @@
236236
},
237237
{
238238
"metadata": {},
239-
"source": "# Fetch a data row from the first dataset example\nts = dataset.export()\nts.wait_till_done()\nDATA_ROW_ID = [json.loads(output.json) for output in ts.get_buffered_stream()\n ][0][\"data_row\"][\"id\"]\nGLOBAL_KEY = [json.loads(output.json) for output in ts.get_buffered_stream()\n ][0][\"data_row\"][\"global_key\"]\n\nprint(f\"Pick either a data row id : {DATA_ROW_ID} or global key: {GLOBAL_KEY}\")",
239+
"source": "# Fetch a data row from the first dataset example\nts = dataset.export()\nts.wait_till_done()\nDATA_ROW_ID = [output.json for output in ts.get_buffered_stream()\n ][0][\"data_row\"][\"id\"]\nGLOBAL_KEY = [output.json for output in ts.get_buffered_stream()\n ][0][\"data_row\"][\"global_key\"]\n\nprint(f\"Pick either a data row id : {DATA_ROW_ID} or global key: {GLOBAL_KEY}\")",
240240
"cell_type": "code",
241241
"outputs": [],
242242
"execution_count": null

examples/basics/projects.ipynb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
{
3131
"metadata": {},
3232
"source": [
33-
"# Projects"
33+
"# Projects\n",
34+
"This notebook covers the basics of projects:"
3435
],
3536
"cell_type": "markdown"
3637
},
@@ -47,7 +48,14 @@
4748
},
4849
{
4950
"metadata": {},
50-
"source": "%pip install -q \"labelbox[data]\"",
51+
"source": [
52+
"## Set up"
53+
],
54+
"cell_type": "markdown"
55+
},
56+
{
57+
"metadata": {},
58+
"source": "%pip install -q --upgrade \"labelbox[data]\"",
5159
"cell_type": "code",
5260
"outputs": [],
5361
"execution_count": null
@@ -62,14 +70,14 @@
6270
{
6371
"metadata": {},
6472
"source": [
65-
"# API Key and Client\n",
66-
"Provide a valid api key below in order to properly connect to the Labelbox Client."
73+
"## API key and client\n",
74+
"Provide a valid API key below to connect to the Labelbox client properly. For more information, please review the [Create API key](https://docs.labelbox.com/reference/create-api-key) guide."
6775
],
6876
"cell_type": "markdown"
6977
},
7078
{
7179
"metadata": {},
72-
"source": "# Add your API key\nAPI_KEY = \"\"\n# To get your API key go to: Workspace settings -> API -> Create API Key\nclient = lb.Client(api_key=API_KEY)",
80+
"source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)",
7381
"cell_type": "code",
7482
"outputs": [],
7583
"execution_count": null
@@ -355,7 +363,8 @@
355363
{
356364
"metadata": {},
357365
"source": [
358-
"### Clean Up"
366+
"## Clean up\n",
367+
"Uncomment and run the cell below to optionally delete Labelbox objects created."
359368
],
360369
"cell_type": "markdown"
361370
},

examples/exports/composite_mask_export.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
},
212212
{
213213
"metadata": {},
214-
"source": "stream = export_task.get_buffered_stream()\n\nmask_tool_rgb_mapping = {}\n\nfor output in stream:\n # Parse the JSON string from the output\n output_json = json.loads(output.json)\n\n # Get the labels for the specified project ID or an empty list if the project ID is not found\n project_labels = (output_json[\"projects\"].get(PROJECT_ID,\n {}).get(\"labels\", []))\n\n # Iterate through each label\n for label in project_labels:\n # Get the list of annotations (objects) for the label\n annotations = label[\"annotations\"].get(\"objects\", [])\n\n # Iterate through each annotation\n for annotation in annotations:\n # Check if the annotation is of type \"ImageSegmentationMask\"\n if annotation.get(\"annotation_kind\") == \"ImageSegmentationMask\":\n # Add the color RGB information to the mapping dictionary\n mask_tool_rgb_mapping.setdefault(annotation[\"name\"], []).append(\n annotation[\"composite_mask\"][\"color_rgb\"])\n\nprint(mask_tool_rgb_mapping)",
214+
"source": "stream = export_task.get_buffered_stream()\n\nmask_tool_rgb_mapping = {}\n\nfor output in stream:\n # Parse the JSON string from the output\n output_json = output.json\n\n # Get the labels for the specified project ID or an empty list if the project ID is not found\n project_labels = (output_json[\"projects\"].get(PROJECT_ID,\n {}).get(\"labels\", []))\n\n # Iterate through each label\n for label in project_labels:\n # Get the list of annotations (objects) for the label\n annotations = label[\"annotations\"].get(\"objects\", [])\n\n # Iterate through each annotation\n for annotation in annotations:\n # Check if the annotation is of type \"ImageSegmentationMask\"\n if annotation.get(\"annotation_kind\") == \"ImageSegmentationMask\":\n # Add the color RGB information to the mapping dictionary\n mask_tool_rgb_mapping.setdefault(annotation[\"name\"], []).append(\n annotation[\"composite_mask\"][\"color_rgb\"])\n\nprint(mask_tool_rgb_mapping)",
215215
"cell_type": "code",
216216
"outputs": [],
217217
"execution_count": null
@@ -246,7 +246,7 @@
246246
},
247247
{
248248
"metadata": {},
249-
"source": "tools_frames_color = {}\nstream = export_task_video.get_buffered_stream()\n\n# Iterate over each output in the stream\nfor output in stream:\n output_json = json.loads(output.json)\n\n # Iterate over the labels in the specific project\n for dr in output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]:\n frames_data = dr[\"annotations\"][\"frames\"]\n\n # Iterate over each frame in the frames data\n for frame_key, frame_value in frames_data.items():\n\n # Iterate over each annotation in the frame\n for annotation_key, annotation_value in frame_value.items():\n if \"objects\" in annotation_key and annotation_value.values():\n\n # Iterate over each object in the annotation\n for object_key, object_value in annotation_value.items():\n if (object_value[\"annotation_kind\"] ==\n \"VideoSegmentationMask\"):\n # Update tools_frames_color with object information\n tools_frames_color.setdefault(\n object_value[\"name\"], []).append({\n frame_key:\n object_value[\"composite_mask\"]\n [\"color_rgb\"]\n })\n\nprint(tools_frames_color)",
249+
"source": "tools_frames_color = {}\nstream = export_task_video.get_buffered_stream()\n\n# Iterate over each output in the stream\nfor output in stream:\n output_json = output.json\n\n # Iterate over the labels in the specific project\n for dr in output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]:\n frames_data = dr[\"annotations\"][\"frames\"]\n\n # Iterate over each frame in the frames data\n for frame_key, frame_value in frames_data.items():\n\n # Iterate over each annotation in the frame\n for annotation_key, annotation_value in frame_value.items():\n if \"objects\" in annotation_key and annotation_value.values():\n\n # Iterate over each object in the annotation\n for object_key, object_value in annotation_value.items():\n if (object_value[\"annotation_kind\"] ==\n \"VideoSegmentationMask\"):\n # Update tools_frames_color with object information\n tools_frames_color.setdefault(\n object_value[\"name\"], []).append({\n frame_key:\n object_value[\"composite_mask\"]\n [\"color_rgb\"]\n })\n\nprint(tools_frames_color)",
250250
"cell_type": "code",
251251
"outputs": [],
252252
"execution_count": null

examples/model_experiments/custom_metrics_demo.ipynb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
{
3131
"metadata": {},
3232
"source": [
33-
"----\n",
34-
"\n",
3533
"# Model Diagnostics - Custom Metrics Demo\n",
3634
"\n",
3735
"* Measuring model quality is critical to efficiently building models. It is important that the metrics used to measure model quality closely align with the business objectives for the model. Otherwise, slight changes in model quality, as they related to these core objectives, are lost to noise. Custom metrics enables users to measure model quality in terms of their exact business goals. By incorporating custom metrics into workflows, users can:\n",
@@ -44,13 +42,13 @@
4442
{
4543
"metadata": {},
4644
"source": [
47-
"## Environment setup"
45+
"## Set up"
4846
],
4947
"cell_type": "markdown"
5048
},
5149
{
5250
"metadata": {},
53-
"source": "%pip install -q \"labelbox[data]\"",
51+
"source": "%pip install -q --upgrade \"labelbox[data]\"",
5452
"cell_type": "code",
5553
"outputs": [],
5654
"execution_count": null
@@ -65,14 +63,14 @@
6563
{
6664
"metadata": {},
6765
"source": [
68-
"## Replace with your API Key\n",
69-
"Guides on [Create an API key](https://docs.labelbox.com/docs/create-an-api-key)"
66+
"## API key and client\n",
67+
"Provide a valid API key below to connect to the Labelbox client properly. For more information, please review the [Create API key](https://docs.labelbox.com/reference/create-api-key) guide."
7068
],
7169
"cell_type": "markdown"
7270
},
7371
{
7472
"metadata": {},
75-
"source": "API_KEY = \"\"\nclient = lb.Client(API_KEY)",
73+
"source": "API_KEY = None\nclient = lb.Client(API_KEY)",
7674
"cell_type": "code",
7775
"outputs": [],
7876
"execution_count": null
@@ -87,7 +85,14 @@
8785
{
8886
"metadata": {},
8987
"source": [
90-
"### Classification: Radio (single-choice)"
88+
"## Classifications"
89+
],
90+
"cell_type": "markdown"
91+
},
92+
{
93+
"metadata": {},
94+
"source": [
95+
"### Radio (single-choice)"
9196
],
9297
"cell_type": "markdown"
9398
},
@@ -101,7 +106,7 @@
101106
{
102107
"metadata": {},
103108
"source": [
104-
"### Classification: checklist (multi-choice)"
109+
"#### Checklist (multi-choice)"
105110
],
106111
"cell_type": "markdown"
107112
},

0 commit comments

Comments
 (0)