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

Converting JSON output as CSV? #303

Closed dvelasco3 closed 2 years ago

dvelasco3 commented 2 years ago

I ran MegaDetector on a folder containing roughly 30,000 photos, and got back a JSON file containing the results of the detections.

I'm wondering if there's a way I can convert the JSON file to a CSV spreadsheet? I am looking to compare the results of the detections with another CSV containing efficiency / time info for human labor detections.

I found this stack overflow page that has some python commands that might work, but I wanted to check in here to see what I'm missing to be able to start this process?

https://stackoverflow.com/questions/1871524/how-can-i-convert-json-to-csv

agentmorris commented 2 years ago

I think you want this script:

https://github.com/microsoft/CameraTraps/blob/main/api/batch_processing/postprocessing/convert_output_format.py

It will give you a row for each image, and a column with the maximum confidence for each class (animal, person, vehicle).

Hope that helps!

-Dan

dvelasco3 commented 2 years ago

I'm a bit confused as to how I can use that file. I tried to run the file you linked as a python command but then I received this error:

error: the following arguments are required: input_path, output_path

Following this I tried attaching this command following my running of the file:

--input_path c:/path/to/file

but I got this error instead:

convert_output_format.py: error: unrecognized arguments: --input_path --output_path

I'm just confused how I can run this file, and input my output JSON in order to get a CSV file.

Thanks, and sorry about any confusion.

agentmorris commented 2 years ago

If your .json file is, for example:

c:\my_results\results.json

...and you want to write the converted output to, for example:

c:\my_results\results.csv

You can run:

python convert_output_format.py "c:\my_results\results.json" "c:\my_results\results.csv"

Hope that helps!

-Dan