megadetector 5.0.8__py3-none-any.whl → 5.0.10__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 (190) hide show
  1. api/__init__.py +0 -0
  2. api/batch_processing/__init__.py +0 -0
  3. api/batch_processing/api_core/__init__.py +0 -0
  4. api/batch_processing/api_core/batch_service/__init__.py +0 -0
  5. api/batch_processing/api_core/batch_service/score.py +0 -1
  6. api/batch_processing/api_core/server_job_status_table.py +0 -1
  7. api/batch_processing/api_core_support/__init__.py +0 -0
  8. api/batch_processing/api_core_support/aggregate_results_manually.py +0 -1
  9. api/batch_processing/api_support/__init__.py +0 -0
  10. api/batch_processing/api_support/summarize_daily_activity.py +0 -1
  11. api/batch_processing/data_preparation/__init__.py +0 -0
  12. api/batch_processing/data_preparation/manage_local_batch.py +65 -65
  13. api/batch_processing/data_preparation/manage_video_batch.py +8 -8
  14. api/batch_processing/integration/digiKam/xmp_integration.py +0 -1
  15. api/batch_processing/integration/eMammal/test_scripts/push_annotations_to_emammal.py +0 -1
  16. api/batch_processing/postprocessing/__init__.py +0 -0
  17. api/batch_processing/postprocessing/add_max_conf.py +12 -12
  18. api/batch_processing/postprocessing/categorize_detections_by_size.py +32 -14
  19. api/batch_processing/postprocessing/combine_api_outputs.py +68 -54
  20. api/batch_processing/postprocessing/compare_batch_results.py +113 -43
  21. api/batch_processing/postprocessing/convert_output_format.py +41 -16
  22. api/batch_processing/postprocessing/load_api_results.py +16 -17
  23. api/batch_processing/postprocessing/md_to_coco.py +31 -21
  24. api/batch_processing/postprocessing/md_to_labelme.py +52 -22
  25. api/batch_processing/postprocessing/merge_detections.py +14 -14
  26. api/batch_processing/postprocessing/postprocess_batch_results.py +246 -174
  27. api/batch_processing/postprocessing/remap_detection_categories.py +32 -25
  28. api/batch_processing/postprocessing/render_detection_confusion_matrix.py +60 -27
  29. api/batch_processing/postprocessing/repeat_detection_elimination/find_repeat_detections.py +53 -44
  30. api/batch_processing/postprocessing/repeat_detection_elimination/remove_repeat_detections.py +25 -14
  31. api/batch_processing/postprocessing/repeat_detection_elimination/repeat_detections_core.py +242 -158
  32. api/batch_processing/postprocessing/separate_detections_into_folders.py +159 -114
  33. api/batch_processing/postprocessing/subset_json_detector_output.py +146 -169
  34. api/batch_processing/postprocessing/top_folders_to_bottom.py +77 -43
  35. api/synchronous/__init__.py +0 -0
  36. api/synchronous/api_core/animal_detection_api/__init__.py +0 -0
  37. api/synchronous/api_core/animal_detection_api/api_backend.py +0 -2
  38. api/synchronous/api_core/animal_detection_api/api_frontend.py +266 -268
  39. api/synchronous/api_core/animal_detection_api/config.py +35 -35
  40. api/synchronous/api_core/tests/__init__.py +0 -0
  41. api/synchronous/api_core/tests/load_test.py +109 -109
  42. classification/__init__.py +0 -0
  43. classification/aggregate_classifier_probs.py +21 -24
  44. classification/analyze_failed_images.py +11 -13
  45. classification/cache_batchapi_outputs.py +51 -51
  46. classification/create_classification_dataset.py +69 -68
  47. classification/crop_detections.py +54 -53
  48. classification/csv_to_json.py +97 -100
  49. classification/detect_and_crop.py +105 -105
  50. classification/evaluate_model.py +43 -42
  51. classification/identify_mislabeled_candidates.py +47 -46
  52. classification/json_to_azcopy_list.py +10 -10
  53. classification/json_validator.py +72 -71
  54. classification/map_classification_categories.py +44 -43
  55. classification/merge_classification_detection_output.py +68 -68
  56. classification/prepare_classification_script.py +157 -154
  57. classification/prepare_classification_script_mc.py +228 -228
  58. classification/run_classifier.py +27 -26
  59. classification/save_mislabeled.py +30 -30
  60. classification/train_classifier.py +20 -20
  61. classification/train_classifier_tf.py +21 -22
  62. classification/train_utils.py +10 -10
  63. data_management/__init__.py +0 -0
  64. data_management/annotations/__init__.py +0 -0
  65. data_management/annotations/annotation_constants.py +18 -31
  66. data_management/camtrap_dp_to_coco.py +238 -0
  67. data_management/cct_json_utils.py +102 -59
  68. data_management/cct_to_md.py +176 -158
  69. data_management/cct_to_wi.py +247 -219
  70. data_management/coco_to_labelme.py +272 -263
  71. data_management/coco_to_yolo.py +79 -58
  72. data_management/databases/__init__.py +0 -0
  73. data_management/databases/add_width_and_height_to_db.py +20 -16
  74. data_management/databases/combine_coco_camera_traps_files.py +35 -31
  75. data_management/databases/integrity_check_json_db.py +62 -24
  76. data_management/databases/subset_json_db.py +24 -15
  77. data_management/generate_crops_from_cct.py +27 -45
  78. data_management/get_image_sizes.py +188 -162
  79. data_management/importers/add_nacti_sizes.py +8 -8
  80. data_management/importers/add_timestamps_to_icct.py +78 -78
  81. data_management/importers/animl_results_to_md_results.py +158 -158
  82. data_management/importers/auckland_doc_test_to_json.py +9 -9
  83. data_management/importers/auckland_doc_to_json.py +8 -8
  84. data_management/importers/awc_to_json.py +7 -7
  85. data_management/importers/bellevue_to_json.py +15 -15
  86. data_management/importers/cacophony-thermal-importer.py +13 -13
  87. data_management/importers/carrizo_shrubfree_2018.py +8 -8
  88. data_management/importers/carrizo_trail_cam_2017.py +8 -8
  89. data_management/importers/cct_field_adjustments.py +9 -9
  90. data_management/importers/channel_islands_to_cct.py +10 -10
  91. data_management/importers/eMammal/copy_and_unzip_emammal.py +1 -0
  92. data_management/importers/ena24_to_json.py +7 -7
  93. data_management/importers/filenames_to_json.py +8 -8
  94. data_management/importers/helena_to_cct.py +7 -7
  95. data_management/importers/idaho-camera-traps.py +7 -7
  96. data_management/importers/idfg_iwildcam_lila_prep.py +10 -10
  97. data_management/importers/jb_csv_to_json.py +9 -9
  98. data_management/importers/mcgill_to_json.py +8 -8
  99. data_management/importers/missouri_to_json.py +18 -18
  100. data_management/importers/nacti_fieldname_adjustments.py +10 -10
  101. data_management/importers/noaa_seals_2019.py +7 -7
  102. data_management/importers/pc_to_json.py +7 -7
  103. data_management/importers/plot_wni_giraffes.py +7 -7
  104. data_management/importers/prepare-noaa-fish-data-for-lila.py +359 -359
  105. data_management/importers/prepare_zsl_imerit.py +7 -7
  106. data_management/importers/rspb_to_json.py +8 -8
  107. data_management/importers/save_the_elephants_survey_A.py +8 -8
  108. data_management/importers/save_the_elephants_survey_B.py +9 -9
  109. data_management/importers/snapshot_safari_importer.py +26 -26
  110. data_management/importers/snapshot_safari_importer_reprise.py +665 -665
  111. data_management/importers/snapshot_serengeti_lila.py +14 -14
  112. data_management/importers/sulross_get_exif.py +8 -9
  113. data_management/importers/timelapse_csv_set_to_json.py +11 -11
  114. data_management/importers/ubc_to_json.py +13 -13
  115. data_management/importers/umn_to_json.py +7 -7
  116. data_management/importers/wellington_to_json.py +8 -8
  117. data_management/importers/wi_to_json.py +9 -9
  118. data_management/importers/zamba_results_to_md_results.py +181 -181
  119. data_management/labelme_to_coco.py +65 -24
  120. data_management/labelme_to_yolo.py +8 -8
  121. data_management/lila/__init__.py +0 -0
  122. data_management/lila/add_locations_to_island_camera_traps.py +9 -9
  123. data_management/lila/add_locations_to_nacti.py +147 -147
  124. data_management/lila/create_lila_blank_set.py +13 -13
  125. data_management/lila/create_lila_test_set.py +8 -8
  126. data_management/lila/create_links_to_md_results_files.py +106 -106
  127. data_management/lila/download_lila_subset.py +44 -110
  128. data_management/lila/generate_lila_per_image_labels.py +55 -42
  129. data_management/lila/get_lila_annotation_counts.py +18 -15
  130. data_management/lila/get_lila_image_counts.py +11 -11
  131. data_management/lila/lila_common.py +96 -33
  132. data_management/lila/test_lila_metadata_urls.py +132 -116
  133. data_management/ocr_tools.py +173 -128
  134. data_management/read_exif.py +110 -97
  135. data_management/remap_coco_categories.py +83 -83
  136. data_management/remove_exif.py +58 -62
  137. data_management/resize_coco_dataset.py +30 -23
  138. data_management/wi_download_csv_to_coco.py +246 -239
  139. data_management/yolo_output_to_md_output.py +86 -73
  140. data_management/yolo_to_coco.py +300 -60
  141. detection/__init__.py +0 -0
  142. detection/detector_training/__init__.py +0 -0
  143. detection/process_video.py +85 -33
  144. detection/pytorch_detector.py +43 -25
  145. detection/run_detector.py +157 -72
  146. detection/run_detector_batch.py +179 -113
  147. detection/run_inference_with_yolov5_val.py +108 -48
  148. detection/run_tiled_inference.py +111 -40
  149. detection/tf_detector.py +51 -29
  150. detection/video_utils.py +606 -521
  151. docs/source/conf.py +43 -0
  152. md_utils/__init__.py +0 -0
  153. md_utils/azure_utils.py +9 -9
  154. md_utils/ct_utils.py +228 -68
  155. md_utils/directory_listing.py +59 -64
  156. md_utils/md_tests.py +968 -871
  157. md_utils/path_utils.py +460 -134
  158. md_utils/process_utils.py +157 -133
  159. md_utils/sas_blob_utils.py +20 -20
  160. md_utils/split_locations_into_train_val.py +45 -32
  161. md_utils/string_utils.py +33 -10
  162. md_utils/url_utils.py +176 -60
  163. md_utils/write_html_image_list.py +40 -33
  164. md_visualization/__init__.py +0 -0
  165. md_visualization/plot_utils.py +102 -109
  166. md_visualization/render_images_with_thumbnails.py +34 -34
  167. md_visualization/visualization_utils.py +597 -291
  168. md_visualization/visualize_db.py +76 -48
  169. md_visualization/visualize_detector_output.py +61 -42
  170. {megadetector-5.0.8.dist-info → megadetector-5.0.10.dist-info}/METADATA +13 -7
  171. megadetector-5.0.10.dist-info/RECORD +224 -0
  172. {megadetector-5.0.8.dist-info → megadetector-5.0.10.dist-info}/top_level.txt +1 -0
  173. taxonomy_mapping/__init__.py +0 -0
  174. taxonomy_mapping/map_lila_taxonomy_to_wi_taxonomy.py +342 -335
  175. taxonomy_mapping/map_new_lila_datasets.py +154 -154
  176. taxonomy_mapping/prepare_lila_taxonomy_release.py +142 -134
  177. taxonomy_mapping/preview_lila_taxonomy.py +591 -591
  178. taxonomy_mapping/retrieve_sample_image.py +12 -12
  179. taxonomy_mapping/simple_image_download.py +11 -11
  180. taxonomy_mapping/species_lookup.py +10 -10
  181. taxonomy_mapping/taxonomy_csv_checker.py +18 -18
  182. taxonomy_mapping/taxonomy_graph.py +47 -47
  183. taxonomy_mapping/validate_lila_category_mappings.py +83 -76
  184. data_management/cct_json_to_filename_json.py +0 -89
  185. data_management/cct_to_csv.py +0 -140
  186. data_management/databases/remove_corrupted_images_from_db.py +0 -191
  187. detection/detector_training/copy_checkpoints.py +0 -43
  188. megadetector-5.0.8.dist-info/RECORD +0 -205
  189. {megadetector-5.0.8.dist-info → megadetector-5.0.10.dist-info}/LICENSE +0 -0
  190. {megadetector-5.0.8.dist-info → megadetector-5.0.10.dist-info}/WHEEL +0 -0
