megadetector 5.0.10__py3-none-any.whl → 5.0.11__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 (226) hide show
  1. {megadetector-5.0.10.dist-info → megadetector-5.0.11.dist-info}/LICENSE +0 -0
  2. {megadetector-5.0.10.dist-info → megadetector-5.0.11.dist-info}/METADATA +12 -11
  3. megadetector-5.0.11.dist-info/RECORD +5 -0
  4. megadetector-5.0.11.dist-info/top_level.txt +1 -0
  5. api/__init__.py +0 -0
  6. api/batch_processing/__init__.py +0 -0
  7. api/batch_processing/api_core/__init__.py +0 -0
  8. api/batch_processing/api_core/batch_service/__init__.py +0 -0
  9. api/batch_processing/api_core/batch_service/score.py +0 -439
  10. api/batch_processing/api_core/server.py +0 -294
  11. api/batch_processing/api_core/server_api_config.py +0 -98
  12. api/batch_processing/api_core/server_app_config.py +0 -55
  13. api/batch_processing/api_core/server_batch_job_manager.py +0 -220
  14. api/batch_processing/api_core/server_job_status_table.py +0 -152
  15. api/batch_processing/api_core/server_orchestration.py +0 -360
  16. api/batch_processing/api_core/server_utils.py +0 -92
  17. api/batch_processing/api_core_support/__init__.py +0 -0
  18. api/batch_processing/api_core_support/aggregate_results_manually.py +0 -46
  19. api/batch_processing/api_support/__init__.py +0 -0
  20. api/batch_processing/api_support/summarize_daily_activity.py +0 -152
  21. api/batch_processing/data_preparation/__init__.py +0 -0
  22. api/batch_processing/data_preparation/manage_local_batch.py +0 -2391
  23. api/batch_processing/data_preparation/manage_video_batch.py +0 -327
  24. api/batch_processing/integration/digiKam/setup.py +0 -6
  25. api/batch_processing/integration/digiKam/xmp_integration.py +0 -465
  26. api/batch_processing/integration/eMammal/test_scripts/config_template.py +0 -5
  27. api/batch_processing/integration/eMammal/test_scripts/push_annotations_to_emammal.py +0 -126
  28. api/batch_processing/integration/eMammal/test_scripts/select_images_for_testing.py +0 -55
  29. api/batch_processing/postprocessing/__init__.py +0 -0
  30. api/batch_processing/postprocessing/add_max_conf.py +0 -64
  31. api/batch_processing/postprocessing/categorize_detections_by_size.py +0 -163
  32. api/batch_processing/postprocessing/combine_api_outputs.py +0 -249
  33. api/batch_processing/postprocessing/compare_batch_results.py +0 -958
  34. api/batch_processing/postprocessing/convert_output_format.py +0 -397
  35. api/batch_processing/postprocessing/load_api_results.py +0 -195
  36. api/batch_processing/postprocessing/md_to_coco.py +0 -310
  37. api/batch_processing/postprocessing/md_to_labelme.py +0 -330
  38. api/batch_processing/postprocessing/merge_detections.py +0 -401
  39. api/batch_processing/postprocessing/postprocess_batch_results.py +0 -1904
  40. api/batch_processing/postprocessing/remap_detection_categories.py +0 -170
  41. api/batch_processing/postprocessing/render_detection_confusion_matrix.py +0 -661
  42. api/batch_processing/postprocessing/repeat_detection_elimination/find_repeat_detections.py +0 -211
  43. api/batch_processing/postprocessing/repeat_detection_elimination/remove_repeat_detections.py +0 -82
  44. api/batch_processing/postprocessing/repeat_detection_elimination/repeat_detections_core.py +0 -1631
  45. api/batch_processing/postprocessing/separate_detections_into_folders.py +0 -731
  46. api/batch_processing/postprocessing/subset_json_detector_output.py +0 -696
  47. api/batch_processing/postprocessing/top_folders_to_bottom.py +0 -223
  48. api/synchronous/__init__.py +0 -0
  49. api/synchronous/api_core/animal_detection_api/__init__.py +0 -0
  50. api/synchronous/api_core/animal_detection_api/api_backend.py +0 -152
  51. api/synchronous/api_core/animal_detection_api/api_frontend.py +0 -266
  52. api/synchronous/api_core/animal_detection_api/config.py +0 -35
  53. api/synchronous/api_core/animal_detection_api/data_management/annotations/annotation_constants.py +0 -47
  54. api/synchronous/api_core/animal_detection_api/detection/detector_training/copy_checkpoints.py +0 -43
  55. api/synchronous/api_core/animal_detection_api/detection/detector_training/model_main_tf2.py +0 -114
  56. api/synchronous/api_core/animal_detection_api/detection/process_video.py +0 -543
  57. api/synchronous/api_core/animal_detection_api/detection/pytorch_detector.py +0 -304
  58. api/synchronous/api_core/animal_detection_api/detection/run_detector.py +0 -627
  59. api/synchronous/api_core/animal_detection_api/detection/run_detector_batch.py +0 -1029
  60. api/synchronous/api_core/animal_detection_api/detection/run_inference_with_yolov5_val.py +0 -581
  61. api/synchronous/api_core/animal_detection_api/detection/run_tiled_inference.py +0 -754
  62. api/synchronous/api_core/animal_detection_api/detection/tf_detector.py +0 -165
  63. api/synchronous/api_core/animal_detection_api/detection/video_utils.py +0 -495
  64. api/synchronous/api_core/animal_detection_api/md_utils/azure_utils.py +0 -174
  65. api/synchronous/api_core/animal_detection_api/md_utils/ct_utils.py +0 -262
  66. api/synchronous/api_core/animal_detection_api/md_utils/directory_listing.py +0 -251
  67. api/synchronous/api_core/animal_detection_api/md_utils/matlab_porting_tools.py +0 -97
  68. api/synchronous/api_core/animal_detection_api/md_utils/path_utils.py +0 -416
  69. api/synchronous/api_core/animal_detection_api/md_utils/process_utils.py +0 -110
  70. api/synchronous/api_core/animal_detection_api/md_utils/sas_blob_utils.py +0 -509
  71. api/synchronous/api_core/animal_detection_api/md_utils/string_utils.py +0 -59
  72. api/synchronous/api_core/animal_detection_api/md_utils/url_utils.py +0 -144
  73. api/synchronous/api_core/animal_detection_api/md_utils/write_html_image_list.py +0 -226
  74. api/synchronous/api_core/animal_detection_api/md_visualization/visualization_utils.py +0 -841
  75. api/synchronous/api_core/tests/__init__.py +0 -0
  76. api/synchronous/api_core/tests/load_test.py +0 -110
  77. classification/__init__.py +0 -0
  78. classification/aggregate_classifier_probs.py +0 -108
  79. classification/analyze_failed_images.py +0 -227
  80. classification/cache_batchapi_outputs.py +0 -198
  81. classification/create_classification_dataset.py +0 -627
  82. classification/crop_detections.py +0 -516
  83. classification/csv_to_json.py +0 -226
  84. classification/detect_and_crop.py +0 -855
  85. classification/efficientnet/__init__.py +0 -9
  86. classification/efficientnet/model.py +0 -415
  87. classification/efficientnet/utils.py +0 -610
  88. classification/evaluate_model.py +0 -520
  89. classification/identify_mislabeled_candidates.py +0 -152
  90. classification/json_to_azcopy_list.py +0 -63
  91. classification/json_validator.py +0 -695
  92. classification/map_classification_categories.py +0 -276
  93. classification/merge_classification_detection_output.py +0 -506
  94. classification/prepare_classification_script.py +0 -194
  95. classification/prepare_classification_script_mc.py +0 -228
  96. classification/run_classifier.py +0 -286
  97. classification/save_mislabeled.py +0 -110
  98. classification/train_classifier.py +0 -825
  99. classification/train_classifier_tf.py +0 -724
  100. classification/train_utils.py +0 -322
  101. data_management/__init__.py +0 -0
  102. data_management/annotations/__init__.py +0 -0
  103. data_management/annotations/annotation_constants.py +0 -34
  104. data_management/camtrap_dp_to_coco.py +0 -238
  105. data_management/cct_json_utils.py +0 -395
  106. data_management/cct_to_md.py +0 -176
  107. data_management/cct_to_wi.py +0 -289
  108. data_management/coco_to_labelme.py +0 -272
  109. data_management/coco_to_yolo.py +0 -662
  110. data_management/databases/__init__.py +0 -0
  111. data_management/databases/add_width_and_height_to_db.py +0 -33
  112. data_management/databases/combine_coco_camera_traps_files.py +0 -206
  113. data_management/databases/integrity_check_json_db.py +0 -477
  114. data_management/databases/subset_json_db.py +0 -115
  115. data_management/generate_crops_from_cct.py +0 -149
  116. data_management/get_image_sizes.py +0 -188
  117. data_management/importers/add_nacti_sizes.py +0 -52
  118. data_management/importers/add_timestamps_to_icct.py +0 -79
  119. data_management/importers/animl_results_to_md_results.py +0 -158
  120. data_management/importers/auckland_doc_test_to_json.py +0 -372
  121. data_management/importers/auckland_doc_to_json.py +0 -200
  122. data_management/importers/awc_to_json.py +0 -189
  123. data_management/importers/bellevue_to_json.py +0 -273
  124. data_management/importers/cacophony-thermal-importer.py +0 -796
  125. data_management/importers/carrizo_shrubfree_2018.py +0 -268
  126. data_management/importers/carrizo_trail_cam_2017.py +0 -287
  127. data_management/importers/cct_field_adjustments.py +0 -57
  128. data_management/importers/channel_islands_to_cct.py +0 -913
  129. data_management/importers/eMammal/copy_and_unzip_emammal.py +0 -180
  130. data_management/importers/eMammal/eMammal_helpers.py +0 -249
  131. data_management/importers/eMammal/make_eMammal_json.py +0 -223
  132. data_management/importers/ena24_to_json.py +0 -275
  133. data_management/importers/filenames_to_json.py +0 -385
  134. data_management/importers/helena_to_cct.py +0 -282
  135. data_management/importers/idaho-camera-traps.py +0 -1407
  136. data_management/importers/idfg_iwildcam_lila_prep.py +0 -294
  137. data_management/importers/jb_csv_to_json.py +0 -150
  138. data_management/importers/mcgill_to_json.py +0 -250
  139. data_management/importers/missouri_to_json.py +0 -489
  140. data_management/importers/nacti_fieldname_adjustments.py +0 -79
  141. data_management/importers/noaa_seals_2019.py +0 -181
  142. data_management/importers/pc_to_json.py +0 -365
  143. data_management/importers/plot_wni_giraffes.py +0 -123
  144. data_management/importers/prepare-noaa-fish-data-for-lila.py +0 -359
  145. data_management/importers/prepare_zsl_imerit.py +0 -131
  146. data_management/importers/rspb_to_json.py +0 -356
  147. data_management/importers/save_the_elephants_survey_A.py +0 -320
  148. data_management/importers/save_the_elephants_survey_B.py +0 -332
  149. data_management/importers/snapshot_safari_importer.py +0 -758
  150. data_management/importers/snapshot_safari_importer_reprise.py +0 -665
  151. data_management/importers/snapshot_serengeti_lila.py +0 -1067
  152. data_management/importers/snapshotserengeti/make_full_SS_json.py +0 -150
  153. data_management/importers/snapshotserengeti/make_per_season_SS_json.py +0 -153
  154. data_management/importers/sulross_get_exif.py +0 -65
  155. data_management/importers/timelapse_csv_set_to_json.py +0 -490
  156. data_management/importers/ubc_to_json.py +0 -399
  157. data_management/importers/umn_to_json.py +0 -507
  158. data_management/importers/wellington_to_json.py +0 -263
  159. data_management/importers/wi_to_json.py +0 -441
  160. data_management/importers/zamba_results_to_md_results.py +0 -181
  161. data_management/labelme_to_coco.py +0 -548
  162. data_management/labelme_to_yolo.py +0 -272
  163. data_management/lila/__init__.py +0 -0
  164. data_management/lila/add_locations_to_island_camera_traps.py +0 -97
  165. data_management/lila/add_locations_to_nacti.py +0 -147
  166. data_management/lila/create_lila_blank_set.py +0 -557
  167. data_management/lila/create_lila_test_set.py +0 -151
  168. data_management/lila/create_links_to_md_results_files.py +0 -106
  169. data_management/lila/download_lila_subset.py +0 -177
  170. data_management/lila/generate_lila_per_image_labels.py +0 -515
  171. data_management/lila/get_lila_annotation_counts.py +0 -170
  172. data_management/lila/get_lila_image_counts.py +0 -111
  173. data_management/lila/lila_common.py +0 -300
  174. data_management/lila/test_lila_metadata_urls.py +0 -132
  175. data_management/ocr_tools.py +0 -874
  176. data_management/read_exif.py +0 -681
  177. data_management/remap_coco_categories.py +0 -84
  178. data_management/remove_exif.py +0 -66
  179. data_management/resize_coco_dataset.py +0 -189
  180. data_management/wi_download_csv_to_coco.py +0 -246
  181. data_management/yolo_output_to_md_output.py +0 -441
  182. data_management/yolo_to_coco.py +0 -676
  183. detection/__init__.py +0 -0
  184. detection/detector_training/__init__.py +0 -0
  185. detection/detector_training/model_main_tf2.py +0 -114
  186. detection/process_video.py +0 -703
  187. detection/pytorch_detector.py +0 -337
  188. detection/run_detector.py +0 -779
  189. detection/run_detector_batch.py +0 -1219
  190. detection/run_inference_with_yolov5_val.py +0 -917
  191. detection/run_tiled_inference.py +0 -935
  192. detection/tf_detector.py +0 -188
  193. detection/video_utils.py +0 -606
  194. docs/source/conf.py +0 -43
  195. md_utils/__init__.py +0 -0
  196. md_utils/azure_utils.py +0 -174
  197. md_utils/ct_utils.py +0 -612
  198. md_utils/directory_listing.py +0 -246
  199. md_utils/md_tests.py +0 -968
  200. md_utils/path_utils.py +0 -1044
  201. md_utils/process_utils.py +0 -157
  202. md_utils/sas_blob_utils.py +0 -509
  203. md_utils/split_locations_into_train_val.py +0 -228
  204. md_utils/string_utils.py +0 -92
  205. md_utils/url_utils.py +0 -323
  206. md_utils/write_html_image_list.py +0 -225
  207. md_visualization/__init__.py +0 -0
  208. md_visualization/plot_utils.py +0 -293
  209. md_visualization/render_images_with_thumbnails.py +0 -275
  210. md_visualization/visualization_utils.py +0 -1537
  211. md_visualization/visualize_db.py +0 -551
  212. md_visualization/visualize_detector_output.py +0 -406
  213. megadetector-5.0.10.dist-info/RECORD +0 -224
  214. megadetector-5.0.10.dist-info/top_level.txt +0 -8
  215. taxonomy_mapping/__init__.py +0 -0
  216. taxonomy_mapping/map_lila_taxonomy_to_wi_taxonomy.py +0 -491
  217. taxonomy_mapping/map_new_lila_datasets.py +0 -154
  218. taxonomy_mapping/prepare_lila_taxonomy_release.py +0 -142
  219. taxonomy_mapping/preview_lila_taxonomy.py +0 -591
  220. taxonomy_mapping/retrieve_sample_image.py +0 -71
  221. taxonomy_mapping/simple_image_download.py +0 -218
  222. taxonomy_mapping/species_lookup.py +0 -834
  223. taxonomy_mapping/taxonomy_csv_checker.py +0 -159
  224. taxonomy_mapping/taxonomy_graph.py +0 -346
  225. taxonomy_mapping/validate_lila_category_mappings.py +0 -83
  226. {megadetector-5.0.10.dist-info → megadetector-5.0.11.dist-info}/WHEEL +0 -0
