PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, May 5, 2022

[FIXED] How to convert yolo annotations to coco format. Json?

 May 05, 2022     annotation-processing, data-annotations, deep-learning, image, object-detection     No comments   

Issue

I want to convert my labels in yolo format to coco format I have tried https://github.com/Taeyoung96/Yolo-to-COCO-format-converter And Pylabel They all have a bugs.

I want to train on detectron 2 but it fails to load the dataset because of the wrong json file.

Thanks everybody


Solution

Could you try with this tool (disclaimer: I'm the author)? It is not (yet) a Python package so you need to downloads the repo first. This should ressemble something like:

from ObjectDetectionEval import *
from pathlib import Path


def main() -> None:
  path = Path("/path/to/annotations/")  # Where the .txt files are
  names_file = Path("/path/to/classes.names")
  save_file = Path("coco.json")

  annotations = AnnotationSet.from_yolo(gts_path).map_labels(names)
  
  # If you need to change the labels
  # names = Annotation.parse_names_file(names_file)
  # annotations.map_labels(names)

  annotations.save_coco(save_file)


if __name__ == "__main__":
    main()

If you need more control (coordinate format, images location and extension, etc.) you should use the more generic AnnotationSet.from_txt(). If it does not suit your needs you can easily implement your own parser using AnnotationSet.from_folder().



Answered By - Louis Lac
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing