megadetector 5.0.28__py3-none-any.whl → 10.0.0__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.
- megadetector/api/batch_processing/integration/digiKam/xmp_integration.py +2 -2
- megadetector/api/batch_processing/integration/eMammal/test_scripts/push_annotations_to_emammal.py +1 -1
- megadetector/api/batch_processing/integration/eMammal/test_scripts/select_images_for_testing.py +1 -1
- megadetector/classification/aggregate_classifier_probs.py +3 -3
- megadetector/classification/analyze_failed_images.py +5 -5
- megadetector/classification/cache_batchapi_outputs.py +5 -5
- megadetector/classification/create_classification_dataset.py +11 -12
- megadetector/classification/crop_detections.py +10 -10
- megadetector/classification/csv_to_json.py +8 -8
- megadetector/classification/detect_and_crop.py +13 -15
- megadetector/classification/efficientnet/model.py +8 -8
- megadetector/classification/efficientnet/utils.py +6 -5
- megadetector/classification/evaluate_model.py +7 -7
- megadetector/classification/identify_mislabeled_candidates.py +6 -6
- megadetector/classification/json_to_azcopy_list.py +1 -1
- megadetector/classification/json_validator.py +29 -32
- megadetector/classification/map_classification_categories.py +9 -9
- megadetector/classification/merge_classification_detection_output.py +12 -9
- megadetector/classification/prepare_classification_script.py +19 -19
- megadetector/classification/prepare_classification_script_mc.py +26 -26
- megadetector/classification/run_classifier.py +4 -4
- megadetector/classification/save_mislabeled.py +6 -6
- megadetector/classification/train_classifier.py +1 -1
- megadetector/classification/train_classifier_tf.py +9 -9
- megadetector/classification/train_utils.py +10 -10
- megadetector/data_management/annotations/annotation_constants.py +1 -2
- megadetector/data_management/camtrap_dp_to_coco.py +79 -46
- megadetector/data_management/cct_json_utils.py +103 -103
- megadetector/data_management/cct_to_md.py +49 -49
- megadetector/data_management/cct_to_wi.py +33 -33
- megadetector/data_management/coco_to_labelme.py +75 -75
- megadetector/data_management/coco_to_yolo.py +210 -193
- megadetector/data_management/databases/add_width_and_height_to_db.py +86 -12
- megadetector/data_management/databases/combine_coco_camera_traps_files.py +40 -40
- megadetector/data_management/databases/integrity_check_json_db.py +228 -200
- megadetector/data_management/databases/subset_json_db.py +33 -33
- megadetector/data_management/generate_crops_from_cct.py +88 -39
- megadetector/data_management/get_image_sizes.py +54 -49
- megadetector/data_management/labelme_to_coco.py +133 -125
- megadetector/data_management/labelme_to_yolo.py +159 -73
- megadetector/data_management/lila/create_lila_blank_set.py +81 -83
- megadetector/data_management/lila/create_lila_test_set.py +32 -31
- megadetector/data_management/lila/create_links_to_md_results_files.py +18 -18
- megadetector/data_management/lila/download_lila_subset.py +21 -24
- megadetector/data_management/lila/generate_lila_per_image_labels.py +365 -107
- megadetector/data_management/lila/get_lila_annotation_counts.py +35 -33
- megadetector/data_management/lila/get_lila_image_counts.py +22 -22
- megadetector/data_management/lila/lila_common.py +73 -70
- megadetector/data_management/lila/test_lila_metadata_urls.py +28 -19
- megadetector/data_management/mewc_to_md.py +344 -340
- megadetector/data_management/ocr_tools.py +262 -255
- megadetector/data_management/read_exif.py +249 -227
- megadetector/data_management/remap_coco_categories.py +90 -28
- megadetector/data_management/remove_exif.py +81 -21
- megadetector/data_management/rename_images.py +187 -187
- megadetector/data_management/resize_coco_dataset.py +588 -120
- megadetector/data_management/speciesnet_to_md.py +41 -41
- megadetector/data_management/wi_download_csv_to_coco.py +55 -55
- megadetector/data_management/yolo_output_to_md_output.py +248 -122
- megadetector/data_management/yolo_to_coco.py +333 -191
- megadetector/detection/change_detection.py +832 -0
- megadetector/detection/process_video.py +340 -337
- megadetector/detection/pytorch_detector.py +358 -278
- megadetector/detection/run_detector.py +399 -186
- megadetector/detection/run_detector_batch.py +404 -377
- megadetector/detection/run_inference_with_yolov5_val.py +340 -327
- megadetector/detection/run_tiled_inference.py +257 -249
- megadetector/detection/tf_detector.py +24 -24
- megadetector/detection/video_utils.py +332 -295
- megadetector/postprocessing/add_max_conf.py +19 -11
- megadetector/postprocessing/categorize_detections_by_size.py +45 -45
- megadetector/postprocessing/classification_postprocessing.py +468 -433
- megadetector/postprocessing/combine_batch_outputs.py +23 -23
- megadetector/postprocessing/compare_batch_results.py +590 -525
- megadetector/postprocessing/convert_output_format.py +106 -102
- megadetector/postprocessing/create_crop_folder.py +347 -147
- megadetector/postprocessing/detector_calibration.py +173 -168
- megadetector/postprocessing/generate_csv_report.py +508 -499
- megadetector/postprocessing/load_api_results.py +48 -27
- megadetector/postprocessing/md_to_coco.py +133 -102
- megadetector/postprocessing/md_to_labelme.py +107 -90
- megadetector/postprocessing/md_to_wi.py +40 -40
- megadetector/postprocessing/merge_detections.py +92 -114
- megadetector/postprocessing/postprocess_batch_results.py +319 -301
- megadetector/postprocessing/remap_detection_categories.py +91 -38
- megadetector/postprocessing/render_detection_confusion_matrix.py +214 -205
- megadetector/postprocessing/repeat_detection_elimination/find_repeat_detections.py +57 -57
- megadetector/postprocessing/repeat_detection_elimination/remove_repeat_detections.py +27 -28
- megadetector/postprocessing/repeat_detection_elimination/repeat_detections_core.py +704 -679
- megadetector/postprocessing/separate_detections_into_folders.py +226 -211
- megadetector/postprocessing/subset_json_detector_output.py +265 -262
- megadetector/postprocessing/top_folders_to_bottom.py +45 -45
- megadetector/postprocessing/validate_batch_results.py +70 -70
- megadetector/taxonomy_mapping/map_lila_taxonomy_to_wi_taxonomy.py +52 -52
- megadetector/taxonomy_mapping/map_new_lila_datasets.py +18 -19
- megadetector/taxonomy_mapping/prepare_lila_taxonomy_release.py +54 -33
- megadetector/taxonomy_mapping/preview_lila_taxonomy.py +67 -67
- megadetector/taxonomy_mapping/retrieve_sample_image.py +16 -16
- megadetector/taxonomy_mapping/simple_image_download.py +8 -8
- megadetector/taxonomy_mapping/species_lookup.py +156 -74
- megadetector/taxonomy_mapping/taxonomy_csv_checker.py +14 -14
- megadetector/taxonomy_mapping/taxonomy_graph.py +10 -10
- megadetector/taxonomy_mapping/validate_lila_category_mappings.py +13 -13
- megadetector/utils/ct_utils.py +1049 -211
- megadetector/utils/directory_listing.py +21 -77
- megadetector/utils/gpu_test.py +22 -22
- megadetector/utils/md_tests.py +632 -529
- megadetector/utils/path_utils.py +1520 -431
- megadetector/utils/process_utils.py +41 -41
- megadetector/utils/split_locations_into_train_val.py +62 -62
- megadetector/utils/string_utils.py +148 -27
- megadetector/utils/url_utils.py +489 -176
- megadetector/utils/wi_utils.py +2658 -2526
- megadetector/utils/write_html_image_list.py +137 -137
- megadetector/visualization/plot_utils.py +34 -30
- megadetector/visualization/render_images_with_thumbnails.py +39 -74
- megadetector/visualization/visualization_utils.py +487 -435
- megadetector/visualization/visualize_db.py +232 -198
- megadetector/visualization/visualize_detector_output.py +82 -76
- {megadetector-5.0.28.dist-info → megadetector-10.0.0.dist-info}/METADATA +5 -2
- megadetector-10.0.0.dist-info/RECORD +139 -0
- {megadetector-5.0.28.dist-info → megadetector-10.0.0.dist-info}/WHEEL +1 -1
- megadetector/api/batch_processing/api_core/__init__.py +0 -0
- megadetector/api/batch_processing/api_core/batch_service/__init__.py +0 -0
- megadetector/api/batch_processing/api_core/batch_service/score.py +0 -439
- megadetector/api/batch_processing/api_core/server.py +0 -294
- megadetector/api/batch_processing/api_core/server_api_config.py +0 -97
- megadetector/api/batch_processing/api_core/server_app_config.py +0 -55
- megadetector/api/batch_processing/api_core/server_batch_job_manager.py +0 -220
- megadetector/api/batch_processing/api_core/server_job_status_table.py +0 -149
- megadetector/api/batch_processing/api_core/server_orchestration.py +0 -360
- megadetector/api/batch_processing/api_core/server_utils.py +0 -88
- megadetector/api/batch_processing/api_core_support/__init__.py +0 -0
- megadetector/api/batch_processing/api_core_support/aggregate_results_manually.py +0 -46
- megadetector/api/batch_processing/api_support/__init__.py +0 -0
- megadetector/api/batch_processing/api_support/summarize_daily_activity.py +0 -152
- megadetector/api/batch_processing/data_preparation/__init__.py +0 -0
- megadetector/api/synchronous/__init__.py +0 -0
- megadetector/api/synchronous/api_core/animal_detection_api/__init__.py +0 -0
- megadetector/api/synchronous/api_core/animal_detection_api/api_backend.py +0 -151
- megadetector/api/synchronous/api_core/animal_detection_api/api_frontend.py +0 -263
- megadetector/api/synchronous/api_core/animal_detection_api/config.py +0 -35
- megadetector/api/synchronous/api_core/tests/__init__.py +0 -0
- megadetector/api/synchronous/api_core/tests/load_test.py +0 -110
- megadetector/data_management/importers/add_nacti_sizes.py +0 -52
- megadetector/data_management/importers/add_timestamps_to_icct.py +0 -79
- megadetector/data_management/importers/animl_results_to_md_results.py +0 -158
- megadetector/data_management/importers/auckland_doc_test_to_json.py +0 -373
- megadetector/data_management/importers/auckland_doc_to_json.py +0 -201
- megadetector/data_management/importers/awc_to_json.py +0 -191
- megadetector/data_management/importers/bellevue_to_json.py +0 -272
- megadetector/data_management/importers/cacophony-thermal-importer.py +0 -793
- megadetector/data_management/importers/carrizo_shrubfree_2018.py +0 -269
- megadetector/data_management/importers/carrizo_trail_cam_2017.py +0 -289
- megadetector/data_management/importers/cct_field_adjustments.py +0 -58
- megadetector/data_management/importers/channel_islands_to_cct.py +0 -913
- megadetector/data_management/importers/eMammal/copy_and_unzip_emammal.py +0 -180
- megadetector/data_management/importers/eMammal/eMammal_helpers.py +0 -249
- megadetector/data_management/importers/eMammal/make_eMammal_json.py +0 -223
- megadetector/data_management/importers/ena24_to_json.py +0 -276
- megadetector/data_management/importers/filenames_to_json.py +0 -386
- megadetector/data_management/importers/helena_to_cct.py +0 -283
- megadetector/data_management/importers/idaho-camera-traps.py +0 -1407
- megadetector/data_management/importers/idfg_iwildcam_lila_prep.py +0 -294
- megadetector/data_management/importers/import_desert_lion_conservation_camera_traps.py +0 -387
- megadetector/data_management/importers/jb_csv_to_json.py +0 -150
- megadetector/data_management/importers/mcgill_to_json.py +0 -250
- megadetector/data_management/importers/missouri_to_json.py +0 -490
- megadetector/data_management/importers/nacti_fieldname_adjustments.py +0 -79
- megadetector/data_management/importers/noaa_seals_2019.py +0 -181
- megadetector/data_management/importers/osu-small-animals-to-json.py +0 -364
- megadetector/data_management/importers/pc_to_json.py +0 -365
- megadetector/data_management/importers/plot_wni_giraffes.py +0 -123
- megadetector/data_management/importers/prepare_zsl_imerit.py +0 -131
- megadetector/data_management/importers/raic_csv_to_md_results.py +0 -416
- megadetector/data_management/importers/rspb_to_json.py +0 -356
- megadetector/data_management/importers/save_the_elephants_survey_A.py +0 -320
- megadetector/data_management/importers/save_the_elephants_survey_B.py +0 -329
- megadetector/data_management/importers/snapshot_safari_importer.py +0 -758
- megadetector/data_management/importers/snapshot_serengeti_lila.py +0 -1067
- megadetector/data_management/importers/snapshotserengeti/make_full_SS_json.py +0 -150
- megadetector/data_management/importers/snapshotserengeti/make_per_season_SS_json.py +0 -153
- megadetector/data_management/importers/sulross_get_exif.py +0 -65
- megadetector/data_management/importers/timelapse_csv_set_to_json.py +0 -490
- megadetector/data_management/importers/ubc_to_json.py +0 -399
- megadetector/data_management/importers/umn_to_json.py +0 -507
- megadetector/data_management/importers/wellington_to_json.py +0 -263
- megadetector/data_management/importers/wi_to_json.py +0 -442
- megadetector/data_management/importers/zamba_results_to_md_results.py +0 -180
- megadetector/data_management/lila/add_locations_to_island_camera_traps.py +0 -101
- megadetector/data_management/lila/add_locations_to_nacti.py +0 -151
- megadetector/utils/azure_utils.py +0 -178
- megadetector/utils/sas_blob_utils.py +0 -509
- megadetector-5.0.28.dist-info/RECORD +0 -209
- /megadetector/{api/batch_processing/__init__.py → __init__.py} +0 -0
- {megadetector-5.0.28.dist-info → megadetector-10.0.0.dist-info}/licenses/LICENSE +0 -0
- {megadetector-5.0.28.dist-info → megadetector-10.0.0.dist-info}/top_level.txt +0 -0
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
"""
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Converts the WI (SpeciesNet) predictions.json format to MD .json format. This is just a
|
|
6
|
-
command-line wrapper around utils.wi_utils.generate_md_results_from_predictions_json.
|
|
7
|
-
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
#%% Imports and constants
|
|
11
|
-
|
|
12
|
-
import sys
|
|
13
|
-
import argparse
|
|
14
|
-
from megadetector.utils.wi_utils import generate_md_results_from_predictions_json
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
#%% Command-line driver
|
|
18
|
-
|
|
19
|
-
def main():
|
|
20
|
-
|
|
21
|
-
parser = argparse.ArgumentParser()
|
|
22
|
-
parser.add_argument('predictions_json_file', action='store', type=str,
|
|
23
|
-
help='.json file to convert from SpeciesNet predictions.json format to MD format')
|
|
24
|
-
parser.add_argument('md_results_file', action='store', type=str,
|
|
25
|
-
help='output file to write in MD format')
|
|
26
|
-
parser.add_argument('--base_folder', action='store', type=str, default=None,
|
|
27
|
-
help='leading string to remove from each path in the predictions.json ' + \
|
|
28
|
-
'file (to convert from absolute to relative paths)')
|
|
29
|
-
|
|
30
|
-
if len(sys.argv[1:]) == 0:
|
|
31
|
-
parser.print_help()
|
|
32
|
-
parser.exit()
|
|
33
|
-
|
|
34
|
-
args = parser.parse_args()
|
|
35
|
-
|
|
36
|
-
generate_md_results_from_predictions_json(args.predictions_json_file,
|
|
37
|
-
args.md_results_file,
|
|
38
|
-
args.base_folder)
|
|
39
|
-
|
|
40
|
-
if __name__ == '__main__':
|
|
41
|
-
main()
|
|
1
|
+
"""
|
|
2
|
+
|
|
3
|
+
speciesnet_to_md.py
|
|
4
|
+
|
|
5
|
+
Converts the WI (SpeciesNet) predictions.json format to MD .json format. This is just a
|
|
6
|
+
command-line wrapper around utils.wi_utils.generate_md_results_from_predictions_json.
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
#%% Imports and constants
|
|
11
|
+
|
|
12
|
+
import sys
|
|
13
|
+
import argparse
|
|
14
|
+
from megadetector.utils.wi_utils import generate_md_results_from_predictions_json
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
#%% Command-line driver
|
|
18
|
+
|
|
19
|
+
def main(): # noqa
|
|
20
|
+
|
|
21
|
+
parser = argparse.ArgumentParser()
|
|
22
|
+
parser.add_argument('predictions_json_file', action='store', type=str,
|
|
23
|
+
help='.json file to convert from SpeciesNet predictions.json format to MD format')
|
|
24
|
+
parser.add_argument('md_results_file', action='store', type=str,
|
|
25
|
+
help='output file to write in MD format')
|
|
26
|
+
parser.add_argument('--base_folder', action='store', type=str, default=None,
|
|
27
|
+
help='leading string to remove from each path in the predictions.json ' + \
|
|
28
|
+
'file (to convert from absolute to relative paths)')
|
|
29
|
+
|
|
30
|
+
if len(sys.argv[1:]) == 0:
|
|
31
|
+
parser.print_help()
|
|
32
|
+
parser.exit()
|
|
33
|
+
|
|
34
|
+
args = parser.parse_args()
|
|
35
|
+
|
|
36
|
+
generate_md_results_from_predictions_json(args.predictions_json_file,
|
|
37
|
+
args.md_results_file,
|
|
38
|
+
args.base_folder)
|
|
39
|
+
|
|
40
|
+
if __name__ == '__main__':
|
|
41
|
+
main()
|
|
@@ -27,7 +27,7 @@ wi_extra_annotation_columns = \
|
|
|
27
27
|
|
|
28
28
|
wi_extra_image_columns = ('project_id','deployment_id')
|
|
29
29
|
|
|
30
|
-
def _make_location_id(project_id,deployment_id):
|
|
30
|
+
def _make_location_id(project_id,deployment_id):
|
|
31
31
|
return 'project_' + str(project_id) + '_deployment_' + deployment_id
|
|
32
32
|
|
|
33
33
|
default_category_remappings = {
|
|
@@ -47,86 +47,86 @@ def wi_download_csv_to_coco(csv_file_in,
|
|
|
47
47
|
verbose=True,
|
|
48
48
|
category_remappings=default_category_remappings):
|
|
49
49
|
"""
|
|
50
|
-
Converts a .csv file from a Wildlife Insights project export to a COCO
|
|
50
|
+
Converts a .csv file from a Wildlife Insights project export to a COCO
|
|
51
51
|
Camera Traps .json file.
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
Args:
|
|
54
54
|
csv_file_in (str): the downloaded .csv file we should convert to COCO
|
|
55
|
-
coco_file_out (str, optional): the .json file we should write; if [coco_file_out] is None,
|
|
55
|
+
coco_file_out (str, optional): the .json file we should write; if [coco_file_out] is None,
|
|
56
56
|
uses [csv_file_in].json
|
|
57
|
-
image_folder (str, optional): the folder where images live, only relevant if
|
|
57
|
+
image_folder (str, optional): the folder where images live, only relevant if
|
|
58
58
|
[validate_images] is True
|
|
59
59
|
validate_images (bool, optional): whether to check images for corruption and load
|
|
60
60
|
image sizes; if this is True, [image_folder] must be a valid folder
|
|
61
|
-
gs_prefix (str, optional): a string to remove from GS URLs to convert to path names...
|
|
61
|
+
gs_prefix (str, optional): a string to remove from GS URLs to convert to path names...
|
|
62
62
|
for example, if your gs:// URLs look like:
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
`gs://11234134_xyz/deployment/55554/dfadfasdfs.jpg`
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
...and you specify gs_prefix='11234134_xyz/deployment/', the filenames in
|
|
67
67
|
the .json file will look like:
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
`55554/dfadfasdfs.jpg`
|
|
70
70
|
verbose (bool, optional): enable additional debug console output
|
|
71
71
|
category_remappings (dict, optional): str --> str dict that maps any number of
|
|
72
72
|
WI category names to output category names; for example defaults to mapping
|
|
73
|
-
"Homo Species" to "Human", but leaves 99.99% of categories unchanged.
|
|
74
|
-
|
|
75
|
-
Returns:
|
|
73
|
+
"Homo Species" to "Human", but leaves 99.99% of categories unchanged.
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
76
|
dict: COCO-formatted data, identical to what's written to [coco_file_out]
|
|
77
77
|
"""
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
##%% Create COCO dictionaries
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
category_name_to_id = {}
|
|
82
82
|
category_name_to_id['empty'] = 0
|
|
83
|
-
|
|
83
|
+
|
|
84
84
|
df = pd.read_csv(csv_file_in)
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
print('Read {} rows from {}'.format(len(df),csv_file_in))
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
image_id_to_image = {}
|
|
89
89
|
image_id_to_annotations = defaultdict(list)
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
# i_row = 0; row = df.iloc[i_row]
|
|
92
92
|
for i_row,row in df.iterrows():
|
|
93
|
-
|
|
93
|
+
|
|
94
94
|
image_id = row['image_id']
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
if image_id not in image_id_to_image:
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
im = {}
|
|
99
99
|
image_id_to_image[image_id] = im
|
|
100
|
-
|
|
100
|
+
|
|
101
101
|
im['id'] = image_id
|
|
102
|
-
|
|
102
|
+
|
|
103
103
|
gs_url = row['location']
|
|
104
104
|
assert gs_url.startswith('gs://')
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
file_name = gs_url.replace('gs://','')
|
|
107
107
|
if gs_prefix is not None:
|
|
108
108
|
file_name = file_name.replace(gs_prefix,'')
|
|
109
|
-
|
|
109
|
+
|
|
110
110
|
location_id = _make_location_id(row['project_id'],row['deployment_id'])
|
|
111
111
|
im['file_name'] = file_name
|
|
112
112
|
im['location'] = location_id
|
|
113
113
|
im['datetime'] = row['timestamp']
|
|
114
|
-
|
|
114
|
+
|
|
115
115
|
im['wi_image_info'] = {}
|
|
116
116
|
for s in wi_extra_image_columns:
|
|
117
117
|
im['wi_image_info'][s] = str(row[s])
|
|
118
|
-
|
|
118
|
+
|
|
119
119
|
else:
|
|
120
|
-
|
|
120
|
+
|
|
121
121
|
im = image_id_to_image[image_id]
|
|
122
122
|
assert im['datetime'] == row['timestamp']
|
|
123
123
|
location_id = _make_location_id(row['project_id'],row['deployment_id'])
|
|
124
124
|
assert im['location'] == location_id
|
|
125
|
-
|
|
125
|
+
|
|
126
126
|
category_name = row['common_name']
|
|
127
127
|
if category_remappings is not None and category_name in category_remappings:
|
|
128
128
|
category_name = category_remappings[category_name]
|
|
129
|
-
|
|
129
|
+
|
|
130
130
|
if category_name == 'Blank':
|
|
131
131
|
category_name = 'empty'
|
|
132
132
|
assert row['is_blank'] == 1
|
|
@@ -138,24 +138,24 @@ def wi_download_csv_to_coco(csv_file_in,
|
|
|
138
138
|
else:
|
|
139
139
|
category_id = len(category_name_to_id)
|
|
140
140
|
category_name_to_id[category_name] = category_id
|
|
141
|
-
|
|
141
|
+
|
|
142
142
|
ann = {}
|
|
143
143
|
ann['image_id'] = image_id
|
|
144
144
|
annotations_this_image = image_id_to_annotations[image_id]
|
|
145
145
|
annotation_number = len(annotations_this_image)
|
|
146
|
-
ann['id'] = image_id + '_' + str(annotation_number).zfill(2)
|
|
146
|
+
ann['id'] = image_id + '_' + str(annotation_number).zfill(2)
|
|
147
147
|
ann['category_id'] = category_id
|
|
148
148
|
annotations_this_image.append(ann)
|
|
149
|
-
|
|
149
|
+
|
|
150
150
|
extra_info = {}
|
|
151
|
-
for s in wi_extra_annotation_columns:
|
|
151
|
+
for s in wi_extra_annotation_columns:
|
|
152
152
|
v = row[s]
|
|
153
153
|
if not isnan(v):
|
|
154
154
|
extra_info[s] = v
|
|
155
155
|
ann['wi_extra_info'] = extra_info
|
|
156
|
-
|
|
156
|
+
|
|
157
157
|
# ...for each row
|
|
158
|
-
|
|
158
|
+
|
|
159
159
|
images = list(image_id_to_image.values())
|
|
160
160
|
categories = []
|
|
161
161
|
for category_name in category_name_to_id:
|
|
@@ -173,25 +173,25 @@ def wi_download_csv_to_coco(csv_file_in,
|
|
|
173
173
|
coco_data['images'] = images
|
|
174
174
|
coco_data['annotations'] = annotations
|
|
175
175
|
coco_data['categories'] = categories
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
##%% Validate images, add sizes
|
|
179
|
-
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
##%% Validate images, add sizes
|
|
179
|
+
|
|
180
180
|
if validate_images:
|
|
181
|
-
|
|
181
|
+
|
|
182
182
|
print('Validating images')
|
|
183
|
-
|
|
183
|
+
|
|
184
184
|
assert os.path.isdir(image_folder), \
|
|
185
185
|
'Must specify a valid image folder if you specify validate_images=True'
|
|
186
|
-
|
|
186
|
+
|
|
187
187
|
# TODO: trivially parallelizable
|
|
188
|
-
#
|
|
188
|
+
#
|
|
189
189
|
# im = images[0]
|
|
190
190
|
for im in tqdm(images):
|
|
191
191
|
file_name_relative = im['file_name']
|
|
192
192
|
file_name_abs = os.path.join(image_folder,file_name_relative)
|
|
193
193
|
assert os.path.isfile(file_name_abs)
|
|
194
|
-
|
|
194
|
+
|
|
195
195
|
im['corrupt'] = False
|
|
196
196
|
try:
|
|
197
197
|
pil_im = vis_utils.load_image(file_name_abs)
|
|
@@ -200,19 +200,19 @@ def wi_download_csv_to_coco(csv_file_in,
|
|
|
200
200
|
if not im['corrupt']:
|
|
201
201
|
im['width'] = pil_im.width
|
|
202
202
|
im['height'] = pil_im.height
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
|
|
204
|
+
|
|
205
205
|
##%% Write output json
|
|
206
|
-
|
|
207
|
-
if coco_file_out is None:
|
|
206
|
+
|
|
207
|
+
if coco_file_out is None:
|
|
208
208
|
coco_file_out = csv_file_in + '.json'
|
|
209
|
-
|
|
209
|
+
|
|
210
210
|
with open(coco_file_out,'w') as f:
|
|
211
211
|
json.dump(coco_data,f,indent=1)
|
|
212
212
|
|
|
213
213
|
|
|
214
214
|
##%% Validate output
|
|
215
|
-
|
|
215
|
+
|
|
216
216
|
from megadetector.data_management.databases.integrity_check_json_db import \
|
|
217
217
|
IntegrityCheckOptions,integrity_check_json_db
|
|
218
218
|
options = IntegrityCheckOptions()
|
|
@@ -220,18 +220,18 @@ def wi_download_csv_to_coco(csv_file_in,
|
|
|
220
220
|
options.bCheckImageExistence = True
|
|
221
221
|
options.verbose = verbose
|
|
222
222
|
_ = integrity_check_json_db(coco_file_out,options)
|
|
223
|
-
|
|
223
|
+
|
|
224
224
|
return coco_data
|
|
225
225
|
|
|
226
|
-
# ...def wi_download_csv_to_coco(...)
|
|
226
|
+
# ...def wi_download_csv_to_coco(...)
|
|
227
227
|
|
|
228
228
|
|
|
229
229
|
#%% Interactive driver
|
|
230
230
|
|
|
231
231
|
if False:
|
|
232
|
-
|
|
232
|
+
|
|
233
233
|
#%%
|
|
234
|
-
|
|
234
|
+
|
|
235
235
|
base_folder = r'a/b/c'
|
|
236
236
|
csv_file_in = os.path.join(base_folder,'images.csv')
|
|
237
237
|
coco_file_out = None
|