From 1e1917ee8a7f461414d6ebc29562d88627333cc3 Mon Sep 17 00:00:00 2001 From: ezekielemerson <91079021+ezekielemerson@users.noreply.github.com> Date: Wed, 23 Mar 2022 10:59:23 -0400 Subject: [PATCH] Revert "test" This reverts commit f282bc7bb0bbbf7ed35fe57cf035f5e862b5b6c5. --- examples/basics/ontologies.ipynb | 221 +++++++++++++------------------ 1 file changed, 95 insertions(+), 126 deletions(-) diff --git a/examples/basics/ontologies.ipynb b/examples/basics/ontologies.ipynb index f4be7ad88..078f0ddfd 100644 --- a/examples/basics/ontologies.ipynb +++ b/examples/basics/ontologies.ipynb @@ -2,18 +2,15 @@ "cells": [ { "cell_type": "markdown", - "id": "db768cda", - "metadata": {}, "source": [ "\n", " \n", "" - ] + ], + "metadata": {} }, { "cell_type": "markdown", - "id": "cb5611d0", - "metadata": {}, "source": [ "\n", "\n", "" - ] + ], + "metadata": {} }, { "cell_type": "markdown", - "id": "north-mountain", - "metadata": {}, "source": [ "# Ontologies\n", "* An ontology is a collection different tools and classifications that can be used within a project's editor. Each tool or classification is called a \"Feature Schema\". \n", @@ -38,74 +34,65 @@ "* Helpful Links:\n", " * [Ontology documentation](https://docs.labelbox.com/docs/labelbox-ontology)\n", " * [Project Setup Using Ontologies](https://github.com/Labelbox/labelbox-python/blob/develop/examples/project_configuration/project_setup.ipynb)" - ] + ], + "metadata": {} }, { "cell_type": "code", "execution_count": 1, - "id": "continuous-syndrome", - "metadata": { - "scrolled": true - }, - "outputs": [], "source": [ "!pip install labelbox" - ] + ], + "outputs": [], + "metadata": { + "scrolled": true + } }, { "cell_type": "code", "execution_count": 2, - "id": "passing-question", - "metadata": { - "scrolled": true - }, - "outputs": [], "source": [ "from labelbox import Client, OntologyBuilder, Tool, Classification, Option\n", "import json" - ] + ], + "outputs": [], + "metadata": { + "scrolled": true + } }, { "cell_type": "markdown", - "id": "a9ae9522", - "metadata": {}, "source": [ "# API Key and Client\n", "Provide a valid api key below in order to properly connect to the Labelbox Client." - ] + ], + "metadata": {} }, { "cell_type": "code", "execution_count": 3, - "id": "baking-recipient", - "metadata": { - "scrolled": true - }, - "outputs": [], "source": [ "# Add your api key\n", "API_KEY = None\n", "client = Client(api_key=API_KEY)" - ] + ], + "outputs": [], + "metadata": { + "scrolled": true + } }, { "cell_type": "markdown", - "id": "18d7cb3b", - "metadata": {}, "source": [ "### Create Ontology From Normalized Data\n", "* Users can create ontologies from a json definition of the ontology\n", "* See below `OntologyBuilder` section for more details on constructing the normalized ontology" - ] + ], + "metadata": {} }, { "cell_type": "code", "execution_count": 4, - "id": "refined-welsh", - "metadata": { - "scrolled": true - }, - "outputs": [], "source": [ "# This will automatically create new feature schema\n", "ontology_name = \"sdk-ontology\"\n", @@ -122,26 +109,24 @@ "ontology = client.create_ontology(name=ontology_name,\n", " normalized=ontology_normalized_json)\n", "print(ontology)" - ] + ], + "outputs": [], + "metadata": { + "scrolled": true + } }, { "cell_type": "markdown", - "id": "2c9ad9b8", - "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." - ] + ], + "metadata": {} }, { "cell_type": "code", "execution_count": 5, - "id": "faced-genome", - "metadata": { - "scrolled": true - }, - "outputs": [], "source": [ "# First create the feature schema\n", "feature_schema_cat = client.create_feature_schema(feature_schema_cat_normalized)\n", @@ -149,27 +134,25 @@ "print(feature_schema_cat.uid)\n", "ontology = client.create_ontology_from_feature_schemas(ontology_name,\n", " [feature_schema_cat.uid])" - ] + ], + "outputs": [], + "metadata": { + "scrolled": true + } }, { "cell_type": "markdown", - "id": "8c647804", - "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)." - ] + ], + "metadata": {} }, { "cell_type": "code", "execution_count": 6, - "id": "pacific-combining", - "metadata": { - "scrolled": true - }, - "outputs": [], "source": [ "# Create new dog schema id\n", "feature_schema_dog_normalized = {\n", @@ -183,78 +166,72 @@ "# (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])" - ] + ], + "outputs": [], + "metadata": { + "scrolled": true + } }, { "cell_type": "markdown", - "id": "boring-detail", - "metadata": {}, "source": [ "### Read\n", "* We can directly query by id for ontologies and feature schemas\n", "* We also can search for both by name" - ] + ], + "metadata": {} }, { "cell_type": "code", "execution_count": 7, - "id": "d746a962", - "metadata": { - "scrolled": true - }, - "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)" - ] + ], + "outputs": [], + "metadata": { + "scrolled": true + } }, { "cell_type": "code", "execution_count": 8, - "id": "05f8f22c", - "metadata": { - "scrolled": true - }, - "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)" - ] + ], + "outputs": [], + "metadata": { + "scrolled": true + } }, { "cell_type": "markdown", - "id": "relevant-transfer", - "metadata": {}, "source": [ "### Update and Delete\n", "- At this time, these options are not supported from the SDK.\n", "- Updating an ontology is dangerous and could cause labels to be hidden. \n", " - Use caution when doing so" - ] + ], + "metadata": {} }, { "cell_type": "markdown", - "id": "8ccb7742", - "metadata": {}, "source": [ "### Ontology Builder\n", "* The ontology builder is a tool for creating and modifying normalized json" - ] + ], + "metadata": {} }, { "cell_type": "code", "execution_count": 9, - "id": "aaa47614", - "metadata": { - "scrolled": true - }, - "outputs": [], "source": [ "# Create normalized json with a bounding box and segmentation tool\n", "ontology_builder = OntologyBuilder(tools=[\n", @@ -265,24 +242,22 @@ "ontology = client.create_ontology(\"ontology-builder-ontology\",\n", " ontology_builder.asdict())\n", "print(json.dumps(ontology.normalized, indent=2))" - ] + ], + "outputs": [], + "metadata": { + "scrolled": true + } }, { "cell_type": "markdown", - "id": "0dbc543d", - "metadata": {}, "source": [ "* Alternative syntax for defining the ontology via the OntologyBuilder" - ] + ], + "metadata": {} }, { "cell_type": "code", "execution_count": 10, - "id": "912a0445", - "metadata": { - "scrolled": true - }, - "outputs": [], "source": [ "# Create\n", "ontology_builder = OntologyBuilder()\n", @@ -294,24 +269,22 @@ "ontology = client.create_ontology(\"ontology-builder-ontology\",\n", " ontology_builder.asdict())\n", "print(json.dumps(ontology.normalized, indent=2))" - ] + ], + "outputs": [], + "metadata": { + "scrolled": true + } }, { "cell_type": "markdown", - "id": "460c30f8", - "metadata": {}, "source": [ "* Classifications are supported too (Both for top level and as subclassifications)" - ] + ], + "metadata": {} }, { "cell_type": "code", "execution_count": 11, - "id": "e212df2b", - "metadata": { - "scrolled": true - }, - "outputs": [], "source": [ "ontology_builder = OntologyBuilder(\n", " tools=[\n", @@ -330,24 +303,22 @@ " Option(value=\"blurry\")])\n", " ])\n", "print(json.dumps(ontology_builder.asdict(), indent=2))" - ] + ], + "outputs": [], + "metadata": { + "scrolled": true + } }, { "cell_type": "markdown", - "id": "b2ebb94a", - "metadata": {}, "source": [ "* All Tool objects are constructed the same way:" - ] + ], + "metadata": {} }, { "cell_type": "code", "execution_count": 12, - "id": "df8e624c", - "metadata": { - "scrolled": true - }, - "outputs": [], "source": [ "bbox_tool = Tool(tool=Tool.Type.BBOX, name=\"dog_box\")\n", "poly_tool = Tool(tool=Tool.Type.POLYGON, name=\"dog_poly\")\n", @@ -355,40 +326,38 @@ "point_tool = Tool(tool=Tool.Type.POINT, name=\"dog_center\")\n", "line_tool = Tool(tool=Tool.Type.LINE, name=\"dog_orientation\")\n", "ner_tool = Tool(tool=Tool.Type.NER, name=\"dog_reference\")" - ] + ], + "outputs": [], + "metadata": { + "scrolled": true + } }, { "cell_type": "markdown", - "id": "8f0c38be", - "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)" - ] + ], + "metadata": {} }, { "cell_type": "code", "execution_count": 13, - "id": "9ada8aef", - "metadata": { - "scrolled": true - }, - "outputs": [], "source": [ "text_classification = Classification(class_type=Classification.Type.TEXT,\n", " instructions=\"dog_name\")\n", - "radio_classification = Classification(class_type=Classification.Type.CHECKLIST,\n", + "radio_classification = Classification(class_type=Classification.Type.RADIO,\n", " instructions=\"dog_breed\",\n", " options=[Option(\"poodle\")])\n", - "dropdown_classification = Classification(\n", - " class_type=Classification.Type.DROPDOWN,\n", - " instructions=\"dog_features\",\n", - " options=[Option(\"short\"), Option(\"fluffy\")])\n", "checklist_classification = Classification(\n", " class_type=Classification.Type.CHECKLIST,\n", " instructions=\"background\",\n", " options=[Option(\"at_park\"), Option(\"has_leash\")])" - ] + ], + "outputs": [], + "metadata": { + "scrolled": true + } } ], "metadata": { @@ -412,4 +381,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} +} \ No newline at end of file