Skip to content

Commit

Permalink
[IO-483][external] Fix dataset pull with non-unique item names (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
rslota authored Dec 2, 2022
1 parent c20eea9 commit 9b64d8f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion darwin/dataset/remote_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
Union,
)

from rich.console import Console

from darwin.dataset.download_manager import download_all_images_from_annotations
from darwin.dataset.identifier import DatasetIdentifier
from darwin.dataset.release import Release
Expand All @@ -41,7 +43,6 @@
from darwin.item import DatasetItem
from darwin.item_sorter import ItemSorter
from darwin.utils import parse_darwin_json, split_video_annotation, urljoin
from rich.console import Console

if TYPE_CHECKING:
from darwin.client import Client
Expand Down Expand Up @@ -259,6 +260,8 @@ def pull(
except PermissionError:
print(f"Could not remove dataset in {annotations_dir}. Permission denied.")
annotations_dir.mkdir(parents=True, exist_ok=False)
stems: dict = {}

# Move the annotations into the right folder and rename them to have the image
# original filename as contained in the json
for annotation_path in tmp_dir.glob("*.json"):
Expand All @@ -267,6 +270,12 @@ def pull(
continue

filename = Path(annotation.filename).stem
if filename in stems:
stems[filename] += 1
filename = f"{filename}_{stems[filename]}"
else:
stems[filename] = 1

destination_name = annotations_dir / f"{filename}{annotation_path.suffix}"
shutil.move(str(annotation_path), str(destination_name))

Expand Down

0 comments on commit 9b64d8f

Please sign in to comment.