Python torchvision.transforms.transforms.ColorJitter() Examples
The following are 2
code examples of torchvision.transforms.transforms.ColorJitter().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
torchvision.transforms.transforms
, or try the search function
.
Example #1
Source File: transforms.py From Jacinle with MIT License | 5 votes |
def call_image(self, img): return torch_transforms.ColorJitter(self.brightness, self.contrast, self.saturation, self.hue)(img)
Example #2
Source File: COCODataset.py From FasterRCNN.pytorch with MIT License | 5 votes |
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