Skip to content

Commit 63c5cbf

Browse files
authored
Merge pull request #242 from Labelbox/ms/abc
abstract base classes
2 parents 4306e1a + e61ea69 commit 63c5cbf

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

CHANGELOG.md

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

109
# Version 3.0.0-rc2 (2021-08-09)
1110
## Updates

labelbox/data/annotation_types/data/base_data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
from abc import ABC
12
from typing import Optional
23

34
from pydantic import BaseModel
45

56

6-
class BaseData(BaseModel):
7+
class BaseData(BaseModel, ABC):
78
"""
89
Base class for objects representing data.
910
This class shouldn't directly be used

labelbox/data/annotation_types/data/raster.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Callable, Optional
22
from io import BytesIO
3+
from abc import ABC
34

45
import numpy as np
56
from pydantic import BaseModel
@@ -13,7 +14,7 @@
1314
from ..types import TypedArray
1415

1516

16-
class RasterData(BaseModel):
17+
class RasterData(BaseModel, ABC):
1718
"""
1819
Represents an image or segmentation mask.
1920
"""
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,25 @@
11
from typing import Dict, Any, Optional, Union, Tuple
2+
from abc import ABC, abstractmethod
23

34
import geojson
45
import numpy as np
56
from shapely import geometry as geom
67
from pydantic import BaseModel
78

89

9-
class Geometry(BaseModel):
10+
class Geometry(BaseModel, ABC):
1011
"""
11-
Base class for geometry objects. Shouldn't be directly instantiated.
12+
Base class for geometry objects.
1213
"""
1314
extra: Dict[str, Any] = {}
1415

15-
@property
16-
def geometry(self) -> geojson:
17-
raise NotImplementedError("Subclass must override this")
18-
1916
@property
2017
def shapely(
2118
self
2219
) -> Union[geom.Point, geom.LineString, geom.Polygon, geom.MultiPoint,
2320
geom.MultiLineString, geom.MultiPolygon]:
2421
return geom.shape(self.geometry)
2522

26-
def raster(self,
27-
height: Optional[int] = None,
28-
width: Optional[int] = None,
29-
canvas: Optional[np.ndarray] = None,
30-
color: Optional[Union[int, Tuple[int, int, int]]] = None,
31-
thickness: Optional[int] = 1) -> np.ndarray:
32-
raise NotImplementedError("Subclass must override this")
33-
3423
def get_or_create_canvas(self, height: Optional[int], width: Optional[int],
3524
canvas: Optional[np.ndarray]) -> np.ndarray:
3625
if canvas is None:
@@ -39,3 +28,17 @@ def get_or_create_canvas(self, height: Optional[int], width: Optional[int],
3928
"Must either provide canvas or height and width")
4029
canvas = np.zeros((height, width, 3), dtype=np.uint8)
4130
return canvas
31+
32+
@property
33+
@abstractmethod
34+
def geometry(self) -> geojson:
35+
pass
36+
37+
@abstractmethod
38+
def raster(self,
39+
height: Optional[int] = None,
40+
width: Optional[int] = None,
41+
canvas: Optional[np.ndarray] = None,
42+
color: Optional[Union[int, Tuple[int, int, int]]] = None,
43+
thickness: Optional[int] = 1) -> np.ndarray:
44+
pass

0 commit comments

Comments
 (0)