Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions megadetector/postprocessing/combine_batch_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import argparse
import sys
import json

from megadetector.utils import ct_utils


Expand Down
2 changes: 1 addition & 1 deletion megadetector/postprocessing/generate_csv_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def generate_csv_report(md_results_file,

# Classifications should always be sorted by confidence. Not
# technically required, but always true in practice.
assert is_list_sorted([c[1] for c in det['classifications']]), \
assert is_list_sorted([c[1] for c in det['classifications']], reverse=True), \
'This script does not yet support unsorted classifications'
assert classification_category_id_to_name is not None, \
'If classifications are present, category mappings should be present'
Expand Down
21 changes: 19 additions & 2 deletions megadetector/postprocessing/remap_detection_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,46 @@ def remap_detection_categories(input_file,

# det = im['detections'][0]
for det in im['detections']:

input_category_id = det['category']

if input_category_id not in input_category_id_to_output_category_id:

input_category_name = '[unknown]'
if input_category_id in input_categories:
input_category_name = input_categories[input_category_id]

s = 'Detection category {} ({}) not mapped'.format(
input_category_id,input_category_name)

if invalid_category_handling == 'error':

raise ValueError(s)

else:

assert invalid_category_handling == 'unknown'
print('Warning: {}'.format(s))
if 'unknown' in output_category_name_to_output_category_id:
output_category_id = output_category_name_to_output_category_id['unknown']
else:
category_id_values = [int(x) for x in output_category_name_to_output_category_id.values()]
unknown_category_id = max(category_id_values) + 1
# Create a new "unknown" category for the unmapped category
category_id_values = \
[int(x) for x in output_category_name_to_output_category_id.values()]
unknown_category_id = str(max(category_id_values) + 1)
output_category_name_to_output_category_id['unknown'] = unknown_category_id
target_category_map[unknown_category_id] = 'unknown'
output_category_id = unknown_category_id
else:

output_category_id = input_category_id_to_output_category_id[input_category_id]

# ...if this category ID has been mapped to the output dict

det['category'] = output_category_id

# ...for each detection

# ...for each image

input_data['detection_categories'] = target_category_map
Expand Down
Loading