Skip to content

Commit aa0c5fe

Browse files
committed
AL-3578: Format
1 parent f093e6f commit aa0c5fe

File tree

11 files changed

+188
-198
lines changed

11 files changed

+188
-198
lines changed

labelbox/data/annotation_types/label.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def frame_annotations(
6262
frame_dict = defaultdict(list)
6363
for annotation in self.annotations:
6464
if isinstance(
65-
annotation,
66-
(VideoObjectAnnotation, VideoClassificationAnnotation)):
65+
annotation,
66+
(VideoObjectAnnotation, VideoClassificationAnnotation)):
6767
frame_dict[annotation.frame].append(annotation)
6868
return frame_dict
6969

@@ -151,8 +151,7 @@ def assign_feature_schema_ids(
151151
elif isinstance(annotation, ObjectAnnotation):
152152
self._assign_or_raise(annotation, tool_lookup)
153153
for classification in annotation.classifications:
154-
self._assign_or_raise(
155-
classification, classification_lookup)
154+
self._assign_or_raise(classification, classification_lookup)
156155
self._assign_option(classification, classification_lookup)
157156
else:
158157
raise TypeError(

labelbox/data/mixins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def dict(self, *args, **kwargs):
2424

2525

2626
class ConfidenceNotSupportedMixin:
27+
2728
def __new__(cls, *args, **kwargs):
2829
if 'confidence' in kwargs:
2930
raise ConfidenceNotSupportedException(
30-
'Confidence is not supported for this annotaiton type yet'
31-
)
31+
'Confidence is not supported for this annotaiton type yet')
3232
return super().__new__(cls)

labelbox/data/serialization/ndjson/classification.py

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,23 @@ class NDChecklistSubclass(NDFeature):
7070

7171
def to_common(self) -> Checklist:
7272
return Checklist(answer=[
73-
ClassificationAnswer(
74-
name=answer.name,
75-
feature_schema_id=answer.schema_id,
76-
confidence=answer.confidence
77-
)
73+
ClassificationAnswer(name=answer.name,
74+
feature_schema_id=answer.schema_id,
75+
confidence=answer.confidence)
7876
for answer in self.answer
7977
])
8078

8179
@classmethod
8280
def from_common(cls, checklist: Checklist, name: str,
8381
feature_schema_id: Cuid) -> "NDChecklistSubclass":
8482
return cls(answer=[
85-
NDFeature(
86-
name=answer.name,
87-
schema_id=answer.feature_schema_id,
88-
confidence=answer.confidence
89-
)
83+
NDFeature(name=answer.name,
84+
schema_id=answer.feature_schema_id,
85+
confidence=answer.confidence)
9086
for answer in checklist.answer
9187
],
92-
name=name,
93-
schema_id=feature_schema_id)
88+
name=name,
89+
schema_id=feature_schema_id)
9490

9591
def dict(self, *args, **kwargs):
9692
res = super().dict(*args, **kwargs)
@@ -104,22 +100,18 @@ class NDRadioSubclass(NDFeature):
104100

105101
def to_common(self) -> Radio:
106102
return Radio(
107-
answer=ClassificationAnswer(
108-
name=self.answer.name,
109-
feature_schema_id=self.answer.schema_id,
110-
confidence=self.answer.confidence)
111-
)
103+
answer=ClassificationAnswer(name=self.answer.name,
104+
feature_schema_id=self.answer.schema_id,
105+
confidence=self.answer.confidence))
112106

113107
@classmethod
114108
def from_common(cls, radio: Radio, name: str,
115109
feature_schema_id: Cuid) -> "NDRadioSubclass":
116-
return cls(answer=NDFeature(
117-
name=radio.answer.name,
118-
schema_id=radio.answer.feature_schema_id,
119-
confidence=radio.answer.confidence
120-
),
121-
name=name,
122-
schema_id=feature_schema_id)
110+
return cls(answer=NDFeature(name=radio.answer.name,
111+
schema_id=radio.answer.feature_schema_id,
112+
confidence=radio.answer.confidence),
113+
name=name,
114+
schema_id=feature_schema_id)
123115

