Skip to content

Commit 762db47

Browse files
committed
Deleted filering in the tags preprocessing
1 parent 6783ea7 commit 762db47

File tree

3 files changed

+129
-39
lines changed

3 files changed

+129
-39
lines changed

src/superannotate/lib/core/data_handlers.py

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
from typing import Dict
99
from typing import List
1010

11-
import lib.core as constances
12-
from lib.core.enums import ClassTypeEnum
13-
from lib.core.reporter import Reporter
1411
from superannotate_schemas.schemas.classes import AnnotationClass
1512
from superannotate_schemas.schemas.classes import Attribute
1613
from superannotate_schemas.schemas.classes import AttributeGroup
1714

15+
import lib.core as constances
16+
from lib.core.enums import ClassTypeEnum
17+
from lib.core.reporter import Reporter
18+
1819

1920
class BaseDataHandler(metaclass=ABCMeta):
2021
@abstractmethod
@@ -40,17 +41,15 @@ def __init__(self, annotation_classes: List[AnnotationClass]):
4041

4142
@lru_cache()
4243
def get_annotation_class(
43-
self, name: str, class_type: ClassTypeEnum
44+
self, name: str
4445
) -> AnnotationClass:
4546
for annotation_class in self._annotation_classes:
46-
if annotation_class.name == name and class_type.equals(
47-
annotation_class.type
48-
):
47+
if annotation_class.name == name:
4948
return annotation_class
5049

5150
@lru_cache()
5251
def get_attribute_group(
53-
self, annotation_class: AnnotationClass, attr_group_name: str
52+
self, annotation_class: AnnotationClass, attr_group_name: str
5453
) -> AttributeGroup:
5554
for attr_group in annotation_class.attribute_groups:
5655
if attr_group.name == attr_group_name:
@@ -108,9 +107,7 @@ class DocumentTagHandler(BaseAnnotationDateHandler):
108107
def handle(self, annotation: dict):
109108
new_tags = []
110109
for tag in annotation["tags"]:
111-
annotation_class = self.get_annotation_class(
112-
tag, class_type=ClassTypeEnum.OBJECT
113-
)
110+
annotation_class = self.get_annotation_class(tag)
114111
if annotation_class:
115112
new_tags.append(annotation_class.id)
116113
annotation["tags"] = new_tags
@@ -119,10 +116,10 @@ def handle(self, annotation: dict):
119116

