-
Notifications
You must be signed in to change notification settings - Fork 7k
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
enforce pickleability for v2 transforms and wrapped datasets #7860
Changes from all commits
60110cb
c68a6de
d228bdb
1efe583
5358620
af66bd0
f339e6c
1e35ee7
edc043e
d256c3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,14 +183,18 @@ def test_combined_targets(self): | |
), "Type of the combined target does not match the type of the corresponding individual target: " | ||
f"{actual} is not {expected}", | ||
|
||
def test_transforms_v2_wrapper_spawn(self): | ||
with self.create_dataset(target_type="category") as (dataset, _): | ||
datasets_utils.check_transforms_v2_wrapper_spawn(dataset) | ||
|
||
|
||
class Caltech256TestCase(datasets_utils.ImageDatasetTestCase): | ||
DATASET_CLASS = datasets.Caltech256 | ||
|
||
def inject_fake_data(self, tmpdir, config): | ||
tmpdir = pathlib.Path(tmpdir) / "caltech256" / "256_ObjectCategories" | ||
|
||
categories = ((1, "ak47"), (127, "laptop-101"), (257, "clutter")) | ||
categories = ((1, "ak47"), (2, "american-flag"), (3, "backpack")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Option 3. is by far the least amount of work, so I went for that here. |
||
num_images_per_category = 2 | ||
|
||
for idx, category in categories: | ||
|
@@ -258,6 +262,10 @@ def inject_fake_data(self, tmpdir, config): | |
|
||
return split_to_num_examples[config["split"]] | ||
|
||
def test_transforms_v2_wrapper_spawn(self): | ||
with self.create_dataset() as (dataset, _): | ||
datasets_utils.check_transforms_v2_wrapper_spawn(dataset) | ||
|
||
|
||
class CityScapesTestCase(datasets_utils.ImageDatasetTestCase): | ||
DATASET_CLASS = datasets.Cityscapes | ||
|
@@ -382,6 +390,11 @@ def test_feature_types_target_polygon(self): | |
assert isinstance(polygon_img, PIL.Image.Image) | ||
(polygon_target, info["expected_polygon_target"]) | ||
|
||
def test_transforms_v2_wrapper_spawn(self): | ||
for target_type in ["instance", "semantic", ["instance", "semantic"]]: | ||
with self.create_dataset(target_type=target_type) as (dataset, _): | ||
datasets_utils.check_transforms_v2_wrapper_spawn(dataset) | ||
|
||
|
||
class ImageNetTestCase(datasets_utils.ImageDatasetTestCase): | ||
DATASET_CLASS = datasets.ImageNet | ||
|
@@ -413,6 +426,10 @@ def inject_fake_data(self, tmpdir, config): | |
torch.save((wnid_to_classes, None), tmpdir / "meta.bin") | ||
return num_examples | ||
|
||
def test_transforms_v2_wrapper_spawn(self): | ||
with self.create_dataset() as (dataset, _): | ||
datasets_utils.check_transforms_v2_wrapper_spawn(dataset) | ||
|
||
|
||
class CIFAR10TestCase(datasets_utils.ImageDatasetTestCase): | ||
DATASET_CLASS = datasets.CIFAR10 | ||
|
@@ -607,6 +624,11 @@ def test_images_names_split(self): | |
|
||
assert merged_imgs_names == all_imgs_names | ||
|
||
def test_transforms_v2_wrapper_spawn(self): | ||
for target_type in ["identity", "bbox", ["identity", "bbox"]]: | ||
with self.create_dataset(target_type=target_type) as (dataset, _): | ||
datasets_utils.check_transforms_v2_wrapper_spawn(dataset) | ||
|
||
|
||
class VOCSegmentationTestCase(datasets_utils.ImageDatasetTestCase): | ||
DATASET_CLASS = datasets.VOCSegmentation | ||
|
@@ -694,6 +716,10 @@ def add_bndbox(obj, bndbox=None): | |
|
||
return data | ||
|
||
def test_transforms_v2_wrapper_spawn(self): | ||
with self.create_dataset() as (dataset, _): | ||
datasets_utils.check_transforms_v2_wrapper_spawn(dataset) | ||
|
||
|
||
class VOCDetectionTestCase(VOCSegmentationTestCase): | ||
DATASET_CLASS = datasets.VOCDetection | ||
|
@@ -714,6 +740,10 @@ def test_annotations(self): | |
|
||
assert object == info["annotation"] | ||
|
||
def test_transforms_v2_wrapper_spawn(self): | ||
with self.create_dataset() as (dataset, _): | ||
datasets_utils.check_transforms_v2_wrapper_spawn(dataset) | ||
|
||
|
||
class CocoDetectionTestCase(datasets_utils.ImageDatasetTestCase): | ||
DATASET_CLASS = datasets.CocoDetection | ||
|
@@ -784,6 +814,10 @@ def _create_json(self, root, name, content): | |
json.dump(content, fh) | ||
return file | ||
|
||
def test_transforms_v2_wrapper_spawn(self): | ||
with self.create_dataset() as (dataset, _): | ||
datasets_utils.check_transforms_v2_wrapper_spawn(dataset) | ||
|
||
|
||
class CocoCaptionsTestCase(CocoDetectionTestCase): | ||
DATASET_CLASS = datasets.CocoCaptions | ||
|
@@ -800,6 +834,11 @@ def test_captions(self): | |
_, captions = dataset[0] | ||
assert tuple(captions) == tuple(info["captions"]) | ||
|
||
def test_transforms_v2_wrapper_spawn(self): | ||
# We need to define this method, because otherwise the test from the super class will | ||
# be run | ||
pytest.skip("CocoCaptions is currently not supported by the v2 wrapper.") | ||
|
||
|
||
class UCF101TestCase(datasets_utils.VideoDatasetTestCase): | ||
DATASET_CLASS = datasets.UCF101 | ||
|
@@ -966,6 +1005,10 @@ def inject_fake_data(self, tmpdir, config): | |
) | ||
return num_videos_per_class * len(classes) | ||
|
||
def test_transforms_v2_wrapper_spawn(self): | ||
with self.create_dataset(output_format="TCHW") as (dataset, _): | ||
datasets_utils.check_transforms_v2_wrapper_spawn(dataset) | ||
|
||
|
||
class HMDB51TestCase(datasets_utils.VideoDatasetTestCase): | ||
DATASET_CLASS = datasets.HMDB51 | ||
|
@@ -1193,6 +1236,10 @@ def _create_segmentation(self, size): | |
def _file_stem(self, idx): | ||
return f"2008_{idx:06d}" | ||
|
||
def test_transforms_v2_wrapper_spawn(self): | ||
with self.create_dataset(mode="segmentation") as (dataset, _): | ||
datasets_utils.check_transforms_v2_wrapper_spawn(dataset) | ||
|
||
|
||
class FakeDataTestCase(datasets_utils.ImageDatasetTestCase): | ||
DATASET_CLASS = datasets.FakeData | ||
|
@@ -1642,6 +1689,10 @@ def inject_fake_data(self, tmpdir, config): | |
|
||
return split_to_num_examples[config["train"]] | ||
|
||
def test_transforms_v2_wrapper_spawn(self): | ||
with self.create_dataset() as (dataset, _): | ||
datasets_utils.check_transforms_v2_wrapper_spawn(dataset) | ||
|
||
|
||
class SvhnTestCase(datasets_utils.ImageDatasetTestCase): | ||
DATASET_CLASS = datasets.SVHN | ||
|
@@ -2516,6 +2567,10 @@ def _meta_to_split_and_classification_ann(self, meta, idx): | |
breed_id = "-1" | ||
return (image_id, class_id, species, breed_id) | ||
|
||
def test_transforms_v2_wrapper_spawn(self): | ||
with self.create_dataset() as (dataset, _): | ||
datasets_utils.check_transforms_v2_wrapper_spawn(dataset) | ||
|
||
|
||
class StanfordCarsTestCase(datasets_utils.ImageDatasetTestCase): | ||
DATASET_CLASS = datasets.StanfordCars | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,13 +137,13 @@ def parse_train_val_annotations_file(self) -> None: | |
{ | ||
"img_path": img_path, | ||
"annotations": { | ||
"bbox": labels_tensor[:, 0:4], # x, y, width, height | ||
"blur": labels_tensor[:, 4], | ||
"expression": labels_tensor[:, 5], | ||
"illumination": labels_tensor[:, 6], | ||
"occlusion": labels_tensor[:, 7], | ||
"pose": labels_tensor[:, 8], | ||
"invalid": labels_tensor[:, 9], | ||
"bbox": labels_tensor[:, 0:4].clone(), # x, y, width, height | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Views on tensor cannot be pickled correctly. Meaning regardless of the v2 wrapper, |
||
"blur": labels_tensor[:, 4].clone(), | ||
"expression": labels_tensor[:, 5].clone(), | ||
"illumination": labels_tensor[:, 6].clone(), | ||
"occlusion": labels_tensor[:, 7].clone(), | ||
"pose": labels_tensor[:, 8].clone(), | ||
"invalid": labels_tensor[:, 9].clone(), | ||
}, | ||
} | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We never actually consumed the dataset before. Thus, any failures that happen not for the first sample are not detected. Fortunately, only one test was broken that I'll flag below.