124116

125117
# ====== End of subclasses
@@ -148,18 +140,16 @@ def from_common(
148140
extra: Dict[str, Any], data: Union[VideoData, TextData,
149141
ImageData]) -> "NDChecklist":
150142
return cls(answer=[
151-
NDFeature(
152-
name=answer.name,
153-
schema_id=answer.feature_schema_id,
154-
confidence=answer.confidence
155-
)
143+
NDFeature(name=answer.name,
144+
schema_id=answer.feature_schema_id,
145+
confidence=answer.confidence)
156146
for answer in checklist.answer
157147
],
158-
data_row={'id': data.uid},
159-
name=name,
160-
schema_id=feature_schema_id,
161-
uuid=extra.get('uuid'),
162-
frames=extra.get('frames'))
148+
data_row={'id': data.uid},
149+
name=name,
150+
schema_id=feature_schema_id,
151+
uuid=extra.get('uuid'),
152+
frames=extra.get('frames'))
163153

164154

165155
class NDRadio(NDAnnotation, NDRadioSubclass, VideoSupported):
@@ -168,16 +158,14 @@ class NDRadio(NDAnnotation, NDRadioSubclass, VideoSupported):
168158
def from_common(cls, radio: Radio, name: str, feature_schema_id: Cuid,
169159
extra: Dict[str, Any], data: Union[VideoData, TextData,
170160
ImageData]) -> "NDRadio":
171-
return cls(answer=NDFeature(
172-
name=radio.answer.name,
173-
schema_id=radio.answer.feature_schema_id,
174-
confidence=radio.answer.confidence
175-
),
176-
data_row={'id': data.uid},
177-
name=name,
178-
schema_id=feature_schema_id,
179-
uuid=extra.get('uuid'),
180-
frames=extra.get('frames'))
161+
return cls(answer=NDFeature(name=radio.answer.name,
162+
schema_id=radio.answer.feature_schema_id,
163+
confidence=radio.answer.confidence),
164+
data_row={'id': data.uid},
165+
name=name,
166+
schema_id=feature_schema_id,
167+
uuid=extra.get('uuid'),
168+
frames=extra.get('frames'))
181169

182170

183171
class NDSubclassification:
@@ -262,11 +250,12 @@ def lookup_classification(
262250
Radio: NDRadio
263251
}.get(type(annotation.value))
264252

253+
265254
# Make sure to keep NDChecklistSubclass prior to NDRadioSubclass in the list,
266255
# otherwise list of answers gets parsed by NDRadio whereas NDChecklist must be used
267256
NDSubclassificationType = Union[NDChecklistSubclass, NDRadioSubclass,
268257
NDTextSubclass]
269258

270259
# Make sure to keep NDChecklist prior to NDRadio in the list,
271260
# otherwise list of answers gets parsed by NDRadio whereas NDChecklist must be used
272-
NDClassificationType = Union[NDChecklist, NDRadio, NDText]
261+
NDClassificationType = Union[NDChecklist, NDRadio, NDText]

labelbox/data/serialization/ndjson/objects.py

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,24 @@ def to_common(self) -> Point:
4848
return Point(x=self.point.x, y=self.point.y)
4949

5050
@classmethod
51-
def from_common(cls, point: Point,
52-
classifications: List[ClassificationAnnotation], name: str,
53-
feature_schema_id: Cuid, extra: Dict[str, Any],
51+
def from_common(cls,
52+
point: Point,
53+
classifications: List[ClassificationAnnotation],
54+
name: str,
55+
feature_schema_id: Cuid,
56+
extra: Dict[str, Any],
5457
data: Union[ImageData, TextData],
55-
confidence: Optional[float] = None
56-
) -> "NDPoint":
58+
confidence: Optional[float] = None) -> "NDPoint":
5759
return cls(point={
5860
'x': point.x,
5961
'y': point.y
6062
},
61-
dataRow=DataRow(id=data.uid),
62-
name=name,
63-
schema_id=feature_schema_id,
64-
uuid=extra.get('uuid'),
65-
classifications=classifications,
66-
confidence=confidence
67-
)
63+
dataRow=DataRow(id=data.uid),
64+
name=name,
65+
schema_id=feature_schema_id,
66+
uuid=extra.get('uuid'),
67+
classifications=classifications,
68+
confidence=confidence)
6869