120117
class MissingIDsHandler(BaseAnnotationDateHandler):
121118
def __init__(
122-
self,
123-
annotation_classes: List[AnnotationClass],
124-
templates: List[dict],
125-
reporter: Reporter,
119+
self,
120+
annotation_classes: List[AnnotationClass],
121+
templates: List[dict],
122+
reporter: Reporter,
126123
):
127124
super().__init__(annotation_classes)
128125
self.validate_existing_classes(annotation_classes)
@@ -175,9 +172,7 @@ def handle(self, annotation: dict):
175172
annotation_instance["classId"] = -1
176173
else:
177174
class_name = annotation_instance["className"]
178-
annotation_type = annotation_instance.get("type", ClassTypeEnum.OBJECT)
179-
class_type = self._get_class_type(annotation_type)
180-
annotation_class = self.get_annotation_class(class_name, class_type)
175+
annotation_class = self.get_annotation_class(class_name)
181176
if not annotation_class:
182177
self.reporter.log_warning(f"Couldn't find class {class_name}")
183178
self.reporter.store_message("missing_classes", class_name)
@@ -199,7 +194,7 @@ def handle(self, annotation: dict):
199194
template["name"]: template["id"] for template in self._templates
200195
}
201196
for annotation_instance in (
202-
i for i in annotation["instances"] if i.get("type", None) == "template"
197+
i for i in annotation["instances"] if i.get("type", None) == "template"
203198
):
204199
annotation_instance["templateId"] = template_name_id_map.get(
205200
annotation_instance.get("templateName", ""), -1
@@ -209,13 +204,7 @@ def handle(self, annotation: dict):
209204
i for i in annotation["instances"] if "className" in i and i["classId"] > 0
210205
]:
211206
annotation_class_name = annotation_instance["className"]
212-
annotation_class_type = self._get_class_type(
213-
annotation_instance.get("type", ClassTypeEnum.OBJECT)
214-
)
215-
216-
annotation_class = self.get_annotation_class(
217-
annotation_class_name, annotation_class_type
218-
)
207+
annotation_class = self.get_annotation_class(annotation_class_name)
219208
if not annotation_class:
220209
self.reporter.log_warning(
221210
f"Couldn't find annotation class {annotation_class_name}"
@@ -291,9 +280,7 @@ def convert_timestamp(timestamp):
291280
"locked": False,
292281
}
293282
if class_name:
294-
annotation_class = self.get_annotation_class(
295-
class_name, ClassTypeEnum.OBJECT
296-
)
283+
annotation_class = self.get_annotation_class(class_name)
297284
if annotation_class:
298285
editor_instance["classId"] = annotation_class.id
299286
else:
@@ -328,9 +315,7 @@ def convert_timestamp(timestamp):
328315
] = timestamp_data["points"]
329316
if not class_name:
330317
continue
331-
annotation_class = self.get_annotation_class(
332-
class_name, ClassTypeEnum.OBJECT
333-
)
318+
annotation_class = self.get_annotation_class(class_name)
334319
if not annotation_class:
335320
self.reporter.store_message(
336321
"missing_classes", meta["className"]
@@ -365,10 +350,10 @@ def convert_timestamp(timestamp):
365350
(group_name, attr_name)
366351
)
367352
attributes_to_add = (
368-
existing_attributes_in_current_instance - active_attributes
353+
existing_attributes_in_current_instance - active_attributes
369354
)
370355
attributes_to_delete = (
371-
active_attributes - existing_attributes_in_current_instance
356+
active_attributes - existing_attributes_in_current_instance
372357
)
373358
if attributes_to_add or attributes_to_delete:
374359
editor_instance["timeline"][timestamp][

src/superannotate/lib/core/usecases/images.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2845,10 +2845,6 @@ def __init__(
28452845
self._annotation_classes = annotation_classes
28462846
self._project = project
28472847

2848-
def validate_annotation_classes(self):
2849-
if "attribute_groups" not in self._annotation_classes:
2850-
raise AppValidationException("Field attribute_groups is required.")
2851-
28522848
def validate_project_type(self):
28532849
if self._project.project_type != ProjectType.VECTOR.value and "tag" in [
28542850
i.type for i in self._annotation_classes
Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,110 @@
1-
[{"id":56820,"project_id":7617,"name":"Personal vehicle","color":"#547497","count":18,"createdAt":"2020-09-29T10:39:39.000Z","updatedAt":"2020-09-29T10:48:18.000Z","attribute_groups":[{"id":21448,"class_id":56820,"name":"Large","is_multiselect":0,"createdAt":"2020-09-29T10:39:39.000Z","updatedAt":"2020-09-29T10:39:39.000Z","attributes":[{"id":57096,"group_id":21448,"project_id":7617,"name":"no","count":0,"createdAt":"2020-09-29T10:39:39.000Z","updatedAt":"2020-09-29T10:39:39.000Z"},{"id":57097,"group_id":21448,"project_id":7617,"name":"yes","count":1,"createdAt":"2020-09-29T10:39:39.000Z","updatedAt":"2020-09-29T10:48:18.000Z"}]}]},{"id":56821,"project_id":7617,"name":"Large vehicle","color":"#2ba36d","count":1,"createdAt":"2020-09-29T10:39:39.000Z","updatedAt":"2020-09-29T10:48:18.000Z","attribute_groups":[{"id":21449,"class_id":56821,"name":"small","is_multiselect":0,"createdAt":"2020-09-29T10:39:39.000Z","updatedAt":"2020-09-29T10:39:39.000Z","attributes":[{"id":57098,"group_id":21449,"project_id":7617,"name":"yes","count":0,"createdAt":"2020-09-29T10:39:39.000Z","updatedAt":"2020-09-29T10:39:39.000Z"},{"id":57099,"group_id":21449,"project_id":7617,"name":"no","count":1,"createdAt":"2020-09-29T10:39:39.000Z","updatedAt":"2020-09-29T10:48:18.000Z"}]}]},{"id":56822,"project_id":7617,"name":"Pedestrian","color":"#d4da03","count":3,"createdAt":"2020-09-29T10:39:39.000Z","updatedAt":"2020-09-29T10:48:18.000Z","attribute_groups":[]},{"id":56823,"project_id":7617,"name":"Two wheeled vehicle","color":"#f11aec","count":1,"createdAt":"2020-09-29T10:39:39.000Z","updatedAt":"2020-09-29T10:48:18.000Z","attribute_groups":[]},{"id":56824,"project_id":7617,"name":"Traffic sign","color":"#d8a7fd","count":9,"createdAt":"2020-09-29T10:39:39.000Z","updatedAt":"2020-09-29T10:48:18.000Z","attribute_groups":[]}]
1+
[
2+
{
3+
"id": 56820,
4+
"project_id": 7617,
5+
"name": "Personal vehicle",
6+
"color": "#547497",
7+
"count": 18,
8+
"createdAt": "2020-09-29T10:39:39.000Z",
9+
"updatedAt": "2020-09-29T10:48:18.000Z",
10+
"attribute_groups": [
11+
{
12+
"id": 21448,
13+
"class_id": 56820,
14+
"name": "Large",
15+
"is_multiselect": 0,
16+
"createdAt": "2020-09-29T10:39:39.000Z",
17+
"updatedAt": "2020-09-29T10:39:39.000Z",
18+
"attributes": [
19+
{
20+
"id": 57096,
21+
"group_id": 21448,
22+
"project_id": 7617,
23+
"name": "no",
24+
"count": 0,
25+
"createdAt": "2020-09-29T10:39:39.000Z",
26+
"updatedAt": "2020-09-29T10:39:39.000Z"
27+
},
28+
{
29+
"id": 57097,
30+
"group_id": 21448,
31+
"project_id": 7617,
32+
"name": "yes",
33+
"count": 1,
34+
"createdAt": "2020-09-29T10:39:39.000Z",
35+
"updatedAt": "2020-09-29T10:48:18.000Z"
36+
}
37+
]
38+
}
39+
]
40+
},
41+
{
42+
"id": 56821,
43+
"project_id": 7617,
44+
"name": "Large vehicle",
45+
"color": "#2ba36d",
46+
"count": 1,
47+
"createdAt": "2020-09-29T10:39:39.000Z",
48+
"updatedAt": "2020-09-29T10:48:18.000Z",
49+
"attribute_groups": [
50+
{
51+
"id": 21449,
52+
"class_id": 56821,
53+
"name": "small",
54+
"is_multiselect": 0,
55+
"createdAt": "2020-09-29T10:39:39.000Z",
56+
"updatedAt": "2020-09-29T10:39:39.000Z",
57+
"attributes": [
58+
{
59+
"id": 57098,
60+
"group_id": 21449,
61+
"project_id": 7617,
62+
"name": "yes",
63+
"count": 0,
64+
"createdAt": "2020-09-29T10:39:39.000Z",
65+
"updatedAt": "2020-09-29T10:39:39.000Z"
66+
},
67+
{
68+
"id": 57099,
69+
"group_id": 21449,
70+
"project_id": 7617,
71+
"name": "no",
72+
"count": 1,
73+
"createdAt": "2020-09-29T10:39:39.000Z",
74+
"updatedAt": "2020-09-29T10:48:18.000Z"
75+
}
76+
]
77+
}
78+
]
79+
},
80+
{
81+
"id": 56822,
82+
"project_id": 7617,
83+
"name": "Pedestrian",
84+
"color": "#d4da03",
85+
"count": 3,
86+
"createdAt": "2020-09-29T10:39:39.000Z",
87+
"updatedAt": "2020-09-29T10:48:18.000Z",
88+
"attribute_groups": []
89+
},
90+
{
91+
"id": 56823,
92+
"project_id": 7617,
93+
"name": "Two wheeled vehicle",
94+
"color": "#f11aec",
95+
"count": 1,
96+
"createdAt": "2020-09-29T10:39:39.000Z",
97+
"updatedAt": "2020-09-29T10:48:18.000Z",
98+
"attribute_groups": []
99+
},
100+
{
101+
"id": 56824,
102+
"project_id": 7617,
103+
"name": "Traffic sign",
104+
"color": "#d8a7fd",
105+
"count": 9,
106+
"createdAt": "2020-09-29T10:39:39.000Z",
107+
"updatedAt": "2020-09-29T10:48:18.000Z",
108+
"attribute_groups": []
109+
}
110+
]

0 commit comments

Comments
 (0)