本文整理匯總了Python中torchvision.transforms.RandomGrayscale方法的典型用法代碼示例。如果您正苦於以下問題:Python transforms.RandomGrayscale方法的具體用法?Python transforms.RandomGrayscale怎麽用?Python transforms.RandomGrayscale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torchvision.transforms
的用法示例。
在下文中一共展示了transforms.RandomGrayscale方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_jig_train_transformers
# 需要導入模塊: from torchvision import transforms [as 別名]
# 或者: from torchvision.transforms import RandomGrayscale [as 別名]
def get_jig_train_transformers(args):
size = args.img_transform.random_resize_crop.size
scale = args.img_transform.random_resize_crop.scale
img_tr = [transforms.RandomResizedCrop((int(size[0]), int(size[1])), (scale[0], scale[1]))]
if args.img_transform.random_horiz_flip > 0.0:
img_tr.append(transforms.RandomHorizontalFlip(args.img_transform.random_horiz_flip))
if args.img_transform.jitter > 0.0:
img_tr.append(transforms.ColorJitter(
brightness=args.img_transform.jitter, contrast=args.img_transform.jitter,
saturation=args.jitter, hue=min(0.5, args.jitter)))
tile_tr = []
if args.jig_transform.tile_random_grayscale:
tile_tr.append(transforms.RandomGrayscale(args.jig_transform.tile_random_grayscale))
mean = args.normalize.mean
std = args.normalize.std
tile_tr = tile_tr + [transforms.ToTensor(), transforms.Normalize(mean=mean, std=std)]
return transforms.Compose(img_tr), transforms.Compose(tile_tr)
示例2: __init__
# 需要導入模塊: from torchvision import transforms [as 別名]
# 或者: from torchvision.transforms import RandomGrayscale [as 別名]
def __init__(self):
# flipping image along vertical axis
self.flip_lr = transforms.RandomHorizontalFlip(p=0.5)
# image augmentation functions
normalize = transforms.Normalize(mean=[x / 255.0 for x in [125.3, 123.0, 113.9]],
std=[x / 255.0 for x in [63.0, 62.1, 66.7]])
col_jitter = transforms.RandomApply([
transforms.ColorJitter(0.4, 0.4, 0.4, 0.2)], p=0.8)
img_jitter = transforms.RandomApply([
RandomTranslateWithReflect(4)], p=0.8)
rnd_gray = transforms.RandomGrayscale(p=0.25)
# main transform for self-supervised training
self.train_transform = transforms.Compose([
img_jitter,
col_jitter,
rnd_gray,
transforms.ToTensor(),
normalize
])
# transform for testing
self.test_transform = transforms.Compose([
transforms.ToTensor(),
normalize
])
示例3: image_random_grayscaler
# 需要導入模塊: from torchvision import transforms [as 別名]
# 或者: from torchvision.transforms import RandomGrayscale [as 別名]
def image_random_grayscaler(p=0.5):
return transforms.RandomGrayscale(p=p)
示例4: get_train_transformers
# 需要導入模塊: from torchvision import transforms [as 別名]
# 或者: from torchvision.transforms import RandomGrayscale [as 別名]
def get_train_transformers(args):
img_tr = [transforms.RandomResizedCrop((int(args.image_size), int(args.image_size)), (args.min_scale, args.max_scale))]
if args.random_horiz_flip > 0.0:
img_tr.append(transforms.RandomHorizontalFlip(args.random_horiz_flip))
if args.jitter > 0.0:
img_tr.append(transforms.ColorJitter(brightness=args.jitter, contrast=args.jitter, saturation=args.jitter, hue=min(0.5, args.jitter)))
tile_tr = []
if args.tile_random_grayscale:
tile_tr.append(transforms.RandomGrayscale(args.tile_random_grayscale))
tile_tr = tile_tr + [transforms.ToTensor(), transforms.Normalize([0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])]
return transforms.Compose(img_tr), transforms.Compose(tile_tr)