Skip to content

Commit 2b04180

Browse files
Merge pull request #836 from Labelbox/sdubinin/al-000-fixed-missing-confidence-attribute
[AL-000] Fixed missing confidence attribute in NDline and NDTextEntity
2 parents 3eabd6e + 1d286ca commit 2b04180

File tree

7 files changed

+129
-8
lines changed

7 files changed

+129
-8
lines changed

labelbox/data/serialization/ndjson/objects.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,14 @@ def to_common(self) -> Line:
9393
return Line(points=[Point(x=pt.x, y=pt.y) for pt in self.line])
9494

9595
@classmethod
96-
def from_common(cls, line: Line,
97-
classifications: List[ClassificationAnnotation], name: str,
98-
feature_schema_id: Cuid, extra: Dict[str, Any],
99-
data: Union[ImageData, TextData]) -> "NDLine":
96+
def from_common(cls,
97+
line: Line,
98+
classifications: List[ClassificationAnnotation],
99+
name: str,
100+
feature_schema_id: Cuid,
101+
extra: Dict[str, Any],
102+
data: Union[ImageData, TextData],
103+
confidence: Optional[float] = None) -> "NDLine":
100104
return cls(line=[{
101105
'x': pt.x,
102106
'y': pt.y
@@ -105,7 +109,8 @@ def from_common(cls, line: Line,
105109
name=name,
106110
schema_id=feature_schema_id,
107111
uuid=extra.get('uuid'),
108-
classifications=classifications)
112+
classifications=classifications,
113+
confidence=confidence)
109114

110115

111116
class NDFrameLine(VideoSupported):
@@ -340,7 +345,7 @@ class Location(BaseModel):
340345
end: int
341346

342347

343-
class NDTextEntity(NDBaseObject):
348+
class NDTextEntity(NDBaseObject, ConfidenceMixin):
344349
location: Location
345350

346351
def to_common(self) -> TextEntity:
@@ -350,7 +355,8 @@ def to_common(self) -> TextEntity:
350355
def from_common(cls, text_entity: TextEntity,
351356
classifications: List[ClassificationAnnotation], name: str,
352357
feature_schema_id: Cuid, extra: Dict[str, Any],
353-
data: Union[ImageData, TextData]) -> "NDTextEntity":
358+
data: Union[ImageData,
359+
TextData], confidence: float) -> "NDTextEntity":
354360
return cls(location=Location(
355361
start=text_entity.start,
356362
end=text_entity.end,
@@ -359,7 +365,8 @@ def from_common(cls, text_entity: TextEntity,
359365
name=name,
360366
schema_id=feature_schema_id,
361367
uuid=extra.get('uuid'),
362-
classifications=classifications)
368+
classifications=classifications,
369+
confidence=confidence)
363370

364371

365372
class NDObject:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[
2+
{
3+
"line": [
4+
{
5+
"x": 2534.353,
6+
"y": 249.471
7+
},
8+
{
9+
"x": 2429.492,
10+
"y": 182.092
11+
},
12+
{
13+
"x": 2294.322,
14+
"y": 221.962
15+
}
16+
],
17+
"uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4",
18+
"dataRow": {
19+
"id": "cl6xnv9h61fv0085yhtoq06ht"
20+
},
21+
"name": "some-line",
22+
"schemaId": "cl6xnuwt95lqq07330tbb3mfd",
23+
"classifications": [],
24+
"confidence": 0.58
25+
}
26+
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[
2+
{
3+
"line": [
4+
{
5+
"x": 2534.353,
6+
"y": 249.471
7+
},
8+
{
9+
"x": 2429.492,
10+
"y": 182.092
11+
},
12+
{
13+
"x": 2294.322,
14+
"y": 221.962
15+
}
16+
],
17+
"uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4",
18+
"dataRow": {
19+
"id": "cl6xnv9h61fv0085yhtoq06ht"
20+
},
21+
"name": "some-line",
22+
"schemaId": "cl6xnuwt95lqq07330tbb3mfd",
23+
"classifications": []
24+
}
25+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"location": {
4+
"start": 67,
5+
"end": 128
6+
},
7+
"uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4",
8+
"dataRow": {
9+
"id": "cl6xnv9h61fv0085yhtoq06ht"
10+
},
11+
"name": "some-text-entity",
12+
"schemaId": "cl6xnuwt95lqq07330tbb3mfd",
13+
"classifications": [],
14+
"confidence": 0.53
15+
}
16+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"location": {
4+
"start": 67,
5+
"end": 128
6+
},
7+
"uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4",
8+
"dataRow": {
9+
"id": "cl6xnv9h61fv0085yhtoq06ht"
10+
},
11+
"name": "some-text-entity",
12+
"schemaId": "cl6xnuwt95lqq07330tbb3mfd",
13+
"classifications": []
14+
}
15+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import json
2+
import pytest
3+
from labelbox.data.serialization.ndjson.converter import NDJsonConverter
4+
5+
6+
@pytest.mark.parametrize("filename", [
7+
"tests/data/assets/ndjson/polyline_without_confidence_import.json",
8+
"tests/data/assets/ndjson/polyline_import.json"
9+
])
10+
def test_polyline_import(filename: str):
11+
with open(filename, 'r') as file:
12+
data = json.load(file)
13+
res = NDJsonConverter.deserialize(data).as_list()
14+
res = list(NDJsonConverter.serialize(res))
15+
assert res == data
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import json
2+
3+
import pytest
4+
5+
from labelbox.data.serialization.ndjson.converter import NDJsonConverter
6+
7+
8+
@pytest.mark.parametrize("filename", [
9+
"tests/data/assets/ndjson/text_entity_import.json",
10+
"tests/data/assets/ndjson/text_entity_without_confidence_import.json"
11+
])
12+
def test_text_entity_import(filename: str):
13+
with open('tests/data/assets/ndjson/text_entity_import.json', 'r') as file:
14+
data = json.load(file)
15+
res = NDJsonConverter.deserialize(data).as_list()
16+
res = list(NDJsonConverter.serialize(res))
17+
assert res == data

0 commit comments

Comments
 (0)