|
48 | 48 | { |
49 | 49 | "metadata": {}, |
50 | 50 | "source": [ |
51 | | - "!pip install labelbox -q\n", |
52 | | - "!pip install numpy" |
| 51 | + "%pip install -q \"labelbox[data]\"\n", |
| 52 | + "%pip install -q numpy" |
53 | 53 | ], |
54 | 54 | "cell_type": "code", |
55 | 55 | "outputs": [], |
|
105 | 105 | "source": [ |
106 | 106 | "# Create Labelbox project\n", |
107 | 107 | "\n", |
108 | | - "project = client.create_project(name=\"batch-test-project\",\n", |
109 | | - " description=\"a description\",\n", |
110 | | - " quality_mode=QualityMode.Benchmark, # For Consensus projects use quality_mode = QualityMode.Consensus\n", |
111 | | - " media_type=lb.MediaType.Image,\n", |
112 | | - " )\n", |
| 108 | + "project = client.create_project(\n", |
| 109 | + " name=\"batch-test-project\",\n", |
| 110 | + " description=\"a description\",\n", |
| 111 | + " quality_mode=QualityMode.\n", |
| 112 | + " Benchmark, # For Consensus projects use quality_mode = QualityMode.Consensus\n", |
| 113 | + " media_type=lb.MediaType.Image,\n", |
| 114 | + ")\n", |
113 | 115 | "\n", |
114 | 116 | "dataset = client.create_dataset(name=\"queue_dataset\")" |
115 | 117 | ], |
|
133 | 135 | " name=\"Quality Issues\",\n", |
134 | 136 | " options=[\n", |
135 | 137 | " lb.Option(value=\"blurry\", label=\"Blurry\"),\n", |
136 | | - " lb.Option(value=\"distorted\", label=\"Distorted\")\n", |
137 | | - " ]\n", |
| 138 | + " lb.Option(value=\"distorted\", label=\"Distorted\"),\n", |
| 139 | + " ],\n", |
138 | 140 | " )\n", |
139 | 141 | "]\n", |
140 | 142 | "\n", |
141 | 143 | "ontology_builder = lb.OntologyBuilder(\n", |
142 | | - " tools=[],\n", |
143 | | - " classifications=classification_features\n", |
| 144 | + " tools=[], classifications=classification_features\n", |
144 | 145 | ")\n", |
145 | 146 | "\n", |
146 | 147 | "ontology = client.create_ontology(\n", |
147 | | - " \"Ontology from new features\",\n", |
148 | | - " ontology_builder.asdict(),\n", |
149 | | - " media_type=lb.MediaType.Image\n", |
| 148 | + " \"Ontology from new features\",\n", |
| 149 | + " ontology_builder.asdict(),\n", |
| 150 | + " media_type=lb.MediaType.Image,\n", |
150 | 151 | ")\n", |
151 | 152 | "\n", |
152 | 153 | "project.setup_editor(ontology)" |
|
170 | 171 | "global_keys = []\n", |
171 | 172 | "# Generate data rows\n", |
172 | 173 | "for i in range(1, 5):\n", |
173 | | - " global_key = str(uuid4())\n", |
174 | | - " row = {\n", |
175 | | - " \"row_data\": f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n", |
176 | | - " \"global_key\": global_key\n", |
| 174 | + " global_key = str(uuid4())\n", |
| 175 | + " row = {\n", |
| 176 | + " \"row_data\":\n", |
| 177 | + " f\"https://storage.googleapis.com/labelbox-datasets/People_Clothing_Segmentation/jpeg_images/IMAGES/img_000{i}.jpeg\",\n", |
| 178 | + " \"global_key\":\n", |
| 179 | + " global_key,\n", |
177 | 180 | " }\n", |
178 | | - " global_keys.append(global_key)\n", |
179 | | - " uploads.append(row)\n", |
180 | | - "\n", |
| 181 | + " global_keys.append(global_key)\n", |
| 182 | + " uploads.append(row)\n", |
181 | 183 | "\n", |
182 | 184 | "data_rows = dataset.create_data_rows(uploads)\n", |
183 | 185 | "data_rows.wait_till_done()\n", |
184 | | - "print(\"Errors\" , data_rows.errors)\n", |
185 | | - "print(\"Dataset status: \", data_rows.status)\n" |
| 186 | + "print(\"Errors\", data_rows.errors)\n", |
| 187 | + "print(\"Dataset status: \", data_rows.status)" |
186 | 188 | ], |
187 | 189 | "cell_type": "code", |
188 | 190 | "outputs": [], |
|
203 | 205 | "# Create the batch\n", |
204 | 206 | "\n", |
205 | 207 | "batch = project.create_batch(\n", |
206 | | - " \"batch-demo\", # Each batch in a project must have a unique name\n", |
207 | | - " global_keys = global_keys[0:2], # A list of data rows, data row ids or global keys\n", |
208 | | - " priority=5 # priority between 1(Highest) - 5(lowest) 5 is the max priority that can be set\n", |
| 208 | + " \"batch-demo\", # Each batch in a project must have a unique name\n", |
| 209 | + " global_keys=global_keys[\n", |
| 210 | + " 0:2], # A list of data rows, data row ids or global keys\n", |
| 211 | + " priority=\n", |
| 212 | + " 5, # priority between 1(Highest) - 5(lowest) 5 is the max priority that can be set\n", |
209 | 213 | ")\n", |
210 | 214 | "\n", |
211 | 215 | "batch2 = project.create_batch(\n", |
212 | | - " \"batch-demo-2\", # Each batch in a project must have a unique name\n", |
213 | | - " #Provide a slice of the data since you can't import assets with global keys that already exist in the project.\n", |
214 | | - " global_keys=global_keys[2:4], # A list of data rows, data row ids or global keys\n", |
215 | | - " priority=1 # priority between 1(Highest) - 5(lowest) 5 is the max priority that can be set\n", |
| 216 | + " \"batch-demo-2\", # Each batch in a project must have a unique name\n", |
| 217 | + " # Provide a slice of the data since you can't import assets with global keys that already exist in the project.\n", |
| 218 | + " global_keys=global_keys[\n", |
| 219 | + " 2:4], # A list of data rows, data row ids or global keys\n", |
| 220 | + " priority=\n", |
| 221 | + " 1, # priority between 1(Highest) - 5(lowest) 5 is the max priority that can be set\n", |
216 | 222 | ")\n", |
217 | 223 | "\n", |
218 | | - "\n", |
219 | 224 | "print(\"Batch: \", batch)\n", |
220 | 225 | "print(\"Batch2: \", batch2)" |
221 | 226 | ], |
|
226 | 231 | { |
227 | 232 | "metadata": {}, |
228 | 233 | "source": [ |
229 | | - "print(\"View the results here:\",\n", |
230 | | - " f\"https://app.labelbox.com/projects/{project.uid}\")\n", |
| 234 | + "print(\n", |
| 235 | + " \"View the results here:\", f\"https://app.labelbox.com/projects/{project.uid}\"\n", |
| 236 | + ")\n", |
231 | 237 | "# Click `start labeling` to see the images in order" |
232 | 238 | ], |
233 | 239 | "cell_type": "code", |
|
246 | 252 | { |
247 | 253 | "metadata": {}, |
248 | 254 | "source": [ |
249 | | - "client.enable_experimental = True\n", |
250 | | - "\n", |
251 | 255 | "export_task = project.export()\n", |
252 | 256 | "export_task.wait_till_done()" |
253 | 257 | ], |
|
261 | 265 | "# Get data rows from project\n", |
262 | 266 | "data_rows = []\n", |
263 | 267 | "\n", |
| 268 | + "\n", |
264 | 269 | "def json_stream_handler(output: lb.JsonConverterOutput):\n", |
265 | | - " data_row = json.loads(output.json_str)\n", |
266 | | - " data_rows.append(lb.GlobalKey(data_row[\"data_row\"][\"global_key\"])) # Convert json data row into data row identifier object\n", |
| 270 | + " data_row = json.loads(output.json_str)\n", |
| 271 | + " data_rows.append(\n", |
| 272 | + " lb.GlobalKey(data_row[\"data_row\"][\"global_key\"])\n", |
| 273 | + " ) # Convert json data row into data row identifier object\n", |
267 | 274 | "\n", |
268 | 275 | "\n", |
269 | 276 | "if export_task.has_errors():\n", |
270 | | - " export_task.get_stream(\n", |
271 | | - "\n", |
272 | | - " converter=lb.JsonConverter(),\n", |
273 | | - " stream_type=lb.StreamType.ERRORS\n", |
274 | | - " ).start(stream_handler=lambda error: print(error))\n", |
| 277 | + " export_task.get_stream(\n", |
| 278 | + " converter=lb.JsonConverter(), stream_type=lb.StreamType.ERRORS\n", |
| 279 | + " ).start(stream_handler=lambda error: print(error))\n", |
275 | 280 | "\n", |
276 | 281 | "if export_task.has_result():\n", |
277 | | - " export_json = export_task.get_stream(\n", |
278 | | - " converter=lb.JsonConverter(),\n", |
279 | | - " stream_type=lb.StreamType.RESULT\n", |
280 | | - " ).start(stream_handler=json_stream_handler)" |
| 282 | + " export_json = export_task.get_stream(\n", |
| 283 | + " converter=lb.JsonConverter(), stream_type=lb.StreamType.RESULT\n", |
| 284 | + " ).start(stream_handler=json_stream_handler)" |
281 | 285 | ], |
282 | 286 | "cell_type": "code", |
283 | 287 | "outputs": [], |
|
290 | 294 | "project_lpos = project.labeling_parameter_overrides()\n", |
291 | 295 | "\n", |
292 | 296 | "for lpo in project_lpos:\n", |
293 | | - " print(lpo)\n", |
294 | | - " print(\"Data row:\", lpo.data_row().uid)" |
| 297 | + " print(lpo)\n", |
| 298 | + " print(\"Data row:\", lpo.data_row().uid)" |
295 | 299 | ], |
296 | 300 | "cell_type": "code", |
297 | 301 | "outputs": [], |
|
302 | 306 | "source": [ |
303 | 307 | "# Add LPOs\n", |
304 | 308 | "lpos = []\n", |
305 | | - "priority=1\n", |
| 309 | + "priority = 1\n", |
306 | 310 | "for data_row in data_rows:\n", |
307 | | - " lpos.append((data_row, priority, 1))\n", |
308 | | - " priority+=1\n", |
309 | | - "\n", |
| 311 | + " lpos.append((data_row, priority))\n", |
| 312 | + " priority += 1\n", |
310 | 313 | "\n", |
311 | 314 | "project.set_labeling_parameter_overrides(lpos)\n", |
312 | 315 | "\n", |
313 | 316 | "# Check results\n", |
314 | 317 | "project_lpos = list(project.labeling_parameter_overrides())\n", |
315 | 318 | "\n", |
316 | 319 | "for lpo in project_lpos:\n", |
317 | | - " print(lpo)" |
| 320 | + " print(lpo)" |
318 | 321 | ], |
319 | 322 | "cell_type": "code", |
320 | 323 | "outputs": [], |
|
328 | 331 | "for data_row in data_rows:\n", |
329 | 332 | " global_keys.append(data_row.key)\n", |
330 | 333 | "\n", |
331 | | - "project.update_data_row_labeling_priority(data_rows=lb.GlobalKeys(global_keys), priority=1)\n", |
| 334 | + "project.update_data_row_labeling_priority(\n", |
| 335 | + " data_rows=lb.GlobalKeys(global_keys), priority=1\n", |
| 336 | + ")\n", |
332 | 337 | "\n", |
333 | 338 | "# Check results\n", |
334 | 339 | "project_lpos = list(project.labeling_parameter_overrides())\n", |
335 | 340 | "\n", |
336 | 341 | "for lpo in project_lpos:\n", |
337 | | - " print(lpo)" |
| 342 | + " print(lpo)" |
338 | 343 | ], |
339 | 344 | "cell_type": "code", |
340 | 345 | "outputs": [], |
|
0 commit comments