本文整理汇总了Python中torchvision.transforms.transforms.ColorJitter方法的典型用法代码示例。如果您正苦于以下问题:Python transforms.ColorJitter方法的具体用法?Python transforms.ColorJitter怎么用?Python transforms.ColorJitter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torchvision.transforms.transforms
的用法示例。
在下文中一共展示了transforms.ColorJitter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: call_image
# 需要导入模块: from torchvision.transforms import transforms [as 别名]
# 或者: from torchvision.transforms.transforms import ColorJitter [as 别名]
def call_image(self, img):
return torch_transforms.ColorJitter(self.brightness, self.contrast, self.saturation, self.hue)(img)
示例2: preprocessImage
# 需要导入模块: from torchvision.transforms import transforms [as 别名]
# 或者: from torchvision.transforms.transforms import ColorJitter [as 别名]
def preprocessImage(img, use_color_jitter, image_size_dict, img_norm_info, use_caffe_pretrained_model):
# calculate target_size and scale_factor, target_size's format is (h, w)
w_ori, h_ori = img.width, img.height
if w_ori > h_ori:
target_size = (image_size_dict.get('SHORT_SIDE'), image_size_dict.get('LONG_SIDE'))
else:
target_size = (image_size_dict.get('LONG_SIDE'), image_size_dict.get('SHORT_SIDE'))
h_t, w_t = target_size
scale_factor = min(w_t/w_ori, h_t/h_ori)
target_size = (round(scale_factor*h_ori), round(scale_factor*w_ori))
# define and do transform
if use_caffe_pretrained_model:
means_norm = img_norm_info['caffe'].get('mean_rgb')
stds_norm = img_norm_info['caffe'].get('std_rgb')
if use_color_jitter:
transform = transforms.Compose([transforms.Resize(target_size),
transforms.ColorJitter(brightness=0.5, contrast=0.5, saturation=0.5, hue=0.1),
transforms.ToTensor(),
transforms.Normalize(mean=means_norm, std=stds_norm)])
else:
transform = transforms.Compose([transforms.Resize(target_size),
transforms.ToTensor(),
transforms.Normalize(mean=means_norm, std=stds_norm)])
img = transform(img) * 255
img = img[(2, 1, 0), :, :]
else:
means_norm = img_norm_info['pytorch'].get('mean_rgb')
stds_norm = img_norm_info['pytorch'].get('std_rgb')
if use_color_jitter:
transform = transforms.Compose([transforms.Resize(target_size),
transforms.ColorJitter(brightness=0.5, contrast=0.5, saturation=0.5, hue=0.1),
transforms.ToTensor(),
transforms.Normalize(mean=means_norm, std=stds_norm)])
else:
transform = transforms.Compose([transforms.Resize(target_size),
transforms.ToTensor(),
transforms.Normalize(mean=means_norm, std=stds_norm)])
img = transform(img)
# return necessary data
return img, scale_factor, target_size