diff --git a/README.md b/README.md index 2ae9a5ea..c9bcff5a 100644 --- a/README.md +++ b/README.md @@ -221,9 +221,9 @@ We have conducted all the tests under the same setting, please refer to the mode ## Quick Start ### Create a model -In flowvision we support two ways to create a model. +FlowVision supports two ways to create a model: -- Import the target model from `flowvision.models`, e.g., create `alexnet` from flowvision +- Import the target model from `flowvision.models`, e.g., create `alexnet` from FlowVision ```python from flowvision.models.alexnet import alexnet @@ -284,8 +284,8 @@ You can get the results like: ╘════════════════════════════════════════════╧══════════════╛ ``` -### Search for supported model by Wildcard -It is easy to search for model architectures by using Wildcard as below: +### Search for supported model by wildcard +It is easy to search for model architectures by using wildcard as below: ```python from flowvision.models import ModelCreator all_efficientnet_models = ModelCreator.model_table("**efficientnet**") @@ -314,8 +314,8 @@ You can get the results like: ╘════════════════════╧══════════════╛ ``` -### List all models supported in flowvision -`ModelCreator.model_list` has similar function as `ModelCreator.model_table` but return a list object, which gives the user a more flexible way to check the supported model in flowvision. +### List all models supported in FlowVision +`ModelCreator.model_list` has similar function as `ModelCreator.model_table` but returns a list object, which gives the user a more flexible way to check the supported model in flowvision. - List all models with pretrained weights ```python from flowvision.models import ModelCreator diff --git a/docs/README.md b/docs/README.md index a4c67a0e..e023cd6c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,7 +1,7 @@ ## Steps for Build Docs -Before generating the doc, you need to install flowvision by: +Before generating the doc, you need to install FlowVision by: ```bash cd ${flow-vision-path} diff --git a/docs/source/tutorials/Getting Started.md b/docs/source/tutorials/Getting Started.md index d02f3ac9..b61e7e80 100644 --- a/docs/source/tutorials/Getting Started.md +++ b/docs/source/tutorials/Getting Started.md @@ -1,7 +1,7 @@ # Getting Started ## Installation -- To install latest stable release of flowvision: +- To install the latest stable release of FlowVision: ```bash pip install flowvision==0.1.0 ``` @@ -14,9 +14,9 @@ pip install -e . ## Usage ### Create a model -In flowvision we support two ways to create a model. +FlowVision supports two ways to create a model: -- Import the target model from `flowvision.models`, e.g., create `alexnet` from flowvision +- Import the target model from `flowvision.models`, e.g., create `alexnet` from FlowVision ```python from flowvision.models.alexnet import alexnet @@ -77,8 +77,8 @@ You can get the results like: ╘════════════════════════════════════════════╧══════════════╛ ``` -### Search for supported model by Wildcard -It is easy to search for model architectures by using Wildcard as below: +### Search for the supported model by wildcard +It is easy to search for model architectures by using wildcard as below: ```python from flowvision.models import ModelCreator all_efficientnet_models = ModelCreator.model_table("**efficientnet**") @@ -107,8 +107,8 @@ You can get the results like: ╘════════════════════╧══════════════╛ ``` -### List all models supported in flowvision -`ModelCreator.model_list` has similar function as `ModelCreator.model_table` but return a list object, which gives the user a more flexible way to check the supported model in flowvision. +### List all models supported in FlowVision +`ModelCreator.model_list` has a similar function as `ModelCreator.model_table` but returns a list object, which gives the user a more flexible way to check the supported model in FlowVision. - List all models with pretrained weights ```python from flowvision.models import ModelCreator diff --git a/flowvision/data/auto_augment.py b/flowvision/data/auto_augment.py index 2ffebd09..11d7458c 100644 --- a/flowvision/data/auto_augment.py +++ b/flowvision/data/auto_augment.py @@ -539,11 +539,11 @@ def __repr__(self): def auto_augment_transform(config_str, hparams): """ - Create a AutoAugment transform + Creates a AutoAugment transform :param config_str: String defining configuration of auto augmentation. Consists of multiple sections separated by dashes ('-'). The first section defines the AutoAugment policy (one of 'v0', 'v0r', 'original', 'originalr'). - The remaining sections, not order sepecific determine + The remaining sections, not order specific determine * 'mstd' - float std deviation of magnitude noise applied Example: 'original-mstd0.5' results in AutoAugment with original policy, magnitude_std 0.5 @@ -681,15 +681,15 @@ def __repr__(self): def rand_augment_transform(config_str, hparams): """ - Create a RandAugment transform + Creates a RandAugment transform :param config_str: String defining configuration of random augmentation. Consists of multiple sections separated by dashes ('-'). The first section defines the specific variant of rand augment (currently only 'rand'). The remaining - sections, not order sepecific determine + sections, not order specific determine * 'm' - integer magnitude of rand augment * 'n' - integer num layers (number of transform ops selected per image) - * 'w' - integer probabiliy weight index (index of a set of weights to influence choice of op) + * 'w' - integer probability weight index (index of a set of weights to influence choice of op) * 'mstd' - float std deviation of magnitude noise applied, or uniform sampling if infinity (or > 100) * 'mmax' - set upper bound for magnitude to something other than default of _LEVEL_DENOM (10) * 'inc' - integer (bool), use augmentations that increase in severity with magnitude (default: 0) @@ -846,11 +846,11 @@ def __repr__(self): def augment_and_mix_transform(config_str, hparams): - """ Create AugMix OneFlow transform + """ Creates AugMix OneFlow transform :param config_str: String defining configuration of random augmentation. Consists of multiple sections separated by dashes ('-'). The first section defines the specific variant of rand augment (currently only 'rand'). The remaining - sections, not order sepecific determine + sections, not order specific determine * 'm' - integer magnitude (severity) of augmentation mix (default: 3) * 'w' - integer width of augmentation chain (default: 3) diff --git a/flowvision/data/mixup.py b/flowvision/data/mixup.py index 38c98c9c..679feb77 100644 --- a/flowvision/data/mixup.py +++ b/flowvision/data/mixup.py @@ -39,7 +39,7 @@ def mixup_target(target, num_classes, lam=1.0, smoothing=0.0, device="cuda"): def rand_bbox(img_shape, lam, margin=0.0, count=None): """ Standard CutMix bounding-box - Generates a random square bbox based on lambda value. This impl includes + Generates a random square bbox based on lambda value. This implementation includes support for enforcing a border margin as percent of bbox dimensions. Args: @@ -90,7 +90,7 @@ def rand_bbox_minmax(img_shape, minmax, count=None): def cutmix_bbox_and_lam( img_shape, lam, ratio_minmax=None, correct_lam=True, count=None ): - """ Generate bbox and apply lambda correction. + """ Generates bbox and apply lambda correction. """ if ratio_minmax is not None: yl, yu, xl, xu = rand_bbox_minmax(img_shape, ratio_minmax, count=count) diff --git a/flowvision/data/random_erasing.py b/flowvision/data/random_erasing.py index a945e9ba..5bc1c86a 100644 --- a/flowvision/data/random_erasing.py +++ b/flowvision/data/random_erasing.py @@ -26,7 +26,7 @@ class RandomErasing: or single image tensor after it has been normalized by dataset mean and std. Args: - probability: Probability that the Random Erasing operation will be performed + probability: Probability that the RandomErasing operation will be performed min_area: Minimum percentage of erased area wrt input image area max_area: Maximum percentage of erased area wrt input image area min_aspect: Minimum aspect ratio of erased area @@ -36,7 +36,7 @@ class RandomErasing: * 'rand' - erase block is same per-channel random (normal) color * 'pixel' - erase block is per-pixel random (normal) color - max_count: Maximum number of erasing blocks per image, area per box is scaled by count. + max_count: Maximum number of erasing blocks per image, and area per box is scaled by count. per-image count is randomly chosen between 1 and this value """ diff --git a/flowvision/layers/blocks/boxes.py b/flowvision/layers/blocks/boxes.py index aab6f29a..0608fae4 100644 --- a/flowvision/layers/blocks/boxes.py +++ b/flowvision/layers/blocks/boxes.py @@ -32,7 +32,7 @@ def batched_nms( """ Performs non-maximum suppression in a batched fashion. - Each index value correspond to a category, and NMS + Each index value corresponds to a category, and NMS will not be applied between elements of different categories. Args: @@ -151,7 +151,7 @@ def _box_inter_union(boxes1: Tensor, boxes2: Tensor) -> Tuple[Tensor, Tensor]: def box_iou(boxes1: Tensor, boxes2: Tensor) -> Tensor: """ - Return intersection-over-union (Jaccard index) between two sets of boxes. + Returns intersection-over-union (Jaccard index) between two sets of boxes. Both sets of boxes are expected to be in ``(x1, y1, x2, y2)`` format with ``0 <= x1 < x2`` and ``0 <= y1 < y2``. diff --git a/flowvision/models/detection/faster_rcnn.py b/flowvision/models/detection/faster_rcnn.py index 854cff3a..58b9df28 100644 --- a/flowvision/models/detection/faster_rcnn.py +++ b/flowvision/models/detection/faster_rcnn.py @@ -47,7 +47,7 @@ class FasterRCNN(GeneralizedRCNN): The input to the model is expected to be a list of tensors, each of shape [C, H, W], one for each image, and should be in 0-1 range. Different images can have different sizes. - The behavior of the model changes depending if it is in training or evaluation mode. + The behavior of the model changes depending on if it is in training or evaluation mode. During training, the model expects both the input tensors, as well as a targets (list of dictionary), containing: @@ -309,7 +309,7 @@ def fasterrcnn_resnet50_fpn( **kwargs, ): """ - Constructs a Faster R-CNN model with a ResNet-50-FPN backbone. + Constructs the Faster R-CNN model with a ResNet-50-FPN backbone. Reference: `"Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks" `_. @@ -317,7 +317,7 @@ def fasterrcnn_resnet50_fpn( The input to the model is expected to be a list of tensors, each of shape ``[C, H, W]``, one for each images, and should be in ``0-1`` range. Different images can have different sizes. - The behavior of the model changes depending if it is in training or evaluation mode. + The behavior of the model changes depending on if it is in training or evaluation mode. During training, the model expects both the input tensors, as well as a targets (list of dictionary), containing: @@ -475,7 +475,7 @@ def fasterrcnn_mobilenet_v3_large_320_fpn( **kwargs, ): """ - Constructs a low resolution Faster R-CNN model with a MobileNetV3-Large FPN backbone tunned for mobile use-cases. + Constructs the low resolution Faster R-CNN model with a MobileNetV3-Large FPN backbone tunned for mobile use-cases. It works similarly to Faster R-CNN with ResNet-50 FPN backbone. See :func:`~flowvision.models.detection.fasterrcnn_resnet50_fpn` for more details. @@ -528,7 +528,7 @@ def fasterrcnn_mobilenet_v3_large_fpn( **kwargs, ): """ - Constructs a high resolution Faster R-CNN model with a MobileNetV3-Large FPN backbone. + Constructs the high resolution Faster R-CNN model with a MobileNetV3-Large FPN backbone. It works similarly to Faster R-CNN with ResNet-50 FPN backbone. See :func:`~flowvision.models.detection.fasterrcnn_resnet50_fpn` for more details. diff --git a/flowvision/models/detection/fcos.py b/flowvision/models/detection/fcos.py index 3994b305..4c37c4d5 100644 --- a/flowvision/models/detection/fcos.py +++ b/flowvision/models/detection/fcos.py @@ -298,7 +298,7 @@ class FCOS(nn.Module): The input to the model is expected to be a list of tensors, each of shape [C, H, W], one for each image, and should be in 0-1 range. Different images can have different sizes. - The behavior of the model changes depending if it is in training or evaluation mode. + The behavior of the model changes depending on if it is in training or evaluation mode. During training, the model expects both the input tensors, as well as a targets (list of dictionary), containing: @@ -729,7 +729,7 @@ def fcos_resnet50_fpn( The input to the model is expected to be a list of tensors, each of shape ``[C, H, W]``, one for each image, and should be in ``0-1`` range. Different images can have different sizes. - The behavior of the model changes depending if it is in training or evaluation mode. + The behavior of the model changes depending on if it is in training or evaluation mode. During training, the model expects both the input tensors, as well as a targets (list of dictionary), containing: diff --git a/flowvision/models/detection/mask_rcnn.py b/flowvision/models/detection/mask_rcnn.py index a93eef37..1253c249 100644 --- a/flowvision/models/detection/mask_rcnn.py +++ b/flowvision/models/detection/mask_rcnn.py @@ -24,7 +24,7 @@ class MaskRCNN(FasterRCNN): The input to the model is expected to be a list of tensors, each of shape [C, H, W], one for each image, and should be in 0-1 range. Different images can have different sizes. - The behavior of the model changes depending if it is in training or evaluation mode. + The behavior of the model changes depending on if it is in training or evaluation mode. During training, the model expects both the input tensors, as well as a targets (list of dictionary), containing: @@ -275,7 +275,7 @@ def maskrcnn_resnet50_fpn( The input to the model is expected to be a list of tensors, each of shape ``[C, H, W]``, one for each image, and should be in ``0-1`` range. Different images can have different sizes. - The behavior of the model changes depending if it is in training or evaluation mode. + The behavior of the model changes depending on if it is in training or evaluation mode. During training, the model expects both the input tensors, as well as a targets (list of dictionary), containing: diff --git a/flowvision/models/detection/retinanet.py b/flowvision/models/detection/retinanet.py index dfece726..05d47487 100644 --- a/flowvision/models/detection/retinanet.py +++ b/flowvision/models/detection/retinanet.py @@ -278,7 +278,7 @@ class RetinaNet(nn.Module): The input to the model is expected to be a list of tensors, each of shape [C, H, W], one for each image, and should be in 0-1 range. Different images can have different sizes. - The behavior of the model changes depending if it is in training or evaluation mode. + The behavior of the model changes depending on if it is in training or evaluation mode. During training, the model expects both the input tensors, as well as a targets (list of dictionary), containing: @@ -663,14 +663,14 @@ def retinanet_resnet50_fpn( **kwargs, ): """ - Constructs a RetinaNet model with a ResNet-50-FPN backbone. + Constructs the RetinaNet model with a ResNet-50-FPN backbone. Reference: `"Focal Loss for Dense Object Detection" `_. The input to the model is expected to be a list of tensors, each of shape ``[C, H, W]``, one for each image, and should be in ``0-1`` range. Different images can have different sizes. - The behavior of the model changes depending if it is in training or evaluation mode. + The behavior of the model changes depending on if it is in training or evaluation mode. During training, the model expects both the input tensors, as well as a targets (list of dictionary), containing: diff --git a/flowvision/models/detection/ssd.py b/flowvision/models/detection/ssd.py index be74db9e..5aaa4a0a 100644 --- a/flowvision/models/detection/ssd.py +++ b/flowvision/models/detection/ssd.py @@ -117,7 +117,7 @@ class SSD(nn.Module): image, and should be in 0-1 range. Different images can have different sizes but they will be resized to a fixed size before passing it to the backbone. - The behavior of the model changes depending if it is in training or evaluation mode. + The behavior of the model changes depending on if it is in training or evaluation mode. During training, the model expects both the input tensors, as well as a targets (list of dictionary), containing: @@ -599,15 +599,15 @@ def ssd300_vgg16( trainable_backbone_layers: Optional[int] = None, **kwargs: Any ): - """Constructs an SSD model with input size 300x300 and a VGG16 backbone. + """Constructs the SSD model with input size 300x300 and a VGG16 backbone. Reference: `"SSD: Single Shot MultiBox Detector" `_. The input to the model is expected to be a list of tensors, each of shape [C, H, W], one for each - image, and should be in 0-1 range. Different images can have different sizes but they will be resized + image, and should be in 0-1 range. Different images can have different sizes, but they will be resized to a fixed size before passing it to the backbone. - The behavior of the model changes depending if it is in training or evaluation mode. + The behavior of the model changes depending on if it is in training or evaluation mode. During training, the model expects both the input tensors, as well as a targets (list of dictionary), containing: diff --git a/flowvision/models/detection/ssdlite.py b/flowvision/models/detection/ssdlite.py index 7a82d120..6096a189 100644 --- a/flowvision/models/detection/ssdlite.py +++ b/flowvision/models/detection/ssdlite.py @@ -237,7 +237,7 @@ def ssdlite320_mobilenet_v3_large( norm_layer: Optional[Callable[..., nn.Module]] = None, **kwargs: Any ): - """Constructs an SSDlite model with input size 320x320 and a MobileNetV3 Large backbone, as described at + """Constructs the SSDlite model with input size 320x320 and a MobileNetV3 Large backbone, as described at `"Searching for MobileNetV3" `_ and `"MobileNetV2: Inverted Residuals and Linear Bottlenecks" diff --git a/flowvision/models/segmentation/deeplabv3.py b/flowvision/models/segmentation/deeplabv3.py index a92588f1..c2cc2f29 100644 --- a/flowvision/models/segmentation/deeplabv3.py +++ b/flowvision/models/segmentation/deeplabv3.py @@ -193,7 +193,7 @@ def _load_weights(model, arch_type, backbone, progress): def deeplabv3_resnet50_coco( pretrained=False, progress=True, num_classes=21, aux_loss=None, **kwargs ): - """Constructs a DeepLabV3 model with a ResNet-50 backbone. + """Constructs the DeepLabV3 model with a ResNet-50 backbone. Args: pretrained (bool): If True, returns a model pre-trained on COCO train2017 which contains the same classes as Pascal VOC @@ -218,7 +218,7 @@ def deeplabv3_resnet50_coco( def deeplabv3_resnet101_coco( pretrained=False, progress=True, num_classes=21, aux_loss=None, **kwargs ): - """Constructs a DeepLabV3 model with a ResNet-101 backbone. + """Constructs the DeepLabV3 model with a ResNet-101 backbone. Args: pretrained (bool): If True, returns a model pre-trained on COCO train2017 which contains the same classes as Pascal VOC @@ -243,7 +243,7 @@ def deeplabv3_resnet101_coco( def deeplabv3_mobilenet_v3_large_coco( pretrained=False, progress=True, num_classes=21, aux_loss=None, **kwargs ): - """Constructs a DeepLabV3 model with a MobileNetV3-Large backbone. + """Constructs the DeepLabV3 model with a MobileNetV3-Large backbone. Args: pretrained (bool): If True, returns a model pre-trained on COCO train2017 which contains the same classes as Pascal VOC diff --git a/flowvision/models/segmentation/fcn.py b/flowvision/models/segmentation/fcn.py index 7d8624a8..9f533085 100644 --- a/flowvision/models/segmentation/fcn.py +++ b/flowvision/models/segmentation/fcn.py @@ -121,7 +121,7 @@ def _load_weights(model, arch_type, backbone, progress): def fcn_resnet50_coco( pretrained=False, progress=True, num_classes=21, aux_loss=None, **kwargs ): - """Constructs a Fully-Convolutional Network model with a ResNet-50 backbone. + """Constructs the Fully-Convolutional Network model with a ResNet-50 backbone. Args: pretrained (bool): If True, returns a model pre-trained on COCO train2017 which @@ -147,7 +147,7 @@ def fcn_resnet50_coco( def fcn_resnet101_coco( pretrained=False, progress=True, num_classes=21, aux_loss=None, **kwargs ): - """Constructs a Fully-Convolutional Network model with a ResNet-101 backbone. + """Constructs the Fully-Convolutional Network model with a ResNet-101 backbone. Args: pretrained (bool): If True, returns a model pre-trained on COCO train2017 which diff --git a/flowvision/models/segmentation/lraspp.py b/flowvision/models/segmentation/lraspp.py index cb203b8a..95db3f6a 100644 --- a/flowvision/models/segmentation/lraspp.py +++ b/flowvision/models/segmentation/lraspp.py @@ -121,7 +121,7 @@ def _segm_lraspp_mobilenetv3(backbone_name, num_classes, pretrained_backbone=Tru def lraspp_mobilenet_v3_large_coco( pretrained=False, progress=True, num_classes=21, **kwargs ): - """Constructs a Lite R-ASPP Network model with a MobileNetV3-Large backbone. + """Constructs the Lite R-ASPP Network model with a MobileNetV3-Large backbone. Args: pretrained (bool): If True, returns a model pre-trained on COCO train2017 which contains the same classes as Pascal VOC diff --git a/flowvision/scheduler/scheduler.py b/flowvision/scheduler/scheduler.py index 48094cf7..80ac214b 100644 --- a/flowvision/scheduler/scheduler.py +++ b/flowvision/scheduler/scheduler.py @@ -17,7 +17,7 @@ class Scheduler: The schedulers built on this should try to remain as stateless as possible (for simplicity). This family of schedulers is attempting to avoid the confusion of the meaning of 'last_epoch' - and -1 values for special behaviour. All epoch and update counts must be tracked in the training + and -1 values for special behavior. All epoch and update counts must be tracked in the training code and explicitly passed in to the schedulers on the corresponding step or step_update call. Based on ideas from: diff --git a/flowvision/transforms/functional.py b/flowvision/transforms/functional.py index 9e29491a..0b0e51f2 100644 --- a/flowvision/transforms/functional.py +++ b/flowvision/transforms/functional.py @@ -214,7 +214,7 @@ def pil_to_tensor(pic): def convert_image_dtype( image: flow.Tensor, dtype: flow.dtype = flow.float ) -> flow.Tensor: - """Convert a tensor image to the given ``dtype`` and scale the values accordingly + """Converts a tensor image to the given ``dtype`` and scale the values accordingly This function does not support PIL Image. Args: @@ -242,7 +242,7 @@ def convert_image_dtype( def to_pil_image(pic, mode=None): - """Convert a tensor or an ndarray to PIL Image. + """Converts a tensor or an ndarray to PIL Image. See :class:`~flowvision.transforms.ToPILImage` for more details. @@ -434,7 +434,7 @@ def resize( size: List[int], interpolation: InterpolationMode = InterpolationMode.BILINEAR, ) -> Tensor: - r"""Resize the input image to the given size. + r"""Resizes the input image to the given size. If the image is oneflow Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions @@ -483,7 +483,7 @@ def scale(*args, **kwargs): def pad( img: Tensor, padding: List[int], fill: int = 0, padding_mode: str = "constant" ) -> Tensor: - r"""Pad the given image on all sides with the given "pad" value. + r"""Pads the given image on all sides with the given "pad" value. If the image is oneflow Tensor, it is expected to have [..., H, W] shape, where ... means at most 2 leading dimensions for mode reflect and symmetric, at most 3 leading dimensions for mode edge, @@ -527,7 +527,7 @@ def pad( def crop(img: Tensor, top: int, left: int, height: int, width: int) -> Tensor: - """Crop the given image at specified location and output size. + """Crops the given image at specified location and output size. If the image is oneflow Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions. If image size is smaller than output size along any edge, image is padded with 0 and then cropped. @@ -597,7 +597,7 @@ def resized_crop( size: List[int], interpolation: InterpolationMode = InterpolationMode.BILINEAR, ) -> Tensor: - """Crop the given image and resize it to desired size. + """Crops the given image and resize it to desired size. If the image is oneflow Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions @@ -663,7 +663,7 @@ def vflip(img: Tensor) -> Tensor: def five_crop( img: Tensor, size: List[int] ) -> Tuple[Tensor, Tensor, Tensor, Tensor, Tensor]: - """Crop the given image into four corners and the central crop. + """Crops the given image into four corners and the central crop. If the image is oneflow Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions @@ -713,7 +713,7 @@ def five_crop( def ten_crop(img: Tensor, size: List[int], vertical_flip: bool = False) -> List[Tensor]: """Generate ten cropped images from the given image. - Crop the given image into four corners and the central crop plus the + Crops the given image into four corners and the central crop plus the flipped version of these (horizontal flipping is used by default). If the image is oneflow Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions @@ -988,7 +988,7 @@ def rotate( def rgb_to_grayscale(img: Tensor, num_output_channels: int = 1) -> Tensor: """Convert RGB image to grayscale version of image. - If the image is flow Tensor, it is expected + If the image is oneflow Tensor, it is expected to have [..., 3, H, W] shape, where ... means an arbitrary number of leading dimensions Note: diff --git a/flowvision/transforms/transforms.py b/flowvision/transforms/transforms.py index 21199887..75fedc50 100644 --- a/flowvision/transforms/transforms.py +++ b/flowvision/transforms/transforms.py @@ -63,7 +63,7 @@ def __repr__(self): class ToTensor: - r"""Convert a ``PIL Image`` or ``numpy.ndarray`` to tensor. + r"""Converts a ``PIL Image`` or ``numpy.ndarray`` to tensor. Converts a PIL Image or numpy.ndarray (H x W x C) in the range [0, 255] to a flow.FloatTensor of shape (C x H x W) in the range [0.0, 1.0] @@ -91,7 +91,7 @@ def __repr__(self): class PILToTensor: - """Convert a ``PIL Image`` to a tensor of the same type + """Converts a ``PIL Image`` to a tensor of the same type Converts a PIL Image (H x W x C) to a Tensor of shape (C x H x W). """ @@ -111,7 +111,7 @@ def __repr__(self): class ConvertImageDtype(Module): - """Convert a tensor image to the given ``dtype`` and scale the values accordingly + """Converts a tensor image to the given ``dtype`` and scale the values accordingly This function does not support PIL Image. Args: @@ -138,7 +138,7 @@ def forward(self, image): class ToPILImage: - """Convert a tensor or an ndarray to PIL Image. + """Converts a tensor or an ndarray to PIL Image. Converts a flow.Tensor of shape C x H x W or a numpy ndarray of shape H x W x C to a PIL Image while preserving the value range. @@ -178,7 +178,7 @@ def __repr__(self): class Normalize(Module): - r"""Normalize a tensor image with mean and standard deviation. + r"""Normalizes a tensor image with mean and standard deviation. This transform does not support PIL Image. Given mean: ``(mean[1],...,mean[n])`` and std: ``(std[1],..,std[n])`` for ``n`` channels, this transform will normalize each channel of the input @@ -216,7 +216,7 @@ def __repr__(self): class Resize(Module): - r"""Resize the input image to the given size. + r"""Resizes the input image to the given size. If the image is oneflow Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions @@ -315,7 +315,7 @@ def __repr__(self): class Pad(Module): - r"""Pad the given image on all sides with the given "pad" value. + r"""Pads the given image on all sides with the given "pad" value. If the image is oneflow Tensor, it is expected to have [..., H, W] shape, where ... means at most 2 leading dimensions for mode reflect and symmetric, at most 3 leading dimensions for mode edge, @@ -392,7 +392,7 @@ def __repr__(self): class Lambda: - r"""Apply a user-defined lambda as a transform. + r"""Applies a user-defined lambda as a transform. Args: lambd (function): Lambda/function to be used for transform. @@ -428,7 +428,7 @@ def _setup_size(size, error_msg): class RandomTransforms: - r"""Base class for a list of transformations with randomness + r"""Bases class for a list of transformations with randomness Args: transforms (sequence): list of transformations @@ -452,7 +452,7 @@ def __repr__(self): class RandomApply(Module): - """Apply randomly a list of transformations with a given probability. + """Applies randomly a list of transformations with a given probability. .. note:: In order to script the transformation, please use ``flow.nn.ModuleList`` as input instead of list/tuple of @@ -495,7 +495,7 @@ def __repr__(self): class RandomOrder(RandomTransforms): - """Apply a list of transformations in a random order. + """Applies a list of transformations in a random order. """ def __call__(self, img): @@ -507,7 +507,7 @@ def __call__(self, img): class RandomChoice(RandomTransforms): - """Apply single transformation randomly picked from a list. + """Applies a single transformation randomly picked from a list. """ def __call__(self, img): @@ -516,7 +516,7 @@ def __call__(self, img): class RandomCrop(Module): - """Crop the given image at a random location. + """Crops the given image at a random location. If the image is oneflow Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions, but if non-constant padding is used, the input is expected to have at most 2 leading dimensions @@ -560,7 +560,7 @@ class RandomCrop(Module): def get_params( img: Tensor, output_size: Tuple[int, int] ) -> Tuple[int, int, int, int]: - """Get parameters for ``crop`` for a random crop. + """Gets parameters for ``crop`` for a random crop. Args: img (PIL Image or Tensor): Image to be cropped. @@ -634,8 +634,8 @@ def __repr__(self): class RandomHorizontalFlip(Module): - """Horizontally flip the given image randomly with a given probability. - If the image is flow Tensor, it is expected + """Horizontally flips the given image randomly with a given probability. + If the image is oneflow Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions @@ -665,8 +665,8 @@ def __repr__(self): class RandomVerticalFlip(Module): - """Vertically flip the given image randomly with a given probability. - If the image is flow Tensor, it is expected + """Vertically flips the given image randomly with a given probability. + If the image is oneflow Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions @@ -696,9 +696,9 @@ def __repr__(self): class RandomResizedCrop(Module): - """Crop a random portion of image and resize it to a given size. + """Crops a random portion of image and resize it to a given size. - If the image is flow Tensor, it is expected + If the image is oneflow Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions A crop of the original image is made: the crop has a random area (H * W) @@ -756,7 +756,7 @@ def __init__( def get_params( img: Tensor, scale: List[float], ratio: List[float] ) -> Tuple[int, int, int, int]: - """Get parameters for ``crop`` for a random sized crop. + """Gets parameters for ``crop`` for a random sized crop. Args: img (PIL Image or Tensor): Input image. @@ -832,8 +832,8 @@ def __init__(self, *args, **kwargs): class FiveCrop(Module): - """Crop the given image into four corners and the central crop. - If the image is flow Tensor, it is expected + """Crops the given image into four corners and the central crop. + If the image is oneflow Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions @@ -880,9 +880,9 @@ def __repr__(self): class TenCrop(Module): - """Crop the given image into four corners and the central crop plus the flipped version of + """Crops the given image into four corners and the central crop plus the flipped version of these (horizontal flipping is used by default). - If the image is flow Tensor, it is expected + If the image is oneflow Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions @@ -934,7 +934,7 @@ def __repr__(self): class ColorJitter(Module): """Randomly change the brightness, contrast, saturation and hue of an image. - If the image is flow Tensor, it is expected + If the image is oneflow Tensor, it is expected to have [..., 3, H, W] shape, where ... means an arbitrary number of leading dimensions. If img is PIL Image, mode "1", "L", "I", "F" and modes with transparency (alpha channel) are not supported. @@ -1078,7 +1078,7 @@ def __repr__(self): class RandomRotation(Module): """Rotate the image by angle. - If the image is flow Tensor, it is expected + If the image is oneflow Tensor, it is expected to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions. Args: @@ -1147,7 +1147,7 @@ def __init__( @staticmethod def get_params(degrees: List[float]) -> float: - """Get parameters for ``rotate`` for a random rotation. + """Gets parameters for ``rotate`` for a random rotation. Returns: float: angle parameter to be passed to ``rotate`` for random rotation. @@ -1189,8 +1189,8 @@ def __repr__(self): class RandomGrayscale(Module): - """Randomly convert image to grayscale with a probability of p (default 0.1). - If the image is flow Tensor, it is expected + """Randomly converts image to grayscale with a probability of p (default 0.1). + If the image is oneflow Tensor, it is expected to have [..., 3, H, W] shape, where ... means an arbitrary number of leading dimensions Args: @@ -1278,14 +1278,14 @@ def __init__(self, kernel_size, sigma=(0.1, 2.0)): @staticmethod def get_params(sigma_min: float, sigma_max: float) -> float: - """Choose sigma for random gaussian blurring. + """Choose sigma for random Gaussian blurring. Args: sigma_min (float): Minimum standard deviation that can be chosen for blurring kernel. sigma_max (float): Maximum standard deviation that can be chosen for blurring kernel. Returns: - float: Standard deviation to be passed to calculate kernel for gaussian blurring. + float: Standard deviation to be passed to calculate kernel for Gaussian blurring. """ return flow.empty(1).uniform_(sigma_min, sigma_max).item() diff --git a/flowvision/utils/clip_grad.py b/flowvision/utils/clip_grad.py index 1ef8f432..d815b23c 100644 --- a/flowvision/utils/clip_grad.py +++ b/flowvision/utils/clip_grad.py @@ -11,11 +11,11 @@ def dispatch_clip_grad( parameters, value: float, mode: str = "norm", norm_type: float = 2.0 ): - """ Dispatch to gradient clipping method + """ Dispatches to gradient clipping method Args: parameters (Iterable): model parameters to clip - value (float): clipping value/factor/norm, mode dependant + value (float): clipping value/factor/norm, mode dependent mode (str): clipping mode, one of 'norm', 'value', 'agc' norm_type (float): p-norm, default 2.0 """ diff --git a/flowvision/utils/vision_helpers.py b/flowvision/utils/vision_helpers.py index 75756953..469ab70d 100644 --- a/flowvision/utils/vision_helpers.py +++ b/flowvision/utils/vision_helpers.py @@ -19,7 +19,7 @@ def make_grid( scale_each: bool = False, pad_value: int = 0, ) -> flow.Tensor: - """Make a grid of images. + """Makes grid of images. Args: tensor (Tensor or list): 4D mini-batch Tensor of shape (B x C x H x W) @@ -126,7 +126,7 @@ def save_image( pad_value: int = 0, format: Optional[str] = None, ) -> None: - """Save a given Tensor into an image file. + """Saves a given Tensor into an image file. Args: tensor (Tensor or list): Image to be saved. If given a mini-batch tensor,