-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Add FlyingChairs dataset for optical flow #4860
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
Changes from all commits
f5df5fc
c3dd41b
8c76602
e6ecc4e
721b94b
b59a5c7
e03f37f
6f95da0
3b8ba30
d725627
d729264
de49c75
53283c2
cd5237f
4d81e22
e32448d
80badf2
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 |
---|---|---|
|
@@ -8,12 +8,14 @@ | |
from PIL import Image | ||
|
||
from ..io.image import _read_png_16 | ||
from .utils import verify_str_arg | ||
from .vision import VisionDataset | ||
|
||
|
||
__all__ = ( | ||
"KittiFlow", | ||
"Sintel", | ||
"FlyingChairs", | ||
) | ||
|
||
|
||
|
@@ -109,11 +111,8 @@ class Sintel(FlowDataset): | |
def __init__(self, root, split="train", pass_name="clean", transforms=None): | ||
super().__init__(root=root, transforms=transforms) | ||
|
||
if split not in ("train", "test"): | ||
raise ValueError("split must be either 'train' or 'test'") | ||
|
||
if pass_name not in ("clean", "final"): | ||
raise ValueError("pass_name must be either 'clean' or 'final'") | ||
verify_str_arg(split, "split", valid_values=("train", "test")) | ||
verify_str_arg(pass_name, "pass_name", valid_values=("clean", "final")) | ||
|
||
root = Path(root) / "Sintel" | ||
|
||
|
@@ -171,8 +170,7 @@ class KittiFlow(FlowDataset): | |
def __init__(self, root, split="train", transforms=None): | ||
super().__init__(root=root, transforms=transforms) | ||
|
||
if split not in ("train", "test"): | ||
raise ValueError("split must be either 'train' or 'test'") | ||
verify_str_arg(split, "split", valid_values=("train", "test")) | ||
|
||
root = Path(root) / "Kitti" / (split + "ing") | ||
images1 = sorted(glob(str(root / "image_2" / "*_10.png"))) | ||
|
@@ -208,6 +206,71 @@ def _read_flow(self, file_name): | |
return _read_16bits_png_with_flow_and_valid_mask(file_name) | ||
|
||
|
||
class FlyingChairs(FlowDataset): | ||
"""`FlyingChairs <https://lmb.informatik.uni-freiburg.de/resources/datasets/FlyingChairs.en.html#flyingchairs>`_ Dataset for optical flow. | ||
You will also need to download the FlyingChairs_train_val.txt file from the dataset page. | ||
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. Is not providing download functionality for these datasets intentional? 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. For this one specifically and for Sintel, I think we could provide download functionalities. I'm just leaving this for another potential PR For the others it's not as easy because e.g. FlyingThings3D can only be downloaded via bittorrent, and for Kitti one need to register on the website first (in theory...). |
||
The dataset is expected to have the following structure: :: | ||
root | ||
FlyingChairs | ||
data | ||
00001_flow.flo | ||
00001_img1.ppm | ||
00001_img2.ppm | ||
... | ||
FlyingChairs_train_val.txt | ||
Args: | ||
root (string): Root directory of the FlyingChairs Dataset. | ||
split (string, optional): The dataset split, either "train" (default) or "val" | ||
transforms (callable, optional): A function/transform that takes in | ||
``img1, img2, flow, valid`` and returns a transformed version. | ||
``valid`` is expected for consistency with other datasets which | ||
return a built-in valid mask, such as :class:`~torchvision.datasets.KittiFlow`. | ||
""" | ||
|
||
def __init__(self, root, split="train", transforms=None): | ||
super().__init__(root=root, transforms=transforms) | ||
|
||
verify_str_arg(split, "split", valid_values=("train", "val")) | ||
|
||
root = Path(root) / "FlyingChairs" | ||
images = sorted(glob(str(root / "data" / "*.ppm"))) | ||
flows = sorted(glob(str(root / "data" / "*.flo"))) | ||
|
||
split_file_name = "FlyingChairs_train_val.txt" | ||
|
||
if not os.path.exists(root / split_file_name): | ||
raise FileNotFoundError( | ||
"The FlyingChairs_train_val.txt file was not found - please download it from the dataset page (see docstring)." | ||
) | ||
|
||
split_list = np.loadtxt(str(root / split_file_name), dtype=np.int32) | ||
for i in range(len(flows)): | ||
split_id = split_list[i] | ||
if (split == "train" and split_id == 1) or (split == "val" and split_id == 2): | ||
self._flow_list += [flows[i]] | ||
self._image_list += [[images[2 * i], images[2 * i + 1]]] | ||
|
||
def __getitem__(self, index): | ||
"""Return example at given index. | ||
Args: | ||
index(int): The index of the example to retrieve | ||
Returns: | ||
tuple: A 3-tuple with ``(img1, img2, flow)``. | ||
The flow is a numpy array of shape (2, H, W) and the images are PIL images. | ||
""" | ||
return super().__getitem__(index) | ||
|
||
def _read_flow(self, file_name): | ||
return _read_flo(file_name) | ||
|
||
|
||
def _read_flo(file_name): | ||
"""Read .flo file in Middlebury format""" | ||
# Code adapted from: | ||
|
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.
Instead of passing this information through class variables,
inject_fake_data
can also return a dictionary. If you returndict(num_examples=..., flow_shape=...)
there, you can access it here with