@@ -1,13 +1,13 @@
1
- ########
2
- #
3
- # remap_detection_categories.py
4
- #
5
- # Given a MegaDetector results file, remap the category IDs according to a specified
6
- # dictionary, writing the results to a new file.
7
- #
8
- # Currently only supports remapping detection categories, not classification categories.
9
- #
10
- ########
1
+ """
2
+
3
+ remap_detection_categories.py
4
+
5
+ Given a MegaDetector results file, remap the category IDs according to a specified
6
+ dictionary, writing the results to a new file.
7
+
8
+ Currently only supports remapping detection categories, not classification categories.
9
+
10
+ """
11
11
 
12
12
  #%% Constants and imports
13
13
 
@@ -27,27 +27,35 @@ def remap_detection_categories(input_file,
27
27
  extra_category_handling='error',
28
28
  overwrite=False):
29
29
  """
30
- Given a MD results file [input_file], remap the category IDs according to the dictionary
30
+ Given a MegaDetector results file [input_file], remap the category IDs according to the dictionary
31
31
  [target_category_map], writing the results to [output_file]. The remapped dictionary needs to have
32
32
  the same category names as the input file's detection_categories dictionary.
33
33
 
34
- Currently only supports remapping detection categories, not classification categories.
35
-
36
- target_category_map can also be a MD results file, in which case we'll use that file's
37
- detection_categories dictionary.
34
+ Typically used to map, e.g., a variety of species to the class "mammal" or the class "animal".
38
35
 
39
- [extra_category_handling] specifies what we should do if categories are present in the source file
40
- that are not present in the target mapping.
41
-
42
- 'error' == Error in this case.
43
- 'drop_if_unused' == Don't include these in the output file's category mappings if they are unused,
44
- error if they are.
45
- 'remap' == Remap to unused category IDs. This is reserved for future use, not currently implemented.
36
+ Currently only supports remapping detection categories, not classification categories.
46
37
 
38
+ Args:
39
+ input_file (str): the MD .json results file to remap
40
+ output_file (str): the remapped .json file to write
41
+ target_category_map (dict): the category mapping that should be used in the output file.
42
+ This can also be a MD results file, in which case we'll use that file's
43
+ detection_categories dictionary.
44
+ extra_category_handling (str, optional): specifies what we should do if categories are present
45
+ in the source file that are not present in the target mapping:
46
+
47
+ * 'error' == Error in this case.
48
+ * 'drop_if_unused' == Don't include these in the output file's category mappings if they are
49
+ unused, error if they are.
50
+ * 'remap' == Remap to unused category IDs. This is reserved for future use, not currently
51
+ implemented.
52
+ overwrite (bool, optional): whether to overwrite [output_file] if it exists; if this is True and
53
+ [output_file] exists, this function is a no-op
54
+
47
55
  """
