megadetector 5.0.28__py3-none-any.whl → 5.0.29__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/api_core/batch_service/score.py +4 -5
- megadetector/api/batch_processing/api_core_support/aggregate_results_manually.py +1 -1
- megadetector/api/batch_processing/api_support/summarize_daily_activity.py +1 -1
- 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/api/synchronous/api_core/tests/load_test.py +2 -3
- 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/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 +23 -23
- 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 -1
- megadetector/data_management/camtrap_dp_to_coco.py +45 -45
- megadetector/data_management/cct_json_utils.py +101 -101
- 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 +189 -189
- megadetector/data_management/databases/add_width_and_height_to_db.py +3 -2
- megadetector/data_management/databases/combine_coco_camera_traps_files.py +38 -38
- megadetector/data_management/databases/integrity_check_json_db.py +202 -188
- megadetector/data_management/databases/subset_json_db.py +33 -33
- megadetector/data_management/generate_crops_from_cct.py +38 -38
- megadetector/data_management/get_image_sizes.py +54 -49
- megadetector/data_management/labelme_to_coco.py +130 -124
- megadetector/data_management/labelme_to_yolo.py +78 -72
- 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 +91 -91
- megadetector/data_management/lila/get_lila_annotation_counts.py +30 -30
- megadetector/data_management/lila/get_lila_image_counts.py +22 -22
- megadetector/data_management/lila/lila_common.py +70 -70
- megadetector/data_management/lila/test_lila_metadata_urls.py +13 -14
- megadetector/data_management/mewc_to_md.py +339 -340
- megadetector/data_management/ocr_tools.py +258 -252
- megadetector/data_management/read_exif.py +231 -224
- megadetector/data_management/remap_coco_categories.py +26 -26
- megadetector/data_management/remove_exif.py +31 -20
- megadetector/data_management/rename_images.py +187 -187
- megadetector/data_management/resize_coco_dataset.py +41 -41
- 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 +117 -120
- megadetector/data_management/yolo_to_coco.py +195 -188
- megadetector/detection/change_detection.py +831 -0
- megadetector/detection/process_video.py +340 -337
- megadetector/detection/pytorch_detector.py +304 -262
- megadetector/detection/run_detector.py +177 -164
- megadetector/detection/run_detector_batch.py +364 -363
- megadetector/detection/run_inference_with_yolov5_val.py +328 -325
- megadetector/detection/run_tiled_inference.py +256 -249
- megadetector/detection/tf_detector.py +24 -24
- megadetector/detection/video_utils.py +290 -282
- megadetector/postprocessing/add_max_conf.py +15 -11
- megadetector/postprocessing/categorize_detections_by_size.py +44 -44
- megadetector/postprocessing/classification_postprocessing.py +415 -415
- megadetector/postprocessing/combine_batch_outputs.py +20 -21
- megadetector/postprocessing/compare_batch_results.py +528 -517
- megadetector/postprocessing/convert_output_format.py +97 -97
- megadetector/postprocessing/create_crop_folder.py +219 -146
- megadetector/postprocessing/detector_calibration.py +173 -168
- megadetector/postprocessing/generate_csv_report.py +508 -499
- megadetector/postprocessing/load_api_results.py +23 -20
- megadetector/postprocessing/md_to_coco.py +129 -98
- megadetector/postprocessing/md_to_labelme.py +89 -83
- megadetector/postprocessing/md_to_wi.py +40 -40
- megadetector/postprocessing/merge_detections.py +87 -114
- megadetector/postprocessing/postprocess_batch_results.py +313 -298
- megadetector/postprocessing/remap_detection_categories.py +36 -36
- megadetector/postprocessing/render_detection_confusion_matrix.py +205 -199
- 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 +702 -677
- 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 +15 -15
- megadetector/taxonomy_mapping/prepare_lila_taxonomy_release.py +14 -14
- megadetector/taxonomy_mapping/preview_lila_taxonomy.py +66 -66
- megadetector/taxonomy_mapping/retrieve_sample_image.py +16 -16
- megadetector/taxonomy_mapping/simple_image_download.py +8 -8
- megadetector/taxonomy_mapping/species_lookup.py +33 -33
- 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/azure_utils.py +22 -22
- megadetector/utils/ct_utils.py +1018 -200
- megadetector/utils/directory_listing.py +21 -77
- megadetector/utils/gpu_test.py +22 -22
- megadetector/utils/md_tests.py +541 -518
- megadetector/utils/path_utils.py +1457 -398
- megadetector/utils/process_utils.py +41 -41
- megadetector/utils/sas_blob_utils.py +53 -49
- megadetector/utils/split_locations_into_train_val.py +61 -61
- megadetector/utils/string_utils.py +147 -26
- megadetector/utils/url_utils.py +463 -173
- megadetector/utils/wi_utils.py +2629 -2526
- megadetector/utils/write_html_image_list.py +137 -137
- megadetector/visualization/plot_utils.py +21 -21
- megadetector/visualization/render_images_with_thumbnails.py +37 -73
- megadetector/visualization/visualization_utils.py +401 -397
- megadetector/visualization/visualize_db.py +197 -190
- megadetector/visualization/visualize_detector_output.py +79 -73
- {megadetector-5.0.28.dist-info → megadetector-5.0.29.dist-info}/METADATA +135 -132
- megadetector-5.0.29.dist-info/RECORD +163 -0
- {megadetector-5.0.28.dist-info → megadetector-5.0.29.dist-info}/WHEEL +1 -1
- {megadetector-5.0.28.dist-info → megadetector-5.0.29.dist-info}/licenses/LICENSE +0 -0
- {megadetector-5.0.28.dist-info → megadetector-5.0.29.dist-info}/top_level.txt +0 -0
- 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-5.0.28.dist-info/RECORD +0 -209
|
@@ -28,23 +28,23 @@ def labelme_file_to_yolo_file(labelme_file,
|
|
|
28
28
|
"""
|
|
29
29
|
Convert the single .json file labelme_file to yolo format, writing the results to the text
|
|
30
30
|
file yolo_file (defaults to s/json/txt).
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
If required_token is not None and the dict in labelme_file does not contain the key [required_token],
|
|
33
|
-
this function no-ops (i.e., does not generate a YOLO file).
|
|
34
|
-
|
|
33
|
+
this function no-ops (i.e., does not generate a YOLO file).
|
|
34
|
+
|
|
35
35
|
overwrite_behavior should be 'skip' or 'overwrite' (default).
|
|
36
36
|
"""
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
result = {}
|
|
39
39
|
result['labelme_file'] = labelme_file
|
|
40
40
|
result['status'] = 'unknown'
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
assert os.path.isfile(labelme_file), 'Could not find labelme .json file {}'.format(labelme_file)
|
|
43
43
|
assert labelme_file.endswith('.json'), 'Illegal labelme .json file {}'.format(labelme_file)
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
if yolo_file is None:
|
|
46
46
|
yolo_file = os.path.splitext(labelme_file)[0] + '.txt'
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
if os.path.isfile(yolo_file):
|
|
49
49
|
if overwrite_behavior == 'skip':
|
|
50
50
|
result['status'] = 'skip-exists'
|
|
@@ -52,31 +52,31 @@ def labelme_file_to_yolo_file(labelme_file,
|
|
|
52
52
|
else:
|
|
53
53
|
assert overwrite_behavior == 'overwrite', \
|
|
54
54
|
'Unrecognized overwrite behavior {}'.format(overwrite_behavior)
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
with open(labelme_file,'r') as f:
|
|
57
57
|
labelme_data = json.load(f)
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
if required_token is not None and required_token not in labelme_data:
|
|
60
60
|
result['status'] = 'skip-no-required-token'
|
|
61
61
|
return result
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
im_height = labelme_data['imageHeight']
|
|
64
64
|
im_width = labelme_data['imageWidth']
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
yolo_lines = []
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
for shape in labelme_data['shapes']:
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
assert shape['shape_type'] == 'rectangle', \
|
|
71
71
|
'I only know how to convert rectangles to YOLO format'
|
|
72
72
|
assert shape['label'] in category_name_to_category_id, \
|
|
73
73
|
'Category {} not in category mapping'.format(shape['label'])
|
|
74
74
|
assert len(shape['points']) == 2, 'Illegal rectangle'
|
|
75
75
|
category_id = category_name_to_category_id[shape['label']]
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
p0 = shape['points'][0]
|
|
78
78
|
p1 = shape['points'][1]
|
|
79
|
-
|
|
79
|
+
|
|
80
80
|
# Labelme: [[x0,y0],[x1,y1]] (arbitrarily sorted) (absolute coordinates)
|
|
81
81
|
#
|
|
82
82
|
# YOLO: [class, x_center, y_center, width, height] (normalized coordinates)
|
|
@@ -84,12 +84,12 @@ def labelme_file_to_yolo_file(labelme_file,
|
|
|
84
84
|
maxx_abs = max(p0[0],p1[0])
|
|
85
85
|
miny_abs = min(p0[1],p1[1])
|
|
86
86
|
maxy_abs = max(p0[1],p1[1])
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
if (minx_abs >= (im_width-1)) or (maxx_abs <= 0) or \
|
|
89
89
|
(miny_abs >= (im_height-1)) or (maxy_abs <= 0):
|
|
90
|
-
print('Skipping invalid shape in {}'.format(labelme_file))
|
|
90
|
+
print('Skipping invalid shape in {}'.format(labelme_file))
|
|
91
91
|
continue
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
# Clip to [0,1]... it's not obvious that the YOLO format doesn't allow bounding
|
|
94
94
|
# boxes to extend outside the image, but YOLOv5 and YOLOv8 get sad about boxes
|
|
95
95
|
# that extend outside the image.
|
|
@@ -97,30 +97,30 @@ def labelme_file_to_yolo_file(labelme_file,
|
|
|
97
97
|
maxy_abs = min(maxy_abs,im_height-1)
|
|
98
98
|
minx_abs = max(minx_abs,0.0)
|
|
99
99
|
miny_abs = max(miny_abs,0.0)
|
|
100
|
-
|
|
100
|
+
|
|
101
101
|
minx_rel = minx_abs / (im_width-1)
|
|
102
102
|
maxx_rel = maxx_abs / (im_width-1)
|
|
103
103
|
miny_rel = miny_abs / (im_height-1)
|
|
104
104
|
maxy_rel = maxy_abs / (im_height-1)
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
assert maxx_rel >= minx_rel
|
|
107
107
|
assert maxy_rel >= miny_rel
|
|
108
|
-
|
|
108
|
+
|
|
109
109
|
xcenter_rel = (maxx_rel + minx_rel) / 2.0
|
|
110
110
|
ycenter_rel = (maxy_rel + miny_rel) / 2.0
|
|
111
111
|
w_rel = maxx_rel - minx_rel
|
|
112
112
|
h_rel = maxy_rel - miny_rel
|
|
113
|
-
|
|
113
|
+
|
|
114
114
|
yolo_line = '{} {:.3f} {:.3f} {:.3f} {:.3f}'.format(category_id,
|
|
115
115
|
xcenter_rel, ycenter_rel, w_rel, h_rel)
|
|
116
116
|
yolo_lines.append(yolo_line)
|
|
117
|
-
|
|
117
|
+
|
|
118
118
|
# ...for each shape
|
|
119
|
-
|
|
119
|
+
|
|
120
120
|
with open(yolo_file,'w') as f:
|
|
121
121
|
for s in yolo_lines:
|
|
122
122
|
f.write(s + '\n')
|
|
123
|
-
|
|
123
|
+
|
|
124
124
|
result['status'] = 'converted'
|
|
125
125
|
return result
|
|
126
126
|
|
|
@@ -136,22 +136,22 @@ def labelme_folder_to_yolo(labelme_folder,
|
|
|
136
136
|
Given a folder with images and labelme .json files, convert the .json files
|
|
137
137
|
to YOLO .txt format. If category_name_to_category_id is None, first reads
|
|
138
138
|
all the labels in the folder to build a zero-indexed name --> ID mapping.
|
|
139
|
-
|
|
139
|
+
|
|
140
140
|
If required_token is not None and a labelme_file does not contain the key [required_token],
|
|
141
141
|
it won't be converted. Typically used to specify a field that indicates which files have
|
|
142
142
|
been reviewed.
|
|
143
|
-
|
|
143
|
+
|
|
144
144
|
If relative_filenames_to_convert is not None, this should be a list of .json (not image)
|
|
145
145
|
files that should get converted, relative to the base folder.
|
|
146
|
-
|
|
146
|
+
|
|
147
147
|
overwrite_behavior should be 'skip' or 'overwrite' (default).
|
|
148
|
-
|
|
148
|
+
|
|
149
149
|
returns a dict with:
|
|
150
150
|
'category_name_to_category_id', whether it was passed in or constructed
|
|
151
151
|
'image_results': a list of results for each image (converted, skipped, error)
|
|
152
|
-
|
|
152
|
+
|
|
153
153
|
"""
|
|
154
|
-
|
|
154
|
+
|
|
155
155
|
if relative_filenames_to_convert is not None:
|
|
156
156
|
labelme_files_relative = relative_filenames_to_convert
|
|
157
157
|
assert all([fn.endswith('.json') for fn in labelme_files_relative]), \
|
|
@@ -159,35 +159,35 @@ def labelme_folder_to_yolo(labelme_folder,
|
|
|
159
159
|
else:
|
|
160
160
|
labelme_files_relative = recursive_file_list(labelme_folder,return_relative_paths=True)
|
|
161
161
|
labelme_files_relative = [fn for fn in labelme_files_relative if fn.endswith('.json')]
|
|
162
|
-
|
|
162
|
+
|
|
163
163
|
if required_token is None:
|
|
164
164
|
valid_labelme_files_relative = labelme_files_relative
|
|
165
|
-
else:
|
|
165
|
+
else:
|
|
166
166
|
valid_labelme_files_relative = []
|
|
167
|
-
|
|
167
|
+
|
|
168
168
|
# fn_relative = labelme_files_relative[-1]
|
|
169
169
|
for fn_relative in labelme_files_relative:
|
|
170
|
-
|
|
171
|
-
fn_abs = os.path.join(labelme_folder,fn_relative)
|
|
172
|
-
|
|
170
|
+
|
|
171
|
+
fn_abs = os.path.join(labelme_folder,fn_relative)
|
|
172
|
+
|
|
173
173
|
with open(fn_abs,'r') as f:
|
|
174
174
|
labelme_data = json.load(f)
|
|
175
175
|
if required_token not in labelme_data:
|
|
176
176
|
continue
|
|
177
|
-
|
|
177
|
+
|
|
178
178
|
valid_labelme_files_relative.append(fn_relative)
|
|
179
|
-
|
|
179
|
+
|
|
180
180
|
print('{} of {} files are valid'.format(len(valid_labelme_files_relative),
|
|
181
181
|
len(labelme_files_relative)))
|
|
182
|
-
|
|
182
|
+
|
|
183
183
|
del labelme_files_relative
|
|
184
|
-
|
|
184
|
+
|
|
185
185
|
if category_name_to_category_id is None:
|
|
186
|
-
|
|
186
|
+
|
|
187
187
|
category_name_to_category_id = {}
|
|
188
|
-
|
|
188
|
+
|
|
189
189
|
for fn_relative in valid_labelme_files_relative:
|
|
190
|
-
|
|
190
|
+
|
|
191
191
|
fn_abs = os.path.join(labelme_folder,fn_relative)
|
|
192
192
|
with open(fn_abs,'r') as f:
|
|
193
193
|
labelme_data = json.load(f)
|
|
@@ -196,16 +196,16 @@ def labelme_folder_to_yolo(labelme_folder,
|
|
|
196
196
|
if label not in category_name_to_category_id:
|
|
197
197
|
category_name_to_category_id[label] = len(category_name_to_category_id)
|
|
198
198
|
# ...for each file
|
|
199
|
-
|
|
199
|
+
|
|
200
200
|
# ...if we need to build a category mapping
|
|
201
|
-
|
|
201
|
+
|
|
202
202
|
image_results = []
|
|
203
|
-
|
|
203
|
+
|
|
204
204
|
n_workers = min(n_workers,len(valid_labelme_files_relative))
|
|
205
|
-
|
|
205
|
+
|
|
206
206
|
if n_workers <= 1:
|
|
207
207
|
for fn_relative in tqdm(valid_labelme_files_relative):
|
|
208
|
-
|
|
208
|
+
|
|
209
209
|
fn_abs = os.path.join(labelme_folder,fn_relative)
|
|
210
210
|
image_result = labelme_file_to_yolo_file(fn_abs,
|
|
211
211
|
category_name_to_category_id,
|
|
@@ -215,35 +215,41 @@ def labelme_folder_to_yolo(labelme_folder,
|
|
|
215
215
|
image_results.append(image_result)
|
|
216
216
|
# ...for each file
|
|
217
217
|
else:
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
218
|
+
pool = None
|
|
219
|
+
try:
|
|
220
|
+
if use_threads:
|
|
221
|
+
pool = ThreadPool(n_workers)
|
|
222
|
+
else:
|
|
223
|
+
pool = Pool(n_workers)
|
|
224
|
+
|
|
225
|
+
valid_labelme_files_abs = [os.path.join(labelme_folder,fn_relative) for \
|
|
226
|
+
fn_relative in valid_labelme_files_relative]
|
|
227
|
+
|
|
228
|
+
image_results = list(tqdm(pool.imap(
|
|
229
|
+
partial(labelme_file_to_yolo_file,
|
|
230
|
+
category_name_to_category_id=category_name_to_category_id,
|
|
231
|
+
yolo_file=None,
|
|
232
|
+
required_token=required_token,
|
|
233
|
+
overwrite_behavior=overwrite_behavior),
|
|
234
|
+
valid_labelme_files_abs),
|
|
235
|
+
total=len(valid_labelme_files_abs)))
|
|
236
|
+
finally:
|
|
237
|
+
pool.close()
|
|
238
|
+
pool.join()
|
|
239
|
+
print("Pool closed and joined for labelme conversion to YOLO")
|
|
234
240
|
|
|
235
241
|
assert len(valid_labelme_files_relative) == len(image_results)
|
|
236
|
-
|
|
242
|
+
|
|
237
243
|
print('Converted {} labelme .json files to YOLO'.format(
|
|
238
244
|
len(valid_labelme_files_relative)))
|
|
239
|
-
|
|
245
|
+
|
|
240
246
|
labelme_to_yolo_results = {}
|
|
241
247
|
labelme_to_yolo_results['category_name_to_category_id'] = category_name_to_category_id
|
|
242
248
|
labelme_to_yolo_results['image_results'] = image_results
|
|
243
|
-
|
|
249
|
+
|
|
244
250
|
return labelme_to_yolo_results
|
|
245
|
-
|
|
246
|
-
# ...def labelme_folder_to_yolo(...)
|
|
251
|
+
|
|
252
|
+
# ...def labelme_folder_to_yolo(...)
|
|
247
253
|
|
|
248
254
|
|
|
249
255
|
#%% Interactive driver
|
|
@@ -260,13 +266,13 @@ if False:
|
|
|
260
266
|
labelme_folder = os.path.expanduser('~/tmp/labels')
|
|
261
267
|
|
|
262
268
|
#%%
|
|
263
|
-
|
|
269
|
+
|
|
264
270
|
category_name_to_category_id = \
|
|
265
271
|
labelme_folder_to_yolo(labelme_folder,
|
|
266
272
|
category_name_to_category_id=category_name_to_category_id,
|
|
267
273
|
required_token=required_token,
|
|
268
274
|
overwrite_behavior='overwrite')
|
|
269
|
-
|
|
275
|
+
|
|
270
276
|
#%% Command-line driver
|
|
271
277
|
|
|
272
278
|
# TODO
|