Skip to content

Commit f30d572

Browse files
author
Matt Sokoloff
committed
wip
1 parent 53247b9 commit f30d572

File tree

5 files changed

+49
-13
lines changed

5 files changed

+49
-13
lines changed

labelbox/data/annotation_types/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@
2929
from .collection import LabelGenerator
3030

3131
from .metrics import ScalarMetric
32+
from .metrics import CustomScalarMetric
33+
from .metrics import MetricAggregation
34+

labelbox/data/annotation_types/label.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from collections import defaultdict
2+
from labelbox.data.annotation_types.metrics.scalar import CustomScalarMetric
23

34
from typing import Any, Callable, Dict, List, Union, Optional
45

@@ -21,7 +22,7 @@ class Label(BaseModel):
2122
data: Union[VideoData, ImageData, TextData]
2223
annotations: List[Union[ClassificationAnnotation, ObjectAnnotation,
2324
VideoObjectAnnotation,
24-
VideoClassificationAnnotation, ScalarMetric]] = []
25+
VideoClassificationAnnotation, ScalarMetric, CustomScalarMetric]] = []
2526
extra: Dict[str, Any] = {}
2627

2728
def object_annotations(self) -> List[ObjectAnnotation]:

labelbox/data/annotation_types/metrics.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

labelbox/schema/bulk_import_request.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ def create_from_local_file(cls,
388388

389389
def delete(self) -> None:
390390
""" Deletes the import job and also any annotations created by this import.
391-
392-
Returns:
391+
392+
Returns:
393393
None
394394
"""
395395
id_param = "bulk_request_id"
@@ -635,7 +635,6 @@ def determinants(parent_cls) -> List[str]:
635635

636636
###### Classifications ######
637637

638-
639638
class NDText(NDBase):
640639
ontology_type: Literal["text"] = "text"
641640
answer: str = pydantic.Field(determinant=True)

tests/data/annotation_types/test_metrics.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from labelbox.data.annotation_types.metrics.aggregations import MetricAggregation
2+
from labelbox.data.annotation_types.metrics.scalar import CustomScalarMetric
13
from labelbox.data.annotation_types.collection import LabelList
24
from labelbox.data.annotation_types import ScalarMetric, Label, ImageData
35

6+
import pytest
47

58
def test_scalar_metric():
69
value = 10
@@ -27,3 +30,42 @@ def test_scalar_metric():
2730
}
2831
assert label.dict() == expected
2932
next(LabelList([label])).dict() == expected
33+
34+
35+
@pytest.mark.parametrize(
36+
'feature_name,subclass_name,aggregation',
37+
[
38+
("cat", "orange" , MetricAggregation.ARITHMETIC_MEAN),
39+
("cat", None, MetricAggregation.ARITHMETIC_MEAN),
40+
(None, None, MetricAggregation.ARITHMETIC_MEAN),
41+
(None, None, None),
42+
])
43+
def test_custom_scalar_metric(feature_name, subclass_name, aggregation):
44+
value = 0.5
45+
metric = CustomScalarMetric(metric_name = "iou", value=value, feature_name=feature_name, subclass_name = subclass_name, aggregation = aggregation)
46+
assert metric.value == value
47+
48+
label = Label(data=ImageData(uid="ckrmd9q8g000009mg6vej7hzg"),
49+
annotations=[metric])
50+
expected = {
51+
'data': {
52+
'external_id': None,
53+
'uid': 'ckrmd9q8g000009mg6vej7hzg',
54+
'im_bytes': None,
55+
'file_path': None,
56+
'url': None,
57+
'arr': None
58+
},
59+
'annotations': [{
60+
'value': 10.0,
61+
62+
'extra': {}
63+
}],
64+
'extra': {},
65+
'uid': None
66+
}
67+
assert label.dict() == expected
68+
next(LabelList([label])).dict() == expected
69+
70+
71+

0 commit comments

Comments
 (0)