megadetector 10.0.13__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.

Potentially problematic release.


This version of megadetector might be problematic. Click here for more details.

Files changed (147) hide show
  1. megadetector/__init__.py +0 -0
  2. megadetector/api/__init__.py +0 -0
  3. megadetector/api/batch_processing/integration/digiKam/setup.py +6 -0
  4. megadetector/api/batch_processing/integration/digiKam/xmp_integration.py +465 -0
  5. megadetector/api/batch_processing/integration/eMammal/test_scripts/config_template.py +5 -0
  6. megadetector/api/batch_processing/integration/eMammal/test_scripts/push_annotations_to_emammal.py +125 -0
  7. megadetector/api/batch_processing/integration/eMammal/test_scripts/select_images_for_testing.py +55 -0
  8. megadetector/classification/__init__.py +0 -0
  9. megadetector/classification/aggregate_classifier_probs.py +108 -0
  10. megadetector/classification/analyze_failed_images.py +227 -0
  11. megadetector/classification/cache_batchapi_outputs.py +198 -0
  12. megadetector/classification/create_classification_dataset.py +626 -0
  13. megadetector/classification/crop_detections.py +516 -0
  14. megadetector/classification/csv_to_json.py +226 -0
  15. megadetector/classification/detect_and_crop.py +853 -0
  16. megadetector/classification/efficientnet/__init__.py +9 -0
  17. megadetector/classification/efficientnet/model.py +415 -0
  18. megadetector/classification/efficientnet/utils.py +608 -0
  19. megadetector/classification/evaluate_model.py +520 -0
  20. megadetector/classification/identify_mislabeled_candidates.py +152 -0
  21. megadetector/classification/json_to_azcopy_list.py +63 -0
  22. megadetector/classification/json_validator.py +696 -0
  23. megadetector/classification/map_classification_categories.py +276 -0
  24. megadetector/classification/merge_classification_detection_output.py +509 -0
  25. megadetector/classification/prepare_classification_script.py +194 -0
  26. megadetector/classification/prepare_classification_script_mc.py +228 -0
  27. megadetector/classification/run_classifier.py +287 -0
  28. megadetector/classification/save_mislabeled.py +110 -0
  29. megadetector/classification/train_classifier.py +827 -0
  30. megadetector/classification/train_classifier_tf.py +725 -0
  31. megadetector/classification/train_utils.py +323 -0
  32. megadetector/data_management/__init__.py +0 -0
  33. megadetector/data_management/animl_to_md.py +161 -0
  34. megadetector/data_management/annotations/__init__.py +0 -0
  35. megadetector/data_management/annotations/annotation_constants.py +33 -0
  36. megadetector/data_management/camtrap_dp_to_coco.py +270 -0
  37. megadetector/data_management/cct_json_utils.py +566 -0
  38. megadetector/data_management/cct_to_md.py +184 -0
  39. megadetector/data_management/cct_to_wi.py +293 -0
  40. megadetector/data_management/coco_to_labelme.py +284 -0
  41. megadetector/data_management/coco_to_yolo.py +702 -0
  42. megadetector/data_management/databases/__init__.py +0 -0
  43. megadetector/data_management/databases/add_width_and_height_to_db.py +107 -0
  44. megadetector/data_management/databases/combine_coco_camera_traps_files.py +210 -0
  45. megadetector/data_management/databases/integrity_check_json_db.py +528 -0
  46. megadetector/data_management/databases/subset_json_db.py +195 -0
  47. megadetector/data_management/generate_crops_from_cct.py +200 -0
  48. megadetector/data_management/get_image_sizes.py +164 -0
  49. megadetector/data_management/labelme_to_coco.py +559 -0
  50. megadetector/data_management/labelme_to_yolo.py +349 -0
  51. megadetector/data_management/lila/__init__.py +0 -0
  52. megadetector/data_management/lila/create_lila_blank_set.py +556 -0
  53. megadetector/data_management/lila/create_lila_test_set.py +187 -0
  54. megadetector/data_management/lila/create_links_to_md_results_files.py +106 -0
  55. megadetector/data_management/lila/download_lila_subset.py +182 -0
  56. megadetector/data_management/lila/generate_lila_per_image_labels.py +777 -0
  57. megadetector/data_management/lila/get_lila_annotation_counts.py +174 -0
  58. megadetector/data_management/lila/get_lila_image_counts.py +112 -0
  59. megadetector/data_management/lila/lila_common.py +319 -0
  60. megadetector/data_management/lila/test_lila_metadata_urls.py +164 -0
  61. megadetector/data_management/mewc_to_md.py +344 -0
  62. megadetector/data_management/ocr_tools.py +873 -0
  63. megadetector/data_management/read_exif.py +964 -0
  64. megadetector/data_management/remap_coco_categories.py +195 -0
  65. megadetector/data_management/remove_exif.py +156 -0
  66. megadetector/data_management/rename_images.py +194 -0
  67. megadetector/data_management/resize_coco_dataset.py +663 -0
  68. megadetector/data_management/speciesnet_to_md.py +41 -0
  69. megadetector/data_management/wi_download_csv_to_coco.py +247 -0
  70. megadetector/data_management/yolo_output_to_md_output.py +594 -0
  71. megadetector/data_management/yolo_to_coco.py +876 -0
  72. megadetector/data_management/zamba_to_md.py +188 -0
  73. megadetector/detection/__init__.py +0 -0
  74. megadetector/detection/change_detection.py +840 -0
  75. megadetector/detection/process_video.py +479 -0
  76. megadetector/detection/pytorch_detector.py +1451 -0
  77. megadetector/detection/run_detector.py +1267 -0
  78. megadetector/detection/run_detector_batch.py +2159 -0
  79. megadetector/detection/run_inference_with_yolov5_val.py +1314 -0
  80. megadetector/detection/run_md_and_speciesnet.py +1494 -0
  81. megadetector/detection/run_tiled_inference.py +1038 -0
  82. megadetector/detection/tf_detector.py +209 -0
  83. megadetector/detection/video_utils.py +1379 -0
  84. megadetector/postprocessing/__init__.py +0 -0
  85. megadetector/postprocessing/add_max_conf.py +72 -0
  86. megadetector/postprocessing/categorize_detections_by_size.py +166 -0
  87. megadetector/postprocessing/classification_postprocessing.py +1752 -0
  88. megadetector/postprocessing/combine_batch_outputs.py +249 -0
  89. megadetector/postprocessing/compare_batch_results.py +2110 -0
  90. megadetector/postprocessing/convert_output_format.py +403 -0
  91. megadetector/postprocessing/create_crop_folder.py +629 -0
  92. megadetector/postprocessing/detector_calibration.py +570 -0
  93. megadetector/postprocessing/generate_csv_report.py +522 -0
  94. megadetector/postprocessing/load_api_results.py +223 -0
  95. megadetector/postprocessing/md_to_coco.py +428 -0
  96. megadetector/postprocessing/md_to_labelme.py +351 -0
  97. megadetector/postprocessing/md_to_wi.py +41 -0
  98. megadetector/postprocessing/merge_detections.py +392 -0
  99. megadetector/postprocessing/postprocess_batch_results.py +2077 -0
  100. megadetector/postprocessing/remap_detection_categories.py +226 -0
  101. megadetector/postprocessing/render_detection_confusion_matrix.py +677 -0
  102. megadetector/postprocessing/repeat_detection_elimination/find_repeat_detections.py +206 -0
  103. megadetector/postprocessing/repeat_detection_elimination/remove_repeat_detections.py +82 -0
  104. megadetector/postprocessing/repeat_detection_elimination/repeat_detections_core.py +1665 -0
  105. megadetector/postprocessing/separate_detections_into_folders.py +795 -0
  106. megadetector/postprocessing/subset_json_detector_output.py +964 -0
  107. megadetector/postprocessing/top_folders_to_bottom.py +238 -0
  108. megadetector/postprocessing/validate_batch_results.py +332 -0
  109. megadetector/taxonomy_mapping/__init__.py +0 -0
  110. megadetector/taxonomy_mapping/map_lila_taxonomy_to_wi_taxonomy.py +491 -0
  111. megadetector/taxonomy_mapping/map_new_lila_datasets.py +213 -0
  112. megadetector/taxonomy_mapping/prepare_lila_taxonomy_release.py +165 -0
  113. megadetector/taxonomy_mapping/preview_lila_taxonomy.py +543 -0
  114. megadetector/taxonomy_mapping/retrieve_sample_image.py +71 -0
  115. megadetector/taxonomy_mapping/simple_image_download.py +224 -0
  116. megadetector/taxonomy_mapping/species_lookup.py +1008 -0
  117. megadetector/taxonomy_mapping/taxonomy_csv_checker.py +159 -0
  118. megadetector/taxonomy_mapping/taxonomy_graph.py +346 -0
  119. megadetector/taxonomy_mapping/validate_lila_category_mappings.py +83 -0
  120. megadetector/tests/__init__.py +0 -0
  121. megadetector/tests/test_nms_synthetic.py +335 -0
  122. megadetector/utils/__init__.py +0 -0
  123. megadetector/utils/ct_utils.py +1857 -0
  124. megadetector/utils/directory_listing.py +199 -0
  125. megadetector/utils/extract_frames_from_video.py +307 -0
  126. megadetector/utils/gpu_test.py +125 -0
  127. megadetector/utils/md_tests.py +2072 -0
  128. megadetector/utils/path_utils.py +2832 -0
  129. megadetector/utils/process_utils.py +172 -0
  130. megadetector/utils/split_locations_into_train_val.py +237 -0
  131. megadetector/utils/string_utils.py +234 -0
  132. megadetector/utils/url_utils.py +825 -0
  133. megadetector/utils/wi_platform_utils.py +968 -0
  134. megadetector/utils/wi_taxonomy_utils.py +1759 -0
  135. megadetector/utils/write_html_image_list.py +239 -0
  136. megadetector/visualization/__init__.py +0 -0
  137. megadetector/visualization/plot_utils.py +309 -0
  138. megadetector/visualization/render_images_with_thumbnails.py +243 -0
  139. megadetector/visualization/visualization_utils.py +1940 -0
  140. megadetector/visualization/visualize_db.py +630 -0
  141. megadetector/visualization/visualize_detector_output.py +479 -0
  142. megadetector/visualization/visualize_video_output.py +705 -0
  143. megadetector-10.0.13.dist-info/METADATA +134 -0
  144. megadetector-10.0.13.dist-info/RECORD +147 -0
  145. megadetector-10.0.13.dist-info/WHEEL +5 -0
  146. megadetector-10.0.13.dist-info/licenses/LICENSE +19 -0
  147. megadetector-10.0.13.dist-info/top_level.txt +1 -0
