megadetector 10.0.15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- megadetector/__init__.py +0 -0
- megadetector/api/__init__.py +0 -0
- megadetector/api/batch_processing/integration/digiKam/setup.py +6 -0
- megadetector/api/batch_processing/integration/digiKam/xmp_integration.py +465 -0
- megadetector/api/batch_processing/integration/eMammal/test_scripts/config_template.py +5 -0
- megadetector/api/batch_processing/integration/eMammal/test_scripts/push_annotations_to_emammal.py +125 -0
- megadetector/api/batch_processing/integration/eMammal/test_scripts/select_images_for_testing.py +55 -0
- megadetector/classification/__init__.py +0 -0
- megadetector/classification/aggregate_classifier_probs.py +108 -0
- megadetector/classification/analyze_failed_images.py +227 -0
- megadetector/classification/cache_batchapi_outputs.py +198 -0
- megadetector/classification/create_classification_dataset.py +626 -0
- megadetector/classification/crop_detections.py +516 -0
- megadetector/classification/csv_to_json.py +226 -0
- megadetector/classification/detect_and_crop.py +853 -0
- megadetector/classification/efficientnet/__init__.py +9 -0
- megadetector/classification/efficientnet/model.py +415 -0
- megadetector/classification/efficientnet/utils.py +608 -0
- megadetector/classification/evaluate_model.py +520 -0
- megadetector/classification/identify_mislabeled_candidates.py +152 -0
- megadetector/classification/json_to_azcopy_list.py +63 -0
- megadetector/classification/json_validator.py +696 -0
- megadetector/classification/map_classification_categories.py +276 -0
- megadetector/classification/merge_classification_detection_output.py +509 -0
- megadetector/classification/prepare_classification_script.py +194 -0
- megadetector/classification/prepare_classification_script_mc.py +228 -0
- megadetector/classification/run_classifier.py +287 -0
- megadetector/classification/save_mislabeled.py +110 -0
- megadetector/classification/train_classifier.py +827 -0
- megadetector/classification/train_classifier_tf.py +725 -0
- megadetector/classification/train_utils.py +323 -0
- megadetector/data_management/__init__.py +0 -0
- megadetector/data_management/animl_to_md.py +161 -0
- megadetector/data_management/annotations/__init__.py +0 -0
- megadetector/data_management/annotations/annotation_constants.py +33 -0
- megadetector/data_management/camtrap_dp_to_coco.py +270 -0
- megadetector/data_management/cct_json_utils.py +566 -0
- megadetector/data_management/cct_to_md.py +184 -0
- megadetector/data_management/cct_to_wi.py +293 -0
- megadetector/data_management/coco_to_labelme.py +284 -0
- megadetector/data_management/coco_to_yolo.py +701 -0
- megadetector/data_management/databases/__init__.py +0 -0
- megadetector/data_management/databases/add_width_and_height_to_db.py +107 -0
- megadetector/data_management/databases/combine_coco_camera_traps_files.py +210 -0
- megadetector/data_management/databases/integrity_check_json_db.py +563 -0
- megadetector/data_management/databases/subset_json_db.py +195 -0
- megadetector/data_management/generate_crops_from_cct.py +200 -0
- megadetector/data_management/get_image_sizes.py +164 -0
- megadetector/data_management/labelme_to_coco.py +559 -0
- megadetector/data_management/labelme_to_yolo.py +349 -0
- megadetector/data_management/lila/__init__.py +0 -0
- megadetector/data_management/lila/create_lila_blank_set.py +556 -0
- megadetector/data_management/lila/create_lila_test_set.py +192 -0
- megadetector/data_management/lila/create_links_to_md_results_files.py +106 -0
- megadetector/data_management/lila/download_lila_subset.py +182 -0
- megadetector/data_management/lila/generate_lila_per_image_labels.py +777 -0
- megadetector/data_management/lila/get_lila_annotation_counts.py +174 -0
- megadetector/data_management/lila/get_lila_image_counts.py +112 -0
- megadetector/data_management/lila/lila_common.py +319 -0
- megadetector/data_management/lila/test_lila_metadata_urls.py +164 -0
- megadetector/data_management/mewc_to_md.py +344 -0
- megadetector/data_management/ocr_tools.py +873 -0
- megadetector/data_management/read_exif.py +964 -0
- megadetector/data_management/remap_coco_categories.py +195 -0
- megadetector/data_management/remove_exif.py +156 -0
- megadetector/data_management/rename_images.py +194 -0
- megadetector/data_management/resize_coco_dataset.py +665 -0
- megadetector/data_management/speciesnet_to_md.py +41 -0
- megadetector/data_management/wi_download_csv_to_coco.py +247 -0
- megadetector/data_management/yolo_output_to_md_output.py +594 -0
- megadetector/data_management/yolo_to_coco.py +984 -0
- megadetector/data_management/zamba_to_md.py +188 -0
- megadetector/detection/__init__.py +0 -0
- megadetector/detection/change_detection.py +840 -0
- megadetector/detection/process_video.py +479 -0
- megadetector/detection/pytorch_detector.py +1451 -0
- megadetector/detection/run_detector.py +1267 -0
- megadetector/detection/run_detector_batch.py +2172 -0
- megadetector/detection/run_inference_with_yolov5_val.py +1314 -0
- megadetector/detection/run_md_and_speciesnet.py +1604 -0
- megadetector/detection/run_tiled_inference.py +1044 -0
- megadetector/detection/tf_detector.py +209 -0
- megadetector/detection/video_utils.py +1379 -0
- megadetector/postprocessing/__init__.py +0 -0
- megadetector/postprocessing/add_max_conf.py +72 -0
- megadetector/postprocessing/categorize_detections_by_size.py +166 -0
- megadetector/postprocessing/classification_postprocessing.py +1943 -0
- megadetector/postprocessing/combine_batch_outputs.py +249 -0
- megadetector/postprocessing/compare_batch_results.py +2110 -0
- megadetector/postprocessing/convert_output_format.py +403 -0
- megadetector/postprocessing/create_crop_folder.py +629 -0
- megadetector/postprocessing/detector_calibration.py +570 -0
- megadetector/postprocessing/generate_csv_report.py +522 -0
- megadetector/postprocessing/load_api_results.py +223 -0
- megadetector/postprocessing/md_to_coco.py +428 -0
- megadetector/postprocessing/md_to_labelme.py +351 -0
- megadetector/postprocessing/md_to_wi.py +41 -0
- megadetector/postprocessing/merge_detections.py +392 -0
- megadetector/postprocessing/postprocess_batch_results.py +2140 -0
- megadetector/postprocessing/remap_detection_categories.py +226 -0
- megadetector/postprocessing/render_detection_confusion_matrix.py +677 -0
- megadetector/postprocessing/repeat_detection_elimination/find_repeat_detections.py +206 -0
- megadetector/postprocessing/repeat_detection_elimination/remove_repeat_detections.py +82 -0
- megadetector/postprocessing/repeat_detection_elimination/repeat_detections_core.py +1665 -0
- megadetector/postprocessing/separate_detections_into_folders.py +795 -0
- megadetector/postprocessing/subset_json_detector_output.py +964 -0
- megadetector/postprocessing/top_folders_to_bottom.py +238 -0
- megadetector/postprocessing/validate_batch_results.py +332 -0
- megadetector/taxonomy_mapping/__init__.py +0 -0
- megadetector/taxonomy_mapping/map_lila_taxonomy_to_wi_taxonomy.py +491 -0
- megadetector/taxonomy_mapping/map_new_lila_datasets.py +211 -0
- megadetector/taxonomy_mapping/prepare_lila_taxonomy_release.py +165 -0
- megadetector/taxonomy_mapping/preview_lila_taxonomy.py +543 -0
- megadetector/taxonomy_mapping/retrieve_sample_image.py +71 -0
- megadetector/taxonomy_mapping/simple_image_download.py +231 -0
- megadetector/taxonomy_mapping/species_lookup.py +1008 -0
- megadetector/taxonomy_mapping/taxonomy_csv_checker.py +159 -0
- megadetector/taxonomy_mapping/taxonomy_graph.py +346 -0
- megadetector/taxonomy_mapping/validate_lila_category_mappings.py +83 -0
- megadetector/tests/__init__.py +0 -0
- megadetector/tests/test_nms_synthetic.py +335 -0
- megadetector/utils/__init__.py +0 -0
- megadetector/utils/ct_utils.py +1857 -0
- megadetector/utils/directory_listing.py +199 -0
- megadetector/utils/extract_frames_from_video.py +307 -0
- megadetector/utils/gpu_test.py +125 -0
- megadetector/utils/md_tests.py +2072 -0
- megadetector/utils/path_utils.py +2872 -0
- megadetector/utils/process_utils.py +172 -0
- megadetector/utils/split_locations_into_train_val.py +237 -0
- megadetector/utils/string_utils.py +234 -0
- megadetector/utils/url_utils.py +825 -0
- megadetector/utils/wi_platform_utils.py +968 -0
- megadetector/utils/wi_taxonomy_utils.py +1766 -0
- megadetector/utils/write_html_image_list.py +239 -0
- megadetector/visualization/__init__.py +0 -0
- megadetector/visualization/plot_utils.py +309 -0
- megadetector/visualization/render_images_with_thumbnails.py +243 -0
- megadetector/visualization/visualization_utils.py +1973 -0
- megadetector/visualization/visualize_db.py +630 -0
- megadetector/visualization/visualize_detector_output.py +498 -0
- megadetector/visualization/visualize_video_output.py +705 -0
- megadetector-10.0.15.dist-info/METADATA +115 -0
- megadetector-10.0.15.dist-info/RECORD +147 -0
- megadetector-10.0.15.dist-info/WHEEL +5 -0
- megadetector-10.0.15.dist-info/licenses/LICENSE +19 -0
- megadetector-10.0.15.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""
|
|
2
|
+
|
|
3
|
+
zamba_to_md.py
|
|
4
|
+
|
|
5
|
+
Convert a labels.csv file produced by Zamba Cloud to a MD results file suitable
|
|
6
|
+
for import into Timelapse.
|
|
7
|
+
|
|
8
|
+
Columns are expected to be:
|
|
9
|
+
|
|
10
|
+
video_uuid (not used)
|
|
11
|
+
original_filename (assumed to be a relative path name)
|
|
12
|
+
top_k_label,top_k_probability, for k = 1..N
|
|
13
|
+
[category name 1],[category name 2],...
|
|
14
|
+
corrected_label
|
|
15
|
+
|
|
16
|
+
Because the MD results file fundamentally stores detections, what we'll
|
|
17
|
+
actually do is create bogus detections that fill the entire image.
|
|
18
|
+
|
|
19
|
+
There is no special handling of empty/blank categories; because these results are
|
|
20
|
+
based on a classifier, rather than a detector (where "blank" would be the absence of
|
|
21
|
+
all other categories), "blank" can be queried in Timelapse just like any other class.
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
#%% Imports and constants
|
|
26
|
+
|
|
27
|
+
import sys
|
|
28
|
+
import argparse
|
|
29
|
+
|
|
30
|
+
import pandas as pd
|
|
31
|
+
|
|
32
|
+
from megadetector.utils.ct_utils import write_json
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
#%% Main function
|
|
36
|
+
|
|
37
|
+
def zamba_results_to_md_results(input_file,output_file=None):
|
|
38
|
+
"""
|
|
39
|
+
Converts the .csv file [input_file] to the MD-formatted .json file [output_file].
|
|
40
|
+
|
|
41
|
+
If [output_file] is None, '.json' will be appended to the input file.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
input_file (str): the .csv file to convert
|
|
45
|
+
output_file (str, optional): the output .json file (defaults to
|
|
46
|
+
[input_file].json)
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
if output_file is None:
|
|
50
|
+
output_file = input_file + '.json'
|
|
51
|
+
|
|
52
|
+
df = pd.read_csv(input_file)
|
|
53
|
+
|
|
54
|
+
expected_columns = ('video_uuid','corrected_label','original_filename')
|
|
55
|
+
for s in expected_columns:
|
|
56
|
+
assert s in df.columns,\
|
|
57
|
+
'Expected column {} not found, are you sure this is a Zamba results .csv file?'.format(
|
|
58
|
+
s)
|
|
59
|
+
|
|
60
|
+
# How many results are included per file?
|
|
61
|
+
assert 'top_1_probability' in df.columns and 'top_1_label' in df.columns
|
|
62
|
+
top_k = 2
|
|
63
|
+
while(True):
|
|
64
|
+
p_string = 'top_' + str(top_k) + '_probability'
|
|
65
|
+
label_string = 'top_' + str(top_k) + '_label'
|
|
66
|
+
|
|
67
|
+
if p_string in df.columns:
|
|
68
|
+
assert label_string in df.columns,\
|
|
69
|
+
'Oops, {} is a column but {} is not'.format(
|
|
70
|
+
p_string,label_string)
|
|
71
|
+
top_k += 1
|
|
72
|
+
continue
|
|
73
|
+
else:
|
|
74
|
+
assert label_string not in df.columns,\
|
|
75
|
+
'Oops, {} is a column but {} is not'.format(
|
|
76
|
+
label_string,p_string)
|
|
77
|
+
top_k -= 1
|
|
78
|
+
break
|
|
79
|
+
|
|
80
|
+
print('Found {} probability column pairs'.format(top_k))
|
|
81
|
+
|
|
82
|
+
# Category names start after the fixed columns and the probability columns
|
|
83
|
+
category_names = []
|
|
84
|
+
column_names = list(df.columns)
|
|
85
|
+
first_category_name_index = 0
|
|
86
|
+
while('top_' in column_names[first_category_name_index] or \
|
|
87
|
+
column_names[first_category_name_index] in expected_columns):
|
|
88
|
+
first_category_name_index += 1
|
|
89
|
+
|
|
90
|
+
i_column = first_category_name_index
|
|
91
|
+
while( (i_column < len(column_names)) and (column_names[i_column] != 'corrected_label') ):
|
|
92
|
+
category_names.append(column_names[i_column])
|
|
93
|
+
i_column += 1
|
|
94
|
+
|
|
95
|
+
print('Found {} categories:\n'.format(len(category_names)))
|
|
96
|
+
|
|
97
|
+
for s in category_names:
|
|
98
|
+
print(s)
|
|
99
|
+
|
|
100
|
+
info = {}
|
|
101
|
+
info['format_version'] = '1.3'
|
|
102
|
+
info['detector'] = 'Zamba Cloud'
|
|
103
|
+
info['classifier'] = 'Zamba Cloud'
|
|
104
|
+
|
|
105
|
+
detection_category_id_to_name = {}
|
|
106
|
+
for category_id,category_name in enumerate(category_names):
|
|
107
|
+
detection_category_id_to_name[str(category_id)] = category_name
|
|
108
|
+
detection_category_name_to_id = {v: k for k, v in detection_category_id_to_name.items()}
|
|
109
|
+
|
|
110
|
+
images = []
|
|
111
|
+
|
|
112
|
+
# i_row = 0; row = df.iloc[i_row]
|
|
113
|
+
for i_row,row in df.iterrows():
|
|
114
|
+
|
|
115
|
+
im = {}
|
|
116
|
+
images.append(im)
|
|
117
|
+
im['file'] = row['original_filename']
|
|
118
|
+
|
|
119
|
+
detections = []
|
|
120
|
+
|
|
121
|
+
# k = 1
|
|
122
|
+
for k in range(1,top_k+1):
|
|
123
|
+
label = row['top_{}_label'.format(k)]
|
|
124
|
+
confidence = row['top_{}_probability'.format(k)]
|
|
125
|
+
det = {}
|
|
126
|
+
det['category'] = detection_category_name_to_id[label]
|
|
127
|
+
det['conf'] = confidence
|
|
128
|
+
det['bbox'] = [0,0,1.0,1.0]
|
|
129
|
+
detections.append(det)
|
|
130
|
+
|
|
131
|
+
im['detections'] = detections
|
|
132
|
+
|
|
133
|
+
# ...for each row
|
|
134
|
+
|
|
135
|
+
results = {}
|
|
136
|
+
results['info'] = info
|
|
137
|
+
results['detection_categories'] = detection_category_id_to_name
|
|
138
|
+
results['images'] = images
|
|
139
|
+
|
|
140
|
+
write_json(output_file,results)
|
|
141
|
+
|
|
142
|
+
# ...zamba_results_to_md_results(...)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
#%% Interactive driver
|
|
146
|
+
|
|
147
|
+
if False:
|
|
148
|
+
|
|
149
|
+
pass
|
|
150
|
+
|
|
151
|
+
#%%
|
|
152
|
+
|
|
153
|
+
input_file = r"G:\temp\labels-job-b95a4b76-e332-4e17-ab40-03469392d36a-2023-11-04_16-28-50.060130.csv"
|
|
154
|
+
output_file = None
|
|
155
|
+
zamba_results_to_md_results(input_file,output_file)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
#%% Command-line driver
|
|
159
|
+
|
|
160
|
+
def main():
|
|
161
|
+
"""
|
|
162
|
+
Command-line driver for zamba_to_md
|
|
163
|
+
"""
|
|
164
|
+
|
|
165
|
+
parser = argparse.ArgumentParser(
|
|
166
|
+
description='Convert a Zamba-formatted .csv results file to a MD-formatted .json results file')
|
|
167
|
+
|
|
168
|
+
parser.add_argument(
|
|
169
|
+
'input_file',
|
|
170
|
+
type=str,
|
|
171
|
+
help='input .csv file')
|
|
172
|
+
|
|
173
|
+
parser.add_argument(
|
|
174
|
+
'--output_file',
|
|
175
|
+
type=str,
|
|
176
|
+
default=None,
|
|
177
|
+
help='output .json file (defaults to input file appended with ".json")')
|
|
178
|
+
|
|
179
|
+
if len(sys.argv[1:]) == 0:
|
|
180
|
+
parser.print_help()
|
|
181
|
+
parser.exit()
|
|
182
|
+
|
|
183
|
+
args = parser.parse_args()
|
|
184
|
+
|
|
185
|
+
zamba_results_to_md_results(args.input_file,args.output_file)
|
|
186
|
+
|
|
187
|
+
if __name__ == '__main__':
|
|
188
|
+
main()
|
|
File without changes
|