From d3a69d09d63da6a4e7de93f83b09e4cb329f4936 Mon Sep 17 00:00:00 2001
From: Andrea Ovalle <74880762+ovalle15@users.noreply.github.com>
Date: Fri, 28 Oct 2022 09:34:32 -0400
Subject: [PATCH] Update project setup
---
.../project_configuration/project_setup.ipynb | 599 ++++++++++++------
1 file changed, 394 insertions(+), 205 deletions(-)
diff --git a/examples/project_configuration/project_setup.ipynb b/examples/project_configuration/project_setup.ipynb
index 6914e4593..52f394107 100644
--- a/examples/project_configuration/project_setup.ipynb
+++ b/examples/project_configuration/project_setup.ipynb
@@ -1,217 +1,406 @@
{
- "cells": [
- {
- "cell_type": "markdown",
- "id": "db768cda",
- "metadata": {},
- "source": [
- "
\n",
- " \n",
- " | "
- ]
- },
- {
- "cell_type": "markdown",
- "id": "cb5611d0",
- "metadata": {},
- "source": [
- "\n",
- " \n",
- " | \n",
- "\n",
- "\n",
- " \n",
- " | "
- ]
- },
- {
- "cell_type": "markdown",
- "id": "boxed-football",
- "metadata": {},
- "source": [
- "# Project Setup\n",
- "* This notebok describes how to create and configure a project\n",
- "* This is the same as creating a new project in the editor and going through all of the steps."
- ]
- },
- {
- "cell_type": "markdown",
- "id": "thousand-difference",
- "metadata": {},
- "source": [
- "* When a user creates a project with client.create_project() the project is not ready for labeling.\n",
- " * An ontology must be set\n",
- " * datasets must be attached"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "id": "contemporary-banking",
- "metadata": {},
- "outputs": [],
- "source": [
- "!pip install labelbox"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "id": "ordered-notice",
- "metadata": {},
- "outputs": [],
- "source": [
- "from labelbox import Client, Project, Tool, OntologyBuilder\n",
- "from labelbox.schema.media_type import MediaType"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "2c66dbf3",
- "metadata": {},
- "source": [
- "# API Key and Client\n",
- "Provide a valid api key below in order to properly connect to the Labelbox Client."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "id": "royal-algeria",
- "metadata": {},
- "outputs": [],
- "source": [
- "# Add your api key\n",
- "API_KEY = None\n",
- "client = Client(api_key=API_KEY)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "least-stone",
- "metadata": {},
- "source": [
- "### Create Dataset\n",
- "* Create dataset and attach data\n",
- "* More details on attaching data can be found [here](https://github.com/Labelbox/labelbox-python/blob/develop/examples/basics/data_rows.ipynb)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "id": "0c195add",
- "metadata": {},
- "outputs": [],
- "source": [
- "dataset = client.create_dataset(name=\"my_new_dataset\")\n",
- "# Add data_rows since this is a new dataset (see basics/data_rows.ipynb for more information on this)\n",
- "test_img_url = \"https://raw.githubusercontent.com/Labelbox/labelbox-python/develop/examples/assets/2560px-Kitano_Street_Kobe01s5s4110.jpg\"\n",
- "dataset.create_data_row(row_data=test_img_url)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "e4f8b7f7",
- "metadata": {},
- "source": [
- "### Create Or Select an Ontology\n",
- "* Optionally create an ontology or select from an existing one.\n",
- "* More details on ontology management can be found [here](https://github.com/Labelbox/labelbox-python/blob/develop/examples/basics/ontologies.ipynb)\n",
- " "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "id": "a9e4738c",
- "metadata": {},
- "outputs": [],
- "source": [
- "# Create\n",
- "ontology_builder = OntologyBuilder(\n",
- " tools=[Tool(name=\"cat\", tool=Tool.Type.BBOX)])\n",
- "ontology = client.create_ontology(\"project-setup-demo-ontology\",\n",
- " ontology_builder.asdict())\n",
- "# Select existing ontology\n",
- "#ontology = client.get_ontology(\"\")\n",
- "#ontology = existing_project.ontology()"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "limiting-bleeding",
- "metadata": {},
- "source": [
- "### Create Project and Setup the Editor\n",
- "* Setting up a project will add an ontology and will enable labeling to begin\n",
- "* Attaching dataset(s) will add all data_rows belonging to the dataset to the queue."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "id": "reserved-vietnam",
- "metadata": {},
- "outputs": [],
- "source": [
- "project = client.create_project(name=\"my_new_project\", media_type=MediaType.Image)\n",
- "project.setup_editor(ontology)\n",
- "project.datasets.connect(dataset)"
- ]
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "db768cda",
+ "metadata": {
+ "id": "db768cda"
+ },
+ "source": [
+ "\n",
+ " \n",
+ " | "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "cb5611d0",
+ "metadata": {
+ "id": "cb5611d0"
+ },
+ "source": [
+ "\n",
+ " \n",
+ " | \n",
+ "\n",
+ "\n",
+ " \n",
+ " | "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "boxed-football",
+ "metadata": {
+ "id": "boxed-football"
+ },
+ "source": [
+ "# Project Setup\n",
+ "* This notebok describes how to create and configure a project\n",
+ "* This is the same as creating a new project in the editor and going through all of the steps."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "thousand-difference",
+ "metadata": {
+ "id": "thousand-difference"
+ },
+ "source": [
+ "* When a user creates a project with client.create_project() the project is not ready for labeling.\n",
+ " * An ontology must be set\n",
+ " * Datasets/Batchh must be attached"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "contemporary-banking",
+ "metadata": {
+ "id": "contemporary-banking"
+ },
+ "outputs": [],
+ "source": [
+ "!pip install labelbox[data]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "id": "ordered-notice",
+ "metadata": {
+ "id": "ordered-notice"
+ },
+ "outputs": [],
+ "source": [
+ "from labelbox import Client, Project, Tool, OntologyBuilder\n",
+ "from labelbox.schema.media_type import MediaType\n",
+ "from labelbox.schema.queue_mode import QueueMode\n",
+ "import uuid"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "2c66dbf3",
+ "metadata": {
+ "id": "2c66dbf3"
+ },
+ "source": [
+ "# API Key and Client\n",
+ "Provide a valid api key below in order to properly connect to the Labelbox Client."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "id": "royal-algeria",
+ "metadata": {
+ "id": "royal-algeria"
+ },
+ "outputs": [],
+ "source": [
+ "# Add your api key\n",
+ "API_KEY=None\n",
+ "client = Client(api_key=API_KEY)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "least-stone",
+ "metadata": {
+ "id": "least-stone"
+ },
+ "source": [
+ "### Create Dataset\n",
+ "* Create dataset and attach data\n",
+ "* More details on attaching data can be found [here](https://github.com/Labelbox/labelbox-python/blob/develop/examples/basics/data_rows.ipynb)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "id": "0c195add",
+ "metadata": {
+ "id": "0c195add",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
},
+ "outputId": "de924e2b-f996-42b5-e02a-337c5662eaa4"
+ },
+ "outputs": [
{
- "cell_type": "markdown",
- "id": "afraid-trademark",
- "metadata": {},
- "source": [
- "### Review"
- ]
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "ERRORS: None\n",
+ "RESULT URL: https://storage.labelbox.com/cl3ahv73w1891087qbwzs3edd%2Fdata-row-imports-results%2Fcl9sj9crk0zf307yo0mnm17y4_cl9sj9e1u50gm07upd3xj7vyx.json?Expires=1667050292662&KeyName=labelbox-assets-key-3&Signature=JW912R-7wveaHGyhkdKIBRKEtVw\n"
+ ]
+ }
+ ],
+ "source": [
+ "dataset = client.create_dataset(name=\"project_setup_demo\")\n",
+ "## Example image\n",
+ "uploads = []\n",
+ "# Generate data rows\n",
+ "for i in range(1,9):\n",
+ " uploads.append({\n",
+ " 'row_data': f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n",
+ " \"global_key\": f\"ID-{ uuid.uuid1()}\"\n",
+ " })\n",
+ "data_rows = dataset.create_data_rows(uploads)\n",
+ "data_rows.wait_till_done()\n",
+ "print(\"ERRORS: \" , data_rows.errors)\n",
+ "print(\"RESULT URL: \", data_rows.result_url)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "e4f8b7f7",
+ "metadata": {
+ "id": "e4f8b7f7"
+ },
+ "source": [
+ "### Create Or Select an Ontology\n",
+ "* Optionally create an ontology or select from an existing one.\n",
+ "* More details on ontology management can be found [here](https://github.com/Labelbox/labelbox-python/blob/develop/examples/basics/ontologies.ipynb)\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "id": "a9e4738c",
+ "metadata": {
+ "id": "a9e4738c"
+ },
+ "outputs": [],
+ "source": [
+ "# Create\n",
+ "ontology_builder = OntologyBuilder(\n",
+ " tools=[Tool(name=\"cat\", tool=Tool.Type.BBOX)])\n",
+ "ontology = client.create_ontology(\"project-setup-demo-ontology\",\n",
+ " ontology_builder.asdict())\n",
+ "# Select existing ontology\n",
+ "#ontology = client.get_ontology(\"\")\n",
+ "#ontology = existing_project.ontology()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "limiting-bleeding",
+ "metadata": {
+ "id": "limiting-bleeding"
+ },
+ "source": [
+ "### Create Project and Setup the Editor\n",
+ "* Setting up a project will add an ontology and will enable labeling to begin\n",
+ "* Attaching dataset(s) will add all data_rows belonging to the dataset to the queue.\n",
+ "* Creating batches will add data rows exported from a dataset"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "id": "reserved-vietnam",
+ "metadata": {
+ "id": "reserved-vietnam"
+ },
+ "outputs": [],
+ "source": [
+ "batch_project = client.create_project(name=\"batch-test-project\", \n",
+ " media_type=MediaType.Image,\n",
+ " # Setup quality settings (Benchmarks)\n",
+ " auto_audit_percentage=1,\n",
+ " auto_audit_number_of_labels=1,\n",
+ " queue_mode=QueueMode.Batch)\n",
+ "\n",
+ "\n",
+ "dataset_project = client.create_project(name=\"dataset-test-project\",\n",
+ " description=\"a description\",\n",
+ " media_type=MediaType.Image,\n",
+ " ## Setup quality settings (Consensus)\n",
+ " auto_audit_percentage=0.1,\n",
+ " auto_audit_number_of_labels=3,\n",
+ " queue_mode=QueueMode.Dataset)\n",
+ "\n",
+ "batch_project.setup_editor(ontology)\n",
+ "dataset_project.setup_editor(ontology)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "# Add data to your projects "
+ ],
+ "metadata": {
+ "id": "yLPMPtv6-zPU"
+ },
+ "id": "yLPMPtv6-zPU"
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "\n",
+ "####### Connect your dataset \n",
+ "# Dataset projects do not support batches\n",
+ "\n",
+ "dataset_project.datasets.connect(dataset)\n",
+ "\n",
+ "######## Create batches \n",
+ "# Batch projects do not support datasets\n",
+ "\n",
+ "# We need the data row ID to create a batch\n",
+ "batch_datarows = [dr.uid for dr in list(dataset.export_data_rows())]\n",
+ "\n",
+ "## When creating a batch you can also setup the data rows priority\n",
+ "batch = batch_project.create_batch(\n",
+ " \"batch-demo\", # Each batch in a project must have a unique name\n",
+ " batch_datarows, # A list of data rows or data row ids\n",
+ " 5 # priority between 1(Highest) - 5(lowest)\n",
+ ")\n",
+ "print(\"Batch: \", batch)"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
},
+ "id": "IVwLUGRz-yrg",
+ "outputId": "b026daaa-ada8-4c49-80f0-5f1eb03ab896"
+ },
+ "id": "IVwLUGRz-yrg",
+ "execution_count": 7,
+ "outputs": [
{
- "cell_type": "code",
- "execution_count": 7,
- "id": "vanilla-diamond",
- "metadata": {},
- "outputs": [],
- "source": [
- "# Note setup_complete will be None if it fails.\n",
- "print(project.setup_complete)\n",
- "print(project.ontology())\n",
- "print([ds.name for ds in project.datasets()])"
- ]
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Batch: \n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "afraid-trademark",
+ "metadata": {
+ "id": "afraid-trademark"
+ },
+ "source": [
+ "### Review"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "id": "vanilla-diamond",
+ "metadata": {
+ "id": "vanilla-diamond",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
},
+ "outputId": "1b6883f4-9b3d-474d-b2c4-97afdf6473d5"
+ },
+ "outputs": [
{
- "cell_type": "code",
- "execution_count": 8,
- "id": "alpha-dayton",
- "metadata": {},
- "outputs": [],
- "source": [
- "print(f\"https://app.labelbox.com/projects/{project.uid}\")"
- ]
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "2022-10-28 13:32:45+00:00\n",
+ "2022-10-28 13:32:50+00:00\n",
+ "\n",
+ "\n",
+ "['batch-demo']\n",
+ "['project_setup_demo']\n"
+ ]
}
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3 (ipykernel)",
- "language": "python",
- "name": "python3"
+ ],
+ "source": [
+ "# Note setup_complete will be None if it fails.\n",
+ "print(batch_project.setup_complete)\n",
+ "print(dataset_project.setup_complete)\n",
+ "print(batch_project.ontology())\n",
+ "\n",
+ "print(dataset_project.ontology())\n",
+ "print([ds.name for ds in batch_project.batches()])\n",
+ "print([ds.name for ds in dataset_project.datasets()])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "id": "alpha-dayton",
+ "metadata": {
+ "id": "alpha-dayton",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
},
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.8.2"
+ "outputId": "29225ad8-a6b9-43fd-f50b-2e935e1f1dfd"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "https://app.labelbox.com/projects/cl9sjavsl2oqx07w92abm9zy0\n",
+ "https://app.labelbox.com/projects/cl9sjaw2d2pgq07vddlfsgy6k\n"
+ ]
}
+ ],
+ "source": [
+ "print(f\"https://app.labelbox.com/projects/{batch_project.uid}\")\n",
+ "print(f\"https://app.labelbox.com/projects/{dataset_project.uid}\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "# Cleanup"
+ ],
+ "metadata": {
+ "id": "9YPXMzQBBHsL"
+ },
+ "id": "9YPXMzQBBHsL"
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "# batch_project.delete()\n",
+ "# dataset_project.delete()\n",
+ "# dataset.delete()"
+ ],
+ "metadata": {
+ "id": "ueOV7oaxBGv0"
+ },
+ "id": "ueOV7oaxBGv0",
+ "execution_count": 10,
+ "outputs": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.8.2"
},
- "nbformat": 4,
- "nbformat_minor": 5
+ "colab": {
+ "provenance": [],
+ "collapsed_sections": []
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
}