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


Python functional.resized_crop方法代码示例

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


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

示例1: process_images

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import resized_crop [as 别名]
def process_images(self, clean, mask):
        i, j, h, w = RandomResizedCrop.get_params(clean, scale=(0.5, 2.0), ratio=(3. / 4., 4. / 3.))
        clean_img = resized_crop(clean, i, j, h, w, size=self.img_size, interpolation=Image.BICUBIC)
        mask = resized_crop(mask, i, j, h, w, self.img_size, interpolation=Image.BICUBIC)

        # get mask before further image augment
        # mask = self.get_mask(raw_img, clean_img)

        if self.add_random_masks:
            mask = random_masks(mask.copy(), size=self.img_size[0], offset=10)
        mask = np.where(np.array(mask) > brightness_difference * 255, np.uint8(255), np.uint8(0))
        mask = cv2.dilate(mask, np.ones((10, 10), np.uint8), iterations=1)

        mask = np.expand_dims(mask, -1)
        mask_t = to_tensor(mask)
        # mask_t = (mask_t > brightness_difference).float()

        # mask_t, _ = torch.max(mask_t, dim=0, keepdim=True)
        binary_mask = (1 - mask_t)  # valid positions are 1; holes are 0
        binary_mask = binary_mask.expand(3, -1, -1)
        clean_img = self.transformer(clean_img)
        corrupted_img = clean_img * binary_mask
        return corrupted_img, binary_mask, clean_img 
开发者ID:yu45020,项目名称:Text_Segmentation_Image_Inpainting,代码行数:25,代码来源:Dataloader.py

示例2: resized_crop

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import resized_crop [as 别名]
def resized_crop(img, i, j, h, w, size, interpolation='BILINEAR'):
    """Crop the given CV Image and resize it to desired size. Notably used in RandomResizedCrop.

    Args:
        img (np.ndarray): Image to be cropped.
        i: Upper pixel coordinate.
        j: Left pixel coordinate.
        h: Height of the cropped image.
        w: Width of the cropped image.
        size (sequence or int): Desired output size. Same semantics as ``scale``.
        interpolation (str, optional): Desired interpolation. Default is
            ``BILINEAR``.
    Returns:
        np.ndarray: Cropped image.
    """
    assert _is_numpy_image(img), 'img should be CV Image'
    img = crop(img, i, j, h, w)
    img = resize(img, size, interpolation)
    return img 
开发者ID:YU-Zhiyang,项目名称:opencv_transforms_torchvision,代码行数:21,代码来源:cvfunctional.py

