From 4819349ce64337b1120c2e5b97472adcd035b3c0 Mon Sep 17 00:00:00 2001 From: Sravani Mutta Date: Wed, 24 Jan 2024 15:05:51 +0530 Subject: [PATCH 1/2] updated segmentation mask tool name in ontologies tutorial --- examples/basics/ontologies.ipynb | 241 ++++++++++++++++--------------- 1 file changed, 123 insertions(+), 118 deletions(-) diff --git a/examples/basics/ontologies.ipynb b/examples/basics/ontologies.ipynb index 64a13d7ff..635bbcfd5 100644 --- a/examples/basics/ontologies.ipynb +++ b/examples/basics/ontologies.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,10 +22,10 @@ "\n", "" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "# Ontologies\n", @@ -37,48 +35,49 @@ "* Helpful Links:\n", " * [Ontology documentation](https://docs.labelbox.com/docs/labelbox-ontology)\n", " * [Project Setup Using Ontologies](https://github.com/Labelbox/labelbox-python/blob/master/examples/project_configuration/project_setup.ipynb)" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "!pip install labelbox -q" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "import labelbox as lb\n", "import json" - ], - "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", "client = lb.Client(api_key=API_KEY)" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", + "id": "1d40f49d", "metadata": {}, "source": [ "### Create Ontology From Normalized Data\n", @@ -92,14 +91,16 @@ "| Polygon | polygon |\n", "| Polyline | line |\n", "| Point | point |\n", - "| Segmentation mask | superpixel |\n", + "| Segmentation mask | raster-segmentation |\n", "| Entity | named-entity |\n", "| Relationship | edge |" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# This will automatically create new feature schema\n", "ontology_name = \"sdk-ontology\"\n", @@ -116,22 +117,22 @@ "ontology = client.create_ontology(name=ontology_name,\n", " normalized=ontology_normalized_json)\n", "print(ontology)" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "### Create Ontology From Existing Feature Schemas\n", "* It is often useful to support the same features in multiple ontologies. \n", "* Labelbox supports this workflow by allowing users to create ontologies using existing feature schemas." - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# First create the feature schema\n", "feature_schema_cat = client.create_feature_schema(feature_schema_cat_normalized)\n", @@ -139,23 +140,23 @@ "print(feature_schema_cat.uid)\n", "ontology = client.create_ontology_from_feature_schemas(ontology_name,\n", " [feature_schema_cat.uid])" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "### Create Ontology From a Mix of New and Existing Feature Schemas\n", "* If we want to create a new ontology that expands upon a previous ontology it is helpful to be able to share a portion of the features.\n", "* To do this we will create the new schema ids that we want. Then we will create an ontology from the new list of ids.\n", "* Note that for additional customization you can also combine the normalized json and use the create_ontology() method (not covered here)." - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Create new dog schema id\n", "feature_schema_dog_normalized = {\n", @@ -169,103 +170,101 @@ "# (ie. the cat feature schema will not be re-created)\n", "ontology = client.create_ontology_from_feature_schemas(\n", " ontology_name, [feature_schema_cat.uid, feature_schema_dog.uid])" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "### Read\n", "* We can directly query by id for ontologies and feature schemas\n", "* We also can search for both by name" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "#### Fetch by ID\n", "feature_schema = client.get_feature_schema(feature_schema_cat.uid)\n", "ontology = client.get_ontology(ontology.uid)\n", "print(feature_schema)\n", "print(ontology)" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "#### Search by name\n", "feature_schema = next(client.get_feature_schemas(\"cat\"))\n", "ontology = next(client.get_ontologies(ontology_name))\n", "print(feature_schema)\n", "print(ontology)" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "### Update and Delete" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Check if feature is archived\n", "feature_schema = next(client.get_feature_schemas(\"cat\"))\n", "client.is_feature_schema_archived(ontology_id=ontology.uid, feature_schema_id=feature_schema.uid)" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Update a feature's title \n", "client.update_feature_schema_title(feature_schema_id=feature_schema.uid, title=\"cat-2\")\n", "feature = client.get_feature_schema(feature_schema_id=feature_schema.uid)\n", "print(\"Feature: \", feature)" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Replace a feature \n", "tool = lb.Tool(feature_schema_id=feature_schema.uid, name=\"tool-cat-upserted\", tool=lb.Tool.Type.BBOX, color=\"#FF0000\")\n", "upserted_feature_schema_id = client.upsert_feature_schema(tool.asdict()).uid\n", "feature = client.get_feature_schema(feature_schema_id=upserted_feature_schema_id)\n", "print(\"Updated feature: \", feature)" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Insert a new feature \n", "tool = lb.Tool(name=\"tool-cat-2\", tool=lb.Tool.Type.RASTER_SEGMENTATION)\n", "feature_schema_id_new = client.create_feature_schema(tool.asdict()).uid\n", "client.insert_feature_schema_into_ontology(feature_schema_id=feature_schema_id_new, ontology_id=ontology.uid , position=2)\n", "print(\"Updated ontology: \", client.get_ontology(ontology_id=ontology.uid))" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "Delete or Archived a feature:\n", @@ -273,40 +272,42 @@ "If the feature schema is a root level node with associated labels, it will be archived.\n", "If the feature schema is a nested node in the ontology and does not have associated labels, it will be deleted.\n", "If the feature schema is a nested node in the ontology and has associated labels, it will not be deleted." - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "client.delete_feature_schema_from_ontology(ontology_id=ontology.uid, feature_schema_id=feature_schema_id_new)" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Only features with annotations will be archived, features without annotations will be deleted. \n", "feature_schema_id_with_annotations = \"\" \n", "ontology_id = \"\"\n", "client.unarchive_feature_schema_node(ontology_id=ontology_id, root_feature_schema_id=feature_schema_id_with_annotations)" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "### Ontology Builder\n", "* The ontology builder is a tool for creating and modifying normalized json" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Create normalized json with a bounding box and segmentation tool\n", "ontology_builder = lb.OntologyBuilder(tools=[\n", @@ -317,20 +318,20 @@ "ontology = client.create_ontology(\"ontology-builder-ontology\",\n", " ontology_builder.asdict())\n", "print(json.dumps(ontology.normalized, indent=2))" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "* Alternative syntax for defining the ontology via the OntologyBuilder" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Create\n", "ontology_builder = lb.OntologyBuilder()\n", @@ -342,20 +343,20 @@ "ontology = client.create_ontology(\"ontology-builder-ontology\",\n", " ontology_builder.asdict())\n", "print(json.dumps(ontology.normalized, indent=2))" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "* Classifications are supported too (Both for top level and as subclassifications)" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "ontology_builder = lb.OntologyBuilder(\n", " tools=[\n", @@ -374,20 +375,20 @@ " lb.Option(value=\"blurry\")])\n", " ])\n", "print(json.dumps(ontology_builder.asdict(), indent=2))" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "Example of how to add sub-classfication within an option" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# We will use add_classification to add this classification to a previously built ontology_builder or you can create new ontology_builder = OntologyBuilder() \n", "radio_classification = lb.Classification(class_type=lb.Classification.Type.RADIO,\n", @@ -403,20 +404,20 @@ "ontology = client.create_ontology(\"example of nested classification\",\n", " ontology_builder.asdict())\n", "print(json.dumps(ontology.normalized, indent=2))" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "* All Tool objects are constructed the same way:" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "bbox_tool = lb.Tool(tool=lb.Tool.Type.BBOX, name=\"dog_box\")\n", "poly_tool = lb.Tool(tool=lb.Tool.Type.POLYGON, name=\"dog_poly\")\n", @@ -425,21 +426,21 @@ "line_tool = lb.Tool(tool=lb.Tool.Type.LINE, name=\"dog_orientation\")\n", "ner_tool = lb.Tool(tool=lb.Tool.Type.NER, name=\"dog_reference\")\n", "relationship_tool = lb.Tool(tool=lb.Tool.Type.RELATIONSHIP, name=\"relationship\")" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] }, { + "cell_type": "markdown", "metadata": {}, "source": [ "* Classifications are all constructed the same way (except text which doesn't require options)\n", "* Classifications can be global or subclasses to a tool (ie dog bounding box, with a breed classification)" - ], - "cell_type": "markdown" + ] }, { + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "text_classification = lb.Classification(class_type=lb.Classification.Type.TEXT,\n", " name=\"dog_name\")\n", @@ -450,10 +451,14 @@ " class_type=lb.Classification.Type.CHECKLIST,\n", " name=\"background\",\n", " options=[lb.Option(\"at_park\"), lb.Option(\"has_leash\")])" - ], - "cell_type": "code", - "outputs": [], - "execution_count": null + ] } - ] -} \ No newline at end of file + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 5fb56ef051536dae5281217ca62b29bf54867e62 Mon Sep 17 00:00:00 2001 From: Sravani Mutta Date: Wed, 24 Jan 2024 16:53:40 +0530 Subject: [PATCH 2/2] SN-108-remove-superpixel --- examples/basics/ontologies.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/basics/ontologies.ipynb b/examples/basics/ontologies.ipynb index 635bbcfd5..a9dc0b4f9 100644 --- a/examples/basics/ontologies.ipynb +++ b/examples/basics/ontologies.ipynb @@ -91,7 +91,7 @@ "| Polygon | polygon |\n", "| Polyline | line |\n", "| Point | point |\n", - "| Segmentation mask | raster-segmentation |\n", + "| Segmentation mask | raster-segmentation |\n", "| Entity | named-entity |\n", "| Relationship | edge |" ]