Skip to content

Commit

Permalink
[PLA-683][external] 2 Minor fixes for importing of PASCAL VOC annotat…
Browse files Browse the repository at this point in the history
…ions (#783)

* Fixed mislabelled default arg value

* Added support for importing PASCAL VOC annotations to folders + unit test

* Fixed misconfigured querystring filter name in fetch_remote_files()

* removed test file
  • Loading branch information
JBWilkie committed Mar 7, 2024
1 parent d144a43 commit b9d1430
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion darwin/cli_functions.py
Expand Up @@ -881,7 +881,7 @@ def dataset_import(
import_reviewers : bool, default: False
If ``True`` it will import the reviewers from the files to the dataset, if .
If ``False`` it will not import the reviewers.
use_multi_cpu : bool, default: True
use_multi_cpu : bool, default: False
If ``True`` it will use all multiple CPUs to speed up the import process.
cpu_limit : Optional[int], default: Core count - 2
The maximum number of CPUs to use for the import process.
Expand Down
5 changes: 4 additions & 1 deletion darwin/importer/formats/pascal_voc.py
Expand Up @@ -3,6 +3,7 @@
from typing import List, Optional

import darwin.datatypes as dt
from darwin.path_utils import deconstruct_full_path


def parse_path(path: Path) -> Optional[dt.AnnotationFile]:
Expand Down Expand Up @@ -57,8 +58,10 @@ def parse_path(path: Path) -> Optional[dt.AnnotationFile]:
)
annotation_classes = {annotation.annotation_class for annotation in annotations}

remote_path, filename = deconstruct_full_path(filename)

return dt.AnnotationFile(
path, filename, annotation_classes, annotations, remote_path="/"
path, filename, annotation_classes, annotations, remote_path=remote_path
)


Expand Down
2 changes: 1 addition & 1 deletion darwin/importer/importer.py
Expand Up @@ -221,7 +221,7 @@ def get_remote_files(
for i in range(0, len(filenames), chunk_size):
chunk = filenames[i : i + chunk_size]
for remote_file in dataset.fetch_remote_files(
{"types": "image,playback_video,video_frame", "filenames": chunk}
{"types": "image,playback_video,video_frame", "item_names": chunk}
):
slot_name = _get_slot_name(remote_file)
remote_files[remote_file.full_path] = (remote_file.id, slot_name)
Expand Down
14 changes: 14 additions & 0 deletions tests/darwin/importer/formats/import_pascalvoc_test.py
Expand Up @@ -171,3 +171,17 @@ def test_returns_annotation_file_with_correct_annotations_with_float_values(
assert annotation.subs == []

assert annotation_file.remote_path == "/"

def test_deconstructs_filepath_properly_if_folder_included_in_filename(
self, annotation_path: Path
):
annotation_path.write_text(
"<root><filename>folder/image.jpg</filename><object><name>Class</name><bndbox><xmin>10</xmin><xmax>10</xmax><ymin>10</ymin><ymax>10</ymax></bndbox></object></root>"
)

annotation_file = parse_path(annotation_path)

assert annotation_file is not None
assert annotation_file.path == annotation_path
assert annotation_file.filename == "image.jpg"
assert annotation_file.remote_path == "/folder"

0 comments on commit b9d1430

Please sign in to comment.