Skip to content

Commit

Permalink
Add async download functionality for projects
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenAnpu committed Nov 10, 2024
1 parent 14f1d8a commit eaf1fe6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git+https://github.com/supervisely/supervisely.git@project_download_async
13 changes: 11 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import os
from distutils import util

Expand Down Expand Up @@ -118,16 +119,24 @@ def download(project: sly.Project) -> str:

sly.logger.info(f"Starting download of project {project.name} to {download_dir}...")

sly.Project.download(
loop = sly.fs.get_or_create_event_loop()
coro = sly.Project.download_async(
api,
project_id,
dest_dir=download_dir,
dataset_ids=dataset_ids,
log_progress=True,
batch_size=batch_size,
save_image_meta=True,
save_images=save_images,
)
if loop.is_running():
sly.logger.debug("Loop is already running, using run_coroutine_threadsafe")
future = asyncio.run_coroutine_threadsafe(coro, loop)
future.result()
else:
sly.logger.debug("Loop is not running, using run_until_complete")
loop.run_until_complete(coro)

meta_path = os.path.join(download_dir, "meta.json")
meta = sly.ProjectMeta.from_json(sly.json.load_json_file(meta_path))
if any(obj_cls.geometry_type == sly.Cuboid2d for obj_cls in meta.obj_classes):
Expand Down

0 comments on commit eaf1fe6

Please sign in to comment.