当前位置: 首页>>代码示例>>Python>>正文


Python functional.pad方法代码示例

本文整理汇总了Python中torchvision.transforms.functional.pad方法的典型用法代码示例。如果您正苦于以下问题:Python functional.pad方法的具体用法?Python functional.pad怎么用?Python functional.pad使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在torchvision.transforms.functional的用法示例。


在下文中一共展示了functional.pad方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pad_func

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import pad [as 别名]
def pad_func(self, img, params):
        if self.padding is not None:
            img.img = F.pad(img.img, self.padding, self.fill, self.padding_mode)
            if img.x is not None:
                img.x = F.pad(img.x, self.padding, self.fill, self.padding_mode)
            if img.y is not None:
                img.y = F.pad(img.y, self.padding, self.fill, self.padding_mode)

        if self.pad_if_needed and img.img.size[0] < self.size[1]:
            img.img = F.pad(img.img, (self.size[1] - img.img.size[0], 0), self.fill, self.padding_mode)
            if img.x is not None:
                img.x = F.pad(img.x, (self.size[1] - img.img.size[0], 0), self.fill, self.padding_mode)
            if img.y is not None:
                img.y = F.pad(img.y, (self.size[1] - img.img.size[0], 0), self.fill, self.padding_mode)

        if self.pad_if_needed and img.img.size[1] < self.size[0]:
            img.img = F.pad(img.img, (0, self.size[0] - img.img.size[1]), self.fill, self.padding_mode)
            if img.x is not None:
                img.x = F.pad(img.x, (0, self.size[0] - img.img.size[1]), self.fill, self.padding_mode)
            if img.y is not None:
                img.y = F.pad(img.y, (0, self.size[0] - img.img.size[1]), self.fill, self.padding_mode)

        return img 
开发者ID:yolomax,项目名称:person-reid-lib,代码行数:25,代码来源:transforms.py

示例2: _get_params

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import pad [as 别名]
def _get_params(self, images):
        """
        Args:
            img (PIL Image) list: Image to be cropped.
        Returns:
            PIL Image list: Cropped image.
        """
        while isinstance(images, (tuple, list)):
            images = images[0]
        img = images.img

        if self.padding is not None:
            img = F.pad(img, self.padding, self.fill, self.padding_mode)

        # pad the width if needed
        if self.pad_if_needed and img.size[0] < self.size[1]:
            img = F.pad(img, (self.size[1] - img.size[0], 0), self.fill, self.padding_mode)
        # pad the height if needed
        if self.pad_if_needed and img.size[1] < self.size[0]:
            img = F.pad(img, (0, self.size[0] - img.size[1]), self.fill, self.padding_mode)

        return self.get_params(img, self.size) 
开发者ID:yolomax,项目名称:person-reid-lib,代码行数:24,代码来源:transforms.py

示例3: undo_transform

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import pad [as 别名]
def undo_transform(self, sample):
        rdict = {}
        input_data = sample['input']
        fh, fw, w, h = self.get_params(sample)
        th, tw = self.size

        pad_left = fw
        pad_right = w - pad_left - tw
        pad_top = fh
        pad_bottom = h - pad_top - th

        padding = (pad_left, pad_top, pad_right, pad_bottom)
        input_data = F.pad(input_data, padding)
        rdict['input'] = input_data

        sample.update(rdict)
        return sample 
开发者ID:perone,项目名称:medicaltorch,代码行数:19,代码来源:transforms.py

示例4: cv_transform

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import pad [as 别名]
def cv_transform(img):
    # img = resize(img, size=(100, 300))
    # img = to_tensor(img)
    # img = normalize(img, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
    # img = pad(img, padding=(10, 10, 20, 20), fill=(255, 255, 255), padding_mode='constant')
    # img = pad(img, padding=(100, 100, 100, 100), fill=5, padding_mode='symmetric')
    # img = crop(img, -40, -20, 1000, 1000)
    # img = center_crop(img, (310, 300))
    # img = resized_crop(img, -10.3, -20, 330, 220, (500, 500))
    # img = hflip(img)
    # img = vflip(img)
    # tl, tr, bl, br, center = five_crop(img, 100)
    # img = adjust_brightness(img, 2.1)
    # img = adjust_contrast(img, 1.5)
    # img = adjust_saturation(img, 2.3)
    # img = adjust_hue(img, 0.5)
    # img = adjust_gamma(img, gamma=3, gain=0.1)
    # img = rotate(img, 10, resample='BILINEAR', expand=True, center=None)
    # img = to_grayscale(img, 3)
    # img = affine(img, 10, (0, 0), 1, 0, resample='BICUBIC', fillcolor=(255,255,0))
    # img = gaussion_noise(img)
    # img = poisson_noise(img)
    img = salt_and_pepper(img)
    return to_tensor(img) 
开发者ID:YU-Zhiyang,项目名称:opencv_transforms_torchvision,代码行数:26,代码来源:cvfunctional.py

示例5: pil_transform

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import pad [as 别名]
def pil_transform(img):
    # img = functional.resize(img, size=(100, 300))
    # img = functional.to_tensor(img)
    # img = functional.normalize(img, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
    # img = functional.pad(img, padding=(10, 10, 20, 20), fill=(255, 255, 255), padding_mode='constant')
    # img = functional.pad(img, padding=(100, 100, 100, 100), padding_mode='symmetric')
    # img = functional.crop(img, -40, -20, 1000, 1000)
    # img = functional.center_crop(img, (310, 300))
    # img = functional.resized_crop(img, -10.3, -20, 330, 220, (500, 500))
    # img = functional.hflip(img)
    # img = functional.vflip(img)
    # tl, tr, bl, br, center = functional.five_crop(img, 100)
    # img = functional.adjust_brightness(img, 2.1)
    # img = functional.adjust_contrast(img, 1.5)
    # img = functional.adjust_saturation(img, 2.3)
    # img = functional.adjust_hue(img, 0.5)
    # img = functional.adjust_gamma(img, gamma=3, gain=0.1)
    # img = functional.rotate(img, 10, resample=PIL.Image.BILINEAR, expand=True, center=None)
    # img = functional.to_grayscale(img, 3)
    # img = functional.affine(img, 10, (0, 0), 1, 0, resample=PIL.Image.BICUBIC, fillcolor=(255,255,0))

    return functional.to_tensor(img) 
开发者ID:YU-Zhiyang,项目名称:opencv_transforms_torchvision,代码行数:24,代码来源:cvfunctional.py

示例6: _maybe_pad

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import pad [as 别名]
def _maybe_pad(self, frame: Image):
        if self.padding is not None:
            frame = F.pad(frame, self.padding, self.fill, self.padding_mode)
        # pad the width if needed
        frame_width = frame.size[0]
        desired_width = self.size[1]
        if self.pad_if_needed and frame_width < desired_width:
            horizontal_padding = desired_width - frame_width
            frame = F.pad(frame, (horizontal_padding, 0), self.fill, self.padding_mode)
        # pad the height if needed
        frame_height = frame.size[1]
        desired_height = self.size[0]
        if self.pad_if_needed and frame_height < desired_height:
            vertical_padding = desired_height - frame_height
            frame = F.pad(frame, (0, vertical_padding), self.fill, self.padding_mode)
        return frame 
开发者ID:torchvideo,项目名称:torchvideo,代码行数:18,代码来源:random_crop_video.py

示例7: pad

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import pad [as 别名]
def pad(img, padding, mode='constant', fill=0):
    if isinstance(padding, int):
        padding = (padding, padding, padding, padding)
    elif len(padding) == 2:
        padding = (padding[0], padding[1], padding[0], padding[1])
    else:
        assert len(padding) == 4

    if mode == 'constant':
        img_new = TF.pad(img, padding, fill=fill)
    else:
        np_padding = ((padding[1], padding[3]), (padding[0], padding[2]), (0, 0))
        img_new = Image.fromarray(np.pad(
            np.array(img), np_padding, mode=mode
        ))

    return img_new 
