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


Python functional.normalize方法代码示例

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


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

示例1: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import normalize [as 别名]
def __call__(self, rgb_img, label_img=None):

        label1 = label_img
        label2 = label_img
        if self.scale1 != 1:
            w, h = label_img.size
            label1 = label1.resize((w//self.scale1, h//self.scale1), Image.NEAREST)

        if self.scale2 != 1:
            w, h = label_img.size
            label2 = label2.resize((w//self.scale2, h//self.scale2), Image.NEAREST)

        rgb_img = F.to_tensor(rgb_img) # convert to tensor (values between 0 and 1)
        rgb_img = F.normalize(rgb_img, self.mean, self.std) # normalize the tensor
        label1 = torch.LongTensor(np.array(label1).astype(np.int64))
        label2 = torch.LongTensor(np.array(label2).astype(np.int64))


        return rgb_img, label1, label2 
开发者ID:clovaai,项目名称:ext_portrait_segmentation,代码行数:21,代码来源:PILTransform.py

示例2: prepare_input

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import normalize [as 别名]
def prepare_input(frame, flip_left_right=False, debug=False):
    # BGR to RGB and flip frame
    input_image = np.flip(frame, axis=2).copy()
    if flip_left_right:
        input_image = np.flip(input_image, axis=1).copy()

    # Concert to shape batch_size=1, rgb, h, w
    input_image = torch.Tensor(input_image.transpose(2, 0, 1))

    # To debug what is actually fed to network
    if debug:
        plt.imshow(input_image.numpy().transpose(1, 2, 0) / 255)
        plt.show()
    input_image = func_transforms.normalize(
        input_image / 255, [0.5, 0.5, 0.5], [1, 1, 1]
    ).unsqueeze(0)
    # Equivalently
    # input_image_1 = input_image / 255 - 0.5
    input_image = input_image.cuda()
    return input_image 
开发者ID:hassony2,项目名称:obman_train,代码行数:22,代码来源:preprocess.py

示例3: normalize

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import normalize [as 别名]
def normalize(tensor, mean, std):
    """Normalize a tensor image with mean and standard deviation.

    See ``Normalize`` for more details.

    Args:
        tensor (Tensor): Tensor image of size (C, H, W) to be normalized.
        mean (sequence): Sequence of means for each channel.
        std (sequence): Sequence of standard deviations for each channely.

    Returns:
        Tensor: Normalized Tensor image.
    """
    if _is_tensor_image(tensor):
        for t, m, s in zip(tensor, mean, std):
            t.sub_(m).div_(s)
        return tensor
    elif _is_numpy_image(tensor):
        return (tensor.astype(np.float32) - 255.0 * np.array(mean))/np.array(std)
    else:
        raise RuntimeError('Undefined type') 
开发者ID:YU-Zhiyang,项目名称:opencv_transforms_torchvision,代码行数:23,代码来源:cvfunctional.py

示例4: cv_transform

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

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import normalize [as 别名]
def __getitem__(self, index):
        # Apply transforms to the image.
        image = torch.FloatTensor(self.nc,self.out_img_size, self.out_img_size).fill_(-1.)
        # Get the individual images.
        randbox = random.randrange(len(self.metadata['images'][index]))
        imglabel = np.zeros(10, dtype=np.int)
        boxlabel = np.zeros(10, dtype=np.int)
        for i,bb in enumerate(self.metadata['images'][index]):
            imid = random.randrange(self.num_data)
            bbox = [int(bc*self.out_img_size) for bc in bb]
            img, label = self.dataset[imid]
            scImg = FN.resize(img,(bbox[3],bbox[2]))
            image[:, bbox[1]:bbox[1]+bbox[3], bbox[0]:bbox[0]+bbox[2]] = FN.normalize(FN.to_tensor(scImg), mean=(0.5,)*self.nc, std=(0.5,)*self.nc)
            #imglabel[label] = 1
            if i == randbox:
                outBox = FN.normalize(FN.to_tensor(FN.resize(scImg, (self.bbox_out_size, self.bbox_out_size))), mean=(0.5,)*self.nc, std=(0.5,)*self.nc)
                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.
                outbbox = bbox
                #boxlabel[label]=1

        #return image[[0,0,0],::], torch.FloatTensor([1]), outBox[[0,0,0],::], torch.FloatTensor([1]), mask, torch.IntTensor(outbbox)
        return image, torch.FloatTensor([1]), outBox, torch.FloatTensor([1]), mask, torch.IntTensor(outbbox) 
开发者ID:rakshithShetty,项目名称:adversarial-object-removal,代码行数:25,代码来源:data_loader_stargan.py

示例7: base_transform_nimgs

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import normalize [as 别名]
def base_transform_nimgs(images, size, mean, stds, seq_len=1):
    res_imgs = []
    # print(images.shape)
    for i in range(seq_len):
        # img = Image.fromarray(images[i,:, :, :])
        # img = img.resize((size, size), Image.BILINEAR)
        img = cv2.resize(images[i, :, :, :], (size, size)).astype(np.float32)
        #img = images[i, :, :, :].astype(np.float32)
        # img  = np.asarray(img)
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) / 255.0

        res_imgs += [torch.from_numpy(img).permute(2, 0, 1)]
    # pdb.set_trace()
    # res_imgs = np.asarray(res_imgs)
    return [F.normalize(img_tensor, mean, stds) for img_tensor in res_imgs]
    
    # return res_imgs 
开发者ID:gurkirt,项目名称:FPN.pytorch1.0,代码行数:19,代码来源:__init__.py

示例8: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import normalize [as 别名]
def __call__(self, image, target):
        if self.to_bgr255:
            image = image[[2, 1, 0]] * 255
        image = F.normalize(image, mean=self.mean, std=self.std)
        return image, target 
开发者ID:Res2Net,项目名称:Res2Net-maskrcnn,代码行数:7,代码来源:transforms.py

示例9: to_tensor_and_normalize

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import normalize [as 别名]
def to_tensor_and_normalize(image):
        return functional.normalize(functional.to_tensor(image), mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)) 
开发者ID:yuweijiang,项目名称:HGL-pytorch,代码行数:4,代码来源:box_utils.py

示例10: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import normalize [as 别名]
def __call__(self, sample):
        sample['leftImage'] = F.normalize(
            sample['leftImage'], mean=self.mean, std=self.std
        )
        sample['rightImage'] = F.normalize(
            sample['rightImage'], mean=self.mean, std=self.std
        )
        return sample 
开发者ID:DeepMotionAIResearch,项目名称:DenseMatchingBenchmark,代码行数:10,代码来源:flow_trans.py

示例11: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import normalize [as 别名]
def __call__(self, image, target):
        image = F.normalize(image, mean=self.mean, std=self.std)
        return image, target 
开发者ID:paperswithcode,项目名称:torchbench,代码行数:5,代码来源:transforms.py

示例12: _instance_process

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import normalize [as 别名]
def _instance_process(self, image, params):
        image.img = F.normalize(image.img, self.mean[:3], self.std[:3])
        if image.x is not None:
            image.x = F.normalize(image.x, self.mean[3:4], self.std[3:4])
        if image.y is not None:
            image.y = F.normalize(image.y, self.mean[3:4], self.std[3:4])
        return image 
开发者ID:yolomax,项目名称:person-reid-lib,代码行数:9,代码来源:transforms.py

示例13: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import normalize [as 别名]
def __call__(self, image, target=None):
        if self.to_bgr255:
            image = image[[2, 1, 0]] * 255
        image = F.normalize(image, mean=self.mean, std=self.std)
        if target is None:
            return image
        return image, target 
开发者ID:simaiden,项目名称:Clothing-Detection,代码行数:9,代码来源:transforms.py

示例14: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import normalize [as 别名]
def __call__(self, sample):
        input_data = sample['input']

        input_data = F.normalize(input_data, self.mean, self.std)

        rdict = {
            'input': input_data,
        }
        sample.update(rdict)
        return sample 
开发者ID:perone,项目名称:medicaltorch,代码行数:12,代码来源:transforms.py

示例15: __call__

# 需要导入模块: from torchvision.transforms import functional [as 别名]
# 或者: from torchvision.transforms.functional import normalize [as 别名]
def __call__(self, img, target):
        img = F.normalize(img, mean=self.mean, std=self.std)

        return img, target 
开发者ID:rosinality,项目名称:ocr-pytorch,代码行数:6,代码来源:transform.py


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