Skip to content

Commit

Permalink
Include transitions from attributes to no attributes in video annotat…
Browse files Browse the repository at this point in the history
…ion importing
  • Loading branch information
JBWilkie committed Jan 29, 2025
1 parent 68e080b commit 4942e35
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 deletions.
2 changes: 1 addition & 1 deletion darwin/dataset/download_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ def _remove_empty_directories(images_path: Path) -> bool:


def _check_for_duplicate_local_filepaths(
download_functions: List[Callable[[], None]]
download_functions: List[Callable[[], None]],
) -> None:
"""
If pulling a release without folders, check for duplicate filepaths in the download functions.
Expand Down
2 changes: 1 addition & 1 deletion darwin/future/core/items/uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def _build_layout(item: UploadItem) -> Dict:


async def _build_payload_items(
items_and_paths: List[Tuple[UploadItem, Path]]
items_and_paths: List[Tuple[UploadItem, Path]],
) -> List[Dict]:
"""
Builds the payload for the items to be registered for upload
Expand Down
13 changes: 9 additions & 4 deletions darwin/importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@


def _build_main_annotations_lookup_table(
annotation_classes: List[Dict[str, Unknown]]
annotation_classes: List[Dict[str, Unknown]],
) -> Dict[str, Unknown]:
MAIN_ANNOTATION_TYPES = [
"bounding_box",
Expand Down Expand Up @@ -484,7 +484,7 @@ def _serialize_item_level_properties(


def _parse_metadata_file(
metadata_path: Union[Path, bool]
metadata_path: Union[Path, bool],
) -> Tuple[List[PropertyClass], List[Dict[str, str]]]:
if isinstance(metadata_path, Path):
metadata = parse_metadata(metadata_path)
Expand Down Expand Up @@ -1001,7 +1001,7 @@ def _import_properties(


def _normalize_item_properties(
item_properties: Union[Dict[str, Dict[str, Any]], List[Dict[str, str]]]
item_properties: Union[Dict[str, Dict[str, Any]], List[Dict[str, str]]],
) -> Dict[str, Dict[str, Any]]:
"""
Normalizes item properties to a common dictionary format.
Expand Down Expand Up @@ -1586,6 +1586,7 @@ def _handle_subs(
data: dt.DictFreeForm,
annotation_class_id: str,
attributes: Dict[str, dt.UnknownType],
include_empty_attributes: Optional[bool] = False,
) -> dt.DictFreeForm:
for sub in annotation.subs:
if sub.annotation_type == "text":
Expand All @@ -1609,6 +1610,9 @@ def _handle_subs(
else:
data[sub.annotation_type] = sub.data

if not data.get("attributes") and include_empty_attributes:
data["attributes"] = {"attributes": []}

return data


Expand Down Expand Up @@ -1707,6 +1711,7 @@ def _get_annotation_data(
_format_polygon_for_import(annotation, data),
annotation_class_id,
attributes,
include_empty_attributes=True,
),
)
else:
Expand Down Expand Up @@ -2046,7 +2051,7 @@ def _overwrite_warning(


def _get_annotation_format(
importer: Callable[[Path], Union[List[dt.AnnotationFile], dt.AnnotationFile, None]]
importer: Callable[[Path], Union[List[dt.AnnotationFile], dt.AnnotationFile, None]],
) -> str:
"""
Returns the annotation format of the importer used to parse local annotation files
Expand Down
4 changes: 2 additions & 2 deletions darwin/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ def _parse_annotators(annotators: List[Dict[str, Any]]) -> List[dt.AnnotationAut


def _parse_properties(
properties: List[Dict[str, Any]]
properties: List[Dict[str, Any]],
) -> Optional[List[SelectedProperty]]:
selected_properties = []
for property in properties:
Expand Down Expand Up @@ -1512,7 +1512,7 @@ def _parse_version(data: dict) -> dt.AnnotationFileVersion:


def _data_to_annotations(
data: Dict[str, Any]
data: Dict[str, Any],
) -> List[Union[dt.Annotation, dt.VideoAnnotation]]:
raw_image_annotations = filter(
lambda annotation: (
Expand Down
2 changes: 1 addition & 1 deletion e2e_tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def export_release(


def delete_annotation_uuids(
annotations: Sequence[Union[dt.Annotation, dt.VideoAnnotation]]
annotations: Sequence[Union[dt.Annotation, dt.VideoAnnotation]],
):
"""
Removes all UUIDs present in instances of `dt.Annotation` and `dt.VideoAnnotation` objects.
Expand Down
31 changes: 31 additions & 0 deletions tests/darwin/importer/importer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,37 @@ def test_handle_subs() -> None:
assert result == expected_result


def test__handle_subs_empty_attributes() -> None:
from darwin.importer.importer import _handle_subs

annotation = dt.Annotation(
annotation_class=dt.AnnotationClass(
name="bbox1", annotation_type="bounding_box"
),
data={"x": 451.525, "y": 213.559, "w": 913.22, "h": 538.983},
subs=[],
slot_names=[],
id="a25e4613-718c-4cc8-9170-1bf372853f22",
)

initial_data = {
"bounding_box": {"x": 451.525, "y": 213.559, "w": 913.22, "h": 538.983}
}

result = _handle_subs(
annotation=annotation,
data=initial_data,
annotation_class_id="bbox1",
attributes={},
include_empty_attributes=True,
)

assert result == {
"bounding_box": {"x": 451.525, "y": 213.559, "w": 913.22, "h": 538.983},
"attributes": {"attributes": []},
}


def test__format_polygon_for_import() -> None:
from darwin.importer.importer import _format_polygon_for_import

Expand Down

0 comments on commit 4942e35

Please sign in to comment.