Skip to content

Commit

Permalink
time downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
vorozhkog committed Nov 28, 2024
1 parent eb82571 commit 6448cd9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 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
4 changes: 3 additions & 1 deletion local.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEAM_ID = 431
WORKSPACE_ID = 1019
PROJECT_ID = 42759
PROJECT_ID = 41703

# options: "images" "annotations"
modal.state.selectedOutput="images"
Expand All @@ -9,3 +9,5 @@ modal.state.selectedFilter="all"
modal.state.allDatasets=True
modal.state.datasets=[71754]
modal.state.captions=False

LOGLEVEL = "debug"
28 changes: 18 additions & 10 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import convert_geometry
import functions as f
import workflow as w
from tinytimer import Timer

# region constants
USER_NAME = "Supervisely"
Expand Down Expand Up @@ -82,7 +83,7 @@ def export_to_coco(api: sly.Api) -> None:
min_report_percent=5,
)

dataset_path = os.path.join(img_dir, project.name, dataset.name)
dataset_path = os.path.join(coco_dataset_dir, project.name, dataset.name)
os.makedirs(dataset_path, exist_ok=True)

if selected_output == "images":
Expand All @@ -93,15 +94,18 @@ def export_to_coco(api: sly.Api) -> None:
else:
semaphore = None
# api._get_default_semaphore()
coro = api.image.download_paths_async(
image_ids, paths, semaphore, progress_cb=ds_progress.iters_done_report

with Timer() as t:
coro = api.image.download_paths_async(image_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(image_ids)} images ({t.elapsed/len(image_ids):.4f} seconds per image)"
)
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)

for batch in sly.batched(images):
batch_ids = [image_info.id for image_info in batch]
Expand Down Expand Up @@ -133,7 +137,11 @@ def export_to_coco(api: sly.Api) -> None:

# if selected_output == "images":
# image_paths = [os.path.join(img_dir, image_info.name) for image_info in batch]
# f.download_batch_with_retry(api, dataset.id, image_ids, image_paths)
# with Timer() as t:
# f.download_batch_with_retry(api, dataset.id, image_ids, image_paths)
# sly.logger.info(
# f"Downloading time: {t.elapsed:.4f} seconds per {len(image_ids)} images ({t.elapsed/len(image_ids):.4f} seconds per image)"
# )

# ann_infos = api.annotation.download_batch(dataset.id, image_ids)
# anns = []
Expand Down

0 comments on commit 6448cd9

Please sign in to comment.