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,206 @@
1
+ r"""
2
+
3
+ find_repeat_detections.py
4
+
5
+ If you want to use this script, we recommend that you read the RDE user's guide:
6
+
7
+ https://github.com/agentmorris/MegaDetector/tree/main/megadetector/postprocessing/repeat_detection_elimination
8
+
9
+ Really, don't try to run this script without reading the user's guide, you'll think
10
+ it's more magical than it is.
11
+
12
+ This script looks through a sequence of detections in the API output json file, and finds
13
+ candidates that might be "repeated false positives", i.e. that random branch that the
14
+ detector thinks is an animal/person/vehicle.
15
+
16
+ Typically after running this script, you would do a manual step to remove
17
+ true positives, then run remove_repeat_detections to produce a final output file.
18
+
19
+ There's no way that statement was self-explanatory; see the user's guide.
20
+
21
+ This script is just a command-line driver for repeat_detections_core.py.
22
+
23
+ """
24
+
25
+ #%% Constants and imports
26
+
27
+ import argparse
28
+ import os
29
+ import sys
30
+
31
+ from megadetector.utils import ct_utils
32
+ from megadetector.postprocessing.repeat_detection_elimination import repeat_detections_core
33
+
34
+
35
+ #%% Interactive driver
36
+
37
+ if False:
38
+
39
+ #%%
40
+
41
+ base_dir = ''
42
+
43
+ options = repeat_detections_core.RepeatDetectionOptions()
44
+ options.imageBase = base_dir
45
+ options.outputBase = os.path.join(base_dir, 'repeat_detections')
46
+ options.filenameReplacements = {} # E.g., {'20190430cameratraps\\':''}
47
+
48
+ options.confidenceMin = 0.15
49
+ options.confidenceMax = 1.01
50
+ options.iouThreshold = 0.85
51
+ options.occurrenceThreshold = 8
52
+ options.maxSuspiciousDetectionSize = 0.2
53
+
54
+ options.filterFileToLoad = ''
55
+ options.filterFileToLoad = os.path.join(base_dir,r'..\detectionIndex.json')
56
+
57
+ options.debugMaxDir = -1
58
+ options.debugMaxRenderDir = -1
59
+ options.debugMaxRenderDetection = -1
60
+ options.debugMaxRenderInstance = -1
61
+
62
+ options.bParallelizeComparisons = False
63
+ options.bParallelizeRendering = False
64
+ options.excludeClasses = [2]
65
+
66
+ input_filename = os.path.join(base_dir, 'blah.json')
67
+ output_filename = os.path.join(base_dir, 'blah.json')
68
+
69
+ results = repeat_detections_core.find_repeat_detections(input_filename, output_filename, options)
70
+
71
+
72
+ #%% Command-line driver
73
+
74
+ def main(): # noqa
75
+
76
+ default_options = repeat_detections_core.RepeatDetectionOptions()
77
+
78
+ parser = argparse.ArgumentParser()
79
+
80
+ parser.add_argument('inputFile', type=str, help='MD results .json file to process')
81
+
82
+ parser.add_argument('--outputFile', action='store', type=str, default=None,
83
+ help='.json file to write filtered results to... do not use this if you are going to ' + \
84
+ 'do manual review of the repeat detection images (which you should)')
85
+
86
+ parser.add_argument('--imageBase', action='store', type=str, default='',
87
+ help='Image base dir')
88
+
89
+ parser.add_argument('--outputBase', action='store', type=str, default='',
90
+ help='filtering folder output dir')
91
+
92
+ parser.add_argument('--confidenceMin', action='store', type=float,
93
+ default=default_options.confidenceMin,
94
+ help='Detection confidence threshold; don\'t process anything below this')
95
+
96
+ parser.add_argument('--confidenceMax', action='store', type=float,
97
+ default=default_options.confidenceMax,
98
+ help='Detection confidence threshold; don\'t process anything above this')
99
+
100
+ parser.add_argument('--iouThreshold', action='store', type=float,
101
+ default=default_options.iouThreshold,
102
+ help='Detections with IOUs greater than this are considered ' + \
103
+ '"the same detection"')
104
+
105
+ parser.add_argument('--occurrenceThreshold', action='store', type=int,
106
+ default=default_options.occurrenceThreshold,
107
+ help='More than this many near-identical detections in a group ' + \
108
+ '(e.g. a folder) is considered suspicious')
109
+
110
+ parser.add_argument('--minSuspiciousDetectionSize', action='store', type=float,
111
+ default=default_options.minSuspiciousDetectionSize,
112
+ help='Detections smaller than this fraction of image area are not ' + \
113
+ 'considered suspicious')
114
+
115
+ parser.add_argument('--maxSuspiciousDetectionSize', action='store', type=float,
116
+ default=default_options.maxSuspiciousDetectionSize,
117
+ help='Detections larger than this fraction of image area are not ' + \
118
+ 'considered suspicious')
119
+
120
+ parser.add_argument('--maxImagesPerFolder', action='store', type=int,
121
+ default=default_options.maxImagesPerFolder,
122
+ help='Ignore folders with more than this many images in them')
123
+
124
+ parser.add_argument('--excludeClasses', action='store', nargs='+', type=int,
125
+ default=None,
126
+ help='List of integer classes we don\'t want to treat as suspicious, separated by spaces.')
127
+
128
+ parser.add_argument('--pass_detections_to_processes_method', action='store', type=str,
129
+ default=default_options.pass_detections_to_processes_method,
130
+ help='Pass detections information to/from workers via "memory" (default) or "files"')
131
+
132
+ parser.add_argument('--nWorkers', action='store', type=int,
133
+ default=default_options.nWorkers,
134
+ help='Level of parallelism for rendering and IOU computation')
135
+
136
+ parser.add_argument('--parallelizationUsesProcesses', action='store_false',
137
+ dest='parallelizationUsesThreads',
138
+ help='Parallelize with processes (defaults to threads)')
139
+
140
+ parser.add_argument('--filterFileToLoad', action='store', type=str, default='',
141
+ help='Path to detectionIndex.json, which should be inside a ' + \
142
+ 'folder of images that are manually verified to _not_ ' + \
143
+ 'contain valid animals')
144
+
145
+ parser.add_argument('--omitFilteringFolder', action='store_false',
146
+ dest='bWriteFilteringFolder',
147
+ help='Should we skip creating the folder of rendered detections filtering?')
148
+
149
+ parser.add_argument('--debugMaxDir', action='store', type=int, default=-1,
150
+ help='For debugging only, limit the number of directories we process')
151
+ parser.add_argument('--debugMaxRenderDir', action='store', type=int, default=-1,
152
+ help='For debugging only, limit the number of directories we render')
153
+ parser.add_argument('--debugMaxRenderDetection', action='store', type=int, default=-1,
154
+ help='For debugging only, limit the number of detections we process per folder')
155
+ parser.add_argument('--debugMaxRenderInstance', action='store', type=int, default=-1,
156
+ help='For debugging only, limit the number of instances we process per detection')
157
+
158
+ parser.add_argument('--forceSerialComparisons', action='store_false',
159
+ dest='bParallelizeComparisons',
160
+ help='Disable parallelization during the comparison stage')
161
+ parser.add_argument('--forceSerialRendering', action='store_false',
162
+ dest='bParallelizeRendering',
163
+ help='Disable parallelization during the rendering stage')
164
+
165
+ parser.add_argument('--maxOutputImageWidth', action='store', type=int,
166
+ default=default_options.maxOutputImageWidth,
167
+ help='Maximum output size for thumbnail images')
168
+
169
+ parser.add_argument('--lineThickness', action='store', type=int,
170
+ default=default_options.lineThickness,
171
+ help='Line thickness thumbnail images')
172
+
173
+ parser.add_argument('--boxExpansion', action='store', type=int,
174
+ default=default_options.boxExpansion,
175
+ help='Box expansion for thumbnail images')
176
+
177
+ parser.add_argument('--nDirLevelsFromLeaf', type=int,
178
+ default=default_options.nDirLevelsFromLeaf,
179
+ help='Number of levels from the leaf folders to use for repeat ' + \
180
+ 'detection (0 == leaves)')
181
+
182
+ parser.add_argument('--bRenderOtherDetections', action='store_true',
183
+ help='Show non-target detections in light gray on each image')
184
+
185
+ parser.add_argument('--bRenderDetectionTiles', action='store_true',
186
+ help='Should we render a grid showing every instance (up to a limit) for each detection?')
187
+
188
+ parser.add_argument('--detectionTilesPrimaryImageWidth', type=int,
189
+ default=default_options.detectionTilesPrimaryImageWidth,
190
+ help='The width of the main image when rendering images with detection tiles')
191
+
192
+ if len(sys.argv[1:]) == 0:
193
+ parser.print_help()
194
+ parser.exit()
195
+
196
+ args = parser.parse_args()
197
+
198
+ # Convert to an options object
199
+ options = repeat_detections_core.RepeatDetectionOptions()
200
+
201
+ ct_utils.args_to_object(args, options)
202
+
203
+ repeat_detections_core.find_repeat_detections(args.inputFile, args.outputFile, options)
204
+
205
+ if __name__ == '__main__':
206
+ main()
@@ -0,0 +1,82 @@
1
+ """
2
+
3
+ remove_repeat_detections.py
4
+
5
+ Used after running find_repeat_detections, then manually filtering the results,
6
+ to create a final filtered output file.
7
+
8
+ If you want to use this script, we recommend that you read the RDE user's guide:
9
+
10
+ https://github.com/agentmorris/MegaDetector/tree/main/megadetector/postprocessing/repeat_detection_elimination
11
+
12
+ """
13
+
14
+ #%% Constants and imports
15
+
16
+ import argparse
17
+ import os
18
+ import sys
19
+
20
+ from megadetector.postprocessing.repeat_detection_elimination import repeat_detections_core
21
+
22
+
23
+ #%% Main function
24
+
25
+ def remove_repeat_detections(input_file,output_file,filtering_dir):
26
+ """
27
+ Given an index file that was produced in a first pass through find_repeat_detections,
28
+ and a folder of images (from which the user has deleted images they don't want removed),
29
+ remove the identified repeat detections from a set of MD results and write to a new file.
30
+
31
+ Args:
32
+ input_file (str): .json file of MD results, from which we should remove repeat detections
33
+ output_file (str): output .json file to which we should write MD results (with repeat
34
+ detections removed)
35
+ filtering_dir (str): the folder produced by find_repeat_detections, containing a
36
+ detectionIndex.json file
37
+ """
38
+
39
+ assert os.path.isfile(input_file), "Can't find file {}".format(input_file)
40
+ assert os.path.exists(filtering_dir), "Can't find input file/folder {}".format(filtering_dir)
41
+ options = repeat_detections_core.RepeatDetectionOptions()
42
+ if os.path.isfile(filtering_dir):
43
+ options.filterFileToLoad = filtering_dir
44
+ else:
45
+ assert os.path.isdir(filtering_dir), '{} is not a valid folder'.format(filtering_dir)
46
+ options.filterFileToLoad = \
47
+ os.path.join(filtering_dir,repeat_detections_core.detection_index_file_name_base)
48
+ repeat_detections_core.find_repeat_detections(input_file, output_file, options)
49
+
50
+
51
+ #%% Interactive driver
52
+
53
+ if False:
54
+
55
+ #%%
56
+
57
+ input_file = r''
58
+ output_file = r''
59
+ filtering_dir = r''
60
+ remove_repeat_detections(input_file,output_file,filtering_dir)
61
+
62
+
63
+ #%% Command-line driver
64
+
65
+ def main(): # noqa
66
+
67
+ parser = argparse.ArgumentParser()
68
+ parser.add_argument('input_file', help='.json file containing the original, unfiltered API results')
69
+ parser.add_argument('output_file', help='.json file to which you want to write the final, ' + \
70
+ 'filtered API results')
71
+ parser.add_argument('filtering_dir', help='directory where you looked at lots of images and ' + \
72
+ 'decided which ones were really false positives')
73
+
74
+ if len(sys.argv[1:]) == 0:
75
+ parser.print_help()
76
+ parser.exit()
77
+
78
+ args = parser.parse_args()
79
+ remove_repeat_detections(args.input_file, args.output_file, args.filtering_dir)
80
+
81
+ if __name__ == '__main__':
82
+ main()