Skip to content

Commit b35dc30

Browse files
authored
Merge pull request #239 from Labelbox/ms/mask-data
Add MaskData
2 parents b50b51b + e75731b commit b35dc30

File tree

17 files changed

+144
-117
lines changed

17 files changed

+144
-117
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Geometry.raster now has a consistent interface and improved functionality
66
* renamed schema_id to feature_schema_id in the `FeatureSchema` class
77
* ImageData can load 2d images or masks
8+
* Mask objects now use `MaskData` to represent segmentation masks instead of `ImageData`
89

910
# Version 3.0.0-rc2 (2021-08-09)
1011
## Updates

examples/annotation_types/basics.ipynb

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"from labelbox.data.annotation_types import (\n",
5757
" Label,\n",
5858
" ImageData,\n",
59+
" MaskData,\n",
5960
" LabelList,\n",
6061
" TextData,\n",
6162
" VideoData,\n",
@@ -551,12 +552,12 @@
551552
"source": [
552553
"\n",
553554
"mask_annotation = ObjectAnnotation(\n",
554-
" value = Mask(mask = ImageData(arr = np.zeros((32,32,3), dtype = np.uint8)), color = (255,255,255)),\n",
555+
" value = Mask(mask = MaskData(arr = np.zeros((32,32,3), dtype = np.uint8)), color = (255,255,255)),\n",
555556
" name = \"mask class name\"\n",
556557
")\n",
557558
"\n",
558559
"mask_annotation = ObjectAnnotation(\n",
559-
" value = Mask(mask = ImageData(arr = np.zeros((32,32,3), dtype = np.uint8)), color = (255,255,255)),\n",
560+
" value = Mask(mask = MaskData(arr = np.zeros((32,32,3), dtype = np.uint8)), color = (255,255,255)),\n",
560561
" feature_schema_id = \"ckrgcel71000008jtd9mn0szu\"\n",
561562
")"
562563
]
@@ -577,7 +578,7 @@
577578
"metadata": {},
578579
"outputs": [],
579580
"source": [
580-
"raster_data = ImageData(arr = np.zeros((32,32,3), dtype = np.uint8))\n",
581+
"raster_data = MaskData(arr = np.zeros((32,32,3), dtype = np.uint8))\n",
581582
"mask_annotation = ObjectAnnotation(\n",
582583
" value = Mask(mask = raster_data, color = [255,255,255]),\n",
583584
" name = \"eyes\"\n",
@@ -604,7 +605,7 @@
604605
"metadata": {},
605606
"outputs": [],
606607
"source": [
607-
"raster_data = ImageData(arr = np.zeros((32,32, 3), dtype = np.uint8))\n",
608+
"raster_data = MaskData(arr = np.zeros((32,32, 3), dtype = np.uint8))\n",
608609
"mask_annotation = ObjectAnnotation(\n",
609610
" value = Mask(mask = raster_data, color = (128,255,255)),\n",
610611
" name = \"eye\"\n",
@@ -734,7 +735,7 @@
734735
"outputs": [],
735736
"source": [
736737
"mask_annotation = Mask(\n",
737-
" mask = ImageData(arr = np_mask),\n",
738+
" mask = MaskData(arr = np_mask),\n",
738739
" color = color \n",
739740
")\n",
740741
"\n",
@@ -790,7 +791,7 @@
790791
"metadata": {},
791792
"outputs": [],
792793
"source": [
793-
"mask_data = ImageData(arr = np_seg_mask)\n",
794+
"mask_data = MaskData(arr = np_seg_mask)\n",
794795
"eye_mask = Mask(mask = mask_data, color = eye_color)\n",
795796
"nose_mask = Mask(mask = mask_data, color = nose_color)\n"
796797
]
@@ -954,7 +955,7 @@
954955
" ),\n",
955956
" ObjectAnnotation(\n",
956957
" name = \"deer_eyes\",\n",
957-
" value = Mask(mask = ImageData(arr = np_mask), color = color)\n",
958+
" value = Mask(mask = MaskData(arr = np_mask), color = color)\n",
958959
" )\n",
959960
" ]\n",
960961
")"
@@ -1283,6 +1284,22 @@
12831284
"metadata": {},
12841285
"outputs": [],
12851286
"source": []
1287+
},
1288+
{
1289+
"cell_type": "code",
1290+
"execution_count": null,
1291+
"id": "progressive-courage",
1292+
"metadata": {},
1293+
"outputs": [],
1294+
"source": []
1295+
},
1296+
{
1297+
"cell_type": "code",
1298+
"execution_count": null,
1299+
"id": "asian-album",
1300+
"metadata": {},
1301+
"outputs": [],
1302+
"source": []
12861303
}
12871304
],
12881305
"metadata": {

examples/annotation_types/converters.ipynb

Lines changed: 69 additions & 69 deletions
Large diffs are not rendered by default.

examples/annotation_types/label_containers.ipynb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"from labelbox import LabelingFrontend\n",
3737
"from labelbox.data.annotation_types import (\n",
3838
" Label, \n",
39-
" ImageData, \n",
39+
" ImageData,\n",
40+
" MaskData,\n",
4041
" Mask, \n",
4142
" Point, \n",
4243
" Polygon, \n",
@@ -137,7 +138,7 @@
137138
" Point(x = 99, y = 181).raster(im_h, im_w, thickness = 3),\n",
138139
" ]\n",
139140
" mask_arr = np.max([*eye_masks,nose_mask] , axis = 0)\n",
140-
" mask = ImageData(arr = mask_arr)\n",
141+
" mask = MaskData(arr = mask_arr)\n",
141142
" return [Label(\n",
142143
" data = ImageData(im_bytes = requests.get(image_url).content),\n",
143144
" annotations = [\n",
@@ -572,6 +573,14 @@
572573
"metadata": {},
573574
"outputs": [],
574575
"source": []
576+
},
577+
{
578+
"cell_type": "code",
579+
"execution_count": null,
580+
"id": "foreign-berkeley",
581+
"metadata": {},
582+
"outputs": [],
583+
"source": []
575584
}
576585
],
577586
"metadata": {

examples/annotation_types/mal_using_annotation_types.ipynb

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"from labelbox.data.annotation_types import (\n",
6868
" LabelList,\n",
6969
" ImageData,\n",
70+
" MaskData,\n",
7071
" Rectangle,\n",
7172
" ObjectAnnotation,\n",
7273
" ClassificationAnnotation,\n",
@@ -170,7 +171,7 @@
170171
" start = Point(x = box[1], y = box[0]), end = Point(x = box[3], y = box[2])\n",
171172
" )\n",
172173
" elif name == 'car':\n",
173-
" value = Mask(mask = ImageData.from_2D_arr(arr = seg), color = (1,1,1))\n",
174+
" value = Mask(mask = MaskData.from_2D_arr(arr = seg), color = (1,1,1))\n",
174175
" if value is not None:\n",
175176
" annotations.append(\n",
176177
" ObjectAnnotation(\n",
@@ -322,22 +323,6 @@
322323
"for status in upload_task.statuses[:5]:\n",
323324
" print(status)"
324325
]
325-
},
326-
{
327-
"cell_type": "code",
328-
"execution_count": null,
329-
"id": "micro-salem",
330-
"metadata": {},
331-
"outputs": [],
332-
"source": []
333-
},
334-
{
335-
"cell_type": "code",
336-
"execution_count": null,
337-
"id": "prospective-grave",
338-
"metadata": {},
339-
"outputs": [],
340-
"source": []
341326
}
342327
],
343328
"metadata": {

examples/model_diagnostics/model_diagnostics_demo.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
" LabelList, \n",
137137
" Label, \n",
138138
" ImageData, \n",
139+
" MaskData,\n",
139140
" Mask, \n",
140141
" Polygon,\n",
141142
" Point, \n",
@@ -270,7 +271,7 @@
270271
" elif class_info['kind'] == Tool.Type.POINT:\n",
271272
" value = Point(x=(box[1] + box[3]) / 2., y = (box[0] + box[2]) / 2.)\n",
272273
" elif class_info['kind'] == Tool.Type.SEGMENTATION:\n",
273-
" value = Mask(mask = ImageData.from_2D_arr(seg * class_info['color']), color = (class_info['color'],)* 3)\n",
274+
" value = Mask(mask = MaskData.from_2D_arr(seg * class_info['color']), color = (class_info['color'],)* 3)\n",
274275
" else:\n",
275276
" raise ValueError(f\"Unsupported kind found. {class_info['kind']}\")\n",
276277
" annotations.append(ObjectAnnotation(name = class_info['name'], value = value))\n",

examples/model_diagnostics/model_diagnostics_guide.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
" LabelList, \n",
139139
" Label, \n",
140140
" ImageData, \n",
141+
" MaskData,\n",
141142
" Mask,\n",
142143
" Polygon,\n",
143144
" Line,\n",
@@ -271,7 +272,7 @@
271272
" value = Rectangle(start = Point(x = xmin, y = ymin), end = Point(x=xmax, y=ymax))\n",
272273
" value = Point(x=x, y =y)\n",
273274
" value = Line(points = [Point(x = x, y = y) for x,y in instance])\n",
274-
" value = Mask(mask = ImageData.from_2D_arr(seg * grayscale_color), color = (grayscale_color,)* 3)\n",
275+
" value = Mask(mask = MaskData.from_2D_arr(seg * grayscale_color), color = (grayscale_color,)* 3)\n",
275276
" \n",
276277
" annotations.append(ObjectAnnotation(name =class_name, value = value))\n",
277278
" \n",

labelbox/data/annotation_types/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from .classification import Text
2020

2121
from .data import ImageData
22+
from .data import MaskData
2223
from .data import TextData
2324
from .data import VideoData
2425

labelbox/data/annotation_types/collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def add_to_dataset(self,
7777
def add_url_to_masks(self, signer, max_concurrency=20) -> "LabelList":
7878
"""
7979
Creates signed urls for all masks in the LabelList.
80-
Multiple masks can reference the same ImageData mask so this makes sure we only upload that url once.
80+
Multiple masks objects can reference the same MaskData so this makes sure we only upload that url once.
8181
Only uploads url if one doesn't already exist.
8282
8383
Args:
@@ -235,7 +235,7 @@ def add_url_to_masks(self, signer: Callable[[bytes],
235235
str]) -> "LabelGenerator":
236236
"""
237237
Creates signed urls for all masks in the LabelGenerator.
238-
Multiple masks can reference the same ImageData mask so this makes sure we only upload that url once.
238+
Multiple masks can reference the same MaskData so this makes sure we only upload that url once.
239239
Only uploads url if one doesn't already exist.
240240
241241
Args:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from .raster import ImageData
2+
from .raster import MaskData
23
from .text import TextData
34
from .video import VideoData

0 commit comments

Comments
 (0)