Skip to content

Commit

Permalink
get_detection_dataset_dicts(names=)
Browse files Browse the repository at this point in the history
Summary: simplify argument name, otherwise `dataloader.train.datasets.dataset_names` is long and repetitive

Reviewed By: theschnitz

Differential Revision: D26667042

fbshipit-source-id: 92803ef87f4396513376f8a98d6787b0b424c10a
  • Loading branch information
ppwwyyxx authored and facebook-github-bot committed Feb 25, 2021
1 parent ab70550 commit 01a362f
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions detectron2/data/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,32 +206,30 @@ def short_name(x):
)


def get_detection_dataset_dicts(
dataset_names, filter_empty=True, min_keypoints=0, proposal_files=None
):
def get_detection_dataset_dicts(names, filter_empty=True, min_keypoints=0, proposal_files=None):
"""
Load and prepare dataset dicts for instance detection/segmentation and semantic segmentation.
Args:
dataset_names (str or list[str]): a dataset name or a list of dataset names
names (str or list[str]): a dataset name or a list of dataset names
filter_empty (bool): whether to filter out images without instance annotations
min_keypoints (int): filter out images with fewer keypoints than
`min_keypoints`. Set to 0 to do nothing.
proposal_files (list[str]): if given, a list of object proposal files
that match each dataset in `dataset_names`.
that match each dataset in `names`.
Returns:
list[dict]: a list of dicts following the standard dataset dict format.
"""
if isinstance(dataset_names, str):
dataset_names = [dataset_names]
assert len(dataset_names)
dataset_dicts = [DatasetCatalog.get(dataset_name) for dataset_name in dataset_names]
for dataset_name, dicts in zip(dataset_names, dataset_dicts):
if isinstance(names, str):
names = [names]
assert len(names), names
dataset_dicts = [DatasetCatalog.get(dataset_name) for dataset_name in names]
for dataset_name, dicts in zip(names, dataset_dicts):
assert len(dicts), "Dataset '{}' is empty!".format(dataset_name)

if proposal_files is not None:
assert len(dataset_names) == len(proposal_files)
assert len(names) == len(proposal_files)
# load precomputed proposals from proposal files
dataset_dicts = [
load_proposals_into_dataset(dataset_i_dicts, proposal_file)
Expand All @@ -248,13 +246,13 @@ def get_detection_dataset_dicts(

if has_instances:
try:
class_names = MetadataCatalog.get(dataset_names[0]).thing_classes
check_metadata_consistency("thing_classes", dataset_names)
class_names = MetadataCatalog.get(names[0]).thing_classes
check_metadata_consistency("thing_classes", names)
print_instances_class_histogram(dataset_dicts, class_names)
except AttributeError: # class names are not available for this dataset
pass

assert len(dataset_dicts), "No valid data found in {}.".format(",".join(dataset_names))
assert len(dataset_dicts), "No valid data found in {}.".format(",".join(names))
return dataset_dicts


Expand Down

0 comments on commit 01a362f

Please sign in to comment.