Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -540,17 +540,6 @@ E2
!feature


## Graceful handling of augmentation for MDv1000-cedar

MDv1000-cedar does not support image augmentation. It's not important to add it; the entire point of MDv1000-cedar is for compute-constrained scenarios. Right now, though, it crashes unhelpfully. Handle this more gracefully.

P2

E0

!bug


## Document the "modern" preprocessing approach

With the release of MDv1000, I introduced two preprocessing approaches: "classic" (which matches what we always did for MDv5, and roughly matches YOLOv5's detect.py) and "modern" (which roughly matches YOLOv5's val.py). Neither is obviously better or worse, but they are different. There is a separate item for evaluating this difference (and others); this item is just about more properly documenting the difference, and documenting how to invoke each approach. This would include finding a couple of example images where they produce different results.
Expand Down
5 changes: 5 additions & 0 deletions megadetector/detection/process_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from megadetector.detection.run_detector import load_detector
from megadetector.detection.run_detector import is_gpu_available
from megadetector.detection.run_detector import try_download_known_detector
from megadetector.detection.run_detector import check_augmentation_support
from megadetector.postprocessing.validate_batch_results import \
ValidateBatchResultsOptions, validate_batch_results

Expand Down Expand Up @@ -832,6 +833,10 @@ def process_videos(options):
raise ValueError('{} is not a known model name or an existing model file'.format(
options.model_file))

# Error if augmentation is enabled for a no-augmentation-support model
if options.augment:
check_augmentation_support(model_file)

detector_options = options.detector_options
if detector_options is None:
detector_options = {}
Expand Down
42 changes: 41 additions & 1 deletion megadetector/detection/run_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@
{
'url':model_url_base + 'md_v1000.0.0-cedar.pt',
'normalized_typical_inference_speed':2.0,
'md5':'3d6472c9b95ba687b59ebe255f7c576b'
'md5':'3d6472c9b95ba687b59ebe255f7c576b',
'supports_augmentation':False
},
'v1000.0.0-sorrel':
{
Expand Down Expand Up @@ -341,6 +342,42 @@ def get_detector_version_from_filename(detector_filename,
return model_string_to_model_version[matches[0]]


def model_supports_augmentation(model_file):
"""
Determines whether a model file can be run with image augmentation (--augment).

Args:
model_file (str): model filename, e.g. c:/x/z/md_v1000.0.0-cedar.pt

Returns:
bool: False if [model_file] is a known model that doesn't support augmentation,
otherwise True
"""

detector_version = get_detector_version_from_model_file(model_file)
if detector_version not in known_models:
return True
return known_models[detector_version].get('supports_augmentation',True)

# ...def model_supports_augmentation(...)


def check_augmentation_support(model_file):
"""
Raises a ValueError if [model_file] doesn't support image augmentation.

Args:
model_file (str): model filename
"""

if not model_supports_augmentation(model_file):
raise ValueError(
'Image augmentation is not supported for {} ({})'.format(
model_file,get_detector_version_from_model_file(model_file)))

# ...def check_augmentation_support(...)


def get_detector_version_from_model_file(detector_filename,verbose=False):
"""
Gets the canonical detection version from a model file, preferably by reading it
Expand Down Expand Up @@ -1164,6 +1201,9 @@ def load_and_run_detector(model_file,
force_download=force_model_download,
verbose=verbose)

if augment:
check_augmentation_support(model_file)

detector = load_detector(model_file,
detector_options=detector_options,
verbose=verbose)
Expand Down
5 changes: 5 additions & 0 deletions megadetector/detection/run_detector_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
from megadetector.detection import run_detector
from megadetector.detection.run_detector import \
is_gpu_available,\
check_augmentation_support,\
load_detector,\
try_download_known_detector,\
get_detector_version_from_filename,\
Expand Down Expand Up @@ -1270,6 +1271,10 @@ def load_and_run_detector_batch(model_file,
if not os.path.isfile(model_file):
raise ValueError('{} is not a known model name or an existing model file'.format(model_file))

# Error if augmentation is enabled for a no-augmentation-support model
if augment:
check_augmentation_support(model_file)

# Print debug information about GPU availability
gpu_available = is_gpu_available(model_file, context_string='load_and_run_detector_batch')

Expand Down
13 changes: 8 additions & 5 deletions notebooks/wi_utils_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@

#%% Generate an allow-list

taxon = 'sciurus carolinensis'
taxon = 'gulo gulo'
# taxon = 'eastern fox squirrel'

allow_countries = ['USA']
allow_states = ['ID','MT']
species_string = taxonomy_handler.species_string_to_canonical_species_string(taxon)
taxonomy_info = taxonomy_handler.taxonomy_string_to_taxonomy_info[species_string]

Expand All @@ -187,9 +190,9 @@
assert len(taxonomy_string_short.split(';')) == 5

rows = taxonomy_handler.generate_csv_rows_for_species(species_string=species_string,
allow_countries=['USA'],
allow_countries=allow_countries,
block_countries=None,
allow_states=['CA','OR','ID','MT','WA'],
allow_states=allow_states,
block_states=None)

# import clipboard; clipboard.copy('\n'.join(rows))
Expand Down Expand Up @@ -221,9 +224,9 @@

#%% Determine whether a species is allowed in a location

taxon = 'diprotodontia'
taxon = 'gulo gulo'
country = 'USA'
state = None
state = 'MT'
allowed = taxonomy_handler.species_allowed_in_country(taxon,country,state=state,return_status=False)
taxonomy_info = taxonomy_handler.species_string_to_taxonomy_info(taxon)
common_name = taxonomy_info['common_name']
Expand Down
Loading