Skip to content

Commit d95be4a

Browse files
authored
[PLT-448] Added coco deprecation message (#1574)
1 parent 629c3b8 commit d95be4a

File tree

5 files changed

+53
-11
lines changed

5 files changed

+53
-11
lines changed

libs/labelbox/src/labelbox/data/serialization/coco/annotation.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
from typing import Tuple, List, Union
1+
from typing import Any, Tuple, List, Union
22
from pathlib import Path
33
from collections import defaultdict
4+
import warnings
45

5-
from labelbox import pydantic_compat
6+
from ...annotation_types.relationship import RelationshipAnnotation
7+
from ...annotation_types.metrics.confusion_matrix import ConfusionMatrixMetric
8+
from ...annotation_types.metrics.scalar import ScalarMetric
9+
from ...annotation_types.video import VideoMaskAnnotation
10+
from ...annotation_types.annotation import ObjectAnnotation
11+
from ...annotation_types.classification.classification import ClassificationAnnotation
12+
13+
from .... import pydantic_compat
614
import numpy as np
715

816
from .path import PathSerializerMixin
@@ -18,11 +26,20 @@ def rle_decoding(rle_arr: List[int], w: int, h: int) -> np.ndarray:
1826
return mask.reshape((w, h)).T
1927

2028

21-
def get_annotation_lookup(annotations):
29+
def get_annotation_lookup(
30+
annotations: List[Union[ClassificationAnnotation, ObjectAnnotation,
31+
VideoMaskAnnotation, ScalarMetric,
32+
ConfusionMatrixMetric, RelationshipAnnotation]]
33+
) -> defaultdict[Any, list]:
34+
"""Get annotations from Label.annotations objects
35+
36+
Args:
37+
annotations (Label.annotations): Annotations attached to labelbox Label object used as private method
38+
"""
2239
annotation_lookup = defaultdict(list)
2340
for annotation in annotations:
2441
annotation_lookup[getattr(annotation, 'image_id', None) or
25-
getattr(annotation, 'name')].append(annotation)
42+
getattr(annotation, 'name', None)].append(annotation)
2643
return annotation_lookup
2744

2845

libs/labelbox/src/labelbox/data/serialization/coco/categories.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from hashlib import md5
33

4-
from labelbox import pydantic_compat
4+
from .... import pydantic_compat
55

66

77
class Categories(pydantic_compat.BaseModel):

libs/labelbox/src/labelbox/data/serialization/coco/converter.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from typing import Dict, Any, Union
22
from pathlib import Path
33
import os
4+
import warnings
45

5-
from labelbox.data.annotation_types.collection import LabelCollection, LabelGenerator
6-
from labelbox.data.serialization.coco.instance_dataset import CocoInstanceDataset
7-
from labelbox.data.serialization.coco.panoptic_dataset import CocoPanopticDataset
6+
from ...annotation_types.collection import LabelCollection, LabelGenerator
7+
from ...serialization.coco.instance_dataset import CocoInstanceDataset
8+
from ...serialization.coco.panoptic_dataset import CocoPanopticDataset
89

910

1011
def create_path_if_not_exists(path: Union[Path, str],
@@ -28,7 +29,7 @@ def validate_path(path: Union[Path, str], name: str):
2829

2930
class COCOConverter:
3031
"""
31-
Class for convertering between coco and labelbox formats
32+
Class for converting between coco and labelbox formats
3233
Note that this class is only compatible with image data.
3334
3435
Subclasses are currently ignored.
@@ -55,6 +56,12 @@ def serialize_instances(labels: LabelCollection,
5556
Returns:
5657
A dictionary containing labels in the coco object format.
5758
"""
59+
60+
warnings.warn(
61+
"You are currently utilizing COCOconverter for this action, which will be deprecated in a later release.",
62+
DeprecationWarning,
63+
stacklevel=2)
64+
5865
image_root = create_path_if_not_exists(image_root, ignore_existing_data)
5966
return CocoInstanceDataset.from_common(labels=labels,
6067
image_root=image_root,
@@ -85,6 +92,12 @@ def serialize_panoptic(labels: LabelCollection,
8592
Returns:
8693
A dictionary containing labels in the coco panoptic format.
8794
"""
95+
96+
warnings.warn(
97+
"You are currently utilizing COCOconverter for this action, which will be deprecated in a later release.",
98+
DeprecationWarning,
99+
stacklevel=2)
100+
88101
image_root = create_path_if_not_exists(image_root, ignore_existing_data)
89102
mask_root = create_path_if_not_exists(mask_root, ignore_existing_data)
90103
return CocoPanopticDataset.from_common(labels=labels,
@@ -107,6 +120,12 @@ def deserialize_panoptic(json_data: Dict[str, Any], image_root: Union[Path,
107120
Returns:
108121
LabelGenerator
109122
"""
123+
124+
warnings.warn(
125+
"You are currently utilizing COCOconverter for this action, which will be deprecated in a later release.",
126+
DeprecationWarning,
127+
stacklevel=2)
128+
110129
image_root = validate_path(image_root, 'image_root')
111130
mask_root = validate_path(mask_root, 'mask_root')
112131
objs = CocoPanopticDataset(**json_data)
@@ -125,6 +144,12 @@ def deserialize_instances(json_data: Dict[str, Any],
125144
Returns:
126145
LabelGenerator
127146
"""
147+
148+
warnings.warn(
149+
"You are currently utilizing COCOconverter for this action, which will be deprecated in a later release.",
150+
DeprecationWarning,
151+
stacklevel=2)
152+
128153
image_root = validate_path(image_root, 'image_root')
129154
objs = CocoInstanceDataset(**json_data)
130155
gen = objs.to_common(image_root)

libs/labelbox/src/labelbox/data/serialization/coco/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import imagesize
66

77
from .path import PathSerializerMixin
8-
from labelbox.data.annotation_types import Label
8+
from ...annotation_types import Label
99

1010

1111
class CocoImage(PathSerializerMixin):

libs/labelbox/src/labelbox/data/serialization/coco/instance_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import numpy as np
88
from tqdm import tqdm
9-
from labelbox import pydantic_compat
9+
from .... import pydantic_compat
1010

1111
from ...annotation_types import ImageData, MaskData, Mask, ObjectAnnotation, Label, Polygon, Point, Rectangle
1212
from ...annotation_types.collection import LabelCollection

0 commit comments

Comments
 (0)