本文整理汇总了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)