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


Python transforms.ColorJitter方法代码示例

本文整理汇总了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) 
开发者ID:vacancy,项目名称:Jacinle,代码行数:4,代码来源:transforms.py

示例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 
开发者ID:DetectionBLWX,项目名称:FasterRCNN.pytorch,代码行数:42,代码来源:COCODataset.py


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