6970

7071
class NDFramePoint(VideoSupported):
@@ -100,11 +101,11 @@ def from_common(cls, line: Line,
100101
'x': pt.x,
101102
'y': pt.y
102103
} for pt in line.points],
103-
dataRow=DataRow(id=data.uid),
104-
name=name,
105-
schema_id=feature_schema_id,
106-
uuid=extra.get('uuid'),
107-
classifications=classifications)
104+
dataRow=DataRow(id=data.uid),
105+
name=name,
106+
schema_id=feature_schema_id,
107+
uuid=extra.get('uuid'),
108+
classifications=classifications)
108109

109110

110111
class NDFrameLine(VideoSupported):
@@ -136,23 +137,24 @@ def to_common(self) -> Polygon:
136137
return Polygon(points=[Point(x=pt.x, y=pt.y) for pt in self.polygon])
137138

138139
@classmethod
139-
def from_common(cls, polygon: Polygon,
140-
classifications: List[ClassificationAnnotation], name: str,
141-
feature_schema_id: Cuid, extra: Dict[str, Any],
140+
def from_common(cls,
141+
polygon: Polygon,
142+
classifications: List[ClassificationAnnotation],
143+
name: str,
144+
feature_schema_id: Cuid,
145+
extra: Dict[str, Any],
142146
data: Union[ImageData, TextData],
143-
confidence: Optional[float] = None
144-
) -> "NDPolygon":
147+
confidence: Optional[float] = None) -> "NDPolygon":
145148
return cls(polygon=[{
146149
'x': pt.x,
147150
'y': pt.y
148151
} for pt in polygon.points],
149-
dataRow=DataRow(id=data.uid),
150-
name=name,
151-
schema_id=feature_schema_id,
152-
uuid=extra.get('uuid'),
153-
classifications=classifications,
154-
confidence=confidence
155-
)
152+
dataRow=DataRow(id=data.uid),
153+
name=name,
154+
schema_id=feature_schema_id,
155+
uuid=extra.get('uuid'),
156+
classifications=classifications,
157+
confidence=confidence)
156158

157159

158160
class NDRectangle(NDBaseObject, ConfidenceMixin):
@@ -164,9 +166,12 @@ def to_common(self) -> Rectangle:
164166
y=self.bbox.top + self.bbox.height))
165167

