Bug when exporting coco json?

Hey @mz0g,

This has caused some confusion for me as well, and I don’t fully understand why they are including the super category as a class. This format works fine for RF-DETR, I assume because Roboflow made RF-DETR, but if you try to use this format for Detectron2, particularly the faster RCNN models, it creates an issue where it ignores your last class for evaluation. I assume the issue with Detectron2 has to do with the super category being recognized as a separate class. I haven’t tried any other platforms beyond that.

You can see Roboflow’s response to my similar question at…

Extra Coco JSON Class - Community Help - Roboflow

The answer was basically “that’s the way it is”. I’ve been unable to find any documentation outside of Roboflow about a super category being included as its own class in COCO format. However, take what I have to say with a grain of salt, I am fairly new to computer vision and am by no means a professional. I’d be eager to see what the Roboflow team has to say about this.

Also, to fix the json such that it would work for Detectron2, I wrote the following to eliminate the separate super category…

import json

jsonPaths = ['/path/to/train/_annotations.coco.json','/path/to/valid/_annotations.coco.json']

for jsonPath in jsonPaths:
  with open(jsonPath, 'r') as f:
      data = json.load(f)

  del data['categories'][0]

  for i, cat in enumerate(data['categories']):
      cat['id'] = i

  for ann in data['annotations']:
      ann['category_id'] -= 1

  for ann in data['annotations']:
    if ann['category_id'] > 2:
      print(ann)

  with open(jsonPath, "w") as f:
      json.dump(data, f)

Best,
Rhys

1 Like