Skip to content

Commit

Permalink
add async
Browse files Browse the repository at this point in the history
  • Loading branch information
vorozhkog committed Nov 29, 2024
1 parent 29c900d commit bee34e6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
supervisely==6.73.162
git+https://github.com/supervisely/supervisely.git@project_download_async
10 changes: 7 additions & 3 deletions local.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
TEAM_ID = 448
WORKSPACE_ID = 690
PROJECT_ID = 35637
# TEAM_ID = 448
# WORKSPACE_ID = 690
# PROJECT_ID = 35637

TEAM_ID = 431
WORKSPACE_ID = 1019
PROJECT_ID = 40721
29 changes: 27 additions & 2 deletions src/convert_sly_to_yolov5.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from dotenv import load_dotenv
import supervisely as sly
from workflow import Workflow
import asyncio
from tinytimer import Timer

# region constants
TRAIN_TAG_NAME = "train"
Expand Down Expand Up @@ -178,8 +180,31 @@ def _add_to_split(image_id, img_name, split_ids, split_image_paths, labels_dir,
)
train_count += 1

api.image.download_paths(dataset.id, train_ids, train_image_paths)
api.image.download_paths(dataset.id, val_ids, val_image_paths)
if api.server_address.startswith("https://"):
semaphore = asyncio.Semaphore(100)
else:
semaphore = None

ids = train_ids + val_ids
paths = train_image_paths + val_image_paths

with Timer() as t:
coro = api.image.download_paths_async(ids, paths, semaphore)
loop = sly.utils.get_or_create_event_loop()
if loop.is_running():
future = asyncio.run_coroutine_threadsafe(coro, loop)
future.result()
else:
loop.run_until_complete(coro)
sly.logger.info(
f"Downloading time: {t.elapsed:.4f} seconds per {len(ids)} images ({t.elapsed/len(ids):.4f} seconds per image)"
)
# with Timer() as t:
# api.image.download_paths(dataset.id, train_ids, train_image_paths)
# api.image.download_paths(dataset.id, val_ids, val_image_paths)
# sly.logger.info(
# f"Downloading time: {t.elapsed:.4f} seconds per {len(train_ids + val_ids) } images ({t.elapsed/len(train_ids + val_ids):.4f} seconds per image)"
# )

progress.iters_done_report(len(batch))
if unsupported_shapes > 0:
Expand Down

0 comments on commit bee34e6

Please sign in to comment.