microsoft / CameraTraps

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

Detection JSON file formatted in one line #463

Closed JaimyvS closed 3 months ago

JaimyvS commented 3 months ago

Search before asking

Bug

A small bug report, that might be better defined as a quality of life improvement.

Whenever I run a batch detection script with a JSON file as output. The JSON file is formatted into one single line.

E.g.: {"annotations": [{"img_id": "./test_set/DSC_7607.JPG", "bbox": [[2078, 876, 3845, 3421], [1419, 1354, 1963, 2938], [3098, 1244, 3312, 1645]], "category": [0, 0, 1], "confidence": [0.8661148548126221, 0.582044243812561, 0.20031577348709106]},

Instead of:

{
   "annotations":[
      {
         "img_id":"input/Todo/DSC_7606.JPG",
         "bbox":[
            [
               3028,
               1535,
               4209,
               2784
            ],
            [
               5679,
               1906,
               5905,
               2163
            ],
            [
               5902,
               1914,
               6048,
               2151
            ]
         ],
         "category":[
            0,
            0,
            0
         ],
         "confidence":[
            0.9651390314102173,
            0.9075486063957214,
            0.7744619250297546
         ]
      },

Of course, this is easily done with online JSON beautifiers but with multiple files, having it directly as output would make it much easier to quickly look through the results.

Thanks!

Environment

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

calebrob6 commented 3 months ago

Potentially solved by adding indent=4 to json.dump in the methods in utils/post_process.py, e.g. https://github.com/microsoft/CameraTraps/blob/e2196157658e8751d7c34e205aae22f09883de2b/PytorchWildlife/utils/post_process.py#L107C14-L107C18

zhmiao commented 3 months ago

Hello @JaimyvS , thank you very much for reporting! As @calebrob6 mentioned, it can be easily done but I would say rather than a bug, it is more of an enhancement. We will add indention to the output json in our next updates!

zhmiao commented 3 months ago

Hello @JaimyvS and @calebrob6, this issue is addressed with the newest commits! You can update the package through pip and test the new json output functions! Thank you very much again!