From 5654d807f559e88fcfdff62ff16cc67b961daf66 Mon Sep 17 00:00:00 2001 From: Zhipeng Xue <543984341@qq.com> Date: Sat, 13 Jul 2024 18:12:12 +0800 Subject: [PATCH 1/4] Fix Type hint --- rastervision_core/rastervision/core/data/utils/misc.py | 4 ++-- .../rastervision/pytorch_learner/learner.py | 2 +- .../rastervision/pytorch_learner/learner_config.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rastervision_core/rastervision/core/data/utils/misc.py b/rastervision_core/rastervision/core/data/utils/misc.py index a26328d32..900517109 100644 --- a/rastervision_core/rastervision/core/data/utils/misc.py +++ b/rastervision_core/rastervision/core/data/utils/misc.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Any, Sequence +from typing import TYPE_CHECKING, Any, Sequence, Union import logging import numpy as np @@ -14,7 +14,7 @@ def color_to_triple( - color: str | Sequence | None = None) -> tuple[int, int, int]: + color: str | Sequence | None = None) -> Union[list, tuple[int, int, int]]: """Given a PIL ImageColor string, return a triple of integers representing the red, green, and blue values. diff --git a/rastervision_pytorch_learner/rastervision/pytorch_learner/learner.py b/rastervision_pytorch_learner/rastervision/pytorch_learner/learner.py index f9762f83b..cb39cf178 100644 --- a/rastervision_pytorch_learner/rastervision/pytorch_learner/learner.py +++ b/rastervision_pytorch_learner/rastervision/pytorch_learner/learner.py @@ -1182,7 +1182,7 @@ def build_dataset(self, return ds def build_dataloaders(self, distributed: bool | None = None - ) -> tuple[DataLoader, DataLoader, DataLoader]: + ) -> tuple[DataLoader, DataLoader, DataLoader | None]: """Build DataLoaders for train, validation, and test splits.""" if distributed is None: distributed = self.distributed diff --git a/rastervision_pytorch_learner/rastervision/pytorch_learner/learner_config.py b/rastervision_pytorch_learner/rastervision/pytorch_learner/learner_config.py index c9326ad1e..e2575c810 100644 --- a/rastervision_pytorch_learner/rastervision/pytorch_learner/learner_config.py +++ b/rastervision_pytorch_learner/rastervision/pytorch_learner/learner_config.py @@ -680,7 +680,7 @@ def num_classes(self): @field_validator('augmentors') @classmethod - def validate_augmentors(cls, v: list[str]) -> str: + def validate_augmentors(cls, v: list[str]) -> list[str]: for aug_name in v: if aug_name not in augmentors: raise ConfigError(f'Unsupported augmentor "{aug_name}"') @@ -863,7 +863,7 @@ def validate_group_uris(self) -> Self: def _build_dataset(self, dirs: Iterable[str], tf: A.BasicTransform | None = None - ) -> tuple[Dataset, Dataset, Dataset]: + ) -> Dataset: """Make datasets for a single split. Args: @@ -1224,7 +1224,7 @@ def _build_dataset(self, split: Literal['train', 'valid', 'test'], tf: A.BasicTransform | None = None, tmp_dir: str | None = None, - **kwargs) -> tuple[Dataset, Dataset, Dataset]: + **kwargs) -> Dataset: """Make training, validation, and test datasets. Args: From 35c0b0483ea28f6959b9aad329888bc0e85fa1bf Mon Sep 17 00:00:00 2001 From: Zhipeng Xue <543984341@qq.com> Date: Tue, 16 Jul 2024 14:21:29 +0800 Subject: [PATCH 2/4] fix type hint --- rastervision_core/rastervision/core/data/utils/misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rastervision_core/rastervision/core/data/utils/misc.py b/rastervision_core/rastervision/core/data/utils/misc.py index 900517109..1621fb785 100644 --- a/rastervision_core/rastervision/core/data/utils/misc.py +++ b/rastervision_core/rastervision/core/data/utils/misc.py @@ -14,7 +14,7 @@ def color_to_triple( - color: str | Sequence | None = None) -> Union[list, tuple[int, int, int]]: + color: str | Sequence | None = None) -> list[str] | tuple[int, int, int]: """Given a PIL ImageColor string, return a triple of integers representing the red, green, and blue values. From 790d2f7d8d7e9b62e48a6bb39377661fd7e2ead1 Mon Sep 17 00:00:00 2001 From: Zhipeng Xue <543984341@qq.com> Date: Tue, 16 Jul 2024 23:19:13 +0800 Subject: [PATCH 3/4] Remove Union --- rastervision_core/rastervision/core/data/utils/misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rastervision_core/rastervision/core/data/utils/misc.py b/rastervision_core/rastervision/core/data/utils/misc.py index 1621fb785..d5974e0db 100644 --- a/rastervision_core/rastervision/core/data/utils/misc.py +++ b/rastervision_core/rastervision/core/data/utils/misc.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Any, Sequence, Union +from typing import TYPE_CHECKING, Any, Sequence import logging import numpy as np From e9e98c46a29c153f3f5300bb28dd5b9e3765928e Mon Sep 17 00:00:00 2001 From: zhipengxue97 <543984341@qq.com> Date: Wed, 17 Jul 2024 02:08:25 +0000 Subject: [PATCH 4/4] format code --- rastervision_core/rastervision/core/data/utils/misc.py | 4 ++-- .../rastervision/pytorch_learner/learner.py | 5 +++-- .../rastervision/pytorch_learner/learner_config.py | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rastervision_core/rastervision/core/data/utils/misc.py b/rastervision_core/rastervision/core/data/utils/misc.py index d5974e0db..914d18633 100644 --- a/rastervision_core/rastervision/core/data/utils/misc.py +++ b/rastervision_core/rastervision/core/data/utils/misc.py @@ -13,8 +13,8 @@ log = logging.getLogger(__name__) -def color_to_triple( - color: str | Sequence | None = None) -> list[str] | tuple[int, int, int]: +def color_to_triple(color: str | Sequence | None = None + ) -> list[str] | tuple[int, int, int]: """Given a PIL ImageColor string, return a triple of integers representing the red, green, and blue values. diff --git a/rastervision_pytorch_learner/rastervision/pytorch_learner/learner.py b/rastervision_pytorch_learner/rastervision/pytorch_learner/learner.py index cb39cf178..ce370a92c 100644 --- a/rastervision_pytorch_learner/rastervision/pytorch_learner/learner.py +++ b/rastervision_pytorch_learner/rastervision/pytorch_learner/learner.py @@ -1181,8 +1181,9 @@ def build_dataset(self, ds = self.cfg.data.build_dataset(split=split, tmp_dir=self.tmp_dir) return ds - def build_dataloaders(self, distributed: bool | None = None - ) -> tuple[DataLoader, DataLoader, DataLoader | None]: + def build_dataloaders( + self, distributed: bool | None = None + ) -> tuple[DataLoader, DataLoader, DataLoader | None]: """Build DataLoaders for train, validation, and test splits.""" if distributed is None: distributed = self.distributed diff --git a/rastervision_pytorch_learner/rastervision/pytorch_learner/learner_config.py b/rastervision_pytorch_learner/rastervision/pytorch_learner/learner_config.py index e2575c810..1ed445586 100644 --- a/rastervision_pytorch_learner/rastervision/pytorch_learner/learner_config.py +++ b/rastervision_pytorch_learner/rastervision/pytorch_learner/learner_config.py @@ -862,8 +862,7 @@ def validate_group_uris(self) -> Self: def _build_dataset(self, dirs: Iterable[str], - tf: A.BasicTransform | None = None - ) -> Dataset: + tf: A.BasicTransform | None = None) -> Dataset: """Make datasets for a single split. Args: