本文整理汇总了Python中nvidia.dali.ops.RandomResizedCrop方法的典型用法代码示例。如果您正苦于以下问题:Python ops.RandomResizedCrop方法的具体用法?Python ops.RandomResizedCrop怎么用?Python ops.RandomResizedCrop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nvidia.dali.ops
的用法示例。
在下文中一共展示了ops.RandomResizedCrop方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from nvidia.dali import ops [as 别名]
# 或者: from nvidia.dali.ops import RandomResizedCrop [as 别名]
def __init__(self, batch_size, num_threads, device_id, rec_path, idx_path,
shard_id, num_shards, crop_shape,
nvjpeg_padding, prefetch_queue=3,
output_layout=types.NCHW, pad_output=True, dtype='float16'):
super(HybridTrainPipe, self).__init__(batch_size, num_threads, device_id, seed = 12 + device_id, prefetch_queue_depth = prefetch_queue)
self.input = ops.MXNetReader(path = [rec_path], index_path=[idx_path],
random_shuffle=True, shard_id=shard_id, num_shards=num_shards)
self.decode = ops.nvJPEGDecoder(device = "mixed", output_type = types.RGB,
device_memory_padding = nvjpeg_padding,
host_memory_padding = nvjpeg_padding)
self.rrc = ops.RandomResizedCrop(device = "gpu", size = crop_shape)
self.cmnp = ops.CropMirrorNormalize(device = "gpu",
output_dtype = types.FLOAT16 if dtype == 'float16' else types.FLOAT,
output_layout = output_layout,
crop = crop_shape,
pad_output = pad_output,
image_type = types.RGB,
mean = _mean_pixel,
std = _std_pixel)
self.coin = ops.CoinFlip(probability = 0.5)
示例2: __init__
# 需要导入模块: from nvidia.dali import ops [as 别名]
# 或者: from nvidia.dali.ops import RandomResizedCrop [as 别名]
def __init__(self, batch_size, num_threads, device_id, data_dir, crop, seed=12, local_rank=0, world_size=1,
spos_pre=False):
super(HybridTrainPipe, self).__init__(batch_size, num_threads, device_id, seed=seed + device_id)
color_space_type = types.BGR if spos_pre else types.RGB
self.input = ops.FileReader(file_root=data_dir, shard_id=local_rank, num_shards=world_size, random_shuffle=True)
self.decode = ops.ImageDecoder(device="mixed", output_type=color_space_type)
self.res = ops.RandomResizedCrop(device="gpu", size=crop,
interp_type=types.INTERP_LINEAR if spos_pre else types.INTERP_TRIANGULAR)
self.twist = ops.ColorTwist(device="gpu")
self.jitter_rng = ops.Uniform(range=[0.6, 1.4])
self.cmnp = ops.CropMirrorNormalize(device="gpu",
output_dtype=types.FLOAT,
output_layout=types.NCHW,
image_type=color_space_type,
mean=0. if spos_pre else [0.485 * 255, 0.456 * 255, 0.406 * 255],
std=1. if spos_pre else [0.229 * 255, 0.224 * 255, 0.225 * 255])
self.coin = ops.CoinFlip(probability=0.5)
示例3: imgnet_transform
# 需要导入模块: from nvidia.dali import ops [as 别名]
# 或者: from nvidia.dali.ops import RandomResizedCrop [as 别名]
def imgnet_transform(is_training=True):
if is_training:
transform_list = transforms.Compose([transforms.RandomResizedCrop(224),
transforms.RandomHorizontalFlip(),
transforms.ColorJitter(brightness=0.5,
contrast=0.5,
saturation=0.3),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])])
else:
transform_list = transforms.Compose([transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])])
return transform_list
示例4: get_imagenet_iter_torch
# 需要导入模块: from nvidia.dali import ops [as 别名]
# 或者: from nvidia.dali.ops import RandomResizedCrop [as 别名]
def get_imagenet_iter_torch(type, image_dir, batch_size, num_threads, device_id, num_gpus, crop, val_size=256,
world_size=1, local_rank=0):
if type == 'train':
transform = transforms.Compose([
transforms.RandomResizedCrop(crop, scale=(0.08, 1.25)),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
dataset = datasets.ImageFolder(image_dir + '/train', transform)
dataloader = torch.utils.data.DataLoader(dataset, batch_size=batch_size, shuffle=True, num_workers=num_threads,
pin_memory=True)
else:
transform = transforms.Compose([
transforms.Resize(val_size),
transforms.CenterCrop(crop),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
dataset = datasets.ImageFolder(image_dir + '/val', transform)
dataloader = torch.utils.data.DataLoader(dataset, batch_size=batch_size, shuffle=False, num_workers=num_threads,
pin_memory=True)
return dataloader
示例5: __init__
# 需要导入模块: from nvidia.dali import ops [as 别名]
# 或者: from nvidia.dali.ops import RandomResizedCrop [as 别名]
def __init__(self, batch_size, num_threads, shard_id, image_dir, file_list, nvjpeg_padding,
prefetch_queue=3, seed=1, num_shards=1, channel_last=True,
spatial_size=(224, 224), dtype="half",
mean=_pixel_mean, std=_pixel_std, pad_output=True):
super(TrainPipeline, self).__init__(
batch_size, num_threads, shard_id, seed=seed, prefetch_queue_depth=prefetch_queue)
self.input = ops.FileReader(file_root=image_dir, file_list=file_list,
random_shuffle=True, num_shards=num_shards, shard_id=shard_id)
self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB,
device_memory_padding=nvjpeg_padding,
host_memory_padding=nvjpeg_padding)
self.rrc = ops.RandomResizedCrop(device="gpu", size=spatial_size)
self.cmnp = ops.CropMirrorNormalize(device="gpu",
output_dtype=types.FLOAT16 if dtype == "half" else types.FLOAT,
output_layout=types.NHWC if channel_last else types.NCHW,
crop=spatial_size,
image_type=types.RGB,
mean=mean,
std=std,
pad_output=pad_output)
self.coin = ops.CoinFlip(probability=0.5)
示例6: __init__
# 需要导入模块: from nvidia.dali import ops [as 别名]
# 或者: from nvidia.dali.ops import RandomResizedCrop [as 别名]
def __init__(self, file_list, file_root, crop_size,
batch_size, n_threads, device_id,
random_shuffle=True, seed=-1, mean=None, std=None,
n_samples=None):
super(DaliPipelineTrain, self).__init__(batch_size, n_threads,
device_id, seed=seed)
crop_size = _pair(crop_size)
if mean is None:
mean = [0.485 * 255, 0.456 * 255, 0.406 * 255]
if std is None:
std = [0.229 * 255, 0.224 * 255, 0.225 * 255]
if n_samples is None:
initial_fill = 4096
else:
initial_fill = min(4096, n_samples)
self.loader = ops.FileReader(file_root=file_root, file_list=file_list,
random_shuffle=random_shuffle,
initial_fill=initial_fill)
self.decode = ops.HostDecoder()
self.resize = ops.Resize(device='gpu', resize_x=256, resize_y=256)
# self.hue = ops.Hue(device="gpu")
# self.bright = ops.Brightness(device="gpu")
# self.cntrst = ops.Contrast(device="gpu")
# self.rotate = ops.Rotate(device="gpu")
# self.jitter = ops.Jitter(device="gpu")
random_area = (crop_size[0] / 256.0) * (crop_size[1] / 256.0)
random_area = _pair(random_area)
random_aspect_ratio = _pair(1.0)
self.rrcrop = ops.RandomResizedCrop(
device='gpu', size=crop_size, random_area=random_area,
random_aspect_ratio=random_aspect_ratio)
self.cmnorm = ops.CropMirrorNormalize(
device='gpu', crop=list(crop_size), mean=mean, std=std)
self.coin = ops.CoinFlip(probability=0.5)
示例7: __init__
# 需要导入模块: from nvidia.dali import ops [as 别名]
# 或者: from nvidia.dali.ops import RandomResizedCrop [as 别名]
def __init__(self, batch_size, num_threads, device_id, data_dir, crop, dali_cpu=False, local_rank=0, world_size=1):
super(HybridTrainPipe, self).__init__(batch_size, num_threads, device_id, seed=12 + device_id)
dali_device = "gpu"
self.input = ops.FileReader(file_root=data_dir, shard_id=local_rank, num_shards=world_size, random_shuffle=True)
self.decode = ops.ImageDecoder(device="mixed", output_type=types.RGB)
self.res = ops.RandomResizedCrop(device="gpu", size=crop, random_area=[0.08, 1.25])
self.cmnp = ops.CropMirrorNormalize(device="gpu",
output_dtype=types.FLOAT,
output_layout=types.NCHW,
image_type=types.RGB,
mean=[0.485 * 255, 0.456 * 255, 0.406 * 255],
std=[0.229 * 255, 0.224 * 255, 0.225 * 255])
self.coin = ops.CoinFlip(probability=0.5)
print('DALI "{0}" variant'.format(dali_device))
示例8: __init__
# 需要导入模块: from nvidia.dali import ops [as 别名]
# 或者: from nvidia.dali.ops import RandomResizedCrop [as 别名]
def __init__(self, batch_size, num_threads, device_id, rec_path, idx_path,
shard_id, num_shards, crop_shape,
min_random_area, max_random_area,
min_random_aspect_ratio, max_random_aspect_ratio,
nvjpeg_padding, prefetch_queue=3,
seed=12,
output_layout=types.NCHW, pad_output=True, dtype='float16',
mlperf_print=True):
super(HybridTrainPipe, self).__init__(
batch_size, num_threads, device_id,
seed = seed + device_id,
prefetch_queue_depth = prefetch_queue)
if mlperf_print:
# Shuffiling is done inside ops.MXNetReader
mx_resnet_print(key=mlperf_log.INPUT_ORDER)
self.input = ops.MXNetReader(path = [rec_path], index_path=[idx_path],
random_shuffle=True, shard_id=shard_id, num_shards=num_shards)
self.decode = ops.nvJPEGDecoder(device = "mixed", output_type = types.RGB,
device_memory_padding = nvjpeg_padding,
host_memory_padding = nvjpeg_padding)
self.rrc = ops.RandomResizedCrop(device = "gpu",
random_area = [
min_random_area,
max_random_area],
random_aspect_ratio = [
min_random_aspect_ratio,
max_random_aspect_ratio],
size = crop_shape)
self.cmnp = ops.CropMirrorNormalize(device = "gpu",
output_dtype = types.FLOAT16 if dtype == 'float16' else types.FLOAT,
output_layout = output_layout,
crop = crop_shape,
pad_output = pad_output,
image_type = types.RGB,
mean = _mean_pixel,
std = _std_pixel)
self.coin = ops.CoinFlip(probability = 0.5)
if mlperf_print:
mx_resnet_print(
key=mlperf_log.INPUT_CROP_USES_BBOXES,
val=False)
mx_resnet_print(
key=mlperf_log.INPUT_DISTORTED_CROP_RATIO_RANGE,
val=(min_random_aspect_ratio,
max_random_aspect_ratio))
mx_resnet_print(
key=mlperf_log.INPUT_DISTORTED_CROP_AREA_RANGE,
val=(min_random_area,
max_random_area))
mx_resnet_print(
key=mlperf_log.INPUT_MEAN_SUBTRACTION,
val=_mean_pixel)
mx_resnet_print(
key=mlperf_log.INPUT_RANDOM_FLIP)