Skip to content

Commit 6390193

Browse files
Vaghinak BasentsyanVaghinak Basentsyan
authored andcommitted
tod
1 parent e31a91a commit 6390193

File tree

11 files changed

+3345
-31
lines changed

11 files changed

+3345
-31
lines changed

src/superannotate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
from superannotate.lib.app.interface.sdk_interface import create_project
6161
from superannotate.lib.app.interface.sdk_interface import create_project_from_metadata
6262
from superannotate.lib.app.interface.sdk_interface import delete_annotation_class
63+
from superannotate.lib.app.interface.sdk_interface import delete_annotations
6364
from superannotate.lib.app.interface.sdk_interface import (
6465
delete_contributor_to_team_invitation,
6566
)
@@ -89,7 +90,6 @@
8990
from superannotate.lib.app.interface.sdk_interface import (
9091
get_project_default_image_quality_in_editor,
9192
)
92-
from superannotate.lib.app.interface.sdk_interface import delete_annotations
9393
from superannotate.lib.app.interface.sdk_interface import get_project_image_count
9494
from superannotate.lib.app.interface.sdk_interface import get_project_metadata
9595
from superannotate.lib.app.interface.sdk_interface import get_project_settings

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ def get_image_annotations(project: Union[str, dict], image_name: str):
14981498
project_name=project_name, folder_name=folder_name, image_name=image_name
14991499
)
15001500
if res.errors:
1501-
raise AppValidationException(res)
1501+
raise AppException(res)
15021502
return res.data
15031503

15041504

@@ -3609,4 +3609,8 @@ def delete_annotations(project: str, image_names: List[str] = None):
36093609

36103610
project_name, folder_name = extract_project_folder(project)
36113611

3612-
controller.delete_annotations(project_name=project, folder_name=folder_name, image_names=image_names)
3612+
response = controller.delete_annotations(
3613+
project_name=project, folder_name=folder_name, image_names=image_names
3614+
)
3615+
if response.errors:
3616+
raise AppException(response.errors)

src/superannotate/lib/core/serviceproviders.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,16 @@ def run_prediction(
297297
):
298298
raise NotImplementedError
299299

300-
def delete_image_annotations(self, team_id: int, project_id: int, folder_id: int = None, image_names: List[str] = None) -> int:
300+
def delete_image_annotations(
301+
self,
302+
team_id: int,
303+
project_id: int,
304+
folder_id: int = None,
305+
image_names: List[str] = None,
306+
) -> int:
301307
raise NotImplementedError
302308

303-
def get_annotations_delete_progress(self, team_id: int, project_id: int, poll_id: int):
309+
def get_annotations_delete_progress(
310+
self, team_id: int, project_id: int, poll_id: int
311+
):
304312
raise NotImplementedError

src/superannotate/lib/core/usecases.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,6 +2082,9 @@ def execute(self):
20822082
file_postfix = "___objects.json"
20832083
else:
20842084
file_postfix = "___pixel.json"
2085+
data["annotation_mask_filename"] = f"{self._image_name}___save.png"
2086+
data["annotation_json_filename"] = f"{self._image_name}{file_postfix}"
2087+
20852088
response = requests.get(
20862089
url=credentials["annotation_json_path"]["url"],
20872090
headers=credentials["annotation_json_path"]["headers"],
@@ -2099,7 +2102,6 @@ def execute(self):
20992102
headers=annotation_blue_map_creds["headers"],
21002103
)
21012104
data["annotation_mask"] = io.BytesIO(response.content)
2102-
data["annotation_mask_filename"] = f"{self._image_name}___save.png"
21032105

21042106
self._response.data = data
21052107

@@ -4487,12 +4489,13 @@ def execute(self):
44874489

44884490
class DeleteAnnotations(BaseUseCase):
44894491
POLL_AWAIT_TIME = 2
4492+
44904493
def __init__(
4491-
self,
4492-
project: ProjectEntity,
4493-
folder: FolderEntity,
4494-
backend_service: SuerannotateServiceProvider,
4495-
image_names: Optional[List[str]] = None,
4494+
self,
4495+
project: ProjectEntity,
4496+
folder: FolderEntity,
4497+
backend_service: SuerannotateServiceProvider,
4498+
image_names: Optional[List[str]] = None,
44964499
):
44974500
super().__init__()
44984501
self._project = project
@@ -4504,20 +4507,34 @@ def execute(self) -> Response:
45044507

45054508
if self._folder.name == "root" and not self._image_names:
45064509
poll_id = self._backend_service.delete_image_annotations(
4507-
project_id=self._project.uuid,
4508-
team_id=self._project.team_id,
4510+
project_id=self._project.uuid, team_id=self._project.team_id,
45094511
)
45104512
else:
45114513
poll_id = self._backend_service.delete_image_annotations(
45124514
project_id=self._project.uuid,
45134515
team_id=self._project.team_id,
45144516
folder_id=self._folder.uuid,
45154517
image_names=self._image_names,
4516-
)
4518+
)
45174519

45184520
if poll_id:
45194521
timeout_start = time.time()
45204522
while time.time() < timeout_start + self.POLL_AWAIT_TIME:
4521-
var = self._backend_service.get_annotations_delete_progress(
4522-
self._project.uuid, self._project.team_id, poll_id)
4523-
4523+
progress = int(
4524+
self._backend_service.get_annotations_delete_progress(
4525+
project_id=self._project.uuid,
4526+
team_id=self._project.team_id,
4527+
poll_id=poll_id,
4528+
).get("process", -1)
4529+
)
4530+
if 0 < progress < 100:
4531+
logger.info(f"Delete annotations in progress {progress}/100")
4532+
elif 0 > progress:
4533+
self._response.errors = "Annotations delete fails."
4534+
break
4535+
else:
4536+
logger.info(f"Annotations deleted")
4537+
break
4538+
else:
4539+
self._response.errors = AppException("Invalid image names.")
4540+
return self._response

src/superannotate/lib/infrastructure/controller.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,13 +1447,18 @@ def search_models(
14471447
)
14481448
return use_case.execute()
14491449

1450-
def delete_annotations(self, project_name: str, folder_name: str, image_names: Optional[List[str]] = None):
1450+
def delete_annotations(
1451+
self,
1452+
project_name: str,
1453+
folder_name: str,
1454+
image_names: Optional[List[str]] = None,
1455+
):
14511456
project = self._get_project(project_name)
14521457
folder = self._get_folder(project, folder_name)
14531458
use_case = usecases.DeleteAnnotations(
14541459
project=project,
14551460
folder=folder,
14561461
backend_service=self._backend_client,
1457-
image_names=image_names
1462+
image_names=image_names,
14581463
)
1459-
return use_case.execute()
1464+
return use_case.execute()

src/superannotate/lib/infrastructure/services.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,13 @@ def run_prediction(
948948
)
949949
return res.json()
950950