48
56
 
49
57
  if os.path.exists(output_file) and (not overwrite):
50
- print('File {} exists, bypassing remapping'.format(output_file))
58
+ print('File {} exists, bypassing remapping'.format(output_file))
51
59
  return
52
60
 
53
61
  assert os.path.isfile(input_file), \
@@ -130,7 +138,7 @@ def remap_detection_categories(input_file,
130
138
 
131
139
 
132
140
  print('Saved remapped results to {}'.format(output_file))
133
-
141
+
134
142
 
135
143
  #%% Interactive driver
136
144
 
@@ -160,4 +168,3 @@ if False:
160
168
  #%% Command-line driver
161
169
 
162
170
  # TODO
163
-
@@ -1,12 +1,12 @@
1
- ########
2
- #
3
- # render_detection_confusion_matrix.py
4
- #
5
- # Given a CCT-formatted ground truth file and a MegaDetector-formatted results file,
6
- # render an HTML confusion matrix. Typically used for multi-class detectors. Currently
7
- # assumes a single class per image.
8
- #
9
- ########
1
+ """
2
+
3
+ render_detection_confusion_matrix.py
4
+
5
+ Given a CCT-formatted ground truth file and a MegaDetector-formatted results file,
6
+ render an HTML confusion matrix. Typically used for multi-class detectors. Currently
7
+ assumes a single class per image.
8
+
9
+ """
10
10
 
11
11
  #%% Imports and constants
12
12
 
@@ -33,7 +33,10 @@ from multiprocessing.pool import Pool
33
33
 
34
34
  #%% Support functions
35
35
 
36
- def image_to_output_file(im,preview_images_folder):
36
+ def _image_to_output_file(im,preview_images_folder):
37
+ """
38
+ Produces a clean filename from im (if [im] is a str) or im['file'] (if [im] is a dict).
39
+ """
37
40
 
38
41
  if isinstance(im,str):
39
42
  filename_relative = im
@@ -44,7 +47,10 @@ def image_to_output_file(im,preview_images_folder):
44
47
  return os.path.join(preview_images_folder,fn_clean)
45
48
 
46
49
 
47
- def render_image(im,render_image_constants):
50
+ def _render_image(im,render_image_constants):
51
+ """
52
+ Internal function for rendering a single image to the confusion matrix preview folder.
53
+ """
48
54
 
49
55
  filename_to_ground_truth_im = render_image_constants['filename_to_ground_truth_im']
50
56
  image_folder = render_image_constants['image_folder']
@@ -56,7 +62,7 @@ def render_image(im,render_image_constants):
56
62
 
57
63
  assert im['file'] in filename_to_ground_truth_im
58
64
 
59
- output_file = image_to_output_file(im,preview_images_folder)
65
+ output_file = _image_to_output_file(im,preview_images_folder)
60
66
  if os.path.isfile(output_file) and not force_render_images:
61
67
  return output_file
62
68
 
@@ -105,9 +111,36 @@ def render_detection_confusion_matrix(ground_truth_file,
105
111
  confidence_thresholds and rendering_confidence_thresholds are dictionaries mapping
106
112
  class names to thresholds. "default" is a special token that will be used for all
107
113
  classes not otherwise assigned thresholds.
114
+
115
+ Args:
116
+ ground_truth_file (str): the CCT-formatted .json file with ground truth information
117
+ results_file (str): the MegaDetector results .json file
118
+ image_folder (str): the folder where images live; filenames in [ground_truth_file] and
119
+ [results_file] should be relative to this folder.
120
+ preview_folder (str): the output folder, i.e. the folder in which we'll create our nifty
121
+ HTML stuff.
122
+ force_rendering_images (bool, optional): if False, skips images that already exist
123
+ confidence_thresholds (dict, optional): a dictionary mapping class names to thresholds;
124
+ all classes not explicitly named here will use the threshold for the "default" category.
125
+ rendering_thresholds (dict, optional): a dictionary mapping class names to thresholds;
126
+ all classes not explicitly named here will use the threshold for the "default" category.
127
+ target_image_size (tuple, optional): output image size, as a pair of ints (width,height). If one
128
+ value is -1 and the other is not, aspect ratio is preserved. If both are -1, the original image
129
+ sizes are preserved.
130
+ parallelize_rendering (bool, optional): enable (default) or disable parallelization when rendering
131
+ parallelize_rendering_n_core (int, optional): number of threads or processes to use for rendering, only
132
+ used if parallelize_rendering is True
133
+ parallelize_rendering_with_threads: whether to use threads (True) or processes (False) when rendering,
134
+ only used if parallelize_rendering is True
135
+ job_name (str, optional): job name to include in big letters in the output file
136
+ model_file (str, optional) model filename to include in HTML output
137
+ empty_category_name (str, optional): special category name that we should treat as empty, typically
138
+ "empty"
139
+ html_image_list_options (dict, optional): options listed passed along to write_html_image_list;
140
+ see write_html_image_list for documentation.
108
141
  """
109
142
 
110
- #%% Argument and path handling
143
+ ##%% Argument and path handling
111
144
 
112
145
  preview_images_folder = os.path.join(preview_folder,'images')
113
146
  os.makedirs(preview_images_folder,exist_ok=True)
@@ -118,7 +151,7 @@ def render_detection_confusion_matrix(ground_truth_file,
118
151
  rendering_confidence_thresholds = {'default':0.4}
119
152
 
120
153
 
121
- #%% Load ground truth
154
+ ##%% Load ground truth
122
155
 
123
156
  with open(ground_truth_file,'r') as f:
124
157
  ground_truth_data_cct = json.load(f)
@@ -129,14 +162,14 @@ def render_detection_confusion_matrix(ground_truth_file,
129
162
  filename_to_ground_truth_im[im['file_name']] = im
130
163
 
131
164
 
132
- #%% Confirm that the ground truth images are present in the image folder
165
+ ##%% Confirm that the ground truth images are present in the image folder
133
166
 
134
167
  ground_truth_images = find_images(image_folder,return_relative_paths=True,recursive=True)
135
168
  assert len(ground_truth_images) == len(ground_truth_data_cct['images'])
136
169
  del ground_truth_images
137
170
 
138
171
 
139
- #%% Map images to categories
172
+ ##%% Map images to categories
140
173
 
141
174
  # gt_image_id_to_image = {im['id']:im for im in ground_truth_data_cct['images']}
142
175
  gt_image_id_to_annotations = defaultdict(list)
@@ -175,7 +208,7 @@ def render_detection_confusion_matrix(ground_truth_file,
175
208
  'No ground truth category assigned to {}'.format(filename)
176
209
 
177
210
 
178
- #%% Load results
211
+ ##%% Load results
179
212
 
180
213
  with open(results_file,'r') as f:
181
214
  md_formatted_results = json.load(f)
@@ -183,7 +216,7 @@ def render_detection_confusion_matrix(ground_truth_file,
183
216
  results_category_id_to_name = md_formatted_results['detection_categories']
184
217
 
185
218
 
186
- #%% Render images with detections
219
+ ##%% Render images with detections
187
220
 
188
221
  render_image_constants = {}
189
222
  render_image_constants['filename_to_ground_truth_im'] = filename_to_ground_truth_im
@@ -211,7 +244,7 @@ def render_detection_confusion_matrix(ground_truth_file,
211
244
  print('Rendering images with {} {}'.format(parallelize_rendering_n_cores,
212
245
  worker_string))
213
246
 
214
- _ = list(tqdm(pool.imap(partial(render_image,render_image_constants=render_image_constants),
247
+ _ = list(tqdm(pool.imap(partial(_render_image,render_image_constants=render_image_constants),
215
248
  md_formatted_results['images']),
216
249
  total=len(md_formatted_results['images'])))
217
250
 
@@ -219,10 +252,10 @@ def render_detection_confusion_matrix(ground_truth_file,
219
252
 
220
253
  # im = md_formatted_results['images'][0]
221
254
  for im in tqdm(md_formatted_results['images']):
222
- render_image(im,render_image_constants)
255
+ _render_image(im,render_image_constants)
223
256
 
224
257
 
225
- #%% Map images to predicted categories, and vice-versa
258
+ ##%% Map images to predicted categories, and vice-versa
226
259
 
227
260
  filename_to_predicted_categories = defaultdict(set)
228
261
  predicted_category_name_to_filenames = defaultdict(set)
@@ -247,7 +280,7 @@ def render_detection_confusion_matrix(ground_truth_file,
247
280
  # ...for each image
248
281
 
249
282
 
250
- #%% Create TP/TN/FP/FN lists
283
+ ##%% Create TP/TN/FP/FN lists
251
284
 
252
285
  category_name_to_image_lists = {}
253
286
 
@@ -301,7 +334,7 @@ def render_detection_confusion_matrix(ground_truth_file,
301
334
  # ...for each filename
302
335
 
303
336
 
304
- #%% Create confusion matrix
337
+ ##%% Create confusion matrix
305
338
 
306
339
  gt_category_name_to_category_index = {}
307
340
 
@@ -383,7 +416,7 @@ def render_detection_confusion_matrix(ground_truth_file,
383
416
  # open_file(cm_figure_fn_abs)
384
417
 
385
418
 
386
- #%% Create HTML confusion matrix
419
+ ##%% Create HTML confusion matrix
387
420
 
388
421
  html_confusion_matrix = '<table class="result-table">\n'
389
422
  html_confusion_matrix += '<tr>\n'
@@ -423,7 +456,7 @@ def render_detection_confusion_matrix(ground_truth_file,
423
456
  title = '<b>Image</b>: {}, <b>Max conf</b>: {:0.3f}'.format(
424
457
  image_filename_relative, max_conf)
425
458
  image_link = 'images/' + os.path.basename(
426
- image_to_output_file(image_filename_relative,preview_images_folder))
459
+ _image_to_output_file(image_filename_relative,preview_images_folder))
427
460
  html_image_info = {
428
461
  'filename': image_link,
429
462
  'title': title,
@@ -527,7 +560,7 @@ def render_detection_confusion_matrix(ground_truth_file,
527
560
  title = '<b>Image</b>: {}, <b>Max conf</b>: {:0.3f}'.format(
528
561
  image_filename_relative, max_conf)
529
562
  image_link = 'images/' + os.path.basename(
530
- image_to_output_file(image_filename_relative,preview_images_folder))
563
+ _image_to_output_file(image_filename_relative,preview_images_folder))
531
564
  html_image_info = {
532
565
  'filename': image_link,
533
566
  'title': title,
@@ -618,7 +651,7 @@ def render_detection_confusion_matrix(ground_truth_file,
618
651
  f.write(html)
619
652
 
620
653
 
621
- #%% Prepare return data
654
+ ##%% Prepare return data
622
655
 
623
656
  confusion_matrix_info = {}
624
657
  confusion_matrix_info['html_file'] = target_html_file
@@ -1,24 +1,26 @@
1
- ########
2
- #
3
- # find_repeat_detections.py
4
- #
5
- # If you want to use this script, we recommend that you read the user's guide:
6
- #
7
- # https://github.com/agentmorris/MegaDetector/tree/master/api/batch_processing/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
- ########
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/master/api/batch_processing/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
+ """
22
24
 
23
25
  #%% Constants and imports
24
26
 
@@ -51,7 +53,7 @@ if False:
51
53
  options.maxSuspiciousDetectionSize = 0.2
52
54
 
53
55
  options.filterFileToLoad = ''
54
- options.filterFileToLoad = os.path.join(baseDir,'...\detectionIndex.json')
56
+ options.filterFileToLoad = os.path.join(baseDir,r'..\detectionIndex.json')
55
57
 
56
58
  options.debugMaxDir = -1
57
59
  options.debugMaxRenderDir = -1
@@ -75,15 +77,16 @@ def main():
75
77
  defaultOptions = repeat_detections_core.RepeatDetectionOptions()
76
78
 
77
79
  parser = argparse.ArgumentParser()
78
- parser.add_argument('inputFile')
80
+
81
+ parser.add_argument('inputFile', type=str, help='MD results .json file to process')
79
82
 
80
83
  parser.add_argument('--outputFile', action='store', type=str, default=None,
81
- help=".json file to write filtered results to... don't use this " + \
82
- "if you're going to do manual review of the repeat detection images")
84
+ help='.json file to write filtered results to... do not use this if you are going to ' + \
85
+ 'do manual review of the repeat detection images (which you should)')
83
86
 
84
87
  parser.add_argument('--imageBase', action='store', type=str, default='',
85
- help='Image base dir, relevant if renderHtml is True or if " + \
86
- "omitFilteringFolder is not set')
88
+ help='Image base dir, relevant if renderHtml is True or if ' + \
89
+ '"omitFilteringFolder" is not set')
87
90
 
88
91
  parser.add_argument('--outputBase', action='store', type=str, default='',
89
92
  help='HTML or filtering folder output dir')
@@ -99,22 +102,22 @@ def main():
99
102
  parser.add_argument('--iouThreshold', action='store', type=float,
100
103
  default=defaultOptions.iouThreshold,
101
104
  help='Detections with IOUs greater than this are considered ' + \
102
- '"the same detection"')
105
+ '"the same detection"')
103
106
 
