Skip to content

Commit 2a97fa6

Browse files
authored
Merge pull request #340 from Labelbox/ms/ontology-updates
ontology management
2 parents 9ee6dff + bc9f27e commit 2a97fa6

File tree

8 files changed

+628
-504
lines changed

8 files changed

+628
-504
lines changed

examples/basics/ontologies.ipynb

Lines changed: 221 additions & 369 deletions
Large diffs are not rendered by default.

examples/project_configuration/project_setup.ipynb

Lines changed: 47 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"metadata": {},
77
"source": [
88
"# Project Setup\n",
9-
"* This section describes how to create and configure a project\n",
9+
"* This notebok describes how to create and configure a project\n",
1010
"* This is the same as creating a new project in the editor and going through all of the steps."
1111
]
1212
},
@@ -22,7 +22,7 @@
2222
},
2323
{
2424
"cell_type": "code",
25-
"execution_count": 1,
25+
"execution_count": null,
2626
"id": "contemporary-banking",
2727
"metadata": {},
2828
"outputs": [],
@@ -32,60 +32,24 @@
3232
},
3333
{
3434
"cell_type": "code",
35-
"execution_count": 2,
35+
"execution_count": null,
3636
"id": "ordered-notice",
3737
"metadata": {},
3838
"outputs": [],
3939
"source": [
40-
"from labelbox import Client, Project, LabelingFrontend\n",
41-
"from labelbox.schema.ontology import Tool, OntologyBuilder\n",
42-
"from getpass import getpass\n",
43-
"import os"
40+
"from labelbox import Client, Project, Tool, OntologyBuilder"
4441
]
4542
},
4643
{
4744
"cell_type": "code",
48-
"execution_count": 3,
49-
"id": "alert-train",
50-
"metadata": {},
51-
"outputs": [],
52-
"source": [
53-
"# If you don't want to give google access to drive you can skip this cell\n",
54-
"# and manually set `API_KEY` below.\n",
55-
"\n",
56-
"COLAB = \"google.colab\" in str(get_ipython())\n",
57-
"if COLAB:\n",
58-
" !pip install colab-env -qU\n",
59-
" from colab_env import envvar_handler\n",
60-
" envvar_handler.envload()\n",
61-
"\n",
62-
"API_KEY = os.environ.get(\"LABELBOX_API_KEY\")\n",
63-
"if not os.environ.get(\"LABELBOX_API_KEY\"):\n",
64-
" API_KEY = getpass(\"Please enter your labelbox api key\")\n",
65-
" if COLAB:\n",
66-
" envvar_handler.add_env(\"LABELBOX_API_KEY\", API_KEY)"
67-
]
68-
},
69-
{
70-
"cell_type": "code",
71-
"execution_count": 4,
45+
"execution_count": null,
7246
"id": "royal-algeria",
7347
"metadata": {},
7448
"outputs": [],
7549
"source": [
76-
"# Set this to a project that is already set up\n",
77-
"PROJECT_ID = \"ckm4xyfncfgja0760vpfdxoro\"\n",
78-
"# Only update this if you have an on-prem deployment\n",
79-
"ENDPOINT = \"https://api.labelbox.com/graphql\""
80-
]
81-
},
82-
{
83-
"cell_type": "code",
84-
"execution_count": 5,
85-
"id": "welsh-maker",
86-
"metadata": {},
87-
"outputs": [],
88-
"source": [
50+
"# Add your api key\n",
51+
"API_KEY = None\n",
52+
"ENDPOINT = \"https://api.labelbox.com/graphql\"\n",
8953
"client = Client(api_key=API_KEY, endpoint=ENDPOINT)"
9054
]
9155
},
@@ -94,86 +58,71 @@
9458
"id": "least-stone",
9559
"metadata": {},
9660
"source": [
97-
"### Identify project, dataset, and ontology\n",
98-
"* Pick the project to setup\n",
99-
"* Dataset(s) to attach to that project\n",
100-
"* Configure the ontology for the project"
61+
"### Create Dataset\n",
62+
"* Create dataset and attach data\n",
63+
"* More details on attaching data can be found [here](https://github.com/Labelbox/labelbox-python/blob/develop/examples/basics/data_rows.ipynb)"
10164
]
10265
},
10366
{
10467
"cell_type": "code",
105-
"execution_count": 6,
106-
"id": "mobile-south",
68+
"execution_count": null,
69+
"id": "0c195add",
10770
"metadata": {},
10871
"outputs": [],
10972
"source": [
110-
"# Use bounding boxes to label cats\n",
111-
"ontology_builder = OntologyBuilder(\n",
112-
" tools=[Tool(name=\"cat\", tool=Tool.Type.BBOX)])\n",
113-
"project = client.create_project(name=\"my_new_project\")\n",
11473
"dataset = client.create_dataset(name=\"my_new_dataset\")\n",
11574
"# Add data_rows since this is a new dataset (see basics/data_rows.ipynb for more information on this)\n",
11675
"test_img_url = \"https://raw.githubusercontent.com/Labelbox/labelbox-python/develop/examples/assets/2560px-Kitano_Street_Kobe01s5s4110.jpg\"\n",
11776
"dataset.create_data_row(row_data=test_img_url)"
11877
]
11978
},
12079
{
121-
"cell_type": "code",
122-
"execution_count": 7,
123-
"id": "neural-scanning",
80+
"cell_type": "markdown",
81+
"id": "e4f8b7f7",
12482
"metadata": {},
125-
"outputs": [],
12683
"source": [
127-
"# Unless you are using a custom editor you should always use the following editor:\n",
128-
"editor = next(\n",
129-
" client.get_labeling_frontends(where=LabelingFrontend.name == \"Editor\"))"
84+
"### Create Or Select an Ontology\n",
85+
"* Optionally create an ontology or select from an existing one.\n",
86+
"* More details on ontology management can be found [here](https://github.com/Labelbox/labelbox-python/blob/develop/examples/basics/ontologies.ipynb)\n",
87+
" "
13088
]
13189
},
13290
{
13391
"cell_type": "code",
134-
"execution_count": 8,
135-
"id": "attended-twist",
92+
"execution_count": null,
93+
"id": "a9e4738c",
13694
"metadata": {},
13795
"outputs": [],
13896
"source": [
139-
"# Note that you can use any dataset or ontology even if they already exist.\n",
140-
"existing_project = client.get_project(PROJECT_ID)\n",
141-
"# We are not using this, but it is possible to copy the ontology to the new project\n",
142-
"ontology = existing_project.ontology()"
97+
"# Create\n",
98+
"ontology_builder = OntologyBuilder(\n",
99+
" tools=[Tool(name=\"cat\", tool=Tool.Type.BBOX)])\n",
100+
"ontology = client.create_ontology(\"project-setup-demo-ontology\", ontology_builder.asdict())\n",
101+
"# Select existing ontology\n",
102+
"#ontology = client.get_ontology(\"<ontology_id>\")\n",
103+
"#ontology = existing_project.ontology()\n"
143104
]
144105
},
145106
{
146107
"cell_type": "markdown",
147108
"id": "limiting-bleeding",
148109
"metadata": {},
149110
"source": [
150-
"### Setup and attach dataset\n",
111+
"### Create Project and Setup the Editor\n",
151112
"* Setting up a project will add an ontology and will enable labeling to begin\n",
152113
"* Attaching dataset(s) will add all data_rows belonging to the dataset to the queue."
153114
]
154115
},
155116
{
156117
"cell_type": "code",
157-
"execution_count": 9,
118+
"execution_count": null,
158119
"id": "reserved-vietnam",
159120
"metadata": {},
160121
"outputs": [],
161122
"source": [
162-
"project.setup(editor, ontology_builder.asdict())\n",
163-
"# Could also do if ontology is a normalized ontology\n",
164-
"# project.setup(editor, ontology.normalized)"
165-
]
166-
},
167-
{
168-
"cell_type": "code",
169-
"execution_count": 10,
170-
"id": "unexpected-vegetarian",
171-
"metadata": {},
172-
"outputs": [],
173-
"source": [
174-
"# Run this for each dataset we want to attach\n",
175-
"project.datasets.connect(dataset)\n",
176-
"# project.datasets.connect(another_dataset)"
123+
"project = client.create_project(name=\"my_new_project\")\n",
124+
"project.setup_editor(ontology)\n",
125+
"project.datasets.connect(dataset)"
177126
]
178127
},
179128
{
@@ -186,41 +135,39 @@
186135
},
187136
{
188137
"cell_type": "code",
189-
"execution_count": 11,
138+
"execution_count": null,
190139
"id": "vanilla-diamond",
191140
"metadata": {},
192-
"outputs": [
193-
{
194-
"name": "stdout",
195-
"output_type": "stream",
196-
"text": [
197-
"2021-03-17 12:35:00+00:00\n",
198-
"<labelbox.orm.db_object.RelationshipManager object at 0x1046030d0>\n",
199-
"['my_new_dataset']\n"
200-
]
201-
}
202-
],
141+
"outputs": [],
203142
"source": [
204143
"# Note setup_complete will be None if it fails.\n",
205144
"print(project.setup_complete)\n",
206-
"print(project.ontology)\n",
145+
"print(project.ontology())\n",
207146
"print([ds.name for ds in project.datasets()])"
208147
]
209148
},
210149
{
211150
"cell_type": "code",
212-
"execution_count": 12,
151+
"execution_count": null,
213152
"id": "alpha-dayton",
214153
"metadata": {},
215154
"outputs": [],
216155
"source": [
217156
"print(f\"https://app.labelbox.com/projects/{project.uid}\")"
218157
]
158+
},
159+
{
160+
"cell_type": "code",
161+
"execution_count": null,
162+
"id": "dec2f4c9",
163+
"metadata": {},
164+
"outputs": [],
165+
"source": []
219166
}
220167
],
221168
"metadata": {
222169
"kernelspec": {
223-
"display_name": "Python 3",
170+
"display_name": "Python 3 (ipykernel)",
224171
"language": "python",
225172
"name": "python3"
226173
},
@@ -234,7 +181,7 @@
234181
"name": "python",
235182
"nbconvert_exporter": "python",
236183
"pygments_lexer": "ipython3",
237-
"version": "3.8.8"
184+
"version": "3.8.2"
238185
}
239186
},
240187
"nbformat": 4,

0 commit comments

Comments
 (0)