Skip to content

Commit fcc9fd0

Browse files
author
Matt Sokoloff
committed
basics
1 parent eded4ee commit fcc9fd0

File tree

6 files changed

+1065
-0
lines changed

6 files changed

+1065
-0
lines changed

examples/basics/Ontology.ipynb

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "exposed-bullet",
6+
"metadata": {},
7+
"source": [
8+
"# Ontology\n",
9+
"\n",
10+
"* An ontology defines the types of vector tools and classifications available for a project\n",
11+
"* Currently the only way to create an ontology object is by setting up a project with one.\n",
12+
"* Project setup is going to be explained in another section. \n",
13+
"* This notebook will cover client side tools for working with ontologies\n",
14+
"-----\n",
15+
"Set the following variable to run this notebook"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": 1,
21+
"id": "treated-convenience",
22+
"metadata": {},
23+
"outputs": [],
24+
"source": [
25+
"#Make sure this project has been fully setup\n",
26+
"PROJECT_ID = \"ckm4xyfncfgja0760vpfdxoro\""
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": 2,
32+
"id": "prescription-harbor",
33+
"metadata": {},
34+
"outputs": [
35+
{
36+
"ename": "ImportError",
37+
"evalue": "cannot import name 'OntologyBuilder' from 'labelbox.schema.ontology' (/Users/matthewsokoloff/Library/Python/3.8/lib/python/site-packages/labelbox/schema/ontology.py)",
38+
"output_type": "error",
39+
"traceback": [
40+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
41+
"\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)",
42+
"\u001b[0;32m<ipython-input-2-128ad64f9bcd>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mlabelbox\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mschema\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0montology\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mOntologyBuilder\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mTool\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mClassification\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mlabelbox\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mproject\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
43+
"\u001b[0;31mImportError\u001b[0m: cannot import name 'OntologyBuilder' from 'labelbox.schema.ontology' (/Users/matthewsokoloff/Library/Python/3.8/lib/python/site-packages/labelbox/schema/ontology.py)"
44+
]
45+
}
46+
],
47+
"source": [
48+
"from labelbox.schema.ontology import OntologyBuilder, Tool, Classification\n",
49+
"from labelbox import project"
50+
]
51+
},
52+
{
53+
"cell_type": "markdown",
54+
"id": "sophisticated-sunglasses",
55+
"metadata": {},
56+
"source": [
57+
"#### Create"
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": 3,
63+
"id": "recent-composer",
64+
"metadata": {},
65+
"outputs": [
66+
{
67+
"data": {
68+
"text/plain": [
69+
"'2.4.10'"
70+
]
71+
},
72+
"execution_count": 3,
73+
"metadata": {},
74+
"output_type": "execute_result"
75+
}
76+
],
77+
"source": [
78+
"pip3 install "
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": null,
84+
"id": "published-maintenance",
85+
"metadata": {},
86+
"outputs": [],
87+
"source": []
88+
}
89+
],
90+
"metadata": {
91+
"kernelspec": {
92+
"display_name": "Python 3",
93+
"language": "python",
94+
"name": "python3"
95+
},
96+
"language_info": {
97+
"codemirror_mode": {
98+
"name": "ipython",
99+
"version": 3
100+
},
101+
"file_extension": ".py",
102+
"mimetype": "text/x-python",
103+
"name": "python",
104+
"nbconvert_exporter": "python",
105+
"pygments_lexer": "ipython3",
106+
"version": "3.8.2"
107+
}
108+
},
109+
"nbformat": 4,
110+
"nbformat_minor": 5
111+
}

examples/basics/README.MD

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
* Basic tutorial to show usage of all functionality.
2+
3+
* To see how each of the pieces works together look at the example workflows under the examples directory
4+
5+
6+
* Order to go through this:
7+
8+
1. Basics
9+
2. Datarows
10+
- other concepts: Metadata
11+
3. Datasets
12+
- Other concepts: Tasks
13+
4. Ontology
14+
5. Labeling Front End
15+
6. Projects

examples/basics/basics.ipynb

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "complimentary-passing",
6+
"metadata": {},
7+
"source": [
8+
"# Basics"
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"id": "smaller-syndication",
14+
"metadata": {},
15+
"source": [
16+
"#### Quick install instructions\n",
17+
"The quick version is basically just\n",
18+
"1. `!pip install labelbox`\n",
19+
"2. `export LABELBOX_API_KEY=\"<your_api_key>\"`\n",
20+
"* Get this from the UI under (Account -> API -> Create API Key)\n",
21+
"\n",
22+
"\n",
23+
"This only works for cloud deployments.\n",
24+
"* For more details : https://docs.labelbox.com/python-sdk/en/index-en#labelbox-python-sdk"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": 1,
30+
"id": "everyday-street",
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"from labelbox import Client\n",
35+
"from labelbox import Project, Dataset"
36+
]
37+
},
38+
{
39+
"cell_type": "markdown",
40+
"id": "committed-matthew",
41+
"metadata": {},
42+
"source": [
43+
"### Main takeaways:\n",
44+
"* All interactions with labelbox happen through the client\n",
45+
"* all attributes that are labelbox.orm.Fields can be accessed via object.field_name\n",
46+
"* all attributes that are labelbox.orm.Relationships can be accessed via object.relationship()\n",
47+
"----\n",
48+
"* To use on your own data you need to plug in the following:\n",
49+
"1. Project and Dataset ids (go to the web ui and you can find these in the url)\n",
50+
" * (https://app.labelbox.com/projects/<project_id>\n",
51+
" * https://app.labelbox.com/dataset/<dataset_id>\n",
52+
"2. A project name and a dataset name\n",
53+
" * Select any project names from here: https://app.labelbox.com/projects\n",
54+
" * Select any dataset names from here: https://app.labelbox.com/data"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": 9,
60+
"id": "instructional-reply",
61+
"metadata": {},
62+
"outputs": [],
63+
"source": [
64+
"PROJECT_ID = \"ckk4q1viuc0w20704eh69u28h\"\n",
65+
"DATASET_ID = \"ckk4q1vjznyhu087203wlghfr\"\n",
66+
"PROJECT_NAME = \"Sample Project\"\n",
67+
"DATASET_NAME = \"Example Jellyfish Dataset\""
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": 10,
73+
"id": "thick-gasoline",
74+
"metadata": {},
75+
"outputs": [],
76+
"source": [
77+
"#Client is used for all DB interactions.\n",
78+
"#This is usually the starting point for all usage.\n",
79+
"client = Client()"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": 11,
85+
"id": "victorian-consumer",
86+
"metadata": {},
87+
"outputs": [],
88+
"source": [
89+
"#Client can be used to fetch by id:\n",
90+
"project = client.get_project(PROJECT_ID)\n",
91+
"dataset = client.get_dataset(DATASET_ID)"
92+
]
93+
},
94+
{
95+
"cell_type": "code",
96+
"execution_count": 12,
97+
"id": "industrial-onion",
98+
"metadata": {},
99+
"outputs": [
100+
{
101+
"data": {
102+
"text/plain": [
103+
"<Project ID: ckk4q1viuc0w20704eh69u28h>"
104+
]
105+
},
106+
"execution_count": 12,
107+
"metadata": {},
108+
"output_type": "execute_result"
109+
}
110+
],
111+
"source": [
112+
"project"
113+
]
114+
},
115+
{
116+
"cell_type": "code",
117+
"execution_count": null,
118+
"id": "superb-revolution",
119+
"metadata": {},
120+
"outputs": [],
121+
"source": []
122+
},
123+
{
124+
"cell_type": "code",
125+
"execution_count": 13,
126+
"id": "cubic-joint",
127+
"metadata": {},
128+
"outputs": [
129+
{
130+
"data": {
131+
"text/plain": [
132+
"<labelbox.pagination.PaginatedCollection at 0x10caa6160>"
133+
]
134+
},
135+
"execution_count": 13,
136+
"metadata": {},
137+
"output_type": "execute_result"
138+
}
139+
],
140+
"source": [
141+
"#Or you can fetch all based on a condition\n",
142+
"projects = client.get_projects(where = Project.name == PROJECT_NAME)\n",
143+
"datasets = client.get_datasets(where = Dataset.name == DATASET_NAME)\n",
144+
"projects"
145+
]
146+
},
147+
{
148+
"cell_type": "code",
149+
"execution_count": 14,
150+
"id": "adapted-parish",
151+
"metadata": {},
152+
"outputs": [
153+
{
154+
"data": {
155+
"text/plain": [
156+
"<Project ID: ckk4q1viuc0w20704eh69u28h>"
157+
]
158+
},
159+
"execution_count": 14,
160+
"metadata": {},
161+
"output_type": "execute_result"
162+
}
163+
],
164+
"source": [
165+
"#The above two queries return PaginatedCollections because the filter parameters aren't guarenteed to be unique.\n",
166+
"#This object is an iterable containing the query results\n",
167+
"next(projects)"
168+
]
169+
},
170+
{
171+
"cell_type": "code",
172+
"execution_count": 15,
173+
"id": "future-bargain",
174+
"metadata": {},
175+
"outputs": [
176+
{
177+
"data": {
178+
"text/plain": [
179+
"[<Dataset ID: cklv1qzlv1oqn0y9ne7b9gtpb>]"
180+
]
181+
},
182+
"execution_count": 15,
183+
"metadata": {},
184+
"output_type": "execute_result"
185+
}
186+
],
187+
"source": [
188+
"# If you are interested in the relationship between objects then \n",
189+
"#You can only filter on attributes of either a dataset or a project.\n",
190+
"#If you want all datasets that belongs to a particular project then you can do that with the following query.\n",
191+
"sample_project_datasets = project.datasets()\n",
192+
"list(sample_project_datasets)"
193+
]
194+
},
195+
{
196+
"cell_type": "code",
197+
"execution_count": null,
198+
"id": "bacterial-yield",
199+
"metadata": {},
200+
"outputs": [],
201+
"source": []
202+
}
203+
],
204+
"metadata": {
205+
"kernelspec": {
206+
"display_name": "Python 3",
207+
"language": "python",
208+
"name": "python3"
209+
},
210+
"language_info": {
211+
"codemirror_mode": {
212+
"name": "ipython",
213+
"version": 3
214+
},
215+
"file_extension": ".py",
216+
"mimetype": "text/x-python",
217+
"name": "python",
218+
"nbconvert_exporter": "python",
219+
"pygments_lexer": "ipython3",
220+
"version": "3.8.2"
221+
}
222+
},
223+
"nbformat": 4,
224+
"nbformat_minor": 5
225+
}

0 commit comments

Comments
 (0)