agentmorris / MegaDetector

MegaDetector is an AI model that helps conservation folks spend less time doing boring things with camera trap images.
MIT License
101 stars 23 forks source link

Script to convert Mega output JSON to COCO? #50

Closed agentmorris closed 1 year ago

agentmorris commented 1 year ago

Hi, we are trying to do some transfer learning with our Megadetector output JSON (retraining Mobilenet in TF2) and just realized the JSON output format from Megadetector is not in COCO format. Do you know if there is a handy script laying around somewhere that converts the images..detections into annotations and fixes the bounding box coordinates and any other differences i haven't learned about yet! Thank you


Issue cloned from Microsoft/CameraTraps, original issue posted by maxogden on Nov 18, 2021.

agentmorris commented 1 year ago

Almost? We (Microsoft-ish people) have only done this once AFAIK, to take data that was provided to us in MegaDetector output format and prepare a COCO .json file for release on lila.science. The full code to do that did a whole bunch of things that were very particular to that data set, but there is one cell that is almost self-explanatory, whose inputs are the stuff you get from a MegaDetector output file, and whose outputs are ready to be serialized to a COCO Camera Traps .json file (which is COCO-ish). I made a best effort to turn that one useful cell into a self-contained script, but I have not run this code, so YMMV:

https://github.com/microsoft/CameraTraps/blob/master/data_management/md_to_coco_starter_code.py

Note that the two formats aren't strictly apples to apples; the MegaDetector output format includes probabilities, and COCO is built from the ground up as a ground truth format. You will have to decide what that means for your interpretation of COCO; you might store probabilities as an ancillary field, or you might threshold probabilities and make it a proper COCO file.

Hope that helps! Let us know how it goes, and if you hance a chance, let us know, either here or by email what you're up to with MegaDetector!

Thanks.


(Comment originally posted by agentmorris)

agentmorris commented 1 year ago

Thank you, will check that script out!


(Comment originally posted by maxogden)

agentmorris commented 1 year ago

Closing because the answer was either "no" or "sort of", but Max has his answer either way. :)


(Comment originally posted by agentmorris)

agentmorris commented 11 months ago

A zillion years later, this script is done now:

https://github.com/agentmorris/MegaDetector/blob/main/api/batch_processing/postprocessing/md_to_coco.py