Skip to content

Commit

Permalink
Fix for pulling releases containing folders but in a flat structure (…
Browse files Browse the repository at this point in the history
…WIP)
  • Loading branch information
JBWilkie committed Oct 27, 2023
1 parent 118c4f4 commit db229fc
Show file tree
Hide file tree
Showing 3 changed files with 258 additions and 76 deletions.
5 changes: 4 additions & 1 deletion darwin/dataset/local_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,12 @@ def _setup_annotations_and_images(
split_type,
):
# Find all the annotations and their corresponding images
with_folders = any([item.is_dir() for item in images_dir.iterdir()])

This comment has been minimized.

Copy link
@JBWilkie

JBWilkie Oct 27, 2023

Author Collaborator

This is the important part of the changes - We check if there are any folders in the pulled release then add this as an argument to get_image_path_from_stream()

for annotation_path in sorted(annotations_dir.glob("**/*.json")):
darwin_json = stream_darwin_json(annotation_path)
image_path = get_image_path_from_stream(darwin_json, images_dir)
image_path = get_image_path_from_stream(
darwin_json, images_dir, with_folders
)
if image_path.exists():
self.images_path.append(image_path)
self.annotations_path.append(annotation_path)
Expand Down
9 changes: 6 additions & 3 deletions darwin/dataset/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def exhaust_generator(
Exhausts the generator passed as parameter. Can be done multi threaded if desired.
Creates and returns a coco record from the given annotation.
Uses ``BoxMode.XYXY_ABS`` from ``detectron2.structures`` if available, defaults to ``box_mode = 0``
otherwise.
Parameters
Expand Down Expand Up @@ -571,9 +571,10 @@ def _map_annotations_to_images(
images_paths = []
annotations_paths = []
invalid_annotation_paths = []
with_folders = any([item.is_dir() for item in images_dir.iterdir()])
for annotation_path in annotations_dir.glob("**/*.json"):
darwin_json = stream_darwin_json(annotation_path)
image_path = get_image_path_from_stream(darwin_json, images_dir)
image_path = get_image_path_from_stream(darwin_json, images_dir, with_folders)
if image_path.exists():
images_paths.append(image_path)
annotations_paths.append(annotation_path)
Expand All @@ -583,7 +584,9 @@ def _map_annotations_to_images(
invalid_annotation_paths.append(annotation_path)
continue
else:
raise ValueError(f"Annotation ({annotation_path}) does not have a corresponding image")
raise ValueError(
f"Annotation ({annotation_path}) does not have a corresponding image"
)

return images_paths, annotations_paths, invalid_annotation_paths

Expand Down
Loading

1 comment on commit db229fc

@JBWilkie
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of this is accidentally applied linting / fotmatting that we're not applying to anything outside darwin/future

Please sign in to comment.