Skip to content

Commit 604e819

Browse files
🎨 Cleaned
1 parent 8829358 commit 604e819

File tree

1 file changed

+57
-158
lines changed

1 file changed

+57
-158
lines changed

examples/basics/quick_start.ipynb

Lines changed: 57 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
2+
"nbformat": 4,
3+
"nbformat_minor": 2,
4+
"metadata": {},
25
"cells": [
36
{
4-
"cell_type": "markdown",
57
"metadata": {},
68
"source": [
7-
"<td>\n",
8-
" <a target=\"_blank\" href=\"https://labelbox.com\" ><img src=\"https://labelbox.com/blog/content/images/2021/02/logo-v4.svg\" width=256/></a>\n",
9+
"<td>",
10+
" <a target=\"_blank\" href=\"https://labelbox.com\" ><img src=\"https://labelbox.com/blog/content/images/2021/02/logo-v4.svg\" width=256/></a>",
911
"</td>\n"
10-
]
12+
],
13+
"cell_type": "markdown"
1114
},
1215
{
13-
"cell_type": "markdown",
1416
"metadata": {},
1517
"source": [
1618
"<td>\n",
@@ -22,10 +24,10 @@
2224
"<a href=\"https://github.com/Labelbox/labelbox-python/tree/develop/examples/basics/quick_start.ipynb\" target=\"_blank\"><img\n",
2325
"src=\"https://img.shields.io/badge/GitHub-100000?logo=github&logoColor=white\" alt=\"GitHub\"></a>\n",
2426
"</td>"
25-
]
27+
],
28+
"cell_type": "markdown"
2629
},
2730
{
28-
"cell_type": "markdown",
2931
"metadata": {},
3032
"source": [
3133
"# Quick Start\n",
@@ -41,56 +43,48 @@
4143
"5. Exporting from our project\n",
4244
"\n",
4345
"This notebook is geared towards new users of our SDK."
44-
]
46+
],
47+
"cell_type": "markdown"
4548
},
4649
{
47-
"cell_type": "markdown",
4850
"metadata": {},
4951
"source": [
5052
"## Setup\n",
5153
"\n",
5254
"To start, we first need to install the labelbox library and then import the SDK module. It is recommended to install \"labelbox[data]\" over labelbox to obtain all the correct dependencies. We will also be importing the python UUID library to generate unique IDs for the variety of objects that will be created with this notebook."
53-
]
55+
],
56+
"cell_type": "markdown"
5457
},
5558
{
56-
"cell_type": "code",
57-
"execution_count": null,
5859
"metadata": {},
60+
"source": "%pip install -q \"labelbox[data]\"",
61+
"cell_type": "code",
5962
"outputs": [],
60-
"source": [
61-
"%pip install -q \"labelbox[data]\""
62-
]
63+
"execution_count": null
6364
},
6465
{
65-
"cell_type": "code",
66-
"execution_count": null,
6766
"metadata": {},
67+
"source": "import labelbox as lb\nimport uuid",
68+
"cell_type": "code",
6869
"outputs": [],
69-
"source": [
70-
"import labelbox as lb\n",
71-
"import uuid"
72-
]
70+
"execution_count": null
7371
},
7472
{
75-
"cell_type": "markdown",
7673
"metadata": {},
7774
"source": [
7875
"## API Key and Client\n",
7976
"Provide a valid API key below to connect to the Labelbox client properly. For more information, please review the [Create API Key](https://docs.labelbox.com/reference/create-api-key) guide."
80-
]
77+
],
78+
"cell_type": "markdown"
8179
},
8280
{
83-
"cell_type": "code",
84-
"execution_count": null,
8581
"metadata": {},
82+
"source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)",
83+
"cell_type": "code",
8684
"outputs": [],
87-
"source": [
88-
"API_KEY = None\n",
89-
"client = lb.Client(api_key=API_KEY)"
90-
]
85+
"execution_count": null
9186
},
9287
{
93-
"cell_type": "markdown",
9488
"metadata": {},
9589
"source": [
9690
"## Step 1: Create Dataset and Import Data Row\n",
@@ -99,193 +93,98 @@
9993
"\n",
10094
"* Data rows are internal representation of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n",
10195
"* A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catelog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox."
102-
]
96+
],
97+
"cell_type": "markdown"
10398
},
10499
{
105-
"cell_type": "code",
106-
"execution_count": null,
107100
"metadata": {},
101+
"source": "# Create dataset from client\ndataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n\nglobal_key = str(uuid.uuid4()) # Unique user specified ID\n\n# Data row structure\nimage_data_rows = [{\n \"row_data\":\n \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n \"global_key\":\n global_key,\n \"media_type\":\n \"IMAGE\",\n}]\n\n# Bulk import data row\ntask = dataset.create_data_rows(image_data_rows) # List of data rows\ntask.wait_till_done()\nprint(task.errors) # Print any errors",
102+
"cell_type": "code",
108103
"outputs": [],
109-
"source": [
110-
"# Create dataset from client\n",
111-
"dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n",
112-
"\n",
113-
"global_key = str(uuid.uuid4()) # Unique user specified ID\n",
114-
"\n",
115-
"# Data row structure\n",
116-
"image_data_rows = [{\n",
117-
" \"row_data\":\n",
118-
" \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n",
119-
" \"global_key\":\n",
120-
" global_key,\n",
121-
" \"media_type\":\n",
122-
" \"IMAGE\",\n",
123-
"}]\n",
124-
"\n",
125-
"# Bulk import data row\n",
126-
"task = dataset.create_data_rows(image_data_rows) # List of data rows\n",
127-
"task.wait_till_done()\n",
128-
"print(task.errors) # Print any errors"
129-
]
104+
"execution_count": null
130105
},
131106
{
132-
"cell_type": "markdown",
133107
"metadata": {},
134108
"source": [
135109
"## Step 2: Creating an Ontology\n",
136110
"\n",
137111
"Before we send our data row to a labeling project we first must create an ontology. In the example below we will be creating a simple ontology with a bounding box tool and a check list classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n",
138112
"\n",
139113
"* An ontology is a collection of annotations and their relationships (also known as a taxonomy). Ontologies can be reused across different projects. It is essential for data labeling, model training, and evaluation. Created ontologies with there associated features are located inside the _Schema_ section within Labelbox."
140-
]
114+
],
115+
"cell_type": "markdown"
141116
},
142117
{
143-
"cell_type": "code",
144-
"execution_count": null,
145118
"metadata": {},
119+
"source": "# Bounding box feature\nobject_features = [\n lb.Tool(\n tool=lb.Tool.Type.BBOX,\n name=\"regulatory-sign\",\n color=\"#ff0000\",\n )\n]\n\n# Checklist feature\nclassification_features = [\n lb.Classification(\n class_type=lb.Classification.Type.CHECKLIST,\n name=\"Quality Issues\",\n options=[\n lb.Option(value=\"blurry\", label=\"Blurry\"),\n lb.Option(value=\"distorted\", label=\"Distorted\"),\n ],\n )\n]\n\n# Builder function\nontology_builder = lb.OntologyBuilder(tools=object_features,\n classifications=classification_features)\n\n# Create ontology\nontology = client.create_ontology(\n \"Ontology from new features\",\n ontology_builder.asdict(),\n media_type=lb.MediaType.Image,\n)",
120+
"cell_type": "code",
146121
"outputs": [],
147-
"source": [
148-
"# Bounding box feature\n",
149-
"object_features = [\n",
150-
" lb.Tool(\n",
151-
" tool=lb.Tool.Type.BBOX,\n",
152-
" name=\"regulatory-sign\",\n",
153-
" color=\"#ff0000\",\n",
154-
" )\n",
155-
"]\n",
156-
"\n",
157-
"# Checklist feature\n",
158-
"classification_features = [\n",
159-
" lb.Classification(\n",
160-
" class_type=lb.Classification.Type.CHECKLIST,\n",
161-
" name=\"Quality Issues\",\n",
162-
" options=[\n",
163-
" lb.Option(value=\"blurry\", label=\"Blurry\"),\n",
164-
" lb.Option(value=\"distorted\", label=\"Distorted\"),\n",
165-
" ],\n",
166-
" )\n",
167-
"]\n",
168-
"\n",
169-
"# Builder function\n",
170-
"ontology_builder = lb.OntologyBuilder(tools=object_features,\n",
171-
" classifications=classification_features)\n",
172-
"\n",
173-
"# Create ontology\n",
174-
"ontology = client.create_ontology(\n",
175-
" \"Ontology from new features\",\n",
176-
" ontology_builder.asdict(),\n",
177-
" media_type=lb.MediaType.Image,\n",
178-
")"
179-
]
122+
"execution_count": null
180123
},
181124
{
182-
"cell_type": "markdown",
183125
"metadata": {},
184126
"source": [
185127
"## Step 3: Creating a Project and Attaching our Ontology\n",
186128
"\n",
187129
"Now that we have made our ontology we are ready to create a project were we can label our data row.\n",
188130
"\n",
189131
"* Projects are labeling environments in Labelbox similar to a factory assembly line for producing annotations. The initial state of the project can start with raw data, pre-existing ground truth, or pre-labeled data."
190-
]
132+
],
133+
"cell_type": "markdown"
191134
},
192135
{
193-
"cell_type": "code",
194-
"execution_count": null,
195136
"metadata": {},
137+
"source": "# Create a new project\nproject = client.create_project(\n name=\"Quick Start Example Project\",\n media_type=lb.MediaType.Image, # specify the media type\n)\n\n# Attach created ontology\nproject.setup_editor(ontology)",
138+
"cell_type": "code",
196139
"outputs": [],
197-
"source": [
198-
"# Create a new project\n",
199-
"project = client.create_project(\n",
200-
" name=\"Quick Start Example Project\",\n",
201-
" media_type=lb.MediaType.Image, # specify the media type\n",
202-
")\n",
203-
"\n",
204-
"# Attach created ontology\n",
205-
"project.setup_editor(ontology)"
206-
]
140+
"execution_count": null
207141
},
208142
{
209-
"cell_type": "markdown",
210143
"metadata": {},
211144
"source": [
212145
"## Step 4: Sending our Data Row to our Project by Creating a Batch\n",
213146
"\n",
214147
"With our project created we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue were labelers are able to annotate our data row. For more information on batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides."
215-
]
148+
],
149+
"cell_type": "markdown"
216150
},
217151
{
218-
"cell_type": "code",
219-
"execution_count": null,
220152
"metadata": {},
153+
"source": "project.create_batch(\n name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n global_keys=[\n global_key\n ], # Global key we used earlier in this guide to create our dataset\n priority=5,\n)",
154+
"cell_type": "code",
221155
"outputs": [],
222-
"source": [
223-
"project.create_batch(\n",
224-
" name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n",
225-
" global_keys=[\n",
226-
" global_key\n",
227-
" ], # Global key we used earlier in this guide to create our dataset\n",
228-
" priority=5,\n",
229-
")"
230-
]
156+
"execution_count": null
231157
},
232158
{
233-
"cell_type": "markdown",
234159
"metadata": {},
235160
"source": [
236161
"# Step 5: Exporting from our Project\n",
237162
"\n",
238-
"We have now successfully set up a project for labeling using only the SDK! 🚀 From here you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide no labels will be presented on our data row. For a full overview of exporting visit our our [export overview](https://docs.labelbox.com/reference/label-export) developer guide. "
239-
]
163+
"We have now successfully set up a project for labeling using only the SDK! \ud83d\ude80 From here you can either label our data row directly inside the [labeling queue](https://docs.labelbox.com/docs/labeling-queue) or [import annotations](https://docs.labelbox.com/reference/import-image-annotations) directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide no labels will be presented on our data row. For a full overview of exporting visit our our [export overview](https://docs.labelbox.com/reference/label-export) developer guide. "
164+
],
165+
"cell_type": "markdown"
240166
},
241167
{
242-
"cell_type": "code",
243-
"execution_count": null,
244168
"metadata": {},
169+
"source": "# Start export from project\nexport_task = project.export()\nexport_task.wait_till_done()\n\n# Conditional if task has errors\nif export_task.has_errors():\n export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n stream_handler=lambda error: print(error))\n\n# Start export stream\nstream = export_task.get_buffered_stream()\n\n# Iterate through data rows\nfor data_row in stream:\n print(data_row.json)",
170+
"cell_type": "code",
245171
"outputs": [],
246-
"source": [
247-
"# Start export from project\n",
248-
"export_task = project.export()\n",
249-
"export_task.wait_till_done()\n",
250-
"\n",
251-
"# Conditional if task has errors\n",
252-
"if export_task.has_errors():\n",
253-
" export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n",
254-
" stream_handler=lambda error: print(error))\n",
255-
"\n",
256-
"# Start export stream\n",
257-
"stream = export_task.get_buffered_stream()\n",
258-
"\n",
259-
"# Iterate through data rows\n",
260-
"for data_row in stream:\n",
261-
" print(data_row.json)"
262-
]
172+
"execution_count": null
263173
},
264174
{
265-
"cell_type": "markdown",
266175
"metadata": {},
267176
"source": [
268177
"## Clean up\n",
269178
"This section serves as an optional clean up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown."
270-
]
179+
],
180+
"cell_type": "markdown"
271181
},
272182
{
273-
"cell_type": "code",
274-
"execution_count": null,
275183
"metadata": {},
184+
"source": "# project.delete()\n# client.delete_unused_ontology(ontology.uid)\n# dataset.delete()",
185+
"cell_type": "code",
276186
"outputs": [],
277-
"source": [
278-
"# project.delete()\n",
279-
"# client.delete_unused_ontology(ontology.uid)\n",
280-
"# dataset.delete()"
281-
]
187+
"execution_count": null
282188
}
283-
],
284-
"metadata": {
285-
"language_info": {
286-
"name": "python"
287-
}
288-
},
289-
"nbformat": 4,
290-
"nbformat_minor": 2
291-
}
189+
]
190+
}

0 commit comments

Comments
 (0)