Skip to content

Commit cff246b

Browse files
committed
handling the case where detector_options is supplied programmatically as None
1 parent 4a2450d commit cff246b

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

megadetector/detection/run_detector.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@
9898
'v5a.0.0':'v5a.0.1',
9999
'v5b.0.0':'v5b.0.1',
100100

101+
'md1000-redwood':'v1000.0.0-redwood',
102+
'md1000-cedar':'v1000.0.0-cedar',
103+
'md1000-larch':'v1000.0.0-larch',
104+
'md1000-sorrel':'v1000.0.0-sorrel',
105+
'md1000-spruce':'v1000.0.0-spruce',
106+
101107
'mdv1000-redwood':'v1000.0.0-redwood',
102108
'mdv1000-cedar':'v1000.0.0-cedar',
103109
'mdv1000-larch':'v1000.0.0-larch',
@@ -125,6 +131,7 @@
125131
'megadetector':'v5a.0.1',
126132
}
127133

134+
# python -m http.server 8181
128135
model_url_base = 'http://localhost:8181/'
129136
assert model_url_base.endswith('/')
130137

megadetector/detection/run_detector_batch.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ def run_detector_with_image_queue(image_files,
350350
if loader_workers <= 0:
351351
loader_workers = 1
352352

353+
if detector_options is None:
354+
detector_options = {}
355+
353356
q = multiprocessing.JoinableQueue(max_queue_size)
354357
return_queue = multiprocessing.Queue(1)
355358

@@ -532,6 +535,9 @@ def process_images(im_files,
532535
elapsed = time.time() - start_time
533536
print('Loaded model (batch level) in {}'.format(humanfriendly.format_timespan(elapsed)))
534537

538+
if detector_options is None:
539+
detector_options = {}
540+
535541
if use_image_queue:
536542

537543
run_detector_with_image_queue(im_files,
@@ -751,6 +757,9 @@ def load_and_run_detector_batch(model_file,
751757
if n_cores is None or n_cores <= 0:
752758
n_cores = 1
753759

760+
if detector_options is None:
761+
detector_options = {}
762+
754763
if confidence_threshold is None:
755764
confidence_threshold=run_detector.DEFAULT_OUTPUT_CONFIDENCE_THRESHOLD
756765

megadetector/postprocessing/md_to_labelme.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,13 @@ def get_labelme_dict_for_image(im,image_base_name=None,category_id_to_name=None,
108108
# ...def get_labelme_dict_for_image()
109109

110110

111-
def _write_output_for_image(im,image_base,extension_prefix,info,
112-
confidence_threshold,category_id_to_name,overwrite,
111+
def _write_output_for_image(im,
112+
image_base,
113+
extension_prefix,
114+
info,
115+
confidence_threshold,
116+
category_id_to_name,
117+
overwrite,
113118
verbose=False):
114119

115120
if 'failure' in im and im['failure'] is not None:
@@ -140,9 +145,14 @@ def _write_output_for_image(im,image_base,extension_prefix,info,
140145

141146

142147

143-
def md_to_labelme(results_file,image_base,confidence_threshold=None,
144-
overwrite=False,extension_prefix='',n_workers=1,
145-
use_threads=False,bypass_image_size_read=False,
148+
def md_to_labelme(results_file,
149+
image_base,
150+
confidence_threshold=None,
151+
overwrite=False,
152+
extension_prefix='',
153+
n_workers=1,
154+
use_threads=False,
155+
bypass_image_size_read=False,
146156
verbose=False):
147157
"""
148158
For all the images in [results_file], write a .json file in labelme format alongside the
@@ -153,11 +163,12 @@ def md_to_labelme(results_file,image_base,confidence_threshold=None,
153163
image_base (str): folder of images; filenames in [results_file] should be relative to
154164
this folder
155165
confidence_threshold (float, optional): only detections at or above this confidence threshold
156-
will be included in the output dict
166+
will be included in the output dict. If None, no threshold will be applied.
157167
overwrite (bool, optional): whether to overwrite existing output files; if this is False
158168
and the output file for an image exists, we'll skip that image
159169
extension_prefix (str, optional): if non-empty, "extension_prefix" will be inserted before the .json
160-
extension
170+
extension (typically used to generate multiple copies of labelme files representing different
171+
MD thresholds)
161172
n_workers (int, optional): enables multiprocessing if > 1
162173
use_threads (bool, optional): if [n_workers] > 1, determines whether we parallelize via threads (True)
163174
or processes (False)

megadetector/utils/url_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ class TestUrlUtils:
472472
Tests for url_utils.py
473473
"""
474474

475-
476475
def set_up(self):
477476
"""
478477
Create a temporary directory for testing.
@@ -708,9 +707,11 @@ def test_get_url_size_and_sizes(self):
708707
assert sizes_map[REDIRECT_DEST_URL] == size_dynamic
709708

710709

711-
def test_url_utils():
710+
def _test_url_utils():
712711
"""
713-
Runs all tests in the TestUrlUtils class.
712+
Runs all tests in the TestUrlUtils class. I generally disable this during testing
713+
because it creates irritating nondeterminism, and this is neither a core module nor
714+
a module that changes often.
714715
"""
715716

716717
test_instance = TestUrlUtils()

0 commit comments

Comments
 (0)