104
107
  parser.add_argument('--occurrenceThreshold', action='store', type=int,
105
108
  default=defaultOptions.occurrenceThreshold,
106
109
  help='More than this many near-identical detections in a group ' + \
107
- '(e.g. a folder) is considered suspicious')
110
+ '(e.g. a folder) is considered suspicious')
108
111
 
109
112
  parser.add_argument('--minSuspiciousDetectionSize', action='store', type=float,
110
113
  default=defaultOptions.minSuspiciousDetectionSize,
111
114
  help='Detections smaller than this fraction of image area are not ' + \
112
- 'considered suspicious')
115
+ 'considered suspicious')
113
116
 
114
117
  parser.add_argument('--maxSuspiciousDetectionSize', action='store', type=float,
115
118
  default=defaultOptions.maxSuspiciousDetectionSize,
116
119
  help='Detections larger than this fraction of image area are not ' + \
117
- 'considered suspicious')
120
+ 'considered suspicious')
118
121
 
119
122
  parser.add_argument('--maxImagesPerFolder', action='store', type=int,
120
123
  default=defaultOptions.maxImagesPerFolder,
@@ -138,26 +141,32 @@ def main():
138
141
 
139
142
  parser.add_argument('--filterFileToLoad', action='store', type=str, default='',
140
143
  help='Path to detectionIndex.json, which should be inside a ' + \
141
- 'folder of images that are manually verified to _not_ ' + \
142
- 'contain valid animals')
144
+ 'folder of images that are manually verified to _not_ ' + \
145
+ 'contain valid animals')
143
146
 
