From 483766917dbf19a506e555754804b8cf22b7bc4f Mon Sep 17 00:00:00 2001 From: Paul Noirel Date: Mon, 26 Feb 2024 17:01:53 +0000 Subject: [PATCH] Add example for tags management --- examples/basics/projects.ipynb | 251 ++++++++++++++++++++++----------- 1 file changed, 166 insertions(+), 85 deletions(-) diff --git a/examples/basics/projects.ipynb b/examples/basics/projects.ipynb index e05adb08e..a1245ff56 100644 --- a/examples/basics/projects.ipynb +++ b/examples/basics/projects.ipynb @@ -1,18 +1,16 @@ { - "nbformat": 4, - "nbformat_minor": 5, - "metadata": {}, "cells": [ { + "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", "" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "\n", @@ -24,17 +22,17 @@ "\n", "" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "# Projects" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "* A project can be thought of as a specific labeling task on a set of labels\n", @@ -42,77 +40,79 @@ "* Each project has an ontology which defines the types of annotations supported during the labeling process\n", "**Note that there is a lot of advanced usage that is not covered in this notebook. See examples/project_configuration/project_setup.ipynb for those functions**\n", "* Also note that deprecated functions are not explained here." - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "!pip install -q \"labelbox[data]\"" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "import labelbox as lb\n", "import labelbox.types as lb_types\n", "import uuid" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "# API Key and Client\n", "Provide a valid api key below in order to properly connect to the Labelbox Client." - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Add your API key\n", "API_KEY = \"\"\n", "# To get your API key go to: Workspace settings -> API -> Create API Key\n", "client = lb.Client(api_key=API_KEY)" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "### Create a project\n" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Creates an empty project\n", "project = client.create_project(name=\"my-test-project\",\n", " description=\"a description\",\n", " media_type=lb.MediaType.Image)" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "### Create a dataset with data rows" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "dataset = client.create_dataset(name=\"project-demo-dataset\")\n", "global_keys = []\n", @@ -130,49 +130,126 @@ "task.wait_till_done()\n", "print(\"ERRORS: \" , task.errors)\n", "print(\"RESULT URL: \", task.result_url)" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "### Add a data rows to a project \n" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "project.create_batch(\n", " \"project-demo\", # each batch in a project must have a unique name\n", " global_keys=global_keys, # paginated collection of data row objects, list of data row ids or global keys\n", " priority=1 # priority between 1(highest) - 5(lowest)\n", ")" - ], + ] + }, + { + "cell_type": "markdown", + "id": "bc1b9e39", + "metadata": {}, + "source": [ + "### Create tags and assign them to a project\n", + "In this section, we are creating a tag in the ontology and associating it with a project. Then we are listing the tags attached to a project.\n" + ] + }, + { + "cell_type": "markdown", + "id": "78e10b96", + "metadata": {}, + "source": [ + "#### Create a tag" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "acf68444", + "metadata": {}, + "outputs": [], + "source": [ + "# Get the organization\n", + "organization = client.get_organization()\n", + "\n", + "tag = organization.create_resource_tag(\n", + " {\n", + " \"text\": \"new-tag-name\",\n", + " \"color\": \"4ed2f9\"\n", + " }\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "62666b38", + "metadata": {}, + "source": [ + "#### Assign the tag to a project" + ] + }, + { "cell_type": "code", + "execution_count": null, + "id": "dc6184ef", + "metadata": {}, + "outputs": [], + "source": [ + "tags = project.update_project_resource_tags([tag.uid])" + ] + }, + { + "cell_type": "markdown", + "id": "3dbd49fe", + "metadata": {}, + "source": [ + "#### Get project tags" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "01a1c401", + "metadata": {}, "outputs": [], - "execution_count": null + "source": [ + "tags = project.get_resource_tags()" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "### Attach ontology and label data rows\n", "\n", "In this section, we are creating an ontology to attach to a project and creating labels to import as ground truths. We need this setup to demonstrate other methods later in the demo. For more information, please reference our [Ontology](https://docs.labelbox.com/reference/ontology) and [Import Image Annotation](https://docs.labelbox.com/reference/import-image-annotations) development guides." - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", + "id": "2725b574", + "metadata": {}, + "source": [] + }, + { + "cell_type": "markdown", "metadata": {}, "source": [ "Create your ontology" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Create normalized json with a radio classification\n", "ontology_builder = lb.OntologyBuilder(classifications=[ # List of Classification objects\n", @@ -186,37 +263,37 @@ "# Creating an ontology\n", "ontology = client.create_ontology(\"test-ontology\",\n", " ontology_builder.asdict())" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "Attach ontology to project" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "\n", "project.setup_editor(ontology)" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "Create labels and upload them to project as ground truths" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Create labels\n", "labels = []\n", @@ -240,51 +317,51 @@ "upload_job.wait_until_done()\n", "\n", "print(f\"Errors: {upload_job.errors}\")" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "### Move data rows in project to different task queues" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Get list of task queues for project\n", "task_queues = project.task_queues()\n", "\n", "for task_queue in task_queues:\n", " print(task_queue)" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "project.move_data_rows_to_task_queue(data_row_ids=lb.GlobalKeys(global_keys), #Provide a list of global keys\n", " task_queue_id=task_queues[2].uid #Passing None moves data rows to \"Done\" task queue\n", " )" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "### Fetch project configuration" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Note the project is not fully setup many of the fields will be empty. \n", "print(\"Project is not setup yet:\", project.setup_complete is None)\n", @@ -294,28 +371,32 @@ "batches = [b for b in project.batches()]\n", "print(\"Project Batches\", batches)\n", "print(\"Ontology:\", project.ontology())" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "### Clean Up" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# project.delete()\n", "# dataset.delete()\n", "# client.delete_unused_ontology(ontology.uid)" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] } - ] -} \ No newline at end of file + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}