|
48 | 48 | { |
49 | 49 | "metadata": {}, |
50 | 50 | "source": [ |
51 | | - "!pip install labelbox -q" |
| 51 | + "!pip install -q \"labelbox[data]\"" |
52 | 52 | ], |
53 | 53 | "cell_type": "code", |
54 | 54 | "outputs": [], |
|
58 | 58 | "metadata": {}, |
59 | 59 | "source": [ |
60 | 60 | "import labelbox as lb\n", |
61 | | - "import os\n", |
| 61 | + "import labelbox.types as lb_types\n", |
62 | 62 | "import uuid" |
63 | 63 | ], |
64 | 64 | "cell_type": "code", |
|
76 | 76 | { |
77 | 77 | "metadata": {}, |
78 | 78 | "source": [ |
79 | | - "# Add your api key\n", |
| 79 | + "# Add your API key\n", |
80 | 80 | "API_KEY = \"\"\n", |
| 81 | + "# To get your API key go to: Workspace settings -> API -> Create API Key\n", |
81 | 82 | "client = lb.Client(api_key=API_KEY)" |
82 | 83 | ], |
83 | 84 | "cell_type": "code", |
|
154 | 155 | "outputs": [], |
155 | 156 | "execution_count": null |
156 | 157 | }, |
| 158 | + { |
| 159 | + "metadata": {}, |
| 160 | + "source": [ |
| 161 | + "### Attach ontology and label data rows\n", |
| 162 | + "\n", |
| 163 | + "In this section, we are creating an ontology to attach to a project and creating labels to import as ground truths. We need this setup to demonstrate other methods later in the demo. For more information, please reference our [Ontology](https://docs.labelbox.com/reference/ontology) and [Import Image Annotation](https://docs.labelbox.com/reference/import-image-annotations) development guides." |
| 164 | + ], |
| 165 | + "cell_type": "markdown" |
| 166 | + }, |
| 167 | + { |
| 168 | + "metadata": {}, |
| 169 | + "source": [ |
| 170 | + "Create your ontology" |
| 171 | + ], |
| 172 | + "cell_type": "markdown" |
| 173 | + }, |
| 174 | + { |
| 175 | + "metadata": {}, |
| 176 | + "source": [ |
| 177 | + "# Create normalized json with a radio classification\n", |
| 178 | + "ontology_builder = lb.OntologyBuilder(classifications=[ # List of Classification objects\n", |
| 179 | + " lb.Classification(class_type=lb.Classification.Type.RADIO,\n", |
| 180 | + " name=\"radio_question\",\n", |
| 181 | + " options=[\n", |
| 182 | + " lb.Option(value=\"first_radio_answer\"),\n", |
| 183 | + " lb.Option(value=\"second_radio_answer\")\n", |
| 184 | + " ]),\n", |
| 185 | + "])\n", |
| 186 | + "# Creating an ontology\n", |
| 187 | + "ontology = client.create_ontology(\"test-ontology\",\n", |
| 188 | + " ontology_builder.asdict())" |
| 189 | + ], |
| 190 | + "cell_type": "code", |
| 191 | + "outputs": [], |
| 192 | + "execution_count": null |
| 193 | + }, |
| 194 | + { |
| 195 | + "metadata": {}, |
| 196 | + "source": [ |
| 197 | + "Attach ontology to project" |
| 198 | + ], |
| 199 | + "cell_type": "markdown" |
| 200 | + }, |
| 201 | + { |
| 202 | + "metadata": {}, |
| 203 | + "source": [ |
| 204 | + "\n", |
| 205 | + "project.setup_editor(ontology)" |
| 206 | + ], |
| 207 | + "cell_type": "code", |
| 208 | + "outputs": [], |
| 209 | + "execution_count": null |
| 210 | + }, |
| 211 | + { |
| 212 | + "metadata": {}, |
| 213 | + "source": [ |
| 214 | + "Create labels and upload them to project as ground truths" |
| 215 | + ], |
| 216 | + "cell_type": "markdown" |
| 217 | + }, |
| 218 | + { |
| 219 | + "metadata": {}, |
| 220 | + "source": [ |
| 221 | + "# Create labels\n", |
| 222 | + "labels = []\n", |
| 223 | + "for global_key in global_keys:\n", |
| 224 | + " labels.append(lb_types.Label(data=lb_types.ImageData(global_key=global_key),\n", |
| 225 | + " annotations=[\n", |
| 226 | + " # Create radio classification annotation for labels\n", |
| 227 | + " lb_types.ClassificationAnnotation(\n", |
| 228 | + " name=\"radio_question\",\n", |
| 229 | + " value=lb_types.Radio(answer=lb_types.ClassificationAnswer(\n", |
| 230 | + " name=\"second_radio_answer\")))\n", |
| 231 | + " ]))\n", |
| 232 | + "\n", |
| 233 | + "# Upload labels for the data rows in project\n", |
| 234 | + "upload_job = lb.LabelImport.create_from_objects(\n", |
| 235 | + " client = client,\n", |
| 236 | + " project_id = project.uid,\n", |
| 237 | + " name=\"label_import_job\"+str(uuid.uuid4()),\n", |
| 238 | + " labels=labels)\n", |
| 239 | + "\n", |
| 240 | + "upload_job.wait_until_done()\n", |
| 241 | + "\n", |
| 242 | + "print(f\"Errors: {upload_job.errors}\")" |
| 243 | + ], |
| 244 | + "cell_type": "code", |
| 245 | + "outputs": [], |
| 246 | + "execution_count": null |
| 247 | + }, |
| 248 | + { |
| 249 | + "metadata": {}, |
| 250 | + "source": [ |
| 251 | + "### Move data rows in project to different task queues" |
| 252 | + ], |
| 253 | + "cell_type": "markdown" |
| 254 | + }, |
| 255 | + { |
| 256 | + "metadata": {}, |
| 257 | + "source": [ |
| 258 | + "# Get list of task queues for project\n", |
| 259 | + "task_queues = project.task_queues()\n", |
| 260 | + "\n", |
| 261 | + "for task_queue in task_queues:\n", |
| 262 | + " print(task_queue)" |
| 263 | + ], |
| 264 | + "cell_type": "code", |
| 265 | + "outputs": [], |
| 266 | + "execution_count": null |
| 267 | + }, |
| 268 | + { |
| 269 | + "metadata": {}, |
| 270 | + "source": [ |
| 271 | + "project.move_data_rows_to_task_queue(data_row_ids=lb.GlobalKeys(global_keys), #Provide a list of global keys\n", |
| 272 | + " task_queue_id=task_queues[2].uid #Passing None moves data rows to \"Done\" task queue\n", |
| 273 | + ")" |
| 274 | + ], |
| 275 | + "cell_type": "code", |
| 276 | + "outputs": [], |
| 277 | + "execution_count": null |
| 278 | + }, |
157 | 279 | { |
158 | 280 | "metadata": {}, |
159 | 281 | "source": [ |
|
180 | 302 | { |
181 | 303 | "metadata": {}, |
182 | 304 | "source": [ |
183 | | - "### Delete" |
| 305 | + "### Clean Up" |
184 | 306 | ], |
185 | 307 | "cell_type": "markdown" |
186 | 308 | }, |
187 | 309 | { |
188 | 310 | "metadata": {}, |
189 | 311 | "source": [ |
190 | | - "# project.delete()" |
| 312 | + "# project.delete()\n", |
| 313 | + "# dataset.delete()\n", |
| 314 | + "# client.delete_unused_ontology(ontology.uid)" |
191 | 315 | ], |
192 | 316 | "cell_type": "code", |
193 | 317 | "outputs": [], |
|
0 commit comments