From ccb388087223c5adb1ca2daf0291368ab2b4866c Mon Sep 17 00:00:00 2001 From: dengkaipeng Date: Mon, 27 Apr 2020 06:14:40 +0000 Subject: [PATCH] add Compose doc --- hapi/datasets/flowers.py | 2 +- hapi/datasets/mnist.py | 2 +- hapi/vision/transforms/transforms.py | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/hapi/datasets/flowers.py b/hapi/datasets/flowers.py index 1f4f707..aaae610 100644 --- a/hapi/datasets/flowers.py +++ b/hapi/datasets/flowers.py @@ -121,7 +121,7 @@ class Flowers(Dataset): image = np.array(Image.open(io.BytesIO(image))) if self.transform is not None: - image, label = self.transform(image, label) + image = self.transform(image) return image, label diff --git a/hapi/datasets/mnist.py b/hapi/datasets/mnist.py index 18c6290..e45aea7 100644 --- a/hapi/datasets/mnist.py +++ b/hapi/datasets/mnist.py @@ -149,7 +149,7 @@ class MNIST(Dataset): def __getitem__(self, idx): image, label = self.images[idx], self.labels[idx] if self.transform is not None: - image, label = self.transform(image, label) + image = self.transform(image) return image, label def __len__(self): diff --git a/hapi/vision/transforms/transforms.py b/hapi/vision/transforms/transforms.py index 14bcd00..90b43b8 100644 --- a/hapi/vision/transforms/transforms.py +++ b/hapi/vision/transforms/transforms.py @@ -61,6 +61,24 @@ class Compose(object): Args: transforms (list of ``Transform`` objects): list of transforms to compose. + Returns: + A compose object which is callable, __call__ for this Compose + object will call each given :attr:`transforms` sequencely. + + Examples: + + .. code-block:: python + + from hapi.datasets import Flowers + from hapi.vision.transforms import Compose, ColorJitter, Resize + + transform = Compose([ColorJitter(), Resize(size=608)]) + flowers = Flowers(mode='test', transform=transform) + + for i in range(10): + sample = flowers[i] + print(sample[0].shape, sample[1]) + """ def __init__(self, transforms): -- GitLab