Skip to content

Commit 97bba85

Browse files
Vaghinak BasentsyanVaghinak Basentsyan
authored andcommitted
added progres bar for annotations upload
1 parent 0840c0a commit 97bba85

File tree

11 files changed

+208
-237
lines changed

11 files changed

+208
-237
lines changed

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
minversion = 3.0
33
log_cli=true
44
python_files = test_*.py
5-
;addopts = -n32 --dist=loadscope
5+
addopts = -n32 --dist=loadscope

src/superannotate/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@
286286

287287
__author__ = "Superannotate"
288288

289-
290-
file_dir = os.path.split(os.path.realpath(__file__))[0]
291-
sys.path.append(file_dir)
292-
logging.config.fileConfig(os.path.join(file_dir, "logging.conf"))
293-
logger = logging.getLogger()
289+
WORKING_DIR = os.path.split(os.path.realpath(__file__))[0]
290+
sys.path.append(WORKING_DIR)
291+
logging.config.fileConfig(
292+
os.path.join(WORKING_DIR, "logging.conf"), disable_existing_loggers=False
293+
)

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

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from typeguard import typechecked
4747

4848

49-
logger = logging.getLogger()
49+
logger = logging.getLogger("root")
5050
controller = Controller(logger)
5151

5252

@@ -2232,6 +2232,7 @@ def download_image(
22322232
)
22332233
if response.errors:
22342234
raise AppException(response.errors)
2235+
logger.info(f"Downloaded image {image_name} to {local_dir_path} ")
22352236
return response.data
22362237

22372238

@@ -2418,28 +2419,19 @@ def upload_annotations_from_folder_to_project(
24182419
logger.info(
24192420
"Uploading %s annotations to project %s.", len(annotation_paths), project_name
24202421
)
2421-
2422-
uploaded_annotations = []
2423-
failed_annotations = []
2424-
missing_annotations = []
2425-
chunk_size = 50
2422+
use_case = controller.upload_annotations_from_folder(
2423+
project_name=project_name,
2424+
folder_name=folder_name,
2425+
folder_path=folder_path,
2426+
annotation_paths=annotation_paths, # noqa: E203
2427+
client_s3_bucket=from_s3_bucket,
2428+
)
24262429
with tqdm(
24272430
total=len(annotation_paths), desc="Uploading annotations"
24282431
) as progress_bar:
2429-
for i in range(0, len(annotation_paths), chunk_size):
2430-
response = controller.upload_annotations_from_folder(
2431-
project_name=project_name,
2432-
folder_name=folder_name,
2433-
folder_path=folder_path,
2434-
annotation_paths=annotation_paths[i : i + chunk_size], # noqa: E203
2435-
client_s3_bucket=from_s3_bucket,
2436-
)
2437-
if response.data:
2438-
uploaded_annotations.extend(response.data[0])
2439-
missing_annotations.extend(response.data[1])
2440-
failed_annotations.extend(response.data[2])
2441-
progress_bar.update(chunk_size)
2442-
return uploaded_annotations, failed_annotations, missing_annotations
2432+
for _ in use_case.execute():
2433+
progress_bar.update(1)
2434+
return use_case.data
24432435

24442436

24452437
@Trackable
@@ -2499,31 +2491,20 @@ def upload_preannotations_from_folder_to_project(
24992491
logger.info(
25002492
"Uploading %s annotations to project %s.", len(annotation_paths), project_name
25012493
)
2502-
uploaded_annotations = []
2503-
failed_annotations = []
2504-
missing_annotations = []
2505-
chunk_size = 10
2494+
use_case = controller.upload_annotations_from_folder(
2495+
project_name=project_name,
2496+
folder_name=folder_name,
2497+
folder_path=folder_path,
2498+
annotation_paths=annotation_paths, # noqa: E203
2499+
client_s3_bucket=from_s3_bucket,
2500+
is_pre_annotations=True,
2501+
)
25062502
with tqdm(
2507-
total=len(annotation_paths), desc="Uploading pre annotations"
2503+
total=len(annotation_paths), desc="Uploading annotations"
25082504
) as progress_bar:
2509-
for i in range(0, len(annotation_paths), chunk_size):
2510-
response = controller.upload_annotations_from_folder(
2511-
project_name=project_name,
2512-
folder_name=folder_name,
2513-
folder_path=folder_path,
2514-
annotation_paths=annotation_paths[i : i + chunk_size], # noqa: E203
2515-
client_s3_bucket=from_s3_bucket,
2516-
is_pre_annotations=True,
2517-
)
2518-
if response.errors:
2519-
logger.warning(response.errors)
2520-
if response.data:
2521-
uploaded_annotations.extend(response.data[0])
2522-
missing_annotations.extend(response.data[1])
2523-
failed_annotations.extend(response.data[2])
2524-
progress_bar.update(chunk_size)
2525-
2526-
return uploaded_annotations, failed_annotations, missing_annotations
2505+
for _ in use_case.execute():
2506+
progress_bar.update(1)
2507+
return use_case.data
25272508

25282509

25292510
@Trackable

src/superannotate/lib/core/plugin.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,17 @@ def draw_point(self, x, y, fill_color, outline_color, size=2):
147147
self._image.convert("RGBA")
148148
self._image = Image.alpha_composite(self._image, image)
149149

150-
def draw_ellipse(self, cx, cy, rx, ry, fill_color, outline_color):
150+
def draw_ellipse(self, cx, cy, rx, ry, fill_color, outline_color, fixed=False):
151151
image = self.get_empty_image()
152152
draw = ImageDraw.Draw(image)
153-
draw.ellipse(
154-
(cx - rx, cy - ry, cx + rx, cy + ry), fill=fill_color, outline=outline_color
155-
)
153+
if fixed:
154+
draw.ellipse((cx, cy, rx, ry), fill=fill_color, outline=outline_color)
155+
else:
156+
draw.ellipse(
157+
(cx - rx, cy - ry, cx + rx, cy + ry),
158+
fill=fill_color,
159+
outline=outline_color,
160+
)
156161
self._image.convert("RGBA")
157162
self._image = Image.alpha_composite(self._image, image)
158163

0 commit comments

Comments
 (0)