From 8c6dae88a7818741579db48695b212010fb2c30b Mon Sep 17 00:00:00 2001 From: Zirui Wu Date: Mon, 20 Jul 2020 14:31:08 -0400 Subject: [PATCH] update docstring for compose/randomAppply/randomChoice to stay consistent with py_transforms address review cmts address review cmts --- mindspore/dataset/transforms/c_transforms.py | 23 +++++++++++-------- .../dataset/transforms/vision/c_transforms.py | 15 ++++++++++++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/mindspore/dataset/transforms/c_transforms.py b/mindspore/dataset/transforms/c_transforms.py index c6aa9a073..b99e6a69d 100644 --- a/mindspore/dataset/transforms/c_transforms.py +++ b/mindspore/dataset/transforms/c_transforms.py @@ -240,42 +240,47 @@ class Compose(cde.ComposeOp): Args: transforms (list): List of transformations to be applied. - Example: + + Examples: >>> compose = Compose([vision.Decode(), vision.RandomCrop()]) >>> dataset = ds.map(operations=compose) """ @check_random_transform_ops - def __init__(self, op_list): - super().__init__(op_list) + def __init__(self, transforms): + super().__init__(transforms) class RandomApply(cde.RandomApplyOp): """ Randomly performs a series of transforms with a given probability. + Args: transforms (list): List of transformations to be applied. prob (float, optional): The probability to apply the transformation list (default=0.5) - Example: + + Examples: >>> rand_apply = RandomApply([vision.RandomCrop()]) >>> dataset = ds.map(operations=rand_apply) """ @check_random_transform_ops - def __init__(self, op_list, prob=0.5): - super().__init__(prob, op_list) + def __init__(self, transforms, prob=0.5): + super().__init__(prob, transforms) class RandomChoice(cde.RandomChoiceOp): """ Randomly selects one transform from a list of transforms to perform operation. + Args: transforms (list): List of transformations to be chosen from to apply. - Example: + + Examples: >>> rand_choice = RandomChoice([vision.CenterCrop(), vision.RandomCrop()]) >>> dataset = ds.map(operations=rand_choice) """ @check_random_transform_ops - def __init__(self, op_list): - super().__init__(op_list) + def __init__(self, transforms): + super().__init__(transforms) diff --git a/mindspore/dataset/transforms/vision/c_transforms.py b/mindspore/dataset/transforms/vision/c_transforms.py index 9a73a9007..d783108e5 100644 --- a/mindspore/dataset/transforms/vision/c_transforms.py +++ b/mindspore/dataset/transforms/vision/c_transforms.py @@ -738,6 +738,21 @@ class UniformAugment(cde.UniformAugOp): class RandomSelectSubpolicy(cde.RandomSelectSubpolicyOp): + """ + Choose a random sub-policy from a list to be applied on the input image. A sub-policy is a list of tuples + (op, prob), where op is a TensorOp operation and prob is the probability that this op will be applied. Once + a sub-policy is selected, each op within the subpolicy with be applied in sequence according to its probability + + Args: + policy (list(list(tuple(TensorOp,float))): List of sub-policies to choose from. + + Examples: + >>> policy = [[(c_vision.RandomRotation((45, 45))), (c_transforms.RandomVerticalFlip()), + >>> (c_transforms.RandomColorAdjust())], + >>> [(c_vision.RandomRotation((90, 90))), (c_transforms.RandomColorAdjust())]] + >>> ds_policy = ds.map(input_columns=["image"], operations=visions.RandomSelectSubpolicy(policy)) + """ + @check_random_select_subpolicy_op def __init__(self, policy): super().__init__(policy) -- GitLab