144
147
  parser.add_argument('--omitFilteringFolder', action='store_false',
145
148
  dest='bWriteFilteringFolder',
146
149
  help='Should we create a folder of rendered detections for post-filtering?')
147
150
 
148
- parser.add_argument('--debugMaxDir', action='store', type=int, default=-1)
149
- parser.add_argument('--debugMaxRenderDir', action='store', type=int, default=-1)
150
- parser.add_argument('--debugMaxRenderDetection', action='store', type=int, default=-1)
151
- parser.add_argument('--debugMaxRenderInstance', action='store', type=int, default=-1)
151
+ parser.add_argument('--debugMaxDir', action='store', type=int, default=-1,
152
+ help='For debugging only, limit the number of directories we process')
153
+ parser.add_argument('--debugMaxRenderDir', action='store', type=int, default=-1,
154
+ help='For debugging only, limit the number of directories we render')
155
+ parser.add_argument('--debugMaxRenderDetection', action='store', type=int, default=-1,
156
+ help='For debugging only, limit the number of detections we process per folder')
157
+ parser.add_argument('--debugMaxRenderInstance', action='store', type=int, default=-1,
158
+ help='For debugging only, limit the number of instances we process per detection')
152
159
 
153
160
  parser.add_argument('--forceSerialComparisons', action='store_false',
154
- dest='bParallelizeComparisons')
161
+ dest='bParallelizeComparisons',
162
+ help='Disable parallelization during the comparison stage')
155
163
  parser.add_argument('--forceSerialRendering', action='store_false',
156
- dest='bParallelizeRendering')
164
+ dest='bParallelizeRendering',
165
+ help='Disable parallelization during the rendering stage')
157
166
 
