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

fix splitting CelebA dataset + corresponding test #4377

Merged
merged 7 commits into from
Sep 8, 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
13 changes: 12 additions & 1 deletion test/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def inject_fake_data(self, tmpdir, config):
return dict(num_examples=num_images_per_split[config["split"]], attr_names=attr_names)

def _create_split_txt(self, root):
num_images_per_split = dict(train=3, valid=2, test=1)
num_images_per_split = dict(train=4, valid=3, test=2)

data = [
[self._SPLIT_TO_IDX[split]] for split, num_images in num_images_per_split.items() for _ in range(num_images)
Expand Down Expand Up @@ -595,6 +595,17 @@ def test_attr_names(self):
with self.create_dataset() as (dataset, info):
assert tuple(dataset.attr_names) == info["attr_names"]

def test_images_names_split(self):
with self.create_dataset(split='all') as (dataset, _):
all_imgs_names = set(dataset.filename)

merged_imgs_names = set()
for split in ["train", "valid", "test"]:
with self.create_dataset(split=split) as (dataset, _):
merged_imgs_names.update(dataset.filename)

assert merged_imgs_names == all_imgs_names


class VOCSegmentationTestCase(datasets_utils.ImageDatasetTestCase):
DATASET_CLASS = datasets.VOCSegmentation
Expand Down
5 changes: 4 additions & 1 deletion torchvision/datasets/celeba.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ def __init__(

mask = slice(None) if split_ is None else (splits.data == split_).squeeze()

self.filename = splits.index
if mask == slice(None): # if split == "all"
self.filename = splits.index
else:
self.filename = [splits.index[i] for i in torch.squeeze(torch.nonzero(mask))]
self.identity = identity.data[mask]
self.bbox = bbox.data[mask]
self.landmarks_align = landmarks_align.data[mask]
Expand Down