diff --git a/README.md b/README.md index 82e9e96..303fbd9 100644 --- a/README.md +++ b/README.md @@ -1043,10 +1043,10 @@ tasks = client.get_image_tasks(project="YOUR_PROJECT_SLUG") client.export_coco(tasks) ``` -Export with specifying output directory. +Export with specifying output directory and file name. ```python -client.export_coco(tasks=tasks, output_dir="YOUR_DIRECTROY") +client.export_coco(tasks=tasks, output_dir="YOUR_DIRECTROY", output_file_name="YOUR_FILE_NAME") ``` If you would like to export pose estimation type annotations, please pass annotations. @@ -1055,7 +1055,7 @@ If you would like to export pose estimation type annotations, please pass annota project_slug = "YOUR_PROJECT_SLUG" tasks = client.get_image_tasks(project=project_slug) annotations = client.get_annotations(project=project_slug) -client.export_coco(tasks=tasks, annotations=annotations, output_dir="YOUR_DIRECTROY") +client.export_coco(tasks=tasks, annotations=annotations, output_dir="YOUR_DIRECTROY", output_file_name="YOUR_FILE_NAME") ``` ### YOLO diff --git a/fastlabel/__init__.py b/fastlabel/__init__.py index 51bcb67..cd942ce 100644 --- a/fastlabel/__init__.py +++ b/fastlabel/__init__.py @@ -1082,7 +1082,7 @@ def __get_yolo_format_annotations(self, dataset_folder_path: str) -> dict: # Task Convert - def export_coco(self, tasks: list, annotations: list = [], output_dir: str = os.path.join("output", "coco")) -> None: + def export_coco(self, tasks: list, annotations: list = [], output_dir: str = os.path.join("output", "coco"), output_file_name: str = "annotations.json") -> None: """ Convert tasks to COCO format and export as a file. If you pass annotations, you can export Pose Estimation type annotations. @@ -1090,10 +1090,14 @@ def export_coco(self, tasks: list, annotations: list = [], output_dir: str = os. tasks is a list of tasks. (Required) annotations is a list of annotations. (Optional) output_dir is output directory(default: output/coco). (Optional) + output_file_name is output file name(default: annotations.json). (Optional) """ + if not utils.is_json_ext(output_file_name): + raise FastLabelInvalidException( + "Output file name must have a json extension", 422) coco = converters.to_coco(tasks, annotations) os.makedirs(output_dir, exist_ok=True) - file_path = os.path.join(output_dir, "annotations.json") + file_path = os.path.join(output_dir, output_file_name) with open(file_path, 'w') as f: json.dump(coco, f, indent=4, ensure_ascii=False) diff --git a/fastlabel/utils.py b/fastlabel/utils.py index 1af798f..d78ec65 100644 --- a/fastlabel/utils.py +++ b/fastlabel/utils.py @@ -19,6 +19,10 @@ def is_video_supported_ext(file_path: str) -> bool: return file_path.lower().endswith('.mp4') +def is_json_ext(file_name: str) -> bool: + return file_name.lower().endswith('.json') + + def get_basename(file_path: str) -> str: """ e.g.) file.jpg -> file diff --git a/setup.py b/setup.py index 0243625..366d786 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setuptools.setup( name="fastlabel", - version="0.11.11", + version="0.11.12", author="eisuke-ueta", author_email="eisuke.ueta@fastlabel.ai", description="The official Python SDK for FastLabel API, the Data Platform for AI",