开发者ID:vacancy,项目名称:Jacinle,代码行数:19,代码来源:image.py

示例8: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import pad [as 别名]
def __call__(self, frames):
        """
        Args:
            frames: a list of PIL Image
        Returns:
            a list of PIL Image: Cropped images.
        """

        i, j, h, w = self.get_params(frames, self.size)

        out_frames = []
        for frame in frames:
            if self.padding is not None:
                frame = F.pad(frame, self.padding, self.fill, self.padding_mode)

            # pad the width if needed
            if self.pad_if_needed and frame.size[0] < self.size[1]:
                frame = F.pad(frame, (int((1 + self.size[1] - frame.size[0]) / 2), 0), self.fill, self.padding_mode)
            # pad the height if needed
            if self.pad_if_needed and frame.size[1] < self.size[0]:
                frame = F.pad(frame, (0, int((1 + self.size[0] - frame.size[1]) / 2)), self.fill, self.padding_mode)

            out_frames.append(F.crop(frame, i, j, h, w))
        return out_frames 
开发者ID:hangzhaomit,项目名称:Sound-of-Pixels,代码行数:26,代码来源:video_transforms.py

示例9: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import pad [as 别名]
def __call__(self, img):
        """
        Args:
            img (PIL Image): Image to be padded.
        Returns:
            PIL Image: Padded image.
        """
        w, h = img.size
        m = self.multiple
        nw = (w // m + int((w % m) != 0)) * m
        nh = (h // m + int((h % m) != 0)) * m
        padw = nw - w
        padh = nh - h

        out = vf.pad(img, (0, 0, padw, padh), self.fill, self.padding_mode)
        return out 
开发者ID:jornpeters,项目名称:integer_discrete_flows,代码行数:18,代码来源:load_data.py

示例10: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import pad [as 别名]
def __call__(self, img):
        """
        Args:
            img (PIL Image): Image to be cropped.

        Returns:
            PIL Image: Cropped image.
        """
        if self.padding is not None:
            img = F.pad(img, self.padding, self.fill, self.padding_mode)

        # pad the width if needed
        if self.pad_if_needed and img.size[0] < self.size[1]:
            img = F.pad(img, (self.size[1] - img.size[0], 0), self.fill, self.padding_mode)
        # pad the height if needed
        if self.pad_if_needed and img.size[1] < self.size[0]:
            img = F.pad(img, (0, self.size[0] - img.size[1]), self.fill, self.padding_mode)

        i, j, h, w = self.get_params(img, self.size)

        return F.crop(img, i, j, h, w) 
开发者ID:yalesong,项目名称:pvse,代码行数:23,代码来源:video_transforms.py

示例11: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import pad [as 别名]
def __call__(self, image, bboxes):
        if self.padding is not None:
            image = F.pad(image, self.padding, self.fill, self.padding_mode)
            bboxes = bboxes.pad(padding)

        # pad the width if needed
        if self.pad_if_needed and image.size[0] < self.size[1]:
            image = F.pad(image, (self.size[1] - image.size[0], 0), self.fill, self.padding_mode)
            bboxes = bboxes.pad((self.size[1] - image.size[0], 0))
        # pad the height if needed
        if self.pad_if_needed and image.size[1] < self.size[0]:
            image = F.pad(image, (0, self.size[0] - image.size[1]), self.fill, self.padding_mode)
            bboxes = bboxes.pad((0, self.size[0] - image.size[1]))
        
        i, j, h, w = self.get_params(image, self.size)
        return F.crop(image, i, j, h, w), bboxes.crop((i, j, i+h, j+w)) 
开发者ID:liux0614,项目名称:yolo_nano,代码行数:18,代码来源:transforms.py


注:本文中的torchvision.transforms.functional.pad方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。