158
167
  parser.add_argument('--maxOutputImageWidth', action='store', type=int,
159
168
  default=defaultOptions.maxOutputImageWidth,
160
- help='Maximum output size for thumbnail images')
169
+ help='Maximum output size for thumbnail images')
161
170
 
162
171
  parser.add_argument('--lineThickness', action='store', type=int,
163
172
  default=defaultOptions.lineThickness,
@@ -170,16 +179,17 @@ def main():
170
179
  parser.add_argument('--nDirLevelsFromLeaf', type=int,
171
180
  default=defaultOptions.nDirLevelsFromLeaf,
172
181
  help='Number of levels from the leaf folders to use for repeat ' + \
173
- 'detection (0 == leaves)')
182
+ 'detection (0 == leaves)')
174
183
 
175
184
  parser.add_argument('--bRenderOtherDetections', action='store_true',
176
185
  help='Show non-target detections in light gray on each image')
177
186
 
178
187
  parser.add_argument('--bRenderDetectionTiles', action='store_true',
179
- help='Should we render a grid showing every instance for each detection?')
188
+ help='Should we render a grid showing every instance (up to a limit) for each detection?')
180
189
 
181
190
  parser.add_argument('--detectionTilesPrimaryImageWidth', type=int,
182
- default=defaultOptions.detectionTilesPrimaryImageWidth)
191
+ default=defaultOptions.detectionTilesPrimaryImageWidth,
192
+ help='The width of the main image when rendering images with detection tiles')
183
193
 
