(self, img: Tensor)
return img
img (PIL Image or Tensor): Image to be transformed.

        Returns:
            PIL Image or Tensor: AutoAugmented image.
img (PIL Image or Tensor): Image to be transformed.
img ( PIL Image or Tensor ) : Image to be transformed .
def forward(self, img: Tensor):
        """
            img (PIL Image or Tensor): Image to be transformed.

        Returns:
            PIL Image or Tensor: AutoAugmented image.
        """
        fill = self.fill
        if isinstance(img, Tensor):
            if isinstance(fill, (int, float)):
                fill = [float(fill)] * F._get_image_num_channels(img)
            elif fill is not None:
                fill = [float(f) for f in fill]

        transform_id, probs, signs = self.get_params(len(self.transforms))

        for i, (op_name, p,
                magnitude_id) in enumerate(self.transforms[transform_id]):
            if probs[i] <= p:
                magnitudes, signed = self._get_op_meta(op_name)
                magnitude = float(magnitudes[magnitude_id].item()) \
                    if magnitudes is not None and magnitude_id is not None else 0.0
                if signed is not None and signed and signs[i] == 0:
                    magnitude *= -1.0

                if op_name == "ShearX":
                    img = F.affine(
                        img,
                        angle=0.0,
                        translate=[0, 0],
                        scale=1.0,
                        shear=[math.degrees(magnitude), 0.0],
                        interpolation=self.interpolation,
                        fill=fill)
                elif op_name == "ShearY":
                    img = F.affine(
                        img,
                        angle=0.0,
                        translate=[0, 0],
                        scale=1.0,
                        shear=[0.0, math.degrees(magnitude)],
                        interpolation=self.interpolation,
                        fill=fill)
                elif op_name == "TranslateX":
                    img = F.affine(
                        img,
                        angle=0.0,
                        translate=[
                            int(F._get_image_size(img)[0] * magnitude), 0
                        ],
                        scale=1.0,
                        interpolation=self.interpolation,
                        shear=[0.0, 0.0],
                        fill=fill)
                elif op_name == "TranslateY":
                    img = F.affine(
                        img,
                        angle=0.0,
                        translate=[
                            0, int(F._get_image_size(img)[1] * magnitude)
                        ],
                        scale=1.0,
                        interpolation=self.interpolation,
                        shear=[0.0, 0.0],
                        fill=fill)
                elif op_name == "Rotate":
                    img = F.rotate(
                        img,
                        magnitude,
                        interpolation=self.interpolation,
                        fill=fill)
                elif op_name == "Brightness":
                    img = F.adjust_brightness(img, 1.0 + magnitude)
                elif op_name == "Color":
                    img = F.adjust_saturation(img, 1.0 + magnitude)
                elif op_name == "Contrast":
                    img = F.adjust_contrast(img, 1.0 + magnitude)
                elif op_name == "Sharpness":
                    img = F.adjust_sharpness(img, 1.0 + magnitude)
                elif op_name == "Posterize":
                    img = F.posterize(img, int(magnitude))
                elif op_name == "Solarize":
                    img = F.solarize(img, magnitude)
                elif op_name == "AutoContrast":
                    img = F.autocontrast(img)
                elif op_name == "Equalize":
                    img = F.equalize(img)
                elif op_name == "Invert":
                    img = F.invert(img)
                else:
                    raise ValueError(
                        "The provided operator {} is not recognized.".format(
                            op_name))

        return img
def forward ( self , img : Tensor ) : fill = self . fill if isinstance ( img , Tensor ) : if isinstance ( fill , ( int , float ) ) : fill = [ float ( fill ) ] * F . _get_image_num_channels ( img ) elif fill is not None : fill = [ float ( f ) for f in fill ] transform_id , probs , signs = self . get_params ( len ( self . transforms ) ) for i , ( op_name , p , magnitude_id ) in enumerate ( self . transforms [ transform_id ] ) : if probs [ i ] <= p : magnitudes , signed = self . _get_op_meta ( op_name ) magnitude = float ( magnitudes [ magnitude_id ] . item ( ) ) if magnitudes is not None and magnitude_id is not None else 0.0 if signed is not None and signed and signs [ i ] == 0 : magnitude *= - 1.0 if op_name == "ShearX" : img = F . affine ( img , angle = 0.0 , translate = [ 0 , 0 ] , scale = 1.0 , shear = [ math . degrees ( magnitude ) , 0.0 ] , interpolation = self . interpolation , fill = fill ) elif op_name == "ShearY" : img = F . affine ( img , angle = 0.0 , translate = [ 0 , 0 ] , scale = 1.0 , shear = [ 0.0 , math . degrees ( magnitude ) ] , interpolation = self . interpolation , fill = fill ) elif op_name == "TranslateX" : img = F . affine ( img , angle = 0.0 , translate = [ int ( F . _get_image_size ( img ) [ 0 ] * magnitude ) , 0 ] , scale = 1.0 , interpolation = self . interpolation , shear = [ 0.0 , 0.0 ] , fill = fill ) elif op_name == "TranslateY" : img = F . affine ( img , angle = 0.0 , translate = [ 0 , int ( F . _get_image_size ( img ) [ 1 ] * magnitude ) ] , scale = 1.0 , interpolation = self . interpolation , shear = [ 0.0 , 0.0 ] , fill = fill ) elif op_name == "Rotate" : img = F . rotate ( img , magnitude , interpolation = self . interpolation , fill = fill ) elif op_name == "Brightness" : img = F . adjust_brightness ( img , 1.0 + magnitude ) elif op_name == "Color" : img = F . adjust_saturation ( img , 1.0 + magnitude ) elif op_name == "Contrast" : img = F . adjust_contrast ( img , 1.0 + magnitude ) elif op_name == "Sharpness" : img = F . adjust_sharpness ( img , 1.0 + magnitude ) elif op_name == "Posterize" : img = F . posterize ( img , int ( magnitude ) ) elif op_name == "Solarize" : img = F . solarize ( img , magnitude ) elif op_name == "AutoContrast" : img = F . autocontrast ( img ) elif op_name == "Equalize" : img = F . equalize ( img ) elif op_name == "Invert" : img = F . invert ( img ) else : raise ValueError ( "The provided operator {} is not recognized." . format ( op_name ) ) return img