示例3: cv_transform

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import resized_crop [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

示例4: pil_transform

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import resized_crop [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

示例5: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import resized_crop [as 别名]
def __call__(self, image, target):
        i, j, h, w = self.get_params(image, self.scale, self.ratio)
        image = F.resized_crop(image, i, j, h, w, self.size, self.interpolation)
        # Crop
        target['boxes'][:, [0, 2]] = target['boxes'][:, [0, 2]].clamp_(j, j + w)
        target['boxes'][:, [1, 3]] = target['boxes'][:, [1, 3]].clamp_(i, i + h)
        # Reset origin
        target['boxes'][:, [0, 2]] -= j
        target['boxes'][:, [1, 3]] -= i
        # Remove targets that are out of crop
        target_filter = (target['boxes'][:, 0] != target['boxes'][:, 2]) & \
                        (target['boxes'][:, 1] != target['boxes'][:, 3])
        target['boxes'] = target['boxes'][target_filter]
        target['labels'] = target['labels'][target_filter]
        # Resize
        target['boxes'][:, [0, 2]] *= self.size[0] / w
        target['boxes'][:, [1, 3]] *= self.size[1] / h

        return image, target 
开发者ID:frgfm,项目名称:Holocron,代码行数:21,代码来源:transforms.py

示例6: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import resized_crop [as 别名]
def __call__(self, img1, img2):
        img1 = tvF.resize(img1, self.size, interpolation=Image.LANCZOS)
        img2 = tvF.resize(img2, self.size, interpolation=Image.LANCZOS)
        if random.random() < 0.5:
            img1 = tvF.hflip(img1)
            img2 = tvF.hflip(img2)
        if random.random() < 0.5:
            rot = random.uniform(-10, 10)
            crop_ratio = rot_crop(rot)
            img1 = tvF.rotate(img1, rot, resample=Image.BILINEAR)
            img2 = tvF.rotate(img2, rot, resample=Image.BILINEAR)
            img1 = tvF.center_crop(img1, int(img1.size[0] * crop_ratio))
            img2 = tvF.center_crop(img2, int(img2.size[0] * crop_ratio))

        i, j, h, w = self.get_params(img1, self.scale, self.ratio)

        # return the image with the same transformation
        return (tvF.resized_crop(img1, i, j, h, w, self.size, self.interpolation),
                tvF.resized_crop(img2, i, j, h, w, self.size, self.interpolation)) 
开发者ID:blandocs,项目名称:Tag2Pix,代码行数:21,代码来源:dataloader.py

示例7: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import resized_crop [as 别名]
def __call__(self, img):
        if self.randomize:
            self.random_crop = self.get_params(img, self.scale, self.ratio)
            self.randomize = False

        i, j, h, w = self.random_crop
        return F.resized_crop(img, i, j, h, w, self.size, self.interpolation) 
开发者ID:kenshohara,项目名称:3D-ResNets-PyTorch,代码行数:9,代码来源:spatial_transforms.py

示例8: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import resized_crop [as 别名]
def __call__(self, img, anns):
        i, j, h, w = self.get_params(img, self.scale, self.ratio)
        new_anns = HF.resized_crop(anns, j, i, w, h, self.size, self.min_area_frac)
        if len(new_anns) == 0:
            return img, anns
        img = VF.resized_crop(img, i, j, h, w, self.size[::-1], self.interpolation)
        return img, new_anns 
开发者ID:qixuxiang,项目名称:Pytorch_Lightweight_Network,代码行数:9,代码来源:__init__.py

示例9: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import resized_crop [as 别名]
def __call__(self, img_dict):
        """
        Args:
            img (PIL Image): Image to be cropped and resized.
        Returns:
            PIL Image: Randomly cropped and resized image.
        """
        keys = ['rgb', 'ir', 'depth']
        
        i, j, h, w = self.get_params(img_dict[keys[0]], self.scale, self.ratio)
        for key in keys:
            img_dict[key] = F.resized_crop(img_dict[key], i, j, h, w, 
                                           self.size, self.interpolation)
        return img_dict 
开发者ID:AlexanderParkin,项目名称:ChaLearn_liveness_challenge,代码行数:16,代码来源:transforms.py

示例10: _transform

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import resized_crop [as 别名]
def _transform(
        self, frames: PILVideo, params: Tuple[ImageShape, Point]
    ) -> PILVideoI:
        crop_shape, offset = params
        for frame in frames:
            yield F.resized_crop(
                frame,
                offset.y,
                offset.x,
                crop_shape.height,
                crop_shape.width,
                size=self.size,
                interpolation=self.interpolation,
            )
        pass 
开发者ID:torchvideo,项目名称:torchvideo,代码行数:17,代码来源:multiscale_crop_video.py

示例11: _transform_frame

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import resized_crop [as 别名]
def _transform_frame(self, frame: Image, i: int, j: int, h: int, w: int) -> Image:
        return F.resized_crop(frame, i, j, h, w, self.size, self.interpolation) 
开发者ID:torchvideo,项目名称:torchvideo,代码行数:4,代码来源:random_resized_crop_video.py

示例12: __getitem__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import resized_crop [as 别名]
def __getitem__(self, index):
        # In this situation ignore index and sample classes uniformly
        if self.balance_classes:
            currCls = random.choice(self.attToImgId.keys())
            index = random.choice(self.attToImgId[currCls])
            cid = [self.sattr_to_idx[currCls]] if currCls != 'bg' else [0]
        else:
            cid = [0]

        image = Image.open(os.path.join(self.image_path,self.dataset['images'][index]['filepath'], self.dataset['images'][index]['filename']))
        if image.mode != 'RGB':
            #print image.mode
            image = image.convert('RGB')

        bbox, bboxLabel, cbid = self.randomBBoxSample(index)
        label = self.dataset['images'][index]['label']

        # Apply transforms to the image.
        image = self.transform[0](image)
        # Now do the flipping
        if self.randHFlip and random.random()>0.5:
            image = FN.hflip(image)
            bbox[0] = 1.0-(bbox[0]+bbox[2])

        #Convert BBox to actual co-ordinates
        bbox = [int(bc*self.out_img_size) for bc in bbox]
        #print bbox, image.size, cbid
        #assert bbox[3]>0;
        #assert bbox[2]>0;
        #if not ((bbox[0]>=0) and (bbox[0]<128)):
        #    print bbox;
        #    import ipdb;ipdb.set_trace()
        #assert ((bbox[0]>=0) and (bbox[0]<128));
        #assert ((bbox[1]>=0) and (bbox[1]<128))
        #Now obtain the crop
        boxCrop = FN.resized_crop(image, bbox[1], bbox[0], bbox[3],bbox[2], (self.bbox_out_size, self.bbox_out_size))
        # Create Mask
        mask = torch.zeros(1,self.out_img_size,self.out_img_size)
        mask[0,bbox[1]:bbox[1]+bbox[3],bbox[0]:bbox[0]+bbox[2]] = 1.

        return self.transform[-1](image), torch.FloatTensor(label), self.transform[-1](boxCrop), torch.FloatTensor(bboxLabel), mask, torch.IntTensor(bbox), torch.LongTensor(cid) 
开发者ID:rakshithShetty,项目名称:adversarial-object-removal,代码行数:43,代码来源:data_loader_stargan.py

示例13: __call__

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

        Returns:
            PIL Image: Randomly cropped and resized image.
        """
        i, j, h, w = self.get_params(img, self.scale, self.ratio)
        if isinstance(self.interpolation, (tuple, list)):
            interpolation = random.choice(self.interpolation)
        else:
            interpolation = self.interpolation
        return F.resized_crop(img, i, j, h, w, self.size, interpolation) 
开发者ID:rwightman,项目名称:pytorch-image-models,代码行数:16,代码来源:transforms.py

示例14: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import resized_crop [as 别名]
def __call__(self, img):
        """
        Args:
            img (PIL Image): Image to be cropped and resized.
        Returns:
            PIL Image: Randomly cropped and resized image.
        """
        i, j, h, w = self.get_params(img, self.scale)
        return F.resized_crop(img, i, j, h, w, self.size, self.interpolation) 
开发者ID:Vermeille,项目名称:Torchelie,代码行数:11,代码来源:__init__.py

示例15: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import resized_crop [as 别名]
def __call__(self, sample):
        image, label = sample['image'], sample['label']
        if self.i is None or self.image_mode:
            self.i, self.j, self.h, self.w = transforms.RandomResizedCrop.get_params(image, self.scale, self.ratio)
        image = F.resized_crop(image, self.i, self.j, self.h, self.w, self.size, Image.BILINEAR)
        label = F.resized_crop(label, self.i, self.j, self.h, self.w, self.size, Image.BILINEAR)
        sample['image'], sample['label'] = image, label
        return sample 
开发者ID:Kinpzz,项目名称:RCRNet-Pytorch,代码行数:10,代码来源:transforms.py


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