951-
def delete_image_annotations(self, team_id: int, project_id: int, folder_id: int = None,
952-
image_names: List[str] = None) -> int:
951+
def delete_image_annotations(
952+
self,
953+
team_id: int,
954+
project_id: int,
955+
folder_id: int = None,
956+
image_names: List[str] = None,
957+
) -> int:
953958
delete_annotations_url = urljoin(self.api_url, self.URL_DELETE_ANNOTATIONS)
954959
params = {"team_id": team_id, "project_id": project_id}
955960
data = {}
@@ -958,20 +963,19 @@ def delete_image_annotations(self, team_id: int, project_id: int, folder_id: int
958963
if image_names:
959964
data["image_names"] = image_names
960965
response = self._request(
961-
delete_annotations_url,
962-
"post",
963-
params=params,
964-
data=data
966+
delete_annotations_url, "post", params=params, data=data
965967
)
966968
if response.ok:
967969
return response.json()["poll_id"]
968970

969-
def get_annotations_delete_progress(self, team_id: int, project_id: int, poll_id: int):
971+
def get_annotations_delete_progress(
972+
self, team_id: int, project_id: int, poll_id: int
973+
):
970974
get_progress_url = urljoin(self.api_url, self.URL_DELETE_ANNOTATIONS_PROGRESS)
971975

972976
response = self._request(
973977
get_progress_url,
974978
"get",
975-
params={"team_id": team_id, "project_id": project_id, "poll_id": poll_id}
979+
params={"team_id": team_id, "project_id": project_id, "poll_id": poll_id},
976980
)
977-
return response.json()
981+
return response.json()
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
[
2+
{
3+
"id": 55917,
4+
"project_id": 11979,
5+
"name": "Personal vehicle",
6+
"color": "#ecb65f",
7+
"count": 25,
8+
"createdAt": "2020-10-12T11:35:20.000Z",
9+
"updatedAt": "2020-10-12T11:48:19.000Z",
10+
"attribute_groups": [
11+
{
12+
"id": 17245,
13+
"class_id": 55917,
14+
"name": "Num doors",
15+
"is_multiselect": 0,
16+
"createdAt": "2020-10-12T11:35:20.000Z",
17+
"updatedAt": "2020-10-12T11:35:20.000Z",
18+
"attributes": [
19+
{
20+
"id": 62792,
21+
"group_id": 17245,
22+
"project_id": 11979,
23+
"name": "2",
24+
"count": 1,
25+
"createdAt": "2020-10-12T11:35:20.000Z",
26+
"updatedAt": "2020-10-12T11:46:28.000Z"
27+
},
28+
{
29+
"id": 62793,
30+
"group_id": 17245,
31+
"project_id": 11979,
32+
"name": "4",
33+
"count": 1,
34+
"createdAt": "2020-10-12T11:35:20.000Z",
35+
"updatedAt": "2020-10-12T11:35:20.000Z"
36+
}
37+
]
38+
}
39+
]
40+
},
41+
{
42+
"id": 55918,
43+
"project_id": 11979,
44+
"name": "Large vehicle",
45+
"color": "#737b28",
46+
"count": 1,
47+
"createdAt": "2020-10-12T11:35:20.000Z",
48+
"updatedAt": "2020-10-12T11:48:19.000Z",
49+
"attribute_groups": [
50+
{
51+
"id": 17246,
52+
"class_id": 55918,
53+
"name": "swedish",
54+
"is_multiselect": 0,
55+
"createdAt": "2020-10-12T11:35:20.000Z",
56+
"updatedAt": "2020-10-12T11:35:20.000Z",
57+
"attributes": [
58+
{
59+
"id": 62794,
60+
"group_id": 17246,
61+
"project_id": 11979,
62+
"name": "yes",
63+
"count": 0,
64+
"createdAt": "2020-10-12T11:35:20.000Z",
65+
"updatedAt": "2020-10-12T11:35:20.000Z"
66+
},
67+
{
68+
"id": 62795,
69+
"group_id": 17246,
70+
"project_id": 11979,
71+
"name": "no",
72+
"count": 1,
73+
"createdAt": "2020-10-12T11:35:20.000Z",
74+
"updatedAt": "2020-10-12T11:46:28.000Z"
75+
}
76+
]
77+
},
78+
{
79+
"id": 17247,
80+
"class_id": 55918,
81+
"name": "Num doors",
82+
"is_multiselect": 0,
83+
"createdAt": "2020-10-12T11:35:20.000Z",
84+
"updatedAt": "2020-10-12T11:35:20.000Z",
85+
"attributes": [
86+
{
87+
"id": 62796,
88+
"group_id": 17247,
89+
"project_id": 11979,
90+
"name": "2",
91+
"count": 0,
92+
"createdAt": "2020-10-12T11:35:20.000Z",
93+
"updatedAt": "2020-10-12T11:35:20.000Z"
94+
},
95+
{
96+
"id": 62797,
97+
"group_id": 17247,
98+
"project_id": 11979,
99+
"name": "4",
100+
"count": 1,
101+
"createdAt": "2020-10-12T11:35:20.000Z",
102+
"updatedAt": "2020-10-12T11:46:28.000Z"
103+
}
104+
]
105+
}
106+
]
107+
},
108+
{
109+
"id": 55919,
110+
"project_id": 11979,
111+
"name": "Human",
112+
"color": "#e4542b",
113+
"count": 9,
114+
"createdAt": "2020-10-12T11:35:20.000Z",
115+
"updatedAt": "2020-10-12T11:48:14.000Z",
116+
"attribute_groups": [
117+
{
118+
"id": 17248,
119+
"class_id": 55919,
120+
"name": "Height",
121+
"is_multiselect": 0,
122+
"createdAt": "2020-10-12T11:35:20.000Z",
123+
"updatedAt": "2020-10-12T11:35:20.000Z",
124+
"attributes": [
125+
{
126+
"id": 62798,
127+
"group_id": 17248,
128+
"project_id": 11979,
129+
"name": "Tall",
130+
"count": 0,
131+
"createdAt": "2020-10-12T11:35:20.000Z",
132+
"updatedAt": "2020-10-12T11:35:20.000Z"
133+
},
134+
{
135+
"id": 62799,
136+
"group_id": 17248,
137+
"project_id": 11979,
138+
"name": "Short",
139+
"count": 0,
140+
"createdAt": "2020-10-12T11:35:20.000Z",
141+
"updatedAt": "2020-10-12T11:35:20.000Z"
142+
}
143+
]
144+
}
145+
]
146+
},
147+
{
148+
"id": 55920,
149+
"project_id": 11979,
150+
"name": "Plant",
151+
"color": "#46ccb2",
152+
"count": 0,
153+
"createdAt": "2020-10-12T11:35:20.000Z",
154+
"updatedAt": "2020-10-12T11:35:20.000Z",
155+
"attribute_groups": []
156+
}
157+
]
209 KB
Loading
10.6 KB
Loading

0 commit comments

Comments
 (0)