Skip to content

[SN-145] removed buffered stream mentioning #1662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/annotation_import/pdf.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
},
{
"metadata": {},
"source": "client.enable_experimental = True\ntask = lb.DataRow.export(client=client, global_keys=[global_key])\ntask.wait_till_done()\nstream = task.get_stream()\n\ntext_layer = \"\"\nfor output in stream:\n output_json = json.loads(output.json_str)\n text_layer = output_json[\"media_attributes\"][\"text_layer_url\"]\nprint(text_layer)",
"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)",
"cell_type": "code",
"outputs": [],
"execution_count": null
Expand Down
4 changes: 2 additions & 2 deletions examples/basics/batches.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
},
{
"metadata": {},
"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.JsonConverterOutput):\n data_row = json.loads(output.json_str)\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n 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_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
"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)",
"cell_type": "code",
"outputs": [],
"execution_count": null
Expand Down Expand Up @@ -254,7 +254,7 @@
},
{
"metadata": {},
"source": "data_rows = []\n\n\ndef json_stream_handler(output: lb.JsonConverterOutput):\n data_row = json.loads(output.json_str)\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n 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_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
"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)",
"cell_type": "code",
"outputs": [],
"execution_count": null
Expand Down
2 changes: 1 addition & 1 deletion examples/basics/custom_embeddings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
},
{
"metadata": {},
"source": "data_rows = []\n\n\ndef json_stream_handler(output: lb.JsonConverterOutput):\n data_row = json.loads(output.json_str)\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n 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_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
"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)",
"cell_type": "code",
"outputs": [],
"execution_count": null
Expand Down
4 changes: 2 additions & 2 deletions examples/basics/data_rows.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
},
{
"metadata": {},
"source": "data_rows = []\n\n\ndef json_stream_handler(output: lb.JsonConverterOutput):\n data_row = json.loads(output.json_str)\n data_rows.append(data_row)\n\n\nif export_task.has_errors():\n export_task.get_stream(converter=lb.JsonConverter(),\n 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_stream(\n converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT).start(\n stream_handler=json_stream_handler)",
"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)",
"cell_type": "code",
"outputs": [],
"execution_count": null
Expand Down Expand Up @@ -236,7 +236,7 @@
},
{
"metadata": {},
"source": "# Fetch a data row from the first dataset example\nts = dataset.export()\nts.wait_till_done()\nDATA_ROW_ID = [json.loads(output.json_str) for output in ts.get_stream()\n ][0][\"data_row\"][\"id\"]\nGLOBAL_KEY = [json.loads(output.json_str) for output in ts.get_stream()\n ][0][\"data_row\"][\"global_key\"]\n\nprint(f\"Pick either a data row id : {DATA_ROW_ID} or global key: {GLOBAL_KEY}\")",
"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}\")",
"cell_type": "code",
"outputs": [],
"execution_count": null
Expand Down
4 changes: 2 additions & 2 deletions examples/exports/composite_mask_export.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
},
{
"metadata": {},
"source": "stream = export_task.get_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_str)\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)",
"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)",
"cell_type": "code",
"outputs": [],
"execution_count": null
Expand Down Expand Up @@ -246,7 +246,7 @@
},
{
"metadata": {},
"source": "tools_frames_color = {}\nstream = export_task_video.get_stream()\n\n# Iterate over each output in the stream\nfor output in stream:\n output_json = json.loads(output.json_str)\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)",
"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)",
"cell_type": "code",
"outputs": [],
"execution_count": null
Expand Down
Loading
Loading