184
194
  parser.add_argument('--renderHtml', action='store_true',
185
195
  dest='bRenderHtml', help='Should we render HTML output?')
@@ -197,6 +207,5 @@ def main():
197
207
 
198
208
  repeat_detections_core.find_repeat_detections(args.inputFile, args.outputFile, options)
199
209
 
200
-
201
210
  if __name__ == '__main__':
202
211
  main()
@@ -1,15 +1,15 @@
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 user's guide:
9
- #
10
- # https://github.com/agentmorris/MegaDetector/tree/master/api/batch_processing/postprocessing/repeat_detection_elimination
11
- #
12
- ########
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/master/api/batch_processing/postprocessing/repeat_detection_elimination
11
+
12
+ """
13
13
 
14
14
  #%% Constants and imports
15
15
 
@@ -21,7 +21,19 @@ from api.batch_processing.postprocessing.repeat_detection_elimination import rep
21
21
  #%% Main function
22
22
 
23
23
  def remove_repeat_detections(inputFile,outputFile,filteringDir):
24
-
24
+ """
25
+ Given an index file that was produced in a first pass through find_repeat_detections,
26
+ and a folder of images (from which the user has deleted images they don't want removed),
27
+ remove the identified repeat detections from a set of MD results and write to a new file.
28
+
29
+ Args:
30
+ inputFile (str): .json file of MD results, from which we should remove repeat detections
31
+ outputFile (str): output .json file to which we should write MD results (with repeat
32
+ detections removed)
33
+ filteringDir (str): the folder produced by find_repeat_detections, containing a
34
+ detectionIndex.json file
35
+ """
36
+
25
37
  assert os.path.isfile(inputFile), "Can't find file {}".format(inputFile)
26
38
  assert os.path.isdir(filteringDir), "Can't find folder {}".format(filteringDir)
27
39
  options = repeat_detections_core.RepeatDetectionOptions()
@@ -66,6 +78,5 @@ def main():
66
78
  args = parser.parse_args()
67
79
  remove_repeat_detections(args.inputFile, args.outputFile, args.filteringDir)
68
80
 
69
-
70
81
  if __name__ == '__main__':
71
82
  main()