microsoft / CameraTraps

PyTorch Wildlife: a Collaborative Deep Learning Framework for Conservation.
https://cameratraps.readthedocs.io/en/latest/
MIT License
784 stars 246 forks source link

Script to convert Mega output JSON to COCO? #262

Closed max-mapper closed 3 years ago

max-mapper commented 3 years 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

agentmorris commented 3 years 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.

max-mapper commented 3 years ago

Thank you, will check that script out!

agentmorris commented 3 years ago

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