Skip to content

Commit

Permalink
[AI-1245] added albumentations transform test (#672)
Browse files Browse the repository at this point in the history
* added albumentations transform test

* updated poetry file

* added albumentations to poetry.lock

* added manual install of albumentations

* added main

* updated poetry.lock with add albumentations

* albumentations only for python >= 3.8

* generated new lock file

* ran black

* ran black

* formatted the files with black

* formatting test

* formatting test

* ran ruff on changes files

* testing with black line-length 80

* all black checks passed locally

* formatted darwin.py
  • Loading branch information
ChristofferEdlund authored Oct 16, 2023
1 parent 288ff13 commit 56968b3
Show file tree
Hide file tree
Showing 6 changed files with 363 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"editor.tabSize": 2
},
"python.formatting.blackPath": "black",
"python.formatting.provider": "none",
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"-l 120"
],
Expand Down
4 changes: 2 additions & 2 deletions darwin/exporter/formats/darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ def build_image_annotation(annotation_file: dt.AnnotationFile) -> Dict[str, Any]
}
"""
annotations: List[Dict[str, Any]] = []
print(annotations)
for annotation in annotation_file.annotations:
payload = {
annotation.annotation_class.annotation_type: _build_annotation_data(annotation),
"name": annotation.annotation_class.name,
}

if (
annotation.annotation_class.annotation_type == "complex_polygon"
or annotation.annotation_class.annotation_type == "polygon"
annotation.annotation_class.annotation_type == "complex_polygon" or annotation.annotation_class.annotation_type == "polygon"
) and "bounding_box" in annotation.data:
payload["bounding_box"] = annotation.data["bounding_box"]

Expand Down
11 changes: 3 additions & 8 deletions darwin/exporter/formats/darwin_1_0.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import Any, Dict, Iterable, List, Union
from typing import Iterable, List, Union

import orjson as json

Expand Down Expand Up @@ -34,14 +34,11 @@ def export(annotation_files: Iterable[AnnotationFile], output_dir: Path) -> None


def _export_file(annotation_file: AnnotationFile, _: int, output_dir: Path) -> None:

try:
filename = annotation_file.path.parts[-1]
output_file_path = (output_dir / filename).with_suffix(".json")
except Exception as e:
raise ExportException_CouldNotAssembleOutputPath(
f"Could not export file {annotation_file.path} to {output_dir}"
) from e
raise ExportException_CouldNotAssembleOutputPath(f"Could not export file {annotation_file.path} to {output_dir}") from e

try:
output: DictFreeForm = _build_json(annotation_file)
Expand All @@ -50,9 +47,7 @@ def _export_file(annotation_file: AnnotationFile, _: int, output_dir: Path) -> N

try:
with open(output_file_path, "w") as f:
op = json.dumps(output, option=json.OPT_INDENT_2 | json.OPT_SERIALIZE_NUMPY | json.OPT_NON_STR_KEYS).decode(
"utf-8"
)
op = json.dumps(output, option=json.OPT_INDENT_2 | json.OPT_SERIALIZE_NUMPY | json.OPT_NON_STR_KEYS).decode("utf-8")
f.write(op)
except Exception as e:
raise ExportException_CouldNotWriteFile(f"Could not write output for {annotation_file.path}") from e
Expand Down
Loading

0 comments on commit 56968b3

Please sign in to comment.