From 4c8a14f4b43510cdf71ce1281c8af83e55ac7d34 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Tue, 28 May 2024 19:45:56 -0500 Subject: [PATCH 01/17] added quick_start notebook --- examples/basics/quick_start.ipynb | 78 +++++++++++++++++++++++++++++++ examples/pyproject.toml | 2 +- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 examples/basics/quick_start.ipynb diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb new file mode 100644 index 000000000..7de1ed789 --- /dev/null +++ b/examples/basics/quick_start.ipynb @@ -0,0 +1,78 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Quick Start\n", + "\n", + "This notebook is intended to be a quick overview on Labelbox-Python SDK by demonstrating a simple but common work flow\n", + "\n", + "In this guide, we will be:\n", + "\n", + "1. Creating a dataset:\n", + " A dataset is a collection of data rows imported into Labelbox.\n", + "2. Importing an image data row\n", + "3. Creating an ontology\n", + "4. Creating an project and attaching an ontology\n", + "5. Sending our data row towards are project by creating a batch\n", + "6. Exporting from our project\n", + "\n", + "This notebook is geared towards new users of our SDK." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup\n", + "\n", + "To start, we first need to install the labelbox library and then import the SDK module. It is recommended to install \"labelbox[data]\" over labelbox to obtain all the correct dependencies. We will also be importing the python UUID library to generate unique IDs for the variety of objects that will be created with this notebook." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%pip install -q \"labelbox[data]\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import labelbox as lb\n", + "import uuid" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## API Key and Client\n", + "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." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "API_KEY = None\n", + "client = lb.Client(api_key=API_KEY)" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/pyproject.toml b/examples/pyproject.toml index 152e59473..969454ecc 100644 --- a/examples/pyproject.toml +++ b/examples/pyproject.toml @@ -23,7 +23,7 @@ dev-dependencies = [ "black[jupyter]>=24.4.2", "databooks>=1.3.10", # higher versions dont support python 3.8 - "pandas>=1.5.3", + "pandas>=2.0.3", ] [tool.rye.scripts] From d502d4a21ac178dc270eb58b209fe1e166cae07b Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 29 May 2024 10:47:38 -0500 Subject: [PATCH 02/17] finished quick start guide --- examples/basics/quick_start.ipynb | 205 ++++++++++++++++++++++++++++-- 1 file changed, 197 insertions(+), 8 deletions(-) diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb index 7de1ed789..18891a0b5 100644 --- a/examples/basics/quick_start.ipynb +++ b/examples/basics/quick_start.ipynb @@ -6,17 +6,15 @@ "source": [ "# Quick Start\n", "\n", - "This notebook is intended to be a quick overview on Labelbox-Python SDK by demonstrating a simple but common work flow\n", + "This notebook is intended to be a quick overview on Labelbox-Python SDK by demonstrating a simple but common work flow.\n", "\n", "In this guide, we will be:\n", "\n", - "1. Creating a dataset:\n", - " A dataset is a collection of data rows imported into Labelbox.\n", - "2. Importing an image data row\n", - "3. Creating an ontology\n", - "4. Creating an project and attaching an ontology\n", - "5. Sending our data row towards are project by creating a batch\n", - "6. Exporting from our project\n", + "1. Creating a dataset and importing a image data row\n", + "2. Creating a ontology\n", + "3. Creating a project and attaching our ontology\n", + "4. Sending our data row to our Project by creating a batch\n", + "5. Exporting from our project\n", "\n", "This notebook is geared towards new users of our SDK." ] @@ -66,6 +64,197 @@ "API_KEY = None\n", "client = lb.Client(api_key=API_KEY)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Step 1: Create Dataset and Import Data Row\n", + "\n", + "Below we will be creating a dataset and then attaching a publicly hosted image data row. Typically you would either import data rows that are hosted on a cloud provider (_recommended_) or import them locally. For more information, visit our [import image data section](https://docs.labelbox.com/reference/image) in our developer guides.\n", + "\n", + "* Data rows are internal representation of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", + "* A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catelog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Create dataset from client\n", + "dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n", + "\n", + "global_key = str(uuid.uuid4()) # Unique user specified ID\n", + "\n", + "# Data row structure\n", + "image_data_rows = [\n", + " {\n", + " \"row_data\": \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n", + " \"global_key\": global_key,\n", + " \"media_type\": \"IMAGE\",\n", + " }\n", + "]\n", + "\n", + "# Bulk import data row\n", + "task = dataset.create_data_rows(image_data_rows) # List of data rows\n", + "task.wait_till_done()\n", + "print(task.errors) # Print any errors" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Step 2: Creating an Ontology\n", + "\n", + "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a check list classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", + "\n", + "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Bounding box feature\n", + "object_features = [\n", + " lb.Tool(\n", + " tool=lb.Tool.Type.BBOX,\n", + " name=\"regulatory-sign\",\n", + " color=\"#ff0000\",\n", + " )\n", + "]\n", + "\n", + "# Checklist feature\n", + "classification_features = [\n", + " lb.Classification(\n", + " class_type=lb.Classification.Type.CHECKLIST,\n", + " name=\"Quality Issues\",\n", + " options=[\n", + " lb.Option(value=\"blurry\", label=\"Blurry\"),\n", + " lb.Option(value=\"distorted\", label=\"Distorted\")\n", + " ]\n", + " )\n", + "\n", + "]\n", + "\n", + "# Builder function\n", + "ontology_builder = lb.OntologyBuilder(\n", + " tools=object_features,\n", + " classifications=classification_features\n", + ")\n", + "\n", + "# Create ontology\n", + "ontology = client.create_ontology(\n", + " \"Ontology from new features\",\n", + " ontology_builder.asdict(),\n", + " media_type=lb.MediaType.Image\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Step 3: Creating a Project and Attaching our Ontology\n", + "\n", + "Now that we have made our ontology we are ready to create a project were we can label our data row.\n", + "\n", + "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Create a new project\n", + "project = client.create_project(\n", + " name=\"Quick Start Example Project\", \n", + " media_type=lb.MediaType.Image # specify the media type\n", + ")\n", + "\n", + "# Attach created ontology\n", + "project.setup_editor(ontology)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", + "\n", + "With our project created we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue were labelers are able to annotate our data row. For more information on batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "project.create_batch(\n", + " name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n", + " global_keys=[global_key], # Global key we used earlier in this guide to create our dataset\n", + " priority=5,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Step 5: Exporting from our Project\n", + "\n", + "We have now successfully set up a project for labeling using only the SDK! 🚀 From here you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide no labels will be presented on our data row. For a full overview of exporting visit our our [export overview](https://docs.labelbox.com/reference/label-export) developer guide. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Start export from project\n", + "export_task = project.export()\n", + "export_task.wait_till_done()\n", + "\n", + "# Conditional if task has errors\n", + "if export_task.has_errors():\n", + " export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n", + " stream_handler=lambda error: print(error))\n", + "\n", + "# Start export stream\n", + "stream = export_task.get_buffered_stream()\n", + "\n", + "# Iterate through data rows\n", + "for data_row in stream:\n", + " print(data_row.json)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Clean up\n", + "This section serves as an optional clean up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# project.delete()\n", + "# client.delete_unused_ontology(ontology.uid)\n", + "# dataset.delete()" + ] } ], "metadata": { From c0460749ff008d3d9f90c3d810f07060309a30f3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 29 May 2024 15:49:29 +0000 Subject: [PATCH 03/17] :art: Cleaned --- examples/basics/quick_start.ipynb | 427 +++++++++++------------------- 1 file changed, 161 insertions(+), 266 deletions(-) diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb index 18891a0b5..84fff7230 100644 --- a/examples/basics/quick_start.ipynb +++ b/examples/basics/quick_start.ipynb @@ -1,267 +1,162 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Quick Start\n", - "\n", - "This notebook is intended to be a quick overview on Labelbox-Python SDK by demonstrating a simple but common work flow.\n", - "\n", - "In this guide, we will be:\n", - "\n", - "1. Creating a dataset and importing a image data row\n", - "2. Creating a ontology\n", - "3. Creating a project and attaching our ontology\n", - "4. Sending our data row to our Project by creating a batch\n", - "5. Exporting from our project\n", - "\n", - "This notebook is geared towards new users of our SDK." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Setup\n", - "\n", - "To start, we first need to install the labelbox library and then import the SDK module. It is recommended to install \"labelbox[data]\" over labelbox to obtain all the correct dependencies. We will also be importing the python UUID library to generate unique IDs for the variety of objects that will be created with this notebook." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%pip install -q \"labelbox[data]\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import labelbox as lb\n", - "import uuid" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## API Key and Client\n", - "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." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "API_KEY = None\n", - "client = lb.Client(api_key=API_KEY)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Step 1: Create Dataset and Import Data Row\n", - "\n", - "Below we will be creating a dataset and then attaching a publicly hosted image data row. Typically you would either import data rows that are hosted on a cloud provider (_recommended_) or import them locally. For more information, visit our [import image data section](https://docs.labelbox.com/reference/image) in our developer guides.\n", - "\n", - "* Data rows are internal representation of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", - "* A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catelog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Create dataset from client\n", - "dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n", - "\n", - "global_key = str(uuid.uuid4()) # Unique user specified ID\n", - "\n", - "# Data row structure\n", - "image_data_rows = [\n", - " {\n", - " \"row_data\": \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n", - " \"global_key\": global_key,\n", - " \"media_type\": \"IMAGE\",\n", - " }\n", - "]\n", - "\n", - "# Bulk import data row\n", - "task = dataset.create_data_rows(image_data_rows) # List of data rows\n", - "task.wait_till_done()\n", - "print(task.errors) # Print any errors" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Step 2: Creating an Ontology\n", - "\n", - "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a check list classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", - "\n", - "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Bounding box feature\n", - "object_features = [\n", - " lb.Tool(\n", - " tool=lb.Tool.Type.BBOX,\n", - " name=\"regulatory-sign\",\n", - " color=\"#ff0000\",\n", - " )\n", - "]\n", - "\n", - "# Checklist feature\n", - "classification_features = [\n", - " lb.Classification(\n", - " class_type=lb.Classification.Type.CHECKLIST,\n", - " name=\"Quality Issues\",\n", - " options=[\n", - " lb.Option(value=\"blurry\", label=\"Blurry\"),\n", - " lb.Option(value=\"distorted\", label=\"Distorted\")\n", - " ]\n", - " )\n", - "\n", - "]\n", - "\n", - "# Builder function\n", - "ontology_builder = lb.OntologyBuilder(\n", - " tools=object_features,\n", - " classifications=classification_features\n", - ")\n", - "\n", - "# Create ontology\n", - "ontology = client.create_ontology(\n", - " \"Ontology from new features\",\n", - " ontology_builder.asdict(),\n", - " media_type=lb.MediaType.Image\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Step 3: Creating a Project and Attaching our Ontology\n", - "\n", - "Now that we have made our ontology we are ready to create a project were we can label our data row.\n", - "\n", - "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Create a new project\n", - "project = client.create_project(\n", - " name=\"Quick Start Example Project\", \n", - " media_type=lb.MediaType.Image # specify the media type\n", - ")\n", - "\n", - "# Attach created ontology\n", - "project.setup_editor(ontology)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", - "\n", - "With our project created we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue were labelers are able to annotate our data row. For more information on batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "project.create_batch(\n", - " name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n", - " global_keys=[global_key], # Global key we used earlier in this guide to create our dataset\n", - " priority=5,\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Step 5: Exporting from our Project\n", - "\n", - "We have now successfully set up a project for labeling using only the SDK! 🚀 From here you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide no labels will be presented on our data row. For a full overview of exporting visit our our [export overview](https://docs.labelbox.com/reference/label-export) developer guide. " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Start export from project\n", - "export_task = project.export()\n", - "export_task.wait_till_done()\n", - "\n", - "# Conditional if task has errors\n", - "if export_task.has_errors():\n", - " export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n", - " stream_handler=lambda error: print(error))\n", - "\n", - "# Start export stream\n", - "stream = export_task.get_buffered_stream()\n", - "\n", - "# Iterate through data rows\n", - "for data_row in stream:\n", - " print(data_row.json)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Clean up\n", - "This section serves as an optional clean up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# project.delete()\n", - "# client.delete_unused_ontology(ontology.uid)\n", - "# dataset.delete()" - ] - } - ], - "metadata": { - "language_info": { - "name": "python" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} + "nbformat": 4, + "nbformat_minor": 2, + "metadata": {}, + "cells": [ + { + "metadata": {}, + "source": [ + "", + " ", + "\n" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "" + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "%pip install -q \"labelbox[data]\"", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": "import labelbox as lb\nimport uuid", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "## API Key and Client\n", + "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." + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "## Step 1: Create Dataset and Import Data Row\n", + "\n", + "Below we will be creating a dataset and then attaching a publicly hosted image data row. Typically you would either import data rows that are hosted on a cloud provider (_recommended_) or import them locally. For more information, visit our [import image data section](https://docs.labelbox.com/reference/image) in our developer guides.\n", + "\n", + "* Data rows are internal representation of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", + "* A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catelog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "# Create dataset from client\ndataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n\nglobal_key = str(uuid.uuid4()) # Unique user specified ID\n\n# Data row structure\nimage_data_rows = [{\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"IMAGE\",\n}]\n\n# Bulk import data row\ntask = dataset.create_data_rows(image_data_rows) # List of data rows\ntask.wait_till_done()\nprint(task.errors) # Print any errors", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "## Step 2: Creating an Ontology\n", + "\n", + "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a check list classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", + "\n", + "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "# Bounding box feature\nobject_features = [\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"regulatory-sign\",\n color=\"#ff0000\",\n )\n]\n\n# Checklist feature\nclassification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\n# Builder function\nontology_builder = lb.OntologyBuilder(tools=object_features,\n classifications=classification_features)\n\n# Create ontology\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "## Step 3: Creating a Project and Attaching our Ontology\n", + "\n", + "Now that we have made our ontology we are ready to create a project were we can label our data row.\n", + "\n", + "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "# Create a new project\nproject = client.create_project(\n name=\"Quick Start Example Project\",\n media_type=lb.MediaType.Image, # specify the media type\n)\n\n# Attach created ontology\nproject.setup_editor(ontology)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", + "\n", + "With our project created we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue were labelers are able to annotate our data row. For more information on batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "project.create_batch(\n name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n global_keys=[\n global_key\n ], # Global key we used earlier in this guide to create our dataset\n priority=5,\n)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "# Step 5: Exporting from our Project\n", + "\n", + "We have now successfully set up a project for labeling using only the SDK! \ud83d\ude80 From here you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide no labels will be presented on our data row. For a full overview of exporting visit our our [export overview](https://docs.labelbox.com/reference/label-export) developer guide. " + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "# Start export from project\nexport_task = project.export()\nexport_task.wait_till_done()\n\n# Conditional if task has errors\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\n# Start export stream\nstream = export_task.get_buffered_stream()\n\n# Iterate through data rows\nfor data_row in stream:\n print(data_row.json)", + "cell_type": "code", + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "source": [ + "## Clean up\n", + "This section serves as an optional clean up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." + ], + "cell_type": "markdown" + }, + { + "metadata": {}, + "source": "# project.delete()\n# client.delete_unused_ontology(ontology.uid)\n# dataset.delete()", + "cell_type": "code", + "outputs": [], + "execution_count": null + } + ] +} \ No newline at end of file From 144e6c18c02b4b18ccef860b8dbfa6f83f9598a3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 29 May 2024 15:50:08 +0000 Subject: [PATCH 04/17] :memo: README updated --- examples/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/README.md b/examples/README.md index 8abd54521..48580ecbb 100644 --- a/examples/README.md +++ b/examples/README.md @@ -46,6 +46,11 @@ Open In Github Open In Colab + + Quick Start + Open In Github + Open In Colab + Basics Open In Github From 882935872adc8471a6fb0249737b2841c5c3e02c Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 29 May 2024 10:52:57 -0500 Subject: [PATCH 05/17] fixed header --- examples/basics/quick_start.ipynb | 233 +++++++++++++++++++++++------- 1 file changed, 181 insertions(+), 52 deletions(-) diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb index 84fff7230..cb98cdaea 100644 --- a/examples/basics/quick_start.ipynb +++ b/examples/basics/quick_start.ipynb @@ -1,18 +1,16 @@ { - "nbformat": 4, - "nbformat_minor": 2, - "metadata": {}, "cells": [ { + "cell_type": "markdown", "metadata": {}, "source": [ - "", - " ", + "\n", + " \n", "\n" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "\n", @@ -24,39 +22,75 @@ "\n", "" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, - "source": "%pip install -q \"labelbox[data]\"", + "source": [ + "# Quick Start\n", + "\n", + "This notebook is intended to be a quick overview on Labelbox-Python SDK by demonstrating a simple but common work flow.\n", + "\n", + "In this guide, we will be:\n", + "\n", + "1. Creating a dataset and importing a image data row\n", + "2. Creating a ontology\n", + "3. Creating a project and attaching our ontology\n", + "4. Sending our data row to our Project by creating a batch\n", + "5. Exporting from our project\n", + "\n", + "This notebook is geared towards new users of our SDK." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup\n", + "\n", + "To start, we first need to install the labelbox library and then import the SDK module. It is recommended to install \"labelbox[data]\" over labelbox to obtain all the correct dependencies. We will also be importing the python UUID library to generate unique IDs for the variety of objects that will be created with this notebook." + ] + }, + { "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "%pip install -q \"labelbox[data]\"" + ] }, { - "metadata": {}, - "source": "import labelbox as lb\nimport uuid", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "import labelbox as lb\n", + "import uuid" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## API Key and Client\n", "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." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "API_KEY = None\n", + "client = lb.Client(api_key=API_KEY)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1: Create Dataset and Import Data Row\n", @@ -65,17 +99,37 @@ "\n", "* Data rows are internal representation of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", "* A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catelog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Create dataset from client\ndataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n\nglobal_key = str(uuid.uuid4()) # Unique user specified ID\n\n# Data row structure\nimage_data_rows = [{\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"IMAGE\",\n}]\n\n# Bulk import data row\ntask = dataset.create_data_rows(image_data_rows) # List of data rows\ntask.wait_till_done()\nprint(task.errors) # Print any errors", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Create dataset from client\n", + "dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n", + "\n", + "global_key = str(uuid.uuid4()) # Unique user specified ID\n", + "\n", + "# Data row structure\n", + "image_data_rows = [{\n", + " \"row_data\":\n", + " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n", + " \"global_key\":\n", + " global_key,\n", + " \"media_type\":\n", + " \"IMAGE\",\n", + "}]\n", + "\n", + "# Bulk import data row\n", + "task = dataset.create_data_rows(image_data_rows) # List of data rows\n", + "task.wait_till_done()\n", + "print(task.errors) # Print any errors" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 2: Creating an Ontology\n", @@ -83,17 +137,49 @@ "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a check list classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", "\n", "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Bounding box feature\nobject_features = [\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"regulatory-sign\",\n color=\"#ff0000\",\n )\n]\n\n# Checklist feature\nclassification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\n# Builder function\nontology_builder = lb.OntologyBuilder(tools=object_features,\n classifications=classification_features)\n\n# Create ontology\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Bounding box feature\n", + "object_features = [\n", + " lb.Tool(\n", + " tool=lb.Tool.Type.BBOX,\n", + " name=\"regulatory-sign\",\n", + " color=\"#ff0000\",\n", + " )\n", + "]\n", + "\n", + "# Checklist feature\n", + "classification_features = [\n", + " lb.Classification(\n", + " class_type=lb.Classification.Type.CHECKLIST,\n", + " name=\"Quality Issues\",\n", + " options=[\n", + " lb.Option(value=\"blurry\", label=\"Blurry\"),\n", + " lb.Option(value=\"distorted\", label=\"Distorted\"),\n", + " ],\n", + " )\n", + "]\n", + "\n", + "# Builder function\n", + "ontology_builder = lb.OntologyBuilder(tools=object_features,\n", + " classifications=classification_features)\n", + "\n", + "# Create ontology\n", + "ontology = client.create_ontology(\n", + " \"Ontology from new features\",\n", + " ontology_builder.asdict(),\n", + " media_type=lb.MediaType.Image,\n", + ")" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 3: Creating a Project and Attaching our Ontology\n", @@ -101,62 +187,105 @@ "Now that we have made our ontology we are ready to create a project were we can label our data row.\n", "\n", "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Create a new project\nproject = client.create_project(\n name=\"Quick Start Example Project\",\n media_type=lb.MediaType.Image, # specify the media type\n)\n\n# Attach created ontology\nproject.setup_editor(ontology)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Create a new project\n", + "project = client.create_project(\n", + " name=\"Quick Start Example Project\",\n", + " media_type=lb.MediaType.Image, # specify the media type\n", + ")\n", + "\n", + "# Attach created ontology\n", + "project.setup_editor(ontology)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", "\n", "With our project created we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue were labelers are able to annotate our data row. For more information on batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "project.create_batch(\n name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n global_keys=[\n global_key\n ], # Global key we used earlier in this guide to create our dataset\n priority=5,\n)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "project.create_batch(\n", + " name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n", + " global_keys=[\n", + " global_key\n", + " ], # Global key we used earlier in this guide to create our dataset\n", + " priority=5,\n", + ")" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "# Step 5: Exporting from our Project\n", "\n", - "We have now successfully set up a project for labeling using only the SDK! \ud83d\ude80 From here you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide no labels will be presented on our data row. For a full overview of exporting visit our our [export overview](https://docs.labelbox.com/reference/label-export) developer guide. " - ], - "cell_type": "markdown" + "We have now successfully set up a project for labeling using only the SDK! 🚀 From here you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide no labels will be presented on our data row. For a full overview of exporting visit our our [export overview](https://docs.labelbox.com/reference/label-export) developer guide. " + ] }, { - "metadata": {}, - "source": "# Start export from project\nexport_task = project.export()\nexport_task.wait_till_done()\n\n# Conditional if task has errors\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\n# Start export stream\nstream = export_task.get_buffered_stream()\n\n# Iterate through data rows\nfor data_row in stream:\n print(data_row.json)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Start export from project\n", + "export_task = project.export()\n", + "export_task.wait_till_done()\n", + "\n", + "# Conditional if task has errors\n", + "if export_task.has_errors():\n", + " export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n", + " stream_handler=lambda error: print(error))\n", + "\n", + "# Start export stream\n", + "stream = export_task.get_buffered_stream()\n", + "\n", + "# Iterate through data rows\n", + "for data_row in stream:\n", + " print(data_row.json)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Clean up\n", "This section serves as an optional clean up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# project.delete()\n# client.delete_unused_ontology(ontology.uid)\n# dataset.delete()", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# project.delete()\n", + "# client.delete_unused_ontology(ontology.uid)\n", + "# dataset.delete()" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" } - ] -} \ No newline at end of file + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 604e81961cb988140475036ed3c9d5364433b493 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 29 May 2024 15:53:50 +0000 Subject: [PATCH 06/17] :art: Cleaned --- examples/basics/quick_start.ipynb | 215 ++++++++---------------------- 1 file changed, 57 insertions(+), 158 deletions(-) diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb index cb98cdaea..34a6ae176 100644 --- a/examples/basics/quick_start.ipynb +++ b/examples/basics/quick_start.ipynb @@ -1,16 +1,18 @@ { + "nbformat": 4, + "nbformat_minor": 2, + "metadata": {}, "cells": [ { - "cell_type": "markdown", "metadata": {}, "source": [ - "\n", - " \n", + "", + " ", "\n" - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "\n", @@ -22,10 +24,10 @@ "\n", "" - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "# Quick Start\n", @@ -41,56 +43,48 @@ "5. Exporting from our project\n", "\n", "This notebook is geared towards new users of our SDK." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Setup\n", "\n", "To start, we first need to install the labelbox library and then import the SDK module. It is recommended to install \"labelbox[data]\" over labelbox to obtain all the correct dependencies. We will also be importing the python UUID library to generate unique IDs for the variety of objects that will be created with this notebook." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "%pip install -q \"labelbox[data]\"", + "cell_type": "code", "outputs": [], - "source": [ - "%pip install -q \"labelbox[data]\"" - ] + "execution_count": null }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "import labelbox as lb\nimport uuid", + "cell_type": "code", "outputs": [], - "source": [ - "import labelbox as lb\n", - "import uuid" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## API Key and Client\n", "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." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)", + "cell_type": "code", "outputs": [], - "source": [ - "API_KEY = None\n", - "client = lb.Client(api_key=API_KEY)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1: Create Dataset and Import Data Row\n", @@ -99,37 +93,17 @@ "\n", "* Data rows are internal representation of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", "* A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catelog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Create dataset from client\ndataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n\nglobal_key = str(uuid.uuid4()) # Unique user specified ID\n\n# Data row structure\nimage_data_rows = [{\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"IMAGE\",\n}]\n\n# Bulk import data row\ntask = dataset.create_data_rows(image_data_rows) # List of data rows\ntask.wait_till_done()\nprint(task.errors) # Print any errors", + "cell_type": "code", "outputs": [], - "source": [ - "# Create dataset from client\n", - "dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n", - "\n", - "global_key = str(uuid.uuid4()) # Unique user specified ID\n", - "\n", - "# Data row structure\n", - "image_data_rows = [{\n", - " \"row_data\":\n", - " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n", - " \"global_key\":\n", - " global_key,\n", - " \"media_type\":\n", - " \"IMAGE\",\n", - "}]\n", - "\n", - "# Bulk import data row\n", - "task = dataset.create_data_rows(image_data_rows) # List of data rows\n", - "task.wait_till_done()\n", - "print(task.errors) # Print any errors" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 2: Creating an Ontology\n", @@ -137,49 +111,17 @@ "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a check list classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", "\n", "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Bounding box feature\nobject_features = [\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"regulatory-sign\",\n color=\"#ff0000\",\n )\n]\n\n# Checklist feature\nclassification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\n# Builder function\nontology_builder = lb.OntologyBuilder(tools=object_features,\n classifications=classification_features)\n\n# Create ontology\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)", + "cell_type": "code", "outputs": [], - "source": [ - "# Bounding box feature\n", - "object_features = [\n", - " lb.Tool(\n", - " tool=lb.Tool.Type.BBOX,\n", - " name=\"regulatory-sign\",\n", - " color=\"#ff0000\",\n", - " )\n", - "]\n", - "\n", - "# Checklist feature\n", - "classification_features = [\n", - " lb.Classification(\n", - " class_type=lb.Classification.Type.CHECKLIST,\n", - " name=\"Quality Issues\",\n", - " options=[\n", - " lb.Option(value=\"blurry\", label=\"Blurry\"),\n", - " lb.Option(value=\"distorted\", label=\"Distorted\"),\n", - " ],\n", - " )\n", - "]\n", - "\n", - "# Builder function\n", - "ontology_builder = lb.OntologyBuilder(tools=object_features,\n", - " classifications=classification_features)\n", - "\n", - "# Create ontology\n", - "ontology = client.create_ontology(\n", - " \"Ontology from new features\",\n", - " ontology_builder.asdict(),\n", - " media_type=lb.MediaType.Image,\n", - ")" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 3: Creating a Project and Attaching our Ontology\n", @@ -187,105 +129,62 @@ "Now that we have made our ontology we are ready to create a project were we can label our data row.\n", "\n", "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Create a new project\nproject = client.create_project(\n name=\"Quick Start Example Project\",\n media_type=lb.MediaType.Image, # specify the media type\n)\n\n# Attach created ontology\nproject.setup_editor(ontology)", + "cell_type": "code", "outputs": [], - "source": [ - "# Create a new project\n", - "project = client.create_project(\n", - " name=\"Quick Start Example Project\",\n", - " media_type=lb.MediaType.Image, # specify the media type\n", - ")\n", - "\n", - "# Attach created ontology\n", - "project.setup_editor(ontology)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", "\n", "With our project created we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue were labelers are able to annotate our data row. For more information on batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "project.create_batch(\n name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n global_keys=[\n global_key\n ], # Global key we used earlier in this guide to create our dataset\n priority=5,\n)", + "cell_type": "code", "outputs": [], - "source": [ - "project.create_batch(\n", - " name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n", - " global_keys=[\n", - " global_key\n", - " ], # Global key we used earlier in this guide to create our dataset\n", - " priority=5,\n", - ")" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "# Step 5: Exporting from our Project\n", "\n", - "We have now successfully set up a project for labeling using only the SDK! 🚀 From here you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide no labels will be presented on our data row. For a full overview of exporting visit our our [export overview](https://docs.labelbox.com/reference/label-export) developer guide. " - ] + "We have now successfully set up a project for labeling using only the SDK! \ud83d\ude80 From here you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide no labels will be presented on our data row. For a full overview of exporting visit our our [export overview](https://docs.labelbox.com/reference/label-export) developer guide. " + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Start export from project\nexport_task = project.export()\nexport_task.wait_till_done()\n\n# Conditional if task has errors\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\n# Start export stream\nstream = export_task.get_buffered_stream()\n\n# Iterate through data rows\nfor data_row in stream:\n print(data_row.json)", + "cell_type": "code", "outputs": [], - "source": [ - "# Start export from project\n", - "export_task = project.export()\n", - "export_task.wait_till_done()\n", - "\n", - "# Conditional if task has errors\n", - "if export_task.has_errors():\n", - " export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n", - " stream_handler=lambda error: print(error))\n", - "\n", - "# Start export stream\n", - "stream = export_task.get_buffered_stream()\n", - "\n", - "# Iterate through data rows\n", - "for data_row in stream:\n", - " print(data_row.json)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Clean up\n", "This section serves as an optional clean up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# project.delete()\n# client.delete_unused_ontology(ontology.uid)\n# dataset.delete()", + "cell_type": "code", "outputs": [], - "source": [ - "# project.delete()\n", - "# client.delete_unused_ontology(ontology.uid)\n", - "# dataset.delete()" - ] + "execution_count": null } - ], - "metadata": { - "language_info": { - "name": "python" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} + ] +} \ No newline at end of file From ed4ce66ba6239e19d2352cc6643daea8a3e2bae3 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 29 May 2024 10:59:15 -0500 Subject: [PATCH 07/17] typo --- examples/basics/quick_start.ipynb | 217 ++++++++++++++++++++++-------- 1 file changed, 160 insertions(+), 57 deletions(-) diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb index 34a6ae176..e9509a89f 100644 --- a/examples/basics/quick_start.ipynb +++ b/examples/basics/quick_start.ipynb @@ -1,18 +1,16 @@ { - "nbformat": 4, - "nbformat_minor": 2, - "metadata": {}, "cells": [ { + "cell_type": "markdown", "metadata": {}, "source": [ - "", - " ", + "\n", + " \n", "\n" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "\n", @@ -24,10 +22,10 @@ "\n", "" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "# Quick Start\n", @@ -43,48 +41,56 @@ "5. Exporting from our project\n", "\n", "This notebook is geared towards new users of our SDK." - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Setup\n", "\n", "To start, we first need to install the labelbox library and then import the SDK module. It is recommended to install \"labelbox[data]\" over labelbox to obtain all the correct dependencies. We will also be importing the python UUID library to generate unique IDs for the variety of objects that will be created with this notebook." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "%pip install -q \"labelbox[data]\"", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "%pip install -q \"labelbox[data]\"" + ] }, { - "metadata": {}, - "source": "import labelbox as lb\nimport uuid", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "import labelbox as lb\n", + "import uuid" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## API Key and Client\n", "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." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "API_KEY = None\n", + "client = lb.Client(api_key=API_KEY)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1: Create Dataset and Import Data Row\n", @@ -93,17 +99,37 @@ "\n", "* Data rows are internal representation of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", "* A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catelog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Create dataset from client\ndataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n\nglobal_key = str(uuid.uuid4()) # Unique user specified ID\n\n# Data row structure\nimage_data_rows = [{\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"IMAGE\",\n}]\n\n# Bulk import data row\ntask = dataset.create_data_rows(image_data_rows) # List of data rows\ntask.wait_till_done()\nprint(task.errors) # Print any errors", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Create dataset from client\n", + "dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n", + "\n", + "global_key = str(uuid.uuid4()) # Unique user specified ID\n", + "\n", + "# Data row structure\n", + "image_data_rows = [{\n", + " \"row_data\":\n", + " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n", + " \"global_key\":\n", + " global_key,\n", + " \"media_type\":\n", + " \"IMAGE\",\n", + "}]\n", + "\n", + "# Bulk import data row\n", + "task = dataset.create_data_rows(image_data_rows) # List of data rows\n", + "task.wait_till_done()\n", + "print(task.errors) # Print any errors" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 2: Creating an Ontology\n", @@ -111,17 +137,49 @@ "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a check list classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", "\n", "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Bounding box feature\nobject_features = [\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"regulatory-sign\",\n color=\"#ff0000\",\n )\n]\n\n# Checklist feature\nclassification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\n# Builder function\nontology_builder = lb.OntologyBuilder(tools=object_features,\n classifications=classification_features)\n\n# Create ontology\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Bounding box feature\n", + "object_features = [\n", + " lb.Tool(\n", + " tool=lb.Tool.Type.BBOX,\n", + " name=\"regulatory-sign\",\n", + " color=\"#ff0000\",\n", + " )\n", + "]\n", + "\n", + "# Checklist feature\n", + "classification_features = [\n", + " lb.Classification(\n", + " class_type=lb.Classification.Type.CHECKLIST,\n", + " name=\"Quality Issues\",\n", + " options=[\n", + " lb.Option(value=\"blurry\", label=\"Blurry\"),\n", + " lb.Option(value=\"distorted\", label=\"Distorted\"),\n", + " ],\n", + " )\n", + "]\n", + "\n", + "# Builder function\n", + "ontology_builder = lb.OntologyBuilder(tools=object_features,\n", + " classifications=classification_features)\n", + "\n", + "# Create ontology\n", + "ontology = client.create_ontology(\n", + " \"Ontology from new features\",\n", + " ontology_builder.asdict(),\n", + " media_type=lb.MediaType.Image,\n", + ")" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 3: Creating a Project and Attaching our Ontology\n", @@ -129,62 +187,107 @@ "Now that we have made our ontology we are ready to create a project were we can label our data row.\n", "\n", "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Create a new project\nproject = client.create_project(\n name=\"Quick Start Example Project\",\n media_type=lb.MediaType.Image, # specify the media type\n)\n\n# Attach created ontology\nproject.setup_editor(ontology)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Create a new project\n", + "project = client.create_project(\n", + " name=\"Quick Start Example Project\",\n", + " media_type=lb.MediaType.Image, # specify the media type\n", + ")\n", + "\n", + "# Attach created ontology\n", + "project.setup_editor(ontology)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", "\n", "With our project created we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue were labelers are able to annotate our data row. For more information on batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "project.create_batch(\n name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n global_keys=[\n global_key\n ], # Global key we used earlier in this guide to create our dataset\n priority=5,\n)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "project.create_batch(\n", + " name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n", + " global_keys=[\n", + " global_key\n", + " ], # Global key we used earlier in this guide to create our dataset\n", + " priority=5,\n", + ")" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "# Step 5: Exporting from our Project\n", "\n", - "We have now successfully set up a project for labeling using only the SDK! \ud83d\ude80 From here you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide no labels will be presented on our data row. For a full overview of exporting visit our our [export overview](https://docs.labelbox.com/reference/label-export) developer guide. " - ], - "cell_type": "markdown" + "We have now successfully set up a project for labeling using only the SDK! 🚀 \n", + "\n", + "From here you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide no labels will be presented on our data row. For a full overview of exporting visit our [export overview](https://docs.labelbox.com/reference/label-export) developer guide. " + ] }, { - "metadata": {}, - "source": "# Start export from project\nexport_task = project.export()\nexport_task.wait_till_done()\n\n# Conditional if task has errors\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\n# Start export stream\nstream = export_task.get_buffered_stream()\n\n# Iterate through data rows\nfor data_row in stream:\n print(data_row.json)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Start export from project\n", + "export_task = project.export()\n", + "export_task.wait_till_done()\n", + "\n", + "# Conditional if task has errors\n", + "if export_task.has_errors():\n", + " export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n", + " stream_handler=lambda error: print(error))\n", + "\n", + "# Start export stream\n", + "stream = export_task.get_buffered_stream()\n", + "\n", + "# Iterate through data rows\n", + "for data_row in stream:\n", + " print(data_row.json)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Clean up\n", "This section serves as an optional clean up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# project.delete()\n# client.delete_unused_ontology(ontology.uid)\n# dataset.delete()", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# project.delete()\n", + "# client.delete_unused_ontology(ontology.uid)\n", + "# dataset.delete()" + ] } - ] -} \ No newline at end of file + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From d689b2069d4be8ccfe56ead170cb38e0e66074dc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 29 May 2024 16:00:08 +0000 Subject: [PATCH 08/17] :art: Cleaned --- examples/basics/quick_start.ipynb | 215 ++++++++---------------------- 1 file changed, 57 insertions(+), 158 deletions(-) diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb index e9509a89f..3205acd00 100644 --- a/examples/basics/quick_start.ipynb +++ b/examples/basics/quick_start.ipynb @@ -1,16 +1,18 @@ { + "nbformat": 4, + "nbformat_minor": 2, + "metadata": {}, "cells": [ { - "cell_type": "markdown", "metadata": {}, "source": [ - "\n", - " \n", + "", + " ", "\n" - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "\n", @@ -22,10 +24,10 @@ "\n", "" - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "# Quick Start\n", @@ -41,56 +43,48 @@ "5. Exporting from our project\n", "\n", "This notebook is geared towards new users of our SDK." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Setup\n", "\n", "To start, we first need to install the labelbox library and then import the SDK module. It is recommended to install \"labelbox[data]\" over labelbox to obtain all the correct dependencies. We will also be importing the python UUID library to generate unique IDs for the variety of objects that will be created with this notebook." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "%pip install -q \"labelbox[data]\"", + "cell_type": "code", "outputs": [], - "source": [ - "%pip install -q \"labelbox[data]\"" - ] + "execution_count": null }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "import labelbox as lb\nimport uuid", + "cell_type": "code", "outputs": [], - "source": [ - "import labelbox as lb\n", - "import uuid" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## API Key and Client\n", "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." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)", + "cell_type": "code", "outputs": [], - "source": [ - "API_KEY = None\n", - "client = lb.Client(api_key=API_KEY)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1: Create Dataset and Import Data Row\n", @@ -99,37 +93,17 @@ "\n", "* Data rows are internal representation of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", "* A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catelog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Create dataset from client\ndataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n\nglobal_key = str(uuid.uuid4()) # Unique user specified ID\n\n# Data row structure\nimage_data_rows = [{\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"IMAGE\",\n}]\n\n# Bulk import data row\ntask = dataset.create_data_rows(image_data_rows) # List of data rows\ntask.wait_till_done()\nprint(task.errors) # Print any errors", + "cell_type": "code", "outputs": [], - "source": [ - "# Create dataset from client\n", - "dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n", - "\n", - "global_key = str(uuid.uuid4()) # Unique user specified ID\n", - "\n", - "# Data row structure\n", - "image_data_rows = [{\n", - " \"row_data\":\n", - " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n", - " \"global_key\":\n", - " global_key,\n", - " \"media_type\":\n", - " \"IMAGE\",\n", - "}]\n", - "\n", - "# Bulk import data row\n", - "task = dataset.create_data_rows(image_data_rows) # List of data rows\n", - "task.wait_till_done()\n", - "print(task.errors) # Print any errors" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 2: Creating an Ontology\n", @@ -137,49 +111,17 @@ "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a check list classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", "\n", "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Bounding box feature\nobject_features = [\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"regulatory-sign\",\n color=\"#ff0000\",\n )\n]\n\n# Checklist feature\nclassification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\n# Builder function\nontology_builder = lb.OntologyBuilder(tools=object_features,\n classifications=classification_features)\n\n# Create ontology\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)", + "cell_type": "code", "outputs": [], - "source": [ - "# Bounding box feature\n", - "object_features = [\n", - " lb.Tool(\n", - " tool=lb.Tool.Type.BBOX,\n", - " name=\"regulatory-sign\",\n", - " color=\"#ff0000\",\n", - " )\n", - "]\n", - "\n", - "# Checklist feature\n", - "classification_features = [\n", - " lb.Classification(\n", - " class_type=lb.Classification.Type.CHECKLIST,\n", - " name=\"Quality Issues\",\n", - " options=[\n", - " lb.Option(value=\"blurry\", label=\"Blurry\"),\n", - " lb.Option(value=\"distorted\", label=\"Distorted\"),\n", - " ],\n", - " )\n", - "]\n", - "\n", - "# Builder function\n", - "ontology_builder = lb.OntologyBuilder(tools=object_features,\n", - " classifications=classification_features)\n", - "\n", - "# Create ontology\n", - "ontology = client.create_ontology(\n", - " \"Ontology from new features\",\n", - " ontology_builder.asdict(),\n", - " media_type=lb.MediaType.Image,\n", - ")" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 3: Creating a Project and Attaching our Ontology\n", @@ -187,107 +129,64 @@ "Now that we have made our ontology we are ready to create a project were we can label our data row.\n", "\n", "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Create a new project\nproject = client.create_project(\n name=\"Quick Start Example Project\",\n media_type=lb.MediaType.Image, # specify the media type\n)\n\n# Attach created ontology\nproject.setup_editor(ontology)", + "cell_type": "code", "outputs": [], - "source": [ - "# Create a new project\n", - "project = client.create_project(\n", - " name=\"Quick Start Example Project\",\n", - " media_type=lb.MediaType.Image, # specify the media type\n", - ")\n", - "\n", - "# Attach created ontology\n", - "project.setup_editor(ontology)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", "\n", "With our project created we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue were labelers are able to annotate our data row. For more information on batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "project.create_batch(\n name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n global_keys=[\n global_key\n ], # Global key we used earlier in this guide to create our dataset\n priority=5,\n)", + "cell_type": "code", "outputs": [], - "source": [ - "project.create_batch(\n", - " name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n", - " global_keys=[\n", - " global_key\n", - " ], # Global key we used earlier in this guide to create our dataset\n", - " priority=5,\n", - ")" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "# Step 5: Exporting from our Project\n", "\n", - "We have now successfully set up a project for labeling using only the SDK! 🚀 \n", + "We have now successfully set up a project for labeling using only the SDK! \ud83d\ude80 \n", "\n", "From here you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide no labels will be presented on our data row. For a full overview of exporting visit our [export overview](https://docs.labelbox.com/reference/label-export) developer guide. " - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Start export from project\nexport_task = project.export()\nexport_task.wait_till_done()\n\n# Conditional if task has errors\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\n# Start export stream\nstream = export_task.get_buffered_stream()\n\n# Iterate through data rows\nfor data_row in stream:\n print(data_row.json)", + "cell_type": "code", "outputs": [], - "source": [ - "# Start export from project\n", - "export_task = project.export()\n", - "export_task.wait_till_done()\n", - "\n", - "# Conditional if task has errors\n", - "if export_task.has_errors():\n", - " export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n", - " stream_handler=lambda error: print(error))\n", - "\n", - "# Start export stream\n", - "stream = export_task.get_buffered_stream()\n", - "\n", - "# Iterate through data rows\n", - "for data_row in stream:\n", - " print(data_row.json)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Clean up\n", "This section serves as an optional clean up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# project.delete()\n# client.delete_unused_ontology(ontology.uid)\n# dataset.delete()", + "cell_type": "code", "outputs": [], - "source": [ - "# project.delete()\n", - "# client.delete_unused_ontology(ontology.uid)\n", - "# dataset.delete()" - ] + "execution_count": null } - ], - "metadata": { - "language_info": { - "name": "python" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} + ] +} \ No newline at end of file From 74fa626e486cc71f5a08f272b8ecffbfa3a66407 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 29 May 2024 12:38:36 -0500 Subject: [PATCH 09/17] typos --- examples/basics/quick_start.ipynb | 221 ++++++++++++++++++++++-------- 1 file changed, 161 insertions(+), 60 deletions(-) diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb index 3205acd00..e3e5f9150 100644 --- a/examples/basics/quick_start.ipynb +++ b/examples/basics/quick_start.ipynb @@ -1,18 +1,16 @@ { - "nbformat": 4, - "nbformat_minor": 2, - "metadata": {}, "cells": [ { + "cell_type": "markdown", "metadata": {}, "source": [ - "", - " ", + "\n", + " \n", "\n" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "\n", @@ -24,10 +22,10 @@ "\n", "" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "# Quick Start\n", @@ -39,52 +37,60 @@ "1. Creating a dataset and importing a image data row\n", "2. Creating a ontology\n", "3. Creating a project and attaching our ontology\n", - "4. Sending our data row to our Project by creating a batch\n", + "4. Sending our data row to our project by creating a batch\n", "5. Exporting from our project\n", "\n", "This notebook is geared towards new users of our SDK." - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Setup\n", "\n", - "To start, we first need to install the labelbox library and then import the SDK module. It is recommended to install \"labelbox[data]\" over labelbox to obtain all the correct dependencies. We will also be importing the python UUID library to generate unique IDs for the variety of objects that will be created with this notebook." - ], - "cell_type": "markdown" + "We first need to install the labelbox library and then import the SDK module. It is recommended to install \"labelbox[data]\" over labelbox to obtain all the correct dependencies. We will also be importing the Python UUID library to generate unique IDs for the variety of objects that will be created with this notebook." + ] }, { - "metadata": {}, - "source": "%pip install -q \"labelbox[data]\"", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "%pip install -q \"labelbox[data]\"" + ] }, { - "metadata": {}, - "source": "import labelbox as lb\nimport uuid", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "import labelbox as lb\n", + "import uuid" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## API Key and Client\n", "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." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "API_KEY = None\n", + "client = lb.Client(api_key=API_KEY)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1: Create Dataset and Import Data Row\n", @@ -93,17 +99,37 @@ "\n", "* Data rows are internal representation of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", "* A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catelog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Create dataset from client\ndataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n\nglobal_key = str(uuid.uuid4()) # Unique user specified ID\n\n# Data row structure\nimage_data_rows = [{\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"IMAGE\",\n}]\n\n# Bulk import data row\ntask = dataset.create_data_rows(image_data_rows) # List of data rows\ntask.wait_till_done()\nprint(task.errors) # Print any errors", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Create dataset from client\n", + "dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n", + "\n", + "global_key = str(uuid.uuid4()) # Unique user specified ID\n", + "\n", + "# Data row structure\n", + "image_data_rows = [{\n", + " \"row_data\":\n", + " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n", + " \"global_key\":\n", + " global_key,\n", + " \"media_type\":\n", + " \"IMAGE\",\n", + "}]\n", + "\n", + "# Bulk import data row\n", + "task = dataset.create_data_rows(image_data_rows) # List of data rows\n", + "task.wait_till_done()\n", + "print(task.errors) # Print any errors" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 2: Creating an Ontology\n", @@ -111,17 +137,49 @@ "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a check list classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", "\n", "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Bounding box feature\nobject_features = [\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"regulatory-sign\",\n color=\"#ff0000\",\n )\n]\n\n# Checklist feature\nclassification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\n# Builder function\nontology_builder = lb.OntologyBuilder(tools=object_features,\n classifications=classification_features)\n\n# Create ontology\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Bounding box feature\n", + "object_features = [\n", + " lb.Tool(\n", + " tool=lb.Tool.Type.BBOX,\n", + " name=\"regulatory-sign\",\n", + " color=\"#ff0000\",\n", + " )\n", + "]\n", + "\n", + "# Checklist feature\n", + "classification_features = [\n", + " lb.Classification(\n", + " class_type=lb.Classification.Type.CHECKLIST,\n", + " name=\"Quality Issues\",\n", + " options=[\n", + " lb.Option(value=\"blurry\", label=\"Blurry\"),\n", + " lb.Option(value=\"distorted\", label=\"Distorted\"),\n", + " ],\n", + " )\n", + "]\n", + "\n", + "# Builder function\n", + "ontology_builder = lb.OntologyBuilder(tools=object_features,\n", + " classifications=classification_features)\n", + "\n", + "# Create ontology\n", + "ontology = client.create_ontology(\n", + " \"Ontology from new features\",\n", + " ontology_builder.asdict(),\n", + " media_type=lb.MediaType.Image,\n", + ")" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 3: Creating a Project and Attaching our Ontology\n", @@ -129,64 +187,107 @@ "Now that we have made our ontology we are ready to create a project were we can label our data row.\n", "\n", "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Create a new project\nproject = client.create_project(\n name=\"Quick Start Example Project\",\n media_type=lb.MediaType.Image, # specify the media type\n)\n\n# Attach created ontology\nproject.setup_editor(ontology)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Create a new project\n", + "project = client.create_project(\n", + " name=\"Quick Start Example Project\",\n", + " media_type=lb.MediaType.Image, # specify the media type\n", + ")\n", + "\n", + "# Attach created ontology\n", + "project.setup_editor(ontology)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", "\n", "With our project created we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue were labelers are able to annotate our data row. For more information on batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "project.create_batch(\n name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n global_keys=[\n global_key\n ], # Global key we used earlier in this guide to create our dataset\n priority=5,\n)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "project.create_batch(\n", + " name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n", + " global_keys=[\n", + " global_key\n", + " ], # Global key we used earlier in this guide to create our dataset\n", + " priority=5,\n", + ")" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "# Step 5: Exporting from our Project\n", "\n", - "We have now successfully set up a project for labeling using only the SDK! \ud83d\ude80 \n", + "We have now successfully set up a project for labeling using only the SDK! 🚀 \n", "\n", - "From here you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide no labels will be presented on our data row. For a full overview of exporting visit our [export overview](https://docs.labelbox.com/reference/label-export) developer guide. " - ], - "cell_type": "markdown" + "From here you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide no labels will be presented on our data row. For a full overview of exporting visit our [export overview](https://docs.labelbox.com/reference/label-export) developer guide. " + ] }, { - "metadata": {}, - "source": "# Start export from project\nexport_task = project.export()\nexport_task.wait_till_done()\n\n# Conditional if task has errors\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\n# Start export stream\nstream = export_task.get_buffered_stream()\n\n# Iterate through data rows\nfor data_row in stream:\n print(data_row.json)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Start export from project\n", + "export_task = project.export()\n", + "export_task.wait_till_done()\n", + "\n", + "# Conditional if task has errors\n", + "if export_task.has_errors():\n", + " export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n", + " stream_handler=lambda error: print(error))\n", + "\n", + "# Start export stream\n", + "stream = export_task.get_buffered_stream()\n", + "\n", + "# Iterate through data rows\n", + "for data_row in stream:\n", + " print(data_row.json)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Clean up\n", "This section serves as an optional clean up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# project.delete()\n# client.delete_unused_ontology(ontology.uid)\n# dataset.delete()", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# project.delete()\n", + "# client.delete_unused_ontology(ontology.uid)\n", + "# dataset.delete()" + ] } - ] -} \ No newline at end of file + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 620c733eae096fcc212df5d8c324f9bda8030c74 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 29 May 2024 13:52:54 -0500 Subject: [PATCH 10/17] added information from feedback --- examples/basics/quick_start.ipynb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb index e3e5f9150..17c62af77 100644 --- a/examples/basics/quick_start.ipynb +++ b/examples/basics/quick_start.ipynb @@ -95,10 +95,10 @@ "source": [ "## Step 1: Create Dataset and Import Data Row\n", "\n", - "Below we will be creating a dataset and then attaching a publicly hosted image data row. Typically you would either import data rows that are hosted on a cloud provider (_recommended_) or import them locally. For more information, visit our [import image data section](https://docs.labelbox.com/reference/image) in our developer guides.\n", + "Below, we will create a dataset and then attach a publicly hosted image data row. Typically, you would either import data rows hosted on a cloud provider (_recommended_) or import them locally. For more information, visit our [import image data section](https://docs.labelbox.com/reference/image) in our developer guides.\n", "\n", - "* Data rows are internal representation of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", - "* A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catelog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." + "- Data rows are internal representations of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", + "- A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catalog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." ] }, { @@ -134,7 +134,7 @@ "source": [ "## Step 2: Creating an Ontology\n", "\n", - "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a check list classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", + "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a checklist classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", "\n", "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." ] @@ -184,7 +184,7 @@ "source": [ "## Step 3: Creating a Project and Attaching our Ontology\n", "\n", - "Now that we have made our ontology we are ready to create a project were we can label our data row.\n", + "Now that we have made our ontology, we are ready to create a project where we can label our data row.\n", "\n", "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." ] @@ -211,7 +211,9 @@ "source": [ "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", "\n", - "With our project created we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue were labelers are able to annotate our data row. For more information on batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." + "With our project created, we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue, where labelers are able to annotate our data row.\n", + "\n", + "* A batch is a curated selection of data rows you can send to a project for labeling. You can create a batch with a combination of data rows within any dataset. For more information on creating batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." ] }, { @@ -233,11 +235,11 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Step 5: Exporting from our Project\n", + "## Step 5: Exporting from our Project\n", "\n", "We have now successfully set up a project for labeling using only the SDK! 🚀 \n", "\n", - "From here you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide no labels will be presented on our data row. For a full overview of exporting visit our [export overview](https://docs.labelbox.com/reference/label-export) developer guide. " + "From here, you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide, no labels will be presented on our data row. For a full overview of exporting, visit our [export overview](https://docs.labelbox.com/reference/label-export) developer guide." ] }, { @@ -268,7 +270,8 @@ "metadata": {}, "source": [ "## Clean up\n", - "This section serves as an optional clean up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." + "\n", + "This section serves as an optional clean-up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." ] }, { From ea1382472dbf7dd52506e15a7cd604c66b3d1a5e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 29 May 2024 18:56:31 +0000 Subject: [PATCH 11/17] :art: Cleaned --- examples/basics/quick_start.ipynb | 215 ++++++++---------------------- 1 file changed, 57 insertions(+), 158 deletions(-) diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb index 17c62af77..346a12b88 100644 --- a/examples/basics/quick_start.ipynb +++ b/examples/basics/quick_start.ipynb @@ -1,16 +1,18 @@ { + "nbformat": 4, + "nbformat_minor": 2, + "metadata": {}, "cells": [ { - "cell_type": "markdown", "metadata": {}, "source": [ - "\n", - " \n", + "", + " ", "\n" - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "\n", @@ -22,10 +24,10 @@ "\n", "" - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "# Quick Start\n", @@ -41,56 +43,48 @@ "5. Exporting from our project\n", "\n", "This notebook is geared towards new users of our SDK." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Setup\n", "\n", "We first need to install the labelbox library and then import the SDK module. It is recommended to install \"labelbox[data]\" over labelbox to obtain all the correct dependencies. We will also be importing the Python UUID library to generate unique IDs for the variety of objects that will be created with this notebook." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "%pip install -q \"labelbox[data]\"", + "cell_type": "code", "outputs": [], - "source": [ - "%pip install -q \"labelbox[data]\"" - ] + "execution_count": null }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "import labelbox as lb\nimport uuid", + "cell_type": "code", "outputs": [], - "source": [ - "import labelbox as lb\n", - "import uuid" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## API Key and Client\n", "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." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)", + "cell_type": "code", "outputs": [], - "source": [ - "API_KEY = None\n", - "client = lb.Client(api_key=API_KEY)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1: Create Dataset and Import Data Row\n", @@ -99,37 +93,17 @@ "\n", "- Data rows are internal representations of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", "- A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catalog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Create dataset from client\ndataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n\nglobal_key = str(uuid.uuid4()) # Unique user specified ID\n\n# Data row structure\nimage_data_rows = [{\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"IMAGE\",\n}]\n\n# Bulk import data row\ntask = dataset.create_data_rows(image_data_rows) # List of data rows\ntask.wait_till_done()\nprint(task.errors) # Print any errors", + "cell_type": "code", "outputs": [], - "source": [ - "# Create dataset from client\n", - "dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n", - "\n", - "global_key = str(uuid.uuid4()) # Unique user specified ID\n", - "\n", - "# Data row structure\n", - "image_data_rows = [{\n", - " \"row_data\":\n", - " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n", - " \"global_key\":\n", - " global_key,\n", - " \"media_type\":\n", - " \"IMAGE\",\n", - "}]\n", - "\n", - "# Bulk import data row\n", - "task = dataset.create_data_rows(image_data_rows) # List of data rows\n", - "task.wait_till_done()\n", - "print(task.errors) # Print any errors" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 2: Creating an Ontology\n", @@ -137,49 +111,17 @@ "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a checklist classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", "\n", "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Bounding box feature\nobject_features = [\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"regulatory-sign\",\n color=\"#ff0000\",\n )\n]\n\n# Checklist feature\nclassification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\n# Builder function\nontology_builder = lb.OntologyBuilder(tools=object_features,\n classifications=classification_features)\n\n# Create ontology\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)", + "cell_type": "code", "outputs": [], - "source": [ - "# Bounding box feature\n", - "object_features = [\n", - " lb.Tool(\n", - " tool=lb.Tool.Type.BBOX,\n", - " name=\"regulatory-sign\",\n", - " color=\"#ff0000\",\n", - " )\n", - "]\n", - "\n", - "# Checklist feature\n", - "classification_features = [\n", - " lb.Classification(\n", - " class_type=lb.Classification.Type.CHECKLIST,\n", - " name=\"Quality Issues\",\n", - " options=[\n", - " lb.Option(value=\"blurry\", label=\"Blurry\"),\n", - " lb.Option(value=\"distorted\", label=\"Distorted\"),\n", - " ],\n", - " )\n", - "]\n", - "\n", - "# Builder function\n", - "ontology_builder = lb.OntologyBuilder(tools=object_features,\n", - " classifications=classification_features)\n", - "\n", - "# Create ontology\n", - "ontology = client.create_ontology(\n", - " \"Ontology from new features\",\n", - " ontology_builder.asdict(),\n", - " media_type=lb.MediaType.Image,\n", - ")" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 3: Creating a Project and Attaching our Ontology\n", @@ -187,26 +129,17 @@ "Now that we have made our ontology, we are ready to create a project where we can label our data row.\n", "\n", "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Create a new project\nproject = client.create_project(\n name=\"Quick Start Example Project\",\n media_type=lb.MediaType.Image, # specify the media type\n)\n\n# Attach created ontology\nproject.setup_editor(ontology)", + "cell_type": "code", "outputs": [], - "source": [ - "# Create a new project\n", - "project = client.create_project(\n", - " name=\"Quick Start Example Project\",\n", - " media_type=lb.MediaType.Image, # specify the media type\n", - ")\n", - "\n", - "# Attach created ontology\n", - "project.setup_editor(ontology)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", @@ -214,83 +147,49 @@ "With our project created, we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue, where labelers are able to annotate our data row.\n", "\n", "* A batch is a curated selection of data rows you can send to a project for labeling. You can create a batch with a combination of data rows within any dataset. For more information on creating batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "project.create_batch(\n name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n global_keys=[\n global_key\n ], # Global key we used earlier in this guide to create our dataset\n priority=5,\n)", + "cell_type": "code", "outputs": [], - "source": [ - "project.create_batch(\n", - " name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n", - " global_keys=[\n", - " global_key\n", - " ], # Global key we used earlier in this guide to create our dataset\n", - " priority=5,\n", - ")" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 5: Exporting from our Project\n", "\n", - "We have now successfully set up a project for labeling using only the SDK! 🚀 \n", + "We have now successfully set up a project for labeling using only the SDK! \ud83d\ude80 \n", "\n", "From here, you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide, no labels will be presented on our data row. For a full overview of exporting, visit our [export overview](https://docs.labelbox.com/reference/label-export) developer guide." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Start export from project\nexport_task = project.export()\nexport_task.wait_till_done()\n\n# Conditional if task has errors\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\n# Start export stream\nstream = export_task.get_buffered_stream()\n\n# Iterate through data rows\nfor data_row in stream:\n print(data_row.json)", + "cell_type": "code", "outputs": [], - "source": [ - "# Start export from project\n", - "export_task = project.export()\n", - "export_task.wait_till_done()\n", - "\n", - "# Conditional if task has errors\n", - "if export_task.has_errors():\n", - " export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n", - " stream_handler=lambda error: print(error))\n", - "\n", - "# Start export stream\n", - "stream = export_task.get_buffered_stream()\n", - "\n", - "# Iterate through data rows\n", - "for data_row in stream:\n", - " print(data_row.json)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Clean up\n", "\n", "This section serves as an optional clean-up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# project.delete()\n# client.delete_unused_ontology(ontology.uid)\n# dataset.delete()", + "cell_type": "code", "outputs": [], - "source": [ - "# project.delete()\n", - "# client.delete_unused_ontology(ontology.uid)\n", - "# dataset.delete()" - ] + "execution_count": null } - ], - "metadata": { - "language_info": { - "name": "python" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} + ] +} \ No newline at end of file From cec0a5ceb0e35a4248eb5f44ad132be67bce7e47 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 29 May 2024 13:57:26 -0500 Subject: [PATCH 12/17] last typo fix --- examples/basics/quick_start.ipynb | 217 ++++++++++++++++++++++-------- 1 file changed, 159 insertions(+), 58 deletions(-) diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb index 346a12b88..8fdc668fa 100644 --- a/examples/basics/quick_start.ipynb +++ b/examples/basics/quick_start.ipynb @@ -1,18 +1,16 @@ { - "nbformat": 4, - "nbformat_minor": 2, - "metadata": {}, "cells": [ { + "cell_type": "markdown", "metadata": {}, "source": [ - "", - " ", + "\n", + " \n", "\n" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "\n", @@ -24,10 +22,10 @@ "\n", "" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "# Quick Start\n", @@ -43,48 +41,56 @@ "5. Exporting from our project\n", "\n", "This notebook is geared towards new users of our SDK." - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Setup\n", "\n", "We first need to install the labelbox library and then import the SDK module. It is recommended to install \"labelbox[data]\" over labelbox to obtain all the correct dependencies. We will also be importing the Python UUID library to generate unique IDs for the variety of objects that will be created with this notebook." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "%pip install -q \"labelbox[data]\"", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "%pip install -q \"labelbox[data]\"" + ] }, { - "metadata": {}, - "source": "import labelbox as lb\nimport uuid", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "import labelbox as lb\n", + "import uuid" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## API Key and Client\n", "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." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "API_KEY = None\n", + "client = lb.Client(api_key=API_KEY)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1: Create Dataset and Import Data Row\n", @@ -93,17 +99,37 @@ "\n", "- Data rows are internal representations of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", "- A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catalog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Create dataset from client\ndataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n\nglobal_key = str(uuid.uuid4()) # Unique user specified ID\n\n# Data row structure\nimage_data_rows = [{\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"IMAGE\",\n}]\n\n# Bulk import data row\ntask = dataset.create_data_rows(image_data_rows) # List of data rows\ntask.wait_till_done()\nprint(task.errors) # Print any errors", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Create dataset from client\n", + "dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n", + "\n", + "global_key = str(uuid.uuid4()) # Unique user specified ID\n", + "\n", + "# Data row structure\n", + "image_data_rows = [{\n", + " \"row_data\":\n", + " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n", + " \"global_key\":\n", + " global_key,\n", + " \"media_type\":\n", + " \"IMAGE\",\n", + "}]\n", + "\n", + "# Bulk import data row\n", + "task = dataset.create_data_rows(image_data_rows) # List of data rows\n", + "task.wait_till_done()\n", + "print(task.errors) # Print any errors" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 2: Creating an Ontology\n", @@ -111,17 +137,49 @@ "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a checklist classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", "\n", "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Bounding box feature\nobject_features = [\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"regulatory-sign\",\n color=\"#ff0000\",\n )\n]\n\n# Checklist feature\nclassification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\n# Builder function\nontology_builder = lb.OntologyBuilder(tools=object_features,\n classifications=classification_features)\n\n# Create ontology\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Bounding box feature\n", + "object_features = [\n", + " lb.Tool(\n", + " tool=lb.Tool.Type.BBOX,\n", + " name=\"regulatory-sign\",\n", + " color=\"#ff0000\",\n", + " )\n", + "]\n", + "\n", + "# Checklist feature\n", + "classification_features = [\n", + " lb.Classification(\n", + " class_type=lb.Classification.Type.CHECKLIST,\n", + " name=\"Quality Issues\",\n", + " options=[\n", + " lb.Option(value=\"blurry\", label=\"Blurry\"),\n", + " lb.Option(value=\"distorted\", label=\"Distorted\"),\n", + " ],\n", + " )\n", + "]\n", + "\n", + "# Builder function\n", + "ontology_builder = lb.OntologyBuilder(tools=object_features,\n", + " classifications=classification_features)\n", + "\n", + "# Create ontology\n", + "ontology = client.create_ontology(\n", + " \"Ontology from new features\",\n", + " ontology_builder.asdict(),\n", + " media_type=lb.MediaType.Image,\n", + ")" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 3: Creating a Project and Attaching our Ontology\n", @@ -129,17 +187,26 @@ "Now that we have made our ontology, we are ready to create a project where we can label our data row.\n", "\n", "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Create a new project\nproject = client.create_project(\n name=\"Quick Start Example Project\",\n media_type=lb.MediaType.Image, # specify the media type\n)\n\n# Attach created ontology\nproject.setup_editor(ontology)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Create a new project\n", + "project = client.create_project(\n", + " name=\"Quick Start Example Project\",\n", + " media_type=lb.MediaType.Image, # specify the media type\n", + ")\n", + "\n", + "# Attach created ontology\n", + "project.setup_editor(ontology)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", @@ -147,49 +214,83 @@ "With our project created, we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue, where labelers are able to annotate our data row.\n", "\n", "* A batch is a curated selection of data rows you can send to a project for labeling. You can create a batch with a combination of data rows within any dataset. For more information on creating batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "project.create_batch(\n name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n global_keys=[\n global_key\n ], # Global key we used earlier in this guide to create our dataset\n priority=5,\n)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "project.create_batch(\n", + " name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n", + " global_keys=[\n", + " global_key\n", + " ], # Global key we used earlier in this guide to create our dataset\n", + " priority=5,\n", + ")" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 5: Exporting from our Project\n", "\n", - "We have now successfully set up a project for labeling using only the SDK! \ud83d\ude80 \n", + "We have now successfully set up a project for labeling using only the SDK! 🚀 \n", "\n", "From here, you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide, no labels will be presented on our data row. For a full overview of exporting, visit our [export overview](https://docs.labelbox.com/reference/label-export) developer guide." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Start export from project\nexport_task = project.export()\nexport_task.wait_till_done()\n\n# Conditional if task has errors\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\n# Start export stream\nstream = export_task.get_buffered_stream()\n\n# Iterate through data rows\nfor data_row in stream:\n print(data_row.json)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Start export from project\n", + "export_task = project.export()\n", + "export_task.wait_till_done()\n", + "\n", + "# Conditional if task has errors\n", + "if export_task.has_errors():\n", + " export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n", + " stream_handler=lambda error: print(error))\n", + "\n", + "# Start export stream\n", + "stream = export_task.get_buffered_stream()\n", + "\n", + "# Iterate through data rows\n", + "for data_row in stream:\n", + " print(data_row.json)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ - "## Clean up\n", + "## Clean Up\n", "\n", "This section serves as an optional clean-up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# project.delete()\n# client.delete_unused_ontology(ontology.uid)\n# dataset.delete()", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# project.delete()\n", + "# client.delete_unused_ontology(ontology.uid)\n", + "# dataset.delete()" + ] } - ] -} \ No newline at end of file + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 66665cd7ffcd9c07610c2f87828b997ec87efacc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 29 May 2024 18:58:18 +0000 Subject: [PATCH 13/17] :art: Cleaned --- examples/basics/quick_start.ipynb | 215 ++++++++---------------------- 1 file changed, 57 insertions(+), 158 deletions(-) diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb index 8fdc668fa..66837ea5b 100644 --- a/examples/basics/quick_start.ipynb +++ b/examples/basics/quick_start.ipynb @@ -1,16 +1,18 @@ { + "nbformat": 4, + "nbformat_minor": 2, + "metadata": {}, "cells": [ { - "cell_type": "markdown", "metadata": {}, "source": [ - "\n", - " \n", + "", + " ", "\n" - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "\n", @@ -22,10 +24,10 @@ "\n", "" - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "# Quick Start\n", @@ -41,56 +43,48 @@ "5. Exporting from our project\n", "\n", "This notebook is geared towards new users of our SDK." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Setup\n", "\n", "We first need to install the labelbox library and then import the SDK module. It is recommended to install \"labelbox[data]\" over labelbox to obtain all the correct dependencies. We will also be importing the Python UUID library to generate unique IDs for the variety of objects that will be created with this notebook." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "%pip install -q \"labelbox[data]\"", + "cell_type": "code", "outputs": [], - "source": [ - "%pip install -q \"labelbox[data]\"" - ] + "execution_count": null }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "import labelbox as lb\nimport uuid", + "cell_type": "code", "outputs": [], - "source": [ - "import labelbox as lb\n", - "import uuid" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## API Key and Client\n", "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." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)", + "cell_type": "code", "outputs": [], - "source": [ - "API_KEY = None\n", - "client = lb.Client(api_key=API_KEY)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1: Create Dataset and Import Data Row\n", @@ -99,37 +93,17 @@ "\n", "- Data rows are internal representations of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", "- A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catalog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Create dataset from client\ndataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n\nglobal_key = str(uuid.uuid4()) # Unique user specified ID\n\n# Data row structure\nimage_data_rows = [{\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"IMAGE\",\n}]\n\n# Bulk import data row\ntask = dataset.create_data_rows(image_data_rows) # List of data rows\ntask.wait_till_done()\nprint(task.errors) # Print any errors", + "cell_type": "code", "outputs": [], - "source": [ - "# Create dataset from client\n", - "dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n", - "\n", - "global_key = str(uuid.uuid4()) # Unique user specified ID\n", - "\n", - "# Data row structure\n", - "image_data_rows = [{\n", - " \"row_data\":\n", - " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n", - " \"global_key\":\n", - " global_key,\n", - " \"media_type\":\n", - " \"IMAGE\",\n", - "}]\n", - "\n", - "# Bulk import data row\n", - "task = dataset.create_data_rows(image_data_rows) # List of data rows\n", - "task.wait_till_done()\n", - "print(task.errors) # Print any errors" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 2: Creating an Ontology\n", @@ -137,49 +111,17 @@ "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a checklist classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", "\n", "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Bounding box feature\nobject_features = [\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"regulatory-sign\",\n color=\"#ff0000\",\n )\n]\n\n# Checklist feature\nclassification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\n# Builder function\nontology_builder = lb.OntologyBuilder(tools=object_features,\n classifications=classification_features)\n\n# Create ontology\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)", + "cell_type": "code", "outputs": [], - "source": [ - "# Bounding box feature\n", - "object_features = [\n", - " lb.Tool(\n", - " tool=lb.Tool.Type.BBOX,\n", - " name=\"regulatory-sign\",\n", - " color=\"#ff0000\",\n", - " )\n", - "]\n", - "\n", - "# Checklist feature\n", - "classification_features = [\n", - " lb.Classification(\n", - " class_type=lb.Classification.Type.CHECKLIST,\n", - " name=\"Quality Issues\",\n", - " options=[\n", - " lb.Option(value=\"blurry\", label=\"Blurry\"),\n", - " lb.Option(value=\"distorted\", label=\"Distorted\"),\n", - " ],\n", - " )\n", - "]\n", - "\n", - "# Builder function\n", - "ontology_builder = lb.OntologyBuilder(tools=object_features,\n", - " classifications=classification_features)\n", - "\n", - "# Create ontology\n", - "ontology = client.create_ontology(\n", - " \"Ontology from new features\",\n", - " ontology_builder.asdict(),\n", - " media_type=lb.MediaType.Image,\n", - ")" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 3: Creating a Project and Attaching our Ontology\n", @@ -187,26 +129,17 @@ "Now that we have made our ontology, we are ready to create a project where we can label our data row.\n", "\n", "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Create a new project\nproject = client.create_project(\n name=\"Quick Start Example Project\",\n media_type=lb.MediaType.Image, # specify the media type\n)\n\n# Attach created ontology\nproject.setup_editor(ontology)", + "cell_type": "code", "outputs": [], - "source": [ - "# Create a new project\n", - "project = client.create_project(\n", - " name=\"Quick Start Example Project\",\n", - " media_type=lb.MediaType.Image, # specify the media type\n", - ")\n", - "\n", - "# Attach created ontology\n", - "project.setup_editor(ontology)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", @@ -214,83 +147,49 @@ "With our project created, we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue, where labelers are able to annotate our data row.\n", "\n", "* A batch is a curated selection of data rows you can send to a project for labeling. You can create a batch with a combination of data rows within any dataset. For more information on creating batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "project.create_batch(\n name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n global_keys=[\n global_key\n ], # Global key we used earlier in this guide to create our dataset\n priority=5,\n)", + "cell_type": "code", "outputs": [], - "source": [ - "project.create_batch(\n", - " name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n", - " global_keys=[\n", - " global_key\n", - " ], # Global key we used earlier in this guide to create our dataset\n", - " priority=5,\n", - ")" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 5: Exporting from our Project\n", "\n", - "We have now successfully set up a project for labeling using only the SDK! 🚀 \n", + "We have now successfully set up a project for labeling using only the SDK! \ud83d\ude80 \n", "\n", "From here, you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide, no labels will be presented on our data row. For a full overview of exporting, visit our [export overview](https://docs.labelbox.com/reference/label-export) developer guide." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Start export from project\nexport_task = project.export()\nexport_task.wait_till_done()\n\n# Conditional if task has errors\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\n# Start export stream\nstream = export_task.get_buffered_stream()\n\n# Iterate through data rows\nfor data_row in stream:\n print(data_row.json)", + "cell_type": "code", "outputs": [], - "source": [ - "# Start export from project\n", - "export_task = project.export()\n", - "export_task.wait_till_done()\n", - "\n", - "# Conditional if task has errors\n", - "if export_task.has_errors():\n", - " export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n", - " stream_handler=lambda error: print(error))\n", - "\n", - "# Start export stream\n", - "stream = export_task.get_buffered_stream()\n", - "\n", - "# Iterate through data rows\n", - "for data_row in stream:\n", - " print(data_row.json)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Clean Up\n", "\n", "This section serves as an optional clean-up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# project.delete()\n# client.delete_unused_ontology(ontology.uid)\n# dataset.delete()", + "cell_type": "code", "outputs": [], - "source": [ - "# project.delete()\n", - "# client.delete_unused_ontology(ontology.uid)\n", - "# dataset.delete()" - ] + "execution_count": null } - ], - "metadata": { - "language_info": { - "name": "python" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} + ] +} \ No newline at end of file From f3ca467c13733cb04769e087deb1da3a13be3332 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Thu, 30 May 2024 09:33:33 -0500 Subject: [PATCH 14/17] typos --- examples/basics/quick_start.ipynb | 223 ++++++++++++++++++++++-------- 1 file changed, 162 insertions(+), 61 deletions(-) diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb index 66837ea5b..066d183d1 100644 --- a/examples/basics/quick_start.ipynb +++ b/examples/basics/quick_start.ipynb @@ -1,18 +1,16 @@ { - "nbformat": 4, - "nbformat_minor": 2, - "metadata": {}, "cells": [ { + "cell_type": "markdown", "metadata": {}, "source": [ - "", - " ", + "\n", + " \n", "\n" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "\n", @@ -24,67 +22,75 @@ "\n", "" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "# Quick Start\n", "\n", - "This notebook is intended to be a quick overview on Labelbox-Python SDK by demonstrating a simple but common work flow.\n", + "This notebook is intended to be a quick overview on Labelbox-Python SDK by demonstrating a simple but common workflow.\n", "\n", "In this guide, we will be:\n", "\n", - "1. Creating a dataset and importing a image data row\n", + "1. Creating a dataset and importing an image data row\n", "2. Creating a ontology\n", "3. Creating a project and attaching our ontology\n", "4. Sending our data row to our project by creating a batch\n", - "5. Exporting from our project\n", + "5. Exporting our image data row from our project\n", "\n", "This notebook is geared towards new users of our SDK." - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Setup\n", "\n", - "We first need to install the labelbox library and then import the SDK module. It is recommended to install \"labelbox[data]\" over labelbox to obtain all the correct dependencies. We will also be importing the Python UUID library to generate unique IDs for the variety of objects that will be created with this notebook." - ], - "cell_type": "markdown" + "We first need to install the labelbox library and then import the SDK module. It is recommended to install `\"labelbox[data]\"` over `labelbox` to obtain all the correct dependencies. We will also be importing the Python `uuid` library to generate universal unique IDs for the variety of objects that will be created with this notebook." + ] }, { - "metadata": {}, - "source": "%pip install -q \"labelbox[data]\"", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "%pip install -q \"labelbox[data]\"" + ] }, { - "metadata": {}, - "source": "import labelbox as lb\nimport uuid", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "import labelbox as lb\n", + "import uuid" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## API Key and Client\n", "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." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "API_KEY = None\n", + "client = lb.Client(api_key=API_KEY)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1: Create Dataset and Import Data Row\n", @@ -93,17 +99,37 @@ "\n", "- Data rows are internal representations of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", "- A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catalog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Create dataset from client\ndataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n\nglobal_key = str(uuid.uuid4()) # Unique user specified ID\n\n# Data row structure\nimage_data_rows = [{\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"IMAGE\",\n}]\n\n# Bulk import data row\ntask = dataset.create_data_rows(image_data_rows) # List of data rows\ntask.wait_till_done()\nprint(task.errors) # Print any errors", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Create dataset from client\n", + "dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n", + "\n", + "global_key = str(uuid.uuid4()) # Unique user specified ID\n", + "\n", + "# Data row structure\n", + "image_data_rows = [{\n", + " \"row_data\":\n", + " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n", + " \"global_key\":\n", + " global_key,\n", + " \"media_type\":\n", + " \"IMAGE\",\n", + "}]\n", + "\n", + "# Bulk import data row\n", + "task = dataset.create_data_rows(image_data_rows) # List of data rows\n", + "task.wait_till_done()\n", + "print(task.errors) # Print any errors" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 2: Creating an Ontology\n", @@ -111,17 +137,49 @@ "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a checklist classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", "\n", "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Bounding box feature\nobject_features = [\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"regulatory-sign\",\n color=\"#ff0000\",\n )\n]\n\n# Checklist feature\nclassification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\n# Builder function\nontology_builder = lb.OntologyBuilder(tools=object_features,\n classifications=classification_features)\n\n# Create ontology\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Bounding box feature\n", + "object_features = [\n", + " lb.Tool(\n", + " tool=lb.Tool.Type.BBOX,\n", + " name=\"regulatory-sign\",\n", + " color=\"#ff0000\",\n", + " )\n", + "]\n", + "\n", + "# Checklist feature\n", + "classification_features = [\n", + " lb.Classification(\n", + " class_type=lb.Classification.Type.CHECKLIST,\n", + " name=\"Quality Issues\",\n", + " options=[\n", + " lb.Option(value=\"blurry\", label=\"Blurry\"),\n", + " lb.Option(value=\"distorted\", label=\"Distorted\"),\n", + " ],\n", + " )\n", + "]\n", + "\n", + "# Builder function\n", + "ontology_builder = lb.OntologyBuilder(tools=object_features,\n", + " classifications=classification_features)\n", + "\n", + "# Create ontology\n", + "ontology = client.create_ontology(\n", + " \"Ontology from new features\",\n", + " ontology_builder.asdict(),\n", + " media_type=lb.MediaType.Image,\n", + ")" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 3: Creating a Project and Attaching our Ontology\n", @@ -129,17 +187,26 @@ "Now that we have made our ontology, we are ready to create a project where we can label our data row.\n", "\n", "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Create a new project\nproject = client.create_project(\n name=\"Quick Start Example Project\",\n media_type=lb.MediaType.Image, # specify the media type\n)\n\n# Attach created ontology\nproject.setup_editor(ontology)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Create a new project\n", + "project = client.create_project(\n", + " name=\"Quick Start Example Project\",\n", + " media_type=lb.MediaType.Image, # specify the media type\n", + ")\n", + "\n", + "# Attach created ontology\n", + "project.setup_editor(ontology)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", @@ -147,49 +214,83 @@ "With our project created, we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue, where labelers are able to annotate our data row.\n", "\n", "* A batch is a curated selection of data rows you can send to a project for labeling. You can create a batch with a combination of data rows within any dataset. For more information on creating batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "project.create_batch(\n name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n global_keys=[\n global_key\n ], # Global key we used earlier in this guide to create our dataset\n priority=5,\n)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "project.create_batch(\n", + " name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n", + " global_keys=[\n", + " global_key\n", + " ], # Global key we used earlier in this guide to create our dataset\n", + " priority=5,\n", + ")" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 5: Exporting from our Project\n", "\n", - "We have now successfully set up a project for labeling using only the SDK! \ud83d\ude80 \n", + "We have now successfully set up a project for labeling using only the SDK! 🚀 \n", "\n", "From here, you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide, no labels will be presented on our data row. For a full overview of exporting, visit our [export overview](https://docs.labelbox.com/reference/label-export) developer guide." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Start export from project\nexport_task = project.export()\nexport_task.wait_till_done()\n\n# Conditional if task has errors\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\n# Start export stream\nstream = export_task.get_buffered_stream()\n\n# Iterate through data rows\nfor data_row in stream:\n print(data_row.json)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Start export from project\n", + "export_task = project.export()\n", + "export_task.wait_till_done()\n", + "\n", + "# Conditional if task has errors\n", + "if export_task.has_errors():\n", + " export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n", + " stream_handler=lambda error: print(error))\n", + "\n", + "# Start export stream\n", + "stream = export_task.get_buffered_stream()\n", + "\n", + "# Iterate through data rows\n", + "for data_row in stream:\n", + " print(data_row.json)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Clean Up\n", "\n", "This section serves as an optional clean-up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# project.delete()\n# client.delete_unused_ontology(ontology.uid)\n# dataset.delete()", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# project.delete()\n", + "# client.delete_unused_ontology(ontology.uid)\n", + "# dataset.delete()" + ] } - ] -} \ No newline at end of file + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 1653e1ea48808bb25bae90cba6322bc8471e07e5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 30 May 2024 14:34:26 +0000 Subject: [PATCH 15/17] :art: Cleaned --- examples/basics/quick_start.ipynb | 215 ++++++++---------------------- 1 file changed, 57 insertions(+), 158 deletions(-) diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb index 066d183d1..0bbded2e8 100644 --- a/examples/basics/quick_start.ipynb +++ b/examples/basics/quick_start.ipynb @@ -1,16 +1,18 @@ { + "nbformat": 4, + "nbformat_minor": 2, + "metadata": {}, "cells": [ { - "cell_type": "markdown", "metadata": {}, "source": [ - "\n", - " \n", + "", + " ", "\n" - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "\n", @@ -22,10 +24,10 @@ "\n", "" - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "# Quick Start\n", @@ -41,56 +43,48 @@ "5. Exporting our image data row from our project\n", "\n", "This notebook is geared towards new users of our SDK." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Setup\n", "\n", "We first need to install the labelbox library and then import the SDK module. It is recommended to install `\"labelbox[data]\"` over `labelbox` to obtain all the correct dependencies. We will also be importing the Python `uuid` library to generate universal unique IDs for the variety of objects that will be created with this notebook." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "%pip install -q \"labelbox[data]\"", + "cell_type": "code", "outputs": [], - "source": [ - "%pip install -q \"labelbox[data]\"" - ] + "execution_count": null }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "import labelbox as lb\nimport uuid", + "cell_type": "code", "outputs": [], - "source": [ - "import labelbox as lb\n", - "import uuid" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## API Key and Client\n", "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." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)", + "cell_type": "code", "outputs": [], - "source": [ - "API_KEY = None\n", - "client = lb.Client(api_key=API_KEY)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1: Create Dataset and Import Data Row\n", @@ -99,37 +93,17 @@ "\n", "- Data rows are internal representations of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", "- A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catalog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Create dataset from client\ndataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n\nglobal_key = str(uuid.uuid4()) # Unique user specified ID\n\n# Data row structure\nimage_data_rows = [{\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"IMAGE\",\n}]\n\n# Bulk import data row\ntask = dataset.create_data_rows(image_data_rows) # List of data rows\ntask.wait_till_done()\nprint(task.errors) # Print any errors", + "cell_type": "code", "outputs": [], - "source": [ - "# Create dataset from client\n", - "dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n", - "\n", - "global_key = str(uuid.uuid4()) # Unique user specified ID\n", - "\n", - "# Data row structure\n", - "image_data_rows = [{\n", - " \"row_data\":\n", - " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n", - " \"global_key\":\n", - " global_key,\n", - " \"media_type\":\n", - " \"IMAGE\",\n", - "}]\n", - "\n", - "# Bulk import data row\n", - "task = dataset.create_data_rows(image_data_rows) # List of data rows\n", - "task.wait_till_done()\n", - "print(task.errors) # Print any errors" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 2: Creating an Ontology\n", @@ -137,49 +111,17 @@ "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a checklist classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", "\n", "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Bounding box feature\nobject_features = [\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"regulatory-sign\",\n color=\"#ff0000\",\n )\n]\n\n# Checklist feature\nclassification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\n# Builder function\nontology_builder = lb.OntologyBuilder(tools=object_features,\n classifications=classification_features)\n\n# Create ontology\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)", + "cell_type": "code", "outputs": [], - "source": [ - "# Bounding box feature\n", - "object_features = [\n", - " lb.Tool(\n", - " tool=lb.Tool.Type.BBOX,\n", - " name=\"regulatory-sign\",\n", - " color=\"#ff0000\",\n", - " )\n", - "]\n", - "\n", - "# Checklist feature\n", - "classification_features = [\n", - " lb.Classification(\n", - " class_type=lb.Classification.Type.CHECKLIST,\n", - " name=\"Quality Issues\",\n", - " options=[\n", - " lb.Option(value=\"blurry\", label=\"Blurry\"),\n", - " lb.Option(value=\"distorted\", label=\"Distorted\"),\n", - " ],\n", - " )\n", - "]\n", - "\n", - "# Builder function\n", - "ontology_builder = lb.OntologyBuilder(tools=object_features,\n", - " classifications=classification_features)\n", - "\n", - "# Create ontology\n", - "ontology = client.create_ontology(\n", - " \"Ontology from new features\",\n", - " ontology_builder.asdict(),\n", - " media_type=lb.MediaType.Image,\n", - ")" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 3: Creating a Project and Attaching our Ontology\n", @@ -187,26 +129,17 @@ "Now that we have made our ontology, we are ready to create a project where we can label our data row.\n", "\n", "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Create a new project\nproject = client.create_project(\n name=\"Quick Start Example Project\",\n media_type=lb.MediaType.Image, # specify the media type\n)\n\n# Attach created ontology\nproject.setup_editor(ontology)", + "cell_type": "code", "outputs": [], - "source": [ - "# Create a new project\n", - "project = client.create_project(\n", - " name=\"Quick Start Example Project\",\n", - " media_type=lb.MediaType.Image, # specify the media type\n", - ")\n", - "\n", - "# Attach created ontology\n", - "project.setup_editor(ontology)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", @@ -214,83 +147,49 @@ "With our project created, we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue, where labelers are able to annotate our data row.\n", "\n", "* A batch is a curated selection of data rows you can send to a project for labeling. You can create a batch with a combination of data rows within any dataset. For more information on creating batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "project.create_batch(\n name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n global_keys=[\n global_key\n ], # Global key we used earlier in this guide to create our dataset\n priority=5,\n)", + "cell_type": "code", "outputs": [], - "source": [ - "project.create_batch(\n", - " name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n", - " global_keys=[\n", - " global_key\n", - " ], # Global key we used earlier in this guide to create our dataset\n", - " priority=5,\n", - ")" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 5: Exporting from our Project\n", "\n", - "We have now successfully set up a project for labeling using only the SDK! 🚀 \n", + "We have now successfully set up a project for labeling using only the SDK! \ud83d\ude80 \n", "\n", "From here, you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide, no labels will be presented on our data row. For a full overview of exporting, visit our [export overview](https://docs.labelbox.com/reference/label-export) developer guide." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Start export from project\nexport_task = project.export()\nexport_task.wait_till_done()\n\n# Conditional if task has errors\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\n# Start export stream\nstream = export_task.get_buffered_stream()\n\n# Iterate through data rows\nfor data_row in stream:\n print(data_row.json)", + "cell_type": "code", "outputs": [], - "source": [ - "# Start export from project\n", - "export_task = project.export()\n", - "export_task.wait_till_done()\n", - "\n", - "# Conditional if task has errors\n", - "if export_task.has_errors():\n", - " export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n", - " stream_handler=lambda error: print(error))\n", - "\n", - "# Start export stream\n", - "stream = export_task.get_buffered_stream()\n", - "\n", - "# Iterate through data rows\n", - "for data_row in stream:\n", - " print(data_row.json)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Clean Up\n", "\n", "This section serves as an optional clean-up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# project.delete()\n# client.delete_unused_ontology(ontology.uid)\n# dataset.delete()", + "cell_type": "code", "outputs": [], - "source": [ - "# project.delete()\n", - "# client.delete_unused_ontology(ontology.uid)\n", - "# dataset.delete()" - ] + "execution_count": null } - ], - "metadata": { - "language_info": { - "name": "python" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} + ] +} \ No newline at end of file From 622c0f57849e3def9b3d800202f3432d0b2b260d Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Fri, 31 May 2024 09:04:32 -0500 Subject: [PATCH 16/17] typo --- examples/basics/quick_start.ipynb | 219 ++++++++++++++++++++++-------- 1 file changed, 160 insertions(+), 59 deletions(-) diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb index 0bbded2e8..644b7e608 100644 --- a/examples/basics/quick_start.ipynb +++ b/examples/basics/quick_start.ipynb @@ -1,18 +1,16 @@ { - "nbformat": 4, - "nbformat_minor": 2, - "metadata": {}, "cells": [ { + "cell_type": "markdown", "metadata": {}, "source": [ - "", - " ", + "\n", + " \n", "\n" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "\n", @@ -24,10 +22,10 @@ "\n", "" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "# Quick Start\n", @@ -42,49 +40,57 @@ "4. Sending our data row to our project by creating a batch\n", "5. Exporting our image data row from our project\n", "\n", - "This notebook is geared towards new users of our SDK." - ], - "cell_type": "markdown" + "This notebook is geared towards new users of Labelbox-Python SDK." + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Setup\n", "\n", - "We first need to install the labelbox library and then import the SDK module. It is recommended to install `\"labelbox[data]\"` over `labelbox` to obtain all the correct dependencies. We will also be importing the Python `uuid` library to generate universal unique IDs for the variety of objects that will be created with this notebook." - ], - "cell_type": "markdown" + "We first need to install the `labelbox` library and then import the SDK module. It is recommended to install `\"labelbox[data]\"` over `labelbox` to obtain all the correct dependencies. We will also be importing the Python `uuid` library to generate universal unique IDs for the variety of objects that will be created with this notebook." + ] }, { - "metadata": {}, - "source": "%pip install -q \"labelbox[data]\"", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "%pip install -q \"labelbox[data]\"" + ] }, { - "metadata": {}, - "source": "import labelbox as lb\nimport uuid", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "import labelbox as lb\n", + "import uuid" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## API Key and Client\n", "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." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "API_KEY = None\n", + "client = lb.Client(api_key=API_KEY)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1: Create Dataset and Import Data Row\n", @@ -93,17 +99,37 @@ "\n", "- Data rows are internal representations of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", "- A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catalog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Create dataset from client\ndataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n\nglobal_key = str(uuid.uuid4()) # Unique user specified ID\n\n# Data row structure\nimage_data_rows = [{\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"IMAGE\",\n}]\n\n# Bulk import data row\ntask = dataset.create_data_rows(image_data_rows) # List of data rows\ntask.wait_till_done()\nprint(task.errors) # Print any errors", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Create dataset from client\n", + "dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n", + "\n", + "global_key = str(uuid.uuid4()) # Unique user specified ID\n", + "\n", + "# Data row structure\n", + "image_data_rows = [{\n", + " \"row_data\":\n", + " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n", + " \"global_key\":\n", + " global_key,\n", + " \"media_type\":\n", + " \"IMAGE\",\n", + "}]\n", + "\n", + "# Bulk import data row\n", + "task = dataset.create_data_rows(image_data_rows) # List of data rows\n", + "task.wait_till_done()\n", + "print(task.errors) # Print any errors" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 2: Creating an Ontology\n", @@ -111,17 +137,49 @@ "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a checklist classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", "\n", "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Bounding box feature\nobject_features = [\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"regulatory-sign\",\n color=\"#ff0000\",\n )\n]\n\n# Checklist feature\nclassification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\n# Builder function\nontology_builder = lb.OntologyBuilder(tools=object_features,\n classifications=classification_features)\n\n# Create ontology\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Bounding box feature\n", + "object_features = [\n", + " lb.Tool(\n", + " tool=lb.Tool.Type.BBOX,\n", + " name=\"regulatory-sign\",\n", + " color=\"#ff0000\",\n", + " )\n", + "]\n", + "\n", + "# Checklist feature\n", + "classification_features = [\n", + " lb.Classification(\n", + " class_type=lb.Classification.Type.CHECKLIST,\n", + " name=\"Quality Issues\",\n", + " options=[\n", + " lb.Option(value=\"blurry\", label=\"Blurry\"),\n", + " lb.Option(value=\"distorted\", label=\"Distorted\"),\n", + " ],\n", + " )\n", + "]\n", + "\n", + "# Builder function\n", + "ontology_builder = lb.OntologyBuilder(tools=object_features,\n", + " classifications=classification_features)\n", + "\n", + "# Create ontology\n", + "ontology = client.create_ontology(\n", + " \"Ontology from new features\",\n", + " ontology_builder.asdict(),\n", + " media_type=lb.MediaType.Image,\n", + ")" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 3: Creating a Project and Attaching our Ontology\n", @@ -129,17 +187,26 @@ "Now that we have made our ontology, we are ready to create a project where we can label our data row.\n", "\n", "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Create a new project\nproject = client.create_project(\n name=\"Quick Start Example Project\",\n media_type=lb.MediaType.Image, # specify the media type\n)\n\n# Attach created ontology\nproject.setup_editor(ontology)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Create a new project\n", + "project = client.create_project(\n", + " name=\"Quick Start Example Project\",\n", + " media_type=lb.MediaType.Image,\n", + ")\n", + "\n", + "# Attach created ontology\n", + "project.setup_editor(ontology)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", @@ -147,49 +214,83 @@ "With our project created, we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue, where labelers are able to annotate our data row.\n", "\n", "* A batch is a curated selection of data rows you can send to a project for labeling. You can create a batch with a combination of data rows within any dataset. For more information on creating batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "project.create_batch(\n name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n global_keys=[\n global_key\n ], # Global key we used earlier in this guide to create our dataset\n priority=5,\n)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "project.create_batch(\n", + " name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n", + " global_keys=[\n", + " global_key\n", + " ], # Global key we used earlier in this guide to create our dataset\n", + " priority=5,\n", + ")" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Step 5: Exporting from our Project\n", "\n", - "We have now successfully set up a project for labeling using only the SDK! \ud83d\ude80 \n", + "We have now successfully set up a project for labeling using only the SDK! 🚀 \n", "\n", "From here, you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide, no labels will be presented on our data row. For a full overview of exporting, visit our [export overview](https://docs.labelbox.com/reference/label-export) developer guide." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# Start export from project\nexport_task = project.export()\nexport_task.wait_till_done()\n\n# Conditional if task has errors\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\n# Start export stream\nstream = export_task.get_buffered_stream()\n\n# Iterate through data rows\nfor data_row in stream:\n print(data_row.json)", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# Start export from project\n", + "export_task = project.export()\n", + "export_task.wait_till_done()\n", + "\n", + "# Conditional if task has errors\n", + "if export_task.has_errors():\n", + " export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n", + " stream_handler=lambda error: print(error))\n", + "\n", + "# Start export stream\n", + "stream = export_task.get_buffered_stream()\n", + "\n", + "# Iterate through data rows\n", + "for data_row in stream:\n", + " print(data_row.json)" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "## Clean Up\n", "\n", "This section serves as an optional clean-up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." - ], - "cell_type": "markdown" + ] }, { - "metadata": {}, - "source": "# project.delete()\n# client.delete_unused_ontology(ontology.uid)\n# dataset.delete()", "cell_type": "code", + "execution_count": null, + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "# project.delete()\n", + "# client.delete_unused_ontology(ontology.uid)\n", + "# dataset.delete()" + ] } - ] -} \ No newline at end of file + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From a695c46913fdb73e6633270af30ab20983bc7400 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 31 May 2024 14:05:24 +0000 Subject: [PATCH 17/17] :art: Cleaned --- examples/basics/quick_start.ipynb | 215 ++++++++---------------------- 1 file changed, 57 insertions(+), 158 deletions(-) diff --git a/examples/basics/quick_start.ipynb b/examples/basics/quick_start.ipynb index 644b7e608..4cc621743 100644 --- a/examples/basics/quick_start.ipynb +++ b/examples/basics/quick_start.ipynb @@ -1,16 +1,18 @@ { + "nbformat": 4, + "nbformat_minor": 2, + "metadata": {}, "cells": [ { - "cell_type": "markdown", "metadata": {}, "source": [ - "\n", - " \n", + "", + " ", "\n" - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "\n", @@ -22,10 +24,10 @@ "\n", "" - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "# Quick Start\n", @@ -41,56 +43,48 @@ "5. Exporting our image data row from our project\n", "\n", "This notebook is geared towards new users of Labelbox-Python SDK." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Setup\n", "\n", "We first need to install the `labelbox` library and then import the SDK module. It is recommended to install `\"labelbox[data]\"` over `labelbox` to obtain all the correct dependencies. We will also be importing the Python `uuid` library to generate universal unique IDs for the variety of objects that will be created with this notebook." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "%pip install -q \"labelbox[data]\"", + "cell_type": "code", "outputs": [], - "source": [ - "%pip install -q \"labelbox[data]\"" - ] + "execution_count": null }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "import labelbox as lb\nimport uuid", + "cell_type": "code", "outputs": [], - "source": [ - "import labelbox as lb\n", - "import uuid" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## API Key and Client\n", "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." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)", + "cell_type": "code", "outputs": [], - "source": [ - "API_KEY = None\n", - "client = lb.Client(api_key=API_KEY)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1: Create Dataset and Import Data Row\n", @@ -99,37 +93,17 @@ "\n", "- Data rows are internal representations of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n", "- A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catalog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Create dataset from client\ndataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n\nglobal_key = str(uuid.uuid4()) # Unique user specified ID\n\n# Data row structure\nimage_data_rows = [{\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"IMAGE\",\n}]\n\n# Bulk import data row\ntask = dataset.create_data_rows(image_data_rows) # List of data rows\ntask.wait_till_done()\nprint(task.errors) # Print any errors", + "cell_type": "code", "outputs": [], - "source": [ - "# Create dataset from client\n", - "dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n", - "\n", - "global_key = str(uuid.uuid4()) # Unique user specified ID\n", - "\n", - "# Data row structure\n", - "image_data_rows = [{\n", - " \"row_data\":\n", - " \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n", - " \"global_key\":\n", - " global_key,\n", - " \"media_type\":\n", - " \"IMAGE\",\n", - "}]\n", - "\n", - "# Bulk import data row\n", - "task = dataset.create_data_rows(image_data_rows) # List of data rows\n", - "task.wait_till_done()\n", - "print(task.errors) # Print any errors" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 2: Creating an Ontology\n", @@ -137,49 +111,17 @@ "Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a checklist classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n", "\n", "* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Bounding box feature\nobject_features = [\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"regulatory-sign\",\n color=\"#ff0000\",\n )\n]\n\n# Checklist feature\nclassification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\n# Builder function\nontology_builder = lb.OntologyBuilder(tools=object_features,\n classifications=classification_features)\n\n# Create ontology\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)", + "cell_type": "code", "outputs": [], - "source": [ - "# Bounding box feature\n", - "object_features = [\n", - " lb.Tool(\n", - " tool=lb.Tool.Type.BBOX,\n", - " name=\"regulatory-sign\",\n", - " color=\"#ff0000\",\n", - " )\n", - "]\n", - "\n", - "# Checklist feature\n", - "classification_features = [\n", - " lb.Classification(\n", - " class_type=lb.Classification.Type.CHECKLIST,\n", - " name=\"Quality Issues\",\n", - " options=[\n", - " lb.Option(value=\"blurry\", label=\"Blurry\"),\n", - " lb.Option(value=\"distorted\", label=\"Distorted\"),\n", - " ],\n", - " )\n", - "]\n", - "\n", - "# Builder function\n", - "ontology_builder = lb.OntologyBuilder(tools=object_features,\n", - " classifications=classification_features)\n", - "\n", - "# Create ontology\n", - "ontology = client.create_ontology(\n", - " \"Ontology from new features\",\n", - " ontology_builder.asdict(),\n", - " media_type=lb.MediaType.Image,\n", - ")" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 3: Creating a Project and Attaching our Ontology\n", @@ -187,26 +129,17 @@ "Now that we have made our ontology, we are ready to create a project where we can label our data row.\n", "\n", "* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Create a new project\nproject = client.create_project(\n name=\"Quick Start Example Project\",\n media_type=lb.MediaType.Image,\n)\n\n# Attach created ontology\nproject.setup_editor(ontology)", + "cell_type": "code", "outputs": [], - "source": [ - "# Create a new project\n", - "project = client.create_project(\n", - " name=\"Quick Start Example Project\",\n", - " media_type=lb.MediaType.Image,\n", - ")\n", - "\n", - "# Attach created ontology\n", - "project.setup_editor(ontology)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 4: Sending our Data Row to our Project by Creating a Batch\n", @@ -214,83 +147,49 @@ "With our project created, we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue, where labelers are able to annotate our data row.\n", "\n", "* A batch is a curated selection of data rows you can send to a project for labeling. You can create a batch with a combination of data rows within any dataset. For more information on creating batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "project.create_batch(\n name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n global_keys=[\n global_key\n ], # Global key we used earlier in this guide to create our dataset\n priority=5,\n)", + "cell_type": "code", "outputs": [], - "source": [ - "project.create_batch(\n", - " name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n", - " global_keys=[\n", - " global_key\n", - " ], # Global key we used earlier in this guide to create our dataset\n", - " priority=5,\n", - ")" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Step 5: Exporting from our Project\n", "\n", - "We have now successfully set up a project for labeling using only the SDK! 🚀 \n", + "We have now successfully set up a project for labeling using only the SDK! \ud83d\ude80 \n", "\n", "From here, you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide, no labels will be presented on our data row. For a full overview of exporting, visit our [export overview](https://docs.labelbox.com/reference/label-export) developer guide." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# Start export from project\nexport_task = project.export()\nexport_task.wait_till_done()\n\n# Conditional if task has errors\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\n# Start export stream\nstream = export_task.get_buffered_stream()\n\n# Iterate through data rows\nfor data_row in stream:\n print(data_row.json)", + "cell_type": "code", "outputs": [], - "source": [ - "# Start export from project\n", - "export_task = project.export()\n", - "export_task.wait_till_done()\n", - "\n", - "# Conditional if task has errors\n", - "if export_task.has_errors():\n", - " export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n", - " stream_handler=lambda error: print(error))\n", - "\n", - "# Start export stream\n", - "stream = export_task.get_buffered_stream()\n", - "\n", - "# Iterate through data rows\n", - "for data_row in stream:\n", - " print(data_row.json)" - ] + "execution_count": null }, { - "cell_type": "markdown", "metadata": {}, "source": [ "## Clean Up\n", "\n", "This section serves as an optional clean-up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown." - ] + ], + "cell_type": "markdown" }, { - "cell_type": "code", - "execution_count": null, "metadata": {}, + "source": "# project.delete()\n# client.delete_unused_ontology(ontology.uid)\n# dataset.delete()", + "cell_type": "code", "outputs": [], - "source": [ - "# project.delete()\n", - "# client.delete_unused_ontology(ontology.uid)\n", - "# dataset.delete()" - ] + "execution_count": null } - ], - "metadata": { - "language_info": { - "name": "python" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} + ] +} \ No newline at end of file