From 8a0c6662c864e7ba72d824d99e37d1a2083148e7 Mon Sep 17 00:00:00 2001 From: Adeel Hassan Date: Wed, 23 Aug 2023 09:54:35 -0400 Subject: [PATCH] misc doc and type hint fixes --- docs/usage/tutorials/pred_and_eval_ss.ipynb | 2 +- .../label/semantic_segmentation_labels.py | 41 ++++++++----------- .../pytorch_learner/learner_config.py | 12 +++--- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/docs/usage/tutorials/pred_and_eval_ss.ipynb b/docs/usage/tutorials/pred_and_eval_ss.ipynb index bd2d09e154..add1810a9c 100644 --- a/docs/usage/tutorials/pred_and_eval_ss.ipynb +++ b/docs/usage/tutorials/pred_and_eval_ss.ipynb @@ -43,7 +43,7 @@ }, "source": [ "Load a :class:`Learner` with a trained model from bundle -- :meth:`.Learner.from_model_bundle`\n", - "---------------------------------------------------------------------------------------------" + "----------------------------------------------------------------------------------------------" ] }, { diff --git a/rastervision_core/rastervision/core/data/label/semantic_segmentation_labels.py b/rastervision_core/rastervision/core/data/label/semantic_segmentation_labels.py index 8cdb1c4d39..d35c2bad04 100644 --- a/rastervision_core/rastervision/core/data/label/semantic_segmentation_labels.py +++ b/rastervision_core/rastervision/core/data/label/semantic_segmentation_labels.py @@ -1,5 +1,4 @@ -from typing import (TYPE_CHECKING, Any, Iterable, List, Optional, Sequence, - Union) +from typing import (TYPE_CHECKING, Any, Iterable, List, Optional, Sequence) from abc import abstractmethod import numpy as np @@ -23,8 +22,8 @@ def __init__(self, extent: Box, num_classes: int, dtype: np.dtype): """Constructor. Args: - extent (Box): The extent of the region to which - the labels belong, in global coordinates. + extent (Box): The extent of the region to which the labels belong, + in global coordinates. num_classes (int): Number of classes. """ self.extent = extent @@ -143,9 +142,8 @@ def transform_shape(x, y, z=None): del self[window] @classmethod - def make_empty(cls, extent: Box, num_classes: int, smooth: bool = False - ) -> Union['SemanticSegmentationDiscreteLabels', - 'SemanticSegmentationSmoothLabels']: + def make_empty(cls, extent: Box, num_classes: int, + smooth: bool = False) -> 'SemanticSegmentationLabels': """Instantiate an empty instance. Args: @@ -157,8 +155,7 @@ def make_empty(cls, extent: Box, num_classes: int, smooth: bool = False SemanticSegmentationDiscreteLabels object. Defaults to False. Returns: - Union[SemanticSegmentationDiscreteLabels, - SemanticSegmentationSmoothLabels]: If smooth=True, returns a + SemanticSegmentationLabels: If smooth=True, returns a SemanticSegmentationSmoothLabels. Otherwise, a SemanticSegmentationDiscreteLabels. @@ -174,15 +171,14 @@ def make_empty(cls, extent: Box, num_classes: int, smooth: bool = False extent=extent, num_classes=num_classes) @classmethod - def from_predictions(cls, - windows: Iterable['Box'], - predictions: Iterable[Any], - extent: Box, - num_classes: int, - smooth: bool = False, - crop_sz: Optional[int] = None - ) -> Union['SemanticSegmentationDiscreteLabels', - 'SemanticSegmentationSmoothLabels']: + def from_predictions( + cls, + windows: Iterable['Box'], + predictions: Iterable[Any], + extent: Box, + num_classes: int, + smooth: bool = False, + crop_sz: Optional[int] = None) -> 'SemanticSegmentationLabels': """Instantiate from windows and their corresponding predictions. Args: @@ -202,8 +198,7 @@ def from_predictions(cls, windows. Defaults to None. Returns: - Union[SemanticSegmentationDiscreteLabels, - SemanticSegmentationSmoothLabels]: If smooth=True, returns a + SemanticSegmentationLabels: If smooth=True, returns a SemanticSegmentationSmoothLabels. Otherwise, a SemanticSegmentationDiscreteLabels. """ @@ -349,8 +344,7 @@ def from_predictions(cls, extent: Box, num_classes: int, crop_sz: Optional[int] = None - ) -> Union['SemanticSegmentationDiscreteLabels', - 'SemanticSegmentationSmoothLabels']: + ) -> 'SemanticSegmentationDiscreteLabels': labels = cls.make_empty(extent, num_classes) labels.add_predictions(windows, predictions, crop_sz=crop_sz) return labels @@ -522,8 +516,7 @@ def from_predictions(cls, extent: Box, num_classes: int, crop_sz: Optional[int] = None - ) -> Union['SemanticSegmentationDiscreteLabels', - 'SemanticSegmentationSmoothLabels']: + ) -> 'SemanticSegmentationSmoothLabels': labels = cls.make_empty(extent, num_classes) labels.add_predictions(windows, predictions, crop_sz=crop_sz) return labels diff --git a/rastervision_pytorch_learner/rastervision/pytorch_learner/learner_config.py b/rastervision_pytorch_learner/rastervision/pytorch_learner/learner_config.py index 08a14aa60c..df0dc1eb31 100644 --- a/rastervision_pytorch_learner/rastervision/pytorch_learner/learner_config.py +++ b/rastervision_pytorch_learner/rastervision/pytorch_learner/learner_config.py @@ -1015,12 +1015,12 @@ def get_data_dirs(self, uri: Union[str, List[str]], Args: uri (Union[str, List[str]]): a URI or a list of URIs of one of the following: - (1) a URI of a directory containing "train", "valid", and - (optinally) "test" subdirectories - (2) a URI of a zip file containing (1) - (3) a list of (2) - (4) a URI of a directory containing zip files - containing (1) + + (1) a URI of a directory containing "train", "valid", and + (optinally) "test" subdirectories + (2) a URI of a zip file containing (1) + (3) a list of (2) + (4) a URI of a directory containing zip files containing (1) Returns: paths to directories that each contain contents of one zip file