COCO Annotation Converter is a Python script designed to convert annotations from the pred_coco.json
format to the COCO Results Format. This tool is useful for those working with COCO datasets who need to transform predictions into a compatible format for analysis and evaluation.
- Support for Various Annotation Structures: Handles annotations as dictionaries containing the
annotations
key as well as lists of annotations. - Confidence Score Filtering: Allows setting a minimum score threshold to include only relevant detections.
- Category Management: Maps category names to their respective IDs based on ground truth annotations.
- Support for Segmentations and Keypoints: Includes segmentation and keypoint information if present in the annotations.
- Python 3.6 or higher
-
Clone the Repository:
git clone https://github.com/your-username/coco-annotation-converter.git cd coco-annotation-converter
-
Create a Virtual Environment (Optional but Recommended):
python3 -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install Dependencies:
pip install -r requirements.txt
If the
requirements.txt
file is not present, you can install dependencies manually:pip install argparse
Run the converter.py
script via the command line, specifying the paths to the necessary files.
python converter.py --pred PATH_TO_PRED_COCO_JSON --output OUTPUT_PATH [--score_thresh THRESHOLD]
Or as external pip package as:
import converter
converter.setup_logging()
converter.convert_pred_coco('path/to/pred_coco.json', 'path/to/output.json')