@@ -1,465 +0,0 @@
1
- #
2
- # xmp_integration.py
3
- #
4
- # Tools for loading MegaDetector batch API results into XMP metadata, specifically
5
- # for consumption in digiKam:
6
- #
7
- # https://cran.r-project.org/web/packages/camtrapR/vignettes/camtrapr2.html
8
- #
9
-
10
- #%% Imports and constants
11
-
12
- import argparse
13
- import tkinter
14
- from tkinter import ttk, messagebox, filedialog
15
-
16
- import inspect
17
- import os
18
- import sys
19
- import json
20
- import pyexiv2
21
- import ntpath
22
- import threading
23
- import traceback
24
-
25
- from tqdm import tqdm
26
- from multiprocessing import Pool
27
- from multiprocessing.pool import ThreadPool
28
- from functools import partial
29
-
30
- category_mapping = {'person': 'Human', 'animal': 'Animal', 'vehicle': 'Vehicle'}
31
-
32
-
33
- #%% Class definitions
34
-
35
- class xmp_gui:
36
-
37
- root = None
38
- textarea_min_threshold = None
39
- textarea_status = None
40
- textarea_remove_path = None
41
- textarea_rename_conf = None
42
- textarea_rename_cats = None
43
- num_threads = 1
44
-
45
- class xmp_integration_options:
46
-
47
- # Folder where images are stored
48
- image_folder = None
49
-
50
- # .json file containing MegaDetector output
51
- input_file = None
52
-
53
- # String to remove from all path names, typically representing a
54
- # prefix that was added during MegaDetector processing
55
- remove_path = None
56
-
57
- # Optionally *rename* (not copy) all images that have no detections
58
- # above [rename_conf] for the categories in rename_cats from x.jpg to
59
- # x.check.jpg
60
- rename_conf = None
61
-
62
- # Comma-deleted list of category names (or "all") to apply the rename_conf
63
- # behavior to.
64
- rename_cats = None
65
-
66
- # Minimum detection threshold (applies to all classes, defaults to None,
67
- # i.e. 0.0
68
- min_threshold = None
69
- num_threads = 1
70
- xmp_gui = None
71
-
72
-
73
- #%% Functions
74
-
75
- def write_status(options,s):
76
-
77
- if options.xmp_gui is None:
78
- return
79
- options.xmp_gui.textarea_status.configure(state="normal")
80
- options.xmp_gui.textarea_status.insert(tkinter.END, s + '\n')
81
- options.xmp_gui.textarea_status.configure(state="disabled")
82
-
83
-
84
- n_images_processed = 0
85
-
86
- def update_xmp_metadata(categories, options, rename_cats, n_images, image):
87
- """
88
- Update the XMP metadata for a single image
89
- """
90
-
91
- # Relative image path
92
- filename = ''
93
-
94
- # Absolute image path
95
- img_path = ''
96
-
97
- global n_images_processed
98
-
99
- try:
100
-
101
- filename = image['file']
102
- if options.remove_path != None and len(options.remove_path) > 0:
103
- filename = filename.replace(options.remove_path, '')
104
- img_path = os.path.join(options.image_folder, filename)
105
- assert os.path.isfile(img_path), 'Image {} not found'.format(img_path)
106
-
107
- # List of categories to write to XMP metadata
108
- image_categories = []
109
-
110
- # Categories with above-threshold detections present for
111
- # this image
112
- original_image_cats = []
113
-
114
- # Maximum confidence for each category
115
- original_image_cats_conf = {}
116
-
117
- for detection in image['detections']:
118
-
119
- cat = category_mapping[categories[detection['category']]]
120
-
121
- # Have we already added this to the list of categories to
122
- # write out to this image?
123
- if cat not in image_categories:
124
-
125
- # If we're supposed to compare to a threshold...
126
- if len(options.min_threshold) > 0 and \
127
- options.min_threshold != None:
128
- if float(detection['conf']) > float(options.min_threshold):
129
- image_categories.append(cat)
130
- original_image_cats.append(
131
- categories[detection['category']])
132
-
133
- # Else we treat *any* detection as valid...
134
- else:
135
- image_categories.append(cat)
136
- original_image_cats.append(categories[detection['category']])
137
-
138
- # Keep track of the highest-confidence detection for this class
139
- if options.min_threshold != None and \
140
- len(options.min_threshold) > 0 and \
141
- detection['conf'] > \
142
- original_image_cats_conf.get(
143
- categories[detection['category']], 0):
144
-
145
- original_image_cats_conf[categories[detection['category']]] = \
146
- detection['conf']
147
-
148
- img = pyexiv2.Image(r'{0}'.format(img_path))
149
- img.modify_xmp({'Xmp.lr.hierarchicalSubject': image_categories})
150
-
151
- # If we're doing the rename/.check behavior...
152
- if not (options.rename_conf is None and options.rename_cats is None):
153
-
154
- matching_cats = set(rename_cats).intersection(set(original_image_cats))
155
- is_conf_low = False
156
- if options.min_threshold != None and len(options.min_threshold) > 0:
157
- for matching_cat in matching_cats:
158
- if original_image_cats_conf[matching_cat] < float(options.rename_conf):
159
- is_conf_low = True
160
- if options.min_threshold != None and \
161
- len(options.min_threshold) > 0 and \
162
- len(image['detections']) == 0 or \
163
- (len(options.rename_conf) > 0 and \
164
- is_conf_low is True and \
165
- len(matching_cats) > 0):
166
-
167
- parent_folder = os.path.dirname(img_path)
168
- file_name = ntpath.basename(img_path)
169
- manual_file_name = file_name.split('.')[0]+'_check' + '.' + file_name.split('.')[1]
170
- os.rename(img_path, os.path.join(parent_folder, manual_file_name))
171
-
172
- if options.xmp_gui is not None:
173
-
174
- n_images_processed += 1
175
- percentage = round((n_images_processed)/n_images*100)
176
- options.xmp_gui.progress_bar['value'] = percentage
177
- options.xmp_gui.root.update_idletasks()
178
- options.xmp_gui.style.configure('text.Horizontal.Tprogress_bar',
179
- text='{:g} %'.format(percentage))
180
-
181
- except Exception as e:
182
-
183
- s = 'Error processing image {}: {}'.format(filename,str(e))
184
- print(s)
185
- traceback.print_exc()
186
- write_status(options,s)
187
-
188
- if False:
189
-
190
- # Legacy code to rename files where XMP writing failed
191
- parent_folder = os.path.dirname(img_path)
192
- file_name = ntpath.basename(img_path)
193
- failed_file_name = file_name.split('.')[0]+'_failed' + '.' + file_name.split('.')[1]
194
- os.rename(img_path, os.path.join(
195
- parent_folder, failed_file_name))
196
-
197
-
198
- def process_input_data(options):
199
- """
200
- Main function to loop over images and modify XMP data
201
- """
202
-
203
- if options.xmp_gui is not None:
204
-
205
- if (options.image_folder is None) or (len(options.image_folder) == 0):
206
- tkinter.messagebox.showerror(title='Error', message='Image folder is not selected')
207
- sys.exit()
208
- if (options.input_file is None) or (len(options.input_file) == 0):
209
- tkinter.messagebox.showerror(
210
- title='Error', message='No MegaDetector .json file selected')
211
- sys.exit()
212
- options.remove_path = options.xmp_gui.textarea_remove_path.get()
213
- options.rename_conf = options.xmp_gui.textarea_rename_conf.get()
214
- options.rename_cats = options.xmp_gui.textarea_rename_cats.get()
215
- options.num_threads = options.xmp_gui.textarea_num_threads.get()
216
- options.min_threshold = options.xmp_gui.textarea_min_threshold.get()
217
-
218
- try:
219
-
220
- with open(options.input_file, 'r') as f:
221
- data = f.read()
222
-
223
- data = json.loads(data)
224
- categories = data['detection_categories']
225
-
226
- images = data['images']
227
- n_images = len(images)
228
- if not (options.rename_conf is None and options.rename_cats is None):
229
- rename_cats = options.rename_cats.split(",")
230
- if rename_cats[0] == 'all':
231
- rename_cats = list(category_mapping.keys())
232
- else:
233
- rename_cats = []
234
- if len(options.num_threads) > 0:
235
- num_threads = int(options.num_threads)
236
- else:
237
- num_threads = 1
238
- print(num_threads)
239
- if options.xmp_gui is None:
240
- func = partial(update_xmp_metadata, categories, options, rename_cats, n_images)
241
- with Pool(num_threads) as p:
242
- with tqdm(total=n_images) as pbar:
243
- for i, _ in enumerate(p.imap_unordered(func, images)):
244
- pbar.update()
245
- else:
246
- func = partial(update_xmp_metadata, categories, options, rename_cats, n_images)
247
- with ThreadPool(num_threads) as p:
248
- p.map(func, images)
249
- s = 'Successfully processed {} images'.format(n_images)
250
- print(s)
251
- write_status(options,s)
252
-
253
- except Exception as e:
254
-
255
- print('Error processing input data: {}'.format(str(e)))
256
- traceback.print_exc()
257
- if options.xmp_gui is not None:
258
- tkinter.messagebox.showerror(title='Error',
259
- message='Make Sure you selected the proper image folder and JSON files')
260
- sys.exit()
261
-
262
-
263
- def start_input_processing(options):
264
-
265
- t = threading.Thread(target=lambda: process_input_data(options))
266
- t.start()
267
-
268
-
269
- def browse_folder(options,folder_path_var):
270
-
271
- filename = tkinter.filedialog.askdirectory()
272
- options.image_folder = r'{0}'.format(filename)
273
- folder_path_var.set(filename)
274
-
275
-
276
- def browse_file(options,file_path_var):
277
-
278
- filename = tkinter.filedialog.askopenfilename()
279
- options.input_file = r'{0}'.format(filename)
280
- file_path_var.set(filename)
281
-
282
-
283
- def create_gui(options):
284
-
285
- root = tkinter.Tk()
286
- root.resizable(False, False)
287
- root.configure(background='white')
288
- root.title('DigiKam Integration')
289
-
290
- group = tkinter.LabelFrame(root, padx=5, pady=5)
291
- group.configure(background = 'white')
292
- group.pack(padx=10, pady=10, fill='both', expand='yes')
293
-
294
- canvas = tkinter.Canvas(group, width = 800, height = 150)
295
- canvas.configure(background = 'white')
296
- canvas.pack()
297
- img1 = tkinter.PhotoImage(file='images/aiforearth.png')
298
- canvas.create_image(0,0, anchor=tkinter.NW, image=img1)
299
- img2 = tkinter.PhotoImage(file='images/bg.png')
300
- canvas.create_image(0,20, anchor=tkinter.NW, image=img2)
301
-
302
- frame = tkinter.Frame(root)
303
- frame.configure(background='white')
304
- frame.pack()
305
-
306
- l1 = tkinter.Label(frame, text='Folder containing images')
307
- l1.configure(background='white')
308
- l1.grid(row=0, column=0)
309
-
310
- folder_path_var = tkinter.StringVar()
311
-
312
- e1 = tkinter.Entry(frame, width=50, textvariable=folder_path_var, highlightthickness=1)
313
- e1.configure(highlightbackground='grey', highlightcolor='grey')
314
- e1.grid(row=0, column=2)
315
-
316
- b1 = tkinter.Button(frame, text='Browse', fg='blue', command=lambda: browse_folder(options,folder_path_var))
317
- b1.grid(row=0, column=5, padx=10)
318
-
319
- l2 = tkinter.Label(frame, text='Path to MegaDetector output .json file')
320
- l2.configure(background='white')
321
- l2.grid(row=1, column=0)
322
-
323
- file_path_var = tkinter.StringVar()
324
-
325
- e2 = tkinter.Entry(frame, width=50, textvariable=file_path_var, highlightthickness=1)
326
- e2.configure(highlightbackground='grey', highlightcolor='grey')
327
- e2.grid(row=1, column=2)
328
-
329
- b2 = tkinter.Button(frame, text='Browse', fg='blue', command=lambda: browse_file(options,file_path_var))
330
- b2.grid(row=1, column=5, padx=10)
331
-
332
- l6 = tkinter.Label(frame, text='Minimum confidence to consider a category')
333
- l6.configure(background='white')
334
- l6.grid(row=2, column=0)
335
-
336
- textarea_min_threshold = tkinter.Entry(frame, width=50, highlightthickness=1)
337
- textarea_min_threshold.configure(highlightbackground='grey', highlightcolor='grey')
338
- textarea_min_threshold.grid(row=2, column=2)
339
-
340
- l3 = tkinter.Label(frame, text='Prefix to remove from image paths (optional)')
341
- l3.configure(background='white')
342
- l3.grid(row=3, column=0)
343
-
344
- textarea_remove_path = tkinter.Entry(frame, width=50, highlightthickness=1)
345
- textarea_remove_path.configure(highlightbackground='grey', highlightcolor='grey')
346
- textarea_remove_path.grid(row=3, column=2)
347
-
348
- l4 = tkinter.Label(frame, text='Confidence level to move images requires manual check (optional)')
349
- l4.configure(background='white')
350
- l4.grid(row=4, column=0)
351
-
352
- textarea_rename_conf = tkinter.Entry(frame, width=50, highlightthickness=1)
353
- textarea_rename_conf.configure(highlightbackground='grey', highlightcolor='grey')
354
- textarea_rename_conf.grid(row=4, column=2)
355
-
356
-
357
- l5 = tkinter.Label(frame, text='Categories to check for the confidence (optional)')
358
- l5.configure(background='white')
359
- l5.grid(row=5, column=0)
360
-
361
- textarea_rename_cats = tkinter.Entry(frame, width=50, highlightthickness=1)
362
- textarea_rename_cats.configure(highlightbackground='grey', highlightcolor='grey')
363
- textarea_rename_cats.grid(row=5, column=2)
364
-
365
- l6 = tkinter.Label(frame, text='Number of threads to run (optional)')
366
- l6.configure(background='white')
367
- l6.grid(row=6, column=0)
368
-
369
- textarea_num_threads = tkinter.Entry(frame, width=50, highlightthickness=1)
370
- textarea_num_threads.configure(highlightbackground='grey', highlightcolor='grey')
371
- textarea_num_threads.grid(row=6, column=2)
372
-
373
- sb = tkinter.Button(frame, text='Submit', fg='black',
374
- command=lambda: start_input_processing(options), padx=10)
375
- sb.grid(row=7, column=2, padx=10, pady=10)
376
-
377
- style = tkinter.ttk.Style(root)
378
- style.layout('text.Horizontal.Tprogress_bar',
379
- [('Horizontal.progress_bar.trough',
380
- {'children': [('Horizontal.progress_bar.pbar',
381
- {'side': 'left', 'sticky': 'ns'})],
382
- 'sticky': 'nswe'}),
383
- ('Horizontal.progress_bar.label', {'sticky': ''})])
384
- style.configure('text.Horizontal.Tprogress_bar', text='0 %')
385
-
386
- progress_bar = tkinter.ttk.Progressbar(root, style='text.Horizontal.Tprogress_bar', length=700,
387
- maximum=100, value=0, mode='determinate')
388
- progress_bar.pack(pady=10)
389
-
390
- group2 = tkinter.LabelFrame(root, text='Status', padx=5, pady=5)
391
- group2.pack(padx=10, pady=10, fill='both', expand='yes')
392
-
393
- textarea_status = tkinter.Text(group2, height=10, width=100)
394
- textarea_status.configure(state="disabled")
395
- textarea_status.pack()
396
-
397
- options.xmp_gui = xmp_gui()
398
- options.xmp_gui.root = root
399
- options.xmp_gui.textarea_min_threshold = textarea_min_threshold
400
- options.xmp_gui.textarea_remove_path = textarea_remove_path
401
- options.xmp_gui.textarea_rename_conf = textarea_rename_conf
402
- options.xmp_gui.textarea_rename_cats = textarea_rename_cats
403
- options.xmp_gui.textarea_num_threads = textarea_num_threads
404
- options.xmp_gui.textarea_status = textarea_status
405
- options.xmp_gui.progress_bar = progress_bar
406
- options.xmp_gui.style = style
407
-
408
- root.mainloop()
409
-
410
-
411
- #%% Interactive/test driver
412
-
413
- if False:
414
-
415
- #%%
416
-
417
- options = xmp_integration_options()
418
- options.input_file = r"C:\temp\demo_images\ssmini_xmp_test_orig\ssmini.mdv4.json"
419
- options.image_folder = r"C:\temp\demo_images\ssmini_xmp_test"
420
- options.remove_path = 'my_images/'
421
- process_input_data(options)
422
-
423
-
424
- #%% Command-line driver
425
-
426
- def args_to_object(args,obj):
427
- """
428
- Copy all fields from the argparse table "args" to the object "obj"
429
- """
430
- for n, v in inspect.getmembers(args):
431
- if not n.startswith('_'):
432
- setattr(obj, n, v)
433
-
434
-
435
- def main():
436
-
437
- parser = argparse.ArgumentParser()
438
- parser.add_argument('--input_file', help = 'Path to the MegaDetector .json file', default=None)
439
- parser.add_argument('--image_folder', help = 'Path to the folder containing images', default=None)
440
- parser.add_argument('--min_threshold', help = 'Minimum detection confidence that will be treated as a detection event', default=None)
441
- parser.add_argument('--remove_path', help = 'Prefix to remove from image paths in the .json file', default=None)
442
- parser.add_argument('--rename_conf', help = 'Below this confidence level, images will be renamed for manual check', default=None)
443
- parser.add_argument('--rename_cat', help = 'Category (or comma-delimited categories) to apply renaming behavior to', default=None)
444
- parser.add_argument('--num_threads', help = 'Number of threads to use for image processing', default=1)
445
- parser.add_argument('--gui', help = 'Run in GUI mode', action='store_true')
446
-
447
- options = xmp_integration_options()
448
- args = parser.parse_args()
449
- args_to_object(args,options)
450
-
451
- if options.gui:
452
- assert options.input_file is None, 'Command-line argument specified in GUI mode'
453
- assert options.image_folder is None, 'Command-line argument specified in GUI mode'
454
- assert options.min_threshold is None, 'Command-line argument specified in GUI mode'
455
- assert options.remove_path is None, 'Command-line argument specified in GUI mode'
456
- assert options.rename_conf is None, 'Command-line argument specified in GUI mode'
457
- assert options.rename_cat is None, 'Command-line argument specified in GUI mode'
458
- assert options.num_threads == 1, 'Command-line argument specified in GUI mode'
459
- create_gui(options)
460
- else:
461
- process_input_data(options)
462
-
463
- if __name__ == '__main__':
464
-
465
- main()
@@ -1,5 +0,0 @@
1
- host="localhost"
2
- username="root"
3
- password=""
4
- port=3307
5
- database="wild_id"
@@ -1,126 +0,0 @@
1
- #
2
- # Test script for pushing annotations to the eMammal db
3
- #
4
-
5
- #%% Imports
6
-
7
- import sys
8
- import json
9
- import argparse
10
- import pymysql
11
- import config as cfg
12
-
13
- from tqdm import tqdm
14
- from enum import Enum
15
-
16
-
17
- #%% Database functions
18
-
19
- class Categories(Enum):
20
- animal = 1
21
- person = 2
22
- vehicle = 3
23
-
24
- mysql_connection = pymysql.connect( host=cfg.host,
25
- user=cfg.username,
26
- passwd=cfg.password,
27
- db=cfg.database,
28
- port=cfg.port)
29
-
30
- def update_data(sql):
31
- with mysql_connection.cursor() as cursor:
32
- cursor.execute(sql)
33
-
34
- def get_records_all(sql):
35
- with mysql_connection.cursor() as cursor:
36
- sql = sql
37
- cursor.execute(sql)
38
- rows = cursor.fetchall()
39
- return rows
40
-
41
- def format_data_print_deployments(rows):
42
- count = 0
43
- result = []
44
- for row in rows:
45
- count += 1
46
- print("{}. {}-{}".format(str(count), row[0],row[1]))
47
- result.append((count, row[0], row[1]))
48
-
49
- return result
50
-
51
-
52
- #%% Command-line driver
53
-
54
- def main():
55
-
56
- parser = argparse.ArgumentParser()
57
- parser.add_argument('input_file', type=str, help='Input .json filename')
58
-
59
- if len(sys.argv[1:]) == 0:
60
- parser.print_help()
61
- parser.exit()
62
-
63
- args = parser.parse_args()
64
-
65
- print("Enter the number of the deployment:")
66
-
67
- rows = get_records_all(''' select * from deployment ''')
68
- deployments = format_data_print_deployments(rows)
69
- print("\n")
70
- deployment_choice = input()
71
- deployment_id = deployments[int(deployment_choice)][1]
72
-
73
- print(deployment_id)
74
-
75
- # TODO: check project ID ?
76
- sql = ''' SELECT emammal_project_taxa_id FROM wild_id.emammal_project_taxa
77
- where species in ("No Animal", "Unknown Animal", "Homo sapiens", "Vehicle") '''
78
-
79
-
80
- emammal_categories = get_records_all(sql)
81
-
82
- with open(args.input_file) as f:
83
- data = json.load(f)
84
-
85
- images = data['images']
86
- emammal_category = 0
87
- for index, im in tqdm(enumerate(images), total=len(images)):
88
- fn = im['file']
89
-
90
- if len(im['detections']) <= 0:
91
- image_type_id = 2
92
-
93
- # No-animal category
94
- emammal_categories = emammal_categories[0]
95
- else:
96
- max_conf = im['max_detection_conf']
97
- detection = [k for k in im['detections'] if k['conf'] == max_conf]
98
- category= int(detection[0]['category'])
99
-
100
- if category == Categories.animal:
101
- image_type_id = 1
102
- emammal_category = emammal_categories[1]
103
- else:
104
- image_type_id = 5
105
- if category == Categories.person:
106
- emammal_category = emammal_categories[2]
107
- elif category == Categories.vehicle:
108
- emammal_category = emammal_categories[3]
109
-
110
- sql = """ UPDATE wild_id.emammal_sequence_annotation,
111
- wild_id.image,
112
- wild_id.image_sequence,
113
- wild_id.deployment
114
- SET wild_id.emammal_sequence_annotation.project_taxa_id = 4
115
- WHERE wild_id.image.image_sequence_id = wild_id.emammal_sequence_annotation.sequence_id
116
- AND wild_id.image_sequence.deployment_id = wild_id.deployment.deployment_id
117
- AND wild_id.image.raw_name = '{}' """.format(fn)
118
-
119
-
120
- print(sql)
121
- update_data(sql)
122
- mysql_connection.commit()
123
-
124
- if __name__ == '__main__':
125
- main()
126
-
@@ -1,55 +0,0 @@
1
- #%% Imports
2
-
3
- import os
4
- import sys
5
- import argparse
6
- import json
7
- import shutil
8
-
9
- from tqdm import tqdm
10
-
11
- #%% Main function
12
-
13
- def main():
14
-
15
- parser = argparse.ArgumentParser()
16
- parser.add_argument('input_file', type=str, help='Input .json filename')
17
-
18
- if len(sys.argv[1:]) == 0:
19
- parser.print_help()
20
- parser.exit()
21
-
22
- args = parser.parse_args()
23
-
24
- with open(args.input_file) as f:
25
- data = json.load(f)
26
-
27
- images = data['images'][:1000]
28
- data['images'] = images
29
- with open('output.json', 'w') as f:
30
- json.dump(data, f, indent=1)
31
-
32
- select_images_folder = "select_images_folder"
33
-
34
- if os.path.exists(select_images_folder):
35
- shutil.rmtree(select_images_folder, ignore_errors=True)
36
-
37
- os.mkdir(select_images_folder)
38
-
39
- source = os.getcwd() + "\\SWWLF2019_R1_GMU1_F_9\\"
40
- destination = os.getcwd() + "\\" + select_images_folder + "\\"
41
-
42
- # if not os.path.exists(directory):
43
- # os.makedirs(directory)
44
-
45
- for index, im in tqdm(enumerate(images), total=len(images)):
46
- fn=im['file']
47
- fn = fn.replace('/', '\\')
48
- print(os.path.dirname(fn))
49
- directory = destination + os.path.dirname(fn)
50
- if not os.path.exists(directory):
51
- os.makedirs(directory)
52
- dest = shutil.copyfile(source + fn, destination + fn)
53
-
54
- if __name__ == '__main__':
55
- main()
File without changes