166168
@classmethod
167-
def from_common(cls, rectangle: Rectangle,
168-
classifications: List[ClassificationAnnotation], name: str,
169-
feature_schema_id: Cuid, extra: Dict[str, Any],
169+
def from_common(cls,
170+
rectangle: Rectangle,
171+
classifications: List[ClassificationAnnotation],
172+
name: str,
173+
feature_schema_id: Cuid,
174+
extra: Dict[str, Any],
170175
data: Union[ImageData, TextData],
171176
confidence: Optional[float] = None) -> "NDRectangle":
172177
return cls(bbox=Bbox(top=rectangle.start.y,
@@ -180,8 +185,7 @@ def from_common(cls, rectangle: Rectangle,
180185
classifications=classifications,
181186
page=extra.get('page'),
182187
unit=extra.get('unit'),
183-
confidence=confidence
184-
)
188+
confidence=confidence)
185189

186190

187191
class NDFrameRectangle(VideoSupported):
@@ -304,15 +308,17 @@ def to_common(self) -> Mask:
304308
return Mask(mask=MaskData.from_2D_arr(image), color=(1, 1, 1))
305309

306310
@classmethod
307-
def from_common(cls, mask: Mask,
308-
classifications: List[ClassificationAnnotation], name: str,
309-
feature_schema_id: Cuid, extra: Dict[str, Any],
311+
def from_common(cls,
312+
mask: Mask,
313+
classifications: List[ClassificationAnnotation],
314+
name: str,
315+
feature_schema_id: Cuid,
316+
extra: Dict[str, Any],
310317
data: Union[ImageData, TextData],
311318
confidence: Optional[float] = None) -> "NDMask":
312319

313320
if mask.mask.url is not None:
314-
lbv1_mask = _URIMask(
315-
instanceURI=mask.mask.url, colorRGB=mask.color)
321+
lbv1_mask = _URIMask(instanceURI=mask.mask.url, colorRGB=mask.color)
316322
else:
317323
binary = np.all(mask.mask.value == mask.color, axis=-1)
318324
im_bytes = BytesIO()
@@ -326,8 +332,7 @@ def from_common(cls, mask: Mask,
326332
schema_id=feature_schema_id,
327333
uuid=extra.get('uuid'),
328334
classifications=classifications,
329-
confidence=confidence
330-
)
335+
confidence=confidence)
331336

332337

333338
class Location(BaseModel):
@@ -350,11 +355,11 @@ def from_common(cls, text_entity: TextEntity,
350355
start=text_entity.start,
351356
end=text_entity.end,
352357
),
353-
dataRow=DataRow(id=data.uid),
354-
name=name,
355-
schema_id=feature_schema_id,
356-
uuid=extra.get('uuid'),
357-
classifications=classifications)
358+
dataRow=DataRow(id=data.uid),
359+
name=name,
360+
schema_id=feature_schema_id,
361+
uuid=extra.get('uuid'),
362+
classifications=classifications)
358363

359364

360365
class NDObject:
@@ -366,8 +371,8 @@ def to_common(annotation: "NDObjectType") -> ObjectAnnotation:
366371
NDSubclassification.to_common(annot)
367372
for annot in annotation.classifications
368373
]
369-
confidence = annotation.confidence if hasattr(
370-
annotation, 'confidence') else None
374+
confidence = annotation.confidence if hasattr(annotation,
375+
'confidence') else None
371376
return ObjectAnnotation(value=common_annotation,
372377
name=annotation.name,
373378
feature_schema_id=annotation.schema_id,
@@ -377,8 +382,7 @@ def to_common(annotation: "NDObjectType") -> ObjectAnnotation:
377382
'page': annotation.page,
378383
'unit': annotation.unit
379384
},
380-
confidence=confidence
381-
)
385+
confidence=confidence)
382386

383387
@classmethod
384388
def from_common(

labelbox/schema/annotation_import.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def wait_until_done(self,
9393
"""
9494
pbar = tqdm(total=100,
9595
bar_format="{n}% |{bar}| [{elapsed}, {rate_fmt}{postfix}]"
96-
) if show_progress else None
96+
) if show_progress else None
9797
while self.state.value == AnnotationImportState.RUNNING.value:
9898
logger.info(f"Sleeping for {sleep_time_seconds} seconds...")
9999
time.sleep(sleep_time_seconds)
@@ -612,7 +612,7 @@ def create_from_objects(cls, client: "labelbox.Client", project_id: str,
612612
if not data_str:
613613
raise ValueError('labels cannot be empty')
614614
data = data_str.encode('utf-8')
615-
615+
616616
has_confidence = LabelsConfidencePresenceChecker.check(labels)
617617
if has_confidence:
618618
logger.warning("""
@@ -677,8 +677,7 @@ def from_name(cls,
677677
}
678678
response = client.execute(query_str, params)
679679
if response is None:
680-
raise labelbox.exceptions.ResourceNotFoundError(
681-
LabelImport, params)
680+
raise labelbox.exceptions.ResourceNotFoundError(LabelImport, params)
682681
response = response["labelImport"]
683682
if as_json:
684683
return response

0 commit comments

Comments
 (0)