Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions fastlabel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,18 +1082,22 @@ 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.

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)

Expand Down
4 changes: 4 additions & 0 deletions fastlabel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down