2020-06-16 00:05:18 +08:00
|
|
|
import torch
|
2020-06-24 13:59:02 +08:00
|
|
|
from PIL import Image
|
2020-06-16 00:05:18 +08:00
|
|
|
|
|
|
|
from .registry import DATASETS
|
|
|
|
from .base import BaseDataset
|
|
|
|
|
|
|
|
|
|
|
|
def rotate(img):
|
|
|
|
'''
|
|
|
|
img: Tensor(CHW)
|
|
|
|
'''
|
|
|
|
return [
|
|
|
|
img,
|
|
|
|
torch.flip(img.transpose(1, 2), [1]),
|
|
|
|
torch.flip(img, [1, 2]),
|
|
|
|
torch.flip(img, [1]).transpose(1, 2)
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@DATASETS.register_module
|
|
|
|
class RotationPredDataset(BaseDataset):
|
|
|
|
"""Dataset for rotation prediction
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, data_source, pipeline):
|
|
|
|
super(RotationPredDataset, self).__init__(data_source, pipeline)
|
|
|
|
|
|
|
|
def __getitem__(self, idx):
|
2020-06-17 01:31:59 +08:00
|
|
|
img = self.data_source.get_sample(idx)
|
2020-06-24 11:24:21 +08:00
|
|
|
assert isinstance(img, Image.Image), \
|
|
|
|
'The output from the data source must be an Image, got: {}. \
|
|
|
|
Please ensure that the list file does not contain labels.'.format(
|
|
|
|
type(img))
|
2020-06-16 00:05:18 +08:00
|
|
|
img = self.pipeline(img)
|
|
|
|
img = torch.stack(rotate(img), dim=0)
|
|
|
|
rotation_labels = torch.LongTensor([0, 1, 2, 3])
|
|
|
|
return dict(img=img, rot_label=rotation_labels)
|
|
|
|
|
|
|
|
def evaluate(self, scores, keyword, logger=None):
|
|
|
|
raise NotImplemented
|