本文整理匯總了Python中nvidia.dali.ops.FileReader方法的典型用法代碼示例。如果您正苦於以下問題:Python ops.FileReader方法的具體用法?Python ops.FileReader怎麽用?Python ops.FileReader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類nvidia.dali.ops
的用法示例。
在下文中一共展示了ops.FileReader方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from nvidia.dali import ops [as 別名]
# 或者: from nvidia.dali.ops import FileReader [as 別名]
def __init__(self, file_list, file_root, crop_size,
batch_size, n_threads, device_id,
random_shuffle=False, seed=-1, mean=None, std=None,
n_samples=None):
super(DaliPipelineVal, 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 = 512
else:
initial_fill = min(512, 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.cmnorm = ops.CropMirrorNormalize(
device='gpu', crop=list(crop_size), mean=mean, std=std)
示例2: __init__
# 需要導入模塊: from nvidia.dali import ops [as 別名]
# 或者: from nvidia.dali.ops import FileReader [as 別名]
def __init__(self, batch_size, num_threads, device_id, data_dir, crop, size):
super(HybridValPipe, self).__init__(batch_size, num_threads, device_id, seed = 12 + device_id)
if torch.distributed.is_initialized():
local_rank = torch.distributed.get_rank()
world_size = torch.distributed.get_world_size()
else:
local_rank = 0
world_size = 1
self.input = ops.FileReader(
file_root = data_dir,
shard_id = local_rank,
num_shards = world_size,
random_shuffle = False)
self.decode = ops.nvJPEGDecoder(device = "mixed", output_type = types.RGB)
self.res = ops.Resize(device = "gpu", resize_shorter = size)
self.cmnp = ops.CropMirrorNormalize(device = "gpu",
output_dtype = types.FLOAT,
output_layout = types.NCHW,
crop = (crop, crop),
image_type = types.RGB,
mean = [0.485 * 255,0.456 * 255,0.406 * 255],
std = [0.229 * 255,0.224 * 255,0.225 * 255])
示例3: __init__
# 需要導入模塊: from nvidia.dali import ops [as 別名]
# 或者: from nvidia.dali.ops import FileReader [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)
示例4: __init__
# 需要導入模塊: from nvidia.dali import ops [as 別名]
# 或者: from nvidia.dali.ops import FileReader [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)
示例5: __init__
# 需要導入模塊: from nvidia.dali import ops [as 別名]
# 或者: from nvidia.dali.ops import FileReader [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))
示例6: __init__
# 需要導入模塊: from nvidia.dali import ops [as 別名]
# 或者: from nvidia.dali.ops import FileReader [as 別名]
def __init__(self, batch_size, num_threads, device_id, data_dir, crop, size,
mean, std, local_rank=0, world_size=1, dali_cpu=False, shuffle=False, fp16=False):
# As we're recreating the Pipeline at every epoch, the seed must be -1 (random seed)
super(HybridValPipe, self).__init__(batch_size, num_threads, device_id, seed=-1)
# Enabling read_ahead slowed down processing ~40%
# Note: initial_fill is for the shuffle buffer. As we only want to see every example once, this is set to 1
self.input = ops.FileReader(file_root=data_dir, shard_id=local_rank, num_shards=world_size, random_shuffle=shuffle, initial_fill=1)
if dali_cpu:
decode_device = "cpu"
self.dali_device = "cpu"
self.crop = ops.Crop(device="cpu", crop=(crop, crop))
else:
decode_device = "mixed"
self.dali_device = "gpu"
output_dtype = types.FLOAT
if fp16:
output_dtype = types.FLOAT16
self.cmnp = ops.CropMirrorNormalize(device="gpu",
output_dtype=output_dtype,
output_layout=types.NCHW,
crop=(crop, crop),
image_type=types.RGB,
mean=mean,
std=std)
self.decode = ops.ImageDecoder(device=decode_device, output_type=types.RGB)
# Resize to desired size. To match torchvision dataloader, use triangular interpolation
self.res = ops.Resize(device=self.dali_device, resize_shorter=size, interp_type=types.INTERP_TRIANGULAR)