Skip to content

Commit d502d4a

Browse files
committed
finished quick start guide
1 parent 4c8a14f commit d502d4a

File tree

1 file changed

+197
-8
lines changed

1 file changed

+197
-8
lines changed

examples/basics/quick_start.ipynb

Lines changed: 197 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@
66
"source": [
77
"# Quick Start\n",
88
"\n",
9-
"This notebook is intended to be a quick overview on Labelbox-Python SDK by demonstrating a simple but common work flow\n",
9+
"This notebook is intended to be a quick overview on Labelbox-Python SDK by demonstrating a simple but common work flow.\n",
1010
"\n",
1111
"In this guide, we will be:\n",
1212
"\n",
13-
"1. Creating a dataset:\n",
14-
" A dataset is a collection of data rows imported into Labelbox.\n",
15-
"2. Importing an image data row\n",
16-
"3. Creating an ontology\n",
17-
"4. Creating an project and attaching an ontology\n",
18-
"5. Sending our data row towards are project by creating a batch\n",
19-
"6. Exporting from our project\n",
13+
"1. Creating a dataset and importing a image data row\n",
14+
"2. Creating a ontology\n",
15+
"3. Creating a project and attaching our ontology\n",
16+
"4. Sending our data row to our Project by creating a batch\n",
17+
"5. Exporting from our project\n",
2018
"\n",
2119
"This notebook is geared towards new users of our SDK."
2220
]
@@ -66,6 +64,197 @@
6664
"API_KEY = None\n",
6765
"client = lb.Client(api_key=API_KEY)"
6866
]
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"metadata": {},
71+
"source": [
72+
"## Step 1: Create Dataset and Import Data Row\n",
73+
"\n",
74+
"Below we will be creating a dataset and then attaching a publicly hosted image data row. Typically you would either import data rows that are hosted on a cloud provider (_recommended_) or import them locally. For more information, visit our [import image data section](https://docs.labelbox.com/reference/image) in our developer guides.\n",
75+
"\n",
76+
"* 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",
77+
"* 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."
78+
]
79+
},
80+
{
81+
"cell_type": "code",
82+
"execution_count": null,
83+
"metadata": {},
84+
"outputs": [],
85+
"source": [
86+
"# Create dataset from client\n",
87+
"dataset = client.create_dataset(name=\"Quick Start Example Dataset\")\n",
88+
"\n",
89+
"global_key = str(uuid.uuid4()) # Unique user specified ID\n",
90+
"\n",
91+
"# Data row structure\n",
92+
"image_data_rows = [\n",
93+
" {\n",
94+
" \"row_data\": \"https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg\",\n",
95+
" \"global_key\": global_key,\n",
96+
" \"media_type\": \"IMAGE\",\n",
97+
" }\n",
98+
"]\n",
99+
"\n",
100+
"# Bulk import data row\n",
101+
"task = dataset.create_data_rows(image_data_rows) # List of data rows\n",
102+
"task.wait_till_done()\n",
103+
"print(task.errors) # Print any errors"
104+
]
105+
},
106+
{
107+
"cell_type": "markdown",
108+
"metadata": {},
109+
"source": [
110+
"## Step 2: Creating an Ontology\n",
111+
"\n",
112+
"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",
113+
"\n",
114+
"* 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."
115+
]
116+
},
117+
{
118+
"cell_type": "code",
119+
"execution_count": null,
120+
"metadata": {},
121+
"outputs": [],
122+
"source": [
123+
"# Bounding box feature\n",
124+
"object_features = [\n",
125+
" lb.Tool(\n",
126+
" tool=lb.Tool.Type.BBOX,\n",
127+
" name=\"regulatory-sign\",\n",
128+
" color=\"#ff0000\",\n",
129+
" )\n",
130+
"]\n",
131+
"\n",
132+
"# Checklist feature\n",
133+
"classification_features = [\n",
134+
" lb.Classification(\n",
135+
" class_type=lb.Classification.Type.CHECKLIST,\n",
136+
" name=\"Quality Issues\",\n",
137+
" options=[\n",
138+
" lb.Option(value=\"blurry\", label=\"Blurry\"),\n",
139+
" lb.Option(value=\"distorted\", label=\"Distorted\")\n",
140+
" ]\n",
141+
" )\n",
142+
"\n",
143+
"]\n",
144+
"\n",
145+
"# Builder function\n",
146+
"ontology_builder = lb.OntologyBuilder(\n",
147+
" tools=object_features,\n",
148+
" classifications=classification_features\n",
149+
")\n",
150+
"\n",
151+
"# Create ontology\n",
152+
"ontology = client.create_ontology(\n",
153+
" \"Ontology from new features\",\n",
154+
" ontology_builder.asdict(),\n",
155+
" media_type=lb.MediaType.Image\n",
156+
")"
157+
]
158+
},
159+
{
160+
"cell_type": "markdown",
161+
"metadata": {},
162+
"source": [
163+
"## Step 3: Creating a Project and Attaching our Ontology\n",
164+
"\n",
165+
"Now that we have made our ontology we are ready to create a project were we can label our data row.\n",
166+
"\n",
167+
"* 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."
168+
]
169+
},
170+
{
171+
"cell_type": "code",
172+
"execution_count": null,
173+
"metadata": {},
174+
"outputs": [],
175+
"source": [
176+
"# Create a new project\n",
177+
"project = client.create_project(\n",
178+
" name=\"Quick Start Example Project\", \n",
179+
" media_type=lb.MediaType.Image # specify the media type\n",
180+
")\n",
181+
"\n",
182+
"# Attach created ontology\n",
183+
"project.setup_editor(ontology)"
184+
]
185+
},
186+
{
187+
"cell_type": "markdown",
188+
"metadata": {},
189+
"source": [
190+
"## Step 4: Sending our Data Row to our Project by Creating a Batch\n",
191+
"\n",
192+
"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."
193+
]
194+
},
195+
{
196+
"cell_type": "code",
197+
"execution_count": null,
198+
"metadata": {},
199+
"outputs": [],
200+
"source": [
201+
"project.create_batch(\n",
202+
" name=\"Quick Start Example Batch\" + str(uuid.uuid4()),\n",
203+
" global_keys=[global_key], # Global key we used earlier in this guide to create our dataset\n",
204+
" priority=5,\n",
205+
")"
206+
]
207+
},
208+
{
209+
"cell_type": "markdown",
210+
"metadata": {},
211+
"source": [
212+
"# Step 5: Exporting from our Project\n",
213+
"\n",
214+
"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. "
215+
]
216+
},
217+
{
218+
"cell_type": "code",
219+
"execution_count": null,
220+
"metadata": {},
221+
"outputs": [],
222+
"source": [
223+
"# Start export from project\n",
224+
"export_task = project.export()\n",
225+
"export_task.wait_till_done()\n",
226+
"\n",
227+
"# Conditional if task has errors\n",
228+
"if export_task.has_errors():\n",
229+
" export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(\n",
230+
" stream_handler=lambda error: print(error))\n",
231+
"\n",
232+
"# Start export stream\n",
233+
"stream = export_task.get_buffered_stream()\n",
234+
"\n",
235+
"# Iterate through data rows\n",
236+
"for data_row in stream:\n",
237+
" print(data_row.json)"
238+
]
239+
},
240+
{
241+
"cell_type": "markdown",
242+
"metadata": {},
243+
"source": [
244+
"## Clean up\n",
245+
"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."
246+
]
247+
},
248+
{
249+
"cell_type": "code",
250+
"execution_count": null,
251+
"metadata": {},
252+
"outputs": [],
253+
"source": [
254+
"# project.delete()\n",
255+
"# client.delete_unused_ontology(ontology.uid)\n",
256+
"# dataset.delete()"
257+
]
69258
}
70259
],
71260
"metadata": {

0 commit comments

Comments
 (0)