Skip to content

Commit 622c0f5

Browse files
committed
typo
1 parent 1653e1e commit 622c0f5

File tree

1 file changed

+160
-59
lines changed

1 file changed

+160
-59
lines changed

examples/basics/quick_start.ipynb

Lines changed: 160 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
{
2-
"nbformat": 4,
3-
"nbformat_minor": 2,
4-
"metadata": {},
52
"cells": [
63
{
4+
"cell_type": "markdown",
75
"metadata": {},
86
"source": [
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>",
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",
119
"</td>\n"
12-
],
13-
"cell_type": "markdown"
10+
]
1411
},
1512
{
13+
"cell_type": "markdown",
1614
"metadata": {},
1715
"source": [
1816
"<td>\n",
@@ -24,10 +22,10 @@
2422
"<a href=\"https://github.com/Labelbox/labelbox-python/tree/develop/examples/basics/quick_start.ipynb\" target=\"_blank\"><img\n",
2523
"src=\"https://img.shields.io/badge/GitHub-100000?logo=github&logoColor=white\" alt=\"GitHub\"></a>\n",
2624
"</td>"
27-
],
28-
"cell_type": "markdown"
25+
]
2926
},
3027
{
28+
"cell_type": "markdown",
3129
"metadata": {},
3230
"source": [
3331
"# Quick Start\n",
@@ -42,49 +40,57 @@
4240
"4. Sending our data row to our project by creating a batch\n",
4341
"5. Exporting our image data row from our project\n",
4442
"\n",
45-
"This notebook is geared towards new users of our SDK."
46-
],
47-
"cell_type": "markdown"
43+
"This notebook is geared towards new users of Labelbox-Python SDK."
44+
]
4845
},
4946
{
47+
"cell_type": "markdown",
5048
"metadata": {},
5149
"source": [
5250
"## Setup\n",
5351
"\n",
54-
"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 universal unique IDs for the variety of objects that will be created with this notebook."
55-
],
56-
"cell_type": "markdown"
52+
"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 universal unique IDs for the variety of objects that will be created with this notebook."
53+
]
5754
},
5855
{
59-
"metadata": {},
60-
"source": "%pip install -q \"labelbox[data]\"",
6156
"cell_type": "code",
57+
"execution_count": null,
58+
"metadata": {},
6259
"outputs": [],
63-
"execution_count": null
60+
"source": [
61+
"%pip install -q \"labelbox[data]\""
62+
]
6463
},
6564
{
66-
"metadata": {},
67-
"source": "import labelbox as lb\nimport uuid",
6865
"cell_type": "code",
66+
"execution_count": null,
67+
"metadata": {},
6968
"outputs": [],
70-
"execution_count": null
69+
"source": [
70+
"import labelbox as lb\n",
71+
"import uuid"
72+
]
7173
},
7274
{
75+
"cell_type": "markdown",
7376
"metadata": {},
7477
"source": [
7578
"## API Key and Client\n",
7679
"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."
77-
],
78-
"cell_type": "markdown"
80+
]
7981
},
8082
{
81-
"metadata": {},
82-
"source": "API_KEY = None\nclient = lb.Client(api_key=API_KEY)",
8383
"cell_type": "code",
84+
"execution_count": null,
85+
"metadata": {},
8486
"outputs": [],
85-
"execution_count": null
87+
"source": [
88+
"API_KEY = None\n",
89+
"client = lb.Client(api_key=API_KEY)"
90+
]
8691
},
8792
{
93+
"cell_type": "markdown",
8894
"metadata": {},
8995
"source": [
9096
"## Step 1: Create Dataset and Import Data Row\n",
@@ -93,103 +99,198 @@
9399
"\n",
94100
"- Data rows are internal representations of an asset in Labelbox. A data row contains the asset to be labeled and all of the relevant information about that asset\n",
95101
"- A dataset is a collection of data rows imported into Labelbox. They live inside the [_Catalog_](https://docs.labelbox.com/docs/catalog-overview) section of Labelbox."
96-
],
97-
"cell_type": "markdown"
102+
]
98103
},
99104
{
100-
"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",
102105
"cell_type": "code",
106+
"execution_count": null,
107+
"metadata": {},
103108
"outputs": [],
104-
"execution_count": null
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+
]
105130
},
106131
{
132+
"cell_type": "markdown",
107133
"metadata": {},
108134
"source": [
109135
"## Step 2: Creating an Ontology\n",
110136
"\n",
111137
"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 checklist classification feature. For more information, visit the [ontology section](https://docs.labelbox.com/reference/ontology) inside our developer guides. \n",
112138
"\n",
113139
"* 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."
114-
],
115-
"cell_type": "markdown"
140+
]
116141
},
117142
{
118-
"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)",
120143
"cell_type": "code",
144+
"execution_count": null,
145+
"metadata": {},
121146
"outputs": [],
122-
"execution_count": null
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+
]
123180
},
124181
{
182+
"cell_type": "markdown",
125183
"metadata": {},
126184
"source": [
127185
"## Step 3: Creating a Project and Attaching our Ontology\n",
128186
"\n",
129187
"Now that we have made our ontology, we are ready to create a project where we can label our data row.\n",
130188
"\n",
131189
"* 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."
132-
],
133-
"cell_type": "markdown"
190+
]
134191
},
135192
{
136-
"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)",
138193
"cell_type": "code",
194+
"execution_count": null,
195+
"metadata": {},
139196
"outputs": [],
140-
"execution_count": null
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,\n",
202+
")\n",
203+
"\n",
204+
"# Attach created ontology\n",
205+
"project.setup_editor(ontology)"
206+
]
141207
},
142208
{
209+
"cell_type": "markdown",
143210
"metadata": {},
144211
"source": [
145212
"## Step 4: Sending our Data Row to our Project by Creating a Batch\n",
146213
"\n",
147214
"With our project created, we can send our data rows by creating a batch. Our data rows will start in the initial labeling queue, where labelers are able to annotate our data row.\n",
148215
"\n",
149216
"* A batch is a curated selection of data rows you can send to a project for labeling. You can create a batch with a combination of data rows within any dataset. For more information on creating batches, review the [batches section](https://docs.labelbox.com/reference/batch#create-a-batch) of our developer guides."
150-
],
151-
"cell_type": "markdown"
217+
]
152218
},
153219
{
154-
"metadata": {},
155-
"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)",
156220
"cell_type": "code",
221+
"execution_count": null,
222+
"metadata": {},
157223
"outputs": [],
158-
"execution_count": null
224+
"source": [
225+
"project.create_batch(\n",
226+
" name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n",
227+
" global_keys=[\n",
228+
" global_key\n",
229+
" ], # Global key we used earlier in this guide to create our dataset\n",
230+
" priority=5,\n",
231+
")"
232+
]
159233
},
160234
{
235+
"cell_type": "markdown",
161236
"metadata": {},
162237
"source": [
163238
"## Step 5: Exporting from our Project\n",
164239
"\n",
165-
"We have now successfully set up a project for labeling using only the SDK! \ud83d\ude80 \n",
240+
"We have now successfully set up a project for labeling using only the SDK! 🚀 \n",
166241
"\n",
167242
"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 [export overview](https://docs.labelbox.com/reference/label-export) developer guide."
168-
],
169-
"cell_type": "markdown"
243+
]
170244
},
171245
{
172-
"metadata": {},
173-
"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)",
174246
"cell_type": "code",
247+
"execution_count": null,
248+
"metadata": {},
175249
"outputs": [],
176-
"execution_count": null
250+
"source": [
251+
"# Start export from project\n",
252+
"export_task = project.export()\n",
253+
"export_task.wait_till_done()\n",
254+
"\n",
255+
"# Conditional if task has errors\n",
256+
"if export_task.has_errors():\n",
257+
" export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n",
258+
" stream_handler=lambda error: print(error))\n",
259+
"\n",
260+
"# Start export stream\n",
261+
"stream = export_task.get_buffered_stream()\n",
262+
"\n",
263+
"# Iterate through data rows\n",
264+
"for data_row in stream:\n",
265+
" print(data_row.json)"
266+
]
177267
},
178268
{
269+
"cell_type": "markdown",
179270
"metadata": {},
180271
"source": [
181272
"## Clean Up\n",
182273
"\n",
183274
"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."
184-
],
185-
"cell_type": "markdown"
275+
]
186276
},
187277
{
188-
"metadata": {},
189-
"source": "# project.delete()\n# client.delete_unused_ontology(ontology.uid)\n# dataset.delete()",
190278
"cell_type": "code",
279+
"execution_count": null,
280+
"metadata": {},
191281
"outputs": [],
192-
"execution_count": null
282+
"source": [
283+
"# project.delete()\n",
284+
"# client.delete_unused_ontology(ontology.uid)\n",
285+
"# dataset.delete()"
286+
]
193287
}
194-
]
195-
}
288+
],
289+
"metadata": {
290+
"language_info": {
291+
"name": "python"
292+
}
293+
},
294+
"nbformat": 4,
295+
"nbformat_minor": 2
296+
}

0 commit comments

Comments
 (0)