diff --git a/examples/README.md b/examples/README.md index 387840707..1523e1737 100644 --- a/examples/README.md +++ b/examples/README.md @@ -90,6 +90,11 @@ Open In Github Open In Colab + + Export V1 to V2 Migration Support + Open In Github + Open In Colab + diff --git a/examples/exports/export_v1_to_v2_migration_support.ipynb b/examples/exports/export_v1_to_v2_migration_support.ipynb new file mode 100644 index 000000000..9fed974f6 --- /dev/null +++ b/examples/exports/export_v1_to_v2_migration_support.ipynb @@ -0,0 +1,572 @@ +{ + "nbformat": 4, + "nbformat_minor": 5, + "metadata": {}, + "cells": [ + { + "metadata": {}, + "source": [ + "", + " ", + "\n" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": [ + "# Export V1 migration" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": [ + "Export V1 is no longer available in any version of the SDK in favor of the latest `export()` method, which allows you to export data with granular control. This notebook provide guidelines and comparisons on migrating from Export V1 to `export()` to ensure successful data export." + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": [ + "### Key changes\n", + "The `export()` method adds the following changes and benefits compared to Export V1 methods:\n", + "1. Flexibility: `export()` provides parameters and filters to select and export data you need.\n", + "2. Simplicity: `export()` allows you to do all type of export operations using a single method.\n", + "3. Scalability: `export()` allows you to stream an **unlimited** number of data rows.\n", + "\n", + "For complete details on how to use `export()`, see the [Export overview](https://docs.labelbox.com/reference/export-overview)." + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": [ + "### Export V1 deprecated methods:\n", + "Project methods :\n", + "1. ```project.export_labels()```\n", + "2. ```project.label_generator()```\n", + "3. ```project.export_queued_data_rows()```\n", + "\n", + "Dataset methods:\n", + "1. ```dataset.export_data_rows()```\n", + "\n", + "Batch methods:\n", + "1. ```batch.export_data_rows()```\n", + "\n", + "Model methods :\n", + "1. ```model_run.export_labels()```\n", + "\n" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": [ + "# Imports" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "%pip install -q \"labelbox[data]\"", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": "import labelbox as lb\nimport pprint\n\npp = pprint.PrettyPrinter(width=30, compact=True)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "## API Key and Client\n", + "See the developer guide for [creating an API key](https://docs.labelbox.com/reference/create-api-key)." + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "API_KEY = \"\"\nclient = lb.Client(api_key=API_KEY)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "## Export labels from a project\n" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "PROJECT_ID = \"\"\nproject = client.get_project(PROJECT_ID)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "##### Export V1 (deprecated) \n", + "1. ```project.export_labels()```\n", + " - Parameters: \n", + " - ```download: bool = False```\n", + " - ```timeout_seconds: int = 1800```\n", + " - Output : (str | List[Dict[Any, Any]] | None)" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": [ + "2. ```project.label_generator()```\n", + " - Parameters:\n", + " - ```timeout_seconds: int = 600```\n", + " - Output: LabelGenerator" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "# Single entry from the output of project.label_generator() (deprecated)\n# Label objects will not be deprecated.\nsingle_output_from_generator = \"\"\"\n\nLabel(\n uid='clrf5csho2ihx07ilffgp2fzj',\n data=ImageData(\n im_bytes=None,\n file_path=None,\n url='https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg',\n arr=None\n ),\n annotations=[\n ObjectAnnotation(\n confidence=None,\n name='bounding_box',\n feature_schema_id='clrf5ck4a0b9b071paa9ncu15',\n extra={\n 'instanceURI': 'https://api.labelbox.com/masks/feature/clrf5csvi6ofm07lsf9pygwvi?token='\n 'color': '#ff0000',\n 'feature_id': 'clrf5csvi6ofm07lsf9pygwvi',\n 'value': 'bounding_box',\n 'page': None,\n 'unit': None\n },\n value=Rectangle(\n extra={},\n start=Point(extra={}, x=2096.0, y=1264.0),\n end=Point(extra={}, x=2240.0, y=1689.0)\n ),\n classifications=[]\n ),\n # Add more annotations as needed\n # ...\n ],\n extra={\n 'Created By': 'aovalle@labelbox.com',\n 'Project Name': 'Image Annotation Import Demo',\n 'Created At': '2024-01-15T16:35:59.000Z',\n 'Updated At': '2024-01-15T16:51:56.000Z',\n 'Seconds to Label': 66.0,\n 'Agreement': -1.0,\n 'Benchmark Agreement': -1.0,\n 'Benchmark ID': None,\n 'Dataset Name': 'image-demo-dataset',\n 'Reviews': [],\n 'View Label': 'https://editor.labelbox.com?project=clrf5ckex09m9070x1te223u5&label=clrf5csho2ihx07ilffgp2fzj',\n 'Has Open Issues': 0.0,\n 'Skipped': False,\n 'media_type': 'image',\n 'Data Split': None,\n 'Global Key': '2560px-Kitano_Street_Kobe01s5s41102.jpeg'\n }\n)\n\n\"\"\"", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "##### Export\n", + "\n", + "For complete details on the supported filters abd parameters, including how they are used and what information is included, please see the [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters) documentation.\n", + "\n", + "`project.export()`\n", + "- Parameters: \n", + " - ```\"label_details\": True```\n", + " - ```\"attachments\": True```\n", + " - ```\"data_row_details\": True```\n", + " - ```\"project_details\": True```\n", + " - ```\"label_details\": True```\n", + " - ```\"performance_details\": True```\n", + "- Output:\n", + " - ```ExportTask```\n", + " - `ExportTask.has_result()` return type: bool\n", + " - `ExportTask.has_errors()` return type: bool\n", + " - `ExportTask.get_buffered_stream()` return type: Stream[BufferedJsonConverterOutput]" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "## Set the export parameters to only export labels\nexport_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"label_details\": True,\n \"performance_details\": True,\n}\n# You also have the option to include additional filtering to narrow down the list of labels\nfilters = {}\n\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.BufferedJsonConverterOutput):\n print(output.json)\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)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "## Export queued (\"To Label\") data rows from a project" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": [ + "##### Export V1 (deprecated): \n", + "1. ``project.export_queued_data_rows()`` :\n", + " - Parameters:\n", + " - ``timeout_seconds: int = 120``\n", + " - ``include_metadata: bool = False``\n", + " - Output: List[Dict[str, str]]" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "# Single entry from the output of project.export_queued_data_rows() (deprecated)\nsingle_output_example = \"\"\"\n[\n {'id': 'clpouak6nap2g0783ajd1d6pf',\n 'createdAt': '2023-12-03T02:04:34.062Z',\n 'updatedAt': '2023-12-03T02:05:33.797Z',\n 'externalId': None,\n 'globalKey': 'b57c9ab2-304f-4c17-ba5f-c536f39a6a46',\n 'metadataFields': [],\n 'customMetadata': [],\n 'rowData': 'https://storage.googleapis.com/labelbox-developer-testing-assets/image/data_files/santa.jpeg',\n 'mediaAttributes': {'assetType': 'image',\n 'contentLength': 305973,\n 'height': 1333,\n 'mimeType': 'image/jpeg',\n 'subType': 'jpeg',\n 'superType': 'image',\n 'width': 2000}}\n]\n\n\"\"\"", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "##### Export\n", + "\n", + "`project.export()`:\n", + "\n", + "- Parameters (Minimum required parameters): \n", + " - ```\"data_row_details\": True```\n", + " - ```\"project_details\": True```\n", + "- Required filters:\n", + " - ``` \"workflow_status\": \"ToLabel\"```\n", + " - Output:\n", + " - ```ExportTask```\n", + " - `ExportTask.has_result()` return type: bool\n", + " - `ExportTask.has_errors()` return type: bool\n", + " - `ExportTask.get_buffered_stream()` return type: Stream[BufferedJsonConverterOutput]\n", + " \n", + " For complete details on supported filters and parameters, including how they are used and what information is included, see [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters)." + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "export_params = {\n \"attachments\": True, # Set to true if you want to export attachments\n \"metadata_fields\": True, # Set to true if you want to export metadata\n \"data_row_details\": True,\n \"project_details\": True,\n}\nfilters = {\n \"workflow_status\":\n \"ToLabel\" ## Using this filter will only export queued data rows\n}\n\n# An ExportTask is returned, this provides additional information about the status of your task, such as\n# any errors encountered and includes additional methods to stream your data\n\nexport_task = project.export(params=export_params, filters=filters)\nexport_task.wait_till_done()", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.BufferedJsonConverterOutput):\n print(output.json)\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)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "## Export data rows from a Dataset" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "DATASET_ID = \"\"\ndataset = client.get_dataset(DATASET_ID)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "#### Export V1 (deprecated):\n", + "\n", + "`dataset.export_data_rows()`\n", + " - Parameters: \n", + " - ``timeout_seconds=120``\n", + " - ``include_metadata: bool = True``\n", + " - Output:\n", + " - Data row object generator\n" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "# Single entry from the output of dataset.export_data_rows() (deprecated)\n# Data row objects will not be deprecated.\n\nsingle_output_from_data_row_generator = \"\"\"\n\n\"\"\"", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "#### Export\n", + "\n", + "`project.export()`:\n", + "\n", + "- Parameters (minimum required parameters): \n", + " - ``\"data_row_details\": True``\n", + "- Output:\n", + " - ```ExportTask```\n", + " - `ExportTask.has_result()` return type: bool\n", + " - `ExportTask.has_errors()` return type: bool\n", + " - `ExportTask.get_buffered_stream()` return type: Stream[BufferedJsonConverterOutput]\n", + "\n", + " For complete details on supported filters and parameters, including how they are used and what information is included, see [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters).\n", + " " + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "export_params = {\n \"attachments\": True, # Set to true if you want to export attachments\n \"metadata_fields\": True, # Set to true if you want to export metadata\n \"data_row_details\": True,\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 = dataset.export(params=export_params, filters=filters)\nexport_task.wait_till_done()", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.BufferedJsonConverterOutput):\n print(output.json)\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)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "## Export data rows from a batch" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": [ + "#### Export V1 (deprecated):\n", + "`batch.export_data_rows()`\n", + " - Parameters: \n", + " - ``timeout_seconds=120``\n", + " - ``include_metadata: bool = True``\n", + " - Output:\n", + " - Data row object generator" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "# Single output from batch.export_data_rows() method (deprecated)\n# Data row objects will not be deprecated\n\nsingle_output_from_data_row_generator = \"\"\"\n\n\"\"\"", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "#### Export V2\n", + "\n", + "`project.export()`:\n", + "- Required parameters: \n", + " - ```\"data_row_details\": True```,\n", + " - ```\"batch_ids\": [] ```\n", + "- Output:\n", + " - ```ExportTask```\n", + " - `ExportTask.has_result()` return type: bool\n", + " - `ExportTask.has_errors()` return type: bool\n", + " - `ExportTask.get_buffered_stream()` return type: Stream[BufferedJsonConverterOutput]\n", + " \n", + " For complete details on supported filters and parameters, including how they are used and what information is included, see [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters)." + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "# Find the batch ID by navigating to \"Batches\" --> \"Manage batches\" --> \"Copy Batch ID\"\nBATCH_ID = \"\"", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "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_ID\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()", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.BufferedJsonConverterOutput):\n print(output.json)\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)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "## Export data rows from a Model" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": [ + "#### Export V1 (deprecated):\n", + "`model_run.export_labels(downlaod=True)`\n", + "- Parameters: \n", + " - ```download: bool = False```\n", + " - ```timeout_seconds: int = 1800```\n", + "- Output : (str | List[Dict[Any, Any]] | None)" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "# Single output from model_run.export_labels()\nsingle_output_example = \"\"\"\n[\n {'ID': '1c48a7a0-3016-48e0-b0e3-47430f974869',\n 'Data Split': 'training',\n 'DataRow ID': 'clpqdyf650xd40712pycshy6a',\n 'External ID': './resume/BANKING/99124477.pdf',\n 'Labeled Data': 'https://storage.labelbox.com/cl5bn8qvq1av907xtb3bp8q60%2F8c6afc38-42a4-b2e1-a2e3-1e3b0c2998fc-99124477.pdf?Expires=1706637969726&KeyName=labelbox-assets-key-3&Signature=2nVt3sJ21CbjGS9I64yFquUELRw',\n 'Media Attributes': {'assetType': 'pdf',\n 'contentLength': 42535,\n 'mimeType': 'application/pdf',\n 'pageCount': 3,\n 'subType': 'pdf',\n 'superType': 'application'},\n 'Label': {'objects': [{'featureId': 'b9f3b584-0f45-050a-88d4-39c2a169c8e1',\n 'schemaId': 'clq1ckwbd08jp07z91q9mch5j',\n 'title': 'Test',\n 'value': 'test',\n 'color': '#1CE6FF',\n 'data': {'location': [{'text-bbox': {'page': 1,\n 'top': 158.44,\n 'left': 58.765,\n 'height': 13.691,\n 'width': 78.261}}],\n 'unit': 'POINTS'}}],\n 'classifications': [],\n 'relationships': []}}\n ]\n \"\"\"", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "#### Export\n", + "\n", + "`model_run.export()`:\n", + "\n", + "- Required parameters: \n", + " - ```\"data_row_details\": True```\n", + " - ```\"project_details\": True```\n", + " - ```\"label_details\": True```\n", + "- Required filters:\n", + " - N/A -> Filters not supported\n", + "- Output:\n", + " - ```ExportTask```\n", + " - `ExportTask.has_result()` return type: bool\n", + " - `ExportTask.has_errors()` return type: bool\n", + " - `ExportTask.get_buffered_stream()` return type: Stream[BufferedJsonConverterOutput]\n", + "\n", + "For complete details on supported filters and parameters, including how they are used and what information is included, see [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters)." + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "MODEL_RUN_ID = \"\"\nmodel_run = client.get_model_run(MODEL_RUN_ID)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"performance_details\": True,\n}\n\nexport_task = model_run.export(params=export_params)\nexport_task.wait_till_done()", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": "# Provide results with JSON converter\n# Returns streamed JSON output strings from export task results/errors, one by one\n\n\n# Callback used for JSON Converter\ndef json_stream_handler(output: lb.BufferedJsonConverterOutput):\n print(output.json)\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)\n\nprint(\n \"file size: \",\n export_task.get_total_file_size(stream_type=lb.StreamType.RESULT),\n)\nprint(\n \"line count: \",\n export_task.get_total_lines(stream_type=lb.StreamType.RESULT),\n)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "## Export data rows from a video project\n", + "Video projects include additional fields. Please refer to the example below to extract specific fields from video exports.\n" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": [ + "##### Export V1 (deprecated) \n", + "1. ```project.export_labels()```\n", + " - Parameters: \n", + " - ```download: bool = False```\n", + " - ```timeout_seconds: int = 1800```\n", + " - Output : (str | List[Dict[Any, Any]] | None)" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": [ + "2. ```project.video_label_generator()```\n", + " - Parameters:\n", + " - ```timeout_seconds: int = 600```\n", + " - Output: LabelGenerator" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": [ + "##### Export\n", + "\n", + "1. `project.export()`:\n", + "\n", + "- Required parameters: \n", + " - ```\"attachments\": True```\n", + " - ```\"data_row_details\": True```\n", + " - ```\"project_details\": True```\n", + " - ```\"label_details\": True```\n", + " - ```\"performance_details\": True```\n", + "- Output:\n", + " - ```ExportTask```\n", + " - `ExportTask.has_result()` return type: bool\n", + " - `ExportTask.has_errors()` return type: bool\n", + " - `ExportTask.get_buffered_stream()` return type: Stream[BufferedJsonConverterOutput]\n", + " \n", + " For complete details on supported filters and parameters, including how they are used and what information is included, see [Export overview](https://docs.labelbox.com/reference/label-export#optional-parameters-and-filters)." + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "VIDEO_PROJECT_ID = \"\"\nproject = client.get_project(VIDEO_PROJECT_ID)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": "export_params = {\n \"attachments\": True,\n \"metadata_fields\": True,\n \"data_row_details\": True,\n \"project_details\": True,\n \"performance_details\": True,\n \"label_details\": True,\n \"interpolated_frames\":\n True, # For additional information on interpolated frames please visit our documentation https://docs.labelbox.com/docs/video-annotations#video-editor-components\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()", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "Fetch frame specific objects and frame or global classifications" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "import pprint as pp # Assuming pp is imported from pprint module\n\nframes_objects_class_list = []\nglobal_class_list = []\n\nstream = export_task.get_buffered_stream()\nfor output in stream:\n output_json = output.json\n for dr in output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]:\n frames_data = dr[\"annotations\"][\"frames\"]\n for k, v in frames_data.items():\n frames_objects_class_list.append({k: v})\n global_class_list.extend(dr[\"annotations\"][\"classifications\"])\n\n print(\"------- Frame specific classifications and objects -------\")\n pp.pprint(frames_objects_class_list)\n\n print(\"------ Global classifications -------\")\n pp.pprint(global_class_list)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "Fetch key frame feature map" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "keyframe_map = []\n\nstream = export_task.get_buffered_stream()\nfor output in stream:\n output_json = output.json\n labels = output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]\n for label in labels:\n annotations = label[\"annotations\"][\"key_frame_feature_map\"]\n for key, value in annotations.items():\n keyframe_map.append({key: value})\n\nprint(\"----- Keyframe Feature Map -----\")\npp.pprint(keyframe_map)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "Fetch segments" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "segments_map = []\nstream = export_task.get_buffered_stream()\nfor output in stream:\n output_json = output.json\n labels = output_json[\"projects\"][VIDEO_PROJECT_ID][\"labels\"]\n for label in labels:\n annotations = label[\"annotations\"][\"segments\"]\n for key, value in annotations.items():\n segments_map.append({key: value})\n\nprint(\"----- Segments Feature Map -----\")\npp.pprint(segments_map)", + "cell_type": "code", + "outputs": [], + "execution_count": null + } + ] +} \ No newline at end of file