|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "markdown", |
5 | | - "id": "acute-fluid", |
| 5 | + "id": "afraid-timing", |
6 | 6 | "metadata": { |
7 | 7 | "id": "EyNkbpW7ouEf" |
8 | 8 | }, |
9 | 9 | "source": [ |
10 | 10 | " \n", |
11 | 11 | "<td>\n", |
12 | | - " <a target=\"_blank\" href=\"https://labelbox.com\" ><img src=\"https://labelbox.com/blog/content/images/2021/02/logo-v4.svg\" width=256/>\n", |
13 | | - "</td>\n", |
14 | | - "\n", |
| 12 | + " <a target=\"_blank\" href=\"https://labelbox.com\" ><img src=\"https://labelbox.com/blog/content/images/2021/02/logo-v4.svg\" width=256/></a>\n", |
| 13 | + "</td>" |
| 14 | + ] |
| 15 | + }, |
| 16 | + { |
| 17 | + "cell_type": "markdown", |
| 18 | + "id": "foster-injection", |
| 19 | + "metadata": {}, |
| 20 | + "source": [ |
15 | 21 | "----\n", |
16 | 22 | "\n", |
17 | 23 | "# Model Diagnostics\n", |
|
34 | 40 | "## Steps\n", |
35 | 41 | "\n", |
36 | 42 | "1. Have a set of ground truth labels in a project\n", |
37 | | - "2. Install beta release of the SDK (SDK versions that are compatible with Model Diagnostics will have a \"b\" in the version name. The first SDK release to support this is 2.5b0.)\n", |
| 43 | + "2. Install the latest SDK release (At this time that is 3.0.0rc0)\n", |
38 | 44 | "3. Create a `Model`\n", |
39 | 45 | "4. Create a `Model Run`\n", |
40 | 46 | "5. Compute predictions\n", |
|
67 | 73 | }, |
68 | 74 | "outputs": [], |
69 | 75 | "source": [ |
70 | | - "!pip3 install \"labelbox[data]==3.0.0rc0\" \\\n", |
71 | | - " tensorflow" |
| 76 | + "!pip install \"labelbox[data]==3.0.0rc1\" \\\n", |
| 77 | + " scikit-image \\\n", |
| 78 | + " tensorflow" |
72 | 79 | ] |
73 | 80 | }, |
74 | 81 | { |
|
85 | 92 | "\n", |
86 | 93 | "if COLAB:\n", |
87 | 94 | " !git clone https://github.com/Labelbox/labelbox-python.git\n", |
88 | | - " !cd labelbox-python && git checkout mea-dev\n", |
89 | | - " !mv labelbox-python/examples/model_assisted_labeling/*.py .\n", |
90 | | - " !mv labelbox-python/examples/model_assisted_labeling/mapillary_sample.csv ." |
| 95 | + " !cd labelbox-python\n", |
| 96 | + " !mv labelbox-python/examples/model_assisted_labeling/*.py ." |
91 | 97 | ] |
92 | 98 | }, |
93 | 99 | { |
|
109 | 115 | }, |
110 | 116 | "outputs": [], |
111 | 117 | "source": [ |
112 | | - "from io import BytesIO\n", |
113 | | - "from getpass import getpass\n", |
114 | 118 | "import uuid\n", |
115 | 119 | "import numpy as np\n", |
116 | | - "from PIL import Image\n", |
| 120 | + "from skimage import measure\n", |
117 | 121 | "import requests\n", |
118 | 122 | "from tqdm import notebook\n", |
119 | | - "from collections import defaultdict\n", |
120 | | - "import ndjson\n", |
| 123 | + "import requests\n", |
| 124 | + "import csv\n", |
121 | 125 | "import os\n", |
122 | 126 | "\n", |
123 | 127 | "from labelbox.schema.ontology import OntologyBuilder, Tool\n", |
124 | | - "from labelbox import Client, LabelingFrontend, MALPredictionImport, DataRow\n", |
125 | | - "from labelbox.data.metrics.iou import data_row_miou\n", |
126 | | - "\n", |
| 128 | + "from labelbox import Client, LabelingFrontend, MALPredictionImport\n", |
127 | 129 | "from labelbox.data.metrics.iou import data_row_miou\n", |
128 | 130 | "from labelbox.data.serialization import NDJsonConverter\n", |
129 | | - "from labelbox.data.annotation_types import ScalarMetric, LabelList, Label, RasterData, Mask, Point, Rectangle, ObjectAnnotation\n", |
130 | | - "\n", |
131 | | - "\n", |
| 131 | + "from labelbox.data.annotation_types import (\n", |
| 132 | + " ScalarMetric, \n", |
| 133 | + " LabelList, \n", |
| 134 | + " Label, \n", |
| 135 | + " RasterData, \n", |
| 136 | + " Mask, \n", |
| 137 | + " Point, \n", |
| 138 | + " Rectangle, \n", |
| 139 | + " ObjectAnnotation\n", |
| 140 | + ")\n", |
132 | 141 | "\n", |
133 | 142 | "try:\n", |
134 | 143 | " from image_model import predict, load_model, class_mappings\n", |
135 | | - " from ndjson_utils import (\n", |
136 | | - " create_boxes_ndjson, \n", |
137 | | - " create_polygon_ndjson, \n", |
138 | | - " create_mask_ndjson, \n", |
139 | | - " create_point_ndjson\n", |
140 | | - " )\n", |
141 | 144 | "except ModuleNotFoundError: \n", |
142 | 145 | " # !git clone https://github.com/Labelbox/labelbox-python.git\n", |
143 | 146 | " # !cd labelbox-python && git checkout mea-dev\n", |
144 | 147 | " # !mv labelbox-python/examples/model_assisted_labeling/*.py .\n", |
145 | | - " # !mv labelbox-python/examples/model_assisted_labeling/mapillary_sample.csv .\n", |
146 | 148 | " raise Exception(\"You will need to run from the labelbox-python git repo\")" |
147 | 149 | ] |
148 | 150 | }, |
|
180 | 182 | }, |
181 | 183 | "outputs": [], |
182 | 184 | "source": [ |
183 | | - "API_KEY = \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJja2s0cTF2Z3djMHZwMDcwNHhoeDdtNHZrIiwib3JnYW5pemF0aW9uSWQiOiJja2s0cTF2Z2Fwc2F1MDczMjRhd25zanEyIiwiYXBpS2V5SWQiOiJja3J3bWNmZXQwa2N6MHkyYzh4Z3E1NHhoIiwic2VjcmV0IjoiZGM0ZTEwM2E1ZTQ2YzRiOGFkZWU2ZmMxMGM2ZTAwMTkiLCJpYXQiOjE2MjgwMjg4NTQsImV4cCI6MjI1OTE4MDg1NH0.-zl_aqbd0IoCRsKFHps0HzNhGOUFaVt6bb24AUVj28k\"\n", |
184 | 185 | "client = Client(api_key=API_KEY)\n", |
185 | 186 | "load_model() # initialize Tensorflow Model" |
186 | 187 | ] |
|
224 | 225 | { |
225 | 226 | "cell_type": "code", |
226 | 227 | "execution_count": null, |
227 | | - "id": "existing-generic", |
| 228 | + "id": "spoken-watson", |
228 | 229 | "metadata": {}, |
229 | 230 | "outputs": [], |
230 | 231 | "source": [ |
231 | 232 | "# --- setup dataset ---\n", |
232 | 233 | "# load mapillary sample\n", |
233 | | - "with open('mapillary_sample.csv', 'r') as file:\n", |
234 | | - " urls = [row[:-1].split(\",\") for row in file.readlines()][:10]" |
| 234 | + "sample_csv_url = \"https://raw.githubusercontent.com/Labelbox/labelbox-python/develop/examples/model_assisted_labeling/mapillary_sample.csv\"\n", |
| 235 | + "with requests.get(sample_csv_url, stream=True) as r:\n", |
| 236 | + " image_data = [row.split(',') for row in (line.decode('utf-8') for line in r.iter_lines())]" |
| 237 | + ] |
| 238 | + }, |
| 239 | + { |
| 240 | + "cell_type": "markdown", |
| 241 | + "id": "packed-madison", |
| 242 | + "metadata": {}, |
| 243 | + "source": [ |
| 244 | + "* Set up this prediction look to construct Annotation Types" |
235 | 245 | ] |
236 | 246 | }, |
237 | 247 | { |
|
244 | 254 | "outputs": [], |
245 | 255 | "source": [ |
246 | 256 | "predictions = LabelList([])\n", |
247 | | - "for (image_url, external_id) in notebook.tqdm(urls):\n", |
| 257 | + "for (image_url, external_id) in notebook.tqdm(image_data):\n", |
248 | 258 | " image = RasterData(url = image_url, external_id = external_id)\n", |
249 | 259 | " height, width = image.data.shape[:2]\n", |
250 | 260 | " prediction = predict(np.array([image.im_bytes]), min_score=0.5, height=height, width = width)\n", |
|
271 | 281 | }, |
272 | 282 | { |
273 | 283 | "cell_type": "markdown", |
274 | | - "id": "endless-expert", |
| 284 | + "id": "smooth-irrigation", |
275 | 285 | "metadata": {}, |
276 | 286 | "source": [ |
277 | 287 | "## Setup a project\n", |
|
281 | 291 | { |
282 | 292 | "cell_type": "code", |
283 | 293 | "execution_count": null, |
284 | | - "id": "married-candy", |
| 294 | + "id": "available-endorsement", |
285 | 295 | "metadata": {}, |
286 | 296 | "outputs": [], |
287 | 297 | "source": [ |
|
299 | 309 | { |
300 | 310 | "cell_type": "code", |
301 | 311 | "execution_count": null, |
302 | | - "id": "specified-directive", |
| 312 | + "id": "fresh-vertex", |
303 | 313 | "metadata": {}, |
304 | 314 | "outputs": [], |
305 | 315 | "source": [ |
|
503 | 513 | { |
504 | 514 | "cell_type": "code", |
505 | 515 | "execution_count": null, |
506 | | - "id": "premier-arkansas", |
| 516 | + "id": "variable-consumption", |
| 517 | + "metadata": {}, |
| 518 | + "outputs": [], |
| 519 | + "source": [] |
| 520 | + }, |
| 521 | + { |
| 522 | + "cell_type": "code", |
| 523 | + "execution_count": null, |
| 524 | + "id": "dense-malawi", |
507 | 525 | "metadata": {}, |
508 | 526 | "outputs": [], |
509 | 527 | "source": [] |
|
0 commit comments