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

[Type Hints] datasets.WILLOWObjectClass, PascalVOCKeypoints and PascalPF #5781

Merged
merged 3 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
autofixes
  • Loading branch information
wwymak committed Oct 19, 2022
commit 04061f0799013035bcc9d7747497f55b9d13762e
15 changes: 9 additions & 6 deletions torch_geometric/datasets/pascal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os.path as osp
import shutil
from itertools import chain
from typing import Callable, List, Optional
from xml.dom import minidom

import numpy as np
Expand Down Expand Up @@ -70,28 +71,30 @@ class PascalVOCKeypoints(InMemoryDataset):
device = 'cuda' if torch.cuda.is_available() else 'cpu'
batch_size = 32

def __init__(self, root, category, train=True, transform=None,
pre_transform=None, pre_filter=None):
def __init__(self, root: str, category: str, train: bool = True,
transform: Optional[Callable] = None,
pre_transform: Optional[Callable] = None,
pre_filter: Optional[Callable] = None):
self.category = category.lower()
assert self.category in self.categories
super().__init__(root, transform, pre_transform, pre_filter)
path = self.processed_paths[0] if train else self.processed_paths[1]
self.data, self.slices = torch.load(path)

@property
def raw_dir(self):
def raw_dir(self) -> str:
return osp.join(self.root, 'raw')

@property
def processed_dir(self):
def processed_dir(self) -> str:
return osp.join(self.root, self.category.capitalize(), 'processed')

@property
def raw_file_names(self):
def raw_file_names(self) -> List[str]:
return ['images', 'annotations', 'splits.npz']

@property
def processed_file_names(self):
def processed_file_names(self) -> List[str]:
return ['training.pt', 'test.pt']

def download(self):
Expand Down
15 changes: 11 additions & 4 deletions torch_geometric/datasets/pascal_pf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import os.path as osp
import shutil
from typing import Callable, List, Optional

import torch

Expand Down Expand Up @@ -49,20 +50,26 @@ class PascalPF(InMemoryDataset):
'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'
]

def __init__(self, root, category, transform=None, pre_transform=None,
pre_filter=None):
def __init__(
self,
root: str,
category: str,
transform: Optional[Callable] = None,
pre_transform: Optional[Callable] = None,
pre_filter: Optional[Callable] = None,
):
self.category = category.lower()
assert self.category in self.categories
super().__init__(root, transform, pre_transform, pre_filter)
self.data, self.slices = torch.load(self.processed_paths[0])
self.pairs = torch.load(self.processed_paths[1])

@property
def raw_file_names(self):
def raw_file_names(self) -> List[str]:
return ['Annotations', 'parsePascalVOC.mat']

@property
def processed_file_names(self):
def processed_file_names(self) -> List[str]:
return [f'{self.category}.pt', f'{self.category}_pairs.pt']

def download(self):
Expand Down
19 changes: 13 additions & 6 deletions torch_geometric/datasets/willow_object_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import os.path as osp
import shutil
from typing import Callable, List, Optional

import torch
import torch.nn.functional as F
Expand Down Expand Up @@ -48,27 +49,33 @@ class WILLOWObjectClass(InMemoryDataset):
device = 'cuda' if torch.cuda.is_available() else 'cpu'
batch_size = 32

def __init__(self, root, category, transform=None, pre_transform=None,
pre_filter=None):
def __init__(
self,
root: str,
category: str,
transform: Optional[Callable] = None,
pre_transform: Optional[Callable] = None,
pre_filter: Optional[Callable] = None,
):
assert category.lower() in self.categories
self.category = category
super().__init__(root, transform, pre_transform, pre_filter)
self.data, self.slices = torch.load(self.processed_paths[0])

@property
def raw_dir(self):
def raw_dir(self) -> str:
return osp.join(self.root, 'raw')

@property
def processed_dir(self):
def processed_dir(self) -> str:
return osp.join(self.root, self.category.capitalize(), 'processed')

@property
def raw_file_names(self):
def raw_file_names(self) -> List[str]:
return [category.capitalize() for category in self.categories]

@property
def processed_file_names(self):
def processed_file_names(self) -> str:
return 'data.pt'

def download(self):
Expand Down