|
30 | 30 | { |
31 | 31 | "metadata": {}, |
32 | 32 | "source": [ |
33 | | - "# Batches\n", |
34 | | - "https://docs.labelbox.com/docs/batches" |
| 33 | + "# Batches" |
35 | 34 | ], |
36 | 35 | "cell_type": "markdown" |
37 | 36 | }, |
38 | 37 | { |
39 | 38 | "metadata": {}, |
40 | 39 | "source": [ |
| 40 | + "This notebook covers the basics of batches:\n", |
| 41 | + "\n", |
41 | 42 | "* A batch is collection of data rows.\n", |
42 | 43 | "* A data row cannot be part of more than one batch in a given project.\n", |
43 | 44 | "* Batches work for all data types, but there can only be one data type per project.\n", |
|
50 | 51 | }, |
51 | 52 | { |
52 | 53 | "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]\"", |
54 | 62 | "cell_type": "code", |
55 | 63 | "outputs": [], |
56 | 64 | "execution_count": null |
|
66 | 74 | "metadata": {}, |
67 | 75 | "source": [ |
68 | 76 | "## 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." |
70 | 78 | ], |
71 | 79 | "cell_type": "markdown" |
72 | 80 | }, |
73 | 81 | { |
74 | 82 | "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)", |
76 | 84 | "cell_type": "code", |
77 | 85 | "outputs": [], |
78 | 86 | "execution_count": null |
|
121 | 129 | }, |
122 | 130 | { |
123 | 131 | "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)", |
125 | 133 | "cell_type": "code", |
126 | 134 | "outputs": [], |
127 | 135 | "execution_count": null |
|
247 | 255 | }, |
248 | 256 | { |
249 | 257 | "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()", |
251 | 259 | "cell_type": "code", |
252 | 260 | "outputs": [], |
253 | 261 | "execution_count": null |
254 | 262 | }, |
255 | 263 | { |
256 | 264 | "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)", |
258 | 266 | "cell_type": "code", |
259 | 267 | "outputs": [], |
260 | 268 | "execution_count": null |
|
283 | 291 | { |
284 | 292 | "metadata": {}, |
285 | 293 | "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." |
288 | 296 | ], |
289 | 297 | "cell_type": "markdown" |
290 | 298 | }, |
291 | 299 | { |
292 | 300 | "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()", |
294 | 302 | "cell_type": "code", |
295 | 303 | "outputs": [], |
296 | 304 | "execution_count": null |
|
0 commit comments