@@ -0,0 +1,226 @@
1
+ """
2
+
3
+ csv_to_json.py
4
+
5
+ Converts CSV to JSON format for label specification.
6
+
7
+ There are 3 possible values for the 'type' column in the CSV:
8
+
9
+ - "row": this selects a specific rowfrom the master taxonomy CSV
10
+ content syntax: <dataset_name>|<dataset_label>
11
+
12
+ - "datasettaxon": this selects all animals in a taxon from a particular dataset
13
+ content syntax: <dataset_name>|<taxon_level>|<taxon_name>
14
+
15
+ - <taxon_level>: this selects all animals in a taxon across all datasets
16
+ content syntax: <taxon_name>
17
+
18
+ Example CSV input:
19
+
20
+ "
21
+ # comment lines starting with '#' are allowed
22
+ output_label,type,content
23
+ cervid,row,idfg|deer
24
+ cervid,row,idfg|elk
25
+ cervid,row,idfg|prong
26
+ cervid,row,idfg_swwlf_2019|elk
27
+ cervid,row,idfg_swwlf_2019|muledeer
28
+ cervid,row,idfg_swwlf_2019|whitetaileddeer
29
+ cervid,max_count,50000
30
+ cervid,family,cervidae
31
+ cervid,datasettaxon,idfg|family|cervidae
32
+ cervid,datasettaxon,idfg_swwlf_2019|family|cervidae
33
+ bird,row,idfg_swwlf_2019|bird
34
+ bird,class,aves
35
+ bird,max_count,50000
36
+ bird,prioritize,"[['idfg_swwlf_2019'], ['idfg']]"
37
+ !bird,row,idfg_swwlf_2019|turkey
38
+ !bird,genus,meleagris
39
+ "
40
+
41
+ Example JSON output:
42
+
43
+ "
44
+ {
45
+ "cervid": {
46
+ "dataset_labels": {
47
+ "idfg": ["deer", "elk", "prong"],
48
+ "idfg_swwlf_2019": ["elk", "muledeer", "whitetaileddeer"]
49
+ },
50
+ "taxa": [
51
+ {
52
+ "level": "family",
53
+ "name": "cervidae"
54
+ },
55
+ {
56
+ "level": "family",
57
+ "name": "cervidae"
58
+ "datasets": ["idfg"]
59
+ },
60
+ {
61
+ "level": "family",
62
+ "name": "cervidae"
63
+ "datasets": ["idfg_swwlf_2019"]
64
+ }
65
+ ],
66
+ "max_count": 50000
67
+ },
68
+ "bird": {
69
+ "dataset_labels": {
70
+ "idfg_swwlf_2019": ["bird"]
71
+ },
72
+ "taxa": [
73
+ {
74
+ "level": "class",
75
+ "name": "aves"
76
+ }
77
+ ],
78
+ "exclude": {
79
+ "dataset_labels": {
80
+ "idfg_swwlf_2019": ["turkey"]
81
+ },
82
+ "taxa": [
83
+ {
84
+ "level": "genus",
85
+ "name": "meleagris"
86
+ }
87
+ ]
88
+ },
89
+ "max_count": "50000",
90
+ "prioritize": [
91
+ ["idfg_swwlf_2019"],
92
+ ["idfg"]
93
+ ],
94
+ }
95
+ }
96
+ "
97
+
98
+ """
99
+
100
+ #%% Imports
101
+
102
+ from __future__ import annotations
103
+
104
+ import argparse
105
+ from collections import defaultdict
106
+ import json
107
+ from typing import Any
108
+
109
+ import pandas as pd
110
+ from megadetector.utils import ct_utils
111
+
112
+
113
+ #%% Main function
114
+
115
+ def main(): # noqa
116
+ args = _parse_args()
117
+ js = csv_to_jsondict(args.input_csv_file)
118
+ for label in js:
119
+ js[label] = order_spec_dict(js[label])
120
+ ct_utils.write_json(args.output_json_path, js, indent=args.json_indent)
121
+
122
+
123
+ #%% Support functions
124
+
125
+ def parse_csv_row(obj: dict[str, Any], rowtype: str, content: str) -> None:
126
+ """
127
+ Parses a row in the CSV.
128
+ """
129
+
130
+ if rowtype == 'row':
131
+ if 'dataset_labels' not in obj:
132
+ obj['dataset_labels'] = defaultdict(list)
133
+
134
+ assert '|' in content
135
+ ds, ds_label = content.split('|')
136
+ obj['dataset_labels'][ds].append(ds_label)
137
+
138
+ elif rowtype == 'datasettaxon':
139
+ if 'taxa' not in obj:
140
+ obj['taxa'] = []
141
+
142
+ assert '|' in content
143
+ ds, taxon_level, taxon_name = content.split('|')
144
+ obj['taxa'].append({
145
+ 'level': taxon_level,
146
+ 'name': taxon_name,
147
+ 'datasets': [ds]
148
+ })
149
+
150
+ elif rowtype == 'max_count':
151
+ obj['max_count'] = int(content)
152
+
153
+ elif rowtype == 'prioritize':
154
+ obj['prioritize'] = eval(content) # pylint: disable=eval-used
155
+
156
+ else:
157
+ if 'taxa' not in obj:
158
+ obj['taxa'] = []
159
+
160
+ taxon_level = rowtype
161
+ taxon_name = content
162
+ obj['taxa'].append({
163
+ 'level': taxon_level,
164
+ 'name': taxon_name
165
+ })
166
+
167
+
168
+ def csv_to_jsondict(csv_path: str) -> dict[str, dict[str, Any]]:
169
+ """
170
+ Converts CSV to json-style dictionary.
171
+ """
172
+
173
+ df = pd.read_csv(csv_path, comment='#', skip_blank_lines=True)
174
+ assert (df.columns == ['output_label', 'type', 'content']).all()
175
+
176
+ js: defaultdict[str, dict[str, Any]] = defaultdict(dict)
177
+
178
+ for i in df.index:
179
+ label, rowtype, content = df.loc[i]
180
+ if label.startswith('!'):
181
+ label = label[1:]
182
+ if 'exclude' not in js[label]:
183
+ js[label]['exclude'] = {}
184
+ obj = js[label]['exclude']
185
+ else:
186
+ obj = js[label]
187
+ parse_csv_row(obj, rowtype, content)
188
+
189
+ return js
190
+
191
+
192
+ def order_spec_dict(spec_dict: dict[str, Any]) -> dict[str, Any]:
193
+ """
194
+ Returns spec_dict with keys in a specific order.
195
+ """
196
+
197
+ if 'exclude' in spec_dict:
198
+ spec_dict['exclude'] = order_spec_dict(spec_dict['exclude'])
199
+ ordered_spec_dict: dict[str, Any] = {}
200
+ for key in ['dataset_labels', 'taxa', 'exclude', 'max_count', 'prioritize']:
201
+ if key in spec_dict:
202
+ ordered_spec_dict[key] = spec_dict[key]
203
+ return ordered_spec_dict
204
+
205
+
206
+ #%% Command-line driver
207
+
208
+ def _parse_args() -> argparse.Namespace:
209
+
210
+ parser = argparse.ArgumentParser(
211
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter,
212
+ description='Converts CSV to JSON format for label specification.')
213
+ parser.add_argument(
214
+ 'input_csv_file',
215
+ help='path to CSV file containing label specification')
216
+ parser.add_argument(
217
+ 'output_json_path',
218
+ help='path to save converted JSON file')
219
+ parser.add_argument(
220
+ '--json-indent', type=int,
221
+ help='number of spaces to use for JSON indent (default no indent)')
222
+ return parser.parse_args()
223
+
224
+
225
+ if __name__ == '__main__':
226
+ main()