Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open Images download hotfix #1151

Merged
merged 6 commits into from
Jul 31, 2021
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
81 changes: 45 additions & 36 deletions fiftyone/utils/openimages.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ def setup(self):
attrs=attrs,
oi_attrs=oi_attrs,
seg_classes=seg_classes,
track_all_ids=max_samples is not None,
ids_only=False,
track_all_ids=max_samples is not None,
only_matching=self.only_matching,
download=False,
)
Expand Down Expand Up @@ -592,7 +592,7 @@ def _setup(
download=False,
):
did_download = False
label_types = _parse_label_types(label_types)
_label_types = _parse_label_types(label_types)

if etau.is_str(classes):
classes = [classes]
Expand Down Expand Up @@ -633,7 +633,7 @@ def _setup(
else:
oi_classes = None

if "relationships" in label_types:
if "relationships" in _label_types:
# Map of attribute IDs to attribute names
attrs_map, _did_download = _get_attrs_map(
dataset_dir, download=download
Expand Down Expand Up @@ -670,7 +670,7 @@ def _setup(
oi_attrs = None
all_attrs = None

if "segmentations" in label_types:
if "segmentations" in _label_types:
seg_classes, _did_download = _get_seg_classes(
dataset_dir, classes_map=classes_map, download=download
)
Expand Down Expand Up @@ -961,8 +961,9 @@ def _get_all_label_data(
attrs=None,
oi_attrs=None,
seg_classes=None,
track_all_ids=True,
download_only=False,
ids_only=False,
track_all_ids=True,
only_matching=False,
split=None,
download=False,
Expand Down Expand Up @@ -994,8 +995,9 @@ def _get_all_label_data(
"classifications",
classes=classes,
oi_classes=oi_classes,
track_all_ids=track_all_ids,
download_only=download_only,
ids_only=ids_only,
track_all_ids=track_all_ids,
only_matching=only_matching,
url=url,
download=download,
Expand All @@ -1022,8 +1024,9 @@ def _get_all_label_data(
oi_classes=oi_classes,
url=url,
download=download,
track_all_ids=track_all_ids,
download_only=download_only,
ids_only=ids_only,
track_all_ids=track_all_ids,
only_matching=only_matching,
)
did_download |= _did_download
Expand All @@ -1043,8 +1046,9 @@ def _get_all_label_data(
"relationships",
classes=attrs,
oi_classes=oi_attrs,
track_all_ids=track_all_ids,
download_only=download_only,
ids_only=ids_only,
track_all_ids=track_all_ids,
only_matching=only_matching,
url=url,
download=download,
Expand Down Expand Up @@ -1076,8 +1080,9 @@ def _get_all_label_data(
"segmentations",
classes=classes,
oi_classes=oi_classes,
track_all_ids=track_all_ids,
download_only=download_only,
ids_only=ids_only,
track_all_ids=track_all_ids,
only_matching=only_matching,
url=url,
download=download,
Expand Down Expand Up @@ -1118,8 +1123,9 @@ def _get_label_data(
label_type,
classes=None,
oi_classes=None,
track_all_ids=True,
download_only=False,
ids_only=False,
track_all_ids=True,
only_matching=False,
url=None,
download=True,
Expand All @@ -1129,6 +1135,9 @@ def _get_label_data(
csv_path, url, quiet=0, download=download
)

if download_only:
return set(), set(), {}, did_download

df = _parse_csv(csv_path, dataframe=True)
df.set_index("ImageID", drop=False, inplace=True)
df = df.loc[df.index.intersection(image_ids)]
Expand Down Expand Up @@ -1204,36 +1213,36 @@ def _download(
num_workers=None,
download=True,
):
did_download = False
# Download any necessary labels, and, if specific classes/attributes are
# requested, determine which image IDs have the specified labels
(
_,
_,
_,
_,
all_label_ids,
any_label_ids,
did_download,
) = _get_all_label_data(
dataset_dir,
image_ids,
label_types=label_types,
classes=classes,
oi_classes=oi_classes,
attrs=attrs,
oi_attrs=oi_attrs,
seg_classes=seg_classes,
download_only=classes is None and attrs is None,
ids_only=True,
track_all_ids=max_samples is not None,
split=split,
download=download,
)

downloaded_ids = set(downloaded_ids)

# Make list of `target_ids`
if classes is not None or attrs is not None:
# Determine which samples have specified classes/attributes
(
_,
_,
_,
_,
all_label_ids,
any_label_ids,
_did_download,
) = _get_all_label_data(
dataset_dir,
image_ids,
label_types=label_types,
classes=classes,
oi_classes=oi_classes,
attrs=attrs,
oi_attrs=oi_attrs,
seg_classes=seg_classes,
track_all_ids=max_samples is not None,
ids_only=True,
split=split,
download=download,
)
did_download |= _did_download

if max_samples is not None:
#
# Bias sampling to meet user requirements per the priorities below:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def finalize_options(self):
]


VERSION = "0.11.2"
VERSION = "0.11.2.1"


def get_version():
Expand Down
60 changes: 30 additions & 30 deletions tests/intensive/dataset_zoo_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,36 +210,6 @@ def test_coco_2017():


def test_open_images_v6():
dataset = foz.load_zoo_dataset(
"open-images-v6", split="validation", max_samples=5,
)
schema = dataset.get_field_schema()

assert "positive_labels" in schema
assert "negative_labels" in schema
assert "detections" in schema
assert "relationships" in schema
assert "segmentations" in schema
assert "open_images_id" in schema
assert len(dataset) == 5
assert len(dataset.match_tags("validation")) == 5
dataset.delete()

dataset = foz.load_zoo_dataset(
"open-images-v6", split="validation", max_samples=5, label_field="gt",
)
schema = dataset.get_field_schema()

assert "gt_positive_labels" in schema
assert "gt_negative_labels" in schema
assert "gt_detections" in schema
assert "gt_relationships" in schema
assert "gt_segmentations" in schema
assert "gt_open_images_id" in schema
assert len(dataset) == 5
assert len(dataset.match_tags("validation")) == 5
dataset.delete()

dataset = foz.load_zoo_dataset(
"open-images-v6",
split="validation",
Expand Down Expand Up @@ -302,6 +272,36 @@ def test_open_images_v6():
assert "open_images_id" not in schema
dataset.delete()

dataset = foz.load_zoo_dataset(
"open-images-v6", split="validation", max_samples=5,
)
schema = dataset.get_field_schema()

assert "positive_labels" in schema
assert "negative_labels" in schema
assert "detections" in schema
assert "relationships" in schema
assert "segmentations" in schema
assert "open_images_id" in schema
assert len(dataset) == 5
assert len(dataset.match_tags("validation")) == 5
dataset.delete()

dataset = foz.load_zoo_dataset(
"open-images-v6", split="validation", max_samples=5, label_field="gt",
)
schema = dataset.get_field_schema()

assert "gt_positive_labels" in schema
assert "gt_negative_labels" in schema
assert "gt_detections" in schema
assert "gt_relationships" in schema
assert "gt_segmentations" in schema
assert "gt_open_images_id" in schema
assert len(dataset) == 5
assert len(dataset.match_tags("validation")) == 5
dataset.delete()

dataset = foz.load_zoo_dataset(
"open-images-v6",
split="validation",
Expand Down