Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: make JSON indentation configurable when merging COCO files #171

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 9 additions & 3 deletions pyodi/apps/coco/coco_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,25 @@
# API REFERENCE
""" # noqa: E501
import json
from typing import Any, Dict
from typing import Any, Dict, Union

from loguru import logger


@logger.catch(reraise=True)
def coco_merge(input_extend: str, input_add: str, output_file: str,) -> str:
def coco_merge(
input_extend: str,
input_add: str,
output_file: str,
json_indentation: Union[int, None] = 2,
philenius marked this conversation as resolved.
Show resolved Hide resolved
) -> str:
"""Merge COCO annotation files.

Args:
input_extend: Path to input file to be extended.
input_add: Path to input file to be added.
output_file : Path to output file with merged annotations.
json_indentation: If set to a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of `0` will only insert newlines. `None` is the most compact representation (no indentation).
philenius marked this conversation as resolved.
Show resolved Hide resolved
"""
with open(input_extend, "r") as f:
data_extend = json.load(f)
Expand Down Expand Up @@ -88,6 +94,6 @@ def coco_merge(input_extend: str, input_add: str, output_file: str,) -> str:
)

with open(output_file, "w") as f:
json.dump(output, f, indent=2)
json.dump(output, f, indent=json_indentation)

return output_file
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pyodi
version = 0.0.6
version = 0.0.7
author = Pyodi
description = Object Detection Insights
long_description = file: README.md
Expand Down