Skip to content

Commit 3599a77

Browse files
authored
[SN-96,97] update composite mask notebook, and data row metadata notebook (#1541)
Added bulk export with data row identifiers Added bulk delete with data row identifiers Updated composite mask export text
1 parent 6b6db1a commit 3599a77

File tree

2 files changed

+71
-19
lines changed

2 files changed

+71
-19
lines changed

examples/basics/data_row_metadata.ipynb

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
{
122122
"metadata": {},
123123
"source": [
124-
"# list all your metadata ontology as a dictionary accessable by id \n",
124+
"# list all your metadata ontology as a dictionary accessable by id\n",
125125
"metadata_ontologies = mdo.fields_by_id\n",
126126
"pprint(metadata_ontologies, indent=2)"
127127
],
@@ -166,6 +166,57 @@
166166
"outputs": [],
167167
"execution_count": null
168168
},
169+
{
170+
"metadata": {},
171+
"source": [
172+
"### Export metadata fields"
173+
],
174+
"cell_type": "markdown"
175+
},
176+
{
177+
"metadata": {},
178+
"source": [
179+
"data_row_ids = [\"<data_row_id>\"]\n",
180+
"global_keys = [\"<global_key>\"]\n",
181+
"\n",
182+
"# These methods provide validation that the ID you are passing is a global key or data row id ,\n",
183+
"# this method also assures that all IDs are unique\n",
184+
"datarow_identifiers = lb.DataRowIds(data_row_ids)\n",
185+
"global_key_identifiers = lb.GlobalKeys(global_keys)\n",
186+
"\n",
187+
"# Use one of the identifiers\n",
188+
"mdo.bulk_export(data_row_ids=global_key_identifiers)\n",
189+
"# mdo.bulk_export(data_row_ids=datarow_identifiers)"
190+
],
191+
"cell_type": "code",
192+
"outputs": [],
193+
"execution_count": null
194+
},
195+
{
196+
"metadata": {},
197+
"source": [
198+
"### Delete metadata fields from a data row"
199+
],
200+
"cell_type": "markdown"
201+
},
202+
{
203+
"metadata": {},
204+
"source": [
205+
"global_key = \"<global_key>\"\n",
206+
"schema_ids_to_delete =[\"<metadata_schema_id>\"]\n",
207+
"data_row_id = \"<data_row_id>\"\n",
208+
"\n",
209+
"deletions = [\n",
210+
" lb.DeleteDataRowMetadata(data_row_id=lb.GlobalKey(global_key), fields=schema_ids_to_delete)\n",
211+
" ]\n",
212+
"\n",
213+
"# Delete the specified metadata on the data row\n",
214+
"mdo.bulk_delete(deletes=deletions)"
215+
],
216+
"cell_type": "code",
217+
"outputs": [],
218+
"execution_count": null
219+
},
169220
{
170221
"metadata": {},
171222
"source": [
@@ -190,19 +241,19 @@
190241
"source": [
191242
"# Construct a metadata field of string kind\n",
192243
"tag_metadata_field = lb.DataRowMetadataField(\n",
193-
" name=\"tag\", \n",
194-
" value=\"tag_string\", \n",
244+
" name=\"tag\",\n",
245+
" value=\"tag_string\",\n",
195246
")\n",
196247
"\n",
197248
"# Construct an metadata field of datetime kind\n",
198249
"capture_datetime_field = lb.DataRowMetadataField(\n",
199-
" name=\"captureDateTime\", \n",
200-
" value=datetime.utcnow(), \n",
250+
" name=\"captureDateTime\",\n",
251+
" value=datetime.utcnow(),\n",
201252
")\n",
202253
"\n",
203254
"# Construct a metadata field of Enums options\n",
204255
"split_metadata_field = lb.DataRowMetadataField(\n",
205-
" name=\"split\", \n",
256+
" name=\"split\",\n",
206257
" value=\"train\",\n",
207258
")\n"
208259
],
@@ -253,12 +304,12 @@
253304
{
254305
"metadata": {},
255306
"source": [
256-
"# Final \n",
307+
"# Final\n",
257308
"custom_metadata_fields = []\n",
258309
"\n",
259-
"# Create the schema for the metadata \n",
310+
"# Create the schema for the metadata\n",
260311
"number_schema = mdo.create_schema(\n",
261-
" name=\"numberMetadataCustom\", \n",
312+
" name=\"numberMetadataCustom\",\n",
262313
" kind=DataRowMetadataKind.number\n",
263314
")\n",
264315
"\n",
@@ -277,16 +328,16 @@
277328
{
278329
"metadata": {},
279330
"source": [
280-
"# Create the schema for an enum metadata \n",
331+
"# Create the schema for an enum metadata\n",
281332
"custom_metadata_fields = []\n",
282333
"\n",
283334
"enum_schema = mdo.create_schema(\n",
284-
" name=\"enumMetadata\", \n",
335+
" name=\"enumMetadata\",\n",
285336
" kind=DataRowMetadataKind.enum,\n",
286337
" options=[\"option1\", \"option2\"]\n",
287338
")\n",
288339
"\n",
289-
"# Add fields to the metadata schema \n",
340+
"# Add fields to the metadata schema\n",
290341
"data_row_metadata_fields_enum_1 = lb.DataRowMetadataField(\n",
291342
" name=enum_schema.name,\n",
292343
" value=\"option1\"\n",
@@ -333,7 +384,7 @@
333384
"global_key = \"s_basic.jpg\"\n",
334385
"data_row = {\"row_data\": \"https://storage.googleapis.com/labelbox-sample-datasets/Docs/basic.jpg\", \"global_key\": global_key}\n",
335386
"# This line works with dictionaries as well as schemas and fields created with DataRowMetadataField\n",
336-
"data_row['metadata_fields'] = custom_metadata_fields + [ split_metadata_field , capture_datetime_field_dict, tag_metadata_field ]\n",
387+
"data_row[\"metadata_fields\"] = custom_metadata_fields + [ split_metadata_field , capture_datetime_field_dict, tag_metadata_field ]\n",
337388
"\n",
338389
"\n",
339390
"task = dataset.create_data_rows([data_row])\n",
@@ -360,13 +411,13 @@
360411
"\n",
361412
"# Update the metadata\n",
362413
"updated_metadata = lb.DataRowMetadataField(\n",
363-
" schema_id=num_schema.uid, \n",
414+
" schema_id=num_schema.uid,\n",
364415
" value=10.2\n",
365416
")\n",
366417
"\n",
367418
"# Create data row payload\n",
368419
"data_row_payload = lb.DataRowMetadata(\n",
369-
" global_key=global_key, \n",
420+
" global_key=global_key,\n",
370421
" fields=[updated_metadata]\n",
371422
")\n",
372423
"\n",
@@ -387,12 +438,12 @@
387438
{
388439
"metadata": {},
389440
"source": [
390-
"# update a name \n",
441+
"# update a name\n",
391442
"number_schema = mdo.update_schema(name=\"numberMetadataCustom\", new_name=\"numberMetadataCustomNew\")\n",
392443
"\n",
393444
"# update an Enum metadata schema option's name, this only applies to Enum metadata schema.\n",
394445
"enum_schema = mdo.update_enum_option(\n",
395-
" name=\"enumMetadata\", \n",
446+
" name=\"enumMetadata\",\n",
396447
" option=\"option1\",\n",
397448
" new_option=\"option3\"\n",
398449
")"
@@ -415,7 +466,7 @@
415466
"source": [
416467
"data_row = next(dataset.data_rows())\n",
417468
"for metadata_field in data_row.metadata_fields:\n",
418-
" print(metadata_field['name'], \":\", metadata_field['value'])"
469+
" print(metadata_field[\"name\"], \":\", metadata_field[\"value\"])"
419470
],
420471
"cell_type": "code",
421472
"outputs": [],

examples/exports/composite_mask_export.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
{
3131
"metadata": {},
3232
"source": [
33-
"# Export composite masks\n",
33+
"# Export composite masks \n",
34+
"##### **Composite masks are only available on raster segmentation projects**\n",
3435
"\n",
3536
"Composite masks are a combination of mask instances grouped in a single mask URL. \n",
3637
"\n",

0 commit comments

Comments
 (0)